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