// SPDX-License-Identifier: GPL-2.0 /* Copyright (C) 2018-2019, Intel Corporation. */ #include <linux/unaligned.h> #include <linux/uuid.h> #include <linux/crc32.h> #include <linux/pldmfw.h> #include "ice.h" #include "ice_fw_update.h" struct ice_fwu_priv { … }; /** * ice_send_package_data - Send record package data to firmware * @context: PLDM fw update structure * @data: pointer to the package data * @length: length of the package data * * Send a copy of the package data associated with the PLDM record matching * this device to the firmware. * * Note that this function sends an AdminQ command that will fail unless the * NVM resource has been acquired. * * Returns: zero on success, or a negative error code on failure. */ static int ice_send_package_data(struct pldmfw *context, const u8 *data, u16 length) { … } /** * ice_check_component_response - Report firmware response to a component * @pf: device private data structure * @id: component id being checked * @response: indicates whether this component can be updated * @code: code indicating reason for response * @extack: netlink extended ACK structure * * Check whether firmware indicates if this component can be updated. Report * a suitable error message over the netlink extended ACK if the component * cannot be updated. * * Returns: zero if the component can be updated, or -ECANCELED of the * firmware indicates the component cannot be updated. */ static int ice_check_component_response(struct ice_pf *pf, u16 id, u8 response, u8 code, struct netlink_ext_ack *extack) { … } /** * ice_send_component_table - Send PLDM component table to firmware * @context: PLDM fw update structure * @component: the component to process * @transfer_flag: relative transfer order of this component * * Read relevant data from the component and forward it to the device * firmware. Check the response to determine if the firmware indicates that * the update can proceed. * * This function sends AdminQ commands related to the NVM, and assumes that * the NVM resource has been acquired. * * Returns: zero on success, or a negative error code on failure. */ static int ice_send_component_table(struct pldmfw *context, struct pldmfw_component *component, u8 transfer_flag) { … } /** * ice_write_one_nvm_block - Write an NVM block and await completion response * @pf: the PF data structure * @module: the module to write to * @offset: offset in bytes * @block_size: size of the block to write, up to 4k * @block: pointer to block of data to write * @last_cmd: whether this is the last command * @reset_level: storage for reset level required * @extack: netlink extended ACK structure * * Write a block of data to a flash module, and await for the completion * response message from firmware. * * Note this function assumes the caller has acquired the NVM resource. * * On successful return, reset level indicates the device reset required to * complete the update. * * 0 - ICE_AQC_NVM_POR_FLAG - A full power on is required * 1 - ICE_AQC_NVM_PERST_FLAG - A cold PCIe reset is required * 2 - ICE_AQC_NVM_EMPR_FLAG - An EMP reset is required * * Returns: zero on success, or a negative error code on failure. */ int ice_write_one_nvm_block(struct ice_pf *pf, u16 module, u32 offset, u16 block_size, u8 *block, bool last_cmd, u8 *reset_level, struct netlink_ext_ack *extack) { … } /** * ice_write_nvm_module - Write data to an NVM module * @pf: the PF driver structure * @module: the module id to program * @component: the name of the component being updated * @image: buffer of image data to write to the NVM * @length: length of the buffer * @reset_level: storage for reset level required * @extack: netlink extended ACK structure * * Loop over the data for a given NVM module and program it in 4 Kb * blocks. Notify devlink core of progress after each block is programmed. * Loops over a block of data and programs the NVM in 4k block chunks. * * Note this function assumes the caller has acquired the NVM resource. * * Returns: zero on success, or a negative error code on failure. */ static int ice_write_nvm_module(struct ice_pf *pf, u16 module, const char *component, const u8 *image, u32 length, u8 *reset_level, struct netlink_ext_ack *extack) { … } /* Length in seconds to wait before timing out when erasing a flash module. * Yes, erasing really can take minutes to complete. */ #define ICE_FW_ERASE_TIMEOUT … /** * ice_erase_nvm_module - Erase an NVM module and await firmware completion * @pf: the PF data structure * @module: the module to erase * @component: name of the component being updated * @extack: netlink extended ACK structure * * Erase the inactive NVM bank associated with this module, and await for * a completion response message from firmware. * * Note this function assumes the caller has acquired the NVM resource. * * Returns: zero on success, or a negative error code on failure. */ static int ice_erase_nvm_module(struct ice_pf *pf, u16 module, const char *component, struct netlink_ext_ack *extack) { … } /** * ice_switch_flash_banks - Tell firmware to switch NVM banks * @pf: Pointer to the PF data structure * @activate_flags: flags used for the activation command * @emp_reset_available: on return, indicates if EMP reset is available * @extack: netlink extended ACK structure * * Notify firmware to activate the newly written flash banks, and wait for the * firmware response. * * Returns: zero on success or an error code on failure. */ static int ice_switch_flash_banks(struct ice_pf *pf, u8 activate_flags, u8 *emp_reset_available, struct netlink_ext_ack *extack) { … } /** * ice_flash_component - Flash a component of the NVM * @context: PLDM fw update structure * @component: the component table to program * * Program the flash contents for a given component. First, determine the * module id. Then, erase the secondary bank for this module. Finally, write * the contents of the component to the NVM. * * Note this function assumes the caller has acquired the NVM resource. * * Returns: zero on success, or a negative error code on failure. */ static int ice_flash_component(struct pldmfw *context, struct pldmfw_component *component) { … } /** * ice_finalize_update - Perform last steps to complete device update * @context: PLDM fw update structure * * Called as the last step of the update process. Complete the update by * telling the firmware to switch active banks, and perform a reset of * configured. * * Returns: 0 on success, or an error code on failure. */ static int ice_finalize_update(struct pldmfw *context) { … } struct ice_pldm_pci_record_id { … }; /** * ice_op_pci_match_record - Check if a PCI device matches the record * @context: PLDM fw update structure * @record: list of records extracted from the PLDM image * * Determine if the PCI device associated with this device matches the record * data provided. * * Searches the descriptor TLVs and extracts the relevant descriptor data into * a pldm_pci_record_id. This is then compared against the PCI device ID * information. * * Returns: true if the device matches the record, false otherwise. */ static bool ice_op_pci_match_record(struct pldmfw *context, struct pldmfw_record *record) { … } static const struct pldmfw_ops ice_fwu_ops_e810 = …; static const struct pldmfw_ops ice_fwu_ops_e822 = …; /** * ice_get_pending_updates - Check if the component has a pending update * @pf: the PF driver structure * @pending: on return, bitmap of updates pending * @extack: Netlink extended ACK * * Check if the device has any pending updates on any flash components. * * Returns: zero on success, or a negative error code on failure. Updates * pending with the bitmap of pending updates. */ int ice_get_pending_updates(struct ice_pf *pf, u8 *pending, struct netlink_ext_ack *extack) { … } /** * ice_cancel_pending_update - Cancel any pending update for a component * @pf: the PF driver structure * @component: if not NULL, the name of the component being updated * @extack: Netlink extended ACK structure * * Cancel any pending update for the specified component. If component is * NULL, all device updates will be canceled. * * Returns: zero on success, or a negative error code on failure. */ static int ice_cancel_pending_update(struct ice_pf *pf, const char *component, struct netlink_ext_ack *extack) { … } /** * ice_devlink_flash_update - Write a firmware image to the device * @devlink: pointer to devlink associated with the device to update * @params: devlink flash update parameters * @extack: netlink extended ACK structure * * Parse the data for a given firmware file, verifying that it is a valid PLDM * formatted image that matches this device. * * Extract the device record Package Data and Component Tables and send them * to the firmware. Extract and write the flash data for each of the three * main flash components, "fw.mgmt", "fw.undi", and "fw.netlist". Notify * firmware once the data is written to the inactive banks. * * Returns: zero on success or a negative error code on failure. */ int ice_devlink_flash_update(struct devlink *devlink, struct devlink_flash_update_params *params, struct netlink_ext_ack *extack) { … }