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