2 * e100net.c: A network driver for the ETRAX 100LX network controller.
4 * Copyright (c) 1998-2002 Axis Communications AB.
6 * The outline of this driver comes from skeleton.c.
11 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/delay.h>
15 #include <linux/types.h>
16 #include <linux/fcntl.h>
17 #include <linux/interrupt.h>
18 #include <linux/ptrace.h>
19 #include <linux/ioport.h>
21 #include <linux/slab.h>
22 #include <linux/string.h>
23 #include <linux/spinlock.h>
24 #include <linux/errno.h>
25 #include <linux/init.h>
26 #include <linux/bitops.h>
29 #include <linux/mii.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/skbuff.h>
33 #include <linux/ethtool.h>
35 #include <asm/arch/svinto.h>/* DMA and register descriptions */
36 #include <asm/io.h> /* CRIS_LED_* I/O functions */
39 #include <asm/system.h>
40 #include <asm/ethernet.h>
41 #include <asm/cache.h>
42 #include <asm/arch/io_interface_mux.h>
48 * The name of the card. Is used for messages and in the requests for
49 * io regions, irqs and dma channels
52 static const char* cardname
= "ETRAX 100LX built-in ethernet controller";
54 /* A default ethernet address. Highlevel SW will set the real one later */
56 static struct sockaddr default_mac
= {
58 { 0x00, 0x40, 0x8C, 0xCD, 0x00, 0x00 }
61 /* Information that need to be kept for each board. */
63 struct net_device_stats stats
;
64 struct mii_if_info mii_if
;
66 /* Tx control lock. This protects the transmit buffer ring
67 * state along with the "tx full" state of the driver. This
68 * means all netif_queue flow control actions are protected
69 * by this lock as well.
73 spinlock_t led_lock
; /* Protect LED state */
74 spinlock_t transceiver_lock
; /* Protect transceiver state. */
77 typedef struct etrax_eth_descr
79 etrax_dma_descr descr
;
83 /* Some transceivers requires special handling */
84 struct transceiver_ops
87 void (*check_speed
)(struct net_device
* dev
);
88 void (*check_duplex
)(struct net_device
* dev
);
99 /* Dma descriptors etc. */
101 #define MAX_MEDIA_DATA_SIZE 1522
103 #define MIN_PACKET_LEN 46
104 #define ETHER_HEAD_LEN 14
109 #define MDIO_START 0x1
110 #define MDIO_READ 0x2
111 #define MDIO_WRITE 0x1
112 #define MDIO_PREAMBLE 0xfffffffful
114 /* Broadcom specific */
115 #define MDIO_AUX_CTRL_STATUS_REG 0x18
116 #define MDIO_BC_FULL_DUPLEX_IND 0x1
117 #define MDIO_BC_SPEED 0x2
120 #define MDIO_TDK_DIAGNOSTIC_REG 18
121 #define MDIO_TDK_DIAGNOSTIC_RATE 0x400
122 #define MDIO_TDK_DIAGNOSTIC_DPLX 0x800
124 /*Intel LXT972A specific*/
125 #define MDIO_INT_STATUS_REG_2 0x0011
126 #define MDIO_INT_FULL_DUPLEX_IND (1 << 9)
127 #define MDIO_INT_SPEED (1 << 14)
129 /* Network flash constants */
130 #define NET_FLASH_TIME (HZ/50) /* 20 ms */
131 #define NET_FLASH_PAUSE (HZ/100) /* 10 ms */
132 #define NET_LINK_UP_CHECK_INTERVAL (2*HZ) /* 2 s */
133 #define NET_DUPLEX_CHECK_INTERVAL (2*HZ) /* 2 s */
135 #define NO_NETWORK_ACTIVITY 0
136 #define NETWORK_ACTIVITY 1
138 #define NBR_OF_RX_DESC 32
139 #define NBR_OF_TX_DESC 16
141 /* Large packets are sent directly to upper layers while small packets are */
142 /* copied (to reduce memory waste). The following constant decides the breakpoint */
143 #define RX_COPYBREAK 256
145 /* Due to a chip bug we need to flush the cache when descriptors are returned */
146 /* to the DMA. To decrease performance impact we return descriptors in chunks. */
147 /* The following constant determines the number of descriptors to return. */
148 #define RX_QUEUE_THRESHOLD NBR_OF_RX_DESC/2
150 #define GET_BIT(bit,val) (((val) >> (bit)) & 0x01)
152 /* Define some macros to access ETRAX 100 registers */
153 #define SETF(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \
154 IO_FIELD_(reg##_, field##_, val)
155 #define SETS(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \
156 IO_STATE_(reg##_, field##_, _##val)
158 static etrax_eth_descr
*myNextRxDesc
; /* Points to the next descriptor to
160 static etrax_eth_descr
*myLastRxDesc
; /* The last processed descriptor */
162 static etrax_eth_descr RxDescList
[NBR_OF_RX_DESC
] __attribute__ ((aligned(32)));
164 static etrax_eth_descr
* myFirstTxDesc
; /* First packet not yet sent */
165 static etrax_eth_descr
* myLastTxDesc
; /* End of send queue */
166 static etrax_eth_descr
* myNextTxDesc
; /* Next descriptor to use */
167 static etrax_eth_descr TxDescList
[NBR_OF_TX_DESC
] __attribute__ ((aligned(32)));
169 static unsigned int network_rec_config_shadow
= 0;
171 static unsigned int network_tr_ctrl_shadow
= 0;
173 /* Network speed indication. */
174 static DEFINE_TIMER(speed_timer
, NULL
, 0, 0);
175 static DEFINE_TIMER(clear_led_timer
, NULL
, 0, 0);
176 static int current_speed
; /* Speed read from transceiver */
177 static int current_speed_selection
; /* Speed selected by user */
178 static unsigned long led_next_time
;
179 static int led_active
;
180 static int rx_queue_len
;
183 static DEFINE_TIMER(duplex_timer
, NULL
, 0, 0);
184 static int full_duplex
;
185 static enum duplex current_duplex
;
187 /* Index to functions, as function prototypes. */
189 static int etrax_ethernet_init(void);
191 static int e100_open(struct net_device
*dev
);
192 static int e100_set_mac_address(struct net_device
*dev
, void *addr
);
193 static int e100_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
194 static irqreturn_t
e100rxtx_interrupt(int irq
, void *dev_id
);
195 static irqreturn_t
e100nw_interrupt(int irq
, void *dev_id
);
196 static void e100_rx(struct net_device
*dev
);
197 static int e100_close(struct net_device
*dev
);
198 static int e100_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
199 static int e100_set_config(struct net_device
* dev
, struct ifmap
* map
);
200 static void e100_tx_timeout(struct net_device
*dev
);
201 static struct net_device_stats
*e100_get_stats(struct net_device
*dev
);
202 static void set_multicast_list(struct net_device
*dev
);
203 static void e100_hardware_send_packet(struct net_local
* np
, char *buf
, int length
);
204 static void update_rx_stats(struct net_device_stats
*);
205 static void update_tx_stats(struct net_device_stats
*);
206 static int e100_probe_transceiver(struct net_device
* dev
);
208 static void e100_check_speed(unsigned long priv
);
209 static void e100_set_speed(struct net_device
* dev
, unsigned long speed
);
210 static void e100_check_duplex(unsigned long priv
);
211 static void e100_set_duplex(struct net_device
* dev
, enum duplex
);
212 static void e100_negotiate(struct net_device
* dev
);
214 static int e100_get_mdio_reg(struct net_device
*dev
, int phy_id
, int location
);
215 static void e100_set_mdio_reg(struct net_device
*dev
, int phy_id
, int location
, int value
);
217 static void e100_send_mdio_cmd(unsigned short cmd
, int write_cmd
);
218 static void e100_send_mdio_bit(unsigned char bit
);
219 static unsigned char e100_receive_mdio_bit(void);
220 static void e100_reset_transceiver(struct net_device
* net
);
222 static void e100_clear_network_leds(unsigned long dummy
);
223 static void e100_set_network_leds(int active
);
225 static const struct ethtool_ops e100_ethtool_ops
;
226 #if defined(CONFIG_ETRAX_NO_PHY)
227 static void dummy_check_speed(struct net_device
* dev
);
228 static void dummy_check_duplex(struct net_device
* dev
);
230 static void broadcom_check_speed(struct net_device
* dev
);
231 static void broadcom_check_duplex(struct net_device
* dev
);
232 static void tdk_check_speed(struct net_device
* dev
);
233 static void tdk_check_duplex(struct net_device
* dev
);
234 static void intel_check_speed(struct net_device
* dev
);
235 static void intel_check_duplex(struct net_device
* dev
);
236 static void generic_check_speed(struct net_device
* dev
);
237 static void generic_check_duplex(struct net_device
* dev
);
239 #ifdef CONFIG_NET_POLL_CONTROLLER
240 static void e100_netpoll(struct net_device
* dev
);
243 static int autoneg_normal
= 1;
245 struct transceiver_ops transceivers
[] =
247 #if defined(CONFIG_ETRAX_NO_PHY)
248 {0x0000, dummy_check_speed
, dummy_check_duplex
} /* Dummy */
250 {0x1018, broadcom_check_speed
, broadcom_check_duplex
}, /* Broadcom */
251 {0xC039, tdk_check_speed
, tdk_check_duplex
}, /* TDK 2120 */
252 {0x039C, tdk_check_speed
, tdk_check_duplex
}, /* TDK 2120C */
253 {0x04de, intel_check_speed
, intel_check_duplex
}, /* Intel LXT972A*/
254 {0x0000, generic_check_speed
, generic_check_duplex
} /* Generic, must be last */
258 struct transceiver_ops
* transceiver
= &transceivers
[0];
260 #define tx_done(dev) (*R_DMA_CH0_CMD == 0)
263 * Check for a network adaptor of this type, and return '0' if one exists.
264 * If dev->base_addr == 0, probe all likely locations.
265 * If dev->base_addr == 1, always return failure.
266 * If dev->base_addr == 2, allocate space for the device and return success
267 * (detachable devices only).
271 etrax_ethernet_init(void)
273 struct net_device
*dev
;
274 struct net_local
* np
;
278 "ETRAX 100LX 10/100MBit ethernet v2.0 (c) 1998-2007 Axis Communications AB\n");
280 if (cris_request_io_interface(if_eth
, cardname
)) {
281 printk(KERN_CRIT
"etrax_ethernet_init failed to get IO interface\n");
285 dev
= alloc_etherdev(sizeof(struct net_local
));
289 np
= netdev_priv(dev
);
291 /* we do our own locking */
292 dev
->features
|= NETIF_F_LLTX
;
294 dev
->base_addr
= (unsigned int)R_NETWORK_SA_0
; /* just to have something to show */
296 /* now setup our etrax specific stuff */
298 dev
->irq
= NETWORK_DMA_RX_IRQ_NBR
; /* we really use DMATX as well... */
299 dev
->dma
= NETWORK_RX_DMA_NBR
;
301 /* fill in our handlers so the network layer can talk to us in the future */
303 dev
->open
= e100_open
;
304 dev
->hard_start_xmit
= e100_send_packet
;
305 dev
->stop
= e100_close
;
306 dev
->get_stats
= e100_get_stats
;
307 dev
->set_multicast_list
= set_multicast_list
;
308 dev
->set_mac_address
= e100_set_mac_address
;
309 dev
->ethtool_ops
= &e100_ethtool_ops
;
310 dev
->do_ioctl
= e100_ioctl
;
311 dev
->set_config
= e100_set_config
;
312 dev
->tx_timeout
= e100_tx_timeout
;
313 #ifdef CONFIG_NET_POLL_CONTROLLER
314 dev
->poll_controller
= e100_netpoll
;
317 spin_lock_init(&np
->lock
);
318 spin_lock_init(&np
->led_lock
);
319 spin_lock_init(&np
->transceiver_lock
);
321 /* Initialise the list of Etrax DMA-descriptors */
323 /* Initialise receive descriptors */
325 for (i
= 0; i
< NBR_OF_RX_DESC
; i
++) {
326 /* Allocate two extra cachelines to make sure that buffer used
327 * by DMA does not share cacheline with any other data (to
330 RxDescList
[i
].skb
= dev_alloc_skb(MAX_MEDIA_DATA_SIZE
+ 2 * L1_CACHE_BYTES
);
331 if (!RxDescList
[i
].skb
)
333 RxDescList
[i
].descr
.ctrl
= 0;
334 RxDescList
[i
].descr
.sw_len
= MAX_MEDIA_DATA_SIZE
;
335 RxDescList
[i
].descr
.next
= virt_to_phys(&RxDescList
[i
+ 1]);
336 RxDescList
[i
].descr
.buf
= L1_CACHE_ALIGN(virt_to_phys(RxDescList
[i
].skb
->data
));
337 RxDescList
[i
].descr
.status
= 0;
338 RxDescList
[i
].descr
.hw_len
= 0;
339 prepare_rx_descriptor(&RxDescList
[i
].descr
);
342 RxDescList
[NBR_OF_RX_DESC
- 1].descr
.ctrl
= d_eol
;
343 RxDescList
[NBR_OF_RX_DESC
- 1].descr
.next
= virt_to_phys(&RxDescList
[0]);
346 /* Initialize transmit descriptors */
347 for (i
= 0; i
< NBR_OF_TX_DESC
; i
++) {
348 TxDescList
[i
].descr
.ctrl
= 0;
349 TxDescList
[i
].descr
.sw_len
= 0;
350 TxDescList
[i
].descr
.next
= virt_to_phys(&TxDescList
[i
+ 1].descr
);
351 TxDescList
[i
].descr
.buf
= 0;
352 TxDescList
[i
].descr
.status
= 0;
353 TxDescList
[i
].descr
.hw_len
= 0;
354 TxDescList
[i
].skb
= 0;
357 TxDescList
[NBR_OF_TX_DESC
- 1].descr
.ctrl
= d_eol
;
358 TxDescList
[NBR_OF_TX_DESC
- 1].descr
.next
= virt_to_phys(&TxDescList
[0].descr
);
360 /* Initialise initial pointers */
362 myNextRxDesc
= &RxDescList
[0];
363 myLastRxDesc
= &RxDescList
[NBR_OF_RX_DESC
- 1];
364 myFirstTxDesc
= &TxDescList
[0];
365 myNextTxDesc
= &TxDescList
[0];
366 myLastTxDesc
= &TxDescList
[NBR_OF_TX_DESC
- 1];
368 /* Register device */
369 err
= register_netdev(dev
);
375 /* set the default MAC address */
377 e100_set_mac_address(dev
, &default_mac
);
379 /* Initialize speed indicator stuff. */
382 current_speed_selection
= 0; /* Auto */
383 speed_timer
.expires
= jiffies
+ NET_LINK_UP_CHECK_INTERVAL
;
384 speed_timer
.data
= (unsigned long)dev
;
385 speed_timer
.function
= e100_check_speed
;
387 clear_led_timer
.function
= e100_clear_network_leds
;
388 clear_led_timer
.data
= (unsigned long)dev
;
391 current_duplex
= autoneg
;
392 duplex_timer
.expires
= jiffies
+ NET_DUPLEX_CHECK_INTERVAL
;
393 duplex_timer
.data
= (unsigned long)dev
;
394 duplex_timer
.function
= e100_check_duplex
;
396 /* Initialize mii interface */
397 np
->mii_if
.phy_id_mask
= 0x1f;
398 np
->mii_if
.reg_num_mask
= 0x1f;
399 np
->mii_if
.dev
= dev
;
400 np
->mii_if
.mdio_read
= e100_get_mdio_reg
;
401 np
->mii_if
.mdio_write
= e100_set_mdio_reg
;
403 /* Initialize group address registers to make sure that no */
404 /* unwanted addresses are matched */
405 *R_NETWORK_GA_0
= 0x00000000;
406 *R_NETWORK_GA_1
= 0x00000000;
408 /* Initialize next time the led can flash */
409 led_next_time
= jiffies
;
413 /* set MAC address of the interface. called from the core after a
414 * SIOCSIFADDR ioctl, and from the bootup above.
418 e100_set_mac_address(struct net_device
*dev
, void *p
)
420 struct net_local
*np
= netdev_priv(dev
);
421 struct sockaddr
*addr
= p
;
422 DECLARE_MAC_BUF(mac
);
424 spin_lock(&np
->lock
); /* preemption protection */
428 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
430 /* Write it to the hardware.
431 * Note the way the address is wrapped:
432 * *R_NETWORK_SA_0 = a0_0 | (a0_1 << 8) | (a0_2 << 16) | (a0_3 << 24);
433 * *R_NETWORK_SA_1 = a0_4 | (a0_5 << 8);
436 *R_NETWORK_SA_0
= dev
->dev_addr
[0] | (dev
->dev_addr
[1] << 8) |
437 (dev
->dev_addr
[2] << 16) | (dev
->dev_addr
[3] << 24);
438 *R_NETWORK_SA_1
= dev
->dev_addr
[4] | (dev
->dev_addr
[5] << 8);
441 /* show it in the log as well */
443 printk(KERN_INFO
"%s: changed MAC to %s\n",
444 dev
->name
, print_mac(mac
, dev
->dev_addr
));
446 spin_unlock(&np
->lock
);
452 * Open/initialize the board. This is called (in the current kernel)
453 * sometime after booting when the 'ifconfig' program is run.
455 * This routine should set everything up anew at each open, even
456 * registers that "should" only need to be set once at boot, so that
457 * there is non-reboot way to recover if something goes wrong.
461 e100_open(struct net_device
*dev
)
465 /* enable the MDIO output pin */
467 *R_NETWORK_MGM_CTRL
= IO_STATE(R_NETWORK_MGM_CTRL
, mdoe
, enable
);
470 IO_STATE(R_IRQ_MASK0_CLR
, overrun
, clr
) |
471 IO_STATE(R_IRQ_MASK0_CLR
, underrun
, clr
) |
472 IO_STATE(R_IRQ_MASK0_CLR
, excessive_col
, clr
);
474 /* clear dma0 and 1 eop and descr irq masks */
476 IO_STATE(R_IRQ_MASK2_CLR
, dma0_descr
, clr
) |
477 IO_STATE(R_IRQ_MASK2_CLR
, dma0_eop
, clr
) |
478 IO_STATE(R_IRQ_MASK2_CLR
, dma1_descr
, clr
) |
479 IO_STATE(R_IRQ_MASK2_CLR
, dma1_eop
, clr
);
481 /* Reset and wait for the DMA channels */
483 RESET_DMA(NETWORK_TX_DMA_NBR
);
484 RESET_DMA(NETWORK_RX_DMA_NBR
);
485 WAIT_DMA(NETWORK_TX_DMA_NBR
);
486 WAIT_DMA(NETWORK_RX_DMA_NBR
);
488 /* Initialise the etrax network controller */
490 /* allocate the irq corresponding to the receiving DMA */
492 if (request_irq(NETWORK_DMA_RX_IRQ_NBR
, e100rxtx_interrupt
,
493 IRQF_SAMPLE_RANDOM
, cardname
, (void *)dev
)) {
497 /* allocate the irq corresponding to the transmitting DMA */
499 if (request_irq(NETWORK_DMA_TX_IRQ_NBR
, e100rxtx_interrupt
, 0,
500 cardname
, (void *)dev
)) {
504 /* allocate the irq corresponding to the network errors etc */
506 if (request_irq(NETWORK_STATUS_IRQ_NBR
, e100nw_interrupt
, 0,
507 cardname
, (void *)dev
)) {
512 * Always allocate the DMA channels after the IRQ,
513 * and clean up on failure.
516 if (cris_request_dma(NETWORK_TX_DMA_NBR
,
518 DMA_VERBOSE_ON_ERROR
,
523 if (cris_request_dma(NETWORK_RX_DMA_NBR
,
525 DMA_VERBOSE_ON_ERROR
,
530 /* give the HW an idea of what MAC address we want */
532 *R_NETWORK_SA_0
= dev
->dev_addr
[0] | (dev
->dev_addr
[1] << 8) |
533 (dev
->dev_addr
[2] << 16) | (dev
->dev_addr
[3] << 24);
534 *R_NETWORK_SA_1
= dev
->dev_addr
[4] | (dev
->dev_addr
[5] << 8);
538 /* use promiscuous mode for testing */
539 *R_NETWORK_GA_0
= 0xffffffff;
540 *R_NETWORK_GA_1
= 0xffffffff;
542 *R_NETWORK_REC_CONFIG
= 0xd; /* broadcast rec, individ. rec, ma0 enabled */
544 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, max_size
, size1522
);
545 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, broadcast
, receive
);
546 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, ma0
, enable
);
547 SETF(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, duplex
, full_duplex
);
548 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
551 *R_NETWORK_GEN_CONFIG
=
552 IO_STATE(R_NETWORK_GEN_CONFIG
, phy
, mii_clk
) |
553 IO_STATE(R_NETWORK_GEN_CONFIG
, enable
, on
);
555 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, clr
);
556 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, delay
, none
);
557 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, cancel
, dont
);
558 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, cd
, enable
);
559 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, retry
, enable
);
560 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, pad
, enable
);
561 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, crc
, enable
);
562 *R_NETWORK_TR_CTRL
= network_tr_ctrl_shadow
;
564 local_irq_save(flags
);
566 /* enable the irq's for ethernet DMA */
569 IO_STATE(R_IRQ_MASK2_SET
, dma0_eop
, set
) |
570 IO_STATE(R_IRQ_MASK2_SET
, dma1_eop
, set
);
573 IO_STATE(R_IRQ_MASK0_SET
, overrun
, set
) |
574 IO_STATE(R_IRQ_MASK0_SET
, underrun
, set
) |
575 IO_STATE(R_IRQ_MASK0_SET
, excessive_col
, set
);
577 /* make sure the irqs are cleared */
579 *R_DMA_CH0_CLR_INTR
= IO_STATE(R_DMA_CH0_CLR_INTR
, clr_eop
, do);
580 *R_DMA_CH1_CLR_INTR
= IO_STATE(R_DMA_CH1_CLR_INTR
, clr_eop
, do);
582 /* make sure the rec and transmit error counters are cleared */
584 (void)*R_REC_COUNTERS
; /* dummy read */
585 (void)*R_TR_COUNTERS
; /* dummy read */
587 /* start the receiving DMA channel so we can receive packets from now on */
589 *R_DMA_CH1_FIRST
= virt_to_phys(myNextRxDesc
);
590 *R_DMA_CH1_CMD
= IO_STATE(R_DMA_CH1_CMD
, cmd
, start
);
592 /* Set up transmit DMA channel so it can be restarted later */
594 *R_DMA_CH0_FIRST
= 0;
595 *R_DMA_CH0_DESCR
= virt_to_phys(myLastTxDesc
);
596 netif_start_queue(dev
);
598 local_irq_restore(flags
);
600 /* Probe for transceiver */
601 if (e100_probe_transceiver(dev
))
604 /* Start duplex/speed timers */
605 add_timer(&speed_timer
);
606 add_timer(&duplex_timer
);
608 /* We are now ready to accept transmit requeusts from
609 * the queueing layer of the networking.
611 netif_carrier_on(dev
);
616 cris_free_dma(NETWORK_RX_DMA_NBR
, cardname
);
618 cris_free_dma(NETWORK_TX_DMA_NBR
, cardname
);
620 free_irq(NETWORK_STATUS_IRQ_NBR
, (void *)dev
);
622 free_irq(NETWORK_DMA_TX_IRQ_NBR
, (void *)dev
);
624 free_irq(NETWORK_DMA_RX_IRQ_NBR
, (void *)dev
);
629 #if defined(CONFIG_ETRAX_NO_PHY)
631 dummy_check_speed(struct net_device
* dev
)
637 generic_check_speed(struct net_device
* dev
)
640 struct net_local
*np
= netdev_priv(dev
);
642 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_ADVERTISE
);
643 if ((data
& ADVERTISE_100FULL
) ||
644 (data
& ADVERTISE_100HALF
))
651 tdk_check_speed(struct net_device
* dev
)
654 struct net_local
*np
= netdev_priv(dev
);
656 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
657 MDIO_TDK_DIAGNOSTIC_REG
);
658 current_speed
= (data
& MDIO_TDK_DIAGNOSTIC_RATE
? 100 : 10);
662 broadcom_check_speed(struct net_device
* dev
)
665 struct net_local
*np
= netdev_priv(dev
);
667 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
668 MDIO_AUX_CTRL_STATUS_REG
);
669 current_speed
= (data
& MDIO_BC_SPEED
? 100 : 10);
673 intel_check_speed(struct net_device
* dev
)
676 struct net_local
*np
= netdev_priv(dev
);
678 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
679 MDIO_INT_STATUS_REG_2
);
680 current_speed
= (data
& MDIO_INT_SPEED
? 100 : 10);
684 e100_check_speed(unsigned long priv
)
686 struct net_device
* dev
= (struct net_device
*)priv
;
687 struct net_local
*np
= netdev_priv(dev
);
688 static int led_initiated
= 0;
690 int old_speed
= current_speed
;
692 spin_lock(&np
->transceiver_lock
);
694 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_BMSR
);
695 if (!(data
& BMSR_LSTATUS
)) {
698 transceiver
->check_speed(dev
);
701 spin_lock(&np
->led_lock
);
702 if ((old_speed
!= current_speed
) || !led_initiated
) {
704 e100_set_network_leds(NO_NETWORK_ACTIVITY
);
706 netif_carrier_on(dev
);
708 netif_carrier_off(dev
);
710 spin_unlock(&np
->led_lock
);
712 /* Reinitialize the timer. */
713 speed_timer
.expires
= jiffies
+ NET_LINK_UP_CHECK_INTERVAL
;
714 add_timer(&speed_timer
);
716 spin_unlock(&np
->transceiver_lock
);
720 e100_negotiate(struct net_device
* dev
)
722 struct net_local
*np
= netdev_priv(dev
);
723 unsigned short data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
726 /* Discard old speed and duplex settings */
727 data
&= ~(ADVERTISE_100HALF
| ADVERTISE_100FULL
|
728 ADVERTISE_10HALF
| ADVERTISE_10FULL
);
730 switch (current_speed_selection
) {
732 if (current_duplex
== full
)
733 data
|= ADVERTISE_10FULL
;
734 else if (current_duplex
== half
)
735 data
|= ADVERTISE_10HALF
;
737 data
|= ADVERTISE_10HALF
| ADVERTISE_10FULL
;
741 if (current_duplex
== full
)
742 data
|= ADVERTISE_100FULL
;
743 else if (current_duplex
== half
)
744 data
|= ADVERTISE_100HALF
;
746 data
|= ADVERTISE_100HALF
| ADVERTISE_100FULL
;
750 if (current_duplex
== full
)
751 data
|= ADVERTISE_100FULL
| ADVERTISE_10FULL
;
752 else if (current_duplex
== half
)
753 data
|= ADVERTISE_100HALF
| ADVERTISE_10HALF
;
755 data
|= ADVERTISE_10HALF
| ADVERTISE_10FULL
|
756 ADVERTISE_100HALF
| ADVERTISE_100FULL
;
759 default: /* assume autoneg speed and duplex */
760 data
|= ADVERTISE_10HALF
| ADVERTISE_10FULL
|
761 ADVERTISE_100HALF
| ADVERTISE_100FULL
;
765 e100_set_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_ADVERTISE
, data
);
767 /* Renegotiate with link partner */
768 if (autoneg_normal
) {
769 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_BMCR
);
770 data
|= BMCR_ANENABLE
| BMCR_ANRESTART
;
772 e100_set_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_BMCR
, data
);
776 e100_set_speed(struct net_device
* dev
, unsigned long speed
)
778 struct net_local
*np
= netdev_priv(dev
);
780 spin_lock(&np
->transceiver_lock
);
781 if (speed
!= current_speed_selection
) {
782 current_speed_selection
= speed
;
785 spin_unlock(&np
->transceiver_lock
);
789 e100_check_duplex(unsigned long priv
)
791 struct net_device
*dev
= (struct net_device
*)priv
;
792 struct net_local
*np
= netdev_priv(dev
);
795 spin_lock(&np
->transceiver_lock
);
796 old_duplex
= full_duplex
;
797 transceiver
->check_duplex(dev
);
798 if (old_duplex
!= full_duplex
) {
800 SETF(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, duplex
, full_duplex
);
801 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
804 /* Reinitialize the timer. */
805 duplex_timer
.expires
= jiffies
+ NET_DUPLEX_CHECK_INTERVAL
;
806 add_timer(&duplex_timer
);
807 np
->mii_if
.full_duplex
= full_duplex
;
808 spin_unlock(&np
->transceiver_lock
);
810 #if defined(CONFIG_ETRAX_NO_PHY)
812 dummy_check_duplex(struct net_device
* dev
)
818 generic_check_duplex(struct net_device
* dev
)
821 struct net_local
*np
= netdev_priv(dev
);
823 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_ADVERTISE
);
824 if ((data
& ADVERTISE_10FULL
) ||
825 (data
& ADVERTISE_100FULL
))
832 tdk_check_duplex(struct net_device
* dev
)
835 struct net_local
*np
= netdev_priv(dev
);
837 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
838 MDIO_TDK_DIAGNOSTIC_REG
);
839 full_duplex
= (data
& MDIO_TDK_DIAGNOSTIC_DPLX
) ? 1 : 0;
843 broadcom_check_duplex(struct net_device
* dev
)
846 struct net_local
*np
= netdev_priv(dev
);
848 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
849 MDIO_AUX_CTRL_STATUS_REG
);
850 full_duplex
= (data
& MDIO_BC_FULL_DUPLEX_IND
) ? 1 : 0;
854 intel_check_duplex(struct net_device
* dev
)
857 struct net_local
*np
= netdev_priv(dev
);
859 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
860 MDIO_INT_STATUS_REG_2
);
861 full_duplex
= (data
& MDIO_INT_FULL_DUPLEX_IND
) ? 1 : 0;
865 e100_set_duplex(struct net_device
* dev
, enum duplex new_duplex
)
867 struct net_local
*np
= netdev_priv(dev
);
869 spin_lock(&np
->transceiver_lock
);
870 if (new_duplex
!= current_duplex
) {
871 current_duplex
= new_duplex
;
874 spin_unlock(&np
->transceiver_lock
);
878 e100_probe_transceiver(struct net_device
* dev
)
882 #if !defined(CONFIG_ETRAX_NO_PHY)
883 unsigned int phyid_high
;
884 unsigned int phyid_low
;
886 struct transceiver_ops
* ops
= NULL
;
887 struct net_local
*np
= netdev_priv(dev
);
889 spin_lock(&np
->transceiver_lock
);
891 /* Probe MDIO physical address */
892 for (np
->mii_if
.phy_id
= 0; np
->mii_if
.phy_id
<= 31;
893 np
->mii_if
.phy_id
++) {
894 if (e100_get_mdio_reg(dev
,
895 np
->mii_if
.phy_id
, MII_BMSR
) != 0xffff)
898 if (np
->mii_if
.phy_id
== 32) {
903 /* Get manufacturer */
904 phyid_high
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_PHYSID1
);
905 phyid_low
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_PHYSID2
);
906 oui
= (phyid_high
<< 6) | (phyid_low
>> 10);
908 for (ops
= &transceivers
[0]; ops
->oui
; ops
++) {
914 spin_unlock(&np
->transceiver_lock
);
920 e100_get_mdio_reg(struct net_device
*dev
, int phy_id
, int location
)
922 unsigned short cmd
; /* Data to be sent on MDIO port */
923 int data
; /* Data read from MDIO */
926 /* Start of frame, OP Code, Physical Address, Register Address */
927 cmd
= (MDIO_START
<< 14) | (MDIO_READ
<< 12) | (phy_id
<< 7) |
930 e100_send_mdio_cmd(cmd
, 0);
935 for (bitCounter
=15; bitCounter
>=0 ; bitCounter
--) {
936 data
|= (e100_receive_mdio_bit() << bitCounter
);
943 e100_set_mdio_reg(struct net_device
*dev
, int phy_id
, int location
, int value
)
948 cmd
= (MDIO_START
<< 14) | (MDIO_WRITE
<< 12) | (phy_id
<< 7) |
951 e100_send_mdio_cmd(cmd
, 1);
954 for (bitCounter
=15; bitCounter
>=0 ; bitCounter
--) {
955 e100_send_mdio_bit(GET_BIT(bitCounter
, value
));
961 e100_send_mdio_cmd(unsigned short cmd
, int write_cmd
)
964 unsigned char data
= 0x2;
967 for (bitCounter
= 31; bitCounter
>= 0; bitCounter
--)
968 e100_send_mdio_bit(GET_BIT(bitCounter
, MDIO_PREAMBLE
));
970 for (bitCounter
= 15; bitCounter
>= 2; bitCounter
--)
971 e100_send_mdio_bit(GET_BIT(bitCounter
, cmd
));
974 for (bitCounter
= 1; bitCounter
>= 0 ; bitCounter
--)
976 e100_send_mdio_bit(GET_BIT(bitCounter
, data
));
978 e100_receive_mdio_bit();
982 e100_send_mdio_bit(unsigned char bit
)
984 *R_NETWORK_MGM_CTRL
=
985 IO_STATE(R_NETWORK_MGM_CTRL
, mdoe
, enable
) |
986 IO_FIELD(R_NETWORK_MGM_CTRL
, mdio
, bit
);
988 *R_NETWORK_MGM_CTRL
=
989 IO_STATE(R_NETWORK_MGM_CTRL
, mdoe
, enable
) |
990 IO_MASK(R_NETWORK_MGM_CTRL
, mdck
) |
991 IO_FIELD(R_NETWORK_MGM_CTRL
, mdio
, bit
);
996 e100_receive_mdio_bit()
999 *R_NETWORK_MGM_CTRL
= 0;
1000 bit
= IO_EXTRACT(R_NETWORK_STAT
, mdio
, *R_NETWORK_STAT
);
1002 *R_NETWORK_MGM_CTRL
= IO_MASK(R_NETWORK_MGM_CTRL
, mdck
);
1008 e100_reset_transceiver(struct net_device
* dev
)
1010 struct net_local
*np
= netdev_priv(dev
);
1012 unsigned short data
;
1015 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_BMCR
);
1017 cmd
= (MDIO_START
<< 14) | (MDIO_WRITE
<< 12) | (np
->mii_if
.phy_id
<< 7) | (MII_BMCR
<< 2);
1019 e100_send_mdio_cmd(cmd
, 1);
1023 for (bitCounter
= 15; bitCounter
>= 0 ; bitCounter
--) {
1024 e100_send_mdio_bit(GET_BIT(bitCounter
, data
));
1028 /* Called by upper layers if they decide it took too long to complete
1029 * sending a packet - we need to reset and stuff.
1033 e100_tx_timeout(struct net_device
*dev
)
1035 struct net_local
*np
= netdev_priv(dev
);
1036 unsigned long flags
;
1038 spin_lock_irqsave(&np
->lock
, flags
);
1040 printk(KERN_WARNING
"%s: transmit timed out, %s?\n", dev
->name
,
1041 tx_done(dev
) ? "IRQ problem" : "network cable problem");
1043 /* remember we got an error */
1045 np
->stats
.tx_errors
++;
1047 /* reset the TX DMA in case it has hung on something */
1049 RESET_DMA(NETWORK_TX_DMA_NBR
);
1050 WAIT_DMA(NETWORK_TX_DMA_NBR
);
1052 /* Reset the transceiver. */
1054 e100_reset_transceiver(dev
);
1056 /* and get rid of the packets that never got an interrupt */
1057 while (myFirstTxDesc
!= myNextTxDesc
) {
1058 dev_kfree_skb(myFirstTxDesc
->skb
);
1059 myFirstTxDesc
->skb
= 0;
1060 myFirstTxDesc
= phys_to_virt(myFirstTxDesc
->descr
.next
);
1063 /* Set up transmit DMA channel so it can be restarted later */
1064 *R_DMA_CH0_FIRST
= 0;
1065 *R_DMA_CH0_DESCR
= virt_to_phys(myLastTxDesc
);
1067 /* tell the upper layers we're ok again */
1069 netif_wake_queue(dev
);
1070 spin_unlock_irqrestore(&np
->lock
, flags
);
1074 /* This will only be invoked if the driver is _not_ in XOFF state.
1075 * What this means is that we need not check it, and that this
1076 * invariant will hold if we make sure that the netif_*_queue()
1077 * calls are done at the proper times.
1081 e100_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1083 struct net_local
*np
= netdev_priv(dev
);
1084 unsigned char *buf
= skb
->data
;
1085 unsigned long flags
;
1088 printk("send packet len %d\n", length
);
1090 spin_lock_irqsave(&np
->lock
, flags
); /* protect from tx_interrupt and ourself */
1092 myNextTxDesc
->skb
= skb
;
1094 dev
->trans_start
= jiffies
;
1096 e100_hardware_send_packet(np
, buf
, skb
->len
);
1098 myNextTxDesc
= phys_to_virt(myNextTxDesc
->descr
.next
);
1100 /* Stop queue if full */
1101 if (myNextTxDesc
== myFirstTxDesc
) {
1102 netif_stop_queue(dev
);
1105 spin_unlock_irqrestore(&np
->lock
, flags
);
1111 * The typical workload of the driver:
1112 * Handle the network interface interrupts.
1116 e100rxtx_interrupt(int irq
, void *dev_id
)
1118 struct net_device
*dev
= (struct net_device
*)dev_id
;
1119 struct net_local
*np
= netdev_priv(dev
);
1120 unsigned long irqbits
;
1123 * Note that both rx and tx interrupts are blocked at this point,
1124 * regardless of which got us here.
1127 irqbits
= *R_IRQ_MASK2_RD
;
1129 /* Handle received packets */
1130 if (irqbits
& IO_STATE(R_IRQ_MASK2_RD
, dma1_eop
, active
)) {
1131 /* acknowledge the eop interrupt */
1133 *R_DMA_CH1_CLR_INTR
= IO_STATE(R_DMA_CH1_CLR_INTR
, clr_eop
, do);
1135 /* check if one or more complete packets were indeed received */
1137 while ((*R_DMA_CH1_FIRST
!= virt_to_phys(myNextRxDesc
)) &&
1138 (myNextRxDesc
!= myLastRxDesc
)) {
1139 /* Take out the buffer and give it to the OS, then
1140 * allocate a new buffer to put a packet in.
1143 np
->stats
.rx_packets
++;
1144 /* restart/continue on the channel, for safety */
1145 *R_DMA_CH1_CMD
= IO_STATE(R_DMA_CH1_CMD
, cmd
, restart
);
1146 /* clear dma channel 1 eop/descr irq bits */
1147 *R_DMA_CH1_CLR_INTR
=
1148 IO_STATE(R_DMA_CH1_CLR_INTR
, clr_eop
, do) |
1149 IO_STATE(R_DMA_CH1_CLR_INTR
, clr_descr
, do);
1151 /* now, we might have gotten another packet
1152 so we have to loop back and check if so */
1156 /* Report any packets that have been sent */
1157 while (virt_to_phys(myFirstTxDesc
) != *R_DMA_CH0_FIRST
&&
1158 (netif_queue_stopped(dev
) || myFirstTxDesc
!= myNextTxDesc
)) {
1159 np
->stats
.tx_bytes
+= myFirstTxDesc
->skb
->len
;
1160 np
->stats
.tx_packets
++;
1162 /* dma is ready with the transmission of the data in tx_skb, so now
1163 we can release the skb memory */
1164 dev_kfree_skb_irq(myFirstTxDesc
->skb
);
1165 myFirstTxDesc
->skb
= 0;
1166 myFirstTxDesc
= phys_to_virt(myFirstTxDesc
->descr
.next
);
1167 /* Wake up queue. */
1168 netif_wake_queue(dev
);
1171 if (irqbits
& IO_STATE(R_IRQ_MASK2_RD
, dma0_eop
, active
)) {
1172 /* acknowledge the eop interrupt. */
1173 *R_DMA_CH0_CLR_INTR
= IO_STATE(R_DMA_CH0_CLR_INTR
, clr_eop
, do);
1180 e100nw_interrupt(int irq
, void *dev_id
)
1182 struct net_device
*dev
= (struct net_device
*)dev_id
;
1183 struct net_local
*np
= netdev_priv(dev
);
1184 unsigned long irqbits
= *R_IRQ_MASK0_RD
;
1186 /* check for underrun irq */
1187 if (irqbits
& IO_STATE(R_IRQ_MASK0_RD
, underrun
, active
)) {
1188 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, clr
);
1189 *R_NETWORK_TR_CTRL
= network_tr_ctrl_shadow
;
1190 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, nop
);
1191 np
->stats
.tx_errors
++;
1192 D(printk("ethernet receiver underrun!\n"));
1195 /* check for overrun irq */
1196 if (irqbits
& IO_STATE(R_IRQ_MASK0_RD
, overrun
, active
)) {
1197 update_rx_stats(&np
->stats
); /* this will ack the irq */
1198 D(printk("ethernet receiver overrun!\n"));
1200 /* check for excessive collision irq */
1201 if (irqbits
& IO_STATE(R_IRQ_MASK0_RD
, excessive_col
, active
)) {
1202 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, clr
);
1203 *R_NETWORK_TR_CTRL
= network_tr_ctrl_shadow
;
1204 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, nop
);
1205 np
->stats
.tx_errors
++;
1206 D(printk("ethernet excessive collisions!\n"));
1211 /* We have a good packet(s), get it/them out of the buffers. */
1213 e100_rx(struct net_device
*dev
)
1215 struct sk_buff
*skb
;
1217 struct net_local
*np
= netdev_priv(dev
);
1218 unsigned char *skb_data_ptr
;
1222 etrax_eth_descr
*prevRxDesc
; /* The descriptor right before myNextRxDesc */
1223 spin_lock(&np
->led_lock
);
1224 if (!led_active
&& time_after(jiffies
, led_next_time
)) {
1225 /* light the network leds depending on the current speed. */
1226 e100_set_network_leds(NETWORK_ACTIVITY
);
1228 /* Set the earliest time we may clear the LED */
1229 led_next_time
= jiffies
+ NET_FLASH_TIME
;
1231 mod_timer(&clear_led_timer
, jiffies
+ HZ
/10);
1233 spin_unlock(&np
->led_lock
);
1235 length
= myNextRxDesc
->descr
.hw_len
- 4;
1236 np
->stats
.rx_bytes
+= length
;
1239 printk("Got a packet of length %d:\n", length
);
1240 /* dump the first bytes in the packet */
1241 skb_data_ptr
= (unsigned char *)phys_to_virt(myNextRxDesc
->descr
.buf
);
1242 for (i
= 0; i
< 8; i
++) {
1243 printk("%d: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", i
* 8,
1244 skb_data_ptr
[0],skb_data_ptr
[1],skb_data_ptr
[2],skb_data_ptr
[3],
1245 skb_data_ptr
[4],skb_data_ptr
[5],skb_data_ptr
[6],skb_data_ptr
[7]);
1250 if (length
< RX_COPYBREAK
) {
1251 /* Small packet, copy data */
1252 skb
= dev_alloc_skb(length
- ETHER_HEAD_LEN
);
1254 np
->stats
.rx_errors
++;
1255 printk(KERN_NOTICE
"%s: Memory squeeze, dropping packet.\n", dev
->name
);
1256 goto update_nextrxdesc
;
1259 skb_put(skb
, length
- ETHER_HEAD_LEN
); /* allocate room for the packet body */
1260 skb_data_ptr
= skb_push(skb
, ETHER_HEAD_LEN
); /* allocate room for the header */
1263 printk("head = 0x%x, data = 0x%x, tail = 0x%x, end = 0x%x\n",
1264 skb
->head
, skb
->data
, skb_tail_pointer(skb
),
1265 skb_end_pointer(skb
));
1266 printk("copying packet to 0x%x.\n", skb_data_ptr
);
1269 memcpy(skb_data_ptr
, phys_to_virt(myNextRxDesc
->descr
.buf
), length
);
1272 /* Large packet, send directly to upper layers and allocate new
1273 * memory (aligned to cache line boundary to avoid bug).
1274 * Before sending the skb to upper layers we must make sure
1275 * that skb->data points to the aligned start of the packet.
1278 struct sk_buff
*new_skb
= dev_alloc_skb(MAX_MEDIA_DATA_SIZE
+ 2 * L1_CACHE_BYTES
);
1280 np
->stats
.rx_errors
++;
1281 printk(KERN_NOTICE
"%s: Memory squeeze, dropping packet.\n", dev
->name
);
1282 goto update_nextrxdesc
;
1284 skb
= myNextRxDesc
->skb
;
1285 align
= (int)phys_to_virt(myNextRxDesc
->descr
.buf
) - (int)skb
->data
;
1286 skb_put(skb
, length
+ align
);
1287 skb_pull(skb
, align
); /* Remove alignment bytes */
1288 myNextRxDesc
->skb
= new_skb
;
1289 myNextRxDesc
->descr
.buf
= L1_CACHE_ALIGN(virt_to_phys(myNextRxDesc
->skb
->data
));
1292 skb
->protocol
= eth_type_trans(skb
, dev
);
1294 /* Send the packet to the upper layers */
1298 /* Prepare for next packet */
1299 myNextRxDesc
->descr
.status
= 0;
1300 prevRxDesc
= myNextRxDesc
;
1301 myNextRxDesc
= phys_to_virt(myNextRxDesc
->descr
.next
);
1305 /* Check if descriptors should be returned */
1306 if (rx_queue_len
== RX_QUEUE_THRESHOLD
) {
1307 flush_etrax_cache();
1308 prevRxDesc
->descr
.ctrl
|= d_eol
;
1309 myLastRxDesc
->descr
.ctrl
&= ~d_eol
;
1310 myLastRxDesc
= prevRxDesc
;
1315 /* The inverse routine to net_open(). */
1317 e100_close(struct net_device
*dev
)
1319 struct net_local
*np
= netdev_priv(dev
);
1321 printk(KERN_INFO
"Closing %s.\n", dev
->name
);
1323 netif_stop_queue(dev
);
1326 IO_STATE(R_IRQ_MASK0_CLR
, overrun
, clr
) |
1327 IO_STATE(R_IRQ_MASK0_CLR
, underrun
, clr
) |
1328 IO_STATE(R_IRQ_MASK0_CLR
, excessive_col
, clr
);
1331 IO_STATE(R_IRQ_MASK2_CLR
, dma0_descr
, clr
) |
1332 IO_STATE(R_IRQ_MASK2_CLR
, dma0_eop
, clr
) |
1333 IO_STATE(R_IRQ_MASK2_CLR
, dma1_descr
, clr
) |
1334 IO_STATE(R_IRQ_MASK2_CLR
, dma1_eop
, clr
);
1336 /* Stop the receiver and the transmitter */
1338 RESET_DMA(NETWORK_TX_DMA_NBR
);
1339 RESET_DMA(NETWORK_RX_DMA_NBR
);
1341 /* Flush the Tx and disable Rx here. */
1343 free_irq(NETWORK_DMA_RX_IRQ_NBR
, (void *)dev
);
1344 free_irq(NETWORK_DMA_TX_IRQ_NBR
, (void *)dev
);
1345 free_irq(NETWORK_STATUS_IRQ_NBR
, (void *)dev
);
1347 cris_free_dma(NETWORK_TX_DMA_NBR
, cardname
);
1348 cris_free_dma(NETWORK_RX_DMA_NBR
, cardname
);
1350 /* Update the statistics here. */
1352 update_rx_stats(&np
->stats
);
1353 update_tx_stats(&np
->stats
);
1355 /* Stop speed/duplex timers */
1356 del_timer(&speed_timer
);
1357 del_timer(&duplex_timer
);
1363 e100_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1365 struct mii_ioctl_data
*data
= if_mii(ifr
);
1366 struct net_local
*np
= netdev_priv(dev
);
1370 spin_lock(&np
->lock
); /* Preempt protection */
1372 /* The ioctls below should be considered obsolete but are */
1373 /* still present for compatability with old scripts/apps */
1374 case SET_ETH_SPEED_10
: /* 10 Mbps */
1375 e100_set_speed(dev
, 10);
1377 case SET_ETH_SPEED_100
: /* 100 Mbps */
1378 e100_set_speed(dev
, 100);
1380 case SET_ETH_SPEED_AUTO
: /* Auto-negotiate speed */
1381 e100_set_speed(dev
, 0);
1383 case SET_ETH_DUPLEX_HALF
: /* Half duplex */
1384 e100_set_duplex(dev
, half
);
1386 case SET_ETH_DUPLEX_FULL
: /* Full duplex */
1387 e100_set_duplex(dev
, full
);
1389 case SET_ETH_DUPLEX_AUTO
: /* Auto-negotiate duplex */
1390 e100_set_duplex(dev
, autoneg
);
1392 case SET_ETH_AUTONEG
:
1393 old_autoneg
= autoneg_normal
;
1394 autoneg_normal
= *(int*)data
;
1395 if (autoneg_normal
!= old_autoneg
)
1396 e100_negotiate(dev
);
1399 rc
= generic_mii_ioctl(&np
->mii_if
, if_mii(ifr
),
1403 spin_unlock(&np
->lock
);
1407 static int e100_get_settings(struct net_device
*dev
,
1408 struct ethtool_cmd
*cmd
)
1410 struct net_local
*np
= netdev_priv(dev
);
1413 spin_lock_irq(&np
->lock
);
1414 err
= mii_ethtool_gset(&np
->mii_if
, cmd
);
1415 spin_unlock_irq(&np
->lock
);
1417 /* The PHY may support 1000baseT, but the Etrax100 does not. */
1418 cmd
->supported
&= ~(SUPPORTED_1000baseT_Half
1419 | SUPPORTED_1000baseT_Full
);
1423 static int e100_set_settings(struct net_device
*dev
,
1424 struct ethtool_cmd
*ecmd
)
1426 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
1427 e100_set_duplex(dev
, autoneg
);
1428 e100_set_speed(dev
, 0);
1430 e100_set_duplex(dev
, ecmd
->duplex
== DUPLEX_HALF
? half
: full
);
1431 e100_set_speed(dev
, ecmd
->speed
== SPEED_10
? 10: 100);
1437 static void e100_get_drvinfo(struct net_device
*dev
,
1438 struct ethtool_drvinfo
*info
)
1440 strncpy(info
->driver
, "ETRAX 100LX", sizeof(info
->driver
) - 1);
1441 strncpy(info
->version
, "$Revision: 1.31 $", sizeof(info
->version
) - 1);
1442 strncpy(info
->fw_version
, "N/A", sizeof(info
->fw_version
) - 1);
1443 strncpy(info
->bus_info
, "N/A", sizeof(info
->bus_info
) - 1);
1446 static int e100_nway_reset(struct net_device
*dev
)
1448 if (current_duplex
== autoneg
&& current_speed_selection
== 0)
1449 e100_negotiate(dev
);
1453 static const struct ethtool_ops e100_ethtool_ops
= {
1454 .get_settings
= e100_get_settings
,
1455 .set_settings
= e100_set_settings
,
1456 .get_drvinfo
= e100_get_drvinfo
,
1457 .nway_reset
= e100_nway_reset
,
1458 .get_link
= ethtool_op_get_link
,
1462 e100_set_config(struct net_device
*dev
, struct ifmap
*map
)
1464 struct net_local
*np
= netdev_priv(dev
);
1466 spin_lock(&np
->lock
); /* Preempt protection */
1469 case IF_PORT_UNKNOWN
:
1471 e100_set_speed(dev
, 0);
1472 e100_set_duplex(dev
, autoneg
);
1474 case IF_PORT_10BASET
:
1475 e100_set_speed(dev
, 10);
1476 e100_set_duplex(dev
, autoneg
);
1478 case IF_PORT_100BASET
:
1479 case IF_PORT_100BASETX
:
1480 e100_set_speed(dev
, 100);
1481 e100_set_duplex(dev
, autoneg
);
1483 case IF_PORT_100BASEFX
:
1484 case IF_PORT_10BASE2
:
1486 spin_unlock(&np
->lock
);
1490 printk(KERN_ERR
"%s: Invalid media selected", dev
->name
);
1491 spin_unlock(&np
->lock
);
1494 spin_unlock(&np
->lock
);
1499 update_rx_stats(struct net_device_stats
*es
)
1501 unsigned long r
= *R_REC_COUNTERS
;
1502 /* update stats relevant to reception errors */
1503 es
->rx_fifo_errors
+= IO_EXTRACT(R_REC_COUNTERS
, congestion
, r
);
1504 es
->rx_crc_errors
+= IO_EXTRACT(R_REC_COUNTERS
, crc_error
, r
);
1505 es
->rx_frame_errors
+= IO_EXTRACT(R_REC_COUNTERS
, alignment_error
, r
);
1506 es
->rx_length_errors
+= IO_EXTRACT(R_REC_COUNTERS
, oversize
, r
);
1510 update_tx_stats(struct net_device_stats
*es
)
1512 unsigned long r
= *R_TR_COUNTERS
;
1513 /* update stats relevant to transmission errors */
1515 IO_EXTRACT(R_TR_COUNTERS
, single_col
, r
) +
1516 IO_EXTRACT(R_TR_COUNTERS
, multiple_col
, r
);
1520 * Get the current statistics.
1521 * This may be called with the card open or closed.
1523 static struct net_device_stats
*
1524 e100_get_stats(struct net_device
*dev
)
1526 struct net_local
*lp
= netdev_priv(dev
);
1527 unsigned long flags
;
1529 spin_lock_irqsave(&lp
->lock
, flags
);
1531 update_rx_stats(&lp
->stats
);
1532 update_tx_stats(&lp
->stats
);
1534 spin_unlock_irqrestore(&lp
->lock
, flags
);
1539 * Set or clear the multicast filter for this adaptor.
1540 * num_addrs == -1 Promiscuous mode, receive all packets
1541 * num_addrs == 0 Normal mode, clear multicast list
1542 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1543 * and do best-effort filtering.
1546 set_multicast_list(struct net_device
*dev
)
1548 struct net_local
*lp
= netdev_priv(dev
);
1549 int num_addr
= dev
->mc_count
;
1550 unsigned long int lo_bits
;
1551 unsigned long int hi_bits
;
1553 spin_lock(&lp
->lock
);
1554 if (dev
->flags
& IFF_PROMISC
) {
1555 /* promiscuous mode */
1556 lo_bits
= 0xfffffffful
;
1557 hi_bits
= 0xfffffffful
;
1559 /* Enable individual receive */
1560 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, individual
, receive
);
1561 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
1562 } else if (dev
->flags
& IFF_ALLMULTI
) {
1563 /* enable all multicasts */
1564 lo_bits
= 0xfffffffful
;
1565 hi_bits
= 0xfffffffful
;
1567 /* Disable individual receive */
1568 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, individual
, discard
);
1569 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
1570 } else if (num_addr
== 0) {
1571 /* Normal, clear the mc list */
1572 lo_bits
= 0x00000000ul
;
1573 hi_bits
= 0x00000000ul
;
1575 /* Disable individual receive */
1576 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, individual
, discard
);
1577 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
1579 /* MC mode, receive normal and MC packets */
1581 struct dev_mc_list
*dmi
= dev
->mc_list
;
1585 lo_bits
= 0x00000000ul
;
1586 hi_bits
= 0x00000000ul
;
1587 for (i
= 0; i
< num_addr
; i
++) {
1588 /* Calculate the hash index for the GA registers */
1591 baddr
= dmi
->dmi_addr
;
1592 hash_ix
^= (*baddr
) & 0x3f;
1593 hash_ix
^= ((*baddr
) >> 6) & 0x03;
1595 hash_ix
^= ((*baddr
) << 2) & 0x03c;
1596 hash_ix
^= ((*baddr
) >> 4) & 0xf;
1598 hash_ix
^= ((*baddr
) << 4) & 0x30;
1599 hash_ix
^= ((*baddr
) >> 2) & 0x3f;
1601 hash_ix
^= (*baddr
) & 0x3f;
1602 hash_ix
^= ((*baddr
) >> 6) & 0x03;
1604 hash_ix
^= ((*baddr
) << 2) & 0x03c;
1605 hash_ix
^= ((*baddr
) >> 4) & 0xf;
1607 hash_ix
^= ((*baddr
) << 4) & 0x30;
1608 hash_ix
^= ((*baddr
) >> 2) & 0x3f;
1612 if (hash_ix
>= 32) {
1613 hi_bits
|= (1 << (hash_ix
-32));
1615 lo_bits
|= (1 << hash_ix
);
1619 /* Disable individual receive */
1620 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, individual
, discard
);
1621 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
1623 *R_NETWORK_GA_0
= lo_bits
;
1624 *R_NETWORK_GA_1
= hi_bits
;
1625 spin_unlock(&lp
->lock
);
1629 e100_hardware_send_packet(struct net_local
*np
, char *buf
, int length
)
1631 D(printk("e100 send pack, buf 0x%x len %d\n", buf
, length
));
1633 spin_lock(&np
->led_lock
);
1634 if (!led_active
&& time_after(jiffies
, led_next_time
)) {
1635 /* light the network leds depending on the current speed. */
1636 e100_set_network_leds(NETWORK_ACTIVITY
);
1638 /* Set the earliest time we may clear the LED */
1639 led_next_time
= jiffies
+ NET_FLASH_TIME
;
1641 mod_timer(&clear_led_timer
, jiffies
+ HZ
/10);
1643 spin_unlock(&np
->led_lock
);
1645 /* configure the tx dma descriptor */
1646 myNextTxDesc
->descr
.sw_len
= length
;
1647 myNextTxDesc
->descr
.ctrl
= d_eop
| d_eol
| d_wait
;
1648 myNextTxDesc
->descr
.buf
= virt_to_phys(buf
);
1650 /* Move end of list */
1651 myLastTxDesc
->descr
.ctrl
&= ~d_eol
;
1652 myLastTxDesc
= myNextTxDesc
;
1654 /* Restart DMA channel */
1655 *R_DMA_CH0_CMD
= IO_STATE(R_DMA_CH0_CMD
, cmd
, restart
);
1659 e100_clear_network_leds(unsigned long dummy
)
1661 struct net_device
*dev
= (struct net_device
*)dummy
;
1662 struct net_local
*np
= netdev_priv(dev
);
1664 spin_lock(&np
->led_lock
);
1666 if (led_active
&& time_after(jiffies
, led_next_time
)) {
1667 e100_set_network_leds(NO_NETWORK_ACTIVITY
);
1669 /* Set the earliest time we may set the LED */
1670 led_next_time
= jiffies
+ NET_FLASH_PAUSE
;
1674 spin_unlock(&np
->led_lock
);
1678 e100_set_network_leds(int active
)
1680 #if defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK)
1681 int light_leds
= (active
== NO_NETWORK_ACTIVITY
);
1682 #elif defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY)
1683 int light_leds
= (active
== NETWORK_ACTIVITY
);
1685 #error "Define either CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK or CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY"
1688 if (!current_speed
) {
1689 /* Make LED red, link is down */
1690 #if defined(CONFIG_ETRAX_NETWORK_RED_ON_NO_CONNECTION)
1691 CRIS_LED_NETWORK_SET(CRIS_LED_RED
);
1693 CRIS_LED_NETWORK_SET(CRIS_LED_OFF
);
1695 } else if (light_leds
) {
1696 if (current_speed
== 10) {
1697 CRIS_LED_NETWORK_SET(CRIS_LED_ORANGE
);
1699 CRIS_LED_NETWORK_SET(CRIS_LED_GREEN
);
1702 CRIS_LED_NETWORK_SET(CRIS_LED_OFF
);
1706 #ifdef CONFIG_NET_POLL_CONTROLLER
1708 e100_netpoll(struct net_device
* netdev
)
1710 e100rxtx_interrupt(NETWORK_DMA_TX_IRQ_NBR
, netdev
, NULL
);
1715 etrax_init_module(void)
1717 return etrax_ethernet_init();
1721 e100_boot_setup(char* str
)
1723 struct sockaddr sa
= {0};
1726 /* Parse the colon separated Ethernet station address */
1727 for (i
= 0; i
< ETH_ALEN
; i
++) {
1729 if (sscanf(str
+ 3*i
, "%2x", &tmp
) != 1) {
1730 printk(KERN_WARNING
"Malformed station address");
1733 sa
.sa_data
[i
] = (char)tmp
;
1740 __setup("etrax100_eth=", e100_boot_setup
);
1742 module_init(etrax_init_module
);