Merge tag 'mips-pull-2019-11-16' of git://git.denx.de/u-boot-mips
[oweals/u-boot.git] / drivers / net / sandbox-raw.c
index c04b94c6e186fd4366a53a85ace526f8fc6ce221..7e6625d0202fcf074a1706705d4e4c0a2915af59 100644 (file)
@@ -130,11 +130,21 @@ static void sb_eth_raw_stop(struct udevice *dev)
        sandbox_eth_raw_os_stop(priv);
 }
 
+static int sb_eth_raw_read_rom_hwaddr(struct udevice *dev)
+{
+       struct eth_pdata *pdata = dev_get_platdata(dev);
+
+       net_random_ethaddr(pdata->enetaddr);
+
+       return 0;
+}
+
 static const struct eth_ops sb_eth_raw_ops = {
        .start                  = sb_eth_raw_start,
        .send                   = sb_eth_raw_send,
        .recv                   = sb_eth_raw_recv,
        .stop                   = sb_eth_raw_stop,
+       .read_rom_hwaddr        = sb_eth_raw_read_rom_hwaddr,
 };
 
 static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev)
@@ -142,7 +152,7 @@ static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev)
        struct eth_pdata *pdata = dev_get_platdata(dev);
        struct eth_sandbox_raw_priv *priv = dev_get_priv(dev);
        const char *ifname;
-       u32 local;
+       int ret;
 
        pdata->iobase = dev_read_addr(dev);
 
@@ -151,11 +161,21 @@ static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev)
                strncpy(priv->host_ifname, ifname, IFNAMSIZ);
                printf(": Using %s from DT\n", priv->host_ifname);
        }
+       if (dev_read_u32(dev, "host-raw-interface-idx",
+                        &priv->host_ifindex) < 0) {
+               priv->host_ifindex = 0;
+       } else {
+               ret = sandbox_eth_raw_os_idx_to_name(priv);
+               if (ret < 0)
+                       return ret;
+               printf(": Using interface index %d from DT (%s)\n",
+                      priv->host_ifindex, priv->host_ifname);
+       }
 
-       local = sandbox_eth_raw_os_is_local(priv->host_ifname);
-       if (local < 0)
-               return local;
-       priv->local = local;
+       ret = sandbox_eth_raw_os_is_local(priv->host_ifname);
+       if (ret < 0)
+               return ret;
+       priv->local = ret;
 
        return 0;
 }