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