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