blob: 8e83b66c0a619bf316d6607a1f3ac833ef4e0fb2 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
wdenkd4ca31c2004-01-02 14:00:00 +00002 * (C) Copyright 2001-2004
wdenkc6097192002-11-03 00:24:07 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <command.h>
26#include <net.h>
Marian Balakowiczd9785c12005-11-30 18:06:04 +010027#include <miiphy.h>
wdenkc6097192002-11-03 00:24:07 +000028
Jon Loeliger643d1ab2007-07-09 17:45:14 -050029#if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI)
wdenkc6097192002-11-03 00:24:07 +000030
Ben Warrendd354792008-06-23 22:57:27 -070031/*
32 * CPU and board-specific Ethernet initializations. Aliased function
33 * signals caller to move on
34 */
35static int __def_eth_init(bd_t *bis)
36{
37 return -1;
38}
39int cpu_eth_init(bd_t *bis) __attribute((weak, alias("__def_eth_init")));
40int board_eth_init(bd_t *bis) __attribute((weak, alias("__def_eth_init")));
41
wdenkc6097192002-11-03 00:24:07 +000042#ifdef CFG_GT_6426x
43extern int gt6426x_eth_initialize(bd_t *bis);
44#endif
45
wdenk3a473b22004-01-03 00:43:19 +000046extern int au1x00_enet_initialize(bd_t*);
47extern int dc21x4x_initialize(bd_t*);
wdenk682011f2003-06-03 23:54:09 +000048extern int e1000_initialize(bd_t*);
wdenkc6097192002-11-03 00:24:07 +000049extern int eepro100_initialize(bd_t*);
wdenk3a473b22004-01-03 00:43:19 +000050extern int eth_3com_initialize(bd_t*);
51extern int fec_initialize(bd_t*);
52extern int inca_switch_initialize(bd_t*);
53extern int mpc5xxx_fec_initialize(bd_t*);
Rafal Jaworowski8993e542007-07-27 14:43:59 +020054extern int mpc512x_fec_initialize(bd_t*);
wdenk983fda82004-10-28 00:09:35 +000055extern int mpc8220_fec_initialize(bd_t*);
wdenk3a473b22004-01-03 00:43:19 +000056extern int mv6436x_eth_initialize(bd_t *);
57extern int mv6446x_eth_initialize(bd_t *);
wdenkc6097192002-11-03 00:24:07 +000058extern int natsemi_initialize(bd_t*);
59extern int ns8382x_initialize(bd_t*);
wdenkc6097192002-11-03 00:24:07 +000060extern int pcnet_initialize(bd_t*);
wdenk3e386912003-04-05 00:53:31 +000061extern int plb2800_eth_initialize(bd_t*);
wdenk3a473b22004-01-03 00:43:19 +000062extern int ppc_4xx_eth_initialize(bd_t *);
63extern int rtl8139_initialize(bd_t*);
wdenka8bd82d2004-04-18 22:03:42 +000064extern int rtl8169_initialize(bd_t*);
wdenk3a473b22004-01-03 00:43:19 +000065extern int scc_initialize(bd_t*);
wdenk7152b1d2003-09-05 23:19:14 +000066extern int skge_initialize(bd_t*);
roy zangd1927ce2006-11-02 19:08:55 +080067extern int tsi108_eth_initialize(bd_t*);
Roy Zang1f103102007-11-05 17:39:24 +080068extern int uli526x_initialize(bd_t *);
Wolfgang Denkba94a1b2006-05-30 15:56:48 +020069extern int npe_initialize(bd_t *);
Dave Liu7737d5c2006-11-03 12:11:15 -060070extern int uec_initialize(int);
Aubrey Li9fd437b2007-04-05 18:30:25 +080071extern int bfin_EMAC_initialize(bd_t *);
Daniel Hellstromc2b7da52008-03-28 20:22:53 +010072extern int greth_initialize(bd_t *);
TsiChung Liew8e585f02007-06-18 13:50:13 -050073extern int mcffec_initialize(bd_t*);
TsiChungLiew777d1ab2008-01-15 14:00:25 -060074extern int mcdmafec_initialize(bd_t*);
Stelian Popa8a78f22008-03-26 20:52:28 +010075extern int at91sam9_eth_initialize(bd_t *);
wdenkc6097192002-11-03 00:24:07 +000076
Rafal Jaworowskif85b6072007-12-27 18:19:02 +010077#ifdef CONFIG_API
78extern void (*push_packet)(volatile void *, int);
79
80static struct {
81 uchar data[PKTSIZE];
82 int length;
83} eth_rcv_bufs[PKTBUFSRX];
84
85static unsigned int eth_rcv_current = 0, eth_rcv_last = 0;
86#endif
87
wdenkc6097192002-11-03 00:24:07 +000088static struct eth_device *eth_devices, *eth_current;
89
90struct eth_device *eth_get_dev(void)
91{
92 return eth_current;
93}
94
Marian Balakowicz63ff0042005-10-28 22:30:33 +020095struct eth_device *eth_get_dev_by_name(char *devname)
96{
97 struct eth_device *dev, *target_dev;
98
99 if (!eth_devices)
100 return NULL;
101
102 dev = eth_devices;
103 target_dev = NULL;
104 do {
105 if (strcmp(devname, dev->name) == 0) {
106 target_dev = dev;
107 break;
108 }
109 dev = dev->next;
110 } while (dev != eth_devices);
111
112 return target_dev;
113}
114
wdenkc6097192002-11-03 00:24:07 +0000115int eth_get_dev_index (void)
116{
117 struct eth_device *dev;
118 int num = 0;
119
120 if (!eth_devices) {
121 return (-1);
122 }
123
124 for (dev = eth_devices; dev; dev = dev->next) {
125 if (dev == eth_current)
126 break;
127 ++num;
128 }
129
130 if (dev) {
131 return (num);
132 }
133
134 return (0);
135}
136
137int eth_register(struct eth_device* dev)
138{
139 struct eth_device *d;
140
141 if (!eth_devices) {
142 eth_current = eth_devices = dev;
wdenka3d991b2004-04-15 21:48:45 +0000143#ifdef CONFIG_NET_MULTI
144 /* update current ethernet name */
145 {
146 char *act = getenv("ethact");
147 if (act == NULL || strcmp(act, eth_current->name) != 0)
148 setenv("ethact", eth_current->name);
149 }
150#endif
wdenkc6097192002-11-03 00:24:07 +0000151 } else {
152 for (d=eth_devices; d->next!=eth_devices; d=d->next);
153 d->next = dev;
154 }
155
156 dev->state = ETH_STATE_INIT;
157 dev->next = eth_devices;
158
159 return 0;
160}
161
162int eth_initialize(bd_t *bis)
163{
Shinya Kuribayashi5ca2d092007-11-19 20:27:04 +0900164 char enetvar[32];
165 unsigned char env_enetaddr[6];
wdenkc6097192002-11-03 00:24:07 +0000166 int i, eth_number = 0;
167 char *tmp, *end;
168
169 eth_devices = NULL;
170 eth_current = NULL;
171
Heiko Schocherfad63402007-07-13 09:54:17 +0200172 show_boot_progress (64);
Jon Loeliger643d1ab2007-07-09 17:45:14 -0500173#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowiczd9785c12005-11-30 18:06:04 +0100174 miiphy_init();
175#endif
Ben Warrendd354792008-06-23 22:57:27 -0700176 /* Try board-specific initialization first. If it fails or isn't
177 * present, try the cpu-specific initialization */
178 if (board_eth_init(bis) < 0)
179 cpu_eth_init(bis);
Marian Balakowiczd9785c12005-11-30 18:06:04 +0100180
Stefan Roese1eac2a72006-11-29 15:42:37 +0100181#if defined(CONFIG_DB64360) || defined(CONFIG_CPCI750)
wdenk3a473b22004-01-03 00:43:19 +0000182 mv6436x_eth_initialize(bis);
183#endif
Stefan Roese1eac2a72006-11-29 15:42:37 +0100184#if defined(CONFIG_DB64460) || defined(CONFIG_P3Mx)
wdenk3a473b22004-01-03 00:43:19 +0000185 mv6446x_eth_initialize(bis);
186#endif
Wolfgang Denk7521af12005-10-09 01:04:33 +0200187#if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) && !defined(CONFIG_AP1000)
wdenk8bde7f72003-06-27 21:31:46 +0000188 ppc_4xx_eth_initialize(bis);
wdenka3ed3992003-06-05 19:37:36 +0000189#endif
wdenk6069ff22003-02-28 00:49:47 +0000190#ifdef CONFIG_INCA_IP_SWITCH
191 inca_switch_initialize(bis);
192#endif
wdenk3e386912003-04-05 00:53:31 +0000193#ifdef CONFIG_PLB2800_ETHER
194 plb2800_eth_initialize(bis);
195#endif
wdenkbaac6072004-05-08 20:33:20 +0000196#ifdef SCC_ENET
197 scc_initialize(bis);
198#endif
wdenkbaac6072004-05-08 20:33:20 +0000199#if defined(CONFIG_MPC5xxx_FEC)
200 mpc5xxx_fec_initialize(bis);
201#endif
Rafal Jaworowski8993e542007-07-27 14:43:59 +0200202#if defined(CONFIG_MPC512x_FEC)
203 mpc512x_fec_initialize (bis);
204#endif
wdenk7680c142005-05-16 15:23:22 +0000205#if defined(CONFIG_MPC8220_FEC)
wdenk983fda82004-10-28 00:09:35 +0000206 mpc8220_fec_initialize(bis);
207#endif
wdenkbaac6072004-05-08 20:33:20 +0000208#if defined(CONFIG_SK98)
209 skge_initialize(bis);
210#endif
Dave Liu7737d5c2006-11-03 12:11:15 -0600211#if defined(CONFIG_UEC_ETH1)
212 uec_initialize(0);
213#endif
214#if defined(CONFIG_UEC_ETH2)
215 uec_initialize(1);
216#endif
Joakim Tjernlundccf21c32007-12-06 16:43:40 +0100217#if defined(CONFIG_UEC_ETH3)
218 uec_initialize(2);
219#endif
David Saada24656652008-01-15 10:40:24 +0200220#if defined(CONFIG_UEC_ETH4)
221 uec_initialize(3);
222#endif
Jon Loeligerdebb7352006-04-26 17:58:56 -0500223
Stefan Roesed96f41e2005-11-30 13:06:40 +0100224#if defined(FEC_ENET) || defined(CONFIG_ETHER_ON_FCC)
225 fec_initialize(bis);
226#endif
wdenkbaac6072004-05-08 20:33:20 +0000227#if defined(CONFIG_AU1X00)
228 au1x00_enet_initialize(bis);
229#endif
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200230#if defined(CONFIG_IXP4XX_NPE)
231 npe_initialize(bis);
232#endif
wdenk682011f2003-06-03 23:54:09 +0000233#ifdef CONFIG_E1000
234 e1000_initialize(bis);
235#endif
wdenkc6097192002-11-03 00:24:07 +0000236#ifdef CONFIG_EEPRO100
237 eepro100_initialize(bis);
238#endif
239#ifdef CONFIG_TULIP
240 dc21x4x_initialize(bis);
241#endif
wdenkc7de8292002-11-19 11:04:11 +0000242#ifdef CONFIG_3COM
243 eth_3com_initialize(bis);
244#endif
wdenkc6097192002-11-03 00:24:07 +0000245#ifdef CONFIG_PCNET
246 pcnet_initialize(bis);
247#endif
248#ifdef CFG_GT_6426x
249 gt6426x_eth_initialize(bis);
250#endif
251#ifdef CONFIG_NATSEMI
252 natsemi_initialize(bis);
253#endif
254#ifdef CONFIG_NS8382X
255 ns8382x_initialize(bis);
256#endif
roy zangd1927ce2006-11-02 19:08:55 +0800257#if defined(CONFIG_TSI108_ETH)
258 tsi108_eth_initialize(bis);
259#endif
Roy Zang1f103102007-11-05 17:39:24 +0800260#if defined(CONFIG_ULI526X)
261 uli526x_initialize(bis);
262#endif
wdenk63f34912004-01-02 15:01:32 +0000263#if defined(CONFIG_RTL8139)
264 rtl8139_initialize(bis);
265#endif
wdenka8bd82d2004-04-18 22:03:42 +0000266#if defined(CONFIG_RTL8169)
267 rtl8169_initialize(bis);
268#endif
Aubrey Li9fd437b2007-04-05 18:30:25 +0800269#if defined(CONFIG_BF537)
270 bfin_EMAC_initialize(bis);
271#endif
Daniel Hellstromc2b7da52008-03-28 20:22:53 +0100272#if defined(CONFIG_GRETH)
273 greth_initialize(bis);
274#endif
TsiChungLiew2870e982007-07-05 23:29:21 -0500275#if defined(CONFIG_MCFFEC)
276 mcffec_initialize(bis);
277#endif
TsiChungLiew777d1ab2008-01-15 14:00:25 -0600278#if defined(CONFIG_FSLDMAFEC)
279 mcdmafec_initialize(bis);
280#endif
Stelian Pop8e429b32008-05-08 18:52:23 +0200281#if defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
282 defined(CONFIG_AT91SAM9263)
Stelian Popa8a78f22008-03-26 20:52:28 +0100283 at91sam9_eth_initialize(bis);
Stelian Pop20b197c2008-01-20 19:49:21 +0000284#endif
wdenkc6097192002-11-03 00:24:07 +0000285
286 if (!eth_devices) {
287 puts ("No ethernet found.\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200288 show_boot_progress (-64);
wdenkc6097192002-11-03 00:24:07 +0000289 } else {
290 struct eth_device *dev = eth_devices;
291 char *ethprime = getenv ("ethprime");
292
Heiko Schocherfad63402007-07-13 09:54:17 +0200293 show_boot_progress (65);
wdenkc6097192002-11-03 00:24:07 +0000294 do {
295 if (eth_number)
296 puts (", ");
297
298 printf("%s", dev->name);
299
300 if (ethprime && strcmp (dev->name, ethprime) == 0) {
301 eth_current = dev;
302 puts (" [PRIME]");
303 }
304
305 sprintf(enetvar, eth_number ? "eth%daddr" : "ethaddr", eth_number);
306 tmp = getenv (enetvar);
307
308 for (i=0; i<6; i++) {
309 env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
310 if (tmp)
311 tmp = (*end) ? end+1 : end;
312 }
313
314 if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
315 if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) &&
316 memcmp(dev->enetaddr, env_enetaddr, 6))
317 {
wdenkbaac6072004-05-08 20:33:20 +0000318 printf ("\nWarning: %s MAC addresses don't match:\n",
319 dev->name);
320 printf ("Address in SROM is "
wdenkc6097192002-11-03 00:24:07 +0000321 "%02X:%02X:%02X:%02X:%02X:%02X\n",
322 dev->enetaddr[0], dev->enetaddr[1],
323 dev->enetaddr[2], dev->enetaddr[3],
324 dev->enetaddr[4], dev->enetaddr[5]);
wdenkbaac6072004-05-08 20:33:20 +0000325 printf ("Address in environment is "
wdenkc6097192002-11-03 00:24:07 +0000326 "%02X:%02X:%02X:%02X:%02X:%02X\n",
327 env_enetaddr[0], env_enetaddr[1],
328 env_enetaddr[2], env_enetaddr[3],
329 env_enetaddr[4], env_enetaddr[5]);
330 }
331
332 memcpy(dev->enetaddr, env_enetaddr, 6);
333 }
334
335 eth_number++;
336 dev = dev->next;
337 } while(dev != eth_devices);
338
wdenka3d991b2004-04-15 21:48:45 +0000339#ifdef CONFIG_NET_MULTI
340 /* update current ethernet name */
341 if (eth_current) {
342 char *act = getenv("ethact");
343 if (act == NULL || strcmp(act, eth_current->name) != 0)
344 setenv("ethact", eth_current->name);
345 } else
346 setenv("ethact", NULL);
347#endif
348
wdenkc6097192002-11-03 00:24:07 +0000349 putc ('\n');
350 }
351
352 return eth_number;
353}
354
355void eth_set_enetaddr(int num, char *addr) {
356 struct eth_device *dev;
357 unsigned char enetaddr[6];
358 char *end;
359 int i;
360
wdenkd4ca31c2004-01-02 14:00:00 +0000361 debug ("eth_set_enetaddr(num=%d, addr=%s)\n", num, addr);
362
wdenkc6097192002-11-03 00:24:07 +0000363 if (!eth_devices)
364 return;
365
366 for (i=0; i<6; i++) {
367 enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0;
368 if (addr)
369 addr = (*end) ? end+1 : end;
370 }
371
372 dev = eth_devices;
373 while(num-- > 0) {
374 dev = dev->next;
375
376 if (dev == eth_devices)
377 return;
378 }
379
wdenkd4ca31c2004-01-02 14:00:00 +0000380 debug ( "Setting new HW address on %s\n"
381 "New Address is %02X:%02X:%02X:%02X:%02X:%02X\n",
382 dev->name,
Wolfgang Denka188b582005-09-25 17:05:57 +0200383 enetaddr[0], enetaddr[1],
384 enetaddr[2], enetaddr[3],
385 enetaddr[4], enetaddr[5]);
wdenkc6097192002-11-03 00:24:07 +0000386
387 memcpy(dev->enetaddr, enetaddr, 6);
388}
David Updegraff53a5c422007-06-11 10:41:07 -0500389#ifdef CONFIG_MCAST_TFTP
390/* Multicast.
391 * mcast_addr: multicast ipaddr from which multicast Mac is made
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200392 * join: 1=join, 0=leave.
David Updegraff53a5c422007-06-11 10:41:07 -0500393 */
394int eth_mcast_join( IPaddr_t mcast_ip, u8 join)
395{
396 u8 mcast_mac[6];
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200397 if (!eth_current || !eth_current->mcast)
David Updegraff53a5c422007-06-11 10:41:07 -0500398 return -1;
399 mcast_mac[5] = htonl(mcast_ip) & 0xff;
400 mcast_mac[4] = (htonl(mcast_ip)>>8) & 0xff;
401 mcast_mac[3] = (htonl(mcast_ip)>>16) & 0x7f;
402 mcast_mac[2] = 0x5e;
403 mcast_mac[1] = 0x0;
404 mcast_mac[0] = 0x1;
405 return eth_current->mcast(eth_current, mcast_mac, join);
406}
407
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200408/* the 'way' for ethernet-CRC-32. Spliced in from Linux lib/crc32.c
409 * and this is the ethernet-crc method needed for TSEC -- and perhaps
David Updegraff53a5c422007-06-11 10:41:07 -0500410 * some other adapter -- hash tables
411 */
412#define CRCPOLY_LE 0xedb88320
413u32 ether_crc (size_t len, unsigned char const *p)
414{
415 int i;
416 u32 crc;
417 crc = ~0;
418 while (len--) {
419 crc ^= *p++;
420 for (i = 0; i < 8; i++)
421 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
422 }
423 /* an reverse the bits, cuz of way they arrive -- last-first */
424 crc = (crc >> 16) | (crc << 16);
425 crc = (crc >> 8 & 0x00ff00ff) | (crc << 8 & 0xff00ff00);
426 crc = (crc >> 4 & 0x0f0f0f0f) | (crc << 4 & 0xf0f0f0f0);
427 crc = (crc >> 2 & 0x33333333) | (crc << 2 & 0xcccccccc);
428 crc = (crc >> 1 & 0x55555555) | (crc << 1 & 0xaaaaaaaa);
429 return crc;
430}
431
432#endif
433
wdenkc6097192002-11-03 00:24:07 +0000434
435int eth_init(bd_t *bis)
436{
437 struct eth_device* old_current;
438
Stefan Roese6bc11382008-03-04 17:40:41 +0100439 if (!eth_current) {
440 puts ("No ethernet found.\n");
Upakul Barkakaty505be872007-11-29 12:16:13 +0530441 return -1;
Stefan Roese6bc11382008-03-04 17:40:41 +0100442 }
wdenkc6097192002-11-03 00:24:07 +0000443
444 old_current = eth_current;
445 do {
wdenkd4ca31c2004-01-02 14:00:00 +0000446 debug ("Trying %s\n", eth_current->name);
wdenkc6097192002-11-03 00:24:07 +0000447
Ben Warren422b1a02008-01-09 18:15:53 -0500448 if (eth_current->init(eth_current,bis) >= 0) {
wdenkc6097192002-11-03 00:24:07 +0000449 eth_current->state = ETH_STATE_ACTIVE;
450
Upakul Barkakaty505be872007-11-29 12:16:13 +0530451 return 0;
wdenkc6097192002-11-03 00:24:07 +0000452 }
wdenkd4ca31c2004-01-02 14:00:00 +0000453 debug ("FAIL\n");
wdenkc6097192002-11-03 00:24:07 +0000454
455 eth_try_another(0);
456 } while (old_current != eth_current);
457
Upakul Barkakaty505be872007-11-29 12:16:13 +0530458 return -1;
wdenkc6097192002-11-03 00:24:07 +0000459}
460
461void eth_halt(void)
462{
463 if (!eth_current)
464 return;
465
466 eth_current->halt(eth_current);
467
468 eth_current->state = ETH_STATE_PASSIVE;
469}
470
471int eth_send(volatile void *packet, int length)
472{
473 if (!eth_current)
474 return -1;
475
476 return eth_current->send(eth_current, packet, length);
477}
478
479int eth_rx(void)
480{
481 if (!eth_current)
482 return -1;
483
484 return eth_current->recv(eth_current);
485}
486
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100487#ifdef CONFIG_API
488static void eth_save_packet(volatile void *packet, int length)
489{
490 volatile char *p = packet;
491 int i;
492
493 if ((eth_rcv_last+1) % PKTBUFSRX == eth_rcv_current)
494 return;
495
496 if (PKTSIZE < length)
497 return;
498
499 for (i = 0; i < length; i++)
500 eth_rcv_bufs[eth_rcv_last].data[i] = p[i];
501
502 eth_rcv_bufs[eth_rcv_last].length = length;
503 eth_rcv_last = (eth_rcv_last + 1) % PKTBUFSRX;
504}
505
506int eth_receive(volatile void *packet, int length)
507{
508 volatile char *p = packet;
509 void *pp = push_packet;
510 int i;
511
512 if (eth_rcv_current == eth_rcv_last) {
513 push_packet = eth_save_packet;
514 eth_rx();
515 push_packet = pp;
516
517 if (eth_rcv_current == eth_rcv_last)
518 return -1;
519 }
520
521 if (length < eth_rcv_bufs[eth_rcv_current].length)
522 return -1;
523
524 length = eth_rcv_bufs[eth_rcv_current].length;
525
526 for (i = 0; i < length; i++)
527 p[i] = eth_rcv_bufs[eth_rcv_current].data[i];
528
529 eth_rcv_current = (eth_rcv_current + 1) % PKTBUFSRX;
530 return length;
531}
532#endif /* CONFIG_API */
533
wdenkc6097192002-11-03 00:24:07 +0000534void eth_try_another(int first_restart)
535{
536 static struct eth_device *first_failed = NULL;
Matthias Fuchse1692572008-01-17 07:45:05 +0100537 char *ethrotate;
538
539 /*
540 * Do not rotate between network interfaces when
541 * 'ethrotate' variable is set to 'no'.
542 */
543 if (((ethrotate = getenv ("ethrotate")) != NULL) &&
544 (strcmp(ethrotate, "no") == 0))
545 return;
wdenkc6097192002-11-03 00:24:07 +0000546
547 if (!eth_current)
548 return;
549
wdenkbaac6072004-05-08 20:33:20 +0000550 if (first_restart) {
wdenkc6097192002-11-03 00:24:07 +0000551 first_failed = eth_current;
552 }
553
554 eth_current = eth_current->next;
555
wdenka3d991b2004-04-15 21:48:45 +0000556#ifdef CONFIG_NET_MULTI
557 /* update current ethernet name */
558 {
559 char *act = getenv("ethact");
560 if (act == NULL || strcmp(act, eth_current->name) != 0)
561 setenv("ethact", eth_current->name);
562 }
563#endif
564
wdenkbaac6072004-05-08 20:33:20 +0000565 if (first_failed == eth_current) {
wdenkc6097192002-11-03 00:24:07 +0000566 NetRestartWrap = 1;
567 }
568}
569
wdenka3d991b2004-04-15 21:48:45 +0000570#ifdef CONFIG_NET_MULTI
571void eth_set_current(void)
572{
573 char *act;
574 struct eth_device* old_current;
575
576 if (!eth_current) /* XXX no current */
577 return;
578
579 act = getenv("ethact");
580 if (act != NULL) {
581 old_current = eth_current;
582 do {
583 if (strcmp(eth_current->name, act) == 0)
584 return;
585 eth_current = eth_current->next;
586 } while (old_current != eth_current);
587 }
588
589 setenv("ethact", eth_current->name);
590}
591#endif
592
wdenk5bb226e2003-11-17 21:14:37 +0000593char *eth_get_name (void)
594{
595 return (eth_current ? eth_current->name : "unknown");
596}
Jon Loeliger643d1ab2007-07-09 17:45:14 -0500597#elif defined(CONFIG_CMD_NET) && !defined(CONFIG_NET_MULTI)
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200598
599extern int at91rm9200_miiphy_initialize(bd_t *bis);
600extern int emac4xx_miiphy_initialize(bd_t *bis);
601extern int mcf52x2_miiphy_initialize(bd_t *bis);
602extern int ns7520_miiphy_initialize(bd_t *bis);
Sergey Kubushync74b2102007-08-10 20:26:18 +0200603extern int dm644x_eth_miiphy_initialize(bd_t *bis);
604
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200605
606int eth_initialize(bd_t *bis)
607{
Jon Loeliger643d1ab2007-07-09 17:45:14 -0500608#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowiczd9785c12005-11-30 18:06:04 +0100609 miiphy_init();
610#endif
611
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200612#if defined(CONFIG_AT91RM9200)
613 at91rm9200_miiphy_initialize(bis);
614#endif
615#if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) \
616 && !defined(CONFIG_AP1000) && !defined(CONFIG_405)
617 emac4xx_miiphy_initialize(bis);
618#endif
619#if defined(CONFIG_MCF52x2)
620 mcf52x2_miiphy_initialize(bis);
621#endif
Wolfgang Denk25dbe982008-07-13 23:07:35 +0200622#if defined(CONFIG_DRIVER_NS7520_ETHERNET)
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200623 ns7520_miiphy_initialize(bis);
624#endif
Sergey Kubushync74b2102007-08-10 20:26:18 +0200625#if defined(CONFIG_DRIVER_TI_EMAC)
626 dm644x_eth_miiphy_initialize(bis);
627#endif
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200628 return 0;
629}
wdenkc6097192002-11-03 00:24:07 +0000630#endif