This source file includes following definitions.
- el2_probe
- el2_pio_autoprobe
- el2probe1
- el2_open
- el2_close
- el2_reset_8390
- el2_init_card
- el2_block_output
- el2_block_input
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 static char *version =
19 "3c503.c:v0.99.15k 3/3/93 Donald Becker (becker@super.org)\n";
20
21 #include <linux/config.h>
22 #include <linux/kernel.h>
23 #include <linux/sched.h>
24 #include <linux/errno.h>
25 #include <linux/string.h>
26 #include <asm/io.h>
27 #include <asm/system.h>
28
29 #include <linux/netdevice.h>
30
31 #include "8390.h"
32 #include "3c503.h"
33
34 int el2_probe(struct device *dev);
35 int el2_pio_autoprobe(struct device *dev);
36 int el2probe1(int ioaddr, struct device *dev);
37
38 static int el2_open(struct device *dev);
39 static int el2_close(struct device *dev);
40 static void el2_reset_8390(struct device *dev);
41 static void el2_init_card(struct device *dev);
42 static void el2_block_output(struct device *dev, int count,
43 const unsigned char *buf, const start_page);
44 static int el2_block_input(struct device *dev, int count, char *buf,
45 int ring_offset);
46
47
48
49
50
51
52
53
54
55
56 static int ports[] = {0x300,0x310,0x330,0x350,0x250,0x280,0x2a0,0x2e0,0};
57
58 int
59 el2_probe(struct device *dev)
60 {
61 int *addr, addrs[] = { 0xddffe, 0xd9ffe, 0xcdffe, 0xc9ffe, 0};
62 short ioaddr = dev->base_addr;
63
64 if (ioaddr < 0)
65 return ENXIO;
66 if (ioaddr > 0)
67 return ! el2probe1(ioaddr, dev);
68
69 for (addr = addrs; *addr; addr++) {
70 int i;
71 unsigned int base_bits = *(unsigned char *)*addr;
72
73 for(i = 7; i >= 0; i--, base_bits >>= 1)
74 if (base_bits & 0x1)
75 break;
76 if (base_bits != 1)
77 continue;
78 #ifdef HAVE_PORTRESERVE
79 if (check_region(ports[i], 16))
80 continue;
81 #endif
82 if (el2probe1(ports[i], dev))
83 return 0;
84 }
85 #ifndef no_probe_nonshared_memory
86 return el2_pio_autoprobe(dev);
87 #else
88 return ENODEV;
89 #endif
90 }
91
92
93
94 int
95 el2_pio_autoprobe(struct device *dev)
96 {
97 int i;
98 for (i = 0; i < 8; i++) {
99 #ifdef HAVE_PORTRESERVE
100 if (check_region(ports[i], 16))
101 continue;
102 #endif
103
104 if (inb_p(ports[i] + 0x408) == 0xff)
105 continue;
106 if (inb(ports[i] + 0x403) == (0x80 >> i)
107 && el2probe1(ports[i], dev))
108 return 0;
109 }
110 return ENODEV;
111 }
112
113
114
115
116 int
117 el2probe1(int ioaddr, struct device *dev)
118 {
119 int i, iobase_reg, membase_reg, saved_406;
120 unsigned char *station_addr = dev->dev_addr;
121
122
123
124 printk("3c503 probe at %#3x:", ioaddr);
125 iobase_reg = inb(ioaddr+0x403);
126 membase_reg = inb(ioaddr+0x404);
127
128 if ( (iobase_reg & (iobase_reg - 1))
129 || (membase_reg & (membase_reg - 1))) {
130 printk(" not found.\n");
131 return 0;
132 }
133 saved_406 = inb_p(ioaddr + 0x406);
134 outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406);
135 outb_p(ECNTRL_THIN, ioaddr + 0x406);
136
137 outb(ECNTRL_SAPROM|ECNTRL_THIN, ioaddr + 0x406);
138 for (i = 0; i < ETHER_ADDR_LEN; i++) {
139 printk(" %2.2X", (station_addr[i] = inb(ioaddr + i)));
140 }
141 if ( station_addr[0] != 0x02
142 || station_addr[1] != 0x60
143 || station_addr[2] != 0x8c) {
144 printk(" 3C503 not found.\n");
145
146 outb(saved_406, ioaddr + 0x406);
147 return 0;
148 }
149
150 #ifdef HAVE_PORTRESERVE
151 snarf_region(ioaddr, 16);
152 #endif
153 ethdev_init(dev);
154
155
156 outb(ECNTRL_THIN, ioaddr + 0x406);
157 dev->base_addr = ioaddr;
158
159 if (ei_debug > 2) printk(" memory jumpers %2.2x ", membase_reg);
160 outb(EGACFR_NORM, ioaddr + 0x405);
161
162
163
164
165
166 #if defined(EI8390_THICK) || defined(EL2_AUI)
167 ei_status.interface_num = 1;
168 #else
169 ei_status.interface_num = dev->mem_end & 0xf;
170 #endif
171
172 if ((membase_reg & 0xf0) == 0) {
173 dev->mem_start = 0;
174 } else {
175 dev->mem_start = ((membase_reg & 0xc0) ? 0xD8000 : 0xC8000) +
176 ((membase_reg & 0xA0) ? 0x4000 : 0);
177
178 #define EL2_MEMSIZE (EL2SM_STOP_PG - EL2SM_START_PG)*256
179 #ifdef EL2MEMTEST
180
181 {
182 int *mem_base = (int *)dev->mem_start;
183 int memtest_value = 0xbbadf00d;
184 mem_base[0] = 0xba5eba5e;
185 for (i = 1; i < EL2_MEMSIZE/sizeof(mem_base[0]); i++) {
186 mem_base[i] = memtest_value;
187 if (mem_base[0] != 0xba5eba5e
188 || mem_base[i] != memtest_value) {
189 printk(" memory failure or memory address conflict.\n");
190 dev->mem_start = 0;
191 break;
192 }
193 memtest_value += 0x55555555;
194 mem_base[i] = 0;
195 }
196 }
197 #endif
198
199
200
201 dev->mem_end = dev->rmem_end = dev->mem_start + EL2_MEMSIZE;
202 dev->rmem_start = TX_PAGES*256 + dev->mem_start;
203 }
204
205
206 ei_status.name = "3C503";
207 ei_status.tx_start_page = EL2SM_START_PG;
208 ei_status.rx_start_page = EL2SM_START_PG + TX_PAGES;
209 ei_status.stop_page = EL2SM_STOP_PG;
210 ei_status.reset_8390 = &el2_reset_8390;
211 ei_status.block_input = &el2_block_input;
212 ei_status.block_output = &el2_block_output;
213
214 if (dev->irq == 2)
215 dev->irq = 9;
216 else if (dev->irq > 5 && dev->irq != 9) {
217 printk("\n3c503: configured interrupt %d invalid, using autoIRQ.\n",
218 dev->irq);
219 dev->irq = 0;
220 }
221
222 ei_status.saved_irq = dev->irq;
223
224 dev->start = 0;
225 dev->open = &el2_open;
226 dev->stop = &el2_close;
227
228 if (dev->mem_start)
229 printk("\n%s: %s with shared memory at %#6lx-%#6lx,\n",
230 dev->name, ei_status.name, dev->mem_start, dev->mem_end-1);
231 else
232 printk("\n%s: %s using programmed I/O (REJUMPER for SHARED MEMORY).\n",
233 dev->name, ei_status.name);
234 if (ei_debug > 1)
235 printk(version);
236
237 return ioaddr;
238 }
239
240 static int
241 el2_open(struct device *dev)
242 {
243
244 if (dev->irq < 2) {
245 int irqlist[] = {5, 9, 3, 4, 0};
246 int *irqp = irqlist;
247
248 outb(EGACFR_NORM, E33G_GACFR);
249 do {
250 if (request_irq (*irqp, NULL, 0, "bogus") != -EBUSY) {
251
252 autoirq_setup(0);
253 outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR);
254 outb_p(0x00, E33G_IDCFR);
255 if (*irqp == autoirq_report(0)
256 && request_irq (dev->irq = *irqp, &ei_interrupt, 0, "3c503") == 0)
257 break;
258 }
259 } while (*++irqp);
260 if (*irqp == 0) {
261 outb(EGACFR_IRQOFF, E33G_GACFR);
262 return -EAGAIN;
263 }
264 } else {
265 if (request_irq(dev->irq, &ei_interrupt, 0, "3c503")) {
266 return -EAGAIN;
267 }
268 }
269 el2_init_card(dev);
270 return ei_open(dev);
271 }
272
273 static int
274 el2_close(struct device *dev)
275 {
276 free_irq(dev->irq);
277 dev->irq = ei_status.saved_irq;
278 irq2dev_map[dev->irq] = NULL;
279 outb(EGACFR_IRQOFF, E33G_GACFR);
280
281 NS8390_init(dev, 0);
282
283 return 0;
284 }
285
286
287
288
289
290 static void
291 el2_reset_8390(struct device *dev)
292 {
293 if (ei_debug > 1) {
294 printk("%s: Resetting the 3c503 board...", dev->name);
295 printk("%#x=%#02x %#x=%#02x %#x=%#02x...", E33G_IDCFR, inb(E33G_IDCFR),
296 E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR));
297 }
298 outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL);
299 ei_status.txing = 0;
300 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
301 el2_init_card(dev);
302 if (ei_debug > 1) printk("done\n");
303 }
304
305
306 static void
307 el2_init_card(struct device *dev)
308 {
309
310 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
311
312
313
314 outb(ei_status.rx_start_page, E33G_STARTPG);
315 outb(ei_status.stop_page, E33G_STOPPG);
316
317
318 outb(0xff, E33G_VP2);
319 outb(0xff, E33G_VP1);
320 outb(0x00, E33G_VP0);
321
322 outb_p(0x00, dev->base_addr + EN0_IMR);
323
324 outb(EGACFR_NORM, E33G_GACFR);
325
326
327 outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR);
328 outb_p(8, E33G_DRQCNT);
329 outb_p(0x20, E33G_DMAAH);
330 outb_p(0x00, E33G_DMAAL);
331 return;
332 }
333
334
335
336 static void
337 el2_block_output(struct device *dev, int count,
338 const unsigned char *buf, const start_page)
339 {
340 int i;
341 int boguscount = 0;
342
343
344 outb(EGACFR_NORM, E33G_GACFR);
345
346 if (dev->mem_start) {
347 void *dest_addr = (void *)(dev->mem_start +
348 ((start_page - ei_status.tx_start_page) << 8));
349 memcpy(dest_addr, buf, count);
350 if (ei_debug > 2 && memcmp(dest_addr, buf, count))
351 printk("%s: 3c503 send_packet() bad memory copy @ %#5x.\n",
352 dev->name, (int) dest_addr);
353 return;
354 }
355
356
357 outb(0x00, E33G_DMAAL);
358 outb_p(start_page, E33G_DMAAH);
359 outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT
360 | ECNTRL_START, E33G_CNTRL);
361
362
363
364
365 for(i = 0; i < count; i++) {
366 if (i % 8 == 0)
367 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
368 if (++boguscount > (i<<3) + 32) {
369 printk("%s: FIFO blocked in el2_block_output (at %d of %d, bc=%d).\n",
370 dev->name, i, count, boguscount);
371 return;
372 }
373 outb(buf[i], E33G_FIFOH);
374 }
375 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
376 return;
377 }
378
379
380 static int
381 el2_block_input(struct device *dev, int count, char *buf, int ring_offset)
382 {
383 int boguscount = 0;
384 int end_of_ring = dev->rmem_end;
385 unsigned int i;
386
387
388 if (dev->mem_start) {
389 ring_offset -= (EL2SM_START_PG<<8);
390 if (dev->mem_start + ring_offset + count > end_of_ring) {
391
392 int semi_count = end_of_ring - (dev->mem_start + ring_offset);
393 memcpy(buf, (char *)dev->mem_start + ring_offset, semi_count);
394 count -= semi_count;
395 memcpy(buf + semi_count, (char *)dev->rmem_start, count);
396 return dev->rmem_start + count;
397 }
398 memcpy(buf, (char *)dev->mem_start + ring_offset, count);
399 return ring_offset + count;
400 }
401
402 outb(ring_offset & 0xff, E33G_DMAAL);
403 outb_p((ring_offset >> 8) & 0xff, E33G_DMAAH);
404 outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
405 | ECNTRL_START, E33G_CNTRL);
406
407
408
409 for(i = 0; i < count; i++) {
410 if (i % 8 == 0)
411 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
412 if (++boguscount > (i<<3) + 32) {
413 printk("%s: FIFO blocked in el2_block_input() (at %d of %d, bc=%d).\n",
414 dev->name, i, count, boguscount);
415 boguscount = 0;
416 break;
417 }
418 buf[i] = inb_p(E33G_FIFOH);
419 }
420 outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
421 return 0;
422 }
423
424
425
426
427
428
429