1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2001-2015
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Joe Hershberger, National Instruments
13 #include "eth_internal.h"
15 int eth_env_get_enetaddr_by_index(const char *base_name, int index,
19 sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
20 return eth_env_get_enetaddr(enetvar, enetaddr);
23 int eth_env_set_enetaddr_by_index(const char *base_name, int index,
27 sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
28 return eth_env_set_enetaddr(enetvar, enetaddr);
31 void eth_common_init(void)
33 bootstage_mark(BOOTSTAGE_ID_NET_ETH_START);
34 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
43 int eth_mac_skip(int index)
48 sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
49 skip_state = env_get(enetvar);
50 return skip_state != NULL;
53 void eth_current_changed(void)
55 char *act = env_get("ethact");
59 * The call to eth_get_dev() below has a side effect of rotating
60 * ethernet device if uc_priv->current == NULL. This is not what
61 * we want when 'ethrotate' variable is 'no'.
63 ethrotate = env_get("ethrotate");
64 if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
67 /* update current ethernet name */
69 if (act == NULL || strcmp(act, eth_get_name()) != 0)
70 env_set("ethact", eth_get_name());
73 * remove the variable completely if there is no active
77 env_set("ethact", NULL);
80 void eth_try_another(int first_restart)
82 static void *first_failed;
86 * Do not rotate between network interfaces when
87 * 'ethrotate' variable is set to 'no'.
89 ethrotate = env_get("ethrotate");
90 if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
97 first_failed = eth_get_dev();
99 eth_set_current_to_next();
101 eth_current_changed();
103 if (first_failed == eth_get_dev())
104 net_restart_wrap = 1;
107 void eth_set_current(void)
110 static int env_changed_id;
113 env_id = env_get_id();
114 if ((act == NULL) || (env_changed_id != env_id)) {
115 act = env_get("ethact");
116 env_changed_id = env_id;
120 char *ethprime = env_get("ethprime");
124 dev = eth_get_dev_by_name(ethprime);
130 eth_set_dev(eth_get_dev_by_name(act));
133 eth_current_changed();
136 const char *eth_get_name(void)
138 return eth_get_dev() ? eth_get_dev()->name : "unknown";