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