From: Fabio Pricoco <fabio.pric...@intel.com>

Add support for AQ 0x070C. Includes ice_nvm_sanitize and a helper
function ice_nvm_sanitize_operate to facilitate the operate request.

Signed-off-by: Fabio Pricoco <fabio.pric...@intel.com>
Signed-off-by: Ian Stokes <ian.sto...@intel.com>
---
 drivers/net/ice/base/ice_adminq_cmd.h | 25 ++++++++++++
 drivers/net/ice/base/ice_nvm.c        | 57 +++++++++++++++++++++++++++
 drivers/net/ice/base/ice_nvm.h        |  2 +
 3 files changed, 84 insertions(+)

diff --git a/drivers/net/ice/base/ice_adminq_cmd.h 
b/drivers/net/ice/base/ice_adminq_cmd.h
index e1de15a0a4..848bbef393 100644
--- a/drivers/net/ice/base/ice_adminq_cmd.h
+++ b/drivers/net/ice/base/ice_adminq_cmd.h
@@ -2052,6 +2052,29 @@ struct ice_aqc_nvm_checksum {
        u8 rsvd2[12];
 };
 
+/* Used for NVM Sanitization command - 0x070C */
+struct ice_aqc_nvm_sanitization {
+       u8 cmd_flags;
+#define ICE_AQ_NVM_SANITIZE_REQ_READ                           0
+#define ICE_AQ_NVM_SANITIZE_REQ_OPERATE                                BIT(0)
+
+#define ICE_AQ_NVM_SANITIZE_READ_SUBJECT_NVM_BITS              0
+#define ICE_AQ_NVM_SANITIZE_READ_SUBJECT_NVM_STATE             BIT(1)
+#define ICE_AQ_NVM_SANITIZE_OPERATE_SUBJECT_CLEAR              0
+       u8 values;
+#define ICE_AQ_NVM_SANITIZE_NVM_BITS_HOST_CLEAN_SUPPORT                BIT(0)
+#define ICE_AQ_NVM_SANITIZE_NVM_BITS_BMC_CLEAN_SUPPORT         BIT(2)
+#define ICE_AQ_NVM_SANITIZE_NVM_STATE_HOST_CLEAN_DONE          BIT(0)
+#define ICE_AQ_NVM_SANITIZE_NVM_STATE_HOST_CLEAN_SUCCESS       BIT(1)
+#define ICE_AQ_NVM_SANITIZE_NVM_STATE_BMC_CLEAN_DONE           BIT(2)
+#define ICE_AQ_NVM_SANITIZE_NVM_STATE_BMC_CLEAN_SUCCESS                BIT(3)
+#define ICE_AQ_NVM_SANITIZE_OPERATE_HOST_CLEAN_DONE            BIT(0)
+#define ICE_AQ_NVM_SANITIZE_OPERATE_HOST_CLEAN_SUCCESS         BIT(1)
+#define ICE_AQ_NVM_SANITIZE_OPERATE_BMC_CLEAN_DONE             BIT(2)
+#define ICE_AQ_NVM_SANITIZE_OPERATE_BMC_CLEAN_SUCCESS          BIT(3)
+       u8 reserved[14];
+};
+
 /* Get LLDP MIB (indirect 0x0A00)
  * Note: This is also used by the LLDP MIB Change Event (0x0A01)
  * as the format is the same.
@@ -3113,6 +3136,7 @@ struct ice_aq_desc {
                struct ice_aqc_nvm_cfg nvm_cfg;
                struct ice_aqc_nvm_checksum nvm_checksum;
                struct ice_aqc_pfc_ignore pfc_ignore;
+               struct ice_aqc_nvm_sanitization sanitization;
                struct ice_aqc_set_query_pfc_mode set_query_pfc_mode;
                struct ice_aqc_set_dcb_params set_dcb_params;
                struct ice_aqc_lldp_get_mib lldp_get_mib;
@@ -3365,6 +3389,7 @@ enum ice_adminq_opc {
        ice_aqc_opc_nvm_sr_dump                         = 0x0707,
        ice_aqc_opc_nvm_save_factory_settings           = 0x0708,
        ice_aqc_opc_nvm_update_empr                     = 0x0709,
+       ice_aqc_opc_nvm_sanitization                    = 0x070C,
 
        /* LLDP commands */
        ice_aqc_opc_lldp_get_mib                        = 0x0A00,
diff --git a/drivers/net/ice/base/ice_nvm.c b/drivers/net/ice/base/ice_nvm.c
index 811bbc9bbc..b0d238f7e0 100644
--- a/drivers/net/ice/base/ice_nvm.c
+++ b/drivers/net/ice/base/ice_nvm.c
@@ -1427,3 +1427,60 @@ ice_handle_nvm_access(struct ice_hw *hw, struct 
ice_nvm_access_cmd *cmd,
                return ICE_ERR_PARAM;
        }
 }
+
+/**
+ * ice_nvm_sanitize_operate - Clear the user data
+ * @hw: pointer to the HW struct
+ *
+ * Clear user data from NVM using AQ command (0x070C).
+ *
+ * Return: the exit code of the operation.
+ */
+s32 ice_nvm_sanitize_operate(struct ice_hw *hw)
+{
+       s32 status;
+       u8 values;
+
+       u8 cmd_flags = ICE_AQ_NVM_SANITIZE_REQ_OPERATE |
+                      ICE_AQ_NVM_SANITIZE_OPERATE_SUBJECT_CLEAR;
+
+       status = ice_nvm_sanitize(hw, cmd_flags, &values);
+       if (status)
+               return status;
+       if ((!(values & ICE_AQ_NVM_SANITIZE_OPERATE_HOST_CLEAN_DONE) &&
+            !(values & ICE_AQ_NVM_SANITIZE_OPERATE_BMC_CLEAN_DONE)) ||
+           ((values & ICE_AQ_NVM_SANITIZE_OPERATE_HOST_CLEAN_DONE) &&
+            !(values & ICE_AQ_NVM_SANITIZE_OPERATE_HOST_CLEAN_SUCCESS)) ||
+           ((values & ICE_AQ_NVM_SANITIZE_OPERATE_BMC_CLEAN_DONE) &&
+            !(values & ICE_AQ_NVM_SANITIZE_OPERATE_BMC_CLEAN_SUCCESS)))
+               return ICE_ERR_AQ_ERROR;
+
+       return ICE_SUCCESS;
+}
+
+/**
+ * ice_nvm_sanitize - Sanitize NVM
+ * @hw: pointer to the HW struct
+ * @cmd_flags: flag to the ACI command
+ * @values: values returned from the command
+ *
+ * Sanitize NVM using AQ command (0x070C).
+ *
+ * Return: the exit code of the operation.
+ */
+s32 ice_nvm_sanitize(struct ice_hw *hw, u8 cmd_flags, u8 *values)
+{
+       struct ice_aqc_nvm_sanitization *cmd;
+       struct ice_aq_desc desc;
+       s32 status;
+
+       cmd = &desc.params.sanitization;
+       ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_nvm_sanitization);
+       cmd->cmd_flags = cmd_flags;
+
+       status = ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
+       if (values)
+               *values = cmd->values;
+
+       return status;
+}
diff --git a/drivers/net/ice/base/ice_nvm.h b/drivers/net/ice/base/ice_nvm.h
index 552e4659b7..66443c2694 100644
--- a/drivers/net/ice/base/ice_nvm.h
+++ b/drivers/net/ice/base/ice_nvm.h
@@ -108,4 +108,6 @@ int
 ice_read_sr_buf(struct ice_hw *hw, u16 offset, u16 *words, u16 *data);
 int ice_nvm_validate_checksum(struct ice_hw *hw);
 int ice_nvm_recalculate_checksum(struct ice_hw *hw);
+s32 ice_nvm_sanitize_operate(struct ice_hw *hw);
+s32 ice_nvm_sanitize(struct ice_hw *hw, u8 cmd_flags, u8 *values);
 #endif /* _ICE_NVM_H_ */
-- 
2.43.0

Reply via email to