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
30 static char *version =
31 "ne.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
32
33 #include <linux/kernel.h>
34 #include <linux/sched.h>
35 #include <linux/errno.h>
36 #include <asm/system.h>
37 #include <asm/io.h>
38
39 #include <linux/netdevice.h>
40 #include "8390.h"
41
42
43
44
45 #define CONFIG_NE_BAD_CLONES
46
47
48
49
50
51
52
53
54
55 extern struct device *init_etherdev(struct device *dev, int sizeof_private,
56 unsigned long *mem_startp);
57
58
59
60 static unsigned int netcard_portlist[] =
61 { 0x300, 0x280, 0x320, 0x340, 0x360, 0};
62
63 #ifdef CONFIG_NE_BAD_CLONES
64
65 static struct { char *name8, *name16; unsigned char SAprefix[4];}
66 bad_clone_list[] = {
67 {"DE100", "DE200", {0x00, 0xDE, 0x01,}},
68 {"DE120", "DE220", {0x00, 0x80, 0xc8,}},
69 {"DFI1000", "DFI2000", {'D', 'F', 'I',}},
70 {"EtherNext UTP8", "EtherNext UTP16", {0x00, 0x00, 0x79}},
71 {"NE1000","NE2000-invalid", {0x00, 0x00, 0xd8}},
72 {"NN1000", "NN2000", {0x08, 0x03, 0x08}},
73 {"4-DIM8","4-DIM16", {0x00,0x00,0x4d,}},
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 #define NE_RDC_TIMEOUT 0x02
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 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
180
181
182 {
183 struct {unsigned char value, offset; } program_seq[] = {
184 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD},
185 {0x48, EN0_DCFG},
186 {0x00, EN0_RCNTLO},
187 {0x00, EN0_RCNTHI},
188 {0x00, EN0_IMR},
189 {0xFF, EN0_ISR},
190 {E8390_RXOFF, EN0_RXCR},
191 {E8390_TXOFF, EN0_TXCR},
192 {32, EN0_RCNTLO},
193 {0x00, EN0_RCNTHI},
194 {0x00, EN0_RSARLO},
195 {0x00, EN0_RSARHI},
196 {E8390_RREAD+E8390_START, E8390_CMD},
197 };
198 for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
199 outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
200
201 }
202 for(i = 0; i < 32 ; i+=2) {
203 SA_prom[i] = inb(ioaddr + NE_DATAPORT);
204 SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
205 if (SA_prom[i] != SA_prom[i+1])
206 wordlength = 1;
207 }
208
209 if (wordlength == 2) {
210
211 outb_p(0x49, ioaddr + EN0_DCFG);
212
213
214
215 for (i = 0; i < 16; i++)
216 SA_prom[i] = SA_prom[i+i];
217 start_page = NESM_START_PG;
218 stop_page = NESM_STOP_PG;
219 } else {
220 start_page = NE1SM_START_PG;
221 stop_page = NE1SM_STOP_PG;
222 }
223
224 for(i = 0; i < ETHER_ADDR_LEN; i++) {
225 dev->dev_addr[i] = SA_prom[i];
226 printk(" %2.2x", SA_prom[i]);
227 }
228
229 neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
230 ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
231
232
233 if (neX000) {
234 name = (wordlength == 2) ? "NE2000" : "NE1000";
235 } else if (ctron) {
236 name = "Cabletron";
237 start_page = 0x01;
238 stop_page = (wordlength == 2) ? 0x40 : 0x20;
239 } else {
240 #ifdef CONFIG_NE_BAD_CLONES
241
242
243 for (i = 0; bad_clone_list[i].name8; i++) {
244 if (SA_prom[0] == bad_clone_list[i].SAprefix[0] &&
245 SA_prom[1] == bad_clone_list[i].SAprefix[1] &&
246 SA_prom[2] == bad_clone_list[i].SAprefix[2]) {
247 if (wordlength == 2) {
248 name = bad_clone_list[i].name16;
249 } else {
250 name = bad_clone_list[i].name8;
251 }
252 break;
253 }
254 }
255 if (bad_clone_list[i].name8 == NULL) {
256 printk(" not found (invalid signature %2.2x %2.2x).\n",
257 SA_prom[14], SA_prom[15]);
258 return ENXIO;
259 }
260 #else
261 printk(" not found.\n");
262 return ENXIO;
263 #endif
264
265 }
266
267
268 if (dev == NULL)
269 dev = init_etherdev(0, sizeof(struct ei_device), 0);
270
271 if (dev->irq < 2) {
272 autoirq_setup(0);
273 outb_p(0x50, ioaddr + EN0_IMR);
274 outb_p(0x00, ioaddr + EN0_RCNTLO);
275 outb_p(0x00, ioaddr + EN0_RCNTHI);
276 outb_p(E8390_RREAD+E8390_START, ioaddr);
277 outb_p(0x00, ioaddr + EN0_IMR);
278 dev->irq = autoirq_report(0);
279 if (ei_debug > 2)
280 printk(" autoirq is %d\n", dev->irq);
281 } else if (dev->irq == 2)
282
283
284 dev->irq = 9;
285
286
287
288 {
289 int irqval = request_irq (dev->irq, ei_interrupt, 0, wordlength==2 ? "ne2000":"ne1000");
290 if (irqval) {
291 printk (" unable to get IRQ %d (irqval=%d).\n", dev->irq, irqval);
292 return EAGAIN;
293 }
294 }
295
296 dev->base_addr = ioaddr;
297
298 request_region(ioaddr, NE_IO_EXTENT, wordlength==2 ? "ne2000":"ne1000");
299
300 for(i = 0; i < ETHER_ADDR_LEN; i++)
301 dev->dev_addr[i] = SA_prom[i];
302
303 ethdev_init(dev);
304 printk("\n%s: %s found at %#x, using IRQ %d.\n",
305 dev->name, name, ioaddr, dev->irq);
306
307 if (ei_debug > 0)
308 printk(version);
309
310 ei_status.name = name;
311 ei_status.tx_start_page = start_page;
312 ei_status.stop_page = stop_page;
313 ei_status.word16 = (wordlength == 2);
314
315 ei_status.rx_start_page = start_page + TX_PAGES;
316 #ifdef PACKETBUF_MEMSIZE
317
318 ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
319 #endif
320
321 ei_status.reset_8390 = &ne_reset_8390;
322 ei_status.block_input = &ne_block_input;
323 ei_status.block_output = &ne_block_output;
324 NS8390_init(dev, 0);
325 return 0;
326 }
327
328
329
330 static void
331 ne_reset_8390(struct device *dev)
332 {
333 int tmp = inb_p(NE_BASE + NE_RESET);
334 int reset_start_time = jiffies;
335
336 if (ei_debug > 1) printk("resetting the 8390 t=%ld...", jiffies);
337 ei_status.txing = 0;
338
339 outb_p(tmp, NE_BASE + NE_RESET);
340
341 while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
342 if (jiffies - reset_start_time > 2) {
343 printk("%s: ne_reset_8390() did not complete.\n", dev->name);
344 break;
345 }
346 }
347
348
349
350
351
352
353 static int
354 ne_block_input(struct device *dev, int count, char *buf, int ring_offset)
355 {
356 #ifdef CONFIG_NE_SANITY
357 int xfer_count = count;
358 #endif
359 int nic_base = dev->base_addr;
360
361
362 if (set_bit(0,(void*)&ei_status.dmaing)) {
363 if (ei_debug > 0)
364 printk("%s: DMAing conflict in ne_block_input "
365 "[DMAstat:%d][irqlock:%d][intr:%d].\n",
366 dev->name, ei_status.dmaing, ei_status.irqlock,
367 dev->interrupt);
368 return 0;
369 }
370 ei_status.dmaing |= 0x02;
371 outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
372 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
373 outb_p(count >> 8, nic_base + EN0_RCNTHI);
374 outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
375 outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
376 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
377 if (ei_status.word16) {
378 insw(NE_BASE + NE_DATAPORT,buf,count>>1);
379 if (count & 0x01) {
380 buf[count-1] = inb(NE_BASE + NE_DATAPORT);
381 #ifdef CONFIG_NE_SANITY
382 xfer_count++;
383 #endif
384 }
385 } else {
386 insb(NE_BASE + NE_DATAPORT, buf, count);
387 }
388
389
390
391
392
393 #ifdef CONFIG_NE_SANITY
394 if (ei_debug > 1) {
395 int addr, tries = 20;
396 do {
397
398
399 int high = inb_p(nic_base + EN0_RSARHI);
400 int low = inb_p(nic_base + EN0_RSARLO);
401 addr = (high << 8) + low;
402 if (((ring_offset + xfer_count) & 0xff) == low)
403 break;
404 } while (--tries > 0);
405 if (tries <= 0)
406 printk("%s: RX transfer address mismatch,"
407 "%#4.4x (expected) vs. %#4.4x (actual).\n",
408 dev->name, ring_offset + xfer_count, addr);
409 }
410 #endif
411 outb_p(ENISR_RDC, nic_base + EN0_ISR);
412 ei_status.dmaing &= ~0x03;
413 return ring_offset + count;
414 }
415
416 static void
417 ne_block_output(struct device *dev, int count,
418 const unsigned char *buf, const int start_page)
419 {
420 #ifdef CONFIG_NE_SANITY
421 int retries = 0;
422 #endif
423 int nic_base = NE_BASE;
424 unsigned long dma_start;
425
426
427
428
429 if (ei_status.word16 && (count & 0x01))
430 count++;
431
432
433 if (set_bit(0,(void*)&ei_status.dmaing)) {
434 if (ei_debug > 0)
435 printk("%s: DMAing conflict in ne_block_output."
436 "[DMAstat:%d][irqlock:%d][intr:%d]\n",
437 dev->name, ei_status.dmaing, ei_status.irqlock,
438 dev->interrupt);
439 return;
440 }
441 ei_status.dmaing |= 0x04;
442
443 outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
444
445 #ifdef CONFIG_NE_SANITY
446 retry:
447 #endif
448
449 #ifdef CONFIG_NE_RW_BUGFIX
450
451
452
453
454 outb_p(0x42, nic_base + EN0_RCNTLO);
455 outb_p(0x00, nic_base + EN0_RCNTHI);
456 outb_p(0x42, nic_base + EN0_RSARLO);
457 outb_p(0x00, nic_base + EN0_RSARHI);
458 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
459
460 SLOW_DOWN_IO;
461 SLOW_DOWN_IO;
462 SLOW_DOWN_IO;
463 #endif
464
465 outb_p(ENISR_RDC, nic_base + EN0_ISR);
466
467
468 outb_p(count & 0xff, nic_base + EN0_RCNTLO);
469 outb_p(count >> 8, nic_base + EN0_RCNTHI);
470 outb_p(0x00, nic_base + EN0_RSARLO);
471 outb_p(start_page, nic_base + EN0_RSARHI);
472
473 outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
474 if (ei_status.word16) {
475 outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
476 } else {
477 outsb(NE_BASE + NE_DATAPORT, buf, count);
478 }
479
480 dma_start = jiffies;
481
482 #ifdef CONFIG_NE_SANITY
483
484
485 if (ei_debug > 1) {
486 int addr, tries = 20;
487 do {
488 int high = inb_p(nic_base + EN0_RSARHI);
489 int low = inb_p(nic_base + EN0_RSARLO);
490 addr = (high << 8) + low;
491 if ((start_page << 8) + count == addr)
492 break;
493 } while (--tries > 0);
494 if (tries <= 0) {
495 printk("%s: Tx packet transfer address mismatch,"
496 "%#4.4x (expected) vs. %#4.4x (actual).\n",
497 dev->name, (start_page << 8) + count, addr);
498 if (retries++ == 0)
499 goto retry;
500 }
501 }
502 #endif
503
504 while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
505 if (jiffies - dma_start > NE_RDC_TIMEOUT) {
506 printk("%s: timeout waiting for Tx RDC.\n", dev->name);
507 ne_reset_8390(dev);
508 NS8390_init(dev,1);
509 break;
510 }
511
512 outb_p(ENISR_RDC, nic_base + EN0_ISR);
513 ei_status.dmaing &= ~0x05;
514 return;
515 }
516
517
518
519
520
521
522
523
524