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/string.h>
22 #include <linux/spinlock.h>
23 #include <linux/errno.h>
24 #include <linux/init.h>
25 #include <linux/bitops.h>
28 #include <linux/mii.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/skbuff.h>
32 #include <linux/ethtool.h>
34 #include <arch/svinto.h>/* DMA and register descriptions */
35 #include <asm/io.h> /* CRIS_LED_* I/O functions */
38 #include <asm/system.h>
39 #include <asm/ethernet.h>
40 #include <asm/cache.h>
41 #include <arch/io_interface_mux.h>
47 * The name of the card. Is used for messages and in the requests for
48 * io regions, irqs and dma channels
51 static const char* cardname
= "ETRAX 100LX built-in ethernet controller";
53 /* A default ethernet address. Highlevel SW will set the real one later */
55 static struct sockaddr default_mac
= {
57 { 0x00, 0x40, 0x8C, 0xCD, 0x00, 0x00 }
60 /* Information that need to be kept for each board. */
62 struct net_device_stats stats
;
63 struct mii_if_info mii_if
;
65 /* Tx control lock. This protects the transmit buffer ring
66 * state along with the "tx full" state of the driver. This
67 * means all netif_queue flow control actions are protected
68 * by this lock as well.
72 spinlock_t led_lock
; /* Protect LED state */
73 spinlock_t transceiver_lock
; /* Protect transceiver state. */
76 typedef struct etrax_eth_descr
78 etrax_dma_descr descr
;
82 /* Some transceivers requires special handling */
83 struct transceiver_ops
86 void (*check_speed
)(struct net_device
* dev
);
87 void (*check_duplex
)(struct net_device
* dev
);
98 /* Dma descriptors etc. */
100 #define MAX_MEDIA_DATA_SIZE 1522
102 #define MIN_PACKET_LEN 46
103 #define ETHER_HEAD_LEN 14
108 #define MDIO_START 0x1
109 #define MDIO_READ 0x2
110 #define MDIO_WRITE 0x1
111 #define MDIO_PREAMBLE 0xfffffffful
113 /* Broadcom specific */
114 #define MDIO_AUX_CTRL_STATUS_REG 0x18
115 #define MDIO_BC_FULL_DUPLEX_IND 0x1
116 #define MDIO_BC_SPEED 0x2
119 #define MDIO_TDK_DIAGNOSTIC_REG 18
120 #define MDIO_TDK_DIAGNOSTIC_RATE 0x400
121 #define MDIO_TDK_DIAGNOSTIC_DPLX 0x800
123 /*Intel LXT972A specific*/
124 #define MDIO_INT_STATUS_REG_2 0x0011
125 #define MDIO_INT_FULL_DUPLEX_IND (1 << 9)
126 #define MDIO_INT_SPEED (1 << 14)
128 /* Network flash constants */
129 #define NET_FLASH_TIME (HZ/50) /* 20 ms */
130 #define NET_FLASH_PAUSE (HZ/100) /* 10 ms */
131 #define NET_LINK_UP_CHECK_INTERVAL (2*HZ) /* 2 s */
132 #define NET_DUPLEX_CHECK_INTERVAL (2*HZ) /* 2 s */
134 #define NO_NETWORK_ACTIVITY 0
135 #define NETWORK_ACTIVITY 1
137 #define NBR_OF_RX_DESC 32
138 #define NBR_OF_TX_DESC 16
140 /* Large packets are sent directly to upper layers while small packets are */
141 /* copied (to reduce memory waste). The following constant decides the breakpoint */
142 #define RX_COPYBREAK 256
144 /* Due to a chip bug we need to flush the cache when descriptors are returned */
145 /* to the DMA. To decrease performance impact we return descriptors in chunks. */
146 /* The following constant determines the number of descriptors to return. */
147 #define RX_QUEUE_THRESHOLD NBR_OF_RX_DESC/2
149 #define GET_BIT(bit,val) (((val) >> (bit)) & 0x01)
151 /* Define some macros to access ETRAX 100 registers */
152 #define SETF(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \
153 IO_FIELD_(reg##_, field##_, val)
154 #define SETS(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \
155 IO_STATE_(reg##_, field##_, _##val)
157 static etrax_eth_descr
*myNextRxDesc
; /* Points to the next descriptor to
159 static etrax_eth_descr
*myLastRxDesc
; /* The last processed descriptor */
161 static etrax_eth_descr RxDescList
[NBR_OF_RX_DESC
] __attribute__ ((aligned(32)));
163 static etrax_eth_descr
* myFirstTxDesc
; /* First packet not yet sent */
164 static etrax_eth_descr
* myLastTxDesc
; /* End of send queue */
165 static etrax_eth_descr
* myNextTxDesc
; /* Next descriptor to use */
166 static etrax_eth_descr TxDescList
[NBR_OF_TX_DESC
] __attribute__ ((aligned(32)));
168 static unsigned int network_rec_config_shadow
= 0;
170 static unsigned int network_tr_ctrl_shadow
= 0;
172 /* Network speed indication. */
173 static DEFINE_TIMER(speed_timer
, NULL
, 0, 0);
174 static DEFINE_TIMER(clear_led_timer
, NULL
, 0, 0);
175 static int current_speed
; /* Speed read from transceiver */
176 static int current_speed_selection
; /* Speed selected by user */
177 static unsigned long led_next_time
;
178 static int led_active
;
179 static int rx_queue_len
;
182 static DEFINE_TIMER(duplex_timer
, NULL
, 0, 0);
183 static int full_duplex
;
184 static enum duplex current_duplex
;
186 /* Index to functions, as function prototypes. */
188 static int etrax_ethernet_init(void);
190 static int e100_open(struct net_device
*dev
);
191 static int e100_set_mac_address(struct net_device
*dev
, void *addr
);
192 static int e100_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
193 static irqreturn_t
e100rxtx_interrupt(int irq
, void *dev_id
);
194 static irqreturn_t
e100nw_interrupt(int irq
, void *dev_id
);
195 static void e100_rx(struct net_device
*dev
);
196 static int e100_close(struct net_device
*dev
);
197 static int e100_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
198 static int e100_set_config(struct net_device
* dev
, struct ifmap
* map
);
199 static void e100_tx_timeout(struct net_device
*dev
);
200 static struct net_device_stats
*e100_get_stats(struct net_device
*dev
);
201 static void set_multicast_list(struct net_device
*dev
);
202 static void e100_hardware_send_packet(struct net_local
* np
, char *buf
, int length
);
203 static void update_rx_stats(struct net_device_stats
*);
204 static void update_tx_stats(struct net_device_stats
*);
205 static int e100_probe_transceiver(struct net_device
* dev
);
207 static void e100_check_speed(unsigned long priv
);
208 static void e100_set_speed(struct net_device
* dev
, unsigned long speed
);
209 static void e100_check_duplex(unsigned long priv
);
210 static void e100_set_duplex(struct net_device
* dev
, enum duplex
);
211 static void e100_negotiate(struct net_device
* dev
);
213 static int e100_get_mdio_reg(struct net_device
*dev
, int phy_id
, int location
);
214 static void e100_set_mdio_reg(struct net_device
*dev
, int phy_id
, int location
, int value
);
216 static void e100_send_mdio_cmd(unsigned short cmd
, int write_cmd
);
217 static void e100_send_mdio_bit(unsigned char bit
);
218 static unsigned char e100_receive_mdio_bit(void);
219 static void e100_reset_transceiver(struct net_device
* net
);
221 static void e100_clear_network_leds(unsigned long dummy
);
222 static void e100_set_network_leds(int active
);
224 static const struct ethtool_ops e100_ethtool_ops
;
225 #if defined(CONFIG_ETRAX_NO_PHY)
226 static void dummy_check_speed(struct net_device
* dev
);
227 static void dummy_check_duplex(struct net_device
* dev
);
229 static void broadcom_check_speed(struct net_device
* dev
);
230 static void broadcom_check_duplex(struct net_device
* dev
);
231 static void tdk_check_speed(struct net_device
* dev
);
232 static void tdk_check_duplex(struct net_device
* dev
);
233 static void intel_check_speed(struct net_device
* dev
);
234 static void intel_check_duplex(struct net_device
* dev
);
235 static void generic_check_speed(struct net_device
* dev
);
236 static void generic_check_duplex(struct net_device
* dev
);
238 #ifdef CONFIG_NET_POLL_CONTROLLER
239 static void e100_netpoll(struct net_device
* dev
);
242 static int autoneg_normal
= 1;
244 struct transceiver_ops transceivers
[] =
246 #if defined(CONFIG_ETRAX_NO_PHY)
247 {0x0000, dummy_check_speed
, dummy_check_duplex
} /* Dummy */
249 {0x1018, broadcom_check_speed
, broadcom_check_duplex
}, /* Broadcom */
250 {0xC039, tdk_check_speed
, tdk_check_duplex
}, /* TDK 2120 */
251 {0x039C, tdk_check_speed
, tdk_check_duplex
}, /* TDK 2120C */
252 {0x04de, intel_check_speed
, intel_check_duplex
}, /* Intel LXT972A*/
253 {0x0000, generic_check_speed
, generic_check_duplex
} /* Generic, must be last */
257 struct transceiver_ops
* transceiver
= &transceivers
[0];
259 static const struct net_device_ops e100_netdev_ops
= {
260 .ndo_open
= e100_open
,
261 .ndo_stop
= e100_close
,
262 .ndo_start_xmit
= e100_send_packet
,
263 .ndo_tx_timeout
= e100_tx_timeout
,
264 .ndo_get_stats
= e100_get_stats
,
265 .ndo_set_multicast_list
= set_multicast_list
,
266 .ndo_do_ioctl
= e100_ioctl
,
267 .ndo_set_mac_address
= e100_set_mac_address
,
268 .ndo_validate_addr
= eth_validate_addr
,
269 .ndo_change_mtu
= eth_change_mtu
,
270 .ndo_set_config
= e100_set_config
,
271 #ifdef CONFIG_NET_POLL_CONTROLLER
272 .ndo_poll_controller
= e100_netpoll
,
276 #define tx_done(dev) (*R_DMA_CH0_CMD == 0)
279 * Check for a network adaptor of this type, and return '0' if one exists.
280 * If dev->base_addr == 0, probe all likely locations.
281 * If dev->base_addr == 1, always return failure.
282 * If dev->base_addr == 2, allocate space for the device and return success
283 * (detachable devices only).
287 etrax_ethernet_init(void)
289 struct net_device
*dev
;
290 struct net_local
* np
;
294 "ETRAX 100LX 10/100MBit ethernet v2.0 (c) 1998-2007 Axis Communications AB\n");
296 if (cris_request_io_interface(if_eth
, cardname
)) {
297 printk(KERN_CRIT
"etrax_ethernet_init failed to get IO interface\n");
301 dev
= alloc_etherdev(sizeof(struct net_local
));
305 np
= netdev_priv(dev
);
307 /* we do our own locking */
308 dev
->features
|= NETIF_F_LLTX
;
310 dev
->base_addr
= (unsigned int)R_NETWORK_SA_0
; /* just to have something to show */
312 /* now setup our etrax specific stuff */
314 dev
->irq
= NETWORK_DMA_RX_IRQ_NBR
; /* we really use DMATX as well... */
315 dev
->dma
= NETWORK_RX_DMA_NBR
;
317 /* fill in our handlers so the network layer can talk to us in the future */
319 dev
->ethtool_ops
= &e100_ethtool_ops
;
320 dev
->netdev_ops
= &e100_netdev_ops
;
322 spin_lock_init(&np
->lock
);
323 spin_lock_init(&np
->led_lock
);
324 spin_lock_init(&np
->transceiver_lock
);
326 /* Initialise the list of Etrax DMA-descriptors */
328 /* Initialise receive descriptors */
330 for (i
= 0; i
< NBR_OF_RX_DESC
; i
++) {
331 /* Allocate two extra cachelines to make sure that buffer used
332 * by DMA does not share cacheline with any other data (to
335 RxDescList
[i
].skb
= dev_alloc_skb(MAX_MEDIA_DATA_SIZE
+ 2 * L1_CACHE_BYTES
);
336 if (!RxDescList
[i
].skb
)
338 RxDescList
[i
].descr
.ctrl
= 0;
339 RxDescList
[i
].descr
.sw_len
= MAX_MEDIA_DATA_SIZE
;
340 RxDescList
[i
].descr
.next
= virt_to_phys(&RxDescList
[i
+ 1]);
341 RxDescList
[i
].descr
.buf
= L1_CACHE_ALIGN(virt_to_phys(RxDescList
[i
].skb
->data
));
342 RxDescList
[i
].descr
.status
= 0;
343 RxDescList
[i
].descr
.hw_len
= 0;
344 prepare_rx_descriptor(&RxDescList
[i
].descr
);
347 RxDescList
[NBR_OF_RX_DESC
- 1].descr
.ctrl
= d_eol
;
348 RxDescList
[NBR_OF_RX_DESC
- 1].descr
.next
= virt_to_phys(&RxDescList
[0]);
351 /* Initialize transmit descriptors */
352 for (i
= 0; i
< NBR_OF_TX_DESC
; i
++) {
353 TxDescList
[i
].descr
.ctrl
= 0;
354 TxDescList
[i
].descr
.sw_len
= 0;
355 TxDescList
[i
].descr
.next
= virt_to_phys(&TxDescList
[i
+ 1].descr
);
356 TxDescList
[i
].descr
.buf
= 0;
357 TxDescList
[i
].descr
.status
= 0;
358 TxDescList
[i
].descr
.hw_len
= 0;
359 TxDescList
[i
].skb
= 0;
362 TxDescList
[NBR_OF_TX_DESC
- 1].descr
.ctrl
= d_eol
;
363 TxDescList
[NBR_OF_TX_DESC
- 1].descr
.next
= virt_to_phys(&TxDescList
[0].descr
);
365 /* Initialise initial pointers */
367 myNextRxDesc
= &RxDescList
[0];
368 myLastRxDesc
= &RxDescList
[NBR_OF_RX_DESC
- 1];
369 myFirstTxDesc
= &TxDescList
[0];
370 myNextTxDesc
= &TxDescList
[0];
371 myLastTxDesc
= &TxDescList
[NBR_OF_TX_DESC
- 1];
373 /* Register device */
374 err
= register_netdev(dev
);
380 /* set the default MAC address */
382 e100_set_mac_address(dev
, &default_mac
);
384 /* Initialize speed indicator stuff. */
387 current_speed_selection
= 0; /* Auto */
388 speed_timer
.expires
= jiffies
+ NET_LINK_UP_CHECK_INTERVAL
;
389 speed_timer
.data
= (unsigned long)dev
;
390 speed_timer
.function
= e100_check_speed
;
392 clear_led_timer
.function
= e100_clear_network_leds
;
393 clear_led_timer
.data
= (unsigned long)dev
;
396 current_duplex
= autoneg
;
397 duplex_timer
.expires
= jiffies
+ NET_DUPLEX_CHECK_INTERVAL
;
398 duplex_timer
.data
= (unsigned long)dev
;
399 duplex_timer
.function
= e100_check_duplex
;
401 /* Initialize mii interface */
402 np
->mii_if
.phy_id_mask
= 0x1f;
403 np
->mii_if
.reg_num_mask
= 0x1f;
404 np
->mii_if
.dev
= dev
;
405 np
->mii_if
.mdio_read
= e100_get_mdio_reg
;
406 np
->mii_if
.mdio_write
= e100_set_mdio_reg
;
408 /* Initialize group address registers to make sure that no */
409 /* unwanted addresses are matched */
410 *R_NETWORK_GA_0
= 0x00000000;
411 *R_NETWORK_GA_1
= 0x00000000;
413 /* Initialize next time the led can flash */
414 led_next_time
= jiffies
;
418 /* set MAC address of the interface. called from the core after a
419 * SIOCSIFADDR ioctl, and from the bootup above.
423 e100_set_mac_address(struct net_device
*dev
, void *p
)
425 struct net_local
*np
= netdev_priv(dev
);
426 struct sockaddr
*addr
= p
;
428 spin_lock(&np
->lock
); /* preemption protection */
432 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
434 /* Write it to the hardware.
435 * Note the way the address is wrapped:
436 * *R_NETWORK_SA_0 = a0_0 | (a0_1 << 8) | (a0_2 << 16) | (a0_3 << 24);
437 * *R_NETWORK_SA_1 = a0_4 | (a0_5 << 8);
440 *R_NETWORK_SA_0
= dev
->dev_addr
[0] | (dev
->dev_addr
[1] << 8) |
441 (dev
->dev_addr
[2] << 16) | (dev
->dev_addr
[3] << 24);
442 *R_NETWORK_SA_1
= dev
->dev_addr
[4] | (dev
->dev_addr
[5] << 8);
445 /* show it in the log as well */
447 printk(KERN_INFO
"%s: changed MAC to %pM\n", dev
->name
, dev
->dev_addr
);
449 spin_unlock(&np
->lock
);
455 * Open/initialize the board. This is called (in the current kernel)
456 * sometime after booting when the 'ifconfig' program is run.
458 * This routine should set everything up anew at each open, even
459 * registers that "should" only need to be set once at boot, so that
460 * there is non-reboot way to recover if something goes wrong.
464 e100_open(struct net_device
*dev
)
468 /* enable the MDIO output pin */
470 *R_NETWORK_MGM_CTRL
= IO_STATE(R_NETWORK_MGM_CTRL
, mdoe
, enable
);
473 IO_STATE(R_IRQ_MASK0_CLR
, overrun
, clr
) |
474 IO_STATE(R_IRQ_MASK0_CLR
, underrun
, clr
) |
475 IO_STATE(R_IRQ_MASK0_CLR
, excessive_col
, clr
);
477 /* clear dma0 and 1 eop and descr irq masks */
479 IO_STATE(R_IRQ_MASK2_CLR
, dma0_descr
, clr
) |
480 IO_STATE(R_IRQ_MASK2_CLR
, dma0_eop
, clr
) |
481 IO_STATE(R_IRQ_MASK2_CLR
, dma1_descr
, clr
) |
482 IO_STATE(R_IRQ_MASK2_CLR
, dma1_eop
, clr
);
484 /* Reset and wait for the DMA channels */
486 RESET_DMA(NETWORK_TX_DMA_NBR
);
487 RESET_DMA(NETWORK_RX_DMA_NBR
);
488 WAIT_DMA(NETWORK_TX_DMA_NBR
);
489 WAIT_DMA(NETWORK_RX_DMA_NBR
);
491 /* Initialise the etrax network controller */
493 /* allocate the irq corresponding to the receiving DMA */
495 if (request_irq(NETWORK_DMA_RX_IRQ_NBR
, e100rxtx_interrupt
,
496 IRQF_SAMPLE_RANDOM
, cardname
, (void *)dev
)) {
500 /* allocate the irq corresponding to the transmitting DMA */
502 if (request_irq(NETWORK_DMA_TX_IRQ_NBR
, e100rxtx_interrupt
, 0,
503 cardname
, (void *)dev
)) {
507 /* allocate the irq corresponding to the network errors etc */
509 if (request_irq(NETWORK_STATUS_IRQ_NBR
, e100nw_interrupt
, 0,
510 cardname
, (void *)dev
)) {
515 * Always allocate the DMA channels after the IRQ,
516 * and clean up on failure.
519 if (cris_request_dma(NETWORK_TX_DMA_NBR
,
521 DMA_VERBOSE_ON_ERROR
,
526 if (cris_request_dma(NETWORK_RX_DMA_NBR
,
528 DMA_VERBOSE_ON_ERROR
,
533 /* give the HW an idea of what MAC address we want */
535 *R_NETWORK_SA_0
= dev
->dev_addr
[0] | (dev
->dev_addr
[1] << 8) |
536 (dev
->dev_addr
[2] << 16) | (dev
->dev_addr
[3] << 24);
537 *R_NETWORK_SA_1
= dev
->dev_addr
[4] | (dev
->dev_addr
[5] << 8);
541 /* use promiscuous mode for testing */
542 *R_NETWORK_GA_0
= 0xffffffff;
543 *R_NETWORK_GA_1
= 0xffffffff;
545 *R_NETWORK_REC_CONFIG
= 0xd; /* broadcast rec, individ. rec, ma0 enabled */
547 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, max_size
, size1522
);
548 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, broadcast
, receive
);
549 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, ma0
, enable
);
550 SETF(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, duplex
, full_duplex
);
551 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
554 *R_NETWORK_GEN_CONFIG
=
555 IO_STATE(R_NETWORK_GEN_CONFIG
, phy
, mii_clk
) |
556 IO_STATE(R_NETWORK_GEN_CONFIG
, enable
, on
);
558 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, clr
);
559 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, delay
, none
);
560 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, cancel
, dont
);
561 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, cd
, enable
);
562 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, retry
, enable
);
563 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, pad
, enable
);
564 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, crc
, enable
);
565 *R_NETWORK_TR_CTRL
= network_tr_ctrl_shadow
;
567 local_irq_save(flags
);
569 /* enable the irq's for ethernet DMA */
572 IO_STATE(R_IRQ_MASK2_SET
, dma0_eop
, set
) |
573 IO_STATE(R_IRQ_MASK2_SET
, dma1_eop
, set
);
576 IO_STATE(R_IRQ_MASK0_SET
, overrun
, set
) |
577 IO_STATE(R_IRQ_MASK0_SET
, underrun
, set
) |
578 IO_STATE(R_IRQ_MASK0_SET
, excessive_col
, set
);
580 /* make sure the irqs are cleared */
582 *R_DMA_CH0_CLR_INTR
= IO_STATE(R_DMA_CH0_CLR_INTR
, clr_eop
, do);
583 *R_DMA_CH1_CLR_INTR
= IO_STATE(R_DMA_CH1_CLR_INTR
, clr_eop
, do);
585 /* make sure the rec and transmit error counters are cleared */
587 (void)*R_REC_COUNTERS
; /* dummy read */
588 (void)*R_TR_COUNTERS
; /* dummy read */
590 /* start the receiving DMA channel so we can receive packets from now on */
592 *R_DMA_CH1_FIRST
= virt_to_phys(myNextRxDesc
);
593 *R_DMA_CH1_CMD
= IO_STATE(R_DMA_CH1_CMD
, cmd
, start
);
595 /* Set up transmit DMA channel so it can be restarted later */
597 *R_DMA_CH0_FIRST
= 0;
598 *R_DMA_CH0_DESCR
= virt_to_phys(myLastTxDesc
);
599 netif_start_queue(dev
);
601 local_irq_restore(flags
);
603 /* Probe for transceiver */
604 if (e100_probe_transceiver(dev
))
607 /* Start duplex/speed timers */
608 add_timer(&speed_timer
);
609 add_timer(&duplex_timer
);
611 /* We are now ready to accept transmit requeusts from
612 * the queueing layer of the networking.
614 netif_carrier_on(dev
);
619 cris_free_dma(NETWORK_RX_DMA_NBR
, cardname
);
621 cris_free_dma(NETWORK_TX_DMA_NBR
, cardname
);
623 free_irq(NETWORK_STATUS_IRQ_NBR
, (void *)dev
);
625 free_irq(NETWORK_DMA_TX_IRQ_NBR
, (void *)dev
);
627 free_irq(NETWORK_DMA_RX_IRQ_NBR
, (void *)dev
);
632 #if defined(CONFIG_ETRAX_NO_PHY)
634 dummy_check_speed(struct net_device
* dev
)
640 generic_check_speed(struct net_device
* dev
)
643 struct net_local
*np
= netdev_priv(dev
);
645 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_ADVERTISE
);
646 if ((data
& ADVERTISE_100FULL
) ||
647 (data
& ADVERTISE_100HALF
))
654 tdk_check_speed(struct net_device
* dev
)
657 struct net_local
*np
= netdev_priv(dev
);
659 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
660 MDIO_TDK_DIAGNOSTIC_REG
);
661 current_speed
= (data
& MDIO_TDK_DIAGNOSTIC_RATE
? 100 : 10);
665 broadcom_check_speed(struct net_device
* dev
)
668 struct net_local
*np
= netdev_priv(dev
);
670 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
671 MDIO_AUX_CTRL_STATUS_REG
);
672 current_speed
= (data
& MDIO_BC_SPEED
? 100 : 10);
676 intel_check_speed(struct net_device
* dev
)
679 struct net_local
*np
= netdev_priv(dev
);
681 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
682 MDIO_INT_STATUS_REG_2
);
683 current_speed
= (data
& MDIO_INT_SPEED
? 100 : 10);
687 e100_check_speed(unsigned long priv
)
689 struct net_device
* dev
= (struct net_device
*)priv
;
690 struct net_local
*np
= netdev_priv(dev
);
691 static int led_initiated
= 0;
693 int old_speed
= current_speed
;
695 spin_lock(&np
->transceiver_lock
);
697 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_BMSR
);
698 if (!(data
& BMSR_LSTATUS
)) {
701 transceiver
->check_speed(dev
);
704 spin_lock(&np
->led_lock
);
705 if ((old_speed
!= current_speed
) || !led_initiated
) {
707 e100_set_network_leds(NO_NETWORK_ACTIVITY
);
709 netif_carrier_on(dev
);
711 netif_carrier_off(dev
);
713 spin_unlock(&np
->led_lock
);
715 /* Reinitialize the timer. */
716 speed_timer
.expires
= jiffies
+ NET_LINK_UP_CHECK_INTERVAL
;
717 add_timer(&speed_timer
);
719 spin_unlock(&np
->transceiver_lock
);
723 e100_negotiate(struct net_device
* dev
)
725 struct net_local
*np
= netdev_priv(dev
);
726 unsigned short data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
729 /* Discard old speed and duplex settings */
730 data
&= ~(ADVERTISE_100HALF
| ADVERTISE_100FULL
|
731 ADVERTISE_10HALF
| ADVERTISE_10FULL
);
733 switch (current_speed_selection
) {
735 if (current_duplex
== full
)
736 data
|= ADVERTISE_10FULL
;
737 else if (current_duplex
== half
)
738 data
|= ADVERTISE_10HALF
;
740 data
|= ADVERTISE_10HALF
| ADVERTISE_10FULL
;
744 if (current_duplex
== full
)
745 data
|= ADVERTISE_100FULL
;
746 else if (current_duplex
== half
)
747 data
|= ADVERTISE_100HALF
;
749 data
|= ADVERTISE_100HALF
| ADVERTISE_100FULL
;
753 if (current_duplex
== full
)
754 data
|= ADVERTISE_100FULL
| ADVERTISE_10FULL
;
755 else if (current_duplex
== half
)
756 data
|= ADVERTISE_100HALF
| ADVERTISE_10HALF
;
758 data
|= ADVERTISE_10HALF
| ADVERTISE_10FULL
|
759 ADVERTISE_100HALF
| ADVERTISE_100FULL
;
762 default: /* assume autoneg speed and duplex */
763 data
|= ADVERTISE_10HALF
| ADVERTISE_10FULL
|
764 ADVERTISE_100HALF
| ADVERTISE_100FULL
;
768 e100_set_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_ADVERTISE
, data
);
770 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_BMCR
);
771 if (autoneg_normal
) {
772 /* Renegotiate with link partner */
773 data
|= BMCR_ANENABLE
| BMCR_ANRESTART
;
775 /* Don't negotiate speed or duplex */
776 data
&= ~(BMCR_ANENABLE
| BMCR_ANRESTART
);
778 /* Set speed and duplex static */
779 if (current_speed_selection
== 10)
780 data
&= ~BMCR_SPEED100
;
782 data
|= BMCR_SPEED100
;
784 if (current_duplex
!= full
)
785 data
&= ~BMCR_FULLDPLX
;
787 data
|= BMCR_FULLDPLX
;
789 e100_set_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_BMCR
, data
);
793 e100_set_speed(struct net_device
* dev
, unsigned long speed
)
795 struct net_local
*np
= netdev_priv(dev
);
797 spin_lock(&np
->transceiver_lock
);
798 if (speed
!= current_speed_selection
) {
799 current_speed_selection
= speed
;
802 spin_unlock(&np
->transceiver_lock
);
806 e100_check_duplex(unsigned long priv
)
808 struct net_device
*dev
= (struct net_device
*)priv
;
809 struct net_local
*np
= netdev_priv(dev
);
812 spin_lock(&np
->transceiver_lock
);
813 old_duplex
= full_duplex
;
814 transceiver
->check_duplex(dev
);
815 if (old_duplex
!= full_duplex
) {
817 SETF(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, duplex
, full_duplex
);
818 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
821 /* Reinitialize the timer. */
822 duplex_timer
.expires
= jiffies
+ NET_DUPLEX_CHECK_INTERVAL
;
823 add_timer(&duplex_timer
);
824 np
->mii_if
.full_duplex
= full_duplex
;
825 spin_unlock(&np
->transceiver_lock
);
827 #if defined(CONFIG_ETRAX_NO_PHY)
829 dummy_check_duplex(struct net_device
* dev
)
835 generic_check_duplex(struct net_device
* dev
)
838 struct net_local
*np
= netdev_priv(dev
);
840 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_ADVERTISE
);
841 if ((data
& ADVERTISE_10FULL
) ||
842 (data
& ADVERTISE_100FULL
))
849 tdk_check_duplex(struct net_device
* dev
)
852 struct net_local
*np
= netdev_priv(dev
);
854 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
855 MDIO_TDK_DIAGNOSTIC_REG
);
856 full_duplex
= (data
& MDIO_TDK_DIAGNOSTIC_DPLX
) ? 1 : 0;
860 broadcom_check_duplex(struct net_device
* dev
)
863 struct net_local
*np
= netdev_priv(dev
);
865 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
866 MDIO_AUX_CTRL_STATUS_REG
);
867 full_duplex
= (data
& MDIO_BC_FULL_DUPLEX_IND
) ? 1 : 0;
871 intel_check_duplex(struct net_device
* dev
)
874 struct net_local
*np
= netdev_priv(dev
);
876 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
,
877 MDIO_INT_STATUS_REG_2
);
878 full_duplex
= (data
& MDIO_INT_FULL_DUPLEX_IND
) ? 1 : 0;
882 e100_set_duplex(struct net_device
* dev
, enum duplex new_duplex
)
884 struct net_local
*np
= netdev_priv(dev
);
886 spin_lock(&np
->transceiver_lock
);
887 if (new_duplex
!= current_duplex
) {
888 current_duplex
= new_duplex
;
891 spin_unlock(&np
->transceiver_lock
);
895 e100_probe_transceiver(struct net_device
* dev
)
899 #if !defined(CONFIG_ETRAX_NO_PHY)
900 unsigned int phyid_high
;
901 unsigned int phyid_low
;
903 struct transceiver_ops
* ops
= NULL
;
904 struct net_local
*np
= netdev_priv(dev
);
906 spin_lock(&np
->transceiver_lock
);
908 /* Probe MDIO physical address */
909 for (np
->mii_if
.phy_id
= 0; np
->mii_if
.phy_id
<= 31;
910 np
->mii_if
.phy_id
++) {
911 if (e100_get_mdio_reg(dev
,
912 np
->mii_if
.phy_id
, MII_BMSR
) != 0xffff)
915 if (np
->mii_if
.phy_id
== 32) {
920 /* Get manufacturer */
921 phyid_high
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_PHYSID1
);
922 phyid_low
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_PHYSID2
);
923 oui
= (phyid_high
<< 6) | (phyid_low
>> 10);
925 for (ops
= &transceivers
[0]; ops
->oui
; ops
++) {
931 spin_unlock(&np
->transceiver_lock
);
937 e100_get_mdio_reg(struct net_device
*dev
, int phy_id
, int location
)
939 unsigned short cmd
; /* Data to be sent on MDIO port */
940 int data
; /* Data read from MDIO */
943 /* Start of frame, OP Code, Physical Address, Register Address */
944 cmd
= (MDIO_START
<< 14) | (MDIO_READ
<< 12) | (phy_id
<< 7) |
947 e100_send_mdio_cmd(cmd
, 0);
952 for (bitCounter
=15; bitCounter
>=0 ; bitCounter
--) {
953 data
|= (e100_receive_mdio_bit() << bitCounter
);
960 e100_set_mdio_reg(struct net_device
*dev
, int phy_id
, int location
, int value
)
965 cmd
= (MDIO_START
<< 14) | (MDIO_WRITE
<< 12) | (phy_id
<< 7) |
968 e100_send_mdio_cmd(cmd
, 1);
971 for (bitCounter
=15; bitCounter
>=0 ; bitCounter
--) {
972 e100_send_mdio_bit(GET_BIT(bitCounter
, value
));
978 e100_send_mdio_cmd(unsigned short cmd
, int write_cmd
)
981 unsigned char data
= 0x2;
984 for (bitCounter
= 31; bitCounter
>= 0; bitCounter
--)
985 e100_send_mdio_bit(GET_BIT(bitCounter
, MDIO_PREAMBLE
));
987 for (bitCounter
= 15; bitCounter
>= 2; bitCounter
--)
988 e100_send_mdio_bit(GET_BIT(bitCounter
, cmd
));
991 for (bitCounter
= 1; bitCounter
>= 0 ; bitCounter
--)
993 e100_send_mdio_bit(GET_BIT(bitCounter
, data
));
995 e100_receive_mdio_bit();
999 e100_send_mdio_bit(unsigned char bit
)
1001 *R_NETWORK_MGM_CTRL
=
1002 IO_STATE(R_NETWORK_MGM_CTRL
, mdoe
, enable
) |
1003 IO_FIELD(R_NETWORK_MGM_CTRL
, mdio
, bit
);
1005 *R_NETWORK_MGM_CTRL
=
1006 IO_STATE(R_NETWORK_MGM_CTRL
, mdoe
, enable
) |
1007 IO_MASK(R_NETWORK_MGM_CTRL
, mdck
) |
1008 IO_FIELD(R_NETWORK_MGM_CTRL
, mdio
, bit
);
1012 static unsigned char
1013 e100_receive_mdio_bit()
1016 *R_NETWORK_MGM_CTRL
= 0;
1017 bit
= IO_EXTRACT(R_NETWORK_STAT
, mdio
, *R_NETWORK_STAT
);
1019 *R_NETWORK_MGM_CTRL
= IO_MASK(R_NETWORK_MGM_CTRL
, mdck
);
1025 e100_reset_transceiver(struct net_device
* dev
)
1027 struct net_local
*np
= netdev_priv(dev
);
1029 unsigned short data
;
1032 data
= e100_get_mdio_reg(dev
, np
->mii_if
.phy_id
, MII_BMCR
);
1034 cmd
= (MDIO_START
<< 14) | (MDIO_WRITE
<< 12) | (np
->mii_if
.phy_id
<< 7) | (MII_BMCR
<< 2);
1036 e100_send_mdio_cmd(cmd
, 1);
1040 for (bitCounter
= 15; bitCounter
>= 0 ; bitCounter
--) {
1041 e100_send_mdio_bit(GET_BIT(bitCounter
, data
));
1045 /* Called by upper layers if they decide it took too long to complete
1046 * sending a packet - we need to reset and stuff.
1050 e100_tx_timeout(struct net_device
*dev
)
1052 struct net_local
*np
= netdev_priv(dev
);
1053 unsigned long flags
;
1055 spin_lock_irqsave(&np
->lock
, flags
);
1057 printk(KERN_WARNING
"%s: transmit timed out, %s?\n", dev
->name
,
1058 tx_done(dev
) ? "IRQ problem" : "network cable problem");
1060 /* remember we got an error */
1062 np
->stats
.tx_errors
++;
1064 /* reset the TX DMA in case it has hung on something */
1066 RESET_DMA(NETWORK_TX_DMA_NBR
);
1067 WAIT_DMA(NETWORK_TX_DMA_NBR
);
1069 /* Reset the transceiver. */
1071 e100_reset_transceiver(dev
);
1073 /* and get rid of the packets that never got an interrupt */
1074 while (myFirstTxDesc
!= myNextTxDesc
) {
1075 dev_kfree_skb(myFirstTxDesc
->skb
);
1076 myFirstTxDesc
->skb
= 0;
1077 myFirstTxDesc
= phys_to_virt(myFirstTxDesc
->descr
.next
);
1080 /* Set up transmit DMA channel so it can be restarted later */
1081 *R_DMA_CH0_FIRST
= 0;
1082 *R_DMA_CH0_DESCR
= virt_to_phys(myLastTxDesc
);
1084 /* tell the upper layers we're ok again */
1086 netif_wake_queue(dev
);
1087 spin_unlock_irqrestore(&np
->lock
, flags
);
1091 /* This will only be invoked if the driver is _not_ in XOFF state.
1092 * What this means is that we need not check it, and that this
1093 * invariant will hold if we make sure that the netif_*_queue()
1094 * calls are done at the proper times.
1098 e100_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
1100 struct net_local
*np
= netdev_priv(dev
);
1101 unsigned char *buf
= skb
->data
;
1102 unsigned long flags
;
1105 printk("send packet len %d\n", length
);
1107 spin_lock_irqsave(&np
->lock
, flags
); /* protect from tx_interrupt and ourself */
1109 myNextTxDesc
->skb
= skb
;
1111 dev
->trans_start
= jiffies
; /* NETIF_F_LLTX driver :( */
1113 e100_hardware_send_packet(np
, buf
, skb
->len
);
1115 myNextTxDesc
= phys_to_virt(myNextTxDesc
->descr
.next
);
1117 /* Stop queue if full */
1118 if (myNextTxDesc
== myFirstTxDesc
) {
1119 netif_stop_queue(dev
);
1122 spin_unlock_irqrestore(&np
->lock
, flags
);
1124 return NETDEV_TX_OK
;
1128 * The typical workload of the driver:
1129 * Handle the network interface interrupts.
1133 e100rxtx_interrupt(int irq
, void *dev_id
)
1135 struct net_device
*dev
= (struct net_device
*)dev_id
;
1136 struct net_local
*np
= netdev_priv(dev
);
1137 unsigned long irqbits
;
1140 * Note that both rx and tx interrupts are blocked at this point,
1141 * regardless of which got us here.
1144 irqbits
= *R_IRQ_MASK2_RD
;
1146 /* Handle received packets */
1147 if (irqbits
& IO_STATE(R_IRQ_MASK2_RD
, dma1_eop
, active
)) {
1148 /* acknowledge the eop interrupt */
1150 *R_DMA_CH1_CLR_INTR
= IO_STATE(R_DMA_CH1_CLR_INTR
, clr_eop
, do);
1152 /* check if one or more complete packets were indeed received */
1154 while ((*R_DMA_CH1_FIRST
!= virt_to_phys(myNextRxDesc
)) &&
1155 (myNextRxDesc
!= myLastRxDesc
)) {
1156 /* Take out the buffer and give it to the OS, then
1157 * allocate a new buffer to put a packet in.
1160 np
->stats
.rx_packets
++;
1161 /* restart/continue on the channel, for safety */
1162 *R_DMA_CH1_CMD
= IO_STATE(R_DMA_CH1_CMD
, cmd
, restart
);
1163 /* clear dma channel 1 eop/descr irq bits */
1164 *R_DMA_CH1_CLR_INTR
=
1165 IO_STATE(R_DMA_CH1_CLR_INTR
, clr_eop
, do) |
1166 IO_STATE(R_DMA_CH1_CLR_INTR
, clr_descr
, do);
1168 /* now, we might have gotten another packet
1169 so we have to loop back and check if so */
1173 /* Report any packets that have been sent */
1174 while (virt_to_phys(myFirstTxDesc
) != *R_DMA_CH0_FIRST
&&
1175 (netif_queue_stopped(dev
) || myFirstTxDesc
!= myNextTxDesc
)) {
1176 np
->stats
.tx_bytes
+= myFirstTxDesc
->skb
->len
;
1177 np
->stats
.tx_packets
++;
1179 /* dma is ready with the transmission of the data in tx_skb, so now
1180 we can release the skb memory */
1181 dev_kfree_skb_irq(myFirstTxDesc
->skb
);
1182 myFirstTxDesc
->skb
= 0;
1183 myFirstTxDesc
= phys_to_virt(myFirstTxDesc
->descr
.next
);
1184 /* Wake up queue. */
1185 netif_wake_queue(dev
);
1188 if (irqbits
& IO_STATE(R_IRQ_MASK2_RD
, dma0_eop
, active
)) {
1189 /* acknowledge the eop interrupt. */
1190 *R_DMA_CH0_CLR_INTR
= IO_STATE(R_DMA_CH0_CLR_INTR
, clr_eop
, do);
1197 e100nw_interrupt(int irq
, void *dev_id
)
1199 struct net_device
*dev
= (struct net_device
*)dev_id
;
1200 struct net_local
*np
= netdev_priv(dev
);
1201 unsigned long irqbits
= *R_IRQ_MASK0_RD
;
1203 /* check for underrun irq */
1204 if (irqbits
& IO_STATE(R_IRQ_MASK0_RD
, underrun
, active
)) {
1205 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, clr
);
1206 *R_NETWORK_TR_CTRL
= network_tr_ctrl_shadow
;
1207 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, nop
);
1208 np
->stats
.tx_errors
++;
1209 D(printk("ethernet receiver underrun!\n"));
1212 /* check for overrun irq */
1213 if (irqbits
& IO_STATE(R_IRQ_MASK0_RD
, overrun
, active
)) {
1214 update_rx_stats(&np
->stats
); /* this will ack the irq */
1215 D(printk("ethernet receiver overrun!\n"));
1217 /* check for excessive collision irq */
1218 if (irqbits
& IO_STATE(R_IRQ_MASK0_RD
, excessive_col
, active
)) {
1219 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, clr
);
1220 *R_NETWORK_TR_CTRL
= network_tr_ctrl_shadow
;
1221 SETS(network_tr_ctrl_shadow
, R_NETWORK_TR_CTRL
, clr_error
, nop
);
1222 np
->stats
.tx_errors
++;
1223 D(printk("ethernet excessive collisions!\n"));
1228 /* We have a good packet(s), get it/them out of the buffers. */
1230 e100_rx(struct net_device
*dev
)
1232 struct sk_buff
*skb
;
1234 struct net_local
*np
= netdev_priv(dev
);
1235 unsigned char *skb_data_ptr
;
1239 etrax_eth_descr
*prevRxDesc
; /* The descriptor right before myNextRxDesc */
1240 spin_lock(&np
->led_lock
);
1241 if (!led_active
&& time_after(jiffies
, led_next_time
)) {
1242 /* light the network leds depending on the current speed. */
1243 e100_set_network_leds(NETWORK_ACTIVITY
);
1245 /* Set the earliest time we may clear the LED */
1246 led_next_time
= jiffies
+ NET_FLASH_TIME
;
1248 mod_timer(&clear_led_timer
, jiffies
+ HZ
/10);
1250 spin_unlock(&np
->led_lock
);
1252 length
= myNextRxDesc
->descr
.hw_len
- 4;
1253 np
->stats
.rx_bytes
+= length
;
1256 printk("Got a packet of length %d:\n", length
);
1257 /* dump the first bytes in the packet */
1258 skb_data_ptr
= (unsigned char *)phys_to_virt(myNextRxDesc
->descr
.buf
);
1259 for (i
= 0; i
< 8; i
++) {
1260 printk("%d: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", i
* 8,
1261 skb_data_ptr
[0],skb_data_ptr
[1],skb_data_ptr
[2],skb_data_ptr
[3],
1262 skb_data_ptr
[4],skb_data_ptr
[5],skb_data_ptr
[6],skb_data_ptr
[7]);
1267 if (length
< RX_COPYBREAK
) {
1268 /* Small packet, copy data */
1269 skb
= dev_alloc_skb(length
- ETHER_HEAD_LEN
);
1271 np
->stats
.rx_errors
++;
1272 printk(KERN_NOTICE
"%s: Memory squeeze, dropping packet.\n", dev
->name
);
1273 goto update_nextrxdesc
;
1276 skb_put(skb
, length
- ETHER_HEAD_LEN
); /* allocate room for the packet body */
1277 skb_data_ptr
= skb_push(skb
, ETHER_HEAD_LEN
); /* allocate room for the header */
1280 printk("head = 0x%x, data = 0x%x, tail = 0x%x, end = 0x%x\n",
1281 skb
->head
, skb
->data
, skb_tail_pointer(skb
),
1282 skb_end_pointer(skb
));
1283 printk("copying packet to 0x%x.\n", skb_data_ptr
);
1286 memcpy(skb_data_ptr
, phys_to_virt(myNextRxDesc
->descr
.buf
), length
);
1289 /* Large packet, send directly to upper layers and allocate new
1290 * memory (aligned to cache line boundary to avoid bug).
1291 * Before sending the skb to upper layers we must make sure
1292 * that skb->data points to the aligned start of the packet.
1295 struct sk_buff
*new_skb
= dev_alloc_skb(MAX_MEDIA_DATA_SIZE
+ 2 * L1_CACHE_BYTES
);
1297 np
->stats
.rx_errors
++;
1298 printk(KERN_NOTICE
"%s: Memory squeeze, dropping packet.\n", dev
->name
);
1299 goto update_nextrxdesc
;
1301 skb
= myNextRxDesc
->skb
;
1302 align
= (int)phys_to_virt(myNextRxDesc
->descr
.buf
) - (int)skb
->data
;
1303 skb_put(skb
, length
+ align
);
1304 skb_pull(skb
, align
); /* Remove alignment bytes */
1305 myNextRxDesc
->skb
= new_skb
;
1306 myNextRxDesc
->descr
.buf
= L1_CACHE_ALIGN(virt_to_phys(myNextRxDesc
->skb
->data
));
1309 skb
->protocol
= eth_type_trans(skb
, dev
);
1311 /* Send the packet to the upper layers */
1315 /* Prepare for next packet */
1316 myNextRxDesc
->descr
.status
= 0;
1317 prevRxDesc
= myNextRxDesc
;
1318 myNextRxDesc
= phys_to_virt(myNextRxDesc
->descr
.next
);
1322 /* Check if descriptors should be returned */
1323 if (rx_queue_len
== RX_QUEUE_THRESHOLD
) {
1324 flush_etrax_cache();
1325 prevRxDesc
->descr
.ctrl
|= d_eol
;
1326 myLastRxDesc
->descr
.ctrl
&= ~d_eol
;
1327 myLastRxDesc
= prevRxDesc
;
1332 /* The inverse routine to net_open(). */
1334 e100_close(struct net_device
*dev
)
1336 struct net_local
*np
= netdev_priv(dev
);
1338 printk(KERN_INFO
"Closing %s.\n", dev
->name
);
1340 netif_stop_queue(dev
);
1343 IO_STATE(R_IRQ_MASK0_CLR
, overrun
, clr
) |
1344 IO_STATE(R_IRQ_MASK0_CLR
, underrun
, clr
) |
1345 IO_STATE(R_IRQ_MASK0_CLR
, excessive_col
, clr
);
1348 IO_STATE(R_IRQ_MASK2_CLR
, dma0_descr
, clr
) |
1349 IO_STATE(R_IRQ_MASK2_CLR
, dma0_eop
, clr
) |
1350 IO_STATE(R_IRQ_MASK2_CLR
, dma1_descr
, clr
) |
1351 IO_STATE(R_IRQ_MASK2_CLR
, dma1_eop
, clr
);
1353 /* Stop the receiver and the transmitter */
1355 RESET_DMA(NETWORK_TX_DMA_NBR
);
1356 RESET_DMA(NETWORK_RX_DMA_NBR
);
1358 /* Flush the Tx and disable Rx here. */
1360 free_irq(NETWORK_DMA_RX_IRQ_NBR
, (void *)dev
);
1361 free_irq(NETWORK_DMA_TX_IRQ_NBR
, (void *)dev
);
1362 free_irq(NETWORK_STATUS_IRQ_NBR
, (void *)dev
);
1364 cris_free_dma(NETWORK_TX_DMA_NBR
, cardname
);
1365 cris_free_dma(NETWORK_RX_DMA_NBR
, cardname
);
1367 /* Update the statistics here. */
1369 update_rx_stats(&np
->stats
);
1370 update_tx_stats(&np
->stats
);
1372 /* Stop speed/duplex timers */
1373 del_timer(&speed_timer
);
1374 del_timer(&duplex_timer
);
1380 e100_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1382 struct mii_ioctl_data
*data
= if_mii(ifr
);
1383 struct net_local
*np
= netdev_priv(dev
);
1387 spin_lock(&np
->lock
); /* Preempt protection */
1389 /* The ioctls below should be considered obsolete but are */
1390 /* still present for compatability with old scripts/apps */
1391 case SET_ETH_SPEED_10
: /* 10 Mbps */
1392 e100_set_speed(dev
, 10);
1394 case SET_ETH_SPEED_100
: /* 100 Mbps */
1395 e100_set_speed(dev
, 100);
1397 case SET_ETH_SPEED_AUTO
: /* Auto-negotiate speed */
1398 e100_set_speed(dev
, 0);
1400 case SET_ETH_DUPLEX_HALF
: /* Half duplex */
1401 e100_set_duplex(dev
, half
);
1403 case SET_ETH_DUPLEX_FULL
: /* Full duplex */
1404 e100_set_duplex(dev
, full
);
1406 case SET_ETH_DUPLEX_AUTO
: /* Auto-negotiate duplex */
1407 e100_set_duplex(dev
, autoneg
);
1409 case SET_ETH_AUTONEG
:
1410 old_autoneg
= autoneg_normal
;
1411 autoneg_normal
= *(int*)data
;
1412 if (autoneg_normal
!= old_autoneg
)
1413 e100_negotiate(dev
);
1416 rc
= generic_mii_ioctl(&np
->mii_if
, if_mii(ifr
),
1420 spin_unlock(&np
->lock
);
1424 static int e100_get_settings(struct net_device
*dev
,
1425 struct ethtool_cmd
*cmd
)
1427 struct net_local
*np
= netdev_priv(dev
);
1430 spin_lock_irq(&np
->lock
);
1431 err
= mii_ethtool_gset(&np
->mii_if
, cmd
);
1432 spin_unlock_irq(&np
->lock
);
1434 /* The PHY may support 1000baseT, but the Etrax100 does not. */
1435 cmd
->supported
&= ~(SUPPORTED_1000baseT_Half
1436 | SUPPORTED_1000baseT_Full
);
1440 static int e100_set_settings(struct net_device
*dev
,
1441 struct ethtool_cmd
*ecmd
)
1443 if (ecmd
->autoneg
== AUTONEG_ENABLE
) {
1444 e100_set_duplex(dev
, autoneg
);
1445 e100_set_speed(dev
, 0);
1447 e100_set_duplex(dev
, ecmd
->duplex
== DUPLEX_HALF
? half
: full
);
1448 e100_set_speed(dev
, ecmd
->speed
== SPEED_10
? 10: 100);
1454 static void e100_get_drvinfo(struct net_device
*dev
,
1455 struct ethtool_drvinfo
*info
)
1457 strncpy(info
->driver
, "ETRAX 100LX", sizeof(info
->driver
) - 1);
1458 strncpy(info
->version
, "$Revision: 1.31 $", sizeof(info
->version
) - 1);
1459 strncpy(info
->fw_version
, "N/A", sizeof(info
->fw_version
) - 1);
1460 strncpy(info
->bus_info
, "N/A", sizeof(info
->bus_info
) - 1);
1463 static int e100_nway_reset(struct net_device
*dev
)
1465 if (current_duplex
== autoneg
&& current_speed_selection
== 0)
1466 e100_negotiate(dev
);
1470 static const struct ethtool_ops e100_ethtool_ops
= {
1471 .get_settings
= e100_get_settings
,
1472 .set_settings
= e100_set_settings
,
1473 .get_drvinfo
= e100_get_drvinfo
,
1474 .nway_reset
= e100_nway_reset
,
1475 .get_link
= ethtool_op_get_link
,
1479 e100_set_config(struct net_device
*dev
, struct ifmap
*map
)
1481 struct net_local
*np
= netdev_priv(dev
);
1483 spin_lock(&np
->lock
); /* Preempt protection */
1486 case IF_PORT_UNKNOWN
:
1488 e100_set_speed(dev
, 0);
1489 e100_set_duplex(dev
, autoneg
);
1491 case IF_PORT_10BASET
:
1492 e100_set_speed(dev
, 10);
1493 e100_set_duplex(dev
, autoneg
);
1495 case IF_PORT_100BASET
:
1496 case IF_PORT_100BASETX
:
1497 e100_set_speed(dev
, 100);
1498 e100_set_duplex(dev
, autoneg
);
1500 case IF_PORT_100BASEFX
:
1501 case IF_PORT_10BASE2
:
1503 spin_unlock(&np
->lock
);
1507 printk(KERN_ERR
"%s: Invalid media selected", dev
->name
);
1508 spin_unlock(&np
->lock
);
1511 spin_unlock(&np
->lock
);
1516 update_rx_stats(struct net_device_stats
*es
)
1518 unsigned long r
= *R_REC_COUNTERS
;
1519 /* update stats relevant to reception errors */
1520 es
->rx_fifo_errors
+= IO_EXTRACT(R_REC_COUNTERS
, congestion
, r
);
1521 es
->rx_crc_errors
+= IO_EXTRACT(R_REC_COUNTERS
, crc_error
, r
);
1522 es
->rx_frame_errors
+= IO_EXTRACT(R_REC_COUNTERS
, alignment_error
, r
);
1523 es
->rx_length_errors
+= IO_EXTRACT(R_REC_COUNTERS
, oversize
, r
);
1527 update_tx_stats(struct net_device_stats
*es
)
1529 unsigned long r
= *R_TR_COUNTERS
;
1530 /* update stats relevant to transmission errors */
1532 IO_EXTRACT(R_TR_COUNTERS
, single_col
, r
) +
1533 IO_EXTRACT(R_TR_COUNTERS
, multiple_col
, r
);
1537 * Get the current statistics.
1538 * This may be called with the card open or closed.
1540 static struct net_device_stats
*
1541 e100_get_stats(struct net_device
*dev
)
1543 struct net_local
*lp
= netdev_priv(dev
);
1544 unsigned long flags
;
1546 spin_lock_irqsave(&lp
->lock
, flags
);
1548 update_rx_stats(&lp
->stats
);
1549 update_tx_stats(&lp
->stats
);
1551 spin_unlock_irqrestore(&lp
->lock
, flags
);
1556 * Set or clear the multicast filter for this adaptor.
1557 * num_addrs == -1 Promiscuous mode, receive all packets
1558 * num_addrs == 0 Normal mode, clear multicast list
1559 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1560 * and do best-effort filtering.
1563 set_multicast_list(struct net_device
*dev
)
1565 struct net_local
*lp
= netdev_priv(dev
);
1566 int num_addr
= netdev_mc_count(dev
);
1567 unsigned long int lo_bits
;
1568 unsigned long int hi_bits
;
1570 spin_lock(&lp
->lock
);
1571 if (dev
->flags
& IFF_PROMISC
) {
1572 /* promiscuous mode */
1573 lo_bits
= 0xfffffffful
;
1574 hi_bits
= 0xfffffffful
;
1576 /* Enable individual receive */
1577 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, individual
, receive
);
1578 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
1579 } else if (dev
->flags
& IFF_ALLMULTI
) {
1580 /* enable all multicasts */
1581 lo_bits
= 0xfffffffful
;
1582 hi_bits
= 0xfffffffful
;
1584 /* Disable individual receive */
1585 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, individual
, discard
);
1586 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
1587 } else if (num_addr
== 0) {
1588 /* Normal, clear the mc list */
1589 lo_bits
= 0x00000000ul
;
1590 hi_bits
= 0x00000000ul
;
1592 /* Disable individual receive */
1593 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, individual
, discard
);
1594 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
1596 /* MC mode, receive normal and MC packets */
1598 struct netdev_hw_addr
*ha
;
1601 lo_bits
= 0x00000000ul
;
1602 hi_bits
= 0x00000000ul
;
1603 netdev_for_each_mc_addr(ha
, dev
) {
1604 /* Calculate the hash index for the GA registers */
1608 hash_ix
^= (*baddr
) & 0x3f;
1609 hash_ix
^= ((*baddr
) >> 6) & 0x03;
1611 hash_ix
^= ((*baddr
) << 2) & 0x03c;
1612 hash_ix
^= ((*baddr
) >> 4) & 0xf;
1614 hash_ix
^= ((*baddr
) << 4) & 0x30;
1615 hash_ix
^= ((*baddr
) >> 2) & 0x3f;
1617 hash_ix
^= (*baddr
) & 0x3f;
1618 hash_ix
^= ((*baddr
) >> 6) & 0x03;
1620 hash_ix
^= ((*baddr
) << 2) & 0x03c;
1621 hash_ix
^= ((*baddr
) >> 4) & 0xf;
1623 hash_ix
^= ((*baddr
) << 4) & 0x30;
1624 hash_ix
^= ((*baddr
) >> 2) & 0x3f;
1628 if (hash_ix
>= 32) {
1629 hi_bits
|= (1 << (hash_ix
-32));
1631 lo_bits
|= (1 << hash_ix
);
1634 /* Disable individual receive */
1635 SETS(network_rec_config_shadow
, R_NETWORK_REC_CONFIG
, individual
, discard
);
1636 *R_NETWORK_REC_CONFIG
= network_rec_config_shadow
;
1638 *R_NETWORK_GA_0
= lo_bits
;
1639 *R_NETWORK_GA_1
= hi_bits
;
1640 spin_unlock(&lp
->lock
);
1644 e100_hardware_send_packet(struct net_local
*np
, char *buf
, int length
)
1646 D(printk("e100 send pack, buf 0x%x len %d\n", buf
, length
));
1648 spin_lock(&np
->led_lock
);
1649 if (!led_active
&& time_after(jiffies
, led_next_time
)) {
1650 /* light the network leds depending on the current speed. */
1651 e100_set_network_leds(NETWORK_ACTIVITY
);
1653 /* Set the earliest time we may clear the LED */
1654 led_next_time
= jiffies
+ NET_FLASH_TIME
;
1656 mod_timer(&clear_led_timer
, jiffies
+ HZ
/10);
1658 spin_unlock(&np
->led_lock
);
1660 /* configure the tx dma descriptor */
1661 myNextTxDesc
->descr
.sw_len
= length
;
1662 myNextTxDesc
->descr
.ctrl
= d_eop
| d_eol
| d_wait
;
1663 myNextTxDesc
->descr
.buf
= virt_to_phys(buf
);
1665 /* Move end of list */
1666 myLastTxDesc
->descr
.ctrl
&= ~d_eol
;
1667 myLastTxDesc
= myNextTxDesc
;
1669 /* Restart DMA channel */
1670 *R_DMA_CH0_CMD
= IO_STATE(R_DMA_CH0_CMD
, cmd
, restart
);
1674 e100_clear_network_leds(unsigned long dummy
)
1676 struct net_device
*dev
= (struct net_device
*)dummy
;
1677 struct net_local
*np
= netdev_priv(dev
);
1679 spin_lock(&np
->led_lock
);
1681 if (led_active
&& time_after(jiffies
, led_next_time
)) {
1682 e100_set_network_leds(NO_NETWORK_ACTIVITY
);
1684 /* Set the earliest time we may set the LED */
1685 led_next_time
= jiffies
+ NET_FLASH_PAUSE
;
1689 spin_unlock(&np
->led_lock
);
1693 e100_set_network_leds(int active
)
1695 #if defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK)
1696 int light_leds
= (active
== NO_NETWORK_ACTIVITY
);
1697 #elif defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY)
1698 int light_leds
= (active
== NETWORK_ACTIVITY
);
1700 #error "Define either CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK or CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY"
1703 if (!current_speed
) {
1704 /* Make LED red, link is down */
1705 CRIS_LED_NETWORK_SET(CRIS_LED_OFF
);
1706 } else if (light_leds
) {
1707 if (current_speed
== 10) {
1708 CRIS_LED_NETWORK_SET(CRIS_LED_ORANGE
);
1710 CRIS_LED_NETWORK_SET(CRIS_LED_GREEN
);
1713 CRIS_LED_NETWORK_SET(CRIS_LED_OFF
);
1717 #ifdef CONFIG_NET_POLL_CONTROLLER
1719 e100_netpoll(struct net_device
* netdev
)
1721 e100rxtx_interrupt(NETWORK_DMA_TX_IRQ_NBR
, netdev
, NULL
);
1726 etrax_init_module(void)
1728 return etrax_ethernet_init();
1732 e100_boot_setup(char* str
)
1734 struct sockaddr sa
= {0};
1737 /* Parse the colon separated Ethernet station address */
1738 for (i
= 0; i
< ETH_ALEN
; i
++) {
1740 if (sscanf(str
+ 3*i
, "%2x", &tmp
) != 1) {
1741 printk(KERN_WARNING
"Malformed station address");
1744 sa
.sa_data
[i
] = (char)tmp
;
1751 __setup("etrax100_eth=", e100_boot_setup
);
1753 module_init(etrax_init_module
);