1fed8f4d5SSrujana Challa // SPDX-License-Identifier: GPL-2.0-only
2fed8f4d5SSrujana Challa /* Copyright (C) 2021 Marvell. */
3fed8f4d5SSrujana Challa
4fed8f4d5SSrujana Challa #include "otx2_cpt_devlink.h"
5fed8f4d5SSrujana Challa
otx2_cpt_dl_egrp_create(struct devlink * dl,u32 id,struct devlink_param_gset_ctx * ctx)6fed8f4d5SSrujana Challa static int otx2_cpt_dl_egrp_create(struct devlink *dl, u32 id,
7fed8f4d5SSrujana Challa struct devlink_param_gset_ctx *ctx)
8fed8f4d5SSrujana Challa {
9fed8f4d5SSrujana Challa struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
10fed8f4d5SSrujana Challa struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
11fed8f4d5SSrujana Challa
12fed8f4d5SSrujana Challa return otx2_cpt_dl_custom_egrp_create(cptpf, ctx);
13fed8f4d5SSrujana Challa }
14fed8f4d5SSrujana Challa
otx2_cpt_dl_egrp_delete(struct devlink * dl,u32 id,struct devlink_param_gset_ctx * ctx)15fed8f4d5SSrujana Challa static int otx2_cpt_dl_egrp_delete(struct devlink *dl, u32 id,
16fed8f4d5SSrujana Challa struct devlink_param_gset_ctx *ctx)
17fed8f4d5SSrujana Challa {
18fed8f4d5SSrujana Challa struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
19fed8f4d5SSrujana Challa struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
20fed8f4d5SSrujana Challa
21fed8f4d5SSrujana Challa return otx2_cpt_dl_custom_egrp_delete(cptpf, ctx);
22fed8f4d5SSrujana Challa }
23fed8f4d5SSrujana Challa
otx2_cpt_dl_uc_info(struct devlink * dl,u32 id,struct devlink_param_gset_ctx * ctx)24fed8f4d5SSrujana Challa static int otx2_cpt_dl_uc_info(struct devlink *dl, u32 id,
25fed8f4d5SSrujana Challa struct devlink_param_gset_ctx *ctx)
26fed8f4d5SSrujana Challa {
27fed8f4d5SSrujana Challa struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
28fed8f4d5SSrujana Challa struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
29fed8f4d5SSrujana Challa
30fed8f4d5SSrujana Challa otx2_cpt_print_uc_dbg_info(cptpf);
31fed8f4d5SSrujana Challa
32fed8f4d5SSrujana Challa return 0;
33fed8f4d5SSrujana Challa }
34fed8f4d5SSrujana Challa
35fed8f4d5SSrujana Challa enum otx2_cpt_dl_param_id {
36fed8f4d5SSrujana Challa OTX2_CPT_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
37fed8f4d5SSrujana Challa OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,
38fed8f4d5SSrujana Challa OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,
39fed8f4d5SSrujana Challa };
40fed8f4d5SSrujana Challa
41fed8f4d5SSrujana Challa static const struct devlink_param otx2_cpt_dl_params[] = {
42fed8f4d5SSrujana Challa DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_CREATE,
43fed8f4d5SSrujana Challa "egrp_create", DEVLINK_PARAM_TYPE_STRING,
44fed8f4d5SSrujana Challa BIT(DEVLINK_PARAM_CMODE_RUNTIME),
45fed8f4d5SSrujana Challa otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_create,
46fed8f4d5SSrujana Challa NULL),
47fed8f4d5SSrujana Challa DEVLINK_PARAM_DRIVER(OTX2_CPT_DEVLINK_PARAM_ID_EGRP_DELETE,
48fed8f4d5SSrujana Challa "egrp_delete", DEVLINK_PARAM_TYPE_STRING,
49fed8f4d5SSrujana Challa BIT(DEVLINK_PARAM_CMODE_RUNTIME),
50fed8f4d5SSrujana Challa otx2_cpt_dl_uc_info, otx2_cpt_dl_egrp_delete,
51fed8f4d5SSrujana Challa NULL),
52fed8f4d5SSrujana Challa };
53fed8f4d5SSrujana Challa
otx2_cpt_dl_info_firmware_version_put(struct devlink_info_req * req,struct otx2_cpt_eng_grp_info grp[],const char * ver_name,int eng_type)54*4ad28689SShijith Thotton static int otx2_cpt_dl_info_firmware_version_put(struct devlink_info_req *req,
55*4ad28689SShijith Thotton struct otx2_cpt_eng_grp_info grp[],
56*4ad28689SShijith Thotton const char *ver_name, int eng_type)
57*4ad28689SShijith Thotton {
58*4ad28689SShijith Thotton struct otx2_cpt_engs_rsvd *eng;
59*4ad28689SShijith Thotton int i;
60*4ad28689SShijith Thotton
61*4ad28689SShijith Thotton for (i = 0; i < OTX2_CPT_MAX_ENGINE_GROUPS; i++) {
62*4ad28689SShijith Thotton eng = find_engines_by_type(&grp[i], eng_type);
63*4ad28689SShijith Thotton if (eng)
64*4ad28689SShijith Thotton return devlink_info_version_running_put(req, ver_name,
65*4ad28689SShijith Thotton eng->ucode->ver_str);
66*4ad28689SShijith Thotton }
67*4ad28689SShijith Thotton
68*4ad28689SShijith Thotton return 0;
69*4ad28689SShijith Thotton }
70*4ad28689SShijith Thotton
otx2_cpt_devlink_info_get(struct devlink * dl,struct devlink_info_req * req,struct netlink_ext_ack * extack)71*4ad28689SShijith Thotton static int otx2_cpt_devlink_info_get(struct devlink *dl,
72fed8f4d5SSrujana Challa struct devlink_info_req *req,
73fed8f4d5SSrujana Challa struct netlink_ext_ack *extack)
74fed8f4d5SSrujana Challa {
75*4ad28689SShijith Thotton struct otx2_cpt_devlink *cpt_dl = devlink_priv(dl);
76*4ad28689SShijith Thotton struct otx2_cptpf_dev *cptpf = cpt_dl->cptpf;
77*4ad28689SShijith Thotton int err;
78*4ad28689SShijith Thotton
79*4ad28689SShijith Thotton err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,
80*4ad28689SShijith Thotton "fw.ae", OTX2_CPT_AE_TYPES);
81*4ad28689SShijith Thotton if (err)
82*4ad28689SShijith Thotton return err;
83*4ad28689SShijith Thotton
84*4ad28689SShijith Thotton err = otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,
85*4ad28689SShijith Thotton "fw.se", OTX2_CPT_SE_TYPES);
86*4ad28689SShijith Thotton if (err)
87*4ad28689SShijith Thotton return err;
88*4ad28689SShijith Thotton
89*4ad28689SShijith Thotton return otx2_cpt_dl_info_firmware_version_put(req, cptpf->eng_grps.grp,
90*4ad28689SShijith Thotton "fw.ie", OTX2_CPT_IE_TYPES);
91fed8f4d5SSrujana Challa }
92fed8f4d5SSrujana Challa
93fed8f4d5SSrujana Challa static const struct devlink_ops otx2_cpt_devlink_ops = {
94fed8f4d5SSrujana Challa .info_get = otx2_cpt_devlink_info_get,
95fed8f4d5SSrujana Challa };
96fed8f4d5SSrujana Challa
otx2_cpt_register_dl(struct otx2_cptpf_dev * cptpf)97fed8f4d5SSrujana Challa int otx2_cpt_register_dl(struct otx2_cptpf_dev *cptpf)
98fed8f4d5SSrujana Challa {
99fed8f4d5SSrujana Challa struct device *dev = &cptpf->pdev->dev;
100fed8f4d5SSrujana Challa struct otx2_cpt_devlink *cpt_dl;
101fed8f4d5SSrujana Challa struct devlink *dl;
102fed8f4d5SSrujana Challa int ret;
103fed8f4d5SSrujana Challa
104fed8f4d5SSrujana Challa dl = devlink_alloc(&otx2_cpt_devlink_ops,
105fed8f4d5SSrujana Challa sizeof(struct otx2_cpt_devlink), dev);
106fed8f4d5SSrujana Challa if (!dl) {
107fed8f4d5SSrujana Challa dev_warn(dev, "devlink_alloc failed\n");
108fed8f4d5SSrujana Challa return -ENOMEM;
109fed8f4d5SSrujana Challa }
110fed8f4d5SSrujana Challa
111fed8f4d5SSrujana Challa cpt_dl = devlink_priv(dl);
112fed8f4d5SSrujana Challa cpt_dl->dl = dl;
113fed8f4d5SSrujana Challa cpt_dl->cptpf = cptpf;
114fed8f4d5SSrujana Challa cptpf->dl = dl;
115fed8f4d5SSrujana Challa ret = devlink_params_register(dl, otx2_cpt_dl_params,
116fed8f4d5SSrujana Challa ARRAY_SIZE(otx2_cpt_dl_params));
117fed8f4d5SSrujana Challa if (ret) {
118fed8f4d5SSrujana Challa dev_err(dev, "devlink params register failed with error %d",
119fed8f4d5SSrujana Challa ret);
120fed8f4d5SSrujana Challa devlink_free(dl);
121fed8f4d5SSrujana Challa return ret;
122fed8f4d5SSrujana Challa }
123fed8f4d5SSrujana Challa
124fed8f4d5SSrujana Challa devlink_register(dl);
125fed8f4d5SSrujana Challa
126fed8f4d5SSrujana Challa return 0;
127fed8f4d5SSrujana Challa }
128fed8f4d5SSrujana Challa
otx2_cpt_unregister_dl(struct otx2_cptpf_dev * cptpf)129fed8f4d5SSrujana Challa void otx2_cpt_unregister_dl(struct otx2_cptpf_dev *cptpf)
130fed8f4d5SSrujana Challa {
131fed8f4d5SSrujana Challa struct devlink *dl = cptpf->dl;
132fed8f4d5SSrujana Challa
133fed8f4d5SSrujana Challa if (!dl)
134fed8f4d5SSrujana Challa return;
135fed8f4d5SSrujana Challa
136fed8f4d5SSrujana Challa devlink_unregister(dl);
137fed8f4d5SSrujana Challa devlink_params_unregister(dl, otx2_cpt_dl_params,
138fed8f4d5SSrujana Challa ARRAY_SIZE(otx2_cpt_dl_params));
139fed8f4d5SSrujana Challa devlink_free(dl);
140fed8f4d5SSrujana Challa }
141