From: Alexander Duyck The HW stats are kept as a running total that the driver advances by the difference between the current counter value and the value it last read, and the fbnic_reset_hw_stats function only rebases that last value after a reset so the totals carry over. When a register read fails, as it does for every read once a DPC containment event takes the link down, the fbnic_rd32 function returns all ones and disables CSR access, so every later read also returns all ones until the device is recovered. A stats read in that window adds the difference between all ones and the last value to the total, which subtracts the counter's whole value since the last rebase. Hardware testing with forced AER recovery while reading the stats showed the 64-bit PCIe counters wrapping below zero on the first recovery and dropping again on every one after it. Skip the update when CSR access has been disabled by the time the read returns, which covers the read that failed as well as any after it. The last value is left alone, so the next good read after recovery, once the fbnic_reset_hw_stats function has rebased it, picks up where the total left off. Fixes: 25ba596d137d ("eth: fbnic: add PCIe hardware statistics") Fixes: 4eb7f20bcf06 ("eth: fbnic: Add support to fetch group stats") Signed-off-by: Alexander Duyck --- drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c | 8 ++++++++ drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c b/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c index 8b9b2076beec..8084a63dd807 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c @@ -22,6 +22,10 @@ static void fbnic_hw_stat_rd32(struct fbnic_dev *fbd, u32 reg, u32 new_reg_value; new_reg_value = rd32(fbd, reg); + /* A failed read disables CSR access and returns all ones */ + if (!fbnic_present(fbd)) + return; + stat->value += new_reg_value - stat->u.old_reg_value_32; stat->u.old_reg_value_32 = new_reg_value; } @@ -68,6 +72,10 @@ static void fbnic_hw_stat_rd64(struct fbnic_dev *fbd, u32 reg, s32 offset, u64 new_reg_value; new_reg_value = fbnic_stat_rd64(fbd, reg, offset); + /* A failed read disables CSR access and returns all ones */ + if (!fbnic_present(fbd)) + return; + stat->value += new_reg_value - stat->u.old_reg_value_64; stat->u.old_reg_value_64 = new_reg_value; } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c index 16271c717a5a..2aacbf0a6af4 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c @@ -405,6 +405,10 @@ static void __fbnic_mac_stat_rd64(struct fbnic_dev *fbd, bool reset, u32 reg, u64 new_reg_value; new_reg_value = fbnic_stat_rd64(fbd, reg, 1); + /* A failed read disables CSR access and returns all ones */ + if (!fbnic_present(fbd)) + return; + if (!reset) stat->value += new_reg_value - stat->u.old_reg_value_64; stat->u.old_reg_value_64 = new_reg_value; @@ -417,6 +421,10 @@ static void fbnic_mac_stat_rd32(struct fbnic_dev *fbd, bool reset, u32 reg, u32 new_reg_value; new_reg_value = rd32(fbd, reg); + /* A failed read disables CSR access and returns all ones */ + if (!fbnic_present(fbd)) + return; + if (!reset) stat->value += new_reg_value - stat->u.old_reg_value_32; stat->u.old_reg_value_32 = new_reg_value;