Skip to content

Commit ed82740

Browse files
Michael ChanPaolo Abeni
authored andcommitted
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>
1 parent b54b249 commit ed82740

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
@@ -1023,37 +1023,19 @@ static int bnxt_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
10231023

10241024
}
10251025

1026-
static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
1027-
union devlink_param_value *val)
1026+
static int __bnxt_hwrm_nvm_req(struct bnxt *bp,
1027+
const struct bnxt_dl_nvm_param *nvm, void *msg,
1028+
union devlink_param_value *val)
10281029
{
10291030
struct hwrm_nvm_get_variable_input *req = msg;
1030-
struct bnxt_dl_nvm_param nvm_param;
10311031
struct hwrm_err_output *resp;
10321032
union bnxt_nvm_data *data;
10331033
dma_addr_t data_dma_addr;
1034-
int idx = 0, rc, i;
1035-
1036-
/* Get/Set NVM CFG parameter is supported only on PFs */
1037-
if (BNXT_VF(bp)) {
1038-
hwrm_req_drop(bp, req);
1039-
return -EPERM;
1040-
}
1041-
1042-
for (i = 0; i < ARRAY_SIZE(nvm_params); i++) {
1043-
if (nvm_params[i].id == param_id) {
1044-
nvm_param = nvm_params[i];
1045-
break;
1046-
}
1047-
}
1048-
1049-
if (i == ARRAY_SIZE(nvm_params)) {
1050-
hwrm_req_drop(bp, req);
1051-
return -EOPNOTSUPP;
1052-
}
1034+
int idx = 0, rc;
10531035

1054-
if (nvm_param.dir_type == BNXT_NVM_PORT_CFG)
1036+
if (nvm->dir_type == BNXT_NVM_PORT_CFG)
10551037
idx = bp->pf.port_id;
1056-
else if (nvm_param.dir_type == BNXT_NVM_FUNC_CFG)
1038+
else if (nvm->dir_type == BNXT_NVM_FUNC_CFG)
10571039
idx = bp->pf.fw_fid - BNXT_FIRST_PF_FID;
10581040

10591041
data = hwrm_req_dma_slice(bp, req, sizeof(*data), &data_dma_addr);
@@ -1064,23 +1046,23 @@ static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
10641046
}
10651047

10661048
req->dest_data_addr = cpu_to_le64(data_dma_addr);
1067-
req->data_len = cpu_to_le16(nvm_param.nvm_num_bits);
1068-
req->option_num = cpu_to_le16(nvm_param.offset);
1049+
req->data_len = cpu_to_le16(nvm->nvm_num_bits);
1050+
req->option_num = cpu_to_le16(nvm->offset);
10691051
req->index_0 = cpu_to_le16(idx);
10701052
if (idx)
10711053
req->dimensions = cpu_to_le16(1);
10721054

10731055
resp = hwrm_req_hold(bp, req);
10741056
if (req->req_type == cpu_to_le16(HWRM_NVM_SET_VARIABLE)) {
1075-
bnxt_copy_to_nvm_data(data, val, nvm_param.nvm_num_bits,
1076-
nvm_param.dl_num_bytes);
1057+
bnxt_copy_to_nvm_data(data, val, nvm->nvm_num_bits,
1058+
nvm->dl_num_bytes);
10771059
rc = hwrm_req_send(bp, msg);
10781060
} else {
10791061
rc = hwrm_req_send_silent(bp, msg);
10801062
if (!rc) {
10811063
bnxt_copy_from_nvm_data(val, data,
1082-
nvm_param.nvm_num_bits,
1083-
nvm_param.dl_num_bytes);
1064+
nvm->nvm_num_bits,
1065+
nvm->dl_num_bytes);
10841066
} else {
10851067
if (resp->cmd_err ==
10861068
NVM_GET_VARIABLE_CMD_ERR_CODE_VAR_NOT_EXIST)
@@ -1093,6 +1075,27 @@ static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
10931075
return rc;
10941076
}
10951077

1078+
static int bnxt_hwrm_nvm_req(struct bnxt *bp, u32 param_id, void *msg,
1079+
union devlink_param_value *val)
1080+
{
1081+
struct hwrm_nvm_get_variable_input *req = msg;
1082+
const struct bnxt_dl_nvm_param *nvm_param;
1083+
int i;
1084+
1085+
/* Get/Set NVM CFG parameter is supported only on PFs */
1086+
if (BNXT_VF(bp)) {
1087+
hwrm_req_drop(bp, req);
1088+
return -EPERM;
1089+
}
1090+
1091+
for (i = 0; i < ARRAY_SIZE(nvm_params); i++) {
1092+
nvm_param = &nvm_params[i];
1093+
if (nvm_param->id == param_id)
1094+
return __bnxt_hwrm_nvm_req(bp, nvm_param, msg, val);
1095+
}
1096+
return -EOPNOTSUPP;
1097+
}
1098+
10961099
static int bnxt_dl_nvm_param_get(struct devlink *dl, u32 id,
10971100
struct devlink_param_gset_ctx *ctx)
10981101
{

0 commit comments

Comments
 (0)