net/i40e/base: support NVM feature flags
authorXiaolong Ye <xiaolong.ye@intel.com>
Mon, 13 Jan 2020 02:39:13 +0000 (10:39 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 17 Jan 2020 18:46:02 +0000 (19:46 +0100)
Extend NVM Update API to support reporting of features
available for the tools.

This change is needed by NVM Update to determine if driver
supports changing NVM layout from structured to flat.

Signed-off-by: Piotr Pietruszewski <piotr.pietruszewski@intel.com>
Signed-off-by: Krzysztof Galazka <krzysztof.galazka@intel.com>
Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
Acked-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_nvm.c
drivers/net/i40e/base/i40e_type.h

index 37911a9..cee6de2 100644 (file)
@@ -1014,6 +1014,17 @@ enum i40e_status_code i40e_init_shared_code(struct i40e_hw *hw)
        if (hw->mac.type == I40E_MAC_X722)
                hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE |
                             I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
+       /* NVMUpdate features structure initialization */
+       hw->nvmupd_features.major = I40E_NVMUPD_FEATURES_API_VER_MAJOR;
+       hw->nvmupd_features.minor = I40E_NVMUPD_FEATURES_API_VER_MINOR;
+       hw->nvmupd_features.size = sizeof(hw->nvmupd_features);
+       i40e_memset(hw->nvmupd_features.features, 0x0,
+                   I40E_NVMUPD_FEATURES_API_FEATURES_ARRAY_LEN *
+                   sizeof(*hw->nvmupd_features.features),
+                   I40E_NONDMA_MEM);
+
+       /* No features supported at the moment */
+       hw->nvmupd_features.features[0] = 0;
 
        status = i40e_init_nvm(hw);
        return status;
index 6c8ca87..c8b401c 100644 (file)
@@ -797,6 +797,7 @@ STATIC const char *i40e_nvm_update_state_str[] = {
        "I40E_NVMUPD_EXEC_AQ",
        "I40E_NVMUPD_GET_AQ_RESULT",
        "I40E_NVMUPD_GET_AQ_EVENT",
+       "I40E_NVMUPD_GET_FEATURES",
 };
 
 /**
@@ -859,6 +860,31 @@ enum i40e_status_code i40e_nvmupd_command(struct i40e_hw *hw,
                return I40E_SUCCESS;
        }
 
+       /*
+        * A supported features request returns immediately
+        * rather than going into state machine
+        */
+       if (upd_cmd == I40E_NVMUPD_FEATURES) {
+               if (cmd->data_size < hw->nvmupd_features.size) {
+                       *perrno = -EFAULT;
+                       return I40E_ERR_BUF_TOO_SHORT;
+               }
+
+               /*
+                * If buffer is bigger than i40e_nvmupd_features structure,
+                * make sure the trailing bytes are set to 0x0.
+                */
+               if (cmd->data_size > hw->nvmupd_features.size)
+                       i40e_memset(bytes + hw->nvmupd_features.size, 0x0,
+                                   cmd->data_size - hw->nvmupd_features.size,
+                                   I40E_NONDMA_MEM);
+
+               i40e_memcpy(bytes, &hw->nvmupd_features,
+                           hw->nvmupd_features.size, I40E_NONDMA_MEM);
+
+               return I40E_SUCCESS;
+       }
+
        /* Clear status even it is not read and log */
        if (hw->nvmupd_state == I40E_NVMUPD_STATE_ERROR) {
                i40e_debug(hw, I40E_DEBUG_NVM,
@@ -1325,10 +1351,20 @@ STATIC enum i40e_nvmupd_cmd i40e_nvmupd_validate_command(struct i40e_hw *hw,
                        upd_cmd = I40E_NVMUPD_READ_SA;
                        break;
                case I40E_NVM_EXEC:
-                       if (module == 0xf)
-                               upd_cmd = I40E_NVMUPD_STATUS;
-                       else if (module == 0)
+                       switch (module) {
+                       case I40E_NVM_EXEC_GET_AQ_RESULT:
                                upd_cmd = I40E_NVMUPD_GET_AQ_RESULT;
+                               break;
+                       case I40E_NVM_EXEC_FEATURES:
+                               upd_cmd = I40E_NVMUPD_FEATURES;
+                               break;
+                       case I40E_NVM_EXEC_STATUS:
+                               upd_cmd = I40E_NVMUPD_STATUS;
+                               break;
+                       default:
+                               *perrno = -EFAULT;
+                               return I40E_NVMUPD_INVALID;
+                       }
                        break;
                case I40E_NVM_AQE:
                        upd_cmd = I40E_NVMUPD_GET_AQ_EVENT;
index 06863d7..fcdf0eb 100644 (file)
@@ -478,6 +478,7 @@ enum i40e_nvmupd_cmd {
        I40E_NVMUPD_EXEC_AQ,
        I40E_NVMUPD_GET_AQ_RESULT,
        I40E_NVMUPD_GET_AQ_EVENT,
+       I40E_NVMUPD_FEATURES,
 };
 
 enum i40e_nvmupd_state {
@@ -513,6 +514,10 @@ enum i40e_nvmupd_state {
 #define I40E_NVM_AQE                           0xe
 #define I40E_NVM_EXEC                          0xf
 
+#define I40E_NVM_EXEC_GET_AQ_RESULT            0x0
+#define I40E_NVM_EXEC_FEATURES                 0xe
+#define I40E_NVM_EXEC_STATUS                   0xf
+
 #define I40E_NVM_ADAPT_SHIFT   16
 #define I40E_NVM_ADAPT_MASK    (0xffffULL << I40E_NVM_ADAPT_SHIFT)
 
@@ -527,6 +532,20 @@ struct i40e_nvm_access {
        u8 data[1];
 };
 
+/* NVMUpdate features API */
+#define I40E_NVMUPD_FEATURES_API_VER_MAJOR             0
+#define I40E_NVMUPD_FEATURES_API_VER_MINOR             14
+#define I40E_NVMUPD_FEATURES_API_FEATURES_ARRAY_LEN    12
+
+#define I40E_NVMUPD_FEATURE_FLAT_NVM_SUPPORT           BIT(0)
+
+struct i40e_nvmupd_features {
+       u8 major;
+       u8 minor;
+       u16 size;
+       u8 features[I40E_NVMUPD_FEATURES_API_FEATURES_ARRAY_LEN];
+};
+
 /* (Q)SFP module access definitions */
 #define I40E_I2C_EEPROM_DEV_ADDR       0xA0
 #define I40E_I2C_EEPROM_DEV_ADDR2      0xA2
@@ -730,6 +749,9 @@ struct i40e_hw {
        u16 first_tag;
        u16 second_tag;
 
+       /* NVMUpdate features */
+       struct i40e_nvmupd_features nvmupd_features;
+
        /* debug mask */
        u32 debug_mask;
        char err_str[16];