x86: i8259A: remove redundant irq_descinitialization
[wrt350n-kernel.git] / drivers / net / 3c523.c
blob239fc42fb8df6c97ffe535da49d9b0d2df3e5387
1 /*
2 net-3-driver for the 3c523 Etherlink/MC card (i82586 Ethernet chip)
5 This is an extension to the Linux operating system, and is covered by the
6 same GNU General Public License that covers that work.
8 Copyright 1995, 1996 by Chris Beauregard (cpbeaure@undergrad.math.uwaterloo.ca)
10 This is basically Michael Hipp's ni52 driver, with a new probing
11 algorithm and some minor changes to the 82586 CA and reset routines.
12 Thanks a lot Michael for a really clean i82586 implementation! Unless
13 otherwise documented in ni52.c, any bugs are mine.
15 Contrary to the Ethernet-HOWTO, this isn't based on the 3c507 driver in
16 any way. The ni52 is a lot easier to modify.
18 sources:
19 ni52.c
21 Crynwr packet driver collection was a great reference for my first
22 attempt at this sucker. The 3c507 driver also helped, until I noticed
23 that ni52.c was a lot nicer.
25 EtherLink/MC: Micro Channel Ethernet Adapter Technical Reference
26 Manual, courtesy of 3Com CardFacts, documents the 3c523-specific
27 stuff. Information on CardFacts is found in the Ethernet HOWTO.
28 Also see <a href="http://www.3com.com/">
30 Microprocessor Communications Support Chips, T.J. Byers, ISBN
31 0-444-01224-9, has a section on the i82586. It tells you just enough
32 to know that you really don't want to learn how to program the chip.
34 The original device probe code was stolen from ps2esdi.c
36 Known Problems:
37 Since most of the code was stolen from ni52.c, you'll run across the
38 same bugs in the 0.62 version of ni52.c, plus maybe a few because of
39 the 3c523 idiosynchacies. The 3c523 has 16K of RAM though, so there
40 shouldn't be the overrun problem that the 8K ni52 has.
42 This driver is for a 16K adapter. It should work fine on the 64K
43 adapters, but it will only use one of the 4 banks of RAM. Modifying
44 this for the 64K version would require a lot of heinous bank
45 switching, which I'm sure not interested in doing. If you try to
46 implement a bank switching version, you'll basically have to remember
47 what bank is enabled and do a switch everytime you access a memory
48 location that's not current. You'll also have to remap pointers on
49 the driver side, because it only knows about 16K of the memory.
50 Anyone desperate or masochistic enough to try?
52 It seems to be stable now when multiple transmit buffers are used. I
53 can't see any performance difference, but then I'm working on a 386SX.
55 Multicast doesn't work. It doesn't even pretend to work. Don't use
56 it. Don't compile your kernel with multicast support. I don't know
57 why.
59 Features:
60 This driver is useable as a loadable module. If you try to specify an
61 IRQ or a IO address (via insmod 3c523.o irq=xx io=0xyyy), it will
62 search the MCA slots until it finds a 3c523 with the specified
63 parameters.
65 This driver does support multiple ethernet cards when used as a module
66 (up to MAX_3C523_CARDS, the default being 4)
68 This has been tested with both BNC and TP versions, internal and
69 external transceivers. Haven't tested with the 64K version (that I
70 know of).
72 History:
73 Jan 1st, 1996
74 first public release
75 Feb 4th, 1996
76 update to 1.3.59, incorporated multicast diffs from ni52.c
77 Feb 15th, 1996
78 added shared irq support
79 Apr 1999
80 added support for multiple cards when used as a module
81 added option to disable multicast as is causes problems
82 Ganesh Sittampalam <ganesh.sittampalam@magdalen.oxford.ac.uk>
83 Stuart Adamson <stuart.adamson@compsoc.net>
84 Nov 2001
85 added support for ethtool (jgarzik)
87 $Header: /fsys2/home/chrisb/linux-1.3.59-MCA/drivers/net/RCS/3c523.c,v 1.1 1996/02/05 01:53:46 chrisb Exp chrisb $
90 #define DRV_NAME "3c523"
91 #define DRV_VERSION "17-Nov-2001"
93 #include <linux/init.h>
94 #include <linux/netdevice.h>
95 #include <linux/etherdevice.h>
96 #include <linux/module.h>
97 #include <linux/kernel.h>
98 #include <linux/string.h>
99 #include <linux/errno.h>
100 #include <linux/ioport.h>
101 #include <linux/skbuff.h>
102 #include <linux/slab.h>
103 #include <linux/interrupt.h>
104 #include <linux/delay.h>
105 #include <linux/mca-legacy.h>
106 #include <linux/ethtool.h>
107 #include <linux/bitops.h>
108 #include <linux/jiffies.h>
110 #include <asm/uaccess.h>
111 #include <asm/processor.h>
112 #include <asm/io.h>
114 #include "3c523.h"
116 /*************************************************************************/
117 #define DEBUG /* debug on */
118 #define SYSBUSVAL 0 /* 1 = 8 Bit, 0 = 16 bit - 3c523 only does 16 bit */
119 #undef ELMC_MULTICAST /* Disable multicast support as it is somewhat seriously broken at the moment */
121 #define make32(ptr16) (p->memtop + (short) (ptr16) )
122 #define make24(ptr32) ((char *) (ptr32) - p->base)
123 #define make16(ptr32) ((unsigned short) ((unsigned long) (ptr32) - (unsigned long) p->memtop ))
125 /*************************************************************************/
127 Tables to which we can map values in the configuration registers.
129 static int irq_table[] __initdata = {
130 12, 7, 3, 9
133 static int csr_table[] __initdata = {
134 0x300, 0x1300, 0x2300, 0x3300
137 static int shm_table[] __initdata = {
138 0x0c0000, 0x0c8000, 0x0d0000, 0x0d8000
141 /******************* how to calculate the buffers *****************************
144 * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
145 * --------------- in a different (more stable?) mode. Only in this mode it's
146 * possible to configure the driver with 'NO_NOPCOMMANDS'
148 sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
149 sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
150 sizeof(rfd) = 24; sizeof(rbd) = 12;
151 sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
152 sizeof(nop_cmd) = 8;
154 * if you don't know the driver, better do not change this values: */
156 #define RECV_BUFF_SIZE 1524 /* slightly oversized */
157 #define XMIT_BUFF_SIZE 1524 /* slightly oversized */
158 #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */
159 #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */
160 #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
162 #if (NUM_XMIT_BUFFS == 1)
163 #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
164 #endif
166 /**************************************************************************/
168 #define DELAY(x) { mdelay(32 * x); }
170 /* a much shorter delay: */
171 #define DELAY_16(); { udelay(16) ; }
173 /* wait for command with timeout: */
174 #define WAIT_4_SCB_CMD() { int i; \
175 for(i=0;i<1024;i++) { \
176 if(!p->scb->cmd) break; \
177 DELAY_16(); \
178 if(i == 1023) { \
179 printk(KERN_WARNING "%s:%d: scb_cmd timed out .. resetting i82586\n",\
180 dev->name,__LINE__); \
181 elmc_id_reset586(); } } }
183 static irqreturn_t elmc_interrupt(int irq, void *dev_id);
184 static int elmc_open(struct net_device *dev);
185 static int elmc_close(struct net_device *dev);
186 static int elmc_send_packet(struct sk_buff *, struct net_device *);
187 static struct net_device_stats *elmc_get_stats(struct net_device *dev);
188 static void elmc_timeout(struct net_device *dev);
189 #ifdef ELMC_MULTICAST
190 static void set_multicast_list(struct net_device *dev);
191 #endif
192 static const struct ethtool_ops netdev_ethtool_ops;
194 /* helper-functions */
195 static int init586(struct net_device *dev);
196 static int check586(struct net_device *dev, unsigned long where, unsigned size);
197 static void alloc586(struct net_device *dev);
198 static void startrecv586(struct net_device *dev);
199 static void *alloc_rfa(struct net_device *dev, void *ptr);
200 static void elmc_rcv_int(struct net_device *dev);
201 static void elmc_xmt_int(struct net_device *dev);
202 static void elmc_rnr_int(struct net_device *dev);
204 struct priv {
205 struct net_device_stats stats;
206 unsigned long base;
207 char *memtop;
208 unsigned long mapped_start; /* Start of ioremap */
209 volatile struct rfd_struct *rfd_last, *rfd_top, *rfd_first;
210 volatile struct scp_struct *scp; /* volatile is important */
211 volatile struct iscp_struct *iscp; /* volatile is important */
212 volatile struct scb_struct *scb; /* volatile is important */
213 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
214 #if (NUM_XMIT_BUFFS == 1)
215 volatile struct transmit_cmd_struct *xmit_cmds[2];
216 volatile struct nop_cmd_struct *nop_cmds[2];
217 #else
218 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
219 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
220 #endif
221 volatile int nop_point, num_recv_buffs;
222 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
223 volatile int xmit_count, xmit_last;
224 volatile int slot;
227 #define elmc_attn586() {elmc_do_attn586(dev->base_addr,ELMC_CTRL_INTE);}
228 #define elmc_reset586() {elmc_do_reset586(dev->base_addr,ELMC_CTRL_INTE);}
230 /* with interrupts disabled - this will clear the interrupt bit in the
231 3c523 control register, and won't put it back. This effectively
232 disables interrupts on the card. */
233 #define elmc_id_attn586() {elmc_do_attn586(dev->base_addr,0);}
234 #define elmc_id_reset586() {elmc_do_reset586(dev->base_addr,0);}
236 /*************************************************************************/
238 Do a Channel Attention on the 3c523. This is extremely board dependent.
240 static void elmc_do_attn586(int ioaddr, int ints)
242 /* the 3c523 requires a minimum of 500 ns. The delays here might be
243 a little too large, and hence they may cut the performance of the
244 card slightly. If someone who knows a little more about Linux
245 timing would care to play with these, I'd appreciate it. */
247 /* this bit masking stuff is crap. I'd rather have separate
248 registers with strobe triggers for each of these functions. <sigh>
249 Ya take what ya got. */
251 outb(ELMC_CTRL_RST | 0x3 | ELMC_CTRL_CA | ints, ioaddr + ELMC_CTRL);
252 DELAY_16(); /* > 500 ns */
253 outb(ELMC_CTRL_RST | 0x3 | ints, ioaddr + ELMC_CTRL);
256 /*************************************************************************/
258 Reset the 82586 on the 3c523. Also very board dependent.
260 static void elmc_do_reset586(int ioaddr, int ints)
262 /* toggle the RST bit low then high */
263 outb(0x3 | ELMC_CTRL_LBK, ioaddr + ELMC_CTRL);
264 DELAY_16(); /* > 500 ns */
265 outb(ELMC_CTRL_RST | ELMC_CTRL_LBK | 0x3, ioaddr + ELMC_CTRL);
267 elmc_do_attn586(ioaddr, ints);
270 /**********************************************
271 * close device
274 static int elmc_close(struct net_device *dev)
276 netif_stop_queue(dev);
277 elmc_id_reset586(); /* the hard way to stop the receiver */
278 free_irq(dev->irq, dev);
279 return 0;
282 /**********************************************
283 * open device
286 static int elmc_open(struct net_device *dev)
288 int ret;
290 elmc_id_attn586(); /* disable interrupts */
292 ret = request_irq(dev->irq, &elmc_interrupt, IRQF_SHARED | IRQF_SAMPLE_RANDOM,
293 dev->name, dev);
294 if (ret) {
295 printk(KERN_ERR "%s: couldn't get irq %d\n", dev->name, dev->irq);
296 elmc_id_reset586();
297 return ret;
299 alloc586(dev);
300 init586(dev);
301 startrecv586(dev);
302 netif_start_queue(dev);
303 return 0; /* most done by init */
306 /**********************************************
307 * Check to see if there's an 82586 out there.
310 static int __init check586(struct net_device *dev, unsigned long where, unsigned size)
312 struct priv *p = (struct priv *) dev->priv;
313 char *iscp_addrs[2];
314 int i = 0;
316 p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000;
317 p->memtop = isa_bus_to_virt((unsigned long)where) + size;
318 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
319 memset((char *) p->scp, 0, sizeof(struct scp_struct));
320 p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */
322 iscp_addrs[0] = isa_bus_to_virt((unsigned long)where);
323 iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct);
325 for (i = 0; i < 2; i++) {
326 p->iscp = (struct iscp_struct *) iscp_addrs[i];
327 memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
329 p->scp->iscp = make24(p->iscp);
330 p->iscp->busy = 1;
332 elmc_id_reset586();
334 /* reset586 does an implicit CA */
336 /* apparently, you sometimes have to kick the 82586 twice... */
337 elmc_id_attn586();
338 DELAY(1);
340 if (p->iscp->busy) { /* i82586 clears 'busy' after successful init */
341 return 0;
344 return 1;
347 /******************************************************************
348 * set iscp at the right place, called by elmc_probe and open586.
351 void alloc586(struct net_device *dev)
353 struct priv *p = (struct priv *) dev->priv;
355 elmc_id_reset586();
356 DELAY(2);
358 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
359 p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start);
360 p->iscp = (struct iscp_struct *) ((char *) p->scp - sizeof(struct iscp_struct));
362 memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
363 memset((char *) p->scp, 0, sizeof(struct scp_struct));
365 p->scp->iscp = make24(p->iscp);
366 p->scp->sysbus = SYSBUSVAL;
367 p->iscp->scb_offset = make16(p->scb);
369 p->iscp->busy = 1;
370 elmc_id_reset586();
371 elmc_id_attn586();
373 DELAY(2);
375 if (p->iscp->busy) {
376 printk(KERN_ERR "%s: Init-Problems (alloc).\n", dev->name);
378 memset((char *) p->scb, 0, sizeof(struct scb_struct));
381 /*****************************************************************/
383 static int elmc_getinfo(char *buf, int slot, void *d)
385 int len = 0;
386 struct net_device *dev = d;
387 DECLARE_MAC_BUF(mac);
389 if (dev == NULL)
390 return len;
392 len += sprintf(buf + len, "Revision: 0x%x\n",
393 inb(dev->base_addr + ELMC_REVISION) & 0xf);
394 len += sprintf(buf + len, "IRQ: %d\n", dev->irq);
395 len += sprintf(buf + len, "IO Address: %#lx-%#lx\n", dev->base_addr,
396 dev->base_addr + ELMC_IO_EXTENT);
397 len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start,
398 dev->mem_end - 1);
399 len += sprintf(buf + len, "Transceiver: %s\n", dev->if_port ?
400 "External" : "Internal");
401 len += sprintf(buf + len, "Device: %s\n", dev->name);
402 len += sprintf(buf + len, "Hardware Address: %s\n",
403 print_mac(mac, dev->dev_addr));
405 return len;
406 } /* elmc_getinfo() */
408 /*****************************************************************/
410 static int __init do_elmc_probe(struct net_device *dev)
412 static int slot;
413 int base_addr = dev->base_addr;
414 int irq = dev->irq;
415 u_char status = 0;
416 u_char revision = 0;
417 int i = 0;
418 unsigned int size = 0;
419 int retval;
420 struct priv *pr = dev->priv;
421 DECLARE_MAC_BUF(mac);
423 if (MCA_bus == 0) {
424 return -ENODEV;
426 /* search through the slots for the 3c523. */
427 slot = mca_find_adapter(ELMC_MCA_ID, 0);
428 while (slot != -1) {
429 status = mca_read_stored_pos(slot, 2);
431 dev->irq=irq_table[(status & ELMC_STATUS_IRQ_SELECT) >> 6];
432 dev->base_addr=csr_table[(status & ELMC_STATUS_CSR_SELECT) >> 1];
435 If we're trying to match a specified irq or IO address,
436 we'll reject a match unless it's what we're looking for.
437 Also reject it if the card is already in use.
440 if ((irq && irq != dev->irq) ||
441 (base_addr && base_addr != dev->base_addr)) {
442 slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
443 continue;
445 if (!request_region(dev->base_addr, ELMC_IO_EXTENT, DRV_NAME)) {
446 slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
447 continue;
450 /* found what we're looking for... */
451 break;
454 /* we didn't find any 3c523 in the slots we checked for */
455 if (slot == MCA_NOTFOUND)
456 return ((base_addr || irq) ? -ENXIO : -ENODEV);
458 mca_set_adapter_name(slot, "3Com 3c523 Etherlink/MC");
459 mca_set_adapter_procfn(slot, (MCA_ProcFn) elmc_getinfo, dev);
461 /* if we get this far, adapter has been found - carry on */
462 printk(KERN_INFO "%s: 3c523 adapter found in slot %d\n", dev->name, slot + 1);
464 /* Now we extract configuration info from the card.
465 The 3c523 provides information in two of the POS registers, but
466 the second one is only needed if we want to tell the card what IRQ
467 to use. I suspect that whoever sets the thing up initially would
468 prefer we don't screw with those things.
470 Note that we read the status info when we found the card...
472 See 3c523.h for more details.
475 /* revision is stored in the first 4 bits of the revision register */
476 revision = inb(dev->base_addr + ELMC_REVISION) & 0xf;
478 /* according to docs, we read the interrupt and write it back to
479 the IRQ select register, since the POST might not configure the IRQ
480 properly. */
481 switch (dev->irq) {
482 case 3:
483 mca_write_pos(slot, 3, 0x04);
484 break;
485 case 7:
486 mca_write_pos(slot, 3, 0x02);
487 break;
488 case 9:
489 mca_write_pos(slot, 3, 0x08);
490 break;
491 case 12:
492 mca_write_pos(slot, 3, 0x01);
493 break;
496 memset(pr, 0, sizeof(struct priv));
497 pr->slot = slot;
499 printk(KERN_INFO "%s: 3Com 3c523 Rev 0x%x at %#lx\n", dev->name, (int) revision,
500 dev->base_addr);
502 /* Determine if we're using the on-board transceiver (i.e. coax) or
503 an external one. The information is pretty much useless, but I
504 guess it's worth brownie points. */
505 dev->if_port = (status & ELMC_STATUS_DISABLE_THIN);
507 /* The 3c523 has a 24K chunk of memory. The first 16K is the
508 shared memory, while the last 8K is for the EtherStart BIOS ROM.
509 Which we don't care much about here. We'll just tell Linux that
510 we're using 16K. MCA won't permit address space conflicts caused
511 by not mapping the other 8K. */
512 dev->mem_start = shm_table[(status & ELMC_STATUS_MEMORY_SELECT) >> 3];
514 /* We're using MCA, so it's a given that the information about memory
515 size is correct. The Crynwr drivers do something like this. */
517 elmc_id_reset586(); /* seems like a good idea before checking it... */
519 size = 0x4000; /* check for 16K mem */
520 if (!check586(dev, dev->mem_start, size)) {
521 printk(KERN_ERR "%s: memprobe, Can't find memory at 0x%lx!\n", dev->name,
522 dev->mem_start);
523 retval = -ENODEV;
524 goto err_out;
526 dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */
528 pr->memtop = isa_bus_to_virt(dev->mem_start) + size;
529 pr->base = (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000;
530 alloc586(dev);
532 elmc_id_reset586(); /* make sure it doesn't generate spurious ints */
534 /* set number of receive-buffs according to memsize */
535 pr->num_recv_buffs = NUM_RECV_BUFFS_16;
537 /* dump all the assorted information */
538 printk(KERN_INFO "%s: IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev->name,
539 dev->irq, dev->if_port ? "ex" : "in",
540 dev->mem_start, dev->mem_end - 1);
542 /* The hardware address for the 3c523 is stored in the first six
543 bytes of the IO address. */
544 for (i = 0; i < 6; i++)
545 dev->dev_addr[i] = inb(dev->base_addr + i);
547 printk(KERN_INFO "%s: hardware address %s\n",
548 dev->name, print_mac(mac, dev->dev_addr));
550 dev->open = &elmc_open;
551 dev->stop = &elmc_close;
552 dev->get_stats = &elmc_get_stats;
553 dev->hard_start_xmit = &elmc_send_packet;
554 dev->tx_timeout = &elmc_timeout;
555 dev->watchdog_timeo = HZ;
556 #ifdef ELMC_MULTICAST
557 dev->set_multicast_list = &set_multicast_list;
558 #else
559 dev->set_multicast_list = NULL;
560 #endif
561 dev->ethtool_ops = &netdev_ethtool_ops;
563 /* note that we haven't actually requested the IRQ from the kernel.
564 That gets done in elmc_open(). I'm not sure that's such a good idea,
565 but it works, so I'll go with it. */
567 #ifndef ELMC_MULTICAST
568 dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */
569 #endif
571 retval = register_netdev(dev);
572 if (retval)
573 goto err_out;
575 return 0;
576 err_out:
577 mca_set_adapter_procfn(slot, NULL, NULL);
578 release_region(dev->base_addr, ELMC_IO_EXTENT);
579 return retval;
582 static void cleanup_card(struct net_device *dev)
584 mca_set_adapter_procfn(((struct priv *) (dev->priv))->slot, NULL, NULL);
585 release_region(dev->base_addr, ELMC_IO_EXTENT);
588 #ifndef MODULE
589 struct net_device * __init elmc_probe(int unit)
591 struct net_device *dev = alloc_etherdev(sizeof(struct priv));
592 int err;
594 if (!dev)
595 return ERR_PTR(-ENOMEM);
597 sprintf(dev->name, "eth%d", unit);
598 netdev_boot_setup_check(dev);
600 err = do_elmc_probe(dev);
601 if (err)
602 goto out;
603 return dev;
604 out:
605 free_netdev(dev);
606 return ERR_PTR(err);
608 #endif
610 /**********************************************
611 * init the chip (elmc-interrupt should be disabled?!)
612 * needs a correct 'allocated' memory
615 static int init586(struct net_device *dev)
617 void *ptr;
618 unsigned long s;
619 int i, result = 0;
620 struct priv *p = (struct priv *) dev->priv;
621 volatile struct configure_cmd_struct *cfg_cmd;
622 volatile struct iasetup_cmd_struct *ias_cmd;
623 volatile struct tdr_cmd_struct *tdr_cmd;
624 volatile struct mcsetup_cmd_struct *mc_cmd;
625 struct dev_mc_list *dmi = dev->mc_list;
626 int num_addrs = dev->mc_count;
628 ptr = (void *) ((char *) p->scb + sizeof(struct scb_struct));
630 cfg_cmd = (struct configure_cmd_struct *) ptr; /* configure-command */
631 cfg_cmd->cmd_status = 0;
632 cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST;
633 cfg_cmd->cmd_link = 0xffff;
635 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */
636 cfg_cmd->fifo = 0x08; /* fifo-limit (8=tx:32/rx:64) */
637 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
638 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
639 cfg_cmd->priority = 0x00;
640 cfg_cmd->ifs = 0x60;
641 cfg_cmd->time_low = 0x00;
642 cfg_cmd->time_high = 0xf2;
643 cfg_cmd->promisc = 0;
644 if (dev->flags & (IFF_ALLMULTI | IFF_PROMISC)) {
645 cfg_cmd->promisc = 1;
646 dev->flags |= IFF_PROMISC;
648 cfg_cmd->carr_coll = 0x00;
650 p->scb->cbl_offset = make16(cfg_cmd);
652 p->scb->cmd = CUC_START; /* cmd.-unit start */
653 elmc_id_attn586();
655 s = jiffies; /* warning: only active with interrupts on !! */
656 while (!(cfg_cmd->cmd_status & STAT_COMPL)) {
657 if (time_after(jiffies, s + 30*HZ/100))
658 break;
661 if ((cfg_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_COMPL | STAT_OK)) {
662 printk(KERN_WARNING "%s (elmc): configure command failed: %x\n", dev->name, cfg_cmd->cmd_status);
663 return 1;
666 * individual address setup
668 ias_cmd = (struct iasetup_cmd_struct *) ptr;
670 ias_cmd->cmd_status = 0;
671 ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST;
672 ias_cmd->cmd_link = 0xffff;
674 memcpy((char *) &ias_cmd->iaddr, (char *) dev->dev_addr, ETH_ALEN);
676 p->scb->cbl_offset = make16(ias_cmd);
678 p->scb->cmd = CUC_START; /* cmd.-unit start */
679 elmc_id_attn586();
681 s = jiffies;
682 while (!(ias_cmd->cmd_status & STAT_COMPL)) {
683 if (time_after(jiffies, s + 30*HZ/100))
684 break;
687 if ((ias_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_OK | STAT_COMPL)) {
688 printk(KERN_WARNING "%s (elmc): individual address setup command failed: %04x\n", dev->name, ias_cmd->cmd_status);
689 return 1;
692 * TDR, wire check .. e.g. no resistor e.t.c
694 tdr_cmd = (struct tdr_cmd_struct *) ptr;
696 tdr_cmd->cmd_status = 0;
697 tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST;
698 tdr_cmd->cmd_link = 0xffff;
699 tdr_cmd->status = 0;
701 p->scb->cbl_offset = make16(tdr_cmd);
703 p->scb->cmd = CUC_START; /* cmd.-unit start */
704 elmc_attn586();
706 s = jiffies;
707 while (!(tdr_cmd->cmd_status & STAT_COMPL)) {
708 if (time_after(jiffies, s + 30*HZ/100)) {
709 printk(KERN_WARNING "%s: %d Problems while running the TDR.\n", dev->name, __LINE__);
710 result = 1;
711 break;
715 if (!result) {
716 DELAY(2); /* wait for result */
717 result = tdr_cmd->status;
719 p->scb->cmd = p->scb->status & STAT_MASK;
720 elmc_id_attn586(); /* ack the interrupts */
722 if (result & TDR_LNK_OK) {
723 /* empty */
724 } else if (result & TDR_XCVR_PRB) {
725 printk(KERN_WARNING "%s: TDR: Transceiver problem!\n", dev->name);
726 } else if (result & TDR_ET_OPN) {
727 printk(KERN_WARNING "%s: TDR: No correct termination %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
728 } else if (result & TDR_ET_SRT) {
729 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
730 printk(KERN_WARNING "%s: TDR: Detected a short circuit %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
731 } else {
732 printk(KERN_WARNING "%s: TDR: Unknown status %04x\n", dev->name, result);
736 * ack interrupts
738 p->scb->cmd = p->scb->status & STAT_MASK;
739 elmc_id_attn586();
742 * alloc nop/xmit-cmds
744 #if (NUM_XMIT_BUFFS == 1)
745 for (i = 0; i < 2; i++) {
746 p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
747 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
748 p->nop_cmds[i]->cmd_status = 0;
749 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
750 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
752 p->xmit_cmds[0] = (struct transmit_cmd_struct *) ptr; /* transmit cmd/buff 0 */
753 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
754 #else
755 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
756 p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
757 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
758 p->nop_cmds[i]->cmd_status = 0;
759 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
760 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
761 p->xmit_cmds[i] = (struct transmit_cmd_struct *) ptr; /*transmit cmd/buff 0 */
762 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
764 #endif
766 ptr = alloc_rfa(dev, (void *) ptr); /* init receive-frame-area */
769 * Multicast setup
772 if (dev->mc_count) {
773 /* I don't understand this: do we really need memory after the init? */
774 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
775 if (len <= 0) {
776 printk(KERN_ERR "%s: Ooooops, no memory for MC-Setup!\n", dev->name);
777 } else {
778 if (len < num_addrs) {
779 num_addrs = len;
780 printk(KERN_WARNING "%s: Sorry, can only apply %d MC-Address(es).\n",
781 dev->name, num_addrs);
783 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
784 mc_cmd->cmd_status = 0;
785 mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
786 mc_cmd->cmd_link = 0xffff;
787 mc_cmd->mc_cnt = num_addrs * 6;
788 for (i = 0; i < num_addrs; i++) {
789 memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr, 6);
790 dmi = dmi->next;
792 p->scb->cbl_offset = make16(mc_cmd);
793 p->scb->cmd = CUC_START;
794 elmc_id_attn586();
795 s = jiffies;
796 while (!(mc_cmd->cmd_status & STAT_COMPL)) {
797 if (time_after(jiffies, s + 30*HZ/100))
798 break;
800 if (!(mc_cmd->cmd_status & STAT_COMPL)) {
801 printk(KERN_WARNING "%s: Can't apply multicast-address-list.\n", dev->name);
806 * alloc xmit-buffs / init xmit_cmds
808 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
809 p->xmit_cbuffs[i] = (char *) ptr; /* char-buffs */
810 ptr = (char *) ptr + XMIT_BUFF_SIZE;
811 p->xmit_buffs[i] = (struct tbd_struct *) ptr; /* TBD */
812 ptr = (char *) ptr + sizeof(struct tbd_struct);
813 if ((void *) ptr > (void *) p->iscp) {
814 printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", dev->name);
815 return 1;
817 memset((char *) (p->xmit_cmds[i]), 0, sizeof(struct transmit_cmd_struct));
818 memset((char *) (p->xmit_buffs[i]), 0, sizeof(struct tbd_struct));
819 p->xmit_cmds[i]->cmd_status = STAT_COMPL;
820 p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT;
821 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
822 p->xmit_buffs[i]->next = 0xffff;
823 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
826 p->xmit_count = 0;
827 p->xmit_last = 0;
828 #ifndef NO_NOPCOMMANDS
829 p->nop_point = 0;
830 #endif
833 * 'start transmitter' (nop-loop)
835 #ifndef NO_NOPCOMMANDS
836 p->scb->cbl_offset = make16(p->nop_cmds[0]);
837 p->scb->cmd = CUC_START;
838 elmc_id_attn586();
839 WAIT_4_SCB_CMD();
840 #else
841 p->xmit_cmds[0]->cmd_link = 0xffff;
842 p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_LAST | CMD_INT;
843 #endif
845 return 0;
848 /******************************************************
849 * This is a helper routine for elmc_rnr_int() and init586().
850 * It sets up the Receive Frame Area (RFA).
853 static void *alloc_rfa(struct net_device *dev, void *ptr)
855 volatile struct rfd_struct *rfd = (struct rfd_struct *) ptr;
856 volatile struct rbd_struct *rbd;
857 int i;
858 struct priv *p = (struct priv *) dev->priv;
860 memset((char *) rfd, 0, sizeof(struct rfd_struct) * p->num_recv_buffs);
861 p->rfd_first = rfd;
863 for (i = 0; i < p->num_recv_buffs; i++) {
864 rfd[i].next = make16(rfd + (i + 1) % p->num_recv_buffs);
866 rfd[p->num_recv_buffs - 1].last = RFD_SUSP; /* RU suspend */
868 ptr = (void *) (rfd + p->num_recv_buffs);
870 rbd = (struct rbd_struct *) ptr;
871 ptr = (void *) (rbd + p->num_recv_buffs);
873 /* clr descriptors */
874 memset((char *) rbd, 0, sizeof(struct rbd_struct) * p->num_recv_buffs);
876 for (i = 0; i < p->num_recv_buffs; i++) {
877 rbd[i].next = make16((rbd + (i + 1) % p->num_recv_buffs));
878 rbd[i].size = RECV_BUFF_SIZE;
879 rbd[i].buffer = make24(ptr);
880 ptr = (char *) ptr + RECV_BUFF_SIZE;
883 p->rfd_top = p->rfd_first;
884 p->rfd_last = p->rfd_first + p->num_recv_buffs - 1;
886 p->scb->rfa_offset = make16(p->rfd_first);
887 p->rfd_first->rbd_offset = make16(rbd);
889 return ptr;
893 /**************************************************
894 * Interrupt Handler ...
897 static irqreturn_t
898 elmc_interrupt(int irq, void *dev_id)
900 struct net_device *dev = dev_id;
901 unsigned short stat;
902 struct priv *p;
904 if (!netif_running(dev)) {
905 /* The 3c523 has this habit of generating interrupts during the
906 reset. I'm not sure if the ni52 has this same problem, but it's
907 really annoying if we haven't finished initializing it. I was
908 hoping all the elmc_id_* commands would disable this, but I
909 might have missed a few. */
911 elmc_id_attn586(); /* ack inter. and disable any more */
912 return IRQ_HANDLED;
913 } else if (!(ELMC_CTRL_INT & inb(dev->base_addr + ELMC_CTRL))) {
914 /* wasn't this device */
915 return IRQ_NONE;
917 /* reading ELMC_CTRL also clears the INT bit. */
919 p = (struct priv *) dev->priv;
921 while ((stat = p->scb->status & STAT_MASK))
923 p->scb->cmd = stat;
924 elmc_attn586(); /* ack inter. */
926 if (stat & STAT_CX) {
927 /* command with I-bit set complete */
928 elmc_xmt_int(dev);
930 if (stat & STAT_FR) {
931 /* received a frame */
932 elmc_rcv_int(dev);
934 #ifndef NO_NOPCOMMANDS
935 if (stat & STAT_CNA) {
936 /* CU went 'not ready' */
937 if (netif_running(dev)) {
938 printk(KERN_WARNING "%s: oops! CU has left active state. stat: %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status);
941 #endif
943 if (stat & STAT_RNR) {
944 /* RU went 'not ready' */
946 if (p->scb->status & RU_SUSPEND) {
947 /* special case: RU_SUSPEND */
949 WAIT_4_SCB_CMD();
950 p->scb->cmd = RUC_RESUME;
951 elmc_attn586();
952 } else {
953 printk(KERN_WARNING "%s: Receiver-Unit went 'NOT READY': %04x/%04x.\n", dev->name, (int) stat, (int) p->scb->status);
954 elmc_rnr_int(dev);
957 WAIT_4_SCB_CMD(); /* wait for ack. (elmc_xmt_int can be faster than ack!!) */
958 if (p->scb->cmd) { /* timed out? */
959 break;
962 return IRQ_HANDLED;
965 /*******************************************************
966 * receive-interrupt
969 static void elmc_rcv_int(struct net_device *dev)
971 int status;
972 unsigned short totlen;
973 struct sk_buff *skb;
974 struct rbd_struct *rbd;
975 struct priv *p = (struct priv *) dev->priv;
977 for (; (status = p->rfd_top->status) & STAT_COMPL;) {
978 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
980 if (status & STAT_OK) { /* frame received without error? */
981 if ((totlen = rbd->status) & RBD_LAST) { /* the first and the last buffer? */
982 totlen &= RBD_MASK; /* length of this frame */
983 rbd->status = 0;
984 skb = (struct sk_buff *) dev_alloc_skb(totlen + 2);
985 if (skb != NULL) {
986 skb_reserve(skb, 2); /* 16 byte alignment */
987 skb_put(skb,totlen);
988 skb_copy_to_linear_data(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen);
989 skb->protocol = eth_type_trans(skb, dev);
990 netif_rx(skb);
991 dev->last_rx = jiffies;
992 p->stats.rx_packets++;
993 p->stats.rx_bytes += totlen;
994 } else {
995 p->stats.rx_dropped++;
997 } else {
998 printk(KERN_WARNING "%s: received oversized frame.\n", dev->name);
999 p->stats.rx_dropped++;
1001 } else { /* frame !(ok), only with 'save-bad-frames' */
1002 printk(KERN_WARNING "%s: oops! rfd-error-status: %04x\n", dev->name, status);
1003 p->stats.rx_errors++;
1005 p->rfd_top->status = 0;
1006 p->rfd_top->last = RFD_SUSP;
1007 p->rfd_last->last = 0; /* delete RU_SUSP */
1008 p->rfd_last = p->rfd_top;
1009 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
1013 /**********************************************************
1014 * handle 'Receiver went not ready'.
1017 static void elmc_rnr_int(struct net_device *dev)
1019 struct priv *p = (struct priv *) dev->priv;
1021 p->stats.rx_errors++;
1023 WAIT_4_SCB_CMD(); /* wait for the last cmd */
1024 p->scb->cmd = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
1025 elmc_attn586();
1026 WAIT_4_SCB_CMD(); /* wait for accept cmd. */
1028 alloc_rfa(dev, (char *) p->rfd_first);
1029 startrecv586(dev); /* restart RU */
1031 printk(KERN_WARNING "%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->status);
1035 /**********************************************************
1036 * handle xmit - interrupt
1039 static void elmc_xmt_int(struct net_device *dev)
1041 int status;
1042 struct priv *p = (struct priv *) dev->priv;
1044 status = p->xmit_cmds[p->xmit_last]->cmd_status;
1045 if (!(status & STAT_COMPL)) {
1046 printk(KERN_WARNING "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
1048 if (status & STAT_OK) {
1049 p->stats.tx_packets++;
1050 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
1051 } else {
1052 p->stats.tx_errors++;
1053 if (status & TCMD_LATECOLL) {
1054 printk(KERN_WARNING "%s: late collision detected.\n", dev->name);
1055 p->stats.collisions++;
1056 } else if (status & TCMD_NOCARRIER) {
1057 p->stats.tx_carrier_errors++;
1058 printk(KERN_WARNING "%s: no carrier detected.\n", dev->name);
1059 } else if (status & TCMD_LOSTCTS) {
1060 printk(KERN_WARNING "%s: loss of CTS detected.\n", dev->name);
1061 } else if (status & TCMD_UNDERRUN) {
1062 p->stats.tx_fifo_errors++;
1063 printk(KERN_WARNING "%s: DMA underrun detected.\n", dev->name);
1064 } else if (status & TCMD_MAXCOLL) {
1065 printk(KERN_WARNING "%s: Max. collisions exceeded.\n", dev->name);
1066 p->stats.collisions += 16;
1070 #if (NUM_XMIT_BUFFS != 1)
1071 if ((++p->xmit_last) == NUM_XMIT_BUFFS) {
1072 p->xmit_last = 0;
1074 #endif
1076 netif_wake_queue(dev);
1079 /***********************************************************
1080 * (re)start the receiver
1083 static void startrecv586(struct net_device *dev)
1085 struct priv *p = (struct priv *) dev->priv;
1087 p->scb->rfa_offset = make16(p->rfd_first);
1088 p->scb->cmd = RUC_START;
1089 elmc_attn586(); /* start cmd. */
1090 WAIT_4_SCB_CMD(); /* wait for accept cmd. (no timeout!!) */
1093 /******************************************************
1094 * timeout
1097 static void elmc_timeout(struct net_device *dev)
1099 struct priv *p = (struct priv *) dev->priv;
1100 /* COMMAND-UNIT active? */
1101 if (p->scb->status & CU_ACTIVE) {
1102 #ifdef DEBUG
1103 printk("%s: strange ... timeout with CU active?!?\n", dev->name);
1104 printk("%s: X0: %04x N0: %04x N1: %04x %d\n", dev->name, (int) p->xmit_cmds[0]->cmd_status, (int) p->nop_cmds[0]->cmd_status, (int) p->nop_cmds[1]->cmd_status, (int) p->nop_point);
1105 #endif
1106 p->scb->cmd = CUC_ABORT;
1107 elmc_attn586();
1108 WAIT_4_SCB_CMD();
1109 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
1110 p->scb->cmd = CUC_START;
1111 elmc_attn586();
1112 WAIT_4_SCB_CMD();
1113 netif_wake_queue(dev);
1114 } else {
1115 #ifdef DEBUG
1116 printk("%s: xmitter timed out, try to restart! stat: %04x\n", dev->name, p->scb->status);
1117 printk("%s: command-stats: %04x %04x\n", dev->name, p->xmit_cmds[0]->cmd_status, p->xmit_cmds[1]->cmd_status);
1118 #endif
1119 elmc_close(dev);
1120 elmc_open(dev);
1124 /******************************************************
1125 * send frame
1128 static int elmc_send_packet(struct sk_buff *skb, struct net_device *dev)
1130 int len;
1131 int i;
1132 #ifndef NO_NOPCOMMANDS
1133 int next_nop;
1134 #endif
1135 struct priv *p = (struct priv *) dev->priv;
1137 netif_stop_queue(dev);
1139 len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
1141 if (len != skb->len)
1142 memset((char *) p->xmit_cbuffs[p->xmit_count], 0, ETH_ZLEN);
1143 skb_copy_from_linear_data(skb, (char *) p->xmit_cbuffs[p->xmit_count], skb->len);
1145 #if (NUM_XMIT_BUFFS == 1)
1146 #ifdef NO_NOPCOMMANDS
1147 p->xmit_buffs[0]->size = TBD_LAST | len;
1148 for (i = 0; i < 16; i++) {
1149 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1150 p->scb->cmd = CUC_START;
1151 p->xmit_cmds[0]->cmd_status = 0;
1152 elmc_attn586();
1153 dev->trans_start = jiffies;
1154 if (!i) {
1155 dev_kfree_skb(skb);
1157 WAIT_4_SCB_CMD();
1158 if ((p->scb->status & CU_ACTIVE)) { /* test it, because CU sometimes doesn't start immediately */
1159 break;
1161 if (p->xmit_cmds[0]->cmd_status) {
1162 break;
1164 if (i == 15) {
1165 printk(KERN_WARNING "%s: Can't start transmit-command.\n", dev->name);
1168 #else
1169 next_nop = (p->nop_point + 1) & 0x1;
1170 p->xmit_buffs[0]->size = TBD_LAST | len;
1172 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1173 = make16((p->nop_cmds[next_nop]));
1174 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1176 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
1177 dev->trans_start = jiffies;
1178 p->nop_point = next_nop;
1179 dev_kfree_skb(skb);
1180 #endif
1181 #else
1182 p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len;
1183 if ((next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS) {
1184 next_nop = 0;
1186 p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1187 p->xmit_cmds[p->xmit_count]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1188 = make16((p->nop_cmds[next_nop]));
1189 p->nop_cmds[next_nop]->cmd_status = 0;
1190 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
1191 dev->trans_start = jiffies;
1192 p->xmit_count = next_nop;
1193 if (p->xmit_count != p->xmit_last)
1194 netif_wake_queue(dev);
1195 dev_kfree_skb(skb);
1196 #endif
1197 return 0;
1200 /*******************************************
1201 * Someone wanna have the statistics
1204 static struct net_device_stats *elmc_get_stats(struct net_device *dev)
1206 struct priv *p = (struct priv *) dev->priv;
1207 unsigned short crc, aln, rsc, ovrn;
1209 crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */
1210 p->scb->crc_errs -= crc;
1211 aln = p->scb->aln_errs;
1212 p->scb->aln_errs -= aln;
1213 rsc = p->scb->rsc_errs;
1214 p->scb->rsc_errs -= rsc;
1215 ovrn = p->scb->ovrn_errs;
1216 p->scb->ovrn_errs -= ovrn;
1218 p->stats.rx_crc_errors += crc;
1219 p->stats.rx_fifo_errors += ovrn;
1220 p->stats.rx_frame_errors += aln;
1221 p->stats.rx_dropped += rsc;
1223 return &p->stats;
1226 /********************************************************
1227 * Set MC list ..
1230 #ifdef ELMC_MULTICAST
1231 static void set_multicast_list(struct net_device *dev)
1233 if (!dev->start) {
1234 /* without a running interface, promiscuous doesn't work */
1235 return;
1237 dev->start = 0;
1238 alloc586(dev);
1239 init586(dev);
1240 startrecv586(dev);
1241 dev->start = 1;
1243 #endif
1245 static void netdev_get_drvinfo(struct net_device *dev,
1246 struct ethtool_drvinfo *info)
1248 strcpy(info->driver, DRV_NAME);
1249 strcpy(info->version, DRV_VERSION);
1250 sprintf(info->bus_info, "MCA 0x%lx", dev->base_addr);
1253 static const struct ethtool_ops netdev_ethtool_ops = {
1254 .get_drvinfo = netdev_get_drvinfo,
1257 #ifdef MODULE
1259 /* Increase if needed ;) */
1260 #define MAX_3C523_CARDS 4
1262 static struct net_device *dev_elmc[MAX_3C523_CARDS];
1263 static int irq[MAX_3C523_CARDS];
1264 static int io[MAX_3C523_CARDS];
1265 module_param_array(irq, int, NULL, 0);
1266 module_param_array(io, int, NULL, 0);
1267 MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)");
1268 MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)");
1269 MODULE_LICENSE("GPL");
1271 int __init init_module(void)
1273 int this_dev,found = 0;
1275 /* Loop until we either can't find any more cards, or we have MAX_3C523_CARDS */
1276 for(this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) {
1277 struct net_device *dev = alloc_etherdev(sizeof(struct priv));
1278 if (!dev)
1279 break;
1280 dev->irq=irq[this_dev];
1281 dev->base_addr=io[this_dev];
1282 if (do_elmc_probe(dev) == 0) {
1283 dev_elmc[this_dev] = dev;
1284 found++;
1285 continue;
1287 free_netdev(dev);
1288 if (io[this_dev]==0)
1289 break;
1290 printk(KERN_WARNING "3c523.c: No 3c523 card found at io=%#x\n",io[this_dev]);
1293 if(found==0) {
1294 if(io[0]==0) printk(KERN_NOTICE "3c523.c: No 3c523 cards found\n");
1295 return -ENXIO;
1296 } else return 0;
1299 void __exit cleanup_module(void)
1301 int this_dev;
1302 for (this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) {
1303 struct net_device *dev = dev_elmc[this_dev];
1304 if (dev) {
1305 unregister_netdev(dev);
1306 cleanup_card(dev);
1307 free_netdev(dev);
1312 #endif /* MODULE */