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