Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

qed: Reimplement qed_mcast_bin_from_mac() using library functions

The calculation done by qed_calc_crc32c() is the standard
least-significant-bit-first CRC-32C except it uses
most-significant-bit-first order for the actual CRC variable. That is
equivalent to bit-reflecting the input and output CRC. Replace it with
equivalent calls to the corresponding library functions.

Tested with a simple userspace program which tested that the old and new
implementations of qed_mcast_bin_from_mac() produce the same outputs.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Link: https://patch.msgid.link/20260316221453.66078-1-ebiggers@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Biggers and committed by
Jakub Kicinski
d5516452 4455a30b

+11 -42
+11 -42
drivers/net/ethernet/qlogic/qed/qed_l2.c
··· 7 7 #include <linux/types.h> 8 8 #include <asm/byteorder.h> 9 9 #include <asm/param.h> 10 + #include <linux/crc32.h> 10 11 #include <linux/delay.h> 11 12 #include <linux/dma-mapping.h> 12 13 #include <linux/etherdevice.h> ··· 40 39 #include "qed_sriov.h" 41 40 42 41 #define QED_MAX_SGES_NUM 16 43 - #define CRC32_POLY 0x1edc6f41 44 42 45 43 struct qed_l2_info { 46 44 u32 queues; ··· 1412 1412 return 0; 1413 1413 } 1414 1414 1415 - /******************************************************************************* 1416 - * Description: 1417 - * Calculates crc 32 on a buffer 1418 - * Note: crc32_length MUST be aligned to 8 1419 - * Return: 1420 - ******************************************************************************/ 1421 - static u32 qed_calc_crc32c(u8 *crc32_packet, 1422 - u32 crc32_length, u32 crc32_seed, u8 complement) 1423 - { 1424 - u32 byte = 0, bit = 0, crc32_result = crc32_seed; 1425 - u8 msb = 0, current_byte = 0; 1426 - 1427 - if ((!crc32_packet) || 1428 - (crc32_length == 0) || 1429 - ((crc32_length % 8) != 0)) 1430 - return crc32_result; 1431 - for (byte = 0; byte < crc32_length; byte++) { 1432 - current_byte = crc32_packet[byte]; 1433 - for (bit = 0; bit < 8; bit++) { 1434 - msb = (u8)(crc32_result >> 31); 1435 - crc32_result = crc32_result << 1; 1436 - if (msb != (0x1 & (current_byte >> bit))) { 1437 - crc32_result = crc32_result ^ CRC32_POLY; 1438 - crc32_result |= 1; /*crc32_result[0] = 1;*/ 1439 - } 1440 - } 1441 - } 1442 - return crc32_result; 1443 - } 1444 - 1445 - static u32 qed_crc32c_le(u32 seed, u8 *mac, u32 len) 1446 - { 1447 - u32 packet_buf[2] = { 0 }; 1448 - 1449 - memcpy((u8 *)(&packet_buf[0]), &mac[0], 6); 1450 - return qed_calc_crc32c((u8 *)packet_buf, 8, seed, 0); 1451 - } 1452 - 1453 1415 u8 qed_mcast_bin_from_mac(u8 *mac) 1454 1416 { 1455 - u32 crc = qed_crc32c_le(ETH_MULTICAST_BIN_FROM_MAC_SEED, 1456 - mac, ETH_ALEN); 1417 + u8 padded_mac[8] = {}; 1418 + u32 crc; 1457 1419 1458 - return crc & 0xff; 1420 + memcpy(padded_mac, mac, ETH_ALEN); 1421 + /* 1422 + * This uses the standard CRC-32C, but with the input and output CRCs 1423 + * bit-reflected and the bit-reflected output CRC truncated to 8 bits. 1424 + */ 1425 + crc = crc32c(bitrev32(ETH_MULTICAST_BIN_FROM_MAC_SEED), padded_mac, 1426 + sizeof(padded_mac)); 1427 + return bitrev8(crc >> 24); 1459 1428 } 1460 1429 1461 1430 static int