app/testpmd: fix GTP PSC extension header length
[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(volatile void *qctx, struct plt_tel_data *d)
270 {
271         volatile struct nix_rq_ctx_s *ctx;
272
273         ctx = (volatile struct nix_rq_ctx_s *)qctx;
274
275         /* W0 */
276         CNXK_TEL_DICT_INT(d, ctx, wqe_aura, w0_);
277         CNXK_TEL_DICT_BF_PTR(d, ctx, substream, w0_);
278         CNXK_TEL_DICT_INT(d, ctx, cq, w0_);
279         CNXK_TEL_DICT_INT(d, ctx, ena_wqwd, w0_);
280         CNXK_TEL_DICT_INT(d, ctx, ipsech_ena, w0_);
281         CNXK_TEL_DICT_INT(d, ctx, sso_ena, w0_);
282         CNXK_TEL_DICT_INT(d, ctx, ena, w0_);
283
284         /* W1 */
285         CNXK_TEL_DICT_INT(d, ctx, lpb_drop_ena, w1_);
286         CNXK_TEL_DICT_INT(d, ctx, spb_drop_ena, w1_);
287         CNXK_TEL_DICT_INT(d, ctx, xqe_drop_ena, w1_);
288         CNXK_TEL_DICT_INT(d, ctx, wqe_caching, w1_);
289         CNXK_TEL_DICT_INT(d, ctx, pb_caching, w1_);
290         CNXK_TEL_DICT_INT(d, ctx, sso_tt, w1_);
291         CNXK_TEL_DICT_INT(d, ctx, sso_grp, w1_);
292         CNXK_TEL_DICT_INT(d, ctx, lpb_aura, w1_);
293         CNXK_TEL_DICT_INT(d, ctx, spb_aura, w1_);
294
295         /* W2 */
296         CNXK_TEL_DICT_INT(d, ctx, xqe_hdr_split, w2_);
297         CNXK_TEL_DICT_INT(d, ctx, xqe_imm_copy, w2_);
298         CNXK_TEL_DICT_INT(d, ctx, xqe_imm_size, w2_);
299         CNXK_TEL_DICT_INT(d, ctx, later_skip, w2_);
300         CNXK_TEL_DICT_INT(d, ctx, first_skip, w2_);
301         CNXK_TEL_DICT_INT(d, ctx, lpb_sizem1, w2_);
302         CNXK_TEL_DICT_INT(d, ctx, spb_ena, w2_);
303         CNXK_TEL_DICT_INT(d, ctx, wqe_skip, w2_);
304         CNXK_TEL_DICT_INT(d, ctx, spb_sizem1, w2_);
305
306         /* W3 */
307         CNXK_TEL_DICT_INT(d, ctx, spb_pool_pass, w3_);
308         CNXK_TEL_DICT_INT(d, ctx, spb_pool_drop, w3_);
309         CNXK_TEL_DICT_INT(d, ctx, spb_aura_pass, w3_);
310         CNXK_TEL_DICT_INT(d, ctx, spb_aura_drop, w3_);
311         CNXK_TEL_DICT_INT(d, ctx, wqe_pool_pass, w3_);
312         CNXK_TEL_DICT_INT(d, ctx, wqe_pool_drop, w3_);
313         CNXK_TEL_DICT_INT(d, ctx, xqe_pass, w3_);
314         CNXK_TEL_DICT_INT(d, ctx, xqe_drop, w3_);
315
316         /* W4 */
317         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w4_);
318         CNXK_TEL_DICT_INT(d, ctx, rq_int_ena, w4_);
319         CNXK_TEL_DICT_INT(d, ctx, rq_int, w4_);
320         CNXK_TEL_DICT_INT(d, ctx, lpb_pool_pass, w4_);
321         CNXK_TEL_DICT_INT(d, ctx, lpb_pool_drop, w4_);
322         CNXK_TEL_DICT_INT(d, ctx, lpb_aura_pass, w4_);
323         CNXK_TEL_DICT_INT(d, ctx, lpb_aura_drop, w4_);
324
325         /* W5 */
326         CNXK_TEL_DICT_INT(d, ctx, flow_tagw, w5_);
327         CNXK_TEL_DICT_INT(d, ctx, bad_utag, w5_);
328         CNXK_TEL_DICT_INT(d, ctx, good_utag, w5_);
329         CNXK_TEL_DICT_INT(d, ctx, ltag, w5_);
330
331         /* W6 */
332         CNXK_TEL_DICT_U64(d, ctx, octs, w6_);
333
334         /* W7 */
335         CNXK_TEL_DICT_U64(d, ctx, pkts, w7_);
336
337         /* W8 */
338         CNXK_TEL_DICT_U64(d, ctx, drop_octs, w8_);
339
340         /* W9 */
341         CNXK_TEL_DICT_U64(d, ctx, drop_pkts, w9_);
342
343         /* W10 */
344         CNXK_TEL_DICT_U64(d, ctx, re_pkts, w10_);
345 }
346
347 static void
348 nix_rq_ctx(volatile void *qctx, struct plt_tel_data *d)
349 {
350         volatile struct nix_cn10k_rq_ctx_s *ctx;
351
352         ctx = (volatile struct nix_cn10k_rq_ctx_s *)qctx;
353
354         /* W0 */
355         CNXK_TEL_DICT_INT(d, ctx, wqe_aura, w0_);
356         CNXK_TEL_DICT_INT(d, ctx, len_ol3_dis, w0_);
357         CNXK_TEL_DICT_INT(d, ctx, len_ol4_dis, w0_);
358         CNXK_TEL_DICT_INT(d, ctx, len_il3_dis, w0_);
359         CNXK_TEL_DICT_INT(d, ctx, len_il4_dis, w0_);
360         CNXK_TEL_DICT_INT(d, ctx, csum_ol4_dis, w0_);
361         CNXK_TEL_DICT_INT(d, ctx, lenerr_dis, w0_);
362         CNXK_TEL_DICT_INT(d, ctx, ena_wqwd, w0);
363         CNXK_TEL_DICT_INT(d, ctx, ipsech_ena, w0);
364         CNXK_TEL_DICT_INT(d, ctx, sso_ena, w0);
365         CNXK_TEL_DICT_INT(d, ctx, ena, w0);
366
367         /* W1 */
368         CNXK_TEL_DICT_INT(d, ctx, chi_ena, w1_);
369         CNXK_TEL_DICT_INT(d, ctx, ipsecd_drop_en, w1_);
370         CNXK_TEL_DICT_INT(d, ctx, pb_stashing, w1_);
371         CNXK_TEL_DICT_INT(d, ctx, lpb_drop_ena, w1_);
372         CNXK_TEL_DICT_INT(d, ctx, spb_drop_ena, w1_);
373         CNXK_TEL_DICT_INT(d, ctx, xqe_drop_ena, w1_);
374         CNXK_TEL_DICT_INT(d, ctx, wqe_caching, w1_);
375         CNXK_TEL_DICT_INT(d, ctx, pb_caching, w1_);
376         CNXK_TEL_DICT_INT(d, ctx, sso_tt, w1_);
377         CNXK_TEL_DICT_INT(d, ctx, sso_grp, w1_);
378         CNXK_TEL_DICT_INT(d, ctx, lpb_aura, w1_);
379         CNXK_TEL_DICT_INT(d, ctx, spb_aura, w1_);
380
381         /* W2 */
382         CNXK_TEL_DICT_INT(d, ctx, xqe_hdr_split, w2_);
383         CNXK_TEL_DICT_INT(d, ctx, xqe_imm_copy, w2_);
384         CNXK_TEL_DICT_INT(d, ctx, xqe_imm_size, w2_);
385         CNXK_TEL_DICT_INT(d, ctx, later_skip, w2_);
386         CNXK_TEL_DICT_INT(d, ctx, first_skip, w2_);
387         CNXK_TEL_DICT_INT(d, ctx, lpb_sizem1, w2_);
388         CNXK_TEL_DICT_INT(d, ctx, spb_ena, w2_);
389         CNXK_TEL_DICT_INT(d, ctx, wqe_skip, w2_);
390         CNXK_TEL_DICT_INT(d, ctx, spb_sizem1, w2_);
391         CNXK_TEL_DICT_INT(d, ctx, policer_ena, w2_);
392         CNXK_TEL_DICT_INT(d, ctx, band_prof_id, w2_);
393
394         /* W3 */
395         CNXK_TEL_DICT_INT(d, ctx, spb_pool_pass, w3_);
396         CNXK_TEL_DICT_INT(d, ctx, spb_pool_drop, w3_);
397         CNXK_TEL_DICT_INT(d, ctx, spb_aura_pass, w3_);
398         CNXK_TEL_DICT_INT(d, ctx, spb_aura_drop, w3_);
399         CNXK_TEL_DICT_INT(d, ctx, wqe_pool_pass, w3_);
400         CNXK_TEL_DICT_INT(d, ctx, wqe_pool_drop, w3_);
401         CNXK_TEL_DICT_INT(d, ctx, xqe_pass, w3_);
402         CNXK_TEL_DICT_INT(d, ctx, xqe_drop, w3_);
403
404         /* W4 */
405         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w4_);
406         CNXK_TEL_DICT_INT(d, ctx, rq_int_ena, w4_);
407         CNXK_TEL_DICT_INT(d, ctx, rq_int, w4_);
408         CNXK_TEL_DICT_INT(d, ctx, lpb_pool_pass, w4_);
409         CNXK_TEL_DICT_INT(d, ctx, lpb_pool_drop, w4_);
410         CNXK_TEL_DICT_INT(d, ctx, lpb_aura_pass, w4_);
411         CNXK_TEL_DICT_INT(d, ctx, lpb_aura_drop, w4_);
412
413         /* W5 */
414         CNXK_TEL_DICT_INT(d, ctx, vwqe_skip, w5_);
415         CNXK_TEL_DICT_INT(d, ctx, max_vsize_exp, w5_);
416         CNXK_TEL_DICT_INT(d, ctx, vtime_wait, w5_);
417         CNXK_TEL_DICT_INT(d, ctx, vwqe_ena, w5_);
418         CNXK_TEL_DICT_INT(d, ctx, ipsec_vwqe, w5_);
419         CNXK_TEL_DICT_INT(d, ctx, flow_tagw, w5_);
420         CNXK_TEL_DICT_INT(d, ctx, bad_utag, w5_);
421         CNXK_TEL_DICT_INT(d, ctx, good_utag, w5_);
422         CNXK_TEL_DICT_INT(d, ctx, ltag, w5_);
423
424         /* W6 */
425         CNXK_TEL_DICT_U64(d, ctx, octs, w6_);
426
427         /* W7 */
428         CNXK_TEL_DICT_U64(d, ctx, pkts, w7_);
429
430         /* W8 */
431         CNXK_TEL_DICT_U64(d, ctx, drop_octs, w8_);
432
433         /* W9 */
434         CNXK_TEL_DICT_U64(d, ctx, drop_pkts, w9_);
435
436         /* W10 */
437         CNXK_TEL_DICT_U64(d, ctx, re_pkts, w10_);
438 }
439
440 static int
441 cnxk_tel_nix_rq_ctx(struct roc_nix *roc_nix, uint8_t n, struct plt_tel_data *d)
442 {
443         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
444         struct dev *dev = &nix->dev;
445         struct npa_lf *npa_lf;
446         volatile void *qctx;
447         int rc = -1;
448
449         npa_lf = idev_npa_obj_get();
450         if (npa_lf == NULL)
451                 return NPA_ERR_DEVICE_NOT_BOUNDED;
452
453         rc = nix_q_ctx_get(dev, NIX_AQ_CTYPE_RQ, n, &qctx);
454         if (rc) {
455                 plt_err("Failed to get rq context");
456                 return rc;
457         }
458
459         if (roc_model_is_cn9k())
460                 nix_rq_ctx_cn9k(qctx, d);
461         else
462                 nix_rq_ctx(qctx, d);
463
464         return 0;
465 }
466
467 static int
468 cnxk_tel_nix_cq_ctx(struct roc_nix *roc_nix, uint8_t n, struct plt_tel_data *d)
469 {
470         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
471         struct dev *dev = &nix->dev;
472         struct npa_lf *npa_lf;
473         volatile struct nix_cq_ctx_s *ctx;
474         int rc = -1;
475
476         npa_lf = idev_npa_obj_get();
477         if (npa_lf == NULL)
478                 return NPA_ERR_DEVICE_NOT_BOUNDED;
479
480         rc = nix_q_ctx_get(dev, NIX_AQ_CTYPE_CQ, n, (void *)&ctx);
481         if (rc) {
482                 plt_err("Failed to get cq context");
483                 return rc;
484         }
485
486         /* W0 */
487         CNXK_TEL_DICT_PTR(d, ctx, base, w0_);
488
489         /* W1 */
490         CNXK_TEL_DICT_U64(d, ctx, wrptr, w1_);
491         CNXK_TEL_DICT_INT(d, ctx, avg_con, w1_);
492         CNXK_TEL_DICT_INT(d, ctx, cint_idx, w1_);
493         CNXK_TEL_DICT_INT(d, ctx, cq_err, w1_);
494         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w1_);
495         CNXK_TEL_DICT_INT(d, ctx, bpid, w1_);
496         CNXK_TEL_DICT_INT(d, ctx, bp_ena, w1_);
497
498         /* W2 */
499         CNXK_TEL_DICT_INT(d, ctx, update_time, w2_);
500         CNXK_TEL_DICT_INT(d, ctx, avg_level, w2_);
501         CNXK_TEL_DICT_INT(d, ctx, head, w2_);
502         CNXK_TEL_DICT_INT(d, ctx, tail, w2_);
503
504         /* W3 */
505         CNXK_TEL_DICT_INT(d, ctx, cq_err_int_ena, w3_);
506         CNXK_TEL_DICT_INT(d, ctx, cq_err_int, w3_);
507         CNXK_TEL_DICT_INT(d, ctx, qsize, w3_);
508         CNXK_TEL_DICT_INT(d, ctx, caching, w3_);
509         CNXK_TEL_DICT_INT(d, ctx, substream, w3_);
510         CNXK_TEL_DICT_INT(d, ctx, ena, w3_);
511         CNXK_TEL_DICT_INT(d, ctx, drop_ena, w3_);
512         CNXK_TEL_DICT_INT(d, ctx, drop, w3_);
513         CNXK_TEL_DICT_INT(d, ctx, bp, w3_);
514
515         return 0;
516 }
517
518 static void
519 nix_sq_ctx_cn9k(volatile void *qctx, struct plt_tel_data *d)
520 {
521         volatile struct nix_sq_ctx_s *ctx;
522
523         ctx = (volatile struct nix_sq_ctx_s *)qctx;
524
525         /* W0 */
526         CNXK_TEL_DICT_INT(d, ctx, sqe_way_mask, w0_);
527         CNXK_TEL_DICT_INT(d, ctx, cq, w0_);
528         CNXK_TEL_DICT_INT(d, ctx, sdp_mcast, w0_);
529         CNXK_TEL_DICT_INT(d, ctx, substream, w0_);
530         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w0_);
531         CNXK_TEL_DICT_INT(d, ctx, ena, w0_);
532
533         /* W1 */
534         CNXK_TEL_DICT_INT(d, ctx, sqb_count, w1_);
535         CNXK_TEL_DICT_INT(d, ctx, default_chan, w1_);
536         CNXK_TEL_DICT_INT(d, ctx, smq_rr_quantum, w1_);
537         CNXK_TEL_DICT_INT(d, ctx, sso_ena, w1_);
538         CNXK_TEL_DICT_INT(d, ctx, xoff, w1_);
539         CNXK_TEL_DICT_INT(d, ctx, cq_ena, w1_);
540         CNXK_TEL_DICT_INT(d, ctx, smq, w1_);
541
542         /* W2 */
543         CNXK_TEL_DICT_INT(d, ctx, sqe_stype, w2_);
544         CNXK_TEL_DICT_INT(d, ctx, sq_int_ena, w2_);
545         CNXK_TEL_DICT_INT(d, ctx, sq_int, w2_);
546         CNXK_TEL_DICT_INT(d, ctx, sqb_aura, w2_);
547         CNXK_TEL_DICT_INT(d, ctx, smq_rr_count, w2_);
548
549         /* W3 */
550         CNXK_TEL_DICT_INT(d, ctx, smq_next_sq_vld, w3_);
551         CNXK_TEL_DICT_INT(d, ctx, smq_pend, w3_);
552         CNXK_TEL_DICT_INT(d, ctx, smenq_next_sqb_vld, w3_);
553         CNXK_TEL_DICT_INT(d, ctx, head_offset, w3_);
554         CNXK_TEL_DICT_INT(d, ctx, smenq_offset, w3_);
555         CNXK_TEL_DICT_INT(d, ctx, tail_offset, w3_);
556         CNXK_TEL_DICT_INT(d, ctx, smq_lso_segnum, w3_);
557         CNXK_TEL_DICT_INT(d, ctx, smq_next_sq, w3_);
558         CNXK_TEL_DICT_INT(d, ctx, mnq_dis, w3_);
559         CNXK_TEL_DICT_INT(d, ctx, lmt_dis, w3_);
560         CNXK_TEL_DICT_INT(d, ctx, cq_limit, w3_);
561         CNXK_TEL_DICT_INT(d, ctx, max_sqe_size, w3_);
562
563         /* W4 */
564         CNXK_TEL_DICT_PTR(d, ctx, next_sqb, w4_);
565
566         /* W5 */
567         CNXK_TEL_DICT_PTR(d, ctx, tail_sqb, w5_);
568
569         /* W6 */
570         CNXK_TEL_DICT_PTR(d, ctx, smenq_sqb, w6_);
571
572         /* W7 */
573         CNXK_TEL_DICT_PTR(d, ctx, smenq_next_sqb, w7_);
574
575         /* W8 */
576         CNXK_TEL_DICT_PTR(d, ctx, head_sqb, w8_);
577
578         /* W9 */
579         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vld, w9_);
580         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vlan1_ins_ena, w9_);
581         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vlan0_ins_ena, w9_);
582         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_mps, w9_);
583         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_sb, w9_);
584         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_sizem1, w9_);
585         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_total, w9_);
586
587         /* W10 */
588         CNXK_TEL_DICT_BF_PTR(d, ctx, scm_lso_rem, w10_);
589
590         /* W11 */
591         CNXK_TEL_DICT_BF_PTR(d, ctx, octs, w11_);
592
593         /* W12 */
594         CNXK_TEL_DICT_BF_PTR(d, ctx, pkts, w12_);
595
596         /* W14 */
597         CNXK_TEL_DICT_BF_PTR(d, ctx, drop_octs, w14_);
598
599         /* W15 */
600         CNXK_TEL_DICT_BF_PTR(d, ctx, drop_pkts, w15_);
601 }
602
603 static void
604 nix_sq_ctx(volatile void *qctx, struct plt_tel_data *d)
605 {
606         volatile struct nix_cn10k_sq_ctx_s *ctx;
607
608         ctx = (volatile struct nix_cn10k_sq_ctx_s *)qctx;
609
610         /* W0 */
611         CNXK_TEL_DICT_INT(d, ctx, sqe_way_mask, w0_);
612         CNXK_TEL_DICT_INT(d, ctx, cq, w0_);
613         CNXK_TEL_DICT_INT(d, ctx, sdp_mcast, w0_);
614         CNXK_TEL_DICT_INT(d, ctx, substream, w0_);
615         CNXK_TEL_DICT_INT(d, ctx, qint_idx, w0_);
616         CNXK_TEL_DICT_INT(d, ctx, ena, w0_);
617
618         /* W1 */
619         CNXK_TEL_DICT_INT(d, ctx, sqb_count, w1_);
620         CNXK_TEL_DICT_INT(d, ctx, default_chan, w1_);
621         CNXK_TEL_DICT_INT(d, ctx, smq_rr_weight, w1_);
622         CNXK_TEL_DICT_INT(d, ctx, sso_ena, w1_);
623         CNXK_TEL_DICT_INT(d, ctx, xoff, w1_);
624         CNXK_TEL_DICT_INT(d, ctx, cq_ena, w1_);
625         CNXK_TEL_DICT_INT(d, ctx, smq, w1_);
626
627         /* W2 */
628         CNXK_TEL_DICT_INT(d, ctx, sqe_stype, w2_);
629         CNXK_TEL_DICT_INT(d, ctx, sq_int_ena, w2_);
630         CNXK_TEL_DICT_INT(d, ctx, sq_int, w2_);
631         CNXK_TEL_DICT_INT(d, ctx, sqb_aura, w2_);
632         CNXK_TEL_DICT_INT(d, ctx, smq_rr_count_ub, w2_);
633         CNXK_TEL_DICT_INT(d, ctx, smq_rr_count_lb, w2_);
634
635         /* W3 */
636         CNXK_TEL_DICT_INT(d, ctx, smq_next_sq_vld, w3_);
637         CNXK_TEL_DICT_INT(d, ctx, smq_pend, w3_);
638         CNXK_TEL_DICT_INT(d, ctx, smenq_next_sqb_vld, w3_);
639         CNXK_TEL_DICT_INT(d, ctx, head_offset, w3_);
640         CNXK_TEL_DICT_INT(d, ctx, smenq_offset, w3_);
641         CNXK_TEL_DICT_INT(d, ctx, tail_offset, w3_);
642         CNXK_TEL_DICT_INT(d, ctx, smq_lso_segnum, w3_);
643         CNXK_TEL_DICT_INT(d, ctx, smq_next_sq, w3_);
644         CNXK_TEL_DICT_INT(d, ctx, mnq_dis, w3_);
645         CNXK_TEL_DICT_INT(d, ctx, lmt_dis, w3_);
646         CNXK_TEL_DICT_INT(d, ctx, cq_limit, w3_);
647         CNXK_TEL_DICT_INT(d, ctx, max_sqe_size, w3_);
648
649         /* W4 */
650         CNXK_TEL_DICT_PTR(d, ctx, next_sqb, w4_);
651
652         /* W5 */
653         CNXK_TEL_DICT_PTR(d, ctx, tail_sqb, w5_);
654
655         /* W6 */
656         CNXK_TEL_DICT_PTR(d, ctx, smenq_sqb, w6_);
657
658         /* W7 */
659         CNXK_TEL_DICT_PTR(d, ctx, smenq_next_sqb, w7_);
660
661         /* W8 */
662         CNXK_TEL_DICT_PTR(d, ctx, head_sqb, w8_);
663
664         /* W9 */
665         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vld, w9_);
666         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vlan1_ins_ena, w9_);
667         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_vlan0_ins_ena, w9_);
668         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_mps, w9_);
669         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_sb, w9_);
670         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_sizem1, w9_);
671         CNXK_TEL_DICT_INT(d, ctx, vfi_lso_total, w9_);
672
673         /* W10 */
674         CNXK_TEL_DICT_BF_PTR(d, ctx, scm_lso_rem, w10_);
675
676         /* W11 */
677         CNXK_TEL_DICT_BF_PTR(d, ctx, octs, w11_);
678
679         /* W12 */
680         CNXK_TEL_DICT_BF_PTR(d, ctx, pkts, w12_);
681
682         /* W14 */
683         CNXK_TEL_DICT_BF_PTR(d, ctx, drop_octs, w14_);
684
685         /* W15 */
686         CNXK_TEL_DICT_BF_PTR(d, ctx, drop_pkts, w15_);
687 }
688
689 static int
690 cnxk_tel_nix_sq_ctx(struct roc_nix *roc_nix, uint8_t n, struct plt_tel_data *d)
691 {
692         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
693         struct dev *dev = &nix->dev;
694         struct npa_lf *npa_lf;
695         volatile void *qctx;
696         int rc = -1;
697
698         npa_lf = idev_npa_obj_get();
699         if (npa_lf == NULL)
700                 return NPA_ERR_DEVICE_NOT_BOUNDED;
701
702         rc = nix_q_ctx_get(dev, NIX_AQ_CTYPE_SQ, n, &qctx);
703         if (rc) {
704                 plt_err("Failed to get rq context");
705                 return rc;
706         }
707
708         if (roc_model_is_cn9k())
709                 nix_sq_ctx_cn9k(qctx, d);
710         else
711                 nix_sq_ctx(qctx, d);
712
713         return 0;
714 }
715
716 static int
717 cnxk_nix_tel_handle_list(const char *cmd __plt_unused,
718                          const char *params __plt_unused,
719                          struct plt_tel_data *d)
720 {
721         struct nix_tel_node *node;
722         struct roc_nix *roc_nix;
723
724         plt_tel_data_start_array(d, PLT_TEL_STRING_VAL);
725
726         TAILQ_FOREACH(node, &nix_list, node) {
727                 roc_nix = node->nix;
728                 plt_tel_data_add_array_string(d, roc_nix->pci_dev->name);
729         }
730
731         return 0;
732 }
733
734 static int
735 cnxk_nix_tel_handle_info(const char *cmd __plt_unused, const char *params,
736                          struct plt_tel_data *d)
737 {
738         char name[PCI_PRI_STR_SIZE];
739         struct nix_tel_node *node;
740
741         if (params == NULL || strlen(params) == 0 || !isdigit(*params))
742                 return -1;
743
744         plt_strlcpy(name, params, PCI_PRI_STR_SIZE);
745
746         node = nix_tel_node_get_by_pcidev_name(name);
747         if (!node)
748                 return -1;
749
750         plt_tel_data_start_dict(d);
751         return cnxk_tel_nix(node->nix, d);
752 }
753
754 static int
755 cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
756                            struct plt_tel_data *d)
757 {
758         struct nix_tel_node *node;
759         char *name, *param;
760         char buf[1024];
761         int rc = -1;
762
763         if (params == NULL || strlen(params) == 0 || !isdigit(*params))
764                 goto exit;
765
766         plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1);
767         name = strtok(buf, ",");
768         param = strtok(NULL, "\0");
769
770         node = nix_tel_node_get_by_pcidev_name(name);
771         if (!node)
772                 goto exit;
773
774         plt_tel_data_start_dict(d);
775
776         if (strstr(cmd, "rq")) {
777                 char *tok = strtok(param, ",");
778                 int rq;
779
780                 if (!tok)
781                         goto exit;
782
783                 rq = strtol(tok, NULL, 10);
784                 if ((node->n_rq <= rq) || (rq < 0))
785                         goto exit;
786
787                 if (strstr(cmd, "ctx"))
788                         rc = cnxk_tel_nix_rq_ctx(node->nix, rq, d);
789                 else
790                         rc = cnxk_tel_nix_rq(node->rqs[rq], d);
791
792         } else if (strstr(cmd, "cq")) {
793                 char *tok = strtok(param, ",");
794                 int cq;
795
796                 if (!tok)
797                         goto exit;
798
799                 cq = strtol(tok, NULL, 10);
800                 if ((node->n_cq <= cq) || (cq < 0))
801                         goto exit;
802
803                 if (strstr(cmd, "ctx"))
804                         rc = cnxk_tel_nix_cq_ctx(node->nix, cq, d);
805                 else
806                         rc = cnxk_tel_nix_cq(node->cqs[cq], d);
807
808         } else if (strstr(cmd, "sq")) {
809                 char *tok = strtok(param, ",");
810                 int sq;
811
812                 if (!tok)
813                         goto exit;
814
815                 sq = strtol(tok, NULL, 10);
816                 if ((node->n_sq <= sq) || (sq < 0))
817                         goto exit;
818
819                 if (strstr(cmd, "ctx"))
820                         rc = cnxk_tel_nix_sq_ctx(node->nix, sq, d);
821                 else
822                         rc = cnxk_tel_nix_sq(node->sqs[sq], d);
823         }
824
825 exit:
826         return rc;
827 }
828
829 PLT_INIT(cnxk_telemetry_nix_init)
830 {
831         TAILQ_INIT(&nix_list);
832
833         plt_telemetry_register_cmd(
834                 "/cnxk/nix/list", cnxk_nix_tel_handle_list,
835                 "Returns list of available NIX devices. Takes no parameters");
836         plt_telemetry_register_cmd(
837                 "/cnxk/nix/info", cnxk_nix_tel_handle_info,
838                 "Returns nix information. Parameters: pci id");
839         plt_telemetry_register_cmd(
840                 "/cnxk/nix/rq/info", cnxk_nix_tel_handle_info_x,
841                 "Returns nix rq information. Parameters: pci id, rq id");
842         plt_telemetry_register_cmd(
843                 "/cnxk/nix/rq/ctx", cnxk_nix_tel_handle_info_x,
844                 "Returns nix rq context. Parameters: pci id, rq id");
845         plt_telemetry_register_cmd(
846                 "/cnxk/nix/cq/info", cnxk_nix_tel_handle_info_x,
847                 "Returns nix cq information. Parameters: pci id, cq id");
848         plt_telemetry_register_cmd(
849                 "/cnxk/nix/cq/ctx", cnxk_nix_tel_handle_info_x,
850                 "Returns nix cq context. Parameters: pci id, cq id");
851         plt_telemetry_register_cmd(
852                 "/cnxk/nix/sq/info", cnxk_nix_tel_handle_info_x,
853                 "Returns nix sq information. Parameters: pci id, sq id");
854         plt_telemetry_register_cmd(
855                 "/cnxk/nix/sq/ctx", cnxk_nix_tel_handle_info_x,
856                 "Returns nix sq context. Parameters: pci id, sq id");
857 }