Skip to content

Commit c9f7a48

Browse files
jacob-kelleranguy11
authored andcommitted
ice: move ice_devlink_flash_update and merge with ice_flash_pldm_image
The ice_devlink_flash_update function performs a few upfront checks and then calls ice_flash_pldm_image. Most if these checks make more sense in the context of code within ice_flash_pldm_image. Merge ice_devlink_flash_update and ice_flash_pldm_image into one function, placing it in ice_fw_update.c Since this is still the entry point for devlink, call the function ice_devlink_flash_update instead of ice_flash_pldm_image. This leaves a single function which handles the devlink parameters and then initiates a PLDM update. With this change, the ice_devlink_flash_update function in ice_fw_update.c becomes the main entry point for flash update. It elimintes some unnecessary boiler plate code between the two previous functions. The ultimate motivation for this is that it eases supporting a dry run with the PLDM library in a future change. Signed-off-by: Jacob Keller <[email protected]> Tested-by: Gurucharan G <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent c356eaa commit c9f7a48

File tree

3 files changed

+39
-72
lines changed

3 files changed

+39
-72
lines changed

drivers/net/ethernet/intel/ice/ice_devlink.c

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -370,56 +370,6 @@ static int ice_devlink_info_get(struct devlink *devlink,
370370
return err;
371371
}
372372

373-
/**
374-
* ice_devlink_flash_update - Update firmware stored in flash on the device
375-
* @devlink: pointer to devlink associated with device to update
376-
* @params: flash update parameters
377-
* @extack: netlink extended ACK structure
378-
*
379-
* Perform a device flash update. The bulk of the update logic is contained
380-
* within the ice_flash_pldm_image function.
381-
*
382-
* Returns: zero on success, or an error code on failure.
383-
*/
384-
static int
385-
ice_devlink_flash_update(struct devlink *devlink,
386-
struct devlink_flash_update_params *params,
387-
struct netlink_ext_ack *extack)
388-
{
389-
struct ice_pf *pf = devlink_priv(devlink);
390-
struct ice_hw *hw = &pf->hw;
391-
u8 preservation;
392-
int err;
393-
394-
if (!params->overwrite_mask) {
395-
/* preserve all settings and identifiers */
396-
preservation = ICE_AQC_NVM_PRESERVE_ALL;
397-
} else if (params->overwrite_mask == DEVLINK_FLASH_OVERWRITE_SETTINGS) {
398-
/* overwrite settings, but preserve the vital device identifiers */
399-
preservation = ICE_AQC_NVM_PRESERVE_SELECTED;
400-
} else if (params->overwrite_mask == (DEVLINK_FLASH_OVERWRITE_SETTINGS |
401-
DEVLINK_FLASH_OVERWRITE_IDENTIFIERS)) {
402-
/* overwrite both settings and identifiers, preserve nothing */
403-
preservation = ICE_AQC_NVM_NO_PRESERVATION;
404-
} else {
405-
NL_SET_ERR_MSG_MOD(extack, "Requested overwrite mask is not supported");
406-
return -EOPNOTSUPP;
407-
}
408-
409-
if (!hw->dev_caps.common_cap.nvm_unified_update) {
410-
NL_SET_ERR_MSG_MOD(extack, "Current firmware does not support unified update");
411-
return -EOPNOTSUPP;
412-
}
413-
414-
err = ice_cancel_pending_update(pf, NULL, extack);
415-
if (err)
416-
return err;
417-
418-
devlink_flash_update_status_notify(devlink, "Preparing to flash", NULL, 0, 0);
419-
420-
return ice_flash_pldm_image(pf, params->fw, preservation, extack);
421-
}
422-
423373
static const struct devlink_ops ice_devlink_ops = {
424374
.supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK,
425375
.eswitch_mode_get = ice_eswitch_mode_get,

drivers/net/ethernet/intel/ice/ice_fw_update.c

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,9 @@ static const struct pldmfw_ops ice_fwu_ops = {
652652
*
653653
* Returns: zero on success, or a negative error code on failure.
654654
*/
655-
int ice_cancel_pending_update(struct ice_pf *pf, const char *component,
656-
struct netlink_ext_ack *extack)
655+
static int
656+
ice_cancel_pending_update(struct ice_pf *pf, const char *component,
657+
struct netlink_ext_ack *extack)
657658
{
658659
struct devlink *devlink = priv_to_devlink(pf);
659660
struct device *dev = ice_pf_to_dev(pf);
@@ -737,10 +738,9 @@ int ice_cancel_pending_update(struct ice_pf *pf, const char *component,
737738
}
738739

739740
/**
740-
* ice_flash_pldm_image - Write a PLDM-formatted firmware image to the device
741-
* @pf: private device driver structure
742-
* @fw: firmware object pointing to the relevant firmware file
743-
* @preservation: preservation level to request from firmware
741+
* ice_devlink_flash_update - Write a firmware image to the device
742+
* @devlink: pointer to devlink associated with the device to update
743+
* @params: devlink flash update parameters
744744
* @extack: netlink extended ACK structure
745745
*
746746
* Parse the data for a given firmware file, verifying that it is a valid PLDM
@@ -753,23 +753,35 @@ int ice_cancel_pending_update(struct ice_pf *pf, const char *component,
753753
*
754754
* Returns: zero on success or a negative error code on failure.
755755
*/
756-
int ice_flash_pldm_image(struct ice_pf *pf, const struct firmware *fw,
757-
u8 preservation, struct netlink_ext_ack *extack)
756+
int ice_devlink_flash_update(struct devlink *devlink,
757+
struct devlink_flash_update_params *params,
758+
struct netlink_ext_ack *extack)
758759
{
760+
struct ice_pf *pf = devlink_priv(devlink);
759761
struct device *dev = ice_pf_to_dev(pf);
760762
struct ice_hw *hw = &pf->hw;
761763
struct ice_fwu_priv priv;
764+
u8 preservation;
762765
int err;
763766

764-
switch (preservation) {
765-
case ICE_AQC_NVM_PRESERVE_ALL:
766-
case ICE_AQC_NVM_PRESERVE_SELECTED:
767-
case ICE_AQC_NVM_NO_PRESERVATION:
768-
case ICE_AQC_NVM_FACTORY_DEFAULT:
769-
break;
770-
default:
771-
WARN(1, "Unexpected preservation level request %u", preservation);
772-
return -EINVAL;
767+
if (!params->overwrite_mask) {
768+
/* preserve all settings and identifiers */
769+
preservation = ICE_AQC_NVM_PRESERVE_ALL;
770+
} else if (params->overwrite_mask == DEVLINK_FLASH_OVERWRITE_SETTINGS) {
771+
/* overwrite settings, but preserve the vital device identifiers */
772+
preservation = ICE_AQC_NVM_PRESERVE_SELECTED;
773+
} else if (params->overwrite_mask == (DEVLINK_FLASH_OVERWRITE_SETTINGS |
774+
DEVLINK_FLASH_OVERWRITE_IDENTIFIERS)) {
775+
/* overwrite both settings and identifiers, preserve nothing */
776+
preservation = ICE_AQC_NVM_NO_PRESERVATION;
777+
} else {
778+
NL_SET_ERR_MSG_MOD(extack, "Requested overwrite mask is not supported");
779+
return -EOPNOTSUPP;
780+
}
781+
782+
if (!hw->dev_caps.common_cap.nvm_unified_update) {
783+
NL_SET_ERR_MSG_MOD(extack, "Current firmware does not support unified update");
784+
return -EOPNOTSUPP;
773785
}
774786

775787
memset(&priv, 0, sizeof(priv));
@@ -780,6 +792,12 @@ int ice_flash_pldm_image(struct ice_pf *pf, const struct firmware *fw,
780792
priv.pf = pf;
781793
priv.activate_flags = preservation;
782794

795+
devlink_flash_update_status_notify(devlink, "Preparing to flash", NULL, 0, 0);
796+
797+
err = ice_cancel_pending_update(pf, NULL, extack);
798+
if (err)
799+
return err;
800+
783801
err = ice_acquire_nvm(hw, ICE_RES_WRITE);
784802
if (err) {
785803
dev_err(dev, "Failed to acquire device flash lock, err %d aq_err %s\n",
@@ -788,7 +806,7 @@ int ice_flash_pldm_image(struct ice_pf *pf, const struct firmware *fw,
788806
return err;
789807
}
790808

791-
err = pldmfw_flash_image(&priv.context, fw);
809+
err = pldmfw_flash_image(&priv.context, params->fw);
792810
if (err == -ENOENT) {
793811
dev_err(dev, "Firmware image has no record matching this device\n");
794812
NL_SET_ERR_MSG_MOD(extack, "Firmware image has no record matching this device");

drivers/net/ethernet/intel/ice/ice_fw_update.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
#ifndef _ICE_FW_UPDATE_H_
55
#define _ICE_FW_UPDATE_H_
66

7-
int ice_flash_pldm_image(struct ice_pf *pf, const struct firmware *fw,
8-
u8 preservation, struct netlink_ext_ack *extack);
9-
int ice_cancel_pending_update(struct ice_pf *pf, const char *component,
10-
struct netlink_ext_ack *extack);
7+
int ice_devlink_flash_update(struct devlink *devlink,
8+
struct devlink_flash_update_params *params,
9+
struct netlink_ext_ack *extack);
1110

1211
#endif

0 commit comments

Comments
 (0)