net/i40e/base: retry AQC to overcome IRCRead hangs
authorQi Zhang <qi.z.zhang@intel.com>
Tue, 9 Jan 2018 20:30:03 +0000 (15:30 -0500)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 16 Jan 2018 17:47:49 +0000 (18:47 +0100)
When the I2C is busy, the PHY reads are delayed. The firmware will
return EGAIN in these cases with an expectation that the SW will trigger
the reads again. This patch retries the operation for a maximum period
of 500ms.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
Acked-by: Beilei Xing <beilei.xing@intel.com>
drivers/net/i40e/base/i40e_common.c
drivers/net/i40e/base/i40e_type.h

index 900d379..1dc5c62 100644 (file)
@@ -1675,31 +1675,47 @@ enum i40e_status_code i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
 {
        struct i40e_aq_desc desc;
        enum i40e_status_code status;
+       u16 max_delay = I40E_MAX_PHY_TIMEOUT, total_delay = 0;
        u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
 
        if (!abilities)
                return I40E_ERR_PARAM;
 
-       i40e_fill_default_direct_cmd_desc(&desc,
-                                         i40e_aqc_opc_get_phy_abilities);
+       do {
+               i40e_fill_default_direct_cmd_desc(&desc,
+                                              i40e_aqc_opc_get_phy_abilities);
 
-       desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
-       if (abilities_size > I40E_AQ_LARGE_BUF)
-               desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
+               desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
+               if (abilities_size > I40E_AQ_LARGE_BUF)
+                       desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
 
-       if (qualified_modules)
-               desc.params.external.param0 |=
+               if (qualified_modules)
+                       desc.params.external.param0 |=
                        CPU_TO_LE32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
 
-       if (report_init)
-               desc.params.external.param0 |=
+               if (report_init)
+                       desc.params.external.param0 |=
                        CPU_TO_LE32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
 
-       status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
-                                   cmd_details);
+               status = i40e_asq_send_command(hw, &desc, abilities,
+                                              abilities_size, cmd_details);
 
-       if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
-               status = I40E_ERR_UNKNOWN_PHY;
+               if (status != I40E_SUCCESS)
+                       break;
+
+               if (hw->aq.asq_last_status == I40E_AQ_RC_EIO) {
+                       status = I40E_ERR_UNKNOWN_PHY;
+                       break;
+               } else if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN) {
+                       i40e_msec_delay(1);
+                       total_delay++;
+                       status = I40E_ERR_TIMEOUT;
+               }
+       } while ((hw->aq.asq_last_status != I40E_AQ_RC_OK) &&
+                (total_delay < max_delay));
+
+       if (status != I40E_SUCCESS)
+               return status;
 
        if (report_init) {
                if (hw->mac.type ==  I40E_MAC_XL710 &&
index d049509..438e706 100644 (file)
@@ -77,6 +77,9 @@ POSSIBILITY OF SUCH DAMAGE.
 /* Max default timeout in ms, */
 #define I40E_MAX_NVM_TIMEOUT           18000
 
+/* Max timeout in ms for the phy to respond */
+#define I40E_MAX_PHY_TIMEOUT           500
+
 /* Check whether address is multicast. */
 #define I40E_IS_MULTICAST(address) (bool)(((u8 *)(address))[0] & ((u8)0x01))