The statistics contain 40 bits. The lower 32 bits are read first, followed
by the upper 8 bits.

In some cases, after reading the lower 32 bits, a carry occurs from the
lower bits, which causes the final statistics to be incorrect.

This commit fixes this issue.

Fixes: a37bde56314d ("net/ice: support statistics")
Cc: [email protected]

Signed-off-by: Zhichao Zeng <[email protected]>
---
 drivers/net/intel/ice/ice_ethdev.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/net/intel/ice/ice_ethdev.c 
b/drivers/net/intel/ice/ice_ethdev.c
index 513777e372..be08be0826 100644
--- a/drivers/net/intel/ice/ice_ethdev.c
+++ b/drivers/net/intel/ice/ice_ethdev.c
@@ -6036,10 +6036,19 @@ ice_stat_update_40(struct ice_hw *hw,
                   uint64_t *stat)
 {
        uint64_t new_data;
+       uint32_t lo, hi, lo2;
 
-       new_data = (uint64_t)ICE_READ_REG(hw, loreg);
-       new_data |= (uint64_t)(ICE_READ_REG(hw, hireg) & ICE_8_BIT_MASK) <<
-                   ICE_32_BIT_WIDTH;
+       lo = ICE_READ_REG(hw, loreg);
+       hi = ICE_READ_REG(hw, hireg);
+       lo2 = ICE_READ_REG(hw, loreg);
+
+       if (lo2 < lo) {
+               lo = ICE_READ_REG(hw, loreg);
+               hi = ICE_READ_REG(hw, hireg);
+       }
+
+       new_data = (uint64_t)lo;
+       new_data |= (uint64_t)(hi & ICE_8_BIT_MASK) << ICE_32_BIT_WIDTH;
 
        if (!offset_loaded)
                *offset = new_data;
-- 
2.34.1

Reply via email to