diff mbox series

ARM: imx: stm32: Test whether ethernet node is enabled before reading MAC EEPROM on DHSOM

Message ID 20240312211628.32842-1-marex@denx.de
State Accepted
Commit 786af90de8ceba3cee1818376b9d53421c5be598
Delegated to: Fabio Estevam
Headers show
Series ARM: imx: stm32: Test whether ethernet node is enabled before reading MAC EEPROM on DHSOM | expand

Commit Message

Marek Vasut March 12, 2024, 9:15 p.m. UTC
Check whether the ethernet interface is enabled at all before reading
MAC EEPROM. As a cost saving measure, it can happen that the MAC EEPROM
is not populated on SoMs which do not use ethernet.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "NXP i.MX U-Boot Team" <uboot-imx@nxp.com>
Cc: Andreas Geisreiter <ageisreiter@dh-electronics.de>
Cc: Christoph Niedermaier <cniedermaier@dh-electronics.com>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: u-boot@dh-electronics.com
Cc: u-boot@lists.denx.de
Cc: uboot-stm32@st-md-mailman.stormreply.com
---
NOTE: It is probably best if this goes in via either imx or stm32 tree,
      I can break the patch up, but that would introduce dependency
      between two PRs in different trees. Let me know what you prefer.
---
 board/dhelectronics/common/dh_common.c           | 16 ++++++++++++++++
 board/dhelectronics/common/dh_common.h           |  8 ++++++++
 board/dhelectronics/dh_imx6/dh_imx6.c            |  3 +++
 .../dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c  |  6 ++++++
 board/dhelectronics/dh_stm32mp1/board.c          |  6 ++++++
 5 files changed, 39 insertions(+)

Comments

Fabio Estevam March 13, 2024, 12:52 a.m. UTC | #1
Hi Marek,

On Tue, Mar 12, 2024 at 6:16 PM Marek Vasut <marex@denx.de> wrote:

> NOTE: It is probably best if this goes in via either imx or stm32 tree,
>       I can break the patch up, but that would introduce dependency
>       between two PRs in different trees. Let me know what you prefer.

I can apply it to u-boot-imx next if Patrice and Patrick are OK.
Patrice CHOTARD April 5, 2024, 7:35 a.m. UTC | #2
On 3/13/24 01:52, Fabio Estevam wrote:
> Hi Marek,
> 
> On Tue, Mar 12, 2024 at 6:16 PM Marek Vasut <marex@denx.de> wrote:
> 
>> NOTE: It is probably best if this goes in via either imx or stm32 tree,
>>       I can break the patch up, but that would introduce dependency
>>       between two PRs in different trees. Let me know what you prefer.
> 

Hi Marek, Fabio

Sorry for the delay.

> I can apply it to u-boot-imx next if Patrice and Patrick are OK.

yes, you can apply it directly through u-boot-imx next.

Thanks
Patrice
Patrice CHOTARD April 5, 2024, 7:35 a.m. UTC | #3
On 3/12/24 22:15, Marek Vasut wrote:
> Check whether the ethernet interface is enabled at all before reading
> MAC EEPROM. As a cost saving measure, it can happen that the MAC EEPROM
> is not populated on SoMs which do not use ethernet.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> ---
> Cc: "NXP i.MX U-Boot Team" <uboot-imx@nxp.com>
> Cc: Andreas Geisreiter <ageisreiter@dh-electronics.de>
> Cc: Christoph Niedermaier <cniedermaier@dh-electronics.com>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Patrice Chotard <patrice.chotard@foss.st.com>
> Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: u-boot@dh-electronics.com
> Cc: u-boot@lists.denx.de
> Cc: uboot-stm32@st-md-mailman.stormreply.com
> ---
> NOTE: It is probably best if this goes in via either imx or stm32 tree,
>       I can break the patch up, but that would introduce dependency
>       between two PRs in different trees. Let me know what you prefer.
> ---
>  board/dhelectronics/common/dh_common.c           | 16 ++++++++++++++++
>  board/dhelectronics/common/dh_common.h           |  8 ++++++++
>  board/dhelectronics/dh_imx6/dh_imx6.c            |  3 +++
>  .../dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c  |  6 ++++++
>  board/dhelectronics/dh_stm32mp1/board.c          |  6 ++++++
>  5 files changed, 39 insertions(+)
> 
> diff --git a/board/dhelectronics/common/dh_common.c b/board/dhelectronics/common/dh_common.c
> index 67e3d59b1f3..34094a020b0 100644
> --- a/board/dhelectronics/common/dh_common.c
> +++ b/board/dhelectronics/common/dh_common.c
> @@ -18,6 +18,19 @@ bool dh_mac_is_in_env(const char *env)
>  	return eth_env_get_enetaddr(env, enetaddr);
>  }
>  
> +int dh_get_mac_is_enabled(const char *alias)
> +{
> +	ofnode node = ofnode_path(alias);
> +
> +	if (!ofnode_valid(node))
> +		return -EINVAL;
> +
> +	if (!ofnode_is_enabled(node))
> +		return -ENODEV;
> +
> +	return 0;
> +}
> +
>  int dh_get_mac_from_eeprom(unsigned char *enetaddr, const char *alias)
>  {
>  	struct udevice *dev;
> @@ -57,6 +70,9 @@ __weak int dh_setup_mac_address(void)
>  	if (dh_mac_is_in_env("ethaddr"))
>  		return 0;
>  
> +	if (dh_get_mac_is_enabled("ethernet0"))
> +		return 0;
> +
>  	if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
>  		return eth_env_set_enetaddr("ethaddr", enetaddr);
>  
> diff --git a/board/dhelectronics/common/dh_common.h b/board/dhelectronics/common/dh_common.h
> index 2b24637d96d..a2de5b1553e 100644
> --- a/board/dhelectronics/common/dh_common.h
> +++ b/board/dhelectronics/common/dh_common.h
> @@ -11,6 +11,14 @@
>   */
>  bool dh_mac_is_in_env(const char *env);
>  
> +/*
> + * dh_get_mac_is_enabled - Test if ethernet MAC is enabled in DT
> + *
> + * @alias: alias for ethernet MAC device tree node
> + * Return: 0 if OK, other value on error
> + */
> +int dh_get_mac_is_enabled(const char *alias);
> +
>  /*
>   * dh_get_mac_from_eeprom - Get MAC address from eeprom and write it to enetaddr
>   *
> diff --git a/board/dhelectronics/dh_imx6/dh_imx6.c b/board/dhelectronics/dh_imx6/dh_imx6.c
> index 07fc9b1fe6d..0676587c38a 100644
> --- a/board/dhelectronics/dh_imx6/dh_imx6.c
> +++ b/board/dhelectronics/dh_imx6/dh_imx6.c
> @@ -92,6 +92,9 @@ int dh_setup_mac_address(void)
>  	if (dh_mac_is_in_env("ethaddr"))
>  		return 0;
>  
> +	if (dh_get_mac_is_enabled("ethernet0"))
> +		return 0;
> +
>  	if (!dh_imx_get_mac_from_fuse(enetaddr))
>  		goto out;
>  
> diff --git a/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c b/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
> index 5f12d787d38..ff2c0e87215 100644
> --- a/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
> +++ b/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
> @@ -47,6 +47,9 @@ static int dh_imx8_setup_ethaddr(void)
>  	if (dh_mac_is_in_env("ethaddr"))
>  		return 0;
>  
> +	if (dh_get_mac_is_enabled("ethernet0"))
> +		return 0;
> +
>  	if (!dh_imx_get_mac_from_fuse(enetaddr))
>  		goto out;
>  
> @@ -66,6 +69,9 @@ static int dh_imx8_setup_eth1addr(void)
>  	if (dh_mac_is_in_env("eth1addr"))
>  		return 0;
>  
> +	if (dh_get_mac_is_enabled("ethernet1"))
> +		return 0;
> +
>  	if (!dh_imx_get_mac_from_fuse(enetaddr))
>  		goto increment_out;
>  
> diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c
> index 88eb7d1b8d4..b3309c9d330 100644
> --- a/board/dhelectronics/dh_stm32mp1/board.c
> +++ b/board/dhelectronics/dh_stm32mp1/board.c
> @@ -129,6 +129,9 @@ static int dh_stm32_setup_ethaddr(void)
>  	if (dh_mac_is_in_env("ethaddr"))
>  		return 0;
>  
> +	if (dh_get_mac_is_enabled("ethernet0"))
> +		return 0;
> +
>  	if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
>  		return eth_env_set_enetaddr("ethaddr", enetaddr);
>  
> @@ -142,6 +145,9 @@ static int dh_stm32_setup_eth1addr(void)
>  	if (dh_mac_is_in_env("eth1addr"))
>  		return 0;
>  
> +	if (dh_get_mac_is_enabled("ethernet1"))
> +		return 0;
> +
>  	if (dh_stm32_mac_is_in_ks8851())
>  		return 0;
>  
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
Fabio Estevam April 5, 2024, 4:46 p.m. UTC | #4
On Tue, Mar 12, 2024 at 6:16 PM Marek Vasut <marex@denx.de> wrote:
>
> Check whether the ethernet interface is enabled at all before reading
> MAC EEPROM. As a cost saving measure, it can happen that the MAC EEPROM
> is not populated on SoMs which do not use ethernet.
>
> Signed-off-by: Marek Vasut <marex@denx.de>

Applied, thanks.
diff mbox series

Patch

diff --git a/board/dhelectronics/common/dh_common.c b/board/dhelectronics/common/dh_common.c
index 67e3d59b1f3..34094a020b0 100644
--- a/board/dhelectronics/common/dh_common.c
+++ b/board/dhelectronics/common/dh_common.c
@@ -18,6 +18,19 @@  bool dh_mac_is_in_env(const char *env)
 	return eth_env_get_enetaddr(env, enetaddr);
 }
 
+int dh_get_mac_is_enabled(const char *alias)
+{
+	ofnode node = ofnode_path(alias);
+
+	if (!ofnode_valid(node))
+		return -EINVAL;
+
+	if (!ofnode_is_enabled(node))
+		return -ENODEV;
+
+	return 0;
+}
+
 int dh_get_mac_from_eeprom(unsigned char *enetaddr, const char *alias)
 {
 	struct udevice *dev;
@@ -57,6 +70,9 @@  __weak int dh_setup_mac_address(void)
 	if (dh_mac_is_in_env("ethaddr"))
 		return 0;
 
+	if (dh_get_mac_is_enabled("ethernet0"))
+		return 0;
+
 	if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
 		return eth_env_set_enetaddr("ethaddr", enetaddr);
 
diff --git a/board/dhelectronics/common/dh_common.h b/board/dhelectronics/common/dh_common.h
index 2b24637d96d..a2de5b1553e 100644
--- a/board/dhelectronics/common/dh_common.h
+++ b/board/dhelectronics/common/dh_common.h
@@ -11,6 +11,14 @@ 
  */
 bool dh_mac_is_in_env(const char *env);
 
+/*
+ * dh_get_mac_is_enabled - Test if ethernet MAC is enabled in DT
+ *
+ * @alias: alias for ethernet MAC device tree node
+ * Return: 0 if OK, other value on error
+ */
+int dh_get_mac_is_enabled(const char *alias);
+
 /*
  * dh_get_mac_from_eeprom - Get MAC address from eeprom and write it to enetaddr
  *
diff --git a/board/dhelectronics/dh_imx6/dh_imx6.c b/board/dhelectronics/dh_imx6/dh_imx6.c
index 07fc9b1fe6d..0676587c38a 100644
--- a/board/dhelectronics/dh_imx6/dh_imx6.c
+++ b/board/dhelectronics/dh_imx6/dh_imx6.c
@@ -92,6 +92,9 @@  int dh_setup_mac_address(void)
 	if (dh_mac_is_in_env("ethaddr"))
 		return 0;
 
+	if (dh_get_mac_is_enabled("ethernet0"))
+		return 0;
+
 	if (!dh_imx_get_mac_from_fuse(enetaddr))
 		goto out;
 
diff --git a/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c b/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
index 5f12d787d38..ff2c0e87215 100644
--- a/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
+++ b/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
@@ -47,6 +47,9 @@  static int dh_imx8_setup_ethaddr(void)
 	if (dh_mac_is_in_env("ethaddr"))
 		return 0;
 
+	if (dh_get_mac_is_enabled("ethernet0"))
+		return 0;
+
 	if (!dh_imx_get_mac_from_fuse(enetaddr))
 		goto out;
 
@@ -66,6 +69,9 @@  static int dh_imx8_setup_eth1addr(void)
 	if (dh_mac_is_in_env("eth1addr"))
 		return 0;
 
+	if (dh_get_mac_is_enabled("ethernet1"))
+		return 0;
+
 	if (!dh_imx_get_mac_from_fuse(enetaddr))
 		goto increment_out;
 
diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c
index 88eb7d1b8d4..b3309c9d330 100644
--- a/board/dhelectronics/dh_stm32mp1/board.c
+++ b/board/dhelectronics/dh_stm32mp1/board.c
@@ -129,6 +129,9 @@  static int dh_stm32_setup_ethaddr(void)
 	if (dh_mac_is_in_env("ethaddr"))
 		return 0;
 
+	if (dh_get_mac_is_enabled("ethernet0"))
+		return 0;
+
 	if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
 		return eth_env_set_enetaddr("ethaddr", enetaddr);
 
@@ -142,6 +145,9 @@  static int dh_stm32_setup_eth1addr(void)
 	if (dh_mac_is_in_env("eth1addr"))
 		return 0;
 
+	if (dh_get_mac_is_enabled("ethernet1"))
+		return 0;
+
 	if (dh_stm32_mac_is_in_ks8851())
 		return 0;