MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / net / ne.c
blobaa3ccf04efa1994de87b40ac2e3173f319a115b6
1 /* ne.c: A general non-shared-memory NS8390 ethernet driver for linux. */
2 /*
3 Written 1992-94 by Donald Becker.
5 Copyright 1993 United States Government as represented by the
6 Director, National Security Agency.
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
11 The author may be reached as becker@scyld.com, or C/O
12 Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
14 This driver should work with many programmed-I/O 8390-based ethernet
15 boards. Currently it supports the NE1000, NE2000, many clones,
16 and some Cabletron products.
18 Changelog:
20 Paul Gortmaker : use ENISR_RDC to monitor Tx PIO uploads, made
21 sanity checks and bad clone support optional.
22 Paul Gortmaker : new reset code, reset card after probe at boot.
23 Paul Gortmaker : multiple card support for module users.
24 Paul Gortmaker : Support for PCI ne2k clones, similar to lance.c
25 Paul Gortmaker : Allow users with bad cards to avoid full probe.
26 Paul Gortmaker : PCI probe changes, more PCI cards supported.
27 rjohnson@analogic.com : Changed init order so an interrupt will only
28 occur after memory is allocated for dev->priv. Deallocated memory
29 last in cleanup_modue()
30 Richard Guenther : Added support for ISAPnP cards
31 Paul Gortmaker : Discontinued PCI support - use ne2k-pci.c instead.
32 Hayato Fujiwara : Add m32r support.
33 Greg Ungerer : added some coldfire addressing code.
37 /* Routines for the NatSemi-based designs (NE[12]000). */
39 static const char version1[] =
40 "ne.c:v1.10 9/23/94 Donald Becker (becker@scyld.com)\n";
41 static const char version2[] =
42 "Last modified Nov 1, 2000 by Paul Gortmaker\n";
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/errno.h>
48 #include <linux/isapnp.h>
49 #include <linux/init.h>
50 #include <linux/interrupt.h>
51 #include <linux/delay.h>
52 #include <linux/netdevice.h>
53 #include <linux/etherdevice.h>
55 #include <asm/system.h>
56 #include <asm/io.h>
58 #include "8390.h"
60 #ifdef CONFIG_COLDFIRE
61 #define COLDFIRE_NE2000_FUNCS
62 #include <asm/coldfire.h>
63 #include <asm/mcfsim.h>
64 #include <asm/mcfne.h>
65 unsigned char ne_defethaddr[] = { 0x00, 0xd0, 0xcf, 0x00, 0x00, 0x01 };
66 #endif /* CONFIG_COLDFIRE */
67 #if defined(CONFIG_M5307) && defined(CONFIG_NETtel)
68 static unsigned int ne_portlist[] = { NE2000_ADDR0, NE2000_ADDR1, 0 };
69 static unsigned int ne_irqlist[] = { NE2000_IRQ_VECTOR0,NE2000_IRQ_VECTOR1,0 };
70 #endif
72 #define DRV_NAME "ne"
73 #if defined(CONFIG_CPU_H8300H)
74 #include <asm/h8300_ne.h>
75 #endif
77 /* Some defines that people can play with if so inclined. */
79 /* Do we support clones that don't adhere to 14,15 of the SAprom ? */
80 #define SUPPORT_NE_BAD_CLONES
82 /* Do we perform extra sanity checks on stuff ? */
83 /* #define NE_SANITY_CHECK */
85 /* Do we implement the read before write bugfix ? */
86 /* #define NE_RW_BUGFIX */
88 /* Do we have a non std. amount of memory? (in units of 256 byte pages) */
89 /* #define PACKETBUF_MEMSIZE 0x40 */
91 /* A zero-terminated list of I/O addresses to be probed at boot. */
92 #ifndef MODULE
93 static unsigned int netcard_portlist[] __initdata = {
94 0x300, 0x280, 0x320, 0x340, 0x360, 0x380, 0
96 #endif
98 static struct isapnp_device_id isapnp_clone_list[] __initdata = {
99 { ISAPNP_CARD_ID('A','X','E',0x2011),
100 ISAPNP_VENDOR('A','X','E'), ISAPNP_FUNCTION(0x2011),
101 (long) "NetGear EA201" },
102 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
103 ISAPNP_VENDOR('E','D','I'), ISAPNP_FUNCTION(0x0216),
104 (long) "NN NE2000" },
105 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
106 ISAPNP_VENDOR('P','N','P'), ISAPNP_FUNCTION(0x80d6),
107 (long) "Generic PNP" },
108 { } /* terminate list */
111 MODULE_DEVICE_TABLE(isapnp, isapnp_clone_list);
113 #ifdef SUPPORT_NE_BAD_CLONES
114 /* A list of bad clones that we none-the-less recognize. */
115 static struct { const char *name8, *name16; unsigned char SAprefix[4];}
116 bad_clone_list[] __initdata = {
117 {"DE100", "DE200", {0x00, 0xDE, 0x01,}},
118 {"DE120", "DE220", {0x00, 0x80, 0xc8,}},
119 {"DFI1000", "DFI2000", {'D', 'F', 'I',}}, /* Original, eh? */
120 {"EtherNext UTP8", "EtherNext UTP16", {0x00, 0x00, 0x79}},
121 {"NE1000","NE2000-invalid", {0x00, 0x00, 0xd8}}, /* Ancient real NE1000. */
122 {"NN1000", "NN2000", {0x08, 0x03, 0x08}}, /* Outlaw no-name clone. */
123 {"4-DIM8","4-DIM16", {0x00,0x00,0x4d,}}, /* Outlaw 4-Dimension cards. */
124 {"Con-Intl_8", "Con-Intl_16", {0x00, 0x00, 0x24}}, /* Connect Int'nl */
125 {"ET-100","ET-200", {0x00, 0x45, 0x54}}, /* YANG and YA clone */
126 {"COMPEX","COMPEX16",{0x00,0x80,0x48}}, /* Broken ISA Compex cards */
127 {"E-LAN100", "E-LAN200", {0x00, 0x00, 0x5d}}, /* Broken ne1000 clones */
128 {"PCM-4823", "PCM-4823", {0x00, 0xc0, 0x6c}}, /* Broken Advantech MoBo */
129 {"REALTEK", "RTL8019", {0x00, 0x00, 0xe8}}, /* no-name with Realtek chip */
130 {"LCS-8834", "LCS-8836", {0x04, 0x04, 0x37}}, /* ShinyNet (SET) */
131 {NULL,}
133 #endif
135 /* ---- No user-serviceable parts below ---- */
137 #define NE_BASE (dev->base_addr)
138 #define NE_CMD 0x00
139 #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
140 #define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */
141 #define NE_IO_EXTENT 0x20
143 #define NE1SM_START_PG 0x20 /* First page of TX buffer */
144 #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
145 #define NESM_START_PG 0x40 /* First page of TX buffer */
146 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
148 #ifdef CONFIG_PLAT_MAPPI
149 # define DCR_VAL 0x4b
150 #elif CONFIG_PLAT_OAKS32R
151 # define DCR_VAL 0x48
152 #else
153 # define DCR_VAL 0x49
154 #endif
156 static int ne_probe1(struct net_device *dev, int ioaddr);
157 static int ne_probe_isapnp(struct net_device *dev);
159 static int ne_open(struct net_device *dev);
160 static int ne_close(struct net_device *dev);
162 static void ne_reset_8390(struct net_device *dev);
163 static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
164 int ring_page);
165 static void ne_block_input(struct net_device *dev, int count,
166 struct sk_buff *skb, int ring_offset);
167 static void ne_block_output(struct net_device *dev, const int count,
168 const unsigned char *buf, const int start_page);
171 /* Probe for various non-shared-memory ethercards.
173 NEx000-clone boards have a Station Address PROM (SAPROM) in the packet
174 buffer memory space. NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of
175 the SAPROM, while other supposed NE2000 clones must be detected by their
176 SA prefix.
178 Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
179 mode results in doubled values, which can be detected and compensated for.
181 The probe is also responsible for initializing the card and filling
182 in the 'dev' and 'ei_status' structures.
184 We use the minimum memory size for some ethercard product lines, iff we can't
185 distinguish models. You can increase the packet buffer size by setting
186 PACKETBUF_MEMSIZE. Reported Cabletron packet buffer locations are:
187 E1010 starts at 0x100 and ends at 0x2000.
188 E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory")
189 E2010 starts at 0x100 and ends at 0x4000.
190 E2010-x starts at 0x100 and ends at 0xffff. */
192 static int __init do_ne_probe(struct net_device *dev)
194 unsigned int base_addr = dev->base_addr;
195 #ifndef MODULE
196 int orig_irq = dev->irq;
197 #endif
199 #if defined (CONFIG_NETtel) && defined (CONFIG_M5307)
200 static int index = 0;
201 if (!ne_portlist[index])
202 return -ENXIO;
203 dev->base_addr = base_addr = ne_portlist[index];
204 dev->irq = ne_irqlist[index++];
205 #elif defined(CONFIG_COLDFIRE)
206 static int once = 0;
208 if (once)
209 return -ENXIO;
210 if (base_addr == 0) {
211 dev->base_addr = base_addr = NE2000_ADDR;
212 dev->irq = NE2000_IRQ_VECTOR;
213 once++;
215 #elif defined(CONFIG_CPU_H8300H)
216 static int once = 0;
217 if (once)
218 return -ENXIO;
219 dev->base_addr = base_addr = NE2000_ADDR;
220 dev->irq = NE2000_IRQ_VECTOR;
221 once++;
222 #endif
224 SET_MODULE_OWNER(dev);
226 /* First check any supplied i/o locations. User knows best. <cough> */
227 if (base_addr > 0x1ff) /* Check a single specified location. */
228 return ne_probe1(dev, base_addr);
229 else if (base_addr != 0) /* Don't probe at all. */
230 return -ENXIO;
232 /* Then look for any installed ISAPnP clones */
233 if (isapnp_present() && (ne_probe_isapnp(dev) == 0))
234 return 0;
236 #ifndef MODULE
237 /* Last resort. The semi-risky ISA auto-probe. */
238 for (base_addr = 0; netcard_portlist[base_addr] != 0; base_addr++) {
239 int ioaddr = netcard_portlist[base_addr];
240 dev->irq = orig_irq;
241 if (ne_probe1(dev, ioaddr) == 0)
242 return 0;
244 #endif
246 return -ENODEV;
249 static void cleanup_card(struct net_device *dev)
251 struct pnp_dev *idev = (struct pnp_dev *)ei_status.priv;
252 if (idev)
253 pnp_device_detach(idev);
254 free_irq(dev->irq, dev);
255 #if !defined(CONFIG_COLDFIRE) && !defined(CONFIG_CPU_H8300H)
256 release_region(dev->base_addr, NE_IO_EXTENT);
257 #endif
260 #ifndef MODULE
261 struct net_device * __init ne_probe(int unit)
263 struct net_device *dev = alloc_ei_netdev();
264 int err;
266 if (!dev)
267 return ERR_PTR(-ENOMEM);
268 sprintf(dev->name, "eth%d", unit);
269 netdev_boot_setup_check(dev);
271 err = do_ne_probe(dev);
272 if (err)
273 goto out;
274 err = register_netdev(dev);
275 if (err)
276 goto out1;
277 return dev;
278 out1:
279 cleanup_card(dev);
280 out:
281 free_netdev(dev);
282 return ERR_PTR(err);
284 #endif
286 static int __init ne_probe_isapnp(struct net_device *dev)
288 int i;
290 for (i = 0; isapnp_clone_list[i].vendor != 0; i++) {
291 struct pnp_dev *idev = NULL;
293 while ((idev = pnp_find_dev(NULL,
294 isapnp_clone_list[i].vendor,
295 isapnp_clone_list[i].function,
296 idev))) {
297 /* Avoid already found cards from previous calls */
298 if (pnp_device_attach(idev) < 0)
299 continue;
300 if (pnp_activate_dev(idev) < 0) {
301 pnp_device_detach(idev);
302 continue;
304 /* if no io and irq, search for next */
305 if (!pnp_port_valid(idev, 0) || !pnp_irq_valid(idev, 0)) {
306 pnp_device_detach(idev);
307 continue;
309 /* found it */
310 dev->base_addr = pnp_port_start(idev, 0);
311 dev->irq = pnp_irq(idev, 0);
312 printk(KERN_INFO "ne.c: ISAPnP reports %s at i/o %#lx, irq %d.\n",
313 (char *) isapnp_clone_list[i].driver_data,
314 dev->base_addr, dev->irq);
315 if (ne_probe1(dev, dev->base_addr) != 0) { /* Shouldn't happen. */
316 printk(KERN_ERR "ne.c: Probe of ISAPnP card at %#lx failed.\n", dev->base_addr);
317 pnp_device_detach(idev);
318 return -ENXIO;
320 ei_status.priv = (unsigned long)idev;
321 break;
323 if (!idev)
324 continue;
325 return 0;
328 return -ENODEV;
331 static int __init ne_probe1(struct net_device *dev, int ioaddr)
333 int i;
334 unsigned char SA_prom[32];
335 int wordlength = 2;
336 const char *name = NULL;
337 int start_page, stop_page;
338 int neX000, ctron, copam, bad_card;
339 int reg0, ret;
340 static unsigned version_printed;
342 #if !defined(CONFIG_COLDFIRE) && !defined(CONFIG_CPU_H8300H)
343 if (!request_region(ioaddr, NE_IO_EXTENT, dev->name))
344 return -EBUSY;
345 #endif
346 reg0 = inb_p(ioaddr);
347 if (reg0 == 0xFF) {
348 ret = -ENODEV;
349 goto err_out;
352 /* Do a preliminary verification that we have a 8390. */
354 int regd;
355 outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
356 regd = inb_p(ioaddr + 0x0d);
357 outb_p(0xff, ioaddr + 0x0d);
358 outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
359 inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
360 if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
361 outb_p(reg0, ioaddr);
362 outb_p(regd, ioaddr + 0x0d); /* Restore the old values. */
363 ret = -ENODEV;
364 goto err_out;
368 if (ei_debug && version_printed++ == 0)
369 printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2);
371 printk(KERN_INFO "NE*000 ethercard probe at %#3x:", ioaddr);
373 /* A user with a poor card that fails to ack the reset, or that
374 does not have a valid 0x57,0x57 signature can still use this
375 without having to recompile. Specifying an i/o address along
376 with an otherwise unused dev->mem_end value of "0xBAD" will
377 cause the driver to skip these parts of the probe. */
379 bad_card = ((dev->base_addr != 0) && (dev->mem_end == 0xbad));
381 /* Reset card. Who knows what dain-bramaged state it was left in. */
384 unsigned long reset_start_time = jiffies;
386 /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
387 outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
389 while ((inb_p(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
390 if (jiffies - reset_start_time > 2*HZ/100) {
391 if (bad_card) {
392 printk(" (warning: no reset ack)");
393 break;
394 } else {
395 printk(" not found (no reset ack).\n");
396 ret = -ENODEV;
397 goto err_out;
401 outb_p(0xff, ioaddr + EN0_ISR); /* Ack all intr. */
404 /* Read the 16 bytes of station address PROM.
405 We must first initialize registers, similar to NS8390_init(eifdev, 0).
406 We can't reliably read the SAPROM address without this.
407 (I learned the hard way!). */
409 struct {unsigned char value, offset; } program_seq[] =
411 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
412 {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
413 {0x00, EN0_RCNTLO}, /* Clear the count regs. */
414 {0x00, EN0_RCNTHI},
415 {0x00, EN0_IMR}, /* Mask completion irq. */
416 {0xFF, EN0_ISR},
417 {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
418 {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
419 {32, EN0_RCNTLO},
420 {0x00, EN0_RCNTHI},
421 {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
422 {0x00, EN0_RSARHI},
423 {E8390_RREAD+E8390_START, E8390_CMD},
426 for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
427 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
430 for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
431 SA_prom[i] = inb(ioaddr + NE_DATAPORT);
432 SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
433 if (SA_prom[i] != SA_prom[i+1])
434 wordlength = 1;
437 #if defined(CONFIG_M5307) || defined(CONFIG_M5407)
439 outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
440 for(i = 0; i < 6; i++)
442 SA_prom[i] = inb(ioaddr + i + 1);
444 SA_prom[14] = SA_prom[15] = 0x57;
446 #endif /* CONFIG_M5307 || CONFIG_M5407 */
447 #if defined(CONFIG_NETtel) || defined(CONFIG_SECUREEDGEMP3)
449 unsigned char *ep;
450 static int nr = 0;
451 ep = (unsigned char *) (0xf0006000 + (nr++ * 6));
453 * MAC address should be in FLASH, check that it is valid.
454 * If good use it, otherwise use the default.
456 if (((ep[0] == 0xff) && (ep[1] == 0xff) && (ep[2] == 0xff) &&
457 (ep[3] == 0xff) && (ep[4] == 0xff) && (ep[5] == 0xff)) ||
458 ((ep[0] == 0) && (ep[1] == 0) && (ep[2] == 0) &&
459 (ep[3] == 0) && (ep[4] == 0) && (ep[5] == 0))) {
460 ep = (unsigned char *) &ne_defethaddr[0];
461 ne_defethaddr[5]++;
464 for(i = 0; i < 6; i++)
465 SA_prom[i] = ep[i];
466 SA_prom[14] = SA_prom[15] = 0x57;
468 #if defined(CONFIG_M5206e) && defined(CONFIG_NETtel)
469 wordlength = 1;
471 /* We must set the 8390 for 8bit mode. */
472 outb_p(0x48, ioaddr + EN0_DCFG);
473 #endif
474 start_page = NESM_START_PG;
475 stop_page = NESM_STOP_PG;
477 #elif defined(CONFIG_CFV240)
479 unsigned char *ep = (unsigned char *) 0xffc0406b;
481 * MAC address should be in FLASH, check that it is valid.
482 * If good use it, otherwise use the default.
484 if (((ep[0] == 0xff) && (ep[1] == 0xff) && (ep[2] == 0xff) &&
485 (ep[3] == 0xff) && (ep[4] == 0xff) && (ep[5] == 0xff)) ||
486 ((ep[0] == 0) && (ep[1] == 0) && (ep[2] == 0) &&
487 (ep[3] == 0) && (ep[4] == 0) && (ep[5] == 0))) {
488 ep = (unsigned char *) &ne_defethaddr[0];
489 ne_defethaddr[5]++;
491 outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
492 for(i = 0; i < 6; i++)
493 SA_prom[i] = ep[i];
494 SA_prom[14] = SA_prom[15] = 0x57;
496 #elif defined(CONFIG_M5206e)
498 outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
499 for(i = 0; i < 6; i++)
501 SA_prom[i] = inb(ioaddr + i + 1);
503 SA_prom[14] = SA_prom[15] = 0x57;
504 if(!SA_prom[0] && !SA_prom[1] && !SA_prom[2]) {
505 /* It doesn't seem to be a correct start of a mac-address... */
506 printk("(change MAC=[%02X %02X %02X]->[%02X %02X %02X])",
507 SA_prom[0], SA_prom[1], SA_prom[2],
508 ne_defethaddr[0],ne_defethaddr[1],ne_defethaddr[2]);
509 SA_prom[0] = ne_defethaddr[0];
510 SA_prom[1] = ne_defethaddr[1];
511 SA_prom[2] = ne_defethaddr[2];
514 #endif /* CONFIG_M5206e */
516 #if !(defined(CONFIG_M5206e) && defined(CONFIG_NETtel))
517 if (wordlength == 2)
519 #ifndef CONFIG_COLDFIRE
520 for (i = 0; i < 16; i++)
521 SA_prom[i] = SA_prom[i+i];
522 #endif
523 /* We must set the 8390 for word mode. */
524 outb_p(DCR_VAL, ioaddr + EN0_DCFG);
525 start_page = NESM_START_PG;
526 stop_page = NESM_STOP_PG;
527 } else {
528 start_page = NE1SM_START_PG;
529 stop_page = NE1SM_STOP_PG;
531 #endif
532 #if defined(CONFIG_CPU_H8300H)
533 start_page = NESM_START_PG;
534 stop_page = NESM_STOP_PG;
535 H8300_INIT_NE();
536 #endif
538 #if defined(CONFIG_PLAT_MAPPI) || defined(CONFIG_PLAT_OAKS32R)
539 neX000 = ((SA_prom[14] == 0x57 && SA_prom[15] == 0x57)
540 || (SA_prom[14] == 0x42 && SA_prom[15] == 0x42));
541 #else
542 neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
543 #endif
544 ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
545 copam = (SA_prom[14] == 0x49 && SA_prom[15] == 0x00);
547 /* Set up the rest of the parameters. */
548 if (neX000 || bad_card || copam) {
549 name = (wordlength == 2) ? "NE2000" : "NE1000";
551 else if (ctron)
553 name = (wordlength == 2) ? "Ctron-8" : "Ctron-16";
554 start_page = 0x01;
555 stop_page = (wordlength == 2) ? 0x40 : 0x20;
557 else
559 #ifdef SUPPORT_NE_BAD_CLONES
560 /* Ack! Well, there might be a *bad* NE*000 clone there.
561 Check for total bogus addresses. */
562 for (i = 0; bad_clone_list[i].name8; i++)
564 if (SA_prom[0] == bad_clone_list[i].SAprefix[0] &&
565 SA_prom[1] == bad_clone_list[i].SAprefix[1] &&
566 SA_prom[2] == bad_clone_list[i].SAprefix[2])
568 if (wordlength == 2)
570 name = bad_clone_list[i].name16;
571 } else {
572 name = bad_clone_list[i].name8;
574 break;
577 if (bad_clone_list[i].name8 == NULL)
579 printk(" not found (invalid signature %2.2x %2.2x).\n",
580 SA_prom[14], SA_prom[15]);
581 ret = -ENXIO;
582 goto err_out;
584 #else
585 printk(" not found.\n");
586 ret = -ENXIO;
587 goto err_out;
588 #endif
591 if (dev->irq < 2)
593 unsigned long cookie = probe_irq_on();
594 outb_p(0x50, ioaddr + EN0_IMR); /* Enable one interrupt. */
595 outb_p(0x00, ioaddr + EN0_RCNTLO);
596 outb_p(0x00, ioaddr + EN0_RCNTHI);
597 outb_p(E8390_RREAD+E8390_START, ioaddr); /* Trigger it... */
598 mdelay(10); /* wait 10ms for interrupt to propagate */
599 outb_p(0x00, ioaddr + EN0_IMR); /* Mask it again. */
600 dev->irq = probe_irq_off(cookie);
601 if (ei_debug > 2)
602 printk(" autoirq is %d\n", dev->irq);
603 } else if (dev->irq == 2)
604 /* Fixup for users that don't know that IRQ 2 is really IRQ 9,
605 or don't know which one to set. */
606 dev->irq = 9;
608 if (! dev->irq) {
609 printk(" failed to detect IRQ line.\n");
610 ret = -EAGAIN;
611 goto err_out;
614 /* Snarf the interrupt now. There's no point in waiting since we cannot
615 share and the board will usually be enabled. */
616 ret = request_irq(dev->irq, ei_interrupt, 0, name, dev);
617 #ifdef CONFIG_COLDFIRE
618 if (ret == 0)
619 ne2000_irqsetup(dev->irq);
620 #endif
621 if (ret) {
622 printk (" unable to get IRQ %d (errno=%d).\n", dev->irq, ret);
623 goto err_out;
626 dev->base_addr = ioaddr;
628 #ifdef CONFIG_PLAT_MAPPI
629 outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP,
630 ioaddr + E8390_CMD); /* 0x61 */
631 for (i = 0 ; i < ETHER_ADDR_LEN ; i++) {
632 dev->dev_addr[i] = SA_prom[i]
633 = inb_p(ioaddr + EN1_PHYS_SHIFT(i));
634 printk(" %2.2x", SA_prom[i]);
636 #else
637 for(i = 0; i < ETHER_ADDR_LEN; i++) {
638 printk(" %2.2x", SA_prom[i]);
639 dev->dev_addr[i] = SA_prom[i];
641 #endif
643 printk("\n%s: %s found at %#x, using IRQ %d.\n",
644 dev->name, name, ioaddr, dev->irq);
646 ei_status.name = name;
647 ei_status.tx_start_page = start_page;
648 ei_status.stop_page = stop_page;
649 #ifdef CONFIG_PLAT_OAKS32R
650 ei_status.word16 = 0;
651 #else
652 ei_status.word16 = (wordlength == 2);
653 #endif
655 ei_status.rx_start_page = start_page + TX_PAGES;
656 #ifdef PACKETBUF_MEMSIZE
657 /* Allow the packet buffer size to be overridden by know-it-alls. */
658 ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
659 #endif
661 ei_status.reset_8390 = &ne_reset_8390;
662 ei_status.block_input = &ne_block_input;
663 ei_status.block_output = &ne_block_output;
664 ei_status.get_8390_hdr = &ne_get_8390_hdr;
665 ei_status.priv = 0;
666 dev->open = &ne_open;
667 dev->stop = &ne_close;
668 #ifdef CONFIG_NET_POLL_CONTROLLER
669 dev->poll_controller = ei_poll;
670 #endif
671 NS8390_init(dev, 0);
672 return 0;
674 err_out:
675 #if !defined(CONFIG_COLDFIRE) && !defined(CONFIG_CPU_H8300H)
676 release_region(ioaddr, NE_IO_EXTENT);
677 #endif
678 return ret;
681 static int ne_open(struct net_device *dev)
683 ei_open(dev);
684 return 0;
687 static int ne_close(struct net_device *dev)
689 if (ei_debug > 1)
690 printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
691 ei_close(dev);
692 return 0;
695 /* Hard reset the card. This used to pause for the same period that a
696 8390 reset command required, but that shouldn't be necessary. */
698 static void ne_reset_8390(struct net_device *dev)
700 unsigned long reset_start_time = jiffies;
702 if (ei_debug > 1)
703 printk(KERN_DEBUG "resetting the 8390 t=%ld...", jiffies);
705 /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
706 outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
708 ei_status.txing = 0;
709 ei_status.dmaing = 0;
711 /* This check _should_not_ be necessary, omit eventually. */
712 while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
713 if (jiffies - reset_start_time > 2*HZ/100) {
714 printk(KERN_WARNING "%s: ne_reset_8390() did not complete.\n", dev->name);
715 break;
717 outb_p(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */
720 /* Grab the 8390 specific header. Similar to the block_input routine, but
721 we don't need to be concerned with ring wrap as the header will be at
722 the start of a page, so we optimize accordingly. */
724 static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
726 int nic_base = dev->base_addr;
728 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
730 if (ei_status.dmaing)
732 printk(KERN_EMERG "%s: DMAing conflict in ne_get_8390_hdr "
733 "[DMAstat:%d][irqlock:%d].\n",
734 dev->name, ei_status.dmaing, ei_status.irqlock);
735 return;
738 ei_status.dmaing |= 0x01;
739 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
740 outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
741 outb_p(0, nic_base + EN0_RCNTHI);
742 outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
743 outb_p(ring_page, nic_base + EN0_RSARHI);
744 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
746 if (ei_status.word16)
747 insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
748 else
749 insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
751 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
752 ei_status.dmaing &= ~0x01;
754 le16_to_cpus(&hdr->count);
757 /* Block input and output, similar to the Crynwr packet driver. If you
758 are porting to a new ethercard, look at the packet driver source for hints.
759 The NEx000 doesn't share the on-board packet memory -- you have to put
760 the packet out through the "remote DMA" dataport using outb. */
762 static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
764 #ifdef NE_SANITY_CHECK
765 int xfer_count = count;
766 #endif
767 int nic_base = dev->base_addr;
768 char *buf = skb->data;
770 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
771 if (ei_status.dmaing)
773 printk(KERN_EMERG "%s: DMAing conflict in ne_block_input "
774 "[DMAstat:%d][irqlock:%d].\n",
775 dev->name, ei_status.dmaing, ei_status.irqlock);
776 return;
778 ei_status.dmaing |= 0x01;
779 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
780 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
781 outb_p(count >> 8, nic_base + EN0_RCNTHI);
782 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
783 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
784 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
785 if (ei_status.word16)
787 insw(NE_BASE + NE_DATAPORT,buf,count>>1);
788 if (count & 0x01)
790 buf[count-1] = inb(NE_BASE + NE_DATAPORT);
791 #ifdef NE_SANITY_CHECK
792 xfer_count++;
793 #endif
795 } else {
796 insb(NE_BASE + NE_DATAPORT, buf, count);
799 #ifdef NE_SANITY_CHECK
800 /* This was for the ALPHA version only, but enough people have
801 been encountering problems so it is still here. If you see
802 this message you either 1) have a slightly incompatible clone
803 or 2) have noise/speed problems with your bus. */
805 if (ei_debug > 1)
807 /* DMA termination address check... */
808 int addr, tries = 20;
809 do {
810 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
811 -- it's broken for Rx on some cards! */
812 int high = inb_p(nic_base + EN0_RSARHI);
813 int low = inb_p(nic_base + EN0_RSARLO);
814 addr = (high << 8) + low;
815 if (((ring_offset + xfer_count) & 0xff) == low)
816 break;
817 } while (--tries > 0);
818 if (tries <= 0)
819 printk(KERN_WARNING "%s: RX transfer address mismatch,"
820 "%#4.4x (expected) vs. %#4.4x (actual).\n",
821 dev->name, ring_offset + xfer_count, addr);
823 #endif
824 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
825 ei_status.dmaing &= ~0x01;
828 static void ne_block_output(struct net_device *dev, int count,
829 const unsigned char *buf, const int start_page)
831 int nic_base = NE_BASE;
832 unsigned long dma_start;
833 #ifdef NE_SANITY_CHECK
834 int retries = 0;
835 #endif
837 /* Round the count up for word writes. Do we need to do this?
838 What effect will an odd byte count have on the 8390?
839 I should check someday. */
841 if (ei_status.word16 && (count & 0x01))
842 count++;
844 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
845 if (ei_status.dmaing)
847 printk(KERN_EMERG "%s: DMAing conflict in ne_block_output."
848 "[DMAstat:%d][irqlock:%d]\n",
849 dev->name, ei_status.dmaing, ei_status.irqlock);
850 return;
852 ei_status.dmaing |= 0x01;
853 /* We should already be in page 0, but to be safe... */
854 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
856 #ifdef NE_SANITY_CHECK
857 retry:
858 #endif
860 #ifdef NE8390_RW_BUGFIX
861 /* Handle the read-before-write bug the same way as the
862 Crynwr packet driver -- the NatSemi method doesn't work.
863 Actually this doesn't always work either, but if you have
864 problems with your NEx000 this is better than nothing! */
866 outb_p(0x42, nic_base + EN0_RCNTLO);
867 outb_p(0x00, nic_base + EN0_RCNTHI);
868 outb_p(0x42, nic_base + EN0_RSARLO);
869 outb_p(0x00, nic_base + EN0_RSARHI);
870 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
871 /* Make certain that the dummy read has occurred. */
872 udelay(6);
873 #endif
875 outb_p(ENISR_RDC, nic_base + EN0_ISR);
877 /* Now the normal output. */
878 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
879 outb_p(count >> 8, nic_base + EN0_RCNTHI);
880 outb_p(0x00, nic_base + EN0_RSARLO);
881 outb_p(start_page, nic_base + EN0_RSARHI);
883 outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
884 if (ei_status.word16) {
885 outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
886 } else {
887 outsb(NE_BASE + NE_DATAPORT, buf, count);
890 dma_start = jiffies;
892 #ifdef NE_SANITY_CHECK
893 /* This was for the ALPHA version only, but enough people have
894 been encountering problems so it is still here. */
896 if (ei_debug > 1)
898 /* DMA termination address check... */
899 int addr, tries = 20;
900 do {
901 int high = inb_p(nic_base + EN0_RSARHI);
902 int low = inb_p(nic_base + EN0_RSARLO);
903 addr = (high << 8) + low;
904 if ((start_page << 8) + count == addr)
905 break;
906 } while (--tries > 0);
908 if (tries <= 0)
910 printk(KERN_WARNING "%s: Tx packet transfer address mismatch,"
911 "%#4.4x (expected) vs. %#4.4x (actual).\n",
912 dev->name, (start_page << 8) + count, addr);
913 if (retries++ == 0)
914 goto retry;
917 #endif
919 while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
920 if (jiffies - dma_start > 2*HZ/100) { /* 20ms */
921 printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name);
922 ne_reset_8390(dev);
923 NS8390_init(dev,1);
924 break;
927 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
928 ei_status.dmaing &= ~0x01;
929 return;
933 #ifdef MODULE
934 #define MAX_NE_CARDS 4 /* Max number of NE cards per module */
935 static struct net_device *dev_ne[MAX_NE_CARDS];
936 static int io[MAX_NE_CARDS];
937 static int irq[MAX_NE_CARDS];
938 static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */
940 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
941 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
942 MODULE_PARM(bad, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
943 MODULE_PARM_DESC(io, "I/O base address(es),required");
944 MODULE_PARM_DESC(irq, "IRQ number(s)");
945 MODULE_PARM_DESC(bad, "Accept card(s) with bad signatures");
946 MODULE_DESCRIPTION("NE1000/NE2000 ISA/PnP Ethernet driver");
947 MODULE_LICENSE("GPL");
949 /* This is set up so that no ISA autoprobe takes place. We can't guarantee
950 that the ne2k probe is the last 8390 based probe to take place (as it
951 is at boot) and so the probe will get confused by any other 8390 cards.
952 ISA device autoprobes on a running machine are not recommended anyway. */
954 int init_module(void)
956 int this_dev, found = 0;
958 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
959 struct net_device *dev = alloc_ei_netdev();
960 if (!dev)
961 break;
962 dev->irq = irq[this_dev];
963 dev->mem_end = bad[this_dev];
964 dev->base_addr = io[this_dev];
965 if (do_ne_probe(dev) == 0) {
966 if (register_netdev(dev) == 0) {
967 dev_ne[found++] = dev;
968 continue;
970 cleanup_card(dev);
972 free_netdev(dev);
973 if (found)
974 break;
975 if (io[this_dev] != 0)
976 printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", io[this_dev]);
977 else
978 printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n");
979 return -ENXIO;
981 if (found)
982 return 0;
983 return -ENODEV;
986 void cleanup_module(void)
988 int this_dev;
990 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
991 struct net_device *dev = dev_ne[this_dev];
992 if (dev) {
993 unregister_netdev(dev);
994 cleanup_card(dev);
995 free_netdev(dev);
999 #endif /* MODULE */