[46/69] net/i40e/base: implement lpi statistics read from registers
diff mbox series

Message ID 20191202074935.97629-47-xiaolong.ye@intel.com
State New
Delegated to: xiaolong ye
Headers show
Series
  • update for i40e base code
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Ye Xiaolong Dec. 2, 2019, 7:49 a.m. UTC
On 1g i40e_aq_run_phy_activity() reports lpi statistics always as 0.
If phy is connected on 1g now the i40e_aq_run_phy_activity() call
is skipped and lpi statistics reading is done via direct
I40E_PRTPM_TLPIC,I40E_PRTPM_RLPIC registers read. Added new return
parameter to i40e_get_lpi_counters() because registers are clean
after read and especial if(is_clean) branch to handle statistics
increment such case also.

Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Reviewed-by: Piotr  Kwapulinski <piotr.kwapulinski@intel.com>
Reviewed-by: Pietruszewski Piotr <piotr.pietruszewski@intel.com>
Reviewed-by: Michael Alice <alice.michael@intel.com>
Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
---
 drivers/net/i40e/base/i40e_common.c    | 40 +++++++++++++++-----------
 drivers/net/i40e/base/i40e_prototype.h |  2 +-
 2 files changed, 25 insertions(+), 17 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/i40e/base/i40e_common.c b/drivers/net/i40e/base/i40e_common.c
index 6ae598c95..8763c0e65 100644
--- a/drivers/net/i40e/base/i40e_common.c
+++ b/drivers/net/i40e/base/i40e_common.c
@@ -7173,21 +7173,25 @@  enum i40e_status_code i40e_get_phy_lpi_status(struct i40e_hw *hw,
  * @hw: pointer to the hw struct
  * @tx_counter: pointer to memory for TX LPI counter
  * @rx_counter: pointer to memory for RX LPI counter
+ * @is_clear:   returns true if counters are clear after read
  *
  * Read Low Power Idle (LPI) mode counters from Energy Efficient
  * Ethernet (EEE) statistics.
  **/
 enum i40e_status_code i40e_get_lpi_counters(struct i40e_hw *hw,
-					    u32 *tx_counter, u32 *rx_counter)
+					    u32 *tx_counter, u32 *rx_counter,
+					    bool *is_clear)
 {
 #ifdef CARLSVILLE_HW
 	/* only X710-T*L requires special handling of counters
 	 * for other devices we just read the MAC registers
 	 */
-	if (hw->device_id == I40E_DEV_ID_10G_BASE_T_BC) {
+	if (hw->device_id == I40E_DEV_ID_10G_BASE_T_BC &&
+	    hw->phy.link_info.link_speed != I40E_LINK_SPEED_1GB) {
 		enum i40e_status_code retval;
 		u32 cmd_status;
 
+		*is_clear = false;
 		retval = i40e_aq_run_phy_activity(hw,
 				I40E_AQ_RUN_PHY_ACT_ID_USR_DFND,
 				I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT,
@@ -7200,6 +7204,7 @@  enum i40e_status_code i40e_get_lpi_counters(struct i40e_hw *hw,
 	}
 
 #endif /* CARLSVILLE_HW */
+	*is_clear = true;
 	*tx_counter = rd32(hw, I40E_PRTPM_TLPIC);
 	*rx_counter = rd32(hw, I40E_PRTPM_RLPIC);
 
@@ -7225,25 +7230,28 @@  enum i40e_status_code i40e_lpi_stat_update(struct i40e_hw *hw,
 {
 	enum i40e_status_code retval;
 	u32 tx_counter, rx_counter;
+	bool is_clear;
 
-	retval = i40e_get_lpi_counters(hw, &tx_counter, &rx_counter);
+	retval = i40e_get_lpi_counters(hw, &tx_counter, &rx_counter, &is_clear);
 	if (retval)
 		goto err;
 
-	if (!offset_loaded) {
-		*tx_offset = tx_counter;
-		*rx_offset = rx_counter;
-	}
-
-	if (tx_counter >= *tx_offset)
-		*tx_stat = (u32)(tx_counter - *tx_offset);
-	else
-		*tx_stat = (u32)((tx_counter + BIT_ULL(32)) - *tx_offset);
+	if (is_clear) {
+		*tx_stat += tx_counter;
+		*rx_stat += rx_counter;
+	} else {
+		if (!offset_loaded) {
+			*tx_offset = tx_counter;
+			*rx_offset = rx_counter;
+		}
 
-	if (rx_counter >= *rx_offset)
-		*rx_stat = (u32)(rx_counter - *rx_offset);
-	else
-		*rx_stat = (u32)((rx_counter + BIT_ULL(32)) - *rx_offset);
+		*tx_stat = (tx_counter >= *tx_offset) ?
+			(u32)(tx_counter - *tx_offset) :
+			(u32)((tx_counter + BIT_ULL(32)) - *tx_offset);
+		*rx_stat = (rx_counter >= *rx_offset) ?
+			(u32)(rx_counter - *rx_offset) :
+			(u32)((rx_counter + BIT_ULL(32)) - *rx_offset);
+	}
 err:
 	return retval;
 }
diff --git a/drivers/net/i40e/base/i40e_prototype.h b/drivers/net/i40e/base/i40e_prototype.h
index 975fbd3ca..86e320da8 100644
--- a/drivers/net/i40e/base/i40e_prototype.h
+++ b/drivers/net/i40e/base/i40e_prototype.h
@@ -77,7 +77,7 @@  enum i40e_status_code i40e_blink_phy_link_led(struct i40e_hw *hw,
 enum i40e_status_code i40e_get_phy_lpi_status(struct i40e_hw *hw,
 					      struct i40e_hw_port_stats *stats);
 enum i40e_status_code i40e_get_lpi_counters(struct i40e_hw *hw, u32 *tx_counter,
-					    u32 *rx_counter);
+					    u32 *rx_counter, bool *is_clear);
 enum i40e_status_code i40e_lpi_stat_update(struct i40e_hw *hw,
 					   bool offset_loaded, u64 *tx_offset,
 					   u64 *tx_stat, u64 *rx_offset,