[RFC net-next 1/6] ethernet: add a helper for assigning port addresses
Shannon Nelson
snelson at pensando.io
Fri Oct 15 14:36:00 PDT 2021
On 10/15/21 12:38 PM, Jakub Kicinski wrote:
> We have 5 drivers which offset base MAC addr by port id.
> Create a helper for them.
>
> This helper takes care of overflows, which some drivers
> did not do, please complain if that's going to break
> anything!
>
> Signed-off-by: Jakub Kicinski <kuba at kernel.org>
> ---
> CC: jiri at nvidia.com
> CC: idosch at nvidia.com
> CC: lars.povlsen at microchip.com
> CC: Steen.Hegelund at microchip.com
> CC: UNGLinuxDriver at microchip.com
> CC: bjarni.jonasson at microchip.com
> CC: linux-arm-kernel at lists.infradead.org
> CC: qiangqing.zhang at nxp.com
> CC: vkochan at marvell.com
> CC: tchornyi at marvell.com
> CC: vladimir.oltean at nxp.com
> CC: claudiu.manoil at nxp.com
> CC: alexandre.belloni at bootlin.com
> CC: UNGLinuxDriver at microchip.com
> ---
> include/linux/etherdevice.h | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
> index 23681c3d3b8a..157f6c7ac9ff 100644
> --- a/include/linux/etherdevice.h
> +++ b/include/linux/etherdevice.h
> @@ -551,6 +551,27 @@ static inline unsigned long compare_ether_header(const void *a, const void *b)
> #endif
> }
>
> +/**
> + * 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)
To me, the words "_set_port" imply that you're going to force "id" into
the byte, overwriting what is already there. Since this instead is
adding "id" to the byte, perhaps a better name would include the word
"offset", maybe like eth_hw_addr_set_port_offset(), to better imply the
actual operation.
Personally, I think my name suggestion is too long, but it gets my
thought across.
sln
> +{
> + 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
More information about the linux-arm-kernel
mailing list