All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
To: "dev@pschenker.ch" <dev@pschenker.ch>,
	"u-boot@lists.denx.de" <u-boot@lists.denx.de>
Cc: Philippe Schenker <philippe.schenker@toradex.com>,
	"sjg@chromium.org" <sjg@chromium.org>,
	"stefan.agner@toradex.com" <stefan.agner@toradex.com>,
	Francesco Dolcini <francesco.dolcini@toradex.com>,
	"oleksandr.suvorov@toradex.com" <oleksandr.suvorov@toradex.com>,
	Denys Drozdov <denys.drozdov@toradex.com>
Subject: Re: [PATCH] toradex: tdx-cfg-block: add new toradex oui range
Date: Fri, 1 Jul 2022 05:19:47 +0000	[thread overview]
Message-ID: <0de2ada34b9e7cc381f4e978ea5cab8a323895c3.camel@toradex.com> (raw)
In-Reply-To: <20220620145745.162331-1-dev@pschenker.ch>

On Mon, 2022-06-20 at 16:57 +0200, Philippe Schenker wrote:
> From: Philippe Schenker <philippe.schenker@toradex.com>
> 
> Add new Toradex MAC OUI (8c:06:cb), to the config block. With this change
> we extend the possible serial-numbers as follows:
> 
> For serial-numbers 00000000-16777215 OUI 00:14:2d is taken
> For serial-numbers 16777216-33554431 OUI 8c:06:cb is taken
> 
> Lower 24-bit of the serial number are used in the NIC part of the
> MAC address, the complete serial number can be calculated using the OUI.
> 
> Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
> Reviewed-by: Francesco Dolcini <francesco.dolcini@toradex.com>

Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>

> ---
> 
>  board/toradex/common/tdx-cfg-block.c | 42 +++++++++++++++++++++++++---
>  board/toradex/common/tdx-cfg-block.h |  2 ++
>  board/toradex/common/tdx-common.c    |  5 +---
>  3 files changed, 41 insertions(+), 8 deletions(-)
> 
> diff --git a/board/toradex/common/tdx-cfg-block.c b/board/toradex/common/tdx-cfg-block.c
> index 6c8cf4592d..053c03ddf2 100644
> --- a/board/toradex/common/tdx-cfg-block.c
> +++ b/board/toradex/common/tdx-cfg-block.c
> @@ -159,6 +159,42 @@ const char * const toradex_display_adapters[] = {
>         [159] = "Verdin DSI to LVDS Adapter",
>  };
>  
> +const u32 toradex_ouis[] = {
> +       [0] = 0x00142dUL,
> +       [1] = 0x8c06cbUL,
> +};
> +
> +static u32 get_serial_from_mac(struct toradex_eth_addr *eth_addr)
> +{
> +       int i;
> +       u32 oui = ntohl(eth_addr->oui) >> 8;
> +       u32 nic = ntohl(eth_addr->nic) >> 8;
> +
> +       for (i = 0; i < ARRAY_SIZE(toradex_ouis); i++) {
> +               if (toradex_ouis[i] == oui)
> +                       break;
> +       }
> +
> +       return (u32)((i << 24) + nic);
> +}
> +
> +void get_mac_from_serial(u32 tdx_serial, struct toradex_eth_addr *eth_addr)
> +{
> +       u8 oui_index = tdx_serial >> 24;
> +       u32 nic = tdx_serial & GENMASK(23, 0);
> +       u32 oui;
> +
> +       if (oui_index >= ARRAY_SIZE(toradex_ouis)) {
> +               puts("Can't find OUI for this serial#\n");
> +               oui_index = 0;
> +       }
> +
> +       oui = toradex_ouis[oui_index];
> +
> +       eth_addr->oui = htonl(oui << 8);
> +       eth_addr->nic = htonl(nic << 8);
> +}
> +
>  #ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_MMC
>  static int tdx_cfg_block_mmc_storage(u8 *config_block, int write)
>  {
> @@ -331,8 +367,7 @@ int read_tdx_cfg_block(void)
>                                 memcpy(&tdx_eth_addr, config_block + offset,
>                                        6);
>  
> -                               /* NIC part of MAC address is serial number */
> -                               tdx_serial = ntohl(tdx_eth_addr.nic) >> 8;
> +                               tdx_serial = get_serial_from_mac(&tdx_eth_addr);
>                                 break;
>                         case TAG_HW:
>                                 memcpy(&tdx_hw_tag, config_block + offset, 8);
> @@ -950,8 +985,7 @@ static int do_cfgblock_create(struct cmd_tbl *cmdtp, int flag, int argc,
>         }
>  
>         /* Convert serial number to MAC address (the storage format) */
> -       tdx_eth_addr.oui = htonl(0x00142dUL << 8);
> -       tdx_eth_addr.nic = htonl(tdx_serial << 8);
> +       get_mac_from_serial(tdx_serial, &tdx_eth_addr);
>  
>         /* Valid Tag */
>         write_tag(config_block, &offset, TAG_VALID, NULL, 0);
> diff --git a/board/toradex/common/tdx-cfg-block.h b/board/toradex/common/tdx-cfg-block.h
> index 43e662e41d..1790698486 100644
> --- a/board/toradex/common/tdx-cfg-block.h
> +++ b/board/toradex/common/tdx-cfg-block.h
> @@ -114,4 +114,6 @@ int read_tdx_cfg_block_carrier(void);
>  
>  int try_migrate_tdx_cfg_block_carrier(void);
>  
> +void get_mac_from_serial(u32 tdx_serial, struct toradex_eth_addr *eth_addr);
> +
>  #endif /* _TDX_CFG_BLOCK_H */
> diff --git a/board/toradex/common/tdx-common.c b/board/toradex/common/tdx-common.c
> index 9db4553e0f..211d3c35e0 100644
> --- a/board/toradex/common/tdx-common.c
> +++ b/board/toradex/common/tdx-common.c
> @@ -20,8 +20,6 @@
>  #include <asm/setup.h>
>  #include "tdx-common.h"
>  
> -#define TORADEX_OUI 0x00142dUL
> -
>  #ifdef CONFIG_TDX_CFG_BLOCK
>  static char tdx_serial_str[9];
>  static char tdx_board_rev_str[6];
> @@ -85,8 +83,7 @@ int show_board_info(void)
>  
>         if (read_tdx_cfg_block()) {
>                 printf("MISSING TORADEX CONFIG BLOCK\n");
> -               tdx_eth_addr.oui = htonl(TORADEX_OUI << 8);
> -               tdx_eth_addr.nic = htonl(tdx_serial << 8);
> +               get_mac_from_serial(tdx_serial, &tdx_eth_addr);
>                 checkboard();
>         } else {
>                 sprintf(tdx_serial_str, "%08u", tdx_serial);

  parent reply	other threads:[~2022-07-01  5:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 14:57 [PATCH] toradex: tdx-cfg-block: add new toradex oui range Philippe Schenker
2022-06-20 19:11 ` Fabio Estevam
2022-07-01  5:19 ` Marcel Ziswiler [this message]
2022-07-07  1:56 ` Tom Rini

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=0de2ada34b9e7cc381f4e978ea5cab8a323895c3.camel@toradex.com \
    --to=marcel.ziswiler@toradex.com \
    --cc=denys.drozdov@toradex.com \
    --cc=dev@pschenker.ch \
    --cc=francesco.dolcini@toradex.com \
    --cc=oleksandr.suvorov@toradex.com \
    --cc=philippe.schenker@toradex.com \
    --cc=sjg@chromium.org \
    --cc=stefan.agner@toradex.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.