diff options
author | Madalin Bucur <madalin.bucur@oss.nxp.com> | 2020-03-05 19:08:58 +0200 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2020-03-08 22:02:54 -0700 |
commit | cbb961ca271e18d60cec6e48e32216148f74ee35 (patch) | |
tree | 3c628037209e5bb9e95817da108ebb50ffef3ee8 /drivers/net/ethernet/freescale | |
parent | f3353b99022583cc17142146cdc4dd6a770fbc7f (diff) | |
download | linux-cbb961ca271e18d60cec6e48e32216148f74ee35.tar.bz2 |
dpaa_eth: Use random MAC address when none is given
If there is no valid MAC address in the device tree, use a random
MAC address.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Madalin Bucur <madalin.bucur@oss.nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/freescale')
-rw-r--r-- | drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index fd93d542f497..c0fe305b9d16 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -233,8 +233,20 @@ static int dpaa_netdev_init(struct net_device *net_dev, net_dev->features |= net_dev->hw_features; net_dev->vlan_features = net_dev->features; - memcpy(net_dev->perm_addr, mac_addr, net_dev->addr_len); - memcpy(net_dev->dev_addr, mac_addr, net_dev->addr_len); + if (is_valid_ether_addr(mac_addr)) { + memcpy(net_dev->perm_addr, mac_addr, net_dev->addr_len); + memcpy(net_dev->dev_addr, mac_addr, net_dev->addr_len); + } else { + eth_hw_addr_random(net_dev); + err = priv->mac_dev->change_addr(priv->mac_dev->fman_mac, + (enet_addr_t *)net_dev->dev_addr); + if (err) { + dev_err(dev, "Failed to set random MAC address\n"); + return -EINVAL; + } + dev_info(dev, "Using random MAC address: %pM\n", + net_dev->dev_addr); + } net_dev->ethtool_ops = &dpaa_ethtool_ops; |