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