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