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