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); |
| 82 | static struct ethtool_ops netdev_ethtool_ops; |
| 83 | |
| 84 | |
| 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 | |
| 98 | SET_MODULE_OWNER(dev); |
| 99 | |
| 100 | if (base_addr > 0x1ff) /* Check a single specified location. */ |
| 101 | return el2_probe1(dev, base_addr); |
| 102 | else if (base_addr != 0) /* Don't probe at all. */ |
| 103 | return -ENXIO; |
| 104 | |
| 105 | for (addr = addrs; *addr; addr++) { |
| 106 | void __iomem *p = ioremap(*addr, 1); |
| 107 | unsigned base_bits; |
| 108 | int i; |
| 109 | |
| 110 | if (!p) |
| 111 | continue; |
| 112 | base_bits = readb(p); |
| 113 | iounmap(p); |
| 114 | i = ffs(base_bits) - 1; |
| 115 | if (i == -1 || base_bits != (1 << i)) |
| 116 | continue; |
| 117 | if (el2_probe1(dev, netcard_portlist[i]) == 0) |
| 118 | return 0; |
| 119 | dev->irq = irq; |
| 120 | } |
| 121 | #if ! defined(no_probe_nonshared_memory) |
| 122 | return el2_pio_probe(dev); |
| 123 | #else |
| 124 | return -ENODEV; |
| 125 | #endif |
| 126 | } |
| 127 | |
| 128 | /* Try all of the locations that aren't obviously empty. This touches |
| 129 | a lot of locations, and is much riskier than the code above. */ |
| 130 | static int __init |
| 131 | el2_pio_probe(struct net_device *dev) |
| 132 | { |
| 133 | int i; |
| 134 | int base_addr = dev->base_addr; |
| 135 | int irq = dev->irq; |
| 136 | |
| 137 | if (base_addr > 0x1ff) /* Check a single specified location. */ |
| 138 | return el2_probe1(dev, base_addr); |
| 139 | else if (base_addr != 0) /* Don't probe at all. */ |
| 140 | return -ENXIO; |
| 141 | |
| 142 | for (i = 0; netcard_portlist[i]; i++) { |
| 143 | if (el2_probe1(dev, netcard_portlist[i]) == 0) |
| 144 | return 0; |
| 145 | dev->irq = irq; |
| 146 | } |
| 147 | |
| 148 | return -ENODEV; |
| 149 | } |
| 150 | |
| 151 | static void cleanup_card(struct net_device *dev) |
| 152 | { |
| 153 | /* NB: el2_close() handles free_irq */ |
| 154 | release_region(dev->base_addr, EL2_IO_EXTENT); |
| 155 | if (ei_status.mem) |
| 156 | iounmap(ei_status.mem); |
| 157 | } |
| 158 | |
| 159 | #ifndef MODULE |
| 160 | struct net_device * __init el2_probe(int unit) |
| 161 | { |
| 162 | struct net_device *dev = alloc_ei_netdev(); |
| 163 | int err; |
| 164 | |
| 165 | if (!dev) |
| 166 | return ERR_PTR(-ENOMEM); |
| 167 | |
| 168 | sprintf(dev->name, "eth%d", unit); |
| 169 | netdev_boot_setup_check(dev); |
| 170 | |
| 171 | err = do_el2_probe(dev); |
| 172 | if (err) |
| 173 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | return dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | out: |
| 176 | free_netdev(dev); |
| 177 | return ERR_PTR(err); |
| 178 | } |
| 179 | #endif |
| 180 | |
| 181 | /* Probe for the Etherlink II card at I/O port base IOADDR, |
| 182 | returning non-zero on success. If found, set the station |
| 183 | address and memory parameters in DEVICE. */ |
| 184 | static int __init |
| 185 | el2_probe1(struct net_device *dev, int ioaddr) |
| 186 | { |
| 187 | int i, iobase_reg, membase_reg, saved_406, wordlength, retval; |
| 188 | static unsigned version_printed; |
| 189 | unsigned long vendor_id; |
| 190 | |
| 191 | if (!request_region(ioaddr, EL2_IO_EXTENT, DRV_NAME)) |
| 192 | return -EBUSY; |
| 193 | |
| 194 | if (!request_region(ioaddr + 0x400, 8, DRV_NAME)) { |
| 195 | retval = -EBUSY; |
| 196 | goto out; |
| 197 | } |
| 198 | |
| 199 | /* Reset and/or avoid any lurking NE2000 */ |
| 200 | if (inb(ioaddr + 0x408) == 0xff) { |
| 201 | mdelay(1); |
| 202 | retval = -ENODEV; |
| 203 | goto out1; |
| 204 | } |
| 205 | |
| 206 | /* We verify that it's a 3C503 board by checking the first three octets |
| 207 | of its ethernet address. */ |
| 208 | iobase_reg = inb(ioaddr+0x403); |
| 209 | membase_reg = inb(ioaddr+0x404); |
| 210 | /* ASIC location registers should be 0 or have only a single bit set. */ |
| 211 | if ( (iobase_reg & (iobase_reg - 1)) |
| 212 | || (membase_reg & (membase_reg - 1))) { |
| 213 | retval = -ENODEV; |
| 214 | goto out1; |
| 215 | } |
| 216 | saved_406 = inb_p(ioaddr + 0x406); |
| 217 | outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406); /* Reset it... */ |
| 218 | outb_p(ECNTRL_THIN, ioaddr + 0x406); |
| 219 | /* Map the station addr PROM into the lower I/O ports. We now check |
| 220 | for both the old and new 3Com prefix */ |
| 221 | outb(ECNTRL_SAPROM|ECNTRL_THIN, ioaddr + 0x406); |
| 222 | vendor_id = inb(ioaddr)*0x10000 + inb(ioaddr + 1)*0x100 + inb(ioaddr + 2); |
| 223 | if ((vendor_id != OLD_3COM_ID) && (vendor_id != NEW_3COM_ID)) { |
| 224 | /* Restore the register we frobbed. */ |
| 225 | outb(saved_406, ioaddr + 0x406); |
| 226 | retval = -ENODEV; |
| 227 | goto out1; |
| 228 | } |
| 229 | |
| 230 | if (ei_debug && version_printed++ == 0) |
| 231 | printk(version); |
| 232 | |
| 233 | dev->base_addr = ioaddr; |
| 234 | |
| 235 | printk("%s: 3c503 at i/o base %#3x, node ", dev->name, ioaddr); |
| 236 | |
| 237 | /* Retrieve and print the ethernet address. */ |
| 238 | for (i = 0; i < 6; i++) |
| 239 | printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i)); |
| 240 | |
| 241 | /* Map the 8390 back into the window. */ |
| 242 | outb(ECNTRL_THIN, ioaddr + 0x406); |
| 243 | |
| 244 | /* Check for EL2/16 as described in tech. man. */ |
| 245 | outb_p(E8390_PAGE0, ioaddr + E8390_CMD); |
| 246 | outb_p(0, ioaddr + EN0_DCFG); |
| 247 | outb_p(E8390_PAGE2, ioaddr + E8390_CMD); |
| 248 | wordlength = inb_p(ioaddr + EN0_DCFG) & ENDCFG_WTS; |
| 249 | outb_p(E8390_PAGE0, ioaddr + E8390_CMD); |
| 250 | |
| 251 | /* Probe for, turn on and clear the board's shared memory. */ |
| 252 | if (ei_debug > 2) printk(" memory jumpers %2.2x ", membase_reg); |
| 253 | outb(EGACFR_NORM, ioaddr + 0x405); /* Enable RAM */ |
| 254 | |
| 255 | /* This should be probed for (or set via an ioctl()) at run-time. |
| 256 | Right now we use a sleazy hack to pass in the interface number |
| 257 | at boot-time via the low bits of the mem_end field. That value is |
| 258 | unused, and the low bits would be discarded even if it was used. */ |
| 259 | #if defined(EI8390_THICK) || defined(EL2_AUI) |
| 260 | ei_status.interface_num = 1; |
| 261 | #else |
| 262 | ei_status.interface_num = dev->mem_end & 0xf; |
| 263 | #endif |
| 264 | printk(", using %sternal xcvr.\n", ei_status.interface_num == 0 ? "in" : "ex"); |
| 265 | |
| 266 | if ((membase_reg & 0xf0) == 0) { |
| 267 | dev->mem_start = 0; |
| 268 | ei_status.name = "3c503-PIO"; |
| 269 | ei_status.mem = NULL; |
| 270 | } else { |
| 271 | dev->mem_start = ((membase_reg & 0xc0) ? 0xD8000 : 0xC8000) + |
| 272 | ((membase_reg & 0xA0) ? 0x4000 : 0); |
| 273 | #define EL2_MEMSIZE (EL2_MB1_STOP_PG - EL2_MB1_START_PG)*256 |
| 274 | ei_status.mem = ioremap(dev->mem_start, EL2_MEMSIZE); |
| 275 | |
| 276 | #ifdef EL2MEMTEST |
| 277 | /* This has never found an error, but someone might care. |
| 278 | Note that it only tests the 2nd 8kB on 16kB 3c503/16 |
| 279 | cards between card addr. 0x2000 and 0x3fff. */ |
| 280 | { /* Check the card's memory. */ |
| 281 | void __iomem *mem_base = ei_status.mem; |
| 282 | unsigned int test_val = 0xbbadf00d; |
| 283 | writel(0xba5eba5e, mem_base); |
| 284 | for (i = sizeof(test_val); i < EL2_MEMSIZE; i+=sizeof(test_val)) { |
| 285 | writel(test_val, mem_base + i); |
| 286 | if (readl(mem_base) != 0xba5eba5e |
| 287 | || readl(mem_base + i) != test_val) { |
| 288 | printk("3c503: memory failure or memory address conflict.\n"); |
| 289 | dev->mem_start = 0; |
| 290 | ei_status.name = "3c503-PIO"; |
| 291 | iounmap(mem_base); |
| 292 | ei_status.mem = NULL; |
| 293 | break; |
| 294 | } |
| 295 | test_val += 0x55555555; |
| 296 | writel(0, mem_base + i); |
| 297 | } |
| 298 | } |
| 299 | #endif /* EL2MEMTEST */ |
| 300 | |
| 301 | if (dev->mem_start) |
| 302 | dev->mem_end = dev->mem_start + EL2_MEMSIZE; |
| 303 | |
| 304 | if (wordlength) { /* No Tx pages to skip over to get to Rx */ |
| 305 | ei_status.priv = 0; |
| 306 | ei_status.name = "3c503/16"; |
| 307 | } else { |
| 308 | ei_status.priv = TX_PAGES * 256; |
| 309 | ei_status.name = "3c503"; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | /* |
| 314 | Divide up the memory on the card. This is the same regardless of |
| 315 | whether shared-mem or PIO is used. For 16 bit cards (16kB RAM), |
| 316 | we use the entire 8k of bank1 for an Rx ring. We only use 3k |
| 317 | of the bank0 for 2 full size Tx packet slots. For 8 bit cards, |
| 318 | (8kB RAM) we use 3kB of bank1 for two Tx slots, and the remaining |
| 319 | 5kB for an Rx ring. */ |
| 320 | |
| 321 | if (wordlength) { |
| 322 | ei_status.tx_start_page = EL2_MB0_START_PG; |
| 323 | ei_status.rx_start_page = EL2_MB1_START_PG; |
| 324 | } else { |
| 325 | ei_status.tx_start_page = EL2_MB1_START_PG; |
| 326 | ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES; |
| 327 | } |
| 328 | |
| 329 | /* Finish setting the board's parameters. */ |
| 330 | ei_status.stop_page = EL2_MB1_STOP_PG; |
| 331 | ei_status.word16 = wordlength; |
| 332 | ei_status.reset_8390 = &el2_reset_8390; |
| 333 | ei_status.get_8390_hdr = &el2_get_8390_hdr; |
| 334 | ei_status.block_input = &el2_block_input; |
| 335 | ei_status.block_output = &el2_block_output; |
| 336 | |
| 337 | if (dev->irq == 2) |
| 338 | dev->irq = 9; |
| 339 | else if (dev->irq > 5 && dev->irq != 9) { |
| 340 | printk("3c503: configured interrupt %d invalid, will use autoIRQ.\n", |
| 341 | dev->irq); |
| 342 | dev->irq = 0; |
| 343 | } |
| 344 | |
| 345 | ei_status.saved_irq = dev->irq; |
| 346 | |
| 347 | dev->open = &el2_open; |
| 348 | dev->stop = &el2_close; |
| 349 | dev->ethtool_ops = &netdev_ethtool_ops; |
| 350 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 351 | dev->poll_controller = ei_poll; |
| 352 | #endif |
| 353 | |
| b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 354 | retval = register_netdev(dev); |
| 355 | if (retval) |
| 356 | goto out1; |
| 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | if (dev->mem_start) |
| 359 | printk("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n", |
| 360 | dev->name, ei_status.name, (wordlength+1)<<3, |
| 361 | dev->mem_start, dev->mem_end-1); |
| 362 | |
| 363 | else |
| 364 | { |
| 365 | ei_status.tx_start_page = EL2_MB1_START_PG; |
| 366 | ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES; |
| 367 | printk("\n%s: %s, %dkB RAM, using programmed I/O (REJUMPER for SHARED MEMORY).\n", |
| 368 | dev->name, ei_status.name, (wordlength+1)<<3); |
| 369 | } |
| 370 | release_region(ioaddr + 0x400, 8); |
| 371 | return 0; |
| 372 | out1: |
| 373 | release_region(ioaddr + 0x400, 8); |
| 374 | out: |
| 375 | release_region(ioaddr, EL2_IO_EXTENT); |
| 376 | return retval; |
| 377 | } |
| 378 | |
| 379 | static int |
| 380 | el2_open(struct net_device *dev) |
| 381 | { |
| 382 | int retval = -EAGAIN; |
| 383 | |
| 384 | if (dev->irq < 2) { |
| 385 | int irqlist[] = {5, 9, 3, 4, 0}; |
| 386 | int *irqp = irqlist; |
| 387 | |
| 388 | outb(EGACFR_NORM, E33G_GACFR); /* Enable RAM and interrupts. */ |
| 389 | do { |
| 390 | if (request_irq (*irqp, NULL, 0, "bogus", dev) != -EBUSY) { |
| 391 | /* Twinkle the interrupt, and check if it's seen. */ |
| 392 | unsigned long cookie = probe_irq_on(); |
| 393 | outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR); |
| 394 | outb_p(0x00, E33G_IDCFR); |
| 395 | if (*irqp == probe_irq_off(cookie) /* It's a good IRQ line! */ |
| 396 | && ((retval = request_irq(dev->irq = *irqp, |
| 397 | ei_interrupt, 0, dev->name, dev)) == 0)) |
| 398 | break; |
| 399 | } |
| 400 | } while (*++irqp); |
| 401 | if (*irqp == 0) { |
| 402 | outb(EGACFR_IRQOFF, E33G_GACFR); /* disable interrupts. */ |
| 403 | return retval; |
| 404 | } |
| 405 | } else { |
| 406 | if ((retval = request_irq(dev->irq, ei_interrupt, 0, dev->name, dev))) { |
| 407 | return retval; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | el2_init_card(dev); |
| 412 | ei_open(dev); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static int |
| 417 | el2_close(struct net_device *dev) |
| 418 | { |
| 419 | free_irq(dev->irq, dev); |
| 420 | dev->irq = ei_status.saved_irq; |
| 421 | outb(EGACFR_IRQOFF, E33G_GACFR); /* disable interrupts. */ |
| 422 | |
| 423 | ei_close(dev); |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | /* This is called whenever we have a unrecoverable failure: |
| 428 | transmit timeout |
| 429 | Bad ring buffer packet header |
| 430 | */ |
| 431 | static void |
| 432 | el2_reset_8390(struct net_device *dev) |
| 433 | { |
| 434 | if (ei_debug > 1) { |
| 435 | printk("%s: Resetting the 3c503 board...", dev->name); |
| 436 | printk("%#lx=%#02x %#lx=%#02x %#lx=%#02x...", E33G_IDCFR, inb(E33G_IDCFR), |
| 437 | E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR)); |
| 438 | } |
| 439 | outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL); |
| 440 | ei_status.txing = 0; |
| 441 | outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
| 442 | el2_init_card(dev); |
| 443 | if (ei_debug > 1) printk("done\n"); |
| 444 | } |
| 445 | |
| 446 | /* Initialize the 3c503 GA registers after a reset. */ |
| 447 | static void |
| 448 | el2_init_card(struct net_device *dev) |
| 449 | { |
| 450 | /* Unmap the station PROM and select the DIX or BNC connector. */ |
| 451 | outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
| 452 | |
| 453 | /* Set ASIC copy of rx's first and last+1 buffer pages */ |
| 454 | /* These must be the same as in the 8390. */ |
| 455 | outb(ei_status.rx_start_page, E33G_STARTPG); |
| 456 | outb(ei_status.stop_page, E33G_STOPPG); |
| 457 | |
| 458 | /* Point the vector pointer registers somewhere ?harmless?. */ |
| 459 | outb(0xff, E33G_VP2); /* Point at the ROM restart location 0xffff0 */ |
| 460 | outb(0xff, E33G_VP1); |
| 461 | outb(0x00, E33G_VP0); |
| 462 | /* Turn off all interrupts until we're opened. */ |
| 463 | outb_p(0x00, dev->base_addr + EN0_IMR); |
| 464 | /* Enable IRQs iff started. */ |
| 465 | outb(EGACFR_NORM, E33G_GACFR); |
| 466 | |
| 467 | /* Set the interrupt line. */ |
| 468 | outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR); |
| 469 | outb_p((WRD_COUNT << 1), E33G_DRQCNT); /* Set burst size to 8 */ |
| 470 | outb_p(0x20, E33G_DMAAH); /* Put a valid addr in the GA DMA */ |
| 471 | outb_p(0x00, E33G_DMAAL); |
| 472 | return; /* We always succeed */ |
| 473 | } |
| 474 | |
| 475 | /* |
| 476 | * Either use the shared memory (if enabled on the board) or put the packet |
| 477 | * out through the ASIC FIFO. |
| 478 | */ |
| 479 | static void |
| 480 | el2_block_output(struct net_device *dev, int count, |
| 481 | const unsigned char *buf, int start_page) |
| 482 | { |
| 483 | unsigned short int *wrd; |
| 484 | int boguscount; /* timeout counter */ |
| 485 | unsigned short word; /* temporary for better machine code */ |
| 486 | void __iomem *base = ei_status.mem; |
| 487 | |
| 488 | if (ei_status.word16) /* Tx packets go into bank 0 on EL2/16 card */ |
| 489 | outb(EGACFR_RSEL|EGACFR_TCM, E33G_GACFR); |
| 490 | else |
| 491 | outb(EGACFR_NORM, E33G_GACFR); |
| 492 | |
| 493 | if (base) { /* Shared memory transfer */ |
| 494 | memcpy_toio(base + ((start_page - ei_status.tx_start_page) << 8), |
| 495 | buf, count); |
| 496 | outb(EGACFR_NORM, E33G_GACFR); /* Back to bank1 in case on bank0 */ |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | /* |
| 501 | * No shared memory, put the packet out the other way. |
| 502 | * Set up then start the internal memory transfer to Tx Start Page |
| 503 | */ |
| 504 | |
| 505 | word = (unsigned short)start_page; |
| 506 | outb(word&0xFF, E33G_DMAAH); |
| 507 | outb(word>>8, E33G_DMAAL); |
| 508 | |
| 509 | outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT |
| 510 | | ECNTRL_START, E33G_CNTRL); |
| 511 | |
| 512 | /* |
| 513 | * Here I am going to write data to the FIFO as quickly as possible. |
| 514 | * Note that E33G_FIFOH is defined incorrectly. It is really |
| 515 | * E33G_FIFOL, the lowest port address for both the byte and |
| 516 | * word write. Variable 'count' is NOT checked. Caller must supply a |
| 517 | * valid count. Note that I may write a harmless extra byte to the |
| 518 | * 8390 if the byte-count was not even. |
| 519 | */ |
| 520 | wrd = (unsigned short int *) buf; |
| 521 | count = (count + 1) >> 1; |
| 522 | for(;;) |
| 523 | { |
| 524 | boguscount = 0x1000; |
| 525 | while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0) |
| 526 | { |
| 527 | if(!boguscount--) |
| 528 | { |
| 529 | printk("%s: FIFO blocked in el2_block_output.\n", dev->name); |
| 530 | el2_reset_8390(dev); |
| 531 | goto blocked; |
| 532 | } |
| 533 | } |
| 534 | if(count > WRD_COUNT) |
| 535 | { |
| 536 | outsw(E33G_FIFOH, wrd, WRD_COUNT); |
| 537 | wrd += WRD_COUNT; |
| 538 | count -= WRD_COUNT; |
| 539 | } |
| 540 | else |
| 541 | { |
| 542 | outsw(E33G_FIFOH, wrd, count); |
| 543 | break; |
| 544 | } |
| 545 | } |
| 546 | blocked:; |
| 547 | outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
| 548 | return; |
| 549 | } |
| 550 | |
| 551 | /* Read the 4 byte, page aligned 8390 specific header. */ |
| 552 | static void |
| 553 | el2_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) |
| 554 | { |
| 555 | int boguscount; |
| 556 | void __iomem *base = ei_status.mem; |
| 557 | unsigned short word; |
| 558 | |
| 559 | if (base) { /* Use the shared memory. */ |
| 560 | void __iomem *hdr_start = base + ((ring_page - EL2_MB1_START_PG)<<8); |
| 561 | memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr)); |
| 562 | hdr->count = le16_to_cpu(hdr->count); |
| 563 | return; |
| 564 | } |
| 565 | |
| 566 | /* |
| 567 | * No shared memory, use programmed I/O. |
| 568 | */ |
| 569 | |
| 570 | word = (unsigned short)ring_page; |
| 571 | outb(word&0xFF, E33G_DMAAH); |
| 572 | outb(word>>8, E33G_DMAAL); |
| 573 | |
| 574 | outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT |
| 575 | | ECNTRL_START, E33G_CNTRL); |
| 576 | boguscount = 0x1000; |
| 577 | while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0) |
| 578 | { |
| 579 | if(!boguscount--) |
| 580 | { |
| 581 | printk("%s: FIFO blocked in el2_get_8390_hdr.\n", dev->name); |
| 582 | memset(hdr, 0x00, sizeof(struct e8390_pkt_hdr)); |
| 583 | el2_reset_8390(dev); |
| 584 | goto blocked; |
| 585 | } |
| 586 | } |
| 587 | insw(E33G_FIFOH, hdr, (sizeof(struct e8390_pkt_hdr))>> 1); |
| 588 | blocked:; |
| 589 | outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
| 590 | } |
| 591 | |
| 592 | |
| 593 | static void |
| 594 | el2_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset) |
| 595 | { |
| 596 | int boguscount = 0; |
| 597 | void __iomem *base = ei_status.mem; |
| 598 | unsigned short int *buf; |
| 599 | unsigned short word; |
| 600 | |
| 601 | /* Maybe enable shared memory just be to be safe... nahh.*/ |
| 602 | if (base) { /* Use the shared memory. */ |
| 603 | ring_offset -= (EL2_MB1_START_PG<<8); |
| 604 | if (ring_offset + count > EL2_MEMSIZE) { |
| 605 | /* We must wrap the input move. */ |
| 606 | int semi_count = EL2_MEMSIZE - ring_offset; |
| 607 | memcpy_fromio(skb->data, base + ring_offset, semi_count); |
| 608 | count -= semi_count; |
| 609 | memcpy_fromio(skb->data + semi_count, base + ei_status.priv, count); |
| 610 | } else { |
| 611 | /* Packet is in one chunk -- we can copy + cksum. */ |
| 612 | eth_io_copy_and_sum(skb, base + ring_offset, count, 0); |
| 613 | } |
| 614 | return; |
| 615 | } |
| 616 | |
| 617 | /* |
| 618 | * No shared memory, use programmed I/O. |
| 619 | */ |
| 620 | word = (unsigned short) ring_offset; |
| 621 | outb(word>>8, E33G_DMAAH); |
| 622 | outb(word&0xFF, E33G_DMAAL); |
| 623 | |
| 624 | outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT |
| 625 | | ECNTRL_START, E33G_CNTRL); |
| 626 | |
| 627 | /* |
| 628 | * Here I also try to get data as fast as possible. I am betting that I |
| 629 | * can read one extra byte without clobbering anything in the kernel because |
| 630 | * this would only occur on an odd byte-count and allocation of skb->data |
| 631 | * is word-aligned. Variable 'count' is NOT checked. Caller must check |
| 632 | * for a valid count. |
| 633 | * [This is currently quite safe.... but if one day the 3c503 explodes |
| 634 | * you know where to come looking ;)] |
| 635 | */ |
| 636 | |
| 637 | buf = (unsigned short int *) skb->data; |
| 638 | count = (count + 1) >> 1; |
| 639 | for(;;) |
| 640 | { |
| 641 | boguscount = 0x1000; |
| 642 | while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0) |
| 643 | { |
| 644 | if(!boguscount--) |
| 645 | { |
| 646 | printk("%s: FIFO blocked in el2_block_input.\n", dev->name); |
| 647 | el2_reset_8390(dev); |
| 648 | goto blocked; |
| 649 | } |
| 650 | } |
| 651 | if(count > WRD_COUNT) |
| 652 | { |
| 653 | insw(E33G_FIFOH, buf, WRD_COUNT); |
| 654 | buf += WRD_COUNT; |
| 655 | count -= WRD_COUNT; |
| 656 | } |
| 657 | else |
| 658 | { |
| 659 | insw(E33G_FIFOH, buf, count); |
| 660 | break; |
| 661 | } |
| 662 | } |
| 663 | blocked:; |
| 664 | outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL); |
| 665 | return; |
| 666 | } |
| 667 | |
| 668 | |
| 669 | static void netdev_get_drvinfo(struct net_device *dev, |
| 670 | struct ethtool_drvinfo *info) |
| 671 | { |
| 672 | strcpy(info->driver, DRV_NAME); |
| 673 | strcpy(info->version, DRV_VERSION); |
| 674 | sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr); |
| 675 | } |
| 676 | |
| 677 | static struct ethtool_ops netdev_ethtool_ops = { |
| 678 | .get_drvinfo = netdev_get_drvinfo, |
| 679 | }; |
| 680 | |
| 681 | #ifdef MODULE |
| 682 | #define MAX_EL2_CARDS 4 /* Max number of EL2 cards per module */ |
| 683 | |
| 684 | static struct net_device *dev_el2[MAX_EL2_CARDS]; |
| 685 | static int io[MAX_EL2_CARDS]; |
| 686 | static int irq[MAX_EL2_CARDS]; |
| 687 | static int xcvr[MAX_EL2_CARDS]; /* choose int. or ext. xcvr */ |
| 688 | module_param_array(io, int, NULL, 0); |
| 689 | module_param_array(irq, int, NULL, 0); |
| 690 | module_param_array(xcvr, int, NULL, 0); |
| 691 | MODULE_PARM_DESC(io, "I/O base address(es)"); |
| 692 | MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)"); |
| 693 | MODULE_PARM_DESC(xcvr, "transceiver(s) (0=internal, 1=external)"); |
| 694 | MODULE_DESCRIPTION("3Com ISA EtherLink II, II/16 (3c503, 3c503/16) driver"); |
| 695 | MODULE_LICENSE("GPL"); |
| 696 | |
| 697 | /* This is set up so that only a single autoprobe takes place per call. |
| 698 | ISA device autoprobes on a running machine are not recommended. */ |
| 699 | int |
| 700 | init_module(void) |
| 701 | { |
| 702 | struct net_device *dev; |
| 703 | int this_dev, found = 0; |
| 704 | |
| 705 | for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) { |
| 706 | if (io[this_dev] == 0) { |
| 707 | if (this_dev != 0) break; /* only autoprobe 1st one */ |
| 708 | printk(KERN_NOTICE "3c503.c: Presently autoprobing (not recommended) for a single card.\n"); |
| 709 | } |
| 710 | dev = alloc_ei_netdev(); |
| 711 | if (!dev) |
| 712 | break; |
| 713 | dev->irq = irq[this_dev]; |
| 714 | dev->base_addr = io[this_dev]; |
| 715 | dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */ |
| 716 | if (do_el2_probe(dev) == 0) { |
| b1fc550 | 2005-05-12 20:11:55 -0400 | [diff] [blame] | 717 | dev_el2[found++] = dev; |
| 718 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | free_netdev(dev); |
| 721 | printk(KERN_WARNING "3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]); |
| 722 | break; |
| 723 | } |
| 724 | if (found) |
| 725 | return 0; |
| 726 | return -ENXIO; |
| 727 | } |
| 728 | |
| 729 | void |
| 730 | cleanup_module(void) |
| 731 | { |
| 732 | int this_dev; |
| 733 | |
| 734 | for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) { |
| 735 | struct net_device *dev = dev_el2[this_dev]; |
| 736 | if (dev) { |
| 737 | unregister_netdev(dev); |
| 738 | cleanup_card(dev); |
| 739 | free_netdev(dev); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | #endif /* MODULE */ |