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