1 /* $Id: ethernet.c,v 1.17 2003/07/04 08:27:37 starvik Exp $
3 * e100net.c: A network driver for the ETRAX 100LX network controller.
5 * Copyright (c) 1998-2002 Axis Communications AB.
7 * The outline of this driver comes from skeleton.c.
10 * Revision 1.17 2003/07/04 08:27:37 starvik
11 * Merge of Linux 2.5.74
13 * Revision 1.16 2003/04/24 08:28:22 starvik
14 * New LED behaviour: LED off when no link
16 * Revision 1.15 2003/04/09 05:20:47 starvik
17 * Merge of Linux 2.5.67
19 * Revision 1.13 2003/03/06 16:11:01 henriken
20 * Off by one error in group address register setting.
22 * Revision 1.12 2003/02/27 17:24:19 starvik
23 * Corrected Rev to Revision
25 * Revision 1.11 2003/01/24 09:53:21 starvik
26 * Oops. Initialize GA to 0, not to 1
28 * Revision 1.10 2003/01/24 09:50:55 starvik
29 * Initialize GA_0 and GA_1 to 0 to avoid matching of unwanted packets
31 * Revision 1.9 2002/12/13 07:40:58 starvik
32 * Added basic ethtool interface
33 * Handled out of memory when allocating new buffers
35 * Revision 1.8 2002/12/11 13:13:57 starvik
36 * Added arch/ to v10 specific includes
37 * Added fix from Linux 2.4 in serial.c (flush_to_flip_buffer)
39 * Revision 1.7 2002/11/26 09:41:42 starvik
40 * Added e100_set_config (standard interface to set media type)
41 * Added protection against preemptive scheduling
42 * Added standard MII ioctls
44 * Revision 1.6 2002/11/21 07:18:18 starvik
45 * Timers must be initialized in 2.5.48
47 * Revision 1.5 2002/11/20 11:56:11 starvik
48 * Merge of Linux 2.5.48
50 * Revision 1.4 2002/11/18 07:26:46 starvik
51 * Linux 2.5 port of latest Linux 2.4 ethernet driver
53 * Revision 1.33 2002/10/02 20:16:17 hp
54 * SETF, SETS: Use underscored IO_x_ macros rather than incorrect token concatenation
56 * Revision 1.32 2002/09/16 06:05:58 starvik
57 * Align memory returned by dev_alloc_skb
58 * Moved handling of sent packets to interrupt to avoid reference counting problem
60 * Revision 1.31 2002/09/10 13:28:23 larsv
61 * Return -EINVAL for unknown ioctls to avoid confusing tools that tests
62 * for supported functionality by issuing special ioctls, i.e. wireless
65 * Revision 1.30 2002/05/07 18:50:08 johana
66 * Correct spelling in comments.
68 * Revision 1.29 2002/05/06 05:38:49 starvik
69 * Performance improvements:
70 * Large packets are not copied (breakpoint set to 256 bytes)
71 * The cache bug workaround is delayed until half of the receive list
74 * Transmit interrupts are only enabled when transmit queue is full
76 * Revision 1.28.2.1 2002/04/30 08:15:51 starvik
77 * Performance improvements:
78 * Large packets are not copied (breakpoint set to 256 bytes)
79 * The cache bug workaround is delayed until half of the receive list
82 * Transmit interrupts are only enabled when transmit queue is full
84 * Revision 1.28 2002/04/22 11:47:21 johana
85 * Fix according to 2.4.19-pre7. time_after/time_before and
86 * missing end of comment.
87 * The patch has a typo for ethernet.c in e100_clear_network_leds(),
90 * Revision 1.27 2002/04/12 11:55:11 bjornw
93 * Revision 1.26 2002/03/15 17:11:02 bjornw
94 * Use prepare_rx_descriptor after the CPU has touched the receiving descs
96 * Revision 1.25 2002/03/08 13:07:53 bjornw
97 * Unnecessary spinlock removed
99 * Revision 1.24 2002/02/20 12:57:43 fredriks
100 * Replaced MIN() with min().
102 * Revision 1.23 2002/02/20 10:58:14 fredriks
103 * Strip the Ethernet checksum (4 bytes) before forwarding a frame to upper layers.
105 * Revision 1.22 2002/01/30 07:48:22 matsfg
106 * Initiate R_NETWORK_TR_CTRL
108 * Revision 1.21 2001/11/23 11:54:49 starvik
109 * Added IFF_PROMISC and IFF_ALLMULTI handling in set_multicast_list
110 * Removed compiler warnings
112 * Revision 1.20 2001/11/12 19:26:00 pkj
113 * * Corrected e100_negotiate() to not assign half to current_duplex when
114 * it was supposed to compare them...
115 * * Cleaned up failure handling in e100_open().
116 * * Fixed compiler warnings.
118 * Revision 1.19 2001/11/09 07:43:09 starvik
119 * Added full duplex support
120 * Added ioctl to set speed and duplex
121 * Clear LED timer only runs when LED is lit
123 * Revision 1.18 2001/10/03 14:40:43 jonashg
124 * Update rx_bytes counter.
126 * Revision 1.17 2001/06/11 12:43:46 olof
127 * Modified defines for network LED behavior
129 * Revision 1.16 2001/05/30 06:12:46 markusl
130 * TxDesc.next should not be set to NULL
132 * Revision 1.15 2001/05/29 10:27:04 markusl
133 * Updated after review remarks:
137 * Revision 1.14 2001/05/29 09:20:14 jonashg
138 * Use driver name on printk output so one can tell which driver that complains.
140 * Revision 1.13 2001/05/09 12:35:59 johana
141 * Use DMA_NBR and IRQ_NBR defines from dma.h and irq.h
143 * Revision 1.12 2001/04/05 11:43:11 tobiasa
144 * Check dev before panic.
146 * Revision 1.11 2001/04/04 11:21:05 markusl
147 * Updated according to review remarks
149 * Revision 1.10 2001/03/26 16:03:06 bjornw
150 * Needs linux/config.h
152 * Revision 1.9 2001/03/19 14:47:48 pkj
153 * * Make sure there is always a pause after the network LEDs are
154 * changed so they will not look constantly lit during heavy traffic.
155 * * Always use HZ when setting times relative to jiffies.
156 * * Use LED_NETWORK_SET() when setting the network LEDs.
158 * Revision 1.8 2001/02/27 13:52:48 bjornw
161 * Revision 1.7 2001/02/23 13:46:38 bjornw
164 * Revision 1.6 2001/01/26 15:21:04 starvik
165 * Don't disable interrupts while reading MDIO registers (MDIO is slow)
166 * Corrected promiscuous mode
167 * Improved deallocation of IRQs ("ifconfig eth0 down" now works)
169 * Revision 1.5 2000/11/29 17:22:22 bjornw
170 * Get rid of the udword types legacy stuff
172 * Revision 1.4 2000/11/22 16:36:09 bjornw
173 * Please marketing by using the correct case when spelling Etrax.
175 * Revision 1.3 2000/11/21 16:43:04 bjornw
176 * Minor short->int change
178 * Revision 1.2 2000/11/08 14:27:57 bjornw
181 * Revision 1.1 2000/11/06 13:56:00 bjornw
182 * Verbatim copy of the 1.24 version of e100net.c from elinux
184 * Revision 1.24 2000/10/04 15:55:23 bjornw
185 * * Use virt_to_phys etc. for DMA addresses
186 * * Removed bogus CHECKSUM_UNNECESSARY
191 #include <linux/config.h>
193 #include <linux/module.h>
195 #include <linux/kernel.h>
196 #include <linux/sched.h>
197 #include <linux/delay.h>
198 #include <linux/types.h>
199 #include <linux/fcntl.h>
200 #include <linux/interrupt.h>
201 #include <linux/ptrace.h>
202 #include <linux/ioport.h>
203 #include <linux/in.h>
204 #include <linux/slab.h>
205 #include <linux/string.h>
206 #include <linux/spinlock.h>
207 #include <linux/errno.h>
208 #include <linux/init.h>
210 #include <linux/if.h>
211 #include <linux/mii.h>
212 #include <linux/netdevice.h>
213 #include <linux/etherdevice.h>
214 #include <linux/skbuff.h>
215 #include <linux/ethtool.h>
217 #include <asm/arch/svinto.h>/* DMA and register descriptions */
218 #include <asm/io.h> /* LED_* I/O functions */
221 #include <asm/system.h>
222 #include <asm/bitops.h>
223 #include <asm/ethernet.h>
224 #include <asm/cache.h>
230 * The name of the card. Is used for messages and in the requests for
231 * io regions, irqs and dma channels
234 static const char* cardname = "ETRAX 100LX built-in ethernet controller";
236 /* A default ethernet address. Highlevel SW will set the real one later */
238 static struct sockaddr default_mac = {
240 { 0x00, 0x40, 0x8C, 0xCD, 0x00, 0x00 }
243 /* Information that need to be kept for each board. */
245 struct net_device_stats stats;
247 /* Tx control lock. This protects the transmit buffer ring
248 * state along with the "tx full" state of the driver. This
249 * means all netif_queue flow control actions are protected
250 * by this lock as well.
255 typedef struct etrax_eth_descr
257 etrax_dma_descr descr;
261 /* Duplex settings */
269 /* Dma descriptors etc. */
271 #define MAX_MEDIA_DATA_SIZE 1518
273 #define MIN_PACKET_LEN 46
274 #define ETHER_HEAD_LEN 14
279 #define MDIO_BASE_STATUS_REG 0x1
280 #define MDIO_BASE_CONTROL_REG 0x0
281 #define MDIO_BC_NEGOTIATE 0x0200
282 #define MDIO_BC_FULL_DUPLEX_MASK 0x0100
283 #define MDIO_BC_AUTO_NEG_MASK 0x1000
284 #define MDIO_BC_SPEED_SELECT_MASK 0x2000
285 #define MDIO_ADVERTISMENT_REG 0x4
286 #define MDIO_ADVERT_100_FD 0x100
287 #define MDIO_ADVERT_100_HD 0x080
288 #define MDIO_ADVERT_10_FD 0x040
289 #define MDIO_ADVERT_10_HD 0x020
290 #define MDIO_LINK_UP_MASK 0x4
291 #define MDIO_START 0x1
292 #define MDIO_READ 0x2
293 #define MDIO_WRITE 0x1
294 #define MDIO_PREAMBLE 0xfffffffful
296 /* Broadcom specific */
297 #define MDIO_AUX_CTRL_STATUS_REG 0x18
298 #define MDIO_FULL_DUPLEX_IND 0x1
299 #define MDIO_SPEED 0x2
300 #define MDIO_PHYS_ADDR 0x0
302 /* Network flash constants */
303 #define NET_FLASH_TIME (HZ/50) /* 20 ms */
304 #define NET_FLASH_PAUSE (HZ/100) /* 10 ms */
305 #define NET_LINK_UP_CHECK_INTERVAL (2*HZ) /* 2 s */
306 #define NET_DUPLEX_CHECK_INTERVAL (2*HZ) /* 2 s */
308 #define NO_NETWORK_ACTIVITY 0
309 #define NETWORK_ACTIVITY 1
311 #define NBR_OF_RX_DESC 64
312 #define NBR_OF_TX_DESC 256
314 /* Large packets are sent directly to upper layers while small packets are */
315 /* copied (to reduce memory waste). The following constant decides the breakpoint */
316 #define RX_COPYBREAK 256
318 /* Due to a chip bug we need to flush the cache when descriptors are returned */
319 /* to the DMA. To decrease performance impact we return descriptors in chunks. */
320 /* The following constant determines the number of descriptors to return. */
321 #define RX_QUEUE_THRESHOLD NBR_OF_RX_DESC/2
323 #define GET_BIT(bit,val) (((val) >> (bit)) & 0x01)
325 /* Define some macros to access ETRAX 100 registers */
326 #define SETF(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \
327 IO_FIELD_(reg##_, field##_, val)
328 #define SETS(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \
329 IO_STATE_(reg##_, field##_, _##val)
331 static etrax_eth_descr *myNextRxDesc; /* Points to the next descriptor to
333 static etrax_eth_descr *myLastRxDesc; /* The last processed descriptor */
334 static etrax_eth_descr *myPrevRxDesc; /* The descriptor right before myNextRxDesc */
336 static etrax_eth_descr RxDescList[NBR_OF_RX_DESC] __attribute__ ((aligned(32)));
338 static etrax_eth_descr* myFirstTxDesc; /* First packet not yet sent */
339 static etrax_eth_descr* myLastTxDesc; /* End of send queue */
340 static etrax_eth_descr* myNextTxDesc; /* Next descriptor to use */
341 static etrax_eth_descr TxDescList[NBR_OF_TX_DESC] __attribute__ ((aligned(32)));
343 static unsigned int network_rec_config_shadow = 0;
345 /* Network speed indication. */
346 static struct timer_list speed_timer = TIMER_INITIALIZER(NULL, 0, 0);
347 static struct timer_list clear_led_timer = TIMER_INITIALIZER(NULL, 0, 0);
348 static int current_speed; /* Speed read from transceiver */
349 static int current_speed_selection; /* Speed selected by user */
350 static unsigned long led_next_time;
351 static int led_active;
352 static int rx_queue_len;
355 static struct timer_list duplex_timer = TIMER_INITIALIZER(NULL, 0, 0);
356 static int full_duplex;
357 static enum duplex current_duplex;
359 /* Index to functions, as function prototypes. */
361 static int etrax_ethernet_init(void);
363 static int e100_open(struct net_device *dev);
364 static int e100_set_mac_address(struct net_device *dev, void *addr);
365 static int e100_send_packet(struct sk_buff *skb, struct net_device *dev);
366 static irqreturn_t e100rxtx_interrupt(int irq, void *dev_id, struct pt_regs *regs);
367 static irqreturn_t e100nw_interrupt(int irq, void *dev_id, struct pt_regs *regs);
368 static void e100_rx(struct net_device *dev);
369 static int e100_close(struct net_device *dev);
370 static int e100_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
371 static int e100_ethtool_ioctl(struct net_device* dev, struct ifreq *ifr);
372 static int e100_set_config(struct net_device* dev, struct ifmap* map);
373 static void e100_tx_timeout(struct net_device *dev);
374 static struct net_device_stats *e100_get_stats(struct net_device *dev);
375 static void set_multicast_list(struct net_device *dev);
376 static void e100_hardware_send_packet(char *buf, int length);
377 static void update_rx_stats(struct net_device_stats *);
378 static void update_tx_stats(struct net_device_stats *);
380 static void e100_check_speed(unsigned long dummy);
381 static void e100_set_speed(unsigned long speed);
382 static void e100_check_duplex(unsigned long dummy);
383 static void e100_set_duplex(enum duplex);
384 static void e100_negotiate(void);
386 static unsigned short e100_get_mdio_reg(unsigned char reg_num);
387 static void e100_set_mdio_reg(unsigned char reg, unsigned short data);
388 static void e100_send_mdio_cmd(unsigned short cmd, int write_cmd);
389 static void e100_send_mdio_bit(unsigned char bit);
390 static unsigned char e100_receive_mdio_bit(void);
391 static void e100_reset_transceiver(void);
393 static void e100_clear_network_leds(unsigned long dummy);
394 static void e100_set_network_leds(int active);
396 #define tx_done(dev) (*R_DMA_CH0_CMD == 0)
399 * Check for a network adaptor of this type, and return '0' if one exists.
400 * If dev->base_addr == 0, probe all likely locations.
401 * If dev->base_addr == 1, always return failure.
402 * If dev->base_addr == 2, allocate space for the device and return success
403 * (detachable devices only).
407 etrax_ethernet_init(void)
409 struct net_device *dev;
412 printk("ETRAX 100LX 10/100MBit ethernet v2.0 (c) 2000-2003 Axis Communications AB\n");
414 dev = alloc_etherdev(sizeof(struct net_local));
418 dev->base_addr = (unsigned int)R_NETWORK_SA_0; /* just to have something to show */
420 /* now setup our etrax specific stuff */
422 dev->irq = NETWORK_DMA_RX_IRQ_NBR; /* we really use DMATX as well... */
423 dev->dma = NETWORK_RX_DMA_NBR;
425 /* fill in our handlers so the network layer can talk to us in the future */
427 dev->open = e100_open;
428 dev->hard_start_xmit = e100_send_packet;
429 dev->stop = e100_close;
430 dev->get_stats = e100_get_stats;
431 dev->set_multicast_list = set_multicast_list;
432 dev->set_mac_address = e100_set_mac_address;
433 dev->do_ioctl = e100_ioctl;
434 dev->set_config = e100_set_config;
435 dev->tx_timeout = e100_tx_timeout;
437 /* Initialise the list of Etrax DMA-descriptors */
439 /* Initialise receive descriptors */
441 for (i = 0; i < NBR_OF_RX_DESC; i++) {
442 /* Allocate two extra cachelines to make sure that buffer used by DMA
443 * does not share cacheline with any other data (to avoid cache bug)
445 RxDescList[i].skb = dev_alloc_skb(MAX_MEDIA_DATA_SIZE + 2 * L1_CACHE_BYTES);
446 RxDescList[i].descr.ctrl = 0;
447 RxDescList[i].descr.sw_len = MAX_MEDIA_DATA_SIZE;
448 RxDescList[i].descr.next = virt_to_phys(&RxDescList[i + 1]);
449 RxDescList[i].descr.buf = L1_CACHE_ALIGN(virt_to_phys(RxDescList[i].skb->data));
450 RxDescList[i].descr.status = 0;
451 RxDescList[i].descr.hw_len = 0;
452 prepare_rx_descriptor(&RxDescList[i].descr);
455 RxDescList[NBR_OF_RX_DESC - 1].descr.ctrl = d_eol;
456 RxDescList[NBR_OF_RX_DESC - 1].descr.next = virt_to_phys(&RxDescList[0]);
459 /* Initialize transmit descriptors */
460 for (i = 0; i < NBR_OF_TX_DESC; i++) {
461 TxDescList[i].descr.ctrl = 0;
462 TxDescList[i].descr.sw_len = 0;
463 TxDescList[i].descr.next = virt_to_phys(&TxDescList[i + 1].descr);
464 TxDescList[i].descr.buf = 0;
465 TxDescList[i].descr.status = 0;
466 TxDescList[i].descr.hw_len = 0;
467 TxDescList[i].skb = 0;
470 TxDescList[NBR_OF_TX_DESC - 1].descr.ctrl = d_eol;
471 TxDescList[NBR_OF_TX_DESC - 1].descr.next = virt_to_phys(&TxDescList[0].descr);
473 /* Initialise initial pointers */
475 myNextRxDesc = &RxDescList[0];
476 myLastRxDesc = &RxDescList[NBR_OF_RX_DESC - 1];
477 myPrevRxDesc = &RxDescList[NBR_OF_RX_DESC - 1];
478 myFirstTxDesc = &TxDescList[0];
479 myNextTxDesc = &TxDescList[0];
480 myLastTxDesc = &TxDescList[NBR_OF_TX_DESC - 1];
482 /* Register device */
483 err = register_netdev(dev);
489 /* set the default MAC address */
491 e100_set_mac_address(dev, &default_mac);
493 /* Initialize speed indicator stuff. */
496 current_speed_selection = 0; /* Auto */
497 speed_timer.expires = jiffies + NET_LINK_UP_CHECK_INTERVAL;
498 speed_timer.function = e100_check_speed;
499 add_timer(&speed_timer);
501 clear_led_timer.function = e100_clear_network_leds;
504 current_duplex = autoneg;
505 duplex_timer.expires = jiffies + NET_DUPLEX_CHECK_INTERVAL;
506 duplex_timer.function = e100_check_duplex;
507 add_timer(&duplex_timer);
509 /* Initialize group address registers to make sure that no */
510 /* unwanted addresses are matched */
511 *R_NETWORK_GA_0 = 0x00000000;
512 *R_NETWORK_GA_1 = 0x00000000;
516 /* set MAC address of the interface. called from the core after a
517 * SIOCSIFADDR ioctl, and from the bootup above.
521 e100_set_mac_address(struct net_device *dev, void *p)
523 struct net_local *np = (struct net_local *)dev->priv;
524 struct sockaddr *addr = p;
527 spin_lock(&np->lock); /* preemption protection */
531 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
533 /* Write it to the hardware.
534 * Note the way the address is wrapped:
535 * *R_NETWORK_SA_0 = a0_0 | (a0_1 << 8) | (a0_2 << 16) | (a0_3 << 24);
536 * *R_NETWORK_SA_1 = a0_4 | (a0_5 << 8);
539 *R_NETWORK_SA_0 = dev->dev_addr[0] | (dev->dev_addr[1] << 8) |
540 (dev->dev_addr[2] << 16) | (dev->dev_addr[3] << 24);
541 *R_NETWORK_SA_1 = dev->dev_addr[4] | (dev->dev_addr[5] << 8);
544 /* show it in the log as well */
546 printk("%s: changed MAC to ", dev->name);
548 for (i = 0; i < 5; i++)
549 printk("%02X:", dev->dev_addr[i]);
551 printk("%02X\n", dev->dev_addr[i]);
553 spin_unlock(&np->lock);
559 * Open/initialize the board. This is called (in the current kernel)
560 * sometime after booting when the 'ifconfig' program is run.
562 * This routine should set everything up anew at each open, even
563 * registers that "should" only need to be set once at boot, so that
564 * there is non-reboot way to recover if something goes wrong.
568 e100_open(struct net_device *dev)
572 /* disable the ethernet interface while we configure it */
574 *R_NETWORK_GEN_CONFIG =
575 IO_STATE(R_NETWORK_GEN_CONFIG, phy, mii_clk) |
576 IO_STATE(R_NETWORK_GEN_CONFIG, enable, off);
578 /* enable the MDIO output pin */
580 *R_NETWORK_MGM_CTRL = IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable);
583 IO_STATE(R_IRQ_MASK0_CLR, overrun, clr) |
584 IO_STATE(R_IRQ_MASK0_CLR, underrun, clr) |
585 IO_STATE(R_IRQ_MASK0_CLR, excessive_col, clr);
587 /* clear dma0 and 1 eop and descr irq masks */
589 IO_STATE(R_IRQ_MASK2_CLR, dma0_descr, clr) |
590 IO_STATE(R_IRQ_MASK2_CLR, dma0_eop, clr) |
591 IO_STATE(R_IRQ_MASK2_CLR, dma1_descr, clr) |
592 IO_STATE(R_IRQ_MASK2_CLR, dma1_eop, clr);
594 /* Reset and wait for the DMA channels */
596 RESET_DMA(NETWORK_TX_DMA_NBR);
597 RESET_DMA(NETWORK_RX_DMA_NBR);
598 WAIT_DMA(NETWORK_TX_DMA_NBR);
599 WAIT_DMA(NETWORK_RX_DMA_NBR);
601 /* Initialise the etrax network controller */
603 /* allocate the irq corresponding to the receiving DMA */
605 if (request_irq(NETWORK_DMA_RX_IRQ_NBR, e100rxtx_interrupt, 0,
606 cardname, (void *)dev)) {
610 /* allocate the irq corresponding to the transmitting DMA */
612 if (request_irq(NETWORK_DMA_TX_IRQ_NBR, e100rxtx_interrupt, 0,
613 cardname, (void *)dev)) {
617 /* allocate the irq corresponding to the network errors etc */
619 if (request_irq(NETWORK_STATUS_IRQ_NBR, e100nw_interrupt, 0,
620 cardname, (void *)dev)) {
624 /* give the HW an idea of what MAC address we want */
626 *R_NETWORK_SA_0 = dev->dev_addr[0] | (dev->dev_addr[1] << 8) |
627 (dev->dev_addr[2] << 16) | (dev->dev_addr[3] << 24);
628 *R_NETWORK_SA_1 = dev->dev_addr[4] | (dev->dev_addr[5] << 8);
632 /* use promiscuous mode for testing */
633 *R_NETWORK_GA_0 = 0xffffffff;
634 *R_NETWORK_GA_1 = 0xffffffff;
636 *R_NETWORK_REC_CONFIG = 0xd; /* broadcast rec, individ. rec, ma0 enabled */
638 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, broadcast, receive);
639 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, ma0, enable);
640 SETF(network_rec_config_shadow, R_NETWORK_REC_CONFIG, duplex, full_duplex);
641 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
644 *R_NETWORK_GEN_CONFIG =
645 IO_STATE(R_NETWORK_GEN_CONFIG, phy, mii_clk) |
646 IO_STATE(R_NETWORK_GEN_CONFIG, enable, on);
649 IO_STATE(R_NETWORK_TR_CTRL, clr_error, clr) |
650 IO_STATE(R_NETWORK_TR_CTRL, delay, none) |
651 IO_STATE(R_NETWORK_TR_CTRL, cancel, dont) |
652 IO_STATE(R_NETWORK_TR_CTRL, cd, enable) |
653 IO_STATE(R_NETWORK_TR_CTRL, retry, enable) |
654 IO_STATE(R_NETWORK_TR_CTRL, pad, enable) |
655 IO_STATE(R_NETWORK_TR_CTRL, crc, enable);
660 /* enable the irq's for ethernet DMA */
663 IO_STATE(R_IRQ_MASK2_SET, dma1_eop, set);
666 IO_STATE(R_IRQ_MASK0_SET, overrun, set) |
667 IO_STATE(R_IRQ_MASK0_SET, underrun, set) |
668 IO_STATE(R_IRQ_MASK0_SET, excessive_col, set);
670 /* make sure the irqs are cleared */
672 *R_DMA_CH0_CLR_INTR = IO_STATE(R_DMA_CH0_CLR_INTR, clr_eop, do);
673 *R_DMA_CH1_CLR_INTR = IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do);
675 /* make sure the rec and transmit error counters are cleared */
677 (void)*R_REC_COUNTERS; /* dummy read */
678 (void)*R_TR_COUNTERS; /* dummy read */
680 /* start the receiving DMA channel so we can receive packets from now on */
682 *R_DMA_CH1_FIRST = virt_to_phys(myNextRxDesc);
683 *R_DMA_CH1_CMD = IO_STATE(R_DMA_CH1_CMD, cmd, start);
685 /* Set up transmit DMA channel so it can be restarted later */
687 *R_DMA_CH0_FIRST = 0;
688 *R_DMA_CH0_DESCR = virt_to_phys(myLastTxDesc);
690 restore_flags(flags);
692 /* We are now ready to accept transmit requeusts from
693 * the queueing layer of the networking.
695 netif_start_queue(dev);
700 free_irq(NETWORK_DMA_TX_IRQ_NBR, (void *)dev);
702 free_irq(NETWORK_DMA_RX_IRQ_NBR, (void *)dev);
709 e100_check_speed(unsigned long dummy)
712 int old_speed = current_speed;
714 data = e100_get_mdio_reg(MDIO_BASE_STATUS_REG);
715 if (!(data & MDIO_LINK_UP_MASK)) {
718 data = e100_get_mdio_reg(MDIO_AUX_CTRL_STATUS_REG);
719 current_speed = (data & MDIO_SPEED ? 100 : 10);
722 if (old_speed != current_speed)
723 e100_set_network_leds(NO_NETWORK_ACTIVITY);
725 /* Reinitialize the timer. */
726 speed_timer.expires = jiffies + NET_LINK_UP_CHECK_INTERVAL;
727 add_timer(&speed_timer);
733 unsigned short data = e100_get_mdio_reg(MDIO_ADVERTISMENT_REG);
735 /* Discard old speed and duplex settings */
736 data &= ~(MDIO_ADVERT_100_HD | MDIO_ADVERT_100_FD |
737 MDIO_ADVERT_10_FD | MDIO_ADVERT_10_HD);
739 switch (current_speed_selection) {
741 if (current_duplex == full)
742 data |= MDIO_ADVERT_10_FD;
743 else if (current_duplex == half)
744 data |= MDIO_ADVERT_10_HD;
746 data |= MDIO_ADVERT_10_HD | MDIO_ADVERT_10_FD;
750 if (current_duplex == full)
751 data |= MDIO_ADVERT_100_FD;
752 else if (current_duplex == half)
753 data |= MDIO_ADVERT_100_HD;
755 data |= MDIO_ADVERT_100_HD | MDIO_ADVERT_100_FD;
759 if (current_duplex == full)
760 data |= MDIO_ADVERT_100_FD | MDIO_ADVERT_10_FD;
761 else if (current_duplex == half)
762 data |= MDIO_ADVERT_100_HD | MDIO_ADVERT_10_HD;
764 data |= MDIO_ADVERT_100_HD | MDIO_ADVERT_100_FD | MDIO_ADVERT_10_FD | MDIO_ADVERT_10_HD;
767 default : /* assume autoneg speed and duplex */
768 data |= MDIO_ADVERT_100_HD | MDIO_ADVERT_100_FD |
769 MDIO_ADVERT_10_FD | MDIO_ADVERT_10_HD;
772 e100_set_mdio_reg(MDIO_ADVERTISMENT_REG, data);
774 /* Renegotiate with link partner */
775 data = e100_get_mdio_reg(MDIO_BASE_CONTROL_REG);
776 data |= MDIO_BC_NEGOTIATE;
778 e100_set_mdio_reg(MDIO_BASE_CONTROL_REG, data);
782 e100_set_speed(unsigned long speed)
784 current_speed_selection = speed;
789 e100_check_duplex(unsigned long dummy)
793 data = e100_get_mdio_reg(MDIO_AUX_CTRL_STATUS_REG);
795 if (data & MDIO_FULL_DUPLEX_IND) {
796 if (!full_duplex) { /* Duplex changed to full? */
798 SETF(network_rec_config_shadow, R_NETWORK_REC_CONFIG, duplex, full_duplex);
799 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
802 if (full_duplex) { /* Duplex changed to half? */
804 SETF(network_rec_config_shadow, R_NETWORK_REC_CONFIG, duplex, full_duplex);
805 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
809 /* Reinitialize the timer. */
810 duplex_timer.expires = jiffies + NET_DUPLEX_CHECK_INTERVAL;
811 add_timer(&duplex_timer);
815 e100_set_duplex(enum duplex new_duplex)
817 current_duplex = new_duplex;
822 static unsigned short
823 e100_get_mdio_reg(unsigned char reg_num)
825 unsigned short cmd; /* Data to be sent on MDIO port */
826 unsigned short data; /* Data read from MDIO */
829 /* Start of frame, OP Code, Physical Address, Register Address */
830 cmd = (MDIO_START << 14) | (MDIO_READ << 12) | (MDIO_PHYS_ADDR << 7) |
833 e100_send_mdio_cmd(cmd, 0);
838 for (bitCounter=15; bitCounter>=0 ; bitCounter--) {
839 data |= (e100_receive_mdio_bit() << bitCounter);
846 e100_set_mdio_reg(unsigned char reg, unsigned short data)
851 cmd = (MDIO_START << 14) | (MDIO_WRITE << 12) | (MDIO_PHYS_ADDR << 7) |
854 e100_send_mdio_cmd(cmd, 1);
857 for (bitCounter=15; bitCounter>=0 ; bitCounter--) {
858 e100_send_mdio_bit(GET_BIT(bitCounter, data));
864 e100_send_mdio_cmd(unsigned short cmd, int write_cmd)
867 unsigned char data = 0x2;
870 for (bitCounter = 31; bitCounter>= 0; bitCounter--)
871 e100_send_mdio_bit(GET_BIT(bitCounter, MDIO_PREAMBLE));
873 for (bitCounter = 15; bitCounter >= 2; bitCounter--)
874 e100_send_mdio_bit(GET_BIT(bitCounter, cmd));
877 for (bitCounter = 1; bitCounter >= 0 ; bitCounter--)
879 e100_send_mdio_bit(GET_BIT(bitCounter, data));
881 e100_receive_mdio_bit();
885 e100_send_mdio_bit(unsigned char bit)
887 *R_NETWORK_MGM_CTRL =
888 IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable) |
889 IO_FIELD(R_NETWORK_MGM_CTRL, mdio, bit);
891 *R_NETWORK_MGM_CTRL =
892 IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable) |
893 IO_MASK(R_NETWORK_MGM_CTRL, mdck) |
894 IO_FIELD(R_NETWORK_MGM_CTRL, mdio, bit);
899 e100_receive_mdio_bit()
902 *R_NETWORK_MGM_CTRL = 0;
903 bit = IO_EXTRACT(R_NETWORK_STAT, mdio, *R_NETWORK_STAT);
905 *R_NETWORK_MGM_CTRL = IO_MASK(R_NETWORK_MGM_CTRL, mdck);
911 e100_reset_transceiver(void)
917 data = e100_get_mdio_reg(MDIO_BASE_CONTROL_REG);
919 cmd = (MDIO_START << 14) | (MDIO_WRITE << 12) | (MDIO_PHYS_ADDR << 7) | (MDIO_BASE_CONTROL_REG << 2);
921 e100_send_mdio_cmd(cmd, 1);
925 for (bitCounter = 15; bitCounter >= 0 ; bitCounter--) {
926 e100_send_mdio_bit(GET_BIT(bitCounter, data));
930 /* Called by upper layers if they decide it took too long to complete
931 * sending a packet - we need to reset and stuff.
935 e100_tx_timeout(struct net_device *dev)
937 struct net_local *np = (struct net_local *)dev->priv;
940 spin_lock_irqsave(&np->lock, flags);
942 printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
943 tx_done(dev) ? "IRQ problem" : "network cable problem");
945 /* remember we got an error */
947 np->stats.tx_errors++;
949 /* reset the TX DMA in case it has hung on something */
951 RESET_DMA(NETWORK_TX_DMA_NBR);
952 WAIT_DMA(NETWORK_TX_DMA_NBR);
954 /* Reset the transceiver. */
956 e100_reset_transceiver();
958 /* and get rid of the packets that never got an interrupt */
959 while (myFirstTxDesc != myNextTxDesc)
961 dev_kfree_skb(myFirstTxDesc->skb);
962 myFirstTxDesc->skb = 0;
963 myFirstTxDesc = phys_to_virt(myFirstTxDesc->descr.next);
966 /* Set up transmit DMA channel so it can be restarted later */
967 *R_DMA_CH0_FIRST = 0;
968 *R_DMA_CH0_DESCR = virt_to_phys(myLastTxDesc);
970 /* tell the upper layers we're ok again */
972 netif_wake_queue(dev);
973 spin_unlock_irqrestore(&np->lock, flags);
977 /* This will only be invoked if the driver is _not_ in XOFF state.
978 * What this means is that we need not check it, and that this
979 * invariant will hold if we make sure that the netif_*_queue()
980 * calls are done at the proper times.
984 e100_send_packet(struct sk_buff *skb, struct net_device *dev)
986 struct net_local *np = (struct net_local *)dev->priv;
987 int length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
988 unsigned char *buf = skb->data;
992 printk("send packet len %d\n", length);
994 spin_lock_irqsave(&np->lock, flags); /* protect from tx_interrupt and ourself */
996 myNextTxDesc->skb = skb;
998 dev->trans_start = jiffies;
1000 e100_hardware_send_packet(buf, length);
1002 myNextTxDesc = phys_to_virt(myNextTxDesc->descr.next);
1004 /* Stop queue if full */
1005 if (myNextTxDesc == myFirstTxDesc) {
1006 /* Enable transmit interrupt to wake up queue */
1007 *R_DMA_CH0_CLR_INTR = IO_STATE(R_DMA_CH0_CLR_INTR, clr_eop, do);
1008 *R_IRQ_MASK2_SET = IO_STATE(R_IRQ_MASK2_SET, dma0_eop, set);
1009 netif_stop_queue(dev);
1012 spin_unlock_irqrestore(&np->lock, flags);
1018 * The typical workload of the driver:
1019 * Handle the network interface interrupts.
1023 e100rxtx_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1025 struct net_device *dev = (struct net_device *)dev_id;
1026 struct net_local *np = (struct net_local *)dev->priv;
1027 unsigned long irqbits = *R_IRQ_MASK2_RD;
1029 /* Handle received packets */
1030 if (irqbits & IO_STATE(R_IRQ_MASK2_RD, dma1_eop, active)) {
1031 /* acknowledge the eop interrupt */
1033 *R_DMA_CH1_CLR_INTR = IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do);
1035 /* check if one or more complete packets were indeed received */
1037 while (*R_DMA_CH1_FIRST != virt_to_phys(myNextRxDesc)) {
1038 /* Take out the buffer and give it to the OS, then
1039 * allocate a new buffer to put a packet in.
1042 ((struct net_local *)dev->priv)->stats.rx_packets++;
1043 /* restart/continue on the channel, for safety */
1044 *R_DMA_CH1_CMD = IO_STATE(R_DMA_CH1_CMD, cmd, restart);
1045 /* clear dma channel 1 eop/descr irq bits */
1046 *R_DMA_CH1_CLR_INTR =
1047 IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do) |
1048 IO_STATE(R_DMA_CH1_CLR_INTR, clr_descr, do);
1050 /* now, we might have gotten another packet
1051 so we have to loop back and check if so */
1055 /* Report any packets that have been sent */
1056 while (myFirstTxDesc != phys_to_virt(*R_DMA_CH0_FIRST) &&
1057 myFirstTxDesc != myNextTxDesc)
1059 np->stats.tx_bytes += myFirstTxDesc->skb->len;
1060 np->stats.tx_packets++;
1062 /* dma is ready with the transmission of the data in tx_skb, so now
1063 we can release the skb memory */
1064 dev_kfree_skb_irq(myFirstTxDesc->skb);
1065 myFirstTxDesc->skb = 0;
1066 myFirstTxDesc = phys_to_virt(myFirstTxDesc->descr.next);
1069 if (irqbits & IO_STATE(R_IRQ_MASK2_RD, dma0_eop, active)) {
1070 /* acknowledge the eop interrupt and wake up queue */
1071 *R_DMA_CH0_CLR_INTR = IO_STATE(R_DMA_CH0_CLR_INTR, clr_eop, do);
1072 *R_IRQ_MASK2_CLR = IO_STATE(R_IRQ_MASK2_CLR, dma0_eop, clr);
1073 netif_wake_queue(dev);
1079 e100nw_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1081 struct net_device *dev = (struct net_device *)dev_id;
1082 struct net_local *np = (struct net_local *)dev->priv;
1083 unsigned long irqbits = *R_IRQ_MASK0_RD;
1085 /* check for underrun irq */
1086 if (irqbits & IO_STATE(R_IRQ_MASK0_RD, underrun, active)) {
1087 *R_NETWORK_TR_CTRL = IO_STATE(R_NETWORK_TR_CTRL, clr_error, clr);
1088 np->stats.tx_errors++;
1089 D(printk("ethernet receiver underrun!\n"));
1092 /* check for overrun irq */
1093 if (irqbits & IO_STATE(R_IRQ_MASK0_RD, overrun, active)) {
1094 update_rx_stats(&np->stats); /* this will ack the irq */
1095 D(printk("ethernet receiver overrun!\n"));
1097 /* check for excessive collision irq */
1098 if (irqbits & IO_STATE(R_IRQ_MASK0_RD, excessive_col, active)) {
1099 *R_NETWORK_TR_CTRL = IO_STATE(R_NETWORK_TR_CTRL, clr_error, clr);
1100 np->stats.tx_errors++;
1101 D(printk("ethernet excessive collisions!\n"));
1106 /* We have a good packet(s), get it/them out of the buffers. */
1108 e100_rx(struct net_device *dev)
1110 struct sk_buff *skb;
1112 struct net_local *np = (struct net_local *)dev->priv;
1113 unsigned char *skb_data_ptr;
1118 if (!led_active && time_after(jiffies, led_next_time)) {
1119 /* light the network leds depending on the current speed. */
1120 e100_set_network_leds(NETWORK_ACTIVITY);
1122 /* Set the earliest time we may clear the LED */
1123 led_next_time = jiffies + NET_FLASH_TIME;
1125 mod_timer(&clear_led_timer, jiffies + HZ/10);
1128 length = myNextRxDesc->descr.hw_len - 4;
1129 ((struct net_local *)dev->priv)->stats.rx_bytes += length;
1132 printk("Got a packet of length %d:\n", length);
1133 /* dump the first bytes in the packet */
1134 skb_data_ptr = (unsigned char *)phys_to_virt(myNextRxDesc->descr.buf);
1135 for (i = 0; i < 8; i++) {
1136 printk("%d: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", i * 8,
1137 skb_data_ptr[0],skb_data_ptr[1],skb_data_ptr[2],skb_data_ptr[3],
1138 skb_data_ptr[4],skb_data_ptr[5],skb_data_ptr[6],skb_data_ptr[7]);
1143 if (length < RX_COPYBREAK) {
1144 /* Small packet, copy data */
1145 skb = dev_alloc_skb(length - ETHER_HEAD_LEN);
1147 np->stats.rx_errors++;
1148 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1152 skb_put(skb, length - ETHER_HEAD_LEN); /* allocate room for the packet body */
1153 skb_data_ptr = skb_push(skb, ETHER_HEAD_LEN); /* allocate room for the header */
1156 printk("head = 0x%x, data = 0x%x, tail = 0x%x, end = 0x%x\n",
1157 skb->head, skb->data, skb->tail, skb->end);
1158 printk("copying packet to 0x%x.\n", skb_data_ptr);
1161 memcpy(skb_data_ptr, phys_to_virt(myNextRxDesc->descr.buf), length);
1164 /* Large packet, send directly to upper layers and allocate new
1165 * memory (aligned to cache line boundary to avoid bug).
1166 * Before sending the skb to upper layers we must make sure that
1167 * skb->data points to the aligned start of the packet.
1170 struct sk_buff *new_skb = dev_alloc_skb(MAX_MEDIA_DATA_SIZE + 2 * L1_CACHE_BYTES);
1172 np->stats.rx_errors++;
1173 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1176 skb = myNextRxDesc->skb;
1177 align = (int)phys_to_virt(myNextRxDesc->descr.buf) - (int)skb->data;
1178 skb_put(skb, length + align);
1179 skb_pull(skb, align); /* Remove alignment bytes */
1180 myNextRxDesc->skb = new_skb;
1181 myNextRxDesc->descr.buf = L1_CACHE_ALIGN(virt_to_phys(myNextRxDesc->skb->data));
1185 skb->protocol = eth_type_trans(skb, dev);
1187 /* Send the packet to the upper layers */
1190 /* Prepare for next packet */
1191 myNextRxDesc->descr.status = 0;
1192 myPrevRxDesc = myNextRxDesc;
1193 myNextRxDesc = phys_to_virt(myNextRxDesc->descr.next);
1197 /* Check if descriptors should be returned */
1198 if (rx_queue_len == RX_QUEUE_THRESHOLD) {
1199 flush_etrax_cache();
1200 myPrevRxDesc->descr.ctrl |= d_eol;
1201 myLastRxDesc->descr.ctrl &= ~d_eol;
1202 myLastRxDesc = myPrevRxDesc;
1207 /* The inverse routine to net_open(). */
1209 e100_close(struct net_device *dev)
1211 struct net_local *np = (struct net_local *)dev->priv;
1213 printk("Closing %s.\n", dev->name);
1215 netif_stop_queue(dev);
1217 *R_NETWORK_GEN_CONFIG =
1218 IO_STATE(R_NETWORK_GEN_CONFIG, phy, mii_clk) |
1219 IO_STATE(R_NETWORK_GEN_CONFIG, enable, off);
1222 IO_STATE(R_IRQ_MASK0_CLR, overrun, clr) |
1223 IO_STATE(R_IRQ_MASK0_CLR, underrun, clr) |
1224 IO_STATE(R_IRQ_MASK0_CLR, excessive_col, clr);
1227 IO_STATE(R_IRQ_MASK2_CLR, dma0_descr, clr) |
1228 IO_STATE(R_IRQ_MASK2_CLR, dma0_eop, clr) |
1229 IO_STATE(R_IRQ_MASK2_CLR, dma1_descr, clr) |
1230 IO_STATE(R_IRQ_MASK2_CLR, dma1_eop, clr);
1232 /* Stop the receiver and the transmitter */
1234 RESET_DMA(NETWORK_TX_DMA_NBR);
1235 RESET_DMA(NETWORK_RX_DMA_NBR);
1237 /* Flush the Tx and disable Rx here. */
1239 free_irq(NETWORK_DMA_RX_IRQ_NBR, (void *)dev);
1240 free_irq(NETWORK_DMA_TX_IRQ_NBR, (void *)dev);
1241 free_irq(NETWORK_STATUS_IRQ_NBR, (void *)dev);
1243 /* Update the statistics here. */
1245 update_rx_stats(&np->stats);
1246 update_tx_stats(&np->stats);
1252 e100_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1254 struct mii_ioctl_data *data = (struct mii_ioctl_data *)&ifr->ifr_data;
1255 struct net_local *np = (struct net_local *)dev->priv;
1257 spin_lock(&np->lock); /* Preempt protection */
1260 return e100_ethtool_ioctl(dev,ifr);
1261 case SIOCGMIIPHY: /* Get PHY address */
1262 data->phy_id = MDIO_PHYS_ADDR;
1264 case SIOCGMIIREG: /* Read MII register */
1265 data->val_out = e100_get_mdio_reg(data->reg_num);
1267 case SIOCSMIIREG: /* Write MII register */
1268 e100_set_mdio_reg(data->reg_num, data->val_in);
1270 /* The ioctls below should be considered obsolete but are */
1271 /* still present for compatability with old scripts/apps */
1272 case SET_ETH_SPEED_10: /* 10 Mbps */
1275 case SET_ETH_SPEED_100: /* 100 Mbps */
1276 e100_set_speed(100);
1278 case SET_ETH_SPEED_AUTO: /* Auto negotiate speed */
1281 case SET_ETH_DUPLEX_HALF: /* Hhalf duplex. */
1282 e100_set_duplex(half);
1284 case SET_ETH_DUPLEX_FULL: /* Full duplex. */
1285 e100_set_duplex(full);
1287 case SET_ETH_DUPLEX_AUTO: /* Autonegotiate duplex*/
1288 e100_set_duplex(autoneg);
1293 spin_unlock(&np->lock);
1298 e100_ethtool_ioctl(struct net_device *dev, struct ifreq *ifr)
1300 struct ethtool_cmd ecmd;
1302 if (copy_from_user(&ecmd, ifr->ifr_data, sizeof (ecmd)))
1308 memset((void *) &ecmd, 0, sizeof (ecmd));
1310 SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII |
1311 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
1312 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full;
1313 ecmd.port = PORT_TP;
1314 ecmd.transceiver = XCVR_EXTERNAL;
1315 ecmd.phy_address = MDIO_PHYS_ADDR;
1316 ecmd.speed = current_speed;
1317 ecmd.duplex = full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
1318 ecmd.advertising = ADVERTISED_TP;
1319 if (current_duplex == autoneg && current_speed_selection == 0)
1320 ecmd.advertising = ADVERTISED_Autoneg;
1323 ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
1324 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
1325 if (current_speed_selection == 10)
1326 ecmd.advertising &= ~(ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full);
1327 else if (current_speed_selection == 100)
1328 ecmd.advertising &= ~(ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full);
1329 if (current_duplex == half)
1330 ecmd.advertising &= ~(ADVERTISED_10baseT_Full | ADVERTISED_100baseT_Full);
1331 else if (current_duplex == full)
1332 ecmd.advertising &= ~(ADVERTISED_10baseT_Half | ADVERTISED_100baseT_Half);
1334 ecmd.autoneg = AUTONEG_ENABLE;
1335 if (copy_to_user(ifr->ifr_data, &ecmd, sizeof (ecmd)))
1341 if (!capable(CAP_NET_ADMIN)) {
1344 if (ecmd.autoneg == AUTONEG_ENABLE) {
1345 e100_set_duplex(autoneg);
1348 e100_set_duplex(ecmd.duplex == DUPLEX_HALF ? half : full);
1349 e100_set_speed(ecmd.speed == SPEED_10 ? 10: 100);
1353 case ETHTOOL_GDRVINFO:
1355 struct ethtool_drvinfo info;
1356 memset((void *) &info, 0, sizeof (info));
1357 strncpy(info.driver, "ETRAX 100LX", sizeof(info.driver) - 1);
1358 strncpy(info.version, "$Revision: 1.17 $", sizeof(info.version) - 1);
1359 strncpy(info.fw_version, "N/A", sizeof(info.fw_version) - 1);
1360 strncpy(info.bus_info, "N/A", sizeof(info.bus_info) - 1);
1361 info.regdump_len = 0;
1362 info.eedump_len = 0;
1363 info.testinfo_len = 0;
1364 if (copy_to_user(ifr->ifr_data, &info, sizeof (info)))
1368 case ETHTOOL_NWAY_RST:
1369 if (current_duplex == autoneg && current_speed_selection == 0)
1380 e100_set_config(struct net_device *dev, struct ifmap *map)
1382 struct net_local *np = (struct net_local *)dev->priv;
1383 spin_lock(&np->lock); /* Preempt protection */
1386 case IF_PORT_UNKNOWN:
1389 e100_set_duplex(autoneg);
1391 case IF_PORT_10BASET:
1393 e100_set_duplex(autoneg);
1395 case IF_PORT_100BASET:
1396 case IF_PORT_100BASETX:
1397 e100_set_speed(100);
1398 e100_set_duplex(autoneg);
1400 case IF_PORT_100BASEFX:
1401 case IF_PORT_10BASE2:
1403 spin_unlock(&np->lock);
1407 printk(KERN_ERR "%s: Invalid media selected", dev->name);
1408 spin_unlock(&np->lock);
1411 spin_unlock(&np->lock);
1416 update_rx_stats(struct net_device_stats *es)
1418 unsigned long r = *R_REC_COUNTERS;
1419 /* update stats relevant to reception errors */
1420 es->rx_fifo_errors += IO_EXTRACT(R_REC_COUNTERS, congestion, r);
1421 es->rx_crc_errors += IO_EXTRACT(R_REC_COUNTERS, crc_error, r);
1422 es->rx_frame_errors += IO_EXTRACT(R_REC_COUNTERS, alignment_error, r);
1423 es->rx_length_errors += IO_EXTRACT(R_REC_COUNTERS, oversize, r);
1427 update_tx_stats(struct net_device_stats *es)
1429 unsigned long r = *R_TR_COUNTERS;
1430 /* update stats relevant to transmission errors */
1432 IO_EXTRACT(R_TR_COUNTERS, single_col, r) +
1433 IO_EXTRACT(R_TR_COUNTERS, multiple_col, r);
1434 es->tx_errors += IO_EXTRACT(R_TR_COUNTERS, deferred, r);
1438 * Get the current statistics.
1439 * This may be called with the card open or closed.
1441 static struct net_device_stats *
1442 e100_get_stats(struct net_device *dev)
1444 struct net_local *lp = (struct net_local *)dev->priv;
1445 unsigned long flags;
1446 spin_lock_irqsave(&lp->lock, flags);
1448 update_rx_stats(&lp->stats);
1449 update_tx_stats(&lp->stats);
1451 spin_unlock_irqrestore(&lp->lock, flags);
1456 * Set or clear the multicast filter for this adaptor.
1457 * num_addrs == -1 Promiscuous mode, receive all packets
1458 * num_addrs == 0 Normal mode, clear multicast list
1459 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1460 * and do best-effort filtering.
1463 set_multicast_list(struct net_device *dev)
1465 struct net_local *lp = (struct net_local *)dev->priv;
1466 int num_addr = dev->mc_count;
1467 unsigned long int lo_bits;
1468 unsigned long int hi_bits;
1469 spin_lock(&lp->lock);
1470 if (dev->flags & IFF_PROMISC)
1472 /* promiscuous mode */
1473 lo_bits = 0xfffffffful;
1474 hi_bits = 0xfffffffful;
1476 /* Enable individual receive */
1477 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, receive);
1478 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
1479 } else if (dev->flags & IFF_ALLMULTI) {
1480 /* enable all multicasts */
1481 lo_bits = 0xfffffffful;
1482 hi_bits = 0xfffffffful;
1484 /* Disable individual receive */
1485 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard);
1486 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
1487 } else if (num_addr == 0) {
1488 /* Normal, clear the mc list */
1489 lo_bits = 0x00000000ul;
1490 hi_bits = 0x00000000ul;
1492 /* Disable individual receive */
1493 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard);
1494 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
1496 /* MC mode, receive normal and MC packets */
1498 struct dev_mc_list *dmi = dev->mc_list;
1501 lo_bits = 0x00000000ul;
1502 hi_bits = 0x00000000ul;
1503 for (i=0; i<num_addr; i++) {
1504 /* Calculate the hash index for the GA registers */
1507 baddr = dmi->dmi_addr;
1508 hash_ix ^= (*baddr) & 0x3f;
1509 hash_ix ^= ((*baddr) >> 6) & 0x03;
1511 hash_ix ^= ((*baddr) << 2) & 0x03c;
1512 hash_ix ^= ((*baddr) >> 4) & 0xf;
1514 hash_ix ^= ((*baddr) << 4) & 0x30;
1515 hash_ix ^= ((*baddr) >> 2) & 0x3f;
1517 hash_ix ^= (*baddr) & 0x3f;
1518 hash_ix ^= ((*baddr) >> 6) & 0x03;
1520 hash_ix ^= ((*baddr) << 2) & 0x03c;
1521 hash_ix ^= ((*baddr) >> 4) & 0xf;
1523 hash_ix ^= ((*baddr) << 4) & 0x30;
1524 hash_ix ^= ((*baddr) >> 2) & 0x3f;
1528 if (hash_ix >= 32) {
1529 hi_bits |= (1 << (hash_ix-32));
1532 lo_bits |= (1 << hash_ix);
1536 /* Disable individual receive */
1537 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard);
1538 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
1540 *R_NETWORK_GA_0 = lo_bits;
1541 *R_NETWORK_GA_1 = hi_bits;
1542 spin_unlock(&lp->lock);
1546 e100_hardware_send_packet(char *buf, int length)
1548 D(printk("e100 send pack, buf 0x%x len %d\n", buf, length));
1550 if (!led_active && time_after(jiffies, led_next_time)) {
1551 /* light the network leds depending on the current speed. */
1552 e100_set_network_leds(NETWORK_ACTIVITY);
1554 /* Set the earliest time we may clear the LED */
1555 led_next_time = jiffies + NET_FLASH_TIME;
1557 mod_timer(&clear_led_timer, jiffies + HZ/10);
1560 /* configure the tx dma descriptor */
1561 myNextTxDesc->descr.sw_len = length;
1562 myNextTxDesc->descr.ctrl = d_eop | d_eol | d_wait;
1563 myNextTxDesc->descr.buf = virt_to_phys(buf);
1565 /* Move end of list */
1566 myLastTxDesc->descr.ctrl &= ~d_eol;
1567 myLastTxDesc = myNextTxDesc;
1569 /* Restart DMA channel */
1570 *R_DMA_CH0_CMD = IO_STATE(R_DMA_CH0_CMD, cmd, restart);
1574 e100_clear_network_leds(unsigned long dummy)
1576 if (led_active && time_after(jiffies, led_next_time)) {
1577 e100_set_network_leds(NO_NETWORK_ACTIVITY);
1579 /* Set the earliest time we may set the LED */
1580 led_next_time = jiffies + NET_FLASH_PAUSE;
1586 e100_set_network_leds(int active)
1588 #if defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK)
1589 int light_leds = (active == NO_NETWORK_ACTIVITY);
1590 #elif defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY)
1591 int light_leds = (active == NETWORK_ACTIVITY);
1593 #error "Define either CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK or CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY"
1596 if (!current_speed) {
1597 /* Make LED red, link is down */
1598 LED_NETWORK_SET(LED_OFF);
1600 else if (light_leds) {
1601 if (current_speed == 10) {
1602 LED_NETWORK_SET(LED_ORANGE);
1604 LED_NETWORK_SET(LED_GREEN);
1608 LED_NETWORK_SET(LED_OFF);
1613 etrax_init_module(void)
1615 return etrax_ethernet_init();
1618 module_init(etrax_init_module);