Skip to content

Commit 02e8be5

Browse files
Michael Chandavem330
authored andcommitted
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>
1 parent 6b87bd9 commit 02e8be5

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
@@ -2062,6 +2062,17 @@ static int bnxt_get_regs_len(struct net_device *dev)
20622062
return reg_len;
20632063
}
20642064

2065+
#define BNXT_PCIE_32B_ENTRY(start, end) \
2066+
{ offsetof(struct pcie_ctx_hw_stats, start), \
2067+
offsetof(struct pcie_ctx_hw_stats, end) }
2068+
2069+
static const struct {
2070+
u16 start;
2071+
u16 end;
2072+
} bnxt_pcie_32b_entries[] = {
2073+
BNXT_PCIE_32B_ENTRY(pcie_ltssm_histogram[0], pcie_ltssm_histogram[3]),
2074+
};
2075+
20652076
static void bnxt_get_regs(struct net_device *dev, struct ethtool_regs *regs,
20662077
void *_p)
20672078
{
@@ -2094,12 +2105,27 @@ static void bnxt_get_regs(struct net_device *dev, struct ethtool_regs *regs,
20942105
req->pcie_stat_host_addr = cpu_to_le64(hw_pcie_stats_addr);
20952106
rc = hwrm_req_send(bp, req);
20962107
if (!rc) {
2097-
__le64 *src = (__le64 *)hw_pcie_stats;
2098-
u64 *dst = (u64 *)(_p + BNXT_PXP_REG_LEN);
2099-
int i;
2100-
2101-
for (i = 0; i < sizeof(*hw_pcie_stats) / sizeof(__le64); i++)
2102-
dst[i] = le64_to_cpu(src[i]);
2108+
u8 *dst = (u8 *)(_p + BNXT_PXP_REG_LEN);
2109+
u8 *src = (u8 *)hw_pcie_stats;
2110+
int i, j;
2111+
2112+
for (i = 0, j = 0; i < sizeof(*hw_pcie_stats); ) {
2113+
if (i >= bnxt_pcie_32b_entries[j].start &&
2114+
i <= bnxt_pcie_32b_entries[j].end) {
2115+
u32 *dst32 = (u32 *)(dst + i);
2116+
2117+
*dst32 = le32_to_cpu(*(__le32 *)(src + i));
2118+
i += 4;
2119+
if (i > bnxt_pcie_32b_entries[j].end &&
2120+
j < ARRAY_SIZE(bnxt_pcie_32b_entries) - 1)
2121+
j++;
2122+
} else {
2123+
u64 *dst64 = (u64 *)(dst + i);
2124+
2125+
*dst64 = le64_to_cpu(*(__le64 *)(src + i));
2126+
i += 8;
2127+
}
2128+
}
21032129
}
21042130
hwrm_req_drop(bp, req);
21052131
}

0 commit comments

Comments
 (0)