ondemand: Solve a big performance issue by counting IOWAIT time as busy
[linux/fpc-iii.git] / drivers / net / 3c523.c
blob1719079cc498f86c0289e904c3f54ce16fcbf824
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/interrupt.h>
103 #include <linux/delay.h>
104 #include <linux/mca-legacy.h>
105 #include <linux/ethtool.h>
106 #include <linux/bitops.h>
107 #include <linux/jiffies.h>
109 #include <asm/uaccess.h>
110 #include <asm/processor.h>
111 #include <asm/io.h>
113 #include "3c523.h"
115 /*************************************************************************/
116 #define DEBUG /* debug on */
117 #define SYSBUSVAL 0 /* 1 = 8 Bit, 0 = 16 bit - 3c523 only does 16 bit */
118 #undef ELMC_MULTICAST /* Disable multicast support as it is somewhat seriously broken at the moment */
120 #define make32(ptr16) (p->memtop + (short) (ptr16) )
121 #define make24(ptr32) ((char *) (ptr32) - p->base)
122 #define make16(ptr32) ((unsigned short) ((unsigned long) (ptr32) - (unsigned long) p->memtop ))
124 /*************************************************************************/
126 Tables to which we can map values in the configuration registers.
128 static int irq_table[] __initdata = {
129 12, 7, 3, 9
132 static int csr_table[] __initdata = {
133 0x300, 0x1300, 0x2300, 0x3300
136 static int shm_table[] __initdata = {
137 0x0c0000, 0x0c8000, 0x0d0000, 0x0d8000
140 /******************* how to calculate the buffers *****************************
143 * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
144 * --------------- in a different (more stable?) mode. Only in this mode it's
145 * possible to configure the driver with 'NO_NOPCOMMANDS'
147 sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
148 sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
149 sizeof(rfd) = 24; sizeof(rbd) = 12;
150 sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
151 sizeof(nop_cmd) = 8;
153 * if you don't know the driver, better do not change this values: */
155 #define RECV_BUFF_SIZE 1524 /* slightly oversized */
156 #define XMIT_BUFF_SIZE 1524 /* slightly oversized */
157 #define NUM_XMIT_BUFFS 1 /* config for both, 8K and 16K shmem */
158 #define NUM_RECV_BUFFS_8 4 /* config for 8K shared mem */
159 #define NUM_RECV_BUFFS_16 9 /* config for 16K shared mem */
161 #if (NUM_XMIT_BUFFS == 1)
162 #define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
163 #endif
165 /**************************************************************************/
167 #define DELAY(x) { mdelay(32 * x); }
169 /* a much shorter delay: */
170 #define DELAY_16(); { udelay(16) ; }
172 /* wait for command with timeout: */
173 #define WAIT_4_SCB_CMD() { int i; \
174 for(i=0;i<1024;i++) { \
175 if(!p->scb->cmd) break; \
176 DELAY_16(); \
177 if(i == 1023) { \
178 pr_warning("%s:%d: scb_cmd timed out .. resetting i82586\n",\
179 dev->name,__LINE__); \
180 elmc_id_reset586(); } } }
182 static irqreturn_t elmc_interrupt(int irq, void *dev_id);
183 static int elmc_open(struct net_device *dev);
184 static int elmc_close(struct net_device *dev);
185 static netdev_tx_t elmc_send_packet(struct sk_buff *, struct net_device *);
186 static struct net_device_stats *elmc_get_stats(struct net_device *dev);
187 static void elmc_timeout(struct net_device *dev);
188 #ifdef ELMC_MULTICAST
189 static void set_multicast_list(struct net_device *dev);
190 #endif
191 static const struct ethtool_ops netdev_ethtool_ops;
193 /* helper-functions */
194 static int init586(struct net_device *dev);
195 static int check586(struct net_device *dev, unsigned long where, unsigned size);
196 static void alloc586(struct net_device *dev);
197 static void startrecv586(struct net_device *dev);
198 static void *alloc_rfa(struct net_device *dev, void *ptr);
199 static void elmc_rcv_int(struct net_device *dev);
200 static void elmc_xmt_int(struct net_device *dev);
201 static void elmc_rnr_int(struct net_device *dev);
203 struct priv {
204 unsigned long base;
205 char *memtop;
206 unsigned long mapped_start; /* Start of ioremap */
207 volatile struct rfd_struct *rfd_last, *rfd_top, *rfd_first;
208 volatile struct scp_struct *scp; /* volatile is important */
209 volatile struct iscp_struct *iscp; /* volatile is important */
210 volatile struct scb_struct *scb; /* volatile is important */
211 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
212 #if (NUM_XMIT_BUFFS == 1)
213 volatile struct transmit_cmd_struct *xmit_cmds[2];
214 volatile struct nop_cmd_struct *nop_cmds[2];
215 #else
216 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
217 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
218 #endif
219 volatile int nop_point, num_recv_buffs;
220 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
221 volatile int xmit_count, xmit_last;
222 volatile int slot;
225 #define elmc_attn586() {elmc_do_attn586(dev->base_addr,ELMC_CTRL_INTE);}
226 #define elmc_reset586() {elmc_do_reset586(dev->base_addr,ELMC_CTRL_INTE);}
228 /* with interrupts disabled - this will clear the interrupt bit in the
229 3c523 control register, and won't put it back. This effectively
230 disables interrupts on the card. */
231 #define elmc_id_attn586() {elmc_do_attn586(dev->base_addr,0);}
232 #define elmc_id_reset586() {elmc_do_reset586(dev->base_addr,0);}
234 /*************************************************************************/
236 Do a Channel Attention on the 3c523. This is extremely board dependent.
238 static void elmc_do_attn586(int ioaddr, int ints)
240 /* the 3c523 requires a minimum of 500 ns. The delays here might be
241 a little too large, and hence they may cut the performance of the
242 card slightly. If someone who knows a little more about Linux
243 timing would care to play with these, I'd appreciate it. */
245 /* this bit masking stuff is crap. I'd rather have separate
246 registers with strobe triggers for each of these functions. <sigh>
247 Ya take what ya got. */
249 outb(ELMC_CTRL_RST | 0x3 | ELMC_CTRL_CA | ints, ioaddr + ELMC_CTRL);
250 DELAY_16(); /* > 500 ns */
251 outb(ELMC_CTRL_RST | 0x3 | ints, ioaddr + ELMC_CTRL);
254 /*************************************************************************/
256 Reset the 82586 on the 3c523. Also very board dependent.
258 static void elmc_do_reset586(int ioaddr, int ints)
260 /* toggle the RST bit low then high */
261 outb(0x3 | ELMC_CTRL_LBK, ioaddr + ELMC_CTRL);
262 DELAY_16(); /* > 500 ns */
263 outb(ELMC_CTRL_RST | ELMC_CTRL_LBK | 0x3, ioaddr + ELMC_CTRL);
265 elmc_do_attn586(ioaddr, ints);
268 /**********************************************
269 * close device
272 static int elmc_close(struct net_device *dev)
274 netif_stop_queue(dev);
275 elmc_id_reset586(); /* the hard way to stop the receiver */
276 free_irq(dev->irq, dev);
277 return 0;
280 /**********************************************
281 * open device
284 static int elmc_open(struct net_device *dev)
286 int ret;
288 elmc_id_attn586(); /* disable interrupts */
290 ret = request_irq(dev->irq, elmc_interrupt, IRQF_SHARED | IRQF_SAMPLE_RANDOM,
291 dev->name, dev);
292 if (ret) {
293 pr_err("%s: couldn't get irq %d\n", dev->name, dev->irq);
294 elmc_id_reset586();
295 return ret;
297 alloc586(dev);
298 init586(dev);
299 startrecv586(dev);
300 netif_start_queue(dev);
301 return 0; /* most done by init */
304 /**********************************************
305 * Check to see if there's an 82586 out there.
308 static int __init check586(struct net_device *dev, unsigned long where, unsigned size)
310 struct priv *p = netdev_priv(dev);
311 char *iscp_addrs[2];
312 int i = 0;
314 p->base = (unsigned long) isa_bus_to_virt((unsigned long)where) + size - 0x01000000;
315 p->memtop = isa_bus_to_virt((unsigned long)where) + size;
316 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
317 memset((char *) p->scp, 0, sizeof(struct scp_struct));
318 p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */
320 iscp_addrs[0] = isa_bus_to_virt((unsigned long)where);
321 iscp_addrs[1] = (char *) p->scp - sizeof(struct iscp_struct);
323 for (i = 0; i < 2; i++) {
324 p->iscp = (struct iscp_struct *) iscp_addrs[i];
325 memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
327 p->scp->iscp = make24(p->iscp);
328 p->iscp->busy = 1;
330 elmc_id_reset586();
332 /* reset586 does an implicit CA */
334 /* apparently, you sometimes have to kick the 82586 twice... */
335 elmc_id_attn586();
336 DELAY(1);
338 if (p->iscp->busy) { /* i82586 clears 'busy' after successful init */
339 return 0;
342 return 1;
345 /******************************************************************
346 * set iscp at the right place, called by elmc_probe and open586.
349 static void alloc586(struct net_device *dev)
351 struct priv *p = netdev_priv(dev);
353 elmc_id_reset586();
354 DELAY(2);
356 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
357 p->scb = (struct scb_struct *) isa_bus_to_virt(dev->mem_start);
358 p->iscp = (struct iscp_struct *) ((char *) p->scp - sizeof(struct iscp_struct));
360 memset((char *) p->iscp, 0, sizeof(struct iscp_struct));
361 memset((char *) p->scp, 0, sizeof(struct scp_struct));
363 p->scp->iscp = make24(p->iscp);
364 p->scp->sysbus = SYSBUSVAL;
365 p->iscp->scb_offset = make16(p->scb);
367 p->iscp->busy = 1;
368 elmc_id_reset586();
369 elmc_id_attn586();
371 DELAY(2);
373 if (p->iscp->busy)
374 pr_err("%s: Init-Problems (alloc).\n", dev->name);
376 memset((char *) p->scb, 0, sizeof(struct scb_struct));
379 /*****************************************************************/
381 static int elmc_getinfo(char *buf, int slot, void *d)
383 int len = 0;
384 struct net_device *dev = d;
386 if (dev == NULL)
387 return len;
389 len += sprintf(buf + len, "Revision: 0x%x\n",
390 inb(dev->base_addr + ELMC_REVISION) & 0xf);
391 len += sprintf(buf + len, "IRQ: %d\n", dev->irq);
392 len += sprintf(buf + len, "IO Address: %#lx-%#lx\n", dev->base_addr,
393 dev->base_addr + ELMC_IO_EXTENT);
394 len += sprintf(buf + len, "Memory: %#lx-%#lx\n", dev->mem_start,
395 dev->mem_end - 1);
396 len += sprintf(buf + len, "Transceiver: %s\n", dev->if_port ?
397 "External" : "Internal");
398 len += sprintf(buf + len, "Device: %s\n", dev->name);
399 len += sprintf(buf + len, "Hardware Address: %pM\n",
400 dev->dev_addr);
402 return len;
403 } /* elmc_getinfo() */
405 static const struct net_device_ops netdev_ops = {
406 .ndo_open = elmc_open,
407 .ndo_stop = elmc_close,
408 .ndo_get_stats = elmc_get_stats,
409 .ndo_start_xmit = elmc_send_packet,
410 .ndo_tx_timeout = elmc_timeout,
411 #ifdef ELMC_MULTICAST
412 .ndo_set_multicast_list = set_multicast_list,
413 #endif
414 .ndo_change_mtu = eth_change_mtu,
415 .ndo_set_mac_address = eth_mac_addr,
416 .ndo_validate_addr = eth_validate_addr,
419 /*****************************************************************/
421 static int __init do_elmc_probe(struct net_device *dev)
423 static int slot;
424 int base_addr = dev->base_addr;
425 int irq = dev->irq;
426 u_char status = 0;
427 u_char revision = 0;
428 int i = 0;
429 unsigned int size = 0;
430 int retval;
431 struct priv *pr = netdev_priv(dev);
433 if (MCA_bus == 0) {
434 return -ENODEV;
436 /* search through the slots for the 3c523. */
437 slot = mca_find_adapter(ELMC_MCA_ID, 0);
438 while (slot != -1) {
439 status = mca_read_stored_pos(slot, 2);
441 dev->irq=irq_table[(status & ELMC_STATUS_IRQ_SELECT) >> 6];
442 dev->base_addr=csr_table[(status & ELMC_STATUS_CSR_SELECT) >> 1];
445 If we're trying to match a specified irq or IO address,
446 we'll reject a match unless it's what we're looking for.
447 Also reject it if the card is already in use.
450 if ((irq && irq != dev->irq) ||
451 (base_addr && base_addr != dev->base_addr)) {
452 slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
453 continue;
455 if (!request_region(dev->base_addr, ELMC_IO_EXTENT, DRV_NAME)) {
456 slot = mca_find_adapter(ELMC_MCA_ID, slot + 1);
457 continue;
460 /* found what we're looking for... */
461 break;
464 /* we didn't find any 3c523 in the slots we checked for */
465 if (slot == MCA_NOTFOUND)
466 return ((base_addr || irq) ? -ENXIO : -ENODEV);
468 mca_set_adapter_name(slot, "3Com 3c523 Etherlink/MC");
469 mca_set_adapter_procfn(slot, (MCA_ProcFn) elmc_getinfo, dev);
471 /* if we get this far, adapter has been found - carry on */
472 pr_info("%s: 3c523 adapter found in slot %d\n", dev->name, slot + 1);
474 /* Now we extract configuration info from the card.
475 The 3c523 provides information in two of the POS registers, but
476 the second one is only needed if we want to tell the card what IRQ
477 to use. I suspect that whoever sets the thing up initially would
478 prefer we don't screw with those things.
480 Note that we read the status info when we found the card...
482 See 3c523.h for more details.
485 /* revision is stored in the first 4 bits of the revision register */
486 revision = inb(dev->base_addr + ELMC_REVISION) & 0xf;
488 /* according to docs, we read the interrupt and write it back to
489 the IRQ select register, since the POST might not configure the IRQ
490 properly. */
491 switch (dev->irq) {
492 case 3:
493 mca_write_pos(slot, 3, 0x04);
494 break;
495 case 7:
496 mca_write_pos(slot, 3, 0x02);
497 break;
498 case 9:
499 mca_write_pos(slot, 3, 0x08);
500 break;
501 case 12:
502 mca_write_pos(slot, 3, 0x01);
503 break;
506 memset(pr, 0, sizeof(struct priv));
507 pr->slot = slot;
509 pr_info("%s: 3Com 3c523 Rev 0x%x at %#lx\n", dev->name, (int) revision,
510 dev->base_addr);
512 /* Determine if we're using the on-board transceiver (i.e. coax) or
513 an external one. The information is pretty much useless, but I
514 guess it's worth brownie points. */
515 dev->if_port = (status & ELMC_STATUS_DISABLE_THIN);
517 /* The 3c523 has a 24K chunk of memory. The first 16K is the
518 shared memory, while the last 8K is for the EtherStart BIOS ROM.
519 Which we don't care much about here. We'll just tell Linux that
520 we're using 16K. MCA won't permit address space conflicts caused
521 by not mapping the other 8K. */
522 dev->mem_start = shm_table[(status & ELMC_STATUS_MEMORY_SELECT) >> 3];
524 /* We're using MCA, so it's a given that the information about memory
525 size is correct. The Crynwr drivers do something like this. */
527 elmc_id_reset586(); /* seems like a good idea before checking it... */
529 size = 0x4000; /* check for 16K mem */
530 if (!check586(dev, dev->mem_start, size)) {
531 pr_err("%s: memprobe, Can't find memory at 0x%lx!\n", dev->name,
532 dev->mem_start);
533 retval = -ENODEV;
534 goto err_out;
536 dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */
538 pr->memtop = isa_bus_to_virt(dev->mem_start) + size;
539 pr->base = (unsigned long) isa_bus_to_virt(dev->mem_start) + size - 0x01000000;
540 alloc586(dev);
542 elmc_id_reset586(); /* make sure it doesn't generate spurious ints */
544 /* set number of receive-buffs according to memsize */
545 pr->num_recv_buffs = NUM_RECV_BUFFS_16;
547 /* dump all the assorted information */
548 pr_info("%s: IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev->name,
549 dev->irq, dev->if_port ? "ex" : "in",
550 dev->mem_start, dev->mem_end - 1);
552 /* The hardware address for the 3c523 is stored in the first six
553 bytes of the IO address. */
554 for (i = 0; i < 6; i++)
555 dev->dev_addr[i] = inb(dev->base_addr + i);
557 pr_info("%s: hardware address %pM\n",
558 dev->name, dev->dev_addr);
560 dev->netdev_ops = &netdev_ops;
561 dev->watchdog_timeo = HZ;
562 dev->ethtool_ops = &netdev_ethtool_ops;
564 /* note that we haven't actually requested the IRQ from the kernel.
565 That gets done in elmc_open(). I'm not sure that's such a good idea,
566 but it works, so I'll go with it. */
568 #ifndef ELMC_MULTICAST
569 dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */
570 #endif
572 retval = register_netdev(dev);
573 if (retval)
574 goto err_out;
576 return 0;
577 err_out:
578 mca_set_adapter_procfn(slot, NULL, NULL);
579 release_region(dev->base_addr, ELMC_IO_EXTENT);
580 return retval;
583 #ifdef MODULE
584 static void cleanup_card(struct net_device *dev)
586 mca_set_adapter_procfn(((struct priv *)netdev_priv(dev))->slot,
587 NULL, NULL);
588 release_region(dev->base_addr, ELMC_IO_EXTENT);
590 #else
591 struct net_device * __init elmc_probe(int unit)
593 struct net_device *dev = alloc_etherdev(sizeof(struct priv));
594 int err;
596 if (!dev)
597 return ERR_PTR(-ENOMEM);
599 sprintf(dev->name, "eth%d", unit);
600 netdev_boot_setup_check(dev);
602 err = do_elmc_probe(dev);
603 if (err)
604 goto out;
605 return dev;
606 out:
607 free_netdev(dev);
608 return ERR_PTR(err);
610 #endif
612 /**********************************************
613 * init the chip (elmc-interrupt should be disabled?!)
614 * needs a correct 'allocated' memory
617 static int init586(struct net_device *dev)
619 void *ptr;
620 unsigned long s;
621 int i, result = 0;
622 struct priv *p = netdev_priv(dev);
623 volatile struct configure_cmd_struct *cfg_cmd;
624 volatile struct iasetup_cmd_struct *ias_cmd;
625 volatile struct tdr_cmd_struct *tdr_cmd;
626 volatile struct mcsetup_cmd_struct *mc_cmd;
627 struct dev_mc_list *dmi;
628 int num_addrs = netdev_mc_count(dev);
630 ptr = (void *) ((char *) p->scb + sizeof(struct scb_struct));
632 cfg_cmd = (struct configure_cmd_struct *) ptr; /* configure-command */
633 cfg_cmd->cmd_status = 0;
634 cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST;
635 cfg_cmd->cmd_link = 0xffff;
637 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */
638 cfg_cmd->fifo = 0x08; /* fifo-limit (8=tx:32/rx:64) */
639 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
640 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
641 cfg_cmd->priority = 0x00;
642 cfg_cmd->ifs = 0x60;
643 cfg_cmd->time_low = 0x00;
644 cfg_cmd->time_high = 0xf2;
645 cfg_cmd->promisc = 0;
646 if (dev->flags & (IFF_ALLMULTI | IFF_PROMISC))
647 cfg_cmd->promisc = 1;
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 pr_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 pr_warning("%s (elmc): individual address setup command failed: %04x\n",
689 dev->name, ias_cmd->cmd_status);
690 return 1;
693 * TDR, wire check .. e.g. no resistor e.t.c
695 tdr_cmd = (struct tdr_cmd_struct *) ptr;
697 tdr_cmd->cmd_status = 0;
698 tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST;
699 tdr_cmd->cmd_link = 0xffff;
700 tdr_cmd->status = 0;
702 p->scb->cbl_offset = make16(tdr_cmd);
704 p->scb->cmd = CUC_START; /* cmd.-unit start */
705 elmc_attn586();
707 s = jiffies;
708 while (!(tdr_cmd->cmd_status & STAT_COMPL)) {
709 if (time_after(jiffies, s + 30*HZ/100)) {
710 pr_warning("%s: %d Problems while running the TDR.\n", dev->name, __LINE__);
711 result = 1;
712 break;
716 if (!result) {
717 DELAY(2); /* wait for result */
718 result = tdr_cmd->status;
720 p->scb->cmd = p->scb->status & STAT_MASK;
721 elmc_id_attn586(); /* ack the interrupts */
723 if (result & TDR_LNK_OK) {
724 /* empty */
725 } else if (result & TDR_XCVR_PRB) {
726 pr_warning("%s: TDR: Transceiver problem!\n", dev->name);
727 } else if (result & TDR_ET_OPN) {
728 pr_warning("%s: TDR: No correct termination %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
729 } else if (result & TDR_ET_SRT) {
730 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
731 pr_warning("%s: TDR: Detected a short circuit %d clocks away.\n", dev->name, result & TDR_TIMEMASK);
732 } else {
733 pr_warning("%s: TDR: Unknown status %04x\n", dev->name, result);
737 * ack interrupts
739 p->scb->cmd = p->scb->status & STAT_MASK;
740 elmc_id_attn586();
743 * alloc nop/xmit-cmds
745 #if (NUM_XMIT_BUFFS == 1)
746 for (i = 0; i < 2; i++) {
747 p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
748 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
749 p->nop_cmds[i]->cmd_status = 0;
750 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
751 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
753 p->xmit_cmds[0] = (struct transmit_cmd_struct *) ptr; /* transmit cmd/buff 0 */
754 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
755 #else
756 for (i = 0; i < NUM_XMIT_BUFFS; i++) {
757 p->nop_cmds[i] = (struct nop_cmd_struct *) ptr;
758 p->nop_cmds[i]->cmd_cmd = CMD_NOP;
759 p->nop_cmds[i]->cmd_status = 0;
760 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
761 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
762 p->xmit_cmds[i] = (struct transmit_cmd_struct *) ptr; /*transmit cmd/buff 0 */
763 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
765 #endif
767 ptr = alloc_rfa(dev, (void *) ptr); /* init receive-frame-area */
770 * Multicast setup
773 if (num_addrs) {
774 /* I don't understand this: do we really need memory after the init? */
775 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
776 if (len <= 0) {
777 pr_err("%s: Ooooops, no memory for MC-Setup!\n", dev->name);
778 } else {
779 if (len < num_addrs) {
780 num_addrs = len;
781 pr_warning("%s: Sorry, can only apply %d MC-Address(es).\n",
782 dev->name, num_addrs);
784 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
785 mc_cmd->cmd_status = 0;
786 mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST;
787 mc_cmd->cmd_link = 0xffff;
788 mc_cmd->mc_cnt = num_addrs * 6;
789 i = 0;
790 netdev_for_each_mc_addr(dmi, dev)
791 memcpy((char *) mc_cmd->mc_list[i++], dmi->dmi_addr, 6);
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 pr_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 pr_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 = netdev_priv(dev);
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 = netdev_priv(dev);
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 pr_warning("%s: oops! CU has left active state. stat: %04x/%04x.\n",
939 dev->name, (int) stat, (int) p->scb->status);
942 #endif
944 if (stat & STAT_RNR) {
945 /* RU went 'not ready' */
947 if (p->scb->status & RU_SUSPEND) {
948 /* special case: RU_SUSPEND */
950 WAIT_4_SCB_CMD();
951 p->scb->cmd = RUC_RESUME;
952 elmc_attn586();
953 } else {
954 pr_warning("%s: Receiver-Unit went 'NOT READY': %04x/%04x.\n",
955 dev->name, (int) stat, (int) p->scb->status);
956 elmc_rnr_int(dev);
959 WAIT_4_SCB_CMD(); /* wait for ack. (elmc_xmt_int can be faster than ack!!) */
960 if (p->scb->cmd) { /* timed out? */
961 break;
964 return IRQ_HANDLED;
967 /*******************************************************
968 * receive-interrupt
971 static void elmc_rcv_int(struct net_device *dev)
973 int status;
974 unsigned short totlen;
975 struct sk_buff *skb;
976 struct rbd_struct *rbd;
977 struct priv *p = netdev_priv(dev);
979 for (; (status = p->rfd_top->status) & STAT_COMPL;) {
980 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
982 if (status & STAT_OK) { /* frame received without error? */
983 if ((totlen = rbd->status) & RBD_LAST) { /* the first and the last buffer? */
984 totlen &= RBD_MASK; /* length of this frame */
985 rbd->status = 0;
986 skb = (struct sk_buff *) dev_alloc_skb(totlen + 2);
987 if (skb != NULL) {
988 skb_reserve(skb, 2); /* 16 byte alignment */
989 skb_put(skb,totlen);
990 skb_copy_to_linear_data(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen);
991 skb->protocol = eth_type_trans(skb, dev);
992 netif_rx(skb);
993 dev->stats.rx_packets++;
994 dev->stats.rx_bytes += totlen;
995 } else {
996 dev->stats.rx_dropped++;
998 } else {
999 pr_warning("%s: received oversized frame.\n", dev->name);
1000 dev->stats.rx_dropped++;
1002 } else { /* frame !(ok), only with 'save-bad-frames' */
1003 pr_warning("%s: oops! rfd-error-status: %04x\n", dev->name, status);
1004 dev->stats.rx_errors++;
1006 p->rfd_top->status = 0;
1007 p->rfd_top->last = RFD_SUSP;
1008 p->rfd_last->last = 0; /* delete RU_SUSP */
1009 p->rfd_last = p->rfd_top;
1010 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
1014 /**********************************************************
1015 * handle 'Receiver went not ready'.
1018 static void elmc_rnr_int(struct net_device *dev)
1020 struct priv *p = netdev_priv(dev);
1022 dev->stats.rx_errors++;
1024 WAIT_4_SCB_CMD(); /* wait for the last cmd */
1025 p->scb->cmd = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
1026 elmc_attn586();
1027 WAIT_4_SCB_CMD(); /* wait for accept cmd. */
1029 alloc_rfa(dev, (char *) p->rfd_first);
1030 startrecv586(dev); /* restart RU */
1032 pr_warning("%s: Receive-Unit restarted. Status: %04x\n", dev->name, p->scb->status);
1036 /**********************************************************
1037 * handle xmit - interrupt
1040 static void elmc_xmt_int(struct net_device *dev)
1042 int status;
1043 struct priv *p = netdev_priv(dev);
1045 status = p->xmit_cmds[p->xmit_last]->cmd_status;
1046 if (!(status & STAT_COMPL)) {
1047 pr_warning("%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
1049 if (status & STAT_OK) {
1050 dev->stats.tx_packets++;
1051 dev->stats.collisions += (status & TCMD_MAXCOLLMASK);
1052 } else {
1053 dev->stats.tx_errors++;
1054 if (status & TCMD_LATECOLL) {
1055 pr_warning("%s: late collision detected.\n", dev->name);
1056 dev->stats.collisions++;
1057 } else if (status & TCMD_NOCARRIER) {
1058 dev->stats.tx_carrier_errors++;
1059 pr_warning("%s: no carrier detected.\n", dev->name);
1060 } else if (status & TCMD_LOSTCTS) {
1061 pr_warning("%s: loss of CTS detected.\n", dev->name);
1062 } else if (status & TCMD_UNDERRUN) {
1063 dev->stats.tx_fifo_errors++;
1064 pr_warning("%s: DMA underrun detected.\n", dev->name);
1065 } else if (status & TCMD_MAXCOLL) {
1066 pr_warning("%s: Max. collisions exceeded.\n", dev->name);
1067 dev->stats.collisions += 16;
1071 #if (NUM_XMIT_BUFFS != 1)
1072 if ((++p->xmit_last) == NUM_XMIT_BUFFS) {
1073 p->xmit_last = 0;
1075 #endif
1077 netif_wake_queue(dev);
1080 /***********************************************************
1081 * (re)start the receiver
1084 static void startrecv586(struct net_device *dev)
1086 struct priv *p = netdev_priv(dev);
1088 p->scb->rfa_offset = make16(p->rfd_first);
1089 p->scb->cmd = RUC_START;
1090 elmc_attn586(); /* start cmd. */
1091 WAIT_4_SCB_CMD(); /* wait for accept cmd. (no timeout!!) */
1094 /******************************************************
1095 * timeout
1098 static void elmc_timeout(struct net_device *dev)
1100 struct priv *p = netdev_priv(dev);
1101 /* COMMAND-UNIT active? */
1102 if (p->scb->status & CU_ACTIVE) {
1103 pr_debug("%s: strange ... timeout with CU active?!?\n", dev->name);
1104 pr_debug("%s: X0: %04x N0: %04x N1: %04x %d\n", dev->name,
1105 (int)p->xmit_cmds[0]->cmd_status,
1106 (int)p->nop_cmds[0]->cmd_status,
1107 (int)p->nop_cmds[1]->cmd_status, (int)p->nop_point);
1108 p->scb->cmd = CUC_ABORT;
1109 elmc_attn586();
1110 WAIT_4_SCB_CMD();
1111 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
1112 p->scb->cmd = CUC_START;
1113 elmc_attn586();
1114 WAIT_4_SCB_CMD();
1115 netif_wake_queue(dev);
1116 } else {
1117 pr_debug("%s: xmitter timed out, try to restart! stat: %04x\n",
1118 dev->name, p->scb->status);
1119 pr_debug("%s: command-stats: %04x %04x\n", dev->name,
1120 p->xmit_cmds[0]->cmd_status, p->xmit_cmds[1]->cmd_status);
1121 elmc_close(dev);
1122 elmc_open(dev);
1126 /******************************************************
1127 * send frame
1130 static netdev_tx_t elmc_send_packet(struct sk_buff *skb, struct net_device *dev)
1132 int len;
1133 int i;
1134 #ifndef NO_NOPCOMMANDS
1135 int next_nop;
1136 #endif
1137 struct priv *p = netdev_priv(dev);
1139 netif_stop_queue(dev);
1141 len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
1143 if (len != skb->len)
1144 memset((char *) p->xmit_cbuffs[p->xmit_count], 0, ETH_ZLEN);
1145 skb_copy_from_linear_data(skb, (char *) p->xmit_cbuffs[p->xmit_count], skb->len);
1147 #if (NUM_XMIT_BUFFS == 1)
1148 #ifdef NO_NOPCOMMANDS
1149 p->xmit_buffs[0]->size = TBD_LAST | len;
1150 for (i = 0; i < 16; i++) {
1151 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1152 p->scb->cmd = CUC_START;
1153 p->xmit_cmds[0]->cmd_status = 0;
1154 elmc_attn586();
1155 dev->trans_start = jiffies;
1156 if (!i) {
1157 dev_kfree_skb(skb);
1159 WAIT_4_SCB_CMD();
1160 if ((p->scb->status & CU_ACTIVE)) { /* test it, because CU sometimes doesn't start immediately */
1161 break;
1163 if (p->xmit_cmds[0]->cmd_status) {
1164 break;
1166 if (i == 15) {
1167 pr_warning("%s: Can't start transmit-command.\n", dev->name);
1170 #else
1171 next_nop = (p->nop_point + 1) & 0x1;
1172 p->xmit_buffs[0]->size = TBD_LAST | len;
1174 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1175 = make16((p->nop_cmds[next_nop]));
1176 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1178 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
1179 dev->trans_start = jiffies;
1180 p->nop_point = next_nop;
1181 dev_kfree_skb(skb);
1182 #endif
1183 #else
1184 p->xmit_buffs[p->xmit_count]->size = TBD_LAST | len;
1185 if ((next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS) {
1186 next_nop = 0;
1188 p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1189 p->xmit_cmds[p->xmit_count]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1190 = make16((p->nop_cmds[next_nop]));
1191 p->nop_cmds[next_nop]->cmd_status = 0;
1192 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
1193 dev->trans_start = jiffies;
1194 p->xmit_count = next_nop;
1195 if (p->xmit_count != p->xmit_last)
1196 netif_wake_queue(dev);
1197 dev_kfree_skb(skb);
1198 #endif
1199 return NETDEV_TX_OK;
1202 /*******************************************
1203 * Someone wanna have the statistics
1206 static struct net_device_stats *elmc_get_stats(struct net_device *dev)
1208 struct priv *p = netdev_priv(dev);
1209 unsigned short crc, aln, rsc, ovrn;
1211 crc = p->scb->crc_errs; /* get error-statistic from the ni82586 */
1212 p->scb->crc_errs -= crc;
1213 aln = p->scb->aln_errs;
1214 p->scb->aln_errs -= aln;
1215 rsc = p->scb->rsc_errs;
1216 p->scb->rsc_errs -= rsc;
1217 ovrn = p->scb->ovrn_errs;
1218 p->scb->ovrn_errs -= ovrn;
1220 dev->stats.rx_crc_errors += crc;
1221 dev->stats.rx_fifo_errors += ovrn;
1222 dev->stats.rx_frame_errors += aln;
1223 dev->stats.rx_dropped += rsc;
1225 return &dev->stats;
1228 /********************************************************
1229 * Set MC list ..
1232 #ifdef ELMC_MULTICAST
1233 static void set_multicast_list(struct net_device *dev)
1235 if (!dev->start) {
1236 /* without a running interface, promiscuous doesn't work */
1237 return;
1239 dev->start = 0;
1240 alloc586(dev);
1241 init586(dev);
1242 startrecv586(dev);
1243 dev->start = 1;
1245 #endif
1247 static void netdev_get_drvinfo(struct net_device *dev,
1248 struct ethtool_drvinfo *info)
1250 strcpy(info->driver, DRV_NAME);
1251 strcpy(info->version, DRV_VERSION);
1252 sprintf(info->bus_info, "MCA 0x%lx", dev->base_addr);
1255 static const struct ethtool_ops netdev_ethtool_ops = {
1256 .get_drvinfo = netdev_get_drvinfo,
1259 #ifdef MODULE
1261 /* Increase if needed ;) */
1262 #define MAX_3C523_CARDS 4
1264 static struct net_device *dev_elmc[MAX_3C523_CARDS];
1265 static int irq[MAX_3C523_CARDS];
1266 static int io[MAX_3C523_CARDS];
1267 module_param_array(irq, int, NULL, 0);
1268 module_param_array(io, int, NULL, 0);
1269 MODULE_PARM_DESC(io, "EtherLink/MC I/O base address(es)");
1270 MODULE_PARM_DESC(irq, "EtherLink/MC IRQ number(s)");
1271 MODULE_LICENSE("GPL");
1273 int __init init_module(void)
1275 int this_dev,found = 0;
1277 /* Loop until we either can't find any more cards, or we have MAX_3C523_CARDS */
1278 for(this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) {
1279 struct net_device *dev = alloc_etherdev(sizeof(struct priv));
1280 if (!dev)
1281 break;
1282 dev->irq=irq[this_dev];
1283 dev->base_addr=io[this_dev];
1284 if (do_elmc_probe(dev) == 0) {
1285 dev_elmc[this_dev] = dev;
1286 found++;
1287 continue;
1289 free_netdev(dev);
1290 if (io[this_dev]==0)
1291 break;
1292 pr_warning("3c523.c: No 3c523 card found at io=%#x\n",io[this_dev]);
1295 if(found==0) {
1296 if (io[0]==0)
1297 pr_notice("3c523.c: No 3c523 cards found\n");
1298 return -ENXIO;
1299 } else return 0;
1302 void __exit cleanup_module(void)
1304 int this_dev;
1305 for (this_dev=0; this_dev<MAX_3C523_CARDS; this_dev++) {
1306 struct net_device *dev = dev_elmc[this_dev];
1307 if (dev) {
1308 unregister_netdev(dev);
1309 cleanup_card(dev);
1310 free_netdev(dev);
1315 #endif /* MODULE */