1 /* 3c509.c: A 3c509 EtherLink3 ethernet driver for linux. */
3 Written 1993-1998 by Donald Becker.
5 Copyright 1994-1998 by Donald Becker.
6 Copyright 1993 United States Government as represented by the
7 Director, National Security Agency. This software may be used and
8 distributed according to the terms of the GNU Public License,
9 incorporated herein by reference.
11 This driver is for the 3Com EtherLinkIII series.
13 The author may be reached as becker@cesdis.gsfc.nasa.gov or
14 C/O Center of Excellence in Space Data and Information Sciences
15 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
18 Because of the way 3c509 ISA detection works it's difficult to predict
19 a priori which of several ISA-mode cards will be detected first.
21 This driver does not use predictive interrupt mode, resulting in higher
22 packet latency but lower overhead. If interrupts are disabled for an
23 unusually long time it could also result in missed packets, but in
24 practice this rarely happens.
28 Alan Cox: Removed the 'Unexpected interrupt' bug.
29 Michael Meskes: Upgraded to Donald Becker's version 1.07.
30 Alan Cox: Increased the eeprom delay. Regardless of
31 what the docs say some people definitely
32 get problems with lower (but in card spec)
34 v1.10 4/21/97 Fixed module code so that multiple cards may be detected,
36 Andrea Arcangeli: Upgraded to Donald Becker's version 1.12.
37 Rick Payne: Fixed SMP race condition
38 v1.13 9/8/97 Made 'max_interrupt_work' an insmod-settable variable -djb
39 v1.14 10/15/97 Avoided waiting..discard message for fast machines -djb
40 v1.15 1/31/98 Faster recovery for Tx errors. -djb
41 v1.16 2/3/98 Different ID port handling to avoid sound cards. -djb
44 static char *version = "3c509.c:1.16 (2.2) 2/3/98 becker@cesdis.gsfc.nasa.gov.\n";
45 /* A few values that may be tweaked. */
47 /* Time in jiffies before concluding the transmitter is hung. */
48 #define TX_TIMEOUT (400*HZ/1000)
49 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
50 static int max_interrupt_work = 10;
52 #include <linux/config.h>
53 #include <linux/module.h>
55 #include <linux/mca.h>
56 #include <linux/isapnp.h>
57 #include <linux/sched.h>
58 #include <linux/string.h>
59 #include <linux/interrupt.h>
60 #include <linux/errno.h>
62 #include <linux/malloc.h>
63 #include <linux/ioport.h>
64 #include <linux/netdevice.h>
65 #include <linux/etherdevice.h>
66 #include <linux/skbuff.h>
67 #include <linux/delay.h> /* for udelay() */
68 #include <linux/spinlock.h>
70 #include <asm/bitops.h>
75 int el3_debug = EL3_DEBUG;
80 /* To minimize the size of the driver source I only define operating
81 constants if they are used several times. You'll need the manual
82 anyway if you want to understand driver details. */
83 /* Offsets from base I/O address. */
86 #define EL3_STATUS 0x0e
87 #define EEPROM_READ 0x80
89 #define EL3_IO_EXTENT 16
91 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
94 /* The top five bits written to EL3_CMD are a command, the lower
95 11 bits are the parameter, if applicable. */
97 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
98 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,
99 TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
100 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
101 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
102 SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11,
103 StatsDisable = 22<<11, StopCoax = 23<<11,};
106 IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
107 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
108 IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000, };
110 /* The SetRxFilter command accepts the following classes: */
112 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
114 /* Register window 1 offsets, the window used in normal operation. */
117 #define RX_STATUS 0x08
118 #define TX_STATUS 0x0B
119 #define TX_FREE 0x0C /* Remaining free bytes in Tx buffer. */
121 #define WN0_IRQ 0x08 /* Window 0: Set IRQ line in bits 12-15. */
122 #define WN4_MEDIA 0x0A /* Window 4: Various transcvr/media bits. */
123 #define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
126 * Must be a power of two (we use a binary and in the
129 #define SKB_QUEUE_SIZE 64
132 struct net_device_stats stats;
133 struct net_device *next_dev;
137 struct sk_buff *queue[SKB_QUEUE_SIZE];
140 static int id_port = 0x110; /* Start with 0x110 to avoid new sound cards.*/
141 static struct net_device *el3_root_dev = NULL;
143 static ushort id_read_eeprom(int index);
144 static ushort read_eeprom(int ioaddr, int index);
145 static int el3_open(struct net_device *dev);
146 static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev);
147 static void el3_interrupt(int irq, void *dev_id, struct pt_regs *regs);
148 static void update_stats(struct net_device *dev);
149 static struct net_device_stats *el3_get_stats(struct net_device *dev);
150 static int el3_rx(struct net_device *dev);
151 static int el3_close(struct net_device *dev);
152 static void set_multicast_list(struct net_device *dev);
153 static void el3_tx_timeout (struct net_device *dev);
156 struct el3_mca_adapters_struct {
161 struct el3_mca_adapters_struct el3_mca_adapters[] = {
162 { "3Com 3c529 EtherLink III (10base2)", 0x627c },
163 { "3Com 3c529 EtherLink III (10baseT)", 0x627d },
164 { "3Com 3c529 EtherLink III (test mode)", 0x62db },
165 { "3Com 3c529 EtherLink III (TP or coax)", 0x62f6 },
166 { "3Com 3c529 EtherLink III (TP)", 0x62f7 },
172 struct el3_isapnp_adapters_struct {
173 unsigned short vendor, function;
176 static struct el3_isapnp_adapters_struct el3_isapnp_adapters[] = {
177 {ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5090), "3Com Etherlink III (TP)"},
178 {ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5091), "3Com Etherlink III"},
179 {ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5094), "3Com Etherlink III (combo)"},
180 {ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5095), "3Com Etherlink III (TPO)"},
181 {ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5098), "3Com Etherlink III (TPC)"},
182 {ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_FUNCTION(0x80f8), "3Com Etherlink III compatible"},
185 static u16 el3_isapnp_phys_addr[8][3];
186 #endif /* CONFIG_ISAPNP */
191 int el3_probe(struct net_device *dev)
193 struct el3_private *lp;
194 short lrs_state = 0xff, i;
195 int ioaddr, irq, if_port;
197 static int current_tag = 0;
200 static int pnp_cards = 0;
201 #endif /* __ISAPNP__ */
203 if (dev) SET_MODULE_OWNER(dev);
205 /* First check all slots of the EISA bus. The next slot address to
206 probe is kept in 'eisa_addr' to support multiple probe() calls. */
208 static int eisa_addr = 0x1000;
209 while (eisa_addr < 0x9000) {
213 /* Check the standard EISA ID register for an encoded '3Com'. */
214 if (inw(ioaddr + 0xC80) != 0x6d50)
217 /* Change the register set to the configuration window 0. */
218 outw(SelectWindow | 0, ioaddr + 0xC80 + EL3_CMD);
220 irq = inw(ioaddr + WN0_IRQ) >> 12;
221 if_port = inw(ioaddr + 6)>>14;
222 for (i = 0; i < 3; i++)
223 phys_addr[i] = htons(read_eeprom(ioaddr, i));
225 /* Restore the "Product ID" to the EEPROM read register. */
226 read_eeprom(ioaddr, 3);
228 /* Was the EISA code an add-on hack? Nahhhhh... */
234 /* Based on Erik Nygren's (nygren@mit.edu) 3c529 patch, heavily
235 * modified by Chris Beauregard (cpbeaure@csclub.uwaterloo.ca)
236 * to support standard MCA probing.
238 * redone for multi-card detection by ZP Gu (zpg@castle.net)
239 * now works as a module
246 for( j = 0; el3_mca_adapters[j].name != NULL; j ++ ) {
248 while( slot != MCA_NOTFOUND ) {
249 slot = mca_find_unused_adapter(
250 el3_mca_adapters[j].id, slot );
251 if( slot == MCA_NOTFOUND ) break;
253 /* if we get this far, an adapter has been
254 * detected and is enabled
257 pos4 = mca_read_stored_pos( slot, 4 );
258 pos5 = mca_read_stored_pos( slot, 5 );
260 ioaddr = ((short)((pos4&0xfc)|0x02)) << 8;
263 /* probing for a card at a particular IO/IRQ */
264 if(dev && ((dev->irq >= 1 && dev->irq != irq) ||
265 (dev->base_addr >= 1 && dev->base_addr != ioaddr))) {
266 slot++; /* probing next slot */
270 printk("3c509: found %s at slot %d\n",
271 el3_mca_adapters[j].name, slot + 1 );
274 mca_set_adapter_name(slot, el3_mca_adapters[j].name);
275 mca_set_adapter_procfn(slot, NULL, NULL);
276 mca_mark_as_used(slot);
278 if_port = pos4 & 0x03;
280 printk("3c529: irq %d ioaddr 0x%x ifport %d\n", irq, ioaddr, if_port);
283 for (i = 0; i < 3; i++) {
284 phys_addr[i] = htons(read_eeprom(ioaddr, i));
292 /* if we get here, we didn't find an MCA adapter */
295 #endif /* CONFIG_MCA */
301 for (i=0; el3_isapnp_adapters[i].vendor != 0; i++) {
302 struct pci_dev *idev = NULL;
304 while ((idev = isapnp_find_dev(NULL,
305 el3_isapnp_adapters[i].vendor,
306 el3_isapnp_adapters[i].function,
309 /* Deactivation is needed if the driver was called
310 with "nopnp=1" before, does not harm if not. */
311 idev->deactivate(idev);
312 idev->activate(idev);
313 if (!idev->resource[0].start || check_region(idev->resource[0].start, EL3_IO_EXTENT))
315 ioaddr = idev->resource[0].start;
316 if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509 PnP"))
318 irq = idev->irq_resource[0].start;
320 printk ("ISAPnP reports %s at i/o 0x%x, irq %d\n",
321 el3_isapnp_adapters[i].name, ioaddr, irq);
323 for (j = 0; j < 3; j++)
324 el3_isapnp_phys_addr[pnp_cards][j] =
326 htons(read_eeprom(ioaddr, j));
327 if_port = read_eeprom(ioaddr, 8) >> 14;
333 #endif /* __ISAPNP__ */
335 /* Select an open I/O location at 0x1*0 to do contention select. */
336 for ( ; id_port < 0x200; id_port += 0x10) {
337 if (check_region(id_port, 1))
341 if (inb(id_port) & 0x01)
344 if (id_port >= 0x200) {
345 /* Rare -- do we really need a warning? */
346 printk(" WARNING: No I/O port available for 3c509 activation.\n");
349 /* Next check for all ISA bus boards by sending the ID sequence to the
350 ID_PORT. We find cards past the first by setting the 'current_tag'
351 on cards as they are found. Cards with their tag set will not
352 respond to subsequent ID sequences. */
356 for(i = 0; i < 255; i++) {
357 outb(lrs_state, id_port);
359 lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
362 /* For the first probe, clear all board's tag registers. */
363 if (current_tag == 0)
365 else /* Otherwise kill off already-found boards. */
368 if (id_read_eeprom(7) != 0x6d50) {
372 /* Read in EEPROM data, which does contention-select.
373 Only the lowest address board will stay "on-line".
374 3Com got the byte order backwards. */
375 for (i = 0; i < 3; i++) {
376 phys_addr[i] = htons(id_read_eeprom(i));
381 /* The ISA PnP 3c509 cards respond to the ID sequence.
382 This check is needed in order not to register them twice. */
383 for (i = 0; i < pnp_cards; i++) {
384 if (phys_addr[0] == el3_isapnp_phys_addr[i][0] &&
385 phys_addr[1] == el3_isapnp_phys_addr[i][1] &&
386 phys_addr[2] == el3_isapnp_phys_addr[i][2])
389 printk("3c509 with address %02x %02x %02x %02x %02x %02x was found by ISAPnP\n",
390 phys_addr[0] & 0xff, phys_addr[0] >> 8,
391 phys_addr[1] & 0xff, phys_addr[1] >> 8,
392 phys_addr[2] & 0xff, phys_addr[2] >> 8);
393 /* Set the adaptor tag so that the next card can be found. */
394 outb(0xd0 + ++current_tag, id_port);
399 #endif /* __ISAPNP__ */
402 unsigned int iobase = id_read_eeprom(8);
403 if_port = iobase >> 14;
404 ioaddr = 0x200 + ((iobase & 0x1f) << 4);
406 irq = id_read_eeprom(9) >> 12;
408 if (dev) { /* Set passed-in IRQ or I/O Addr. */
409 if (dev->irq > 1 && dev->irq < 16)
412 if (dev->base_addr) {
413 if (dev->mem_end == 0x3c509 /* Magic key */
414 && dev->base_addr >= 0x200 && dev->base_addr <= 0x3e0)
415 ioaddr = dev->base_addr & 0x3f0;
416 else if (dev->base_addr != ioaddr)
421 if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509"))
424 /* Set the adaptor tag so that the next card can be found. */
425 outb(0xd0 + ++current_tag, id_port);
427 /* Activate the adaptor at the EEPROM location. */
428 outb((ioaddr >> 4) | 0xe0, id_port);
431 if (inw(ioaddr) != 0x6d50) {
432 release_region(ioaddr, EL3_IO_EXTENT);
436 /* Free the interrupt so that some other card can use it. */
437 outw(0x0f00, ioaddr + WN0_IRQ);
440 dev = init_etherdev(dev, sizeof(struct el3_private));
442 release_region(ioaddr, EL3_IO_EXTENT);
445 SET_MODULE_OWNER(dev);
447 memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));
448 dev->base_addr = ioaddr;
450 dev->if_port = (dev->mem_start & 0x1f) ? dev->mem_start & 3 : if_port;
453 const char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};
454 printk("%s: 3c509 at %#3.3lx, %s port, address ",
455 dev->name, dev->base_addr, if_names[dev->if_port]);
458 /* Read in the station address. */
459 for (i = 0; i < 6; i++)
460 printk(" %2.2x", dev->dev_addr[i]);
461 printk(", IRQ %d.\n", dev->irq);
463 /* Make up a EL3-specific-data structure. */
464 if (dev->priv == NULL)
465 dev->priv = kmalloc(sizeof(struct el3_private), GFP_KERNEL);
466 if (dev->priv == NULL)
468 memset(dev->priv, 0, sizeof(struct el3_private));
471 lp->mca_slot = mca_slot;
472 lp->next_dev = el3_root_dev;
473 spin_lock_init(&lp->lock);
479 /* The EL3-specific entries in the device structure. */
480 dev->open = &el3_open;
481 dev->hard_start_xmit = &el3_start_xmit;
482 dev->stop = &el3_close;
483 dev->get_stats = &el3_get_stats;
484 dev->set_multicast_list = &set_multicast_list;
485 dev->tx_timeout = el3_tx_timeout;
486 dev->watchdog_timeo = TX_TIMEOUT;
488 /* Fill in the generic fields of the device structure. */
493 /* Read a word from the EEPROM using the regular EEPROM access register.
494 Assume that we are in register window zero.
496 static ushort read_eeprom(int ioaddr, int index)
498 outw(EEPROM_READ + index, ioaddr + 10);
499 /* Pause for at least 162 us. for the read to take place. */
501 return inw(ioaddr + 12);
504 /* Read a word from the EEPROM when in the ISA ID probe state. */
505 static ushort id_read_eeprom(int index)
509 /* Issue read command, and pause for at least 162 us. for it to complete.
510 Assume extra-fast 16Mhz bus. */
511 outb(EEPROM_READ + index, id_port);
513 /* Pause for at least 162 us. for the read to take place. */
516 for (bit = 15; bit >= 0; bit--)
517 word = (word << 1) + (inb(id_port) & 0x01);
520 printk(" 3c509 EEPROM word %d %#4.4x.\n", index, word);
527 el3_open(struct net_device *dev)
529 int ioaddr = dev->base_addr;
532 outw(TxReset, ioaddr + EL3_CMD);
533 outw(RxReset, ioaddr + EL3_CMD);
534 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
536 i = request_irq(dev->irq, &el3_interrupt, 0, dev->name, dev);
541 printk("%s: Opening, IRQ %d status@%x %4.4x.\n", dev->name,
542 dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));
544 /* Activate board: this is probably unnecessary. */
545 outw(0x0001, ioaddr + 4);
547 /* Set the IRQ line. */
548 outw((dev->irq << 12) | 0x0f00, ioaddr + WN0_IRQ);
550 /* Set the station address in window 2 each time opened. */
553 for (i = 0; i < 6; i++)
554 outb(dev->dev_addr[i], ioaddr + i);
556 if (dev->if_port == 3)
557 /* Start the thinnet transceiver. We should really wait 50ms...*/
558 outw(StartCoax, ioaddr + EL3_CMD);
559 else if (dev->if_port == 0) {
560 /* 10baseT interface, enabled link beat and jabber check. */
562 outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);
565 /* Switch to the stats window, and clear all stats by reading. */
566 outw(StatsDisable, ioaddr + EL3_CMD);
568 for (i = 0; i < 9; i++)
573 /* Switch to register set 1 for normal use. */
576 /* Accept b-case and phys addr only. */
577 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
578 outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
580 netif_start_queue(dev);
582 outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
583 outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
584 /* Allow status bits to be seen. */
585 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
586 /* Ack all pending events, and set active indicator mask. */
587 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
589 outw(SetIntrEnb | IntLatch|TxAvailable|TxComplete|RxComplete|StatsFull,
593 printk("%s: Opened 3c509 IRQ %d status %4.4x.\n",
594 dev->name, dev->irq, inw(ioaddr + EL3_STATUS));
600 el3_tx_timeout (struct net_device *dev)
602 struct el3_private *lp = (struct el3_private *)dev->priv;
603 int ioaddr = dev->base_addr;
605 /* Transmitter timeout, serious problems. */
606 printk("%s: transmit timed out, Tx_status %2.2x status %4.4x "
607 "Tx FIFO room %d.\n",
608 dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS),
609 inw(ioaddr + TX_FREE));
610 lp->stats.tx_errors++;
611 dev->trans_start = jiffies;
612 /* Issue TX_RESET and TX_START commands. */
613 outw(TxReset, ioaddr + EL3_CMD);
614 outw(TxEnable, ioaddr + EL3_CMD);
615 netif_wake_queue(dev);
620 el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
622 struct el3_private *lp = (struct el3_private *)dev->priv;
623 int ioaddr = dev->base_addr;
626 netif_stop_queue (dev);
628 lp->stats.tx_bytes += skb->len;
631 printk("%s: el3_start_xmit(length = %u) called, status %4.4x.\n",
632 dev->name, skb->len, inw(ioaddr + EL3_STATUS));
635 #ifndef final_version
636 { /* Error-checking code, delete someday. */
637 ushort status = inw(ioaddr + EL3_STATUS);
638 if (status & 0x0001 /* IRQ line active, missed one. */
639 && inw(ioaddr + EL3_STATUS) & 1) { /* Make sure. */
640 printk("%s: Missed interrupt, status then %04x now %04x"
641 " Tx %2.2x Rx %4.4x.\n", dev->name, status,
642 inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS),
643 inw(ioaddr + RX_STATUS));
644 /* Fake interrupt trigger by masking, acknowledge interrupts. */
645 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
646 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
648 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
654 * We lock the driver against other processors. Note
655 * we don't need to lock versus the IRQ as we suspended
656 * that. This means that we lose the ability to take
657 * an RX during a TX upload. That sucks a bit with SMP
658 * on an original 3c509 (2K buffer)
660 * Using disable_irq stops us crapping on other
661 * time sensitive devices.
664 spin_lock_irqsave(&lp->lock, flags);
666 /* Put out the doubleword header... */
667 outw(skb->len, ioaddr + TX_FIFO);
668 outw(0x00, ioaddr + TX_FIFO);
669 /* ... and the packet rounded to a doubleword. */
671 outsl_unswapped(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
673 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
676 dev->trans_start = jiffies;
677 if (inw(ioaddr + TX_FREE) > 1536)
678 netif_start_queue(dev);
680 /* Interrupt us when the FIFO has room for max-sized packet. */
681 outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
683 spin_unlock_irqrestore(&lp->lock, flags);
687 /* Clear the Tx status stack. */
692 while (--i > 0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
693 if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
694 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
695 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
696 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
702 /* The EL3 interrupt handler. */
704 el3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
706 struct net_device *dev = (struct net_device *)dev_id;
707 struct el3_private *lp;
709 int i = max_interrupt_work;
712 printk ("el3_interrupt(): irq %d for unknown device.\n", irq);
716 lp = (struct el3_private *)dev->priv;
717 spin_lock(&lp->lock);
719 ioaddr = dev->base_addr;
722 status = inw(ioaddr + EL3_STATUS);
723 printk("%s: interrupt, status %4.4x.\n", dev->name, status);
726 while ((status = inw(ioaddr + EL3_STATUS)) &
727 (IntLatch | RxComplete | StatsFull)) {
729 if (status & RxComplete)
732 if (status & TxAvailable) {
734 printk(" TX room bit was handled.\n");
735 /* There's room in the FIFO for a full-sized packet. */
736 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
737 netif_wake_queue (dev);
739 if (status & (AdapterFailure | RxEarly | StatsFull | TxComplete)) {
740 /* Handle all uncommon interrupts. */
741 if (status & StatsFull) /* Empty statistics. */
743 if (status & RxEarly) { /* Rx early is unused. */
745 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
747 if (status & TxComplete) { /* Really Tx error. */
748 struct el3_private *lp = (struct el3_private *)dev->priv;
752 while (--i>0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
753 if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
754 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
755 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
756 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
759 if (status & AdapterFailure) {
760 /* Adapter failure requires Rx reset and reinit. */
761 outw(RxReset, ioaddr + EL3_CMD);
762 /* Set the Rx filter to the current state. */
763 outw(SetRxFilter | RxStation | RxBroadcast
764 | (dev->flags & IFF_ALLMULTI ? RxMulticast : 0)
765 | (dev->flags & IFF_PROMISC ? RxProm : 0),
767 outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
768 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
773 printk("%s: Infinite loop in interrupt, status %4.4x.\n",
775 /* Clear all interrupts. */
776 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
779 /* Acknowledge the IRQ. */
780 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); /* Ack IRQ */
784 printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
785 inw(ioaddr + EL3_STATUS));
787 spin_unlock(&lp->lock);
792 static struct net_device_stats *
793 el3_get_stats(struct net_device *dev)
795 struct el3_private *lp = (struct el3_private *)dev->priv;
799 * This is fast enough not to bother with disable IRQ
803 spin_lock_irqsave(&lp->lock, flags);
805 spin_unlock_irqrestore(&lp->lock, flags);
809 /* Update statistics. We change to register window 6, so this should be run
810 single-threaded if the device is active. This is expected to be a rare
811 operation, and it's simpler for the rest of the driver to assume that
812 window 1 is always valid rather than use a special window-state variable.
814 static void update_stats(struct net_device *dev)
816 struct el3_private *lp = (struct el3_private *)dev->priv;
817 int ioaddr = dev->base_addr;
820 printk(" Updating the statistics.\n");
821 /* Turn off statistics updates while reading. */
822 outw(StatsDisable, ioaddr + EL3_CMD);
823 /* Switch to the stats window, and read everything. */
825 lp->stats.tx_carrier_errors += inb(ioaddr + 0);
826 lp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
827 /* Multiple collisions. */ inb(ioaddr + 2);
828 lp->stats.collisions += inb(ioaddr + 3);
829 lp->stats.tx_window_errors += inb(ioaddr + 4);
830 lp->stats.rx_fifo_errors += inb(ioaddr + 5);
831 lp->stats.tx_packets += inb(ioaddr + 6);
832 /* Rx packets */ inb(ioaddr + 7);
833 /* Tx deferrals */ inb(ioaddr + 8);
834 inw(ioaddr + 10); /* Total Rx and Tx octets. */
837 /* Back to window 1, and turn statistics back on. */
839 outw(StatsEnable, ioaddr + EL3_CMD);
844 el3_rx(struct net_device *dev)
846 struct el3_private *lp = (struct el3_private *)dev->priv;
847 int ioaddr = dev->base_addr;
851 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
852 inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
853 while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
854 if (rx_status & 0x4000) { /* Error, update stats. */
855 short error = rx_status & 0x3800;
857 outw(RxDiscard, ioaddr + EL3_CMD);
858 lp->stats.rx_errors++;
860 case 0x0000: lp->stats.rx_over_errors++; break;
861 case 0x0800: lp->stats.rx_length_errors++; break;
862 case 0x1000: lp->stats.rx_frame_errors++; break;
863 case 0x1800: lp->stats.rx_length_errors++; break;
864 case 0x2000: lp->stats.rx_frame_errors++; break;
865 case 0x2800: lp->stats.rx_crc_errors++; break;
868 short pkt_len = rx_status & 0x7ff;
871 skb = dev_alloc_skb(pkt_len+5);
872 lp->stats.rx_bytes += pkt_len;
874 printk("Receiving packet size %d status %4.4x.\n",
878 skb_reserve(skb, 2); /* Align IP on 16 byte */
880 /* 'skb->data' points to the start of sk_buff data area. */
882 insl_unswapped(ioaddr+RX_FIFO, skb_put(skb,pkt_len),
885 insl(ioaddr + RX_FIFO, skb_put(skb,pkt_len),
889 outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
890 skb->protocol = eth_type_trans(skb,dev);
892 lp->stats.rx_packets++;
895 outw(RxDiscard, ioaddr + EL3_CMD);
896 lp->stats.rx_dropped++;
898 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
901 inw(ioaddr + EL3_STATUS); /* Delay. */
902 while (inw(ioaddr + EL3_STATUS) & 0x1000)
903 printk(KERN_DEBUG " Waiting for 3c509 to discard packet, status %x.\n",
904 inw(ioaddr + EL3_STATUS) );
911 * Set or clear the multicast filter for this adaptor.
914 set_multicast_list(struct net_device *dev)
917 struct el3_private *lp = (struct el3_private *)dev->priv;
918 int ioaddr = dev->base_addr;
922 if (old != dev->mc_count) {
924 printk("%s: Setting Rx mode to %d addresses.\n", dev->name, dev->mc_count);
927 spin_lock_irqsave(&lp->lock, flags);
928 if (dev->flags&IFF_PROMISC) {
929 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
932 else if (dev->mc_count || (dev->flags&IFF_ALLMULTI)) {
933 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast, ioaddr + EL3_CMD);
936 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
937 spin_unlock_irqrestore(&lp->lock, flags);
941 el3_close(struct net_device *dev)
943 int ioaddr = dev->base_addr;
946 printk("%s: Shutting down ethercard.\n", dev->name);
948 netif_stop_queue(dev);
950 /* Turn off statistics ASAP. We update lp->stats below. */
951 outw(StatsDisable, ioaddr + EL3_CMD);
953 /* Disable the receiver and transmitter. */
954 outw(RxDisable, ioaddr + EL3_CMD);
955 outw(TxDisable, ioaddr + EL3_CMD);
957 if (dev->if_port == 3)
958 /* Turn off thinnet power. Green! */
959 outw(StopCoax, ioaddr + EL3_CMD);
960 else if (dev->if_port == 0) {
961 /* Disable link beat and jabber, if_port may change ere next open(). */
963 outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
966 free_irq(dev->irq, dev);
967 /* Switching back to window 0 disables the IRQ. */
969 /* But we explicitly zero the IRQ line select anyway. */
970 outw(0x0f00, ioaddr + WN0_IRQ);
977 /* Parameters that may be passed into the module. */
978 static int debug = -1;
979 static int irq[] = {-1, -1, -1, -1, -1, -1, -1, -1};
980 static int xcvr[] = {-1, -1, -1, -1, -1, -1, -1, -1};
982 MODULE_PARM(debug,"i");
983 MODULE_PARM(irq,"1-8i");
984 MODULE_PARM(xcvr,"1-8i");
985 MODULE_PARM(max_interrupt_work, "i");
987 MODULE_PARM(nopnp, "i");
999 while (el3_probe(0) == 0) {
1000 if (irq[el3_cards] > 1)
1001 el3_root_dev->irq = irq[el3_cards];
1002 if (xcvr[el3_cards] >= 0)
1003 el3_root_dev->if_port = xcvr[el3_cards];
1007 return el3_cards ? 0 : -ENODEV;
1011 cleanup_module(void)
1013 struct net_device *next_dev;
1015 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1016 while (el3_root_dev) {
1017 struct el3_private *lp = (struct el3_private *)el3_root_dev->priv;
1019 if(lp->mca_slot!=-1)
1020 mca_mark_as_unused(lp->mca_slot);
1022 next_dev = lp->next_dev;
1023 unregister_netdev(el3_root_dev);
1024 release_region(el3_root_dev->base_addr, EL3_IO_EXTENT);
1025 kfree(el3_root_dev);
1026 el3_root_dev = next_dev;
1033 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c509.c"
1034 * version-control: t
1035 * kept-new-versions: 5