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 CONFIG_IS_ENABLED(ETH)
35 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
41 int eth_mac_skip(int index
)
46 sprintf(enetvar
, index
? "eth%dmacskip" : "ethmacskip", index
);
47 skip_state
= env_get(enetvar
);
48 return skip_state
!= NULL
;
51 void eth_current_changed(void)
53 char *act
= env_get("ethact");
57 * The call to eth_get_dev() below has a side effect of rotating
58 * ethernet device if uc_priv->current == NULL. This is not what
59 * we want when 'ethrotate' variable is 'no'.
61 ethrotate
= env_get("ethrotate");
62 if ((ethrotate
!= NULL
) && (strcmp(ethrotate
, "no") == 0))
65 /* update current ethernet name */
67 if (act
== NULL
|| strcmp(act
, eth_get_name()) != 0)
68 env_set("ethact", eth_get_name());
71 * remove the variable completely if there is no active
75 env_set("ethact", NULL
);
78 void eth_try_another(int first_restart
)
80 static void *first_failed
;
84 * Do not rotate between network interfaces when
85 * 'ethrotate' variable is set to 'no'.
87 ethrotate
= env_get("ethrotate");
88 if ((ethrotate
!= NULL
) && (strcmp(ethrotate
, "no") == 0))
95 first_failed
= eth_get_dev();
97 eth_set_current_to_next();
99 eth_current_changed();
101 if (first_failed
== eth_get_dev())
102 net_restart_wrap
= 1;
105 void eth_set_current(void)
108 static int env_changed_id
;
111 env_id
= env_get_id();
112 if ((act
== NULL
) || (env_changed_id
!= env_id
)) {
113 act
= env_get("ethact");
114 env_changed_id
= env_id
;
118 char *ethprime
= env_get("ethprime");
122 dev
= eth_get_dev_by_name(ethprime
);
128 eth_set_dev(eth_get_dev_by_name(act
));
131 eth_current_changed();
134 const char *eth_get_name(void)
136 return eth_get_dev() ? eth_get_dev()->name
: "unknown";