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