Commit 8607a6bf753df210f8873994294c13885f746337

Authored by Simon Glass
Committed by Joe Hershberger
1 parent 9987ecdd36

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>

Showing 3 changed files with 113 additions and 104 deletions Side-by-side Diff

... ... @@ -20,18 +20,6 @@
20 20  
21 21 DECLARE_GLOBAL_DATA_PTR;
22 22  
23   -static int eth_mac_skip(int index)
24   -{
25   - char enetvar[15];
26   - char *skip_state;
27   -
28   - sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
29   - skip_state = getenv(enetvar);
30   - return skip_state != NULL;
31   -}
32   -
33   -static void eth_current_changed(void);
34   -
35 23 /*
36 24 * CPU and board-specific Ethernet initializations. Aliased function
37 25 * signals caller to move on
... ... @@ -74,7 +62,7 @@
74 62 return uc->priv;
75 63 }
76 64  
77   -static void eth_set_current_to_next(void)
  65 +void eth_set_current_to_next(void)
78 66 {
79 67 struct eth_uclass_priv *uc_priv;
80 68  
... ... @@ -107,7 +95,7 @@
107 95 * In case it was not probed, we will attempt to do so.
108 96 * dev may be NULL to unset the active device.
109 97 */
110   -static void eth_set_dev(struct udevice *dev)
  98 +void eth_set_dev(struct udevice *dev)
111 99 {
112 100 if (dev && !device_active(dev)) {
113 101 eth_errno = device_probe(dev);
114 102  
... ... @@ -593,12 +581,12 @@
593 581 static struct eth_device *eth_devices;
594 582 struct eth_device *eth_current;
595 583  
596   -static void eth_set_current_to_next(void)
  584 +void eth_set_current_to_next(void)
597 585 {
598 586 eth_current = eth_current->next;
599 587 }
600 588  
601   -static void eth_set_dev(struct eth_device *dev)
  589 +void eth_set_dev(struct eth_device *dev)
602 590 {
603 591 eth_current = dev;
604 592 }
... ... @@ -992,92 +980,4 @@
992 980 return length;
993 981 }
994 982 #endif /* CONFIG_API */
995   -
996   -static void eth_current_changed(void)
997   -{
998   - char *act = getenv("ethact");
999   - char *ethrotate;
1000   -
1001   - /*
1002   - * The call to eth_get_dev() below has a side effect of rotating
1003   - * ethernet device if uc_priv->current == NULL. This is not what
1004   - * we want when 'ethrotate' variable is 'no'.
1005   - */
1006   - ethrotate = getenv("ethrotate");
1007   - if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
1008   - return;
1009   -
1010   - /* update current ethernet name */
1011   - if (eth_get_dev()) {
1012   - if (act == NULL || strcmp(act, eth_get_name()) != 0)
1013   - setenv("ethact", eth_get_name());
1014   - }
1015   - /*
1016   - * remove the variable completely if there is no active
1017   - * interface
1018   - */
1019   - else if (act != NULL)
1020   - setenv("ethact", NULL);
1021   -}
1022   -
1023   -void eth_try_another(int first_restart)
1024   -{
1025   - static void *first_failed;
1026   - char *ethrotate;
1027   -
1028   - /*
1029   - * Do not rotate between network interfaces when
1030   - * 'ethrotate' variable is set to 'no'.
1031   - */
1032   - ethrotate = getenv("ethrotate");
1033   - if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
1034   - return;
1035   -
1036   - if (!eth_get_dev())
1037   - return;
1038   -
1039   - if (first_restart)
1040   - first_failed = eth_get_dev();
1041   -
1042   - eth_set_current_to_next();
1043   -
1044   - eth_current_changed();
1045   -
1046   - if (first_failed == eth_get_dev())
1047   - net_restart_wrap = 1;
1048   -}
1049   -
1050   -void eth_set_current(void)
1051   -{
1052   - static char *act;
1053   - static int env_changed_id;
1054   - int env_id;
1055   -
1056   - env_id = get_env_id();
1057   - if ((act == NULL) || (env_changed_id != env_id)) {
1058   - act = getenv("ethact");
1059   - env_changed_id = env_id;
1060   - }
1061   -
1062   - if (act == NULL) {
1063   - char *ethprime = getenv("ethprime");
1064   - void *dev = NULL;
1065   -
1066   - if (ethprime)
1067   - dev = eth_get_dev_by_name(ethprime);
1068   - if (dev)
1069   - eth_set_dev(dev);
1070   - else
1071   - eth_set_dev(NULL);
1072   - } else {
1073   - eth_set_dev(eth_get_dev_by_name(act));
1074   - }
1075   -
1076   - eth_current_changed();
1077   -}
1078   -
1079   -const char *eth_get_name(void)
1080   -{
1081   - return eth_get_dev() ? eth_get_dev()->name : "unknown";
1082   -}
... ... @@ -7,7 +7,9 @@
7 7 */
8 8  
9 9 #include <common.h>
  10 +#include <dm.h>
10 11 #include <miiphy.h>
  12 +#include <net.h>
11 13 #include "eth_internal.h"
12 14  
13 15 void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
... ... @@ -63,5 +65,103 @@
63 65 #ifdef CONFIG_PHYLIB
64 66 phy_init();
65 67 #endif
  68 +}
  69 +
  70 +int eth_mac_skip(int index)
  71 +{
  72 + char enetvar[15];
  73 + char *skip_state;
  74 +
  75 + sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
  76 + skip_state = getenv(enetvar);
  77 + return skip_state != NULL;
  78 +}
  79 +
  80 +void eth_current_changed(void)
  81 +{
  82 + char *act = getenv("ethact");
  83 + char *ethrotate;
  84 +
  85 + /*
  86 + * The call to eth_get_dev() below has a side effect of rotating
  87 + * ethernet device if uc_priv->current == NULL. This is not what
  88 + * we want when 'ethrotate' variable is 'no'.
  89 + */
  90 + ethrotate = getenv("ethrotate");
  91 + if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
  92 + return;
  93 +
  94 + /* update current ethernet name */
  95 + if (eth_get_dev()) {
  96 + if (act == NULL || strcmp(act, eth_get_name()) != 0)
  97 + setenv("ethact", eth_get_name());
  98 + }
  99 + /*
  100 + * remove the variable completely if there is no active
  101 + * interface
  102 + */
  103 + else if (act != NULL)
  104 + setenv("ethact", NULL);
  105 +}
  106 +
  107 +void eth_try_another(int first_restart)
  108 +{
  109 + static void *first_failed;
  110 + char *ethrotate;
  111 +
  112 + /*
  113 + * Do not rotate between network interfaces when
  114 + * 'ethrotate' variable is set to 'no'.
  115 + */
  116 + ethrotate = getenv("ethrotate");
  117 + if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
  118 + return;
  119 +
  120 + if (!eth_get_dev())
  121 + return;
  122 +
  123 + if (first_restart)
  124 + first_failed = eth_get_dev();
  125 +
  126 + eth_set_current_to_next();
  127 +
  128 + eth_current_changed();
  129 +
  130 + if (first_failed == eth_get_dev())
  131 + net_restart_wrap = 1;
  132 +}
  133 +
  134 +void eth_set_current(void)
  135 +{
  136 + static char *act;
  137 + static int env_changed_id;
  138 + int env_id;
  139 +
  140 + env_id = get_env_id();
  141 + if ((act == NULL) || (env_changed_id != env_id)) {
  142 + act = getenv("ethact");
  143 + env_changed_id = env_id;
  144 + }
  145 +
  146 + if (act == NULL) {
  147 + char *ethprime = getenv("ethprime");
  148 + void *dev = NULL;
  149 +
  150 + if (ethprime)
  151 + dev = eth_get_dev_by_name(ethprime);
  152 + if (dev)
  153 + eth_set_dev(dev);
  154 + else
  155 + eth_set_dev(NULL);
  156 + } else {
  157 + eth_set_dev(eth_get_dev_by_name(act));
  158 + }
  159 +
  160 + eth_current_changed();
  161 +}
  162 +
  163 +const char *eth_get_name(void)
  164 +{
  165 + return eth_get_dev() ? eth_get_dev()->name : "unknown";
66 166 }
... ... @@ -28,5 +28,14 @@
28 28 int eth_setenv_enetaddr_by_index(const char *base_name, int index,
29 29 uchar *enetaddr);
30 30  
  31 +int eth_mac_skip(int index);
  32 +void eth_current_changed(void);
  33 +#ifdef CONFIG_DM_ETH
  34 +void eth_set_dev(struct udevice *dev);
  35 +#else
  36 +void eth_set_dev(struct eth_device *dev);
  37 +#endif
  38 +void eth_set_current_to_next(void);
  39 +
31 40 #endif