Skip to content

Commit cc3b0ae

Browse files
author
Shruti Parab
committed
bnxt_en: Refactor bnxt_hwrm_nvm_req()
JIRA: https://issues.redhat.com/browse/RHEL-76565 commit ed82740 Author: Michael Chan <michael.chan@broadcom.com> Date: Mon Mar 10 11:31:24 2025 -0700 bnxt_en: Refactor bnxt_hwrm_nvm_req() bnxt_hwrm_nvm_req() first searches the nvm_params[] array for the NVM parameter to set or get. The array entry contains all the NVM information about that parameter. The information is then used to send the FW message to set or get the parameter. Refactor it to only do the array search in bnxt_hwrm_nvm_req() and pass the array entry to the new function __bnxt_hwrm_nvm_req() to send the FW message. The next patch will be able to use the new function. Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Link: https://patch.msgid.link/20250310183129.3154117-3-michael.chan@broadcom.com Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Shruti Parab <shruti.parab@broadcom.com>
1 parent c053174 commit cc3b0ae

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,37 +1010,19 @@ static int bnxt_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
10101010

10111011
}
10121012

1013-
static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
1014-
union devlink_param_value *val)
1013+
static int __bnxt_hwrm_nvm_req(struct bnxt *bp,
1014+
const struct bnxt_dl_nvm_param *nvm, void *msg,
1015+
union devlink_param_value *val)
10151016
{
10161017
struct hwrm_nvm_get_variable_input *req = msg;
1017-
struct bnxt_dl_nvm_param nvm_param;
10181018
struct hwrm_err_output *resp;
10191019
union bnxt_nvm_data *data;
10201020
dma_addr_t data_dma_addr;
1021-
int idx = 0, rc, i;
1022-
1023-
/* Get/Set NVM CFG parameter is supported only on PFs */
1024-
if (BNXT_VF(bp)) {
1025-
hwrm_req_drop(bp, req);
1026-
return -EPERM;
1027-
}
1028-
1029-
for (i = 0; i < ARRAY_SIZE(nvm_params); i++) {
1030-
if (nvm_params[i].id == param_id) {
1031-
nvm_param = nvm_params[i];
1032-
break;
1033-
}
1034-
}
1035-
1036-
if (i == ARRAY_SIZE(nvm_params)) {
1037-
hwrm_req_drop(bp, req);
1038-
return -EOPNOTSUPP;
1039-
}
1021+
int idx = 0, rc;
10401022

1041-
if (nvm_param.dir_type == BNXT_NVM_PORT_CFG)
1023+
if (nvm->dir_type == BNXT_NVM_PORT_CFG)
10421024
idx = bp->pf.port_id;
1043-
else if (nvm_param.dir_type == BNXT_NVM_FUNC_CFG)
1025+
else if (nvm->dir_type == BNXT_NVM_FUNC_CFG)
10441026
idx = bp->pf.fw_fid - BNXT_FIRST_PF_FID;
10451027

10461028
data = hwrm_req_dma_slice(bp, req, sizeof(*data), &data_dma_addr);
@@ -1051,23 +1033,23 @@ static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
10511033
}
10521034

10531035
req->dest_data_addr = cpu_to_le64(data_dma_addr);
1054-
req->data_len = cpu_to_le16(nvm_param.nvm_num_bits);
1055-
req->option_num = cpu_to_le16(nvm_param.offset);
1036+
req->data_len = cpu_to_le16(nvm->nvm_num_bits);
1037+
req->option_num = cpu_to_le16(nvm->offset);
10561038
req->index_0 = cpu_to_le16(idx);
10571039
if (idx)
10581040
req->dimensions = cpu_to_le16(1);
10591041

10601042
resp = hwrm_req_hold(bp, req);
10611043
if (req->req_type == cpu_to_le16(HWRM_NVM_SET_VARIABLE)) {
1062-
bnxt_copy_to_nvm_data(data, val, nvm_param.nvm_num_bits,
1063-
nvm_param.dl_num_bytes);
1044+
bnxt_copy_to_nvm_data(data, val, nvm->nvm_num_bits,
1045+
nvm->dl_num_bytes);
10641046
rc = hwrm_req_send(bp, msg);
10651047
} else {
10661048
rc = hwrm_req_send_silent(bp, msg);
10671049
if (!rc) {
10681050
bnxt_copy_from_nvm_data(val, data,
1069-
nvm_param.nvm_num_bits,
1070-
nvm_param.dl_num_bytes);
1051+
nvm->nvm_num_bits,
1052+
nvm->dl_num_bytes);
10711053
} else {
10721054
if (resp->cmd_err ==
10731055
NVM_GET_VARIABLE_CMD_ERR_CODE_VAR_NOT_EXIST)
@@ -1080,6 +1062,27 @@ static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
10801062
return rc;
10811063
}
10821064

1065+
static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
1066+
union devlink_param_value *val)
1067+
{
1068+
struct hwrm_nvm_get_variable_input *req = msg;
1069+
const struct bnxt_dl_nvm_param *nvm_param;
1070+
int i;
1071+
1072+
/* Get/Set NVM CFG parameter is supported only on PFs */
1073+
if (BNXT_VF(bp)) {
1074+
hwrm_req_drop(bp, req);
1075+
return -EPERM;
1076+
}
1077+
1078+
for (i = 0; i < ARRAY_SIZE(nvm_params); i++) {
1079+
nvm_param = &nvm_params[i];
1080+
if (nvm_param->id == param_id)
1081+
return __bnxt_hwrm_nvm_req(bp, nvm_param, msg, val);
1082+
}
1083+
return -EOPNOTSUPP;
1084+
}
1085+
10831086
static int bnxt_dl_nvm_param_get(struct devlink *dl, u32 id,
10841087
struct devlink_param_gset_ctx *ctx)
10851088
{

0 commit comments

Comments
 (0)