1 /* ne.c: A general non-shared-memory NS8390 ethernet driver for linux. */
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.
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 Osamu Tomita : Separate driver for NEC PC-9800.
36 /* Routines for the NatSemi-based designs (NE[12]000). */
38 static const char version1
[] =
39 "ne.c:v1.10 9/23/94 Donald Becker (becker@scyld.com)\n";
40 static const char version2
[] =
41 "Last modified Nov 1, 2000 by Paul Gortmaker\n";
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/errno.h>
47 #include <linux/isapnp.h>
48 #include <linux/init.h>
49 #include <linux/interrupt.h>
50 #include <linux/delay.h>
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
54 #include <asm/system.h>
59 /* Some defines that people can play with if so inclined. */
61 /* Do we support clones that don't adhere to 14,15 of the SAprom ? */
62 #define SUPPORT_NE_BAD_CLONES
64 /* Do we perform extra sanity checks on stuff ? */
65 /* #define NE_SANITY_CHECK */
67 /* Do we implement the read before write bugfix ? */
68 /* #define NE_RW_BUGFIX */
70 /* Do we have a non std. amount of memory? (in units of 256 byte pages) */
71 /* #define PACKETBUF_MEMSIZE 0x40 */
73 #ifdef SUPPORT_NE_BAD_CLONES
74 /* A list of bad clones that we none-the-less recognize. */
75 static struct { const char *name8
, *name16
; unsigned char SAprefix
[4];}
76 bad_clone_list
[] __initdata
= {
77 {"LA/T-98?", "LA/T-98", {0x00, 0xa0, 0xb0}}, /* I/O Data */
78 {"EGY-98?", "EGY-98", {0x00, 0x40, 0x26}}, /* Melco EGY98 */
79 {"ICM?", "ICM-27xx-ET", {0x00, 0x80, 0xc8}}, /* ICM IF-27xx-ET */
80 {"CNET-98/EL?", "CNET(98)E/L", {0x00, 0x80, 0x4C}}, /* Contec CNET-98/EL */
85 /* ---- No user-serviceable parts below ---- */
87 #define NE_BASE (dev->base_addr)
88 #define NE_CMD EI_SHIFT(0x00)
89 #define NE_DATAPORT EI_SHIFT(0x10) /* NatSemi-defined port window offset. */
90 #define NE_RESET EI_SHIFT(0x1f) /* Issue a read to reset, a write to clear. */
91 #define NE_IO_EXTENT 0x20
93 #define NE1SM_START_PG 0x20 /* First page of TX buffer */
94 #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
95 #define NESM_START_PG 0x40 /* First page of TX buffer */
96 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
98 #include "ne2k_cbus.h"
100 int ne_probe(struct net_device
*dev
);
101 static int ne_probe1(struct net_device
*dev
, int ioaddr
);
102 static int ne_open(struct net_device
*dev
);
103 static int ne_close(struct net_device
*dev
);
105 static void ne_reset_8390(struct net_device
*dev
);
106 static void ne_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
108 static void ne_block_input(struct net_device
*dev
, int count
,
109 struct sk_buff
*skb
, int ring_offset
);
110 static void ne_block_output(struct net_device
*dev
, const int count
,
111 const unsigned char *buf
, const int start_page
);
114 /* Probe for various non-shared-memory ethercards.
116 NEx000-clone boards have a Station Address PROM (SAPROM) in the packet
117 buffer memory space. NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of
118 the SAPROM, while other supposed NE2000 clones must be detected by their
121 Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
122 mode results in doubled values, which can be detected and compensated for.
124 The probe is also responsible for initializing the card and filling
125 in the 'dev' and 'ei_status' structures.
127 We use the minimum memory size for some ethercard product lines, iff we can't
128 distinguish models. You can increase the packet buffer size by setting
129 PACKETBUF_MEMSIZE. Reported Cabletron packet buffer locations are:
130 E1010 starts at 0x100 and ends at 0x2000.
131 E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory")
132 E2010 starts at 0x100 and ends at 0x4000.
133 E2010-x starts at 0x100 and ends at 0xffff. */
135 int __init
ne_probe(struct net_device
*dev
)
137 unsigned int base_addr
= dev
->base_addr
;
139 SET_MODULE_OWNER(dev
);
142 printk(KERN_DEBUG
"ne_probe(): entered.\n");
144 /* If CONFIG_NET_CBUS,
145 we need dev->priv->reg_offset BEFORE to probe */
146 if (ne2k_cbus_init(dev
) != 0)
149 /* First check any supplied i/o locations. User knows best. <cough> */
152 const struct ne2k_cbus_hwinfo
*hw
= ne2k_cbus_get_hwinfo((int)(dev
->mem_start
& NE2K_CBUS_HARDWARE_TYPE_MASK
));
155 printk(KERN_DEBUG
"ne_probe(): call ne_probe_cbus(base_addr=0x%x)\n", base_addr
);
157 result
= ne_probe_cbus(dev
, hw
, base_addr
);
159 ne2k_cbus_destroy(dev
);
165 printk(KERN_DEBUG
"ne_probe(): base_addr is not specified.\n");
168 /* Last resort. The semi-risky C-Bus auto-probe. */
170 printk(KERN_DEBUG
"ne_probe(): auto-probe start.\n");
173 const struct ne2k_cbus_hwinfo
*hw
= ne2k_cbus_get_hwinfo((int)(dev
->mem_start
& NE2K_CBUS_HARDWARE_TYPE_MASK
));
175 if (hw
&& hw
->hwtype
) {
176 const unsigned short *plist
;
177 for (plist
= hw
->portlist
; *plist
; plist
++)
178 if (ne_probe_cbus(dev
, hw
, *plist
) == 0)
181 for (hw
= &ne2k_cbus_hwinfo_list
[0]; hw
->hwtype
; hw
++) {
182 const unsigned short *plist
;
183 for (plist
= hw
->portlist
; *plist
; plist
++)
184 if (ne_probe_cbus(dev
, hw
, *plist
) == 0)
191 ne2k_cbus_destroy(dev
);
196 static int __init
ne_probe_cbus(struct net_device
*dev
, const struct ne2k_cbus_hwinfo
*hw
, int ioaddr
)
199 printk(KERN_DEBUG
"ne_probe_cbus(): entered. (called from %p)\n",
200 __builtin_return_address(0));
202 if (hw
&& hw
->hwtype
) {
203 ne2k_cbus_set_hwtype(dev
, hw
, ioaddr
);
204 return ne_probe1(dev
, ioaddr
);
208 printk(KERN_DEBUG
"ne_probe_cbus(): try to determine hardware types.\n");
209 for (hw
= &ne2k_cbus_hwinfo_list
[0]; hw
->hwtype
; hw
++) {
210 ne2k_cbus_set_hwtype(dev
, hw
, ioaddr
);
211 if (ne_probe1(dev
, ioaddr
) == 0)
218 static int __init
ne_probe1(struct net_device
*dev
, int ioaddr
)
221 unsigned char SA_prom
[32];
223 const char *name
= NULL
;
224 int start_page
, stop_page
;
225 int neX000
, bad_card
;
227 static unsigned version_printed
;
228 const struct ne2k_cbus_region
*rlist
;
229 const struct ne2k_cbus_hwinfo
*hw
= ne2k_cbus_get_hwinfo((int)(dev
->mem_start
& NE2K_CBUS_HARDWARE_TYPE_MASK
));
230 struct ei_device
*ei_local
= (struct ei_device
*)(dev
->priv
);
232 #ifdef CONFIG_NE2K_CBUS_CNET98EL
233 if (hw
->hwtype
== NE2K_CBUS_HARDWARE_TYPE_CNET98EL
) {
234 outb_p(0, CONFIG_NE2K_CBUS_CNET98EL_IO_BASE
);
236 outb_p(1, CONFIG_NE2K_CBUS_CNET98EL_IO_BASE
);
238 outb_p((ioaddr
& 0xf000) >> 8 | 0x08 | 0x01, CONFIG_NE2K_CBUS_CNET98EL_IO_BASE
+ 2);
243 for (rlist
= hw
->regionlist
; rlist
->range
; rlist
++)
244 if (!request_region(ioaddr
+ rlist
->start
,
245 rlist
->range
, dev
->name
)) {
250 reg0
= inb_p(ioaddr
+ EI_SHIFT(0));
256 /* Do a preliminary verification that we have a 8390. */
257 #ifdef CONFIG_NE2K_CBUS_CNET98EL
258 if (hw
->hwtype
!= NE2K_CBUS_HARDWARE_TYPE_CNET98EL
)
262 outb_p(E8390_NODMA
+E8390_PAGE1
+E8390_STOP
, ioaddr
+ E8390_CMD
);
263 regd
= inb_p(ioaddr
+ EI_SHIFT(0x0d));
264 outb_p(0xff, ioaddr
+ EI_SHIFT(0x0d));
265 outb_p(E8390_NODMA
+E8390_PAGE0
, ioaddr
+ E8390_CMD
);
266 inb_p(ioaddr
+ EN0_COUNTER0
); /* Clear the counter by reading. */
267 if (inb_p(ioaddr
+ EN0_COUNTER0
) != 0) {
268 outb_p(reg0
, ioaddr
);
269 outb_p(regd
, ioaddr
+ EI_SHIFT(0x0d)); /* Restore the old values. */
275 if (ei_debug
&& version_printed
++ == 0)
276 printk(KERN_INFO
"%s" KERN_INFO
"%s", version1
, version2
);
278 printk(KERN_INFO
"NE*000 ethercard probe at %#3x:", ioaddr
);
280 /* A user with a poor card that fails to ack the reset, or that
281 does not have a valid 0x57,0x57 signature can still use this
282 without having to recompile. Specifying an i/o address along
283 with an otherwise unused dev->mem_end value of "0xBAD" will
284 cause the driver to skip these parts of the probe. */
286 bad_card
= ((dev
->base_addr
!= 0) && (dev
->mem_end
== 0xbad));
288 /* Reset card. Who knows what dain-bramaged state it was left in. */
291 unsigned long reset_start_time
= jiffies
;
293 /* derived from CNET98EL-patch for bad clones */
294 outb_p(E8390_NODMA
| E8390_STOP
, ioaddr
+ E8390_CMD
);
296 /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
297 outb(inb(ioaddr
+ NE_RESET
), ioaddr
+ NE_RESET
);
299 while ((inb_p(ioaddr
+ EN0_ISR
) & ENISR_RESET
) == 0)
300 if (jiffies
- reset_start_time
> 2*HZ
/100) {
302 printk(" (warning: no reset ack)");
305 printk(" not found (no reset ack).\n");
311 outb_p(0xff, ioaddr
+ EN0_ISR
); /* Ack all intr. */
314 #ifdef CONFIG_NE2K_CBUS_CNET98EL
315 if (hw
->hwtype
== NE2K_CBUS_HARDWARE_TYPE_CNET98EL
) {
316 static const char pat
[32] ="AbcdeFghijKlmnoPqrstUvwxyZ789012";
321 printk(" [CNET98EL-specific initialize...");
322 outb_p(E8390_NODMA
| E8390_STOP
, ioaddr
+ E8390_CMD
); /* 0x20|0x1 */
324 if ((i
& ~0x2) != (0x20 | 0x01))
326 if ((inb(ioaddr
+ 0x7) & 0x80) != 0x80)
328 outb_p(E8390_RXOFF
, ioaddr
+ EN0_RXCR
); /* out(ioaddr+0xc, 0x20) */
329 /* outb_p(ENDCFG_WTS|ENDCFG_FT1|ENDCFG_LS, ioaddr+EN0_DCFG); */
330 outb_p(ENDCFG_WTS
| 0x48, ioaddr
+ EN0_DCFG
); /* 0x49 */
331 outb_p(CNET98EL_START_PG
, ioaddr
+ EN0_STARTPG
);
332 outb_p(CNET98EL_STOP_PG
, ioaddr
+ EN0_STOPPG
);
334 printk("memory check");
335 for (i
= 0; i
< 65536; i
+= 1024) {
338 ne2k_cbus_writemem(dev
, ioaddr
, i
, pat
, 32);
339 while (((inb(ioaddr
+ EN0_ISR
) & ENISR_RDC
) != ENISR_RDC
) && --maxwait
)
341 ne2k_cbus_readmem(dev
, ioaddr
, i
, buf
, 32);
342 if (memcmp(pat
, buf
, 32)) {
351 printk("memory failure at %x\n", i
);
359 printk("IRQ must be specified for C-NET(98)E/L. probe failed.\n");
362 outb((dev
->irq
> 5) ? (dev
->irq
& 4):(dev
->irq
>> 1), ioaddr
+ (0x2 | 0x400));
363 outb(0x7e, ioaddr
+ (0x4 | 0x400));
364 ne2k_cbus_readmem(dev
, ioaddr
, 16384, SA_prom
, 32);
365 outb(0xff, ioaddr
+ EN0_ISR
);
369 #endif /* CONFIG_NE2K_CBUS_CNET98EL */
370 /* Read the 16 bytes of station address PROM.
371 We must first initialize registers, similar to NS8390_init(eifdev, 0).
372 We can't reliably read the SAPROM address without this.
373 (I learned the hard way!). */
375 struct {unsigned char value
; unsigned short offset
;} program_seq
[] =
377 {E8390_NODMA
+E8390_PAGE0
+E8390_STOP
, E8390_CMD
}, /* Select page 0*/
378 /* NEC PC-9800: some board can only handle word-wide access? */
379 {0x48 | ENDCFG_WTS
, EN0_DCFG
}, /* Set word-wide (0x48) access. */
380 {16384 / 256, EN0_STARTPG
},
381 {32768 / 256, EN0_STOPPG
},
382 {0x00, EN0_RCNTLO
}, /* Clear the count regs. */
384 {0x00, EN0_IMR
}, /* Mask completion irq. */
386 {E8390_RXOFF
, EN0_RXCR
}, /* 0x20 Set to monitor */
387 {E8390_TXOFF
, EN0_TXCR
}, /* 0x02 and loopback mode. */
390 {0x00, EN0_RSARLO
}, /* DMA starting at 0x0000. */
392 {E8390_RREAD
+E8390_START
, E8390_CMD
},
395 for (i
= 0; i
< sizeof(program_seq
)/sizeof(program_seq
[0]); i
++)
396 outb_p(program_seq
[i
].value
, ioaddr
+ program_seq
[i
].offset
);
397 insw(ioaddr
+ NE_DATAPORT
, SA_prom
, 32 >> 1);
403 for (i
= 0; i
< 16; i
++)
404 SA_prom
[i
] = SA_prom
[i
+i
];
405 start_page
= NESM_START_PG
;
406 stop_page
= NESM_STOP_PG
;
407 #ifdef CONFIG_NE2K_CBUS_CNET98EL
408 if (hw
->hwtype
== NE2K_CBUS_HARDWARE_TYPE_CNET98EL
) {
409 start_page
= CNET98EL_START_PG
;
410 stop_page
= CNET98EL_STOP_PG
;
414 start_page
= NE1SM_START_PG
;
415 stop_page
= NE1SM_STOP_PG
;
418 neX000
= (SA_prom
[14] == 0x57 && SA_prom
[15] == 0x57);
420 name
= "C-Bus-NE2K-compat";
424 #ifdef SUPPORT_NE_BAD_CLONES
425 /* Ack! Well, there might be a *bad* NE*000 clone there.
426 Check for total bogus addresses. */
427 for (i
= 0; bad_clone_list
[i
].name8
; i
++)
429 if (SA_prom
[0] == bad_clone_list
[i
].SAprefix
[0] &&
430 SA_prom
[1] == bad_clone_list
[i
].SAprefix
[1] &&
431 SA_prom
[2] == bad_clone_list
[i
].SAprefix
[2])
435 name
= bad_clone_list
[i
].name16
;
437 name
= bad_clone_list
[i
].name8
;
442 if (bad_clone_list
[i
].name8
== NULL
)
444 printk(" not found (invalid signature %2.2x %2.2x).\n",
445 SA_prom
[14], SA_prom
[15]);
450 printk(" not found.\n");
458 unsigned long cookie
= probe_irq_on();
459 outb_p(0x50, ioaddr
+ EN0_IMR
); /* Enable one interrupt. */
460 outb_p(0x00, ioaddr
+ EN0_RCNTLO
);
461 outb_p(0x00, ioaddr
+ EN0_RCNTHI
);
462 outb_p(E8390_RREAD
+E8390_START
, ioaddr
); /* Trigger it... */
463 mdelay(10); /* wait 10ms for interrupt to propagate */
464 outb_p(0x00, ioaddr
+ EN0_IMR
); /* Mask it again. */
465 dev
->irq
= probe_irq_off(cookie
);
467 printk(" autoirq is %d\n", dev
->irq
);
468 } else if (dev
->irq
== 7)
469 /* Fixup for users that don't know that IRQ 7 is really IRQ 11,
470 or don't know which one to set. */
474 printk(" failed to detect IRQ line.\n");
479 /* Allocate dev->priv and fill in 8390 specific dev fields. */
480 if (ethdev_init(dev
))
482 printk (" unable to get memory for dev->priv.\n");
487 /* Snarf the interrupt now. There's no point in waiting since we cannot
488 share and the board will usually be enabled. */
489 ret
= request_irq(dev
->irq
, ei_interrupt
, 0, name
, dev
);
491 printk (" unable to get IRQ %d (errno=%d).\n", dev
->irq
, ret
);
495 dev
->base_addr
= ioaddr
;
497 for(i
= 0; i
< ETHER_ADDR_LEN
; i
++) {
498 printk(" %2.2x", SA_prom
[i
]);
499 dev
->dev_addr
[i
] = SA_prom
[i
];
502 printk("\n%s: %s found at %#x, hardware type %d(%s), using IRQ %d.\n",
503 dev
->name
, name
, ioaddr
, hw
->hwtype
, hw
->hwident
, dev
->irq
);
505 ei_status
.name
= name
;
506 ei_status
.tx_start_page
= start_page
;
507 ei_status
.stop_page
= stop_page
;
508 ei_status
.word16
= (wordlength
== 2);
510 ei_status
.rx_start_page
= start_page
+ TX_PAGES
;
511 #ifdef PACKETBUF_MEMSIZE
512 /* Allow the packet buffer size to be overridden by know-it-alls. */
513 ei_status
.stop_page
= ei_status
.tx_start_page
+ PACKETBUF_MEMSIZE
;
516 ei_status
.reset_8390
= &ne_reset_8390
;
517 ei_status
.block_input
= &ne_block_input
;
518 ei_status
.block_output
= &ne_block_output
;
519 ei_status
.get_8390_hdr
= &ne_get_8390_hdr
;
521 dev
->open
= &ne_open
;
522 dev
->stop
= &ne_close
;
527 ne2k_cbus_destroy(dev
);
529 while (rlist
> hw
->regionlist
) {
531 release_region(ioaddr
+ rlist
->start
, rlist
->range
);
536 static int ne_open(struct net_device
*dev
)
542 static int ne_close(struct net_device
*dev
)
545 printk(KERN_DEBUG
"%s: Shutting down ethercard.\n", dev
->name
);
550 /* Hard reset the card. This used to pause for the same period that a
551 8390 reset command required, but that shouldn't be necessary. */
553 static void ne_reset_8390(struct net_device
*dev
)
555 unsigned long reset_start_time
= jiffies
;
556 struct ei_device
*ei_local
= (struct ei_device
*)(dev
->priv
);
559 printk(KERN_DEBUG
"resetting the 8390 t=%ld...", jiffies
);
561 /* derived from CNET98EL-patch for bad clones... */
562 outb_p(E8390_NODMA
| E8390_STOP
, NE_BASE
+ E8390_CMD
); /* 0x20 | 0x1 */
564 /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
565 outb(inb(NE_BASE
+ NE_RESET
), NE_BASE
+ NE_RESET
);
568 ei_status
.dmaing
= 0;
570 /* This check _should_not_ be necessary, omit eventually. */
571 while ((inb_p(NE_BASE
+EN0_ISR
) & ENISR_RESET
) == 0)
572 if (jiffies
- reset_start_time
> 2*HZ
/100) {
573 printk(KERN_WARNING
"%s: ne_reset_8390() did not complete.\n", dev
->name
);
576 outb_p(ENISR_RESET
, NE_BASE
+ EN0_ISR
); /* Ack intr. */
579 /* Grab the 8390 specific header. Similar to the block_input routine, but
580 we don't need to be concerned with ring wrap as the header will be at
581 the start of a page, so we optimize accordingly. */
583 static void ne_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
, int ring_page
)
585 int nic_base
= dev
->base_addr
;
586 struct ei_device
*ei_local
= (struct ei_device
*)(dev
->priv
);
588 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
590 if (ei_status
.dmaing
)
592 printk(KERN_EMERG
"%s: DMAing conflict in ne_get_8390_hdr "
593 "[DMAstat:%d][irqlock:%d].\n",
594 dev
->name
, ei_status
.dmaing
, ei_status
.irqlock
);
598 ei_status
.dmaing
|= 0x01;
599 outb_p(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
600 outb_p(sizeof(struct e8390_pkt_hdr
), nic_base
+ EN0_RCNTLO
);
601 outb_p(0, nic_base
+ EN0_RCNTHI
);
602 outb_p(0, nic_base
+ EN0_RSARLO
); /* On page boundary */
603 outb_p(ring_page
, nic_base
+ EN0_RSARHI
);
604 outb_p(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
606 if (ei_status
.word16
)
607 insw(NE_BASE
+ NE_DATAPORT
, hdr
, sizeof(struct e8390_pkt_hdr
)>>1);
609 insb(NE_BASE
+ NE_DATAPORT
, hdr
, sizeof(struct e8390_pkt_hdr
));
611 outb_p(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
612 ei_status
.dmaing
&= ~0x01;
614 le16_to_cpus(&hdr
->count
);
617 /* Block input and output, similar to the Crynwr packet driver. If you
618 are porting to a new ethercard, look at the packet driver source for hints.
619 The NEx000 doesn't share the on-board packet memory -- you have to put
620 the packet out through the "remote DMA" dataport using outb. */
622 static void ne_block_input(struct net_device
*dev
, int count
, struct sk_buff
*skb
, int ring_offset
)
624 #ifdef NE_SANITY_CHECK
625 int xfer_count
= count
;
627 int nic_base
= dev
->base_addr
;
628 char *buf
= skb
->data
;
629 struct ei_device
*ei_local
= (struct ei_device
*)(dev
->priv
);
631 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
632 if (ei_status
.dmaing
)
634 printk(KERN_EMERG
"%s: DMAing conflict in ne_block_input "
635 "[DMAstat:%d][irqlock:%d].\n",
636 dev
->name
, ei_status
.dmaing
, ei_status
.irqlock
);
639 ei_status
.dmaing
|= 0x01;
641 /* round up count to a word (derived from ICM-patch) */
642 count
= (count
+ 1) & ~1;
644 outb_p(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
645 outb_p(count
& 0xff, nic_base
+ EN0_RCNTLO
);
646 outb_p(count
>> 8, nic_base
+ EN0_RCNTHI
);
647 outb_p(ring_offset
& 0xff, nic_base
+ EN0_RSARLO
);
648 outb_p(ring_offset
>> 8, nic_base
+ EN0_RSARHI
);
649 outb_p(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
650 if (ei_status
.word16
)
652 insw(NE_BASE
+ NE_DATAPORT
,buf
,count
>>1);
655 buf
[count
-1] = inb(NE_BASE
+ NE_DATAPORT
);
656 #ifdef NE_SANITY_CHECK
661 insb(NE_BASE
+ NE_DATAPORT
, buf
, count
);
664 #ifdef NE_SANITY_CHECK
665 /* This was for the ALPHA version only, but enough people have
666 been encountering problems so it is still here. If you see
667 this message you either 1) have a slightly incompatible clone
668 or 2) have noise/speed problems with your bus. */
672 /* DMA termination address check... */
673 int addr
, tries
= 20;
675 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
676 -- it's broken for Rx on some cards! */
677 int high
= inb_p(nic_base
+ EN0_RSARHI
);
678 int low
= inb_p(nic_base
+ EN0_RSARLO
);
679 addr
= (high
<< 8) + low
;
680 if (((ring_offset
+ xfer_count
) & 0xff) == low
)
682 } while (--tries
> 0);
684 printk(KERN_WARNING
"%s: RX transfer address mismatch,"
685 "%#4.4x (expected) vs. %#4.4x (actual).\n",
686 dev
->name
, ring_offset
+ xfer_count
, addr
);
689 outb_p(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
690 ei_status
.dmaing
&= ~0x01;
693 static void ne_block_output(struct net_device
*dev
, int count
,
694 const unsigned char *buf
, const int start_page
)
696 int nic_base
= NE_BASE
;
697 unsigned long dma_start
;
698 #ifdef NE_SANITY_CHECK
701 struct ei_device
*ei_local
= (struct ei_device
*)(dev
->priv
);
703 /* Round the count up for word writes. Do we need to do this?
704 What effect will an odd byte count have on the 8390?
705 I should check someday. */
707 if (ei_status
.word16
&& (count
& 0x01))
710 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
711 if (ei_status
.dmaing
)
713 printk(KERN_EMERG
"%s: DMAing conflict in ne_block_output."
714 "[DMAstat:%d][irqlock:%d]\n",
715 dev
->name
, ei_status
.dmaing
, ei_status
.irqlock
);
718 ei_status
.dmaing
|= 0x01;
719 /* We should already be in page 0, but to be safe... */
720 outb_p(E8390_PAGE0
+E8390_START
+E8390_NODMA
, nic_base
+ NE_CMD
);
722 #ifdef NE_SANITY_CHECK
726 #ifdef NE8390_RW_BUGFIX
727 /* Handle the read-before-write bug the same way as the
728 Crynwr packet driver -- the NatSemi method doesn't work.
729 Actually this doesn't always work either, but if you have
730 problems with your NEx000 this is better than nothing! */
732 outb_p(0x42, nic_base
+ EN0_RCNTLO
);
733 outb_p(0x00, nic_base
+ EN0_RCNTHI
);
734 outb_p(0x42, nic_base
+ EN0_RSARLO
);
735 outb_p(0x00, nic_base
+ EN0_RSARHI
);
736 outb_p(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
737 /* Make certain that the dummy read has occurred. */
741 outb_p(ENISR_RDC
, nic_base
+ EN0_ISR
);
743 /* Now the normal output. */
744 outb_p(count
& 0xff, nic_base
+ EN0_RCNTLO
);
745 outb_p(count
>> 8, nic_base
+ EN0_RCNTHI
);
746 outb_p(0x00, nic_base
+ EN0_RSARLO
);
747 outb_p(start_page
, nic_base
+ EN0_RSARHI
);
749 outb_p(E8390_RWRITE
+E8390_START
, nic_base
+ NE_CMD
);
750 if (ei_status
.word16
) {
751 outsw(NE_BASE
+ NE_DATAPORT
, buf
, count
>>1);
753 outsb(NE_BASE
+ NE_DATAPORT
, buf
, count
);
758 #ifdef NE_SANITY_CHECK
759 /* This was for the ALPHA version only, but enough people have
760 been encountering problems so it is still here. */
764 /* DMA termination address check... */
765 int addr
, tries
= 20;
767 int high
= inb_p(nic_base
+ EN0_RSARHI
);
768 int low
= inb_p(nic_base
+ EN0_RSARLO
);
769 addr
= (high
<< 8) + low
;
770 if ((start_page
<< 8) + count
== addr
)
772 } while (--tries
> 0);
776 printk(KERN_WARNING
"%s: Tx packet transfer address mismatch,"
777 "%#4.4x (expected) vs. %#4.4x (actual).\n",
778 dev
->name
, (start_page
<< 8) + count
, addr
);
785 while ((inb_p(nic_base
+ EN0_ISR
) & ENISR_RDC
) == 0)
786 if (jiffies
- dma_start
> 2*HZ
/100) { /* 20ms */
787 printk(KERN_WARNING
"%s: timeout waiting for Tx RDC.\n", dev
->name
);
793 outb_p(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
794 ei_status
.dmaing
&= ~0x01;
800 #define MAX_NE_CARDS 4 /* Max number of NE cards per module */
801 static struct net_device dev_ne
[MAX_NE_CARDS
];
802 static int io
[MAX_NE_CARDS
];
803 static int irq
[MAX_NE_CARDS
];
804 static int bad
[MAX_NE_CARDS
]; /* 0xbad = bad sig or no reset ack */
805 static int hwtype
[MAX_NE_CARDS
] = { 0, }; /* board type */
807 MODULE_PARM(io
, "1-" __MODULE_STRING(MAX_NE_CARDS
) "i");
808 MODULE_PARM(irq
, "1-" __MODULE_STRING(MAX_NE_CARDS
) "i");
809 MODULE_PARM(bad
, "1-" __MODULE_STRING(MAX_NE_CARDS
) "i");
810 MODULE_PARM(hwtype
, "1-" __MODULE_STRING(MAX_NE_CARDS
) "i");
811 MODULE_PARM_DESC(io
, "I/O base address(es),required");
812 MODULE_PARM_DESC(irq
, "IRQ number(s)");
813 MODULE_PARM_DESC(bad
, "Accept card(s) with bad signatures");
814 MODULE_PARM_DESC(hwtype
, "Board type of PC-9800 C-Bus NIC");
815 MODULE_DESCRIPTION("NE1000/NE2000 PC-9800 C-bus Ethernet driver");
816 MODULE_LICENSE("GPL");
818 /* This is set up so that no ISA autoprobe takes place. We can't guarantee
819 that the ne2k probe is the last 8390 based probe to take place (as it
820 is at boot) and so the probe will get confused by any other 8390 cards.
821 ISA device autoprobes on a running machine are not recommended anyway. */
823 int init_module(void)
825 int this_dev
, found
= 0;
827 for (this_dev
= 0; this_dev
< MAX_NE_CARDS
; this_dev
++) {
828 struct net_device
*dev
= &dev_ne
[this_dev
];
829 dev
->irq
= irq
[this_dev
];
830 dev
->mem_end
= bad
[this_dev
];
831 dev
->base_addr
= io
[this_dev
];
832 dev
->mem_start
= hwtype
[this_dev
];
833 dev
->init
= ne_probe
;
834 if (register_netdev(dev
) == 0) {
838 if (found
!= 0) { /* Got at least one. */
841 if (io
[this_dev
] != 0)
842 printk(KERN_WARNING
"ne.c: No NE*000 card found at i/o = %#x\n", io
[this_dev
]);
844 printk(KERN_NOTICE
"ne.c: You must supply \"io=0xNNN\" value(s) for C-Bus cards.\n");
850 void cleanup_module(void)
854 for (this_dev
= 0; this_dev
< MAX_NE_CARDS
; this_dev
++) {
855 struct net_device
*dev
= &dev_ne
[this_dev
];
856 if (dev
->priv
!= NULL
) {
857 const struct ne2k_cbus_region
*rlist
;
858 const struct ne2k_cbus_hwinfo
*hw
= ne2k_cbus_get_hwinfo((int)(dev
->mem_start
& NE2K_CBUS_HARDWARE_TYPE_MASK
));
860 free_irq(dev
->irq
, dev
);
861 for (rlist
= hw
->regionlist
; rlist
->range
; rlist
++) {
862 release_region(dev
->base_addr
+ rlist
->start
,
865 unregister_netdev(dev
);
866 ne2k_cbus_destroy(dev
);
875 * compile-command: "gcc -DKERNEL -Wall -O6 -fomit-frame-pointer -I/usr/src/linux/net/tcp -c ne.c"
877 * kept-new-versions: 5