net/ice/base: add read PBA module function
authorQi Zhang <qi.z.zhang@intel.com>
Thu, 29 Aug 2019 02:35:59 +0000 (10:35 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 7 Oct 2019 13:00:52 +0000 (15:00 +0200)
New support function added - ice_get_pfa_module_tlv(), the driver or
other modules can make use of this function to read the pfa area.

Signed-off-by: Tarun Singh <tarun.k.singh@intel.com>
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: Xiaolong Ye <xiaolong.ye@intel.com>
drivers/net/ice/base/ice_common.c
drivers/net/ice/base/ice_common.h

index fa97b79..0356537 100644 (file)
@@ -1283,6 +1283,72 @@ enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req)
        return ice_check_reset(hw);
 }
 
+/**
+ * ice_get_pfa_module_tlv - Reads sub module TLV from NVM PFA
+ * @hw: pointer to hardware structure
+ * @module_tlv: pointer to module TLV to return
+ * @module_tlv_len: pointer to module TLV length to return
+ * @module_type: module type requested
+ *
+ * Finds the requested sub module TLV type from the Preserved Field
+ * Area (PFA) and returns the TLV pointer and length. The caller can
+ * use these to read the variable length TLV value.
+ */
+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 status;
+       u16 pfa_len, pfa_ptr;
+       u16 next_tlv;
+
+       status = ice_read_sr_word(hw, ICE_SR_PFA_PTR, &pfa_ptr);
+       if (status != ICE_SUCCESS) {
+               ice_debug(hw, ICE_DBG_INIT, "Preserved Field Array pointer.\n");
+               return status;
+       }
+       status = ice_read_sr_word(hw, pfa_ptr, &pfa_len);
+       if (status != ICE_SUCCESS) {
+               ice_debug(hw, ICE_DBG_INIT, "Failed to read PFA length.\n");
+               return status;
+       }
+       /* Starting with first TLV after PFA length, iterate through the list
+        * of TLVs to find the requested one.
+        */
+       next_tlv = pfa_ptr + 1;
+       while (next_tlv < pfa_ptr + pfa_len) {
+               u16 tlv_sub_module_type;
+               u16 tlv_len;
+
+               /* Read TLV type */
+               status = ice_read_sr_word(hw, next_tlv, &tlv_sub_module_type);
+               if (status != ICE_SUCCESS) {
+                       ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV type.\n");
+                       break;
+               }
+               /* Read TLV length */
+               status = ice_read_sr_word(hw, next_tlv + 1, &tlv_len);
+               if (status != ICE_SUCCESS) {
+                       ice_debug(hw, ICE_DBG_INIT, "Failed to read TLV length.\n");
+                       break;
+               }
+               if (tlv_sub_module_type == module_type) {
+                       if (tlv_len) {
+                               *module_tlv = next_tlv;
+                               *module_tlv_len = tlv_len;
+                               return ICE_SUCCESS;
+                       }
+                       return ICE_ERR_INVAL_SIZE;
+               }
+               /* Check next TLV, i.e. current TLV pointer + length + 2 words
+                * (for current TLV's type and length)
+                */
+               next_tlv = next_tlv + tlv_len + 2;
+       }
+       /* Module does not exist */
+       return ICE_ERR_DOES_NOT_EXIST;
+}
+
 
 
 /**
index 009c052..c5170f7 100644 (file)
@@ -21,6 +21,9 @@ enum ice_status ice_nvm_validate_checksum(struct ice_hw *hw);
 
 enum ice_status ice_init_hw(struct ice_hw *hw);
 void ice_deinit_hw(struct ice_hw *hw);
+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_check_reset(struct ice_hw *hw);
 enum ice_status ice_reset(struct ice_hw *hw, enum ice_reset_req req);