i40e: check for AQ timeout in aq_rc decode
authorShannon Nelson <shannon.nelson@intel.com>
Thu, 13 Nov 2014 08:23:22 +0000 (08:23 +0000)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Tue, 9 Dec 2014 20:57:04 +0000 (12:57 -0800)
Decoding the AQ return code is great except when the AQ send timed out
and there's no return code set.  This changes the handy decoder
interface to help catch and properly report the condition as a useful
errno rather than returning a misleading '0'.

Change-ID: I07a1f94f921606da49ffac7837bcdc37cd8222eb
Signed-off-by: Shannon Nelson <shannon.nelson@intel.com>
Acked-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Tested-by: Jim Young <jamesx.m.young@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/i40e/i40e_adminq.h
drivers/net/ethernet/intel/i40e/i40e_nvm.c
drivers/net/ethernet/intel/i40evf/i40e_adminq.h

index 2c68bf7..564d0b0 100644 (file)
@@ -28,6 +28,7 @@
 #define _I40E_ADMINQ_H_
 
 #include "i40e_osdep.h"
+#include "i40e_status.h"
 #include "i40e_adminq_cmd.h"
 
 #define I40E_ADMINQ_DESC(R, i)   \
@@ -108,7 +109,7 @@ struct i40e_adminq_info {
  * i40e_aq_rc_to_posix - convert errors to user-land codes
  * aq_rc: AdminQ error code to convert
  **/
-static inline int i40e_aq_rc_to_posix(u16 aq_rc)
+static inline int i40e_aq_rc_to_posix(u32 aq_ret, u16 aq_rc)
 {
        int aq_to_posix[] = {
                0,           /* I40E_AQ_RC_OK */
@@ -136,6 +137,10 @@ static inline int i40e_aq_rc_to_posix(u16 aq_rc)
                -EFBIG,      /* I40E_AQ_RC_EFBIG */
        };
 
+       /* aq_rc is invalid if AQ timed out */
+       if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT)
+               return -EAGAIN;
+
        if (aq_rc >= ARRAY_SIZE(aq_to_posix))
                return -ERANGE;
        return aq_to_posix[aq_rc];
index 0fc62fc..1613ef4 100644 (file)
@@ -527,7 +527,8 @@ static i40e_status i40e_nvmupd_state_init(struct i40e_hw *hw,
        case I40E_NVMUPD_READ_SA:
                status = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
                if (status) {
-                       *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status);
+                       *errno = i40e_aq_rc_to_posix(status,
+                                                    hw->aq.asq_last_status);
                } else {
                        status = i40e_nvmupd_nvm_read(hw, cmd, bytes, errno);
                        i40e_release_nvm(hw);
@@ -537,7 +538,8 @@ static i40e_status i40e_nvmupd_state_init(struct i40e_hw *hw,
        case I40E_NVMUPD_READ_SNT:
                status = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
                if (status) {
-                       *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status);
+                       *errno = i40e_aq_rc_to_posix(status,
+                                                    hw->aq.asq_last_status);
                } else {
                        status = i40e_nvmupd_nvm_read(hw, cmd, bytes, errno);
                        if (status)
@@ -550,7 +552,8 @@ static i40e_status i40e_nvmupd_state_init(struct i40e_hw *hw,
        case I40E_NVMUPD_WRITE_ERA:
                status = i40e_acquire_nvm(hw, I40E_RESOURCE_WRITE);
                if (status) {
-                       *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status);
+                       *errno = i40e_aq_rc_to_posix(status,
+                                                    hw->aq.asq_last_status);
                } else {
                        status = i40e_nvmupd_nvm_erase(hw, cmd, errno);
                        if (status)
@@ -563,7 +566,8 @@ static i40e_status i40e_nvmupd_state_init(struct i40e_hw *hw,
        case I40E_NVMUPD_WRITE_SA:
                status = i40e_acquire_nvm(hw, I40E_RESOURCE_WRITE);
                if (status) {
-                       *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status);
+                       *errno = i40e_aq_rc_to_posix(status,
+                                                    hw->aq.asq_last_status);
                } else {
                        status = i40e_nvmupd_nvm_write(hw, cmd, bytes, errno);
                        if (status)
@@ -576,7 +580,8 @@ static i40e_status i40e_nvmupd_state_init(struct i40e_hw *hw,
        case I40E_NVMUPD_WRITE_SNT:
                status = i40e_acquire_nvm(hw, I40E_RESOURCE_WRITE);
                if (status) {
-                       *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status);
+                       *errno = i40e_aq_rc_to_posix(status,
+                                                    hw->aq.asq_last_status);
                } else {
                        status = i40e_nvmupd_nvm_write(hw, cmd, bytes, errno);
                        if (status)
@@ -589,12 +594,14 @@ static i40e_status i40e_nvmupd_state_init(struct i40e_hw *hw,
        case I40E_NVMUPD_CSUM_SA:
                status = i40e_acquire_nvm(hw, I40E_RESOURCE_WRITE);
                if (status) {
-                       *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status);
+                       *errno = i40e_aq_rc_to_posix(status,
+                                                    hw->aq.asq_last_status);
                } else {
                        status = i40e_update_nvm_checksum(hw);
                        if (status) {
                                *errno = hw->aq.asq_last_status ?
-                                  i40e_aq_rc_to_posix(hw->aq.asq_last_status) :
+                                  i40e_aq_rc_to_posix(status,
+                                                      hw->aq.asq_last_status) :
                                   -EIO;
                                i40e_release_nvm(hw);
                        } else {
@@ -691,7 +698,8 @@ static i40e_status i40e_nvmupd_state_writing(struct i40e_hw *hw,
                status = i40e_update_nvm_checksum(hw);
                if (status) {
                        *errno = hw->aq.asq_last_status ?
-                                  i40e_aq_rc_to_posix(hw->aq.asq_last_status) :
+                                  i40e_aq_rc_to_posix(status,
+                                                      hw->aq.asq_last_status) :
                                   -EIO;
                        hw->nvmupd_state = I40E_NVMUPD_STATE_INIT;
                }
@@ -701,7 +709,8 @@ static i40e_status i40e_nvmupd_state_writing(struct i40e_hw *hw,
                status = i40e_update_nvm_checksum(hw);
                if (status)
                        *errno = hw->aq.asq_last_status ?
-                                  i40e_aq_rc_to_posix(hw->aq.asq_last_status) :
+                                  i40e_aq_rc_to_posix(status,
+                                                      hw->aq.asq_last_status) :
                                   -EIO;
                else
                        hw->aq.nvm_release_on_done = true;
@@ -839,7 +848,7 @@ static i40e_status i40e_nvmupd_nvm_read(struct i40e_hw *hw,
                i40e_debug(hw, I40E_DEBUG_NVM,
                           "i40e_nvmupd_nvm_read status %d aq %d\n",
                           status, hw->aq.asq_last_status);
-               *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status);
+               *errno = i40e_aq_rc_to_posix(status, hw->aq.asq_last_status);
        }
 
        return status;
@@ -873,7 +882,7 @@ static i40e_status i40e_nvmupd_nvm_erase(struct i40e_hw *hw,
                i40e_debug(hw, I40E_DEBUG_NVM,
                           "i40e_nvmupd_nvm_erase status %d aq %d\n",
                           status, hw->aq.asq_last_status);
-               *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status);
+               *errno = i40e_aq_rc_to_posix(status, hw->aq.asq_last_status);
        }
 
        return status;
@@ -909,7 +918,7 @@ static i40e_status i40e_nvmupd_nvm_write(struct i40e_hw *hw,
                i40e_debug(hw, I40E_DEBUG_NVM,
                           "i40e_nvmupd_nvm_write status %d aq %d\n",
                           status, hw->aq.asq_last_status);
-               *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status);
+               *errno = i40e_aq_rc_to_posix(status, hw->aq.asq_last_status);
        }
 
        return status;
index 0ffb8d1..6c31bf2 100644 (file)
@@ -28,6 +28,7 @@
 #define _I40E_ADMINQ_H_
 
 #include "i40e_osdep.h"
+#include "i40e_status.h"
 #include "i40e_adminq_cmd.h"
 
 #define I40E_ADMINQ_DESC(R, i)   \
@@ -108,7 +109,7 @@ struct i40e_adminq_info {
  * i40e_aq_rc_to_posix - convert errors to user-land codes
  * aq_rc: AdminQ error code to convert
  **/
-static inline int i40e_aq_rc_to_posix(u16 aq_rc)
+static inline int i40e_aq_rc_to_posix(u32 aq_ret, u16 aq_rc)
 {
        int aq_to_posix[] = {
                0,           /* I40E_AQ_RC_OK */
@@ -136,6 +137,10 @@ static inline int i40e_aq_rc_to_posix(u16 aq_rc)
                -EFBIG,      /* I40E_AQ_RC_EFBIG */
        };
 
+       /* aq_rc is invalid if AQ timed out */
+       if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT)
+               return -EAGAIN;
+
        if (aq_rc >= ARRAY_SIZE(aq_to_posix))
                return -ERANGE;
        return aq_to_posix[aq_rc];