[RFC net-next 1/6] ethernet: add a helper for assigning port addresses
Ido Schimmel
idosch at idosch.org
Sun Oct 17 08:06:17 PDT 2021
On Fri, Oct 15, 2021 at 12:38:43PM -0700, Jakub Kicinski wrote:
> +/**
> + * eth_hw_addr_set_port - Generate and assign Ethernet address to a port
> + * @dev: pointer to port's net_device structure
> + * @base_addr: base Ethernet address
> + * @id: offset to add to the base address
> + *
> + * Assign a MAC address to the net_device using a base address and an offset.
> + * Commonly used by switch drivers which need to compute addresses for all
> + * their ports. addr_assign_type is not changed.
> + */
> +static inline void eth_hw_addr_set_port(struct net_device *dev,
> + const u8 *base_addr, u8 id)
If necessary, would it be possible to change 'id' to u16?
I'm asking because currently in mlxsw we set the MAC of each netdev to
'base_mac + local_port' where 'local_port' is u8. In Spectrum-4 we are
going to have more than 256 logical ports, so 'local_port' becomes u16.
Regarding the naming, eth_hw_addr_gen() sounds good to me.
Thanks for working on this
> +{
> + u64 u = ether_addr_to_u64(base_addr);
> + u8 addr[ETH_ALEN];
> +
> + u += id;
> + u64_to_ether_addr(u, addr);
> + eth_hw_addr_set(dev, addr);
> +}
> +
> /**
> * eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame
> * @skb: Buffer to pad
> --
> 2.31.1
>
More information about the linux-arm-kernel
mailing list