Skip to content

Commit 1278d17

Browse files
Kalesh APdavem330
authored andcommitted
bnxt_en: Fix devlink fw_activate
To install a livepatch, first flash the package to NVM, and then activate the patch through the "HWRM_FW_LIVEPATCH" fw command. To uninstall a patch from NVM, flash the removal package and then activate it through the "HWRM_FW_LIVEPATCH" fw command. The "HWRM_FW_LIVEPATCH" fw command has to consider following scenarios: 1. no patch in NVM and no patch active. Do nothing. 2. patch in NVM, but not active. Activate the patch currently in NVM. 3. patch is not in NVM, but active. Deactivate the patch. 4. patch in NVM and the patch active. Do nothing. Fix the code to handle these scenarios during devlink "fw_activate". To install and activate a live patch: devlink dev flash pci/0000:c1:00.0 file thor_patch.pkg devlink -f dev reload pci/0000:c1:00.0 action fw_activate limit no_reset To remove and deactivate a live patch: devlink dev flash pci/0000:c1:00.0 file thor_patch_rem.pkg devlink -f dev reload pci/0000:c1:00.0 action fw_activate limit no_reset Fixes: 3c41533 ("bnxt_en: implement firmware live patching") Reviewed-by: Vikas Gupta <[email protected]> Reviewed-by: Somnath Kotur <[email protected]> Signed-off-by: Kalesh AP <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b891106 commit 1278d17

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,26 @@ bnxt_dl_livepatch_report_err(struct bnxt *bp, struct netlink_ext_ack *extack,
367367
}
368368
}
369369

370+
/* Live patch status in NVM */
371+
#define BNXT_LIVEPATCH_NOT_INSTALLED 0
372+
#define BNXT_LIVEPATCH_INSTALLED FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_INSTALL
373+
#define BNXT_LIVEPATCH_REMOVED FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_ACTIVE
374+
#define BNXT_LIVEPATCH_MASK (FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_INSTALL | \
375+
FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_ACTIVE)
376+
#define BNXT_LIVEPATCH_ACTIVATED BNXT_LIVEPATCH_MASK
377+
378+
#define BNXT_LIVEPATCH_STATE(flags) ((flags) & BNXT_LIVEPATCH_MASK)
379+
370380
static int
371381
bnxt_dl_livepatch_activate(struct bnxt *bp, struct netlink_ext_ack *extack)
372382
{
373383
struct hwrm_fw_livepatch_query_output *query_resp;
374384
struct hwrm_fw_livepatch_query_input *query_req;
375385
struct hwrm_fw_livepatch_output *patch_resp;
376386
struct hwrm_fw_livepatch_input *patch_req;
387+
u16 flags, live_patch_state;
388+
bool activated = false;
377389
u32 installed = 0;
378-
u16 flags;
379390
u8 target;
380391
int rc;
381392

@@ -394,7 +405,6 @@ bnxt_dl_livepatch_activate(struct bnxt *bp, struct netlink_ext_ack *extack)
394405
hwrm_req_drop(bp, query_req);
395406
return rc;
396407
}
397-
patch_req->opcode = FW_LIVEPATCH_REQ_OPCODE_ACTIVATE;
398408
patch_req->loadtype = FW_LIVEPATCH_REQ_LOADTYPE_NVM_INSTALL;
399409
patch_resp = hwrm_req_hold(bp, patch_req);
400410

@@ -407,12 +417,20 @@ bnxt_dl_livepatch_activate(struct bnxt *bp, struct netlink_ext_ack *extack)
407417
}
408418

409419
flags = le16_to_cpu(query_resp->status_flags);
410-
if (~flags & FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_INSTALL)
420+
live_patch_state = BNXT_LIVEPATCH_STATE(flags);
421+
422+
if (live_patch_state == BNXT_LIVEPATCH_NOT_INSTALLED)
411423
continue;
412-
if ((flags & FW_LIVEPATCH_QUERY_RESP_STATUS_FLAGS_ACTIVE) &&
413-
!strncmp(query_resp->active_ver, query_resp->install_ver,
414-
sizeof(query_resp->active_ver)))
424+
425+
if (live_patch_state == BNXT_LIVEPATCH_ACTIVATED) {
426+
activated = true;
415427
continue;
428+
}
429+
430+
if (live_patch_state == BNXT_LIVEPATCH_INSTALLED)
431+
patch_req->opcode = FW_LIVEPATCH_REQ_OPCODE_ACTIVATE;
432+
else if (live_patch_state == BNXT_LIVEPATCH_REMOVED)
433+
patch_req->opcode = FW_LIVEPATCH_REQ_OPCODE_DEACTIVATE;
416434

417435
patch_req->fw_target = target;
418436
rc = hwrm_req_send(bp, patch_req);
@@ -424,8 +442,13 @@ bnxt_dl_livepatch_activate(struct bnxt *bp, struct netlink_ext_ack *extack)
424442
}
425443

426444
if (!rc && !installed) {
427-
NL_SET_ERR_MSG_MOD(extack, "No live patches found");
428-
rc = -ENOENT;
445+
if (activated) {
446+
NL_SET_ERR_MSG_MOD(extack, "Live patch already activated");
447+
rc = -EEXIST;
448+
} else {
449+
NL_SET_ERR_MSG_MOD(extack, "No live patches found");
450+
rc = -ENOENT;
451+
}
429452
}
430453
hwrm_req_drop(bp, query_req);
431454
hwrm_req_drop(bp, patch_req);

0 commit comments

Comments
 (0)