net/ice/base: track HW stat registers past rollover
[dpdk.git] / drivers / net / ice / base / ice_common.c
index 1ed1510..199430e 100644 (file)
@@ -4004,40 +4004,44 @@ void ice_replay_post(struct ice_hw *hw)
 /**
  * ice_stat_update40 - read 40 bit stat from the chip and update stat values
  * @hw: ptr to the hardware info
- * @hireg: high 32 bit HW register to read from
- * @loreg: low 32 bit HW register to read from
+ * @reg: offset of 64 bit HW register to read from
  * @prev_stat_loaded: bool to specify if previous stats are loaded
  * @prev_stat: ptr to previous loaded stat value
  * @cur_stat: ptr to current stat value
  */
 void
-ice_stat_update40(struct ice_hw *hw, u32 hireg, u32 loreg,
-                 bool prev_stat_loaded, u64 *prev_stat, u64 *cur_stat)
+ice_stat_update40(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
+                 u64 *prev_stat, u64 *cur_stat)
 {
-       u64 new_data;
-
-       new_data = rd32(hw, loreg);
-       new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
+       u64 new_data = rd64(hw, reg) & (BIT_ULL(40) - 1);
 
        /* device stats are not reset at PFR, they likely will not be zeroed
-        * when the driver starts. So save the first values read and use them as
-        * offsets to be subtracted from the raw values in order to report stats
-        * that count from zero.
+        * when the driver starts. Thus, save the value from the first read
+        * without adding to the statistic value so that we report stats which
+        * count up from zero.
         */
-       if (!prev_stat_loaded)
+       if (!prev_stat_loaded) {
                *prev_stat = new_data;
+               return;
+       }
+
+       /* Calculate the difference between the new and old values, and then
+        * add it to the software stat value.
+        */
        if (new_data >= *prev_stat)
-               *cur_stat = new_data - *prev_stat;
+               *cur_stat += new_data - *prev_stat;
        else
                /* to manage the potential roll-over */
-               *cur_stat = (new_data + BIT_ULL(40)) - *prev_stat;
-       *cur_stat &= 0xFFFFFFFFFFULL;
+               *cur_stat += (new_data + BIT_ULL(40)) - *prev_stat;
+
+       /* Update the previously stored value to prepare for next read */
+       *prev_stat = new_data;
 }
 
 /**
  * ice_stat_update32 - read 32 bit stat from the chip and update stat values
  * @hw: ptr to the hardware info
- * @reg: HW register to read from
+ * @reg: offset of HW register to read from
  * @prev_stat_loaded: bool to specify if previous stats are loaded
  * @prev_stat: ptr to previous loaded stat value
  * @cur_stat: ptr to current stat value
@@ -4051,17 +4055,26 @@ ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
        new_data = rd32(hw, reg);
 
        /* device stats are not reset at PFR, they likely will not be zeroed
-        * when the driver starts. So save the first values read and use them as
-        * offsets to be subtracted from the raw values in order to report stats
-        * that count from zero.
+        * when the driver starts. Thus, save the value from the first read
+        * without adding to the statistic value so that we report stats which
+        * count up from zero.
         */
-       if (!prev_stat_loaded)
+       if (!prev_stat_loaded) {
                *prev_stat = new_data;
+               return;
+       }
+
+       /* Calculate the difference between the new and old values, and then
+        * add it to the software stat value.
+        */
        if (new_data >= *prev_stat)
-               *cur_stat = new_data - *prev_stat;
+               *cur_stat += new_data - *prev_stat;
        else
                /* to manage the potential roll-over */
-               *cur_stat = (new_data + BIT_ULL(32)) - *prev_stat;
+               *cur_stat += (new_data + BIT_ULL(32)) - *prev_stat;
+
+       /* Update the previously stored value to prepare for next read */
+       *prev_stat = new_data;
 }