* [PATCH net-next 0/2] eth: fbnic: Add devlink dev flash support
@ 2024-10-12 2:34 Lee Trager
2024-10-12 2:34 ` [PATCH net-next 1/2] eth: fbnic: Add mailbox support for PLDM updates Lee Trager
` (4 more replies)
0 siblings, 5 replies; 15+ messages in thread
From: Lee Trager @ 2024-10-12 2:34 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Mohsin Bashir,
Simon Horman, Lee Trager, Vadim Fedorenko, Sanman Pradhan,
Al Viro
Cc: netdev, linux-doc, linux-kernel
fbnic supports updating firmware using a PLDM image signed and distributed
by Meta. PLDM images are written into stored flash. Flashing does not
interrupt operation.
Mailbox support additional adds support to utilize the kernel completion
API with firmware. This allows the driver to block on firmware response.
Initial support is only for firmware updates, future patches will add
support for additional features.
Lee Trager (2):
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 | 1 +
.../net/ethernet/meta/fbnic/fbnic_devlink.c | 270 +++++++++++++++++-
drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 263 +++++++++++++++++
drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 59 ++++
6 files changed, 604 insertions(+), 1 deletion(-)
--
2.43.5
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net-next 1/2] eth: fbnic: Add mailbox support for PLDM updates
2024-10-12 2:34 [PATCH net-next 0/2] eth: fbnic: Add devlink dev flash support Lee Trager
@ 2024-10-12 2:34 ` Lee Trager
2024-10-14 11:05 ` Vadim Fedorenko
2024-10-12 2:34 ` [PATCH net-next 2/2] eth: fbnic: Add devlink dev flash support Lee Trager
` (3 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Lee Trager @ 2024-10-12 2:34 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Mohsin Bashir,
Simon Horman, Lee Trager, Vadim Fedorenko, Sanman Pradhan,
Al Viro
Cc: netdev, linux-doc, linux-kernel
This adds driver support to utilize the kernel completion API. This allows
the driver to block on a response from firmware. Initially
fbnic_fw_completion only has support for updates, future patches will add
additional features.
Signed-off-by: Lee Trager <lee@trager.us>
---
drivers/net/ethernet/meta/fbnic/fbnic.h | 1 +
drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 263 +++++++++++++++++++++
drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 59 +++++
3 files changed, 323 insertions(+)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic.h b/drivers/net/ethernet/meta/fbnic/fbnic.h
index ca59261f0155..f58727e6e45a 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic.h
+++ b/drivers/net/ethernet/meta/fbnic/fbnic.h
@@ -31,6 +31,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;
/* Lock protecting Tx Mailbox queue to prevent possible races */
spinlock_t fw_tx_lock;
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
index 8f7a2a19ddf8..deebff3b6821 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
@@ -207,6 +207,38 @@ static int fbnic_mbx_map_tlv_msg(struct fbnic_dev *fbd,
return err;
}
+static int fbnic_mbx_map_req_w_cmpl(struct fbnic_dev *fbd,
+ struct fbnic_tlv_msg *msg,
+ struct fbnic_fw_completion *cmpl_data)
+{
+ unsigned long flags;
+ int err;
+
+ spin_lock_irqsave(&fbd->fw_tx_lock, flags);
+
+ /* If we are already waiting on a completion then abort */
+ if (cmpl_data && fbd->cmpl_data) {
+ err = -EBUSY;
+ goto unlock_mbx;
+ }
+
+ /* Record completion location and submit request */
+ if (cmpl_data)
+ fbd->cmpl_data = cmpl_data;
+
+ err = fbnic_mbx_map_msg(fbd, FBNIC_IPC_MBX_TX_IDX, msg,
+ le16_to_cpu(msg->hdr.len) * sizeof(u32), 1);
+
+ /* If msg failed then clear completion data for next caller */
+ if (err && cmpl_data)
+ fbd->cmpl_data = NULL;
+
+unlock_mbx:
+ spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
+
+ return err;
+}
+
static void fbnic_mbx_process_tx_msgs(struct fbnic_dev *fbd)
{
struct fbnic_fw_mbx *tx_mbx = &fbd->mbx[FBNIC_IPC_MBX_TX_IDX];
@@ -651,6 +683,225 @@ void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd)
dev_warn(fbd->dev, "Failed to send heartbeat message\n");
}
+/**
+ * fbnic_fw_xmit_fw_start_upgrade - Create and transmit a start update message
+ * @fbd: FBNIC device structure
+ * @cmpl_data: Completion data for upgrade process
+ * @id: Component ID
+ * @len: Length of FW update package data
+ *
+ * Return: zero on success, negative value on failure
+ *
+ * Asks the FW to prepare for starting a firmware upgrade
+ */
+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 (!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_dev *fbd = opaque;
+ struct fbnic_fw_completion *cmpl_data;
+ int err = 0;
+
+ /* Verify we have a completion pointer */
+ cmpl_data = READ_ONCE(fbd->cmpl_data);
+ if (!cmpl_data ||
+ cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ)
+ return -ENOSPC;
+
+ /* Check for errors */
+ get_signed_result(FBNIC_FW_START_UPGRADE_ERROR, err);
+
+ cmpl_data->result = err;
+ complete(&cmpl_data->done);
+
+ return 0;
+}
+
+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_dev *fbd = opaque;
+ struct fbnic_fw_completion *cmpl_data;
+ u32 length = 0, offset = 0;
+ struct fbnic_tlv_msg *msg;
+ int err;
+
+ /* Start by attempting to allocate a response to the message */
+ msg = fbnic_tlv_msg_alloc(FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_RESP);
+ if (!msg)
+ return -ENOMEM;
+
+ /* Verify we have a completion pointer */
+ cmpl_data = READ_ONCE(fbd->cmpl_data);
+ if (!cmpl_data ||
+ cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ) {
+ err = -ENOSPC;
+ goto msg_err;
+ }
+
+ /* Notify FW if the data link has been severed */
+ if (!cmpl_data->fw_update.data) {
+ err = -ECANCELED;
+ goto msg_err;
+ }
+
+ /* Pull length/offset pair and mark it as complete */
+ get_unsigned_result(FBNIC_FW_WRITE_CHUNK_OFFSET, offset);
+ get_unsigned_result(FBNIC_FW_WRITE_CHUNK_LENGTH, length);
+
+ /* Record offset and length for the response */
+ if (offset) {
+ err = fbnic_tlv_attr_put_int(msg, FBNIC_FW_WRITE_CHUNK_OFFSET,
+ offset);
+ if (err)
+ goto msg_err;
+ }
+
+ err = fbnic_tlv_attr_put_int(msg, FBNIC_FW_WRITE_CHUNK_LENGTH,
+ length);
+ if (err)
+ goto msg_err;
+
+ /* Verify length */
+ if (!length || length > TLV_MAX_DATA) {
+ err = -EINVAL;
+ goto msg_err;
+ }
+
+ /* Verify offset and length are within bounds */
+ if (offset >= cmpl_data->fw_update.size ||
+ offset + length > cmpl_data->fw_update.size) {
+ err = -EFAULT;
+ goto msg_err;
+ }
+
+ /* Add outbound data to message */
+ err = fbnic_tlv_attr_put_value(msg, FBNIC_FW_WRITE_CHUNK_DATA,
+ cmpl_data->fw_update.data + offset,
+ length);
+
+ /* Notify the waiting thread that we processed a message */
+ if (!err)
+ cmpl_data->fw_update.last_offset = offset;
+
+ cmpl_data->result = err;
+ complete(&cmpl_data->done);
+
+msg_err:
+ /* Report error to FW if one occurred */
+ if (err)
+ fbnic_tlv_attr_put_int(msg, FBNIC_FW_WRITE_CHUNK_ERROR, err);
+
+ /* Map and send the response */
+ err = fbnic_mbx_map_tlv_msg(fbd, msg);
+ if (err)
+ free_page((unsigned long)msg);
+
+ return err;
+}
+
+static const struct fbnic_tlv_index fbnic_fw_verify_image_resp_index[] = {
+ FBNIC_TLV_ATTR_S32(FBNIC_FW_VERIFY_IMAGE_ERROR),
+ FBNIC_TLV_ATTR_LAST
+};
+
+static int fbnic_fw_parse_fw_verify_image_resp(void *opaque,
+ struct fbnic_tlv_msg **results)
+{
+ struct fbnic_dev *fbd = opaque;
+ struct fbnic_fw_completion *cmpl_data;
+ int err = 0;
+
+ /* Verify we have a completion pointer */
+ cmpl_data = READ_ONCE(fbd->cmpl_data);
+ if (!cmpl_data ||
+ cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_VERIFY_IMAGE_RESP)
+ return -ENOSPC;
+
+ /* Check for errors */
+ get_signed_result(FBNIC_FW_VERIFY_IMAGE_ERROR, err);
+
+ cmpl_data->result = err;
+ complete(&cmpl_data->done);
+
+ return err;
+}
+
+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_dev *fbd = opaque;
+ struct fbnic_fw_completion *cmpl_data;
+ int err = 0;
+
+ /* Verify we have a completion pointer */
+ cmpl_data = READ_ONCE(fbd->cmpl_data);
+ if (!cmpl_data ||
+ cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ)
+ return -ENOSPC;
+
+ /* Check for errors */
+ get_signed_result(FBNIC_FW_FINISH_UPGRADE_ERROR, err);
+
+ /* Close out update by clearing data pointer */
+ cmpl_data->fw_update.last_offset = cmpl_data->fw_update.size;
+ cmpl_data->fw_update.data = NULL;
+
+ cmpl_data->result = err;
+ complete(&cmpl_data->done);
+
+ return 0;
+}
+
static const struct fbnic_tlv_parser fbnic_fw_tlv_parser[] = {
FBNIC_TLV_PARSER(FW_CAP_RESP, fbnic_fw_cap_resp_index,
fbnic_fw_parse_cap_resp),
@@ -658,6 +909,18 @@ 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_VERIFY_IMAGE_RESP,
+ fbnic_fw_verify_image_resp_index,
+ fbnic_fw_parse_fw_verify_image_resp),
+ FBNIC_TLV_PARSER(FW_FINISH_UPGRADE_REQ,
+ fbnic_fw_finish_upgrade_req_index,
+ fbnic_fw_parse_fw_finish_upgrade_req),
FBNIC_TLV_MSG_ERROR
};
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
index 221faf8c6756..a638d73d2da5 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
@@ -44,6 +44,19 @@ struct fbnic_fw_cap {
u8 link_fec;
};
+struct fbnic_fw_completion {
+ u32 msg_type;
+ struct completion done;
+ int result;
+ union {
+ struct {
+ u32 size;
+ u32 last_offset;
+ const u8 *data;
+ } fw_update;
+ };
+};
+
void fbnic_mbx_init(struct fbnic_dev *fbd);
void fbnic_mbx_clean(struct fbnic_dev *fbd);
void fbnic_mbx_poll(struct fbnic_dev *fbd);
@@ -52,6 +65,9 @@ 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);
#define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \
do { \
@@ -67,6 +83,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 {
@@ -76,6 +101,14 @@ 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_VERIFY_IMAGE_REQ = 0x26,
+ FBNIC_TLV_MSG_ID_FW_VERIFY_IMAGE_RESP = 0x27,
+ FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_REQ = 0x28,
+ FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_RESP = 0x29,
};
#define FBNIC_FW_CAP_RESP_VERSION_MAJOR CSR_GENMASK(31, 24)
@@ -121,4 +154,30 @@ 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_VERIFY_IMAGE_ERROR = 0x0,
+ FBNIC_FW_VERIFY_IMAGE_MSG_MAX
+};
+
+enum {
+ FBNIC_FW_FINISH_UPGRADE_ERROR = 0x0,
+ FBNIC_FW_FINISH_UPGRADE_MSG_MAX
+};
+
#endif /* _FBNIC_FW_H_ */
--
2.43.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH net-next 2/2] eth: fbnic: Add devlink dev flash support
2024-10-12 2:34 [PATCH net-next 0/2] eth: fbnic: Add devlink dev flash support Lee Trager
2024-10-12 2:34 ` [PATCH net-next 1/2] eth: fbnic: Add mailbox support for PLDM updates Lee Trager
@ 2024-10-12 2:34 ` Lee Trager
2024-10-14 11:18 ` Vadim Fedorenko
2024-10-22 1:37 ` [PATCH net-next v2 0/2] " Lee Trager
` (2 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Lee Trager @ 2024-10-12 2:34 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Mohsin Bashir,
Simon Horman, Vadim Fedorenko, Lee Trager, Sanman Pradhan,
Al Viro
Cc: netdev, linux-doc, linux-kernel
fbnic supports updating firmware using a PLDM image signed and distributed
by Meta. PLDM images are written into stored flashed. Flashing does not
interrupt operation.
On host reboot the newly flashed UEFI driver will be used. To run new
control or cmrt firmware the NIC must be power cycled.
Signed-off-by: Lee Trager <lee@trager.us>
---
.../device_drivers/ethernet/meta/fbnic.rst | 11 +
drivers/net/ethernet/meta/Kconfig | 1 +
.../net/ethernet/meta/fbnic/fbnic_devlink.c | 270 +++++++++++++++++-
3 files changed, 281 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst b/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst
index 32ff114f5c26..d6726c254818 100644
--- a/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst
+++ b/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst
@@ -27,3 +27,14 @@ driver takes over.
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 upgrading firmware using devlink dev flash. Firmware images
+are signed and distributed by Meta. All firmware is bundled into a single
+PLDM image which is written into stored flash. Flashing firmware does not
+interrupt operation.
+
+On host reboot the newly flashed UEFI driver will be used. To run new control
+or cmrt firmware the NIC must be power cycled.
diff --git a/drivers/net/ethernet/meta/Kconfig b/drivers/net/ethernet/meta/Kconfig
index 85519690b837..f5d2c6b6399f 100644
--- a/drivers/net/ethernet/meta/Kconfig
+++ b/drivers/net/ethernet/meta/Kconfig
@@ -26,6 +26,7 @@ config FBNIC
select NET_DEVLINK
select PAGE_POOL
select PHYLINK
+ select PLDMFW
help
This driver supports Meta Platforms Host Network Interface.
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
index 0072d612215e..d487ae7f1126 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
@@ -3,6 +3,7 @@
#include <linux/unaligned.h>
#include <linux/pci.h>
+#include <linux/pldmfw.h>
#include <linux/types.h>
#include <net/devlink.h>
@@ -109,8 +110,275 @@ static int fbnic_devlink_info_get(struct devlink *devlink,
return 0;
}
+/**
+ * fbnic_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.
+ *
+ * Return: zero on success
+ * negative error code on failure
+ */
+static int fbnic_send_package_data(struct pldmfw *context, const u8 *data,
+ u16 length)
+{
+ struct device *dev = context->dev;
+
+ /* Temp placeholder required by devlink */
+ dev_info(dev,
+ "Sending %u bytes of PLDM record package data to firmware\n",
+ length);
+
+ return 0;
+}
+
+/**
+ * fbnic_send_component_table - Send PLDM component table to the firmware
+ * @context: PLDM FW update structure
+ * @component: The component to send
+ * @transfer_flag: Flag indication location in component tables
+ *
+ * Read relevant data from component table and forward it to the firmware.
+ * Check response to verify if the firmware indicates that it wishes to
+ * proceed with the update.
+ *
+ * Return: zero on success
+ * negative error code on failure
+ */
+static int fbnic_send_component_table(struct pldmfw *context,
+ struct pldmfw_component *component,
+ u8 transfer_flag)
+{
+ struct device *dev = context->dev;
+ u16 id = component->identifier;
+ u8 test_string[80];
+
+ switch (id) {
+ case QSPI_SECTION_CMRT:
+ case QSPI_SECTION_CONTROL_FW:
+ case QSPI_SECTION_OPTION_ROM:
+ break;
+ default:
+ dev_err(dev, "Unknown component ID %u\n", id);
+ return -EINVAL;
+ }
+
+ dev_dbg(dev, "Sending PLDM component table to firmware\n");
+
+ /* Temp placeholder */
+ memcpy(test_string, component->version_string,
+ min_t(u8, component->version_len, 79));
+ test_string[min_t(u8, component->version_len, 79)] = 0;
+ dev_info(dev, "PLDMFW: Component ID: %u version %s\n",
+ id, test_string);
+
+ return 0;
+}
+
+/**
+ * fbnic_flash_component - Flash a component of the QSPI
+ * @context: PLDM FW update structure
+ * @component: The component table to send to FW
+ *
+ * Map contents of component and make it available for FW to download
+ * so that it can update the contents of the QSPI Flash.
+ *
+ * Return: zero on success
+ * negative error code on failure
+ */
+static int fbnic_flash_component(struct pldmfw *context,
+ struct pldmfw_component *component)
+{
+ const u8 *data = component->component_data;
+ u32 size = component->component_size;
+ struct fbnic_fw_completion *fw_cmpl;
+ struct device *dev = context->dev;
+ struct pci_dev *pdev = to_pci_dev(dev);
+ u16 id = component->identifier;
+ const char *component_name;
+ int retries = 2;
+ int err;
+
+ struct devlink *devlink;
+ struct fbnic_dev *fbd;
+
+ switch (id) {
+ case QSPI_SECTION_CMRT:
+ component_name = "boot1";
+ break;
+ case QSPI_SECTION_CONTROL_FW:
+ component_name = "boot2";
+ break;
+ case QSPI_SECTION_OPTION_ROM:
+ component_name = "option-rom";
+ break;
+ default:
+ dev_err(dev, "Unknown component ID %u\n", id);
+ return -EINVAL;
+ }
+
+ fw_cmpl = kzalloc(sizeof(*fw_cmpl), GFP_KERNEL);
+ if (!fw_cmpl)
+ return -ENOMEM;
+
+ pdev = to_pci_dev(dev);
+ fbd = pci_get_drvdata(pdev);
+ devlink = priv_to_devlink(fbd);
+
+ /* Initialize completion and queue it for FW to process */
+ fw_cmpl->msg_type = FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ;
+ init_completion(&fw_cmpl->done);
+
+ fw_cmpl->fw_update.last_offset = 0;
+ fw_cmpl->fw_update.data = data;
+ fw_cmpl->fw_update.size = size;
+
+ err = fbnic_fw_xmit_fw_start_upgrade(fbd, fw_cmpl, id, size);
+ if (err)
+ goto cmpl_free;
+
+ /* Monitor completions and report status of update */
+ while (fw_cmpl->fw_update.data) {
+ u32 offset = fw_cmpl->fw_update.last_offset;
+
+ devlink_flash_update_status_notify(devlink, "Flashing",
+ component_name, offset,
+ size);
+
+ /* Allow 5 seconds for reply, resend and try up to 2 times */
+ if (wait_for_completion_timeout(&fw_cmpl->done, 5 * HZ)) {
+ reinit_completion(&fw_cmpl->done);
+ /* If we receive a reply, reinit our retry counter */
+ retries = 2;
+ } else if (--retries == 0) {
+ dev_err(fbd->dev, "Timed out waiting on update\n");
+ err = -ETIMEDOUT;
+ goto cmpl_cleanup;
+ }
+ }
+
+ err = fw_cmpl->result;
+ if (err)
+ goto cmpl_cleanup;
+
+ devlink_flash_update_status_notify(devlink, "Flashing",
+ component_name, size, size);
+
+cmpl_cleanup:
+ fbd->cmpl_data = NULL;
+cmpl_free:
+ kfree(fw_cmpl);
+
+ return err;
+}
+
+/**
+ * fbnic_finalize_update - Perform last steps to complete device update
+ * @context: PLDM FW update structure
+ *
+ * Notify FW that update is complete and that it can take any actions
+ * needed to finalize the FW update.
+ *
+ * Return: zero on success
+ * negative error code on failure
+ */
+static int fbnic_finalize_update(struct pldmfw *context)
+{
+ struct device *dev = context->dev;
+
+ /* Temp placeholder required by devlink */
+ dev_info(dev, "PLDMFW: Finalize update\n");
+
+ return 0;
+}
+
+static const struct pldmfw_ops fbnic_pldmfw_ops = {
+ .match_record = pldmfw_op_pci_match_record,
+ .send_package_data = fbnic_send_package_data,
+ .send_component_table = fbnic_send_component_table,
+ .flash_component = fbnic_flash_component,
+ .finalize_update = fbnic_finalize_update,
+};
+
+static void fbnic_devlink_flash_update_report_err(struct fbnic_dev *fbd,
+ struct devlink *devlink,
+ const char *err_msg,
+ int err)
+{
+ char err_str[128];
+
+ snprintf(err_str, sizeof(err_str),
+ "Failed to flash PLDM Image: %s (error: %d)",
+ err_msg, err);
+ devlink_flash_update_status_notify(devlink, err_str, NULL, 0, 0);
+ dev_err(fbd->dev, "%s\n", err_str);
+}
+
+static int
+fbnic_devlink_flash_update(struct devlink *devlink,
+ struct devlink_flash_update_params *params,
+ struct netlink_ext_ack *extack)
+{
+ struct fbnic_dev *fbd = devlink_priv(devlink);
+ const struct firmware *fw = params->fw;
+ struct device *dev = fbd->dev;
+ struct pldmfw context;
+ char *err_msg;
+ int err;
+
+ if (!fw || !fw->data || !fw->size)
+ return -EINVAL;
+
+ devlink_flash_update_status_notify(devlink, "Preparing to flash",
+ NULL, 0, 0);
+
+ context.ops = &fbnic_pldmfw_ops;
+ context.dev = dev;
+
+ err = pldmfw_flash_image(&context, fw);
+ if (err) {
+ switch (err) {
+ case -EINVAL:
+ err_msg = "Invalid image";
+ break;
+ case -EOPNOTSUPP:
+ err_msg = "Unsupported image";
+ break;
+ case -ENOMEM:
+ err_msg = "Out of memory";
+ break;
+ case -EFAULT:
+ err_msg = "Invalid header";
+ break;
+ case -ENOENT:
+ err_msg = "No matching record";
+ break;
+ case -ENODEV:
+ err_msg = "No matching device";
+ break;
+ case -ETIMEDOUT:
+ err_msg = "Timed out waiting for reply";
+ break;
+ default:
+ err_msg = "Unknown error";
+ break;
+ }
+ fbnic_devlink_flash_update_report_err(fbd, devlink,
+ err_msg, err);
+ } else {
+ devlink_flash_update_status_notify(devlink, "Flashing done",
+ NULL, 0, 0);
+ }
+
+ return err;
+}
+
static const struct devlink_ops fbnic_devlink_ops = {
- .info_get = fbnic_devlink_info_get,
+ .info_get = fbnic_devlink_info_get,
+ .flash_update = fbnic_devlink_flash_update,
};
void fbnic_devlink_free(struct fbnic_dev *fbd)
--
2.43.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH net-next 1/2] eth: fbnic: Add mailbox support for PLDM updates
2024-10-12 2:34 ` [PATCH net-next 1/2] eth: fbnic: Add mailbox support for PLDM updates Lee Trager
@ 2024-10-14 11:05 ` Vadim Fedorenko
0 siblings, 0 replies; 15+ messages in thread
From: Vadim Fedorenko @ 2024-10-14 11:05 UTC (permalink / raw)
To: Lee Trager, Alexander Duyck, Jakub Kicinski, kernel-team,
David S. Miller, Eric Dumazet, Paolo Abeni, Jonathan Corbet,
Mohsin Bashir, Simon Horman, Sanman Pradhan, Al Viro
Cc: netdev, linux-doc, linux-kernel
On 12/10/2024 03:34, Lee Trager wrote:
> This adds driver support to utilize the kernel completion API. This allows
> the driver to block on a response from firmware. Initially
> fbnic_fw_completion only has support for updates, future patches will add
> additional features.
>
> Signed-off-by: Lee Trager <lee@trager.us>
> ---
> drivers/net/ethernet/meta/fbnic/fbnic.h | 1 +
> drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 263 +++++++++++++++++++++
> drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 59 +++++
> 3 files changed, 323 insertions(+)
>
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic.h b/drivers/net/ethernet/meta/fbnic/fbnic.h
> index ca59261f0155..f58727e6e45a 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic.h
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic.h
> @@ -31,6 +31,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;
> /* Lock protecting Tx Mailbox queue to prevent possible races */
> spinlock_t fw_tx_lock;
>
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
> index 8f7a2a19ddf8..deebff3b6821 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
> @@ -207,6 +207,38 @@ static int fbnic_mbx_map_tlv_msg(struct fbnic_dev *fbd,
> return err;
> }
>
> +static int fbnic_mbx_map_req_w_cmpl(struct fbnic_dev *fbd,
> + struct fbnic_tlv_msg *msg,
> + struct fbnic_fw_completion *cmpl_data)
> +{
> + unsigned long flags;
> + int err;
> +
> + spin_lock_irqsave(&fbd->fw_tx_lock, flags);
> +
> + /* If we are already waiting on a completion then abort */
> + if (cmpl_data && fbd->cmpl_data) {
> + err = -EBUSY;
> + goto unlock_mbx;
> + }
> +
> + /* Record completion location and submit request */
> + if (cmpl_data)
> + fbd->cmpl_data = cmpl_data;
> +
> + err = fbnic_mbx_map_msg(fbd, FBNIC_IPC_MBX_TX_IDX, msg,
> + le16_to_cpu(msg->hdr.len) * sizeof(u32), 1);
> +
> + /* If msg failed then clear completion data for next caller */
> + if (err && cmpl_data)
> + fbd->cmpl_data = NULL;
> +
> +unlock_mbx:
> + spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
> +
> + return err;
> +}
> +
> static void fbnic_mbx_process_tx_msgs(struct fbnic_dev *fbd)
> {
> struct fbnic_fw_mbx *tx_mbx = &fbd->mbx[FBNIC_IPC_MBX_TX_IDX];
> @@ -651,6 +683,225 @@ void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd)
> dev_warn(fbd->dev, "Failed to send heartbeat message\n");
> }
>
> +/**
> + * fbnic_fw_xmit_fw_start_upgrade - Create and transmit a start update message
> + * @fbd: FBNIC device structure
> + * @cmpl_data: Completion data for upgrade process
> + * @id: Component ID
> + * @len: Length of FW update package data
> + *
> + * Return: zero on success, negative value on failure
> + *
> + * Asks the FW to prepare for starting a firmware upgrade
> + */
> +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 (!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_dev *fbd = opaque;
> + struct fbnic_fw_completion *cmpl_data;
Hi Lee!
Looks like you didn't follow reverse Xmas tree for variables here and
in several functions later, all about cmpl_data variable.
> + int err = 0;
> +
> + /* Verify we have a completion pointer */
> + cmpl_data = READ_ONCE(fbd->cmpl_data);
> + if (!cmpl_data ||
> + cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ)
> + return -ENOSPC;
> +
> + /* Check for errors */
> + get_signed_result(FBNIC_FW_START_UPGRADE_ERROR, err);
> +
> + cmpl_data->result = err;
> + complete(&cmpl_data->done);
> +
> + return 0;
> +}
> +
> +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_dev *fbd = opaque;
> + struct fbnic_fw_completion *cmpl_data;
here again...
> + u32 length = 0, offset = 0;
> + struct fbnic_tlv_msg *msg;
> + int err;
> +
> + /* Start by attempting to allocate a response to the message */
> + msg = fbnic_tlv_msg_alloc(FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_RESP);
> + if (!msg)
> + return -ENOMEM;
> +
> + /* Verify we have a completion pointer */
> + cmpl_data = READ_ONCE(fbd->cmpl_data);
> + if (!cmpl_data ||
> + cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ) {
> + err = -ENOSPC;
> + goto msg_err;
> + }
> +
> + /* Notify FW if the data link has been severed */
> + if (!cmpl_data->fw_update.data) {
> + err = -ECANCELED;
> + goto msg_err;
> + }
> +
> + /* Pull length/offset pair and mark it as complete */
> + get_unsigned_result(FBNIC_FW_WRITE_CHUNK_OFFSET, offset);
> + get_unsigned_result(FBNIC_FW_WRITE_CHUNK_LENGTH, length);
> +
> + /* Record offset and length for the response */
> + if (offset) {
> + err = fbnic_tlv_attr_put_int(msg, FBNIC_FW_WRITE_CHUNK_OFFSET,
> + offset);
> + if (err)
> + goto msg_err;
> + }
> +
> + err = fbnic_tlv_attr_put_int(msg, FBNIC_FW_WRITE_CHUNK_LENGTH,
> + length);
> + if (err)
> + goto msg_err;
> +
> + /* Verify length */
> + if (!length || length > TLV_MAX_DATA) {
> + err = -EINVAL;
> + goto msg_err;
> + }
> +
> + /* Verify offset and length are within bounds */
> + if (offset >= cmpl_data->fw_update.size ||
> + offset + length > cmpl_data->fw_update.size) {
> + err = -EFAULT;
> + goto msg_err;
> + }
> +
> + /* Add outbound data to message */
> + err = fbnic_tlv_attr_put_value(msg, FBNIC_FW_WRITE_CHUNK_DATA,
> + cmpl_data->fw_update.data + offset,
> + length);
> +
> + /* Notify the waiting thread that we processed a message */
> + if (!err)
> + cmpl_data->fw_update.last_offset = offset;
> +
> + cmpl_data->result = err;
> + complete(&cmpl_data->done);
> +
> +msg_err:
> + /* Report error to FW if one occurred */
> + if (err)
> + fbnic_tlv_attr_put_int(msg, FBNIC_FW_WRITE_CHUNK_ERROR, err);
> +
> + /* Map and send the response */
> + err = fbnic_mbx_map_tlv_msg(fbd, msg);
> + if (err)
> + free_page((unsigned long)msg);
> +
> + return err;
> +}
> +
> +static const struct fbnic_tlv_index fbnic_fw_verify_image_resp_index[] = {
> + FBNIC_TLV_ATTR_S32(FBNIC_FW_VERIFY_IMAGE_ERROR),
> + FBNIC_TLV_ATTR_LAST
> +};
> +
> +static int fbnic_fw_parse_fw_verify_image_resp(void *opaque,
> + struct fbnic_tlv_msg **results)
> +{
> + struct fbnic_dev *fbd = opaque;
> + struct fbnic_fw_completion *cmpl_data;
.. and again..
> + int err = 0;
> +
> + /* Verify we have a completion pointer */
> + cmpl_data = READ_ONCE(fbd->cmpl_data);
> + if (!cmpl_data ||
> + cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_VERIFY_IMAGE_RESP)
> + return -ENOSPC;
> +
> + /* Check for errors */
> + get_signed_result(FBNIC_FW_VERIFY_IMAGE_ERROR, err);
> +
> + cmpl_data->result = err;
> + complete(&cmpl_data->done);
> +
> + return err;
> +}
> +
> +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_dev *fbd = opaque;
> + struct fbnic_fw_completion *cmpl_data;
...and again...
> + int err = 0;
> +
> + /* Verify we have a completion pointer */
> + cmpl_data = READ_ONCE(fbd->cmpl_data);
> + if (!cmpl_data ||
> + cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ)
> + return -ENOSPC;
> +
> + /* Check for errors */
> + get_signed_result(FBNIC_FW_FINISH_UPGRADE_ERROR, err);
> +
> + /* Close out update by clearing data pointer */
> + cmpl_data->fw_update.last_offset = cmpl_data->fw_update.size;
> + cmpl_data->fw_update.data = NULL;
> +
> + cmpl_data->result = err;
> + complete(&cmpl_data->done);
> +
> + return 0;
> +}
> +
> static const struct fbnic_tlv_parser fbnic_fw_tlv_parser[] = {
> FBNIC_TLV_PARSER(FW_CAP_RESP, fbnic_fw_cap_resp_index,
> fbnic_fw_parse_cap_resp),
> @@ -658,6 +909,18 @@ 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_VERIFY_IMAGE_RESP,
> + fbnic_fw_verify_image_resp_index,
> + fbnic_fw_parse_fw_verify_image_resp),
> + FBNIC_TLV_PARSER(FW_FINISH_UPGRADE_REQ,
> + fbnic_fw_finish_upgrade_req_index,
> + fbnic_fw_parse_fw_finish_upgrade_req),
> FBNIC_TLV_MSG_ERROR
> };
>
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
> index 221faf8c6756..a638d73d2da5 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
> @@ -44,6 +44,19 @@ struct fbnic_fw_cap {
> u8 link_fec;
> };
>
> +struct fbnic_fw_completion {
> + u32 msg_type;
> + struct completion done;
> + int result;
> + union {
> + struct {
> + u32 size;
> + u32 last_offset;
> + const u8 *data;
> + } fw_update;
> + };
> +};
> +
> void fbnic_mbx_init(struct fbnic_dev *fbd);
> void fbnic_mbx_clean(struct fbnic_dev *fbd);
> void fbnic_mbx_poll(struct fbnic_dev *fbd);
> @@ -52,6 +65,9 @@ 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);
>
> #define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \
> do { \
> @@ -67,6 +83,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 {
> @@ -76,6 +101,14 @@ 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_VERIFY_IMAGE_REQ = 0x26,
> + FBNIC_TLV_MSG_ID_FW_VERIFY_IMAGE_RESP = 0x27,
> + FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_REQ = 0x28,
> + FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_RESP = 0x29,
> };
>
> #define FBNIC_FW_CAP_RESP_VERSION_MAJOR CSR_GENMASK(31, 24)
> @@ -121,4 +154,30 @@ 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_VERIFY_IMAGE_ERROR = 0x0,
> + FBNIC_FW_VERIFY_IMAGE_MSG_MAX
> +};
> +
> +enum {
> + FBNIC_FW_FINISH_UPGRADE_ERROR = 0x0,
> + FBNIC_FW_FINISH_UPGRADE_MSG_MAX
> +};
> +
> #endif /* _FBNIC_FW_H_ */
> --
> 2.43.5
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net-next 2/2] eth: fbnic: Add devlink dev flash support
2024-10-12 2:34 ` [PATCH net-next 2/2] eth: fbnic: Add devlink dev flash support Lee Trager
@ 2024-10-14 11:18 ` Vadim Fedorenko
2024-10-15 10:43 ` Simon Horman
0 siblings, 1 reply; 15+ messages in thread
From: Vadim Fedorenko @ 2024-10-14 11:18 UTC (permalink / raw)
To: Lee Trager, Alexander Duyck, Jakub Kicinski, kernel-team,
David S. Miller, Eric Dumazet, Paolo Abeni, Jonathan Corbet,
Mohsin Bashir, Simon Horman, Sanman Pradhan, Al Viro
Cc: netdev, linux-doc, linux-kernel
On 12/10/2024 03:34, Lee Trager wrote:
> fbnic supports updating firmware using a PLDM image signed and distributed
> by Meta. PLDM images are written into stored flashed. Flashing does not
> interrupt operation.
>
> On host reboot the newly flashed UEFI driver will be used. To run new
> control or cmrt firmware the NIC must be power cycled.
>
> Signed-off-by: Lee Trager <lee@trager.us>
> ---
> .../device_drivers/ethernet/meta/fbnic.rst | 11 +
> drivers/net/ethernet/meta/Kconfig | 1 +
> .../net/ethernet/meta/fbnic/fbnic_devlink.c | 270 +++++++++++++++++-
> 3 files changed, 281 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst b/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst
> index 32ff114f5c26..d6726c254818 100644
> --- a/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst
> +++ b/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst
> @@ -27,3 +27,14 @@ driver takes over.
> 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 upgrading firmware using devlink dev flash. Firmware images
> +are signed and distributed by Meta. All firmware is bundled into a single
> +PLDM image which is written into stored flash. Flashing firmware does not
> +interrupt operation.
> +
> +On host reboot the newly flashed UEFI driver will be used. To run new control
> +or cmrt firmware the NIC must be power cycled.
> diff --git a/drivers/net/ethernet/meta/Kconfig b/drivers/net/ethernet/meta/Kconfig
> index 85519690b837..f5d2c6b6399f 100644
> --- a/drivers/net/ethernet/meta/Kconfig
> +++ b/drivers/net/ethernet/meta/Kconfig
> @@ -26,6 +26,7 @@ config FBNIC
> select NET_DEVLINK
> select PAGE_POOL
> select PHYLINK
> + select PLDMFW
> help
> This driver supports Meta Platforms Host Network Interface.
>
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
> index 0072d612215e..d487ae7f1126 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
> @@ -3,6 +3,7 @@
>
> #include <linux/unaligned.h>
> #include <linux/pci.h>
> +#include <linux/pldmfw.h>
> #include <linux/types.h>
> #include <net/devlink.h>
>
> @@ -109,8 +110,275 @@ static int fbnic_devlink_info_get(struct devlink *devlink,
> return 0;
> }
>
> +/**
> + * fbnic_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.
> + *
> + * Return: zero on success
> + * negative error code on failure
> + */
> +static int fbnic_send_package_data(struct pldmfw *context, const u8 *data,
> + u16 length)
> +{
> + struct device *dev = context->dev;
> +
> + /* Temp placeholder required by devlink */
> + dev_info(dev,
> + "Sending %u bytes of PLDM record package data to firmware\n",
> + length);
> +
> + return 0;
> +}
> +
> +/**
> + * fbnic_send_component_table - Send PLDM component table to the firmware
> + * @context: PLDM FW update structure
> + * @component: The component to send
> + * @transfer_flag: Flag indication location in component tables
> + *
> + * Read relevant data from component table and forward it to the firmware.
> + * Check response to verify if the firmware indicates that it wishes to
> + * proceed with the update.
> + *
> + * Return: zero on success
> + * negative error code on failure
> + */
> +static int fbnic_send_component_table(struct pldmfw *context,
> + struct pldmfw_component *component,
> + u8 transfer_flag)
> +{
> + struct device *dev = context->dev;
> + u16 id = component->identifier;
> + u8 test_string[80];
> +
> + switch (id) {
> + case QSPI_SECTION_CMRT:
> + case QSPI_SECTION_CONTROL_FW:
> + case QSPI_SECTION_OPTION_ROM:
> + break;
> + default:
> + dev_err(dev, "Unknown component ID %u\n", id);
> + return -EINVAL;
> + }
> +
> + dev_dbg(dev, "Sending PLDM component table to firmware\n");
> +
> + /* Temp placeholder */
> + memcpy(test_string, component->version_string,
> + min_t(u8, component->version_len, 79));
> + test_string[min_t(u8, component->version_len, 79)] = 0;
Looks like this construction can be replaced with strscpy().
There were several patchsets in the tree to use strscpy(), let's follow
the pattern.
> + dev_info(dev, "PLDMFW: Component ID: %u version %s\n",
> + id, test_string);
> +
> + return 0;
> +}
> +
> +/**
> + * fbnic_flash_component - Flash a component of the QSPI
> + * @context: PLDM FW update structure
> + * @component: The component table to send to FW
> + *
> + * Map contents of component and make it available for FW to download
> + * so that it can update the contents of the QSPI Flash.
> + *
> + * Return: zero on success
> + * negative error code on failure
> + */
> +static int fbnic_flash_component(struct pldmfw *context,
> + struct pldmfw_component *component)
> +{
> + const u8 *data = component->component_data;
> + u32 size = component->component_size;
> + struct fbnic_fw_completion *fw_cmpl;
> + struct device *dev = context->dev;
> + struct pci_dev *pdev = to_pci_dev(dev);
> + u16 id = component->identifier;
> + const char *component_name;
> + int retries = 2;
> + int err;
> +
> + struct devlink *devlink;
> + struct fbnic_dev *fbd;
> +
> + switch (id) {
> + case QSPI_SECTION_CMRT:
> + component_name = "boot1";
> + break;
> + case QSPI_SECTION_CONTROL_FW:
> + component_name = "boot2";
> + break;
> + case QSPI_SECTION_OPTION_ROM:
> + component_name = "option-rom";
> + break;
> + default:
> + dev_err(dev, "Unknown component ID %u\n", id);
> + return -EINVAL;
> + }
> +
> + fw_cmpl = kzalloc(sizeof(*fw_cmpl), GFP_KERNEL);
> + if (!fw_cmpl)
> + return -ENOMEM;
> +
> + pdev = to_pci_dev(dev);
> + fbd = pci_get_drvdata(pdev);
> + devlink = priv_to_devlink(fbd);
> +
> + /* Initialize completion and queue it for FW to process */
> + fw_cmpl->msg_type = FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ;
> + init_completion(&fw_cmpl->done);
> +
> + fw_cmpl->fw_update.last_offset = 0;
> + fw_cmpl->fw_update.data = data;
> + fw_cmpl->fw_update.size = size;
> +
> + err = fbnic_fw_xmit_fw_start_upgrade(fbd, fw_cmpl, id, size);
> + if (err)
> + goto cmpl_free;
> +
> + /* Monitor completions and report status of update */
> + while (fw_cmpl->fw_update.data) {
> + u32 offset = fw_cmpl->fw_update.last_offset;
> +
> + devlink_flash_update_status_notify(devlink, "Flashing",
> + component_name, offset,
> + size);
> +
> + /* Allow 5 seconds for reply, resend and try up to 2 times */
> + if (wait_for_completion_timeout(&fw_cmpl->done, 5 * HZ)) {
> + reinit_completion(&fw_cmpl->done);
> + /* If we receive a reply, reinit our retry counter */
> + retries = 2;
> + } else if (--retries == 0) {
> + dev_err(fbd->dev, "Timed out waiting on update\n");
> + err = -ETIMEDOUT;
> + goto cmpl_cleanup;
> + }
> + }
> +
> + err = fw_cmpl->result;
> + if (err)
> + goto cmpl_cleanup;
> +
> + devlink_flash_update_status_notify(devlink, "Flashing",
> + component_name, size, size);
> +
> +cmpl_cleanup:
> + fbd->cmpl_data = NULL;
> +cmpl_free:
> + kfree(fw_cmpl);
> +
> + return err;
> +}
> +
[ strip ]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net-next 2/2] eth: fbnic: Add devlink dev flash support
2024-10-14 11:18 ` Vadim Fedorenko
@ 2024-10-15 10:43 ` Simon Horman
2024-10-18 22:48 ` Lee Trager
0 siblings, 1 reply; 15+ messages in thread
From: Simon Horman @ 2024-10-15 10:43 UTC (permalink / raw)
To: Vadim Fedorenko
Cc: Lee Trager, Alexander Duyck, Jakub Kicinski, kernel-team,
David S. Miller, Eric Dumazet, Paolo Abeni, Jonathan Corbet,
Mohsin Bashir, Sanman Pradhan, Al Viro, netdev, linux-doc,
linux-kernel
On Mon, Oct 14, 2024 at 12:18:36PM +0100, Vadim Fedorenko wrote:
> On 12/10/2024 03:34, Lee Trager wrote:
> > fbnic supports updating firmware using a PLDM image signed and distributed
> > by Meta. PLDM images are written into stored flashed. Flashing does not
> > interrupt operation.
> >
> > On host reboot the newly flashed UEFI driver will be used. To run new
> > control or cmrt firmware the NIC must be power cycled.
> >
> > Signed-off-by: Lee Trager <lee@trager.us>
...
> > diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
...
> > +/**
> > + * fbnic_send_component_table - Send PLDM component table to the firmware
> > + * @context: PLDM FW update structure
> > + * @component: The component to send
> > + * @transfer_flag: Flag indication location in component tables
> > + *
> > + * Read relevant data from component table and forward it to the firmware.
> > + * Check response to verify if the firmware indicates that it wishes to
> > + * proceed with the update.
> > + *
> > + * Return: zero on success
> > + * negative error code on failure
> > + */
> > +static int fbnic_send_component_table(struct pldmfw *context,
> > + struct pldmfw_component *component,
> > + u8 transfer_flag)
> > +{
> > + struct device *dev = context->dev;
> > + u16 id = component->identifier;
> > + u8 test_string[80];
> > +
> > + switch (id) {
> > + case QSPI_SECTION_CMRT:
> > + case QSPI_SECTION_CONTROL_FW:
> > + case QSPI_SECTION_OPTION_ROM:
> > + break;
> > + default:
> > + dev_err(dev, "Unknown component ID %u\n", id);
> > + return -EINVAL;
> > + }
> > +
> > + dev_dbg(dev, "Sending PLDM component table to firmware\n");
> > +
> > + /* Temp placeholder */
> > + memcpy(test_string, component->version_string,
> > + min_t(u8, component->version_len, 79));
> > + test_string[min_t(u8, component->version_len, 79)] = 0;
>
> Looks like this construction can be replaced with strscpy().
> There were several patchsets in the tree to use strscpy(), let's follow
> the pattern.
While looking at these lines, I'm unsure why min_t() is being used
instead of min() here. As version_len is unsigned and 79 is a positive
constant, I believe min() should be fine here.
>
> > + dev_info(dev, "PLDMFW: Component ID: %u version %s\n",
> > + id, test_string);
> > +
> > + return 0;
> > +}
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net-next 2/2] eth: fbnic: Add devlink dev flash support
2024-10-15 10:43 ` Simon Horman
@ 2024-10-18 22:48 ` Lee Trager
2024-10-19 9:34 ` Simon Horman
0 siblings, 1 reply; 15+ messages in thread
From: Lee Trager @ 2024-10-18 22:48 UTC (permalink / raw)
To: Simon Horman, Vadim Fedorenko
Cc: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Mohsin Bashir,
Sanman Pradhan, Al Viro, netdev, linux-doc, linux-kernel
On 10/15/24 3:43 AM, Simon Horman wrote:
> On Mon, Oct 14, 2024 at 12:18:36PM +0100, Vadim Fedorenko wrote:
>> On 12/10/2024 03:34, Lee Trager wrote:
>>> fbnic supports updating firmware using a PLDM image signed and distributed
>>> by Meta. PLDM images are written into stored flashed. Flashing does not
>>> interrupt operation.
>>>
>>> On host reboot the newly flashed UEFI driver will be used. To run new
>>> control or cmrt firmware the NIC must be power cycled.
>>>
>>> Signed-off-by: Lee Trager <lee@trager.us>
> ...
>
>>> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
> ...
>
>>> +/**
>>> + * fbnic_send_component_table - Send PLDM component table to the firmware
>>> + * @context: PLDM FW update structure
>>> + * @component: The component to send
>>> + * @transfer_flag: Flag indication location in component tables
>>> + *
>>> + * Read relevant data from component table and forward it to the firmware.
>>> + * Check response to verify if the firmware indicates that it wishes to
>>> + * proceed with the update.
>>> + *
>>> + * Return: zero on success
>>> + * negative error code on failure
>>> + */
>>> +static int fbnic_send_component_table(struct pldmfw *context,
>>> + struct pldmfw_component *component,
>>> + u8 transfer_flag)
>>> +{
>>> + struct device *dev = context->dev;
>>> + u16 id = component->identifier;
>>> + u8 test_string[80];
>>> +
>>> + switch (id) {
>>> + case QSPI_SECTION_CMRT:
>>> + case QSPI_SECTION_CONTROL_FW:
>>> + case QSPI_SECTION_OPTION_ROM:
>>> + break;
>>> + default:
>>> + dev_err(dev, "Unknown component ID %u\n", id);
>>> + return -EINVAL;
>>> + }
>>> +
>>> + dev_dbg(dev, "Sending PLDM component table to firmware\n");
>>> +
>>> + /* Temp placeholder */
>>> + memcpy(test_string, component->version_string,
>>> + min_t(u8, component->version_len, 79));
>>> + test_string[min_t(u8, component->version_len, 79)] = 0;
>> Looks like this construction can be replaced with strscpy().
>> There were several patchsets in the tree to use strscpy(), let's follow
>> the pattern.
> While looking at these lines, I'm unsure why min_t() is being used
> instead of min() here. As version_len is unsigned and 79 is a positive
> constant, I believe min() should be fine here.
clang complains if I'm not explicit with the type by using min_t()
/home/ltrager/fbnic/src/fbnic_devlink.c:194:3: warning: comparison of
distinct pointer types ('typeof (component->version_len) *' (aka
'unsigned char *') and 'typeof (79) *' (aka 'int *'))
[-Wcompare-distinct-pointer-types]
194 | min(component->version_len, 79));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/minmax.h:45:19: note: expanded from macro 'min'
45 | #define min(x, y) __careful_cmp(x, y, <)
| ^~~~~~~~~~~~~~~~~~~~~~
./include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
36 | __builtin_choose_expr(__safe_cmp(x, y), \
| ^~~~~~~~~~~~~~~~
./include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
26 | (__typecheck(x, y) && __no_side_effects(x, y))
| ^~~~~~~~~~~~~~~~~
./include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
20 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
1 warning generated.
>>> + dev_info(dev, "PLDMFW: Component ID: %u version %s\n",
>>> + id, test_string);
>>> +
>>> + return 0;
>>> +}
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net-next 2/2] eth: fbnic: Add devlink dev flash support
2024-10-18 22:48 ` Lee Trager
@ 2024-10-19 9:34 ` Simon Horman
0 siblings, 0 replies; 15+ messages in thread
From: Simon Horman @ 2024-10-19 9:34 UTC (permalink / raw)
To: Lee Trager
Cc: Vadim Fedorenko, Alexander Duyck, Jakub Kicinski, kernel-team,
David S. Miller, Eric Dumazet, Paolo Abeni, Jonathan Corbet,
Mohsin Bashir, Sanman Pradhan, Al Viro, netdev, linux-doc,
linux-kernel
On Fri, Oct 18, 2024 at 03:48:26PM -0700, Lee Trager wrote:
> On 10/15/24 3:43 AM, Simon Horman wrote:
>
> > On Mon, Oct 14, 2024 at 12:18:36PM +0100, Vadim Fedorenko wrote:
> > > On 12/10/2024 03:34, Lee Trager wrote:
> > > > fbnic supports updating firmware using a PLDM image signed and distributed
> > > > by Meta. PLDM images are written into stored flashed. Flashing does not
> > > > interrupt operation.
> > > >
> > > > On host reboot the newly flashed UEFI driver will be used. To run new
> > > > control or cmrt firmware the NIC must be power cycled.
> > > >
> > > > Signed-off-by: Lee Trager <lee@trager.us>
> > ...
> >
> > > > diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
> > ...
> >
> > > > +/**
> > > > + * fbnic_send_component_table - Send PLDM component table to the firmware
> > > > + * @context: PLDM FW update structure
> > > > + * @component: The component to send
> > > > + * @transfer_flag: Flag indication location in component tables
> > > > + *
> > > > + * Read relevant data from component table and forward it to the firmware.
> > > > + * Check response to verify if the firmware indicates that it wishes to
> > > > + * proceed with the update.
> > > > + *
> > > > + * Return: zero on success
> > > > + * negative error code on failure
> > > > + */
> > > > +static int fbnic_send_component_table(struct pldmfw *context,
> > > > + struct pldmfw_component *component,
> > > > + u8 transfer_flag)
> > > > +{
> > > > + struct device *dev = context->dev;
> > > > + u16 id = component->identifier;
> > > > + u8 test_string[80];
> > > > +
> > > > + switch (id) {
> > > > + case QSPI_SECTION_CMRT:
> > > > + case QSPI_SECTION_CONTROL_FW:
> > > > + case QSPI_SECTION_OPTION_ROM:
> > > > + break;
> > > > + default:
> > > > + dev_err(dev, "Unknown component ID %u\n", id);
> > > > + return -EINVAL;
> > > > + }
> > > > +
> > > > + dev_dbg(dev, "Sending PLDM component table to firmware\n");
> > > > +
> > > > + /* Temp placeholder */
> > > > + memcpy(test_string, component->version_string,
> > > > + min_t(u8, component->version_len, 79));
> > > > + test_string[min_t(u8, component->version_len, 79)] = 0;
> > > Looks like this construction can be replaced with strscpy().
> > > There were several patchsets in the tree to use strscpy(), let's follow
> > > the pattern.
> > While looking at these lines, I'm unsure why min_t() is being used
> > instead of min() here. As version_len is unsigned and 79 is a positive
> > constant, I believe min() should be fine here.
>
> clang complains if I'm not explicit with the type by using min_t()
Thanks, and sorry for not checking what clang says.
That is a good enough reason for this for me.
...
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net-next v2 0/2] eth: fbnic: Add devlink dev flash support
2024-10-12 2:34 [PATCH net-next 0/2] eth: fbnic: Add devlink dev flash support Lee Trager
2024-10-12 2:34 ` [PATCH net-next 1/2] eth: fbnic: Add mailbox support for PLDM updates Lee Trager
2024-10-12 2:34 ` [PATCH net-next 2/2] eth: fbnic: Add devlink dev flash support Lee Trager
@ 2024-10-22 1:37 ` Lee Trager
2024-10-22 1:37 ` [PATCH net-next v2 1/2] eth: fbnic: Add mailbox support for PLDM updates Lee Trager
2024-10-22 1:42 ` [PATCH net-next v2 2/2] eth: fbnic: Add devlink dev flash support Lee Trager
4 siblings, 0 replies; 15+ messages in thread
From: Lee Trager @ 2024-10-22 1:37 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Andrew Lunn,
Lee Trager, Sanman Pradhan, Al Viro, Mohsin Bashir, Simon Horman
Cc: Kalesh AP, netdev, linux-doc, linux-kernel
fbnic supports updating firmware using a PLDM image signed and distributed
by Meta. PLDM images are written into stored flash. Flashing does not
interrupt operation.
Mailbox support additional adds support to utilize the kernel completion
API with firmware. This allows the driver to block on firmware response.
Initial support is only for firmware updates, future patches will add
support for additional features.
Changes:
V2:
* Fixed reversed Xmas tree variable declarations
* Replaced memcpy with strscpy
Lee Trager (2):
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 +
.../net/ethernet/meta/fbnic/fbnic_devlink.c | 269 +++++++++++++++++-
drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 263 +++++++++++++++++
drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 64 ++++-
5 files changed, 603 insertions(+), 5 deletions(-)
--
2.43.5
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net-next v2 1/2] eth: fbnic: Add mailbox support for PLDM updates
2024-10-12 2:34 [PATCH net-next 0/2] eth: fbnic: Add devlink dev flash support Lee Trager
` (2 preceding siblings ...)
2024-10-22 1:37 ` [PATCH net-next v2 0/2] " Lee Trager
@ 2024-10-22 1:37 ` Lee Trager
2024-10-26 15:12 ` Simon Horman
2024-10-22 1:42 ` [PATCH net-next v2 2/2] eth: fbnic: Add devlink dev flash support Lee Trager
4 siblings, 1 reply; 15+ messages in thread
From: Lee Trager @ 2024-10-22 1:37 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Andrew Lunn,
Lee Trager, Sanman Pradhan, Al Viro, Mohsin Bashir, Simon Horman
Cc: netdev, linux-doc, linux-kernel
This adds driver support to utilize the kernel completion API. This allows
the driver to block on a response from firmware. Initially
fbnic_fw_completion only has support for updates, future patches will add
additional features.
Signed-off-by: Lee Trager <lee@trager.us>
---
drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 263 +++++++++++++++++++++
drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 64 ++++-
2 files changed, 323 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
index 8f7a2a19ddf8..d46afc38b4a5 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
@@ -207,6 +207,38 @@ static int fbnic_mbx_map_tlv_msg(struct fbnic_dev *fbd,
return err;
}
+static int fbnic_mbx_map_req_w_cmpl(struct fbnic_dev *fbd,
+ struct fbnic_tlv_msg *msg,
+ struct fbnic_fw_completion *cmpl_data)
+{
+ unsigned long flags;
+ int err;
+
+ spin_lock_irqsave(&fbd->fw_tx_lock, flags);
+
+ /* If we are already waiting on a completion then abort */
+ if (cmpl_data && fbd->cmpl_data) {
+ err = -EBUSY;
+ goto unlock_mbx;
+ }
+
+ /* Record completion location and submit request */
+ if (cmpl_data)
+ fbd->cmpl_data = cmpl_data;
+
+ err = fbnic_mbx_map_msg(fbd, FBNIC_IPC_MBX_TX_IDX, msg,
+ le16_to_cpu(msg->hdr.len) * sizeof(u32), 1);
+
+ /* If msg failed then clear completion data for next caller */
+ if (err && cmpl_data)
+ fbd->cmpl_data = NULL;
+
+unlock_mbx:
+ spin_unlock_irqrestore(&fbd->fw_tx_lock, flags);
+
+ return err;
+}
+
static void fbnic_mbx_process_tx_msgs(struct fbnic_dev *fbd)
{
struct fbnic_fw_mbx *tx_mbx = &fbd->mbx[FBNIC_IPC_MBX_TX_IDX];
@@ -651,6 +683,225 @@ void fbnic_fw_check_heartbeat(struct fbnic_dev *fbd)
dev_warn(fbd->dev, "Failed to send heartbeat message\n");
}
+/**
+ * fbnic_fw_xmit_fw_start_upgrade - Create and transmit a start update message
+ * @fbd: FBNIC device structure
+ * @cmpl_data: Completion data for upgrade process
+ * @id: Component ID
+ * @len: Length of FW update package data
+ *
+ * Return: zero on success, negative value on failure
+ *
+ * Asks the FW to prepare for starting a firmware upgrade
+ */
+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 (!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;
+ int err = 0;
+
+ /* Verify we have a completion pointer */
+ cmpl_data = READ_ONCE(fbd->cmpl_data);
+ if (!cmpl_data ||
+ cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ)
+ return -ENOSPC;
+
+ /* Check for errors */
+ get_signed_result(FBNIC_FW_START_UPGRADE_ERROR, err);
+
+ cmpl_data->result = err;
+ complete(&cmpl_data->done);
+
+ return 0;
+}
+
+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 length = 0, offset = 0;
+ struct fbnic_tlv_msg *msg;
+ int err;
+
+ /* Start by attempting to allocate a response to the message */
+ msg = fbnic_tlv_msg_alloc(FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_RESP);
+ if (!msg)
+ return -ENOMEM;
+
+ /* Verify we have a completion pointer */
+ cmpl_data = READ_ONCE(fbd->cmpl_data);
+ if (!cmpl_data ||
+ cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ) {
+ err = -ENOSPC;
+ goto msg_err;
+ }
+
+ /* Notify FW if the data link has been severed */
+ if (!cmpl_data->fw_update.data) {
+ err = -ECANCELED;
+ goto msg_err;
+ }
+
+ /* Pull length/offset pair and mark it as complete */
+ get_unsigned_result(FBNIC_FW_WRITE_CHUNK_OFFSET, offset);
+ get_unsigned_result(FBNIC_FW_WRITE_CHUNK_LENGTH, length);
+
+ /* Record offset and length for the response */
+ if (offset) {
+ err = fbnic_tlv_attr_put_int(msg, FBNIC_FW_WRITE_CHUNK_OFFSET,
+ offset);
+ if (err)
+ goto msg_err;
+ }
+
+ err = fbnic_tlv_attr_put_int(msg, FBNIC_FW_WRITE_CHUNK_LENGTH,
+ length);
+ if (err)
+ goto msg_err;
+
+ /* Verify length */
+ if (!length || length > TLV_MAX_DATA) {
+ err = -EINVAL;
+ goto msg_err;
+ }
+
+ /* Verify offset and length are within bounds */
+ if (offset >= cmpl_data->fw_update.size ||
+ offset + length > cmpl_data->fw_update.size) {
+ err = -EFAULT;
+ goto msg_err;
+ }
+
+ /* Add outbound data to message */
+ err = fbnic_tlv_attr_put_value(msg, FBNIC_FW_WRITE_CHUNK_DATA,
+ cmpl_data->fw_update.data + offset,
+ length);
+
+ /* Notify the waiting thread that we processed a message */
+ if (!err)
+ cmpl_data->fw_update.last_offset = offset;
+
+ cmpl_data->result = err;
+ complete(&cmpl_data->done);
+
+msg_err:
+ /* Report error to FW if one occurred */
+ if (err)
+ fbnic_tlv_attr_put_int(msg, FBNIC_FW_WRITE_CHUNK_ERROR, err);
+
+ /* Map and send the response */
+ err = fbnic_mbx_map_tlv_msg(fbd, msg);
+ if (err)
+ free_page((unsigned long)msg);
+
+ return err;
+}
+
+static const struct fbnic_tlv_index fbnic_fw_verify_image_resp_index[] = {
+ FBNIC_TLV_ATTR_S32(FBNIC_FW_VERIFY_IMAGE_ERROR),
+ FBNIC_TLV_ATTR_LAST
+};
+
+static int fbnic_fw_parse_fw_verify_image_resp(void *opaque,
+ struct fbnic_tlv_msg **results)
+{
+ struct fbnic_fw_completion *cmpl_data;
+ struct fbnic_dev *fbd = opaque;
+ int err = 0;
+
+ /* Verify we have a completion pointer */
+ cmpl_data = READ_ONCE(fbd->cmpl_data);
+ if (!cmpl_data ||
+ cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_VERIFY_IMAGE_RESP)
+ return -ENOSPC;
+
+ /* Check for errors */
+ get_signed_result(FBNIC_FW_VERIFY_IMAGE_ERROR, err);
+
+ cmpl_data->result = err;
+ complete(&cmpl_data->done);
+
+ return err;
+}
+
+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;
+ int err = 0;
+
+ /* Verify we have a completion pointer */
+ cmpl_data = READ_ONCE(fbd->cmpl_data);
+ if (!cmpl_data ||
+ cmpl_data->msg_type != FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ)
+ return -ENOSPC;
+
+ /* Check for errors */
+ get_signed_result(FBNIC_FW_FINISH_UPGRADE_ERROR, err);
+
+ /* Close out update by clearing data pointer */
+ cmpl_data->fw_update.last_offset = cmpl_data->fw_update.size;
+ cmpl_data->fw_update.data = NULL;
+
+ cmpl_data->result = err;
+ complete(&cmpl_data->done);
+
+ return 0;
+}
+
static const struct fbnic_tlv_parser fbnic_fw_tlv_parser[] = {
FBNIC_TLV_PARSER(FW_CAP_RESP, fbnic_fw_cap_resp_index,
fbnic_fw_parse_cap_resp),
@@ -658,6 +909,18 @@ 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_VERIFY_IMAGE_RESP,
+ fbnic_fw_verify_image_resp_index,
+ fbnic_fw_parse_fw_verify_image_resp),
+ FBNIC_TLV_PARSER(FW_FINISH_UPGRADE_REQ,
+ fbnic_fw_finish_upgrade_req_index,
+ fbnic_fw_parse_fw_finish_upgrade_req),
FBNIC_TLV_MSG_ERROR
};
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
index 7cd8841920e4..347e60fee551 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.h
@@ -45,10 +45,20 @@ struct fbnic_fw_cap {
};
struct fbnic_fw_completion {
- struct {
- s32 millivolts;
- s32 millidegrees;
- } tsene;
+ u32 msg_type;
+ struct completion done;
+ int result;
+ union {
+ struct {
+ u32 size;
+ u32 last_offset;
+ const u8 *data;
+ } fw_update;
+ struct {
+ s32 millivolts;
+ s32 millidegrees;
+ } tsene;
+ };
};
void fbnic_mbx_init(struct fbnic_dev *fbd);
@@ -59,6 +69,9 @@ 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);
#define fbnic_mk_full_fw_ver_str(_rev_id, _delim, _commit, _str, _str_sz) \
do { \
@@ -74,6 +87,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 {
@@ -83,6 +105,14 @@ 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_VERIFY_IMAGE_REQ = 0x26,
+ FBNIC_TLV_MSG_ID_FW_VERIFY_IMAGE_RESP = 0x27,
+ FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_REQ = 0x28,
+ FBNIC_TLV_MSG_ID_FW_FINISH_UPGRADE_RESP = 0x29,
};
#define FBNIC_FW_CAP_RESP_VERSION_MAJOR CSR_GENMASK(31, 24)
@@ -128,4 +158,30 @@ 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_VERIFY_IMAGE_ERROR = 0x0,
+ FBNIC_FW_VERIFY_IMAGE_MSG_MAX
+};
+
+enum {
+ FBNIC_FW_FINISH_UPGRADE_ERROR = 0x0,
+ FBNIC_FW_FINISH_UPGRADE_MSG_MAX
+};
+
#endif /* _FBNIC_FW_H_ */
--
2.43.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH net-next v2 2/2] eth: fbnic: Add devlink dev flash support
2024-10-12 2:34 [PATCH net-next 0/2] eth: fbnic: Add devlink dev flash support Lee Trager
` (3 preceding siblings ...)
2024-10-22 1:37 ` [PATCH net-next v2 1/2] eth: fbnic: Add mailbox support for PLDM updates Lee Trager
@ 2024-10-22 1:42 ` Lee Trager
2024-10-24 9:10 ` Simon Horman
4 siblings, 1 reply; 15+ messages in thread
From: Lee Trager @ 2024-10-22 1:42 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Andrew Lunn,
Lee Trager, Sanman Pradhan, Al Viro, Simon Horman, Mohsin Bashir
Cc: netdev, linux-doc, linux-kernel
fbnic supports updating firmware using a PLDM image signed and distributed
by Meta. PLDM images are written into stored flashed. Flashing does not
interrupt operation.
On host reboot the newly flashed UEFI driver will be used. To run new
control or cmrt firmware the NIC must be power cycled.
Signed-off-by: Lee Trager <lee@trager.us>
---
.../device_drivers/ethernet/meta/fbnic.rst | 11 +
drivers/net/ethernet/meta/Kconfig | 1 +
.../net/ethernet/meta/fbnic/fbnic_devlink.c | 269 +++++++++++++++++-
3 files changed, 280 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst b/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst
index 32ff114f5c26..d6726c254818 100644
--- a/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst
+++ b/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst
@@ -27,3 +27,14 @@ driver takes over.
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 upgrading firmware using devlink dev flash. Firmware images
+are signed and distributed by Meta. All firmware is bundled into a single
+PLDM image which is written into stored flash. Flashing firmware does not
+interrupt operation.
+
+On host reboot the newly flashed UEFI driver will be used. To run new control
+or cmrt firmware the NIC must be power cycled.
diff --git a/drivers/net/ethernet/meta/Kconfig b/drivers/net/ethernet/meta/Kconfig
index 831921b9d4d5..3ba527514f1e 100644
--- a/drivers/net/ethernet/meta/Kconfig
+++ b/drivers/net/ethernet/meta/Kconfig
@@ -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.
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
index 0072d612215e..bd718b3e314b 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
@@ -3,6 +3,7 @@
#include <linux/unaligned.h>
#include <linux/pci.h>
+#include <linux/pldmfw.h>
#include <linux/types.h>
#include <net/devlink.h>
@@ -109,8 +110,274 @@ static int fbnic_devlink_info_get(struct devlink *devlink,
return 0;
}
+/**
+ * fbnic_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.
+ *
+ * Return: zero on success
+ * negative error code on failure
+ */
+static int fbnic_send_package_data(struct pldmfw *context, const u8 *data,
+ u16 length)
+{
+ struct device *dev = context->dev;
+
+ /* Temp placeholder required by devlink */
+ dev_info(dev,
+ "Sending %u bytes of PLDM record package data to firmware\n",
+ length);
+
+ return 0;
+}
+
+/**
+ * fbnic_send_component_table - Send PLDM component table to the firmware
+ * @context: PLDM FW update structure
+ * @component: The component to send
+ * @transfer_flag: Flag indication location in component tables
+ *
+ * Read relevant data from component table and forward it to the firmware.
+ * Check response to verify if the firmware indicates that it wishes to
+ * proceed with the update.
+ *
+ * Return: zero on success
+ * negative error code on failure
+ */
+static int fbnic_send_component_table(struct pldmfw *context,
+ struct pldmfw_component *component,
+ u8 transfer_flag)
+{
+ struct device *dev = context->dev;
+ u16 id = component->identifier;
+ u8 test_string[80];
+
+ switch (id) {
+ case QSPI_SECTION_CMRT:
+ case QSPI_SECTION_CONTROL_FW:
+ case QSPI_SECTION_OPTION_ROM:
+ break;
+ default:
+ dev_err(dev, "Unknown component ID %u\n", id);
+ return -EINVAL;
+ }
+
+ dev_dbg(dev, "Sending PLDM component table to firmware\n");
+
+ /* Temp placeholder */
+ strscpy(test_string, component->version_string,
+ min_t(u8, component->version_len, 79));
+ dev_info(dev, "PLDMFW: Component ID: %u version %s\n",
+ id, test_string);
+
+ return 0;
+}
+
+/**
+ * fbnic_flash_component - Flash a component of the QSPI
+ * @context: PLDM FW update structure
+ * @component: The component table to send to FW
+ *
+ * Map contents of component and make it available for FW to download
+ * so that it can update the contents of the QSPI Flash.
+ *
+ * Return: zero on success
+ * negative error code on failure
+ */
+static int fbnic_flash_component(struct pldmfw *context,
+ struct pldmfw_component *component)
+{
+ const u8 *data = component->component_data;
+ u32 size = component->component_size;
+ struct fbnic_fw_completion *fw_cmpl;
+ struct device *dev = context->dev;
+ struct pci_dev *pdev = to_pci_dev(dev);
+ u16 id = component->identifier;
+ const char *component_name;
+ int retries = 2;
+ int err;
+
+ struct devlink *devlink;
+ struct fbnic_dev *fbd;
+
+ switch (id) {
+ case QSPI_SECTION_CMRT:
+ component_name = "boot1";
+ break;
+ case QSPI_SECTION_CONTROL_FW:
+ component_name = "boot2";
+ break;
+ case QSPI_SECTION_OPTION_ROM:
+ component_name = "option-rom";
+ break;
+ default:
+ dev_err(dev, "Unknown component ID %u\n", id);
+ return -EINVAL;
+ }
+
+ fw_cmpl = kzalloc(sizeof(*fw_cmpl), GFP_KERNEL);
+ if (!fw_cmpl)
+ return -ENOMEM;
+
+ pdev = to_pci_dev(dev);
+ fbd = pci_get_drvdata(pdev);
+ devlink = priv_to_devlink(fbd);
+
+ /* Initialize completion and queue it for FW to process */
+ fw_cmpl->msg_type = FBNIC_TLV_MSG_ID_FW_WRITE_CHUNK_REQ;
+ init_completion(&fw_cmpl->done);
+
+ fw_cmpl->fw_update.last_offset = 0;
+ fw_cmpl->fw_update.data = data;
+ fw_cmpl->fw_update.size = size;
+
+ err = fbnic_fw_xmit_fw_start_upgrade(fbd, fw_cmpl, id, size);
+ if (err)
+ goto cmpl_free;
+
+ /* Monitor completions and report status of update */
+ while (fw_cmpl->fw_update.data) {
+ u32 offset = fw_cmpl->fw_update.last_offset;
+
+ devlink_flash_update_status_notify(devlink, "Flashing",
+ component_name, offset,
+ size);
+
+ /* Allow 5 seconds for reply, resend and try up to 2 times */
+ if (wait_for_completion_timeout(&fw_cmpl->done, 5 * HZ)) {
+ reinit_completion(&fw_cmpl->done);
+ /* If we receive a reply, reinit our retry counter */
+ retries = 2;
+ } else if (--retries == 0) {
+ dev_err(fbd->dev, "Timed out waiting on update\n");
+ err = -ETIMEDOUT;
+ goto cmpl_cleanup;
+ }
+ }
+
+ err = fw_cmpl->result;
+ if (err)
+ goto cmpl_cleanup;
+
+ devlink_flash_update_status_notify(devlink, "Flashing",
+ component_name, size, size);
+
+cmpl_cleanup:
+ fbd->cmpl_data = NULL;
+cmpl_free:
+ kfree(fw_cmpl);
+
+ return err;
+}
+
+/**
+ * fbnic_finalize_update - Perform last steps to complete device update
+ * @context: PLDM FW update structure
+ *
+ * Notify FW that update is complete and that it can take any actions
+ * needed to finalize the FW update.
+ *
+ * Return: zero on success
+ * negative error code on failure
+ */
+static int fbnic_finalize_update(struct pldmfw *context)
+{
+ struct device *dev = context->dev;
+
+ /* Temp placeholder required by devlink */
+ dev_info(dev, "PLDMFW: Finalize update\n");
+
+ return 0;
+}
+
+static const struct pldmfw_ops fbnic_pldmfw_ops = {
+ .match_record = pldmfw_op_pci_match_record,
+ .send_package_data = fbnic_send_package_data,
+ .send_component_table = fbnic_send_component_table,
+ .flash_component = fbnic_flash_component,
+ .finalize_update = fbnic_finalize_update,
+};
+
+static void fbnic_devlink_flash_update_report_err(struct fbnic_dev *fbd,
+ struct devlink *devlink,
+ const char *err_msg,
+ int err)
+{
+ char err_str[128];
+
+ snprintf(err_str, sizeof(err_str),
+ "Failed to flash PLDM Image: %s (error: %d)",
+ err_msg, err);
+ devlink_flash_update_status_notify(devlink, err_str, NULL, 0, 0);
+ dev_err(fbd->dev, "%s\n", err_str);
+}
+
+static int
+fbnic_devlink_flash_update(struct devlink *devlink,
+ struct devlink_flash_update_params *params,
+ struct netlink_ext_ack *extack)
+{
+ struct fbnic_dev *fbd = devlink_priv(devlink);
+ const struct firmware *fw = params->fw;
+ struct device *dev = fbd->dev;
+ struct pldmfw context;
+ char *err_msg;
+ int err;
+
+ if (!fw || !fw->data || !fw->size)
+ return -EINVAL;
+
+ devlink_flash_update_status_notify(devlink, "Preparing to flash",
+ NULL, 0, 0);
+
+ context.ops = &fbnic_pldmfw_ops;
+ context.dev = dev;
+
+ err = pldmfw_flash_image(&context, fw);
+ if (err) {
+ switch (err) {
+ case -EINVAL:
+ err_msg = "Invalid image";
+ break;
+ case -EOPNOTSUPP:
+ err_msg = "Unsupported image";
+ break;
+ case -ENOMEM:
+ err_msg = "Out of memory";
+ break;
+ case -EFAULT:
+ err_msg = "Invalid header";
+ break;
+ case -ENOENT:
+ err_msg = "No matching record";
+ break;
+ case -ENODEV:
+ err_msg = "No matching device";
+ break;
+ case -ETIMEDOUT:
+ err_msg = "Timed out waiting for reply";
+ break;
+ default:
+ err_msg = "Unknown error";
+ break;
+ }
+ fbnic_devlink_flash_update_report_err(fbd, devlink,
+ err_msg, err);
+ } else {
+ devlink_flash_update_status_notify(devlink, "Flashing done",
+ NULL, 0, 0);
+ }
+
+ return err;
+}
+
static const struct devlink_ops fbnic_devlink_ops = {
- .info_get = fbnic_devlink_info_get,
+ .info_get = fbnic_devlink_info_get,
+ .flash_update = fbnic_devlink_flash_update,
};
void fbnic_devlink_free(struct fbnic_dev *fbd)
--
2.43.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH net-next v2 2/2] eth: fbnic: Add devlink dev flash support
2024-10-22 1:42 ` [PATCH net-next v2 2/2] eth: fbnic: Add devlink dev flash support Lee Trager
@ 2024-10-24 9:10 ` Simon Horman
2024-10-25 22:32 ` Lee Trager
0 siblings, 1 reply; 15+ messages in thread
From: Simon Horman @ 2024-10-24 9:10 UTC (permalink / raw)
To: Lee Trager
Cc: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Andrew Lunn,
Sanman Pradhan, Al Viro, Mohsin Bashir, netdev, linux-doc,
linux-kernel
On Mon, Oct 21, 2024 at 06:42:24PM -0700, Lee Trager wrote:
> fbnic supports updating firmware using a PLDM image signed and distributed
> by Meta. PLDM images are written into stored flashed. Flashing does not
> interrupt operation.
>
> On host reboot the newly flashed UEFI driver will be used. To run new
> control or cmrt firmware the NIC must be power cycled.
>
> Signed-off-by: Lee Trager <lee@trager.us>
...
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
...
> @@ -109,8 +110,274 @@ static int fbnic_devlink_info_get(struct devlink *devlink,
> return 0;
> }
>
> +/**
> + * fbnic_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.
> + *
> + * Return: zero on success
> + * negative error code on failure
> + */
> +static int fbnic_send_package_data(struct pldmfw *context, const u8 *data,
> + u16 length)
> +{
> + struct device *dev = context->dev;
> +
> + /* Temp placeholder required by devlink */
> + dev_info(dev,
> + "Sending %u bytes of PLDM record package data to firmware\n",
> + length);
Could you clarify what is meant by "Temp placeholder" here and in
fbnic_send_component_table(). And what plans there might be for
a non-temporary solution.
> +
> + return 0;
> +}
> +
> +/**
> + * fbnic_send_component_table - Send PLDM component table to the firmware
> + * @context: PLDM FW update structure
> + * @component: The component to send
> + * @transfer_flag: Flag indication location in component tables
> + *
> + * Read relevant data from component table and forward it to the firmware.
> + * Check response to verify if the firmware indicates that it wishes to
> + * proceed with the update.
> + *
> + * Return: zero on success
> + * negative error code on failure
> + */
> +static int fbnic_send_component_table(struct pldmfw *context,
> + struct pldmfw_component *component,
> + u8 transfer_flag)
> +{
> + struct device *dev = context->dev;
> + u16 id = component->identifier;
> + u8 test_string[80];
> +
> + switch (id) {
> + case QSPI_SECTION_CMRT:
> + case QSPI_SECTION_CONTROL_FW:
> + case QSPI_SECTION_OPTION_ROM:
> + break;
> + default:
> + dev_err(dev, "Unknown component ID %u\n", id);
> + return -EINVAL;
> + }
> +
> + dev_dbg(dev, "Sending PLDM component table to firmware\n");
> +
> + /* Temp placeholder */
> + strscpy(test_string, component->version_string,
> + min_t(u8, component->version_len, 79));
> + dev_info(dev, "PLDMFW: Component ID: %u version %s\n",
> + id, test_string);
> +
> + return 0;
> +}
...
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net-next v2 2/2] eth: fbnic: Add devlink dev flash support
2024-10-24 9:10 ` Simon Horman
@ 2024-10-25 22:32 ` Lee Trager
2024-10-26 15:12 ` Simon Horman
0 siblings, 1 reply; 15+ messages in thread
From: Lee Trager @ 2024-10-25 22:32 UTC (permalink / raw)
To: Simon Horman
Cc: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Andrew Lunn,
Sanman Pradhan, Al Viro, Mohsin Bashir, netdev, linux-doc,
linux-kernel
On 10/24/24 2:10 AM, Simon Horman wrote:
> On Mon, Oct 21, 2024 at 06:42:24PM -0700, Lee Trager wrote:
>> fbnic supports updating firmware using a PLDM image signed and distributed
>> by Meta. PLDM images are written into stored flashed. Flashing does not
>> interrupt operation.
>>
>> On host reboot the newly flashed UEFI driver will be used. To run new
>> control or cmrt firmware the NIC must be power cycled.
>>
>> Signed-off-by: Lee Trager <lee@trager.us>
> ...
>
>> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
> ...
>
>> @@ -109,8 +110,274 @@ static int fbnic_devlink_info_get(struct devlink *devlink,
>> return 0;
>> }
>>
>> +/**
>> + * fbnic_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.
>> + *
>> + * Return: zero on success
>> + * negative error code on failure
>> + */
>> +static int fbnic_send_package_data(struct pldmfw *context, const u8 *data,
>> + u16 length)
>> +{
>> + struct device *dev = context->dev;
>> +
>> + /* Temp placeholder required by devlink */
>> + dev_info(dev,
>> + "Sending %u bytes of PLDM record package data to firmware\n",
>> + length);
> Could you clarify what is meant by "Temp placeholder" here and in
> fbnic_send_component_table(). And what plans there might be for
> a non-temporary solution.
Temp placeholder may not have been the best wording here. pldmfw
requires all ops to be defined as they are always called[1] when
updating. fbnic has an info message here so its doing something but we
have no current plans to expand on fbnic_send_package_data nor
fbnic_finalize_update.
[1]
https://elixir.bootlin.com/linux/v6.12-rc4/source/lib/pldmfw/pldmfw.c#L723
>
>> +
>> + return 0;
>> +}
>> +
>> +/**
>> + * fbnic_send_component_table - Send PLDM component table to the firmware
>> + * @context: PLDM FW update structure
>> + * @component: The component to send
>> + * @transfer_flag: Flag indication location in component tables
>> + *
>> + * Read relevant data from component table and forward it to the firmware.
>> + * Check response to verify if the firmware indicates that it wishes to
>> + * proceed with the update.
>> + *
>> + * Return: zero on success
>> + * negative error code on failure
>> + */
>> +static int fbnic_send_component_table(struct pldmfw *context,
>> + struct pldmfw_component *component,
>> + u8 transfer_flag)
>> +{
>> + struct device *dev = context->dev;
>> + u16 id = component->identifier;
>> + u8 test_string[80];
>> +
>> + switch (id) {
>> + case QSPI_SECTION_CMRT:
>> + case QSPI_SECTION_CONTROL_FW:
>> + case QSPI_SECTION_OPTION_ROM:
>> + break;
>> + default:
>> + dev_err(dev, "Unknown component ID %u\n", id);
>> + return -EINVAL;
>> + }
>> +
>> + dev_dbg(dev, "Sending PLDM component table to firmware\n");
>> +
>> + /* Temp placeholder */
>> + strscpy(test_string, component->version_string,
>> + min_t(u8, component->version_len, 79));
>> + dev_info(dev, "PLDMFW: Component ID: %u version %s\n",
>> + id, test_string);
>> +
>> + return 0;
>> +}
> ...
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net-next v2 2/2] eth: fbnic: Add devlink dev flash support
2024-10-25 22:32 ` Lee Trager
@ 2024-10-26 15:12 ` Simon Horman
0 siblings, 0 replies; 15+ messages in thread
From: Simon Horman @ 2024-10-26 15:12 UTC (permalink / raw)
To: Lee Trager
Cc: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Andrew Lunn,
Sanman Pradhan, Al Viro, Mohsin Bashir, netdev, linux-doc,
linux-kernel
On Fri, Oct 25, 2024 at 03:32:32PM -0700, Lee Trager wrote:
>
> On 10/24/24 2:10 AM, Simon Horman wrote:
> > On Mon, Oct 21, 2024 at 06:42:24PM -0700, Lee Trager wrote:
> > > fbnic supports updating firmware using a PLDM image signed and distributed
> > > by Meta. PLDM images are written into stored flashed. Flashing does not
> > > interrupt operation.
> > >
> > > On host reboot the newly flashed UEFI driver will be used. To run new
> > > control or cmrt firmware the NIC must be power cycled.
> > >
> > > Signed-off-by: Lee Trager <lee@trager.us>
> > ...
> >
> > > diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c b/drivers/net/ethernet/meta/fbnic/fbnic_devlink.c
> > ...
> >
> > > @@ -109,8 +110,274 @@ static int fbnic_devlink_info_get(struct devlink *devlink,
> > > return 0;
> > > }
> > >
> > > +/**
> > > + * fbnic_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.
> > > + *
> > > + * Return: zero on success
> > > + * negative error code on failure
> > > + */
> > > +static int fbnic_send_package_data(struct pldmfw *context, const u8 *data,
> > > + u16 length)
> > > +{
> > > + struct device *dev = context->dev;
> > > +
> > > + /* Temp placeholder required by devlink */
> > > + dev_info(dev,
> > > + "Sending %u bytes of PLDM record package data to firmware\n",
> > > + length);
> > Could you clarify what is meant by "Temp placeholder" here and in
> > fbnic_send_component_table(). And what plans there might be for
> > a non-temporary solution.
>
> Temp placeholder may not have been the best wording here. pldmfw requires
> all ops to be defined as they are always called[1] when updating. fbnic has
> an info message here so its doing something but we have no current plans to
> expand on fbnic_send_package_data nor fbnic_finalize_update.
>
> [1]
> https://elixir.bootlin.com/linux/v6.12-rc4/source/lib/pldmfw/pldmfw.c#L723
Thanks for the clarification. Perhaps the wording could be improved,
but I don't think that needs to block progress.
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net-next v2 1/2] eth: fbnic: Add mailbox support for PLDM updates
2024-10-22 1:37 ` [PATCH net-next v2 1/2] eth: fbnic: Add mailbox support for PLDM updates Lee Trager
@ 2024-10-26 15:12 ` Simon Horman
0 siblings, 0 replies; 15+ messages in thread
From: Simon Horman @ 2024-10-26 15:12 UTC (permalink / raw)
To: Lee Trager
Cc: Alexander Duyck, Jakub Kicinski, kernel-team, David S. Miller,
Eric Dumazet, Paolo Abeni, Jonathan Corbet, Andrew Lunn,
Sanman Pradhan, Al Viro, Mohsin Bashir, netdev, linux-doc,
linux-kernel
On Mon, Oct 21, 2024 at 06:37:46PM -0700, Lee Trager wrote:
> This adds driver support to utilize the kernel completion API. This allows
> the driver to block on a response from firmware. Initially
> fbnic_fw_completion only has support for updates, future patches will add
> additional features.
>
> Signed-off-by: Lee Trager <lee@trager.us>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2024-10-26 15:12 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-12 2:34 [PATCH net-next 0/2] eth: fbnic: Add devlink dev flash support Lee Trager
2024-10-12 2:34 ` [PATCH net-next 1/2] eth: fbnic: Add mailbox support for PLDM updates Lee Trager
2024-10-14 11:05 ` Vadim Fedorenko
2024-10-12 2:34 ` [PATCH net-next 2/2] eth: fbnic: Add devlink dev flash support Lee Trager
2024-10-14 11:18 ` Vadim Fedorenko
2024-10-15 10:43 ` Simon Horman
2024-10-18 22:48 ` Lee Trager
2024-10-19 9:34 ` Simon Horman
2024-10-22 1:37 ` [PATCH net-next v2 0/2] " Lee Trager
2024-10-22 1:37 ` [PATCH net-next v2 1/2] eth: fbnic: Add mailbox support for PLDM updates Lee Trager
2024-10-26 15:12 ` Simon Horman
2024-10-22 1:42 ` [PATCH net-next v2 2/2] eth: fbnic: Add devlink dev flash support Lee Trager
2024-10-24 9:10 ` Simon Horman
2024-10-25 22:32 ` Lee Trager
2024-10-26 15:12 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).