xref: /dpdk/drivers/bus/fslmc/qbman/qbman_debug.c (revision 2d0c29a37a9c080c1cccb1ad7941aba2ccf5437e)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2015 Freescale Semiconductor, Inc.
3  */
4 
5 #include "compat.h"
6 #include <fsl_qbman_debug.h>
7 #include "qbman_portal.h"
8 
9 /* QBMan portal management command code */
10 #define QBMAN_BP_QUERY            0x32
11 #define QBMAN_FQ_QUERY            0x44
12 #define QBMAN_FQ_QUERY_NP         0x45
13 #define QBMAN_WQ_QUERY            0x47
14 #define QBMAN_CGR_QUERY           0x51
15 #define QBMAN_WRED_QUERY          0x54
16 #define QBMAN_CGR_STAT_QUERY      0x55
17 #define QBMAN_CGR_STAT_QUERY_CLR  0x56
18 
19 struct qbman_fq_query_desc {
20 	uint8_t verb;
21 	uint8_t reserved[3];
22 	uint32_t fqid;
23 	uint8_t reserved2[57];
24 };
25 
26 int qbman_fq_query_state(struct qbman_swp *s, uint32_t fqid,
27 			 struct qbman_fq_query_np_rslt *r)
28 {
29 	struct qbman_fq_query_desc *p;
30 
31 	p = (struct qbman_fq_query_desc *)qbman_swp_mc_start(s);
32 	if (!p)
33 		return -EBUSY;
34 
35 	p->fqid = fqid;
36 	*r = *(struct qbman_fq_query_np_rslt *)qbman_swp_mc_complete(s, p,
37 						QBMAN_FQ_QUERY_NP);
38 	if (!r) {
39 		pr_err("qbman: Query FQID %d NP fields failed, no response\n",
40 		       fqid);
41 		return -EIO;
42 	}
43 
44 	/* Decode the outcome */
45 	QBMAN_BUG_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_FQ_QUERY_NP);
46 
47 	/* Determine success or failure */
48 	if (r->rslt != QBMAN_MC_RSLT_OK) {
49 		pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
50 		       fqid, r->rslt);
51 		return -EIO;
52 	}
53 
54 	return 0;
55 }
56 
57 uint32_t qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt *r)
58 {
59 	return (r->frm_cnt & 0x00FFFFFF);
60 }
61 
62 uint32_t qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt *r)
63 {
64 	return r->byte_cnt;
65 }
66