From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/4] net: add ethaddr sequence handling
Date: Tue, 26 Nov 2024 16:17:41 +0100 [thread overview]
Message-ID: <20241126151744.3621717-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241126151744.3621717-1-a.fatoum@pengutronix.de>
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, ð_count)
eth_register_ethaddr(i++, eth_addr);
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
next prev parent reply other threads:[~2024-11-26 15:18 UTC|newest]
Thread overview: 5+ 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 ` Ahmad Fatoum [this message]
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
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=20241126151744.3621717-2-a.fatoum@pengutronix.de \
--to=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