crypto/cnxk: move IPsec SA creation to common
[dpdk.git] / drivers / common / cnxk / cnxk_telemetry_npa.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #include "cnxk_telemetry.h"
6 #include "roc_api.h"
7 #include "roc_priv.h"
8
9 static int
10 cnxk_tel_npa(struct plt_tel_data *d)
11 {
12         struct npa_lf *lf;
13         int aura_cnt = 0;
14         uint32_t i;
15
16         lf = idev_npa_obj_get();
17         if (lf == NULL)
18                 return NPA_ERR_DEVICE_NOT_BOUNDED;
19
20         for (i = 0; i < lf->nr_pools; i++) {
21                 if (plt_bitmap_get(lf->npa_bmp, i))
22                         continue;
23                 aura_cnt++;
24         }
25
26         plt_tel_data_add_dict_ptr(d, "npa", lf);
27         plt_tel_data_add_dict_int(d, "pf", dev_get_pf(lf->pf_func));
28         plt_tel_data_add_dict_int(d, "vf", dev_get_vf(lf->pf_func));
29         plt_tel_data_add_dict_int(d, "aura_cnt", aura_cnt);
30
31         CNXK_TEL_DICT_STR(d, lf->pci_dev, name, pcidev_);
32         CNXK_TEL_DICT_PTR(d, lf, npa_bmp);
33         CNXK_TEL_DICT_PTR(d, lf, npa_bmp_mem);
34         CNXK_TEL_DICT_PTR(d, lf, npa_qint_mem);
35         CNXK_TEL_DICT_PTR(d, lf, mbox);
36         CNXK_TEL_DICT_PTR(d, lf, base);
37         CNXK_TEL_DICT_INT(d, lf, stack_pg_ptrs);
38         CNXK_TEL_DICT_INT(d, lf, stack_pg_bytes);
39         CNXK_TEL_DICT_INT(d, lf, npa_msixoff);
40         CNXK_TEL_DICT_INT(d, lf, nr_pools);
41         CNXK_TEL_DICT_INT(d, lf, pf_func);
42         CNXK_TEL_DICT_INT(d, lf, aura_sz);
43         CNXK_TEL_DICT_INT(d, lf, qints);
44
45         return 0;
46 }
47
48 static int
49 cnxk_tel_npa_aura(int aura_id, struct plt_tel_data *d)
50 {
51         __io struct npa_aura_s *aura;
52         struct npa_aq_enq_req *req;
53         struct npa_aq_enq_rsp *rsp;
54         struct npa_lf *lf;
55         int rc;
56
57         lf = idev_npa_obj_get();
58         if (lf == NULL)
59                 return NPA_ERR_DEVICE_NOT_BOUNDED;
60
61         if (plt_bitmap_get(lf->npa_bmp, aura_id))
62                 return -1;
63
64         req = mbox_alloc_msg_npa_aq_enq(lf->mbox);
65         if (!req) {
66                 plt_err("Failed to alloc aq enq for npa");
67                 return -1;
68         }
69
70         req->aura_id = aura_id;
71         req->ctype = NPA_AQ_CTYPE_AURA;
72         req->op = NPA_AQ_INSTOP_READ;
73
74         rc = mbox_process_msg(lf->mbox, (void *)&rsp);
75         if (rc) {
76                 plt_err("Failed to get pool(%d) context", aura_id);
77                 return rc;
78         }
79
80         aura = &rsp->aura;
81         CNXK_TEL_DICT_PTR(d, aura, pool_addr, w0_);
82         CNXK_TEL_DICT_INT(d, aura, ena, w1_);
83         CNXK_TEL_DICT_INT(d, aura, pool_caching, w1_);
84         CNXK_TEL_DICT_INT(d, aura, pool_way_mask, w1_);
85         CNXK_TEL_DICT_INT(d, aura, avg_con, w1_);
86         CNXK_TEL_DICT_INT(d, aura, pool_drop_ena, w1_);
87         CNXK_TEL_DICT_INT(d, aura, aura_drop_ena, w1_);
88         CNXK_TEL_DICT_INT(d, aura, bp_ena, w1_);
89         CNXK_TEL_DICT_INT(d, aura, aura_drop, w1_);
90         CNXK_TEL_DICT_INT(d, aura, avg_level, w1_);
91         CNXK_TEL_DICT_U64(d, aura, count, w2_);
92         CNXK_TEL_DICT_INT(d, aura, nix0_bpid, w2_);
93         CNXK_TEL_DICT_INT(d, aura, nix1_bpid, w2_);
94         CNXK_TEL_DICT_U64(d, aura, limit, w3_);
95         CNXK_TEL_DICT_INT(d, aura, bp, w3_);
96         CNXK_TEL_DICT_INT(d, aura, fc_ena, w3_);
97         CNXK_TEL_DICT_INT(d, aura, fc_up_crossing, w3_);
98         CNXK_TEL_DICT_INT(d, aura, fc_stype, w3_);
99         CNXK_TEL_DICT_INT(d, aura, fc_hyst_bits, w3_);
100         CNXK_TEL_DICT_INT(d, aura, fc_addr, w4_);
101         CNXK_TEL_DICT_INT(d, aura, pool_drop, w5_);
102         CNXK_TEL_DICT_INT(d, aura, update_time, w5_);
103         CNXK_TEL_DICT_INT(d, aura, err_int, w5_);
104         CNXK_TEL_DICT_INT(d, aura, err_int_ena, w5_);
105         CNXK_TEL_DICT_INT(d, aura, thresh_int, w5_);
106         CNXK_TEL_DICT_INT(d, aura, thresh_int_ena, w5_);
107         CNXK_TEL_DICT_INT(d, aura, thresh_up, w5_);
108         CNXK_TEL_DICT_INT(d, aura, thresh_qint_idx, w5_);
109         CNXK_TEL_DICT_INT(d, aura, err_qint_idx, w5_);
110         CNXK_TEL_DICT_U64(d, aura, thresh, w6_);
111
112         return 0;
113 }
114
115 static int
116 cnxk_tel_npa_pool(int pool_id, struct plt_tel_data *d)
117 {
118         __io struct npa_pool_s *pool;
119         struct npa_aq_enq_req *req;
120         struct npa_aq_enq_rsp *rsp;
121         struct npa_lf *lf;
122         int rc;
123
124         lf = idev_npa_obj_get();
125         if (lf == NULL)
126                 return NPA_ERR_DEVICE_NOT_BOUNDED;
127
128         if (plt_bitmap_get(lf->npa_bmp, pool_id))
129                 return -1;
130
131         req = mbox_alloc_msg_npa_aq_enq(lf->mbox);
132         if (!req) {
133                 plt_err("Failed to alloc aq enq for npa");
134                 return -1;
135         }
136
137         req->aura_id = pool_id;
138         req->ctype = NPA_AQ_CTYPE_POOL;
139         req->op = NPA_AQ_INSTOP_READ;
140
141         rc = mbox_process_msg(lf->mbox, (void *)&rsp);
142         if (rc) {
143                 plt_err("Failed to get pool(%d) context", pool_id);
144                 return rc;
145         }
146
147         pool = &rsp->pool;
148         CNXK_TEL_DICT_PTR(d, pool, stack_base, w0_);
149         CNXK_TEL_DICT_INT(d, pool, ena, w1_);
150         CNXK_TEL_DICT_INT(d, pool, nat_align, w1_);
151         CNXK_TEL_DICT_INT(d, pool, stack_caching, w1_);
152         CNXK_TEL_DICT_INT(d, pool, stack_way_mask, w1_);
153         CNXK_TEL_DICT_INT(d, pool, buf_offset, w1_);
154         CNXK_TEL_DICT_INT(d, pool, buf_size, w1_);
155         CNXK_TEL_DICT_INT(d, pool, stack_max_pages, w2_);
156         CNXK_TEL_DICT_INT(d, pool, stack_pages, w2_);
157         CNXK_TEL_DICT_INT(d, pool, op_pc, w3_);
158         CNXK_TEL_DICT_INT(d, pool, stack_offset, w4_);
159         CNXK_TEL_DICT_INT(d, pool, shift, w4_);
160         CNXK_TEL_DICT_INT(d, pool, avg_level, w4_);
161         CNXK_TEL_DICT_INT(d, pool, avg_con, w4_);
162         CNXK_TEL_DICT_INT(d, pool, fc_ena, w4_);
163         CNXK_TEL_DICT_INT(d, pool, fc_stype, w4_);
164         CNXK_TEL_DICT_INT(d, pool, fc_hyst_bits, w4_);
165         CNXK_TEL_DICT_INT(d, pool, fc_up_crossing, w4_);
166         CNXK_TEL_DICT_INT(d, pool, update_time, w4_);
167         CNXK_TEL_DICT_PTR(d, pool, fc_addr, w5_);
168         CNXK_TEL_DICT_PTR(d, pool, ptr_start, w6_);
169         CNXK_TEL_DICT_PTR(d, pool, ptr_end, w7_);
170         CNXK_TEL_DICT_INT(d, pool, err_int, w8_);
171         CNXK_TEL_DICT_INT(d, pool, err_int_ena, w8_);
172         CNXK_TEL_DICT_INT(d, pool, thresh_int, w8_);
173         CNXK_TEL_DICT_INT(d, pool, thresh_int_ena, w8_);
174         CNXK_TEL_DICT_INT(d, pool, thresh_up, w8_);
175         CNXK_TEL_DICT_INT(d, pool, thresh_qint_idx, w8_);
176         CNXK_TEL_DICT_INT(d, pool, err_qint_idx, w8_);
177
178         return 0;
179 }
180
181 static int
182 cnxk_npa_tel_handle_info(const char *cmd __plt_unused,
183                          const char *params __plt_unused,
184                          struct plt_tel_data *d)
185 {
186         plt_tel_data_start_dict(d);
187         return cnxk_tel_npa(d);
188 }
189
190 static int
191 cnxk_npa_tel_handle_aura_list(const char *cmd __plt_unused,
192                               const char *params __plt_unused,
193                               struct plt_tel_data *d)
194 {
195         struct npa_lf *lf;
196         int i;
197
198         lf = idev_npa_obj_get();
199         if (lf == NULL)
200                 return NPA_ERR_DEVICE_NOT_BOUNDED;
201
202         plt_tel_data_start_array(d, PLT_TEL_INT_VAL);
203
204         for (i = 0; i < (int)lf->nr_pools; i++)
205                 if (!plt_bitmap_get(lf->npa_bmp, i))
206                         rte_tel_data_add_array_int(d, i);
207
208         return 0;
209 }
210
211 static int
212 cnxk_npa_tel_handle_pool_list(const char *cmd, const char *params,
213                               struct plt_tel_data *d)
214 {
215         /* In current implementation, aura and pool ID mapped 1:1 */
216         return cnxk_npa_tel_handle_aura_list(cmd, params, d);
217 }
218
219 static int
220 cnxk_npa_tel_handle_info_x(const char *cmd, const char *params,
221                            struct plt_tel_data *d)
222 {
223         int id, rc;
224
225         if (params == NULL || strlen(params) == 0 || !isdigit(*params))
226                 return -1;
227
228         id = strtol(params, NULL, 10);
229         plt_tel_data_start_dict(d);
230
231         if (strstr(cmd, "aura/info"))
232                 rc = cnxk_tel_npa_aura(id, d);
233         else
234                 rc = cnxk_tel_npa_pool(id, d);
235
236         return rc;
237 }
238
239 PLT_INIT(cnxk_telemetry_npa_init)
240 {
241         plt_telemetry_register_cmd(
242                 "/cnxk/npa/info", cnxk_npa_tel_handle_info,
243                 "Returns npa information. Takes no parameters");
244
245         plt_telemetry_register_cmd(
246                 "/cnxk/npa/aura/list", cnxk_npa_tel_handle_aura_list,
247                 "Returns list of npa aura id. Takes no parameters");
248
249         plt_telemetry_register_cmd(
250                 "/cnxk/npa/aura/info", cnxk_npa_tel_handle_info_x,
251                 "Returns npa aura information. Parameters: aura_id");
252
253         plt_telemetry_register_cmd(
254                 "/cnxk/npa/pool/list", cnxk_npa_tel_handle_pool_list,
255                 "Returns list of npa pool id. Takes no parameters");
256
257         plt_telemetry_register_cmd(
258                 "/cnxk/npa/pool/info", cnxk_npa_tel_handle_info_x,
259                 "Returns npa pool information. Parameters: pool_id");
260 }