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 <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
204
205 ei_status.name = "3C503";
206 ei_status.tx_start_page = EL2SM_START_PG;
207 ei_status.rx_start_page = EL2SM_START_PG + TX_PAGES;
208 ei_status.stop_page = EL2SM_STOP_PG;
209 ei_status.reset_8390 = &el2_reset_8390;
210 ei_status.block_input = &el2_block_input;
211 ei_status.block_output = &el2_block_output;
212
213 if (dev->irq == 2)
214 dev->irq = 9;
215 else if (dev->irq > 5 && dev->irq != 9) {
216 printk("\n3c503: configured interrupt %d invalid, using autoIRQ.\n",
217 dev->irq);
218 dev->irq = 0;
219 }
220
221 ei_status.saved_irq = dev->irq;
222
223 dev->start = 0;
224 dev->open = &el2_open;
225 dev->stop = &el2_close;
226
227 if (dev->mem_start)
228 printk("\n%s: %s with shared memory at %#6lx-%#6lx,\n",
229 dev->name, ei_status.name, dev->mem_start, dev->mem_end-1);
230 else
231 printk("\n%s: %s using programmed I/O (REJUMPER for SHARED MEMORY).\n",
232 dev->name, ei_status.name);
233 if (ei_debug > 1)
234 printk(version);
235
236 return ioaddr;
237 }
238
239 static int
240 el2_open(struct device *dev)
241 {
242
243 if (dev->irq < 2) {
244 int irqlist[] = {5, 9, 3, 4, 0};
245 int *irqp = irqlist;
246
247 outb(EGACFR_NORM, E33G_GACFR);
248 do {
249 if (request_irq (*irqp, NULL) != -EBUSY) {
250
251 autoirq_setup(0);
252 outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR);
253 outb_p(0x00, E33G_IDCFR);
254 if (*irqp == autoirq_report(0)
255 && request_irq (dev->irq = *irqp, &ei_interrupt) == 0)
256 break;
257 }
258 } while (*++irqp);
259 if (*irqp == 0) {
260 outb(EGACFR_IRQOFF, E33G_GACFR);
261 return -EAGAIN;
262 }
263 } else {
264 if (request_irq(dev->irq, &ei_interrupt)) {
265 return -EAGAIN;
266 }
267 }
268 el2_init_card(dev);
269 return ei_open(dev);
270 }
271
272 static int
273 el2_close(struct device *dev)
274 {
275 free_irq(dev->irq);
276 dev->irq = ei_status.saved_irq;
277 irq2dev_map[dev->irq] = NULL;
278 outb(EGACFR_IRQOFF, E33G_GACFR);
279
280 NS8390_init(dev, 0);
281
282 return 0;
283 }
284
285
286
287
288
289 static void
290 el2_reset_8390(struct device *dev)
291 {
292 if (ei_debug > 1) {
293 printk("%s: Resetting the 3c503 board...", dev->name);
294 printk("%#x=%#02x %#x=%#02x %#x=%#02x...", E33G_IDCFR, inb(E33G_IDCFR),
295 E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR));
296 }
297 outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL);
298 ei_status.txing = 0;
299 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
300 el2_init_card(dev);
301 if (ei_debug > 1) printk("done\n");
302 }
303
304
305 static void
306 el2_init_card(struct device *dev)
307 {
308
309 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
310
311
312
313 outb(ei_status.rx_start_page, E33G_STARTPG);
314 outb(ei_status.stop_page, E33G_STOPPG);
315
316
317 outb(0xff, E33G_VP2);
318 outb(0xff, E33G_VP1);
319 outb(0x00, E33G_VP0);
320
321 outb_p(0x00, dev->base_addr + EN0_IMR);
322
323 outb(EGACFR_NORM, E33G_GACFR);
324
325
326 outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR);
327 outb_p(8, E33G_DRQCNT);
328 outb_p(0x20, E33G_DMAAH);
329 outb_p(0x00, E33G_DMAAL);
330 return;
331 }
332
333
334
335 static void
336 el2_block_output(struct device *dev, int count,
337 const unsigned char *buf, const start_page)
338 {
339 int i;
340 int boguscount = 0;
341
342
343 outb(EGACFR_NORM, E33G_GACFR);
344
345 if (dev->mem_start) {
346 void *dest_addr = (void *)(dev->mem_start +
347 ((start_page - ei_status.tx_start_page) << 8));
348 memcpy(dest_addr, buf, count);
349 if (ei_debug > 2 && memcmp(dest_addr, buf, count))
350 printk("%s: 3c503 send_packet() bad memory copy @ %#5x.\n",
351 dev->name, (int) dest_addr);
352 return;
353 }
354
355
356 outb(0x00, E33G_DMAAL);
357 outb_p(start_page, E33G_DMAAH);
358 outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT
359 | ECNTRL_START, E33G_CNTRL);
360
361
362
363
364 for(i = 0; i < count; i++) {
365 if (i % 8 == 0)
366 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
367 if (++boguscount > (i<<3) + 32) {
368 printk("%s: FIFO blocked in el2_block_output (at %d of %d, bc=%d).\n",
369 dev->name, i, count, boguscount);
370 return;
371 }
372 outb(buf[i], E33G_FIFOH);
373 }
374 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
375 return;
376 }
377
378
379 static int
380 el2_block_input(struct device *dev, int count, char *buf, int ring_offset)
381 {
382 int boguscount = 0;
383 int end_of_ring = dev->rmem_end;
384 unsigned int i;
385
386
387 if (dev->mem_start) {
388 ring_offset -= (EL2SM_START_PG<<8);
389 if (dev->mem_start + ring_offset + count > end_of_ring) {
390
391 int semi_count = end_of_ring - (dev->mem_start + ring_offset);
392 memcpy(buf, (char *)dev->mem_start + ring_offset, semi_count);
393 count -= semi_count;
394 memcpy(buf + semi_count, (char *)dev->rmem_start, count);
395 return dev->rmem_start + count;
396 }
397 memcpy(buf, (char *)dev->mem_start + ring_offset, count);
398 return ring_offset + count;
399 }
400
401 outb(ring_offset & 0xff, E33G_DMAAL);
402 outb_p((ring_offset >> 8) & 0xff, E33G_DMAAH);
403 outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
404 | ECNTRL_START, E33G_CNTRL);
405
406
407
408 for(i = 0; i < count; i++) {
409 if (i % 8 == 0)
410 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
411 if (++boguscount > (i<<3) + 32) {
412 printk("%s: FIFO blocked in el2_block_input() (at %d of %d, bc=%d).\n",
413 dev->name, i, count, boguscount);
414 boguscount = 0;
415 break;
416 }
417 buf[i] = inb_p(E33G_FIFOH);
418 }
419 outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
420 return 0;
421 }
422
423
424
425
426
427
428