[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211015193848.779420-2-kuba@kernel.org>
Date: Fri, 15 Oct 2021 12:38:43 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: netdev@...r.kernel.org
Cc: olteanv@...il.com, andrew@...n.ch, idosch@...sch.org,
f.fainelli@...il.com, Jakub Kicinski <kuba@...nel.org>,
jiri@...dia.com, idosch@...dia.com, lars.povlsen@...rochip.com,
Steen.Hegelund@...rochip.com, UNGLinuxDriver@...rochip.com,
bjarni.jonasson@...rochip.com,
linux-arm-kernel@...ts.infradead.org, qiangqing.zhang@....com,
vkochan@...vell.com, tchornyi@...vell.com, vladimir.oltean@....com,
claudiu.manoil@....com, alexandre.belloni@...tlin.com
Subject: [RFC net-next 1/6] 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: Jakub Kicinski <kuba@...nel.org>
---
CC: jiri@...dia.com
CC: idosch@...dia.com
CC: lars.povlsen@...rochip.com
CC: Steen.Hegelund@...rochip.com
CC: UNGLinuxDriver@...rochip.com
CC: bjarni.jonasson@...rochip.com
CC: linux-arm-kernel@...ts.infradead.org
CC: qiangqing.zhang@....com
CC: vkochan@...vell.com
CC: tchornyi@...vell.com
CC: vladimir.oltean@....com
CC: claudiu.manoil@....com
CC: alexandre.belloni@...tlin.com
CC: UNGLinuxDriver@...rochip.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)
+{
+ 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
Powered by blists - more mailing lists