km/scripts: search for kernel/DTBs at serverip:/PRODUCTNAME via TFTP in develop mode
[oweals/u-boot.git] / net / eth.c
index 26520d303885ea1e77e396b7f175d13f0299417b..c542f4aa3b3b1e4f2e6fbb5db4c0ea579aefe45e 100644 (file)
--- a/net/eth.c
+++ b/net/eth.c
@@ -31,13 +31,13 @@ void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
        }
 }
 
-int eth_getenv_enetaddr(char *name, uchar *enetaddr)
+int eth_getenv_enetaddr(const char *name, uchar *enetaddr)
 {
        eth_parse_enetaddr(getenv(name), enetaddr);
        return is_valid_ethaddr(enetaddr);
 }
 
-int eth_setenv_enetaddr(char *name, const uchar *enetaddr)
+int eth_setenv_enetaddr(const char *name, const uchar *enetaddr)
 {
        char buf[20];
 
@@ -179,8 +179,12 @@ struct udevice *eth_get_dev(void)
  */
 static void eth_set_dev(struct udevice *dev)
 {
-       if (dev && !device_active(dev))
+       if (dev && !device_active(dev)) {
                eth_errno = device_probe(dev);
+               if (eth_errno)
+                       dev = NULL;
+       }
+
        eth_get_uclass_priv()->current = dev;
 }
 
@@ -213,10 +217,9 @@ struct udevice *eth_get_dev_by_name(const char *devname)
                 * match an alias or it will match a literal name and we'll pick
                 * up the error when we try to probe again in eth_set_dev().
                 */
-               device_probe(it);
-               /*
-                * Check for the name or the sequence number to match
-                */
+               if (device_probe(it))
+                       continue;
+               /* Check for the name or the sequence number to match */
                if (strcmp(it->name, devname) == 0 ||
                    (endp > startp && it->seq == seq))
                        return it;
@@ -346,23 +349,27 @@ int eth_init(void)
 
        old_current = current;
        do {
-               debug("Trying %s\n", current->name);
-
-               if (device_active(current)) {
-                       ret = eth_get_ops(current)->start(current);
-                       if (ret >= 0) {
-                               struct eth_device_priv *priv =
-                                       current->uclass_priv;
-
-                               priv->state = ETH_STATE_ACTIVE;
-                               return 0;
+               if (current) {
+                       debug("Trying %s\n", current->name);
+
+                       if (device_active(current)) {
+                               ret = eth_get_ops(current)->start(current);
+                               if (ret >= 0) {
+                                       struct eth_device_priv *priv =
+                                               current->uclass_priv;
+
+                                       priv->state = ETH_STATE_ACTIVE;
+                                       return 0;
+                               }
+                       } else {
+                               ret = eth_errno;
                        }
+
+                       debug("FAIL\n");
                } else {
-                       ret = eth_errno;
+                       debug("PROBE FAIL\n");
                }
 
-               debug("FAIL\n");
-
                /*
                 * If ethrotate is enabled, this will change "current",
                 * otherwise we will drop out of this while loop immediately
@@ -389,6 +396,17 @@ void eth_halt(void)
        priv->state = ETH_STATE_PASSIVE;
 }
 
+int eth_is_active(struct udevice *dev)
+{
+       struct eth_device_priv *priv;
+
+       if (!dev || !device_active(dev))
+               return 0;
+
+       priv = dev_get_uclass_priv(dev);
+       return priv->state == ETH_STATE_ACTIVE;
+}
+
 int eth_send(void *packet, int length)
 {
        struct udevice *current;
@@ -564,8 +582,13 @@ static int eth_post_probe(struct udevice *dev)
 
 static int eth_pre_remove(struct udevice *dev)
 {
+       struct eth_pdata *pdata = dev->platdata;
+
        eth_get_ops(dev)->stop(dev);
 
+       /* clear the MAC address */
+       memset(pdata->enetaddr, 0, 6);
+
        return 0;
 }
 
@@ -580,7 +603,7 @@ UCLASS_DRIVER(eth) = {
        .per_device_auto_alloc_size = sizeof(struct eth_device_priv),
        .flags          = DM_UC_FLAG_SEQ_ALIAS,
 };
-#endif
+#endif /* #ifdef CONFIG_DM_ETH */
 
 #ifndef CONFIG_DM_ETH
 
@@ -680,6 +703,7 @@ static int on_ethaddr(const char *name, const char *value, enum env_op op,
                                memset(dev->enetaddr, 0, 6);
                        }
                }
+               dev = dev->next;
        } while (dev != eth_devices);
 
        return 0;
@@ -918,6 +942,11 @@ void eth_halt(void)
        eth_current->state = ETH_STATE_PASSIVE;
 }
 
+int eth_is_active(struct eth_device *dev)
+{
+       return dev && dev->state == ETH_STATE_ACTIVE;
+}
+
 int eth_send(void *packet, int length)
 {
        if (!eth_current)