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