Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* 3c501.c: A 3Com 3c501 Ethernet driver for Linux. */ |
| 2 | /* |
| 3 | Written 1992,1993,1994 Donald Becker |
| 4 | |
| 5 | Copyright 1993 United States Government as represented by the |
| 6 | Director, National Security Agency. This software may be used and |
| 7 | distributed according to the terms of the GNU General Public License, |
| 8 | incorporated herein by reference. |
| 9 | |
| 10 | This is a device driver for the 3Com Etherlink 3c501. |
| 11 | Do not purchase this card, even as a joke. It's performance is horrible, |
| 12 | and it breaks in many ways. |
| 13 | |
| 14 | The original author may be reached as becker@scyld.com, or C/O |
| 15 | Scyld Computing Corporation |
| 16 | 410 Severn Ave., Suite 210 |
| 17 | Annapolis MD 21403 |
| 18 | |
| 19 | Fixed (again!) the missing interrupt locking on TX/RX shifting. |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 20 | Alan Cox <Alan.Cox@linux.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | Removed calls to init_etherdev since they are no longer needed, and |
| 23 | cleaned up modularization just a bit. The driver still allows only |
| 24 | the default address for cards when loaded as a module, but that's |
| 25 | really less braindead than anyone using a 3c501 board. :) |
| 26 | 19950208 (invid@msen.com) |
| 27 | |
| 28 | Added traps for interrupts hitting the window as we clear and TX load |
| 29 | the board. Now getting 150K/second FTP with a 3c501 card. Still playing |
| 30 | with a TX-TX optimisation to see if we can touch 180-200K/second as seems |
| 31 | theoretically maximum. |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 32 | 19950402 Alan Cox <Alan.Cox@linux.org> |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 33 | |
| 34 | Cleaned up for 2.3.x because we broke SMP now. |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 35 | 20000208 Alan Cox <alan@redhat.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | Check up pass for 2.5. Nothing significant changed |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 38 | 20021009 Alan Cox <alan@redhat.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 40 | Fixed zero fill corner case |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 41 | 20030104 Alan Cox <alan@redhat.com> |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 42 | |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | For the avoidance of doubt the "preferred form" of this code is one which |
| 45 | is in an open non patent encumbered format. Where cryptographic key signing |
| 46 | forms part of the process of creating an executable the information |
| 47 | including keys needed to generate an equivalently functional executable |
| 48 | are deemed to be part of the source code. |
| 49 | |
| 50 | */ |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * DOC: 3c501 Card Notes |
| 55 | * |
| 56 | * Some notes on this thing if you have to hack it. [Alan] |
| 57 | * |
| 58 | * Some documentation is available from 3Com. Due to the boards age |
| 59 | * standard responses when you ask for this will range from 'be serious' |
| 60 | * to 'give it to a museum'. The documentation is incomplete and mostly |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 61 | * of historical interest anyway. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * |
| 63 | * The basic system is a single buffer which can be used to receive or |
| 64 | * transmit a packet. A third command mode exists when you are setting |
| 65 | * things up. |
| 66 | * |
| 67 | * If it's transmitting it's not receiving and vice versa. In fact the |
| 68 | * time to get the board back into useful state after an operation is |
| 69 | * quite large. |
| 70 | * |
| 71 | * The driver works by keeping the board in receive mode waiting for a |
| 72 | * packet to arrive. When one arrives it is copied out of the buffer |
| 73 | * and delivered to the kernel. The card is reloaded and off we go. |
| 74 | * |
| 75 | * When transmitting lp->txing is set and the card is reset (from |
| 76 | * receive mode) [possibly losing a packet just received] to command |
| 77 | * mode. A packet is loaded and transmit mode triggered. The interrupt |
| 78 | * handler runs different code for transmit interrupts and can handle |
| 79 | * returning to receive mode or retransmissions (yes you have to help |
| 80 | * out with those too). |
| 81 | * |
| 82 | * DOC: Problems |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 83 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | * There are a wide variety of undocumented error returns from the card |
| 85 | * and you basically have to kick the board and pray if they turn up. Most |
| 86 | * only occur under extreme load or if you do something the board doesn't |
| 87 | * like (eg touching a register at the wrong time). |
| 88 | * |
| 89 | * The driver is less efficient than it could be. It switches through |
| 90 | * receive mode even if more transmits are queued. If this worries you buy |
| 91 | * a real Ethernet card. |
| 92 | * |
| 93 | * The combination of slow receive restart and no real multicast |
| 94 | * filter makes the board unusable with a kernel compiled for IP |
| 95 | * multicasting in a real multicast environment. That's down to the board, |
| 96 | * but even with no multicast programs running a multicast IP kernel is |
| 97 | * in group 224.0.0.1 and you will therefore be listening to all multicasts. |
| 98 | * One nv conference running over that Ethernet and you can give up. |
| 99 | * |
| 100 | */ |
| 101 | |
| 102 | #define DRV_NAME "3c501" |
| 103 | #define DRV_VERSION "2002/10/09" |
| 104 | |
| 105 | |
| 106 | static const char version[] = |
| 107 | DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@redhat.com).\n"; |
| 108 | |
| 109 | /* |
| 110 | * Braindamage remaining: |
| 111 | * The 3c501 board. |
| 112 | */ |
| 113 | |
| 114 | #include <linux/module.h> |
| 115 | |
| 116 | #include <linux/kernel.h> |
| 117 | #include <linux/fcntl.h> |
| 118 | #include <linux/ioport.h> |
| 119 | #include <linux/interrupt.h> |
| 120 | #include <linux/slab.h> |
| 121 | #include <linux/string.h> |
| 122 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #include <linux/spinlock.h> |
| 124 | #include <linux/ethtool.h> |
| 125 | #include <linux/delay.h> |
| 126 | #include <linux/bitops.h> |
| 127 | |
| 128 | #include <asm/uaccess.h> |
| 129 | #include <asm/io.h> |
| 130 | |
| 131 | #include <linux/netdevice.h> |
| 132 | #include <linux/etherdevice.h> |
| 133 | #include <linux/skbuff.h> |
| 134 | #include <linux/init.h> |
| 135 | |
| 136 | #include "3c501.h" |
| 137 | |
| 138 | /* |
| 139 | * The boilerplate probe code. |
| 140 | */ |
| 141 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 142 | static int io = 0x280; |
| 143 | static int irq = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | static int mem_start; |
| 145 | |
| 146 | /** |
| 147 | * el1_probe: - probe for a 3c501 |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 148 | * @dev: The device structure passed in to probe. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | * |
| 150 | * This can be called from two places. The network layer will probe using |
| 151 | * a device structure passed in with the probe information completed. For a |
| 152 | * modular driver we use #init_module to fill in our own structure and probe |
| 153 | * for it. |
| 154 | * |
| 155 | * Returns 0 on success. ENXIO if asked not to probe and ENODEV if asked to |
| 156 | * probe and failing to find anything. |
| 157 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | struct net_device * __init el1_probe(int unit) |
| 160 | { |
| 161 | struct net_device *dev = alloc_etherdev(sizeof(struct net_local)); |
| 162 | static unsigned ports[] = { 0x280, 0x300, 0}; |
| 163 | unsigned *port; |
| 164 | int err = 0; |
| 165 | |
| 166 | if (!dev) |
| 167 | return ERR_PTR(-ENOMEM); |
| 168 | |
| 169 | if (unit >= 0) { |
| 170 | sprintf(dev->name, "eth%d", unit); |
| 171 | netdev_boot_setup_check(dev); |
| 172 | io = dev->base_addr; |
| 173 | irq = dev->irq; |
| 174 | mem_start = dev->mem_start & 7; |
| 175 | } |
| 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | if (io > 0x1ff) { /* Check a single specified location. */ |
| 178 | err = el1_probe1(dev, io); |
| 179 | } else if (io != 0) { |
| 180 | err = -ENXIO; /* Don't probe at all. */ |
| 181 | } else { |
| 182 | for (port = ports; *port && el1_probe1(dev, *port); port++) |
| 183 | ; |
| 184 | if (!*port) |
| 185 | err = -ENODEV; |
| 186 | } |
| 187 | if (err) |
| 188 | goto out; |
| 189 | err = register_netdev(dev); |
| 190 | if (err) |
| 191 | goto out1; |
| 192 | return dev; |
| 193 | out1: |
| 194 | release_region(dev->base_addr, EL1_IO_EXTENT); |
| 195 | out: |
| 196 | free_netdev(dev); |
| 197 | return ERR_PTR(err); |
| 198 | } |
| 199 | |
| 200 | /** |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 201 | * el1_probe1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | * @dev: The device structure to use |
| 203 | * @ioaddr: An I/O address to probe at. |
| 204 | * |
| 205 | * The actual probe. This is iterated over by #el1_probe in order to |
| 206 | * check all the applicable device locations. |
| 207 | * |
| 208 | * Returns 0 for a success, in which case the device is activated, |
| 209 | * EAGAIN if the IRQ is in use by another driver, and ENODEV if the |
| 210 | * board cannot be found. |
| 211 | */ |
| 212 | |
| 213 | static int __init el1_probe1(struct net_device *dev, int ioaddr) |
| 214 | { |
| 215 | struct net_local *lp; |
| 216 | const char *mname; /* Vendor name */ |
| 217 | unsigned char station_addr[6]; |
| 218 | int autoirq = 0; |
| 219 | int i; |
| 220 | |
| 221 | /* |
| 222 | * Reserve I/O resource for exclusive use by this driver |
| 223 | */ |
| 224 | |
| 225 | if (!request_region(ioaddr, EL1_IO_EXTENT, DRV_NAME)) |
| 226 | return -ENODEV; |
| 227 | |
| 228 | /* |
| 229 | * Read the station address PROM data from the special port. |
| 230 | */ |
| 231 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 232 | for (i = 0; i < 6; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | outw(i, ioaddr + EL1_DATAPTR); |
| 234 | station_addr[i] = inb(ioaddr + EL1_SAPROM); |
| 235 | } |
| 236 | /* |
| 237 | * Check the first three octets of the S.A. for 3Com's prefix, or |
| 238 | * for the Sager NP943 prefix. |
| 239 | */ |
| 240 | |
| 241 | if (station_addr[0] == 0x02 && station_addr[1] == 0x60 |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 242 | && station_addr[2] == 0x8c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | mname = "3c501"; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 244 | else if (station_addr[0] == 0x00 && station_addr[1] == 0x80 |
| 245 | && station_addr[2] == 0xC8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | mname = "NP943"; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 247 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | release_region(ioaddr, EL1_IO_EXTENT); |
| 249 | return -ENODEV; |
| 250 | } |
| 251 | |
| 252 | /* |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 253 | * We auto-IRQ by shutting off the interrupt line and letting it |
| 254 | * float high. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | */ |
| 256 | |
| 257 | dev->irq = irq; |
| 258 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 259 | if (dev->irq < 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | unsigned long irq_mask; |
| 261 | |
| 262 | irq_mask = probe_irq_on(); |
| 263 | inb(RX_STATUS); /* Clear pending interrupts. */ |
| 264 | inb(TX_STATUS); |
| 265 | outb(AX_LOOP + 1, AX_CMD); |
| 266 | |
| 267 | outb(0x00, AX_CMD); |
| 268 | |
| 269 | mdelay(20); |
| 270 | autoirq = probe_irq_off(irq_mask); |
| 271 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 272 | if (autoirq == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | printk(KERN_WARNING "%s probe at %#x failed to detect IRQ line.\n", |
| 274 | mname, ioaddr); |
| 275 | release_region(ioaddr, EL1_IO_EXTENT); |
| 276 | return -EAGAIN; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | outb(AX_RESET+AX_LOOP, AX_CMD); /* Loopback mode. */ |
| 281 | dev->base_addr = ioaddr; |
| 282 | memcpy(dev->dev_addr, station_addr, ETH_ALEN); |
| 283 | |
| 284 | if (mem_start & 0xf) |
| 285 | el_debug = mem_start & 0x7; |
| 286 | if (autoirq) |
| 287 | dev->irq = autoirq; |
| 288 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 289 | printk(KERN_INFO "%s: %s EtherLink at %#lx, using %sIRQ %d.\n", |
| 290 | dev->name, mname, dev->base_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | autoirq ? "auto":"assigned ", dev->irq); |
| 292 | |
| 293 | #ifdef CONFIG_IP_MULTICAST |
| 294 | printk(KERN_WARNING "WARNING: Use of the 3c501 in a multicast kernel is NOT recommended.\n"); |
| 295 | #endif |
| 296 | |
| 297 | if (el_debug) |
| 298 | printk(KERN_DEBUG "%s", version); |
| 299 | |
| 300 | memset(dev->priv, 0, sizeof(struct net_local)); |
| 301 | lp = netdev_priv(dev); |
| 302 | spin_lock_init(&lp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | /* |
| 305 | * The EL1-specific entries in the device structure. |
| 306 | */ |
| 307 | |
| 308 | dev->open = &el_open; |
| 309 | dev->hard_start_xmit = &el_start_xmit; |
| 310 | dev->tx_timeout = &el_timeout; |
| 311 | dev->watchdog_timeo = HZ; |
| 312 | dev->stop = &el1_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | dev->set_multicast_list = &set_multicast_list; |
| 314 | dev->ethtool_ops = &netdev_ethtool_ops; |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * el1_open: |
| 320 | * @dev: device that is being opened |
| 321 | * |
| 322 | * When an ifconfig is issued which changes the device flags to include |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 323 | * IFF_UP this function is called. It is only called when the change |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | * occurs, not when the interface remains up. #el1_close will be called |
| 325 | * when it goes down. |
| 326 | * |
| 327 | * Returns 0 for a successful open, or -EAGAIN if someone has run off |
| 328 | * with our interrupt line. |
| 329 | */ |
| 330 | |
| 331 | static int el_open(struct net_device *dev) |
| 332 | { |
| 333 | int retval; |
| 334 | int ioaddr = dev->base_addr; |
| 335 | struct net_local *lp = netdev_priv(dev); |
| 336 | unsigned long flags; |
| 337 | |
| 338 | if (el_debug > 2) |
| 339 | printk(KERN_DEBUG "%s: Doing el_open()...", dev->name); |
| 340 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 341 | retval = request_irq(dev->irq, &el_interrupt, 0, dev->name, dev); |
| 342 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return retval; |
| 344 | |
| 345 | spin_lock_irqsave(&lp->lock, flags); |
| 346 | el_reset(dev); |
| 347 | spin_unlock_irqrestore(&lp->lock, flags); |
| 348 | |
| 349 | lp->txing = 0; /* Board in RX mode */ |
| 350 | outb(AX_RX, AX_CMD); /* Aux control, irq and receive enabled */ |
| 351 | netif_start_queue(dev); |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * el_timeout: |
| 357 | * @dev: The 3c501 card that has timed out |
| 358 | * |
| 359 | * Attempt to restart the board. This is basically a mixture of extreme |
| 360 | * violence and prayer |
| 361 | * |
| 362 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | static void el_timeout(struct net_device *dev) |
| 365 | { |
| 366 | struct net_local *lp = netdev_priv(dev); |
| 367 | int ioaddr = dev->base_addr; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | if (el_debug) |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 370 | printk(KERN_DEBUG "%s: transmit timed out, txsr %#2x axsr=%02x rxsr=%02x.\n", |
| 371 | dev->name, inb(TX_STATUS), |
| 372 | inb(AX_STATUS), inb(RX_STATUS)); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 373 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | outb(TX_NORM, TX_CMD); |
| 375 | outb(RX_NORM, RX_CMD); |
| 376 | outb(AX_OFF, AX_CMD); /* Just trigger a false interrupt. */ |
| 377 | outb(AX_RX, AX_CMD); /* Aux control, irq and receive enabled */ |
| 378 | lp->txing = 0; /* Ripped back in to RX */ |
| 379 | netif_wake_queue(dev); |
| 380 | } |
| 381 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /** |
| 384 | * el_start_xmit: |
| 385 | * @skb: The packet that is queued to be sent |
| 386 | * @dev: The 3c501 card we want to throw it down |
| 387 | * |
| 388 | * Attempt to send a packet to a 3c501 card. There are some interesting |
| 389 | * catches here because the 3c501 is an extremely old and therefore |
| 390 | * stupid piece of technology. |
| 391 | * |
| 392 | * If we are handling an interrupt on the other CPU we cannot load a packet |
| 393 | * as we may still be attempting to retrieve the last RX packet buffer. |
| 394 | * |
| 395 | * When a transmit times out we dump the card into control mode and just |
| 396 | * start again. It happens enough that it isnt worth logging. |
| 397 | * |
| 398 | * We avoid holding the spin locks when doing the packet load to the board. |
| 399 | * The device is very slow, and its DMA mode is even slower. If we held the |
| 400 | * lock while loading 1500 bytes onto the controller we would drop a lot of |
| 401 | * serial port characters. This requires we do extra locking, but we have |
| 402 | * no real choice. |
| 403 | */ |
| 404 | |
| 405 | static int el_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 406 | { |
| 407 | struct net_local *lp = netdev_priv(dev); |
| 408 | int ioaddr = dev->base_addr; |
| 409 | unsigned long flags; |
| 410 | |
| 411 | /* |
| 412 | * Avoid incoming interrupts between us flipping txing and flipping |
| 413 | * mode as the driver assumes txing is a faithful indicator of card |
| 414 | * state |
| 415 | */ |
| 416 | |
| 417 | spin_lock_irqsave(&lp->lock, flags); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | /* |
| 420 | * Avoid timer-based retransmission conflicts. |
| 421 | */ |
| 422 | |
| 423 | netif_stop_queue(dev); |
| 424 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 425 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | int len = skb->len; |
| 427 | int pad = 0; |
| 428 | int gp_start; |
| 429 | unsigned char *buf = skb->data; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | if (len < ETH_ZLEN) |
| 432 | pad = ETH_ZLEN - len; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 433 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 434 | gp_start = 0x800 - (len + pad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | lp->tx_pkt_start = gp_start; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 437 | lp->collisions = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 439 | dev->stats.tx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | /* |
| 442 | * Command mode with status cleared should [in theory] |
| 443 | * mean no more interrupts can be pending on the card. |
| 444 | */ |
| 445 | |
| 446 | outb_p(AX_SYS, AX_CMD); |
| 447 | inb_p(RX_STATUS); |
| 448 | inb_p(TX_STATUS); |
| 449 | |
| 450 | lp->loading = 1; |
| 451 | lp->txing = 1; |
| 452 | |
| 453 | /* |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 454 | * Turn interrupts back on while we spend a pleasant |
| 455 | * afternoon loading bytes into the board |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | */ |
| 457 | |
| 458 | spin_unlock_irqrestore(&lp->lock, flags); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 459 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 460 | /* Set rx packet area to 0. */ |
| 461 | outw(0x00, RX_BUF_CLR); |
| 462 | /* aim - packet will be loaded into buffer start */ |
| 463 | outw(gp_start, GP_LOW); |
| 464 | /* load buffer (usual thing each byte increments the pointer) */ |
| 465 | outsb(DATAPORT, buf, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | if (pad) { |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 467 | while (pad--) /* Zero fill buffer tail */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | outb(0, DATAPORT); |
| 469 | } |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 470 | /* the board reuses the same register */ |
| 471 | outw(gp_start, GP_LOW); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 472 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 473 | if (lp->loading != 2) { |
| 474 | /* fire ... Trigger xmit. */ |
| 475 | outb(AX_XMIT, AX_CMD); |
| 476 | lp->loading = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | dev->trans_start = jiffies; |
| 478 | if (el_debug > 2) |
| 479 | printk(KERN_DEBUG " queued xmit.\n"); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 480 | dev_kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | return 0; |
| 482 | } |
| 483 | /* A receive upset our load, despite our best efforts */ |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 484 | if (el_debug > 2) |
| 485 | printk(KERN_DEBUG "%s: burped during tx load.\n", |
| 486 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | spin_lock_irqsave(&lp->lock, flags); |
Alan Cox | ad390d2d56 | 2008-03-10 21:57:20 +0000 | [diff] [blame] | 488 | } while (1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /** |
| 492 | * el_interrupt: |
| 493 | * @irq: Interrupt number |
| 494 | * @dev_id: The 3c501 that burped |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 496 | * Handle the ether interface interrupts. The 3c501 needs a lot more |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | * hand holding than most cards. In particular we get a transmit interrupt |
| 498 | * with a collision error because the board firmware isnt capable of rewinding |
| 499 | * its own transmit buffer pointers. It can however count to 16 for us. |
| 500 | * |
| 501 | * On the receive side the card is also very dumb. It has no buffering to |
| 502 | * speak of. We simply pull the packet out of its PIO buffer (which is slow) |
| 503 | * and queue it for the kernel. Then we reset the card for the next packet. |
| 504 | * |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 505 | * We sometimes get surprise interrupts late both because the SMP IRQ delivery |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | * is message passing and because the card sometimes seems to deliver late. I |
| 507 | * think if it is part way through a receive and the mode is changed it carries |
| 508 | * on receiving and sends us an interrupt. We have to band aid all these cases |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 509 | * to get a sensible 150kBytes/second performance. Even then you want a small |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | * TCP window. |
| 511 | */ |
| 512 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 513 | static irqreturn_t el_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | { |
| 515 | struct net_device *dev = dev_id; |
| 516 | struct net_local *lp; |
| 517 | int ioaddr; |
| 518 | int axsr; /* Aux. status reg. */ |
| 519 | |
| 520 | ioaddr = dev->base_addr; |
| 521 | lp = netdev_priv(dev); |
| 522 | |
| 523 | spin_lock(&lp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | /* |
| 526 | * What happened ? |
| 527 | */ |
| 528 | |
| 529 | axsr = inb(AX_STATUS); |
| 530 | |
| 531 | /* |
| 532 | * Log it |
| 533 | */ |
| 534 | |
| 535 | if (el_debug > 3) |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 536 | printk(KERN_DEBUG "%s: el_interrupt() aux=%#02x", |
| 537 | dev->name, axsr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 539 | if (lp->loading == 1 && !lp->txing) |
| 540 | printk(KERN_WARNING "%s: Inconsistent state loading while not in tx\n", |
| 541 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 543 | if (lp->txing) { |
| 544 | /* |
| 545 | * Board in transmit mode. May be loading. If we are |
| 546 | * loading we shouldn't have got this. |
| 547 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | int txsr = inb(TX_STATUS); |
| 549 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 550 | if (lp->loading == 1) { |
| 551 | if (el_debug > 2) { |
| 552 | printk(KERN_DEBUG "%s: Interrupt while loading [", |
| 553 | dev->name); |
| 554 | printk(" txsr=%02x gp=%04x rp=%04x]\n", |
| 555 | txsr, inw(GP_LOW), inw(RX_LOW)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 557 | /* Force a reload */ |
| 558 | lp->loading = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | spin_unlock(&lp->lock); |
| 560 | goto out; |
| 561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | if (el_debug > 6) |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 563 | printk(KERN_DEBUG " txsr=%02x gp=%04x rp=%04x", |
| 564 | txsr, inw(GP_LOW), inw(RX_LOW)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 566 | if ((axsr & 0x80) && (txsr & TX_READY) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | /* |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 568 | * FIXME: is there a logic to whether to keep |
| 569 | * on trying or reset immediately ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | */ |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 571 | if (el_debug > 1) |
| 572 | printk(KERN_DEBUG "%s: Unusual interrupt during Tx, txsr=%02x axsr=%02x gp=%03x rp=%03x.\n", |
| 573 | dev->name, txsr, axsr, |
| 574 | inw(ioaddr + EL1_DATAPTR), |
| 575 | inw(ioaddr + EL1_RXPTR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | lp->txing = 0; |
| 577 | netif_wake_queue(dev); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 578 | } else if (txsr & TX_16COLLISIONS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | /* |
| 580 | * Timed out |
| 581 | */ |
| 582 | if (el_debug) |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 583 | printk(KERN_DEBUG "%s: Transmit failed 16 times, Ethernet jammed?\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | outb(AX_SYS, AX_CMD); |
| 585 | lp->txing = 0; |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 586 | dev->stats.tx_aborted_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | netif_wake_queue(dev); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 588 | } else if (txsr & TX_COLLISION) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | /* |
| 590 | * Retrigger xmit. |
| 591 | */ |
| 592 | |
| 593 | if (el_debug > 6) |
| 594 | printk(KERN_DEBUG " retransmitting after a collision.\n"); |
| 595 | /* |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 596 | * Poor little chip can't reset its own start |
| 597 | * pointer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | */ |
| 599 | |
| 600 | outb(AX_SYS, AX_CMD); |
| 601 | outw(lp->tx_pkt_start, GP_LOW); |
| 602 | outb(AX_XMIT, AX_CMD); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 603 | dev->stats.collisions++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | spin_unlock(&lp->lock); |
| 605 | goto out; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 606 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | /* |
| 608 | * It worked.. we will now fall through and receive |
| 609 | */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 610 | dev->stats.tx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | if (el_debug > 6) |
| 612 | printk(KERN_DEBUG " Tx succeeded %s\n", |
Alan Cox | ad390d2d56 | 2008-03-10 21:57:20 +0000 | [diff] [blame] | 613 | (txsr & TX_RDY) ? "." : |
| 614 | "but tx is busy!"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | /* |
| 616 | * This is safe the interrupt is atomic WRT itself. |
| 617 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | lp->txing = 0; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 619 | /* In case more to transmit */ |
| 620 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 622 | } else { |
| 623 | /* |
| 624 | * In receive mode. |
| 625 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | int rxsr = inb(RX_STATUS); |
| 628 | if (el_debug > 5) |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 629 | printk(KERN_DEBUG " rxsr=%02x txsr=%02x rp=%04x", rxsr, inb(TX_STATUS), inw(RX_LOW)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | /* |
| 631 | * Just reading rx_status fixes most errors. |
| 632 | */ |
| 633 | if (rxsr & RX_MISSED) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 634 | dev->stats.rx_missed_errors++; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 635 | else if (rxsr & RX_RUNT) { |
| 636 | /* Handled to avoid board lock-up. */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 637 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | if (el_debug > 5) |
| 639 | printk(KERN_DEBUG " runt.\n"); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 640 | } else if (rxsr & RX_GOOD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | /* |
| 642 | * Receive worked. |
| 643 | */ |
| 644 | el_receive(dev); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 645 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | /* |
| 647 | * Nothing? Something is broken! |
| 648 | */ |
| 649 | if (el_debug > 2) |
| 650 | printk(KERN_DEBUG "%s: No packet seen, rxsr=%02x **resetting 3c501***\n", |
| 651 | dev->name, rxsr); |
| 652 | el_reset(dev); |
| 653 | } |
| 654 | if (el_debug > 3) |
| 655 | printk(KERN_DEBUG ".\n"); |
| 656 | } |
| 657 | |
| 658 | /* |
| 659 | * Move into receive mode |
| 660 | */ |
| 661 | |
| 662 | outb(AX_RX, AX_CMD); |
| 663 | outw(0x00, RX_BUF_CLR); |
| 664 | inb(RX_STATUS); /* Be certain that interrupts are cleared. */ |
| 665 | inb(TX_STATUS); |
| 666 | spin_unlock(&lp->lock); |
| 667 | out: |
| 668 | return IRQ_HANDLED; |
| 669 | } |
| 670 | |
| 671 | |
| 672 | /** |
| 673 | * el_receive: |
| 674 | * @dev: Device to pull the packets from |
| 675 | * |
| 676 | * We have a good packet. Well, not really "good", just mostly not broken. |
| 677 | * We must check everything to see if it is good. In particular we occasionally |
| 678 | * get wild packet sizes from the card. If the packet seems sane we PIO it |
| 679 | * off the card and queue it for the protocol layers. |
| 680 | */ |
| 681 | |
| 682 | static void el_receive(struct net_device *dev) |
| 683 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | int ioaddr = dev->base_addr; |
| 685 | int pkt_len; |
| 686 | struct sk_buff *skb; |
| 687 | |
| 688 | pkt_len = inw(RX_LOW); |
| 689 | |
| 690 | if (el_debug > 4) |
| 691 | printk(KERN_DEBUG " el_receive %d.\n", pkt_len); |
| 692 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 693 | if (pkt_len < 60 || pkt_len > 1536) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | if (el_debug) |
Alan Cox | ad390d2d56 | 2008-03-10 21:57:20 +0000 | [diff] [blame] | 695 | printk(KERN_DEBUG "%s: bogus packet, length=%d\n", |
| 696 | dev->name, pkt_len); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 697 | dev->stats.rx_over_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | return; |
| 699 | } |
| 700 | |
| 701 | /* |
| 702 | * Command mode so we can empty the buffer |
| 703 | */ |
| 704 | |
| 705 | outb(AX_SYS, AX_CMD); |
| 706 | skb = dev_alloc_skb(pkt_len+2); |
| 707 | |
| 708 | /* |
| 709 | * Start of frame |
| 710 | */ |
| 711 | |
| 712 | outw(0x00, GP_LOW); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 713 | if (skb == NULL) { |
Alan Cox | ad390d2d56 | 2008-03-10 21:57:20 +0000 | [diff] [blame] | 714 | printk(KERN_INFO "%s: Memory squeeze, dropping packet.\n", |
| 715 | dev->name); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 716 | dev->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | return; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 718 | } else { |
| 719 | skb_reserve(skb, 2); /* Force 16 byte alignment */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | /* |
| 721 | * The read increments through the bytes. The interrupt |
| 722 | * handler will fix the pointer when it returns to |
| 723 | * receive mode. |
| 724 | */ |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 725 | insb(DATAPORT, skb_put(skb, pkt_len), pkt_len); |
| 726 | skb->protocol = eth_type_trans(skb, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | netif_rx(skb); |
| 728 | dev->last_rx = jiffies; |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 729 | dev->stats.rx_packets++; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 730 | dev->stats.rx_bytes += pkt_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * el_reset: Reset a 3c501 card |
| 737 | * @dev: The 3c501 card about to get zapped |
| 738 | * |
| 739 | * Even resetting a 3c501 isnt simple. When you activate reset it loses all |
| 740 | * its configuration. You must hold the lock when doing this. The function |
| 741 | * cannot take the lock itself as it is callable from the irq handler. |
| 742 | */ |
| 743 | |
| 744 | static void el_reset(struct net_device *dev) |
| 745 | { |
| 746 | struct net_local *lp = netdev_priv(dev); |
| 747 | int ioaddr = dev->base_addr; |
| 748 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 749 | if (el_debug > 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | printk(KERN_INFO "3c501 reset..."); |
| 751 | outb(AX_RESET, AX_CMD); /* Reset the chip */ |
Alan Cox | ad390d2d56 | 2008-03-10 21:57:20 +0000 | [diff] [blame] | 752 | /* Aux control, irq and loopback enabled */ |
| 753 | outb(AX_LOOP, AX_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
| 755 | int i; |
| 756 | for (i = 0; i < 6; i++) /* Set the station address. */ |
| 757 | outb(dev->dev_addr[i], ioaddr + i); |
| 758 | } |
| 759 | |
| 760 | outw(0, RX_BUF_CLR); /* Set rx packet area to 0. */ |
| 761 | outb(TX_NORM, TX_CMD); /* tx irq on done, collision */ |
| 762 | outb(RX_NORM, RX_CMD); /* Set Rx commands. */ |
| 763 | inb(RX_STATUS); /* Clear status. */ |
| 764 | inb(TX_STATUS); |
| 765 | lp->txing = 0; |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * el1_close: |
| 770 | * @dev: 3c501 card to shut down |
| 771 | * |
| 772 | * Close a 3c501 card. The IFF_UP flag has been cleared by the user via |
| 773 | * the SIOCSIFFLAGS ioctl. We stop any further transmissions being queued, |
| 774 | * and then disable the interrupts. Finally we reset the chip. The effects |
| 775 | * of the rest will be cleaned up by #el1_open. Always returns 0 indicating |
| 776 | * a success. |
| 777 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | static int el1_close(struct net_device *dev) |
| 780 | { |
| 781 | int ioaddr = dev->base_addr; |
| 782 | |
| 783 | if (el_debug > 2) |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 784 | printk(KERN_INFO "%s: Shutting down Ethernet card at %#x.\n", |
| 785 | dev->name, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | netif_stop_queue(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | /* |
| 790 | * Free and disable the IRQ. |
| 791 | */ |
| 792 | |
| 793 | free_irq(dev->irq, dev); |
| 794 | outb(AX_RESET, AX_CMD); /* Reset the chip */ |
| 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | * set_multicast_list: |
| 801 | * @dev: The device to adjust |
| 802 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 803 | * Set or clear the multicast filter for this adaptor to use the best-effort |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | * filtering supported. The 3c501 supports only three modes of filtering. |
| 805 | * It always receives broadcasts and packets for itself. You can choose to |
| 806 | * optionally receive all packets, or all multicast packets on top of this. |
| 807 | */ |
| 808 | |
| 809 | static void set_multicast_list(struct net_device *dev) |
| 810 | { |
| 811 | int ioaddr = dev->base_addr; |
| 812 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 813 | if (dev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | outb(RX_PROM, RX_CMD); |
| 815 | inb(RX_STATUS); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 816 | } else if (dev->mc_list || dev->flags & IFF_ALLMULTI) { |
| 817 | /* Multicast or all multicast is the same */ |
| 818 | outb(RX_MULT, RX_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | inb(RX_STATUS); /* Clear status. */ |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 820 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | outb(RX_NORM, RX_CMD); |
| 822 | inb(RX_STATUS); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | |
| 827 | static void netdev_get_drvinfo(struct net_device *dev, |
| 828 | struct ethtool_drvinfo *info) |
| 829 | { |
| 830 | strcpy(info->driver, DRV_NAME); |
| 831 | strcpy(info->version, DRV_VERSION); |
| 832 | sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr); |
| 833 | } |
| 834 | |
| 835 | static u32 netdev_get_msglevel(struct net_device *dev) |
| 836 | { |
| 837 | return debug; |
| 838 | } |
| 839 | |
| 840 | static void netdev_set_msglevel(struct net_device *dev, u32 level) |
| 841 | { |
| 842 | debug = level; |
| 843 | } |
| 844 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 845 | static const struct ethtool_ops netdev_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | .get_drvinfo = netdev_get_drvinfo, |
| 847 | .get_msglevel = netdev_get_msglevel, |
| 848 | .set_msglevel = netdev_set_msglevel, |
| 849 | }; |
| 850 | |
| 851 | #ifdef MODULE |
| 852 | |
| 853 | static struct net_device *dev_3c501; |
| 854 | |
| 855 | module_param(io, int, 0); |
| 856 | module_param(irq, int, 0); |
| 857 | MODULE_PARM_DESC(io, "EtherLink I/O base address"); |
| 858 | MODULE_PARM_DESC(irq, "EtherLink IRQ number"); |
| 859 | |
| 860 | /** |
| 861 | * init_module: |
| 862 | * |
| 863 | * When the driver is loaded as a module this function is called. We fake up |
| 864 | * a device structure with the base I/O and interrupt set as if it were being |
| 865 | * called from Space.c. This minimises the extra code that would otherwise |
| 866 | * be required. |
| 867 | * |
| 868 | * Returns 0 for success or -EIO if a card is not found. Returning an error |
| 869 | * here also causes the module to be unloaded |
| 870 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 871 | |
Randy Dunlap | 96e672c | 2006-06-10 13:33:48 -0700 | [diff] [blame] | 872 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
| 874 | dev_3c501 = el1_probe(-1); |
| 875 | if (IS_ERR(dev_3c501)) |
| 876 | return PTR_ERR(dev_3c501); |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | /** |
| 881 | * cleanup_module: |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 882 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | * The module is being unloaded. We unhook our network device from the system |
| 884 | * and then free up the resources we took when the card was found. |
| 885 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 886 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 887 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
| 889 | struct net_device *dev = dev_3c501; |
| 890 | unregister_netdev(dev); |
| 891 | release_region(dev->base_addr, EL1_IO_EXTENT); |
| 892 | free_netdev(dev); |
| 893 | } |
| 894 | |
| 895 | #endif /* MODULE */ |
| 896 | |
| 897 | MODULE_AUTHOR("Donald Becker, Alan Cox"); |
| 898 | MODULE_DESCRIPTION("Support for the ancient 3Com 3c501 ethernet card"); |
| 899 | MODULE_LICENSE("GPL"); |
| 900 | |