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