summaryrefslogtreecommitdiff
path: root/include/linux/etherdevice.h
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2021-10-19 14:46:25 +0300
committerDavid S. Miller <davem@davemloft.net>2021-10-19 14:46:25 +0300
commitf4e728ff9407757238eea953c449490d6d969fda (patch)
tree6245a606738a864d83b1175b7458d0a6dce61844 /include/linux/etherdevice.h
parent867a92846e2eee774a9a995793e3bb964676b33e (diff)
parent07a7ec9bdafee05d7f161a4a2159e94d4b6b3253 (diff)
downloadlinux-f4e728ff9407757238eea953c449490d6d969fda.tar.xz
Merge branch 'eth_hw_addr_gen-for-switches'
Jakub Kicinski says: ==================== ethernet: add eth_hw_addr_gen() for switches While doing the last polishing of the drivers/ethernet changes I realized we have a handful of drivers offsetting some base MAC addr by an id. So I decided to add a helper for it. The helper takes care of wrapping which is probably not 100% necessary but seems like a good idea. And it saves driver side LoC (the diffstat is actually negative if we compare against the changes I'd have to make if I was to convert all these drivers to not operate directly on netdev->dev_addr). ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/etherdevice.h')
-rw-r--r--include/linux/etherdevice.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 23681c3d3b8a..2ad71cc90b37 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -552,6 +552,27 @@ static inline unsigned long compare_ether_header(const void *a, const void *b)
}
/**
+ * 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
* @skb: Buffer to pad
*