net/ice/base: add NVM helper functions
authorQi Zhang <qi.z.zhang@intel.com>
Mon, 15 Jun 2020 02:04:42 +0000 (10:04 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 16 Jun 2020 17:21:08 +0000 (19:21 +0200)
Add couple functions that DPDK would like to use for accessing the
NVM.

Signed-off-by: Paul M Stillwell Jr <paul.m.stillwell.jr@intel.com>
Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
Acked-by: Qiming Yang <qiming.yang@intel.com>
drivers/net/ice/base/ice_common.h
drivers/net/ice/base/ice_nvm.c
drivers/net/ice/base/ice_nvm.h

index 6d971a6..46741a3 100644 (file)
@@ -18,7 +18,6 @@ enum ice_fw_modes {
        ICE_FW_MODE_ROLLBACK
 };
 
-enum ice_status ice_nvm_validate_checksum(struct ice_hw *hw);
 enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw);
 void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw);
 enum ice_status ice_init_hw(struct ice_hw *hw);
index d5e6215..bedfbcb 100644 (file)
@@ -17,7 +17,7 @@
  *
  * Read the NVM using the admin queue commands (0x0701)
  */
-static enum ice_status
+enum ice_status
 ice_aq_read_nvm(struct ice_hw *hw, u16 module_typeid, u32 offset, u16 length,
                void *data, bool last_command, bool read_shadow_ram,
                struct ice_sq_cd *cd)
@@ -186,7 +186,7 @@ ice_read_sr_buf_aq(struct ice_hw *hw, u16 offset, u16 *words, u16 *data)
  *
  * This function will request NVM ownership.
  */
-static enum ice_status
+enum ice_status
 ice_acquire_nvm(struct ice_hw *hw, enum ice_aq_res_access_type access)
 {
        ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
@@ -203,7 +203,7 @@ ice_acquire_nvm(struct ice_hw *hw, enum ice_aq_res_access_type access)
  *
  * This function will release NVM ownership.
  */
-static void ice_release_nvm(struct ice_hw *hw)
+void ice_release_nvm(struct ice_hw *hw)
 {
        ice_debug(hw, ICE_DBG_TRACE, "%s\n", __func__);
 
@@ -300,6 +300,67 @@ ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len,
        return ICE_ERR_DOES_NOT_EXIST;
 }
 
+/**
+ * ice_read_pba_string - Reads part number string from NVM
+ * @hw: pointer to hardware structure
+ * @pba_num: stores the part number string from the NVM
+ * @pba_num_size: part number string buffer length
+ *
+ * Reads the part number string from the NVM.
+ */
+enum ice_status
+ice_read_pba_string(struct ice_hw *hw, u8 *pba_num, u32 pba_num_size)
+{
+       u16 pba_tlv, pba_tlv_len;
+       enum ice_status status;
+       u16 pba_word, pba_size;
+       u16 i;
+
+       status = ice_get_pfa_module_tlv(hw, &pba_tlv, &pba_tlv_len,
+                                       ICE_SR_PBA_BLOCK_PTR);
+       if (status != ICE_SUCCESS) {
+               ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Block TLV.\n");
+               return status;
+       }
+
+       /* pba_size is the next word */
+       status = ice_read_sr_word(hw, (pba_tlv + 2), &pba_size);
+       if (status != ICE_SUCCESS) {
+               ice_debug(hw, ICE_DBG_INIT, "Failed to read PBA Section size.\n");
+               return status;
+       }
+
+       if (pba_tlv_len < pba_size) {
+               ice_debug(hw, ICE_DBG_INIT, "Invalid PBA Block TLV size.\n");
+               return ICE_ERR_INVAL_SIZE;
+       }
+
+       /* Subtract one to get PBA word count (PBA Size word is included in
+        * total size)
+        */
+       pba_size--;
+       if (pba_num_size < (((u32)pba_size * 2) + 1)) {
+               ice_debug(hw, ICE_DBG_INIT,
+                         "Buffer too small for PBA data.\n");
+               return ICE_ERR_PARAM;
+       }
+
+       for (i = 0; i < pba_size; i++) {
+               status = ice_read_sr_word(hw, (pba_tlv + 2 + 1) + i, &pba_word);
+               if (status != ICE_SUCCESS) {
+                       ice_debug(hw, ICE_DBG_INIT,
+                                 "Failed to read PBA Block word %d.\n", i);
+                       return status;
+               }
+
+               pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
+               pba_num[(i * 2) + 1] = pba_word & 0xFF;
+       }
+       pba_num[(pba_size * 2)] = '\0';
+
+       return status;
+}
+
 /**
  * ice_get_orom_ver_info - Read Option ROM version information
  * @hw: pointer to the HW struct
index 9a61d41..8e2eb4d 100644 (file)
@@ -85,13 +85,23 @@ enum ice_status
 ice_handle_nvm_access(struct ice_hw *hw, struct ice_nvm_access_cmd *cmd,
                      union ice_nvm_access_data *data);
 enum ice_status
+ice_acquire_nvm(struct ice_hw *hw, enum ice_aq_res_access_type access);
+void ice_release_nvm(struct ice_hw *hw);
+enum ice_status
+ice_aq_read_nvm(struct ice_hw *hw, u16 module_typeid, u32 offset, u16 length,
+               void *data, bool last_command, bool read_shadow_ram,
+               struct ice_sq_cd *cd);
+enum ice_status
 ice_read_flat_nvm(struct ice_hw *hw, u32 offset, u32 *length, u8 *data,
                  bool read_shadow_ram);
 enum ice_status
 ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len,
                       u16 module_type);
+enum ice_status
+ice_read_pba_string(struct ice_hw *hw, u8 *pba_num, u32 pba_num_size);
 enum ice_status ice_init_nvm(struct ice_hw *hw);
 enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data);
 enum ice_status
 ice_read_sr_buf(struct ice_hw *hw, u16 offset, u16 *words, u16 *data);
+enum ice_status ice_nvm_validate_checksum(struct ice_hw *hw);
 #endif /* _ICE_NVM_H_ */