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 | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 20 | Alan Cox <alan@lxorguk.ukuu.org.uk> |
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 | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 32 | 19950402 Alan Cox <alan@lxorguk.ukuu.org.uk> |
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 | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 35 | 20000208 Alan Cox <alan@lxorguk.ukuu.org.uk> |
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 | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 38 | 20021009 Alan Cox <alan@lxorguk.ukuu.org.uk> |
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 | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 41 | 20030104 Alan Cox <alan@lxorguk.ukuu.org.uk> |
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[] = |
Alan Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 107 | DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@lxorguk.ukuu.org.uk).\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Stephen Hemminger | 878f648 | 2009-01-09 13:01:11 +0000 | [diff] [blame] | 200 | static const struct net_device_ops el_netdev_ops = { |
| 201 | .ndo_open = el_open, |
| 202 | .ndo_stop = el1_close, |
| 203 | .ndo_start_xmit = el_start_xmit, |
| 204 | .ndo_tx_timeout = el_timeout, |
| 205 | .ndo_set_multicast_list = set_multicast_list, |
| 206 | .ndo_change_mtu = eth_change_mtu, |
| 207 | .ndo_set_mac_address = eth_mac_addr, |
| 208 | .ndo_validate_addr = eth_validate_addr, |
| 209 | }; |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /** |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 212 | * el1_probe1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | * @dev: The device structure to use |
| 214 | * @ioaddr: An I/O address to probe at. |
| 215 | * |
| 216 | * The actual probe. This is iterated over by #el1_probe in order to |
| 217 | * check all the applicable device locations. |
| 218 | * |
| 219 | * Returns 0 for a success, in which case the device is activated, |
| 220 | * EAGAIN if the IRQ is in use by another driver, and ENODEV if the |
| 221 | * board cannot be found. |
| 222 | */ |
| 223 | |
| 224 | static int __init el1_probe1(struct net_device *dev, int ioaddr) |
| 225 | { |
| 226 | struct net_local *lp; |
| 227 | const char *mname; /* Vendor name */ |
| 228 | unsigned char station_addr[6]; |
| 229 | int autoirq = 0; |
| 230 | int i; |
| 231 | |
| 232 | /* |
| 233 | * Reserve I/O resource for exclusive use by this driver |
| 234 | */ |
| 235 | |
| 236 | if (!request_region(ioaddr, EL1_IO_EXTENT, DRV_NAME)) |
| 237 | return -ENODEV; |
| 238 | |
| 239 | /* |
| 240 | * Read the station address PROM data from the special port. |
| 241 | */ |
| 242 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 243 | for (i = 0; i < 6; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | outw(i, ioaddr + EL1_DATAPTR); |
| 245 | station_addr[i] = inb(ioaddr + EL1_SAPROM); |
| 246 | } |
| 247 | /* |
| 248 | * Check the first three octets of the S.A. for 3Com's prefix, or |
| 249 | * for the Sager NP943 prefix. |
| 250 | */ |
| 251 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 252 | if (station_addr[0] == 0x02 && station_addr[1] == 0x60 && |
| 253 | station_addr[2] == 0x8c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | mname = "3c501"; |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 255 | else if (station_addr[0] == 0x00 && station_addr[1] == 0x80 && |
| 256 | station_addr[2] == 0xC8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | mname = "NP943"; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 258 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | release_region(ioaddr, EL1_IO_EXTENT); |
| 260 | return -ENODEV; |
| 261 | } |
| 262 | |
| 263 | /* |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 264 | * We auto-IRQ by shutting off the interrupt line and letting it |
| 265 | * float high. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | */ |
| 267 | |
| 268 | dev->irq = irq; |
| 269 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 270 | if (dev->irq < 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | unsigned long irq_mask; |
| 272 | |
| 273 | irq_mask = probe_irq_on(); |
| 274 | inb(RX_STATUS); /* Clear pending interrupts. */ |
| 275 | inb(TX_STATUS); |
| 276 | outb(AX_LOOP + 1, AX_CMD); |
| 277 | |
| 278 | outb(0x00, AX_CMD); |
| 279 | |
| 280 | mdelay(20); |
| 281 | autoirq = probe_irq_off(irq_mask); |
| 282 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 283 | if (autoirq == 0) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 284 | pr_warning("%s probe at %#x failed to detect IRQ line.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | mname, ioaddr); |
| 286 | release_region(ioaddr, EL1_IO_EXTENT); |
| 287 | return -EAGAIN; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | outb(AX_RESET+AX_LOOP, AX_CMD); /* Loopback mode. */ |
| 292 | dev->base_addr = ioaddr; |
| 293 | memcpy(dev->dev_addr, station_addr, ETH_ALEN); |
| 294 | |
| 295 | if (mem_start & 0xf) |
| 296 | el_debug = mem_start & 0x7; |
| 297 | if (autoirq) |
| 298 | dev->irq = autoirq; |
| 299 | |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 300 | pr_info("%s: %s EtherLink at %#lx, using %sIRQ %d.\n", |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 301 | dev->name, mname, dev->base_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | autoirq ? "auto":"assigned ", dev->irq); |
| 303 | |
| 304 | #ifdef CONFIG_IP_MULTICAST |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 305 | pr_warning("WARNING: Use of the 3c501 in a multicast kernel is NOT recommended.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | #endif |
| 307 | |
| 308 | if (el_debug) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 309 | pr_debug("%s", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | lp = netdev_priv(dev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 312 | memset(lp, 0, sizeof(struct net_local)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | spin_lock_init(&lp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /* |
| 316 | * The EL1-specific entries in the device structure. |
| 317 | */ |
| 318 | |
Stephen Hemminger | 878f648 | 2009-01-09 13:01:11 +0000 | [diff] [blame] | 319 | dev->netdev_ops = &el_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | dev->watchdog_timeo = HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | dev->ethtool_ops = &netdev_ethtool_ops; |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * el1_open: |
| 327 | * @dev: device that is being opened |
| 328 | * |
| 329 | * When an ifconfig is issued which changes the device flags to include |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 330 | * 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] | 331 | * occurs, not when the interface remains up. #el1_close will be called |
| 332 | * when it goes down. |
| 333 | * |
| 334 | * Returns 0 for a successful open, or -EAGAIN if someone has run off |
| 335 | * with our interrupt line. |
| 336 | */ |
| 337 | |
| 338 | static int el_open(struct net_device *dev) |
| 339 | { |
| 340 | int retval; |
| 341 | int ioaddr = dev->base_addr; |
| 342 | struct net_local *lp = netdev_priv(dev); |
| 343 | unsigned long flags; |
| 344 | |
| 345 | if (el_debug > 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 346 | pr_debug("%s: Doing el_open()...\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 348 | retval = request_irq(dev->irq, el_interrupt, 0, dev->name, dev); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 349 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | return retval; |
| 351 | |
| 352 | spin_lock_irqsave(&lp->lock, flags); |
| 353 | el_reset(dev); |
| 354 | spin_unlock_irqrestore(&lp->lock, flags); |
| 355 | |
| 356 | lp->txing = 0; /* Board in RX mode */ |
| 357 | outb(AX_RX, AX_CMD); /* Aux control, irq and receive enabled */ |
| 358 | netif_start_queue(dev); |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * el_timeout: |
| 364 | * @dev: The 3c501 card that has timed out |
| 365 | * |
| 366 | * Attempt to restart the board. This is basically a mixture of extreme |
| 367 | * violence and prayer |
| 368 | * |
| 369 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | static void el_timeout(struct net_device *dev) |
| 372 | { |
| 373 | struct net_local *lp = netdev_priv(dev); |
| 374 | int ioaddr = dev->base_addr; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | if (el_debug) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 377 | pr_debug("%s: transmit timed out, txsr %#2x axsr=%02x rxsr=%02x.\n", |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 378 | dev->name, inb(TX_STATUS), |
| 379 | inb(AX_STATUS), inb(RX_STATUS)); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 380 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | outb(TX_NORM, TX_CMD); |
| 382 | outb(RX_NORM, RX_CMD); |
| 383 | outb(AX_OFF, AX_CMD); /* Just trigger a false interrupt. */ |
| 384 | outb(AX_RX, AX_CMD); /* Aux control, irq and receive enabled */ |
| 385 | lp->txing = 0; /* Ripped back in to RX */ |
| 386 | netif_wake_queue(dev); |
| 387 | } |
| 388 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | /** |
| 391 | * el_start_xmit: |
| 392 | * @skb: The packet that is queued to be sent |
| 393 | * @dev: The 3c501 card we want to throw it down |
| 394 | * |
| 395 | * Attempt to send a packet to a 3c501 card. There are some interesting |
| 396 | * catches here because the 3c501 is an extremely old and therefore |
| 397 | * stupid piece of technology. |
| 398 | * |
| 399 | * If we are handling an interrupt on the other CPU we cannot load a packet |
| 400 | * as we may still be attempting to retrieve the last RX packet buffer. |
| 401 | * |
| 402 | * When a transmit times out we dump the card into control mode and just |
| 403 | * start again. It happens enough that it isnt worth logging. |
| 404 | * |
| 405 | * We avoid holding the spin locks when doing the packet load to the board. |
| 406 | * The device is very slow, and its DMA mode is even slower. If we held the |
| 407 | * lock while loading 1500 bytes onto the controller we would drop a lot of |
| 408 | * serial port characters. This requires we do extra locking, but we have |
| 409 | * no real choice. |
| 410 | */ |
| 411 | |
Stephen Hemminger | 27a1de9 | 2009-08-31 19:50:54 +0000 | [diff] [blame] | 412 | static netdev_tx_t el_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
| 414 | struct net_local *lp = netdev_priv(dev); |
| 415 | int ioaddr = dev->base_addr; |
| 416 | unsigned long flags; |
| 417 | |
| 418 | /* |
| 419 | * Avoid incoming interrupts between us flipping txing and flipping |
| 420 | * mode as the driver assumes txing is a faithful indicator of card |
| 421 | * state |
| 422 | */ |
| 423 | |
| 424 | spin_lock_irqsave(&lp->lock, flags); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | /* |
| 427 | * Avoid timer-based retransmission conflicts. |
| 428 | */ |
| 429 | |
| 430 | netif_stop_queue(dev); |
| 431 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 432 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | int len = skb->len; |
| 434 | int pad = 0; |
| 435 | int gp_start; |
| 436 | unsigned char *buf = skb->data; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | if (len < ETH_ZLEN) |
| 439 | pad = ETH_ZLEN - len; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 440 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 441 | gp_start = 0x800 - (len + pad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | lp->tx_pkt_start = gp_start; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 444 | lp->collisions = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 446 | dev->stats.tx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | /* |
| 449 | * Command mode with status cleared should [in theory] |
| 450 | * mean no more interrupts can be pending on the card. |
| 451 | */ |
| 452 | |
| 453 | outb_p(AX_SYS, AX_CMD); |
| 454 | inb_p(RX_STATUS); |
| 455 | inb_p(TX_STATUS); |
| 456 | |
| 457 | lp->loading = 1; |
| 458 | lp->txing = 1; |
| 459 | |
| 460 | /* |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 461 | * Turn interrupts back on while we spend a pleasant |
| 462 | * afternoon loading bytes into the board |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | */ |
| 464 | |
| 465 | spin_unlock_irqrestore(&lp->lock, flags); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 466 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 467 | /* Set rx packet area to 0. */ |
| 468 | outw(0x00, RX_BUF_CLR); |
| 469 | /* aim - packet will be loaded into buffer start */ |
| 470 | outw(gp_start, GP_LOW); |
| 471 | /* load buffer (usual thing each byte increments the pointer) */ |
| 472 | outsb(DATAPORT, buf, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | if (pad) { |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 474 | while (pad--) /* Zero fill buffer tail */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | outb(0, DATAPORT); |
| 476 | } |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 477 | /* the board reuses the same register */ |
| 478 | outw(gp_start, GP_LOW); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 479 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 480 | if (lp->loading != 2) { |
| 481 | /* fire ... Trigger xmit. */ |
| 482 | outb(AX_XMIT, AX_CMD); |
| 483 | lp->loading = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | dev->trans_start = jiffies; |
| 485 | if (el_debug > 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 486 | pr_debug(" queued xmit.\n"); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 487 | dev_kfree_skb(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 488 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | /* A receive upset our load, despite our best efforts */ |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 491 | if (el_debug > 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 492 | pr_debug("%s: burped during tx load.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | spin_lock_irqsave(&lp->lock, flags); |
Alan Cox | ad390d2 | 2008-03-10 21:57:20 +0000 | [diff] [blame] | 494 | } while (1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /** |
| 498 | * el_interrupt: |
| 499 | * @irq: Interrupt number |
| 500 | * @dev_id: The 3c501 that burped |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 502 | * Handle the ether interface interrupts. The 3c501 needs a lot more |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | * hand holding than most cards. In particular we get a transmit interrupt |
| 504 | * with a collision error because the board firmware isnt capable of rewinding |
| 505 | * its own transmit buffer pointers. It can however count to 16 for us. |
| 506 | * |
| 507 | * On the receive side the card is also very dumb. It has no buffering to |
| 508 | * speak of. We simply pull the packet out of its PIO buffer (which is slow) |
| 509 | * and queue it for the kernel. Then we reset the card for the next packet. |
| 510 | * |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 511 | * We sometimes get surprise interrupts late both because the SMP IRQ delivery |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | * is message passing and because the card sometimes seems to deliver late. I |
| 513 | * think if it is part way through a receive and the mode is changed it carries |
| 514 | * 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] | 515 | * 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] | 516 | * TCP window. |
| 517 | */ |
| 518 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 519 | static irqreturn_t el_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
| 521 | struct net_device *dev = dev_id; |
| 522 | struct net_local *lp; |
| 523 | int ioaddr; |
| 524 | int axsr; /* Aux. status reg. */ |
| 525 | |
| 526 | ioaddr = dev->base_addr; |
| 527 | lp = netdev_priv(dev); |
| 528 | |
| 529 | spin_lock(&lp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | /* |
| 532 | * What happened ? |
| 533 | */ |
| 534 | |
| 535 | axsr = inb(AX_STATUS); |
| 536 | |
| 537 | /* |
| 538 | * Log it |
| 539 | */ |
| 540 | |
| 541 | if (el_debug > 3) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 542 | pr_debug("%s: el_interrupt() aux=%#02x\n", dev->name, axsr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 544 | if (lp->loading == 1 && !lp->txing) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 545 | pr_warning("%s: Inconsistent state loading while not in tx\n", |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 546 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 548 | if (lp->txing) { |
| 549 | /* |
| 550 | * Board in transmit mode. May be loading. If we are |
| 551 | * loading we shouldn't have got this. |
| 552 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | int txsr = inb(TX_STATUS); |
| 554 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 555 | if (lp->loading == 1) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 556 | if (el_debug > 2) |
| 557 | pr_debug("%s: Interrupt while loading [txsr=%02x gp=%04x rp=%04x]\n", |
| 558 | dev->name, txsr, inw(GP_LOW), inw(RX_LOW)); |
| 559 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 560 | /* Force a reload */ |
| 561 | lp->loading = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | spin_unlock(&lp->lock); |
| 563 | goto out; |
| 564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | if (el_debug > 6) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 566 | pr_debug("%s: txsr=%02x gp=%04x rp=%04x\n", dev->name, |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 567 | txsr, inw(GP_LOW), inw(RX_LOW)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 569 | if ((axsr & 0x80) && (txsr & TX_READY) == 0) { |
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 | * FIXME: is there a logic to whether to keep |
| 572 | * on trying or reset immediately ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | */ |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 574 | if (el_debug > 1) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 575 | pr_debug("%s: Unusual interrupt during Tx, txsr=%02x axsr=%02x gp=%03x rp=%03x.\n", |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 576 | dev->name, txsr, axsr, |
| 577 | inw(ioaddr + EL1_DATAPTR), |
| 578 | inw(ioaddr + EL1_RXPTR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | lp->txing = 0; |
| 580 | netif_wake_queue(dev); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 581 | } else if (txsr & TX_16COLLISIONS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* |
| 583 | * Timed out |
| 584 | */ |
| 585 | if (el_debug) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 586 | pr_debug("%s: Transmit failed 16 times, Ethernet jammed?\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | outb(AX_SYS, AX_CMD); |
| 588 | lp->txing = 0; |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 589 | dev->stats.tx_aborted_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | netif_wake_queue(dev); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 591 | } else if (txsr & TX_COLLISION) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | /* |
| 593 | * Retrigger xmit. |
| 594 | */ |
| 595 | |
| 596 | if (el_debug > 6) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 597 | pr_debug("%s: retransmitting after a collision.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | /* |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 599 | * Poor little chip can't reset its own start |
| 600 | * pointer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | */ |
| 602 | |
| 603 | outb(AX_SYS, AX_CMD); |
| 604 | outw(lp->tx_pkt_start, GP_LOW); |
| 605 | outb(AX_XMIT, AX_CMD); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 606 | dev->stats.collisions++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | spin_unlock(&lp->lock); |
| 608 | goto out; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 609 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | /* |
| 611 | * It worked.. we will now fall through and receive |
| 612 | */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 613 | dev->stats.tx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | if (el_debug > 6) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 615 | pr_debug("%s: Tx succeeded %s\n", dev->name, |
| 616 | (txsr & TX_RDY) ? "." : "but tx is busy!"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* |
| 618 | * This is safe the interrupt is atomic WRT itself. |
| 619 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | lp->txing = 0; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 621 | /* In case more to transmit */ |
| 622 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 624 | } else { |
| 625 | /* |
| 626 | * In receive mode. |
| 627 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
| 629 | int rxsr = inb(RX_STATUS); |
| 630 | if (el_debug > 5) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 631 | pr_debug("%s: rxsr=%02x txsr=%02x rp=%04x\n", |
| 632 | dev->name, rxsr, inb(TX_STATUS), inw(RX_LOW)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | /* |
| 634 | * Just reading rx_status fixes most errors. |
| 635 | */ |
| 636 | if (rxsr & RX_MISSED) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 637 | dev->stats.rx_missed_errors++; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 638 | else if (rxsr & RX_RUNT) { |
| 639 | /* Handled to avoid board lock-up. */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 640 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | if (el_debug > 5) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 642 | pr_debug("%s: runt.\n", dev->name); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 643 | } else if (rxsr & RX_GOOD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | /* |
| 645 | * Receive worked. |
| 646 | */ |
| 647 | el_receive(dev); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 648 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | /* |
| 650 | * Nothing? Something is broken! |
| 651 | */ |
| 652 | if (el_debug > 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 653 | pr_debug("%s: No packet seen, rxsr=%02x **resetting 3c501***\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | dev->name, rxsr); |
| 655 | el_reset(dev); |
| 656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | /* |
| 660 | * Move into receive mode |
| 661 | */ |
| 662 | |
| 663 | outb(AX_RX, AX_CMD); |
| 664 | outw(0x00, RX_BUF_CLR); |
| 665 | inb(RX_STATUS); /* Be certain that interrupts are cleared. */ |
| 666 | inb(TX_STATUS); |
| 667 | spin_unlock(&lp->lock); |
| 668 | out: |
| 669 | return IRQ_HANDLED; |
| 670 | } |
| 671 | |
| 672 | |
| 673 | /** |
| 674 | * el_receive: |
| 675 | * @dev: Device to pull the packets from |
| 676 | * |
| 677 | * We have a good packet. Well, not really "good", just mostly not broken. |
| 678 | * We must check everything to see if it is good. In particular we occasionally |
| 679 | * get wild packet sizes from the card. If the packet seems sane we PIO it |
| 680 | * off the card and queue it for the protocol layers. |
| 681 | */ |
| 682 | |
| 683 | static void el_receive(struct net_device *dev) |
| 684 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | int ioaddr = dev->base_addr; |
| 686 | int pkt_len; |
| 687 | struct sk_buff *skb; |
| 688 | |
| 689 | pkt_len = inw(RX_LOW); |
| 690 | |
| 691 | if (el_debug > 4) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 692 | pr_debug(" el_receive %d.\n", pkt_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 694 | if (pkt_len < 60 || pkt_len > 1536) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | if (el_debug) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 696 | pr_debug("%s: bogus packet, length=%d\n", |
Alan Cox | ad390d2 | 2008-03-10 21:57:20 +0000 | [diff] [blame] | 697 | dev->name, pkt_len); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 698 | dev->stats.rx_over_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | return; |
| 700 | } |
| 701 | |
| 702 | /* |
| 703 | * Command mode so we can empty the buffer |
| 704 | */ |
| 705 | |
| 706 | outb(AX_SYS, AX_CMD); |
| 707 | skb = dev_alloc_skb(pkt_len+2); |
| 708 | |
| 709 | /* |
| 710 | * Start of frame |
| 711 | */ |
| 712 | |
| 713 | outw(0x00, GP_LOW); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 714 | if (skb == NULL) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 715 | pr_info("%s: Memory squeeze, dropping packet.\n", 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); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 728 | dev->stats.rx_packets++; |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 729 | dev->stats.rx_bytes += pkt_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * el_reset: Reset a 3c501 card |
| 736 | * @dev: The 3c501 card about to get zapped |
| 737 | * |
| 738 | * Even resetting a 3c501 isnt simple. When you activate reset it loses all |
| 739 | * its configuration. You must hold the lock when doing this. The function |
| 740 | * cannot take the lock itself as it is callable from the irq handler. |
| 741 | */ |
| 742 | |
| 743 | static void el_reset(struct net_device *dev) |
| 744 | { |
| 745 | struct net_local *lp = netdev_priv(dev); |
| 746 | int ioaddr = dev->base_addr; |
| 747 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 748 | if (el_debug > 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 749 | pr_info("3c501 reset...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | outb(AX_RESET, AX_CMD); /* Reset the chip */ |
Alan Cox | ad390d2 | 2008-03-10 21:57:20 +0000 | [diff] [blame] | 751 | /* Aux control, irq and loopback enabled */ |
| 752 | outb(AX_LOOP, AX_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | { |
| 754 | int i; |
| 755 | for (i = 0; i < 6; i++) /* Set the station address. */ |
| 756 | outb(dev->dev_addr[i], ioaddr + i); |
| 757 | } |
| 758 | |
| 759 | outw(0, RX_BUF_CLR); /* Set rx packet area to 0. */ |
| 760 | outb(TX_NORM, TX_CMD); /* tx irq on done, collision */ |
| 761 | outb(RX_NORM, RX_CMD); /* Set Rx commands. */ |
| 762 | inb(RX_STATUS); /* Clear status. */ |
| 763 | inb(TX_STATUS); |
| 764 | lp->txing = 0; |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * el1_close: |
| 769 | * @dev: 3c501 card to shut down |
| 770 | * |
| 771 | * Close a 3c501 card. The IFF_UP flag has been cleared by the user via |
| 772 | * the SIOCSIFFLAGS ioctl. We stop any further transmissions being queued, |
| 773 | * and then disable the interrupts. Finally we reset the chip. The effects |
| 774 | * of the rest will be cleaned up by #el1_open. Always returns 0 indicating |
| 775 | * a success. |
| 776 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | static int el1_close(struct net_device *dev) |
| 779 | { |
| 780 | int ioaddr = dev->base_addr; |
| 781 | |
| 782 | if (el_debug > 2) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 783 | pr_info("%s: Shutting down Ethernet card at %#x.\n", |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 784 | dev->name, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | netif_stop_queue(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | /* |
| 789 | * Free and disable the IRQ. |
| 790 | */ |
| 791 | |
| 792 | free_irq(dev->irq, dev); |
| 793 | outb(AX_RESET, AX_CMD); /* Reset the chip */ |
| 794 | |
| 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | * set_multicast_list: |
| 800 | * @dev: The device to adjust |
| 801 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 802 | * 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] | 803 | * filtering supported. The 3c501 supports only three modes of filtering. |
| 804 | * It always receives broadcasts and packets for itself. You can choose to |
| 805 | * optionally receive all packets, or all multicast packets on top of this. |
| 806 | */ |
| 807 | |
| 808 | static void set_multicast_list(struct net_device *dev) |
| 809 | { |
| 810 | int ioaddr = dev->base_addr; |
| 811 | |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 812 | if (dev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | outb(RX_PROM, RX_CMD); |
| 814 | inb(RX_STATUS); |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 815 | } else if (dev->mc_list || dev->flags & IFF_ALLMULTI) { |
| 816 | /* Multicast or all multicast is the same */ |
| 817 | outb(RX_MULT, RX_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | inb(RX_STATUS); /* Clear status. */ |
Alan Cox | a35f5de | 2007-11-19 15:02:32 +0000 | [diff] [blame] | 819 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | outb(RX_NORM, RX_CMD); |
| 821 | inb(RX_STATUS); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | |
| 826 | static void netdev_get_drvinfo(struct net_device *dev, |
| 827 | struct ethtool_drvinfo *info) |
| 828 | { |
| 829 | strcpy(info->driver, DRV_NAME); |
| 830 | strcpy(info->version, DRV_VERSION); |
| 831 | sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr); |
| 832 | } |
| 833 | |
| 834 | static u32 netdev_get_msglevel(struct net_device *dev) |
| 835 | { |
| 836 | return debug; |
| 837 | } |
| 838 | |
| 839 | static void netdev_set_msglevel(struct net_device *dev, u32 level) |
| 840 | { |
| 841 | debug = level; |
| 842 | } |
| 843 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 844 | static const struct ethtool_ops netdev_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | .get_drvinfo = netdev_get_drvinfo, |
| 846 | .get_msglevel = netdev_get_msglevel, |
| 847 | .set_msglevel = netdev_set_msglevel, |
| 848 | }; |
| 849 | |
| 850 | #ifdef MODULE |
| 851 | |
| 852 | static struct net_device *dev_3c501; |
| 853 | |
| 854 | module_param(io, int, 0); |
| 855 | module_param(irq, int, 0); |
| 856 | MODULE_PARM_DESC(io, "EtherLink I/O base address"); |
| 857 | MODULE_PARM_DESC(irq, "EtherLink IRQ number"); |
| 858 | |
| 859 | /** |
| 860 | * init_module: |
| 861 | * |
| 862 | * When the driver is loaded as a module this function is called. We fake up |
| 863 | * a device structure with the base I/O and interrupt set as if it were being |
| 864 | * called from Space.c. This minimises the extra code that would otherwise |
| 865 | * be required. |
| 866 | * |
| 867 | * Returns 0 for success or -EIO if a card is not found. Returning an error |
| 868 | * here also causes the module to be unloaded |
| 869 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 870 | |
Randy Dunlap | 96e672c | 2006-06-10 13:33:48 -0700 | [diff] [blame] | 871 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | { |
| 873 | dev_3c501 = el1_probe(-1); |
| 874 | if (IS_ERR(dev_3c501)) |
| 875 | return PTR_ERR(dev_3c501); |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * cleanup_module: |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 881 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | * The module is being unloaded. We unhook our network device from the system |
| 883 | * and then free up the resources we took when the card was found. |
| 884 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 885 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 886 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | { |
| 888 | struct net_device *dev = dev_3c501; |
| 889 | unregister_netdev(dev); |
| 890 | release_region(dev->base_addr, EL1_IO_EXTENT); |
| 891 | free_netdev(dev); |
| 892 | } |
| 893 | |
| 894 | #endif /* MODULE */ |
| 895 | |
| 896 | MODULE_AUTHOR("Donald Becker, Alan Cox"); |
| 897 | MODULE_DESCRIPTION("Support for the ancient 3Com 3c501 ethernet card"); |
| 898 | MODULE_LICENSE("GPL"); |
| 899 | |