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
14 #include "eth_internal.h"
16 int eth_env_get_enetaddr_by_index(const char *base_name, int index,
20 sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
21 return eth_env_get_enetaddr(enetvar, enetaddr);
24 int eth_env_set_enetaddr_by_index(const char *base_name, int index,
28 sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
29 return eth_env_set_enetaddr(enetvar, enetaddr);
32 void eth_common_init(void)
34 bootstage_mark(BOOTSTAGE_ID_NET_ETH_START);
35 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
44 int eth_mac_skip(int index)
49 sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
50 skip_state = env_get(enetvar);
51 return skip_state != NULL;
54 void eth_current_changed(void)
56 char *act = env_get("ethact");
60 * The call to eth_get_dev() below has a side effect of rotating
61 * ethernet device if uc_priv->current == NULL. This is not what
62 * we want when 'ethrotate' variable is 'no'.
64 ethrotate = env_get("ethrotate");
65 if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
68 /* update current ethernet name */
70 if (act == NULL || strcmp(act, eth_get_name()) != 0)
71 env_set("ethact", eth_get_name());
74 * remove the variable completely if there is no active
78 env_set("ethact", NULL);
81 void eth_try_another(int first_restart)
83 static void *first_failed;
87 * Do not rotate between network interfaces when
88 * 'ethrotate' variable is set to 'no'.
90 ethrotate = env_get("ethrotate");
91 if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
98 first_failed = eth_get_dev();
100 eth_set_current_to_next();
102 eth_current_changed();
104 if (first_failed == eth_get_dev())
105 net_restart_wrap = 1;
108 void eth_set_current(void)
111 static int env_changed_id;
114 env_id = env_get_id();
115 if ((act == NULL) || (env_changed_id != env_id)) {
116 act = env_get("ethact");
117 env_changed_id = env_id;
121 char *ethprime = env_get("ethprime");
125 dev = eth_get_dev_by_name(ethprime);
131 eth_set_dev(eth_get_dev_by_name(act));
134 eth_current_changed();
137 const char *eth_get_name(void)
139 return eth_get_dev() ? eth_get_dev()->name : "unknown";