summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2016-01-17 14:51:59 -0700
committerJoe Hershberger <joe.hershberger@ni.com>2016-01-28 12:32:46 -0600
commit8607a6bf753df210f8873994294c13885f746337 (patch)
treed66ab661d8563a7c1576bd1cec3c8790df77d6a7 /net
parent9987ecdd36da79535c4229ecc5693533aaa8d17b (diff)
net: Move remaining common functions to eth_common.c
Move eth_current_changed(), eth_set_current(), eth_mac_skip() and eth_get_name() into the common file. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Diffstat (limited to 'net')
-rw-r--r--net/eth.c108
-rw-r--r--net/eth_common.c100
-rw-r--r--net/eth_internal.h9
3 files changed, 113 insertions, 104 deletions
diff --git a/net/eth.c b/net/eth.c
index af8fcaea904..907eb118fff 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -20,18 +20,6 @@
DECLARE_GLOBAL_DATA_PTR;
-static int eth_mac_skip(int index)
-{
- char enetvar[15];
- char *skip_state;
-
- sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
- skip_state = getenv(enetvar);
- return skip_state != NULL;
-}
-
-static void eth_current_changed(void);
-
/*
* CPU and board-specific Ethernet initializations. Aliased function
* signals caller to move on
@@ -74,7 +62,7 @@ static struct eth_uclass_priv *eth_get_uclass_priv(void)
return uc->priv;
}
-static void eth_set_current_to_next(void)
+void eth_set_current_to_next(void)
{
struct eth_uclass_priv *uc_priv;
@@ -107,7 +95,7 @@ struct udevice *eth_get_dev(void)
* In case it was not probed, we will attempt to do so.
* dev may be NULL to unset the active device.
*/
-static void eth_set_dev(struct udevice *dev)
+void eth_set_dev(struct udevice *dev)
{
if (dev && !device_active(dev)) {
eth_errno = device_probe(dev);
@@ -593,12 +581,12 @@ static unsigned int eth_rcv_current, eth_rcv_last;
static struct eth_device *eth_devices;
struct eth_device *eth_current;
-static void eth_set_current_to_next(void)
+void eth_set_current_to_next(void)
{
eth_current = eth_current->next;
}
-static void eth_set_dev(struct eth_device *dev)
+void eth_set_dev(struct eth_device *dev)
{
eth_current = dev;
}
@@ -992,91 +980,3 @@ int eth_receive(void *packet, int length)
return length;
}
#endif /* CONFIG_API */
-
-static void eth_current_changed(void)
-{
- char *act = getenv("ethact");
- char *ethrotate;
-
- /*
- * The call to eth_get_dev() below has a side effect of rotating
- * ethernet device if uc_priv->current == NULL. This is not what
- * we want when 'ethrotate' variable is 'no'.
- */
- ethrotate = getenv("ethrotate");
- if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
- return;
-
- /* update current ethernet name */
- if (eth_get_dev()) {
- if (act == NULL || strcmp(act, eth_get_name()) != 0)
- setenv("ethact", eth_get_name());
- }
- /*
- * remove the variable completely if there is no active
- * interface
- */
- else if (act != NULL)
- setenv("ethact", NULL);
-}
-
-void eth_try_another(int first_restart)
-{
- static void *first_failed;
- char *ethrotate;
-
- /*
- * Do not rotate between network interfaces when
- * 'ethrotate' variable is set to 'no'.
- */
- ethrotate = getenv("ethrotate");
- if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
- return;
-
- if (!eth_get_dev())
- return;
-
- if (first_restart)
- first_failed = eth_get_dev();
-
- eth_set_current_to_next();
-
- eth_current_changed();
-
- if (first_failed == eth_get_dev())
- net_restart_wrap = 1;
-}
-
-void eth_set_current(void)
-{
- static char *act;
- static int env_changed_id;
- int env_id;
-
- env_id = get_env_id();
- if ((act == NULL) || (env_changed_id != env_id)) {
- act = getenv("ethact");
- env_changed_id = env_id;
- }
-
- if (act == NULL) {
- char *ethprime = getenv("ethprime");
- void *dev = NULL;
-
- if (ethprime)
- dev = eth_get_dev_by_name(ethprime);
- if (dev)
- eth_set_dev(dev);
- else
- eth_set_dev(NULL);
- } else {
- eth_set_dev(eth_get_dev_by_name(act));
- }
-
- eth_current_changed();
-}
-
-const char *eth_get_name(void)
-{
- return eth_get_dev() ? eth_get_dev()->name : "unknown";
-}
diff --git a/net/eth_common.c b/net/eth_common.c
index 3fa6d83c70b..288090155e5 100644
--- a/net/eth_common.c
+++ b/net/eth_common.c
@@ -7,7 +7,9 @@
*/
#include <common.h>
+#include <dm.h>
#include <miiphy.h>
+#include <net.h>
#include "eth_internal.h"
void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
@@ -64,3 +66,101 @@ void eth_common_init(void)
phy_init();
#endif
}
+
+int eth_mac_skip(int index)
+{
+ char enetvar[15];
+ char *skip_state;
+
+ sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
+ skip_state = getenv(enetvar);
+ return skip_state != NULL;
+}
+
+void eth_current_changed(void)
+{
+ char *act = getenv("ethact");
+ char *ethrotate;
+
+ /*
+ * The call to eth_get_dev() below has a side effect of rotating
+ * ethernet device if uc_priv->current == NULL. This is not what
+ * we want when 'ethrotate' variable is 'no'.
+ */
+ ethrotate = getenv("ethrotate");
+ if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
+ return;
+
+ /* update current ethernet name */
+ if (eth_get_dev()) {
+ if (act == NULL || strcmp(act, eth_get_name()) != 0)
+ setenv("ethact", eth_get_name());
+ }
+ /*
+ * remove the variable completely if there is no active
+ * interface
+ */
+ else if (act != NULL)
+ setenv("ethact", NULL);
+}
+
+void eth_try_another(int first_restart)
+{
+ static void *first_failed;
+ char *ethrotate;
+
+ /*
+ * Do not rotate between network interfaces when
+ * 'ethrotate' variable is set to 'no'.
+ */
+ ethrotate = getenv("ethrotate");
+ if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
+ return;
+
+ if (!eth_get_dev())
+ return;
+
+ if (first_restart)
+ first_failed = eth_get_dev();
+
+ eth_set_current_to_next();
+
+ eth_current_changed();
+
+ if (first_failed == eth_get_dev())
+ net_restart_wrap = 1;
+}
+
+void eth_set_current(void)
+{
+ static char *act;
+ static int env_changed_id;
+ int env_id;
+
+ env_id = get_env_id();
+ if ((act == NULL) || (env_changed_id != env_id)) {
+ act = getenv("ethact");
+ env_changed_id = env_id;
+ }
+
+ if (act == NULL) {
+ char *ethprime = getenv("ethprime");
+ void *dev = NULL;
+
+ if (ethprime)
+ dev = eth_get_dev_by_name(ethprime);
+ if (dev)
+ eth_set_dev(dev);
+ else
+ eth_set_dev(NULL);
+ } else {
+ eth_set_dev(eth_get_dev_by_name(act));
+ }
+
+ eth_current_changed();
+}
+
+const char *eth_get_name(void)
+{
+ return eth_get_dev() ? eth_get_dev()->name : "unknown";
+}
diff --git a/net/eth_internal.h b/net/eth_internal.h
index 38d84201e61..6e4753cd0dd 100644
--- a/net/eth_internal.h
+++ b/net/eth_internal.h
@@ -28,4 +28,13 @@ void eth_common_init(void);
int eth_setenv_enetaddr_by_index(const char *base_name, int index,
uchar *enetaddr);
+int eth_mac_skip(int index);
+void eth_current_changed(void);
+#ifdef CONFIG_DM_ETH
+void eth_set_dev(struct udevice *dev);
+#else
+void eth_set_dev(struct eth_device *dev);
+#endif
+void eth_set_current_to_next(void);
+
#endif