mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/4] net: add ethaddr sequence handling
Date: Thu, 28 Nov 2024 08:28:37 +0100	[thread overview]
Message-ID: <Z0gbpZog23pPY-UA@pengutronix.de> (raw)
In-Reply-To: <20241126151744.3621717-2-a.fatoum@pengutronix.de>

On Tue, Nov 26, 2024 at 04:17:41PM +0100, Ahmad Fatoum wrote:
> Instead of storing every MAC address in full, boards may elect
> to store a base address and increment it N times. Add a helper
> to iterate over such an Ethernet address sequence. Example usage:
> 
>   const u8 *eth_addr;
>   u8 eth_base[ETH_ALEN] = "\x00\x01\x02\x03\x04\x05";
>   int i = 0, eth_count = 4;
> 
>   for_each_seq_ethaddr(eth_addr, eth_base, &eth_count)
>           eth_register_ethaddr(i++, eth_addr);

	for (i = 0; i < 4; i++, eth_addr_inc(eth_addr))
		eth_register_ethaddr(i, eth_addr);

I think the open coded variant is easier to read and write, I don't
think we should introduce a helper for this.

Sascha

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  include/net.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/include/net.h b/include/net.h
> index a04ed5b0ab92..1b6995b50043 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -516,6 +516,18 @@ static inline void eth_addr_add(u8 *addr, long offset)
>  	u64_to_ether_addr(u, addr);
>  }
>  
> +#define for_each_seq_ethaddr(eth_addr, eth_base, eth_count) \
> +	for (eth_addr = *eth_count ? eth_base : NULL; eth_addr; eth_addr = eth_addr_seq_next(eth_base, eth_count))
> +
> +static inline const u8 *eth_addr_seq_next(u8 eth_base[6], unsigned *eth_count)
> +{
> +	if (--(*eth_count) <= 0)
> +		return NULL;
> +
> +	eth_addr_inc(eth_base);
> +	return eth_base;
> +}
> +
>  typedef void rx_handler_f(void *ctx, char *packet, unsigned int len);
>  
>  struct eth_device *eth_get_byname(const char *name);
> -- 
> 2.39.5
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2024-11-28  7:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-26 15:17 [PATCH 0/4] net: ethernet address helpers for board code Ahmad Fatoum
2024-11-26 15:17 ` [PATCH 1/4] net: add ethaddr sequence handling Ahmad Fatoum
2024-11-28  7:28   ` Sascha Hauer [this message]
2024-11-28  7:30     ` Ahmad Fatoum
2024-11-26 15:17 ` [PATCH 2/4] net: factor out eth_of_get_fixup_node Ahmad Fatoum
2024-11-26 15:17 ` [PATCH 3/4] net: export list of registered ethernet addresses Ahmad Fatoum
2024-11-26 15:17 ` [PATCH 4/4] net: implement ethaddr_string_cmp() Ahmad Fatoum
2024-11-28  7:36   ` Sascha Hauer
2024-11-28  7:43     ` Ahmad Fatoum
2024-11-28  7:52       ` Sascha Hauer
2024-11-28  8:00         ` Ahmad Fatoum

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=Z0gbpZog23pPY-UA@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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