net/mlx5: remove redundant flag in device config
[dpdk.git] / drivers / common / cnxk / cnxk_telemetry_nix.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 struct nix_tel_node {
10         TAILQ_ENTRY(nix_tel_node) node;
11         struct roc_nix *nix;
12         uint16_t n_rq;
13         uint16_t n_cq;
14         uint16_t n_sq;
15         struct roc_nix_rq **rqs;
16         struct roc_nix_cq **cqs;
17         struct roc_nix_sq **sqs;
18 };
19
20 TAILQ_HEAD(nix_tel_node_list, nix_tel_node);
21 static struct nix_tel_node_list nix_list;
22
23 static struct nix_tel_node *
24 nix_tel_node_get(struct roc_nix *roc_nix)
25 {
26         struct nix_tel_node *node, *roc_node = NULL;
27
28         TAILQ_FOREACH(node, &nix_list, node) {
29                 if (node->nix == roc_nix) {
30                         roc_node = node;
31                         break;
32                 }
33         }
34
35         return roc_node;
36 }
37
38 int
39 nix_tel_node_add(struct roc_nix *roc_nix)
40 {
41         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
42         struct nix_tel_node *node;
43
44         node = nix_tel_node_get(roc_nix);
45         if (node) {
46                 if (nix->nb_rx_queues == node->n_rq &&
47                     nix->nb_tx_queues == node->n_sq)
48                         return 0;
49
50                 nix_tel_node_del(roc_nix);
51         }
52
53         node = plt_zmalloc(sizeof(struct nix_tel_node), 0);
54         if (!node)
55                 return -1;
56
57         node->nix = roc_nix;
58         node->rqs =
59                 plt_zmalloc(nix->nb_rx_queues * sizeof(struct roc_nix_rq *), 0);
60         node->cqs =
61                 plt_zmalloc(nix->nb_rx_queues * sizeof(struct roc_nix_cq *), 0);
62         node->sqs =
63                 plt_zmalloc(nix->nb_tx_queues * sizeof(struct roc_nix_sq *), 0);
64         TAILQ_INSERT_TAIL(&nix_list, node, node);
65
66         return 0;
67 }
68
69 void
70 nix_tel_node_del(struct roc_nix *roc_nix)
71 {
72         struct nix_tel_node *node;
73
74         TAILQ_FOREACH(node, &nix_list, node) {
75                 if (node->nix == roc_nix) {
76                         plt_free(node->rqs);
77                         plt_free(node->cqs);
78                         plt_free(node->sqs);
79                         TAILQ_REMOVE(&nix_list, node, node);
80                 }
81         }
82
83         plt_free(node);
84 }
85
86 static struct nix_tel_node *
87 nix_tel_node_get_by_pcidev_name(const char *name)
88 {
89         struct nix_tel_node *node, *roc_node = NULL;
90
91         TAILQ_FOREACH(node, &nix_list, node) {
92                 if (!strncmp(node->nix->pci_dev->name, name,
93                              PCI_PRI_STR_SIZE)) {
94                         roc_node = node;
95                         break;
96                 }
97         }
98
99         return roc_node;
100 }
101
102 int
103 nix_tel_node_add_rq(struct roc_nix_rq *rq)
104 {
105         struct nix_tel_node *node;
106
107         node = nix_tel_node_get(rq->roc_nix);
108         if (!node)
109                 return -1;
110
111         node->rqs[rq->qid] = rq;
112         node->n_rq++;
113         return 0;
114 }
115
116 int
117 nix_tel_node_add_cq(struct roc_nix_cq *cq)
118 {
119         struct nix_tel_node *node;
120
121         node = nix_tel_node_get(cq->roc_nix);
122         if (!node)
123                 return -1;
124
125         node->cqs[cq->qid] = cq;
126         node->n_cq++;
127         return 0;
128 }
129
130 int
131 nix_tel_node_add_sq(struct roc_nix_sq *sq)
132 {
133         struct nix_tel_node *node;
134
135         node = nix_tel_node_get(sq->roc_nix);
136         if (!node)
137                 return -1;
138
139         node->sqs[sq->qid] = sq;
140         node->n_sq++;
141         return 0;
142 }
143
144 static int
145 cnxk_tel_nix(struct roc_nix *roc_nix, struct plt_tel_data *d)
146 {
147         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
148
149         struct dev *dev = &nix->dev;
150
151         plt_tel_data_add_dict_ptr(d, "nix", nix);
152         plt_tel_data_add_dict_int(d, "pf_func", dev->pf_func);
153         plt_tel_data_add_dict_int(d, "pf", dev_get_pf(dev->pf_func));
154         plt_tel_data_add_dict_int(d, "vf", dev_get_vf(dev->pf_func));
155
156         CNXK_TEL_DICT_PTR(d, dev, bar2);
157         CNXK_TEL_DICT_PTR(d, dev, bar4);
158         CNXK_TEL_DICT_INT(d, roc_nix, port_id);
159         CNXK_TEL_DICT_INT(d, roc_nix, rss_tag_as_xor);
160         CNXK_TEL_DICT_INT(d, roc_nix, max_sqb_count);
161         CNXK_TEL_DICT_PTR(d, nix, pci_dev);
162         CNXK_TEL_DICT_PTR(d, nix, base);
163         CNXK_TEL_DICT_PTR(d, nix, lmt_base);
164         CNXK_TEL_DICT_INT(d, nix, reta_sz);
165         CNXK_TEL_DICT_INT(d, nix, tx_chan_base);
166         CNXK_TEL_DICT_INT(d, nix, rx_chan_base);
167         CNXK_TEL_DICT_INT(d, nix, nb_tx_queues);
168         CNXK_TEL_DICT_INT(d, nix, nb_rx_queues);
169         CNXK_TEL_DICT_INT(d, nix, lso_tsov6_idx);
170         CNXK_TEL_DICT_INT(d, nix, lso_tsov4_idx);
171
172         plt_tel_data_add_dict_int(d, "lso_udp_tun_v4v4",
173                                   nix->lso_udp_tun_idx[ROC_NIX_LSO_TUN_V4V4]);
174         plt_tel_data_add_dict_int(d, "lso_udp_tun_v4v6",
175                                   nix->lso_udp_tun_idx[ROC_NIX_LSO_TUN_V4V6]);
176         plt_tel_data_add_dict_int(d, "lso_udp_tun_v6v4",
177                                   nix->lso_udp_tun_idx[ROC_NIX_LSO_TUN_V6V4]);
178         plt_tel_data_add_dict_int(d, "lso_udp_tun_v6v6",
179                                   nix->lso_udp_tun_idx[ROC_NIX_LSO_TUN_V6V6]);
180         plt_tel_data_add_dict_int(d, "lso_tun_v4v4",
181                                   nix->lso_tun_idx[ROC_NIX_LSO_TUN_V4V4]);
182         plt_tel_data_add_dict_int(d, "lso_tun_v4v6",
183                                   nix->lso_tun_idx[ROC_NIX_LSO_TUN_V4V6]);
184         plt_tel_data_add_dict_int(d, "lso_tun_v6v4",
185                                   nix->lso_tun_idx[ROC_NIX_LSO_TUN_V6V4]);
186         plt_tel_data_add_dict_int(d, "lso_tun_v6v6",
187                                   nix->lso_tun_idx[ROC_NIX_LSO_TUN_V6V6]);
188
189         CNXK_TEL_DICT_INT(d, nix, lf_tx_stats);
190         CNXK_TEL_DICT_INT(d, nix, lf_rx_stats);
191         CNXK_TEL_DICT_INT(d, nix, cgx_links);
192         CNXK_TEL_DICT_INT(d, nix, lbk_links);
193         CNXK_TEL_DICT_INT(d, nix, sdp_links);
194         CNXK_TEL_DICT_INT(d, nix, tx_link);
195         CNXK_TEL_DICT_INT(d, nix, sqb_size);
196         CNXK_TEL_DICT_INT(d, nix, msixoff);
197         CNXK_TEL_DICT_INT(d, nix, cints);
198         CNXK_TEL_DICT_INT(d, nix, qints);
199         CNXK_TEL_DICT_INT(d, nix, sdp_link);
200         CNXK_TEL_DICT_INT(d, nix, ptp_en);
201         CNXK_TEL_DICT_INT(d, nix, rss_alg_idx);
202         CNXK_TEL_DICT_INT(d, nix, tx_pause);
203
204         return 0;
205 }
206
207 static int
208 cnxk_tel_nix_rq(struct roc_nix_rq *rq, struct plt_tel_data *d)
209 {
210         plt_tel_data_add_dict_ptr(d, "nix_rq", rq);
211         CNXK_TEL_DICT_INT(d, rq, qid);
212         CNXK_TEL_DICT_PTR(d, rq, aura_handle);
213         CNXK_TEL_DICT_INT(d, rq, ipsech_ena);
214         CNXK_TEL_DICT_INT(d, rq, first_skip);
215         CNXK_TEL_DICT_INT(d, rq, later_skip);
216         CNXK_TEL_DICT_INT(d, rq, lpb_size);
217         CNXK_TEL_DICT_INT(d, rq, sso_ena);
218         CNXK_TEL_DICT_INT(d, rq, tag_mask);
219         CNXK_TEL_DICT_INT(d, rq, flow_tag_width);
220         CNXK_TEL_DICT_INT(d, rq, tt);
221         CNXK_TEL_DICT_INT(d, rq, hwgrp);
222         CNXK_TEL_DICT_INT(d, rq, vwqe_ena);
223         CNXK_TEL_DICT_INT(d, rq, vwqe_first_skip);
224         CNXK_TEL_DICT_INT(d, rq, vwqe_max_sz_exp);
225         CNXK_TEL_DICT_INT(d, rq, vwqe_wait_tmo);
226         CNXK_TEL_DICT_INT(d, rq, vwqe_aura_handle);
227         CNXK_TEL_DICT_PTR(d, rq, roc_nix);
228
229         return 0;
230 }
231
232 static int
233 cnxk_tel_nix_cq(struct roc_nix_cq *cq, struct plt_tel_data *d)
234 {
235         plt_tel_data_add_dict_ptr(d, "nix_cq", cq);
236         CNXK_TEL_DICT_INT(d, cq, qid);
237         CNXK_TEL_DICT_INT(d, cq, nb_desc);
238         CNXK_TEL_DICT_PTR(d, cq, roc_nix);
239         CNXK_TEL_DICT_PTR(d, cq, door);
240         CNXK_TEL_DICT_PTR(d, cq, status);
241         CNXK_TEL_DICT_PTR(d, cq, wdata);
242         CNXK_TEL_DICT_PTR(d, cq, desc_base);
243         CNXK_TEL_DICT_INT(d, cq, qmask);
244
245         return 0;
246 }
247
248 static int
249 cnxk_tel_nix_sq(struct roc_nix_sq *sq, struct plt_tel_data *d)
250 {
251         plt_tel_data_add_dict_ptr(d, "nix_sq", sq);
252         CNXK_TEL_DICT_INT(d, sq, qid);
253         CNXK_TEL_DICT_INT(d, sq, max_sqe_sz);
254         CNXK_TEL_DICT_INT(d, sq, nb_desc);
255         CNXK_TEL_DICT_INT(d, sq, sqes_per_sqb_log2);
256         CNXK_TEL_DICT_PTR(d, sq, roc_nix);
257         CNXK_TEL_DICT_PTR(d, sq, aura_handle);
258         CNXK_TEL_DICT_INT(d, sq, nb_sqb_bufs_adj);
259         CNXK_TEL_DICT_INT(d, sq, nb_sqb_bufs);
260         CNXK_TEL_DICT_PTR(d, sq, io_addr);
261         CNXK_TEL_DICT_PTR(d, sq, lmt_addr);
262         CNXK_TEL_DICT_PTR(d, sq, sqe_mem);
263         CNXK_TEL_DICT_PTR(d, sq, fc);
264
265         return 0;
266 }
267
268 static void
269 nix_rq_ctx_cn9k(void *qctx, struct plt_tel_data *d)
270 {
271         struct nix_rq_ctx_s *ctx = (struct nix_rq_ctx_s *)qctx;
272
273         /* W0 */
274         CNXK_TEL_DICT_INT(d, ctx, wqe_aura, w0_);
275         CNXK_TEL_DICT_BF_PTR(d, ctx, substream, w0_);
276         CNXK_TEL_DICT_INT(d, ctx, cq, w0_);
277         CNXK_TEL_DICT_INT(d, ctx, ena_wqwd, w0_);
278         CNXK_TEL_DICT_INT(d, ctx, ipsech_ena, w0_);
279         CNXK_TEL_DICT_INT(d, ctx, sso_ena, w0_);
280         CNXK_TEL_DICT_INT(d, ctx, ena, w0_);
281
282         /* W1 */
283         CNXK_TEL_DICT_INT(d, ctx, lpb_drop_ena, w1_);
284         CNXK_TEL_DICT_INT(d, ctx, spb_drop_ena, w1_);
285         CNXK_TEL_DICT_INT(d, ctx, xqe_drop_ena, w1_);
286         CNXK_TEL_DICT_INT(d, ctx, wqe_caching, w1_);
287         CNXK_TEL_DICT_INT(d, ctx, pb_caching, w1_);
288         CNXK_TEL_DICT_INT(d, ctx, sso_tt, w1_);
289         CNXK_TEL_DICT_INT(d, ctx, sso_grp, w1_);
290         CNXK_TEL_DICT_INT(d, ctx, lpb_aura, w1_);
291         CNXK_TEL_DICT_INT(d, ctx, spb_aura, w1_);
292
293         /* W2 */
294         CNXK_TEL_DICT_INT(d, ctx, xqe_hdr_split, w2_);
295         CNXK_TEL_DICT_INT(d, ctx, xqe_imm_copy, w2_);
296         CNXK_TEL_DICT_INT(d, ctx, xqe_imm_size, w2_);
297         CNXK_TEL_DICT_INT(d, ctx, later_skip, w2_);
298         CNXK_TEL_DICT_INT(d, ctx, first_skip, w2_);
299         CNXK_TEL_DICT_INT(d, ctx, lpb_sizem1, w2_);
300         CNXK_TEL_DICT_INT(d, ctx, spb_ena, w2_);
301         CNXK_TEL_DICT_INT(d, ctx, wqe_skip, w2_);
302         CNXK_TEL_DICT_INT(d, ctx, spb_sizem1, w2_);
303
304         /* W3 */
305         CNXK_TEL_DICT_INT(d, ctx, spb_pool_pass, w3_);
306         CNXK_TEL_DICT_INT(d, ctx, spb_pool_drop, w3_);
307         CNXK_TEL_DICT_INT(d, ctx, spb_aura_pass, w3_);
308         CNXK_TEL_DICT_INT(d, ctx, spb_aura_drop, w3_);
309         CNXK_TEL_DICT_INT(d, ctx, wqe_pool_pass, w3_);
310         CNXK_TEL_DICT_INT(d, ctx, wqe_pool_drop, w3_);
311         CNXK_TEL_DICT_INT(d, ctx, xqe_pass, w3_);
312         CNXK_TEL_DICT_INT(d, ctx, xqe_drop, w3_);
313
314         /* W4 */
315         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w4_);
316         CNXK_TEL_DICT_INT(d, ctx, rq_int_ena, w4_);
317         CNXK_TEL_DICT_INT(d, ctx, rq_int, w4_);
318         CNXK_TEL_DICT_INT(d, ctx, lpb_pool_pass, w4_);
319         CNXK_TEL_DICT_INT(d, ctx, lpb_pool_drop, w4_);
320         CNXK_TEL_DICT_INT(d, ctx, lpb_aura_pass, w4_);
321         CNXK_TEL_DICT_INT(d, ctx, lpb_aura_drop, w4_);
322
323         /* W5 */
324         CNXK_TEL_DICT_INT(d, ctx, flow_tagw, w5_);
325         CNXK_TEL_DICT_INT(d, ctx, bad_utag, w5_);
326         CNXK_TEL_DICT_INT(d, ctx, good_utag, w5_);
327         CNXK_TEL_DICT_INT(d, ctx, ltag, w5_);
328
329         /* W6 */
330         CNXK_TEL_DICT_U64(d, ctx, octs, w6_);
331
332         /* W7 */
333         CNXK_TEL_DICT_U64(d, ctx, pkts, w7_);
334
335         /* W8 */
336         CNXK_TEL_DICT_U64(d, ctx, drop_octs, w8_);
337
338         /* W9 */
339         CNXK_TEL_DICT_U64(d, ctx, drop_pkts, w9_);
340
341         /* W10 */
342         CNXK_TEL_DICT_U64(d, ctx, re_pkts, w10_);
343 }
344
345 static void
346 nix_rq_ctx(void *qctx, struct plt_tel_data *d)
347 {
348         struct nix_cn10k_rq_ctx_s *ctx = (struct nix_cn10k_rq_ctx_s *)qctx;
349
350         /* W0 */
351         CNXK_TEL_DICT_INT(d, ctx, wqe_aura, w0_);
352         CNXK_TEL_DICT_INT(d, ctx, len_ol3_dis, w0_);
353         CNXK_TEL_DICT_INT(d, ctx, len_ol4_dis, w0_);
354         CNXK_TEL_DICT_INT(d, ctx, len_il3_dis, w0_);
355         CNXK_TEL_DICT_INT(d, ctx, len_il4_dis, w0_);
356         CNXK_TEL_DICT_INT(d, ctx, csum_ol4_dis, w0_);
357         CNXK_TEL_DICT_INT(d, ctx, lenerr_dis, w0_);
358         CNXK_TEL_DICT_INT(d, ctx, ena_wqwd, w0);
359         CNXK_TEL_DICT_INT(d, ctx, ipsech_ena, w0);
360         CNXK_TEL_DICT_INT(d, ctx, sso_ena, w0);
361         CNXK_TEL_DICT_INT(d, ctx, ena, w0);
362
363         /* W1 */
364         CNXK_TEL_DICT_INT(d, ctx, chi_ena, w1_);
365         CNXK_TEL_DICT_INT(d, ctx, ipsecd_drop_en, w1_);
366         CNXK_TEL_DICT_INT(d, ctx, pb_stashing, w1_);
367         CNXK_TEL_DICT_INT(d, ctx, lpb_drop_ena, w1_);
368         CNXK_TEL_DICT_INT(d, ctx, spb_drop_ena, w1_);
369         CNXK_TEL_DICT_INT(d, ctx, xqe_drop_ena, w1_);
370         CNXK_TEL_DICT_INT(d, ctx, wqe_caching, w1_);
371         CNXK_TEL_DICT_INT(d, ctx, pb_caching, w1_);
372         CNXK_TEL_DICT_INT(d, ctx, sso_tt, w1_);
373         CNXK_TEL_DICT_INT(d, ctx, sso_grp, w1_);
374         CNXK_TEL_DICT_INT(d, ctx, lpb_aura, w1_);
375         CNXK_TEL_DICT_INT(d, ctx, spb_aura, w1_);
376
377         /* W2 */
378         CNXK_TEL_DICT_INT(d, ctx, xqe_hdr_split, w2_);
379         CNXK_TEL_DICT_INT(d, ctx, xqe_imm_copy, w2_);
380         CNXK_TEL_DICT_INT(d, ctx, xqe_imm_size, w2_);
381         CNXK_TEL_DICT_INT(d, ctx, later_skip, w2_);
382         CNXK_TEL_DICT_INT(d, ctx, first_skip, w2_);
383         CNXK_TEL_DICT_INT(d, ctx, lpb_sizem1, w2_);
384         CNXK_TEL_DICT_INT(d, ctx, spb_ena, w2_);
385         CNXK_TEL_DICT_INT(d, ctx, wqe_skip, w2_);
386         CNXK_TEL_DICT_INT(d, ctx, spb_sizem1, w2_);
387         CNXK_TEL_DICT_INT(d, ctx, policer_ena, w2_);
388         CNXK_TEL_DICT_INT(d, ctx, band_prof_id, w2_);
389
390         /* W3 */
391         CNXK_TEL_DICT_INT(d, ctx, spb_pool_pass, w3_);
392         CNXK_TEL_DICT_INT(d, ctx, spb_pool_drop, w3_);
393         CNXK_TEL_DICT_INT(d, ctx, spb_aura_pass, w3_);
394         CNXK_TEL_DICT_INT(d, ctx, spb_aura_drop, w3_);
395         CNXK_TEL_DICT_INT(d, ctx, wqe_pool_pass, w3_);
396         CNXK_TEL_DICT_INT(d, ctx, wqe_pool_drop, w3_);
397         CNXK_TEL_DICT_INT(d, ctx, xqe_pass, w3_);
398         CNXK_TEL_DICT_INT(d, ctx, xqe_drop, w3_);
399
400         /* W4 */
401         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w4_);
402         CNXK_TEL_DICT_INT(d, ctx, rq_int_ena, w4_);
403         CNXK_TEL_DICT_INT(d, ctx, rq_int, w4_);
404         CNXK_TEL_DICT_INT(d, ctx, lpb_pool_pass, w4_);
405         CNXK_TEL_DICT_INT(d, ctx, lpb_pool_drop, w4_);
406         CNXK_TEL_DICT_INT(d, ctx, lpb_aura_pass, w4_);
407         CNXK_TEL_DICT_INT(d, ctx, lpb_aura_drop, w4_);
408
409         /* W5 */
410         CNXK_TEL_DICT_INT(d, ctx, vwqe_skip, w5_);
411         CNXK_TEL_DICT_INT(d, ctx, max_vsize_exp, w5_);
412         CNXK_TEL_DICT_INT(d, ctx, vtime_wait, w5_);
413         CNXK_TEL_DICT_INT(d, ctx, vwqe_ena, w5_);
414         CNXK_TEL_DICT_INT(d, ctx, ipsec_vwqe, w5_);
415         CNXK_TEL_DICT_INT(d, ctx, flow_tagw, w5_);
416         CNXK_TEL_DICT_INT(d, ctx, bad_utag, w5_);
417         CNXK_TEL_DICT_INT(d, ctx, good_utag, w5_);
418         CNXK_TEL_DICT_INT(d, ctx, ltag, w5_);
419
420         /* W6 */
421         CNXK_TEL_DICT_U64(d, ctx, octs, w6_);
422
423         /* W7 */
424         CNXK_TEL_DICT_U64(d, ctx, pkts, w7_);
425
426         /* W8 */
427         CNXK_TEL_DICT_U64(d, ctx, drop_octs, w8_);
428
429         /* W9 */
430         CNXK_TEL_DICT_U64(d, ctx, drop_pkts, w9_);
431
432         /* W10 */
433         CNXK_TEL_DICT_U64(d, ctx, re_pkts, w10_);
434 }
435
436 static int
437 cnxk_tel_nix_rq_ctx(struct roc_nix *roc_nix, uint8_t n, struct plt_tel_data *d)
438 {
439         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
440         struct dev *dev = &nix->dev;
441         struct npa_lf *npa_lf;
442         volatile void *qctx;
443         int rc = -1;
444
445         npa_lf = idev_npa_obj_get();
446         if (npa_lf == NULL)
447                 return NPA_ERR_DEVICE_NOT_BOUNDED;
448
449         rc = nix_q_ctx_get(dev, NIX_AQ_CTYPE_RQ, n, &qctx);
450         if (rc) {
451                 plt_err("Failed to get rq context");
452                 return rc;
453         }
454
455         if (roc_model_is_cn9k())
456                 nix_rq_ctx_cn9k(&qctx, d);
457         else
458                 nix_rq_ctx(&qctx, d);
459
460         return 0;
461 }
462
463 static int
464 cnxk_tel_nix_cq_ctx(struct roc_nix *roc_nix, uint8_t n, struct plt_tel_data *d)
465 {
466         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
467         struct dev *dev = &nix->dev;
468         struct npa_lf *npa_lf;
469         volatile struct nix_cq_ctx_s *ctx;
470         int rc = -1;
471
472         npa_lf = idev_npa_obj_get();
473         if (npa_lf == NULL)
474                 return NPA_ERR_DEVICE_NOT_BOUNDED;
475
476         rc = nix_q_ctx_get(dev, NIX_AQ_CTYPE_CQ, n, (void *)&ctx);
477         if (rc) {
478                 plt_err("Failed to get cq context");
479                 return rc;
480         }
481
482         /* W0 */
483         CNXK_TEL_DICT_PTR(d, ctx, base, w0_);
484
485         /* W1 */
486         CNXK_TEL_DICT_U64(d, ctx, wrptr, w1_);
487         CNXK_TEL_DICT_INT(d, ctx, avg_con, w1_);
488         CNXK_TEL_DICT_INT(d, ctx, cint_idx, w1_);
489         CNXK_TEL_DICT_INT(d, ctx, cq_err, w1_);
490         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w1_);
491         CNXK_TEL_DICT_INT(d, ctx, bpid, w1_);
492         CNXK_TEL_DICT_INT(d, ctx, bp_ena, w1_);
493
494         /* W2 */
495         CNXK_TEL_DICT_INT(d, ctx, update_time, w2_);
496         CNXK_TEL_DICT_INT(d, ctx, avg_level, w2_);
497         CNXK_TEL_DICT_INT(d, ctx, head, w2_);
498         CNXK_TEL_DICT_INT(d, ctx, tail, w2_);
499
500         /* W3 */
501         CNXK_TEL_DICT_INT(d, ctx, cq_err_int_ena, w3_);
502         CNXK_TEL_DICT_INT(d, ctx, cq_err_int, w3_);
503         CNXK_TEL_DICT_INT(d, ctx, qsize, w3_);
504         CNXK_TEL_DICT_INT(d, ctx, caching, w3_);
505         CNXK_TEL_DICT_INT(d, ctx, substream, w3_);
506         CNXK_TEL_DICT_INT(d, ctx, ena, w3_);
507         CNXK_TEL_DICT_INT(d, ctx, drop_ena, w3_);
508         CNXK_TEL_DICT_INT(d, ctx, drop, w3_);
509         CNXK_TEL_DICT_INT(d, ctx, bp, w3_);
510
511         return 0;
512 }
513
514 static void
515 nix_sq_ctx_cn9k(void *qctx, struct plt_tel_data *d)
516 {
517         struct nix_sq_ctx_s *ctx = (struct nix_sq_ctx_s *)qctx;
518
519         /* W0 */
520         CNXK_TEL_DICT_INT(d, ctx, sqe_way_mask, w0_);
521         CNXK_TEL_DICT_INT(d, ctx, cq, w0_);
522         CNXK_TEL_DICT_INT(d, ctx, sdp_mcast, w0_);
523         CNXK_TEL_DICT_INT(d, ctx, substream, w0_);
524         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w0_);
525         CNXK_TEL_DICT_INT(d, ctx, ena, w0_);
526
527         /* W1 */
528         CNXK_TEL_DICT_INT(d, ctx, sqb_count, w1_);
529         CNXK_TEL_DICT_INT(d, ctx, default_chan, w1_);
530         CNXK_TEL_DICT_INT(d, ctx, smq_rr_quantum, w1_);
531         CNXK_TEL_DICT_INT(d, ctx, sso_ena, w1_);
532         CNXK_TEL_DICT_INT(d, ctx, xoff, w1_);
533         CNXK_TEL_DICT_INT(d, ctx, cq_ena, w1_);
534         CNXK_TEL_DICT_INT(d, ctx, smq, w1_);
535
536         /* W2 */
537         CNXK_TEL_DICT_INT(d, ctx, sqe_stype, w2_);
538         CNXK_TEL_DICT_INT(d, ctx, sq_int_ena, w2_);
539         CNXK_TEL_DICT_INT(d, ctx, sq_int, w2_);
540         CNXK_TEL_DICT_INT(d, ctx, sqb_aura, w2_);
541         CNXK_TEL_DICT_INT(d, ctx, smq_rr_count, w2_);
542
543         /* W3 */
544         CNXK_TEL_DICT_INT(d, ctx, smq_next_sq_vld, w3_);
545         CNXK_TEL_DICT_INT(d, ctx, smq_pend, w3_);
546         CNXK_TEL_DICT_INT(d, ctx, smenq_next_sqb_vld, w3_);
547         CNXK_TEL_DICT_INT(d, ctx, head_offset, w3_);
548         CNXK_TEL_DICT_INT(d, ctx, smenq_offset, w3_);
549         CNXK_TEL_DICT_INT(d, ctx, tail_offset, w3_);
550         CNXK_TEL_DICT_INT(d, ctx, smq_lso_segnum, w3_);
551         CNXK_TEL_DICT_INT(d, ctx, smq_next_sq, w3_);
552         CNXK_TEL_DICT_INT(d, ctx, mnq_dis, w3_);
553         CNXK_TEL_DICT_INT(d, ctx, lmt_dis, w3_);
554         CNXK_TEL_DICT_INT(d, ctx, cq_limit, w3_);
555         CNXK_TEL_DICT_INT(d, ctx, max_sqe_size, w3_);
556
557         /* W4 */
558         CNXK_TEL_DICT_PTR(d, ctx, next_sqb, w4_);
559
560         /* W5 */
561         CNXK_TEL_DICT_PTR(d, ctx, tail_sqb, w5_);
562
563         /* W6 */
564         CNXK_TEL_DICT_PTR(d, ctx, smenq_sqb, w6_);
565
566         /* W7 */
567         CNXK_TEL_DICT_PTR(d, ctx, smenq_next_sqb, w7_);
568
569         /* W8 */
570         CNXK_TEL_DICT_PTR(d, ctx, head_sqb, w8_);
571
572         /* W9 */
573         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vld, w9_);
574         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vlan1_ins_ena, w9_);
575         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vlan0_ins_ena, w9_);
576         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_mps, w9_);
577         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_sb, w9_);
578         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_sizem1, w9_);
579         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_total, w9_);
580
581         /* W10 */
582         CNXK_TEL_DICT_BF_PTR(d, ctx, scm_lso_rem, w10_);
583
584         /* W11 */
585         CNXK_TEL_DICT_BF_PTR(d, ctx, octs, w11_);
586
587         /* W12 */
588         CNXK_TEL_DICT_BF_PTR(d, ctx, pkts, w12_);
589
590         /* W14 */
591         CNXK_TEL_DICT_BF_PTR(d, ctx, drop_octs, w14_);
592
593         /* W15 */
594         CNXK_TEL_DICT_BF_PTR(d, ctx, drop_pkts, w15_);
595 }
596
597 static void
598 nix_sq_ctx(void *qctx, struct plt_tel_data *d)
599 {
600         struct nix_cn10k_sq_ctx_s *ctx = (struct nix_cn10k_sq_ctx_s *)qctx;
601
602         /* W0 */
603         CNXK_TEL_DICT_INT(d, ctx, sqe_way_mask, w0_);
604         CNXK_TEL_DICT_INT(d, ctx, cq, w0_);
605         CNXK_TEL_DICT_INT(d, ctx, sdp_mcast, w0_);
606         CNXK_TEL_DICT_INT(d, ctx, substream, w0_);
607         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w0_);
608         CNXK_TEL_DICT_INT(d, ctx, ena, w0_);
609
610         /* W1 */
611         CNXK_TEL_DICT_INT(d, ctx, sqb_count, w1_);
612         CNXK_TEL_DICT_INT(d, ctx, default_chan, w1_);
613         CNXK_TEL_DICT_INT(d, ctx, smq_rr_weight, w1_);
614         CNXK_TEL_DICT_INT(d, ctx, sso_ena, w1_);
615         CNXK_TEL_DICT_INT(d, ctx, xoff, w1_);
616         CNXK_TEL_DICT_INT(d, ctx, cq_ena, w1_);
617         CNXK_TEL_DICT_INT(d, ctx, smq, w1_);
618
619         /* W2 */
620         CNXK_TEL_DICT_INT(d, ctx, sqe_stype, w2_);
621         CNXK_TEL_DICT_INT(d, ctx, sq_int_ena, w2_);
622         CNXK_TEL_DICT_INT(d, ctx, sq_int, w2_);
623         CNXK_TEL_DICT_INT(d, ctx, sqb_aura, w2_);
624         CNXK_TEL_DICT_INT(d, ctx, smq_rr_count_ub, w2_);
625         CNXK_TEL_DICT_INT(d, ctx, smq_rr_count_lb, w2_);
626
627         /* W3 */
628         CNXK_TEL_DICT_INT(d, ctx, smq_next_sq_vld, w3_);
629         CNXK_TEL_DICT_INT(d, ctx, smq_pend, w3_);
630         CNXK_TEL_DICT_INT(d, ctx, smenq_next_sqb_vld, w3_);
631         CNXK_TEL_DICT_INT(d, ctx, head_offset, w3_);
632         CNXK_TEL_DICT_INT(d, ctx, smenq_offset, w3_);
633         CNXK_TEL_DICT_INT(d, ctx, tail_offset, w3_);
634         CNXK_TEL_DICT_INT(d, ctx, smq_lso_segnum, w3_);
635         CNXK_TEL_DICT_INT(d, ctx, smq_next_sq, w3_);
636         CNXK_TEL_DICT_INT(d, ctx, mnq_dis, w3_);
637         CNXK_TEL_DICT_INT(d, ctx, lmt_dis, w3_);
638         CNXK_TEL_DICT_INT(d, ctx, cq_limit, w3_);
639         CNXK_TEL_DICT_INT(d, ctx, max_sqe_size, w3_);
640
641         /* W4 */
642         CNXK_TEL_DICT_PTR(d, ctx, next_sqb, w4_);
643
644         /* W5 */
645         CNXK_TEL_DICT_PTR(d, ctx, tail_sqb, w5_);
646
647         /* W6 */
648         CNXK_TEL_DICT_PTR(d, ctx, smenq_sqb, w6_);
649
650         /* W7 */
651         CNXK_TEL_DICT_PTR(d, ctx, smenq_next_sqb, w7_);
652
653         /* W8 */
654         CNXK_TEL_DICT_PTR(d, ctx, head_sqb, w8_);
655
656         /* W9 */
657         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vld, w9_);
658         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vlan1_ins_ena, w9_);
659         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vlan0_ins_ena, w9_);
660         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_mps, w9_);
661         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_sb, w9_);
662         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_sizem1, w9_);
663         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_total, w9_);
664
665         /* W10 */
666         CNXK_TEL_DICT_BF_PTR(d, ctx, scm_lso_rem, w10_);
667
668         /* W11 */
669         CNXK_TEL_DICT_BF_PTR(d, ctx, octs, w11_);
670
671         /* W12 */
672         CNXK_TEL_DICT_BF_PTR(d, ctx, pkts, w12_);
673
674         /* W14 */
675         CNXK_TEL_DICT_BF_PTR(d, ctx, drop_octs, w14_);
676
677         /* W15 */
678         CNXK_TEL_DICT_BF_PTR(d, ctx, drop_pkts, w15_);
679 }
680
681 static int
682 cnxk_tel_nix_sq_ctx(struct roc_nix *roc_nix, uint8_t n, struct plt_tel_data *d)
683 {
684         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
685         struct dev *dev = &nix->dev;
686         struct npa_lf *npa_lf;
687         volatile void *qctx;
688         int rc = -1;
689
690         npa_lf = idev_npa_obj_get();
691         if (npa_lf == NULL)
692                 return NPA_ERR_DEVICE_NOT_BOUNDED;
693
694         rc = nix_q_ctx_get(dev, NIX_AQ_CTYPE_SQ, n, &qctx);
695         if (rc) {
696                 plt_err("Failed to get rq context");
697                 return rc;
698         }
699
700         if (roc_model_is_cn9k())
701                 nix_sq_ctx_cn9k(&qctx, d);
702         else
703                 nix_sq_ctx(&qctx, d);
704
705         return 0;
706 }
707
708 static int
709 cnxk_nix_tel_handle_list(const char *cmd __plt_unused,
710                          const char *params __plt_unused,
711                          struct plt_tel_data *d)
712 {
713         struct nix_tel_node *node;
714         struct roc_nix *roc_nix;
715
716         plt_tel_data_start_array(d, PLT_TEL_STRING_VAL);
717
718         TAILQ_FOREACH(node, &nix_list, node) {
719                 roc_nix = node->nix;
720                 plt_tel_data_add_array_string(d, roc_nix->pci_dev->name);
721         }
722
723         return 0;
724 }
725
726 static int
727 cnxk_nix_tel_handle_info(const char *cmd __plt_unused, const char *params,
728                          struct plt_tel_data *d)
729 {
730         char name[PCI_PRI_STR_SIZE];
731         struct nix_tel_node *node;
732
733         if (params == NULL || strlen(params) == 0 || !isdigit(*params))
734                 return -1;
735
736         plt_strlcpy(name, params, PCI_PRI_STR_SIZE);
737
738         node = nix_tel_node_get_by_pcidev_name(name);
739         if (!node)
740                 return -1;
741
742         plt_tel_data_start_dict(d);
743         return cnxk_tel_nix(node->nix, d);
744 }
745
746 static int
747 cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
748                            struct plt_tel_data *d)
749 {
750         struct nix_tel_node *node;
751         char *name, *param;
752         char buf[1024];
753         int rc = -1;
754
755         if (params == NULL || strlen(params) == 0 || !isdigit(*params))
756                 goto exit;
757
758         plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1);
759         name = strtok(buf, ",");
760         param = strtok(NULL, "\0");
761
762         node = nix_tel_node_get_by_pcidev_name(name);
763         if (!node)
764                 goto exit;
765
766         plt_tel_data_start_dict(d);
767
768         if (strstr(cmd, "rq")) {
769                 char *tok = strtok(param, ",");
770                 int rq;
771
772                 if (!tok)
773                         goto exit;
774
775                 rq = strtol(tok, NULL, 10);
776                 if ((node->n_rq <= rq) || (rq < 0))
777                         goto exit;
778
779                 if (strstr(cmd, "ctx"))
780                         rc = cnxk_tel_nix_rq_ctx(node->nix, rq, d);
781                 else
782                         rc = cnxk_tel_nix_rq(node->rqs[rq], d);
783
784         } else if (strstr(cmd, "cq")) {
785                 char *tok = strtok(param, ",");
786                 int cq;
787
788                 if (!tok)
789                         goto exit;
790
791                 cq = strtol(tok, NULL, 10);
792                 if ((node->n_cq <= cq) || (cq < 0))
793                         goto exit;
794
795                 if (strstr(cmd, "ctx"))
796                         rc = cnxk_tel_nix_cq_ctx(node->nix, cq, d);
797                 else
798                         rc = cnxk_tel_nix_cq(node->cqs[cq], d);
799
800         } else if (strstr(cmd, "sq")) {
801                 char *tok = strtok(param, ",");
802                 int sq;
803
804                 if (!tok)
805                         goto exit;
806
807                 sq = strtol(tok, NULL, 10);
808                 if ((node->n_sq <= sq) || (sq < 0))
809                         goto exit;
810
811                 if (strstr(cmd, "ctx"))
812                         rc = cnxk_tel_nix_sq_ctx(node->nix, sq, d);
813                 else
814                         rc = cnxk_tel_nix_sq(node->sqs[sq], d);
815         }
816
817 exit:
818         return rc;
819 }
820
821 PLT_INIT(cnxk_telemetry_nix_init)
822 {
823         TAILQ_INIT(&nix_list);
824
825         plt_telemetry_register_cmd(
826                 "/cnxk/nix/list", cnxk_nix_tel_handle_list,
827                 "Returns list of available NIX devices. Takes no parameters");
828         plt_telemetry_register_cmd(
829                 "/cnxk/nix/info", cnxk_nix_tel_handle_info,
830                 "Returns nix information. Parameters: pci id");
831         plt_telemetry_register_cmd(
832                 "/cnxk/nix/rq/info", cnxk_nix_tel_handle_info_x,
833                 "Returns nix rq information. Parameters: pci id, rq id");
834         plt_telemetry_register_cmd(
835                 "/cnxk/nix/rq/ctx", cnxk_nix_tel_handle_info_x,
836                 "Returns nix rq context. Parameters: pci id, rq id");
837         plt_telemetry_register_cmd(
838                 "/cnxk/nix/cq/info", cnxk_nix_tel_handle_info_x,
839                 "Returns nix cq information. Parameters: pci id, cq id");
840         plt_telemetry_register_cmd(
841                 "/cnxk/nix/cq/ctx", cnxk_nix_tel_handle_info_x,
842                 "Returns nix cq context. Parameters: pci id, cq id");
843         plt_telemetry_register_cmd(
844                 "/cnxk/nix/sq/info", cnxk_nix_tel_handle_info_x,
845                 "Returns nix sq information. Parameters: pci id, sq id");
846         plt_telemetry_register_cmd(
847                 "/cnxk/nix/sq/ctx", cnxk_nix_tel_handle_info_x,
848                 "Returns nix sq context. Parameters: pci id, sq id");
849 }