Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ne-h8300.c
Go to the documentation of this file.
1 /* ne-h8300.c: A NE2000 clone on H8/300 driver for linux. */
2 /*
3  original ne.c
4  Written 1992-94 by Donald Becker.
5 
6  Copyright 1993 United States Government as represented by the
7  Director, National Security Agency.
8 
9  This software may be used and distributed according to the terms
10  of the GNU General Public License, incorporated herein by reference.
11 
12  The author may be reached as [email protected], or C/O
13  Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
14 
15  H8/300 modified
16  Yoshinori Sato <[email protected]>
17 */
18 
19 static const char version1[] =
20 "ne-h8300.c:v1.00 2004/04/11 ysato\n";
21 
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/errno.h>
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
27 #include <linux/delay.h>
28 #include <linux/netdevice.h>
29 #include <linux/etherdevice.h>
30 #include <linux/jiffies.h>
31 
32 #include <asm/io.h>
33 #include <asm/irq.h>
34 
35 #define EI_SHIFT(x) (ei_local->reg_offset[x])
36 
37 #include "8390.h"
38 
39 #define DRV_NAME "ne-h8300"
40 
41 /* Some defines that people can play with if so inclined. */
42 
43 /* Do we perform extra sanity checks on stuff ? */
44 /* #define NE_SANITY_CHECK */
45 
46 /* Do we implement the read before write bugfix ? */
47 /* #define NE_RW_BUGFIX */
48 
49 /* Do we have a non std. amount of memory? (in units of 256 byte pages) */
50 /* #define PACKETBUF_MEMSIZE 0x40 */
51 
52 /* A zero-terminated list of I/O addresses to be probed at boot. */
53 
54 /* ---- No user-serviceable parts below ---- */
55 
56 static const char version[] =
57  "8390.c:v1.10cvs 9/23/94 Donald Becker ([email protected])\n";
58 
59 #include "lib8390.c"
60 
61 #define NE_BASE (dev->base_addr)
62 #define NE_CMD 0x00
63 #define NE_DATAPORT (ei_status.word16?0x20:0x10) /* NatSemi-defined port window offset. */
64 #define NE_RESET (ei_status.word16?0x3f:0x1f) /* Issue a read to reset, a write to clear. */
65 #define NE_IO_EXTENT (ei_status.word16?0x40:0x20)
66 
67 #define NESM_START_PG 0x40 /* First page of TX buffer */
68 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
69 
70 static int ne_probe1(struct net_device *dev, int ioaddr);
71 
72 static int ne_open(struct net_device *dev);
73 static int ne_close(struct net_device *dev);
74 
75 static void ne_reset_8390(struct net_device *dev);
76 static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
77  int ring_page);
78 static void ne_block_input(struct net_device *dev, int count,
79  struct sk_buff *skb, int ring_offset);
80 static void ne_block_output(struct net_device *dev, const int count,
81  const unsigned char *buf, const int start_page);
82 
83 
84 static u32 reg_offset[16];
85 
86 static int __init init_reg_offset(struct net_device *dev,unsigned long base_addr)
87 {
88  struct ei_device *ei_local = netdev_priv(dev);
89  int i;
90  unsigned char bus_width;
91 
92  bus_width = *(volatile unsigned char *)ABWCR;
93  bus_width &= 1 << ((base_addr >> 21) & 7);
94 
95  for (i = 0; i < ARRAY_SIZE(reg_offset); i++)
96  if (bus_width == 0)
97  reg_offset[i] = i * 2 + 1;
98  else
99  reg_offset[i] = i;
100 
101  ei_local->reg_offset = reg_offset;
102  return 0;
103 }
104 
105 static int __initdata h8300_ne_count = 0;
106 #ifdef CONFIG_H8300H_H8MAX
107 static unsigned long __initdata h8300_ne_base[] = { 0x800600 };
108 static int h8300_ne_irq[] = {EXT_IRQ4};
109 #endif
110 #ifdef CONFIG_H8300H_AKI3068NET
111 static unsigned long __initdata h8300_ne_base[] = { 0x200000 };
112 static int h8300_ne_irq[] = {EXT_IRQ5};
113 #endif
114 
115 static inline int init_dev(struct net_device *dev)
116 {
117  if (h8300_ne_count < ARRAY_SIZE(h8300_ne_base)) {
118  dev->base_addr = h8300_ne_base[h8300_ne_count];
119  dev->irq = h8300_ne_irq[h8300_ne_count];
120  h8300_ne_count++;
121  return 0;
122  } else
123  return -ENODEV;
124 }
125 
126 /* Probe for various non-shared-memory ethercards.
127 
128  NEx000-clone boards have a Station Address PROM (SAPROM) in the packet
129  buffer memory space. NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of
130  the SAPROM, while other supposed NE2000 clones must be detected by their
131  SA prefix.
132 
133  Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
134  mode results in doubled values, which can be detected and compensated for.
135 
136  The probe is also responsible for initializing the card and filling
137  in the 'dev' and 'ei_status' structures.
138 
139  We use the minimum memory size for some ethercard product lines, iff we can't
140  distinguish models. You can increase the packet buffer size by setting
141  PACKETBUF_MEMSIZE. Reported Cabletron packet buffer locations are:
142  E1010 starts at 0x100 and ends at 0x2000.
143  E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory")
144  E2010 starts at 0x100 and ends at 0x4000.
145  E2010-x starts at 0x100 and ends at 0xffff. */
146 
147 static int __init do_ne_probe(struct net_device *dev)
148 {
149  unsigned int base_addr = dev->base_addr;
150 
151  /* First check any supplied i/o locations. User knows best. <cough> */
152  if (base_addr > 0x1ff) /* Check a single specified location. */
153  return ne_probe1(dev, base_addr);
154  else if (base_addr != 0) /* Don't probe at all. */
155  return -ENXIO;
156 
157  return -ENODEV;
158 }
159 
160 static void cleanup_card(struct net_device *dev)
161 {
162  free_irq(dev->irq, dev);
164 }
165 
166 #ifndef MODULE
168 {
169  struct net_device *dev = ____alloc_ei_netdev(0);
170  int err;
171 
172  if (!dev)
173  return ERR_PTR(-ENOMEM);
174 
175  if (init_dev(dev))
176  return ERR_PTR(-ENODEV);
177 
178  sprintf(dev->name, "eth%d", unit);
180 
181  err = init_reg_offset(dev, dev->base_addr);
182  if (err)
183  goto out;
184 
185  err = do_ne_probe(dev);
186  if (err)
187  goto out;
188  return dev;
189 out:
190  free_netdev(dev);
191  return ERR_PTR(err);
192 }
193 #endif
194 
195 static const struct net_device_ops ne_netdev_ops = {
196  .ndo_open = ne_open,
197  .ndo_stop = ne_close,
198 
199  .ndo_start_xmit = __ei_start_xmit,
200  .ndo_tx_timeout = __ei_tx_timeout,
201  .ndo_get_stats = __ei_get_stats,
202  .ndo_set_rx_mode = __ei_set_multicast_list,
203  .ndo_validate_addr = eth_validate_addr,
204  .ndo_set_mac_address = eth_mac_addr,
205  .ndo_change_mtu = eth_change_mtu,
206 #ifdef CONFIG_NET_POLL_CONTROLLER
207  .ndo_poll_controller = __ei_poll,
208 #endif
209 };
210 
211 static int __init ne_probe1(struct net_device *dev, int ioaddr)
212 {
213  int i;
214  unsigned char SA_prom[16];
215  int wordlength = 2;
216  const char *name = NULL;
217  int start_page, stop_page;
218  int reg0, ret;
219  static unsigned version_printed;
220  struct ei_device *ei_local = netdev_priv(dev);
221  unsigned char bus_width;
222 
223  if (!request_region(ioaddr, NE_IO_EXTENT, DRV_NAME))
224  return -EBUSY;
225 
226  reg0 = inb_p(ioaddr);
227  if (reg0 == 0xFF) {
228  ret = -ENODEV;
229  goto err_out;
230  }
231 
232  /* Do a preliminary verification that we have a 8390. */
233  {
234  int regd;
236  regd = inb_p(ioaddr + EI_SHIFT(0x0d));
237  outb_p(0xff, ioaddr + EI_SHIFT(0x0d));
239  inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
240  if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
241  outb_p(reg0, ioaddr + EI_SHIFT(0));
242  outb_p(regd, ioaddr + EI_SHIFT(0x0d)); /* Restore the old values. */
243  ret = -ENODEV;
244  goto err_out;
245  }
246  }
247 
248  if (ei_debug && version_printed++ == 0)
249  printk(KERN_INFO "%s", version1);
250 
251  printk(KERN_INFO "NE*000 ethercard probe at %08x:", ioaddr);
252 
253  /* Read the 16 bytes of station address PROM.
254  We must first initialize registers, similar to NS8390_init(eifdev, 0).
255  We can't reliably read the SAPROM address without this.
256  (I learned the hard way!). */
257  {
258  struct {unsigned char value, offset; } program_seq[] =
259  {
260  {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
261  {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
262  {0x00, EN0_RCNTLO}, /* Clear the count regs. */
263  {0x00, EN0_RCNTHI},
264  {0x00, EN0_IMR}, /* Mask completion irq. */
265  {0xFF, EN0_ISR},
266  {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
267  {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
268  {32, EN0_RCNTLO},
269  {0x00, EN0_RCNTHI},
270  {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
271  {0x00, EN0_RSARHI},
273  };
274 
275  for (i = 0; i < ARRAY_SIZE(program_seq); i++)
276  outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
277 
278  }
279  bus_width = *(volatile unsigned char *)ABWCR;
280  bus_width &= 1 << ((ioaddr >> 21) & 7);
281  ei_status.word16 = (bus_width == 0); /* temporary setting */
282  for(i = 0; i < 16 /*sizeof(SA_prom)*/; i++) {
283  SA_prom[i] = inb_p(ioaddr + NE_DATAPORT);
284  inb_p(ioaddr + NE_DATAPORT); /* dummy read */
285  }
286 
287  start_page = NESM_START_PG;
288  stop_page = NESM_STOP_PG;
289 
290  if (bus_width)
291  wordlength = 1;
292  else
293  outb_p(0x49, ioaddr + EN0_DCFG);
294 
295  /* Set up the rest of the parameters. */
296  name = (wordlength == 2) ? "NE2000" : "NE1000";
297 
298  if (! dev->irq) {
299  printk(" failed to detect IRQ line.\n");
300  ret = -EAGAIN;
301  goto err_out;
302  }
303 
304  /* Snarf the interrupt now. There's no point in waiting since we cannot
305  share and the board will usually be enabled. */
306  ret = request_irq(dev->irq, __ei_interrupt, 0, name, dev);
307  if (ret) {
308  printk (" unable to get IRQ %d (errno=%d).\n", dev->irq, ret);
309  goto err_out;
310  }
311 
312  dev->base_addr = ioaddr;
313 
314  for (i = 0; i < ETH_ALEN; i++)
315  dev->dev_addr[i] = SA_prom[i];
316  printk(" %pM\n", dev->dev_addr);
317 
318  printk("%s: %s found at %#x, using IRQ %d.\n",
319  dev->name, name, ioaddr, dev->irq);
320 
321  ei_status.name = name;
322  ei_status.tx_start_page = start_page;
323  ei_status.stop_page = stop_page;
324  ei_status.word16 = (wordlength == 2);
325 
326  ei_status.rx_start_page = start_page + TX_PAGES;
327 #ifdef PACKETBUF_MEMSIZE
328  /* Allow the packet buffer size to be overridden by know-it-alls. */
329  ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
330 #endif
331 
332  ei_status.reset_8390 = &ne_reset_8390;
333  ei_status.block_input = &ne_block_input;
334  ei_status.block_output = &ne_block_output;
335  ei_status.get_8390_hdr = &ne_get_8390_hdr;
336  ei_status.priv = 0;
337 
338  dev->netdev_ops = &ne_netdev_ops;
339 
340  __NS8390_init(dev, 0);
341 
342  ret = register_netdev(dev);
343  if (ret)
344  goto out_irq;
345  return 0;
346 out_irq:
347  free_irq(dev->irq, dev);
348 err_out:
349  release_region(ioaddr, NE_IO_EXTENT);
350  return ret;
351 }
352 
353 static int ne_open(struct net_device *dev)
354 {
355  __ei_open(dev);
356  return 0;
357 }
358 
359 static int ne_close(struct net_device *dev)
360 {
361  if (ei_debug > 1)
362  printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
363  __ei_close(dev);
364  return 0;
365 }
366 
367 /* Hard reset the card. This used to pause for the same period that a
368  8390 reset command required, but that shouldn't be necessary. */
369 
370 static void ne_reset_8390(struct net_device *dev)
371 {
372  unsigned long reset_start_time = jiffies;
373  struct ei_device *ei_local = netdev_priv(dev);
374 
375  if (ei_debug > 1)
376  printk(KERN_DEBUG "resetting the 8390 t=%ld...", jiffies);
377 
378  /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
380 
381  ei_status.txing = 0;
382  ei_status.dmaing = 0;
383 
384  /* This check _should_not_ be necessary, omit eventually. */
385  while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
386  if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
387  printk(KERN_WARNING "%s: ne_reset_8390() did not complete.\n", dev->name);
388  break;
389  }
390  outb_p(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */
391 }
392 
393 /* Grab the 8390 specific header. Similar to the block_input routine, but
394  we don't need to be concerned with ring wrap as the header will be at
395  the start of a page, so we optimize accordingly. */
396 
397 static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
398 {
399  struct ei_device *ei_local = netdev_priv(dev);
400  /* This *shouldn't* happen. If it does, it's the last thing you'll see */
401 
402  if (ei_status.dmaing)
403  {
404  printk(KERN_EMERG "%s: DMAing conflict in ne_get_8390_hdr "
405  "[DMAstat:%d][irqlock:%d].\n",
406  dev->name, ei_status.dmaing, ei_status.irqlock);
407  return;
408  }
409 
410  ei_status.dmaing |= 0x01;
412  outb_p(sizeof(struct e8390_pkt_hdr), NE_BASE + EN0_RCNTLO);
413  outb_p(0, NE_BASE + EN0_RCNTHI);
414  outb_p(0, NE_BASE + EN0_RSARLO); /* On page boundary */
415  outb_p(ring_page, NE_BASE + EN0_RSARHI);
417 
418  if (ei_status.word16) {
419  int len;
420  unsigned short *p = (unsigned short *)hdr;
421  for (len = sizeof(struct e8390_pkt_hdr)>>1; len > 0; len--)
422  *p++ = inw(NE_BASE + NE_DATAPORT);
423  } else
424  insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
425 
426  outb_p(ENISR_RDC, NE_BASE + EN0_ISR); /* Ack intr. */
427  ei_status.dmaing &= ~0x01;
428 
429  le16_to_cpus(&hdr->count);
430 }
431 
432 /* Block input and output, similar to the Crynwr packet driver. If you
433  are porting to a new ethercard, look at the packet driver source for hints.
434  The NEx000 doesn't share the on-board packet memory -- you have to put
435  the packet out through the "remote DMA" dataport using outb. */
436 
437 static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
438 {
439  struct ei_device *ei_local = netdev_priv(dev);
440 #ifdef NE_SANITY_CHECK
441  int xfer_count = count;
442 #endif
443  char *buf = skb->data;
444 
445  /* This *shouldn't* happen. If it does, it's the last thing you'll see */
446  if (ei_status.dmaing)
447  {
448  printk(KERN_EMERG "%s: DMAing conflict in ne_block_input "
449  "[DMAstat:%d][irqlock:%d].\n",
450  dev->name, ei_status.dmaing, ei_status.irqlock);
451  return;
452  }
453  ei_status.dmaing |= 0x01;
455  outb_p(count & 0xff, NE_BASE + EN0_RCNTLO);
456  outb_p(count >> 8, NE_BASE + EN0_RCNTHI);
457  outb_p(ring_offset & 0xff, NE_BASE + EN0_RSARLO);
458  outb_p(ring_offset >> 8, NE_BASE + EN0_RSARHI);
460  if (ei_status.word16)
461  {
462  int len;
463  unsigned short *p = (unsigned short *)buf;
464  for (len = count>>1; len > 0; len--)
465  *p++ = inw(NE_BASE + NE_DATAPORT);
466  if (count & 0x01)
467  {
468  buf[count-1] = inb(NE_BASE + NE_DATAPORT);
469 #ifdef NE_SANITY_CHECK
470  xfer_count++;
471 #endif
472  }
473  } else {
474  insb(NE_BASE + NE_DATAPORT, buf, count);
475  }
476 
477 #ifdef NE_SANITY_CHECK
478  /* This was for the ALPHA version only, but enough people have
479  been encountering problems so it is still here. If you see
480  this message you either 1) have a slightly incompatible clone
481  or 2) have noise/speed problems with your bus. */
482 
483  if (ei_debug > 1)
484  {
485  /* DMA termination address check... */
486  int addr, tries = 20;
487  do {
488  /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
489  -- it's broken for Rx on some cards! */
490  int high = inb_p(NE_BASE + EN0_RSARHI);
491  int low = inb_p(NE_BASE + EN0_RSARLO);
492  addr = (high << 8) + low;
493  if (((ring_offset + xfer_count) & 0xff) == low)
494  break;
495  } while (--tries > 0);
496  if (tries <= 0)
497  printk(KERN_WARNING "%s: RX transfer address mismatch,"
498  "%#4.4x (expected) vs. %#4.4x (actual).\n",
499  dev->name, ring_offset + xfer_count, addr);
500  }
501 #endif
502  outb_p(ENISR_RDC, NE_BASE + EN0_ISR); /* Ack intr. */
503  ei_status.dmaing &= ~0x01;
504 }
505 
506 static void ne_block_output(struct net_device *dev, int count,
507  const unsigned char *buf, const int start_page)
508 {
509  struct ei_device *ei_local = netdev_priv(dev);
510  unsigned long dma_start;
511 #ifdef NE_SANITY_CHECK
512  int retries = 0;
513 #endif
514 
515  /* Round the count up for word writes. Do we need to do this?
516  What effect will an odd byte count have on the 8390?
517  I should check someday. */
518 
519  if (ei_status.word16 && (count & 0x01))
520  count++;
521 
522  /* This *shouldn't* happen. If it does, it's the last thing you'll see */
523  if (ei_status.dmaing)
524  {
525  printk(KERN_EMERG "%s: DMAing conflict in ne_block_output."
526  "[DMAstat:%d][irqlock:%d]\n",
527  dev->name, ei_status.dmaing, ei_status.irqlock);
528  return;
529  }
530  ei_status.dmaing |= 0x01;
531  /* We should already be in page 0, but to be safe... */
533 
534 #ifdef NE_SANITY_CHECK
535 retry:
536 #endif
537 
538 #ifdef NE8390_RW_BUGFIX
539  /* Handle the read-before-write bug the same way as the
540  Crynwr packet driver -- the NatSemi method doesn't work.
541  Actually this doesn't always work either, but if you have
542  problems with your NEx000 this is better than nothing! */
543 
544  outb_p(0x42, NE_BASE + EN0_RCNTLO);
545  outb_p(0x00, NE_BASE + EN0_RCNTHI);
546  outb_p(0x42, NE_BASE + EN0_RSARLO);
547  outb_p(0x00, NE_BASE + EN0_RSARHI);
549  /* Make certain that the dummy read has occurred. */
550  udelay(6);
551 #endif
552 
554 
555  /* Now the normal output. */
556  outb_p(count & 0xff, NE_BASE + EN0_RCNTLO);
557  outb_p(count >> 8, NE_BASE + EN0_RCNTHI);
558  outb_p(0x00, NE_BASE + EN0_RSARLO);
559  outb_p(start_page, NE_BASE + EN0_RSARHI);
560 
562  if (ei_status.word16) {
563  int len;
564  unsigned short *p = (unsigned short *)buf;
565  for (len = count>>1; len > 0; len--)
566  outw(*p++, NE_BASE + NE_DATAPORT);
567  } else {
568  outsb(NE_BASE + NE_DATAPORT, buf, count);
569  }
570 
571  dma_start = jiffies;
572 
573 #ifdef NE_SANITY_CHECK
574  /* This was for the ALPHA version only, but enough people have
575  been encountering problems so it is still here. */
576 
577  if (ei_debug > 1)
578  {
579  /* DMA termination address check... */
580  int addr, tries = 20;
581  do {
582  int high = inb_p(NE_BASE + EN0_RSARHI);
583  int low = inb_p(NE_BASE + EN0_RSARLO);
584  addr = (high << 8) + low;
585  if ((start_page << 8) + count == addr)
586  break;
587  } while (--tries > 0);
588 
589  if (tries <= 0)
590  {
591  printk(KERN_WARNING "%s: Tx packet transfer address mismatch,"
592  "%#4.4x (expected) vs. %#4.4x (actual).\n",
593  dev->name, (start_page << 8) + count, addr);
594  if (retries++ == 0)
595  goto retry;
596  }
597  }
598 #endif
599 
600  while ((inb_p(NE_BASE + EN0_ISR) & ENISR_RDC) == 0)
601  if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
602  printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name);
603  ne_reset_8390(dev);
604  __NS8390_init(dev,1);
605  break;
606  }
607 
608  outb_p(ENISR_RDC, NE_BASE + EN0_ISR); /* Ack intr. */
609  ei_status.dmaing &= ~0x01;
610 }
611 
612 
613 #ifdef MODULE
614 #define MAX_NE_CARDS 1 /* Max number of NE cards per module */
615 static struct net_device *dev_ne[MAX_NE_CARDS];
616 static int io[MAX_NE_CARDS];
617 static int irq[MAX_NE_CARDS];
618 static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */
619 
620 module_param_array(io, int, NULL, 0);
621 module_param_array(irq, int, NULL, 0);
622 module_param_array(bad, int, NULL, 0);
623 MODULE_PARM_DESC(io, "I/O base address(es)");
624 MODULE_PARM_DESC(irq, "IRQ number(s)");
625 MODULE_DESCRIPTION("H8/300 NE2000 Ethernet driver");
626 MODULE_LICENSE("GPL");
627 
628 /* This is set up so that no ISA autoprobe takes place. We can't guarantee
629 that the ne2k probe is the last 8390 based probe to take place (as it
630 is at boot) and so the probe will get confused by any other 8390 cards.
631 ISA device autoprobes on a running machine are not recommended anyway. */
632 
633 int init_module(void)
634 {
635  int this_dev, found = 0;
636  int err;
637 
638  for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
639  struct net_device *dev = ____alloc_ei_netdev(0);
640  if (!dev)
641  break;
642  if (io[this_dev]) {
643  dev->irq = irq[this_dev];
644  dev->mem_end = bad[this_dev];
645  dev->base_addr = io[this_dev];
646  } else {
647  dev->base_addr = h8300_ne_base[this_dev];
648  dev->irq = h8300_ne_irq[this_dev];
649  }
650  err = init_reg_offset(dev, dev->base_addr);
651  if (!err) {
652  if (do_ne_probe(dev) == 0) {
653  dev_ne[found++] = dev;
654  continue;
655  }
656  }
657  free_netdev(dev);
658  if (found)
659  break;
660  if (io[this_dev] != 0)
661  printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", dev->base_addr);
662  else
663  printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n");
664  return -ENXIO;
665  }
666  if (found)
667  return 0;
668  return -ENODEV;
669 }
670 
671 void cleanup_module(void)
672 {
673  int this_dev;
674 
675  for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
676  struct net_device *dev = dev_ne[this_dev];
677  if (dev) {
678  unregister_netdev(dev);
679  cleanup_card(dev);
680  free_netdev(dev);
681  }
682  }
683 }
684 #endif /* MODULE */