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