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