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