3 ne2k_cbus.c: A driver for the NE2000 like ethernet on NEC PC-9800.
5 This is a copy of the 2.5.66 Linux ISA NE2000 driver "ne.c"
6 (Donald Becker/Paul Gortmaker) with the NEC PC-9800 specific
7 changes added by Osamu Tomita.
11 Copyright 1993 United States Government as represented by the
12 Director, National Security Agency.
14 This software may be used and distributed according to the terms
15 of the GNU General Public License, incorporated herein by reference.
20 /* Routines for the NatSemi-based designs (NE[12]000). */
22 static const char version[] =
23 "ne2k_cbus.c:v1.0 3/24/03 Osamu Tomita\n";
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/isapnp.h>
29 #include <linux/init.h>
30 #include <linux/interrupt.h>
31 #include <linux/delay.h>
32 #include <linux/netdevice.h>
33 #include <linux/etherdevice.h>
35 #include <asm/system.h>
40 /* Some defines that people can play with if so inclined. */
42 /* Do we support clones that don't adhere to 14,15 of the SAprom ? */
43 #define SUPPORT_NE_BAD_CLONES
45 /* Do we perform extra sanity checks on stuff ? */
46 /* #define NE_SANITY_CHECK */
48 /* Do we implement the read before write bugfix ? */
49 /* #define NE_RW_BUGFIX */
51 /* Do we have a non std. amount of memory? (in units of 256 byte pages) */
52 /* #define PACKETBUF_MEMSIZE 0x40 */
54 #ifdef SUPPORT_NE_BAD_CLONES
55 /* A list of bad clones that we none-the-less recognize. */
56 static struct { const char *name8, *name16; unsigned char SAprefix[4];}
57 bad_clone_list[] __initdata = {
58 {"LA/T-98?", "LA/T-98", {0x00, 0xa0, 0xb0}}, /* I/O Data */
59 {"EGY-98?", "EGY-98", {0x00, 0x40, 0x26}}, /* Melco EGY98 */
60 {"ICM?", "ICM-27xx-ET", {0x00, 0x80, 0xc8}}, /* ICM IF-27xx-ET */
61 {"CNET-98/EL?", "CNET(98)E/L", {0x00, 0x80, 0x4C}}, /* Contec CNET-98/EL */
66 /* ---- No user-serviceable parts below ---- */
68 #define NE_BASE (dev->base_addr)
69 #define NE_CMD EI_SHIFT(0x00)
70 #define NE_DATAPORT EI_SHIFT(0x10) /* NatSemi-defined port window offset. */
71 #define NE_RESET EI_SHIFT(0x1f) /* Issue a read to reset, a write to clear. */
72 #define NE_IO_EXTENT 0x20
74 #define NE1SM_START_PG 0x20 /* First page of TX buffer */
75 #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
76 #define NESM_START_PG 0x40 /* First page of TX buffer */
77 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
79 #include "ne2k_cbus.h"
81 static int ne_probe1(struct net_device *dev, int ioaddr);
82 static int ne_open(struct net_device *dev);
83 static int ne_close(struct net_device *dev);
85 static void ne_reset_8390(struct net_device *dev);
86 static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
88 static void ne_block_input(struct net_device *dev, int count,
89 struct sk_buff *skb, int ring_offset);
90 static void ne_block_output(struct net_device *dev, const int count,
91 const unsigned char *buf, const int start_page);
94 /* Probe for various non-shared-memory ethercards.
96 NEx000-clone boards have a Station Address PROM (SAPROM) in the packet
97 buffer memory space. NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of
98 the SAPROM, while other supposed NE2000 clones must be detected by their
101 Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
102 mode results in doubled values, which can be detected and compensated for.
104 The probe is also responsible for initializing the card and filling
105 in the 'dev' and 'ei_status' structures.
107 We use the minimum memory size for some ethercard product lines, iff we can't
108 distinguish models. You can increase the packet buffer size by setting
109 PACKETBUF_MEMSIZE. Reported Cabletron packet buffer locations are:
110 E1010 starts at 0x100 and ends at 0x2000.
111 E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory")
112 E2010 starts at 0x100 and ends at 0x4000.
113 E2010-x starts at 0x100 and ends at 0xffff. */
115 static int __init do_ne_probe(struct net_device *dev)
117 unsigned int base_addr = dev->base_addr;
120 SET_MODULE_OWNER(dev);
123 printk(KERN_DEBUG "ne_probe(): entered.\n");
125 /* If CONFIG_NET_CBUS,
126 we need dev->priv->reg_offset BEFORE to probe */
127 if (ne2k_cbus_init(dev) != 0)
130 /* First check any supplied i/o locations. User knows best. <cough> */
133 const struct ne2k_cbus_hwinfo *hw = ne2k_cbus_get_hwinfo((int)(dev->mem_start & NE2K_CBUS_HARDWARE_TYPE_MASK));
136 printk(KERN_DEBUG "ne_probe(): call ne_probe_cbus(base_addr=0x%x)\n", base_addr);
138 result = ne_probe_cbus(dev, hw, base_addr, irq);
140 ne2k_cbus_destroy(dev);
146 printk(KERN_DEBUG "ne_probe(): base_addr is not specified.\n");
149 /* Last resort. The semi-risky C-Bus auto-probe. */
151 printk(KERN_DEBUG "ne_probe(): auto-probe start.\n");
154 const struct ne2k_cbus_hwinfo *hw = ne2k_cbus_get_hwinfo((int)(dev->mem_start & NE2K_CBUS_HARDWARE_TYPE_MASK));
156 if (hw && hw->hwtype) {
157 const unsigned short *plist;
158 for (plist = hw->portlist; *plist; plist++)
159 if (ne_probe_cbus(dev, hw, *plist, irq) == 0)
162 for (hw = &ne2k_cbus_hwinfo_list[0]; hw->hwtype; hw++) {
163 const unsigned short *plist;
164 for (plist = hw->portlist; *plist; plist++)
165 if (ne_probe_cbus(dev, hw, *plist, irq) == 0)
172 ne2k_cbus_destroy(dev);
177 static void cleanup_card(struct net_device *dev)
179 const struct ne2k_cbus_region *rlist;
180 const struct ne2k_cbus_hwinfo *hw = ne2k_cbus_get_hwinfo((int)(dev->mem_start & NE2K_CBUS_HARDWARE_TYPE_MASK));
182 free_irq(dev->irq, dev);
183 for (rlist = hw->regionlist; rlist->range; rlist++) {
184 release_region(dev->base_addr + rlist->start,
187 ne2k_cbus_destroy(dev);
190 struct net_device * __init ne_probe(int unit)
192 struct net_device *dev = alloc_ei_netdev();
196 return ERR_PTR(-ENOMEM);
198 sprintf(dev->name, "eth%d", unit);
199 netdev_boot_setup_check(dev);
201 err = do_ne_probe(dev);
204 err = register_netdev(dev);
215 static int __init ne_probe_cbus(struct net_device *dev, const struct ne2k_cbus_hwinfo *hw, int ioaddr, int irq)
218 printk(KERN_DEBUG "ne_probe_cbus(): entered. (called from %p)\n",
219 __builtin_return_address(0));
221 if (hw && hw->hwtype) {
222 ne2k_cbus_set_hwtype(dev, hw, ioaddr);
224 return ne_probe1(dev, ioaddr);
228 printk(KERN_DEBUG "ne_probe_cbus(): try to determine hardware types.\n");
229 for (hw = &ne2k_cbus_hwinfo_list[0]; hw->hwtype; hw++) {
230 ne2k_cbus_set_hwtype(dev, hw, ioaddr);
232 if (ne_probe1(dev, ioaddr) == 0)
239 static int __init ne_probe1(struct net_device *dev, int ioaddr)
242 unsigned char SA_prom[32];
244 const char *name = NULL;
245 int start_page, stop_page;
246 int neX000, bad_card;
248 static unsigned version_printed;
249 const struct ne2k_cbus_region *rlist;
250 const struct ne2k_cbus_hwinfo *hw = ne2k_cbus_get_hwinfo((int)(dev->mem_start & NE2K_CBUS_HARDWARE_TYPE_MASK));
251 struct ei_device *ei_local = (struct ei_device *)(dev->priv);
253 #ifdef CONFIG_NE2K_CBUS_CNET98EL
254 if (hw->hwtype == NE2K_CBUS_HARDWARE_TYPE_CNET98EL) {
255 outb_p(0, CONFIG_NE2K_CBUS_CNET98EL_IO_BASE);
257 outb_p(1, CONFIG_NE2K_CBUS_CNET98EL_IO_BASE);
259 outb_p((ioaddr & 0xf000) >> 8 | 0x08 | 0x01, CONFIG_NE2K_CBUS_CNET98EL_IO_BASE + 2);
264 for (rlist = hw->regionlist; rlist->range; rlist++)
265 if (!request_region(ioaddr + rlist->start,
266 rlist->range, dev->name)) {
271 reg0 = inb_p(ioaddr + EI_SHIFT(0));
277 /* Do a preliminary verification that we have a 8390. */
278 #ifdef CONFIG_NE2K_CBUS_CNET98EL
279 if (hw->hwtype != NE2K_CBUS_HARDWARE_TYPE_CNET98EL)
283 outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
284 regd = inb_p(ioaddr + EI_SHIFT(0x0d));
285 outb_p(0xff, ioaddr + EI_SHIFT(0x0d));
286 outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
287 inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
288 if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
289 outb_p(reg0, ioaddr);
290 outb_p(regd, ioaddr + EI_SHIFT(0x0d)); /* Restore the old values. */
296 if (ei_debug && version_printed++ == 0)
297 printk(KERN_INFO "%s", version);
299 printk(KERN_INFO "NE*000 ethercard probe at %#3x:", ioaddr);
301 /* A user with a poor card that fails to ack the reset, or that
302 does not have a valid 0x57,0x57 signature can still use this
303 without having to recompile. Specifying an i/o address along
304 with an otherwise unused dev->mem_end value of "0xBAD" will
305 cause the driver to skip these parts of the probe. */
307 bad_card = ((dev->base_addr != 0) && (dev->mem_end == 0xbad));
309 /* Reset card. Who knows what dain-bramaged state it was left in. */
312 unsigned long reset_start_time = jiffies;
314 /* derived from CNET98EL-patch for bad clones */
315 outb_p(E8390_NODMA | E8390_STOP, ioaddr + E8390_CMD);
317 /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
318 outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
320 while ((inb_p(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
321 if (jiffies - reset_start_time > 2*HZ/100) {
323 printk(" (warning: no reset ack)");
326 printk(" not found (no reset ack).\n");
332 outb_p(0xff, ioaddr + EN0_ISR); /* Ack all intr. */
335 #ifdef CONFIG_NE2K_CBUS_CNET98EL
336 if (hw->hwtype == NE2K_CBUS_HARDWARE_TYPE_CNET98EL) {
337 static const char pat[32] ="AbcdeFghijKlmnoPqrstUvwxyZ789012";
342 printk(" [CNET98EL-specific initialize...");
343 outb_p(E8390_NODMA | E8390_STOP, ioaddr + E8390_CMD); /* 0x20|0x1 */
346 if ((i & ~0x2) != (0x20 | 0x01))
348 if ((inb(ioaddr + 0x7) & 0x80) != 0x80)
350 outb_p(E8390_RXOFF, ioaddr + EN0_RXCR); /* out(ioaddr+0xc, 0x20) */
351 /* outb_p(ENDCFG_WTS|ENDCFG_FT1|ENDCFG_LS, ioaddr+EN0_DCFG); */
352 outb_p(ENDCFG_WTS | 0x48, ioaddr + EN0_DCFG); /* 0x49 */
353 outb_p(CNET98EL_START_PG, ioaddr + EN0_STARTPG);
354 outb_p(CNET98EL_STOP_PG, ioaddr + EN0_STOPPG);
356 printk("memory check");
357 for (i = 0; i < 65536; i += 1024) {
360 ne2k_cbus_writemem(dev, ioaddr, i, pat, 32);
361 while (((inb(ioaddr + EN0_ISR) & ENISR_RDC) != ENISR_RDC) && --maxwait)
363 ne2k_cbus_readmem(dev, ioaddr, i, buf, 32);
364 if (memcmp(pat, buf, 32)) {
373 printk("memory failure at %x\n", i);
381 printk("IRQ must be specified for C-NET(98)E/L. probe failed.\n");
384 outb((dev->irq > 5) ? (dev->irq & 4):(dev->irq >> 1), ioaddr + (0x2 | 0x400));
385 outb(0x7e, ioaddr + (0x4 | 0x400));
386 ne2k_cbus_readmem(dev, ioaddr, 16384, SA_prom, 32);
387 outb(0xff, ioaddr + EN0_ISR);
391 #endif /* CONFIG_NE2K_CBUS_CNET98EL */
392 /* Read the 16 bytes of station address PROM.
393 We must first initialize registers, similar to NS8390_init(eifdev, 0).
394 We can't reliably read the SAPROM address without this.
395 (I learned the hard way!). */
397 struct {unsigned char value; unsigned short offset;} program_seq[] =
399 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
400 /* NEC PC-9800: some board can only handle word-wide access? */
401 {0x48 | ENDCFG_WTS, EN0_DCFG}, /* Set word-wide (0x48) access. */
402 {16384 / 256, EN0_STARTPG},
403 {32768 / 256, EN0_STOPPG},
404 {0x00, EN0_RCNTLO}, /* Clear the count regs. */
406 {0x00, EN0_IMR}, /* Mask completion irq. */
408 {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
409 {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
412 {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
414 {E8390_RREAD+E8390_START, E8390_CMD},
417 for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
418 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
419 insw(ioaddr + NE_DATAPORT, SA_prom, 32 >> 1);
425 for (i = 0; i < 16; i++)
426 SA_prom[i] = SA_prom[i+i];
427 start_page = NESM_START_PG;
428 stop_page = NESM_STOP_PG;
429 #ifdef CONFIG_NE2K_CBUS_CNET98EL
430 if (hw->hwtype == NE2K_CBUS_HARDWARE_TYPE_CNET98EL) {
431 start_page = CNET98EL_START_PG;
432 stop_page = CNET98EL_STOP_PG;
436 start_page = NE1SM_START_PG;
437 stop_page = NE1SM_STOP_PG;
440 neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
442 name = "C-Bus-NE2K-compat";
446 #ifdef SUPPORT_NE_BAD_CLONES
447 /* Ack! Well, there might be a *bad* NE*000 clone there.
448 Check for total bogus addresses. */
449 for (i = 0; bad_clone_list[i].name8; i++)
451 if (SA_prom[0] == bad_clone_list[i].SAprefix[0] &&
452 SA_prom[1] == bad_clone_list[i].SAprefix[1] &&
453 SA_prom[2] == bad_clone_list[i].SAprefix[2])
457 name = bad_clone_list[i].name16;
459 name = bad_clone_list[i].name8;
464 if (bad_clone_list[i].name8 == NULL)
466 printk(" not found (invalid signature %2.2x %2.2x).\n",
467 SA_prom[14], SA_prom[15]);
472 printk(" not found.\n");
480 unsigned long cookie = probe_irq_on();
481 outb_p(0x50, ioaddr + EN0_IMR); /* Enable one interrupt. */
482 outb_p(0x00, ioaddr + EN0_RCNTLO);
483 outb_p(0x00, ioaddr + EN0_RCNTHI);
484 outb_p(E8390_RREAD+E8390_START, ioaddr); /* Trigger it... */
485 mdelay(10); /* wait 10ms for interrupt to propagate */
486 outb_p(0x00, ioaddr + EN0_IMR); /* Mask it again. */
487 dev->irq = probe_irq_off(cookie);
489 printk(" autoirq is %d\n", dev->irq);
490 } else if (dev->irq == 7)
491 /* Fixup for users that don't know that IRQ 7 is really IRQ 11,
492 or don't know which one to set. */
496 printk(" failed to detect IRQ line.\n");
501 /* Snarf the interrupt now. There's no point in waiting since we cannot
502 share and the board will usually be enabled. */
503 ret = request_irq(dev->irq, ei_interrupt, 0, name, dev);
505 printk (" unable to get IRQ %d (errno=%d).\n", dev->irq, ret);
509 dev->base_addr = ioaddr;
511 for(i = 0; i < ETHER_ADDR_LEN; i++) {
512 printk(" %2.2x", SA_prom[i]);
513 dev->dev_addr[i] = SA_prom[i];
516 printk("\n%s: %s found at %#x, hardware type %d(%s), using IRQ %d.\n",
517 dev->name, name, ioaddr, hw->hwtype, hw->hwident, dev->irq);
519 ei_status.name = name;
520 ei_status.tx_start_page = start_page;
521 ei_status.stop_page = stop_page;
522 ei_status.word16 = (wordlength == 2);
524 ei_status.rx_start_page = start_page + TX_PAGES;
525 #ifdef PACKETBUF_MEMSIZE
526 /* Allow the packet buffer size to be overridden by know-it-alls. */
527 ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
530 ei_status.reset_8390 = &ne_reset_8390;
531 ei_status.block_input = &ne_block_input;
532 ei_status.block_output = &ne_block_output;
533 ei_status.get_8390_hdr = &ne_get_8390_hdr;
535 dev->open = &ne_open;
536 dev->stop = &ne_close;
537 #ifdef CONFIG_NET_POLL_CONTROLLER
538 dev->poll_controller = ei_poll;
544 ne2k_cbus_destroy(dev);
546 while (rlist > hw->regionlist) {
548 release_region(ioaddr + rlist->start, rlist->range);
553 static int ne_open(struct net_device *dev)
559 static int ne_close(struct net_device *dev)
562 printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
567 /* Hard reset the card. This used to pause for the same period that a
568 8390 reset command required, but that shouldn't be necessary. */
570 static void ne_reset_8390(struct net_device *dev)
572 unsigned long reset_start_time = jiffies;
573 struct ei_device *ei_local = (struct ei_device *)(dev->priv);
576 printk(KERN_DEBUG "resetting the 8390 t=%ld...", jiffies);
578 /* derived from CNET98EL-patch for bad clones... */
579 outb_p(E8390_NODMA | E8390_STOP, NE_BASE + E8390_CMD); /* 0x20 | 0x1 */
581 /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
582 outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
585 ei_status.dmaing = 0;
587 /* This check _should_not_ be necessary, omit eventually. */
588 while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
589 if (jiffies - reset_start_time > 2*HZ/100) {
590 printk(KERN_WARNING "%s: ne_reset_8390() did not complete.\n", dev->name);
593 outb_p(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */
596 /* Grab the 8390 specific header. Similar to the block_input routine, but
597 we don't need to be concerned with ring wrap as the header will be at
598 the start of a page, so we optimize accordingly. */
600 static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
602 int nic_base = dev->base_addr;
603 struct ei_device *ei_local = (struct ei_device *)(dev->priv);
605 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
607 if (ei_status.dmaing)
609 printk(KERN_EMERG "%s: DMAing conflict in ne_get_8390_hdr "
610 "[DMAstat:%d][irqlock:%d].\n",
611 dev->name, ei_status.dmaing, ei_status.irqlock);
615 ei_status.dmaing |= 0x01;
616 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
617 outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
618 outb_p(0, nic_base + EN0_RCNTHI);
619 outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
620 outb_p(ring_page, nic_base + EN0_RSARHI);
621 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
623 if (ei_status.word16)
624 insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
626 insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
628 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
629 ei_status.dmaing &= ~0x01;
631 le16_to_cpus(&hdr->count);
634 /* Block input and output, similar to the Crynwr packet driver. If you
635 are porting to a new ethercard, look at the packet driver source for hints.
636 The NEx000 doesn't share the on-board packet memory -- you have to put
637 the packet out through the "remote DMA" dataport using outb. */
639 static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
641 #ifdef NE_SANITY_CHECK
642 int xfer_count = count;
644 int nic_base = dev->base_addr;
645 char *buf = skb->data;
646 struct ei_device *ei_local = (struct ei_device *)(dev->priv);
648 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
649 if (ei_status.dmaing)
651 printk(KERN_EMERG "%s: DMAing conflict in ne_block_input "
652 "[DMAstat:%d][irqlock:%d].\n",
653 dev->name, ei_status.dmaing, ei_status.irqlock);
656 ei_status.dmaing |= 0x01;
658 /* round up count to a word (derived from ICM-patch) */
659 count = (count + 1) & ~1;
661 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
662 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
663 outb_p(count >> 8, nic_base + EN0_RCNTHI);
664 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
665 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
666 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
667 if (ei_status.word16)
669 insw(NE_BASE + NE_DATAPORT,buf,count>>1);
672 buf[count-1] = inb(NE_BASE + NE_DATAPORT);
673 #ifdef NE_SANITY_CHECK
678 insb(NE_BASE + NE_DATAPORT, buf, count);
681 #ifdef NE_SANITY_CHECK
682 /* This was for the ALPHA version only, but enough people have
683 been encountering problems so it is still here. If you see
684 this message you either 1) have a slightly incompatible clone
685 or 2) have noise/speed problems with your bus. */
689 /* DMA termination address check... */
690 int addr, tries = 20;
692 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
693 -- it's broken for Rx on some cards! */
694 int high = inb_p(nic_base + EN0_RSARHI);
695 int low = inb_p(nic_base + EN0_RSARLO);
696 addr = (high << 8) + low;
697 if (((ring_offset + xfer_count) & 0xff) == low)
699 } while (--tries > 0);
701 printk(KERN_WARNING "%s: RX transfer address mismatch,"
702 "%#4.4x (expected) vs. %#4.4x (actual).\n",
703 dev->name, ring_offset + xfer_count, addr);
706 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
707 ei_status.dmaing &= ~0x01;
710 static void ne_block_output(struct net_device *dev, int count,
711 const unsigned char *buf, const int start_page)
713 int nic_base = NE_BASE;
714 unsigned long dma_start;
715 #ifdef NE_SANITY_CHECK
718 struct ei_device *ei_local = (struct ei_device *)(dev->priv);
720 /* Round the count up for word writes. Do we need to do this?
721 What effect will an odd byte count have on the 8390?
722 I should check someday. */
724 if (ei_status.word16 && (count & 0x01))
727 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
728 if (ei_status.dmaing)
730 printk(KERN_EMERG "%s: DMAing conflict in ne_block_output."
731 "[DMAstat:%d][irqlock:%d]\n",
732 dev->name, ei_status.dmaing, ei_status.irqlock);
735 ei_status.dmaing |= 0x01;
736 /* We should already be in page 0, but to be safe... */
737 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
739 #ifdef NE_SANITY_CHECK
743 #ifdef NE8390_RW_BUGFIX
744 /* Handle the read-before-write bug the same way as the
745 Crynwr packet driver -- the NatSemi method doesn't work.
746 Actually this doesn't always work either, but if you have
747 problems with your NEx000 this is better than nothing! */
749 outb_p(0x42, nic_base + EN0_RCNTLO);
750 outb_p(0x00, nic_base + EN0_RCNTHI);
751 outb_p(0x42, nic_base + EN0_RSARLO);
752 outb_p(0x00, nic_base + EN0_RSARHI);
753 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
754 /* Make certain that the dummy read has occurred. */
758 outb_p(ENISR_RDC, nic_base + EN0_ISR);
760 /* Now the normal output. */
761 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
762 outb_p(count >> 8, nic_base + EN0_RCNTHI);
763 outb_p(0x00, nic_base + EN0_RSARLO);
764 outb_p(start_page, nic_base + EN0_RSARHI);
766 outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
767 if (ei_status.word16) {
768 outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
770 outsb(NE_BASE + NE_DATAPORT, buf, count);
775 #ifdef NE_SANITY_CHECK
776 /* This was for the ALPHA version only, but enough people have
777 been encountering problems so it is still here. */
781 /* DMA termination address check... */
782 int addr, tries = 20;
784 int high = inb_p(nic_base + EN0_RSARHI);
785 int low = inb_p(nic_base + EN0_RSARLO);
786 addr = (high << 8) + low;
787 if ((start_page << 8) + count == addr)
789 } while (--tries > 0);
793 printk(KERN_WARNING "%s: Tx packet transfer address mismatch,"
794 "%#4.4x (expected) vs. %#4.4x (actual).\n",
795 dev->name, (start_page << 8) + count, addr);
802 while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
803 if (jiffies - dma_start > 2*HZ/100) { /* 20ms */
804 printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name);
810 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
811 ei_status.dmaing &= ~0x01;
817 #define MAX_NE_CARDS 4 /* Max number of NE cards per module */
818 static struct net_device *dev_ne[MAX_NE_CARDS];
819 static int io[MAX_NE_CARDS];
820 static int irq[MAX_NE_CARDS];
821 static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */
822 static int hwtype[MAX_NE_CARDS] = { 0, }; /* board type */
824 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
825 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
826 MODULE_PARM(bad, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
827 MODULE_PARM(hwtype, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
828 MODULE_PARM_DESC(io, "I/O base address(es),required");
829 MODULE_PARM_DESC(irq, "IRQ number(s)");
830 MODULE_PARM_DESC(bad, "Accept card(s) with bad signatures");
831 MODULE_PARM_DESC(hwtype, "Board type of PC-9800 C-Bus NIC");
832 MODULE_DESCRIPTION("NE1000/NE2000 PC-9800 C-bus Ethernet driver");
833 MODULE_LICENSE("GPL");
835 /* This is set up so that no ISA autoprobe takes place. We can't guarantee
836 that the ne2k probe is the last 8390 based probe to take place (as it
837 is at boot) and so the probe will get confused by any other 8390 cards.
838 ISA device autoprobes on a running machine are not recommended anyway. */
840 int init_module(void)
842 int this_dev, found = 0;
844 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
845 struct net_device *dev = alloc_ei_netdev();
848 dev->irq = irq[this_dev];
849 dev->mem_end = bad[this_dev];
850 dev->base_addr = io[this_dev];
851 dev->mem_start = hwtype[this_dev];
852 if (do_ne_probe(dev) == 0) {
853 if (register_netdev(dev) == 0) {
854 dev_ne[found++] = dev;
862 if (io[this_dev] != 0)
863 printk(KERN_WARNING "ne2k_cbus: No NE*000 card found at i/o = %#x\n", io[this_dev]);
865 printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n");
873 void cleanup_module(void)
877 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
878 struct net_device *dev = dev_ne[this_dev];
880 unregister_netdev(dev);