Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* 3c503.c: A shared-memory NS8390 ethernet driver for linux. */ |
| 2 | /* |
| 3 | Written 1992-94 by 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 | The author may be reached as becker@scyld.com, or C/O |
| 11 | Scyld Computing Corporation |
| 12 | 410 Severn Ave., Suite 210 |
| 13 | Annapolis MD 21403 |
| 14 | |
| 15 | |
| 16 | This driver should work with the 3c503 and 3c503/16. It should be used |
| 17 | in shared memory mode for best performance, although it may also work |
| 18 | in programmed-I/O mode. |
| 19 | |
| 20 | Sources: |
| 21 | EtherLink II Technical Reference Manual, |
| 22 | EtherLink II/16 Technical Reference Manual Supplement, |
| 23 | 3Com Corporation, 5400 Bayfront Plaza, Santa Clara CA 95052-8145 |
| 24 | |
| 25 | The Crynwr 3c503 packet driver. |
| 26 | |
| 27 | Changelog: |
| 28 | |
| 29 | Paul Gortmaker : add support for the 2nd 8kB of RAM on 16 bit cards. |
| 30 | Paul Gortmaker : multiple card support for module users. |
| 31 | rjohnson@analogic.com : Fix up PIO interface for efficient operation. |
| 32 | Jeff Garzik : ethtool support |
| 33 | |
| 34 | */ |
| 35 | |
| 36 | #define DRV_NAME "3c503" |
| 37 | #define DRV_VERSION "1.10a" |
| 38 | #define DRV_RELDATE "11/17/2001" |
| 39 | |
| 40 | |
| 41 | static const char version[] = |
| 42 | DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Donald Becker (becker@scyld.com)\n"; |
| 43 | |
| 44 | #include <linux/module.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/errno.h> |
| 47 | #include <linux/string.h> |
| 48 | #include <linux/delay.h> |
| 49 | #include <linux/netdevice.h> |
| 50 | #include <linux/etherdevice.h> |
| 51 | #include <linux/init.h> |
| 52 | #include <linux/ethtool.h> |
| 53 | |
| 54 | #include <asm/uaccess.h> |
| 55 | #include <asm/io.h> |
| 56 | #include <asm/system.h> |
| 57 | #include <asm/byteorder.h> |
| 58 | |
| 59 | #include "8390.h" |
| 60 | #include "3c503.h" |
| 61 | #define WRD_COUNT 4 |
| 62 | |
| 63 | static int el2_pio_probe(struct net_device *dev); |
| 64 | static int el2_probe1(struct net_device *dev, int ioaddr); |
| 65 | |
| 66 | /* A zero-terminated list of I/O addresses to be probed in PIO mode. */ |
| 67 | static unsigned int netcard_portlist[] __initdata = |
| 68 | { 0x300,0x310,0x330,0x350,0x250,0x280,0x2a0,0x2e0,0}; |
| 69 | |
| 70 | #define EL2_IO_EXTENT 16 |
| 71 | |
| 72 | static int el2_open(struct net_device *dev); |
| 73 | static int el2_close(struct net_device *dev); |
| 74 | static void el2_reset_8390(struct net_device *dev); |
| 75 | static void el2_init_card(struct net_device *dev); |
| 76 | static void el2_block_output(struct net_device *dev, int count, |
| 77 | const unsigned char *buf, int start_page); |
| 78 | static void el2_block_input(struct net_device *dev, int count, struct sk_buff *skb, |
| 79 | int ring_offset); |
| 80 | static void el2_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, |
| 81 | int ring_page); |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 82 | static const struct ethtool_ops netdev_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* This routine probes for a memory-mapped 3c503 board by looking for |
| 86 | the "location register" at the end of the jumpered boot PROM space. |
| 87 | This works even if a PROM isn't there. |
| 88 | |
| 89 | If the ethercard isn't found there is an optional probe for |
| 90 | ethercard jumpered to programmed-I/O mode. |
| 91 | */ |
| 92 | static int __init do_el2_probe(struct net_device *dev) |
| 93 | { |
| 94 | int *addr, addrs[] = { 0xddffe, 0xd9ffe, 0xcdffe, 0xc9ffe, 0}; |
| 95 | int base_addr = dev->base_addr; |
| 96 | int irq = dev->irq; |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | if (base_addr > 0x1ff) /* Check a single specified location. */ |
| 99 | return el2_probe1(dev, base_addr); |
| 100 | else if (base_addr != 0) /* Don't probe at all. */ |
| 101 | return -ENXIO; |
| 102 | |
| 103 | for (addr = addrs; *addr; addr++) { |
| 104 | void __iomem *p = ioremap(*addr, 1); |
| 105 | unsigned base_bits; |
| 106 | int i; |
| 107 | |
| 108 | if (!p) |
| 109 | continue; |
| 110 | base_bits = readb(p); |
| 111 | iounmap(p); |
| 112 | i = ffs(base_bits) - 1; |
| 113 | if (i == -1 || base_bits != (1 << i)) |
| 114 | continue; |
| 115 | if (el2_probe1(dev, netcard_portlist[i]) == 0) |
| 116 | return 0; |
| 117 | dev->irq = irq; |
| 118 | } |
| 119 | #if ! defined(no_probe_nonshared_memory) |
| 120 | return el2_pio_probe(dev); |
| 121 | #else |
| 122 | return -ENODEV; |
| 123 | #endif |
| 124 | } |
| 125 | |
| 126 | /* Try all of the locations that aren't obviously empty. This touches |
| 127 | a lot of locations, and is much riskier than the code above. */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 128 | static int __init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | el2_pio_probe(struct net_device *dev) |
| 130 | { |
| 131 | int i; |
| 132 | int base_addr = dev->base_addr; |
| 133 | int irq = dev->irq; |
| 134 | |
| 135 | if (base_addr > 0x1ff) /* Check a single specified location. */ |
| 136 | return el2_probe1(dev, base_addr); |
| 137 | else if (base_addr != 0) /* Don't probe at all. */ |
| 138 | return -ENXIO; |
| 139 | |
| 140 | for (i = 0; netcard_portlist[i]; i++) { |
| 141 | if (el2_probe1(dev, netcard_portlist[i]) == 0) |
| 142 | return 0; |
| 143 | dev->irq = irq; |
| 144 | } |
| 145 | |
| 146 | return -ENODEV; |
| 147 | } |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #ifndef MODULE |
| 150 | struct net_device * __init el2_probe(int unit) |
| 151 | { |
Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 152 | struct net_device *dev = alloc_eip_netdev(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | int err; |
| 154 | |
| 155 | if (!dev) |
| 156 | return ERR_PTR(-ENOMEM); |
| 157 | |
| 158 | sprintf(dev->name, "eth%d", unit); |
| 159 | netdev_boot_setup_check(dev); |
| 160 | |
| 161 | err = do_el2_probe(dev); |
| 162 | if (err) |
| 163 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | return dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | out: |
| 166 | free_netdev(dev); |
| 167 | return ERR_PTR(err); |
| 168 | } |
| 169 | #endif |
| 170 | |
Stephen Hemminger | 53cdd28 | 2008-11-25 18:26:20 -0800 | [diff] [blame] | 171 | static const struct net_device_ops el2_netdev_ops = { |
| 172 | .ndo_open = el2_open, |
| 173 | .ndo_stop = el2_close, |
| 174 | |
| 175 | .ndo_start_xmit = eip_start_xmit, |
| 176 | .ndo_tx_timeout = eip_tx_timeout, |
| 177 | .ndo_get_stats = eip_get_stats, |
| 178 | .ndo_set_multicast_list = eip_set_multicast_list, |
| 179 | .ndo_validate_addr = eth_validate_addr, |
Stephen Hemminger | fe96aaa | 2009-01-09 11:13:14 +0000 | [diff] [blame] | 180 | .ndo_set_mac_address = eth_mac_addr, |
Stephen Hemminger | 53cdd28 | 2008-11-25 18:26:20 -0800 | [diff] [blame] | 181 | .ndo_change_mtu = eth_change_mtu, |
| 182 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 183 | .ndo_poll_controller = eip_poll, |
| 184 | #endif |
| 185 | }; |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | /* Probe for the Etherlink II card at I/O port base IOADDR, |
| 188 | returning non-zero on success. If found, set the station |
| 189 | address and memory parameters in DEVICE. */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 190 | static int __init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | el2_probe1(struct net_device *dev, int ioaddr) |
| 192 | { |
| 193 | int i, iobase_reg, membase_reg, saved_406, wordlength, retval; |
| 194 | static unsigned version_printed; |
| 195 | unsigned long vendor_id; |
| 196 | |
| 197 | if (!request_region(ioaddr, EL2_IO_EXTENT, DRV_NAME)) |
| 198 | return -EBUSY; |
| 199 | |
| 200 | if (!request_region(ioaddr + 0x400, 8, DRV_NAME)) { |
| 201 | retval = -EBUSY; |
| 202 | goto out; |
| 203 | } |
| 204 | |
| 205 | /* Reset and/or avoid any lurking NE2000 */ |
| 206 | if (inb(ioaddr + 0x408) == 0xff) { |
| 207 | mdelay(1); |
| 208 | retval = -ENODEV; |
| 209 | goto out1; |
| 210 | } |
| 211 | |
| 212 | /* We verify that it's a 3C503 board by checking the first three octets |
| 213 | of its ethernet address. */ |
| 214 | iobase_reg = inb(ioaddr+0x403); |
| 215 | membase_reg = inb(ioaddr+0x404); |
| 216 | /* ASIC location registers should be 0 or have only a single bit set. */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 217 | if ((iobase_reg & (iobase_reg - 1)) || |
| 218 | (membase_reg & (membase_reg - 1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | retval = -ENODEV; |
| 220 | goto out1; |
| 221 | } |
| 222 | saved_406 = inb_p(ioaddr + 0x406); |
| 223 | outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406); /* Reset it... */ |
| 224 | outb_p(ECNTRL_THIN, ioaddr + 0x406); |
| 225 | /* Map the station addr PROM into the lower I/O ports. We now check |
| 226 | for both the old and new 3Com prefix */ |
| 227 | outb(ECNTRL_SAPROM|ECNTRL_THIN, ioaddr + 0x406); |
| 228 | vendor_id = inb(ioaddr)*0x10000 + inb(ioaddr + 1)*0x100 + inb(ioaddr + 2); |
| 229 | if ((vendor_id != OLD_3COM_ID) && (vendor_id != NEW_3COM_ID)) { |
| 230 | /* Restore the register we frobbed. */ |
| 231 | outb(saved_406, ioaddr + 0x406); |
| 232 | retval = -ENODEV; |
| 233 | goto out1; |
| 234 | } |
| 235 | |
| 236 | if (ei_debug && version_printed++ == 0) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 237 | pr_debug("%s", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | dev->base_addr = ioaddr; |
| 240 | |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 241 | pr_info("%s: 3c503 at i/o base %#3x, node ", dev->name, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | /* Retrieve and print the ethernet address. */ |
| 244 | for (i = 0; i < 6; i++) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 245 | dev->dev_addr[i] = inb(ioaddr + i); |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 246 | pr_cont("%pM", dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | /* Map the 8390 back into the window. */ |
| 249 | outb(ECNTRL_THIN, ioaddr + 0x406); |
| 250 | |
| 251 | /* Check for EL2/16 as described in tech. man. */ |
| 252 | outb_p(E8390_PAGE0, ioaddr + E8390_CMD); |
| 253 | outb_p(0, ioaddr + EN0_DCFG); |
| 254 | outb_p(E8390_PAGE2, ioaddr + E8390_CMD); |
| 255 | wordlength = inb_p(ioaddr + EN0_DCFG) & ENDCFG_WTS; |
| 256 | outb_p(E8390_PAGE0, ioaddr + E8390_CMD); |
| 257 | |
| 258 | /* Probe for, turn on and clear the board's shared memory. */ |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 259 | if (ei_debug > 2) |
| 260 | pr_cont(" memory jumpers %2.2x ", membase_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | outb(EGACFR_NORM, ioaddr + 0x405); /* Enable RAM */ |
| 262 | |
| 263 | /* This should be probed for (or set via an ioctl()) at run-time. |
| 264 | Right now we use a sleazy hack to pass in the interface number |
| 265 | at boot-time via the low bits of the mem_end field. That value is |
| 266 | unused, and the low bits would be discarded even if it was used. */ |
| 267 | #if defined(EI8390_THICK) || defined(EL2_AUI) |
| 268 | ei_status.interface_num = 1; |
| 269 | #else |
| 270 | ei_status.interface_num = dev->mem_end & 0xf; |
| 271 | #endif |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 272 | pr_cont(", using %sternal xcvr.\n", ei_status.interface_num == 0 ? "in" : "ex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | if ((membase_reg & 0xf0) == 0) { |
| 275 | dev->mem_start = 0; |
| 276 | ei_status.name = "3c503-PIO"; |
| 277 | ei_status.mem = NULL; |
| 278 | } else { |
| 279 | dev->mem_start = ((membase_reg & 0xc0) ? 0xD8000 : 0xC8000) + |
| 280 | ((membase_reg & 0xA0) ? 0x4000 : 0); |
| 281 | #define EL2_MEMSIZE (EL2_MB1_STOP_PG - EL2_MB1_START_PG)*256 |
| 282 | ei_status.mem = ioremap(dev->mem_start, EL2_MEMSIZE); |
| 283 | |
| 284 | #ifdef EL2MEMTEST |
| 285 | /* This has never found an error, but someone might care. |
| 286 | Note that it only tests the 2nd 8kB on 16kB 3c503/16 |
| 287 | cards between card addr. 0x2000 and 0x3fff. */ |
| 288 | { /* Check the card's memory. */ |
| 289 | void __iomem *mem_base = ei_status.mem; |
| 290 | unsigned int test_val = 0xbbadf00d; |
| 291 | writel(0xba5eba5e, mem_base); |
| 292 | for (i = sizeof(test_val); i < EL2_MEMSIZE; i+=sizeof(test_val)) { |
| 293 | writel(test_val, mem_base + i); |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 294 | if (readl(mem_base) != 0xba5eba5e || |
| 295 | readl(mem_base + i) != test_val) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 296 | pr_warning("3c503: memory failure or memory address conflict.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | dev->mem_start = 0; |
| 298 | ei_status.name = "3c503-PIO"; |
| 299 | iounmap(mem_base); |
| 300 | ei_status.mem = NULL; |
| 301 | break; |
| 302 | } |
| 303 | test_val += 0x55555555; |
| 304 | writel(0, mem_base + i); |
| 305 | } |
| 306 | } |
| 307 | #endif /* EL2MEMTEST */ |
| 308 | |
| 309 | if (dev->mem_start) |
| 310 | dev->mem_end = dev->mem_start + EL2_MEMSIZE; |
| 311 | |
| 312 | if (wordlength) { /* No Tx pages to skip over to get to Rx */ |
| 313 | ei_status.priv = 0; |
| 314 | ei_status.name = "3c503/16"; |
| 315 | } else { |
| 316 | ei_status.priv = TX_PAGES * 256; |
| 317 | ei_status.name = "3c503"; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | Divide up the memory on the card. This is the same regardless of |
| 323 | whether shared-mem or PIO is used. For 16 bit cards (16kB RAM), |
| 324 | we use the entire 8k of bank1 for an Rx ring. We only use 3k |
| 325 | of the bank0 for 2 full size Tx packet slots. For 8 bit cards, |
| 326 | (8kB RAM) we use 3kB of bank1 for two Tx slots, and the remaining |
| 327 | 5kB for an Rx ring. */ |
| 328 | |
| 329 | if (wordlength) { |
| 330 | ei_status.tx_start_page = EL2_MB0_START_PG; |
| 331 | ei_status.rx_start_page = EL2_MB1_START_PG; |
| 332 | } else { |
| 333 | ei_status.tx_start_page = EL2_MB1_START_PG; |
| 334 | ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES; |
| 335 | } |
| 336 | |
| 337 | /* Finish setting the board's parameters. */ |
| 338 | ei_status.stop_page = EL2_MB1_STOP_PG; |
| 339 | ei_status.word16 = wordlength; |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 340 | ei_status.reset_8390 = el2_reset_8390; |
| 341 | ei_status.get_8390_hdr = el2_get_8390_hdr; |
| 342 | ei_status.block_input = el2_block_input; |
| 343 | ei_status.block_output = el2_block_output; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | if (dev->irq == 2) |
| 346 | dev->irq = 9; |
| 347 | else if (dev->irq > 5 && dev->irq != 9) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 348 | pr_warning("3c503: configured interrupt %d invalid, will use autoIRQ.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | dev->irq); |
| 350 | dev->irq = 0; |
| 351 | } |
| 352 | |
| 353 | ei_status.saved_irq = dev->irq; |
| 354 | |
Stephen Hemminger | 53cdd28 | 2008-11-25 18:26:20 -0800 | [diff] [blame] | 355 | dev->netdev_ops = &el2_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | dev->ethtool_ops = &netdev_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
| b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 358 | retval = register_netdev(dev); |
| 359 | if (retval) |
| 360 | goto out1; |
| 361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | if (dev->mem_start) |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 363 | pr_info("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | dev->name, ei_status.name, (wordlength+1)<<3, |
| 365 | dev->mem_start, dev->mem_end-1); |
| 366 | |
| 367 | else |
| 368 | { |
| 369 | ei_status.tx_start_page = EL2_MB1_START_PG; |
| 370 | ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES; |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 371 | pr_info("%s: %s, %dkB RAM, using programmed I/O (REJUMPER for SHARED MEMORY).\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | dev->name, ei_status.name, (wordlength+1)<<3); |
| 373 | } |
| 374 | release_region(ioaddr + 0x400, 8); |
| 375 | return 0; |
| 376 | out1: |
| 377 | release_region(ioaddr + 0x400, 8); |
| 378 | out: |
| 379 | release_region(ioaddr, EL2_IO_EXTENT); |
| 380 | return retval; |
| 381 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 382 | |
Ben Hutchings | b0cf4df | 2010-04-07 20:55:47 -0700 | [diff] [blame] | 383 | static irqreturn_t el2_probe_interrupt(int irq, void *seen) |
| 384 | { |
| 385 | *(bool *)seen = true; |
| 386 | return IRQ_HANDLED; |
| 387 | } |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | static int |
| 390 | el2_open(struct net_device *dev) |
| 391 | { |
roel kluin | ab08999 | 2009-09-01 06:24:53 +0000 | [diff] [blame] | 392 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
| 394 | if (dev->irq < 2) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 395 | static const int irqlist[] = {5, 9, 3, 4, 0}; |
| 396 | const int *irqp = irqlist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | outb(EGACFR_NORM, E33G_GACFR); /* Enable RAM and interrupts. */ |
| 399 | do { |
Ben Hutchings | b0cf4df | 2010-04-07 20:55:47 -0700 | [diff] [blame] | 400 | bool seen; |
| 401 | |
| 402 | retval = request_irq(*irqp, el2_probe_interrupt, 0, |
| 403 | dev->name, &seen); |
| 404 | if (retval == -EBUSY) |
| 405 | continue; |
| 406 | if (retval < 0) |
| 407 | goto err_disable; |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | /* Twinkle the interrupt, and check if it's seen. */ |
Ben Hutchings | b0cf4df | 2010-04-07 20:55:47 -0700 | [diff] [blame] | 410 | seen = false; |
| 411 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR); |
| 413 | outb_p(0x00, E33G_IDCFR); |
Ben Hutchings | b0cf4df | 2010-04-07 20:55:47 -0700 | [diff] [blame] | 414 | msleep(1); |
| 415 | free_irq(*irqp, el2_probe_interrupt); |
| 416 | if (!seen) |
| 417 | continue; |
| 418 | |
| 419 | retval = request_irq(dev->irq = *irqp, eip_interrupt, 0, |
| 420 | dev->name, dev); |
| 421 | if (retval == -EBUSY) |
| 422 | continue; |
| 423 | if (retval < 0) |
| 424 | goto err_disable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } while (*++irqp); |
Ben Hutchings | b0cf4df | 2010-04-07 20:55:47 -0700 | [diff] [blame] | 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | if (*irqp == 0) { |
Ben Hutchings | b0cf4df | 2010-04-07 20:55:47 -0700 | [diff] [blame] | 428 | err_disable: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | outb(EGACFR_IRQOFF, E33G_GACFR); /* disable interrupts. */ |
roel kluin | ab08999 | 2009-09-01 06:24:53 +0000 | [diff] [blame] | 430 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } |
| 432 | } else { |
Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 433 | if ((retval = request_irq(dev->irq, eip_interrupt, 0, dev->name, dev))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | return retval; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | el2_init_card(dev); |
Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 439 | eip_open(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static int |
| 444 | el2_close(struct net_device *dev) |
| 445 | { |
| 446 | free_irq(dev->irq, dev); |
| 447 | dev->irq = ei_status.saved_irq; |
| 448 | outb(EGACFR_IRQOFF, E33G_GACFR); /* disable interrupts. */ |
| 449 | |
Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 450 | eip_close(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | /* This is called whenever we have a unrecoverable failure: |
| 455 | transmit timeout |
| 456 | Bad ring buffer packet header |
| 457 | */ |
| 458 | static void |
| 459 | el2_reset_8390(struct net_device *dev) |
| 460 | { |
| 461 | if (ei_debug > 1) { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 462 | pr_debug("%s: Resetting the 3c503 board...", dev->name); |
| 463 | pr_cont(" %#lx=%#02x %#lx=%#02x %#lx=%#02x...", E33G_IDCFR, inb(E33G_IDCFR), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR)); |
| 465 | } |
| 466 | outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL); |
| 467 | ei_status.txing = 0; |
| 468 | outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
| 469 | el2_init_card(dev); |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 470 | if (ei_debug > 1) |
| 471 | pr_cont("done\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /* Initialize the 3c503 GA registers after a reset. */ |
| 475 | static void |
| 476 | el2_init_card(struct net_device *dev) |
| 477 | { |
| 478 | /* Unmap the station PROM and select the DIX or BNC connector. */ |
| 479 | outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
| 480 | |
| 481 | /* Set ASIC copy of rx's first and last+1 buffer pages */ |
| 482 | /* These must be the same as in the 8390. */ |
| 483 | outb(ei_status.rx_start_page, E33G_STARTPG); |
| 484 | outb(ei_status.stop_page, E33G_STOPPG); |
| 485 | |
| 486 | /* Point the vector pointer registers somewhere ?harmless?. */ |
| 487 | outb(0xff, E33G_VP2); /* Point at the ROM restart location 0xffff0 */ |
| 488 | outb(0xff, E33G_VP1); |
| 489 | outb(0x00, E33G_VP0); |
| 490 | /* Turn off all interrupts until we're opened. */ |
| 491 | outb_p(0x00, dev->base_addr + EN0_IMR); |
| 492 | /* Enable IRQs iff started. */ |
| 493 | outb(EGACFR_NORM, E33G_GACFR); |
| 494 | |
| 495 | /* Set the interrupt line. */ |
| 496 | outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR); |
| 497 | outb_p((WRD_COUNT << 1), E33G_DRQCNT); /* Set burst size to 8 */ |
| 498 | outb_p(0x20, E33G_DMAAH); /* Put a valid addr in the GA DMA */ |
| 499 | outb_p(0x00, E33G_DMAAL); |
| 500 | return; /* We always succeed */ |
| 501 | } |
| 502 | |
| 503 | /* |
| 504 | * Either use the shared memory (if enabled on the board) or put the packet |
| 505 | * out through the ASIC FIFO. |
| 506 | */ |
| 507 | static void |
| 508 | el2_block_output(struct net_device *dev, int count, |
| 509 | const unsigned char *buf, int start_page) |
| 510 | { |
| 511 | unsigned short int *wrd; |
| 512 | int boguscount; /* timeout counter */ |
| 513 | unsigned short word; /* temporary for better machine code */ |
| 514 | void __iomem *base = ei_status.mem; |
| 515 | |
| 516 | if (ei_status.word16) /* Tx packets go into bank 0 on EL2/16 card */ |
| 517 | outb(EGACFR_RSEL|EGACFR_TCM, E33G_GACFR); |
| 518 | else |
| 519 | outb(EGACFR_NORM, E33G_GACFR); |
| 520 | |
| 521 | if (base) { /* Shared memory transfer */ |
| 522 | memcpy_toio(base + ((start_page - ei_status.tx_start_page) << 8), |
| 523 | buf, count); |
| 524 | outb(EGACFR_NORM, E33G_GACFR); /* Back to bank1 in case on bank0 */ |
| 525 | return; |
| 526 | } |
| 527 | |
| 528 | /* |
| 529 | * No shared memory, put the packet out the other way. |
| 530 | * Set up then start the internal memory transfer to Tx Start Page |
| 531 | */ |
| 532 | |
| 533 | word = (unsigned short)start_page; |
| 534 | outb(word&0xFF, E33G_DMAAH); |
| 535 | outb(word>>8, E33G_DMAAL); |
| 536 | |
| 537 | outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT |
| 538 | | ECNTRL_START, E33G_CNTRL); |
| 539 | |
| 540 | /* |
| 541 | * Here I am going to write data to the FIFO as quickly as possible. |
| 542 | * Note that E33G_FIFOH is defined incorrectly. It is really |
| 543 | * E33G_FIFOL, the lowest port address for both the byte and |
| 544 | * word write. Variable 'count' is NOT checked. Caller must supply a |
| 545 | * valid count. Note that I may write a harmless extra byte to the |
| 546 | * 8390 if the byte-count was not even. |
| 547 | */ |
| 548 | wrd = (unsigned short int *) buf; |
| 549 | count = (count + 1) >> 1; |
| 550 | for(;;) |
| 551 | { |
| 552 | boguscount = 0x1000; |
| 553 | while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0) |
| 554 | { |
| 555 | if(!boguscount--) |
| 556 | { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 557 | pr_notice("%s: FIFO blocked in el2_block_output.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | el2_reset_8390(dev); |
| 559 | goto blocked; |
| 560 | } |
| 561 | } |
| 562 | if(count > WRD_COUNT) |
| 563 | { |
| 564 | outsw(E33G_FIFOH, wrd, WRD_COUNT); |
| 565 | wrd += WRD_COUNT; |
| 566 | count -= WRD_COUNT; |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | outsw(E33G_FIFOH, wrd, count); |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | blocked:; |
| 575 | outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /* Read the 4 byte, page aligned 8390 specific header. */ |
| 579 | static void |
| 580 | el2_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) |
| 581 | { |
| 582 | int boguscount; |
| 583 | void __iomem *base = ei_status.mem; |
| 584 | unsigned short word; |
| 585 | |
| 586 | if (base) { /* Use the shared memory. */ |
| 587 | void __iomem *hdr_start = base + ((ring_page - EL2_MB1_START_PG)<<8); |
| 588 | memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr)); |
| 589 | hdr->count = le16_to_cpu(hdr->count); |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | /* |
| 594 | * No shared memory, use programmed I/O. |
| 595 | */ |
| 596 | |
| 597 | word = (unsigned short)ring_page; |
| 598 | outb(word&0xFF, E33G_DMAAH); |
| 599 | outb(word>>8, E33G_DMAAL); |
| 600 | |
| 601 | outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT |
| 602 | | ECNTRL_START, E33G_CNTRL); |
| 603 | boguscount = 0x1000; |
| 604 | while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0) |
| 605 | { |
| 606 | if(!boguscount--) |
| 607 | { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 608 | pr_notice("%s: FIFO blocked in el2_get_8390_hdr.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | memset(hdr, 0x00, sizeof(struct e8390_pkt_hdr)); |
| 610 | el2_reset_8390(dev); |
| 611 | goto blocked; |
| 612 | } |
| 613 | } |
| 614 | insw(E33G_FIFOH, hdr, (sizeof(struct e8390_pkt_hdr))>> 1); |
| 615 | blocked:; |
| 616 | outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
| 617 | } |
| 618 | |
| 619 | |
| 620 | static void |
| 621 | el2_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset) |
| 622 | { |
| 623 | int boguscount = 0; |
| 624 | void __iomem *base = ei_status.mem; |
| 625 | unsigned short int *buf; |
| 626 | unsigned short word; |
| 627 | |
| 628 | /* Maybe enable shared memory just be to be safe... nahh.*/ |
| 629 | if (base) { /* Use the shared memory. */ |
| 630 | ring_offset -= (EL2_MB1_START_PG<<8); |
| 631 | if (ring_offset + count > EL2_MEMSIZE) { |
| 632 | /* We must wrap the input move. */ |
| 633 | int semi_count = EL2_MEMSIZE - ring_offset; |
| 634 | memcpy_fromio(skb->data, base + ring_offset, semi_count); |
| 635 | count -= semi_count; |
| 636 | memcpy_fromio(skb->data + semi_count, base + ei_status.priv, count); |
| 637 | } else { |
Al Viro | 4ec0311 | 2007-02-09 16:38:30 +0000 | [diff] [blame] | 638 | memcpy_fromio(skb->data, base + ring_offset, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | return; |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * No shared memory, use programmed I/O. |
| 645 | */ |
| 646 | word = (unsigned short) ring_offset; |
| 647 | outb(word>>8, E33G_DMAAH); |
| 648 | outb(word&0xFF, E33G_DMAAL); |
| 649 | |
| 650 | outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT |
| 651 | | ECNTRL_START, E33G_CNTRL); |
| 652 | |
| 653 | /* |
| 654 | * Here I also try to get data as fast as possible. I am betting that I |
| 655 | * can read one extra byte without clobbering anything in the kernel because |
| 656 | * this would only occur on an odd byte-count and allocation of skb->data |
| 657 | * is word-aligned. Variable 'count' is NOT checked. Caller must check |
| 658 | * for a valid count. |
| 659 | * [This is currently quite safe.... but if one day the 3c503 explodes |
| 660 | * you know where to come looking ;)] |
| 661 | */ |
| 662 | |
| 663 | buf = (unsigned short int *) skb->data; |
| 664 | count = (count + 1) >> 1; |
| 665 | for(;;) |
| 666 | { |
| 667 | boguscount = 0x1000; |
| 668 | while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0) |
| 669 | { |
| 670 | if(!boguscount--) |
| 671 | { |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 672 | pr_notice("%s: FIFO blocked in el2_block_input.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | el2_reset_8390(dev); |
| 674 | goto blocked; |
| 675 | } |
| 676 | } |
| 677 | if(count > WRD_COUNT) |
| 678 | { |
| 679 | insw(E33G_FIFOH, buf, WRD_COUNT); |
| 680 | buf += WRD_COUNT; |
| 681 | count -= WRD_COUNT; |
| 682 | } |
| 683 | else |
| 684 | { |
| 685 | insw(E33G_FIFOH, buf, count); |
| 686 | break; |
| 687 | } |
| 688 | } |
| 689 | blocked:; |
| 690 | outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | |
| 694 | static void netdev_get_drvinfo(struct net_device *dev, |
| 695 | struct ethtool_drvinfo *info) |
| 696 | { |
| 697 | strcpy(info->driver, DRV_NAME); |
| 698 | strcpy(info->version, DRV_VERSION); |
| 699 | sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr); |
| 700 | } |
| 701 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 702 | static const struct ethtool_ops netdev_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | .get_drvinfo = netdev_get_drvinfo, |
| 704 | }; |
| 705 | |
| 706 | #ifdef MODULE |
| 707 | #define MAX_EL2_CARDS 4 /* Max number of EL2 cards per module */ |
| 708 | |
| 709 | static struct net_device *dev_el2[MAX_EL2_CARDS]; |
| 710 | static int io[MAX_EL2_CARDS]; |
| 711 | static int irq[MAX_EL2_CARDS]; |
| 712 | static int xcvr[MAX_EL2_CARDS]; /* choose int. or ext. xcvr */ |
| 713 | module_param_array(io, int, NULL, 0); |
| 714 | module_param_array(irq, int, NULL, 0); |
| 715 | module_param_array(xcvr, int, NULL, 0); |
| 716 | MODULE_PARM_DESC(io, "I/O base address(es)"); |
| 717 | MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)"); |
| 718 | MODULE_PARM_DESC(xcvr, "transceiver(s) (0=internal, 1=external)"); |
| 719 | MODULE_DESCRIPTION("3Com ISA EtherLink II, II/16 (3c503, 3c503/16) driver"); |
| 720 | MODULE_LICENSE("GPL"); |
| 721 | |
| 722 | /* This is set up so that only a single autoprobe takes place per call. |
| 723 | ISA device autoprobes on a running machine are not recommended. */ |
Randy Dunlap | 96e672c | 2006-06-10 13:33:48 -0700 | [diff] [blame] | 724 | int __init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | init_module(void) |
| 726 | { |
| 727 | struct net_device *dev; |
| 728 | int this_dev, found = 0; |
| 729 | |
| 730 | for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) { |
| 731 | if (io[this_dev] == 0) { |
| 732 | if (this_dev != 0) break; /* only autoprobe 1st one */ |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 733 | pr_notice("3c503.c: Presently autoprobing (not recommended) for a single card.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | } |
Alan Cox | 055e511 | 2008-07-03 23:43:12 -0700 | [diff] [blame] | 735 | dev = alloc_eip_netdev(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | if (!dev) |
| 737 | break; |
| 738 | dev->irq = irq[this_dev]; |
| 739 | dev->base_addr = io[this_dev]; |
| 740 | dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */ |
| 741 | if (do_el2_probe(dev) == 0) { |
| b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 742 | dev_el2[found++] = dev; |
| 743 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | free_netdev(dev); |
Alexander Beregalov | 646cdb3 | 2009-05-26 12:35:25 +0000 | [diff] [blame] | 746 | pr_warning("3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | break; |
| 748 | } |
| 749 | if (found) |
| 750 | return 0; |
| 751 | return -ENXIO; |
| 752 | } |
| 753 | |
Denis Vlasenko | 64916f1 | 2006-01-05 22:45:47 -0800 | [diff] [blame] | 754 | static void cleanup_card(struct net_device *dev) |
| 755 | { |
| 756 | /* NB: el2_close() handles free_irq */ |
| 757 | release_region(dev->base_addr, EL2_IO_EXTENT); |
| 758 | if (ei_status.mem) |
| 759 | iounmap(ei_status.mem); |
| 760 | } |
| 761 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 762 | void __exit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | cleanup_module(void) |
| 764 | { |
| 765 | int this_dev; |
| 766 | |
| 767 | for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) { |
| 768 | struct net_device *dev = dev_el2[this_dev]; |
| 769 | if (dev) { |
| 770 | unregister_netdev(dev); |
| 771 | cleanup_card(dev); |
| 772 | free_netdev(dev); |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | #endif /* MODULE */ |