Skip to content

Commit f5474e5

Browse files
author
Shruti Parab
committed
bnxt_en: Fix ethtool -d byte order for 32-bit values
JIRA: https://issues.redhat.com/browse/RHEL-76565 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 9013c9a commit f5474e5

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
@@ -2071,6 +2071,17 @@ static int bnxt_get_regs_len(struct net_device *dev)
20712071
return reg_len;
20722072
}
20732073

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

0 commit comments

Comments
 (0)