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