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