wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 2 | * (C) Copyright 2001-2004 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 3 | * 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 Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 27 | #include <miiphy.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 28 | |
Mike Frysinger | 3f6e699 | 2009-01-29 19:43:44 -0500 | [diff] [blame] | 29 | #ifdef CONFIG_CMD_NET |
| 30 | void eth_parse_enetaddr(const char *addr, uchar *enetaddr) |
| 31 | { |
| 32 | char *end; |
| 33 | int i; |
| 34 | |
| 35 | for (i = 0; i < 6; ++i) { |
| 36 | enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; |
| 37 | if (addr) |
| 38 | addr = (*end) ? end + 1 : end; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | int eth_getenv_enetaddr(char *name, uchar *enetaddr) |
| 43 | { |
| 44 | eth_parse_enetaddr(getenv(name), enetaddr); |
| 45 | return is_valid_ether_addr(enetaddr); |
| 46 | } |
| 47 | |
| 48 | int eth_setenv_enetaddr(char *name, const uchar *enetaddr) |
| 49 | { |
| 50 | char buf[20]; |
| 51 | |
| 52 | sprintf(buf, "%pM", enetaddr); |
| 53 | |
| 54 | return setenv(name, buf); |
| 55 | } |
| 56 | #endif |
| 57 | |
Jon Loeliger | 643d1ab | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 58 | #if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 59 | |
Ben Warren | dd35479 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 60 | /* |
| 61 | * CPU and board-specific Ethernet initializations. Aliased function |
| 62 | * signals caller to move on |
| 63 | */ |
| 64 | static int __def_eth_init(bd_t *bis) |
| 65 | { |
| 66 | return -1; |
| 67 | } |
Peter Tyser | f9a109b | 2009-04-20 11:08:46 -0500 | [diff] [blame] | 68 | int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init"))); |
| 69 | int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init"))); |
Ben Warren | dd35479 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 70 | |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 71 | extern int mv6436x_eth_initialize(bd_t *); |
| 72 | extern int mv6446x_eth_initialize(bd_t *); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 73 | |
Rafal Jaworowski | f85b607 | 2007-12-27 18:19:02 +0100 | [diff] [blame] | 74 | #ifdef CONFIG_API |
| 75 | extern void (*push_packet)(volatile void *, int); |
| 76 | |
| 77 | static struct { |
| 78 | uchar data[PKTSIZE]; |
| 79 | int length; |
| 80 | } eth_rcv_bufs[PKTBUFSRX]; |
| 81 | |
| 82 | static unsigned int eth_rcv_current = 0, eth_rcv_last = 0; |
| 83 | #endif |
| 84 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 85 | static struct eth_device *eth_devices, *eth_current; |
| 86 | |
| 87 | struct eth_device *eth_get_dev(void) |
| 88 | { |
| 89 | return eth_current; |
| 90 | } |
| 91 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 92 | struct eth_device *eth_get_dev_by_name(char *devname) |
| 93 | { |
| 94 | struct eth_device *dev, *target_dev; |
| 95 | |
| 96 | if (!eth_devices) |
| 97 | return NULL; |
| 98 | |
| 99 | dev = eth_devices; |
| 100 | target_dev = NULL; |
| 101 | do { |
| 102 | if (strcmp(devname, dev->name) == 0) { |
| 103 | target_dev = dev; |
| 104 | break; |
| 105 | } |
| 106 | dev = dev->next; |
| 107 | } while (dev != eth_devices); |
| 108 | |
| 109 | return target_dev; |
| 110 | } |
| 111 | |
Andy Fleming | 9e56986 | 2009-02-11 15:07:24 -0600 | [diff] [blame] | 112 | struct eth_device *eth_get_dev_by_index(int index) |
| 113 | { |
| 114 | struct eth_device *dev, *target_dev; |
| 115 | int idx = 0; |
| 116 | |
| 117 | if (!eth_devices) |
| 118 | return NULL; |
| 119 | |
| 120 | dev = eth_devices; |
| 121 | target_dev = NULL; |
| 122 | do { |
| 123 | if (idx == index) { |
| 124 | target_dev = dev; |
| 125 | break; |
| 126 | } |
| 127 | dev = dev->next; |
| 128 | idx++; |
| 129 | } while (dev != eth_devices); |
| 130 | |
| 131 | return target_dev; |
| 132 | } |
| 133 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 134 | int eth_get_dev_index (void) |
| 135 | { |
| 136 | struct eth_device *dev; |
| 137 | int num = 0; |
| 138 | |
| 139 | if (!eth_devices) { |
| 140 | return (-1); |
| 141 | } |
| 142 | |
| 143 | for (dev = eth_devices; dev; dev = dev->next) { |
| 144 | if (dev == eth_current) |
| 145 | break; |
| 146 | ++num; |
| 147 | } |
| 148 | |
| 149 | if (dev) { |
| 150 | return (num); |
| 151 | } |
| 152 | |
| 153 | return (0); |
| 154 | } |
| 155 | |
| 156 | int eth_register(struct eth_device* dev) |
| 157 | { |
| 158 | struct eth_device *d; |
| 159 | |
| 160 | if (!eth_devices) { |
| 161 | eth_current = eth_devices = dev; |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 162 | #ifdef CONFIG_NET_MULTI |
| 163 | /* update current ethernet name */ |
| 164 | { |
| 165 | char *act = getenv("ethact"); |
| 166 | if (act == NULL || strcmp(act, eth_current->name) != 0) |
| 167 | setenv("ethact", eth_current->name); |
| 168 | } |
| 169 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 170 | } else { |
| 171 | for (d=eth_devices; d->next!=eth_devices; d=d->next); |
| 172 | d->next = dev; |
| 173 | } |
| 174 | |
| 175 | dev->state = ETH_STATE_INIT; |
| 176 | dev->next = eth_devices; |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | int eth_initialize(bd_t *bis) |
| 182 | { |
Shinya Kuribayashi | 5ca2d09 | 2007-11-19 20:27:04 +0900 | [diff] [blame] | 183 | char enetvar[32]; |
| 184 | unsigned char env_enetaddr[6]; |
Mike Frysinger | 3f6e699 | 2009-01-29 19:43:44 -0500 | [diff] [blame] | 185 | int eth_number = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 186 | |
| 187 | eth_devices = NULL; |
| 188 | eth_current = NULL; |
| 189 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 190 | show_boot_progress (64); |
Jon Loeliger | 643d1ab | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 191 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marian Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 192 | miiphy_init(); |
| 193 | #endif |
Ben Warren | dd35479 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 194 | /* Try board-specific initialization first. If it fails or isn't |
| 195 | * present, try the cpu-specific initialization */ |
| 196 | if (board_eth_init(bis) < 0) |
| 197 | cpu_eth_init(bis); |
Marian Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 198 | |
Stefan Roese | 1eac2a7 | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 199 | #if defined(CONFIG_DB64360) || defined(CONFIG_CPCI750) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 200 | mv6436x_eth_initialize(bis); |
| 201 | #endif |
Stefan Roese | 1eac2a7 | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 202 | #if defined(CONFIG_DB64460) || defined(CONFIG_P3Mx) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 203 | mv6446x_eth_initialize(bis); |
| 204 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 205 | if (!eth_devices) { |
| 206 | puts ("No ethernet found.\n"); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 207 | show_boot_progress (-64); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 208 | } else { |
| 209 | struct eth_device *dev = eth_devices; |
| 210 | char *ethprime = getenv ("ethprime"); |
| 211 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 212 | show_boot_progress (65); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 213 | do { |
| 214 | if (eth_number) |
| 215 | puts (", "); |
| 216 | |
| 217 | printf("%s", dev->name); |
| 218 | |
| 219 | if (ethprime && strcmp (dev->name, ethprime) == 0) { |
| 220 | eth_current = dev; |
| 221 | puts (" [PRIME]"); |
| 222 | } |
| 223 | |
| 224 | sprintf(enetvar, eth_number ? "eth%daddr" : "ethaddr", eth_number); |
Mike Frysinger | 3f6e699 | 2009-01-29 19:43:44 -0500 | [diff] [blame] | 225 | eth_getenv_enetaddr(enetvar, env_enetaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 226 | |
| 227 | if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) { |
| 228 | if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) && |
| 229 | memcmp(dev->enetaddr, env_enetaddr, 6)) |
| 230 | { |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 231 | printf ("\nWarning: %s MAC addresses don't match:\n", |
| 232 | dev->name); |
Mike Frysinger | 3f6e699 | 2009-01-29 19:43:44 -0500 | [diff] [blame] | 233 | printf ("Address in SROM is %pM\n", |
| 234 | dev->enetaddr); |
| 235 | printf ("Address in environment is %pM\n", |
| 236 | env_enetaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | memcpy(dev->enetaddr, env_enetaddr, 6); |
| 240 | } |
| 241 | |
| 242 | eth_number++; |
| 243 | dev = dev->next; |
| 244 | } while(dev != eth_devices); |
| 245 | |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 246 | #ifdef CONFIG_NET_MULTI |
| 247 | /* update current ethernet name */ |
| 248 | if (eth_current) { |
| 249 | char *act = getenv("ethact"); |
| 250 | if (act == NULL || strcmp(act, eth_current->name) != 0) |
| 251 | setenv("ethact", eth_current->name); |
| 252 | } else |
| 253 | setenv("ethact", NULL); |
| 254 | #endif |
| 255 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 256 | putc ('\n'); |
| 257 | } |
| 258 | |
| 259 | return eth_number; |
| 260 | } |
| 261 | |
| 262 | void eth_set_enetaddr(int num, char *addr) { |
| 263 | struct eth_device *dev; |
| 264 | unsigned char enetaddr[6]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 265 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 266 | debug ("eth_set_enetaddr(num=%d, addr=%s)\n", num, addr); |
| 267 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 268 | if (!eth_devices) |
| 269 | return; |
| 270 | |
Mike Frysinger | 3f6e699 | 2009-01-29 19:43:44 -0500 | [diff] [blame] | 271 | eth_parse_enetaddr(addr, enetaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 272 | |
| 273 | dev = eth_devices; |
| 274 | while(num-- > 0) { |
| 275 | dev = dev->next; |
| 276 | |
| 277 | if (dev == eth_devices) |
| 278 | return; |
| 279 | } |
| 280 | |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 281 | debug ( "Setting new HW address on %s\n" |
Mike Frysinger | 3f6e699 | 2009-01-29 19:43:44 -0500 | [diff] [blame] | 282 | "New Address is %pM\n", |
| 283 | dev->name, enetaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 284 | |
| 285 | memcpy(dev->enetaddr, enetaddr, 6); |
| 286 | } |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 287 | #ifdef CONFIG_MCAST_TFTP |
| 288 | /* Multicast. |
| 289 | * mcast_addr: multicast ipaddr from which multicast Mac is made |
Wolfgang Denk | 85eb5ca | 2007-08-14 09:47:27 +0200 | [diff] [blame] | 290 | * join: 1=join, 0=leave. |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 291 | */ |
| 292 | int eth_mcast_join( IPaddr_t mcast_ip, u8 join) |
| 293 | { |
| 294 | u8 mcast_mac[6]; |
Wolfgang Denk | 85eb5ca | 2007-08-14 09:47:27 +0200 | [diff] [blame] | 295 | if (!eth_current || !eth_current->mcast) |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 296 | return -1; |
| 297 | mcast_mac[5] = htonl(mcast_ip) & 0xff; |
| 298 | mcast_mac[4] = (htonl(mcast_ip)>>8) & 0xff; |
| 299 | mcast_mac[3] = (htonl(mcast_ip)>>16) & 0x7f; |
| 300 | mcast_mac[2] = 0x5e; |
| 301 | mcast_mac[1] = 0x0; |
| 302 | mcast_mac[0] = 0x1; |
| 303 | return eth_current->mcast(eth_current, mcast_mac, join); |
| 304 | } |
| 305 | |
Wolfgang Denk | 85eb5ca | 2007-08-14 09:47:27 +0200 | [diff] [blame] | 306 | /* the 'way' for ethernet-CRC-32. Spliced in from Linux lib/crc32.c |
| 307 | * and this is the ethernet-crc method needed for TSEC -- and perhaps |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 308 | * some other adapter -- hash tables |
| 309 | */ |
| 310 | #define CRCPOLY_LE 0xedb88320 |
| 311 | u32 ether_crc (size_t len, unsigned char const *p) |
| 312 | { |
| 313 | int i; |
| 314 | u32 crc; |
| 315 | crc = ~0; |
| 316 | while (len--) { |
| 317 | crc ^= *p++; |
| 318 | for (i = 0; i < 8; i++) |
| 319 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); |
| 320 | } |
| 321 | /* an reverse the bits, cuz of way they arrive -- last-first */ |
| 322 | crc = (crc >> 16) | (crc << 16); |
| 323 | crc = (crc >> 8 & 0x00ff00ff) | (crc << 8 & 0xff00ff00); |
| 324 | crc = (crc >> 4 & 0x0f0f0f0f) | (crc << 4 & 0xf0f0f0f0); |
| 325 | crc = (crc >> 2 & 0x33333333) | (crc << 2 & 0xcccccccc); |
| 326 | crc = (crc >> 1 & 0x55555555) | (crc << 1 & 0xaaaaaaaa); |
| 327 | return crc; |
| 328 | } |
| 329 | |
| 330 | #endif |
| 331 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 332 | |
| 333 | int eth_init(bd_t *bis) |
| 334 | { |
| 335 | struct eth_device* old_current; |
| 336 | |
Stefan Roese | 6bc1138 | 2008-03-04 17:40:41 +0100 | [diff] [blame] | 337 | if (!eth_current) { |
| 338 | puts ("No ethernet found.\n"); |
Upakul Barkakaty | 505be87 | 2007-11-29 12:16:13 +0530 | [diff] [blame] | 339 | return -1; |
Stefan Roese | 6bc1138 | 2008-03-04 17:40:41 +0100 | [diff] [blame] | 340 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 341 | |
| 342 | old_current = eth_current; |
| 343 | do { |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 344 | debug ("Trying %s\n", eth_current->name); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 345 | |
Ben Warren | 422b1a0 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 346 | if (eth_current->init(eth_current,bis) >= 0) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 347 | eth_current->state = ETH_STATE_ACTIVE; |
| 348 | |
Upakul Barkakaty | 505be87 | 2007-11-29 12:16:13 +0530 | [diff] [blame] | 349 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 350 | } |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 351 | debug ("FAIL\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 352 | |
| 353 | eth_try_another(0); |
| 354 | } while (old_current != eth_current); |
| 355 | |
Upakul Barkakaty | 505be87 | 2007-11-29 12:16:13 +0530 | [diff] [blame] | 356 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void eth_halt(void) |
| 360 | { |
| 361 | if (!eth_current) |
| 362 | return; |
| 363 | |
| 364 | eth_current->halt(eth_current); |
| 365 | |
| 366 | eth_current->state = ETH_STATE_PASSIVE; |
| 367 | } |
| 368 | |
| 369 | int eth_send(volatile void *packet, int length) |
| 370 | { |
| 371 | if (!eth_current) |
| 372 | return -1; |
| 373 | |
| 374 | return eth_current->send(eth_current, packet, length); |
| 375 | } |
| 376 | |
| 377 | int eth_rx(void) |
| 378 | { |
| 379 | if (!eth_current) |
| 380 | return -1; |
| 381 | |
| 382 | return eth_current->recv(eth_current); |
| 383 | } |
| 384 | |
Rafal Jaworowski | f85b607 | 2007-12-27 18:19:02 +0100 | [diff] [blame] | 385 | #ifdef CONFIG_API |
| 386 | static void eth_save_packet(volatile void *packet, int length) |
| 387 | { |
| 388 | volatile char *p = packet; |
| 389 | int i; |
| 390 | |
| 391 | if ((eth_rcv_last+1) % PKTBUFSRX == eth_rcv_current) |
| 392 | return; |
| 393 | |
| 394 | if (PKTSIZE < length) |
| 395 | return; |
| 396 | |
| 397 | for (i = 0; i < length; i++) |
| 398 | eth_rcv_bufs[eth_rcv_last].data[i] = p[i]; |
| 399 | |
| 400 | eth_rcv_bufs[eth_rcv_last].length = length; |
| 401 | eth_rcv_last = (eth_rcv_last + 1) % PKTBUFSRX; |
| 402 | } |
| 403 | |
| 404 | int eth_receive(volatile void *packet, int length) |
| 405 | { |
| 406 | volatile char *p = packet; |
| 407 | void *pp = push_packet; |
| 408 | int i; |
| 409 | |
| 410 | if (eth_rcv_current == eth_rcv_last) { |
| 411 | push_packet = eth_save_packet; |
| 412 | eth_rx(); |
| 413 | push_packet = pp; |
| 414 | |
| 415 | if (eth_rcv_current == eth_rcv_last) |
| 416 | return -1; |
| 417 | } |
| 418 | |
| 419 | if (length < eth_rcv_bufs[eth_rcv_current].length) |
| 420 | return -1; |
| 421 | |
| 422 | length = eth_rcv_bufs[eth_rcv_current].length; |
| 423 | |
| 424 | for (i = 0; i < length; i++) |
| 425 | p[i] = eth_rcv_bufs[eth_rcv_current].data[i]; |
| 426 | |
| 427 | eth_rcv_current = (eth_rcv_current + 1) % PKTBUFSRX; |
| 428 | return length; |
| 429 | } |
| 430 | #endif /* CONFIG_API */ |
| 431 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 432 | void eth_try_another(int first_restart) |
| 433 | { |
| 434 | static struct eth_device *first_failed = NULL; |
Matthias Fuchs | e169257 | 2008-01-17 07:45:05 +0100 | [diff] [blame] | 435 | char *ethrotate; |
| 436 | |
| 437 | /* |
| 438 | * Do not rotate between network interfaces when |
| 439 | * 'ethrotate' variable is set to 'no'. |
| 440 | */ |
| 441 | if (((ethrotate = getenv ("ethrotate")) != NULL) && |
| 442 | (strcmp(ethrotate, "no") == 0)) |
| 443 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 444 | |
| 445 | if (!eth_current) |
| 446 | return; |
| 447 | |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 448 | if (first_restart) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 449 | first_failed = eth_current; |
| 450 | } |
| 451 | |
| 452 | eth_current = eth_current->next; |
| 453 | |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 454 | #ifdef CONFIG_NET_MULTI |
| 455 | /* update current ethernet name */ |
| 456 | { |
| 457 | char *act = getenv("ethact"); |
| 458 | if (act == NULL || strcmp(act, eth_current->name) != 0) |
| 459 | setenv("ethact", eth_current->name); |
| 460 | } |
| 461 | #endif |
| 462 | |
wdenk | baac607 | 2004-05-08 20:33:20 +0000 | [diff] [blame] | 463 | if (first_failed == eth_current) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 464 | NetRestartWrap = 1; |
| 465 | } |
| 466 | } |
| 467 | |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 468 | #ifdef CONFIG_NET_MULTI |
| 469 | void eth_set_current(void) |
| 470 | { |
Heiko Schocher | da95427 | 2009-04-28 08:36:11 +0200 | [diff] [blame] | 471 | static char *act = NULL; |
| 472 | static int env_changed_id = 0; |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 473 | struct eth_device* old_current; |
Heiko Schocher | 2f70c49 | 2009-02-10 09:38:52 +0100 | [diff] [blame] | 474 | int env_id; |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 475 | |
| 476 | if (!eth_current) /* XXX no current */ |
| 477 | return; |
| 478 | |
Heiko Schocher | 2f70c49 | 2009-02-10 09:38:52 +0100 | [diff] [blame] | 479 | env_id = get_env_id(); |
| 480 | if ((act == NULL) || (env_changed_id != env_id)) { |
| 481 | act = getenv("ethact"); |
| 482 | env_changed_id = env_id; |
| 483 | } |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 484 | if (act != NULL) { |
| 485 | old_current = eth_current; |
| 486 | do { |
| 487 | if (strcmp(eth_current->name, act) == 0) |
| 488 | return; |
| 489 | eth_current = eth_current->next; |
| 490 | } while (old_current != eth_current); |
| 491 | } |
| 492 | |
| 493 | setenv("ethact", eth_current->name); |
| 494 | } |
| 495 | #endif |
| 496 | |
wdenk | 5bb226e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 497 | char *eth_get_name (void) |
| 498 | { |
| 499 | return (eth_current ? eth_current->name : "unknown"); |
| 500 | } |
Jon Loeliger | 643d1ab | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 501 | #elif defined(CONFIG_CMD_NET) && !defined(CONFIG_NET_MULTI) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 502 | |
| 503 | extern int at91rm9200_miiphy_initialize(bd_t *bis); |
| 504 | extern int emac4xx_miiphy_initialize(bd_t *bis); |
| 505 | extern int mcf52x2_miiphy_initialize(bd_t *bis); |
| 506 | extern int ns7520_miiphy_initialize(bd_t *bis); |
Jean-Christophe PLAGNIOL-VILLARD | d6e0425 | 2008-08-31 04:45:42 +0200 | [diff] [blame] | 507 | extern int davinci_eth_miiphy_initialize(bd_t *bis); |
Sergey Kubushyn | c74b210 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 508 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 509 | |
| 510 | int eth_initialize(bd_t *bis) |
| 511 | { |
Jon Loeliger | 643d1ab | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 512 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Marian Balakowicz | d9785c1 | 2005-11-30 18:06:04 +0100 | [diff] [blame] | 513 | miiphy_init(); |
| 514 | #endif |
| 515 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 516 | #if defined(CONFIG_AT91RM9200) |
| 517 | at91rm9200_miiphy_initialize(bis); |
| 518 | #endif |
Ben Warren | 96e21f8 | 2008-10-27 23:50:15 -0700 | [diff] [blame] | 519 | #if defined(CONFIG_PPC4xx_EMAC) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 520 | emac4xx_miiphy_initialize(bis); |
| 521 | #endif |
| 522 | #if defined(CONFIG_MCF52x2) |
| 523 | mcf52x2_miiphy_initialize(bis); |
| 524 | #endif |
Wolfgang Denk | 25dbe98 | 2008-07-13 23:07:35 +0200 | [diff] [blame] | 525 | #if defined(CONFIG_DRIVER_NS7520_ETHERNET) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 526 | ns7520_miiphy_initialize(bis); |
| 527 | #endif |
Sergey Kubushyn | c74b210 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 528 | #if defined(CONFIG_DRIVER_TI_EMAC) |
Sandeep Paulraj | fcaac58 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 529 | davinci_eth_miiphy_initialize(bis); |
Sergey Kubushyn | c74b210 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 530 | #endif |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 531 | return 0; |
| 532 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 533 | #endif |