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