1 /* ne.c: A general non-shared-memory NS8390 ethernet driver for linux. */
2 /*
3 Written 1992-94 by Donald Becker.
4
5 Copyright 1993 United States Government as represented by the
6 Director, National Security Agency.
7
8 This software may be used and distributed according to the terms
9 of the GNU Public License, incorporated herein by reference.
10
11 The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
12 Center of Excellence in Space Data and Information Sciences
13 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
14
15 This driver should work with many programmed-I/O 8390-based ethernet
16 boards. Currently it supports the NE1000, NE2000, many clones,
17 and some Cabletron products.
18
19 Changelog:
20
21 Paul Gortmaker : use ENISR_RDC to monitor Tx PIO uploads, made
22 sanity checks and bad clone support optional.
23 Paul Gortmaker : new reset code, reset card after probe at boot.
24 Paul Gortmaker : multiple card support for module users.
25 Paul Gortmaker : Support for PCI ne2k clones, similar to lance.c
26 Paul Gortmaker : Allow users with bad cards to avoid full probe.
27 Paul Gortmaker : PCI probe changes, more PCI cards supported.
28 rjohnson@analogic.com : Changed init order so an interrupt will only
29 occur after memory is allocated for dev->priv. Deallocated memory
30 last in cleanup_modue()
31 Richard Guenther : Added support for ISAPnP cards
32 Paul Gortmaker : Discontinued PCI support - use ne2k-pci.c instead.
33
34 */
35
36 /* Routines for the NatSemi-based designs (NE[12]000). */
37
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";
42
43
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/sched.h>
47 #include <linux/errno.h>
48 #include <linux/isapnp.h>
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <asm/system.h>
52 #include <asm/io.h>
53
54 #include <linux/netdevice.h>
55 #include <linux/etherdevice.h>
56 #include "8390.h"
57
58 /* Some defines that people can play with if so inclined. */
59
60 /* Do we support clones that don't adhere to 14,15 of the SAprom ? */
61 #define SUPPORT_NE_BAD_CLONES
62
63 /* Do we perform extra sanity checks on stuff ? */
64 /* #define NE_SANITY_CHECK */
65
66 /* Do we implement the read before write bugfix ? */
67 /* #define NE_RW_BUGFIX */
68
69 /* Do we have a non std. amount of memory? (in units of 256 byte pages) */
70 /* #define PACKETBUF_MEMSIZE 0x40 */
71
72 /* A zero-terminated list of I/O addresses to be probed at boot. */
73 #ifndef MODULE
74 static unsigned int netcard_portlist[] __initdata = {
75 0x300, 0x280, 0x320, 0x340, 0x360, 0x380, 0
76 };
77 #endif
78
79 static struct { unsigned short vendor, function; char *name; }
80 isapnp_clone_list[] __initdata = {
81 {ISAPNP_VENDOR('E','D','I'), ISAPNP_FUNCTION(0x0216), "NN NE2000" },
82 {ISAPNP_VENDOR('P','N','P'), ISAPNP_FUNCTION(0x80d6), "Generic PNP" },
83 {0,}
84 };
85
86 #ifdef SUPPORT_NE_BAD_CLONES
87 /* A list of bad clones that we none-the-less recognize. */
88 static struct { const char *name8, *name16; unsigned char SAprefix[4];}
89 bad_clone_list[] __initdata = {
90 {"DE100", "DE200", {0x00, 0xDE, 0x01,}},
91 {"DE120", "DE220", {0x00, 0x80, 0xc8,}},
92 {"DFI1000", "DFI2000", {'D', 'F', 'I',}}, /* Original, eh? */
93 {"EtherNext UTP8", "EtherNext UTP16", {0x00, 0x00, 0x79}},
94 {"NE1000","NE2000-invalid", {0x00, 0x00, 0xd8}}, /* Ancient real NE1000. */
95 {"NN1000", "NN2000", {0x08, 0x03, 0x08}}, /* Outlaw no-name clone. */
96 {"4-DIM8","4-DIM16", {0x00,0x00,0x4d,}}, /* Outlaw 4-Dimension cards. */
97 {"Con-Intl_8", "Con-Intl_16", {0x00, 0x00, 0x24}}, /* Connect Int'nl */
98 {"ET-100","ET-200", {0x00, 0x45, 0x54}}, /* YANG and YA clone */
99 {"COMPEX","COMPEX16",{0x00,0x80,0x48}}, /* Broken ISA Compex cards */
100 {"E-LAN100", "E-LAN200", {0x00, 0x00, 0x5d}}, /* Broken ne1000 clones */
101 {"PCM-4823", "PCM-4823", {0x00, 0xc0, 0x6c}}, /* Broken Advantech MoBo */
102 {"REALTEK", "RTL8019", {0x00, 0x00, 0xe8}}, /* no-name with Realtek chip */
103 {"LCS-8834", "LCS-8836", {0x04, 0x04, 0x37}}, /* ShinyNet (SET) */
104 {0,}
105 };
106 #endif
107
108 /* ---- No user-serviceable parts below ---- */
109
110 #define NE_BASE (dev->base_addr)
111 #define NE_CMD 0x00
112 #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
113 #define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */
114 #define NE_IO_EXTENT 0x20
115
116 #define NE1SM_START_PG 0x20 /* First page of TX buffer */
117 #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
118 #define NESM_START_PG 0x40 /* First page of TX buffer */
119 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
120
121 int ne_probe(struct net_device *dev);
122 static int ne_probe1(struct net_device *dev, int ioaddr);
123 static int ne_probe_isapnp(struct net_device *dev);
124
125 static int ne_open(struct net_device *dev);
126 static int ne_close(struct net_device *dev);
127
128 static void ne_reset_8390(struct net_device *dev);
129 static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
130 int ring_page);
131 static void ne_block_input(struct net_device *dev, int count,
132 struct sk_buff *skb, int ring_offset);
133 static void ne_block_output(struct net_device *dev, const int count,
134 const unsigned char *buf, const int start_page);
135
136
137 /* Probe for various non-shared-memory ethercards.
138
139 NEx000-clone boards have a Station Address PROM (SAPROM) in the packet
140 buffer memory space. NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of
141 the SAPROM, while other supposed NE2000 clones must be detected by their
142 SA prefix.
143
144 Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
145 mode results in doubled values, which can be detected and compensated for.
146
147 The probe is also responsible for initializing the card and filling
148 in the 'dev' and 'ei_status' structures.
149
150 We use the minimum memory size for some ethercard product lines, iff we can't
151 distinguish models. You can increase the packet buffer size by setting
152 PACKETBUF_MEMSIZE. Reported Cabletron packet buffer locations are:
153 E1010 starts at 0x100 and ends at 0x2000.
154 E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory")
155 E2010 starts at 0x100 and ends at 0x4000.
156 E2010-x starts at 0x100 and ends at 0xffff. */
157
158 int __init ne_probe(struct net_device *dev)
159 {
160 unsigned int base_addr = dev->base_addr;
161
162 SET_MODULE_OWNER(dev);
163
164 /* First check any supplied i/o locations. User knows best. <cough> */
165 if (base_addr > 0x1ff) /* Check a single specified location. */
166 return ne_probe1(dev, base_addr);
167 else if (base_addr != 0) /* Don't probe at all. */
168 return -ENXIO;
169
170 /* Then look for any installed ISAPnP clones */
171 if (isapnp_present() && (ne_probe_isapnp(dev) == 0))
172 return 0;
173
174 #ifndef MODULE
175 /* Last resort. The semi-risky ISA auto-probe. */
176 for (base_addr = 0; netcard_portlist[base_addr] != 0; base_addr++) {
177 int ioaddr = netcard_portlist[base_addr];
178 if (ne_probe1(dev, ioaddr) == 0)
179 return 0;
180 }
181 #endif
182
183 return -ENODEV;
184 }
185
186 static int __init ne_probe_isapnp(struct net_device *dev)
187 {
188 int i;
189
190 for (i = 0; isapnp_clone_list[i].vendor != 0; i++) {
191 struct pci_dev *idev = NULL;
192
193 while ((idev = isapnp_find_dev(NULL,
194 isapnp_clone_list[i].vendor,
195 isapnp_clone_list[i].function,
196 idev))) {
197 /* Avoid already found cards from previous calls */
198 if (idev->prepare(idev))
199 continue;
200 if (idev->activate(idev))
201 continue;
202 /* if no irq, search for next */
203 if (idev->irq_resource[0].start == 0)
204 continue;
205 /* found it */
206 dev->base_addr = idev->resource[0].start;
207 dev->irq = idev->irq_resource[0].start;
208 printk(KERN_INFO "ne.c: ISAPnP reports %s at i/o %#lx, irq %d.\n",
209 isapnp_clone_list[i].name,
210
211 dev->base_addr, dev->irq);
212 if (ne_probe1(dev, dev->base_addr) != 0) { /* Shouldn't happen. */
213 printk(KERN_ERR "ne.c: Probe of ISAPnP card at %#lx failed.\n", dev->base_addr);
214 return -ENXIO;
215 }
216 ei_status.priv = (unsigned long)idev;
217 break;
218 }
219 if (!idev)
220 continue;
221 return 0;
222 }
223
224 return -ENODEV;
225 }
226
227 static int __init ne_probe1(struct net_device *dev, int ioaddr)
228 {
229 int i;
230 unsigned char SA_prom[32];
231 int wordlength = 2;
232 const char *name = NULL;
233 int start_page, stop_page;
234 int neX000, ctron, copam, bad_card;
235 int reg0, ret;
236 static unsigned version_printed = 0;
237
238 if (!request_region(ioaddr, NE_IO_EXTENT, dev->name))
239 return -EBUSY;
240
241 reg0 = inb_p(ioaddr);
242 if (reg0 == 0xFF) {
243 ret = -ENODEV;
244 goto err_out;
245 }
246
247 /* Do a preliminary verification that we have a 8390. */
248 {
249 int regd;
250 outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
251 regd = inb_p(ioaddr + 0x0d);
252 outb_p(0xff, ioaddr + 0x0d);
253 outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
254 inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
255 if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
256 outb_p(reg0, ioaddr);
257 outb_p(regd, ioaddr + 0x0d); /* Restore the old values. */
258 ret = -ENODEV;
259 goto err_out;
260 }
261 }
262
263 if (ei_debug && version_printed++ == 0)
264 printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2);
265
266 printk(KERN_INFO "NE*000 ethercard probe at %#3x:", ioaddr);
267
268 /* A user with a poor card that fails to ack the reset, or that
269 does not have a valid 0x57,0x57 signature can still use this
270 without having to recompile. Specifying an i/o address along
271 with an otherwise unused dev->mem_end value of "0xBAD" will
272 cause the driver to skip these parts of the probe. */
273
274 bad_card = ((dev->base_addr != 0) && (dev->mem_end == 0xbad));
275
276 /* Reset card. Who knows what dain-bramaged state it was left in. */
277
278 {
279 unsigned long reset_start_time = jiffies;
280
281 /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
282 outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
283
284 while ((inb_p(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
285 if (jiffies - reset_start_time > 2*HZ/100) {
286 if (bad_card) {
287 printk(" (warning: no reset ack)");
288 break;
289 } else {
290 printk(" not found (no reset ack).\n");
291 ret = -ENODEV;
292 goto err_out;
293 }
294 }
295
296 outb_p(0xff, ioaddr + EN0_ISR); /* Ack all intr. */
297 }
298
299 /* Read the 16 bytes of station address PROM.
300 We must first initialize registers, similar to NS8390_init(eifdev, 0).
301 We can't reliably read the SAPROM address without this.
302 (I learned the hard way!). */
303 {
304 struct {unsigned char value, offset; } program_seq[] =
305 {
306 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
307 {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
308 {0x00, EN0_RCNTLO}, /* Clear the count regs. */
309 {0x00, EN0_RCNTHI},
310 {0x00, EN0_IMR}, /* Mask completion irq. */
311 {0xFF, EN0_ISR},
312 {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
313 {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
314 {32, EN0_RCNTLO},
315 {0x00, EN0_RCNTHI},
316 {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
317 {0x00, EN0_RSARHI},
318 {E8390_RREAD+E8390_START, E8390_CMD},
319 };
320
321 for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
322 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
323
324 }
325 for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
326 SA_prom[i] = inb(ioaddr + NE_DATAPORT);
327 SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
328 if (SA_prom[i] != SA_prom[i+1])
329 wordlength = 1;
330 }
331
332 if (wordlength == 2)
333 {
334 for (i = 0; i < 16; i++)
335 SA_prom[i] = SA_prom[i+i];
336 /* We must set the 8390 for word mode. */
337 outb_p(0x49, ioaddr + EN0_DCFG);
338 start_page = NESM_START_PG;
339 stop_page = NESM_STOP_PG;
340 } else {
341 start_page = NE1SM_START_PG;
342 stop_page = NE1SM_STOP_PG;
343 }
344
345 neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
346 ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
347 copam = (SA_prom[14] == 0x49 && SA_prom[15] == 0x00);
348
349 /* Set up the rest of the parameters. */
350 if (neX000 || bad_card || copam) {
351 name = (wordlength == 2) ? "NE2000" : "NE1000";
352 }
353 else if (ctron)
354 {
355 name = (wordlength == 2) ? "Ctron-8" : "Ctron-16";
356 start_page = 0x01;
357 stop_page = (wordlength == 2) ? 0x40 : 0x20;
358 }
359 else
360 {
361 #ifdef SUPPORT_NE_BAD_CLONES
362 /* Ack! Well, there might be a *bad* NE*000 clone there.
363 Check for total bogus addresses. */
364 for (i = 0; bad_clone_list[i].name8; i++)
365 {
366 if (SA_prom[0] == bad_clone_list[i].SAprefix[0] &&
367 SA_prom[1] == bad_clone_list[i].SAprefix[1] &&
368 SA_prom[2] == bad_clone_list[i].SAprefix[2])
369 {
370 if (wordlength == 2)
371 {
372 name = bad_clone_list[i].name16;
373 } else {
374 name = bad_clone_list[i].name8;
375 }
376 break;
377 }
378 }
379 if (bad_clone_list[i].name8 == NULL)
380 {
381 printk(" not found (invalid signature %2.2x %2.2x).\n",
382 SA_prom[14], SA_prom[15]);
383 ret = -ENXIO;
384 goto err_out;
385 }
386 #else
387 printk(" not found.\n");
388 ret = -ENXIO;
389 goto err_out;
390 #endif
391 }
392
393 if (dev->irq < 2)
394 {
395 unsigned long cookie = probe_irq_on();
396 outb_p(0x50, ioaddr + EN0_IMR); /* Enable one interrupt. */
397 outb_p(0x00, ioaddr + EN0_RCNTLO);
398 outb_p(0x00, ioaddr + EN0_RCNTHI);
399 outb_p(E8390_RREAD+E8390_START, ioaddr); /* Trigger it... */
400 mdelay(10); /* wait 10ms for interrupt to propagate */
401 outb_p(0x00, ioaddr + EN0_IMR); /* Mask it again. */
402 dev->irq = probe_irq_off(cookie);
403 if (ei_debug > 2)
404 printk(" autoirq is %d\n", dev->irq);
405 } else if (dev->irq == 2)
406 /* Fixup for users that don't know that IRQ 2 is really IRQ 9,
407 or don't know which one to set. */
408 dev->irq = 9;
409
410 if (! dev->irq) {
411 printk(" failed to detect IRQ line.\n");
412 ret = -EAGAIN;
413 goto err_out;
414 }
415
416 /* Allocate dev->priv and fill in 8390 specific dev fields. */
417 if (ethdev_init(dev))
418 {
419 printk (" unable to get memory for dev->priv.\n");
420 ret = -ENOMEM;
421 goto err_out;
422 }
423
424 /* Snarf the interrupt now. There's no point in waiting since we cannot
425 share and the board will usually be enabled. */
426 ret = request_irq(dev->irq, ei_interrupt, 0, name, dev);
427 if (ret) {
428 printk (" unable to get IRQ %d (errno=%d).\n", dev->irq, ret);
429 goto err_out_kfree;
430 }
431
432 dev->base_addr = ioaddr;
433
434 for(i = 0; i < ETHER_ADDR_LEN; i++) {
435 printk(" %2.2x", SA_prom[i]);
436 dev->dev_addr[i] = SA_prom[i];
437 }
438
439 printk("\n%s: %s found at %#x, using IRQ %d.\n",
440 dev->name, name, ioaddr, dev->irq);
441
442 ei_status.name = name;
443 ei_status.tx_start_page = start_page;
444 ei_status.stop_page = stop_page;
445 ei_status.word16 = (wordlength == 2);
446
447 ei_status.rx_start_page = start_page + TX_PAGES;
448 #ifdef PACKETBUF_MEMSIZE
449 /* Allow the packet buffer size to be overridden by know-it-alls. */
450 ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
451 #endif
452
453 ei_status.reset_8390 = &ne_reset_8390;
454 ei_status.block_input = &ne_block_input;
455 ei_status.block_output = &ne_block_output;
456 ei_status.get_8390_hdr = &ne_get_8390_hdr;
457 ei_status.priv = 0;
458 dev->open = &ne_open;
459 dev->stop = &ne_close;
460 NS8390_init(dev, 0);
461 return 0;
462
463 err_out_kfree:
464 kfree(dev->priv);
465 dev->priv = NULL;
466 err_out:
467 release_region(ioaddr, NE_IO_EXTENT);
468 return ret;
469 }
470
471 static int ne_open(struct net_device *dev)
472 {
473 ei_open(dev);
474 return 0;
475 }
476
477 static int ne_close(struct net_device *dev)
478 {
479 if (ei_debug > 1)
480 printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
481 ei_close(dev);
482 return 0;
483 }
484
485 /* Hard reset the card. This used to pause for the same period that a
486 8390 reset command required, but that shouldn't be necessary. */
487
488 static void ne_reset_8390(struct net_device *dev)
489 {
490 unsigned long reset_start_time = jiffies;
491
492 if (ei_debug > 1)
493 printk(KERN_DEBUG "resetting the 8390 t=%ld...", jiffies);
494
495 /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
496 outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
497
498 ei_status.txing = 0;
499 ei_status.dmaing = 0;
500
501 /* This check _should_not_ be necessary, omit eventually. */
502 while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
503 if (jiffies - reset_start_time > 2*HZ/100) {
504 printk(KERN_WARNING "%s: ne_reset_8390() did not complete.\n", dev->name);
505 break;
506 }
507 outb_p(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */
508 }
509
510 /* Grab the 8390 specific header. Similar to the block_input routine, but
511 we don't need to be concerned with ring wrap as the header will be at
512 the start of a page, so we optimize accordingly. */
513
514 static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
515 {
516 int nic_base = dev->base_addr;
517
518 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
519
520 if (ei_status.dmaing)
521 {
522 printk(KERN_EMERG "%s: DMAing conflict in ne_get_8390_hdr "
523 "[DMAstat:%d][irqlock:%d].\n",
524 dev->name, ei_status.dmaing, ei_status.irqlock);
525 return;
526 }
527
528 ei_status.dmaing |= 0x01;
529 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
530 outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
531 outb_p(0, nic_base + EN0_RCNTHI);
532 outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
533 outb_p(ring_page, nic_base + EN0_RSARHI);
534 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
535
536 if (ei_status.word16)
537 insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
538 else
539 insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
540
541 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
542 ei_status.dmaing &= ~0x01;
543
544 le16_to_cpus(&hdr->count);
545 }
546
547 /* Block input and output, similar to the Crynwr packet driver. If you
548 are porting to a new ethercard, look at the packet driver source for hints.
549 The NEx000 doesn't share the on-board packet memory -- you have to put
550 the packet out through the "remote DMA" dataport using outb. */
551
552 static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
553 {
554 #ifdef NE_SANITY_CHECK
555 int xfer_count = count;
556 #endif
557 int nic_base = dev->base_addr;
558 char *buf = skb->data;
559
560 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
561 if (ei_status.dmaing)
562 {
563 printk(KERN_EMERG "%s: DMAing conflict in ne_block_input "
564 "[DMAstat:%d][irqlock:%d].\n",
565 dev->name, ei_status.dmaing, ei_status.irqlock);
566 return;
567 }
568 ei_status.dmaing |= 0x01;
569 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
570 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
571 outb_p(count >> 8, nic_base + EN0_RCNTHI);
572 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
573 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
574 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
575 if (ei_status.word16)
576 {
577 insw(NE_BASE + NE_DATAPORT,buf,count>>1);
578 if (count & 0x01)
579 {
580 buf[count-1] = inb(NE_BASE + NE_DATAPORT);
581 #ifdef NE_SANITY_CHECK
582 xfer_count++;
583 #endif
584 }
585 } else {
586 insb(NE_BASE + NE_DATAPORT, buf, count);
587 }
588
589 #ifdef NE_SANITY_CHECK
590 /* This was for the ALPHA version only, but enough people have
591 been encountering problems so it is still here. If you see
592 this message you either 1) have a slightly incompatible clone
593 or 2) have noise/speed problems with your bus. */
594
595 if (ei_debug > 1)
596 {
597 /* DMA termination address check... */
598 int addr, tries = 20;
599 do {
600 /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
601 -- it's broken for Rx on some cards! */
602 int high = inb_p(nic_base + EN0_RSARHI);
603 int low = inb_p(nic_base + EN0_RSARLO);
604 addr = (high << 8) + low;
605 if (((ring_offset + xfer_count) & 0xff) == low)
606 break;
607 } while (--tries > 0);
608 if (tries <= 0)
609 printk(KERN_WARNING "%s: RX transfer address mismatch,"
610 "%#4.4x (expected) vs. %#4.4x (actual).\n",
611 dev->name, ring_offset + xfer_count, addr);
612 }
613 #endif
614 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
615 ei_status.dmaing &= ~0x01;
616 }
617
618 static void ne_block_output(struct net_device *dev, int count,
619 const unsigned char *buf, const int start_page)
620 {
621 int nic_base = NE_BASE;
622 unsigned long dma_start;
623 #ifdef NE_SANITY_CHECK
624 int retries = 0;
625 #endif
626
627 /* Round the count up for word writes. Do we need to do this?
628 What effect will an odd byte count have on the 8390?
629 I should check someday. */
630
631 if (ei_status.word16 && (count & 0x01))
632 count++;
633
634 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
635 if (ei_status.dmaing)
636 {
637 printk(KERN_EMERG "%s: DMAing conflict in ne_block_output."
638 "[DMAstat:%d][irqlock:%d]\n",
639 dev->name, ei_status.dmaing, ei_status.irqlock);
640 return;
641 }
642 ei_status.dmaing |= 0x01;
643 /* We should already be in page 0, but to be safe... */
644 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
645
646 #ifdef NE_SANITY_CHECK
647 retry:
648 #endif
649
650 #ifdef NE8390_RW_BUGFIX
651 /* Handle the read-before-write bug the same way as the
652 Crynwr packet driver -- the NatSemi method doesn't work.
653 Actually this doesn't always work either, but if you have
654 problems with your NEx000 this is better than nothing! */
655
656 outb_p(0x42, nic_base + EN0_RCNTLO);
657 outb_p(0x00, nic_base + EN0_RCNTHI);
658 outb_p(0x42, nic_base + EN0_RSARLO);
659 outb_p(0x00, nic_base + EN0_RSARHI);
660 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
661 /* Make certain that the dummy read has occurred. */
662 udelay(6);
663 #endif
664
665 outb_p(ENISR_RDC, nic_base + EN0_ISR);
666
667 /* Now the normal output. */
668 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
669 outb_p(count >> 8, nic_base + EN0_RCNTHI);
670 outb_p(0x00, nic_base + EN0_RSARLO);
671 outb_p(start_page, nic_base + EN0_RSARHI);
672
673 outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
674 if (ei_status.word16) {
675 outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
676 } else {
677 outsb(NE_BASE + NE_DATAPORT, buf, count);
678 }
679
680 dma_start = jiffies;
681
682 #ifdef NE_SANITY_CHECK
683 /* This was for the ALPHA version only, but enough people have
684 been encountering problems so it is still here. */
685
686 if (ei_debug > 1)
687 {
688 /* DMA termination address check... */
689 int addr, tries = 20;
690 do {
691 int high = inb_p(nic_base + EN0_RSARHI);
692 int low = inb_p(nic_base + EN0_RSARLO);
693 addr = (high << 8) + low;
694 if ((start_page << 8) + count == addr)
695 break;
696 } while (--tries > 0);
697
698 if (tries <= 0)
699 {
700 printk(KERN_WARNING "%s: Tx packet transfer address mismatch,"
701 "%#4.4x (expected) vs. %#4.4x (actual).\n",
702 dev->name, (start_page << 8) + count, addr);
703 if (retries++ == 0)
704 goto retry;
705 }
706 }
707 #endif
708
709 while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
710 if (jiffies - dma_start > 2*HZ/100) { /* 20ms */
711 printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name);
712 ne_reset_8390(dev);
713 NS8390_init(dev,1);
714 break;
715 }
716
717 outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
718 ei_status.dmaing &= ~0x01;
719 return;
720 }
721
722
723 #ifdef MODULE
724 #define MAX_NE_CARDS 4 /* Max number of NE cards per module */
725 static struct net_device dev_ne[MAX_NE_CARDS];
726 static int io[MAX_NE_CARDS];
727 static int irq[MAX_NE_CARDS];
728 static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */
729
730 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
731 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
732 MODULE_PARM(bad, "1-" __MODULE_STRING(MAX_NE_CARDS) "i");
733
734 /* This is set up so that no ISA autoprobe takes place. We can't guarantee
735 that the ne2k probe is the last 8390 based probe to take place (as it
736 is at boot) and so the probe will get confused by any other 8390 cards.
737 ISA device autoprobes on a running machine are not recommended anyway. */
738
739 int init_module(void)
740 {
741 int this_dev, found = 0;
742
743 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
744 struct net_device *dev = &dev_ne[this_dev];
745 dev->irq = irq[this_dev];
746 dev->mem_end = bad[this_dev];
747 dev->base_addr = io[this_dev];
748 dev->init = ne_probe;
749 if (register_netdev(dev) == 0) {
750 found++;
751 continue;
752 }
753 if (found != 0) { /* Got at least one. */
754 return 0;
755 }
756 if (io[this_dev] != 0)
757 printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", io[this_dev]);
758 else
759 printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n");
760 return -ENXIO;
761 }
762 return 0;
763 }
764
765 void cleanup_module(void)
766 {
767 int this_dev;
768
769 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
770 struct net_device *dev = &dev_ne[this_dev];
771 if (dev->priv != NULL) {
772 void *priv = dev->priv;
773 struct pci_dev *idev = (struct pci_dev *)ei_status.priv;
774 if (idev)
775 idev->deactivate(idev);
776 free_irq(dev->irq, dev);
777 release_region(dev->base_addr, NE_IO_EXTENT);
778 unregister_netdev(dev);
779 kfree(priv);
780 }
781 }
782 }
783 #endif /* MODULE */
784
785 /*
786 * Local variables:
787 * compile-command: "gcc -DKERNEL -Wall -O6 -fomit-frame-pointer -I/usr/src/linux/net/tcp -c ne.c"
788 * version-control: t
789 * kept-new-versions: 5
790 * End:
791 */
792
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.