blob: 3c1edda08d3d5d6827f32618690db332b01b7b55 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* wd.c: A WD80x3 ethernet driver for linux. */
2/*
3 Written 1993-94 by Donald Becker.
4
5 Copyright 1993 United States Government as represented by the
6 Director, National Security Agency.
7
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
10
11 The author may be reached as becker@scyld.com, or C/O
12 Scyld Computing Corporation
13 410 Severn Ave., Suite 210
14 Annapolis MD 21403
15
16 This is a driver for WD8003 and WD8013 "compatible" ethercards.
17
18 Thanks to Russ Nelson (nelson@crnwyr.com) for loaning me a WD8013.
19
20 Changelog:
21
22 Paul Gortmaker : multiple card support for module users, support
23 for non-standard memory sizes.
24
25
26*/
27
28static const char version[] =
29 "wd.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
30
31#include <linux/module.h>
32#include <linux/kernel.h>
33#include <linux/errno.h>
34#include <linux/string.h>
35#include <linux/init.h>
36#include <linux/interrupt.h>
37#include <linux/delay.h>
38#include <linux/netdevice.h>
39#include <linux/etherdevice.h>
40
41#include <asm/io.h>
42#include <asm/system.h>
43
44#include "8390.h"
45
46#define DRV_NAME "wd"
47
48/* A zero-terminated list of I/O addresses to be probed. */
49static unsigned int wd_portlist[] __initdata =
50{0x300, 0x280, 0x380, 0x240, 0};
51
52static int wd_probe1(struct net_device *dev, int ioaddr);
53
54static int wd_open(struct net_device *dev);
55static void wd_reset_8390(struct net_device *dev);
56static void wd_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
57 int ring_page);
58static void wd_block_input(struct net_device *dev, int count,
59 struct sk_buff *skb, int ring_offset);
60static void wd_block_output(struct net_device *dev, int count,
61 const unsigned char *buf, int start_page);
62static int wd_close(struct net_device *dev);
63
Jeff Garzik6aa20a22006-09-13 13:24:59 -040064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define WD_START_PG 0x00 /* First page of TX buffer */
66#define WD03_STOP_PG 0x20 /* Last page +1 of RX ring */
67#define WD13_STOP_PG 0x40 /* Last page +1 of RX ring */
68
69#define WD_CMDREG 0 /* Offset to ASIC command register. */
70#define WD_RESET 0x80 /* Board reset, in WD_CMDREG. */
71#define WD_MEMENB 0x40 /* Enable the shared memory. */
72#define WD_CMDREG5 5 /* Offset to 16-bit-only ASIC register 5. */
73#define ISA16 0x80 /* Enable 16 bit access from the ISA bus. */
74#define NIC16 0x40 /* Enable 16 bit access from the 8390. */
75#define WD_NIC_OFFSET 16 /* Offset to the 8390 from the base_addr. */
76#define WD_IO_EXTENT 32
77
Jeff Garzik6aa20a22006-09-13 13:24:59 -040078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079/* Probe for the WD8003 and WD8013. These cards have the station
80 address PROM at I/O ports <base>+8 to <base>+13, with a checksum
81 following. A Soundblaster can have the same checksum as an WDethercard,
82 so we have an extra exclusionary check for it.
83
84 The wd_probe1() routine initializes the card and fills the
85 station address field. */
86
87static int __init do_wd_probe(struct net_device *dev)
88{
89 int i;
90 struct resource *r;
91 int base_addr = dev->base_addr;
92 int irq = dev->irq;
93 int mem_start = dev->mem_start;
94 int mem_end = dev->mem_end;
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 if (base_addr > 0x1ff) { /* Check a user specified location. */
97 r = request_region(base_addr, WD_IO_EXTENT, "wd-probe");
98 if ( r == NULL)
99 return -EBUSY;
100 i = wd_probe1(dev, base_addr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400101 if (i != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 release_region(base_addr, WD_IO_EXTENT);
103 else
104 r->name = dev->name;
105 return i;
106 }
107 else if (base_addr != 0) /* Don't probe at all. */
108 return -ENXIO;
109
110 for (i = 0; wd_portlist[i]; i++) {
111 int ioaddr = wd_portlist[i];
112 r = request_region(ioaddr, WD_IO_EXTENT, "wd-probe");
113 if (r == NULL)
114 continue;
115 if (wd_probe1(dev, ioaddr) == 0) {
116 r->name = dev->name;
117 return 0;
118 }
119 release_region(ioaddr, WD_IO_EXTENT);
120 dev->irq = irq;
121 dev->mem_start = mem_start;
122 dev->mem_end = mem_end;
123 }
124
125 return -ENODEV;
126}
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifndef MODULE
129struct net_device * __init wd_probe(int unit)
130{
131 struct net_device *dev = alloc_ei_netdev();
132 int err;
133
134 if (!dev)
135 return ERR_PTR(-ENOMEM);
136
137 sprintf(dev->name, "eth%d", unit);
138 netdev_boot_setup_check(dev);
139
140 err = do_wd_probe(dev);
141 if (err)
142 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144out:
145 free_netdev(dev);
146 return ERR_PTR(err);
147}
148#endif
149
Stephen Hemminger458228b2008-11-25 18:21:56 -0800150static const struct net_device_ops wd_netdev_ops = {
151 .ndo_open = wd_open,
152 .ndo_stop = wd_close,
153 .ndo_start_xmit = ei_start_xmit,
154 .ndo_tx_timeout = ei_tx_timeout,
155 .ndo_get_stats = ei_get_stats,
156 .ndo_set_multicast_list = ei_set_multicast_list,
157 .ndo_validate_addr = eth_validate_addr,
158 .ndo_change_mtu = eth_change_mtu,
159#ifdef CONFIG_NET_POLL_CONTROLLER
160 .ndo_poll_controller = ei_poll,
161#endif
162};
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static int __init wd_probe1(struct net_device *dev, int ioaddr)
165{
166 int i;
b1fc5502005-05-12 20:11:55 -0400167 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 int checksum = 0;
169 int ancient = 0; /* An old card without config registers. */
170 int word16 = 0; /* 0 = 8 bit, 1 = 16 bit */
171 const char *model_name;
172 static unsigned version_printed;
173
174 for (i = 0; i < 8; i++)
175 checksum += inb(ioaddr + 8 + i);
176 if (inb(ioaddr + 8) == 0xff /* Extra check to avoid soundcard. */
177 || inb(ioaddr + 9) == 0xff
178 || (checksum & 0xff) != 0xFF)
179 return -ENODEV;
180
181 /* Check for semi-valid mem_start/end values if supplied. */
182 if ((dev->mem_start % 0x2000) || (dev->mem_end % 0x2000)) {
183 printk(KERN_WARNING "wd.c: user supplied mem_start or mem_end not on 8kB boundary - ignored.\n");
184 dev->mem_start = 0;
185 dev->mem_end = 0;
186 }
187
188 if (ei_debug && version_printed++ == 0)
189 printk(version);
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 for (i = 0; i < 6; i++)
Joe Perches0795af52007-10-03 17:59:30 -0700192 dev->dev_addr[i] = inb(ioaddr + 8 + i);
193
Johannes Berge1749612008-10-27 15:59:26 -0700194 printk("%s: WD80x3 at %#3x, %pM",
195 dev->name, ioaddr, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 /* The following PureData probe code was contributed by
198 Mike Jagdis <jaggy@purplet.demon.co.uk>. Puredata does software
199 configuration differently from others so we have to check for them.
200 This detects an 8 bit, 16 bit or dumb (Toshiba, jumpered) card.
201 */
202 if (inb(ioaddr+0) == 'P' && inb(ioaddr+1) == 'D') {
203 unsigned char reg5 = inb(ioaddr+5);
204
205 switch (inb(ioaddr+2)) {
206 case 0x03: word16 = 0; model_name = "PDI8023-8"; break;
207 case 0x05: word16 = 0; model_name = "PDUC8023"; break;
208 case 0x0a: word16 = 1; model_name = "PDI8023-16"; break;
209 /* Either 0x01 (dumb) or they've released a new version. */
210 default: word16 = 0; model_name = "PDI8023"; break;
211 }
212 dev->mem_start = ((reg5 & 0x1c) + 0xc0) << 12;
213 dev->irq = (reg5 & 0xe0) == 0xe0 ? 10 : (reg5 >> 5) + 1;
214 } else { /* End of PureData probe */
215 /* This method of checking for a 16-bit board is borrowed from the
216 we.c driver. A simpler method is just to look in ASIC reg. 0x03.
217 I'm comparing the two method in alpha test to make certain they
218 return the same result. */
219 /* Check for the old 8 bit board - it has register 0/8 aliasing.
220 Do NOT check i>=6 here -- it hangs the old 8003 boards! */
221 for (i = 0; i < 6; i++)
222 if (inb(ioaddr+i) != inb(ioaddr+8+i))
223 break;
224 if (i >= 6) {
225 ancient = 1;
226 model_name = "WD8003-old";
227 word16 = 0;
228 } else {
229 int tmp = inb(ioaddr+1); /* fiddle with 16bit bit */
230 outb( tmp ^ 0x01, ioaddr+1 ); /* attempt to clear 16bit bit */
231 if (((inb( ioaddr+1) & 0x01) == 0x01) /* A 16 bit card */
232 && (tmp & 0x01) == 0x01 ) { /* In a 16 slot. */
233 int asic_reg5 = inb(ioaddr+WD_CMDREG5);
234 /* Magic to set ASIC to word-wide mode. */
235 outb( NIC16 | (asic_reg5&0x1f), ioaddr+WD_CMDREG5);
236 outb(tmp, ioaddr+1);
237 model_name = "WD8013";
238 word16 = 1; /* We have a 16bit board here! */
239 } else {
240 model_name = "WD8003";
241 word16 = 0;
242 }
243 outb(tmp, ioaddr+1); /* Restore original reg1 value. */
244 }
245#ifndef final_version
246 if ( !ancient && (inb(ioaddr+1) & 0x01) != (word16 & 0x01))
247 printk("\nWD80?3: Bus width conflict, %d (probe) != %d (reg report).",
248 word16 ? 16 : 8, (inb(ioaddr+1) & 0x01) ? 16 : 8);
249#endif
250 }
251
252#if defined(WD_SHMEM) && WD_SHMEM > 0x80000
253 /* Allow a compile-time override. */
254 dev->mem_start = WD_SHMEM;
255#else
256 if (dev->mem_start == 0) {
257 /* Sanity and old 8003 check */
258 int reg0 = inb(ioaddr);
259 if (reg0 == 0xff || reg0 == 0) {
260 /* Future plan: this could check a few likely locations first. */
261 dev->mem_start = 0xd0000;
262 printk(" assigning address %#lx", dev->mem_start);
263 } else {
264 int high_addr_bits = inb(ioaddr+WD_CMDREG5) & 0x1f;
265 /* Some boards don't have the register 5 -- it returns 0xff. */
266 if (high_addr_bits == 0x1f || word16 == 0)
267 high_addr_bits = 0x01;
268 dev->mem_start = ((reg0&0x3f) << 13) + (high_addr_bits << 19);
269 }
270 }
271#endif
272
273 /* The 8390 isn't at the base address -- the ASIC regs are there! */
274 dev->base_addr = ioaddr+WD_NIC_OFFSET;
275
276 if (dev->irq < 2) {
277 int irqmap[] = {9,3,5,7,10,11,15,4};
278 int reg1 = inb(ioaddr+1);
279 int reg4 = inb(ioaddr+4);
280 if (ancient || reg1 == 0xff) { /* Ack!! No way to read the IRQ! */
281 short nic_addr = ioaddr+WD_NIC_OFFSET;
282 unsigned long irq_mask;
283
284 /* We have an old-style ethercard that doesn't report its IRQ
285 line. Do autoirq to find the IRQ line. Note that this IS NOT
286 a reliable way to trigger an interrupt. */
287 outb_p(E8390_NODMA + E8390_STOP, nic_addr);
288 outb(0x00, nic_addr+EN0_IMR); /* Disable all intrs. */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 irq_mask = probe_irq_on();
291 outb_p(0xff, nic_addr + EN0_IMR); /* Enable all interrupts. */
292 outb_p(0x00, nic_addr + EN0_RCNTLO);
293 outb_p(0x00, nic_addr + EN0_RCNTHI);
294 outb(E8390_RREAD+E8390_START, nic_addr); /* Trigger it... */
295 mdelay(20);
296 dev->irq = probe_irq_off(irq_mask);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 outb_p(0x00, nic_addr+EN0_IMR); /* Mask all intrs. again. */
299
300 if (ei_debug > 2)
301 printk(" autoirq is %d", dev->irq);
302 if (dev->irq < 2)
303 dev->irq = word16 ? 10 : 5;
304 } else
305 dev->irq = irqmap[((reg4 >> 5) & 0x03) + (reg1 & 0x04)];
306 } else if (dev->irq == 2) /* Fixup bogosity: IRQ2 is really IRQ9 */
307 dev->irq = 9;
308
309 /* Snarf the interrupt now. There's no point in waiting since we cannot
310 share and the board will usually be enabled. */
311 i = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev);
312 if (i) {
313 printk (" unable to get IRQ %d.\n", dev->irq);
314 return i;
315 }
316
317 /* OK, were are certain this is going to work. Setup the device. */
318 ei_status.name = model_name;
319 ei_status.word16 = word16;
320 ei_status.tx_start_page = WD_START_PG;
321 ei_status.rx_start_page = WD_START_PG + TX_PAGES;
322
323 /* Don't map in the shared memory until the board is actually opened. */
324
325 /* Some cards (eg WD8003EBT) can be jumpered for more (32k!) memory. */
326 if (dev->mem_end != 0) {
327 ei_status.stop_page = (dev->mem_end - dev->mem_start)/256;
328 ei_status.priv = dev->mem_end - dev->mem_start;
329 } else {
330 ei_status.stop_page = word16 ? WD13_STOP_PG : WD03_STOP_PG;
331 dev->mem_end = dev->mem_start + (ei_status.stop_page - WD_START_PG)*256;
332 ei_status.priv = (ei_status.stop_page - WD_START_PG)*256;
333 }
334
335 ei_status.mem = ioremap(dev->mem_start, ei_status.priv);
336 if (!ei_status.mem) {
337 free_irq(dev->irq, dev);
338 return -ENOMEM;
339 }
340
341 printk(" %s, IRQ %d, shared memory at %#lx-%#lx.\n",
342 model_name, dev->irq, dev->mem_start, dev->mem_end-1);
343
344 ei_status.reset_8390 = &wd_reset_8390;
345 ei_status.block_input = &wd_block_input;
346 ei_status.block_output = &wd_block_output;
347 ei_status.get_8390_hdr = &wd_get_8390_hdr;
Stephen Hemminger458228b2008-11-25 18:21:56 -0800348
349 dev->netdev_ops = &wd_netdev_ops;
Alan Coxd3d7b532008-08-22 19:24:15 +0100350 NS8390_init(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352#if 1
353 /* Enable interrupt generation on softconfig cards -- M.U */
354 /* .. but possibly potentially unsafe - Donald */
355 if (inb(ioaddr+14) & 0x20)
356 outb(inb(ioaddr+4)|0x80, ioaddr+4);
357#endif
358
b1fc5502005-05-12 20:11:55 -0400359 err = register_netdev(dev);
360 if (err)
361 free_irq(dev->irq, dev);
362 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
365static int
366wd_open(struct net_device *dev)
367{
368 int ioaddr = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */
369
370 /* Map in the shared memory. Always set register 0 last to remain
371 compatible with very old boards. */
372 ei_status.reg0 = ((dev->mem_start>>13) & 0x3f) | WD_MEMENB;
373 ei_status.reg5 = ((dev->mem_start>>19) & 0x1f) | NIC16;
374
375 if (ei_status.word16)
376 outb(ei_status.reg5, ioaddr+WD_CMDREG5);
377 outb(ei_status.reg0, ioaddr); /* WD_CMDREG */
378
Stephen Hemminger458228b2008-11-25 18:21:56 -0800379 return ei_open(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
382static void
383wd_reset_8390(struct net_device *dev)
384{
385 int wd_cmd_port = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */
386
387 outb(WD_RESET, wd_cmd_port);
388 if (ei_debug > 1) printk("resetting the WD80x3 t=%lu...", jiffies);
389 ei_status.txing = 0;
390
391 /* Set up the ASIC registers, just in case something changed them. */
392 outb((((dev->mem_start>>13) & 0x3f)|WD_MEMENB), wd_cmd_port);
393 if (ei_status.word16)
394 outb(NIC16 | ((dev->mem_start>>19) & 0x1f), wd_cmd_port+WD_CMDREG5);
395
396 if (ei_debug > 1) printk("reset done\n");
397 return;
398}
399
400/* Grab the 8390 specific header. Similar to the block_input routine, but
401 we don't need to be concerned with ring wrap as the header will be at
402 the start of a page, so we optimize accordingly. */
403
404static void
405wd_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
406{
407
408 int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */
409 void __iomem *hdr_start = ei_status.mem + ((ring_page - WD_START_PG)<<8);
410
411 /* We'll always get a 4 byte header read followed by a packet read, so
412 we enable 16 bit mode before the header, and disable after the body. */
413 if (ei_status.word16)
414 outb(ISA16 | ei_status.reg5, wd_cmdreg+WD_CMDREG5);
415
416#ifdef __BIG_ENDIAN
417 /* Officially this is what we are doing, but the readl() is faster */
418 /* unfortunately it isn't endian aware of the struct */
419 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
420 hdr->count = le16_to_cpu(hdr->count);
421#else
422 ((unsigned int*)hdr)[0] = readl(hdr_start);
423#endif
424}
425
426/* Block input and output are easy on shared memory ethercards, and trivial
427 on the Western digital card where there is no choice of how to do it.
428 The only complications are that the ring buffer wraps, and need to map
429 switch between 8- and 16-bit modes. */
430
431static void
432wd_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
433{
434 int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */
435 unsigned long offset = ring_offset - (WD_START_PG<<8);
436 void __iomem *xfer_start = ei_status.mem + offset;
437
438 if (offset + count > ei_status.priv) {
439 /* We must wrap the input move. */
440 int semi_count = ei_status.priv - offset;
441 memcpy_fromio(skb->data, xfer_start, semi_count);
442 count -= semi_count;
443 memcpy_fromio(skb->data + semi_count, ei_status.mem + TX_PAGES * 256, count);
444 } else {
445 /* Packet is in one chunk -- we can copy + cksum. */
Al Viro4ec03112007-02-09 16:38:30 +0000446 memcpy_fromio(skb->data, xfer_start, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448
449 /* Turn off 16 bit access so that reboot works. ISA brain-damage */
450 if (ei_status.word16)
451 outb(ei_status.reg5, wd_cmdreg+WD_CMDREG5);
452}
453
454static void
455wd_block_output(struct net_device *dev, int count, const unsigned char *buf,
456 int start_page)
457{
458 int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */
459 void __iomem *shmem = ei_status.mem + ((start_page - WD_START_PG)<<8);
460
461
462 if (ei_status.word16) {
463 /* Turn on and off 16 bit access so that reboot works. */
464 outb(ISA16 | ei_status.reg5, wd_cmdreg+WD_CMDREG5);
465 memcpy_toio(shmem, buf, count);
466 outb(ei_status.reg5, wd_cmdreg+WD_CMDREG5);
467 } else
468 memcpy_toio(shmem, buf, count);
469}
470
471
472static int
473wd_close(struct net_device *dev)
474{
475 int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */
476
477 if (ei_debug > 1)
478 printk("%s: Shutting down ethercard.\n", dev->name);
479 ei_close(dev);
480
481 /* Change from 16-bit to 8-bit shared memory so reboot works. */
482 if (ei_status.word16)
483 outb(ei_status.reg5, wd_cmdreg + WD_CMDREG5 );
484
485 /* And disable the shared memory. */
486 outb(ei_status.reg0 & ~WD_MEMENB, wd_cmdreg);
487
488 return 0;
489}
490
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#ifdef MODULE
493#define MAX_WD_CARDS 4 /* Max number of wd cards per module */
494static struct net_device *dev_wd[MAX_WD_CARDS];
495static int io[MAX_WD_CARDS];
496static int irq[MAX_WD_CARDS];
497static int mem[MAX_WD_CARDS];
498static int mem_end[MAX_WD_CARDS]; /* for non std. mem size */
499
500module_param_array(io, int, NULL, 0);
501module_param_array(irq, int, NULL, 0);
502module_param_array(mem, int, NULL, 0);
503module_param_array(mem_end, int, NULL, 0);
504MODULE_PARM_DESC(io, "I/O base address(es)");
505MODULE_PARM_DESC(irq, "IRQ number(s) (ignored for PureData boards)");
506MODULE_PARM_DESC(mem, "memory base address(es)(ignored for PureData boards)");
507MODULE_PARM_DESC(mem_end, "memory end address(es)");
508MODULE_DESCRIPTION("ISA Western Digital wd8003/wd8013 ; SMC Elite, Elite16 ethernet driver");
509MODULE_LICENSE("GPL");
510
511/* This is set up so that only a single autoprobe takes place per call.
512ISA device autoprobes on a running machine are not recommended. */
Andrew Morton5e5fa012006-08-14 23:00:06 -0700513
514int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
516 struct net_device *dev;
517 int this_dev, found = 0;
518
519 for (this_dev = 0; this_dev < MAX_WD_CARDS; this_dev++) {
520 if (io[this_dev] == 0) {
521 if (this_dev != 0) break; /* only autoprobe 1st one */
522 printk(KERN_NOTICE "wd.c: Presently autoprobing (not recommended) for a single card.\n");
523 }
524 dev = alloc_ei_netdev();
525 if (!dev)
526 break;
527 dev->irq = irq[this_dev];
528 dev->base_addr = io[this_dev];
529 dev->mem_start = mem[this_dev];
530 dev->mem_end = mem_end[this_dev];
531 if (do_wd_probe(dev) == 0) {
b1fc5502005-05-12 20:11:55 -0400532 dev_wd[found++] = dev;
533 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535 free_netdev(dev);
536 printk(KERN_WARNING "wd.c: No wd80x3 card found (i/o = 0x%x).\n", io[this_dev]);
537 break;
538 }
539 if (found)
540 return 0;
541 return -ENXIO;
542}
543
Denis Vlasenko64916f12006-01-05 22:45:47 -0800544static void cleanup_card(struct net_device *dev)
545{
546 free_irq(dev->irq, dev);
547 release_region(dev->base_addr - WD_NIC_OFFSET, WD_IO_EXTENT);
548 iounmap(ei_status.mem);
549}
550
Al Viroafc8eb42006-06-14 18:50:53 -0400551void __exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552cleanup_module(void)
553{
554 int this_dev;
555
556 for (this_dev = 0; this_dev < MAX_WD_CARDS; this_dev++) {
557 struct net_device *dev = dev_wd[this_dev];
558 if (dev) {
559 unregister_netdev(dev);
560 cleanup_card(dev);
561 free_netdev(dev);
562 }
563 }
564}
565#endif /* MODULE */