Skip to contentSkip to conversation

net: add helper eth_hw_addr_crc

PATCH In review Heiner Kallweit 2 participants 4 messages May 4, 2020

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

cover net: add helper eth_hw_addr_crc

Several drivers use the same code as basis for filter hashes. Therefore let's factor it out to a helper. This way drivers don't have to access struct netdev_hw_addr internals.

First user is r8169.

Heiner Kallweit (2):
net: add helper eth_hw_addr_crc
r8169: use new helper eth_hw_addr_crc

 drivers/net/ethernet/realtek/r8169_main.c |  3 +--
 include/linux/etherdevice.h               | 12 ++++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

PATCH 1/2 net: add helper eth_hw_addr_crc

Several drivers use the same code as basis for filter hashes. Therefore let's factor it out to a helper. This way drivers don't have to access struct netdev_hw_addr internals.

---
 include/linux/etherdevice.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/etherdevice.h +12 -0
index 8801f1f98..2e5debc03 100644
@@ -20,6 +20,7 @@
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
 #include <linux/random.h>
+#include <linux/crc32.h>
 #include <asm/unaligned.h>
 #include <asm/bitsperlong.h>
 
@@ -265,6 +266,17 @@ static inline void eth_hw_addr_random(struct net_device *dev)
 	eth_random_addr(dev->dev_addr);
 }
 
+/**
+ * eth_hw_addr_crc - Calculate CRC from netdev_hw_addr
+ * @ha: pointer to hardware address
+ *
+ * Calculate CRC from a hardware address as basis for filter hashes.
+ */
+static inline u32 eth_hw_addr_crc(struct netdev_hw_addr *ha)
+{
+	return ether_crc(ETH_ALEN, ha->addr);
+}
+
 /**
  * ether_addr_copy - Copy an Ethernet address
  * @dst: Pointer to a six-byte array Ethernet address destination
Signature · 1 line
2.26.2
author maintainer
#2 lore raw

PATCH 2/2 r8169: use new helper eth_hw_addr_crc

In reply to Heiner Kallweit

Use new helper eth_hw_addr_crc to simplify the code.

---
 drivers/net/ethernet/realtek/r8169_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +1 -2
index 8b665f2ec..2f6512ed0 100644
@@ -19,7 +19,6 @@
 #include <linux/ethtool.h>
 #include <linux/phy.h>
 #include <linux/if_vlan.h>
-#include <linux/crc32.h>
 #include <linux/in.h>
 #include <linux/io.h>
 #include <linux/ip.h>
@@ -2610,7 +2609,7 @@ static void rtl_set_rx_mode(struct net_device *dev)
 
 		mc_filter[1] = mc_filter[0] = 0;
 		netdev_for_each_mc_addr(ha, dev) {
-			u32 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
+			u32 bit_nr = eth_hw_addr_crc(ha) >> 26;
 			mc_filter[bit_nr >> 5] |= BIT(bit_nr & 31);
 		}
 
Signature · 1 line
2.26.2
maintainer
#3 lore raw
In reply to Heiner Kallweit

From: Heiner Kallweit <[email protected]>
Date: Mon, 4 May 2020 19:25:58 +0200

Quoted 5 lines

Several drivers use the same code as basis for filter hashes. Therefore let's factor it out to a helper. This way drivers don't have to access struct netdev_hw_addr internals.

First user is r8169.

Series applied.