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