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