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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64#define DRV_NAME "3c509"
65#define DRV_VERSION "1.19b"
66#define DRV_RELDATE "08Nov2002"
67
68
69
70
71#define TX_TIMEOUT (400*HZ/1000)
72
73static int max_interrupt_work = 10;
74
75#include <linux/config.h>
76#include <linux/module.h>
77#ifdef CONFIG_MCA
78#include <linux/mca.h>
79#endif
80#include <linux/isapnp.h>
81#include <linux/string.h>
82#include <linux/interrupt.h>
83#include <linux/errno.h>
84#include <linux/in.h>
85#include <linux/slab.h>
86#include <linux/ioport.h>
87#include <linux/init.h>
88#include <linux/netdevice.h>
89#include <linux/etherdevice.h>
90#include <linux/pm.h>
91#include <linux/skbuff.h>
92#include <linux/delay.h>
93#include <linux/spinlock.h>
94#include <linux/ethtool.h>
95#include <linux/device.h>
96#include <linux/eisa.h>
97
98#include <asm/uaccess.h>
99#include <asm/bitops.h>
100#include <asm/io.h>
101#include <asm/irq.h>
102
103static char versionA[] __initdata = DRV_NAME ".c:" DRV_VERSION " " DRV_RELDATE " becker@scyld.com\n";
104static char versionB[] __initdata = "http://www.scyld.com/network/3c509.html\n";
105
106#ifdef EL3_DEBUG
107static int el3_debug = EL3_DEBUG;
108#else
109static int el3_debug = 2;
110#endif
111
112
113
114
115static int el3_cards = 0;
116
117
118
119
120
121#define EL3_DATA 0x00
122#define EL3_CMD 0x0e
123#define EL3_STATUS 0x0e
124#define EEPROM_READ 0x80
125
126#define EL3_IO_EXTENT 16
127
128#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
129
130
131
132
133enum c509cmd {
134 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
135 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,
136 TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
137 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
138 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
139 SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11,
140 StatsDisable = 22<<11, StopCoax = 23<<11, PowerUp = 27<<11,
141 PowerDown = 28<<11, PowerAuto = 29<<11};
142
143enum c509status {
144 IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
145 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
146 IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000, };
147
148
149enum RxFilter {
150 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
151
152
153#define TX_FIFO 0x00
154#define RX_FIFO 0x00
155#define RX_STATUS 0x08
156#define TX_STATUS 0x0B
157#define TX_FREE 0x0C
158
159#define WN0_CONF_CTRL 0x04
160#define WN0_ADDR_CONF 0x06
161#define WN0_IRQ 0x08
162#define WN4_MEDIA 0x0A
163#define MEDIA_TP 0x00C0
164#define WN4_NETDIAG 0x06
165#define FD_ENABLE 0x8000
166
167
168
169
170
171#define SKB_QUEUE_SIZE 64
172
173struct el3_private {
174 struct net_device_stats stats;
175 struct net_device *next_dev;
176 spinlock_t lock;
177
178 int head, size;
179 struct sk_buff *queue[SKB_QUEUE_SIZE];
180#ifdef CONFIG_PM
181 struct pm_dev *pmdev;
182#endif
183 enum {
184 EL3_MCA,
185 EL3_PNP,
186 EL3_EISA,
187 } type;
188 struct device *dev;
189};
190static int id_port __initdata = 0x110;
191static struct net_device *el3_root_dev;
192
193static ushort id_read_eeprom(int index);
194static ushort read_eeprom(int ioaddr, int index);
195static int el3_open(struct net_device *dev);
196static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev);
197static irqreturn_t el3_interrupt(int irq, void *dev_id, struct pt_regs *regs);
198static void update_stats(struct net_device *dev);
199static struct net_device_stats *el3_get_stats(struct net_device *dev);
200static int el3_rx(struct net_device *dev);
201static int el3_close(struct net_device *dev);
202static void set_multicast_list(struct net_device *dev);
203static void el3_tx_timeout (struct net_device *dev);
204static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
205static void el3_down(struct net_device *dev);
206static void el3_up(struct net_device *dev);
207#ifdef CONFIG_PM
208static int el3_suspend(struct pm_dev *pdev);
209static int el3_resume(struct pm_dev *pdev);
210static int el3_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data);
211#endif
212
213#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
214static int el3_device_remove (struct device *device);
215#endif
216
217#ifdef CONFIG_EISA
218struct eisa_device_id el3_eisa_ids[] = {
219 { "TCM5092" },
220 { "TCM5093" },
221 { "" }
222};
223
224static int el3_eisa_probe (struct device *device);
225
226struct eisa_driver el3_eisa_driver = {
227 .id_table = el3_eisa_ids,
228 .driver = {
229 .name = "3c509",
230 .probe = el3_eisa_probe,
231 .remove = __devexit_p (el3_device_remove)
232 }
233};
234#endif
235
236#ifdef CONFIG_MCA
237static int el3_mca_probe(struct device *dev);
238
239static short el3_mca_adapter_ids[] __initdata = {
240 0x627c,
241 0x627d,
242 0x62db,
243 0x62f6,
244 0x62f7,
245 0x0000
246};
247
248static char *el3_mca_adapter_names[] __initdata = {
249 "3Com 3c529 EtherLink III (10base2)",
250 "3Com 3c529 EtherLink III (10baseT)",
251 "3Com 3c529 EtherLink III (test mode)",
252 "3Com 3c529 EtherLink III (TP or coax)",
253 "3Com 3c529 EtherLink III (TP)",
254 NULL
255};
256
257static struct mca_driver el3_mca_driver = {
258 .id_table = el3_mca_adapter_ids,
259 .driver = {
260 .name = "3c529",
261 .bus = &mca_bus_type,
262 .probe = el3_mca_probe,
263 .remove = __devexit_p(el3_device_remove),
264 },
265};
266#endif
267
268#if defined(__ISAPNP__) && !defined(CONFIG_X86_PC9800)
269static struct isapnp_device_id el3_isapnp_adapters[] __initdata = {
270 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
271 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5090),
272 (long) "3Com Etherlink III (TP)" },
273 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
274 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5091),
275 (long) "3Com Etherlink III" },
276 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
277 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5094),
278 (long) "3Com Etherlink III (combo)" },
279 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
280 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5095),
281 (long) "3Com Etherlink III (TPO)" },
282 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
283 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5098),
284 (long) "3Com Etherlink III (TPC)" },
285 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
286 ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_FUNCTION(0x80f7),
287 (long) "3Com Etherlink III compatible" },
288 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
289 ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_FUNCTION(0x80f8),
290 (long) "3Com Etherlink III compatible" },
291 { }
292};
293
294static u16 el3_isapnp_phys_addr[8][3];
295static int nopnp;
296#endif
297
298
299
300
301
302
303
304
305static int __init el3_common_init(struct net_device *dev)
306{
307 struct el3_private *lp = dev->priv;
308 short i;
309 int err;
310
311 spin_lock_init(&lp->lock);
312
313 if (dev->mem_start & 0x05) {
314 dev->if_port = (dev->mem_start & 0x0f);
315 } else {
316
317 dev->if_port |= (dev->mem_start & 0x08);
318 }
319
320
321 dev->open = &el3_open;
322 dev->hard_start_xmit = &el3_start_xmit;
323 dev->stop = &el3_close;
324 dev->get_stats = &el3_get_stats;
325 dev->set_multicast_list = &set_multicast_list;
326 dev->tx_timeout = el3_tx_timeout;
327 dev->watchdog_timeo = TX_TIMEOUT;
328 dev->do_ioctl = netdev_ioctl;
329
330 err = register_netdev(dev);
331 if (err) {
332 printk(KERN_ERR "Failed to register 3c5x9 at %#3.3lx, IRQ %d.\n",
333 dev->base_addr, dev->irq);
334 release_region(dev->base_addr, EL3_IO_EXTENT);
335 return err;
336 }
337
338 {
339 const char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};
340 printk("%s: 3c5x9 found at %#3.3lx, %s port, address ",
341 dev->name, dev->base_addr,
342 if_names[(dev->if_port & 0x03)]);
343 }
344
345
346 for (i = 0; i < 6; i++)
347 printk(" %2.2x", dev->dev_addr[i]);
348 printk(", IRQ %d.\n", dev->irq);
349
350 if (el3_debug > 0)
351 printk(KERN_INFO "%s" KERN_INFO "%s", versionA, versionB);
352 return 0;
353
354}
355
356static void el3_common_remove (struct net_device *dev)
357{
358 struct el3_private *lp = dev->priv;
359
360 (void) lp;
361#ifdef CONFIG_PM
362 if (lp->pmdev)
363 pm_unregister(lp->pmdev);
364#endif
365#if defined(__ISAPNP__) && !defined(CONFIG_X86_PC9800)
366 if (lp->type == EL3_PNP)
367 pnp_device_detach(to_pnp_dev(lp->dev));
368#endif
369
370 unregister_netdev (dev);
371 release_region(dev->base_addr, EL3_IO_EXTENT);
372 free_netdev (dev);
373}
374
375static int __init el3_probe(int card_idx)
376{
377 struct net_device *dev;
378 struct el3_private *lp;
379 short lrs_state = 0xff, i;
380 int ioaddr, irq, if_port;
381 u16 phys_addr[3];
382 static int current_tag;
383 int err = -ENODEV;
384#if defined(__ISAPNP__) && !defined(CONFIG_X86_PC9800)
385 static int pnp_cards;
386 struct pnp_dev *idev = NULL;
387
388 if (nopnp == 1)
389 goto no_pnp;
390
391 for (i=0; el3_isapnp_adapters[i].vendor != 0; i++) {
392 int j;
393 while ((idev = pnp_find_dev(NULL,
394 el3_isapnp_adapters[i].vendor,
395 el3_isapnp_adapters[i].function,
396 idev))) {
397 if (pnp_device_attach(idev) < 0)
398 continue;
399 if (pnp_activate_dev(idev) < 0) {
400 __again:
401 pnp_device_detach(idev);
402 continue;
403 }
404 if (!pnp_port_valid(idev, 0) || !pnp_irq_valid(idev, 0))
405 goto __again;
406 ioaddr = pnp_port_start(idev, 0);
407 if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509 PnP")) {
408 pnp_device_detach(idev);
409 return -EBUSY;
410 }
411 irq = pnp_irq(idev, 0);
412 if (el3_debug > 3)
413 printk ("ISAPnP reports %s at i/o 0x%x, irq %d\n",
414 (char*) el3_isapnp_adapters[i].driver_data, ioaddr, irq);
415 EL3WINDOW(0);
416 for (j = 0; j < 3; j++)
417 el3_isapnp_phys_addr[pnp_cards][j] =
418 phys_addr[j] =
419 htons(read_eeprom(ioaddr, j));
420 if_port = read_eeprom(ioaddr, 8) >> 14;
421 dev = alloc_etherdev(sizeof (struct el3_private));
422 if (!dev) {
423 release_region(ioaddr, EL3_IO_EXTENT);
424 pnp_device_detach(idev);
425 return -ENOMEM;
426 }
427
428 SET_MODULE_OWNER(dev);
429 pnp_cards++;
430
431 netdev_boot_setup_check(dev);
432 goto found;
433 }
434 }
435no_pnp:
436#endif
437
438#ifdef CONFIG_X86_PC9800
439 id_port = 0x71d0;
440#else
441
442 for ( ; id_port < 0x200; id_port += 0x10) {
443 if (!request_region(id_port, 1, "3c509"))
444 continue;
445 outb(0x00, id_port);
446 outb(0xff, id_port);
447 if (inb(id_port) & 0x01){
448 release_region(id_port, 1);
449 break;
450 } else
451 release_region(id_port, 1);
452 }
453 if (id_port >= 0x200) {
454
455 printk(" WARNING: No I/O port available for 3c509 activation.\n");
456 return -ENODEV;
457 }
458#endif
459
460
461
462
463
464 outb(0x00, id_port);
465 outb(0x00, id_port);
466 for(i = 0; i < 255; i++) {
467 outb(lrs_state, id_port);
468 lrs_state <<= 1;
469 lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
470 }
471
472
473 if (current_tag == 0)
474 outb(0xd0, id_port);
475 else
476 outb(0xd8, id_port);
477
478 if (id_read_eeprom(7) != 0x6d50) {
479 return -ENODEV;
480 }
481
482
483
484
485 for (i = 0; i < 3; i++) {
486 phys_addr[i] = htons(id_read_eeprom(i));
487 }
488
489#if defined(__ISAPNP__) && !defined(CONFIG_X86_PC9800)
490 if (nopnp == 0) {
491
492
493 for (i = 0; i < pnp_cards; i++) {
494 if (phys_addr[0] == el3_isapnp_phys_addr[i][0] &&
495 phys_addr[1] == el3_isapnp_phys_addr[i][1] &&
496 phys_addr[2] == el3_isapnp_phys_addr[i][2])
497 {
498 if (el3_debug > 3)
499 printk("3c509 with address %02x %02x %02x %02x %02x %02x was found by ISAPnP\n",
500 phys_addr[0] & 0xff, phys_addr[0] >> 8,
501 phys_addr[1] & 0xff, phys_addr[1] >> 8,
502 phys_addr[2] & 0xff, phys_addr[2] >> 8);
503
504 outb(0xd0 + ++current_tag, id_port);
505 goto no_pnp;
506 }
507 }
508 }
509#endif
510
511 {
512 unsigned int iobase = id_read_eeprom(8);
513 if_port = iobase >> 14;
514#ifdef CONFIG_X86_PC9800
515 ioaddr = 0x40d0 + ((iobase & 0x1f) << 8);
516#else
517 ioaddr = 0x200 + ((iobase & 0x1f) << 4);
518#endif
519 }
520 irq = id_read_eeprom(9) >> 12;
521#ifdef CONFIG_X86_PC9800
522 if (irq == 7)
523 irq = 6;
524 else if (irq == 15)
525 irq = 13;
526#endif
527
528 dev = alloc_etherdev(sizeof (struct el3_private));
529 if (!dev)
530 return -ENOMEM;
531
532 SET_MODULE_OWNER(dev);
533
534 netdev_boot_setup_check(dev);
535
536
537 if (dev->irq > 1 && dev->irq < 16)
538 irq = dev->irq;
539
540 if (dev->base_addr) {
541 if (dev->mem_end == 0x3c509
542 && dev->base_addr >= 0x200 && dev->base_addr <= 0x3e0)
543 ioaddr = dev->base_addr & 0x3f0;
544 else if (dev->base_addr != ioaddr)
545 goto out;
546 }
547
548 if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509")) {
549 err = -EBUSY;
550 goto out;
551 }
552
553
554 outb(0xd0 + ++current_tag, id_port);
555
556
557#ifdef CONFIG_X86_PC9800
558 outb((ioaddr >> 8) | 0xe0, id_port);
559#else
560 outb((ioaddr >> 4) | 0xe0, id_port);
561#endif
562
563 EL3WINDOW(0);
564 if (inw(ioaddr) != 0x6d50)
565 goto out1;
566
567
568 outw(0x0f00, ioaddr + WN0_IRQ);
569
570#if defined(__ISAPNP__) && !defined(CONFIG_X86_PC9800)
571 found:
572#endif
573
574 memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));
575 dev->base_addr = ioaddr;
576 dev->irq = irq;
577 dev->if_port = if_port;
578 lp = dev->priv;
579#if defined(__ISAPNP__) && !defined(CONFIG_X86_PC9800)
580 lp->dev = &idev->dev;
581#endif
582 err = el3_common_init(dev);
583
584 if (err)
585 goto out1;
586
587#ifdef CONFIG_PM
588
589 lp->pmdev = pm_register(PM_ISA_DEV, card_idx, el3_pm_callback);
590 if (lp->pmdev) {
591 struct pm_dev *p;
592 p = lp->pmdev;
593 p->data = (struct net_device *)dev;
594 }
595#endif
596
597 el3_cards++;
598#if !defined(__ISAPNP__) || defined(CONFIG_X86_PC9800)
599 lp->next_dev = el3_root_dev;
600 el3_root_dev = dev;
601#endif
602 return 0;
603
604out1:
605#if defined(__ISAPNP__) && !defined(CONFIG_X86_PC9800)
606 if (idev)
607 pnp_device_detach(idev);
608#endif
609out:
610 free_netdev(dev);
611 return err;
612}
613
614#ifdef CONFIG_MCA
615static int __init el3_mca_probe(struct device *device) {
616
617
618
619
620
621
622
623
624 struct el3_private *lp;
625 short i;
626 int ioaddr, irq, if_port;
627 u16 phys_addr[3];
628 struct net_device *dev = NULL;
629 u_char pos4, pos5;
630 struct mca_device *mdev = to_mca_device(device);
631 int slot = mdev->slot;
632 int err;
633
634 pos4 = mca_device_read_stored_pos(mdev, 4);
635 pos5 = mca_device_read_stored_pos(mdev, 5);
636
637 ioaddr = ((short)((pos4&0xfc)|0x02)) << 8;
638 irq = pos5 & 0x0f;
639
640
641 printk("3c529: found %s at slot %d\n",
642 el3_mca_adapter_names[mdev->index], slot + 1);
643
644
645 strncpy(mdev->name, el3_mca_adapter_names[mdev->index],
646 sizeof(mdev->name));
647 mca_device_set_claim(mdev, 1);
648
649 if_port = pos4 & 0x03;
650
651 irq = mca_device_transform_irq(mdev, irq);
652 ioaddr = mca_device_transform_ioport(mdev, ioaddr);
653 if (el3_debug > 2) {
654 printk("3c529: irq %d ioaddr 0x%x ifport %d\n", irq, ioaddr, if_port);
655 }
656 EL3WINDOW(0);
657 for (i = 0; i < 3; i++) {
658 phys_addr[i] = htons(read_eeprom(ioaddr, i));
659 }
660
661 dev = alloc_etherdev(sizeof (struct el3_private));
662 if (dev == NULL) {
663 release_region(ioaddr, EL3_IO_EXTENT);
664 return -ENOMEM;
665 }
666
667 SET_MODULE_OWNER(dev);
668 netdev_boot_setup_check(dev);
669
670 memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));
671 dev->base_addr = ioaddr;
672 dev->irq = irq;
673 dev->if_port = if_port;
674 lp = dev->priv;
675 lp->dev = device;
676 lp->type = EL3_MCA;
677 device->driver_data = dev;
678 err = el3_common_init(dev);
679
680 if (err) {
681 return -ENOMEM;
682 }
683
684 el3_cards++;
685 return 0;
686}
687
688#endif
689
690#ifdef CONFIG_EISA
691static int __init el3_eisa_probe (struct device *device)
692{
693 struct el3_private *lp;
694 short i;
695 int ioaddr, irq, if_port;
696 u16 phys_addr[3];
697 struct net_device *dev = NULL;
698 struct eisa_device *edev;
699 int err;
700
701
702 edev = to_eisa_device (device);
703 ioaddr = edev->base_addr;
704
705 if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509"))
706 return -EBUSY;
707
708
709 outw(SelectWindow | 0, ioaddr + 0xC80 + EL3_CMD);
710
711 irq = inw(ioaddr + WN0_IRQ) >> 12;
712 if_port = inw(ioaddr + 6)>>14;
713 for (i = 0; i < 3; i++)
714 phys_addr[i] = htons(read_eeprom(ioaddr, i));
715
716
717 read_eeprom(ioaddr, 3);
718
719 dev = alloc_etherdev(sizeof (struct el3_private));
720 if (dev == NULL) {
721 release_region(ioaddr, EL3_IO_EXTENT);
722 return -ENOMEM;
723 }
724
725 SET_MODULE_OWNER(dev);
726
727 netdev_boot_setup_check(dev);
728
729 memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));
730 dev->base_addr = ioaddr;
731 dev->irq = irq;
732 dev->if_port = if_port;
733 lp = dev->priv;
734 lp->dev = device;
735 lp->type = EL3_EISA;
736 eisa_set_drvdata (edev, dev);
737 err = el3_common_init(dev);
738
739 if (err) {
740 return err;
741 }
742
743 el3_cards++;
744 return 0;
745}
746#endif
747
748#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
749
750
751
752static int __devexit el3_device_remove (struct device *device)
753{
754 struct net_device *dev;
755
756 dev = device->driver_data;
757
758 el3_common_remove (dev);
759 return 0;
760}
761#endif
762
763
764
765
766static ushort read_eeprom(int ioaddr, int index)
767{
768 outw(EEPROM_READ + index, ioaddr + 10);
769
770
771 mdelay(2);
772 return inw(ioaddr + 12);
773}
774
775
776static ushort __init id_read_eeprom(int index)
777{
778 int bit, word = 0;
779
780
781
782 outb(EEPROM_READ + index, id_port);
783
784
785
786 mdelay(4);
787
788 for (bit = 15; bit >= 0; bit--)
789 word = (word << 1) + (inb(id_port) & 0x01);
790
791 if (el3_debug > 3)
792 printk(" 3c509 EEPROM word %d %#4.4x.\n", index, word);
793
794 return word;
795}
796
797
798static int
799el3_open(struct net_device *dev)
800{
801 int ioaddr = dev->base_addr;
802 int i;
803
804 outw(TxReset, ioaddr + EL3_CMD);
805 outw(RxReset, ioaddr + EL3_CMD);
806 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
807
808 i = request_irq(dev->irq, &el3_interrupt, 0, dev->name, dev);
809 if (i) return i;
810
811 EL3WINDOW(0);
812 if (el3_debug > 3)
813 printk("%s: Opening, IRQ %d status@%x %4.4x.\n", dev->name,
814 dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));
815
816 el3_up(dev);
817
818 if (el3_debug > 3)
819 printk("%s: Opened 3c509 IRQ %d status %4.4x.\n",
820 dev->name, dev->irq, inw(ioaddr + EL3_STATUS));
821
822 return 0;
823}
824
825static void
826el3_tx_timeout (struct net_device *dev)
827{
828 struct el3_private *lp = (struct el3_private *)dev->priv;
829 int ioaddr = dev->base_addr;
830
831
832 printk("%s: transmit timed out, Tx_status %2.2x status %4.4x "
833 "Tx FIFO room %d.\n",
834 dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS),
835 inw(ioaddr + TX_FREE));
836 lp->stats.tx_errors++;
837 dev->trans_start = jiffies;
838
839 outw(TxReset, ioaddr + EL3_CMD);
840 outw(TxEnable, ioaddr + EL3_CMD);
841 netif_wake_queue(dev);
842}
843
844
845static int
846el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
847{
848 struct el3_private *lp = (struct el3_private *)dev->priv;
849 int ioaddr = dev->base_addr;
850 unsigned long flags;
851
852 netif_stop_queue (dev);
853
854 lp->stats.tx_bytes += skb->len;
855
856 if (el3_debug > 4) {
857 printk("%s: el3_start_xmit(length = %u) called, status %4.4x.\n",
858 dev->name, skb->len, inw(ioaddr + EL3_STATUS));
859 }
860#if 0
861#ifndef final_version
862 {
863 ushort status = inw(ioaddr + EL3_STATUS);
864 if (status & 0x0001
865 && inw(ioaddr + EL3_STATUS) & 1) {
866 printk("%s: Missed interrupt, status then %04x now %04x"
867 " Tx %2.2x Rx %4.4x.\n", dev->name, status,
868 inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS),
869 inw(ioaddr + RX_STATUS));
870
871 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
872 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
873 ioaddr + EL3_CMD);
874 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
875 }
876 }
877#endif
878#endif
879
880
881
882
883
884
885
886
887
888
889
890 spin_lock_irqsave(&lp->lock, flags);
891
892
893 outw(skb->len, ioaddr + TX_FIFO);
894 outw(0x00, ioaddr + TX_FIFO);
895
896#ifdef __powerpc__
897 outsl_ns(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
898#else
899 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
900#endif
901
902 dev->trans_start = jiffies;
903 if (inw(ioaddr + TX_FREE) > 1536)
904 netif_start_queue(dev);
905 else
906
907 outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
908
909 spin_unlock_irqrestore(&lp->lock, flags);
910
911 dev_kfree_skb (skb);
912
913
914 {
915 short tx_status;
916 int i = 4;
917
918 while (--i > 0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
919 if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
920 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
921 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
922 outb(0x00, ioaddr + TX_STATUS);
923 }
924 }
925 return 0;
926}
927
928
929static irqreturn_t
930el3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
931{
932 struct net_device *dev = (struct net_device *)dev_id;
933 struct el3_private *lp;
934 int ioaddr, status;
935 int i = max_interrupt_work;
936
937 if (dev == NULL) {
938 printk ("el3_interrupt(): irq %d for unknown device.\n", irq);
939 return IRQ_NONE;
940 }
941
942 lp = (struct el3_private *)dev->priv;
943 spin_lock(&lp->lock);
944
945 ioaddr = dev->base_addr;
946
947 if (el3_debug > 4) {
948 status = inw(ioaddr + EL3_STATUS);
949 printk("%s: interrupt, status %4.4x.\n", dev->name, status);
950 }
951
952 while ((status = inw(ioaddr + EL3_STATUS)) &
953 (IntLatch | RxComplete | StatsFull)) {
954
955 if (status & RxComplete)
956 el3_rx(dev);
957
958 if (status & TxAvailable) {
959 if (el3_debug > 5)
960 printk(" TX room bit was handled.\n");
961
962 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
963 netif_wake_queue (dev);
964 }
965 if (status & (AdapterFailure | RxEarly | StatsFull | TxComplete)) {
966
967 if (status & StatsFull)
968 update_stats(dev);
969 if (status & RxEarly) {
970 el3_rx(dev);
971 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
972 }
973 if (status & TxComplete) {
974 struct el3_private *lp = (struct el3_private *)dev->priv;
975 short tx_status;
976 int i = 4;
977
978 while (--i>0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
979 if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
980 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
981 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
982 outb(0x00, ioaddr + TX_STATUS);
983 }
984 }
985 if (status & AdapterFailure) {
986
987 outw(RxReset, ioaddr + EL3_CMD);
988
989 outw(SetRxFilter | RxStation | RxBroadcast
990 | (dev->flags & IFF_ALLMULTI ? RxMulticast : 0)
991 | (dev->flags & IFF_PROMISC ? RxProm : 0),
992 ioaddr + EL3_CMD);
993 outw(RxEnable, ioaddr + EL3_CMD);
994 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
995 }
996 }
997
998 if (--i < 0) {
999 printk("%s: Infinite loop in interrupt, status %4.4x.\n",
1000 dev->name, status);
1001
1002 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
1003 break;
1004 }
1005
1006 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
1007 }
1008
1009 if (el3_debug > 4) {
1010 printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
1011 inw(ioaddr + EL3_STATUS));
1012 }
1013 spin_unlock(&lp->lock);
1014 return IRQ_HANDLED;
1015}
1016
1017
1018static struct net_device_stats *
1019el3_get_stats(struct net_device *dev)
1020{
1021 struct el3_private *lp = (struct el3_private *)dev->priv;
1022 unsigned long flags;
1023
1024
1025
1026
1027
1028
1029 spin_lock_irqsave(&lp->lock, flags);
1030 update_stats(dev);
1031 spin_unlock_irqrestore(&lp->lock, flags);
1032 return &lp->stats;
1033}
1034
1035
1036
1037
1038
1039
1040static void update_stats(struct net_device *dev)
1041{
1042 struct el3_private *lp = (struct el3_private *)dev->priv;
1043 int ioaddr = dev->base_addr;
1044
1045 if (el3_debug > 5)
1046 printk(" Updating the statistics.\n");
1047
1048 outw(StatsDisable, ioaddr + EL3_CMD);
1049
1050 EL3WINDOW(6);
1051 lp->stats.tx_carrier_errors += inb(ioaddr + 0);
1052 lp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
1053 inb(ioaddr + 2);
1054 lp->stats.collisions += inb(ioaddr + 3);
1055 lp->stats.tx_window_errors += inb(ioaddr + 4);
1056 lp->stats.rx_fifo_errors += inb(ioaddr + 5);
1057 lp->stats.tx_packets += inb(ioaddr + 6);
1058 inb(ioaddr + 7);
1059 inb(ioaddr + 8);
1060 inw(ioaddr + 10);
1061 inw(ioaddr + 12);
1062
1063
1064 EL3WINDOW(1);
1065 outw(StatsEnable, ioaddr + EL3_CMD);
1066 return;
1067}
1068
1069static int
1070el3_rx(struct net_device *dev)
1071{
1072 struct el3_private *lp = (struct el3_private *)dev->priv;
1073 int ioaddr = dev->base_addr;
1074 short rx_status;
1075
1076 if (el3_debug > 5)
1077 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
1078 inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
1079 while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
1080 if (rx_status & 0x4000) {
1081 short error = rx_status & 0x3800;
1082
1083 outw(RxDiscard, ioaddr + EL3_CMD);
1084 lp->stats.rx_errors++;
1085 switch (error) {
1086 case 0x0000: lp->stats.rx_over_errors++; break;
1087 case 0x0800: lp->stats.rx_length_errors++; break;
1088 case 0x1000: lp->stats.rx_frame_errors++; break;
1089 case 0x1800: lp->stats.rx_length_errors++; break;
1090 case 0x2000: lp->stats.rx_frame_errors++; break;
1091 case 0x2800: lp->stats.rx_crc_errors++; break;
1092 }
1093 } else {
1094 short pkt_len = rx_status & 0x7ff;
1095 struct sk_buff *skb;
1096
1097 skb = dev_alloc_skb(pkt_len+5);
1098 lp->stats.rx_bytes += pkt_len;
1099 if (el3_debug > 4)
1100 printk("Receiving packet size %d status %4.4x.\n",
1101 pkt_len, rx_status);
1102 if (skb != NULL) {
1103 skb->dev = dev;
1104 skb_reserve(skb, 2);
1105
1106
1107#ifdef __powerpc__
1108 insl_ns(ioaddr+RX_FIFO, skb_put(skb,pkt_len),
1109 (pkt_len + 3) >> 2);
1110#else
1111 insl(ioaddr + RX_FIFO, skb_put(skb,pkt_len),
1112 (pkt_len + 3) >> 2);
1113#endif
1114
1115 outw(RxDiscard, ioaddr + EL3_CMD);
1116 skb->protocol = eth_type_trans(skb,dev);
1117 netif_rx(skb);
1118 dev->last_rx = jiffies;
1119 lp->stats.rx_packets++;
1120 continue;
1121 }
1122 outw(RxDiscard, ioaddr + EL3_CMD);
1123 lp->stats.rx_dropped++;
1124 if (el3_debug)
1125 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
1126 dev->name, pkt_len);
1127 }
1128 inw(ioaddr + EL3_STATUS);
1129 while (inw(ioaddr + EL3_STATUS) & 0x1000)
1130 printk(KERN_DEBUG " Waiting for 3c509 to discard packet, status %x.\n",
1131 inw(ioaddr + EL3_STATUS) );
1132 }
1133
1134 return 0;
1135}
1136
1137
1138
1139
1140static void
1141set_multicast_list(struct net_device *dev)
1142{
1143 unsigned long flags;
1144 struct el3_private *lp = (struct el3_private *)dev->priv;
1145 int ioaddr = dev->base_addr;
1146
1147 if (el3_debug > 1) {
1148 static int old;
1149 if (old != dev->mc_count) {
1150 old = dev->mc_count;
1151 printk("%s: Setting Rx mode to %d addresses.\n", dev->name, dev->mc_count);
1152 }
1153 }
1154 spin_lock_irqsave(&lp->lock, flags);
1155 if (dev->flags&IFF_PROMISC) {
1156 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
1157 ioaddr + EL3_CMD);
1158 }
1159 else if (dev->mc_count || (dev->flags&IFF_ALLMULTI)) {
1160 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast, ioaddr + EL3_CMD);
1161 }
1162 else
1163 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
1164 spin_unlock_irqrestore(&lp->lock, flags);
1165}
1166
1167static int
1168el3_close(struct net_device *dev)
1169{
1170 int ioaddr = dev->base_addr;
1171 struct el3_private *lp = (struct el3_private *)dev->priv;
1172
1173 if (el3_debug > 2)
1174 printk("%s: Shutting down ethercard.\n", dev->name);
1175
1176 el3_down(dev);
1177
1178 free_irq(dev->irq, dev);
1179
1180 EL3WINDOW(0);
1181 if (lp->type != EL3_EISA) {
1182
1183
1184
1185 outw(0x0f00, ioaddr + WN0_IRQ);
1186 }
1187
1188 return 0;
1189}
1190
1191static int
1192el3_link_ok(struct net_device *dev)
1193{
1194 int ioaddr = dev->base_addr;
1195 u16 tmp;
1196
1197 EL3WINDOW(4);
1198 tmp = inw(ioaddr + WN4_MEDIA);
1199 EL3WINDOW(1);
1200 return tmp & (1<<11);
1201}
1202
1203static int
1204el3_netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
1205{
1206 u16 tmp;
1207 int ioaddr = dev->base_addr;
1208
1209 EL3WINDOW(0);
1210
1211 tmp = inw(ioaddr + WN0_ADDR_CONF);
1212 ecmd->transceiver = XCVR_INTERNAL;
1213 switch (tmp >> 14) {
1214 case 0:
1215 ecmd->port = PORT_TP;
1216 break;
1217 case 1:
1218 ecmd->port = PORT_AUI;
1219 ecmd->transceiver = XCVR_EXTERNAL;
1220 break;
1221 case 3:
1222 ecmd->port = PORT_BNC;
1223 default:
1224 break;
1225 }
1226
1227 ecmd->duplex = DUPLEX_HALF;
1228 ecmd->supported = 0;
1229 tmp = inw(ioaddr + WN0_CONF_CTRL);
1230 if (tmp & (1<<13))
1231 ecmd->supported |= SUPPORTED_AUI;
1232 if (tmp & (1<<12))
1233 ecmd->supported |= SUPPORTED_BNC;
1234 if (tmp & (1<<9)) {
1235 ecmd->supported |= SUPPORTED_TP | SUPPORTED_10baseT_Half |
1236 SUPPORTED_10baseT_Full;
1237 EL3WINDOW(4);
1238 tmp = inw(ioaddr + WN4_NETDIAG);
1239 if (tmp & FD_ENABLE)
1240 ecmd->duplex = DUPLEX_FULL;
1241 }
1242
1243 ecmd->speed = SPEED_10;
1244 EL3WINDOW(1);
1245 return 0;
1246}
1247
1248static int
1249el3_netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
1250{
1251 u16 tmp;
1252 int ioaddr = dev->base_addr;
1253
1254 if (ecmd->speed != SPEED_10)
1255 return -EINVAL;
1256 if ((ecmd->duplex != DUPLEX_HALF) && (ecmd->duplex != DUPLEX_FULL))
1257 return -EINVAL;
1258 if ((ecmd->transceiver != XCVR_INTERNAL) && (ecmd->transceiver != XCVR_EXTERNAL))
1259 return -EINVAL;
1260
1261
1262 EL3WINDOW(0);
1263 tmp = inw(ioaddr + WN0_ADDR_CONF);
1264 switch (ecmd->port) {
1265 case PORT_TP:
1266 tmp &= ~(3<<14);
1267 dev->if_port = 0;
1268 break;
1269 case PORT_AUI:
1270 tmp |= (1<<14);
1271 dev->if_port = 1;
1272 break;
1273 case PORT_BNC:
1274 tmp |= (3<<14);
1275 dev->if_port = 3;
1276 break;
1277 default:
1278 return -EINVAL;
1279 }
1280
1281 outw(tmp, ioaddr + WN0_ADDR_CONF);
1282 if (dev->if_port == 3) {
1283
1284 tmp = inw(ioaddr + WN0_ADDR_CONF);
1285 if (tmp & (3 << 14)) {
1286 outw(StartCoax, ioaddr + EL3_CMD);
1287 udelay(800);
1288 } else
1289 return -EIO;
1290 }
1291
1292 EL3WINDOW(4);
1293 tmp = inw(ioaddr + WN4_NETDIAG);
1294 if (ecmd->duplex == DUPLEX_FULL)
1295 tmp |= FD_ENABLE;
1296 else
1297 tmp &= ~FD_ENABLE;
1298 outw(tmp, ioaddr + WN4_NETDIAG);
1299 EL3WINDOW(1);
1300
1301 return 0;
1302}
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312static int
1313netdev_ethtool_ioctl (struct net_device *dev, void *useraddr)
1314{
1315 u32 ethcmd;
1316 struct el3_private *lp = dev->priv;
1317
1318
1319
1320
1321 if (get_user(ethcmd, (u32 *)useraddr))
1322 return -EFAULT;
1323
1324 switch (ethcmd) {
1325
1326 case ETHTOOL_GDRVINFO: {
1327 struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
1328 strcpy (info.driver, DRV_NAME);
1329 strcpy (info.version, DRV_VERSION);
1330 if (copy_to_user (useraddr, &info, sizeof (info)))
1331 return -EFAULT;
1332 return 0;
1333 }
1334
1335
1336 case ETHTOOL_GSET: {
1337 int ret;
1338 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
1339 spin_lock_irq(&lp->lock);
1340 ret = el3_netdev_get_ecmd(dev, &ecmd);
1341 spin_unlock_irq(&lp->lock);
1342 if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
1343 return -EFAULT;
1344 return ret;
1345 }
1346
1347
1348 case ETHTOOL_SSET: {
1349 int ret;
1350 struct ethtool_cmd ecmd;
1351 if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
1352 return -EFAULT;
1353 spin_lock_irq(&lp->lock);
1354 ret = el3_netdev_set_ecmd(dev, &ecmd);
1355 spin_unlock_irq(&lp->lock);
1356 return ret;
1357 }
1358
1359
1360 case ETHTOOL_GLINK: {
1361 struct ethtool_value edata = { ETHTOOL_GLINK };
1362 spin_lock_irq(&lp->lock);
1363 edata.data = el3_link_ok(dev);
1364 spin_unlock_irq(&lp->lock);
1365 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1366 return -EFAULT;
1367 return 0;
1368 }
1369
1370
1371 case ETHTOOL_GMSGLVL: {
1372 struct ethtool_value edata = {ETHTOOL_GMSGLVL};
1373 edata.data = el3_debug;
1374 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1375 return -EFAULT;
1376 return 0;
1377 }
1378
1379 case ETHTOOL_SMSGLVL: {
1380 struct ethtool_value edata;
1381 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1382 return -EFAULT;
1383 el3_debug = edata.data;
1384 return 0;
1385 }
1386
1387 default:
1388 break;
1389 }
1390
1391 return -EOPNOTSUPP;
1392}
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403static int
1404netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
1405{
1406 int rc = 0;
1407
1408 switch (cmd) {
1409 case SIOCETHTOOL:
1410 rc = netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
1411 break;
1412
1413 default:
1414 rc = -EOPNOTSUPP;
1415 break;
1416 }
1417
1418 return rc;
1419}
1420
1421static void
1422el3_down(struct net_device *dev)
1423{
1424 int ioaddr = dev->base_addr;
1425
1426 netif_stop_queue(dev);
1427
1428
1429 outw(StatsDisable, ioaddr + EL3_CMD);
1430
1431
1432 outw(RxDisable, ioaddr + EL3_CMD);
1433 outw(TxDisable, ioaddr + EL3_CMD);
1434
1435 if (dev->if_port == 3)
1436
1437 outw(StopCoax, ioaddr + EL3_CMD);
1438 else if (dev->if_port == 0) {
1439
1440 EL3WINDOW(4);
1441 outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
1442 }
1443
1444 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
1445
1446 update_stats(dev);
1447}
1448
1449static void
1450el3_up(struct net_device *dev)
1451{
1452 int i, sw_info, net_diag;
1453 int ioaddr = dev->base_addr;
1454
1455
1456 outw(0x0001, ioaddr + 4);
1457
1458
1459#ifdef CONFIG_X86_PC9800
1460 if (dev->irq == 6)
1461 dev->irq = 7;
1462 else if (dev->irq == 13)
1463 dev->irq = 15;
1464#endif
1465 outw((dev->irq << 12) | 0x0f00, ioaddr + WN0_IRQ);
1466
1467
1468 EL3WINDOW(2);
1469
1470 for (i = 0; i < 6; i++)
1471 outb(dev->dev_addr[i], ioaddr + i);
1472
1473 if ((dev->if_port & 0x03) == 3)
1474
1475 outw(StartCoax, ioaddr + EL3_CMD);
1476 else if ((dev->if_port & 0x03) == 0) {
1477
1478
1479 EL3WINDOW(0);
1480 sw_info = (read_eeprom(ioaddr, 0x14) & 0x400f) |
1481 (read_eeprom(ioaddr, 0x0d) & 0xBff0);
1482
1483 EL3WINDOW(4);
1484 net_diag = inw(ioaddr + WN4_NETDIAG);
1485 net_diag = (net_diag | FD_ENABLE);
1486 printk("%s: ", dev->name);
1487 switch (dev->if_port & 0x0c) {
1488 case 12:
1489
1490 if (sw_info & 0x000f) {
1491 printk("Forcing 3c5x9b full-duplex mode");
1492 break;
1493 }
1494 case 8:
1495
1496 if ((sw_info & 0x000f) && (sw_info & 0x8000)) {
1497 printk("Setting 3c5x9b full-duplex mode (from EEPROM configuration bit)");
1498 break;
1499 }
1500 default:
1501
1502 printk("Setting 3c5x9/3c5x9B half-duplex mode");
1503 net_diag = (net_diag & ~FD_ENABLE);
1504 }
1505
1506 outw(net_diag, ioaddr + WN4_NETDIAG);
1507 printk(" if_port: %d, sw_info: %4.4x\n", dev->if_port, sw_info);
1508 if (el3_debug > 3)
1509 printk("%s: 3c5x9 net diag word is now: %4.4x.\n", dev->name, net_diag);
1510
1511 outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);
1512 }
1513
1514
1515 outw(StatsDisable, ioaddr + EL3_CMD);
1516 EL3WINDOW(6);
1517 for (i = 0; i < 9; i++)
1518 inb(ioaddr + i);
1519 inw(ioaddr + 10);
1520 inw(ioaddr + 12);
1521
1522
1523 EL3WINDOW(1);
1524
1525
1526 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
1527 outw(StatsEnable, ioaddr + EL3_CMD);
1528
1529 outw(RxEnable, ioaddr + EL3_CMD);
1530 outw(TxEnable, ioaddr + EL3_CMD);
1531
1532 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
1533
1534 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
1535 ioaddr + EL3_CMD);
1536 outw(SetIntrEnb | IntLatch|TxAvailable|TxComplete|RxComplete|StatsFull,
1537 ioaddr + EL3_CMD);
1538
1539 netif_start_queue(dev);
1540}
1541
1542
1543#ifdef CONFIG_PM
1544
1545static int
1546el3_suspend(struct pm_dev *pdev)
1547{
1548 unsigned long flags;
1549 struct net_device *dev;
1550 struct el3_private *lp;
1551 int ioaddr;
1552
1553 if (!pdev && !pdev->data)
1554 return -EINVAL;
1555
1556 dev = (struct net_device *)pdev->data;
1557 lp = (struct el3_private *)dev->priv;
1558 ioaddr = dev->base_addr;
1559
1560 spin_lock_irqsave(&lp->lock, flags);
1561
1562 if (netif_running(dev))
1563 netif_device_detach(dev);
1564
1565 el3_down(dev);
1566 outw(PowerDown, ioaddr + EL3_CMD);
1567
1568 spin_unlock_irqrestore(&lp->lock, flags);
1569 return 0;
1570}
1571
1572static int
1573el3_resume(struct pm_dev *pdev)
1574{
1575 unsigned long flags;
1576 struct net_device *dev;
1577 struct el3_private *lp;
1578 int ioaddr;
1579
1580 if (!pdev && !pdev->data)
1581 return -EINVAL;
1582
1583 dev = (struct net_device *)pdev->data;
1584 lp = (struct el3_private *)dev->priv;
1585 ioaddr = dev->base_addr;
1586
1587 spin_lock_irqsave(&lp->lock, flags);
1588
1589 outw(PowerUp, ioaddr + EL3_CMD);
1590 el3_up(dev);
1591
1592 if (netif_running(dev))
1593 netif_device_attach(dev);
1594
1595 spin_unlock_irqrestore(&lp->lock, flags);
1596 return 0;
1597}
1598
1599static int
1600el3_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data)
1601{
1602 switch (rqst) {
1603 case PM_SUSPEND:
1604 return el3_suspend(pdev);
1605
1606 case PM_RESUME:
1607 return el3_resume(pdev);
1608 }
1609 return 0;
1610}
1611
1612#endif
1613
1614
1615static int debug = -1;
1616static int irq[] = {-1, -1, -1, -1, -1, -1, -1, -1};
1617static int xcvr[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
1618
1619MODULE_PARM(debug,"i");
1620MODULE_PARM(irq,"1-8i");
1621MODULE_PARM(xcvr,"1-12i");
1622MODULE_PARM(max_interrupt_work, "i");
1623MODULE_PARM_DESC(debug, "debug level (0-6)");
1624MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)");
1625MODULE_PARM_DESC(xcvr,"transceiver(s) (0=internal, 1=external)");
1626MODULE_PARM_DESC(max_interrupt_work, "maximum events handled per interrupt");
1627#if defined(__ISAPNP__) && !defined(CONFIG_X86_PC9800)
1628MODULE_PARM(nopnp, "i");
1629MODULE_PARM_DESC(nopnp, "disable ISA PnP support (0-1)");
1630MODULE_DEVICE_TABLE(isapnp, el3_isapnp_adapters);
1631#endif
1632MODULE_DESCRIPTION("3Com Etherlink III (3c509, 3c509B) ISA/PnP ethernet driver");
1633MODULE_LICENSE("GPL");
1634
1635static int __init el3_init_module(void)
1636{
1637 el3_cards = 0;
1638
1639 if (debug >= 0)
1640 el3_debug = debug;
1641
1642 el3_root_dev = NULL;
1643 while (el3_probe(el3_cards) == 0) {
1644 if (irq[el3_cards] > 1)
1645 el3_root_dev->irq = irq[el3_cards];
1646 if (xcvr[el3_cards] >= 0)
1647 el3_root_dev->if_port = xcvr[el3_cards];
1648 el3_cards++;
1649 }
1650
1651#ifdef CONFIG_EISA
1652 if (eisa_driver_register (&el3_eisa_driver) < 0) {
1653 eisa_driver_unregister (&el3_eisa_driver);
1654 }
1655#endif
1656#ifdef CONFIG_MCA
1657 mca_register_driver(&el3_mca_driver);
1658#endif
1659 return el3_cards ? 0 : -ENODEV;
1660}
1661
1662static void __exit el3_cleanup_module(void)
1663{
1664 struct net_device *next_dev;
1665
1666 while (el3_root_dev) {
1667 struct el3_private *lp = (struct el3_private *)el3_root_dev->priv;
1668
1669 next_dev = lp->next_dev;
1670 el3_common_remove (el3_root_dev);
1671 el3_root_dev = next_dev;
1672 }
1673
1674#ifdef CONFIG_EISA
1675 eisa_driver_unregister (&el3_eisa_driver);
1676#endif
1677#ifdef CONFIG_MCA
1678 mca_unregister_driver(&el3_mca_driver);
1679#endif
1680}
1681
1682module_init (el3_init_module);
1683module_exit (el3_cleanup_module);
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693