1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (C) 2021 Marvell. */
4 #include "otx2_cpt_devlink.h"
6 static int otx2_cpt_dl_egrp_create(struct devlink
*dl
, u32 id
,
7 struct devlink_param_gset_ctx
*ctx
,
8 struct netlink_ext_ack
*extack
)
10 struct otx2_cpt_devlink
*cpt_dl
= devlink_priv(dl
);
11 struct otx2_cptpf_dev
*cptpf
= cpt_dl
->cptpf
;
13 return otx2_cpt_dl_custom_egrp_create(cptpf
, ctx
);
16 static int otx2_cpt_dl_egrp_delete(struct devlink
*dl
, u32 id
,
17 struct devlink_param_gset_ctx
*ctx
,
18 struct netlink_ext_ack
*extack
)
20 struct otx2_cpt_devlink
*cpt_dl
= devlink_priv(dl
);
21 struct otx2_cptpf_dev
*cptpf
= cpt_dl
->cptpf
;
23 return otx2_cpt_dl_custom_egrp_delete(cptpf
, ctx
);
26 static int otx2_cpt_dl_uc_info(struct devlink
*dl
, u32 id
,
27 struct devlink_param_gset_ctx
*ctx
)
29 ctx
->val
.vstr
[0] = '\0';
34 static int otx2_cpt_dl_t106_mode_get(struct devlink
*dl
, u32 id
,
35 struct devlink_param_gset_ctx
*ctx
)
37 struct otx2_cpt_devlink
*cpt_dl
= devlink_priv(dl
);
38 struct otx2_cptpf_dev
*cptpf
= cpt_dl
->cptpf
;
39 struct pci_dev
*pdev
= cptpf
->pdev
;
42 otx2_cpt_read_af_reg(&cptpf
->afpf_mbox
, pdev
, CPT_AF_CTL
, ®_val
,
44 ctx
->val
.vu8
= (reg_val
>> 18) & 0x1;
49 static int otx2_cpt_dl_t106_mode_set(struct devlink
*dl
, u32 id
,
50 struct devlink_param_gset_ctx
*ctx
,
51 struct netlink_ext_ack
*extack
)
53 struct otx2_cpt_devlink
*cpt_dl
= devlink_priv(dl
);
54 struct otx2_cptpf_dev
*cptpf
= cpt_dl
->cptpf
;
55 struct pci_dev
*pdev
= cptpf
->pdev
;
58 if (cptpf
->enabled_vfs
!= 0 || cptpf
->eng_grps
.is_grps_created
)
61 if (cpt_feature_sgv2(pdev
)) {
62 otx2_cpt_read_af_reg(&cptpf
->afpf_mbox
, pdev
, CPT_AF_CTL
,
63 ®_val
, BLKADDR_CPT0
);
64 reg_val
&= ~(0x1ULL
<< 18);
65 reg_val
|= ((u64
)ctx
->val
.vu8
& 0x1) << 18;
66 return otx2_cpt_write_af_reg(&cptpf
->afpf_mbox
, pdev
,
67 CPT_AF_CTL
, reg_val
, BLKADDR_CPT0
);
73 enum otx2_cpt_dl_param_id
{
74 OTX2_CPT_DEVLINK_PARAM_ID_BASE
= DEVLINK_PARAM_GENERIC_ID_MAX
,
75 OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE
,
76 OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE
,
77 OTX2_CPT_DEVLINK_PARAM_ID_T106_MODE
,
80 static const struct devlink_param otx2_cpt_dl_params
[] = {
81 DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE
,
82 "egrp_create", DEVLINK_PARAM_TYPE_STRING
,
83 BIT(DEVLINK_PARAM_CMODE_RUNTIME
),
84 otx2_cpt_dl_uc_info
, otx2_cpt_dl_egrp_create
,
86 DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE
,
87 "egrp_delete", DEVLINK_PARAM_TYPE_STRING
,
88 BIT(DEVLINK_PARAM_CMODE_RUNTIME
),
89 otx2_cpt_dl_uc_info
, otx2_cpt_dl_egrp_delete
,
91 DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_T106_MODE
,
92 "t106_mode", DEVLINK_PARAM_TYPE_U8
,
93 BIT(DEVLINK_PARAM_CMODE_RUNTIME
),
94 otx2_cpt_dl_t106_mode_get
, otx2_cpt_dl_t106_mode_set
,
98 static int otx2_cpt_dl_info_firmware_version_put(struct devlink_info_req
*req
,
99 struct otx2_cpt_eng_grp_info grp
[],
100 const char *ver_name
, int eng_type
)
102 struct otx2_cpt_engs_rsvd
*eng
;
105 for (i
= 0; i
< OTX2_CPT_MAX_ENGINE_GROUPS
; i
++) {
106 eng
= find_engines_by_type(&grp
[i
], eng_type
);
108 return devlink_info_version_running_put(req
, ver_name
,
109 eng
->ucode
->ver_str
);
115 static int otx2_cpt_devlink_info_get(struct devlink
*dl
,
116 struct devlink_info_req
*req
,
117 struct netlink_ext_ack
*extack
)
119 struct otx2_cpt_devlink
*cpt_dl
= devlink_priv(dl
);
120 struct otx2_cptpf_dev
*cptpf
= cpt_dl
->cptpf
;
123 err
= otx2_cpt_dl_info_firmware_version_put(req
, cptpf
->eng_grps
.grp
,
124 "fw.ae", OTX2_CPT_AE_TYPES
);
128 err
= otx2_cpt_dl_info_firmware_version_put(req
, cptpf
->eng_grps
.grp
,
129 "fw.se", OTX2_CPT_SE_TYPES
);
133 return otx2_cpt_dl_info_firmware_version_put(req
, cptpf
->eng_grps
.grp
,
134 "fw.ie", OTX2_CPT_IE_TYPES
);
137 static const struct devlink_ops otx2_cpt_devlink_ops
= {
138 .info_get
= otx2_cpt_devlink_info_get
,
141 int otx2_cpt_register_dl(struct otx2_cptpf_dev
*cptpf
)
143 struct device
*dev
= &cptpf
->pdev
->dev
;
144 struct otx2_cpt_devlink
*cpt_dl
;
148 dl
= devlink_alloc(&otx2_cpt_devlink_ops
,
149 sizeof(struct otx2_cpt_devlink
), dev
);
151 dev_warn(dev
, "devlink_alloc failed\n");
155 cpt_dl
= devlink_priv(dl
);
157 cpt_dl
->cptpf
= cptpf
;
159 ret
= devlink_params_register(dl
, otx2_cpt_dl_params
,
160 ARRAY_SIZE(otx2_cpt_dl_params
));
162 dev_err(dev
, "devlink params register failed with error %d",
167 devlink_register(dl
);
172 void otx2_cpt_unregister_dl(struct otx2_cptpf_dev
*cptpf
)
174 struct devlink
*dl
= cptpf
->dl
;
179 devlink_unregister(dl
);
180 devlink_params_unregister(dl
, otx2_cpt_dl_params
,
181 ARRAY_SIZE(otx2_cpt_dl_params
));