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