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
32
33
34
35
36#define DRV_NAME "3c503"
37#define DRV_VERSION "1.10a"
38#define DRV_RELDATE "11/17/2001"
39
40
41static const char version[] =
42 DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Donald Becker (becker@scyld.com)\n";
43
44#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/errno.h>
47#include <linux/string.h>
48#include <linux/delay.h>
49#include <linux/netdevice.h>
50#include <linux/etherdevice.h>
51#include <linux/init.h>
52#include <linux/interrupt.h>
53#include <linux/ethtool.h>
54
55#include <asm/uaccess.h>
56#include <asm/io.h>
57#include <asm/byteorder.h>
58
59#include "8390.h"
60#include "3c503.h"
61#define WRD_COUNT 4
62
63static int el2_pio_probe(struct net_device *dev);
64static int el2_probe1(struct net_device *dev, int ioaddr);
65
66
67static unsigned int netcard_portlist[] __initdata =
68 { 0x300,0x310,0x330,0x350,0x250,0x280,0x2a0,0x2e0,0};
69
70#define EL2_IO_EXTENT 16
71
72static int el2_open(struct net_device *dev);
73static int el2_close(struct net_device *dev);
74static void el2_reset_8390(struct net_device *dev);
75static void el2_init_card(struct net_device *dev);
76static void el2_block_output(struct net_device *dev, int count,
77 const unsigned char *buf, int start_page);
78static void el2_block_input(struct net_device *dev, int count, struct sk_buff *skb,
79 int ring_offset);
80static void el2_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
81 int ring_page);
82static const struct ethtool_ops netdev_ethtool_ops;
83
84
85
86
87
88
89
90
91
92static int __init do_el2_probe(struct net_device *dev)
93{
94 int *addr, addrs[] = { 0xddffe, 0xd9ffe, 0xcdffe, 0xc9ffe, 0};
95 int base_addr = dev->base_addr;
96 int irq = dev->irq;
97
98 if (base_addr > 0x1ff)
99 return el2_probe1(dev, base_addr);
100 else if (base_addr != 0)
101 return -ENXIO;
102
103 for (addr = addrs; *addr; addr++) {
104 void __iomem *p = ioremap(*addr, 1);
105 unsigned base_bits;
106 int i;
107
108 if (!p)
109 continue;
110 base_bits = readb(p);
111 iounmap(p);
112 i = ffs(base_bits) - 1;
113 if (i == -1 || base_bits != (1 << i))
114 continue;
115 if (el2_probe1(dev, netcard_portlist[i]) == 0)
116 return 0;
117 dev->irq = irq;
118 }
119#if ! defined(no_probe_nonshared_memory)
120 return el2_pio_probe(dev);
121#else
122 return -ENODEV;
123#endif
124}
125
126
127
128static int __init
129el2_pio_probe(struct net_device *dev)
130{
131 int i;
132 int base_addr = dev->base_addr;
133 int irq = dev->irq;
134
135 if (base_addr > 0x1ff)
136 return el2_probe1(dev, base_addr);
137 else if (base_addr != 0)
138 return -ENXIO;
139
140 for (i = 0; netcard_portlist[i]; i++) {
141 if (el2_probe1(dev, netcard_portlist[i]) == 0)
142 return 0;
143 dev->irq = irq;
144 }
145
146 return -ENODEV;
147}
148
149#ifndef MODULE
150struct net_device * __init el2_probe(int unit)
151{
152 struct net_device *dev = alloc_eip_netdev();
153 int err;
154
155 if (!dev)
156 return ERR_PTR(-ENOMEM);
157
158 sprintf(dev->name, "eth%d", unit);
159 netdev_boot_setup_check(dev);
160
161 err = do_el2_probe(dev);
162 if (err)
163 goto out;
164 return dev;
165out:
166 free_netdev(dev);
167 return ERR_PTR(err);
168}
169#endif
170
171static const struct net_device_ops el2_netdev_ops = {
172 .ndo_open = el2_open,
173 .ndo_stop = el2_close,
174
175 .ndo_start_xmit = eip_start_xmit,
176 .ndo_tx_timeout = eip_tx_timeout,
177 .ndo_get_stats = eip_get_stats,
178 .ndo_set_rx_mode = eip_set_multicast_list,
179 .ndo_validate_addr = eth_validate_addr,
180 .ndo_set_mac_address = eth_mac_addr,
181 .ndo_change_mtu = eth_change_mtu,
182#ifdef CONFIG_NET_POLL_CONTROLLER
183 .ndo_poll_controller = eip_poll,
184#endif
185};
186
187
188
189
190static int __init
191el2_probe1(struct net_device *dev, int ioaddr)
192{
193 int i, iobase_reg, membase_reg, saved_406, wordlength, retval;
194 static unsigned version_printed;
195 unsigned long vendor_id;
196
197 if (!request_region(ioaddr, EL2_IO_EXTENT, DRV_NAME))
198 return -EBUSY;
199
200 if (!request_region(ioaddr + 0x400, 8, DRV_NAME)) {
201 retval = -EBUSY;
202 goto out;
203 }
204
205
206 if (inb(ioaddr + 0x408) == 0xff) {
207 mdelay(1);
208 retval = -ENODEV;
209 goto out1;
210 }
211
212
213
214 iobase_reg = inb(ioaddr+0x403);
215 membase_reg = inb(ioaddr+0x404);
216
217 if ((iobase_reg & (iobase_reg - 1)) ||
218 (membase_reg & (membase_reg - 1))) {
219 retval = -ENODEV;
220 goto out1;
221 }
222 saved_406 = inb_p(ioaddr + 0x406);
223 outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406);
224 outb_p(ECNTRL_THIN, ioaddr + 0x406);
225
226
227 outb(ECNTRL_SAPROM|ECNTRL_THIN, ioaddr + 0x406);
228 vendor_id = inb(ioaddr)*0x10000 + inb(ioaddr + 1)*0x100 + inb(ioaddr + 2);
229 if ((vendor_id != OLD_3COM_ID) && (vendor_id != NEW_3COM_ID)) {
230
231 outb(saved_406, ioaddr + 0x406);
232 retval = -ENODEV;
233 goto out1;
234 }
235
236 if (ei_debug && version_printed++ == 0)
237 pr_debug("%s", version);
238
239 dev->base_addr = ioaddr;
240
241 pr_info("%s: 3c503 at i/o base %#3x, node ", dev->name, ioaddr);
242
243
244 for (i = 0; i < 6; i++)
245 dev->dev_addr[i] = inb(ioaddr + i);
246 pr_cont("%pM", dev->dev_addr);
247
248
249 outb(ECNTRL_THIN, ioaddr + 0x406);
250
251
252 outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
253 outb_p(0, ioaddr + EN0_DCFG);
254 outb_p(E8390_PAGE2, ioaddr + E8390_CMD);
255 wordlength = inb_p(ioaddr + EN0_DCFG) & ENDCFG_WTS;
256 outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
257
258
259 if (ei_debug > 2)
260 pr_cont(" memory jumpers %2.2x ", membase_reg);
261 outb(EGACFR_NORM, ioaddr + 0x405);
262
263
264
265
266
267#if defined(EI8390_THICK) || defined(EL2_AUI)
268 ei_status.interface_num = 1;
269#else
270 ei_status.interface_num = dev->mem_end & 0xf;
271#endif
272 pr_cont(", using %sternal xcvr.\n", ei_status.interface_num == 0 ? "in" : "ex");
273
274 if ((membase_reg & 0xf0) == 0) {
275 dev->mem_start = 0;
276 ei_status.name = "3c503-PIO";
277 ei_status.mem = NULL;
278 } else {
279 dev->mem_start = ((membase_reg & 0xc0) ? 0xD8000 : 0xC8000) +
280 ((membase_reg & 0xA0) ? 0x4000 : 0);
281#define EL2_MEMSIZE (EL2_MB1_STOP_PG - EL2_MB1_START_PG)*256
282 ei_status.mem = ioremap(dev->mem_start, EL2_MEMSIZE);
283
284#ifdef EL2MEMTEST
285
286
287
288 {
289 void __iomem *mem_base = ei_status.mem;
290 unsigned int test_val = 0xbbadf00d;
291 writel(0xba5eba5e, mem_base);
292 for (i = sizeof(test_val); i < EL2_MEMSIZE; i+=sizeof(test_val)) {
293 writel(test_val, mem_base + i);
294 if (readl(mem_base) != 0xba5eba5e ||
295 readl(mem_base + i) != test_val) {
296 pr_warning("3c503: memory failure or memory address conflict.\n");
297 dev->mem_start = 0;
298 ei_status.name = "3c503-PIO";
299 iounmap(mem_base);
300 ei_status.mem = NULL;
301 break;
302 }
303 test_val += 0x55555555;
304 writel(0, mem_base + i);
305 }
306 }
307#endif
308
309 if (dev->mem_start)
310 dev->mem_end = dev->mem_start + EL2_MEMSIZE;
311
312 if (wordlength) {
313 ei_status.priv = 0;
314 ei_status.name = "3c503/16";
315 } else {
316 ei_status.priv = TX_PAGES * 256;
317 ei_status.name = "3c503";
318 }
319 }
320
321
322
323
324
325
326
327
328
329 if (wordlength) {
330 ei_status.tx_start_page = EL2_MB0_START_PG;
331 ei_status.rx_start_page = EL2_MB1_START_PG;
332 } else {
333 ei_status.tx_start_page = EL2_MB1_START_PG;
334 ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES;
335 }
336
337
338 ei_status.stop_page = EL2_MB1_STOP_PG;
339 ei_status.word16 = wordlength;
340 ei_status.reset_8390 = el2_reset_8390;
341 ei_status.get_8390_hdr = el2_get_8390_hdr;
342 ei_status.block_input = el2_block_input;
343 ei_status.block_output = el2_block_output;
344
345 if (dev->irq == 2)
346 dev->irq = 9;
347 else if (dev->irq > 5 && dev->irq != 9) {
348 pr_warning("3c503: configured interrupt %d invalid, will use autoIRQ.\n",
349 dev->irq);
350 dev->irq = 0;
351 }
352
353 ei_status.saved_irq = dev->irq;
354
355 dev->netdev_ops = &el2_netdev_ops;
356 dev->ethtool_ops = &netdev_ethtool_ops;
357
358 retval = register_netdev(dev);
359 if (retval)
360 goto out1;
361
362 if (dev->mem_start)
363 pr_info("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n",
364 dev->name, ei_status.name, (wordlength+1)<<3,
365 dev->mem_start, dev->mem_end-1);
366
367 else
368 {
369 ei_status.tx_start_page = EL2_MB1_START_PG;
370 ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES;
371 pr_info("%s: %s, %dkB RAM, using programmed I/O (REJUMPER for SHARED MEMORY).\n",
372 dev->name, ei_status.name, (wordlength+1)<<3);
373 }
374 release_region(ioaddr + 0x400, 8);
375 return 0;
376out1:
377 release_region(ioaddr + 0x400, 8);
378out:
379 release_region(ioaddr, EL2_IO_EXTENT);
380 return retval;
381}
382
383static irqreturn_t el2_probe_interrupt(int irq, void *seen)
384{
385 *(bool *)seen = true;
386 return IRQ_HANDLED;
387}
388
389static int
390el2_open(struct net_device *dev)
391{
392 int retval;
393
394 if (dev->irq < 2) {
395 static const int irqlist[] = {5, 9, 3, 4, 0};
396 const int *irqp = irqlist;
397
398 outb(EGACFR_NORM, E33G_GACFR);
399 do {
400 bool seen;
401
402 retval = request_irq(*irqp, el2_probe_interrupt, 0,
403 dev->name, &seen);
404 if (retval == -EBUSY)
405 continue;
406 if (retval < 0)
407 goto err_disable;
408
409
410 seen = false;
411 smp_wmb();
412 outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR);
413 outb_p(0x00, E33G_IDCFR);
414 msleep(1);
415 free_irq(*irqp, &seen);
416 if (!seen)
417 continue;
418
419 retval = request_irq(dev->irq = *irqp, eip_interrupt, 0,
420 dev->name, dev);
421 if (retval == -EBUSY)
422 continue;
423 if (retval < 0)
424 goto err_disable;
425 break;
426 } while (*++irqp);
427
428 if (*irqp == 0) {
429 err_disable:
430 outb(EGACFR_IRQOFF, E33G_GACFR);
431 return -EAGAIN;
432 }
433 } else {
434 if ((retval = request_irq(dev->irq, eip_interrupt, 0, dev->name, dev))) {
435 return retval;
436 }
437 }
438
439 el2_init_card(dev);
440 eip_open(dev);
441 return 0;
442}
443
444static int
445el2_close(struct net_device *dev)
446{
447 free_irq(dev->irq, dev);
448 dev->irq = ei_status.saved_irq;
449 outb(EGACFR_IRQOFF, E33G_GACFR);
450
451 eip_close(dev);
452 return 0;
453}
454
455
456
457
458
459static void
460el2_reset_8390(struct net_device *dev)
461{
462 if (ei_debug > 1) {
463 pr_debug("%s: Resetting the 3c503 board...", dev->name);
464 pr_cont(" %#lx=%#02x %#lx=%#02x %#lx=%#02x...", E33G_IDCFR, inb(E33G_IDCFR),
465 E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR));
466 }
467 outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL);
468 ei_status.txing = 0;
469 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
470 el2_init_card(dev);
471 if (ei_debug > 1)
472 pr_cont("done\n");
473}
474
475
476static void
477el2_init_card(struct net_device *dev)
478{
479
480 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
481
482
483
484 outb(ei_status.rx_start_page, E33G_STARTPG);
485 outb(ei_status.stop_page, E33G_STOPPG);
486
487
488 outb(0xff, E33G_VP2);
489 outb(0xff, E33G_VP1);
490 outb(0x00, E33G_VP0);
491
492 outb_p(0x00, dev->base_addr + EN0_IMR);
493
494 outb(EGACFR_NORM, E33G_GACFR);
495
496
497 outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR);
498 outb_p((WRD_COUNT << 1), E33G_DRQCNT);
499 outb_p(0x20, E33G_DMAAH);
500 outb_p(0x00, E33G_DMAAL);
501 return;
502}
503
504
505
506
507
508static void
509el2_block_output(struct net_device *dev, int count,
510 const unsigned char *buf, int start_page)
511{
512 unsigned short int *wrd;
513 int boguscount;
514 unsigned short word;
515 void __iomem *base = ei_status.mem;
516
517 if (ei_status.word16)
518 outb(EGACFR_RSEL|EGACFR_TCM, E33G_GACFR);
519 else
520 outb(EGACFR_NORM, E33G_GACFR);
521
522 if (base) {
523 memcpy_toio(base + ((start_page - ei_status.tx_start_page) << 8),
524 buf, count);
525 outb(EGACFR_NORM, E33G_GACFR);
526 return;
527 }
528
529
530
531
532
533
534 word = (unsigned short)start_page;
535 outb(word&0xFF, E33G_DMAAH);
536 outb(word>>8, E33G_DMAAL);
537
538 outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT
539 | ECNTRL_START, E33G_CNTRL);
540
541
542
543
544
545
546
547
548
549 wrd = (unsigned short int *) buf;
550 count = (count + 1) >> 1;
551 for(;;)
552 {
553 boguscount = 0x1000;
554 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
555 {
556 if(!boguscount--)
557 {
558 pr_notice("%s: FIFO blocked in el2_block_output.\n", dev->name);
559 el2_reset_8390(dev);
560 goto blocked;
561 }
562 }
563 if(count > WRD_COUNT)
564 {
565 outsw(E33G_FIFOH, wrd, WRD_COUNT);
566 wrd += WRD_COUNT;
567 count -= WRD_COUNT;
568 }
569 else
570 {
571 outsw(E33G_FIFOH, wrd, count);
572 break;
573 }
574 }
575 blocked:;
576 outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
577}
578
579
580static void
581el2_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
582{
583 int boguscount;
584 void __iomem *base = ei_status.mem;
585 unsigned short word;
586
587 if (base) {
588 void __iomem *hdr_start = base + ((ring_page - EL2_MB1_START_PG)<<8);
589 memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
590 hdr->count = le16_to_cpu(hdr->count);
591 return;
592 }
593
594
595
596
597
598 word = (unsigned short)ring_page;
599 outb(word&0xFF, E33G_DMAAH);
600 outb(word>>8, E33G_DMAAL);
601
602 outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
603 | ECNTRL_START, E33G_CNTRL);
604 boguscount = 0x1000;
605 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
606 {
607 if(!boguscount--)
608 {
609 pr_notice("%s: FIFO blocked in el2_get_8390_hdr.\n", dev->name);
610 memset(hdr, 0x00, sizeof(struct e8390_pkt_hdr));
611 el2_reset_8390(dev);
612 goto blocked;
613 }
614 }
615 insw(E33G_FIFOH, hdr, (sizeof(struct e8390_pkt_hdr))>> 1);
616 blocked:;
617 outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
618}
619
620
621static void
622el2_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
623{
624 int boguscount = 0;
625 void __iomem *base = ei_status.mem;
626 unsigned short int *buf;
627 unsigned short word;
628
629
630 if (base) {
631 ring_offset -= (EL2_MB1_START_PG<<8);
632 if (ring_offset + count > EL2_MEMSIZE) {
633
634 int semi_count = EL2_MEMSIZE - ring_offset;
635 memcpy_fromio(skb->data, base + ring_offset, semi_count);
636 count -= semi_count;
637 memcpy_fromio(skb->data + semi_count, base + ei_status.priv, count);
638 } else {
639 memcpy_fromio(skb->data, base + ring_offset, count);
640 }
641 return;
642 }
643
644
645
646
647 word = (unsigned short) ring_offset;
648 outb(word>>8, E33G_DMAAH);
649 outb(word&0xFF, E33G_DMAAL);
650
651 outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
652 | ECNTRL_START, E33G_CNTRL);
653
654
655
656
657
658
659
660
661
662
663
664 buf = (unsigned short int *) skb->data;
665 count = (count + 1) >> 1;
666 for(;;)
667 {
668 boguscount = 0x1000;
669 while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
670 {
671 if(!boguscount--)
672 {
673 pr_notice("%s: FIFO blocked in el2_block_input.\n", dev->name);
674 el2_reset_8390(dev);
675 goto blocked;
676 }
677 }
678 if(count > WRD_COUNT)
679 {
680 insw(E33G_FIFOH, buf, WRD_COUNT);
681 buf += WRD_COUNT;
682 count -= WRD_COUNT;
683 }
684 else
685 {
686 insw(E33G_FIFOH, buf, count);
687 break;
688 }
689 }
690 blocked:;
691 outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
692}
693
694
695static void netdev_get_drvinfo(struct net_device *dev,
696 struct ethtool_drvinfo *info)
697{
698 strcpy(info->driver, DRV_NAME);
699 strcpy(info->version, DRV_VERSION);
700 sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr);
701}
702
703static const struct ethtool_ops netdev_ethtool_ops = {
704 .get_drvinfo = netdev_get_drvinfo,
705};
706
707#ifdef MODULE
708#define MAX_EL2_CARDS 4
709
710static struct net_device *dev_el2[MAX_EL2_CARDS];
711static int io[MAX_EL2_CARDS];
712static int irq[MAX_EL2_CARDS];
713static int xcvr[MAX_EL2_CARDS];
714module_param_array(io, int, NULL, 0);
715module_param_array(irq, int, NULL, 0);
716module_param_array(xcvr, int, NULL, 0);
717MODULE_PARM_DESC(io, "I/O base address(es)");
718MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)");
719MODULE_PARM_DESC(xcvr, "transceiver(s) (0=internal, 1=external)");
720MODULE_DESCRIPTION("3Com ISA EtherLink II, II/16 (3c503, 3c503/16) driver");
721MODULE_LICENSE("GPL");
722
723
724
725int __init
726init_module(void)
727{
728 struct net_device *dev;
729 int this_dev, found = 0;
730
731 for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
732 if (io[this_dev] == 0) {
733 if (this_dev != 0) break;
734 pr_notice("3c503.c: Presently autoprobing (not recommended) for a single card.\n");
735 }
736 dev = alloc_eip_netdev();
737 if (!dev)
738 break;
739 dev->irq = irq[this_dev];
740 dev->base_addr = io[this_dev];
741 dev->mem_end = xcvr[this_dev];
742 if (do_el2_probe(dev) == 0) {
743 dev_el2[found++] = dev;
744 continue;
745 }
746 free_netdev(dev);
747 pr_warning("3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]);
748 break;
749 }
750 if (found)
751 return 0;
752 return -ENXIO;
753}
754
755static void cleanup_card(struct net_device *dev)
756{
757
758 release_region(dev->base_addr, EL2_IO_EXTENT);
759 if (ei_status.mem)
760 iounmap(ei_status.mem);
761}
762
763void __exit
764cleanup_module(void)
765{
766 int this_dev;
767
768 for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
769 struct net_device *dev = dev_el2[this_dev];
770 if (dev) {
771 unregister_netdev(dev);
772 cleanup_card(dev);
773 free_netdev(dev);
774 }
775 }
776}
777#endif
778