mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: Sascha Hauer <sha@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] of: of_net: add support to parse ASCII encoded mac-addresses
Date: Tue, 8 Aug 2023 09:58:26 +0200	[thread overview]
Message-ID: <20230808075826.jried4ke6rbv4mjy@pengutronix.de> (raw)
In-Reply-To: <20230808055121.GP26314@pengutronix.de>

Hi Sascha,

On 23-08-08, Sascha Hauer wrote:
> On Mon, Aug 07, 2023 at 07:07:43PM +0200, Marco Felsch wrote:
> > Some vendors like Polyhex store the MAC address ASCII encoded instead of
> > using the plain 6-byte MAC address. This commit adds the support to
> > decode the 12-byte ASCII encoded MAC addresses.
> 
> The upstream i.MX8MP dtsi files have "mac-address" nvmem cells described
> in the device trees, but they point to a 6-byte long cell in ocotp.
> These cells are not overwritten in the Polyhex dts files. How can there
> be a 12-byte ASCII stored?

Please have a look at:

https://lore.kernel.org/all/20230807171513.156907-4-m.felsch@pengutronix.de/

and search for ethmac{1,2}. Once the devicetree is upstream I will sync
our internal -upstream variant.

> > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > ---
> >  drivers/of/of_net.c | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> > 
> > diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
> > index 75a24073da51..4e74986cdda8 100644
> > --- a/drivers/of/of_net.c
> > +++ b/drivers/of/of_net.c
> > @@ -79,6 +79,8 @@ static int of_get_mac_addr(struct device_node *np, const char *name, u8 *addr)
> >  	return -ENODEV;
> >  }
> >  
> > +#define ETH_ALEN_ASCII	12
> > +
> >  int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
> >  {
> >  	struct nvmem_cell *cell;
> > @@ -98,6 +100,23 @@ int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
> >  	if (IS_ERR(mac))
> >  		return PTR_ERR(mac);
> >  
> > +	if (len == ETH_ALEN_ASCII) {
> 
> I don't like this heuristic very much. If I understand the nvmem stuff
> correctly then parsing of properties in non standard formats should be
> fixed in a struct nvmem_cell_info::read_post_process hook.

IMHO there is no standard to store MAC addresses, there is an easy way
(raw address stored in 6-bytes in some nvmem reachable from the host)
and a vendor-know-it-better way. While coding I was thinking about a
property to indicate that the mac-address is stored in ascii like:

&eeprom {
	macaddr1: mac-address@0 {
		reg = <0 0xc>;
		barebox,ascii-mac-address;
	}
}

Then I thought, if someone stores the mac-address in a 12-byte field
this have to be an ascii encoded mac-address and I dropped the
barebox,ascii-mac-address property.

> > +		u8 *mac_new;
> > +		int ret;
> > +
> > +		mac_new = kzalloc(sizeof("xx:xx:xx:xx:xx:xx"), GFP_KERNEL);
> 
> If anything, then sizeof("xxxxxxxxxxxx"), but what you want here is
> ETH_ALEN.

You're right. Thanks.

Regards,
  Marco



  reply	other threads:[~2023-08-08  7:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07 17:07 Marco Felsch
2023-08-08  5:51 ` Sascha Hauer
2023-08-08  7:58   ` Marco Felsch [this message]
2023-08-08  9:36 ` Ahmad Fatoum
2023-08-08  9:46   ` Marco Felsch
2023-08-08 10:23     ` Ahmad Fatoum
2023-08-08 16:20       ` Marco Felsch

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=20230808075826.jried4ke6rbv4mjy@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=sha@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox