All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrice CHOTARD <patrice.chotard@foss.st.com>
To: Patrick Delaunay <patrick.delaunay@foss.st.com>, <u-boot@lists.denx.de>
Cc: Tom Rini <trini@konsulko.com>,
	U-Boot STM32 <uboot-stm32@st-md-mailman.stormreply.com>
Subject: Re: [PATCH 09/16] arm: stm32mp: support 2 MAC address for STM32MP13
Date: Fri, 20 May 2022 08:55:14 +0200	[thread overview]
Message-ID: <368493a0-ec29-7d0a-ef33-9a6fba4b9823@foss.st.com> (raw)
In-Reply-To: <20220506160540.9.I202fcb973ba156e8df0d37ac7befbca1916e72af@changeid>

Hi Patrick

On 5/6/22 16:06, Patrick Delaunay wrote:
> Add support of several MAC address in OTP (3 32bits OTP word for
> 2 MAC address) for SOCs in  STM32MP13x family: STM32MP133 and STM32MP135.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  arch/arm/mach-stm32mp/cpu.c                   | 41 ++++++++++++-------
>  .../arm/mach-stm32mp/include/mach/sys_proto.h |  1 +
>  arch/arm/mach-stm32mp/stm32mp13x.c            | 20 +++++++++
>  arch/arm/mach-stm32mp/stm32mp15x.c            |  5 +++
>  4 files changed, 52 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
> index 240960ada4..855fc755fe 100644
> --- a/arch/arm/mach-stm32mp/cpu.c
> +++ b/arch/arm/mach-stm32mp/cpu.c
> @@ -290,16 +290,18 @@ __weak int setup_mac_address(void)
>  {
>  	int ret;
>  	int i;
> -	u32 otp[2];
> +	u32 otp[3];
>  	uchar enetaddr[6];
>  	struct udevice *dev;
> +	int nb_eth, nb_otp, index;
>  
>  	if (!IS_ENABLED(CONFIG_NET))
>  		return 0;
>  
> -	/* MAC already in environment */
> -	if (eth_env_get_enetaddr("ethaddr", enetaddr))
> -		return 0;
> +	nb_eth = get_eth_nb();
> +
> +	/* 6 bytes for each MAC addr and 4 bytes for each OTP */
> +	nb_otp = DIV_ROUND_UP(6 * nb_eth, 4);
>  
>  	ret = uclass_get_device_by_driver(UCLASS_MISC,
>  					  DM_DRIVER_GET(stm32mp_bsec),
> @@ -307,22 +309,31 @@ __weak int setup_mac_address(void)
>  	if (ret)
>  		return ret;
>  
> -	ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC),
> -			otp, sizeof(otp));
> +	ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC), otp, 4 * nb_otp);
>  	if (ret < 0)
>  		return ret;
>  
> -	for (i = 0; i < 6; i++)
> -		enetaddr[i] = ((uint8_t *)&otp)[i];
> +	for (index = 0; index < nb_eth; index++) {
> +		/* MAC already in environment */
> +		if (eth_env_get_enetaddr_by_index("eth", index, enetaddr))
> +			continue;
> +
> +		for (i = 0; i < 6; i++)
> +			enetaddr[i] = ((uint8_t *)&otp)[i + 6 * index];
>  
> -	if (!is_valid_ethaddr(enetaddr)) {
> -		log_err("invalid MAC address in OTP %pM\n", enetaddr);
> -		return -EINVAL;
> +		if (!is_valid_ethaddr(enetaddr)) {
> +			log_err("invalid MAC address %d in OTP %pM\n",
> +				index, enetaddr);
> +			return -EINVAL;
> +		}
> +		log_debug("OTP MAC address %d = %pM\n", index, enetaddr);
> +		ret = eth_env_set_enetaddr_by_index("eth", index, enetaddr);
> +		if (ret) {
> +			log_err("Failed to set mac address %pM from OTP: %d\n",
> +				enetaddr, ret);
> +			return ret;
> +		}
>  	}
> -	log_debug("OTP MAC address = %pM\n", enetaddr);
> -	ret = eth_env_set_enetaddr("ethaddr", enetaddr);
> -	if (ret)
> -		log_err("Failed to set mac address %pM from OTP: %d\n", enetaddr, ret);
>  
>  	return 0;
>  }
> diff --git a/arch/arm/mach-stm32mp/include/mach/sys_proto.h b/arch/arm/mach-stm32mp/include/mach/sys_proto.h
> index 829b3feebf..4b564e86dc 100644
> --- a/arch/arm/mach-stm32mp/include/mach/sys_proto.h
> +++ b/arch/arm/mach-stm32mp/include/mach/sys_proto.h
> @@ -64,6 +64,7 @@ void get_soc_name(char name[SOC_NAME_SIZE]);
>  /* return boot mode */
>  u32 get_bootmode(void);
>  
> +int get_eth_nb(void);
>  int setup_mac_address(void);
>  
>  /* board power management : configure vddcore according OPP */
> diff --git a/arch/arm/mach-stm32mp/stm32mp13x.c b/arch/arm/mach-stm32mp/stm32mp13x.c
> index 38961310dc..8a56f381ce 100644
> --- a/arch/arm/mach-stm32mp/stm32mp13x.c
> +++ b/arch/arm/mach-stm32mp/stm32mp13x.c
> @@ -51,6 +51,26 @@ u32 get_cpu_type(void)
>  	return (get_cpu_dev() << 16) | get_cpu_rpn();
>  }
>  
> +int get_eth_nb(void)
> +{
> +	int nb_eth = 2;
> +
> +	switch (get_cpu_type()) {
> +	case CPU_STM32MP131Dxx:
> +		fallthrough;
> +	case CPU_STM32MP131Cxx:
> +		fallthrough;
> +	case CPU_STM32MP131Axx:
> +		nb_eth = 1;
> +		break;
> +	default:
> +		nb_eth = 2;
> +		break;
> +	}
> +
> +	return nb_eth;
> +}
> +
>  void get_soc_name(char name[SOC_NAME_SIZE])
>  {
>  	char *cpu_s, *cpu_r;
> diff --git a/arch/arm/mach-stm32mp/stm32mp15x.c b/arch/arm/mach-stm32mp/stm32mp15x.c
> index 800fad2f43..a093e6163e 100644
> --- a/arch/arm/mach-stm32mp/stm32mp15x.c
> +++ b/arch/arm/mach-stm32mp/stm32mp15x.c
> @@ -247,6 +247,11 @@ u32 get_cpu_type(void)
>  	return (get_cpu_dev() << 16) | get_cpu_rpn();
>  }
>  
> +int get_eth_nb(void)
> +{
> +	return 1;
> +}
> +
>  /* Get Package options from OTP */
>  u32 get_cpu_package(void)
>  {

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

  reply	other threads:[~2022-05-20  6:55 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06 14:06 [PATCH 00/16] stm32mp: add STM32MP13x support Patrick Delaunay
2022-05-06 14:06 ` [PATCH 01/16] ARM: dts: stm32: add STM32MP13 SoCs support Patrick Delaunay
2022-05-20  6:31   ` Patrice CHOTARD
2022-06-17  8:47   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 02/16] configs: stm32mp1: move SUPPORT_SPL in STM32MP15x Patrick Delaunay
2022-05-20  6:32   ` Patrice CHOTARD
2022-06-17  8:47   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 03/16] arm: stm32mp: move the get_otp helper function in bsec Patrick Delaunay
2022-05-20  6:32   ` Patrice CHOTARD
2022-06-17  8:47   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 04/16] arm: stm32mp: move code for STM32MP15x Patrick Delaunay
2022-05-20  6:32   ` Patrice CHOTARD
2022-06-17  8:48   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 05/16] arm: stm32mp: add choice for STM32MP SOC family Patrick Delaunay
2022-05-20  6:37   ` Patrice CHOTARD
2022-06-17  8:48   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 06/16] arm: stm32mp: add sub config Kconfig.15x Patrick Delaunay
2022-05-20  6:39   ` Patrice CHOTARD
2022-06-17  8:49   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 07/16] arm: stm32mp: add CONFIG_STM32MP15_PWR Patrick Delaunay
2022-05-20  6:41   ` Patrice CHOTARD
2022-06-17  8:49   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 08/16] arm: stm32mp: add support of STM32MP13x Patrick Delaunay
2022-05-20  6:49   ` Patrice CHOTARD
2022-05-20  7:24     ` [Uboot-stm32] " Patrice CHOTARD
2022-05-20  7:44       ` Marek Vasut
2022-06-17  8:57   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 09/16] arm: stm32mp: support 2 MAC address for STM32MP13 Patrick Delaunay
2022-05-20  6:55   ` Patrice CHOTARD [this message]
2022-06-17  8:57   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 10/16] pinctrl: stm32: add support of STM32MP135 Patrick Delaunay
2022-05-20  6:55   ` Patrice CHOTARD
2022-05-20  6:57   ` Patrice CHOTARD
2022-06-17  8:57   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 11/16] board: stm32pm1: add stm32mp13 board support Patrick Delaunay
2022-05-20  7:02   ` Patrice CHOTARD
2022-05-20 15:33     ` Patrick DELAUNAY
2022-06-17  9:00   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 12/16] ram: stm32mp1: add support of STM32MP13x Patrick Delaunay
2022-05-20  7:09   ` Patrice CHOTARD
2022-06-17  9:01   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 13/16] mmc: stm32_sdmmc2: make reset property optional Patrick Delaunay
2022-05-16 23:34   ` Jaehoon Chung
2022-05-20  7:10   ` Patrice CHOTARD
2022-06-17  9:01   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 14/16] arm: dts: stm32mp: add stm32mp13 device tree for U-Boot Patrick Delaunay
2022-05-20  7:10   ` Patrice CHOTARD
2022-06-17  9:01   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 15/16] configs: add stm32mp13 defconfig Patrick Delaunay
2022-05-20  7:10   ` Patrice CHOTARD
2022-06-17  9:04   ` Patrick DELAUNAY
2022-05-06 14:06 ` [PATCH 16/16] doc: st: stm32mp1: add STM32MP13x support Patrick Delaunay
2022-05-20  7:21   ` Patrice CHOTARD
2022-05-20 16:13     ` Patrick DELAUNAY
2022-06-17  9:05   ` Patrick DELAUNAY

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=368493a0-ec29-7d0a-ef33-9a6fba4b9823@foss.st.com \
    --to=patrice.chotard@foss.st.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-stm32@st-md-mailman.stormreply.com \
    /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.