ia64/linux-2.6.18-xen.hg

annotate drivers/net/3c503.c @ 912:dd42cdb0ab89

[IA64] Build blktap2 driver by default in x86 builds.

add CONFIG_XEN_BLKDEV_TAP2=y to buildconfigs/linux-defconfig_xen_ia64.

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