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)
9 struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
10 struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
12 return otx2_cpt_dl_custom_egrp_create(cptpf, ctx);
15 static int otx2_cpt_dl_egrp_delete(struct devlink *dl, u32 id,
16 struct devlink_param_gset_ctx *ctx)
18 struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
19 struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
21 return otx2_cpt_dl_custom_egrp_delete(cptpf, ctx);
24 static int otx2_cpt_dl_uc_info(struct devlink *dl, u32 id,
25 struct devlink_param_gset_ctx *ctx)
27 struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
28 struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
30 otx2_cpt_print_uc_dbg_info(cptpf);
35 enum otx2_cpt_dl_param_id {
36 OTX2_CPT_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
37 OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,
38 OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,
41 static const struct devlink_param otx2_cpt_dl_params[] = {
42 DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,
43 "egrp_create", DEVLINK_PARAM_TYPE_STRING,
44 BIT(DEVLINK_PARAM_CMODE_RUNTIME),
45 otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_create,
47 DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,
48 "egrp_delete", DEVLINK_PARAM_TYPE_STRING,
49 BIT(DEVLINK_PARAM_CMODE_RUNTIME),
50 otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_delete,
54 static int otx2_cpt_dl_info_firmware_version_put(struct devlink_info_req *req,
55 struct otx2_cpt_eng_grp_info grp[],
56 const char *ver_name, int eng_type)
58 struct otx2_cpt_engs_rsvd *eng;
61 for (i = 0; i < OTX2_CPT_MAX_ENGINE_GROUPS; i++) {
62 eng = find_engines_by_type(&grp[i], eng_type);
64 return devlink_info_version_running_put(req, ver_name,
71 static int otx2_cpt_devlink_info_get(struct devlink *dl,
72 struct devlink_info_req *req,
73 struct netlink_ext_ack *extack)
75 struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
76 struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
79 err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,
80 "fw.ae", OTX2_CPT_AE_TYPES);
84 err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,
85 "fw.se", OTX2_CPT_SE_TYPES);
89 return otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,
90 "fw.ie", OTX2_CPT_IE_TYPES);
93 static const struct devlink_ops otx2_cpt_devlink_ops = {
94 .info_get = otx2_cpt_devlink_info_get,
97 int otx2_cpt_register_dl(struct otx2_cptpf_dev *cptpf)
99 struct device *dev = &cptpf->pdev->dev;
100 struct otx2_cpt_devlink *cpt_dl;
104 dl = devlink_alloc(&otx2_cpt_devlink_ops,
105 sizeof(struct otx2_cpt_devlink), dev);
107 dev_warn(dev, "devlink_alloc failed\n");
111 cpt_dl = devlink_priv(dl);
113 cpt_dl->cptpf = cptpf;
115 ret = devlink_params_register(dl, otx2_cpt_dl_params,
116 ARRAY_SIZE(otx2_cpt_dl_params));
118 dev_err(dev, "devlink params register failed with error %d",
124 devlink_register(dl);
129 void otx2_cpt_unregister_dl(struct otx2_cptpf_dev *cptpf)
131 struct devlink *dl = cptpf->dl;
136 devlink_unregister(dl);
137 devlink_params_unregister(dl, otx2_cpt_dl_params,
138 ARRAY_SIZE(otx2_cpt_dl_params));