bnxt_en: Defrag the NVRAM region when resizing UPDATE region fails

When updating to a new firmware pkg, the driver checks if the UPDATE
region is big enough for the pkg and if it's not big enough, it
issues an NVM_WRITE cmd to update with the requested size.

This NVM_WRITE cmd can fail indicating fragmented region. Currently
the driver fails the fw update when this happens. We can improve the
situation by defragmenting the region and try the NVM_WRITE cmd
again. This will make firmware update more reliable.

Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Signed-off-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Link: https://patch.msgid.link/20260108183521.215610-5-michael.chan@broadcom.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Pavan Chebbi 2026-01-08 10:35:19 -08:00 committed by Jakub Kicinski
parent e1c9c8928b
commit 743e683596

View File

@ -3848,9 +3848,25 @@ static int nvm_update_err_to_stderr(struct net_device *dev, u8 result,
#define BNXT_NVM_MORE_FLAG (cpu_to_le16(NVM_MODIFY_REQ_FLAGS_BATCH_MODE))
#define BNXT_NVM_LAST_FLAG (cpu_to_le16(NVM_MODIFY_REQ_FLAGS_BATCH_LAST))
static int bnxt_hwrm_nvm_defrag(struct bnxt *bp)
{
struct hwrm_nvm_defrag_input *req;
int rc;
rc = hwrm_req_init(bp, req, HWRM_NVM_DEFRAG);
if (rc)
return rc;
req->flags = cpu_to_le32(NVM_DEFRAG_REQ_FLAGS_DEFRAG);
hwrm_req_timeout(bp, req, bp->hwrm_cmd_max_timeout);
return hwrm_req_send(bp, req);
}
static int bnxt_resize_update_entry(struct net_device *dev, size_t fw_size,
struct netlink_ext_ack *extack)
{
struct bnxt *bp = netdev_priv(dev);
bool retry = false;
u32 item_len;
int rc;
@ -3863,9 +3879,19 @@ static int bnxt_resize_update_entry(struct net_device *dev, size_t fw_size,
}
if (fw_size > item_len) {
rc = bnxt_flash_nvram(dev, BNX_DIR_TYPE_UPDATE,
BNX_DIR_ORDINAL_FIRST, 0, 1,
round_up(fw_size, 4096), NULL, 0);
do {
rc = bnxt_flash_nvram(dev, BNX_DIR_TYPE_UPDATE,
BNX_DIR_ORDINAL_FIRST, 0, 1,
round_up(fw_size, 4096), NULL,
0);
if (rc == -ENOSPC) {
if (retry || bnxt_hwrm_nvm_defrag(bp))
break;
retry = true;
}
} while (rc == -ENOSPC);
if (rc) {
BNXT_NVM_ERR_MSG(dev, extack, MSG_RESIZE_UPDATE_ERR);
return rc;