Skip to content

Commit cad5eaf

Browse files
committed
Merge branch 'net-add-helper-eth_hw_addr_crc'
Heiner Kallweit says: ==================== 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. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents e90c9fc + bc54ac3 commit cad5eaf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

drivers/net/ethernet/realtek/r8169_main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <linux/ethtool.h>
2020
#include <linux/phy.h>
2121
#include <linux/if_vlan.h>
22-
#include <linux/crc32.h>
2322
#include <linux/in.h>
2423
#include <linux/io.h>
2524
#include <linux/ip.h>
@@ -2610,7 +2609,7 @@ static void rtl_set_rx_mode(struct net_device *dev)
26102609

26112610
mc_filter[1] = mc_filter[0] = 0;
26122611
netdev_for_each_mc_addr(ha, dev) {
2613-
u32 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2612+
u32 bit_nr = eth_hw_addr_crc(ha) >> 26;
26142613
mc_filter[bit_nr >> 5] |= BIT(bit_nr & 31);
26152614
}
26162615

include/linux/etherdevice.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/if_ether.h>
2121
#include <linux/netdevice.h>
2222
#include <linux/random.h>
23+
#include <linux/crc32.h>
2324
#include <asm/unaligned.h>
2425
#include <asm/bitsperlong.h>
2526

@@ -265,6 +266,17 @@ static inline void eth_hw_addr_random(struct net_device *dev)
265266
eth_random_addr(dev->dev_addr);
266267
}
267268

269+
/**
270+
* eth_hw_addr_crc - Calculate CRC from netdev_hw_addr
271+
* @ha: pointer to hardware address
272+
*
273+
* Calculate CRC from a hardware address as basis for filter hashes.
274+
*/
275+
static inline u32 eth_hw_addr_crc(struct netdev_hw_addr *ha)
276+
{
277+
return ether_crc(ETH_ALEN, ha->addr);
278+
}
279+
268280
/**
269281
* ether_addr_copy - Copy an Ethernet address
270282
* @dst: Pointer to a six-byte array Ethernet address destination

0 commit comments

Comments
 (0)