All of lore.kernel.org
 help / color / mirror / Atom feed
From: Detlev Casanova <detlev.casanova@collabora.com>
To: u-boot@lists.denx.de
Cc: Joe Hershberger <joe.hershberger@ni.com>,
	Ramon Fried <rfried.dev@gmail.com>, Tom Rini <trini@konsulko.com>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Kever Yang <kever.yang@rock-chips.com>,
	Marek Vasut <marek.vasut+renesas@mailbox.org>,
	Jonas Karlman <jonas@kwiboo.se>, Simon Glass <sjg@chromium.org>,
	Fabio Estevam <festevam@denx.de>,
	Detlev Casanova <detlev.casanova@collabora.com>
Subject: [PATCH v2 1/3] net: eth-uclass: Introduce NET_PREFER_ROM_MAC_ADDR
Date: Mon, 22 Apr 2024 09:56:18 -0400	[thread overview]
Message-ID: <20240422135927.23582-2-detlev.casanova@collabora.com> (raw)
In-Reply-To: <20240422135927.23582-1-detlev.casanova@collabora.com>

On some boards, a MAC address is set based on the CPU ID or other
information. This is usually done in the misc_init_r() function.

This becomes a problem for net devices that are probed after the call to
misc_init_r(), for example, when the ethernet is on a PCI port, which
needs to be enumerated.

In this case, misc_init_r() will set the ethaddr variable, then, when
the ethernet device is probed, if it has a ROM address, u-boot will warn
about a MAC address mismatch and use the misc_init_r() address instead
of the one in ROM.

The operating system later will most likely use the ROM MAC address,
which can be confusing.

To avoid that, this commit introduces NET_PREFER_ROM_MAC_ADDR that can
be set for boards that have such an interface.

Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
 net/Kconfig      | 7 +++++++
 net/eth-uclass.c | 9 +++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/net/Kconfig b/net/Kconfig
index 5dff6336293..1797c2cea35 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -227,6 +227,13 @@ config SERVERIP
 	string "Value of the default 'serverip' value in the environment"
 	depends on USE_SERVERIP
 
+config NET_PREFER_ROM_MAC_ADDR
+	bool "Prefer using HW MAC address if environment address differs"
+	default n
+	help
+	  In case of a MAC address mismatch between the environment and the HW,
+	  prefer using the HW address.
+
 config PROT_TCP
 	bool "TCP stack"
 	help
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index 3d0ec91dfa4..682de3ec7bd 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -584,8 +584,13 @@ static int eth_post_probe(struct udevice *dev)
 			       env_enetaddr);
 		}
 
-		/* Override the ROM MAC address */
-		memcpy(pdata->enetaddr, env_enetaddr, ARP_HLEN);
+		if (!IS_ENABLED(CONFIG_NET_PREFER_ROM_MAC_ADDR)) {
+			/* Override the ROM MAC address */
+			printf("Using address in environment\n");
+			memcpy(pdata->enetaddr, env_enetaddr, ARP_HLEN);
+		} else {
+			printf("Using address in %s\n", source);
+		}
 	} else if (is_valid_ethaddr(pdata->enetaddr)) {
 		eth_env_set_enetaddr_by_index("eth", dev_seq(dev),
 					      pdata->enetaddr);
-- 
2.43.2


  reply	other threads:[~2024-04-22 14:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22 13:56 [PATCH v2 0/3] Introduce NET_PREFER_ROM_MAC_ADDR config Detlev Casanova
2024-04-22 13:56 ` Detlev Casanova [this message]
2024-04-22 19:47   ` [PATCH v2 1/3] net: eth-uclass: Introduce NET_PREFER_ROM_MAC_ADDR Marek Vasut
2024-04-23 13:35     ` Detlev Casanova
2024-04-23 13:44       ` Marek Vasut
2024-04-22 13:56 ` [PATCH v2 2/3] configs/rock5b: Set NET_PREFER_ROM_MAC_ADDR to y Detlev Casanova
2024-04-22 19:47   ` Marek Vasut
2024-04-22 13:56 ` [PATCH v2 3/3] net: eth-uclass: Add driver source possibility Detlev Casanova

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240422135927.23582-2-detlev.casanova@collabora.com \
    --to=detlev.casanova@collabora.com \
    --cc=festevam@denx.de \
    --cc=joe.hershberger@ni.com \
    --cc=jonas@kwiboo.se \
    --cc=kever.yang@rock-chips.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=philipp.tomsich@vrull.eu \
    --cc=rfried.dev@gmail.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.