wd.c 18 KB

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