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