| 1 |
// SPDX-License-Identifier: GPL-1.0+ |
| 2 |
/* lasi_82596.c -- driver for the intel 82596 ethernet controller, as |
| 3 |
munged into HPPA boxen . |
| 4 |
|
| 5 |
This driver is based upon 82596.c, original credits are below... |
| 6 |
but there were too many hoops which HP wants jumped through to |
| 7 |
keep this code in there in a sane manner. |
| 8 |
|
| 9 |
3 primary sources of the mess -- |
| 10 |
1) hppa needs *lots* of cacheline flushing to keep this kind of |
| 11 |
MMIO running. |
| 12 |
|
| 13 |
2) The 82596 needs to see all of its pointers as their physical |
| 14 |
address. Thus virt_to_bus/bus_to_virt are *everywhere*. |
| 15 |
|
| 16 |
3) The implementation HP is using seems to be significantly pickier |
| 17 |
about when and how the command and RX units are started. some |
| 18 |
command ordering was changed. |
| 19 |
|
| 20 |
Examination of the mach driver leads one to believe that there |
| 21 |
might be a saner way to pull this off... anyone who feels like a |
| 22 |
full rewrite can be my guest. |
| 23 |
|
| 24 |
Split 02/13/2000 Sam Creasey ([email protected]) |
| 25 |
|
| 26 |
02/01/2000 Initial modifications for parisc by Helge Deller ([email protected]) |
| 27 |
03/02/2000 changes for better/correct(?) cache-flushing (deller) |
| 28 |
*/ |
| 29 |
|
| 30 |
/* 82596.c: A generic 82596 ethernet driver for linux. */ |
| 31 |
/* |
| 32 |
Based on Apricot.c |
| 33 |
Written 1994 by Mark Evans. |
| 34 |
This driver is for the Apricot 82596 bus-master interface |
| 35 |
|
| 36 |
Modularised 12/94 Mark Evans |
| 37 |
|
| 38 |
|
| 39 |
Modified to support the 82596 ethernet chips on 680x0 VME boards. |
| 40 |
by Richard Hirst <[email protected]> |
| 41 |
Renamed to be 82596.c |
| 42 |
|
| 43 |
980825: Changed to receive directly in to sk_buffs which are |
| 44 |
allocated at open() time. Eliminates copy on incoming frames |
| 45 |
(small ones are still copied). Shared data now held in a |
| 46 |
non-cached page, so we can run on 68060 in copyback mode. |
| 47 |
|
| 48 |
TBD: |
| 49 |
* look at deferring rx frames rather than discarding (as per tulip) |
| 50 |
* handle tx ring full as per tulip |
| 51 |
* performance test to tune rx_copybreak |
| 52 |
|
| 53 |
Most of my modifications relate to the braindead big-endian |
| 54 |
implementation by Intel. When the i596 is operating in |
| 55 |
'big-endian' mode, it thinks a 32 bit value of 0x12345678 |
| 56 |
should be stored as 0x56781234. This is a real pain, when |
| 57 |
you have linked lists which are shared by the 680x0 and the |
| 58 |
i596. |
| 59 |
|
| 60 |
Driver skeleton |
| 61 |
Written 1993 by Donald Becker. |
| 62 |
Copyright 1993 United States Government as represented by the Director, |
| 63 |
National Security Agency. |
| 64 |
|
| 65 |
The author may be reached as [email protected], or C/O |
| 66 |
Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403 |
| 67 |
|
| 68 |
*/ |
| 69 |
|
| 70 |
#include <linux/module.h> |
| 71 |
#include <linux/kernel.h> |
| 72 |
#include <linux/string.h> |
| 73 |
#include <linux/ptrace.h> |
| 74 |
#include <linux/errno.h> |
| 75 |
#include <linux/ioport.h> |
| 76 |
#include <linux/interrupt.h> |
| 77 |
#include <linux/delay.h> |
| 78 |
#include <linux/netdevice.h> |
| 79 |
#include <linux/etherdevice.h> |
| 80 |
#include <linux/skbuff.h> |
| 81 |
#include <linux/types.h> |
| 82 |
#include <linux/bitops.h> |
| 83 |
#include <linux/dma-mapping.h> |
| 84 |
|
| 85 |
#include <asm/io.h> |
| 86 |
#include <asm/irq.h> |
| 87 |
#include <asm/pdc.h> |
| 88 |
#include <asm/parisc-device.h> |
| 89 |
|
| 90 |
#define LASI_82596_DRIVER_VERSION "LASI 82596 driver - Revision: 1.30" |
| 91 |
|
| 92 |
#define PA_I82596_RESET 0 /* Offsets relative to LASI-LAN-Addr.*/ |
| 93 |
#define PA_CPU_PORT_L_ACCESS 4 |
| 94 |
#define PA_CHANNEL_ATTENTION 8 |
| 95 |
|
| 96 |
#define OPT_SWAP_PORT 0x0001 /* Need to wordswp on the MPU port */ |
| 97 |
|
| 98 |
#define SYSBUS 0x0000006c |
| 99 |
|
| 100 |
/* big endian CPU, 82596 "big" endian mode */ |
| 101 |
#define SWAP32(x) (((u32)(x)<<16) | ((((u32)(x)))>>16)) |
| 102 |
#define SWAP16(x) (x) |
| 103 |
|
| 104 |
#define NONCOHERENT_DMA 1 |
| 105 |
|
| 106 |
#include "lib82596.c" |
| 107 |
|
| 108 |
MODULE_AUTHOR("Richard Hirst"); |
| 109 |
MODULE_DESCRIPTION("i82596 driver"); |
| 110 |
MODULE_LICENSE("GPL"); |
| 111 |
module_param(i596_debug, int, 0); |
| 112 |
MODULE_PARM_DESC(i596_debug, "lasi_82596 debug mask"); |
| 113 |
|
| 114 |
static inline void ca(struct net_device *dev) |
| 115 |
{ |
| 116 |
gsc_writel(0, dev->base_addr + PA_CHANNEL_ATTENTION); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
static void mpu_port(struct net_device *dev, int c, dma_addr_t x) |
| 121 |
{ |
| 122 |
struct i596_private *lp = netdev_priv(dev); |
| 123 |
|
| 124 |
u32 v = (u32) (c) | (u32) (x); |
| 125 |
u16 a, b; |
| 126 |
|
| 127 |
if (lp->options & OPT_SWAP_PORT) { |
| 128 |
a = v >> 16; |
| 129 |
b = v & 0xffff; |
| 130 |
} else { |
| 131 |
a = v & 0xffff; |
| 132 |
b = v >> 16; |
| 133 |
} |
| 134 |
|
| 135 |
gsc_writel(a, dev->base_addr + PA_CPU_PORT_L_ACCESS); |
| 136 |
if (!running_on_qemu) |
| 137 |
udelay(1); |
| 138 |
gsc_writel(b, dev->base_addr + PA_CPU_PORT_L_ACCESS); |
| 139 |
} |
| 140 |
|
| 141 |
#define LAN_PROM_ADDR 0xF0810000 |
| 142 |
|
| 143 |
static int __init |
| 144 |
lan_init_chip(struct parisc_device *dev) |
| 145 |
{ |
| 146 |
struct net_device *netdevice; |
| 147 |
struct i596_private *lp; |
| 148 |
int retval = -ENOMEM; |
| 149 |
u8 addr[ETH_ALEN]; |
| 150 |
int i; |
| 151 |
|
| 152 |
if (!dev->irq) { |
| 153 |
printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n", |
| 154 |
__FILE__, (unsigned long)dev->hpa.start); |
| 155 |
return -ENODEV; |
| 156 |
} |
| 157 |
|
| 158 |
printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n", |
| 159 |
(unsigned long)dev->hpa.start, dev->irq); |
| 160 |
|
| 161 |
netdevice = alloc_etherdev(sizeof(struct i596_private)); |
| 162 |
if (!netdevice) |
| 163 |
return -ENOMEM; |
| 164 |
SET_NETDEV_DEV(netdevice, &dev->dev); |
| 165 |
parisc_set_drvdata (dev, netdevice); |
| 166 |
|
| 167 |
netdevice->base_addr = dev->hpa.start; |
| 168 |
netdevice->irq = dev->irq; |
| 169 |
|
| 170 |
if (pdc_lan_station_id(addr, netdevice->base_addr)) { |
| 171 |
for (i = 0; i < 6; i++) { |
| 172 |
addr[i] = gsc_readb(LAN_PROM_ADDR + i); |
| 173 |
} |
| 174 |
printk(KERN_INFO |
| 175 |
"%s: MAC of HP700 LAN read from EEPROM\n", __FILE__); |
| 176 |
} |
| 177 |
eth_hw_addr_set(netdevice, addr); |
| 178 |
|
| 179 |
lp = netdev_priv(netdevice); |
| 180 |
lp->options = dev->id.sversion == 0x72 ? OPT_SWAP_PORT : 0; |
| 181 |
lp->dma = dma_alloc_noncoherent(&dev->dev, |
| 182 |
sizeof(struct i596_dma), &lp->dma_addr, |
| 183 |
DMA_BIDIRECTIONAL, GFP_KERNEL); |
| 184 |
if (!lp->dma) |
| 185 |
goto out_free_netdev; |
| 186 |
|
| 187 |
retval = i82596_probe(netdevice); |
| 188 |
if (retval) |
| 189 |
goto out_free_dma; |
| 190 |
return 0; |
| 191 |
|
| 192 |
out_free_dma: |
| 193 |
dma_free_noncoherent(&dev->dev, sizeof(struct i596_dma), |
| 194 |
lp->dma, lp->dma_addr, DMA_BIDIRECTIONAL); |
| 195 |
out_free_netdev: |
| 196 |
free_netdev(netdevice); |
| 197 |
return retval; |
| 198 |
} |
| 199 |
|
| 200 |
static void __exit lan_remove_chip(struct parisc_device *pdev) |
| 201 |
{ |
| 202 |
struct net_device *dev = parisc_get_drvdata(pdev); |
| 203 |
struct i596_private *lp = netdev_priv(dev); |
| 204 |
|
| 205 |
unregister_netdev (dev); |
| 206 |
dma_free_noncoherent(&pdev->dev, sizeof(struct i596_private), lp->dma, |
| 207 |
lp->dma_addr, DMA_BIDIRECTIONAL); |
| 208 |
free_netdev (dev); |
| 209 |
} |
| 210 |
|
| 211 |
static const struct parisc_device_id lan_tbl[] __initconst = { |
| 212 |
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008a }, |
| 213 |
{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00072 }, |
| 214 |
{ 0, } |
| 215 |
}; |
| 216 |
|
| 217 |
MODULE_DEVICE_TABLE(parisc, lan_tbl); |
| 218 |
|
| 219 |
static struct parisc_driver lan_driver __refdata = { |
| 220 |
.name = "lasi_82596", |
| 221 |
.id_table = lan_tbl, |
| 222 |
.probe = lan_init_chip, |
| 223 |
.remove = __exit_p(lan_remove_chip), |
| 224 |
}; |
| 225 |
|
| 226 |
static int lasi_82596_init(void) |
| 227 |
{ |
| 228 |
printk(KERN_INFO LASI_82596_DRIVER_VERSION "\n"); |
| 229 |
return register_parisc_driver(&lan_driver); |
| 230 |
} |
| 231 |
|
| 232 |
module_init(lasi_82596_init); |
| 233 |
|
| 234 |
static void __exit lasi_82596_exit(void) |
| 235 |
{ |
| 236 |
unregister_parisc_driver(&lan_driver); |
| 237 |
} |
| 238 |
|
| 239 |
module_exit(lasi_82596_exit); |