Commit e80094a4 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

ethernet: add a helper for assigning port addresses

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: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarShannon Nelson <snelson@pensando.io>
Reviewed-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 867a9284
...@@ -551,6 +551,27 @@ static inline unsigned long compare_ether_header(const void *a, const void *b) ...@@ -551,6 +551,27 @@ static inline unsigned long compare_ether_header(const void *a, const void *b)
#endif #endif
} }
/**
* eth_hw_addr_gen - 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
*
* Generate a MAC address using a base address and an offset and assign it
* to a net_device. 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_gen(struct net_device *dev, const u8 *base_addr,
unsigned int id)
{
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 * eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame
* @skb: Buffer to pad * @skb: Buffer to pad
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment