From: Nir Efrati <nir.efr...@intel.com>

On some customer platforms it was observed that invalid PHY ID (0x0000) was
returned on first try. This patch introduces PHY ID retry mechanism to
perform retries on PHY ID read for up to a second. Because the original
code was intentionally not checking PHY ID due to a different issue, this
fix only checks if PHY ID is non-zero, but otherwise considers any PHY ID
as valid.

In addition, IEEE standard defines format of PHY ID, so extract these bits
from PHY ID value.

Signed-off-by: Sasha Neftin <sasha.nef...@intel.com>
Signed-off-by: Nir Efrati <nir.efr...@intel.com>
Signed-off-by: Anatoly Burakov <anatoly.bura...@intel.com>
---
 drivers/net/intel/e1000/base/e1000_defines.h |  1 +
 drivers/net/intel/e1000/base/e1000_hw.h      |  1 +
 drivers/net/intel/e1000/base/e1000_i225.c    | 44 +++++++++++++++++++-
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/drivers/net/intel/e1000/base/e1000_defines.h 
b/drivers/net/intel/e1000/base/e1000_defines.h
index 51bc5a069b..eb93675823 100644
--- a/drivers/net/intel/e1000/base/e1000_defines.h
+++ b/drivers/net/intel/e1000/base/e1000_defines.h
@@ -1382,6 +1382,7 @@
 #define BCM54616_E_PHY_ID      0x03625D10
 #define M88_VENDOR             0x0141
 #define I225_I_PHY_ID          0x67C9DC00
+#define I225_I_PHY_ID_MASK     0xFFFFFC00
 #define I226_LM_PHY_ID         0x67C9DC10
 
 /* M88E1000 Specific Registers */
diff --git a/drivers/net/intel/e1000/base/e1000_hw.h 
b/drivers/net/intel/e1000/base/e1000_hw.h
index d5dea74c22..4bc5a8e0f2 100644
--- a/drivers/net/intel/e1000/base/e1000_hw.h
+++ b/drivers/net/intel/e1000/base/e1000_hw.h
@@ -1049,6 +1049,7 @@ struct e1000_dev_spec_vf {
 struct e1000_dev_spec_i225 {
        bool global_device_reset;
        bool eee_disable;
+       bool wait_for_valid_phy_id_read;
        bool clear_semaphore_once;
        bool module_plugged;
        u8 media_port;
diff --git a/drivers/net/intel/e1000/base/e1000_i225.c 
b/drivers/net/intel/e1000/base/e1000_i225.c
index 062a195a66..a1f4c5524b 100644
--- a/drivers/net/intel/e1000/base/e1000_i225.c
+++ b/drivers/net/intel/e1000/base/e1000_i225.c
@@ -143,8 +143,10 @@ static s32 e1000_init_mac_params_i225(struct e1000_hw *hw)
 static s32 e1000_init_phy_params_i225(struct e1000_hw *hw)
 {
        struct e1000_phy_info *phy = &hw->phy;
+       u16 phy_id_retries = 1, phy_id_retries_interval_ms = 100;
        s32 ret_val = E1000_SUCCESS;
        u32 ctrl_ext;
+       u16 i = 0;
 
        DEBUGFUNC("e1000_init_phy_params_i225");
 
@@ -184,10 +186,48 @@ static s32 e1000_init_phy_params_i225(struct e1000_hw *hw)
        phy->ops.read_reg = e1000_read_phy_reg_gpy;
        phy->ops.write_reg = e1000_write_phy_reg_gpy;
 
-       ret_val = e1000_get_phy_id(hw);
-       phy->type = e1000_phy_i225;
+       if (hw->dev_spec._i225.wait_for_valid_phy_id_read) {
+               phy_id_retries = 10;
+               DEBUGOUT1("Going to wait %d ms for a valid PHY ID read...\n",
+                         phy_id_retries * phy_id_retries_interval_ms);
+       }
 
+       for (i = 0; i < phy_id_retries; i++) {
+               ret_val = e1000_get_phy_id(hw);
+               phy->id &= I225_I_PHY_ID_MASK;
+               DEBUGOUT1("PHY ID value = 0x%08x\n", phy->id);
 
+               /*
+               * IGC/IGB merge note: in base code, there was a PHY ID check for
+               * I225 at this point. However, in DPDK version of IGC this check
+               * was removed because it interfered with some i225-based NICs,
+               * and it was deemed unnecessary because only the i225 NIC
+               * would've called this code anyway because it was in the IGC
+               * driver.
+               *
+               * This code was then amended apparently because there were
+               * issues wih reading PHY ID on some platforms, and PHY ID read
+               * was to be retried multiple times. However, the original fix in
+               * the base code still had the PHY ID check, and it is now
+               * necessary because there is a chance to read an invalid PHY ID.
+               * So, in backport, it was decided to replace the equality check
+               * with a non-zero condition, because the "invalid" PHY ID as
+               * reported in the original issue, was 0. So, as long as we read
+               * a non-zero PHY ID, we consider it valid.
+               */
+               if (phy->id != 0) {
+                       phy->type = e1000_phy_i225;
+                       phy->ops.set_d0_lplu_state = 
e1000_set_d0_lplu_state_i225;
+                       phy->ops.set_d3_lplu_state = 
e1000_set_d3_lplu_state_i225;
+
+                       return ret_val;
+               }
+
+               msec_delay(phy_id_retries_interval_ms);
+       }
+
+       DEBUGOUT("Failed to read PHY ID\n");
+       ret_val = E1000_ERR_PHY;
 out:
        return ret_val;
 }
-- 
2.43.5

Reply via email to