This source file includes following definitions.
- ne_probe
- ne_probe1
- ne_open
- ne_close
- ne_reset_8390
- ne_get_8390_hdr
- ne_block_input
- ne_block_output
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 static const char *version =
31 "ne.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
32
33
34 #include <linux/module.h>
35
36 #include <linux/kernel.h>
37 #include <linux/sched.h>
38 #include <linux/errno.h>
39 #include <asm/system.h>
40 #include <asm/io.h>
41
42 #include <linux/netdevice.h>
43 #include <linux/etherdevice.h>
44 #include "8390.h"
45
46
47
48
49 #define SUPPORT_NE_BAD_CLONES
50
51
52
53
54
55
56
57
58
59
60
61
62
63 static unsigned int netcard_portlist[] =
64 { 0x300, 0x280, 0x320, 0x340, 0x360, 0};
65
66 #ifdef SUPPORT_NE_BAD_CLONES
67
68 static struct { const char *name8, *name16; unsigned char SAprefix[4];}
69 bad_clone_list[] = {
70 {"DE100", "DE200", {0x00, 0xDE, 0x01,}},
71 {"DE120", "DE220", {0x00, 0x80, 0xc8,}},
72 {"DFI1000", "DFI2000", {'D', 'F', 'I',}},
73 {"EtherNext UTP8", "EtherNext UTP16", {0x00, 0x00, 0x79}},
74 {"NE1000","NE2000-invalid", {0x00, 0x00, 0xd8}},
75 {"NN1000", "NN2000", {0x08, 0x03, 0x08}},
76 {"4-DIM8","4-DIM16", {0x00,0x00,0x4d,}},
77 {"Con-Intl_8", "Con-Intl_16", {0x00, 0x00, 0x24}},
78 {0,}
79 };
80 #endif
81
82 #define NE_BASE (dev->base_addr)
83 #define NE_CMD 0x00
84 #define NE_DATAPORT 0x10
85 #define NE_RESET 0x1f
86 #define NE_IO_EXTENT 0x20
87
88 #define NE1SM_START_PG 0x20
89 #define NE1SM_STOP_PG 0x40
90 #define NESM_START_PG 0x40
91 #define NESM_STOP_PG 0x80
92
93 int ne_probe(struct device *dev);
94 static int ne_probe1(struct device *dev, int ioaddr);
95
96 static int ne_open(struct device *dev);
97 static int ne_close(struct device *dev);
98
99 static void ne_reset_8390(struct device *dev);
100 static void ne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr,
101 int ring_page);
102 static void ne_block_input(struct device *dev, int count,
103 struct sk_buff *skb, int ring_offset);
104 static void ne_block_output(struct device *dev, const int count,
105 const unsigned char *buf, const int start_page);
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 #ifdef HAVE_DEVLIST
130 struct netdev_entry netcard_drv =
131 {"ne", ne_probe1, NE_IO_EXTENT, netcard_portlist};
132 #else
133
134 int ne_probe(struct device *dev)
135 {
136 int i;
137 int base_addr = dev ? dev->base_addr : 0;
138
139 if (base_addr > 0x1ff)
140 return ne_probe1(dev, base_addr);
141 else if (base_addr != 0)
142 return ENXIO;
143
144 for (i = 0; netcard_portlist[i]; i++) {
145 int ioaddr = netcard_portlist[i];
146 if (check_region(ioaddr, NE_IO_EXTENT))
147 continue;
148 if (ne_probe1(dev, ioaddr) == 0)
149 return 0;
150 }
151
152 return ENODEV;
153 }
154 #endif
155
156 static int ne_probe1(struct device *dev, int ioaddr)
157 {
158 int i;
159 unsigned char SA_prom[32];
160 int wordlength = 2;
161 const char *name = NULL;
162 int start_page, stop_page;
163 int neX000, ctron;
164 int reg0 = inb_p(ioaddr);
165 static unsigned version_printed = 0;
166
167 if (reg0 == 0xFF)
168 return ENODEV;
169
170
171 { int regd;
172 outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
173 regd = inb_p(ioaddr + 0x0d);
174 outb_p(0xff, ioaddr + 0x0d);
175 outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
176 inb_p(ioaddr + EN0_COUNTER0);
177 if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
178 outb_p(reg0, ioaddr);
179 outb_p(regd, ioaddr + 0x0d);
180 return ENODEV;
181 }
182 }
183
184 if (ei_debug && version_printed++ == 0)
185 printk(version);
186
187 printk("NE*000 ethercard probe at %#3x:", ioaddr);
188
189
190 { unsigned long reset_start_time = jiffies;
191
192
193 outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
194
195 while ((inb_p(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
196 if (jiffies - reset_start_time > 2*HZ/100) {
197 printk(" not found (no reset ack).\n");
198 return ENODEV;
199 }
200
201 outb_p(0xff, ioaddr + EN0_ISR);
202 }
203
204
205
206
207
208 {
209 struct {unsigned char value, offset; } program_seq[] = {
210 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD},
211 {0x48, EN0_DCFG},
212 {0x00, EN0_RCNTLO},
213 {0x00, EN0_RCNTHI},
214 {0x00, EN0_IMR},
215 {0xFF, EN0_ISR},
216 {E8390_RXOFF, EN0_RXCR},
217 {E8390_TXOFF, EN0_TXCR},
218 {32, EN0_RCNTLO},
219 {0x00, EN0_RCNTHI},
220 {0x00, EN0_RSARLO},
221 {0x00, EN0_RSARHI},
222 {E8390_RREAD+E8390_START, E8390_CMD},
223 };
224 for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
225 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
226
227 }
228 for(i = 0; i < 32 ; i+=2) {
229 SA_prom[i] = inb(ioaddr + NE_DATAPORT);
230 SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
231 if (SA_prom[i] != SA_prom[i+1])
232 wordlength = 1;
233 }
234
235 if (wordlength == 2) {
236
237 outb_p(0x49, ioaddr + EN0_DCFG);
238
239
240
241 for (i = 0; i < 16; i++)
242 SA_prom[i] = SA_prom[i+i];
243 start_page = NESM_START_PG;
244 stop_page = NESM_STOP_PG;
245 } else {
246 start_page = NE1SM_START_PG;
247 stop_page = NE1SM_STOP_PG;
248 }
249
250 neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
251 ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
252
253
254 if (neX000) {
255 name = (wordlength == 2) ? "NE2000" : "NE1000";
256 } else if (ctron) {
257 name = (wordlength == 2) ? "Ctron-8" : "Ctron-16";
258 start_page = 0x01;
259 stop_page = (wordlength == 2) ? 0x40 : 0x20;
260 } else {
261 #ifdef SUPPORT_NE_BAD_CLONES
262
263
264 for (i = 0; bad_clone_list[i].name8; i++) {
265 if (SA_prom[0] == bad_clone_list[i].SAprefix[0] &&
266 SA_prom[1] == bad_clone_list[i].SAprefix[1] &&
267 SA_prom[2] == bad_clone_list[i].SAprefix[2]) {
268 if (wordlength == 2) {
269 name = bad_clone_list[i].name16;
270 } else {
271 name = bad_clone_list[i].name8;
272 }
273 break;
274 }
275 }
276 if (bad_clone_list[i].name8 == NULL) {
277 printk(" not found (invalid signature %2.2x %2.2x).\n",
278 SA_prom[14], SA_prom[15]);
279 return ENXIO;
280 }
281 #else
282 printk(" not found.\n");
283 return ENXIO;
284 #endif
285
286 }
287
288
289 if (dev == NULL) {
290 printk("ne.c: Passed a NULL device.\n");
291 dev = init_etherdev(0, 0);
292 }
293
294 if (dev->irq < 2) {
295 autoirq_setup(0);
296 outb_p(0x50, ioaddr + EN0_IMR);
297 outb_p(0x00, ioaddr + EN0_RCNTLO);
298 outb_p(0x00, ioaddr + EN0_RCNTHI);
299 outb_p(E8390_RREAD+E8390_START, ioaddr);
300 outb_p(0x00, ioaddr + EN0_IMR);
301 dev->irq = autoirq_report(0);
302 if (ei_debug > 2)
303 printk(" autoirq is %d\n", dev->irq);
304 } else if (dev->irq == 2)
305
306
307 dev->irq = 9;
308
309 if (! dev->irq) {
310 printk(" failed to detect IRQ line.\n");
311 return EAGAIN;
312 }
313
314
315
316 {
317 int irqval = request_irq(dev->irq, ei_interrupt, 0, name);
318 if (irqval) {
319 printk (" unable to get IRQ %d (irqval=%d).\n", dev->irq, irqval);
320 return EAGAIN;
321 }
322 }
323
324 dev->base_addr = ioaddr;
325
326
327 if (ethdev_init(dev)) {
328 printk (" unable to get memory for dev->priv.\n");
329 free_irq(dev->irq);
330 return -ENOMEM;
331 }
332
333 request_region(ioaddr, NE_IO_EXTENT, name);
334
335 for(i = 0; i < ETHER_ADDR_LEN; i++) {
336 printk(" %2.2x", SA_prom[i]);
337 dev->dev_addr[i] = SA_prom[i];
338 }
339
340 printk("\n%s: %s found at %#x, using IRQ %d.\n",
341 dev->name, name, ioaddr, dev->irq);
342
343 ei_status.name = name;
344 ei_status.tx_start_page = start_page;
345 ei_status.stop_page = stop_page;
346 ei_status.word16 = (wordlength == 2);
347
348 ei_status.rx_start_page = start_page + TX_PAGES;
349 #ifdef PACKETBUF_MEMSIZE
350
351 ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
352 #endif
353
354 ei_status.reset_8390 = &ne_reset_8390;
355 ei_status.block_input = &ne_block_input;
356 ei_status.block_output = &ne_block_output;
357 ei_status.get_8390_hdr = &ne_get_8390_hdr;
358 dev->open = &ne_open;
359 dev->stop = &ne_close;
360 NS8390_init(dev, 0);
361 return 0;
362 }
363
364 static int
365 ne_open(struct device *dev)
366 {
367 ei_open(dev);
368 MOD_INC_USE_COUNT;
369 return 0;
370 }
371
372 static int
373 ne_close(struct device *dev)
374 {
375 if (ei_debug > 1)
376 printk("%s: Shutting down ethercard.\n", dev->name);
377 ei_close(dev);
378 MOD_DEC_USE_COUNT;
379 return 0;
380 }
381
382
383
384 static void
385 ne_reset_8390(struct device *dev)
386 {
387 unsigned long reset_start_time = jiffies;
388
389 if (ei_debug > 1) printk("resetting the 8390 t=%ld...", jiffies);
390
391
392 outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
393
394 ei_status.txing = 0;
395 ei_status.dmaing = 0;
396
397
398 while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
399 if (jiffies - reset_start_time > 2*HZ/100) {
400 printk("%s: ne_reset_8390() did not complete.\n", dev->name);
401 break;
402 }
403 outb_p(ENISR_RESET, NE_BASE + EN0_ISR);
404 }
405
406
407
408
409
410 static void
411 ne_get_8390_hdr(struct device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
412 {
413
414 int nic_base = dev->base_addr;
415
416
417 if (ei_status.dmaing) {
418 printk("%s: DMAing conflict in ne_get_8390_hdr "
419 "[DMAstat:%d][irqlock:%d][intr:%d].\n",
420 dev->name, ei_status.dmaing, ei_status.irqlock,
421 dev->interrupt);
422 return;
423 }
424
425 ei_status.dmaing |= 0x01;
426 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
427 outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
428 outb_p(0, nic_base + EN0_RCNTHI);
429 outb_p(0, nic_base + EN0_RSARLO);
430 outb_p(ring_page, nic_base + EN0_RSARHI);
431 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
432
433 if (ei_status.word16)
434 insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
435 else
436 insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
437
438 outb_p(ENISR_RDC, nic_base + EN0_ISR);
439 ei_status.dmaing &= ~0x01;
440 }
441
442
443
444
445
446
447 static void
448 ne_block_input(struct device *dev, int count, struct sk_buff *skb, int ring_offset)
449 {
450 #ifdef NE_SANITY_CHECK
451 int xfer_count = count;
452 #endif
453 int nic_base = dev->base_addr;
454 char *buf = skb->data;
455
456
457 if (ei_status.dmaing) {
458 printk("%s: DMAing conflict in ne_block_input "
459 "[DMAstat:%d][irqlock:%d][intr:%d].\n",
460 dev->name, ei_status.dmaing, ei_status.irqlock,
461 dev->interrupt);
462 return;
463 }
464 ei_status.dmaing |= 0x01;
465 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
466 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
467 outb_p(count >> 8, nic_base + EN0_RCNTHI);
468 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
469 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
470 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
471 if (ei_status.word16) {
472 insw(NE_BASE + NE_DATAPORT,buf,count>>1);
473 if (count & 0x01) {
474 buf[count-1] = inb(NE_BASE + NE_DATAPORT);
475 #ifdef NE_SANITY_CHECK
476 xfer_count++;
477 #endif
478 }
479 } else {
480 insb(NE_BASE + NE_DATAPORT, buf, count);
481 }
482
483 #ifdef NE_SANITY_CHECK
484
485
486
487
488 if (ei_debug > 1) {
489 int addr, tries = 20;
490 do {
491
492
493 int high = inb_p(nic_base + EN0_RSARHI);
494 int low = inb_p(nic_base + EN0_RSARLO);
495 addr = (high << 8) + low;
496 if (((ring_offset + xfer_count) & 0xff) == low)
497 break;
498 } while (--tries > 0);
499 if (tries <= 0)
500 printk("%s: RX transfer address mismatch,"
501 "%#4.4x (expected) vs. %#4.4x (actual).\n",
502 dev->name, ring_offset + xfer_count, addr);
503 }
504 #endif
505 outb_p(ENISR_RDC, nic_base + EN0_ISR);
506 ei_status.dmaing &= ~0x01;
507 }
508
509 static void
510 ne_block_output(struct device *dev, int count,
511 const unsigned char *buf, const int start_page)
512 {
513 int nic_base = NE_BASE;
514 unsigned long dma_start;
515 #ifdef NE_SANITY_CHECK
516 int retries = 0;
517 #endif
518
519
520
521
522 if (ei_status.word16 && (count & 0x01))
523 count++;
524
525
526 if (ei_status.dmaing) {
527 printk("%s: DMAing conflict in ne_block_output."
528 "[DMAstat:%d][irqlock:%d][intr:%d]\n",
529 dev->name, ei_status.dmaing, ei_status.irqlock,
530 dev->interrupt);
531 return;
532 }
533 ei_status.dmaing |= 0x01;
534
535 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
536
537 #ifdef NE_SANITY_CHECK
538 retry:
539 #endif
540
541 #ifdef NE8390_RW_BUGFIX
542
543
544
545
546 outb_p(0x42, nic_base + EN0_RCNTLO);
547 outb_p(0x00, nic_base + EN0_RCNTHI);
548 outb_p(0x42, nic_base + EN0_RSARLO);
549 outb_p(0x00, nic_base + EN0_RSARHI);
550 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
551
552 SLOW_DOWN_IO;
553 SLOW_DOWN_IO;
554 SLOW_DOWN_IO;
555 #endif
556
557 outb_p(ENISR_RDC, nic_base + EN0_ISR);
558
559
560 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
561 outb_p(count >> 8, nic_base + EN0_RCNTHI);
562 outb_p(0x00, nic_base + EN0_RSARLO);
563 outb_p(start_page, nic_base + EN0_RSARHI);
564
565 outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
566 if (ei_status.word16) {
567 outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
568 } else {
569 outsb(NE_BASE + NE_DATAPORT, buf, count);
570 }
571
572 dma_start = jiffies;
573
574 #ifdef NE_SANITY_CHECK
575
576
577 if (ei_debug > 1) {
578 int addr, tries = 20;
579 do {
580 int high = inb_p(nic_base + EN0_RSARHI);
581 int low = inb_p(nic_base + EN0_RSARLO);
582 addr = (high << 8) + low;
583 if ((start_page << 8) + count == addr)
584 break;
585 } while (--tries > 0);
586 if (tries <= 0) {
587 printk("%s: Tx packet transfer address mismatch,"
588 "%#4.4x (expected) vs. %#4.4x (actual).\n",
589 dev->name, (start_page << 8) + count, addr);
590 if (retries++ == 0)
591 goto retry;
592 }
593 }
594 #endif
595
596 while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
597 if (jiffies - dma_start > 2*HZ/100) {
598 printk("%s: timeout waiting for Tx RDC.\n", dev->name);
599 ne_reset_8390(dev);
600 NS8390_init(dev,1);
601 break;
602 }
603
604 outb_p(ENISR_RDC, nic_base + EN0_ISR);
605 ei_status.dmaing &= ~0x01;
606 return;
607 }
608
609
610 #ifdef MODULE
611 #define MAX_NE_CARDS 4
612 #define NAMELEN 8
613 static char namelist[NAMELEN * MAX_NE_CARDS] = { 0, };
614 static struct device dev_ne[MAX_NE_CARDS] = {
615 {
616 NULL,
617 0, 0, 0, 0,
618 0, 0,
619 0, 0, 0, NULL, NULL
620 },
621 };
622
623 static int io[MAX_NE_CARDS] = { 0, };
624 static int irq[MAX_NE_CARDS] = { 0, };
625
626
627
628
629
630
631 int
632 init_module(void)
633 {
634 int this_dev, found = 0;
635
636 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
637 struct device *dev = &dev_ne[this_dev];
638 dev->name = namelist+(NAMELEN*this_dev);
639 dev->irq = irq[this_dev];
640 dev->base_addr = io[this_dev];
641 dev->init = ne_probe;
642 if (io[this_dev] == 0) {
643 if (this_dev != 0) break;
644 printk(KERN_NOTICE "ne.c: Module autoprobing not allowed. Append \"io=0xNNN\" value(s).\n");
645 return -EPERM;
646 }
647 if (register_netdev(dev) != 0) {
648 printk(KERN_WARNING "ne.c: No NE*000 card found (i/o = 0x%x).\n", io[this_dev]);
649 if (found != 0) return 0;
650 return -ENXIO;
651 }
652 found++;
653 }
654
655 return 0;
656 }
657
658 void
659 cleanup_module(void)
660 {
661 int this_dev;
662
663 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
664 struct device *dev = &dev_ne[this_dev];
665 if (dev->priv != NULL) {
666 kfree(dev->priv);
667 dev->priv = NULL;
668 free_irq(dev->irq);
669 irq2dev_map[dev->irq] = NULL;
670 release_region(dev->base_addr, NE_IO_EXTENT);
671 unregister_netdev(dev);
672 }
673 }
674 }
675 #endif
676
677
678
679
680
681
682
683