Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: ethernet: davinci_emac: Use MAC Address from Device Tree

Currently there is a device tree entry called "local-mac-address"
which can be filled by the bootloader or manually set.This is
useful when the user does not want to use the MAC address
programmed into the SoC.

Currently, the davinci_emac reads the MAC from the DT, copies
it from pdata->mac_addr to priv->mac_addr, then blindly overwrites
it by reading from registers in the SoC, and falls back to a
random MAC if it's still not valid. This completely ignores any
MAC address in the device tree.

In order to use the local-mac-address, check to see if the contents
of priv->mac_addr are valid before falling back to reading from the
SoC when the MAC address is not valid.

Signed-off-by: Adam Ford <aford173@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20231022151911.4279-1-aford173@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Adam Ford and committed by
Paolo Abeni
f30a51a4 66e6369e

+12 -10
+12 -10
drivers/net/ethernet/ti/davinci_emac.c
··· 1928 1928 goto err_free_rxchan; 1929 1929 ndev->irq = rc; 1930 1930 1931 - rc = davinci_emac_try_get_mac(pdev, res_ctrl ? 0 : 1, priv->mac_addr); 1932 - if (!rc) 1933 - eth_hw_addr_set(ndev, priv->mac_addr); 1934 - 1931 + /* If the MAC address is not present, read the registers from the SoC */ 1935 1932 if (!is_valid_ether_addr(priv->mac_addr)) { 1936 - /* Use random MAC if still none obtained. */ 1937 - eth_hw_addr_random(ndev); 1938 - memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len); 1939 - dev_warn(&pdev->dev, "using random MAC addr: %pM\n", 1940 - priv->mac_addr); 1941 - } 1933 + rc = davinci_emac_try_get_mac(pdev, res_ctrl ? 0 : 1, priv->mac_addr); 1934 + if (!rc) 1935 + eth_hw_addr_set(ndev, priv->mac_addr); 1942 1936 1937 + if (!is_valid_ether_addr(priv->mac_addr)) { 1938 + /* Use random MAC if still none obtained. */ 1939 + eth_hw_addr_random(ndev); 1940 + memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len); 1941 + dev_warn(&pdev->dev, "using random MAC addr: %pM\n", 1942 + priv->mac_addr); 1943 + } 1944 + } 1943 1945 ndev->netdev_ops = &emac_netdev_ops; 1944 1946 ndev->ethtool_ops = &ethtool_ops; 1945 1947 netif_napi_add(ndev, &priv->napi, emac_poll);