blob: 64105e4eaf31fec7aa643ff55338748fc05eb5ac [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: ethernet.c,v 1.31 2004/10/18 14:49:03 starvik Exp $
2 *
3 * e100net.c: A network driver for the ETRAX 100LX network controller.
4 *
5 * Copyright (c) 1998-2002 Axis Communications AB.
6 *
7 * The outline of this driver comes from skeleton.c.
8 *
9 * $Log: ethernet.c,v $
10 * Revision 1.31 2004/10/18 14:49:03 starvik
11 * Use RX interrupt as random source
12 *
13 * Revision 1.30 2004/09/29 10:44:04 starvik
14 * Enabed MAC-address output again
15 *
16 * Revision 1.29 2004/08/24 07:14:05 starvik
17 * Make use of generic MDIO interface and constants.
18 *
19 * Revision 1.28 2004/08/20 09:37:11 starvik
20 * Added support for Intel LXT972A. Creds to Randy Scarborough.
21 *
22 * Revision 1.27 2004/08/16 12:37:22 starvik
23 * Merge of Linux 2.6.8
24 *
25 * Revision 1.25 2004/06/21 10:29:57 starvik
26 * Merge of Linux 2.6.7
27 *
28 * Revision 1.23 2004/06/09 05:29:22 starvik
29 * Avoid any race where R_DMA_CH1_FIRST is NULL (may trigger cache bug).
30 *
31 * Revision 1.22 2004/05/14 07:58:03 starvik
32 * Merge of changes from 2.4
33 *
34 * Revision 1.20 2004/03/11 11:38:40 starvik
35 * Merge of Linux 2.6.4
36 *
37 * Revision 1.18 2003/12/03 13:45:46 starvik
38 * Use hardware pad for short packets to prevent information leakage.
39 *
40 * Revision 1.17 2003/07/04 08:27:37 starvik
41 * Merge of Linux 2.5.74
42 *
43 * Revision 1.16 2003/04/24 08:28:22 starvik
44 * New LED behaviour: LED off when no link
45 *
46 * Revision 1.15 2003/04/09 05:20:47 starvik
47 * Merge of Linux 2.5.67
48 *
49 * Revision 1.13 2003/03/06 16:11:01 henriken
50 * Off by one error in group address register setting.
51 *
52 * Revision 1.12 2003/02/27 17:24:19 starvik
53 * Corrected Rev to Revision
54 *
55 * Revision 1.11 2003/01/24 09:53:21 starvik
56 * Oops. Initialize GA to 0, not to 1
57 *
58 * Revision 1.10 2003/01/24 09:50:55 starvik
59 * Initialize GA_0 and GA_1 to 0 to avoid matching of unwanted packets
60 *
61 * Revision 1.9 2002/12/13 07:40:58 starvik
62 * Added basic ethtool interface
63 * Handled out of memory when allocating new buffers
64 *
65 * Revision 1.8 2002/12/11 13:13:57 starvik
66 * Added arch/ to v10 specific includes
67 * Added fix from Linux 2.4 in serial.c (flush_to_flip_buffer)
68 *
69 * Revision 1.7 2002/11/26 09:41:42 starvik
70 * Added e100_set_config (standard interface to set media type)
71 * Added protection against preemptive scheduling
72 * Added standard MII ioctls
73 *
74 * Revision 1.6 2002/11/21 07:18:18 starvik
75 * Timers must be initialized in 2.5.48
76 *
77 * Revision 1.5 2002/11/20 11:56:11 starvik
78 * Merge of Linux 2.5.48
79 *
80 * Revision 1.4 2002/11/18 07:26:46 starvik
81 * Linux 2.5 port of latest Linux 2.4 ethernet driver
82 *
83 * Revision 1.33 2002/10/02 20:16:17 hp
84 * SETF, SETS: Use underscored IO_x_ macros rather than incorrect token concatenation
85 *
86 * Revision 1.32 2002/09/16 06:05:58 starvik
87 * Align memory returned by dev_alloc_skb
88 * Moved handling of sent packets to interrupt to avoid reference counting problem
89 *
90 * Revision 1.31 2002/09/10 13:28:23 larsv
91 * Return -EINVAL for unknown ioctls to avoid confusing tools that tests
92 * for supported functionality by issuing special ioctls, i.e. wireless
93 * extensions.
94 *
95 * Revision 1.30 2002/05/07 18:50:08 johana
96 * Correct spelling in comments.
97 *
98 * Revision 1.29 2002/05/06 05:38:49 starvik
99 * Performance improvements:
100 * Large packets are not copied (breakpoint set to 256 bytes)
101 * The cache bug workaround is delayed until half of the receive list
102 * has been used
103 * Added transmit list
104 * Transmit interrupts are only enabled when transmit queue is full
105 *
106 * Revision 1.28.2.1 2002/04/30 08:15:51 starvik
107 * Performance improvements:
108 * Large packets are not copied (breakpoint set to 256 bytes)
109 * The cache bug workaround is delayed until half of the receive list
110 * has been used.
111 * Added transmit list
112 * Transmit interrupts are only enabled when transmit queue is full
113 *
114 * Revision 1.28 2002/04/22 11:47:21 johana
115 * Fix according to 2.4.19-pre7. time_after/time_before and
116 * missing end of comment.
117 * The patch has a typo for ethernet.c in e100_clear_network_leds(),
118 * that is fixed here.
119 *
120 * Revision 1.27 2002/04/12 11:55:11 bjornw
121 * Added TODO
122 *
123 * Revision 1.26 2002/03/15 17:11:02 bjornw
124 * Use prepare_rx_descriptor after the CPU has touched the receiving descs
125 *
126 * Revision 1.25 2002/03/08 13:07:53 bjornw
127 * Unnecessary spinlock removed
128 *
129 * Revision 1.24 2002/02/20 12:57:43 fredriks
130 * Replaced MIN() with min().
131 *
132 * Revision 1.23 2002/02/20 10:58:14 fredriks
133 * Strip the Ethernet checksum (4 bytes) before forwarding a frame to upper layers.
134 *
135 * Revision 1.22 2002/01/30 07:48:22 matsfg
136 * Initiate R_NETWORK_TR_CTRL
137 *
138 * Revision 1.21 2001/11/23 11:54:49 starvik
139 * Added IFF_PROMISC and IFF_ALLMULTI handling in set_multicast_list
140 * Removed compiler warnings
141 *
142 * Revision 1.20 2001/11/12 19:26:00 pkj
143 * * Corrected e100_negotiate() to not assign half to current_duplex when
144 * it was supposed to compare them...
145 * * Cleaned up failure handling in e100_open().
146 * * Fixed compiler warnings.
147 *
148 * Revision 1.19 2001/11/09 07:43:09 starvik
149 * Added full duplex support
150 * Added ioctl to set speed and duplex
151 * Clear LED timer only runs when LED is lit
152 *
153 * Revision 1.18 2001/10/03 14:40:43 jonashg
154 * Update rx_bytes counter.
155 *
156 * Revision 1.17 2001/06/11 12:43:46 olof
157 * Modified defines for network LED behavior
158 *
159 * Revision 1.16 2001/05/30 06:12:46 markusl
160 * TxDesc.next should not be set to NULL
161 *
162 * Revision 1.15 2001/05/29 10:27:04 markusl
163 * Updated after review remarks:
164 * +Use IO_EXTRACT
165 * +Handle underrun
166 *
167 * Revision 1.14 2001/05/29 09:20:14 jonashg
168 * Use driver name on printk output so one can tell which driver that complains.
169 *
170 * Revision 1.13 2001/05/09 12:35:59 johana
171 * Use DMA_NBR and IRQ_NBR defines from dma.h and irq.h
172 *
173 * Revision 1.12 2001/04/05 11:43:11 tobiasa
174 * Check dev before panic.
175 *
176 * Revision 1.11 2001/04/04 11:21:05 markusl
177 * Updated according to review remarks
178 *
179 * Revision 1.10 2001/03/26 16:03:06 bjornw
180 * Needs linux/config.h
181 *
182 * Revision 1.9 2001/03/19 14:47:48 pkj
183 * * Make sure there is always a pause after the network LEDs are
184 * changed so they will not look constantly lit during heavy traffic.
185 * * Always use HZ when setting times relative to jiffies.
186 * * Use LED_NETWORK_SET() when setting the network LEDs.
187 *
188 * Revision 1.8 2001/02/27 13:52:48 bjornw
189 * malloc.h -> slab.h
190 *
191 * Revision 1.7 2001/02/23 13:46:38 bjornw
192 * Spellling check
193 *
194 * Revision 1.6 2001/01/26 15:21:04 starvik
195 * Don't disable interrupts while reading MDIO registers (MDIO is slow)
196 * Corrected promiscuous mode
197 * Improved deallocation of IRQs ("ifconfig eth0 down" now works)
198 *
199 * Revision 1.5 2000/11/29 17:22:22 bjornw
200 * Get rid of the udword types legacy stuff
201 *
202 * Revision 1.4 2000/11/22 16:36:09 bjornw
203 * Please marketing by using the correct case when spelling Etrax.
204 *
205 * Revision 1.3 2000/11/21 16:43:04 bjornw
206 * Minor short->int change
207 *
208 * Revision 1.2 2000/11/08 14:27:57 bjornw
209 * 2.4 port
210 *
211 * Revision 1.1 2000/11/06 13:56:00 bjornw
212 * Verbatim copy of the 1.24 version of e100net.c from elinux
213 *
214 * Revision 1.24 2000/10/04 15:55:23 bjornw
215 * * Use virt_to_phys etc. for DMA addresses
216 * * Removed bogus CHECKSUM_UNNECESSARY
217 *
218 *
219 */
220
221#include <linux/config.h>
222
223#include <linux/module.h>
224
225#include <linux/kernel.h>
226#include <linux/sched.h>
227#include <linux/delay.h>
228#include <linux/types.h>
229#include <linux/fcntl.h>
230#include <linux/interrupt.h>
231#include <linux/ptrace.h>
232#include <linux/ioport.h>
233#include <linux/in.h>
234#include <linux/slab.h>
235#include <linux/string.h>
236#include <linux/spinlock.h>
237#include <linux/errno.h>
238#include <linux/init.h>
239
240#include <linux/if.h>
241#include <linux/mii.h>
242#include <linux/netdevice.h>
243#include <linux/etherdevice.h>
244#include <linux/skbuff.h>
245#include <linux/ethtool.h>
246
247#include <asm/arch/svinto.h>/* DMA and register descriptions */
248#include <asm/io.h> /* LED_* I/O functions */
249#include <asm/irq.h>
250#include <asm/dma.h>
251#include <asm/system.h>
252#include <asm/bitops.h>
253#include <asm/ethernet.h>
254#include <asm/cache.h>
255
256//#define ETHDEBUG
257#define D(x)
258
259/*
260 * The name of the card. Is used for messages and in the requests for
261 * io regions, irqs and dma channels
262 */
263
264static const char* cardname = "ETRAX 100LX built-in ethernet controller";
265
266/* A default ethernet address. Highlevel SW will set the real one later */
267
268static struct sockaddr default_mac = {
269 0,
270 { 0x00, 0x40, 0x8C, 0xCD, 0x00, 0x00 }
271};
272
273/* Information that need to be kept for each board. */
274struct net_local {
275 struct net_device_stats stats;
276 struct mii_if_info mii_if;
277
278 /* Tx control lock. This protects the transmit buffer ring
279 * state along with the "tx full" state of the driver. This
280 * means all netif_queue flow control actions are protected
281 * by this lock as well.
282 */
283 spinlock_t lock;
284};
285
286typedef struct etrax_eth_descr
287{
288 etrax_dma_descr descr;
289 struct sk_buff* skb;
290} etrax_eth_descr;
291
292/* Some transceivers requires special handling */
293struct transceiver_ops
294{
295 unsigned int oui;
296 void (*check_speed)(struct net_device* dev);
297 void (*check_duplex)(struct net_device* dev);
298};
299
300struct transceiver_ops* transceiver;
301
302/* Duplex settings */
303enum duplex
304{
305 half,
306 full,
307 autoneg
308};
309
310/* Dma descriptors etc. */
311
312#define MAX_MEDIA_DATA_SIZE 1518
313
314#define MIN_PACKET_LEN 46
315#define ETHER_HEAD_LEN 14
316
317/*
318** MDIO constants.
319*/
320#define MDIO_START 0x1
321#define MDIO_READ 0x2
322#define MDIO_WRITE 0x1
323#define MDIO_PREAMBLE 0xfffffffful
324
325/* Broadcom specific */
326#define MDIO_AUX_CTRL_STATUS_REG 0x18
327#define MDIO_BC_FULL_DUPLEX_IND 0x1
328#define MDIO_BC_SPEED 0x2
329
330/* TDK specific */
331#define MDIO_TDK_DIAGNOSTIC_REG 18
332#define MDIO_TDK_DIAGNOSTIC_RATE 0x400
333#define MDIO_TDK_DIAGNOSTIC_DPLX 0x800
334
335/*Intel LXT972A specific*/
336#define MDIO_INT_STATUS_REG_2 0x0011
337#define MDIO_INT_FULL_DUPLEX_IND ( 1 << 9 )
338#define MDIO_INT_SPEED ( 1 << 14 )
339
340/* Network flash constants */
341#define NET_FLASH_TIME (HZ/50) /* 20 ms */
342#define NET_FLASH_PAUSE (HZ/100) /* 10 ms */
343#define NET_LINK_UP_CHECK_INTERVAL (2*HZ) /* 2 s */
344#define NET_DUPLEX_CHECK_INTERVAL (2*HZ) /* 2 s */
345
346#define NO_NETWORK_ACTIVITY 0
347#define NETWORK_ACTIVITY 1
348
349#define NBR_OF_RX_DESC 64
350#define NBR_OF_TX_DESC 256
351
352/* Large packets are sent directly to upper layers while small packets are */
353/* copied (to reduce memory waste). The following constant decides the breakpoint */
354#define RX_COPYBREAK 256
355
356/* Due to a chip bug we need to flush the cache when descriptors are returned */
357/* to the DMA. To decrease performance impact we return descriptors in chunks. */
358/* The following constant determines the number of descriptors to return. */
359#define RX_QUEUE_THRESHOLD NBR_OF_RX_DESC/2
360
361#define GET_BIT(bit,val) (((val) >> (bit)) & 0x01)
362
363/* Define some macros to access ETRAX 100 registers */
364#define SETF(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \
365 IO_FIELD_(reg##_, field##_, val)
366#define SETS(var, reg, field, val) var = (var & ~IO_MASK_(reg##_, field##_)) | \
367 IO_STATE_(reg##_, field##_, _##val)
368
369static etrax_eth_descr *myNextRxDesc; /* Points to the next descriptor to
370 to be processed */
371static etrax_eth_descr *myLastRxDesc; /* The last processed descriptor */
372static etrax_eth_descr *myPrevRxDesc; /* The descriptor right before myNextRxDesc */
373
374static etrax_eth_descr RxDescList[NBR_OF_RX_DESC] __attribute__ ((aligned(32)));
375
376static etrax_eth_descr* myFirstTxDesc; /* First packet not yet sent */
377static etrax_eth_descr* myLastTxDesc; /* End of send queue */
378static etrax_eth_descr* myNextTxDesc; /* Next descriptor to use */
379static etrax_eth_descr TxDescList[NBR_OF_TX_DESC] __attribute__ ((aligned(32)));
380
381static unsigned int network_rec_config_shadow = 0;
382static unsigned int mdio_phy_addr; /* Transciever address */
383
384static unsigned int network_tr_ctrl_shadow = 0;
385
386/* Network speed indication. */
Ingo Molnar8d06afa2005-09-09 13:10:40 -0700387static DEFINE_TIMER(speed_timer, NULL, 0, 0);
388static DEFINE_TIMER(clear_led_timer, NULL, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389static int current_speed; /* Speed read from transceiver */
390static int current_speed_selection; /* Speed selected by user */
391static unsigned long led_next_time;
392static int led_active;
393static int rx_queue_len;
394
395/* Duplex */
Ingo Molnar8d06afa2005-09-09 13:10:40 -0700396static DEFINE_TIMER(duplex_timer, NULL, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397static int full_duplex;
398static enum duplex current_duplex;
399
400/* Index to functions, as function prototypes. */
401
402static int etrax_ethernet_init(void);
403
404static int e100_open(struct net_device *dev);
405static int e100_set_mac_address(struct net_device *dev, void *addr);
406static int e100_send_packet(struct sk_buff *skb, struct net_device *dev);
407static irqreturn_t e100rxtx_interrupt(int irq, void *dev_id, struct pt_regs *regs);
408static irqreturn_t e100nw_interrupt(int irq, void *dev_id, struct pt_regs *regs);
409static void e100_rx(struct net_device *dev);
410static int e100_close(struct net_device *dev);
411static int e100_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412static int e100_set_config(struct net_device* dev, struct ifmap* map);
413static void e100_tx_timeout(struct net_device *dev);
414static struct net_device_stats *e100_get_stats(struct net_device *dev);
415static void set_multicast_list(struct net_device *dev);
416static void e100_hardware_send_packet(char *buf, int length);
417static void update_rx_stats(struct net_device_stats *);
418static void update_tx_stats(struct net_device_stats *);
419static int e100_probe_transceiver(struct net_device* dev);
420
421static void e100_check_speed(unsigned long priv);
422static void e100_set_speed(struct net_device* dev, unsigned long speed);
423static void e100_check_duplex(unsigned long priv);
424static void e100_set_duplex(struct net_device* dev, enum duplex);
425static void e100_negotiate(struct net_device* dev);
426
427static int e100_get_mdio_reg(struct net_device *dev, int phy_id, int location);
428static void e100_set_mdio_reg(struct net_device *dev, int phy_id, int location, int value);
429
430static void e100_send_mdio_cmd(unsigned short cmd, int write_cmd);
431static void e100_send_mdio_bit(unsigned char bit);
432static unsigned char e100_receive_mdio_bit(void);
433static void e100_reset_transceiver(struct net_device* net);
434
435static void e100_clear_network_leds(unsigned long dummy);
436static void e100_set_network_leds(int active);
437
Christoph Hellwig76f2b4d2005-11-07 06:18:57 +0100438static struct ethtool_ops e100_ethtool_ops;
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440static void broadcom_check_speed(struct net_device* dev);
441static void broadcom_check_duplex(struct net_device* dev);
442static void tdk_check_speed(struct net_device* dev);
443static void tdk_check_duplex(struct net_device* dev);
444static void intel_check_speed(struct net_device* dev);
445static void intel_check_duplex(struct net_device* dev);
446static void generic_check_speed(struct net_device* dev);
447static void generic_check_duplex(struct net_device* dev);
448
449struct transceiver_ops transceivers[] =
450{
451 {0x1018, broadcom_check_speed, broadcom_check_duplex}, /* Broadcom */
452 {0xC039, tdk_check_speed, tdk_check_duplex}, /* TDK 2120 */
453 {0x039C, tdk_check_speed, tdk_check_duplex}, /* TDK 2120C */
454 {0x04de, intel_check_speed, intel_check_duplex}, /* Intel LXT972A*/
455 {0x0000, generic_check_speed, generic_check_duplex} /* Generic, must be last */
456};
457
458#define tx_done(dev) (*R_DMA_CH0_CMD == 0)
459
460/*
461 * Check for a network adaptor of this type, and return '0' if one exists.
462 * If dev->base_addr == 0, probe all likely locations.
463 * If dev->base_addr == 1, always return failure.
464 * If dev->base_addr == 2, allocate space for the device and return success
465 * (detachable devices only).
466 */
467
468static int __init
469etrax_ethernet_init(void)
470{
471 struct net_device *dev;
472 struct net_local* np;
473 int i, err;
474
475 printk(KERN_INFO
476 "ETRAX 100LX 10/100MBit ethernet v2.0 (c) 2000-2003 Axis Communications AB\n");
477
478 dev = alloc_etherdev(sizeof(struct net_local));
479 np = dev->priv;
480
481 if (!dev)
482 return -ENOMEM;
483
484 dev->base_addr = (unsigned int)R_NETWORK_SA_0; /* just to have something to show */
485
486 /* now setup our etrax specific stuff */
487
488 dev->irq = NETWORK_DMA_RX_IRQ_NBR; /* we really use DMATX as well... */
489 dev->dma = NETWORK_RX_DMA_NBR;
490
491 /* fill in our handlers so the network layer can talk to us in the future */
492
493 dev->open = e100_open;
494 dev->hard_start_xmit = e100_send_packet;
495 dev->stop = e100_close;
496 dev->get_stats = e100_get_stats;
497 dev->set_multicast_list = set_multicast_list;
498 dev->set_mac_address = e100_set_mac_address;
Christoph Hellwig76f2b4d2005-11-07 06:18:57 +0100499 dev->ethtool_ops = &e100_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 dev->do_ioctl = e100_ioctl;
501 dev->set_config = e100_set_config;
502 dev->tx_timeout = e100_tx_timeout;
503
504 /* Initialise the list of Etrax DMA-descriptors */
505
506 /* Initialise receive descriptors */
507
508 for (i = 0; i < NBR_OF_RX_DESC; i++) {
509 /* Allocate two extra cachelines to make sure that buffer used by DMA
510 * does not share cacheline with any other data (to avoid cache bug)
511 */
512 RxDescList[i].skb = dev_alloc_skb(MAX_MEDIA_DATA_SIZE + 2 * L1_CACHE_BYTES);
513 RxDescList[i].descr.ctrl = 0;
514 RxDescList[i].descr.sw_len = MAX_MEDIA_DATA_SIZE;
515 RxDescList[i].descr.next = virt_to_phys(&RxDescList[i + 1]);
516 RxDescList[i].descr.buf = L1_CACHE_ALIGN(virt_to_phys(RxDescList[i].skb->data));
517 RxDescList[i].descr.status = 0;
518 RxDescList[i].descr.hw_len = 0;
519 prepare_rx_descriptor(&RxDescList[i].descr);
520 }
521
522 RxDescList[NBR_OF_RX_DESC - 1].descr.ctrl = d_eol;
523 RxDescList[NBR_OF_RX_DESC - 1].descr.next = virt_to_phys(&RxDescList[0]);
524 rx_queue_len = 0;
525
526 /* Initialize transmit descriptors */
527 for (i = 0; i < NBR_OF_TX_DESC; i++) {
528 TxDescList[i].descr.ctrl = 0;
529 TxDescList[i].descr.sw_len = 0;
530 TxDescList[i].descr.next = virt_to_phys(&TxDescList[i + 1].descr);
531 TxDescList[i].descr.buf = 0;
532 TxDescList[i].descr.status = 0;
533 TxDescList[i].descr.hw_len = 0;
534 TxDescList[i].skb = 0;
535 }
536
537 TxDescList[NBR_OF_TX_DESC - 1].descr.ctrl = d_eol;
538 TxDescList[NBR_OF_TX_DESC - 1].descr.next = virt_to_phys(&TxDescList[0].descr);
539
540 /* Initialise initial pointers */
541
542 myNextRxDesc = &RxDescList[0];
543 myLastRxDesc = &RxDescList[NBR_OF_RX_DESC - 1];
544 myPrevRxDesc = &RxDescList[NBR_OF_RX_DESC - 1];
545 myFirstTxDesc = &TxDescList[0];
546 myNextTxDesc = &TxDescList[0];
547 myLastTxDesc = &TxDescList[NBR_OF_TX_DESC - 1];
548
549 /* Register device */
550 err = register_netdev(dev);
551 if (err) {
552 free_netdev(dev);
553 return err;
554 }
555
556 /* set the default MAC address */
557
558 e100_set_mac_address(dev, &default_mac);
559
560 /* Initialize speed indicator stuff. */
561
562 current_speed = 10;
563 current_speed_selection = 0; /* Auto */
564 speed_timer.expires = jiffies + NET_LINK_UP_CHECK_INTERVAL;
565 duplex_timer.data = (unsigned long)dev;
566 speed_timer.function = e100_check_speed;
567
568 clear_led_timer.function = e100_clear_network_leds;
569
570 full_duplex = 0;
571 current_duplex = autoneg;
572 duplex_timer.expires = jiffies + NET_DUPLEX_CHECK_INTERVAL;
573 duplex_timer.data = (unsigned long)dev;
574 duplex_timer.function = e100_check_duplex;
575
576 /* Initialize mii interface */
577 np->mii_if.phy_id = mdio_phy_addr;
578 np->mii_if.phy_id_mask = 0x1f;
579 np->mii_if.reg_num_mask = 0x1f;
580 np->mii_if.dev = dev;
581 np->mii_if.mdio_read = e100_get_mdio_reg;
582 np->mii_if.mdio_write = e100_set_mdio_reg;
583
584 /* Initialize group address registers to make sure that no */
585 /* unwanted addresses are matched */
586 *R_NETWORK_GA_0 = 0x00000000;
587 *R_NETWORK_GA_1 = 0x00000000;
588 return 0;
589}
590
591/* set MAC address of the interface. called from the core after a
592 * SIOCSIFADDR ioctl, and from the bootup above.
593 */
594
595static int
596e100_set_mac_address(struct net_device *dev, void *p)
597{
598 struct net_local *np = (struct net_local *)dev->priv;
599 struct sockaddr *addr = p;
600 int i;
601
602 spin_lock(&np->lock); /* preemption protection */
603
604 /* remember it */
605
606 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
607
608 /* Write it to the hardware.
609 * Note the way the address is wrapped:
610 * *R_NETWORK_SA_0 = a0_0 | (a0_1 << 8) | (a0_2 << 16) | (a0_3 << 24);
611 * *R_NETWORK_SA_1 = a0_4 | (a0_5 << 8);
612 */
613
614 *R_NETWORK_SA_0 = dev->dev_addr[0] | (dev->dev_addr[1] << 8) |
615 (dev->dev_addr[2] << 16) | (dev->dev_addr[3] << 24);
616 *R_NETWORK_SA_1 = dev->dev_addr[4] | (dev->dev_addr[5] << 8);
617 *R_NETWORK_SA_2 = 0;
618
619 /* show it in the log as well */
620
621 printk(KERN_INFO "%s: changed MAC to ", dev->name);
622
623 for (i = 0; i < 5; i++)
624 printk("%02X:", dev->dev_addr[i]);
625
626 printk("%02X\n", dev->dev_addr[i]);
627
628 spin_unlock(&np->lock);
629
630 return 0;
631}
632
633/*
634 * Open/initialize the board. This is called (in the current kernel)
635 * sometime after booting when the 'ifconfig' program is run.
636 *
637 * This routine should set everything up anew at each open, even
638 * registers that "should" only need to be set once at boot, so that
639 * there is non-reboot way to recover if something goes wrong.
640 */
641
642static int
643e100_open(struct net_device *dev)
644{
645 unsigned long flags;
646
647 /* enable the MDIO output pin */
648
649 *R_NETWORK_MGM_CTRL = IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable);
650
651 *R_IRQ_MASK0_CLR =
652 IO_STATE(R_IRQ_MASK0_CLR, overrun, clr) |
653 IO_STATE(R_IRQ_MASK0_CLR, underrun, clr) |
654 IO_STATE(R_IRQ_MASK0_CLR, excessive_col, clr);
655
656 /* clear dma0 and 1 eop and descr irq masks */
657 *R_IRQ_MASK2_CLR =
658 IO_STATE(R_IRQ_MASK2_CLR, dma0_descr, clr) |
659 IO_STATE(R_IRQ_MASK2_CLR, dma0_eop, clr) |
660 IO_STATE(R_IRQ_MASK2_CLR, dma1_descr, clr) |
661 IO_STATE(R_IRQ_MASK2_CLR, dma1_eop, clr);
662
663 /* Reset and wait for the DMA channels */
664
665 RESET_DMA(NETWORK_TX_DMA_NBR);
666 RESET_DMA(NETWORK_RX_DMA_NBR);
667 WAIT_DMA(NETWORK_TX_DMA_NBR);
668 WAIT_DMA(NETWORK_RX_DMA_NBR);
669
670 /* Initialise the etrax network controller */
671
672 /* allocate the irq corresponding to the receiving DMA */
673
674 if (request_irq(NETWORK_DMA_RX_IRQ_NBR, e100rxtx_interrupt,
675 SA_SAMPLE_RANDOM, cardname, (void *)dev)) {
676 goto grace_exit0;
677 }
678
679 /* allocate the irq corresponding to the transmitting DMA */
680
681 if (request_irq(NETWORK_DMA_TX_IRQ_NBR, e100rxtx_interrupt, 0,
682 cardname, (void *)dev)) {
683 goto grace_exit1;
684 }
685
686 /* allocate the irq corresponding to the network errors etc */
687
688 if (request_irq(NETWORK_STATUS_IRQ_NBR, e100nw_interrupt, 0,
689 cardname, (void *)dev)) {
690 goto grace_exit2;
691 }
692
693 /* give the HW an idea of what MAC address we want */
694
695 *R_NETWORK_SA_0 = dev->dev_addr[0] | (dev->dev_addr[1] << 8) |
696 (dev->dev_addr[2] << 16) | (dev->dev_addr[3] << 24);
697 *R_NETWORK_SA_1 = dev->dev_addr[4] | (dev->dev_addr[5] << 8);
698 *R_NETWORK_SA_2 = 0;
699
700#if 0
701 /* use promiscuous mode for testing */
702 *R_NETWORK_GA_0 = 0xffffffff;
703 *R_NETWORK_GA_1 = 0xffffffff;
704
705 *R_NETWORK_REC_CONFIG = 0xd; /* broadcast rec, individ. rec, ma0 enabled */
706#else
707 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, broadcast, receive);
708 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, ma0, enable);
709 SETF(network_rec_config_shadow, R_NETWORK_REC_CONFIG, duplex, full_duplex);
710 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
711#endif
712
713 *R_NETWORK_GEN_CONFIG =
714 IO_STATE(R_NETWORK_GEN_CONFIG, phy, mii_clk) |
715 IO_STATE(R_NETWORK_GEN_CONFIG, enable, on);
716
717 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, clr);
718 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, delay, none);
719 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, cancel, dont);
720 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, cd, enable);
721 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, retry, enable);
722 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, pad, enable);
723 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, crc, enable);
724 *R_NETWORK_TR_CTRL = network_tr_ctrl_shadow;
725
726 save_flags(flags);
727 cli();
728
729 /* enable the irq's for ethernet DMA */
730
731 *R_IRQ_MASK2_SET =
732 IO_STATE(R_IRQ_MASK2_SET, dma0_eop, set) |
733 IO_STATE(R_IRQ_MASK2_SET, dma1_eop, set);
734
735 *R_IRQ_MASK0_SET =
736 IO_STATE(R_IRQ_MASK0_SET, overrun, set) |
737 IO_STATE(R_IRQ_MASK0_SET, underrun, set) |
738 IO_STATE(R_IRQ_MASK0_SET, excessive_col, set);
739
740 /* make sure the irqs are cleared */
741
742 *R_DMA_CH0_CLR_INTR = IO_STATE(R_DMA_CH0_CLR_INTR, clr_eop, do);
743 *R_DMA_CH1_CLR_INTR = IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do);
744
745 /* make sure the rec and transmit error counters are cleared */
746
747 (void)*R_REC_COUNTERS; /* dummy read */
748 (void)*R_TR_COUNTERS; /* dummy read */
749
750 /* start the receiving DMA channel so we can receive packets from now on */
751
752 *R_DMA_CH1_FIRST = virt_to_phys(myNextRxDesc);
753 *R_DMA_CH1_CMD = IO_STATE(R_DMA_CH1_CMD, cmd, start);
754
755 /* Set up transmit DMA channel so it can be restarted later */
756
757 *R_DMA_CH0_FIRST = 0;
758 *R_DMA_CH0_DESCR = virt_to_phys(myLastTxDesc);
759
760 restore_flags(flags);
761
762 /* Probe for transceiver */
763 if (e100_probe_transceiver(dev))
764 goto grace_exit3;
765
766 /* Start duplex/speed timers */
767 add_timer(&speed_timer);
768 add_timer(&duplex_timer);
769
770 /* We are now ready to accept transmit requeusts from
771 * the queueing layer of the networking.
772 */
773 netif_start_queue(dev);
774
775 return 0;
776
777grace_exit3:
778 free_irq(NETWORK_STATUS_IRQ_NBR, (void *)dev);
779grace_exit2:
780 free_irq(NETWORK_DMA_TX_IRQ_NBR, (void *)dev);
781grace_exit1:
782 free_irq(NETWORK_DMA_RX_IRQ_NBR, (void *)dev);
783grace_exit0:
784 return -EAGAIN;
785}
786
787
788static void
789generic_check_speed(struct net_device* dev)
790{
791 unsigned long data;
792 data = e100_get_mdio_reg(dev, mdio_phy_addr, MII_ADVERTISE);
793 if ((data & ADVERTISE_100FULL) ||
794 (data & ADVERTISE_100HALF))
795 current_speed = 100;
796 else
797 current_speed = 10;
798}
799
800static void
801tdk_check_speed(struct net_device* dev)
802{
803 unsigned long data;
804 data = e100_get_mdio_reg(dev, mdio_phy_addr, MDIO_TDK_DIAGNOSTIC_REG);
805 current_speed = (data & MDIO_TDK_DIAGNOSTIC_RATE ? 100 : 10);
806}
807
808static void
809broadcom_check_speed(struct net_device* dev)
810{
811 unsigned long data;
812 data = e100_get_mdio_reg(dev, mdio_phy_addr, MDIO_AUX_CTRL_STATUS_REG);
813 current_speed = (data & MDIO_BC_SPEED ? 100 : 10);
814}
815
816static void
817intel_check_speed(struct net_device* dev)
818{
819 unsigned long data;
820 data = e100_get_mdio_reg(dev, mdio_phy_addr, MDIO_INT_STATUS_REG_2);
821 current_speed = (data & MDIO_INT_SPEED ? 100 : 10);
822}
823
824static void
825e100_check_speed(unsigned long priv)
826{
827 struct net_device* dev = (struct net_device*)priv;
828 static int led_initiated = 0;
829 unsigned long data;
830 int old_speed = current_speed;
831
832 data = e100_get_mdio_reg(dev, mdio_phy_addr, MII_BMSR);
833 if (!(data & BMSR_LSTATUS)) {
834 current_speed = 0;
835 } else {
836 transceiver->check_speed(dev);
837 }
838
839 if ((old_speed != current_speed) || !led_initiated) {
840 led_initiated = 1;
841 e100_set_network_leds(NO_NETWORK_ACTIVITY);
842 }
843
844 /* Reinitialize the timer. */
845 speed_timer.expires = jiffies + NET_LINK_UP_CHECK_INTERVAL;
846 add_timer(&speed_timer);
847}
848
849static void
850e100_negotiate(struct net_device* dev)
851{
852 unsigned short data = e100_get_mdio_reg(dev, mdio_phy_addr, MII_ADVERTISE);
853
854 /* Discard old speed and duplex settings */
855 data &= ~(ADVERTISE_100HALF | ADVERTISE_100FULL |
856 ADVERTISE_10HALF | ADVERTISE_10FULL);
857
858 switch (current_speed_selection) {
859 case 10 :
860 if (current_duplex == full)
861 data |= ADVERTISE_10FULL;
862 else if (current_duplex == half)
863 data |= ADVERTISE_10HALF;
864 else
865 data |= ADVERTISE_10HALF | ADVERTISE_10FULL;
866 break;
867
868 case 100 :
869 if (current_duplex == full)
870 data |= ADVERTISE_100FULL;
871 else if (current_duplex == half)
872 data |= ADVERTISE_100HALF;
873 else
874 data |= ADVERTISE_100HALF | ADVERTISE_100FULL;
875 break;
876
877 case 0 : /* Auto */
878 if (current_duplex == full)
879 data |= ADVERTISE_100FULL | ADVERTISE_10FULL;
880 else if (current_duplex == half)
881 data |= ADVERTISE_100HALF | ADVERTISE_10HALF;
882 else
883 data |= ADVERTISE_10HALF | ADVERTISE_10FULL |
884 ADVERTISE_100HALF | ADVERTISE_100FULL;
885 break;
886
887 default : /* assume autoneg speed and duplex */
888 data |= ADVERTISE_10HALF | ADVERTISE_10FULL |
889 ADVERTISE_100HALF | ADVERTISE_100FULL;
890 }
891
892 e100_set_mdio_reg(dev, mdio_phy_addr, MII_ADVERTISE, data);
893
894 /* Renegotiate with link partner */
895 data = e100_get_mdio_reg(dev, mdio_phy_addr, MII_BMCR);
896 data |= BMCR_ANENABLE | BMCR_ANRESTART;
897
898 e100_set_mdio_reg(dev, mdio_phy_addr, MII_BMCR, data);
899}
900
901static void
902e100_set_speed(struct net_device* dev, unsigned long speed)
903{
904 if (speed != current_speed_selection) {
905 current_speed_selection = speed;
906 e100_negotiate(dev);
907 }
908}
909
910static void
911e100_check_duplex(unsigned long priv)
912{
913 struct net_device *dev = (struct net_device *)priv;
914 struct net_local *np = (struct net_local *)dev->priv;
915 int old_duplex = full_duplex;
916 transceiver->check_duplex(dev);
917 if (old_duplex != full_duplex) {
918 /* Duplex changed */
919 SETF(network_rec_config_shadow, R_NETWORK_REC_CONFIG, duplex, full_duplex);
920 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
921 }
922
923 /* Reinitialize the timer. */
924 duplex_timer.expires = jiffies + NET_DUPLEX_CHECK_INTERVAL;
925 add_timer(&duplex_timer);
926 np->mii_if.full_duplex = full_duplex;
927}
928
929static void
930generic_check_duplex(struct net_device* dev)
931{
932 unsigned long data;
933 data = e100_get_mdio_reg(dev, mdio_phy_addr, MII_ADVERTISE);
934 if ((data & ADVERTISE_10FULL) ||
935 (data & ADVERTISE_100FULL))
936 full_duplex = 1;
937 else
938 full_duplex = 0;
939}
940
941static void
942tdk_check_duplex(struct net_device* dev)
943{
944 unsigned long data;
945 data = e100_get_mdio_reg(dev, mdio_phy_addr, MDIO_TDK_DIAGNOSTIC_REG);
946 full_duplex = (data & MDIO_TDK_DIAGNOSTIC_DPLX) ? 1 : 0;
947}
948
949static void
950broadcom_check_duplex(struct net_device* dev)
951{
952 unsigned long data;
953 data = e100_get_mdio_reg(dev, mdio_phy_addr, MDIO_AUX_CTRL_STATUS_REG);
954 full_duplex = (data & MDIO_BC_FULL_DUPLEX_IND) ? 1 : 0;
955}
956
957static void
958intel_check_duplex(struct net_device* dev)
959{
960 unsigned long data;
961 data = e100_get_mdio_reg(dev, mdio_phy_addr, MDIO_INT_STATUS_REG_2);
962 full_duplex = (data & MDIO_INT_FULL_DUPLEX_IND) ? 1 : 0;
963}
964
965static void
966e100_set_duplex(struct net_device* dev, enum duplex new_duplex)
967{
968 if (new_duplex != current_duplex) {
969 current_duplex = new_duplex;
970 e100_negotiate(dev);
971 }
972}
973
974static int
975e100_probe_transceiver(struct net_device* dev)
976{
977 unsigned int phyid_high;
978 unsigned int phyid_low;
979 unsigned int oui;
980 struct transceiver_ops* ops = NULL;
981
982 /* Probe MDIO physical address */
983 for (mdio_phy_addr = 0; mdio_phy_addr <= 31; mdio_phy_addr++) {
984 if (e100_get_mdio_reg(dev, mdio_phy_addr, MII_BMSR) != 0xffff)
985 break;
986 }
987 if (mdio_phy_addr == 32)
988 return -ENODEV;
989
990 /* Get manufacturer */
991 phyid_high = e100_get_mdio_reg(dev, mdio_phy_addr, MII_PHYSID1);
992 phyid_low = e100_get_mdio_reg(dev, mdio_phy_addr, MII_PHYSID2);
993 oui = (phyid_high << 6) | (phyid_low >> 10);
994
995 for (ops = &transceivers[0]; ops->oui; ops++) {
996 if (ops->oui == oui)
997 break;
998 }
999 transceiver = ops;
1000
1001 return 0;
1002}
1003
1004static int
1005e100_get_mdio_reg(struct net_device *dev, int phy_id, int location)
1006{
1007 unsigned short cmd; /* Data to be sent on MDIO port */
1008 int data; /* Data read from MDIO */
1009 int bitCounter;
1010
1011 /* Start of frame, OP Code, Physical Address, Register Address */
1012 cmd = (MDIO_START << 14) | (MDIO_READ << 12) | (phy_id << 7) |
1013 (location << 2);
1014
1015 e100_send_mdio_cmd(cmd, 0);
1016
1017 data = 0;
1018
1019 /* Data... */
1020 for (bitCounter=15; bitCounter>=0 ; bitCounter--) {
1021 data |= (e100_receive_mdio_bit() << bitCounter);
1022 }
1023
1024 return data;
1025}
1026
1027static void
1028e100_set_mdio_reg(struct net_device *dev, int phy_id, int location, int value)
1029{
1030 int bitCounter;
1031 unsigned short cmd;
1032
1033 cmd = (MDIO_START << 14) | (MDIO_WRITE << 12) | (phy_id << 7) |
1034 (location << 2);
1035
1036 e100_send_mdio_cmd(cmd, 1);
1037
1038 /* Data... */
1039 for (bitCounter=15; bitCounter>=0 ; bitCounter--) {
1040 e100_send_mdio_bit(GET_BIT(bitCounter, value));
1041 }
1042
1043}
1044
1045static void
1046e100_send_mdio_cmd(unsigned short cmd, int write_cmd)
1047{
1048 int bitCounter;
1049 unsigned char data = 0x2;
1050
1051 /* Preamble */
1052 for (bitCounter = 31; bitCounter>= 0; bitCounter--)
1053 e100_send_mdio_bit(GET_BIT(bitCounter, MDIO_PREAMBLE));
1054
1055 for (bitCounter = 15; bitCounter >= 2; bitCounter--)
1056 e100_send_mdio_bit(GET_BIT(bitCounter, cmd));
1057
1058 /* Turnaround */
1059 for (bitCounter = 1; bitCounter >= 0 ; bitCounter--)
1060 if (write_cmd)
1061 e100_send_mdio_bit(GET_BIT(bitCounter, data));
1062 else
1063 e100_receive_mdio_bit();
1064}
1065
1066static void
1067e100_send_mdio_bit(unsigned char bit)
1068{
1069 *R_NETWORK_MGM_CTRL =
1070 IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable) |
1071 IO_FIELD(R_NETWORK_MGM_CTRL, mdio, bit);
1072 udelay(1);
1073 *R_NETWORK_MGM_CTRL =
1074 IO_STATE(R_NETWORK_MGM_CTRL, mdoe, enable) |
1075 IO_MASK(R_NETWORK_MGM_CTRL, mdck) |
1076 IO_FIELD(R_NETWORK_MGM_CTRL, mdio, bit);
1077 udelay(1);
1078}
1079
1080static unsigned char
1081e100_receive_mdio_bit()
1082{
1083 unsigned char bit;
1084 *R_NETWORK_MGM_CTRL = 0;
1085 bit = IO_EXTRACT(R_NETWORK_STAT, mdio, *R_NETWORK_STAT);
1086 udelay(1);
1087 *R_NETWORK_MGM_CTRL = IO_MASK(R_NETWORK_MGM_CTRL, mdck);
1088 udelay(1);
1089 return bit;
1090}
1091
1092static void
1093e100_reset_transceiver(struct net_device* dev)
1094{
1095 unsigned short cmd;
1096 unsigned short data;
1097 int bitCounter;
1098
1099 data = e100_get_mdio_reg(dev, mdio_phy_addr, MII_BMCR);
1100
1101 cmd = (MDIO_START << 14) | (MDIO_WRITE << 12) | (mdio_phy_addr << 7) | (MII_BMCR << 2);
1102
1103 e100_send_mdio_cmd(cmd, 1);
1104
1105 data |= 0x8000;
1106
1107 for (bitCounter = 15; bitCounter >= 0 ; bitCounter--) {
1108 e100_send_mdio_bit(GET_BIT(bitCounter, data));
1109 }
1110}
1111
1112/* Called by upper layers if they decide it took too long to complete
1113 * sending a packet - we need to reset and stuff.
1114 */
1115
1116static void
1117e100_tx_timeout(struct net_device *dev)
1118{
1119 struct net_local *np = (struct net_local *)dev->priv;
1120 unsigned long flags;
1121
1122 spin_lock_irqsave(&np->lock, flags);
1123
1124 printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
1125 tx_done(dev) ? "IRQ problem" : "network cable problem");
1126
1127 /* remember we got an error */
1128
1129 np->stats.tx_errors++;
1130
1131 /* reset the TX DMA in case it has hung on something */
1132
1133 RESET_DMA(NETWORK_TX_DMA_NBR);
1134 WAIT_DMA(NETWORK_TX_DMA_NBR);
1135
1136 /* Reset the transceiver. */
1137
1138 e100_reset_transceiver(dev);
1139
1140 /* and get rid of the packets that never got an interrupt */
1141 while (myFirstTxDesc != myNextTxDesc)
1142 {
1143 dev_kfree_skb(myFirstTxDesc->skb);
1144 myFirstTxDesc->skb = 0;
1145 myFirstTxDesc = phys_to_virt(myFirstTxDesc->descr.next);
1146 }
1147
1148 /* Set up transmit DMA channel so it can be restarted later */
1149 *R_DMA_CH0_FIRST = 0;
1150 *R_DMA_CH0_DESCR = virt_to_phys(myLastTxDesc);
1151
1152 /* tell the upper layers we're ok again */
1153
1154 netif_wake_queue(dev);
1155 spin_unlock_irqrestore(&np->lock, flags);
1156}
1157
1158
1159/* This will only be invoked if the driver is _not_ in XOFF state.
1160 * What this means is that we need not check it, and that this
1161 * invariant will hold if we make sure that the netif_*_queue()
1162 * calls are done at the proper times.
1163 */
1164
1165static int
1166e100_send_packet(struct sk_buff *skb, struct net_device *dev)
1167{
1168 struct net_local *np = (struct net_local *)dev->priv;
1169 unsigned char *buf = skb->data;
1170 unsigned long flags;
1171
1172#ifdef ETHDEBUG
1173 printk("send packet len %d\n", length);
1174#endif
1175 spin_lock_irqsave(&np->lock, flags); /* protect from tx_interrupt and ourself */
1176
1177 myNextTxDesc->skb = skb;
1178
1179 dev->trans_start = jiffies;
1180
1181 e100_hardware_send_packet(buf, skb->len);
1182
1183 myNextTxDesc = phys_to_virt(myNextTxDesc->descr.next);
1184
1185 /* Stop queue if full */
1186 if (myNextTxDesc == myFirstTxDesc) {
1187 netif_stop_queue(dev);
1188 }
1189
1190 spin_unlock_irqrestore(&np->lock, flags);
1191
1192 return 0;
1193}
1194
1195/*
1196 * The typical workload of the driver:
1197 * Handle the network interface interrupts.
1198 */
1199
1200static irqreturn_t
1201e100rxtx_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1202{
1203 struct net_device *dev = (struct net_device *)dev_id;
1204 struct net_local *np = (struct net_local *)dev->priv;
1205 unsigned long irqbits = *R_IRQ_MASK2_RD;
1206
1207 /* Disable RX/TX IRQs to avoid reentrancy */
1208 *R_IRQ_MASK2_CLR =
1209 IO_STATE(R_IRQ_MASK2_CLR, dma0_eop, clr) |
1210 IO_STATE(R_IRQ_MASK2_CLR, dma1_eop, clr);
1211
1212 /* Handle received packets */
1213 if (irqbits & IO_STATE(R_IRQ_MASK2_RD, dma1_eop, active)) {
1214 /* acknowledge the eop interrupt */
1215
1216 *R_DMA_CH1_CLR_INTR = IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do);
1217
1218 /* check if one or more complete packets were indeed received */
1219
1220 while ((*R_DMA_CH1_FIRST != virt_to_phys(myNextRxDesc)) &&
1221 (myNextRxDesc != myLastRxDesc)) {
1222 /* Take out the buffer and give it to the OS, then
1223 * allocate a new buffer to put a packet in.
1224 */
1225 e100_rx(dev);
1226 ((struct net_local *)dev->priv)->stats.rx_packets++;
1227 /* restart/continue on the channel, for safety */
1228 *R_DMA_CH1_CMD = IO_STATE(R_DMA_CH1_CMD, cmd, restart);
1229 /* clear dma channel 1 eop/descr irq bits */
1230 *R_DMA_CH1_CLR_INTR =
1231 IO_STATE(R_DMA_CH1_CLR_INTR, clr_eop, do) |
1232 IO_STATE(R_DMA_CH1_CLR_INTR, clr_descr, do);
1233
1234 /* now, we might have gotten another packet
1235 so we have to loop back and check if so */
1236 }
1237 }
1238
1239 /* Report any packets that have been sent */
1240 while (myFirstTxDesc != phys_to_virt(*R_DMA_CH0_FIRST) &&
1241 myFirstTxDesc != myNextTxDesc)
1242 {
1243 np->stats.tx_bytes += myFirstTxDesc->skb->len;
1244 np->stats.tx_packets++;
1245
1246 /* dma is ready with the transmission of the data in tx_skb, so now
1247 we can release the skb memory */
1248 dev_kfree_skb_irq(myFirstTxDesc->skb);
1249 myFirstTxDesc->skb = 0;
1250 myFirstTxDesc = phys_to_virt(myFirstTxDesc->descr.next);
1251 }
1252
1253 if (irqbits & IO_STATE(R_IRQ_MASK2_RD, dma0_eop, active)) {
1254 /* acknowledge the eop interrupt and wake up queue */
1255 *R_DMA_CH0_CLR_INTR = IO_STATE(R_DMA_CH0_CLR_INTR, clr_eop, do);
1256 netif_wake_queue(dev);
1257 }
1258
1259 /* Enable RX/TX IRQs again */
1260 *R_IRQ_MASK2_SET =
1261 IO_STATE(R_IRQ_MASK2_SET, dma0_eop, set) |
1262 IO_STATE(R_IRQ_MASK2_SET, dma1_eop, set);
1263
1264 return IRQ_HANDLED;
1265}
1266
1267static irqreturn_t
1268e100nw_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1269{
1270 struct net_device *dev = (struct net_device *)dev_id;
1271 struct net_local *np = (struct net_local *)dev->priv;
1272 unsigned long irqbits = *R_IRQ_MASK0_RD;
1273
1274 /* check for underrun irq */
1275 if (irqbits & IO_STATE(R_IRQ_MASK0_RD, underrun, active)) {
1276 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, clr);
1277 *R_NETWORK_TR_CTRL = network_tr_ctrl_shadow;
1278 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, nop);
1279 np->stats.tx_errors++;
1280 D(printk("ethernet receiver underrun!\n"));
1281 }
1282
1283 /* check for overrun irq */
1284 if (irqbits & IO_STATE(R_IRQ_MASK0_RD, overrun, active)) {
1285 update_rx_stats(&np->stats); /* this will ack the irq */
1286 D(printk("ethernet receiver overrun!\n"));
1287 }
1288 /* check for excessive collision irq */
1289 if (irqbits & IO_STATE(R_IRQ_MASK0_RD, excessive_col, active)) {
1290 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, clr);
1291 *R_NETWORK_TR_CTRL = network_tr_ctrl_shadow;
1292 SETS(network_tr_ctrl_shadow, R_NETWORK_TR_CTRL, clr_error, nop);
1293 *R_NETWORK_TR_CTRL = IO_STATE(R_NETWORK_TR_CTRL, clr_error, clr);
1294 np->stats.tx_errors++;
1295 D(printk("ethernet excessive collisions!\n"));
1296 }
1297 return IRQ_HANDLED;
1298}
1299
1300/* We have a good packet(s), get it/them out of the buffers. */
1301static void
1302e100_rx(struct net_device *dev)
1303{
1304 struct sk_buff *skb;
1305 int length = 0;
1306 struct net_local *np = (struct net_local *)dev->priv;
1307 unsigned char *skb_data_ptr;
1308#ifdef ETHDEBUG
1309 int i;
1310#endif
1311
1312 if (!led_active && time_after(jiffies, led_next_time)) {
1313 /* light the network leds depending on the current speed. */
1314 e100_set_network_leds(NETWORK_ACTIVITY);
1315
1316 /* Set the earliest time we may clear the LED */
1317 led_next_time = jiffies + NET_FLASH_TIME;
1318 led_active = 1;
1319 mod_timer(&clear_led_timer, jiffies + HZ/10);
1320 }
1321
1322 length = myNextRxDesc->descr.hw_len - 4;
1323 ((struct net_local *)dev->priv)->stats.rx_bytes += length;
1324
1325#ifdef ETHDEBUG
1326 printk("Got a packet of length %d:\n", length);
1327 /* dump the first bytes in the packet */
1328 skb_data_ptr = (unsigned char *)phys_to_virt(myNextRxDesc->descr.buf);
1329 for (i = 0; i < 8; i++) {
1330 printk("%d: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", i * 8,
1331 skb_data_ptr[0],skb_data_ptr[1],skb_data_ptr[2],skb_data_ptr[3],
1332 skb_data_ptr[4],skb_data_ptr[5],skb_data_ptr[6],skb_data_ptr[7]);
1333 skb_data_ptr += 8;
1334 }
1335#endif
1336
1337 if (length < RX_COPYBREAK) {
1338 /* Small packet, copy data */
1339 skb = dev_alloc_skb(length - ETHER_HEAD_LEN);
1340 if (!skb) {
1341 np->stats.rx_errors++;
1342 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1343 return;
1344 }
1345
1346 skb_put(skb, length - ETHER_HEAD_LEN); /* allocate room for the packet body */
1347 skb_data_ptr = skb_push(skb, ETHER_HEAD_LEN); /* allocate room for the header */
1348
1349#ifdef ETHDEBUG
1350 printk("head = 0x%x, data = 0x%x, tail = 0x%x, end = 0x%x\n",
1351 skb->head, skb->data, skb->tail, skb->end);
1352 printk("copying packet to 0x%x.\n", skb_data_ptr);
1353#endif
1354
1355 memcpy(skb_data_ptr, phys_to_virt(myNextRxDesc->descr.buf), length);
1356 }
1357 else {
1358 /* Large packet, send directly to upper layers and allocate new
1359 * memory (aligned to cache line boundary to avoid bug).
1360 * Before sending the skb to upper layers we must make sure that
1361 * skb->data points to the aligned start of the packet.
1362 */
1363 int align;
1364 struct sk_buff *new_skb = dev_alloc_skb(MAX_MEDIA_DATA_SIZE + 2 * L1_CACHE_BYTES);
1365 if (!new_skb) {
1366 np->stats.rx_errors++;
1367 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
1368 return;
1369 }
1370 skb = myNextRxDesc->skb;
1371 align = (int)phys_to_virt(myNextRxDesc->descr.buf) - (int)skb->data;
1372 skb_put(skb, length + align);
1373 skb_pull(skb, align); /* Remove alignment bytes */
1374 myNextRxDesc->skb = new_skb;
1375 myNextRxDesc->descr.buf = L1_CACHE_ALIGN(virt_to_phys(myNextRxDesc->skb->data));
1376 }
1377
1378 skb->dev = dev;
1379 skb->protocol = eth_type_trans(skb, dev);
1380
1381 /* Send the packet to the upper layers */
1382 netif_rx(skb);
1383
1384 /* Prepare for next packet */
1385 myNextRxDesc->descr.status = 0;
1386 myPrevRxDesc = myNextRxDesc;
1387 myNextRxDesc = phys_to_virt(myNextRxDesc->descr.next);
1388
1389 rx_queue_len++;
1390
1391 /* Check if descriptors should be returned */
1392 if (rx_queue_len == RX_QUEUE_THRESHOLD) {
1393 flush_etrax_cache();
1394 myPrevRxDesc->descr.ctrl |= d_eol;
1395 myLastRxDesc->descr.ctrl &= ~d_eol;
1396 myLastRxDesc = myPrevRxDesc;
1397 rx_queue_len = 0;
1398 }
1399}
1400
1401/* The inverse routine to net_open(). */
1402static int
1403e100_close(struct net_device *dev)
1404{
1405 struct net_local *np = (struct net_local *)dev->priv;
1406
1407 printk(KERN_INFO "Closing %s.\n", dev->name);
1408
1409 netif_stop_queue(dev);
1410
1411 *R_IRQ_MASK0_CLR =
1412 IO_STATE(R_IRQ_MASK0_CLR, overrun, clr) |
1413 IO_STATE(R_IRQ_MASK0_CLR, underrun, clr) |
1414 IO_STATE(R_IRQ_MASK0_CLR, excessive_col, clr);
1415
1416 *R_IRQ_MASK2_CLR =
1417 IO_STATE(R_IRQ_MASK2_CLR, dma0_descr, clr) |
1418 IO_STATE(R_IRQ_MASK2_CLR, dma0_eop, clr) |
1419 IO_STATE(R_IRQ_MASK2_CLR, dma1_descr, clr) |
1420 IO_STATE(R_IRQ_MASK2_CLR, dma1_eop, clr);
1421
1422 /* Stop the receiver and the transmitter */
1423
1424 RESET_DMA(NETWORK_TX_DMA_NBR);
1425 RESET_DMA(NETWORK_RX_DMA_NBR);
1426
1427 /* Flush the Tx and disable Rx here. */
1428
1429 free_irq(NETWORK_DMA_RX_IRQ_NBR, (void *)dev);
1430 free_irq(NETWORK_DMA_TX_IRQ_NBR, (void *)dev);
1431 free_irq(NETWORK_STATUS_IRQ_NBR, (void *)dev);
1432
1433 /* Update the statistics here. */
1434
1435 update_rx_stats(&np->stats);
1436 update_tx_stats(&np->stats);
1437
1438 /* Stop speed/duplex timers */
1439 del_timer(&speed_timer);
1440 del_timer(&duplex_timer);
1441
1442 return 0;
1443}
1444
1445static int
1446e100_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1447{
1448 struct mii_ioctl_data *data = if_mii(ifr);
1449 struct net_local *np = netdev_priv(dev);
1450
1451 spin_lock(&np->lock); /* Preempt protection */
1452 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 case SIOCGMIIPHY: /* Get PHY address */
1454 data->phy_id = mdio_phy_addr;
1455 break;
1456 case SIOCGMIIREG: /* Read MII register */
1457 data->val_out = e100_get_mdio_reg(dev, mdio_phy_addr, data->reg_num);
1458 break;
1459 case SIOCSMIIREG: /* Write MII register */
1460 e100_set_mdio_reg(dev, mdio_phy_addr, data->reg_num, data->val_in);
1461 break;
1462 /* The ioctls below should be considered obsolete but are */
1463 /* still present for compatability with old scripts/apps */
1464 case SET_ETH_SPEED_10: /* 10 Mbps */
1465 e100_set_speed(dev, 10);
1466 break;
1467 case SET_ETH_SPEED_100: /* 100 Mbps */
1468 e100_set_speed(dev, 100);
1469 break;
1470 case SET_ETH_SPEED_AUTO: /* Auto negotiate speed */
1471 e100_set_speed(dev, 0);
1472 break;
1473 case SET_ETH_DUPLEX_HALF: /* Half duplex. */
1474 e100_set_duplex(dev, half);
1475 break;
1476 case SET_ETH_DUPLEX_FULL: /* Full duplex. */
1477 e100_set_duplex(dev, full);
1478 break;
1479 case SET_ETH_DUPLEX_AUTO: /* Autonegotiate duplex*/
1480 e100_set_duplex(dev, autoneg);
1481 break;
1482 default:
1483 return -EINVAL;
1484 }
1485 spin_unlock(&np->lock);
1486 return 0;
1487}
1488
Christoph Hellwig76f2b4d2005-11-07 06:18:57 +01001489static int e100_set_settings(struct net_device *dev,
1490 struct ethtool_cmd *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Christoph Hellwig76f2b4d2005-11-07 06:18:57 +01001492 ecmd->supported = SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
1494 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full;
Christoph Hellwig76f2b4d2005-11-07 06:18:57 +01001495 ecmd->port = PORT_TP;
1496 ecmd->transceiver = XCVR_EXTERNAL;
1497 ecmd->phy_address = mdio_phy_addr;
1498 ecmd->speed = current_speed;
1499 ecmd->duplex = full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
1500 ecmd->advertising = ADVERTISED_TP;
1501
1502 if (current_duplex == autoneg && current_speed_selection == 0)
1503 ecmd->advertising |= ADVERTISED_Autoneg;
1504 else {
1505 ecmd->advertising |=
1506 ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
1507 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
1508 if (current_speed_selection == 10)
1509 ecmd->advertising &= ~(ADVERTISED_100baseT_Half |
1510 ADVERTISED_100baseT_Full);
1511 else if (current_speed_selection == 100)
1512 ecmd->advertising &= ~(ADVERTISED_10baseT_Half |
1513 ADVERTISED_10baseT_Full);
1514 if (current_duplex == half)
1515 ecmd->advertising &= ~(ADVERTISED_10baseT_Full |
1516 ADVERTISED_100baseT_Full);
1517 else if (current_duplex == full)
1518 ecmd->advertising &= ~(ADVERTISED_10baseT_Half |
1519 ADVERTISED_100baseT_Half);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
Christoph Hellwig76f2b4d2005-11-07 06:18:57 +01001521
1522 ecmd->autoneg = AUTONEG_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 return 0;
1524}
1525
Christoph Hellwig76f2b4d2005-11-07 06:18:57 +01001526static int e100_set_settings(struct net_device *dev,
1527 struct ethtool_cmd *ecmd)
1528{
1529 if (ecmd->autoneg == AUTONEG_ENABLE) {
1530 e100_set_duplex(dev, autoneg);
1531 e100_set_speed(dev, 0);
1532 } else {
1533 e100_set_duplex(dev, ecmd->duplex == DUPLEX_HALF ? half : full);
1534 e100_set_speed(dev, ecmd->speed == SPEED_10 ? 10: 100);
1535 }
1536
1537 return 0;
1538}
1539
1540static void e100_get_drvinfo(struct net_device *dev,
1541 struct ethtool_drvinfo *info)
1542{
1543 strncpy(info->driver, "ETRAX 100LX", sizeof(info->driver) - 1);
1544 strncpy(info->version, "$Revision: 1.31 $", sizeof(info->version) - 1);
1545 strncpy(info->fw_version, "N/A", sizeof(info->fw_version) - 1);
1546 strncpy(info->bus_info, "N/A", sizeof(info->bus_info) - 1);
1547}
1548
1549static int e100_nway_reset(struct net_device *dev)
1550{
1551 if (current_duplex == autoneg && current_speed_selection == 0)
1552 e100_negotiate(dev);
1553 return 0;
1554}
1555
1556static struct ethtool_ops e100_ethtool_ops = {
1557 .get_settings = e100_get_settings,
1558 .set_settings = e100_set_settings,
1559 .get_drvinfo = e100_get_drvinfo,
1560 .nway_reset = e100_nway_reset,
1561 .get_link = ethtool_op_get_link,
1562};
1563
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564static int
1565e100_set_config(struct net_device *dev, struct ifmap *map)
1566{
1567 struct net_local *np = (struct net_local *)dev->priv;
1568 spin_lock(&np->lock); /* Preempt protection */
1569
1570 switch(map->port) {
1571 case IF_PORT_UNKNOWN:
1572 /* Use autoneg */
1573 e100_set_speed(dev, 0);
1574 e100_set_duplex(dev, autoneg);
1575 break;
1576 case IF_PORT_10BASET:
1577 e100_set_speed(dev, 10);
1578 e100_set_duplex(dev, autoneg);
1579 break;
1580 case IF_PORT_100BASET:
1581 case IF_PORT_100BASETX:
1582 e100_set_speed(dev, 100);
1583 e100_set_duplex(dev, autoneg);
1584 break;
1585 case IF_PORT_100BASEFX:
1586 case IF_PORT_10BASE2:
1587 case IF_PORT_AUI:
1588 spin_unlock(&np->lock);
1589 return -EOPNOTSUPP;
1590 break;
1591 default:
1592 printk(KERN_ERR "%s: Invalid media selected", dev->name);
1593 spin_unlock(&np->lock);
1594 return -EINVAL;
1595 }
1596 spin_unlock(&np->lock);
1597 return 0;
1598}
1599
1600static void
1601update_rx_stats(struct net_device_stats *es)
1602{
1603 unsigned long r = *R_REC_COUNTERS;
1604 /* update stats relevant to reception errors */
1605 es->rx_fifo_errors += IO_EXTRACT(R_REC_COUNTERS, congestion, r);
1606 es->rx_crc_errors += IO_EXTRACT(R_REC_COUNTERS, crc_error, r);
1607 es->rx_frame_errors += IO_EXTRACT(R_REC_COUNTERS, alignment_error, r);
1608 es->rx_length_errors += IO_EXTRACT(R_REC_COUNTERS, oversize, r);
1609}
1610
1611static void
1612update_tx_stats(struct net_device_stats *es)
1613{
1614 unsigned long r = *R_TR_COUNTERS;
1615 /* update stats relevant to transmission errors */
1616 es->collisions +=
1617 IO_EXTRACT(R_TR_COUNTERS, single_col, r) +
1618 IO_EXTRACT(R_TR_COUNTERS, multiple_col, r);
1619 es->tx_errors += IO_EXTRACT(R_TR_COUNTERS, deferred, r);
1620}
1621
1622/*
1623 * Get the current statistics.
1624 * This may be called with the card open or closed.
1625 */
1626static struct net_device_stats *
1627e100_get_stats(struct net_device *dev)
1628{
1629 struct net_local *lp = (struct net_local *)dev->priv;
1630 unsigned long flags;
1631 spin_lock_irqsave(&lp->lock, flags);
1632
1633 update_rx_stats(&lp->stats);
1634 update_tx_stats(&lp->stats);
1635
1636 spin_unlock_irqrestore(&lp->lock, flags);
1637 return &lp->stats;
1638}
1639
1640/*
1641 * Set or clear the multicast filter for this adaptor.
1642 * num_addrs == -1 Promiscuous mode, receive all packets
1643 * num_addrs == 0 Normal mode, clear multicast list
1644 * num_addrs > 0 Multicast mode, receive normal and MC packets,
1645 * and do best-effort filtering.
1646 */
1647static void
1648set_multicast_list(struct net_device *dev)
1649{
1650 struct net_local *lp = (struct net_local *)dev->priv;
1651 int num_addr = dev->mc_count;
1652 unsigned long int lo_bits;
1653 unsigned long int hi_bits;
1654 spin_lock(&lp->lock);
1655 if (dev->flags & IFF_PROMISC)
1656 {
1657 /* promiscuous mode */
1658 lo_bits = 0xfffffffful;
1659 hi_bits = 0xfffffffful;
1660
1661 /* Enable individual receive */
1662 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, receive);
1663 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
1664 } else if (dev->flags & IFF_ALLMULTI) {
1665 /* enable all multicasts */
1666 lo_bits = 0xfffffffful;
1667 hi_bits = 0xfffffffful;
1668
1669 /* Disable individual receive */
1670 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard);
1671 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
1672 } else if (num_addr == 0) {
1673 /* Normal, clear the mc list */
1674 lo_bits = 0x00000000ul;
1675 hi_bits = 0x00000000ul;
1676
1677 /* Disable individual receive */
1678 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard);
1679 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
1680 } else {
1681 /* MC mode, receive normal and MC packets */
1682 char hash_ix;
1683 struct dev_mc_list *dmi = dev->mc_list;
1684 int i;
1685 char *baddr;
1686 lo_bits = 0x00000000ul;
1687 hi_bits = 0x00000000ul;
1688 for (i=0; i<num_addr; i++) {
1689 /* Calculate the hash index for the GA registers */
1690
1691 hash_ix = 0;
1692 baddr = dmi->dmi_addr;
1693 hash_ix ^= (*baddr) & 0x3f;
1694 hash_ix ^= ((*baddr) >> 6) & 0x03;
1695 ++baddr;
1696 hash_ix ^= ((*baddr) << 2) & 0x03c;
1697 hash_ix ^= ((*baddr) >> 4) & 0xf;
1698 ++baddr;
1699 hash_ix ^= ((*baddr) << 4) & 0x30;
1700 hash_ix ^= ((*baddr) >> 2) & 0x3f;
1701 ++baddr;
1702 hash_ix ^= (*baddr) & 0x3f;
1703 hash_ix ^= ((*baddr) >> 6) & 0x03;
1704 ++baddr;
1705 hash_ix ^= ((*baddr) << 2) & 0x03c;
1706 hash_ix ^= ((*baddr) >> 4) & 0xf;
1707 ++baddr;
1708 hash_ix ^= ((*baddr) << 4) & 0x30;
1709 hash_ix ^= ((*baddr) >> 2) & 0x3f;
1710
1711 hash_ix &= 0x3f;
1712
1713 if (hash_ix >= 32) {
1714 hi_bits |= (1 << (hash_ix-32));
1715 }
1716 else {
1717 lo_bits |= (1 << hash_ix);
1718 }
1719 dmi = dmi->next;
1720 }
1721 /* Disable individual receive */
1722 SETS(network_rec_config_shadow, R_NETWORK_REC_CONFIG, individual, discard);
1723 *R_NETWORK_REC_CONFIG = network_rec_config_shadow;
1724 }
1725 *R_NETWORK_GA_0 = lo_bits;
1726 *R_NETWORK_GA_1 = hi_bits;
1727 spin_unlock(&lp->lock);
1728}
1729
1730void
1731e100_hardware_send_packet(char *buf, int length)
1732{
1733 D(printk("e100 send pack, buf 0x%x len %d\n", buf, length));
1734
1735 if (!led_active && time_after(jiffies, led_next_time)) {
1736 /* light the network leds depending on the current speed. */
1737 e100_set_network_leds(NETWORK_ACTIVITY);
1738
1739 /* Set the earliest time we may clear the LED */
1740 led_next_time = jiffies + NET_FLASH_TIME;
1741 led_active = 1;
1742 mod_timer(&clear_led_timer, jiffies + HZ/10);
1743 }
1744
1745 /* configure the tx dma descriptor */
1746 myNextTxDesc->descr.sw_len = length;
1747 myNextTxDesc->descr.ctrl = d_eop | d_eol | d_wait;
1748 myNextTxDesc->descr.buf = virt_to_phys(buf);
1749
1750 /* Move end of list */
1751 myLastTxDesc->descr.ctrl &= ~d_eol;
1752 myLastTxDesc = myNextTxDesc;
1753
1754 /* Restart DMA channel */
1755 *R_DMA_CH0_CMD = IO_STATE(R_DMA_CH0_CMD, cmd, restart);
1756}
1757
1758static void
1759e100_clear_network_leds(unsigned long dummy)
1760{
1761 if (led_active && time_after(jiffies, led_next_time)) {
1762 e100_set_network_leds(NO_NETWORK_ACTIVITY);
1763
1764 /* Set the earliest time we may set the LED */
1765 led_next_time = jiffies + NET_FLASH_PAUSE;
1766 led_active = 0;
1767 }
1768}
1769
1770static void
1771e100_set_network_leds(int active)
1772{
1773#if defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK)
1774 int light_leds = (active == NO_NETWORK_ACTIVITY);
1775#elif defined(CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY)
1776 int light_leds = (active == NETWORK_ACTIVITY);
1777#else
1778#error "Define either CONFIG_ETRAX_NETWORK_LED_ON_WHEN_LINK or CONFIG_ETRAX_NETWORK_LED_ON_WHEN_ACTIVITY"
1779#endif
1780
1781 if (!current_speed) {
1782 /* Make LED red, link is down */
1783#if defined(CONFIG_ETRAX_NETWORK_RED_ON_NO_CONNECTION)
1784 LED_NETWORK_SET(LED_RED);
1785#else
1786 LED_NETWORK_SET(LED_OFF);
1787#endif
1788 }
1789 else if (light_leds) {
1790 if (current_speed == 10) {
1791 LED_NETWORK_SET(LED_ORANGE);
1792 } else {
1793 LED_NETWORK_SET(LED_GREEN);
1794 }
1795 }
1796 else {
1797 LED_NETWORK_SET(LED_OFF);
1798 }
1799}
1800
1801static int
1802etrax_init_module(void)
1803{
1804 return etrax_ethernet_init();
1805}
1806
1807static int __init
1808e100_boot_setup(char* str)
1809{
1810 struct sockaddr sa = {0};
1811 int i;
1812
1813 /* Parse the colon separated Ethernet station address */
1814 for (i = 0; i < ETH_ALEN; i++) {
1815 unsigned int tmp;
1816 if (sscanf(str + 3*i, "%2x", &tmp) != 1) {
1817 printk(KERN_WARNING "Malformed station address");
1818 return 0;
1819 }
1820 sa.sa_data[i] = (char)tmp;
1821 }
1822
1823 default_mac = sa;
1824 return 1;
1825}
1826
1827__setup("etrax100_eth=", e100_boot_setup);
1828
1829module_init(etrax_init_module);