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