[PATCH 1/4] net: add ethaddr sequence handling
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Nov 27 23:30:21 PST 2024
On 28.11.24 08:28, Sascha Hauer wrote:
> 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, ð_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.
Fair enough. The patch predates the introduction of eth_addr_inc.
Please drop this one patch.
Thanks,
Ahmad
>
> Sascha
>
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum at 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 |
More information about the barebox
mailing list