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/sched.h>
57 #include <linux/string.h>
58 #include <linux/interrupt.h>
59 #include <linux/errno.h>
61 #include <linux/malloc.h>
62 #include <linux/ioport.h>
63 #include <linux/netdevice.h>
64 #include <linux/etherdevice.h>
65 #include <linux/skbuff.h>
66 #include <linux/delay.h> /* for udelay() */
67 #include <linux/spinlock.h>
69 #include <asm/bitops.h>
74 int el3_debug
= EL3_DEBUG
;
79 /* To minimize the size of the driver source I only define operating
80 constants if they are used several times. You'll need the manual
81 anyway if you want to understand driver details. */
82 /* Offsets from base I/O address. */
85 #define EL3_STATUS 0x0e
86 #define EEPROM_READ 0x80
88 #define EL3_IO_EXTENT 16
90 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
93 /* The top five bits written to EL3_CMD are a command, the lower
94 11 bits are the parameter, if applicable. */
96 TotalReset
= 0<<11, SelectWindow
= 1<<11, StartCoax
= 2<<11,
97 RxDisable
= 3<<11, RxEnable
= 4<<11, RxReset
= 5<<11, RxDiscard
= 8<<11,
98 TxEnable
= 9<<11, TxDisable
= 10<<11, TxReset
= 11<<11,
99 FakeIntr
= 12<<11, AckIntr
= 13<<11, SetIntrEnb
= 14<<11,
100 SetStatusEnb
= 15<<11, SetRxFilter
= 16<<11, SetRxThreshold
= 17<<11,
101 SetTxThreshold
= 18<<11, SetTxStart
= 19<<11, StatsEnable
= 21<<11,
102 StatsDisable
= 22<<11, StopCoax
= 23<<11,};
105 IntLatch
= 0x0001, AdapterFailure
= 0x0002, TxComplete
= 0x0004,
106 TxAvailable
= 0x0008, RxComplete
= 0x0010, RxEarly
= 0x0020,
107 IntReq
= 0x0040, StatsFull
= 0x0080, CmdBusy
= 0x1000, };
109 /* The SetRxFilter command accepts the following classes: */
111 RxStation
= 1, RxMulticast
= 2, RxBroadcast
= 4, RxProm
= 8 };
113 /* Register window 1 offsets, the window used in normal operation. */
116 #define RX_STATUS 0x08
117 #define TX_STATUS 0x0B
118 #define TX_FREE 0x0C /* Remaining free bytes in Tx buffer. */
120 #define WN0_IRQ 0x08 /* Window 0: Set IRQ line in bits 12-15. */
121 #define WN4_MEDIA 0x0A /* Window 4: Various transcvr/media bits. */
122 #define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
125 * Must be a power of two (we use a binary and in the
128 #define SKB_QUEUE_SIZE 64
131 struct enet_statistics stats
;
132 struct net_device
*next_dev
;
136 struct sk_buff
*queue
[SKB_QUEUE_SIZE
];
139 static int id_port
= 0x110; /* Start with 0x110 to avoid new sound cards.*/
140 static struct net_device
*el3_root_dev
= NULL
;
142 static ushort
id_read_eeprom(int index
);
143 static ushort
read_eeprom(int ioaddr
, int index
);
144 static int el3_open(struct net_device
*dev
);
145 static int el3_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
146 static void el3_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
147 static void update_stats(struct net_device
*dev
);
148 static struct enet_statistics
*el3_get_stats(struct net_device
*dev
);
149 static int el3_rx(struct net_device
*dev
);
150 static int el3_close(struct net_device
*dev
);
151 static void set_multicast_list(struct net_device
*dev
);
154 struct el3_mca_adapters_struct
{
159 struct el3_mca_adapters_struct el3_mca_adapters
[] = {
160 { "3Com 3c529 EtherLink III (10base2)", 0x627c },
161 { "3Com 3c529 EtherLink III (10baseT)", 0x627d },
162 { "3Com 3c529 EtherLink III (test mode)", 0x62db },
163 { "3Com 3c529 EtherLink III (TP or coax)", 0x62f6 },
164 { "3Com 3c529 EtherLink III (TP)", 0x62f7 },
169 int el3_probe(struct net_device
*dev
)
171 short lrs_state
= 0xff, i
;
172 int ioaddr
, irq
, if_port
;
174 static int current_tag
= 0;
177 /* First check all slots of the EISA bus. The next slot address to
178 probe is kept in 'eisa_addr' to support multiple probe() calls. */
180 static int eisa_addr
= 0x1000;
181 while (eisa_addr
< 0x9000) {
185 /* Check the standard EISA ID register for an encoded '3Com'. */
186 if (inw(ioaddr
+ 0xC80) != 0x6d50)
189 /* Change the register set to the configuration window 0. */
190 outw(SelectWindow
| 0, ioaddr
+ 0xC80 + EL3_CMD
);
192 irq
= inw(ioaddr
+ WN0_IRQ
) >> 12;
193 if_port
= inw(ioaddr
+ 6)>>14;
194 for (i
= 0; i
< 3; i
++)
195 phys_addr
[i
] = htons(read_eeprom(ioaddr
, i
));
197 /* Restore the "Product ID" to the EEPROM read register. */
198 read_eeprom(ioaddr
, 3);
200 /* Was the EISA code an add-on hack? Nahhhhh... */
206 /* Based on Erik Nygren's (nygren@mit.edu) 3c529 patch, heavily
207 * modified by Chris Beauregard (cpbeaure@csclub.uwaterloo.ca)
208 * to support standard MCA probing.
210 * redone for multi-card detection by ZP Gu (zpg@castle.net)
211 * now works as a module
218 for( j
= 0; el3_mca_adapters
[j
].name
!= NULL
; j
++ ) {
220 while( slot
!= MCA_NOTFOUND
) {
221 slot
= mca_find_unused_adapter(
222 el3_mca_adapters
[j
].id
, slot
);
223 if( slot
== MCA_NOTFOUND
) break;
225 /* if we get this far, an adapter has been
226 * detected and is enabled
229 pos4
= mca_read_stored_pos( slot
, 4 );
230 pos5
= mca_read_stored_pos( slot
, 5 );
232 ioaddr
= ((short)((pos4
&0xfc)|0x02)) << 8;
235 /* probing for a card at a particular IO/IRQ */
236 if(dev
&& ((dev
->irq
>= 1 && dev
->irq
!= irq
) ||
237 (dev
->base_addr
>= 1 && dev
->base_addr
!= ioaddr
))) {
238 slot
++; /* probing next slot */
242 printk("3c509: found %s at slot %d\n",
243 el3_mca_adapters
[j
].name
, slot
+ 1 );
246 mca_set_adapter_name(slot
, el3_mca_adapters
[j
].name
);
247 mca_set_adapter_procfn(slot
, NULL
, NULL
);
248 mca_mark_as_used(slot
);
250 if_port
= pos4
& 0x03;
252 printk("3c529: irq %d ioaddr 0x%x ifport %d\n", irq
, ioaddr
, if_port
);
254 for (i
= 0; i
< 3; i
++) {
255 phys_addr
[i
] = htons(read_eeprom(ioaddr
, i
));
263 /* if we get here, we didn't find an MCA adapter */
267 /* Reset the ISA PnP mechanism on 3c509b. */
268 outb(0x02, 0x279); /* Select PnP config control register. */
269 outb(0x02, 0xA79); /* Return to WaitForKey state. */
270 /* Select an open I/O location at 0x1*0 to do contention select. */
271 for ( ; id_port
< 0x200; id_port
+= 0x10) {
272 if (check_region(id_port
, 1))
276 if (inb(id_port
) & 0x01)
279 if (id_port
>= 0x200) {
280 /* Rare -- do we really need a warning? */
281 printk(" WARNING: No I/O port available for 3c509 activation.\n");
284 /* Next check for all ISA bus boards by sending the ID sequence to the
285 ID_PORT. We find cards past the first by setting the 'current_tag'
286 on cards as they are found. Cards with their tag set will not
287 respond to subsequent ID sequences. */
291 for(i
= 0; i
< 255; i
++) {
292 outb(lrs_state
, id_port
);
294 lrs_state
= lrs_state
& 0x100 ? lrs_state
^ 0xcf : lrs_state
;
297 /* For the first probe, clear all board's tag registers. */
298 if (current_tag
== 0)
300 else /* Otherwise kill off already-found boards. */
303 if (id_read_eeprom(7) != 0x6d50) {
307 /* Read in EEPROM data, which does contention-select.
308 Only the lowest address board will stay "on-line".
309 3Com got the byte order backwards. */
310 for (i
= 0; i
< 3; i
++) {
311 phys_addr
[i
] = htons(id_read_eeprom(i
));
315 unsigned int iobase
= id_read_eeprom(8);
316 if_port
= iobase
>> 14;
317 ioaddr
= 0x200 + ((iobase
& 0x1f) << 4);
319 irq
= id_read_eeprom(9) >> 12;
321 if (dev
) { /* Set passed-in IRQ or I/O Addr. */
322 if (dev
->irq
> 1 && dev
->irq
< 16)
325 if (dev
->base_addr
) {
326 if (dev
->mem_end
== 0x3c509 /* Magic key */
327 && dev
->base_addr
>= 0x200 && dev
->base_addr
<= 0x3e0)
328 ioaddr
= dev
->base_addr
& 0x3f0;
329 else if (dev
->base_addr
!= ioaddr
)
334 /* Set the adaptor tag so that the next card can be found. */
335 outb(0xd0 + ++current_tag
, id_port
);
337 /* Activate the adaptor at the EEPROM location. */
338 outb((ioaddr
>> 4) | 0xe0, id_port
);
341 if (inw(ioaddr
) != 0x6d50)
344 /* Free the interrupt so that some other card can use it. */
345 outw(0x0f00, ioaddr
+ WN0_IRQ
);
348 dev
= init_etherdev(dev
, sizeof(struct el3_private
));
350 memcpy(dev
->dev_addr
, phys_addr
, sizeof(phys_addr
));
351 dev
->base_addr
= ioaddr
;
353 dev
->if_port
= (dev
->mem_start
& 0x1f) ? dev
->mem_start
& 3 : if_port
;
355 request_region(dev
->base_addr
, EL3_IO_EXTENT
, "3c509");
358 const char *if_names
[] = {"10baseT", "AUI", "undefined", "BNC"};
359 printk("%s: 3c509 at %#3.3lx tag %d, %s port, address ",
360 dev
->name
, dev
->base_addr
, current_tag
, if_names
[dev
->if_port
]);
363 /* Read in the station address. */
364 for (i
= 0; i
< 6; i
++)
365 printk(" %2.2x", dev
->dev_addr
[i
]);
366 printk(", IRQ %d.\n", dev
->irq
);
368 /* Make up a EL3-specific-data structure. */
369 if (dev
->priv
== NULL
)
370 dev
->priv
= kmalloc(sizeof(struct el3_private
), GFP_KERNEL
);
371 if (dev
->priv
== NULL
)
373 memset(dev
->priv
, 0, sizeof(struct el3_private
));
375 ((struct el3_private
*)dev
->priv
)->mca_slot
= mca_slot
;
376 ((struct el3_private
*)dev
->priv
)->next_dev
= el3_root_dev
;
382 /* The EL3-specific entries in the device structure. */
383 dev
->open
= &el3_open
;
384 dev
->hard_start_xmit
= &el3_start_xmit
;
385 dev
->stop
= &el3_close
;
386 dev
->get_stats
= &el3_get_stats
;
387 dev
->set_multicast_list
= &set_multicast_list
;
389 /* Fill in the generic fields of the device structure. */
394 /* Read a word from the EEPROM using the regular EEPROM access register.
395 Assume that we are in register window zero.
397 static ushort
read_eeprom(int ioaddr
, int index
)
399 outw(EEPROM_READ
+ index
, ioaddr
+ 10);
400 /* Pause for at least 162 us. for the read to take place. */
402 return inw(ioaddr
+ 12);
405 /* Read a word from the EEPROM when in the ISA ID probe state. */
406 static ushort
id_read_eeprom(int index
)
410 /* Issue read command, and pause for at least 162 us. for it to complete.
411 Assume extra-fast 16Mhz bus. */
412 outb(EEPROM_READ
+ index
, id_port
);
414 /* Pause for at least 162 us. for the read to take place. */
417 for (bit
= 15; bit
>= 0; bit
--)
418 word
= (word
<< 1) + (inb(id_port
) & 0x01);
421 printk(" 3c509 EEPROM word %d %#4.4x.\n", index
, word
);
428 el3_open(struct net_device
*dev
)
430 int ioaddr
= dev
->base_addr
;
433 outw(TxReset
, ioaddr
+ EL3_CMD
);
434 outw(RxReset
, ioaddr
+ EL3_CMD
);
435 outw(SetStatusEnb
| 0x00, ioaddr
+ EL3_CMD
);
437 /* Set the spinlock before grabbing IRQ! */
438 ((struct el3_private
*)dev
->priv
)->lock
= (spinlock_t
) SPIN_LOCK_UNLOCKED
;
440 if (request_irq(dev
->irq
, &el3_interrupt
, 0, dev
->name
, dev
)) {
446 printk("%s: Opening, IRQ %d status@%x %4.4x.\n", dev
->name
,
447 dev
->irq
, ioaddr
+ EL3_STATUS
, inw(ioaddr
+ EL3_STATUS
));
449 /* Activate board: this is probably unnecessary. */
450 outw(0x0001, ioaddr
+ 4);
452 /* Set the IRQ line. */
453 outw((dev
->irq
<< 12) | 0x0f00, ioaddr
+ WN0_IRQ
);
455 /* Set the station address in window 2 each time opened. */
458 for (i
= 0; i
< 6; i
++)
459 outb(dev
->dev_addr
[i
], ioaddr
+ i
);
461 if (dev
->if_port
== 3)
462 /* Start the thinnet transceiver. We should really wait 50ms...*/
463 outw(StartCoax
, ioaddr
+ EL3_CMD
);
464 else if (dev
->if_port
== 0) {
465 /* 10baseT interface, enabled link beat and jabber check. */
467 outw(inw(ioaddr
+ WN4_MEDIA
) | MEDIA_TP
, ioaddr
+ WN4_MEDIA
);
470 /* Switch to the stats window, and clear all stats by reading. */
471 outw(StatsDisable
, ioaddr
+ EL3_CMD
);
473 for (i
= 0; i
< 9; i
++)
478 /* Switch to register set 1 for normal use. */
481 /* Accept b-case and phys addr only. */
482 outw(SetRxFilter
| RxStation
| RxBroadcast
, ioaddr
+ EL3_CMD
);
483 outw(StatsEnable
, ioaddr
+ EL3_CMD
); /* Turn on statistics. */
489 outw(RxEnable
, ioaddr
+ EL3_CMD
); /* Enable the receiver. */
490 outw(TxEnable
, ioaddr
+ EL3_CMD
); /* Enable transmitter. */
491 /* Allow status bits to be seen. */
492 outw(SetStatusEnb
| 0xff, ioaddr
+ EL3_CMD
);
493 /* Ack all pending events, and set active indicator mask. */
494 outw(AckIntr
| IntLatch
| TxAvailable
| RxEarly
| IntReq
,
496 outw(SetIntrEnb
| IntLatch
|TxAvailable
|TxComplete
|RxComplete
|StatsFull
,
500 printk("%s: Opened 3c509 IRQ %d status %4.4x.\n",
501 dev
->name
, dev
->irq
, inw(ioaddr
+ EL3_STATUS
));
504 return 0; /* Always succeed */
508 el3_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
510 struct el3_private
*lp
= (struct el3_private
*)dev
->priv
;
511 int ioaddr
= dev
->base_addr
;
513 /* Transmitter timeout, serious problems. */
515 int tickssofar
= jiffies
- dev
->trans_start
;
516 if (tickssofar
< TX_TIMEOUT
)
518 printk("%s: transmit timed out, Tx_status %2.2x status %4.4x "
519 "Tx FIFO room %d.\n",
520 dev
->name
, inb(ioaddr
+ TX_STATUS
), inw(ioaddr
+ EL3_STATUS
),
521 inw(ioaddr
+ TX_FREE
));
522 lp
->stats
.tx_errors
++;
523 dev
->trans_start
= jiffies
;
524 /* Issue TX_RESET and TX_START commands. */
525 outw(TxReset
, ioaddr
+ EL3_CMD
);
526 outw(TxEnable
, ioaddr
+ EL3_CMD
);
530 lp
->stats
.tx_bytes
+= skb
->len
;
533 printk("%s: el3_start_xmit(length = %u) called, status %4.4x.\n",
534 dev
->name
, skb
->len
, inw(ioaddr
+ EL3_STATUS
));
537 #ifndef final_version
538 { /* Error-checking code, delete someday. */
539 ushort status
= inw(ioaddr
+ EL3_STATUS
);
540 if (status
& 0x0001 /* IRQ line active, missed one. */
541 && inw(ioaddr
+ EL3_STATUS
) & 1) { /* Make sure. */
542 printk("%s: Missed interrupt, status then %04x now %04x"
543 " Tx %2.2x Rx %4.4x.\n", dev
->name
, status
,
544 inw(ioaddr
+ EL3_STATUS
), inb(ioaddr
+ TX_STATUS
),
545 inw(ioaddr
+ RX_STATUS
));
546 /* Fake interrupt trigger by masking, acknowledge interrupts. */
547 outw(SetStatusEnb
| 0x00, ioaddr
+ EL3_CMD
);
548 outw(AckIntr
| IntLatch
| TxAvailable
| RxEarly
| IntReq
,
550 outw(SetStatusEnb
| 0xff, ioaddr
+ EL3_CMD
);
555 /* Avoid timer-based retransmission conflicts. */
556 if (test_and_set_bit(0, (void*)&dev
->tbusy
) != 0)
557 printk("%s: Transmitter access conflict.\n", dev
->name
);
560 * We lock the driver against other processors. Note
561 * we don't need to lock versus the IRQ as we suspended
562 * that. This means that we lose the ability to take
563 * an RX during a TX upload. That sucks a bit with SMP
564 * on an original 3c509 (2K buffer)
566 * Using disable_irq stops us crapping on other
567 * time sensitive devices.
571 disable_irq_nosync(dev
->irq
);
572 spin_lock(&lp
->lock
);
575 /* Put out the doubleword header... */
576 outw(skb
->len
, ioaddr
+ TX_FIFO
);
577 outw(0x00, ioaddr
+ TX_FIFO
);
578 /* ... and the packet rounded to a doubleword. */
580 outsl_unswapped(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+ 3) >> 2);
582 outsl(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+ 3) >> 2);
585 dev
->trans_start
= jiffies
;
586 if (inw(ioaddr
+ TX_FREE
) > 1536) {
589 /* Interrupt us when the FIFO has room for max-sized packet. */
590 outw(SetTxThreshold
+ 1536, ioaddr
+ EL3_CMD
);
592 spin_unlock(&lp
->lock
);
593 enable_irq(dev
->irq
);
599 /* Clear the Tx status stack. */
604 while (--i
> 0 && (tx_status
= inb(ioaddr
+ TX_STATUS
)) > 0) {
605 if (tx_status
& 0x38) lp
->stats
.tx_aborted_errors
++;
606 if (tx_status
& 0x30) outw(TxReset
, ioaddr
+ EL3_CMD
);
607 if (tx_status
& 0x3C) outw(TxEnable
, ioaddr
+ EL3_CMD
);
608 outb(0x00, ioaddr
+ TX_STATUS
); /* Pop the status stack. */
614 /* The EL3 interrupt handler. */
616 el3_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
618 struct net_device
*dev
= (struct net_device
*)dev_id
;
619 struct el3_private
*lp
;
621 int i
= max_interrupt_work
;
624 printk ("el3_interrupt(): irq %d for unknown device.\n", irq
);
628 lp
= (struct el3_private
*)dev
->priv
;
629 spin_lock(&lp
->lock
);
632 printk("%s: Re-entering the interrupt handler.\n", dev
->name
);
635 ioaddr
= dev
->base_addr
;
638 status
= inw(ioaddr
+ EL3_STATUS
);
639 printk("%s: interrupt, status %4.4x.\n", dev
->name
, status
);
642 while ((status
= inw(ioaddr
+ EL3_STATUS
)) &
643 (IntLatch
| RxComplete
| StatsFull
)) {
645 if (status
& RxComplete
)
648 if (status
& TxAvailable
) {
650 printk(" TX room bit was handled.\n");
651 /* There's room in the FIFO for a full-sized packet. */
652 outw(AckIntr
| TxAvailable
, ioaddr
+ EL3_CMD
);
656 if (status
& (AdapterFailure
| RxEarly
| StatsFull
| TxComplete
)) {
657 /* Handle all uncommon interrupts. */
658 if (status
& StatsFull
) /* Empty statistics. */
660 if (status
& RxEarly
) { /* Rx early is unused. */
662 outw(AckIntr
| RxEarly
, ioaddr
+ EL3_CMD
);
664 if (status
& TxComplete
) { /* Really Tx error. */
665 struct el3_private
*lp
= (struct el3_private
*)dev
->priv
;
669 while (--i
>0 && (tx_status
= inb(ioaddr
+ TX_STATUS
)) > 0) {
670 if (tx_status
& 0x38) lp
->stats
.tx_aborted_errors
++;
671 if (tx_status
& 0x30) outw(TxReset
, ioaddr
+ EL3_CMD
);
672 if (tx_status
& 0x3C) outw(TxEnable
, ioaddr
+ EL3_CMD
);
673 outb(0x00, ioaddr
+ TX_STATUS
); /* Pop the status stack. */
676 if (status
& AdapterFailure
) {
677 /* Adapter failure requires Rx reset and reinit. */
678 outw(RxReset
, ioaddr
+ EL3_CMD
);
679 /* Set the Rx filter to the current state. */
680 outw(SetRxFilter
| RxStation
| RxBroadcast
681 | (dev
->flags
& IFF_ALLMULTI
? RxMulticast
: 0)
682 | (dev
->flags
& IFF_PROMISC
? RxProm
: 0),
684 outw(RxEnable
, ioaddr
+ EL3_CMD
); /* Re-enable the receiver. */
685 outw(AckIntr
| AdapterFailure
, ioaddr
+ EL3_CMD
);
690 printk("%s: Infinite loop in interrupt, status %4.4x.\n",
692 /* Clear all interrupts. */
693 outw(AckIntr
| 0xFF, ioaddr
+ EL3_CMD
);
696 /* Acknowledge the IRQ. */
697 outw(AckIntr
| IntReq
| IntLatch
, ioaddr
+ EL3_CMD
); /* Ack IRQ */
701 printk("%s: exiting interrupt, status %4.4x.\n", dev
->name
,
702 inw(ioaddr
+ EL3_STATUS
));
704 spin_unlock(&lp
->lock
);
710 static struct enet_statistics
*
711 el3_get_stats(struct net_device
*dev
)
713 struct el3_private
*lp
= (struct el3_private
*)dev
->priv
;
717 * This is fast enough not to bother with disable IRQ
721 spin_lock_irqsave(&lp
->lock
, flags
);
723 spin_unlock_irqrestore(&lp
->lock
, flags
);
727 /* Update statistics. We change to register window 6, so this should be run
728 single-threaded if the device is active. This is expected to be a rare
729 operation, and it's simpler for the rest of the driver to assume that
730 window 1 is always valid rather than use a special window-state variable.
732 static void update_stats(struct net_device
*dev
)
734 struct el3_private
*lp
= (struct el3_private
*)dev
->priv
;
735 int ioaddr
= dev
->base_addr
;
738 printk(" Updating the statistics.\n");
739 /* Turn off statistics updates while reading. */
740 outw(StatsDisable
, ioaddr
+ EL3_CMD
);
741 /* Switch to the stats window, and read everything. */
743 lp
->stats
.tx_carrier_errors
+= inb(ioaddr
+ 0);
744 lp
->stats
.tx_heartbeat_errors
+= inb(ioaddr
+ 1);
745 /* Multiple collisions. */ inb(ioaddr
+ 2);
746 lp
->stats
.collisions
+= inb(ioaddr
+ 3);
747 lp
->stats
.tx_window_errors
+= inb(ioaddr
+ 4);
748 lp
->stats
.rx_fifo_errors
+= inb(ioaddr
+ 5);
749 lp
->stats
.tx_packets
+= inb(ioaddr
+ 6);
750 /* Rx packets */ inb(ioaddr
+ 7);
751 /* Tx deferrals */ inb(ioaddr
+ 8);
752 inw(ioaddr
+ 10); /* Total Rx and Tx octets. */
755 /* Back to window 1, and turn statistics back on. */
757 outw(StatsEnable
, ioaddr
+ EL3_CMD
);
762 el3_rx(struct net_device
*dev
)
764 struct el3_private
*lp
= (struct el3_private
*)dev
->priv
;
765 int ioaddr
= dev
->base_addr
;
769 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
770 inw(ioaddr
+EL3_STATUS
), inw(ioaddr
+RX_STATUS
));
771 while ((rx_status
= inw(ioaddr
+ RX_STATUS
)) > 0) {
772 if (rx_status
& 0x4000) { /* Error, update stats. */
773 short error
= rx_status
& 0x3800;
775 outw(RxDiscard
, ioaddr
+ EL3_CMD
);
776 lp
->stats
.rx_errors
++;
778 case 0x0000: lp
->stats
.rx_over_errors
++; break;
779 case 0x0800: lp
->stats
.rx_length_errors
++; break;
780 case 0x1000: lp
->stats
.rx_frame_errors
++; break;
781 case 0x1800: lp
->stats
.rx_length_errors
++; break;
782 case 0x2000: lp
->stats
.rx_frame_errors
++; break;
783 case 0x2800: lp
->stats
.rx_crc_errors
++; break;
786 short pkt_len
= rx_status
& 0x7ff;
789 skb
= dev_alloc_skb(pkt_len
+5);
790 lp
->stats
.rx_bytes
+= pkt_len
;
792 printk("Receiving packet size %d status %4.4x.\n",
796 skb_reserve(skb
, 2); /* Align IP on 16 byte */
798 /* 'skb->data' points to the start of sk_buff data area. */
800 insl_unswapped(ioaddr
+RX_FIFO
, skb_put(skb
,pkt_len
),
803 insl(ioaddr
+ RX_FIFO
, skb_put(skb
,pkt_len
),
807 outw(RxDiscard
, ioaddr
+ EL3_CMD
); /* Pop top Rx packet. */
808 skb
->protocol
= eth_type_trans(skb
,dev
);
810 lp
->stats
.rx_packets
++;
813 outw(RxDiscard
, ioaddr
+ EL3_CMD
);
814 lp
->stats
.rx_dropped
++;
816 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
819 inw(ioaddr
+ EL3_STATUS
); /* Delay. */
820 while (inw(ioaddr
+ EL3_STATUS
) & 0x1000)
821 printk(KERN_DEBUG
" Waiting for 3c509 to discard packet, status %x.\n",
822 inw(ioaddr
+ EL3_STATUS
) );
829 * Set or clear the multicast filter for this adaptor.
832 set_multicast_list(struct net_device
*dev
)
835 struct el3_private
*lp
= (struct el3_private
*)dev
->priv
;
836 int ioaddr
= dev
->base_addr
;
840 if (old
!= dev
->mc_count
) {
842 printk("%s: Setting Rx mode to %d addresses.\n", dev
->name
, dev
->mc_count
);
845 spin_lock_irqsave(&lp
->lock
, flags
);
846 if (dev
->flags
&IFF_PROMISC
) {
847 outw(SetRxFilter
| RxStation
| RxMulticast
| RxBroadcast
| RxProm
,
850 else if (dev
->mc_count
|| (dev
->flags
&IFF_ALLMULTI
)) {
851 outw(SetRxFilter
| RxStation
| RxMulticast
| RxBroadcast
, ioaddr
+ EL3_CMD
);
854 outw(SetRxFilter
| RxStation
| RxBroadcast
, ioaddr
+ EL3_CMD
);
855 spin_unlock_irqrestore(&lp
->lock
, flags
);
859 el3_close(struct net_device
*dev
)
861 int ioaddr
= dev
->base_addr
;
864 printk("%s: Shutting down ethercard.\n", dev
->name
);
869 /* Turn off statistics ASAP. We update lp->stats below. */
870 outw(StatsDisable
, ioaddr
+ EL3_CMD
);
872 /* Disable the receiver and transmitter. */
873 outw(RxDisable
, ioaddr
+ EL3_CMD
);
874 outw(TxDisable
, ioaddr
+ EL3_CMD
);
876 if (dev
->if_port
== 3)
877 /* Turn off thinnet power. Green! */
878 outw(StopCoax
, ioaddr
+ EL3_CMD
);
879 else if (dev
->if_port
== 0) {
880 /* Disable link beat and jabber, if_port may change ere next open(). */
882 outw(inw(ioaddr
+ WN4_MEDIA
) & ~MEDIA_TP
, ioaddr
+ WN4_MEDIA
);
885 free_irq(dev
->irq
, dev
);
886 /* Switching back to window 0 disables the IRQ. */
888 /* But we explicitly zero the IRQ line select anyway. */
889 outw(0x0f00, ioaddr
+ WN0_IRQ
);
897 /* Parameters that may be passed into the module. */
898 static int debug
= -1;
899 static int irq
[] = {-1, -1, -1, -1, -1, -1, -1, -1};
900 static int xcvr
[] = {-1, -1, -1, -1, -1, -1, -1, -1};
902 MODULE_PARM(debug
,"i");
903 MODULE_PARM(irq
,"1-8i");
904 MODULE_PARM(xcvr
,"1-8i");
915 while (el3_probe(0) == 0) {
916 if (irq
[el3_cards
] > 1)
917 el3_root_dev
->irq
= irq
[el3_cards
];
918 if (xcvr
[el3_cards
] >= 0)
919 el3_root_dev
->if_port
= xcvr
[el3_cards
];
923 return el3_cards
? 0 : -ENODEV
;
929 struct net_device
*next_dev
;
931 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
932 while (el3_root_dev
) {
933 struct el3_private
*lp
= (struct el3_private
*)el3_root_dev
->priv
;
936 mca_mark_as_unused(lp
->mca_slot
);
938 next_dev
= lp
->next_dev
;
939 unregister_netdev(el3_root_dev
);
940 release_region(el3_root_dev
->base_addr
, EL3_IO_EXTENT
);
942 el3_root_dev
= next_dev
;
949 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c509.c"
951 * kept-new-versions: 5