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