Skip to content

Commit 69319a2

Browse files
author
Shruti Parab
committed
bnxt_en: Fix ethtool -d byte order for 32-bit values
JIRA: https://issues.redhat.com/browse/RHEL-76568 commit 02e8be5 Author: Michael Chan <michael.chan@broadcom.com> Date: Mon Apr 28 15:59:03 2025 -0700 bnxt_en: Fix ethtool -d byte order for 32-bit values For version 1 register dump that includes the PCIe stats, the existing code incorrectly assumes that all PCIe stats are 64-bit values. Fix it by using an array containing the starting and ending index of the 32-bit values. The loop in bnxt_get_regs() will use the array to do proper endian swap for the 32-bit values. Fixes: b5d600b ("bnxt_en: Add support for 'ethtool -d'") Reviewed-by: Shruti Parab <shruti.parab@broadcom.com> Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com> Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Shruti Parab <shruti.parab@broadcom.com>
1 parent b5ebffe commit 69319a2

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,17 @@ static int bnxt_get_regs_len(struct net_device *dev)
20702070
return reg_len;
20712071
}
20722072

2073+
#define BNXT_PCIE_32B_ENTRY(start, end) \
2074+
{ offsetof(struct pcie_ctx_hw_stats, start), \
2075+
offsetof(struct pcie_ctx_hw_stats, end) }
2076+
2077+
static const struct {
2078+
u16 start;
2079+
u16 end;
2080+
} bnxt_pcie_32b_entries[] = {
2081+
BNXT_PCIE_32B_ENTRY(pcie_ltssm_histogram[0], pcie_ltssm_histogram[3]),
2082+
};
2083+
20732084
static void bnxt_get_regs(struct net_device *dev, struct ethtool_regs *regs,
20742085
void *_p)
20752086
{
@@ -2102,12 +2113,27 @@ static void bnxt_get_regs(struct net_device *dev, struct ethtool_regs *regs,
21022113
req->pcie_stat_host_addr = cpu_to_le64(hw_pcie_stats_addr);
21032114
rc = hwrm_req_send(bp, req);
21042115
if (!rc) {
2105-
__le64 *src = (__le64 *)hw_pcie_stats;
2106-
u64 *dst = (u64 *)(_p + BNXT_PXP_REG_LEN);
2107-
int i;
2108-
2109-
for (i = 0; i < sizeof(*hw_pcie_stats) / sizeof(__le64); i++)
2110-
dst[i] = le64_to_cpu(src[i]);
2116+
u8 *dst = (u8 *)(_p + BNXT_PXP_REG_LEN);
2117+
u8 *src = (u8 *)hw_pcie_stats;
2118+
int i, j;
2119+
2120+
for (i = 0, j = 0; i < sizeof(*hw_pcie_stats); ) {
2121+
if (i >= bnxt_pcie_32b_entries[j].start &&
2122+
i <= bnxt_pcie_32b_entries[j].end) {
2123+
u32 *dst32 = (u32 *)(dst + i);
2124+
2125+
*dst32 = le32_to_cpu(*(__le32 *)(src + i));
2126+
i += 4;
2127+
if (i > bnxt_pcie_32b_entries[j].end &&
2128+
j < ARRAY_SIZE(bnxt_pcie_32b_entries) - 1)
2129+
j++;
2130+
} else {
2131+
u64 *dst64 = (u64 *)(dst + i);
2132+
2133+
*dst64 = le64_to_cpu(*(__le64 *)(src + i));
2134+
i += 8;
2135+
}
2136+
}
21112137
}
21122138
hwrm_req_drop(bp, req);
21132139
}

0 commit comments

Comments
 (0)