This source file includes following definitions.
- ne_probe
- ne_probe1
- ne_reset_8390
- 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 {0,}
77 };
78 #endif
79
80 #define NE_BASE (dev->base_addr)
81 #define NE_CMD 0x00
82 #define NE_DATAPORT 0x10
83 #define NE_RESET 0x1f
84 #define NE_IO_EXTENT 0x20
85
86 #define NE1SM_START_PG 0x20
87 #define NE1SM_STOP_PG 0x40
88 #define NESM_START_PG 0x40
89 #define NESM_STOP_PG 0x80
90
91 int ne_probe(struct device *dev);
92 static int ne_probe1(struct device *dev, int ioaddr);
93
94 static void ne_reset_8390(struct device *dev);
95 static int ne_block_input(struct device *dev, int count,
96 char *buf, 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
185 while (jiffies - reset_start_time < 2*HZ/100)
186 barrier();
187
188 if ((inb_p(ioaddr+EN0_ISR) & ENISR_RESET) == 0) {
189 printk(" not found (no reset ack).\n");
190 return ENODEV;
191 }
192 outb_p(0xff, ioaddr + EN0_ISR);
193 }
194
195
196
197
198
199 {
200 struct {unsigned char value, offset; } program_seq[] = {
201 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD},
202 {0x48, EN0_DCFG},
203 {0x00, EN0_RCNTLO},
204 {0x00, EN0_RCNTHI},
205 {0x00, EN0_IMR},
206 {0xFF, EN0_ISR},
207 {E8390_RXOFF, EN0_RXCR},
208 {E8390_TXOFF, EN0_TXCR},
209 {32, EN0_RCNTLO},
210 {0x00, EN0_RCNTHI},
211 {0x00, EN0_RSARLO},
212 {0x00, EN0_RSARHI},
213 {E8390_RREAD+E8390_START, E8390_CMD},
214 };
215 for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
216 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
217
218 }
219 for(i = 0; i < 32 ; i+=2) {
220 SA_prom[i] = inb(ioaddr + NE_DATAPORT);
221 SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
222 if (SA_prom[i] != SA_prom[i+1])
223 wordlength = 1;
224 }
225
226 if (wordlength == 2) {
227
228 outb_p(0x49, ioaddr + EN0_DCFG);
229
230
231
232 for (i = 0; i < 16; i++)
233 SA_prom[i] = SA_prom[i+i];
234 start_page = NESM_START_PG;
235 stop_page = NESM_STOP_PG;
236 } else {
237 start_page = NE1SM_START_PG;
238 stop_page = NE1SM_STOP_PG;
239 }
240
241 for(i = 0; i < ETHER_ADDR_LEN; i++) {
242 dev->dev_addr[i] = SA_prom[i];
243 printk(" %2.2x", SA_prom[i]);
244 }
245
246 neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
247 ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
248
249
250 if (neX000) {
251 name = (wordlength == 2) ? "NE2000" : "NE1000";
252 } else if (ctron) {
253 name = "Cabletron";
254 start_page = 0x01;
255 stop_page = (wordlength == 2) ? 0x40 : 0x20;
256 } else {
257 #ifdef CONFIG_NE_BAD_CLONES
258
259
260 for (i = 0; bad_clone_list[i].name8; i++) {
261 if (SA_prom[0] == bad_clone_list[i].SAprefix[0] &&
262 SA_prom[1] == bad_clone_list[i].SAprefix[1] &&
263 SA_prom[2] == bad_clone_list[i].SAprefix[2]) {
264 if (wordlength == 2) {
265 name = bad_clone_list[i].name16;
266 } else {
267 name = bad_clone_list[i].name8;
268 }
269 break;
270 }
271 }
272 if (bad_clone_list[i].name8 == NULL) {
273 printk(" not found (invalid signature %2.2x %2.2x).\n",
274 SA_prom[14], SA_prom[15]);
275 return ENXIO;
276 }
277 #else
278 printk(" not found.\n");
279 return ENXIO;
280 #endif
281
282 }
283
284
285 if (dev == NULL)
286 dev = init_etherdev(0, sizeof(struct ei_device), 0);
287
288 if (dev->irq < 2) {
289 autoirq_setup(0);
290 outb_p(0x50, ioaddr + EN0_IMR);
291 outb_p(0x00, ioaddr + EN0_RCNTLO);
292 outb_p(0x00, ioaddr + EN0_RCNTHI);
293 outb_p(E8390_RREAD+E8390_START, ioaddr);
294 outb_p(0x00, ioaddr + EN0_IMR);
295 dev->irq = autoirq_report(0);
296 if (ei_debug > 2)
297 printk(" autoirq is %d\n", dev->irq);
298 } else if (dev->irq == 2)
299
300
301 dev->irq = 9;
302
303
304
305 {
306 int irqval = request_irq (dev->irq, ei_interrupt, 0, wordlength==2 ? "ne2000":"ne1000");
307 if (irqval) {
308 printk (" unable to get IRQ %d (irqval=%d).\n", dev->irq, irqval);
309 return EAGAIN;
310 }
311 }
312
313 dev->base_addr = ioaddr;
314
315 request_region(ioaddr, NE_IO_EXTENT, wordlength==2 ? "ne2000":"ne1000");
316
317 for(i = 0; i < ETHER_ADDR_LEN; i++)
318 dev->dev_addr[i] = SA_prom[i];
319
320 ethdev_init(dev);
321 printk("\n%s: %s found at %#x, using IRQ %d.\n",
322 dev->name, name, ioaddr, dev->irq);
323
324 if (ei_debug > 0)
325 printk(version);
326
327 ei_status.name = name;
328 ei_status.tx_start_page = start_page;
329 ei_status.stop_page = stop_page;
330 ei_status.word16 = (wordlength == 2);
331
332 ei_status.rx_start_page = start_page + TX_PAGES;
333 #ifdef PACKETBUF_MEMSIZE
334
335 ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
336 #endif
337
338 ei_status.reset_8390 = &ne_reset_8390;
339 ei_status.block_input = &ne_block_input;
340 ei_status.block_output = &ne_block_output;
341 NS8390_init(dev, 0);
342 return 0;
343 }
344
345
346
347 static void
348 ne_reset_8390(struct device *dev)
349 {
350 unsigned long reset_start_time = jiffies;
351
352 if (ei_debug > 1) printk("resetting the 8390 t=%ld...", jiffies);
353
354
355 outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
356
357 ei_status.txing = 0;
358 ei_status.dmaing = 0;
359
360
361 while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
362 if (jiffies - reset_start_time > 2*HZ/100) {
363 printk("%s: ne_reset_8390() did not complete.\n", dev->name);
364 break;
365 }
366 outb_p(ENISR_RESET, NE_BASE + EN0_ISR);
367 }
368
369
370
371
372
373
374 static int
375 ne_block_input(struct device *dev, int count, char *buf, int ring_offset)
376 {
377 int nic_base = dev->base_addr;
378 #ifdef CONFIG_NE_SANITY
379 int xfer_count = count;
380 #endif
381
382
383 if (ei_status.dmaing) {
384 if (ei_debug > 0)
385 printk("%s: DMAing conflict in ne_block_input "
386 "[DMAstat:%d][irqlock:%d][intr:%d].\n",
387 dev->name, ei_status.dmaing, ei_status.irqlock,
388 dev->interrupt);
389 return 0;
390 }
391 ei_status.dmaing |= 0x01;
392 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
393 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
394 outb_p(count >> 8, nic_base + EN0_RCNTHI);
395 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
396 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
397 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
398 if (ei_status.word16) {
399 insw(NE_BASE + NE_DATAPORT,buf,count>>1);
400 if (count & 0x01) {
401 buf[count-1] = inb(NE_BASE + NE_DATAPORT);
402 #ifdef CONFIG_NE_SANITY
403 xfer_count++;
404 #endif
405 }
406 } else {
407 insb(NE_BASE + NE_DATAPORT, buf, count);
408 }
409
410 #ifdef CONFIG_NE_SANITY
411
412
413
414
415 if (ei_debug > 1) {
416 int addr, tries = 20;
417 do {
418
419
420 int high = inb_p(nic_base + EN0_RSARHI);
421 int low = inb_p(nic_base + EN0_RSARLO);
422 addr = (high << 8) + low;
423 if (((ring_offset + xfer_count) & 0xff) == low)
424 break;
425 } while (--tries > 0);
426 if (tries <= 0)
427 printk("%s: RX transfer address mismatch,"
428 "%#4.4x (expected) vs. %#4.4x (actual).\n",
429 dev->name, ring_offset + xfer_count, addr);
430 }
431 #endif
432 outb_p(ENISR_RDC, nic_base + EN0_ISR);
433 ei_status.dmaing &= ~0x01;
434 return ring_offset + count;
435 }
436
437 static void
438 ne_block_output(struct device *dev, int count,
439 const unsigned char *buf, const int start_page)
440 {
441 int nic_base = NE_BASE;
442 unsigned long dma_start;
443 #ifdef CONFIG_NE_SANITY
444 int retries = 0;
445 #endif
446
447
448
449
450 if (ei_status.word16 && (count & 0x01))
451 count++;
452
453
454 if (ei_status.dmaing) {
455 if (ei_debug > 0)
456 printk("%s: DMAing conflict in ne_block_output."
457 "[DMAstat:%d][irqlock:%d][intr:%d]\n",
458 dev->name, ei_status.dmaing, ei_status.irqlock,
459 dev->interrupt);
460 return;
461 }
462 ei_status.dmaing |= 0x01;
463
464 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
465
466 #ifdef CONFIG_NE_SANITY
467 retry:
468 #endif
469
470 #ifdef NE8390_RW_BUGFIX
471
472
473
474
475 outb_p(0x42, nic_base + EN0_RCNTLO);
476 outb_p(0x00, nic_base + EN0_RCNTHI);
477 outb_p(0x42, nic_base + EN0_RSARLO);
478 outb_p(0x00, nic_base + EN0_RSARHI);
479 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
480
481 SLOW_DOWN_IO;
482 SLOW_DOWN_IO;
483 SLOW_DOWN_IO;
484 #endif
485
486 outb_p(ENISR_RDC, nic_base + EN0_ISR);
487
488
489 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
490 outb_p(count >> 8, nic_base + EN0_RCNTHI);
491 outb_p(0x00, nic_base + EN0_RSARLO);
492 outb_p(start_page, nic_base + EN0_RSARHI);
493
494 outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
495 if (ei_status.word16) {
496 outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
497 } else {
498 outsb(NE_BASE + NE_DATAPORT, buf, count);
499 }
500
501 dma_start = jiffies;
502
503 #ifdef CONFIG_NE_SANITY
504
505
506 if (ei_debug > 1) {
507 int addr, tries = 20;
508 do {
509 int high = inb_p(nic_base + EN0_RSARHI);
510 int low = inb_p(nic_base + EN0_RSARLO);
511 addr = (high << 8) + low;
512 if ((start_page << 8) + count == addr)
513 break;
514 } while (--tries > 0);
515 if (tries <= 0) {
516 printk("%s: Tx packet transfer address mismatch,"
517 "%#4.4x (expected) vs. %#4.4x (actual).\n",
518 dev->name, (start_page << 8) + count, addr);
519 if (retries++ == 0)
520 goto retry;
521 }
522 }
523 #endif
524
525 while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
526 if (jiffies - dma_start > 2*HZ/100) {
527 printk("%s: timeout waiting for Tx RDC.\n", dev->name);
528 ne_reset_8390(dev);
529 NS8390_init(dev,1);
530 break;
531 }
532
533 outb_p(ENISR_RDC, nic_base + EN0_ISR);
534 ei_status.dmaing &= ~0x01;
535 return;
536 }
537
538 #ifdef MODULE
539 char kernel_version[] = UTS_RELEASE;
540 static char devicename[9] = { 0, };
541 static struct device dev_ne2000 = {
542 devicename,
543 0, 0, 0, 0,
544 0, 0,
545 0, 0, 0, NULL, ne_probe };
546
547 int io = 0x300;
548 int irq = 0;
549
550 int init_module(void)
551 {
552 if (io == 0)
553 printk("ne: You should not use auto-probing with insmod!\n");
554 dev_ne2000.base_addr = io;
555 dev_ne2000.irq = irq;
556 if (register_netdev(&dev_ne2000) != 0)
557 return -EIO;
558 return 0;
559 }
560
561 void
562 cleanup_module(void)
563 {
564 if (MOD_IN_USE)
565 printk("ne2000: device busy, remove delayed\n");
566 else
567 {
568 unregister_netdev(&dev_ne2000);
569
570
571 free_irq(dev_ne2000.irq);
572 release_region(dev_ne2000.base_addr, NE_IO_EXTENT);
573 }
574 }
575 #endif
576
577
578
579
580
581
582
583