diff mbox series

[V2] net: ethernet: davinci_emac: Use MAC Address from Device Tree

Message ID 20231022151911.4279-1-aford173@gmail.com (mailing list archive)
State Accepted
Commit f30a51a41828986687997a5aa95b9f8085228cff
Delegated to: Netdev Maintainers
Headers show
Series [V2] net: ethernet: davinci_emac: Use MAC Address from Device Tree | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1363 this patch: 1363
netdev/cc_maintainers warning 3 maintainers not CCed: f.fainelli@gmail.com robh@kernel.org u.kleine-koenig@pengutronix.de
netdev/build_clang success Errors and warnings before: 1388 this patch: 1388
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1388 this patch: 1388
netdev/checkpatch warning WARNING: line length of 86 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Adam Ford Oct. 22, 2023, 3:19 p.m. UTC
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>
---
V2:  Rebase, add R-B tag, and post stand-alone for netdev branch, since
     the device tree patch has already been accepted via the omap tree.

Comments

Jacob Keller Oct. 24, 2023, 12:14 a.m. UTC | #1
On 10/22/2023 8:19 AM, Adam Ford wrote:
> 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>
> ---
> V2:  Rebase, add R-B tag, and post stand-alone for netdev branch, since
>      the device tree patch has already been accepted via the omap tree.

Looks like you didn't add the tag for which tree. Given the context, I
would assume net-next.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Adam Ford Oct. 24, 2023, 1:22 a.m. UTC | #2
On Mon, Oct 23, 2023 at 7:14 PM Jacob Keller <jacob.e.keller@intel.com> wrote:
>
>
>
> On 10/22/2023 8:19 AM, Adam Ford wrote:
> > 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>
> > ---
> > V2:  Rebase, add R-B tag, and post stand-alone for netdev branch, since
> >      the device tree patch has already been accepted via the omap tree.
>
> Looks like you didn't add the tag for which tree. Given the context, I
> would assume net-next.
>

That was my intent.  I sent the e-mail to netdev and CC'd others.  I
thought that was enough.


> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Paolo Abeni Oct. 24, 2023, 9:24 a.m. UTC | #3
On Mon, 2023-10-23 at 20:22 -0500, Adam Ford wrote:
> On Mon, Oct 23, 2023 at 7:14 PM Jacob Keller <jacob.e.keller@intel.com> wrote:
> > Looks like you didn't add the tag for which tree. Given the context, I
> > would assume net-next.
> 
> That was my intent.  I sent the e-mail to netdev and CC'd others.  I
> thought that was enough.

For future submissions: there are 2 different netdev trees, one for new
features (net-next) and another one for bugfixes (net), and you should
specify the target explcitly in the patch prefix. See: 

Documentation/process/maintainer-netdev.rst

for the more details.

Looks like this one is targeting net-next.

Cheers,

Paolo
patchwork-bot+netdevbpf@kernel.org Oct. 24, 2023, 9:30 a.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Sun, 22 Oct 2023 10:19:11 -0500 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [V2] net: ethernet: davinci_emac: Use MAC Address from Device Tree
    https://git.kernel.org/netdev/net-next/c/f30a51a41828

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 23f8bc1cd20d..b0950a318c42 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1928,18 +1928,20 @@  static int davinci_emac_probe(struct platform_device *pdev)
 		goto err_free_rxchan;
 	ndev->irq = rc;
 
-	rc = davinci_emac_try_get_mac(pdev, res_ctrl ? 0 : 1, priv->mac_addr);
-	if (!rc)
-		eth_hw_addr_set(ndev, priv->mac_addr);
-
+	/* If the MAC address is not present, read the registers from the SoC */
 	if (!is_valid_ether_addr(priv->mac_addr)) {
-		/* Use random MAC if still none obtained. */
-		eth_hw_addr_random(ndev);
-		memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len);
-		dev_warn(&pdev->dev, "using random MAC addr: %pM\n",
-			 priv->mac_addr);
+		rc = davinci_emac_try_get_mac(pdev, res_ctrl ? 0 : 1, priv->mac_addr);
+		if (!rc)
+			eth_hw_addr_set(ndev, priv->mac_addr);
+
+		if (!is_valid_ether_addr(priv->mac_addr)) {
+			/* Use random MAC if still none obtained. */
+			eth_hw_addr_random(ndev);
+			memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len);
+			dev_warn(&pdev->dev, "using random MAC addr: %pM\n",
+				 priv->mac_addr);
+		}
 	}
-
 	ndev->netdev_ops = &emac_netdev_ops;
 	ndev->ethtool_ops = &ethtool_ops;
 	netif_napi_add(ndev, &priv->napi, emac_poll);