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