Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2015 Freescale Semiconductor, Inc.
3 : : * Copyright 2018-2020,2022 NXP
4 : : */
5 : :
6 : : #include "compat.h"
7 : : #include <fsl_qbman_debug.h>
8 : : #include "qbman_portal.h"
9 : :
10 : : #include <eal_export.h>
11 : :
12 : : /* QBMan portal management command code */
13 : : #define QBMAN_BP_QUERY 0x32
14 : : #define QBMAN_FQ_QUERY 0x44
15 : : #define QBMAN_FQ_QUERY_NP 0x45
16 : : #define QBMAN_WQ_QUERY 0x47
17 : : #define QBMAN_CGR_QUERY 0x51
18 : : #define QBMAN_WRED_QUERY 0x54
19 : : #define QBMAN_CGR_STAT_QUERY 0x55
20 : : #define QBMAN_CGR_STAT_QUERY_CLR 0x56
21 : :
22 : : struct qbman_bp_query_desc {
23 : : uint8_t verb;
24 : : uint8_t reserved;
25 : : uint16_t bpid;
26 : : uint8_t reserved2[60];
27 : : };
28 : :
29 : : #define QB_BP_STATE_SHIFT 24
30 : : #define QB_BP_VA_SHIFT 1
31 : : #define QB_BP_VA_MASK 0x2
32 : : #define QB_BP_WAE_SHIFT 2
33 : : #define QB_BP_WAE_MASK 0x4
34 : : #define QB_BP_PL_SHIFT 15
35 : : #define QB_BP_PL_MASK 0x8000
36 : : #define QB_BP_ICID_MASK 0x7FFF
37 : :
38 : 0 : int qbman_bp_query(struct qbman_swp *s, uint32_t bpid,
39 : : struct qbman_bp_query_rslt *r)
40 : : {
41 : : struct qbman_bp_query_desc *p;
42 : : struct qbman_bp_query_rslt *bp_query_rslt;
43 : :
44 : : /* Start the management command */
45 : 0 : p = (struct qbman_bp_query_desc *)qbman_swp_mc_start(s);
46 [ # # ]: 0 : if (!p)
47 : : return -EBUSY;
48 : :
49 : : /* Encode the caller-provided attributes */
50 : 0 : p->bpid = bpid;
51 : :
52 : : /* Complete the management command */
53 : 0 : bp_query_rslt = (struct qbman_bp_query_rslt *)qbman_swp_mc_complete(s,
54 : : p, QBMAN_BP_QUERY);
55 [ # # ]: 0 : if (!bp_query_rslt) {
56 : 0 : pr_err("qbman: Query BPID %d failed, no response\n",
57 : : bpid);
58 : 0 : return -EIO;
59 : : }
60 : :
61 : 0 : *r = *bp_query_rslt;
62 : :
63 : : /* Decode the outcome */
64 : : QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_BP_QUERY);
65 : :
66 : : /* Determine success or failure */
67 [ # # ]: 0 : if (r->rslt != QBMAN_MC_RSLT_OK) {
68 : 0 : pr_err("Query of BPID 0x%x failed, code=0x%02x\n", bpid,
69 : : r->rslt);
70 : 0 : return -EIO;
71 : : }
72 : :
73 : : return 0;
74 : : }
75 : :
76 : 0 : int qbman_bp_get_bdi(struct qbman_bp_query_rslt *r)
77 : : {
78 : 0 : return r->bdi & 1;
79 : : }
80 : :
81 : 0 : int qbman_bp_get_va(struct qbman_bp_query_rslt *r)
82 : : {
83 : 0 : return (r->bdi & QB_BP_VA_MASK) >> QB_BP_VA_MASK;
84 : : }
85 : :
86 : 0 : int qbman_bp_get_wae(struct qbman_bp_query_rslt *r)
87 : : {
88 : 0 : return (r->bdi & QB_BP_WAE_MASK) >> QB_BP_WAE_SHIFT;
89 : : }
90 : :
91 : : static uint16_t qbman_bp_thresh_to_value(uint16_t val)
92 : : {
93 : 0 : return (val & 0xff) << ((val & 0xf00) >> 8);
94 : : }
95 : :
96 : 0 : uint16_t qbman_bp_get_swdet(struct qbman_bp_query_rslt *r)
97 : : {
98 : :
99 : 0 : return qbman_bp_thresh_to_value(r->swdet);
100 : : }
101 : :
102 : 0 : uint16_t qbman_bp_get_swdxt(struct qbman_bp_query_rslt *r)
103 : : {
104 : 0 : return qbman_bp_thresh_to_value(r->swdxt);
105 : : }
106 : :
107 : 0 : uint16_t qbman_bp_get_hwdet(struct qbman_bp_query_rslt *r)
108 : : {
109 : 0 : return qbman_bp_thresh_to_value(r->hwdet);
110 : : }
111 : :
112 : 0 : uint16_t qbman_bp_get_hwdxt(struct qbman_bp_query_rslt *r)
113 : : {
114 : 0 : return qbman_bp_thresh_to_value(r->hwdxt);
115 : : }
116 : :
117 : 0 : uint16_t qbman_bp_get_swset(struct qbman_bp_query_rslt *r)
118 : : {
119 : 0 : return qbman_bp_thresh_to_value(r->swset);
120 : : }
121 : :
122 : 0 : uint16_t qbman_bp_get_swsxt(struct qbman_bp_query_rslt *r)
123 : : {
124 : :
125 : 0 : return qbman_bp_thresh_to_value(r->swsxt);
126 : : }
127 : :
128 : 0 : uint16_t qbman_bp_get_vbpid(struct qbman_bp_query_rslt *r)
129 : : {
130 : 0 : return r->vbpid;
131 : : }
132 : :
133 : 0 : uint16_t qbman_bp_get_icid(struct qbman_bp_query_rslt *r)
134 : : {
135 : 0 : return r->icid & QB_BP_ICID_MASK;
136 : : }
137 : :
138 : 0 : int qbman_bp_get_pl(struct qbman_bp_query_rslt *r)
139 : : {
140 : 0 : return (r->icid & QB_BP_PL_MASK) >> QB_BP_PL_SHIFT;
141 : : }
142 : :
143 : 0 : uint64_t qbman_bp_get_bpscn_addr(struct qbman_bp_query_rslt *r)
144 : : {
145 : 0 : return r->bpscn_addr;
146 : : }
147 : :
148 : 0 : uint64_t qbman_bp_get_bpscn_ctx(struct qbman_bp_query_rslt *r)
149 : : {
150 : 0 : return r->bpscn_ctx;
151 : : }
152 : :
153 : 0 : uint16_t qbman_bp_get_hw_targ(struct qbman_bp_query_rslt *r)
154 : : {
155 : 0 : return r->hw_targ;
156 : : }
157 : :
158 : 0 : int qbman_bp_has_free_bufs(struct qbman_bp_query_rslt *r)
159 : : {
160 : 0 : return !(int)(r->state & 0x1);
161 : : }
162 : :
163 : 0 : int qbman_bp_is_depleted(struct qbman_bp_query_rslt *r)
164 : : {
165 : 0 : return (int)((r->state & 0x2) >> 1);
166 : : }
167 : :
168 : 0 : int qbman_bp_is_surplus(struct qbman_bp_query_rslt *r)
169 : : {
170 : 0 : return (int)((r->state & 0x4) >> 2);
171 : : }
172 : :
173 : 0 : uint32_t qbman_bp_num_free_bufs(struct qbman_bp_query_rslt *r)
174 : : {
175 : 0 : return r->fill;
176 : : }
177 : :
178 : 0 : uint32_t qbman_bp_get_hdptr(struct qbman_bp_query_rslt *r)
179 : : {
180 : 0 : return r->hdptr;
181 : : }
182 : :
183 : 0 : uint32_t qbman_bp_get_sdcnt(struct qbman_bp_query_rslt *r)
184 : : {
185 : 0 : return r->sdcnt;
186 : : }
187 : :
188 : 0 : uint32_t qbman_bp_get_hdcnt(struct qbman_bp_query_rslt *r)
189 : : {
190 : 0 : return r->hdcnt;
191 : : }
192 : :
193 : 0 : uint32_t qbman_bp_get_sscnt(struct qbman_bp_query_rslt *r)
194 : : {
195 : 0 : return r->sscnt;
196 : : }
197 : :
198 : : struct qbman_fq_query_desc {
199 : : uint8_t verb;
200 : : uint8_t reserved[3];
201 : : uint32_t fqid;
202 : : uint8_t reserved2[56];
203 : : };
204 : :
205 : : /* FQ query function for programmable fields */
206 : 0 : int qbman_fq_query(struct qbman_swp *s, uint32_t fqid,
207 : : struct qbman_fq_query_rslt *r)
208 : : {
209 : : struct qbman_fq_query_desc *p;
210 : : struct qbman_fq_query_rslt *fq_query_rslt;
211 : :
212 : 0 : p = (struct qbman_fq_query_desc *)qbman_swp_mc_start(s);
213 [ # # ]: 0 : if (!p)
214 : : return -EBUSY;
215 : :
216 : 0 : p->fqid = fqid;
217 : 0 : fq_query_rslt = (struct qbman_fq_query_rslt *)qbman_swp_mc_complete(s,
218 : : p, QBMAN_FQ_QUERY);
219 [ # # ]: 0 : if (!fq_query_rslt) {
220 : 0 : pr_err("qbman: Query FQID %d failed, no response\n",
221 : : fqid);
222 : 0 : return -EIO;
223 : : }
224 : :
225 : 0 : *r = *fq_query_rslt;
226 : :
227 : : /* Decode the outcome */
228 : : QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_FQ_QUERY);
229 : :
230 : : /* Determine success or failure */
231 [ # # ]: 0 : if (r->rslt != QBMAN_MC_RSLT_OK) {
232 : 0 : pr_err("Query of FQID 0x%x failed, code=0x%02x\n",
233 : : fqid, r->rslt);
234 : 0 : return -EIO;
235 : : }
236 : :
237 : : return 0;
238 : : }
239 : :
240 : 0 : uint8_t qbman_fq_attr_get_fqctrl(struct qbman_fq_query_rslt *r)
241 : : {
242 : 0 : return r->fq_ctrl;
243 : : }
244 : :
245 : 0 : uint16_t qbman_fq_attr_get_cgrid(struct qbman_fq_query_rslt *r)
246 : : {
247 : 0 : return r->cgid;
248 : : }
249 : :
250 : 0 : uint16_t qbman_fq_attr_get_destwq(struct qbman_fq_query_rslt *r)
251 : : {
252 : 0 : return r->dest_wq;
253 : : }
254 : :
255 : : static uint16_t qbman_thresh_to_value(uint16_t val)
256 : : {
257 : 0 : return ((val & 0x1FE0) >> 5) << (val & 0x1F);
258 : : }
259 : :
260 : 0 : uint16_t qbman_fq_attr_get_tdthresh(struct qbman_fq_query_rslt *r)
261 : : {
262 : 0 : return qbman_thresh_to_value(r->td_thresh);
263 : : }
264 : :
265 : 0 : int qbman_fq_attr_get_oa_ics(struct qbman_fq_query_rslt *r)
266 : : {
267 : 0 : return (int)(r->oal_oac >> 14) & 0x1;
268 : : }
269 : :
270 : 0 : int qbman_fq_attr_get_oa_cgr(struct qbman_fq_query_rslt *r)
271 : : {
272 : 0 : return (int)(r->oal_oac >> 15);
273 : : }
274 : :
275 : 0 : uint16_t qbman_fq_attr_get_oal(struct qbman_fq_query_rslt *r)
276 : : {
277 : 0 : return (r->oal_oac & 0x0FFF);
278 : : }
279 : :
280 : 0 : int qbman_fq_attr_get_bdi(struct qbman_fq_query_rslt *r)
281 : : {
282 : 0 : return (r->mctl & 0x1);
283 : : }
284 : :
285 : 0 : int qbman_fq_attr_get_ff(struct qbman_fq_query_rslt *r)
286 : : {
287 : 0 : return (r->mctl & 0x2) >> 1;
288 : : }
289 : :
290 : 0 : int qbman_fq_attr_get_va(struct qbman_fq_query_rslt *r)
291 : : {
292 : 0 : return (r->mctl & 0x4) >> 2;
293 : : }
294 : :
295 : 0 : int qbman_fq_attr_get_ps(struct qbman_fq_query_rslt *r)
296 : : {
297 : 0 : return (r->mctl & 0x8) >> 3;
298 : : }
299 : :
300 : 0 : int qbman_fq_attr_get_pps(struct qbman_fq_query_rslt *r)
301 : : {
302 : 0 : return (r->mctl & 0x30) >> 4;
303 : : }
304 : :
305 : 0 : uint16_t qbman_fq_attr_get_icid(struct qbman_fq_query_rslt *r)
306 : : {
307 : 0 : return r->icid & 0x7FFF;
308 : : }
309 : :
310 : 0 : int qbman_fq_attr_get_pl(struct qbman_fq_query_rslt *r)
311 : : {
312 : 0 : return (int)((r->icid & 0x8000) >> 15);
313 : : }
314 : :
315 : 0 : uint32_t qbman_fq_attr_get_vfqid(struct qbman_fq_query_rslt *r)
316 : : {
317 : 0 : return r->vfqid & 0x00FFFFFF;
318 : : }
319 : :
320 : 0 : uint32_t qbman_fq_attr_get_erfqid(struct qbman_fq_query_rslt *r)
321 : : {
322 : 0 : return r->fqid_er & 0x00FFFFFF;
323 : : }
324 : :
325 : 0 : uint16_t qbman_fq_attr_get_opridsz(struct qbman_fq_query_rslt *r)
326 : : {
327 : 0 : return r->opridsz;
328 : : }
329 : :
330 : : RTE_EXPORT_INTERNAL_SYMBOL(qbman_fq_query_state)
331 : 0 : int qbman_fq_query_state(struct qbman_swp *s, uint32_t fqid,
332 : : struct qbman_fq_query_np_rslt *r)
333 : : {
334 : : struct qbman_fq_query_desc *p;
335 : : struct qbman_fq_query_np_rslt *var;
336 : :
337 : 0 : p = (struct qbman_fq_query_desc *)qbman_swp_mc_start(s);
338 [ # # ]: 0 : if (!p)
339 : : return -EBUSY;
340 : :
341 : 0 : p->fqid = fqid;
342 : 0 : var = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY_NP);
343 [ # # ]: 0 : if (!var) {
344 : 0 : pr_err("qbman: Query FQID %d NP fields failed, no response\n",
345 : : fqid);
346 : 0 : return -EIO;
347 : : }
348 : 0 : *r = *var;
349 : :
350 : : /* Decode the outcome */
351 : : QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_FQ_QUERY_NP);
352 : :
353 : : /* Determine success or failure */
354 [ # # ]: 0 : if (r->rslt != QBMAN_MC_RSLT_OK) {
355 : 0 : pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
356 : : fqid, r->rslt);
357 : 0 : return -EIO;
358 : : }
359 : :
360 : : return 0;
361 : : }
362 : :
363 : 0 : uint8_t qbman_fq_state_schedstate(const struct qbman_fq_query_np_rslt *r)
364 : : {
365 : 0 : return r->st1 & 0x7;
366 : : }
367 : :
368 : 0 : int qbman_fq_state_force_eligible(const struct qbman_fq_query_np_rslt *r)
369 : : {
370 : 0 : return (int)((r->st1 & 0x8) >> 3);
371 : : }
372 : :
373 : 0 : int qbman_fq_state_xoff(const struct qbman_fq_query_np_rslt *r)
374 : : {
375 : 0 : return (int)((r->st1 & 0x10) >> 4);
376 : : }
377 : :
378 : 0 : int qbman_fq_state_retirement_pending(const struct qbman_fq_query_np_rslt *r)
379 : : {
380 : 0 : return (int)((r->st1 & 0x20) >> 5);
381 : : }
382 : :
383 : 0 : int qbman_fq_state_overflow_error(const struct qbman_fq_query_np_rslt *r)
384 : : {
385 : 0 : return (int)((r->st1 & 0x40) >> 6);
386 : : }
387 : :
388 : : RTE_EXPORT_INTERNAL_SYMBOL(qbman_fq_state_frame_count)
389 : 0 : uint32_t qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt *r)
390 : : {
391 : 0 : return (r->frm_cnt & 0x00FFFFFF);
392 : : }
393 : :
394 : 0 : uint32_t qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt *r)
395 : : {
396 : 0 : return r->byte_cnt;
397 : : }
398 : :
399 : : /* Query CGR */
400 : : struct qbman_cgr_query_desc {
401 : : uint8_t verb;
402 : : uint8_t reserved;
403 : : uint16_t cgid;
404 : : uint8_t reserved2[60];
405 : : };
406 : :
407 : 0 : int qbman_cgr_query(struct qbman_swp *s, uint32_t cgid,
408 : : struct qbman_cgr_query_rslt *r)
409 : : {
410 : : struct qbman_cgr_query_desc *p;
411 : : struct qbman_cgr_query_rslt *cgr_query_rslt;
412 : :
413 : 0 : p = (struct qbman_cgr_query_desc *)qbman_swp_mc_start(s);
414 [ # # ]: 0 : if (!p)
415 : : return -EBUSY;
416 : :
417 : 0 : p->cgid = cgid;
418 : 0 : cgr_query_rslt = (struct qbman_cgr_query_rslt *)qbman_swp_mc_complete(s,
419 : : p, QBMAN_CGR_QUERY);
420 [ # # ]: 0 : if (!cgr_query_rslt) {
421 : 0 : pr_err("qbman: Query CGID %d failed, no response\n",
422 : : cgid);
423 : 0 : return -EIO;
424 : : }
425 : :
426 : 0 : *r = *cgr_query_rslt;
427 : :
428 : : /* Decode the outcome */
429 : : QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_CGR_QUERY);
430 : :
431 : : /* Determine success or failure */
432 [ # # ]: 0 : if (r->rslt != QBMAN_MC_RSLT_OK) {
433 : 0 : pr_err("Query CGID 0x%x failed,code=0x%02x\n", cgid, r->rslt);
434 : 0 : return -EIO;
435 : : }
436 : :
437 : : return 0;
438 : : }
439 : :
440 : 0 : int qbman_cgr_get_cscn_wq_en_enter(struct qbman_cgr_query_rslt *r)
441 : : {
442 : 0 : return (int)(r->ctl1 & 0x1);
443 : : }
444 : :
445 : 0 : int qbman_cgr_get_cscn_wq_en_exit(struct qbman_cgr_query_rslt *r)
446 : : {
447 : 0 : return (int)((r->ctl1 & 0x2) >> 1);
448 : : }
449 : :
450 : 0 : int qbman_cgr_get_cscn_wq_icd(struct qbman_cgr_query_rslt *r)
451 : : {
452 : 0 : return (int)((r->ctl1 & 0x4) >> 2);
453 : : }
454 : :
455 : 0 : uint8_t qbman_cgr_get_mode(struct qbman_cgr_query_rslt *r)
456 : : {
457 : 0 : return r->mode & 0x3;
458 : : }
459 : :
460 : 0 : int qbman_cgr_get_rej_cnt_mode(struct qbman_cgr_query_rslt *r)
461 : : {
462 : 0 : return (int)((r->mode & 0x4) >> 2);
463 : : }
464 : :
465 : 0 : int qbman_cgr_get_cscn_bdi(struct qbman_cgr_query_rslt *r)
466 : : {
467 : 0 : return (int)((r->mode & 0x8) >> 3);
468 : : }
469 : :
470 : 0 : uint16_t qbman_cgr_attr_get_cs_thres(struct qbman_cgr_query_rslt *r)
471 : : {
472 : 0 : return qbman_thresh_to_value(r->cs_thres);
473 : : }
474 : :
475 : 0 : uint16_t qbman_cgr_attr_get_cs_thres_x(struct qbman_cgr_query_rslt *r)
476 : : {
477 : 0 : return qbman_thresh_to_value(r->cs_thres_x);
478 : : }
479 : :
480 : 0 : uint16_t qbman_cgr_attr_get_td_thres(struct qbman_cgr_query_rslt *r)
481 : : {
482 : 0 : return qbman_thresh_to_value(r->td_thres);
483 : : }
484 : :
485 : 0 : int qbman_cgr_wred_query(struct qbman_swp *s, uint32_t cgid,
486 : : struct qbman_wred_query_rslt *r)
487 : : {
488 : : struct qbman_cgr_query_desc *p;
489 : : struct qbman_wred_query_rslt *wred_query_rslt;
490 : :
491 : 0 : p = (struct qbman_cgr_query_desc *)qbman_swp_mc_start(s);
492 [ # # ]: 0 : if (!p)
493 : : return -EBUSY;
494 : :
495 : 0 : p->cgid = cgid;
496 : 0 : wred_query_rslt = (struct qbman_wred_query_rslt *)qbman_swp_mc_complete(
497 : : s, p, QBMAN_WRED_QUERY);
498 [ # # ]: 0 : if (!wred_query_rslt) {
499 : 0 : pr_err("qbman: Query CGID WRED %d failed, no response\n",
500 : : cgid);
501 : 0 : return -EIO;
502 : : }
503 : :
504 : 0 : *r = *wred_query_rslt;
505 : :
506 : : /* Decode the outcome */
507 : : QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_WRED_QUERY);
508 : :
509 : : /* Determine success or failure */
510 [ # # ]: 0 : if (r->rslt != QBMAN_MC_RSLT_OK) {
511 : 0 : pr_err("Query CGID WRED 0x%x failed,code=0x%02x\n",
512 : : cgid, r->rslt);
513 : 0 : return -EIO;
514 : : }
515 : :
516 : : return 0;
517 : : }
518 : :
519 : 0 : int qbman_cgr_attr_wred_get_edp(struct qbman_wred_query_rslt *r, uint32_t idx)
520 : : {
521 : 0 : return (int)(r->edp[idx] & 1);
522 : : }
523 : :
524 : 0 : uint32_t qbman_cgr_attr_wred_get_parm_dp(struct qbman_wred_query_rslt *r,
525 : : uint32_t idx)
526 : : {
527 : 0 : return r->wred_parm_dp[idx];
528 : : }
529 : :
530 : 0 : void qbman_cgr_attr_wred_dp_decompose(uint32_t dp, uint64_t *minth,
531 : : uint64_t *maxth, uint8_t *maxp)
532 : : {
533 : : uint8_t ma, mn, step_i, step_s, pn;
534 : :
535 : 0 : ma = (uint8_t)(dp >> 24);
536 : 0 : mn = (uint8_t)(dp >> 19) & 0x1f;
537 : 0 : step_i = (uint8_t)(dp >> 11);
538 : 0 : step_s = (uint8_t)(dp >> 6) & 0x1f;
539 : 0 : pn = (uint8_t)dp & 0x3f;
540 : :
541 : 0 : *maxp = (uint8_t)(((pn<<2) * 100)/256);
542 : :
543 [ # # ]: 0 : if (mn == 0)
544 : 0 : *maxth = ma;
545 : : else
546 : 0 : *maxth = ((uint64_t)(ma+256) * (1<<(mn-1)));
547 : :
548 [ # # ]: 0 : if (step_s == 0)
549 : 0 : *minth = *maxth - step_i;
550 : : else
551 : 0 : *minth = *maxth - (256 + step_i) * (1<<(step_s - 1));
552 : 0 : }
553 : :
554 : : /* Query CGR/CCGR/CQ statistics */
555 : : struct qbman_cgr_statistics_query_desc {
556 : : uint8_t verb;
557 : : uint8_t reserved;
558 : : uint16_t cgid;
559 : : uint8_t reserved1;
560 : : uint8_t ct;
561 : : uint8_t reserved2[58];
562 : : };
563 : :
564 : : struct qbman_cgr_statistics_query_rslt {
565 : : uint8_t verb;
566 : : uint8_t rslt;
567 : : uint8_t reserved[14];
568 : : uint64_t frm_cnt;
569 : : uint64_t byte_cnt;
570 : : uint32_t reserved2[8];
571 : : };
572 : :
573 : 0 : static int qbman_cgr_statistics_query(struct qbman_swp *s, uint32_t cgid,
574 : : int clear, uint32_t command_type,
575 : : uint64_t *frame_cnt, uint64_t *byte_cnt)
576 : : {
577 : : struct qbman_cgr_statistics_query_desc *p;
578 : : struct qbman_cgr_statistics_query_rslt *r;
579 : : uint32_t query_verb;
580 : :
581 : 0 : p = (struct qbman_cgr_statistics_query_desc *)qbman_swp_mc_start(s);
582 [ # # ]: 0 : if (!p)
583 : : return -EBUSY;
584 : :
585 : 0 : p->cgid = cgid;
586 [ # # ]: 0 : if (command_type < 2)
587 : 0 : p->ct = command_type;
588 : : query_verb = clear ?
589 [ # # ]: 0 : QBMAN_CGR_STAT_QUERY_CLR : QBMAN_CGR_STAT_QUERY;
590 : 0 : r = (struct qbman_cgr_statistics_query_rslt *)qbman_swp_mc_complete(s,
591 : : p, query_verb);
592 [ # # ]: 0 : if (!r) {
593 : 0 : pr_err("qbman: Query CGID %d statistics failed, no response\n",
594 : : cgid);
595 : 0 : return -EIO;
596 : : }
597 : :
598 : : /* Decode the outcome */
599 : : QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != query_verb);
600 : :
601 : : /* Determine success or failure */
602 [ # # ]: 0 : if (r->rslt != QBMAN_MC_RSLT_OK) {
603 : 0 : pr_err("Query statistics of CGID 0x%x failed, code=0x%02x\n",
604 : : cgid, r->rslt);
605 : 0 : return -EIO;
606 : : }
607 : :
608 [ # # ]: 0 : if (*frame_cnt)
609 : 0 : *frame_cnt = r->frm_cnt & 0xFFFFFFFFFFllu;
610 [ # # ]: 0 : if (*byte_cnt)
611 : 0 : *byte_cnt = r->byte_cnt & 0xFFFFFFFFFFllu;
612 : :
613 : : return 0;
614 : : }
615 : :
616 : 0 : int qbman_cgr_reject_statistics(struct qbman_swp *s, uint32_t cgid, int clear,
617 : : uint64_t *frame_cnt, uint64_t *byte_cnt)
618 : : {
619 : 0 : return qbman_cgr_statistics_query(s, cgid, clear, 0xff,
620 : : frame_cnt, byte_cnt);
621 : : }
622 : :
623 : 0 : int qbman_ccgr_reject_statistics(struct qbman_swp *s, uint32_t cgid, int clear,
624 : : uint64_t *frame_cnt, uint64_t *byte_cnt)
625 : : {
626 : 0 : return qbman_cgr_statistics_query(s, cgid, clear, 1,
627 : : frame_cnt, byte_cnt);
628 : : }
629 : :
630 : 0 : int qbman_cq_dequeue_statistics(struct qbman_swp *s, uint32_t cgid, int clear,
631 : : uint64_t *frame_cnt, uint64_t *byte_cnt)
632 : : {
633 : 0 : return qbman_cgr_statistics_query(s, cgid, clear, 0,
634 : : frame_cnt, byte_cnt);
635 : : }
636 : :
637 : : /* WQ Chan Query */
638 : : struct qbman_wqchan_query_desc {
639 : : uint8_t verb;
640 : : uint8_t reserved;
641 : : uint16_t chid;
642 : : uint8_t reserved2[60];
643 : : };
644 : :
645 : 0 : int qbman_wqchan_query(struct qbman_swp *s, uint16_t chanid,
646 : : struct qbman_wqchan_query_rslt *r)
647 : : {
648 : : struct qbman_wqchan_query_desc *p;
649 : : struct qbman_wqchan_query_rslt *wqchan_query_rslt;
650 : :
651 : : /* Start the management command */
652 : 0 : p = (struct qbman_wqchan_query_desc *)qbman_swp_mc_start(s);
653 [ # # ]: 0 : if (!p)
654 : : return -EBUSY;
655 : :
656 : : /* Encode the caller-provided attributes */
657 : 0 : p->chid = chanid;
658 : :
659 : : /* Complete the management command */
660 : 0 : wqchan_query_rslt = (struct qbman_wqchan_query_rslt *)qbman_swp_mc_complete(
661 : : s, p, QBMAN_WQ_QUERY);
662 [ # # ]: 0 : if (!wqchan_query_rslt) {
663 : 0 : pr_err("qbman: Query WQ Channel %d failed, no response\n",
664 : : chanid);
665 : 0 : return -EIO;
666 : : }
667 : :
668 : 0 : *r = *wqchan_query_rslt;
669 : :
670 : : /* Decode the outcome */
671 : : QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_WQ_QUERY);
672 : :
673 : : /* Determine success or failure */
674 [ # # ]: 0 : if (r->rslt != QBMAN_MC_RSLT_OK) {
675 : 0 : pr_err("Query of WQCHAN 0x%x failed, code=0x%02x\n",
676 : : chanid, r->rslt);
677 : 0 : return -EIO;
678 : : }
679 : :
680 : : return 0;
681 : : }
682 : :
683 : 0 : uint32_t qbman_wqchan_attr_get_wqlen(struct qbman_wqchan_query_rslt *r, int wq)
684 : : {
685 : 0 : return r->wq_len[wq] & 0x00FFFFFF;
686 : : }
687 : :
688 : 0 : uint64_t qbman_wqchan_attr_get_cdan_ctx(struct qbman_wqchan_query_rslt *r)
689 : : {
690 : 0 : return r->cdan_ctx;
691 : : }
692 : :
693 : 0 : uint16_t qbman_wqchan_attr_get_cdan_wqid(struct qbman_wqchan_query_rslt *r)
694 : : {
695 : 0 : return r->cdan_wqid;
696 : : }
697 : :
698 : 0 : uint8_t qbman_wqchan_attr_get_ctrl(struct qbman_wqchan_query_rslt *r)
699 : : {
700 : 0 : return r->ctrl;
701 : : }
702 : :
703 : 0 : uint16_t qbman_wqchan_attr_get_chanid(struct qbman_wqchan_query_rslt *r)
704 : : {
705 : 0 : return r->chid;
706 : : }
|