eth: fbnic: Add devlink dev flash support
Subsystems (5)
v4 cover eth: fbnic: Add devlink dev flash support
fbnic supports updating firmware using signed PLDM images. PLDM images are written into the flash. Flashing does not interrupt the operation of the device.
Changes:
V4:
* Tested flashing in a 50x loop
* Add devl_lock() in shutdown / quiescene paths like suspend to prevent interrupting the FW flashing process.
* Add support for multiple completion messages.
* Removed BSD function notation from fbnic_fw_xmit_fw_start_upgrade()
* Mailbox functions no longer return cmpl_data->result
* Add missing error check in fbnic_fw_xmit_fw_write
* Drop setting cmpl->u.fw_update.* to 0
* Set offset and length before validation
* Drop !fw check
* Firmware upgrades are now process driven
* Fix potential memory leak when an error is received in the mailbox when updating.
* Include anti-rollback support
* Drop retries when updating but increase timeout to 10s
* Use NL_SET_ERR_MSG_FMT_MOD in fbnic_devlink_flash_update()
* Updated cover letter, commit messages, and docs as suggested
* Dropped kdocs
* Patched libpldmfw to not require send_package_data or send_component_table which allowed stub functions to be dropped.
* Dropped all dev_*() printks
* Fixed Xmas tree variable declarations
V3 - https://lore.kernel.org/lkml/[email protected]/T/
* Fix comments
V2 - https://lore.kernel.org/all/[email protected]/
* Fixed reversed Xmas tree variable declarations
* Replaced memcpy with strscpy
Lee Trager (5):
pldmfw: Don't require send_package_data or send_component_table to be
defined
eth: fbnic: Accept minimum anti-rollback version from firmware
eth: fbnic: Add support for multiple concurrent completion messages
eth: fbnic: Add mailbox support for PLDM updates
eth: fbnic: Add devlink dev flash support
.../device_drivers/ethernet/meta/fbnic.rst | 11 + drivers/net/ethernet/meta/Kconfig | 1 + drivers/net/ethernet/meta/fbnic/fbnic.h | 3 +- .../net/ethernet/meta/fbnic/fbnic_devlink.c | 260 +++++++++++++++- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 294 ++++++++++++++++-- drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 53 +++- drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 2 +- drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 9 + lib/pldmfw/pldmfw.c | 6 + 9 files changed, 616 insertions(+), 23 deletions(-)
--
2.47.1
PATCH v4 1/5 pldmfw: Don't require send_package_data or send_component_table to be defined
Not all drivers require send_package_data or send_component_table when updating firmware. Instead of forcing drivers to implement a stub allow these functions to go undefined.
--- lib/pldmfw/pldmfw.c | 6 ++++++ 1 file changed, 6 insertions(+)
lib/pldmfw/pldmfw.c +6 -0
@@ -728,6 +728,9 @@ pldm_send_package_data(struct pldmfw_priv *data)struct pldmfw_record *record = data->matching_record;const struct pldmfw_ops *ops = data->context->ops; +if (!ops->send_package_data) +return 0 ; +return ops->send_package_data (data->context, record->package_data, record->package_data_len); }
@@ -755,6 +758,9 @@ pldm_send_component_tables(struct pldmfw_priv *data)if (!test_bit (index, bitmap))continue ; +if (!data->context->ops->send_component_table) +continue ; +/* determine whether this is the start, middle, end, or both * the start and end of the component tables */
--
2.47.1
Re: [PATCH net-next v4 1/5] pldmfw: Don't require send_package_data or send_component_table to be defined
Quoted 6 lines · Lee Trager
Not all drivers require
send_package_dataorsend_component_tablewhen updating firmware. Instead of forcing drivers to implement a stub allow these functions to go undefined.Signed-off-by Lee Trager <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
Re: [PATCH net-next v4 1/5] pldmfw: Don't require send_package_data or send_component_table to be defined
In reply to Lee TragerQuoted 6 lines · Lee Trager
Not all drivers require
send_package_dataorsend_component_tablewhen updating firmware. Instead of forcing drivers to implement a stub allow these functions to go undefined.Signed-off-by Lee Trager <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
Makes sense.
Quoted 30 lines
--- lib/pldmfw/pldmfw.c | 6 ++++++ 1 file changed, 6 insertions(+)lib/pldmfw/pldmfw.c +6
-1@@ -728,6 +728,9 @@ pldm_send_package_data(struct pldmfw_priv *data)struct pldmfw_record *record = data->matching_record;const struct pldmfw_ops *ops = data->context->ops; +if (!ops->send_package_data) +return 0 ; +return ops->send_package_data (data->context, record->package_data, record->package_data_len); }@@ -755,6 +758,9 @@ pldm_send_component_tables(struct pldmfw_priv *data)if (!test_bit (index, bitmap))continue ; +if (!data->context->ops->send_component_table) +continue ; +/* determine whether this is the start, middle, end, or both * the start and end of the component tables */ --2.47.1
PATCH v4 2/5 eth: fbnic: Accept minimum anti-rollback version from firmware
In reply to Lee Tragerfbnic supports applying firmware which may not be rolled back. This is implemented in firmware however it is useful for the driver to know the minimum supported firmware version. This will enable the driver validate new firmware before it is sent to the NIC. If it is too old the driver can provide a clear message that the version is too old.
--- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 4 ++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 2 ++ 2 files changed, 6 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +4 -0
@@ -464,6 +464,7 @@ static const struct fbnic_tlv_index fbnic_fw_cap_resp_index[] = {FBNIC_TLV_ATTR_U32 (FBNIC_FW_CAP_RESP_UEFI_VERSION ),FBNIC_TLV_ATTR_STRING (FBNIC_FW_CAP_RESP_UEFI_COMMIT_STR ,FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE ), +FBNIC_TLV_ATTR_U32 (FBNIC_FW_CAP_RESP_ANTI_ROLLBACK_VERSION ), FBNIC_TLV_ATTR_LAST };
@@ -586,6 +587,9 @@ static int fbnic_fw_parse_cap_resp(void *opaque, struct fbnic_tlv_msg **results)if (results[FBNIC_FW_CAP_RESP_BMC_ALL_MULTI ] || !bmc_present) fbd->fw_cap.all_multi = all_multi; + fbd->fw_cap.anti_rollback_version = +fta_get_uint (results,FBNIC_FW_CAP_RESP_ANTI_ROLLBACK_VERSION ); +return 0 ; }
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +2 -0
@@ -42,6 +42,7 @@ struct fbnic_fw_cap { u8 all_multi : 1;u8 link_speed;u8 link_fec; +u32 anti_rollback_version; };struct fbnic_fw_completion {
@@ -122,6 +123,7 @@ enum {FBNIC_FW_CAP_RESP_STORED_CMRT_COMMIT_STR =0x10 ,FBNIC_FW_CAP_RESP_UEFI_VERSION =0x11 ,FBNIC_FW_CAP_RESP_UEFI_COMMIT_STR =0x12 , +FBNIC_FW_CAP_RESP_ANTI_ROLLBACK_VERSION =0x15 , FBNIC_FW_CAP_RESP_MSG_MAX };
--
2.47.1
Re: [PATCH net-next v4 2/5] eth: fbnic: Accept minimum anti-rollback version from firmware
Quoted 8 lines · Lee Trager
fbnic supports applying firmware which may not be rolled back. This is implemented in firmware however it is useful for the driver to know the minimum supported firmware version. This will enable the driver validate new firmware before it is sent to the NIC. If it is too old the driver can provide a clear message that the version is too old.
Signed-off-by Lee Trager <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
Jacob Keller
maintainerRe: [PATCH net-next v4 2/5] eth: fbnic: Accept minimum anti-rollback version from firmware
In reply to Lee TragerQuoted 6 lines · Lee Trager
fbnic supports applying firmware which may not be rolled back. This is implemented in firmware however it is useful for the driver to know the minimum supported firmware version. This will enable the driver validate new firmware before it is sent to the NIC. If it is too old the driver can provide a clear message that the version is too old.
This reminds me of the original efforts i had with minimum firmware versions for the ice E810 hardware.
I guess for fbnic, you entirely handle this within firmware so there's no reason to provide an interface to control this, and you have a lot more control over verifying that the anti-rollback behavior is correct.
The definition for the minimum version is baked into the firmware image? So once a version with this anti-rollback is applied it then prevents you from rolling back to lower version, and can do a verification to enforce this. Unlike the similar "opt-in" behavior in ice which requires a user to first apply a firmware and then set the parameter, opening up a bunch of attestation issues due to not being a single atomic operation.
Re: [PATCH net-next v4 2/5] eth: fbnic: Accept minimum anti-rollback version from firmware
Quoted 15 lines · Jacob Keller
Quoted 6 lines · Lee Trager
fbnic supports applying firmware which may not be rolled back. This is implemented in firmware however it is useful for the driver to know the minimum supported firmware version. This will enable the driver validate new firmware before it is sent to the NIC. If it is too old the driver can provide a clear message that the version is too old.
This reminds me of the original efforts i had with minimum firmware versions for the ice E810 hardware.
I guess for fbnic, you entirely handle this within firmware so there's no reason to provide an interface to control this, and you have a lot more control over verifying that the anti-rollback behavior is correct.
Quoted 6 lines
The definition for the minimum version is baked into the firmware image? So once a version with this anti-rollback is applied it then prevents you from rolling back to lower version, and can do a verification to enforce this. Unlike the similar "opt-in" behavior in ice which requires a user to first apply a firmware and then set the parameter, opening up a bunch of attestation issues due to not being a single atomic operation.
Correct this is handled entirely in firmware. We use the normal firmware update process when incrementing anti-rollback. During the updating process firmware first validates that the new version number is >= to the anti rollback version set in the SOTP. If not the update is rejected. The drivers role is purely informational, it checks anti roll back and provides devlink with a human readable error when necessary.
When incrementing anti rollback the NIC first boots the new firmware. Once it has validated it can boot the new firmware it increments the anti roll back version in the SOTP automatically. This makes anti roll back automatic and provides a way for us to abort the process if needed.
PATCH v4 3/5 eth: fbnic: Add support for multiple concurrent completion messages
In reply to Lee TragerExtend fbnic mailbox to support multiple concurrent completion messages at once. This enables fbnic to support running multiple operations at once which depend on a response from firmware via the mailbox.
--- drivers/net/ethernet/meta/fbnic/fbnic.h | 3 +- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 99 +++++++++++++++++---- drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 5 +- drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 2 +- 4 files changed, 87 insertions(+), 22 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic.h +2 -1
@@ -19,6 +19,7 @@struct fbnic_napi_vector ;#define FBNIC_MAX_NAPI_VECTORS 128u +#define FBNIC_MBX_CMPL_SLOTS 4struct fbnic_dev {struct device *dev;
@@ -42,7 +43,7 @@ struct fbnic_dev {struct fbnic_fw_mbx mbx[FBNIC_IPC_MBX_INDICES ];struct fbnic_fw_cap fw_cap; -struct fbnic_fw_completion *cmpl_data; +struct fbnic_fw_completion *cmpl_data[FBNIC_MBX_CMPL_SLOTS ];/* Lock protecting Tx Mailbox queue to prevent possible races */ spinlock_t fw_tx_lock;
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +80 -19
149 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +4 -1
@@ -60,6 +60,8 @@ struct fbnic_fw_completion {void fbnic_mbx_init (struct fbnic_dev *fbd);void fbnic_mbx_clean (struct fbnic_dev *fbd); +int fbnic_mbx_set_cmpl (struct fbnic_dev *fbd, +struct fbnic_fw_completion *cmpl_data);void fbnic_mbx_poll (struct fbnic_dev *fbd);int fbnic_mbx_poll_tx_ready (struct fbnic_dev *fbd);void fbnic_mbx_flush_tx (struct fbnic_dev *fbd);
@@ -70,7 +72,8 @@ int fbnic_fw_xmit_tsene_read_msg(struct fbnic_dev *fbd, struct fbnic_fw_completion *cmpl_data);void fbnic_fw_init_cmpl (struct fbnic_fw_completion *cmpl_data,u32 msg_type); -void fbnic_fw_clear_compl (struct fbnic_dev *fbd); +void fbnic_fw_clear_cmpl (struct fbnic_dev *fbd, +struct fbnic_fw_completion *cmpl_data);void fbnic_fw_put_cmpl (struct fbnic_fw_completion *cmpl_data);#define fbnic_mk_full_fw_ver_str (_rev_id, _delim, _commit, _str, _str_sz) \
drivers/net/ethernet/meta/fbnic/fbnic_mac.c +1 -1
@@ -744,7 +744,7 @@ static int fbnic_mac_get_sensor_asic(struct fbnic_dev *fbd, int id, *val = *sensor; exit_cleanup: -fbnic_fw_clear_compl (fbd); +fbnic_fw_clear_cmpl (fbd, fw_cmpl); exit_free:fbnic_fw_put_cmpl (fw_cmpl);
--
2.47.1
Re: [PATCH net-next v4 3/5] eth: fbnic: Add support for multiple concurrent completion messages
Quoted 6 lines · Lee Trager
Extend fbnic mailbox to support multiple concurrent completion messages at once. This enables fbnic to support running multiple operations at once which depend on a response from firmware via the mailbox.
Signed-off-by Lee Trager <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
PATCH v4 4/5 eth: fbnic: Add mailbox support for PLDM updates
In reply to Lee TragerAdd three new mailbox messages to support PLDM upgrades:
* FW_START_UPGRADE - Enables driver to request starting a firmware upgrade by specifying the component to be upgraded and its size.
* WRITE_CHUNK - Allows firmware to request driver to send a chunk of
data at the specified offset.
* FINISH_UPGRADE - Allows firmware to cancel the upgrade process and
return an error.
--- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 191 +++++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 37 ++++ 2 files changed, 228 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +191 -0
@@ -766,6 +766,188 @@ void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd)dev_warn (fbd->dev,"Failed to send heartbeat message\n" ); } +int fbnic_fw_xmit_fw_start_upgrade (struct fbnic_dev *fbd, +struct fbnic_fw_completion *cmpl_data, +unsigned int id,unsigned int len) +{ +struct fbnic_tlv_msg *msg; +int err; + +if (!fbnic_fw_present (fbd)) +return -ENODEV ; + +if (!len) +return -EINVAL ; + + msg =fbnic_tlv_msg_alloc (FBNIC_TLV_MSG_ID_FW_START_UPGRADE_REQ ); +if (!msg) +return -ENOMEM ; + + err =fbnic_tlv_attr_put_int (msg,FBNIC_FW_START_UPGRADE_SECTION , id); +if (err) + goto free_message; + + err =fbnic_tlv_attr_put_int (msg,FBNIC_FW_START_UPGRADE_IMAGE_LENGTH , + len); +if (err) + goto free_message; + + err =fbnic_mbx_map_req_w_cmpl (fbd, msg, cmpl_data); +if (err) + goto free_message; + +return 0 ; + +free_message: +free_page ((unsigned long )msg); +return err; +} + +static const struct fbnic_tlv_index fbnic_fw_start_upgrade_resp_index[] = { +FBNIC_TLV_ATTR_S32 (FBNIC_FW_START_UPGRADE_ERROR ), +FBNIC_TLV_ATTR_LAST +}; + +static int fbnic_fw_parse_fw_start_upgrade_resp (void *opaque, +struct fbnic_tlv_msg **results) +{ +struct fbnic_fw_completion *cmpl_data; +struct fbnic_dev *fbd = opaque; +u32 msg_type; +s32 err; + +/* Verify we have a completion pointer */ + msg_type =FBNIC_TLV_MSG_ID_FW_START_UPGRADE_REQ ; + cmpl_data =fbnic_fw_get_cmpl_by_type (fbd, msg_type); +if (!cmpl_data) +return -ENOSPC ; + +/* Check for errors */ + err =fta_get_sint (results,FBNIC_FW_START_UPGRADE_ERROR ); + + cmpl_data->result = err; +complete (&cmpl_data->done); +fbnic_fw_put_cmpl (cmpl_data); + +return 0 ; +} + +int fbnic_fw_xmit_fw_write_chunk (struct fbnic_dev *fbd, +const u8 *data,u32 offset,u16 length, +int cancel_error) +{ +struct fbnic_tlv_msg *msg; +int err; + + msg =fbnic_tlv_msg_alloc (FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_RESP ); +if (!msg) +return -ENOMEM ; + +/* Report error to FW to cancel upgrade */ +if (cancel_error) { + err =fbnic_tlv_attr_put_int (msg,FBNIC_FW_WRITE_CHUNK_ERROR , + cancel_error); +if (err) + goto free_message; + } + +if (data) { + err =fbnic_tlv_attr_put_int (msg,FBNIC_FW_WRITE_CHUNK_OFFSET , + offset); +if (err) + goto free_message; + + err =fbnic_tlv_attr_put_int (msg,FBNIC_FW_WRITE_CHUNK_LENGTH , + length); +if (err) + goto free_message; + + err =fbnic_tlv_attr_put_value (msg,FBNIC_FW_WRITE_CHUNK_DATA , + data + offset, length); +if (err) + goto free_message; + } + + err =fbnic_mbx_map_tlv_msg (fbd, msg); +if (err) + goto free_message; + +return 0 ; + +free_message: +free_page ((unsigned long )msg); +return err; +} + +static const struct fbnic_tlv_index fbnic_fw_write_chunk_req_index[] = { +FBNIC_TLV_ATTR_U32 (FBNIC_FW_WRITE_CHUNK_OFFSET ), +FBNIC_TLV_ATTR_U32 (FBNIC_FW_WRITE_CHUNK_LENGTH ), +FBNIC_TLV_ATTR_LAST +}; + +static int fbnic_fw_parse_fw_write_chunk_req (void *opaque, +struct fbnic_tlv_msg **results) +{ +struct fbnic_fw_completion *cmpl_data; +struct fbnic_dev *fbd = opaque; +u32 msg_type; +u32 offset; +u32 length; + +/* Verify we have a completion pointer */ + msg_type =FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ ; + cmpl_data =fbnic_fw_get_cmpl_by_type (fbd, msg_type); +if (!cmpl_data) +return -ENOSPC ; + +/* Pull length/offset pair and mark it as complete */ + offset =fta_get_uint (results,FBNIC_FW_WRITE_CHUNK_OFFSET ); + length =fta_get_uint (results,FBNIC_FW_WRITE_CHUNK_LENGTH ); + cmpl_data->u.fw_update.offset = offset; + cmpl_data->u.fw_update.length = length; + +complete (&cmpl_data->done); +fbnic_fw_put_cmpl (cmpl_data); + +return 0 ; +} + +static const struct fbnic_tlv_index fbnic_fw_finish_upgrade_req_index[] = { +FBNIC_TLV_ATTR_S32 (FBNIC_FW_FINISH_UPGRADE_ERROR ), +FBNIC_TLV_ATTR_LAST +}; + +static int fbnic_fw_parse_fw_finish_upgrade_req (void *opaque, +struct fbnic_tlv_msg **results) +{ +struct fbnic_fw_completion *cmpl_data; +struct fbnic_dev *fbd = opaque; +u32 msg_type; +s32 err; + +/* Verify we have a completion pointer */ + msg_type =FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ ; + cmpl_data =fbnic_fw_get_cmpl_by_type (fbd, msg_type); +if (!cmpl_data) +return -ENOSPC ; + +/* Check for errors */ + err =fta_get_sint (results,FBNIC_FW_FINISH_UPGRADE_ERROR ); + +/* Close out update by incrementing offset by length which should +* match the total size of the component. Set length to 0 since no +* new chunks will be requested. +*/ + cmpl_data->u.fw_update.offset += cmpl_data->u.fw_update.length; + cmpl_data->u.fw_update.length =0 ; + + cmpl_data->result = err; +complete (&cmpl_data->done); +fbnic_fw_put_cmpl (cmpl_data); + +return 0 ; +} +/** * fbnic_fw_xmit_tsene_read_msg - Create and transmit a sensor read request * @fbd: FBNIC device structure
@@ -850,6 +1032,15 @@ static const struct fbnic_tlv_parser fbnic_fw_tlv_parser[] = { fbnic_fw_parse_ownership_resp),FBNIC_TLV_PARSER (HEARTBEAT_RESP , fbnic_heartbeat_resp_index, fbnic_fw_parse_heartbeat_resp), +FBNIC_TLV_PARSER (FW_START_UPGRADE_RESP , + fbnic_fw_start_upgrade_resp_index, + fbnic_fw_parse_fw_start_upgrade_resp), +FBNIC_TLV_PARSER (FW_WRITE_CHUNK_REQ , + fbnic_fw_write_chunk_req_index, + fbnic_fw_parse_fw_write_chunk_req), +FBNIC_TLV_PARSER (FW_FINISH_UPGRADE_REQ , + fbnic_fw_finish_upgrade_req_index, + fbnic_fw_parse_fw_finish_upgrade_req),FBNIC_TLV_PARSER (TSENE_READ_RESP , fbnic_tsene_read_resp_index, fbnic_fw_parse_tsene_read_resp),
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +37 -0
@@ -51,6 +51,10 @@ struct fbnic_fw_completion {struct kref ref_count;int result;union { +struct { +u32 offset; +u32 length; + } fw_update;struct {s32 millivolts;s32 millidegrees;
@@ -68,6 +72,12 @@ void fbnic_mbx_flush_tx(struct fbnic_dev *fbd);int fbnic_fw_xmit_ownership_msg (struct fbnic_dev *fbd,bool take_ownership);int fbnic_fw_init_heartbeat (struct fbnic_dev *fbd,bool poll);void fbnic_fw_check_heartbeat (struct fbnic_dev *fbd); +int fbnic_fw_xmit_fw_start_upgrade (struct fbnic_dev *fbd, +struct fbnic_fw_completion *cmpl_data, +unsigned int id,unsigned int len); +int fbnic_fw_xmit_fw_write_chunk (struct fbnic_dev *fbd, +const u8 *data,u32 offset,u16 length, +int cancel_error);int fbnic_fw_xmit_tsene_read_msg (struct fbnic_dev *fbd,struct fbnic_fw_completion *cmpl_data); void fbnic_fw_init_cmpl(struct fbnic_fw_completion *cmpl_data,
@@ -99,6 +109,12 @@ enum {FBNIC_TLV_MSG_ID_OWNERSHIP_RESP =0x13 ,FBNIC_TLV_MSG_ID_HEARTBEAT_REQ =0x14 ,FBNIC_TLV_MSG_ID_HEARTBEAT_RESP =0x15 , +FBNIC_TLV_MSG_ID_FW_START_UPGRADE_REQ =0x22 , +FBNIC_TLV_MSG_ID_FW_START_UPGRADE_RESP =0x23 , +FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ =0x24 , +FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_RESP =0x25 , +FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_REQ =0x28 , +FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_RESP =0x29 ,FBNIC_TLV_MSG_ID_TSENE_READ_REQ =0x3C , FBNIC_TLV_MSG_ID_TSENE_READ_RESP = 0x3D, };
@@ -154,4 +170,25 @@ enum {FBNIC_FW_OWNERSHIP_FLAG =0x0 ,FBNIC_FW_OWNERSHIP_MSG_MAX }; + +enum { +FBNIC_FW_START_UPGRADE_ERROR =0x0 , +FBNIC_FW_START_UPGRADE_SECTION =0x1 , +FBNIC_FW_START_UPGRADE_IMAGE_LENGTH =0x2 , +FBNIC_FW_START_UPGRADE_MSG_MAX +}; + +enum { +FBNIC_FW_WRITE_CHUNK_OFFSET =0x0 , +FBNIC_FW_WRITE_CHUNK_LENGTH =0x1 , +FBNIC_FW_WRITE_CHUNK_DATA =0x2 , +FBNIC_FW_WRITE_CHUNK_ERROR =0x3 , +FBNIC_FW_WRITE_CHUNK_MSG_MAX +}; + +enum { +FBNIC_FW_FINISH_UPGRADE_ERROR =0x0 , +FBNIC_FW_FINISH_UPGRADE_MSG_MAX +}; +#endif /* _FBNIC_FW_H_ */
--
2.47.1
Re: [PATCH net-next v4 4/5] eth: fbnic: Add mailbox support for PLDM updates
Quoted 10 lines · Lee Trager
Add three new mailbox messages to support PLDM upgrades:
*
FW_START_UPGRADE- Enables driver to request starting a firmware upgrade by specifying the component to be upgraded and its size.
*WRITE_CHUNK- Allows firmware to request driver to send a chunk of
data at the specified offset.
*FINISH_UPGRADE- Allows firmware to cancel the upgrade process and
return an error.
Quoted 2 lines
Signed-off-by Lee Trager <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
PATCH v4 5/5 eth: fbnic: Add devlink dev flash support
In reply to Lee TragerAdd support to update the CMRT and control firmware as well as the UEFI driver on fbnic using devlink dev flash.
Make sure the shutdown / quiescence paths like suspend take the devlink lock to prevent them from interrupting the FW flashing process.
--- .../device_drivers/ethernet/meta/fbnic.rst | 11 + drivers/net/ethernet/meta/Kconfig | 1 + .../net/ethernet/meta/fbnic/fbnic_devlink.c | 260 +++++++++++++++++- drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 9 + drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 9 + 5 files changed, 289 insertions(+), 1 deletion(-)
Documentation/networking/device_drivers/ethernet/meta/fbnic.rst +11 -0
@@ -28,6 +28,17 @@ devlink dev info provides version information for all three components. In addition to the version the hg commit hash of the build is included as a separate entry. +Upgrading Firmware +------------------ + +fbnic supports updating firmware using signed PLDM images with devlink dev +flash. PLDM images are written into the flash. Flashing does not interrupt +the operation of the device. + +On host boot the latest UEFI driver is always used, no explicit activation +is required. Firmware activation is required to run new control firmware. cmrt +firmware can only be activated by power cycling the NIC. + Statistics ----------
drivers/net/ethernet/meta/Kconfig +1 -0
@@ -27,6 +27,7 @@ config FBNIC select NET_DEVLINK select PAGE_POOL select PHYLINK + select PLDMFW help This driver supports Meta Platforms Host Network Interface.
drivers/net/ethernet/meta/fbnic/fbnic_devlink.c +259 -1
277 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +9 -0
@@ -100,6 +100,15 @@ do { \#define fbnic_mk_fw_ver_str (_rev_id, _str) \ fbnic_mk_full_fw_ver_str(_rev_id, "", "", _str, sizeof(_str)) +enum { +QSPI_SECTION_CMRT =0 , +QSPI_SECTION_CONTROL_FW =1 , +QSPI_SECTION_UCODE =2 , +QSPI_SECTION_OPTION_ROM =3 , +QSPI_SECTION_USER =4 , +QSPI_SECTION_INVALID , +}; +#define FW_HEARTBEAT_PERIOD (10 * HZ)enum {
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +9 -0
@@ -6,6 +6,7 @@#include <linux/pci.h> #include <linux/rtnetlink.h> #include <linux/types.h> +#include <net/devlink.h> #include "fbnic.h" #include "fbnic_drvinfo.h"
@@ -388,8 +389,12 @@ static int fbnic_pm_suspend(struct device *dev)rtnl_unlock (); null_uc_addr: +devl_lock (priv_to_devlink (fbd)); +fbnic_fw_free_mbx (fbd); +devl_unlock (priv_to_devlink (fbd)); +/* Free the IRQs so they aren't trying to occupy sleeping CPUs */ fbnic_free_irqs (fbd);
@@ -420,11 +425,15 @@ static int __fbnic_pm_resume(struct device *dev) fbd->mac->init_regs (fbd); +devl_lock (priv_to_devlink (fbd)); +/* Re-enable mailbox */ err =fbnic_fw_request_mbx (fbd);if (err) goto err_free_irqs; +devl_unlock (priv_to_devlink (fbd)); +/* No netdev means there isn't a network interface to bring up */ if (fbnic_init_failure (fbd))return 0 ;
--
2.47.1
Simon Horman
reviewerQuoted 8 lines · Lee Trager
Add support to update the CMRT and control firmware as well as the UEFI driver on fbnic using devlink dev flash.
Make sure the shutdown / quiescence paths like suspend take the devlink lock to prevent them from interrupting the FW flashing process.
Signed-off-by Lee Trager <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
...
Quoted 1 line
drivers/net/ethernet/meta/fbnic/fbnic_devlink.c +0
-0
...
Quoted 6 lines
drivers/net/ethernet/meta/fbnic/fbnic_devlink.c +2
-0@@ -109,8 +111,264 @@ static int fbnic_devlink_info_get(struct devlink *devlink,return 0 ; } +static bool +fbnic_pldm_match_record (struct pldmfw *context,struct pldmfw_record *record)
drivers/net/ethernet/meta/fbnic/fbnic_devlink.c static int fbnic_devlink_info_get(struct devlink *devlink, · line 125
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_devlink.c +10
-0+{ +struct pldmfw_desc_tlv *desc; +u32 anti_rollback_ver =0 ; +struct devlink *devlink; +struct fbnic_dev *fbd; +struct pci_dev *pdev; + +/* First, use the standard PCI matching function */ +if (!pldmfw_op_pci_match_record (context, record)) +return -ENODEV ;
Hi Lee,
The return type of this function is bool, but here a negative integer is being returned. Perhaps this should be:
return false;
Flagged by Smatch
Quoted 36 lines
drivers/net/ethernet/meta/fbnic/fbnic_devlink.c +36
-0+ + pdev =to_pci_dev (context->dev); + fbd =pci_get_drvdata (pdev); + devlink =priv_to_devlink (fbd); + +/* If PCI match is successful, check for vendor-specific descriptors */ +list_for_each_entry (desc, &record->descs, entry) { +if (desc->type !=PLDM_DESC_ID_VENDOR_DEFINED ) +continue ; + +if (desc->size <21 || desc->data[0 ] !=1 || + desc->data[1 ] !=15 ) +continue ; + +if (memcmp (desc->data +2 ,"AntiRollbackVer" ,15 ) !=0 ) +continue ; + + anti_rollback_ver =get_unaligned_le32 (desc->data +17 ); +break ; + } + +/* Compare versions and return error if they do not match */ +if (anti_rollback_ver < fbd->fw_cap.anti_rollback_version) { +char buf[128 ]; + +snprintf (buf,sizeof (buf), +"New firmware anti-rollback version (0x%x) is older than device version (0x%x)!" , + anti_rollback_ver, fbd->fw_cap.anti_rollback_version); +devlink_flash_update_status_notify (devlink, buf, +"Anti-Rollback" ,0 ,0 ); + +return false; + } + +return true; +}
...
Quoted 9 lines · Lee Trager
Add support to update the CMRT and control firmware as well as the UEFI driver on fbnic using devlink dev flash.
Make sure the shutdown / quiescence paths like suspend take the devlink lock to prevent them from interrupting the FW flashing process.
Signed-off-by Lee Trager <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>---
Glad to see the work I put into the lib/pldmfw is able to be re-used!