1*4882a593Smuzhiyun // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
4*4882a593Smuzhiyun * Copyright 2016-2019 NXP
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <asm/cacheflush.h>
9*4882a593Smuzhiyun #include <linux/io.h>
10*4882a593Smuzhiyun #include <linux/slab.h>
11*4882a593Smuzhiyun #include <linux/spinlock.h>
12*4882a593Smuzhiyun #include <soc/fsl/dpaa2-global.h>
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #include "qbman-portal.h"
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun /* All QBMan command and result structures use this "valid bit" encoding */
17*4882a593Smuzhiyun #define QB_VALID_BIT ((u32)0x80)
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun /* QBMan portal management command codes */
20*4882a593Smuzhiyun #define QBMAN_MC_ACQUIRE 0x30
21*4882a593Smuzhiyun #define QBMAN_WQCHAN_CONFIGURE 0x46
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun /* CINH register offsets */
24*4882a593Smuzhiyun #define QBMAN_CINH_SWP_EQCR_PI 0x800
25*4882a593Smuzhiyun #define QBMAN_CINH_SWP_EQCR_CI 0x840
26*4882a593Smuzhiyun #define QBMAN_CINH_SWP_EQAR 0x8c0
27*4882a593Smuzhiyun #define QBMAN_CINH_SWP_CR_RT 0x900
28*4882a593Smuzhiyun #define QBMAN_CINH_SWP_VDQCR_RT 0x940
29*4882a593Smuzhiyun #define QBMAN_CINH_SWP_EQCR_AM_RT 0x980
30*4882a593Smuzhiyun #define QBMAN_CINH_SWP_RCR_AM_RT 0x9c0
31*4882a593Smuzhiyun #define QBMAN_CINH_SWP_DQPI 0xa00
32*4882a593Smuzhiyun #define QBMAN_CINH_SWP_DCAP 0xac0
33*4882a593Smuzhiyun #define QBMAN_CINH_SWP_SDQCR 0xb00
34*4882a593Smuzhiyun #define QBMAN_CINH_SWP_EQCR_AM_RT2 0xb40
35*4882a593Smuzhiyun #define QBMAN_CINH_SWP_RCR_PI 0xc00
36*4882a593Smuzhiyun #define QBMAN_CINH_SWP_RAR 0xcc0
37*4882a593Smuzhiyun #define QBMAN_CINH_SWP_ISR 0xe00
38*4882a593Smuzhiyun #define QBMAN_CINH_SWP_IER 0xe40
39*4882a593Smuzhiyun #define QBMAN_CINH_SWP_ISDR 0xe80
40*4882a593Smuzhiyun #define QBMAN_CINH_SWP_IIR 0xec0
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /* CENA register offsets */
43*4882a593Smuzhiyun #define QBMAN_CENA_SWP_EQCR(n) (0x000 + ((u32)(n) << 6))
44*4882a593Smuzhiyun #define QBMAN_CENA_SWP_DQRR(n) (0x200 + ((u32)(n) << 6))
45*4882a593Smuzhiyun #define QBMAN_CENA_SWP_RCR(n) (0x400 + ((u32)(n) << 6))
46*4882a593Smuzhiyun #define QBMAN_CENA_SWP_CR 0x600
47*4882a593Smuzhiyun #define QBMAN_CENA_SWP_RR(vb) (0x700 + ((u32)(vb) >> 1))
48*4882a593Smuzhiyun #define QBMAN_CENA_SWP_VDQCR 0x780
49*4882a593Smuzhiyun #define QBMAN_CENA_SWP_EQCR_CI 0x840
50*4882a593Smuzhiyun #define QBMAN_CENA_SWP_EQCR_CI_MEMBACK 0x1840
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun /* CENA register offsets in memory-backed mode */
53*4882a593Smuzhiyun #define QBMAN_CENA_SWP_DQRR_MEM(n) (0x800 + ((u32)(n) << 6))
54*4882a593Smuzhiyun #define QBMAN_CENA_SWP_RCR_MEM(n) (0x1400 + ((u32)(n) << 6))
55*4882a593Smuzhiyun #define QBMAN_CENA_SWP_CR_MEM 0x1600
56*4882a593Smuzhiyun #define QBMAN_CENA_SWP_RR_MEM 0x1680
57*4882a593Smuzhiyun #define QBMAN_CENA_SWP_VDQCR_MEM 0x1780
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* Reverse mapping of QBMAN_CENA_SWP_DQRR() */
60*4882a593Smuzhiyun #define QBMAN_IDX_FROM_DQRR(p) (((unsigned long)(p) & 0x1ff) >> 6)
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun /* Define token used to determine if response written to memory is valid */
63*4882a593Smuzhiyun #define QMAN_DQ_TOKEN_VALID 1
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /* SDQCR attribute codes */
66*4882a593Smuzhiyun #define QB_SDQCR_FC_SHIFT 29
67*4882a593Smuzhiyun #define QB_SDQCR_FC_MASK 0x1
68*4882a593Smuzhiyun #define QB_SDQCR_DCT_SHIFT 24
69*4882a593Smuzhiyun #define QB_SDQCR_DCT_MASK 0x3
70*4882a593Smuzhiyun #define QB_SDQCR_TOK_SHIFT 16
71*4882a593Smuzhiyun #define QB_SDQCR_TOK_MASK 0xff
72*4882a593Smuzhiyun #define QB_SDQCR_SRC_SHIFT 0
73*4882a593Smuzhiyun #define QB_SDQCR_SRC_MASK 0xffff
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun /* opaque token for static dequeues */
76*4882a593Smuzhiyun #define QMAN_SDQCR_TOKEN 0xbb
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun #define QBMAN_EQCR_DCA_IDXMASK 0x0f
79*4882a593Smuzhiyun #define QBMAN_ENQUEUE_FLAG_DCA (1ULL << 31)
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun #define EQ_DESC_SIZE_WITHOUT_FD 29
82*4882a593Smuzhiyun #define EQ_DESC_SIZE_FD_START 32
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun enum qbman_sdqcr_dct {
85*4882a593Smuzhiyun qbman_sdqcr_dct_null = 0,
86*4882a593Smuzhiyun qbman_sdqcr_dct_prio_ics,
87*4882a593Smuzhiyun qbman_sdqcr_dct_active_ics,
88*4882a593Smuzhiyun qbman_sdqcr_dct_active
89*4882a593Smuzhiyun };
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun enum qbman_sdqcr_fc {
92*4882a593Smuzhiyun qbman_sdqcr_fc_one = 0,
93*4882a593Smuzhiyun qbman_sdqcr_fc_up_to_3 = 1
94*4882a593Smuzhiyun };
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun /* Internal Function declaration */
97*4882a593Smuzhiyun static int qbman_swp_enqueue_direct(struct qbman_swp *s,
98*4882a593Smuzhiyun const struct qbman_eq_desc *d,
99*4882a593Smuzhiyun const struct dpaa2_fd *fd);
100*4882a593Smuzhiyun static int qbman_swp_enqueue_mem_back(struct qbman_swp *s,
101*4882a593Smuzhiyun const struct qbman_eq_desc *d,
102*4882a593Smuzhiyun const struct dpaa2_fd *fd);
103*4882a593Smuzhiyun static int qbman_swp_enqueue_multiple_direct(struct qbman_swp *s,
104*4882a593Smuzhiyun const struct qbman_eq_desc *d,
105*4882a593Smuzhiyun const struct dpaa2_fd *fd,
106*4882a593Smuzhiyun uint32_t *flags,
107*4882a593Smuzhiyun int num_frames);
108*4882a593Smuzhiyun static int qbman_swp_enqueue_multiple_mem_back(struct qbman_swp *s,
109*4882a593Smuzhiyun const struct qbman_eq_desc *d,
110*4882a593Smuzhiyun const struct dpaa2_fd *fd,
111*4882a593Smuzhiyun uint32_t *flags,
112*4882a593Smuzhiyun int num_frames);
113*4882a593Smuzhiyun static int
114*4882a593Smuzhiyun qbman_swp_enqueue_multiple_desc_direct(struct qbman_swp *s,
115*4882a593Smuzhiyun const struct qbman_eq_desc *d,
116*4882a593Smuzhiyun const struct dpaa2_fd *fd,
117*4882a593Smuzhiyun int num_frames);
118*4882a593Smuzhiyun static
119*4882a593Smuzhiyun int qbman_swp_enqueue_multiple_desc_mem_back(struct qbman_swp *s,
120*4882a593Smuzhiyun const struct qbman_eq_desc *d,
121*4882a593Smuzhiyun const struct dpaa2_fd *fd,
122*4882a593Smuzhiyun int num_frames);
123*4882a593Smuzhiyun static int qbman_swp_pull_direct(struct qbman_swp *s,
124*4882a593Smuzhiyun struct qbman_pull_desc *d);
125*4882a593Smuzhiyun static int qbman_swp_pull_mem_back(struct qbman_swp *s,
126*4882a593Smuzhiyun struct qbman_pull_desc *d);
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun const struct dpaa2_dq *qbman_swp_dqrr_next_direct(struct qbman_swp *s);
129*4882a593Smuzhiyun const struct dpaa2_dq *qbman_swp_dqrr_next_mem_back(struct qbman_swp *s);
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun static int qbman_swp_release_direct(struct qbman_swp *s,
132*4882a593Smuzhiyun const struct qbman_release_desc *d,
133*4882a593Smuzhiyun const u64 *buffers,
134*4882a593Smuzhiyun unsigned int num_buffers);
135*4882a593Smuzhiyun static int qbman_swp_release_mem_back(struct qbman_swp *s,
136*4882a593Smuzhiyun const struct qbman_release_desc *d,
137*4882a593Smuzhiyun const u64 *buffers,
138*4882a593Smuzhiyun unsigned int num_buffers);
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun /* Function pointers */
141*4882a593Smuzhiyun int (*qbman_swp_enqueue_ptr)(struct qbman_swp *s,
142*4882a593Smuzhiyun const struct qbman_eq_desc *d,
143*4882a593Smuzhiyun const struct dpaa2_fd *fd)
144*4882a593Smuzhiyun = qbman_swp_enqueue_direct;
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun int (*qbman_swp_enqueue_multiple_ptr)(struct qbman_swp *s,
147*4882a593Smuzhiyun const struct qbman_eq_desc *d,
148*4882a593Smuzhiyun const struct dpaa2_fd *fd,
149*4882a593Smuzhiyun uint32_t *flags,
150*4882a593Smuzhiyun int num_frames)
151*4882a593Smuzhiyun = qbman_swp_enqueue_multiple_direct;
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun int
154*4882a593Smuzhiyun (*qbman_swp_enqueue_multiple_desc_ptr)(struct qbman_swp *s,
155*4882a593Smuzhiyun const struct qbman_eq_desc *d,
156*4882a593Smuzhiyun const struct dpaa2_fd *fd,
157*4882a593Smuzhiyun int num_frames)
158*4882a593Smuzhiyun = qbman_swp_enqueue_multiple_desc_direct;
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun int (*qbman_swp_pull_ptr)(struct qbman_swp *s, struct qbman_pull_desc *d)
161*4882a593Smuzhiyun = qbman_swp_pull_direct;
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun const struct dpaa2_dq *(*qbman_swp_dqrr_next_ptr)(struct qbman_swp *s)
164*4882a593Smuzhiyun = qbman_swp_dqrr_next_direct;
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun int (*qbman_swp_release_ptr)(struct qbman_swp *s,
167*4882a593Smuzhiyun const struct qbman_release_desc *d,
168*4882a593Smuzhiyun const u64 *buffers,
169*4882a593Smuzhiyun unsigned int num_buffers)
170*4882a593Smuzhiyun = qbman_swp_release_direct;
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun /* Portal Access */
173*4882a593Smuzhiyun
qbman_read_register(struct qbman_swp * p,u32 offset)174*4882a593Smuzhiyun static inline u32 qbman_read_register(struct qbman_swp *p, u32 offset)
175*4882a593Smuzhiyun {
176*4882a593Smuzhiyun return readl_relaxed(p->addr_cinh + offset);
177*4882a593Smuzhiyun }
178*4882a593Smuzhiyun
qbman_write_register(struct qbman_swp * p,u32 offset,u32 value)179*4882a593Smuzhiyun static inline void qbman_write_register(struct qbman_swp *p, u32 offset,
180*4882a593Smuzhiyun u32 value)
181*4882a593Smuzhiyun {
182*4882a593Smuzhiyun writel_relaxed(value, p->addr_cinh + offset);
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun
qbman_get_cmd(struct qbman_swp * p,u32 offset)185*4882a593Smuzhiyun static inline void *qbman_get_cmd(struct qbman_swp *p, u32 offset)
186*4882a593Smuzhiyun {
187*4882a593Smuzhiyun return p->addr_cena + offset;
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun #define QBMAN_CINH_SWP_CFG 0xd00
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun #define SWP_CFG_DQRR_MF_SHIFT 20
193*4882a593Smuzhiyun #define SWP_CFG_EST_SHIFT 16
194*4882a593Smuzhiyun #define SWP_CFG_CPBS_SHIFT 15
195*4882a593Smuzhiyun #define SWP_CFG_WN_SHIFT 14
196*4882a593Smuzhiyun #define SWP_CFG_RPM_SHIFT 12
197*4882a593Smuzhiyun #define SWP_CFG_DCM_SHIFT 10
198*4882a593Smuzhiyun #define SWP_CFG_EPM_SHIFT 8
199*4882a593Smuzhiyun #define SWP_CFG_VPM_SHIFT 7
200*4882a593Smuzhiyun #define SWP_CFG_CPM_SHIFT 6
201*4882a593Smuzhiyun #define SWP_CFG_SD_SHIFT 5
202*4882a593Smuzhiyun #define SWP_CFG_SP_SHIFT 4
203*4882a593Smuzhiyun #define SWP_CFG_SE_SHIFT 3
204*4882a593Smuzhiyun #define SWP_CFG_DP_SHIFT 2
205*4882a593Smuzhiyun #define SWP_CFG_DE_SHIFT 1
206*4882a593Smuzhiyun #define SWP_CFG_EP_SHIFT 0
207*4882a593Smuzhiyun
qbman_set_swp_cfg(u8 max_fill,u8 wn,u8 est,u8 rpm,u8 dcm,u8 epm,int sd,int sp,int se,int dp,int de,int ep)208*4882a593Smuzhiyun static inline u32 qbman_set_swp_cfg(u8 max_fill, u8 wn, u8 est, u8 rpm, u8 dcm,
209*4882a593Smuzhiyun u8 epm, int sd, int sp, int se,
210*4882a593Smuzhiyun int dp, int de, int ep)
211*4882a593Smuzhiyun {
212*4882a593Smuzhiyun return (max_fill << SWP_CFG_DQRR_MF_SHIFT |
213*4882a593Smuzhiyun est << SWP_CFG_EST_SHIFT |
214*4882a593Smuzhiyun wn << SWP_CFG_WN_SHIFT |
215*4882a593Smuzhiyun rpm << SWP_CFG_RPM_SHIFT |
216*4882a593Smuzhiyun dcm << SWP_CFG_DCM_SHIFT |
217*4882a593Smuzhiyun epm << SWP_CFG_EPM_SHIFT |
218*4882a593Smuzhiyun sd << SWP_CFG_SD_SHIFT |
219*4882a593Smuzhiyun sp << SWP_CFG_SP_SHIFT |
220*4882a593Smuzhiyun se << SWP_CFG_SE_SHIFT |
221*4882a593Smuzhiyun dp << SWP_CFG_DP_SHIFT |
222*4882a593Smuzhiyun de << SWP_CFG_DE_SHIFT |
223*4882a593Smuzhiyun ep << SWP_CFG_EP_SHIFT);
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun #define QMAN_RT_MODE 0x00000100
227*4882a593Smuzhiyun
qm_cyc_diff(u8 ringsize,u8 first,u8 last)228*4882a593Smuzhiyun static inline u8 qm_cyc_diff(u8 ringsize, u8 first, u8 last)
229*4882a593Smuzhiyun {
230*4882a593Smuzhiyun /* 'first' is included, 'last' is excluded */
231*4882a593Smuzhiyun if (first <= last)
232*4882a593Smuzhiyun return last - first;
233*4882a593Smuzhiyun else
234*4882a593Smuzhiyun return (2 * ringsize) - (first - last);
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun /**
238*4882a593Smuzhiyun * qbman_swp_init() - Create a functional object representing the given
239*4882a593Smuzhiyun * QBMan portal descriptor.
240*4882a593Smuzhiyun * @d: the given qbman swp descriptor
241*4882a593Smuzhiyun *
242*4882a593Smuzhiyun * Return qbman_swp portal for success, NULL if the object cannot
243*4882a593Smuzhiyun * be created.
244*4882a593Smuzhiyun */
qbman_swp_init(const struct qbman_swp_desc * d)245*4882a593Smuzhiyun struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d)
246*4882a593Smuzhiyun {
247*4882a593Smuzhiyun struct qbman_swp *p = kzalloc(sizeof(*p), GFP_KERNEL);
248*4882a593Smuzhiyun u32 reg;
249*4882a593Smuzhiyun u32 mask_size;
250*4882a593Smuzhiyun u32 eqcr_pi;
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun if (!p)
253*4882a593Smuzhiyun return NULL;
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun spin_lock_init(&p->access_spinlock);
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun p->desc = d;
258*4882a593Smuzhiyun p->mc.valid_bit = QB_VALID_BIT;
259*4882a593Smuzhiyun p->sdq = 0;
260*4882a593Smuzhiyun p->sdq |= qbman_sdqcr_dct_prio_ics << QB_SDQCR_DCT_SHIFT;
261*4882a593Smuzhiyun p->sdq |= qbman_sdqcr_fc_up_to_3 << QB_SDQCR_FC_SHIFT;
262*4882a593Smuzhiyun p->sdq |= QMAN_SDQCR_TOKEN << QB_SDQCR_TOK_SHIFT;
263*4882a593Smuzhiyun if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000)
264*4882a593Smuzhiyun p->mr.valid_bit = QB_VALID_BIT;
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun atomic_set(&p->vdq.available, 1);
267*4882a593Smuzhiyun p->vdq.valid_bit = QB_VALID_BIT;
268*4882a593Smuzhiyun p->dqrr.next_idx = 0;
269*4882a593Smuzhiyun p->dqrr.valid_bit = QB_VALID_BIT;
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_4100) {
272*4882a593Smuzhiyun p->dqrr.dqrr_size = 4;
273*4882a593Smuzhiyun p->dqrr.reset_bug = 1;
274*4882a593Smuzhiyun } else {
275*4882a593Smuzhiyun p->dqrr.dqrr_size = 8;
276*4882a593Smuzhiyun p->dqrr.reset_bug = 0;
277*4882a593Smuzhiyun }
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun p->addr_cena = d->cena_bar;
280*4882a593Smuzhiyun p->addr_cinh = d->cinh_bar;
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun reg = qbman_set_swp_cfg(p->dqrr.dqrr_size,
285*4882a593Smuzhiyun 1, /* Writes Non-cacheable */
286*4882a593Smuzhiyun 0, /* EQCR_CI stashing threshold */
287*4882a593Smuzhiyun 3, /* RPM: RCR in array mode */
288*4882a593Smuzhiyun 2, /* DCM: Discrete consumption ack */
289*4882a593Smuzhiyun 2, /* EPM: EQCR in ring mode */
290*4882a593Smuzhiyun 1, /* mem stashing drop enable enable */
291*4882a593Smuzhiyun 1, /* mem stashing priority enable */
292*4882a593Smuzhiyun 1, /* mem stashing enable */
293*4882a593Smuzhiyun 1, /* dequeue stashing priority enable */
294*4882a593Smuzhiyun 0, /* dequeue stashing enable enable */
295*4882a593Smuzhiyun 0); /* EQCR_CI stashing priority enable */
296*4882a593Smuzhiyun } else {
297*4882a593Smuzhiyun memset(p->addr_cena, 0, 64 * 1024);
298*4882a593Smuzhiyun reg = qbman_set_swp_cfg(p->dqrr.dqrr_size,
299*4882a593Smuzhiyun 1, /* Writes Non-cacheable */
300*4882a593Smuzhiyun 1, /* EQCR_CI stashing threshold */
301*4882a593Smuzhiyun 3, /* RPM: RCR in array mode */
302*4882a593Smuzhiyun 2, /* DCM: Discrete consumption ack */
303*4882a593Smuzhiyun 0, /* EPM: EQCR in ring mode */
304*4882a593Smuzhiyun 1, /* mem stashing drop enable */
305*4882a593Smuzhiyun 1, /* mem stashing priority enable */
306*4882a593Smuzhiyun 1, /* mem stashing enable */
307*4882a593Smuzhiyun 1, /* dequeue stashing priority enable */
308*4882a593Smuzhiyun 0, /* dequeue stashing enable */
309*4882a593Smuzhiyun 0); /* EQCR_CI stashing priority enable */
310*4882a593Smuzhiyun reg |= 1 << SWP_CFG_CPBS_SHIFT | /* memory-backed mode */
311*4882a593Smuzhiyun 1 << SWP_CFG_VPM_SHIFT | /* VDQCR read triggered mode */
312*4882a593Smuzhiyun 1 << SWP_CFG_CPM_SHIFT; /* CR read triggered mode */
313*4882a593Smuzhiyun }
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun qbman_write_register(p, QBMAN_CINH_SWP_CFG, reg);
316*4882a593Smuzhiyun reg = qbman_read_register(p, QBMAN_CINH_SWP_CFG);
317*4882a593Smuzhiyun if (!reg) {
318*4882a593Smuzhiyun pr_err("qbman: the portal is not enabled!\n");
319*4882a593Smuzhiyun kfree(p);
320*4882a593Smuzhiyun return NULL;
321*4882a593Smuzhiyun }
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000) {
324*4882a593Smuzhiyun qbman_write_register(p, QBMAN_CINH_SWP_EQCR_PI, QMAN_RT_MODE);
325*4882a593Smuzhiyun qbman_write_register(p, QBMAN_CINH_SWP_RCR_PI, QMAN_RT_MODE);
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun /*
328*4882a593Smuzhiyun * SDQCR needs to be initialized to 0 when no channels are
329*4882a593Smuzhiyun * being dequeued from or else the QMan HW will indicate an
330*4882a593Smuzhiyun * error. The values that were calculated above will be
331*4882a593Smuzhiyun * applied when dequeues from a specific channel are enabled.
332*4882a593Smuzhiyun */
333*4882a593Smuzhiyun qbman_write_register(p, QBMAN_CINH_SWP_SDQCR, 0);
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun p->eqcr.pi_ring_size = 8;
336*4882a593Smuzhiyun if ((p->desc->qman_version & QMAN_REV_MASK) >= QMAN_REV_5000) {
337*4882a593Smuzhiyun p->eqcr.pi_ring_size = 32;
338*4882a593Smuzhiyun qbman_swp_enqueue_ptr =
339*4882a593Smuzhiyun qbman_swp_enqueue_mem_back;
340*4882a593Smuzhiyun qbman_swp_enqueue_multiple_ptr =
341*4882a593Smuzhiyun qbman_swp_enqueue_multiple_mem_back;
342*4882a593Smuzhiyun qbman_swp_enqueue_multiple_desc_ptr =
343*4882a593Smuzhiyun qbman_swp_enqueue_multiple_desc_mem_back;
344*4882a593Smuzhiyun qbman_swp_pull_ptr = qbman_swp_pull_mem_back;
345*4882a593Smuzhiyun qbman_swp_dqrr_next_ptr = qbman_swp_dqrr_next_mem_back;
346*4882a593Smuzhiyun qbman_swp_release_ptr = qbman_swp_release_mem_back;
347*4882a593Smuzhiyun }
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun for (mask_size = p->eqcr.pi_ring_size; mask_size > 0; mask_size >>= 1)
350*4882a593Smuzhiyun p->eqcr.pi_ci_mask = (p->eqcr.pi_ci_mask << 1) + 1;
351*4882a593Smuzhiyun eqcr_pi = qbman_read_register(p, QBMAN_CINH_SWP_EQCR_PI);
352*4882a593Smuzhiyun p->eqcr.pi = eqcr_pi & p->eqcr.pi_ci_mask;
353*4882a593Smuzhiyun p->eqcr.pi_vb = eqcr_pi & QB_VALID_BIT;
354*4882a593Smuzhiyun p->eqcr.ci = qbman_read_register(p, QBMAN_CINH_SWP_EQCR_CI)
355*4882a593Smuzhiyun & p->eqcr.pi_ci_mask;
356*4882a593Smuzhiyun p->eqcr.available = p->eqcr.pi_ring_size;
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun return p;
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun /**
362*4882a593Smuzhiyun * qbman_swp_finish() - Create and destroy a functional object representing
363*4882a593Smuzhiyun * the given QBMan portal descriptor.
364*4882a593Smuzhiyun * @p: the qbman_swp object to be destroyed
365*4882a593Smuzhiyun */
qbman_swp_finish(struct qbman_swp * p)366*4882a593Smuzhiyun void qbman_swp_finish(struct qbman_swp *p)
367*4882a593Smuzhiyun {
368*4882a593Smuzhiyun kfree(p);
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun /**
372*4882a593Smuzhiyun * qbman_swp_interrupt_read_status()
373*4882a593Smuzhiyun * @p: the given software portal
374*4882a593Smuzhiyun *
375*4882a593Smuzhiyun * Return the value in the SWP_ISR register.
376*4882a593Smuzhiyun */
qbman_swp_interrupt_read_status(struct qbman_swp * p)377*4882a593Smuzhiyun u32 qbman_swp_interrupt_read_status(struct qbman_swp *p)
378*4882a593Smuzhiyun {
379*4882a593Smuzhiyun return qbman_read_register(p, QBMAN_CINH_SWP_ISR);
380*4882a593Smuzhiyun }
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun /**
383*4882a593Smuzhiyun * qbman_swp_interrupt_clear_status()
384*4882a593Smuzhiyun * @p: the given software portal
385*4882a593Smuzhiyun * @mask: The mask to clear in SWP_ISR register
386*4882a593Smuzhiyun */
qbman_swp_interrupt_clear_status(struct qbman_swp * p,u32 mask)387*4882a593Smuzhiyun void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask)
388*4882a593Smuzhiyun {
389*4882a593Smuzhiyun qbman_write_register(p, QBMAN_CINH_SWP_ISR, mask);
390*4882a593Smuzhiyun }
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun /**
393*4882a593Smuzhiyun * qbman_swp_interrupt_get_trigger() - read interrupt enable register
394*4882a593Smuzhiyun * @p: the given software portal
395*4882a593Smuzhiyun *
396*4882a593Smuzhiyun * Return the value in the SWP_IER register.
397*4882a593Smuzhiyun */
qbman_swp_interrupt_get_trigger(struct qbman_swp * p)398*4882a593Smuzhiyun u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p)
399*4882a593Smuzhiyun {
400*4882a593Smuzhiyun return qbman_read_register(p, QBMAN_CINH_SWP_IER);
401*4882a593Smuzhiyun }
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun /**
404*4882a593Smuzhiyun * qbman_swp_interrupt_set_trigger() - enable interrupts for a swp
405*4882a593Smuzhiyun * @p: the given software portal
406*4882a593Smuzhiyun * @mask: The mask of bits to enable in SWP_IER
407*4882a593Smuzhiyun */
qbman_swp_interrupt_set_trigger(struct qbman_swp * p,u32 mask)408*4882a593Smuzhiyun void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask)
409*4882a593Smuzhiyun {
410*4882a593Smuzhiyun qbman_write_register(p, QBMAN_CINH_SWP_IER, mask);
411*4882a593Smuzhiyun }
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun /**
414*4882a593Smuzhiyun * qbman_swp_interrupt_get_inhibit() - read interrupt mask register
415*4882a593Smuzhiyun * @p: the given software portal object
416*4882a593Smuzhiyun *
417*4882a593Smuzhiyun * Return the value in the SWP_IIR register.
418*4882a593Smuzhiyun */
qbman_swp_interrupt_get_inhibit(struct qbman_swp * p)419*4882a593Smuzhiyun int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p)
420*4882a593Smuzhiyun {
421*4882a593Smuzhiyun return qbman_read_register(p, QBMAN_CINH_SWP_IIR);
422*4882a593Smuzhiyun }
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun /**
425*4882a593Smuzhiyun * qbman_swp_interrupt_set_inhibit() - write interrupt mask register
426*4882a593Smuzhiyun * @p: the given software portal object
427*4882a593Smuzhiyun * @mask: The mask to set in SWP_IIR register
428*4882a593Smuzhiyun */
qbman_swp_interrupt_set_inhibit(struct qbman_swp * p,int inhibit)429*4882a593Smuzhiyun void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit)
430*4882a593Smuzhiyun {
431*4882a593Smuzhiyun qbman_write_register(p, QBMAN_CINH_SWP_IIR, inhibit ? 0xffffffff : 0);
432*4882a593Smuzhiyun }
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun /*
435*4882a593Smuzhiyun * Different management commands all use this common base layer of code to issue
436*4882a593Smuzhiyun * commands and poll for results.
437*4882a593Smuzhiyun */
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun /*
440*4882a593Smuzhiyun * Returns a pointer to where the caller should fill in their management command
441*4882a593Smuzhiyun * (caller should ignore the verb byte)
442*4882a593Smuzhiyun */
qbman_swp_mc_start(struct qbman_swp * p)443*4882a593Smuzhiyun void *qbman_swp_mc_start(struct qbman_swp *p)
444*4882a593Smuzhiyun {
445*4882a593Smuzhiyun if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
446*4882a593Smuzhiyun return qbman_get_cmd(p, QBMAN_CENA_SWP_CR);
447*4882a593Smuzhiyun else
448*4882a593Smuzhiyun return qbman_get_cmd(p, QBMAN_CENA_SWP_CR_MEM);
449*4882a593Smuzhiyun }
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun /*
452*4882a593Smuzhiyun * Commits merges in the caller-supplied command verb (which should not include
453*4882a593Smuzhiyun * the valid-bit) and submits the command to hardware
454*4882a593Smuzhiyun */
qbman_swp_mc_submit(struct qbman_swp * p,void * cmd,u8 cmd_verb)455*4882a593Smuzhiyun void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb)
456*4882a593Smuzhiyun {
457*4882a593Smuzhiyun u8 *v = cmd;
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
460*4882a593Smuzhiyun dma_wmb();
461*4882a593Smuzhiyun *v = cmd_verb | p->mc.valid_bit;
462*4882a593Smuzhiyun } else {
463*4882a593Smuzhiyun *v = cmd_verb | p->mc.valid_bit;
464*4882a593Smuzhiyun dma_wmb();
465*4882a593Smuzhiyun qbman_write_register(p, QBMAN_CINH_SWP_CR_RT, QMAN_RT_MODE);
466*4882a593Smuzhiyun }
467*4882a593Smuzhiyun }
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun /*
470*4882a593Smuzhiyun * Checks for a completed response (returns non-NULL if only if the response
471*4882a593Smuzhiyun * is complete).
472*4882a593Smuzhiyun */
qbman_swp_mc_result(struct qbman_swp * p)473*4882a593Smuzhiyun void *qbman_swp_mc_result(struct qbman_swp *p)
474*4882a593Smuzhiyun {
475*4882a593Smuzhiyun u32 *ret, verb;
476*4882a593Smuzhiyun
477*4882a593Smuzhiyun if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000) {
478*4882a593Smuzhiyun ret = qbman_get_cmd(p, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
479*4882a593Smuzhiyun /* Remove the valid-bit - command completed if the rest
480*4882a593Smuzhiyun * is non-zero.
481*4882a593Smuzhiyun */
482*4882a593Smuzhiyun verb = ret[0] & ~QB_VALID_BIT;
483*4882a593Smuzhiyun if (!verb)
484*4882a593Smuzhiyun return NULL;
485*4882a593Smuzhiyun p->mc.valid_bit ^= QB_VALID_BIT;
486*4882a593Smuzhiyun } else {
487*4882a593Smuzhiyun ret = qbman_get_cmd(p, QBMAN_CENA_SWP_RR_MEM);
488*4882a593Smuzhiyun /* Command completed if the valid bit is toggled */
489*4882a593Smuzhiyun if (p->mr.valid_bit != (ret[0] & QB_VALID_BIT))
490*4882a593Smuzhiyun return NULL;
491*4882a593Smuzhiyun /* Command completed if the rest is non-zero */
492*4882a593Smuzhiyun verb = ret[0] & ~QB_VALID_BIT;
493*4882a593Smuzhiyun if (!verb)
494*4882a593Smuzhiyun return NULL;
495*4882a593Smuzhiyun p->mr.valid_bit ^= QB_VALID_BIT;
496*4882a593Smuzhiyun }
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun return ret;
499*4882a593Smuzhiyun }
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun #define QB_ENQUEUE_CMD_OPTIONS_SHIFT 0
502*4882a593Smuzhiyun enum qb_enqueue_commands {
503*4882a593Smuzhiyun enqueue_empty = 0,
504*4882a593Smuzhiyun enqueue_response_always = 1,
505*4882a593Smuzhiyun enqueue_rejects_to_fq = 2
506*4882a593Smuzhiyun };
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun #define QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT 2
509*4882a593Smuzhiyun #define QB_ENQUEUE_CMD_IRQ_ON_DISPATCH_SHIFT 3
510*4882a593Smuzhiyun #define QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT 4
511*4882a593Smuzhiyun #define QB_ENQUEUE_CMD_DCA_EN_SHIFT 7
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun /**
514*4882a593Smuzhiyun * qbman_eq_desc_clear() - Clear the contents of a descriptor to
515*4882a593Smuzhiyun * default/starting state.
516*4882a593Smuzhiyun */
qbman_eq_desc_clear(struct qbman_eq_desc * d)517*4882a593Smuzhiyun void qbman_eq_desc_clear(struct qbman_eq_desc *d)
518*4882a593Smuzhiyun {
519*4882a593Smuzhiyun memset(d, 0, sizeof(*d));
520*4882a593Smuzhiyun }
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun /**
523*4882a593Smuzhiyun * qbman_eq_desc_set_no_orp() - Set enqueue descriptor without orp
524*4882a593Smuzhiyun * @d: the enqueue descriptor.
525*4882a593Smuzhiyun * @response_success: 1 = enqueue with response always; 0 = enqueue with
526*4882a593Smuzhiyun * rejections returned on a FQ.
527*4882a593Smuzhiyun */
qbman_eq_desc_set_no_orp(struct qbman_eq_desc * d,int respond_success)528*4882a593Smuzhiyun void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success)
529*4882a593Smuzhiyun {
530*4882a593Smuzhiyun d->verb &= ~(1 << QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT);
531*4882a593Smuzhiyun if (respond_success)
532*4882a593Smuzhiyun d->verb |= enqueue_response_always;
533*4882a593Smuzhiyun else
534*4882a593Smuzhiyun d->verb |= enqueue_rejects_to_fq;
535*4882a593Smuzhiyun }
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun /*
538*4882a593Smuzhiyun * Exactly one of the following descriptor "targets" should be set. (Calling any
539*4882a593Smuzhiyun * one of these will replace the effect of any prior call to one of these.)
540*4882a593Smuzhiyun * -enqueue to a frame queue
541*4882a593Smuzhiyun * -enqueue to a queuing destination
542*4882a593Smuzhiyun */
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun /**
545*4882a593Smuzhiyun * qbman_eq_desc_set_fq() - set the FQ for the enqueue command
546*4882a593Smuzhiyun * @d: the enqueue descriptor
547*4882a593Smuzhiyun * @fqid: the id of the frame queue to be enqueued
548*4882a593Smuzhiyun */
qbman_eq_desc_set_fq(struct qbman_eq_desc * d,u32 fqid)549*4882a593Smuzhiyun void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid)
550*4882a593Smuzhiyun {
551*4882a593Smuzhiyun d->verb &= ~(1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT);
552*4882a593Smuzhiyun d->tgtid = cpu_to_le32(fqid);
553*4882a593Smuzhiyun }
554*4882a593Smuzhiyun
555*4882a593Smuzhiyun /**
556*4882a593Smuzhiyun * qbman_eq_desc_set_qd() - Set Queuing Destination for the enqueue command
557*4882a593Smuzhiyun * @d: the enqueue descriptor
558*4882a593Smuzhiyun * @qdid: the id of the queuing destination to be enqueued
559*4882a593Smuzhiyun * @qd_bin: the queuing destination bin
560*4882a593Smuzhiyun * @qd_prio: the queuing destination priority
561*4882a593Smuzhiyun */
qbman_eq_desc_set_qd(struct qbman_eq_desc * d,u32 qdid,u32 qd_bin,u32 qd_prio)562*4882a593Smuzhiyun void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
563*4882a593Smuzhiyun u32 qd_bin, u32 qd_prio)
564*4882a593Smuzhiyun {
565*4882a593Smuzhiyun d->verb |= 1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT;
566*4882a593Smuzhiyun d->tgtid = cpu_to_le32(qdid);
567*4882a593Smuzhiyun d->qdbin = cpu_to_le16(qd_bin);
568*4882a593Smuzhiyun d->qpri = qd_prio;
569*4882a593Smuzhiyun }
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun #define EQAR_IDX(eqar) ((eqar) & 0x7)
572*4882a593Smuzhiyun #define EQAR_VB(eqar) ((eqar) & 0x80)
573*4882a593Smuzhiyun #define EQAR_SUCCESS(eqar) ((eqar) & 0x100)
574*4882a593Smuzhiyun
575*4882a593Smuzhiyun #define QB_RT_BIT ((u32)0x100)
576*4882a593Smuzhiyun /**
577*4882a593Smuzhiyun * qbman_swp_enqueue_direct() - Issue an enqueue command
578*4882a593Smuzhiyun * @s: the software portal used for enqueue
579*4882a593Smuzhiyun * @d: the enqueue descriptor
580*4882a593Smuzhiyun * @fd: the frame descriptor to be enqueued
581*4882a593Smuzhiyun *
582*4882a593Smuzhiyun * Please note that 'fd' should only be NULL if the "action" of the
583*4882a593Smuzhiyun * descriptor is "orp_hole" or "orp_nesn".
584*4882a593Smuzhiyun *
585*4882a593Smuzhiyun * Return 0 for successful enqueue, -EBUSY if the EQCR is not ready.
586*4882a593Smuzhiyun */
587*4882a593Smuzhiyun static
qbman_swp_enqueue_direct(struct qbman_swp * s,const struct qbman_eq_desc * d,const struct dpaa2_fd * fd)588*4882a593Smuzhiyun int qbman_swp_enqueue_direct(struct qbman_swp *s,
589*4882a593Smuzhiyun const struct qbman_eq_desc *d,
590*4882a593Smuzhiyun const struct dpaa2_fd *fd)
591*4882a593Smuzhiyun {
592*4882a593Smuzhiyun int flags = 0;
593*4882a593Smuzhiyun int ret = qbman_swp_enqueue_multiple_direct(s, d, fd, &flags, 1);
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun if (ret >= 0)
596*4882a593Smuzhiyun ret = 0;
597*4882a593Smuzhiyun else
598*4882a593Smuzhiyun ret = -EBUSY;
599*4882a593Smuzhiyun return ret;
600*4882a593Smuzhiyun }
601*4882a593Smuzhiyun
602*4882a593Smuzhiyun /**
603*4882a593Smuzhiyun * qbman_swp_enqueue_mem_back() - Issue an enqueue command
604*4882a593Smuzhiyun * @s: the software portal used for enqueue
605*4882a593Smuzhiyun * @d: the enqueue descriptor
606*4882a593Smuzhiyun * @fd: the frame descriptor to be enqueued
607*4882a593Smuzhiyun *
608*4882a593Smuzhiyun * Please note that 'fd' should only be NULL if the "action" of the
609*4882a593Smuzhiyun * descriptor is "orp_hole" or "orp_nesn".
610*4882a593Smuzhiyun *
611*4882a593Smuzhiyun * Return 0 for successful enqueue, -EBUSY if the EQCR is not ready.
612*4882a593Smuzhiyun */
613*4882a593Smuzhiyun static
qbman_swp_enqueue_mem_back(struct qbman_swp * s,const struct qbman_eq_desc * d,const struct dpaa2_fd * fd)614*4882a593Smuzhiyun int qbman_swp_enqueue_mem_back(struct qbman_swp *s,
615*4882a593Smuzhiyun const struct qbman_eq_desc *d,
616*4882a593Smuzhiyun const struct dpaa2_fd *fd)
617*4882a593Smuzhiyun {
618*4882a593Smuzhiyun int flags = 0;
619*4882a593Smuzhiyun int ret = qbman_swp_enqueue_multiple_mem_back(s, d, fd, &flags, 1);
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun if (ret >= 0)
622*4882a593Smuzhiyun ret = 0;
623*4882a593Smuzhiyun else
624*4882a593Smuzhiyun ret = -EBUSY;
625*4882a593Smuzhiyun return ret;
626*4882a593Smuzhiyun }
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun /**
629*4882a593Smuzhiyun * qbman_swp_enqueue_multiple_direct() - Issue a multi enqueue command
630*4882a593Smuzhiyun * using one enqueue descriptor
631*4882a593Smuzhiyun * @s: the software portal used for enqueue
632*4882a593Smuzhiyun * @d: the enqueue descriptor
633*4882a593Smuzhiyun * @fd: table pointer of frame descriptor table to be enqueued
634*4882a593Smuzhiyun * @flags: table pointer of QBMAN_ENQUEUE_FLAG_DCA flags, not used if NULL
635*4882a593Smuzhiyun * @num_frames: number of fd to be enqueued
636*4882a593Smuzhiyun *
637*4882a593Smuzhiyun * Return the number of fd enqueued, or a negative error number.
638*4882a593Smuzhiyun */
639*4882a593Smuzhiyun static
qbman_swp_enqueue_multiple_direct(struct qbman_swp * s,const struct qbman_eq_desc * d,const struct dpaa2_fd * fd,uint32_t * flags,int num_frames)640*4882a593Smuzhiyun int qbman_swp_enqueue_multiple_direct(struct qbman_swp *s,
641*4882a593Smuzhiyun const struct qbman_eq_desc *d,
642*4882a593Smuzhiyun const struct dpaa2_fd *fd,
643*4882a593Smuzhiyun uint32_t *flags,
644*4882a593Smuzhiyun int num_frames)
645*4882a593Smuzhiyun {
646*4882a593Smuzhiyun uint32_t *p = NULL;
647*4882a593Smuzhiyun const uint32_t *cl = (uint32_t *)d;
648*4882a593Smuzhiyun uint32_t eqcr_ci, eqcr_pi, half_mask, full_mask;
649*4882a593Smuzhiyun int i, num_enqueued = 0;
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun spin_lock(&s->access_spinlock);
652*4882a593Smuzhiyun half_mask = (s->eqcr.pi_ci_mask>>1);
653*4882a593Smuzhiyun full_mask = s->eqcr.pi_ci_mask;
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun if (!s->eqcr.available) {
656*4882a593Smuzhiyun eqcr_ci = s->eqcr.ci;
657*4882a593Smuzhiyun p = s->addr_cena + QBMAN_CENA_SWP_EQCR_CI;
658*4882a593Smuzhiyun s->eqcr.ci = qbman_read_register(s, QBMAN_CINH_SWP_EQCR_CI);
659*4882a593Smuzhiyun s->eqcr.ci &= full_mask;
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun s->eqcr.available = qm_cyc_diff(s->eqcr.pi_ring_size,
662*4882a593Smuzhiyun eqcr_ci, s->eqcr.ci);
663*4882a593Smuzhiyun if (!s->eqcr.available) {
664*4882a593Smuzhiyun spin_unlock(&s->access_spinlock);
665*4882a593Smuzhiyun return 0;
666*4882a593Smuzhiyun }
667*4882a593Smuzhiyun }
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
670*4882a593Smuzhiyun num_enqueued = (s->eqcr.available < num_frames) ?
671*4882a593Smuzhiyun s->eqcr.available : num_frames;
672*4882a593Smuzhiyun s->eqcr.available -= num_enqueued;
673*4882a593Smuzhiyun /* Fill in the EQCR ring */
674*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++) {
675*4882a593Smuzhiyun p = (s->addr_cena + QBMAN_CENA_SWP_EQCR(eqcr_pi & half_mask));
676*4882a593Smuzhiyun /* Skip copying the verb */
677*4882a593Smuzhiyun memcpy(&p[1], &cl[1], EQ_DESC_SIZE_WITHOUT_FD - 1);
678*4882a593Smuzhiyun memcpy(&p[EQ_DESC_SIZE_FD_START/sizeof(uint32_t)],
679*4882a593Smuzhiyun &fd[i], sizeof(*fd));
680*4882a593Smuzhiyun eqcr_pi++;
681*4882a593Smuzhiyun }
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun dma_wmb();
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun /* Set the verb byte, have to substitute in the valid-bit */
686*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
687*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++) {
688*4882a593Smuzhiyun p = (s->addr_cena + QBMAN_CENA_SWP_EQCR(eqcr_pi & half_mask));
689*4882a593Smuzhiyun p[0] = cl[0] | s->eqcr.pi_vb;
690*4882a593Smuzhiyun if (flags && (flags[i] & QBMAN_ENQUEUE_FLAG_DCA)) {
691*4882a593Smuzhiyun struct qbman_eq_desc *d = (struct qbman_eq_desc *)p;
692*4882a593Smuzhiyun
693*4882a593Smuzhiyun d->dca = (1 << QB_ENQUEUE_CMD_DCA_EN_SHIFT) |
694*4882a593Smuzhiyun ((flags[i]) & QBMAN_EQCR_DCA_IDXMASK);
695*4882a593Smuzhiyun }
696*4882a593Smuzhiyun eqcr_pi++;
697*4882a593Smuzhiyun if (!(eqcr_pi & half_mask))
698*4882a593Smuzhiyun s->eqcr.pi_vb ^= QB_VALID_BIT;
699*4882a593Smuzhiyun }
700*4882a593Smuzhiyun
701*4882a593Smuzhiyun /* Flush all the cacheline without load/store in between */
702*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
703*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++)
704*4882a593Smuzhiyun eqcr_pi++;
705*4882a593Smuzhiyun s->eqcr.pi = eqcr_pi & full_mask;
706*4882a593Smuzhiyun spin_unlock(&s->access_spinlock);
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun return num_enqueued;
709*4882a593Smuzhiyun }
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun /**
712*4882a593Smuzhiyun * qbman_swp_enqueue_multiple_mem_back() - Issue a multi enqueue command
713*4882a593Smuzhiyun * using one enqueue descriptor
714*4882a593Smuzhiyun * @s: the software portal used for enqueue
715*4882a593Smuzhiyun * @d: the enqueue descriptor
716*4882a593Smuzhiyun * @fd: table pointer of frame descriptor table to be enqueued
717*4882a593Smuzhiyun * @flags: table pointer of QBMAN_ENQUEUE_FLAG_DCA flags, not used if NULL
718*4882a593Smuzhiyun * @num_frames: number of fd to be enqueued
719*4882a593Smuzhiyun *
720*4882a593Smuzhiyun * Return the number of fd enqueued, or a negative error number.
721*4882a593Smuzhiyun */
722*4882a593Smuzhiyun static
qbman_swp_enqueue_multiple_mem_back(struct qbman_swp * s,const struct qbman_eq_desc * d,const struct dpaa2_fd * fd,uint32_t * flags,int num_frames)723*4882a593Smuzhiyun int qbman_swp_enqueue_multiple_mem_back(struct qbman_swp *s,
724*4882a593Smuzhiyun const struct qbman_eq_desc *d,
725*4882a593Smuzhiyun const struct dpaa2_fd *fd,
726*4882a593Smuzhiyun uint32_t *flags,
727*4882a593Smuzhiyun int num_frames)
728*4882a593Smuzhiyun {
729*4882a593Smuzhiyun uint32_t *p = NULL;
730*4882a593Smuzhiyun const uint32_t *cl = (uint32_t *)(d);
731*4882a593Smuzhiyun uint32_t eqcr_ci, eqcr_pi, half_mask, full_mask;
732*4882a593Smuzhiyun int i, num_enqueued = 0;
733*4882a593Smuzhiyun unsigned long irq_flags;
734*4882a593Smuzhiyun
735*4882a593Smuzhiyun spin_lock_irqsave(&s->access_spinlock, irq_flags);
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun half_mask = (s->eqcr.pi_ci_mask>>1);
738*4882a593Smuzhiyun full_mask = s->eqcr.pi_ci_mask;
739*4882a593Smuzhiyun if (!s->eqcr.available) {
740*4882a593Smuzhiyun eqcr_ci = s->eqcr.ci;
741*4882a593Smuzhiyun p = s->addr_cena + QBMAN_CENA_SWP_EQCR_CI_MEMBACK;
742*4882a593Smuzhiyun s->eqcr.ci = *p & full_mask;
743*4882a593Smuzhiyun s->eqcr.available = qm_cyc_diff(s->eqcr.pi_ring_size,
744*4882a593Smuzhiyun eqcr_ci, s->eqcr.ci);
745*4882a593Smuzhiyun if (!s->eqcr.available) {
746*4882a593Smuzhiyun spin_unlock_irqrestore(&s->access_spinlock, irq_flags);
747*4882a593Smuzhiyun return 0;
748*4882a593Smuzhiyun }
749*4882a593Smuzhiyun }
750*4882a593Smuzhiyun
751*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
752*4882a593Smuzhiyun num_enqueued = (s->eqcr.available < num_frames) ?
753*4882a593Smuzhiyun s->eqcr.available : num_frames;
754*4882a593Smuzhiyun s->eqcr.available -= num_enqueued;
755*4882a593Smuzhiyun /* Fill in the EQCR ring */
756*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++) {
757*4882a593Smuzhiyun p = (s->addr_cena + QBMAN_CENA_SWP_EQCR(eqcr_pi & half_mask));
758*4882a593Smuzhiyun /* Skip copying the verb */
759*4882a593Smuzhiyun memcpy(&p[1], &cl[1], EQ_DESC_SIZE_WITHOUT_FD - 1);
760*4882a593Smuzhiyun memcpy(&p[EQ_DESC_SIZE_FD_START/sizeof(uint32_t)],
761*4882a593Smuzhiyun &fd[i], sizeof(*fd));
762*4882a593Smuzhiyun eqcr_pi++;
763*4882a593Smuzhiyun }
764*4882a593Smuzhiyun
765*4882a593Smuzhiyun /* Set the verb byte, have to substitute in the valid-bit */
766*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
767*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++) {
768*4882a593Smuzhiyun p = (s->addr_cena + QBMAN_CENA_SWP_EQCR(eqcr_pi & half_mask));
769*4882a593Smuzhiyun p[0] = cl[0] | s->eqcr.pi_vb;
770*4882a593Smuzhiyun if (flags && (flags[i] & QBMAN_ENQUEUE_FLAG_DCA)) {
771*4882a593Smuzhiyun struct qbman_eq_desc *d = (struct qbman_eq_desc *)p;
772*4882a593Smuzhiyun
773*4882a593Smuzhiyun d->dca = (1 << QB_ENQUEUE_CMD_DCA_EN_SHIFT) |
774*4882a593Smuzhiyun ((flags[i]) & QBMAN_EQCR_DCA_IDXMASK);
775*4882a593Smuzhiyun }
776*4882a593Smuzhiyun eqcr_pi++;
777*4882a593Smuzhiyun if (!(eqcr_pi & half_mask))
778*4882a593Smuzhiyun s->eqcr.pi_vb ^= QB_VALID_BIT;
779*4882a593Smuzhiyun }
780*4882a593Smuzhiyun s->eqcr.pi = eqcr_pi & full_mask;
781*4882a593Smuzhiyun
782*4882a593Smuzhiyun dma_wmb();
783*4882a593Smuzhiyun qbman_write_register(s, QBMAN_CINH_SWP_EQCR_PI,
784*4882a593Smuzhiyun (QB_RT_BIT)|(s->eqcr.pi)|s->eqcr.pi_vb);
785*4882a593Smuzhiyun spin_unlock_irqrestore(&s->access_spinlock, irq_flags);
786*4882a593Smuzhiyun
787*4882a593Smuzhiyun return num_enqueued;
788*4882a593Smuzhiyun }
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun /**
791*4882a593Smuzhiyun * qbman_swp_enqueue_multiple_desc_direct() - Issue a multi enqueue command
792*4882a593Smuzhiyun * using multiple enqueue descriptor
793*4882a593Smuzhiyun * @s: the software portal used for enqueue
794*4882a593Smuzhiyun * @d: table of minimal enqueue descriptor
795*4882a593Smuzhiyun * @fd: table pointer of frame descriptor table to be enqueued
796*4882a593Smuzhiyun * @num_frames: number of fd to be enqueued
797*4882a593Smuzhiyun *
798*4882a593Smuzhiyun * Return the number of fd enqueued, or a negative error number.
799*4882a593Smuzhiyun */
800*4882a593Smuzhiyun static
qbman_swp_enqueue_multiple_desc_direct(struct qbman_swp * s,const struct qbman_eq_desc * d,const struct dpaa2_fd * fd,int num_frames)801*4882a593Smuzhiyun int qbman_swp_enqueue_multiple_desc_direct(struct qbman_swp *s,
802*4882a593Smuzhiyun const struct qbman_eq_desc *d,
803*4882a593Smuzhiyun const struct dpaa2_fd *fd,
804*4882a593Smuzhiyun int num_frames)
805*4882a593Smuzhiyun {
806*4882a593Smuzhiyun uint32_t *p;
807*4882a593Smuzhiyun const uint32_t *cl;
808*4882a593Smuzhiyun uint32_t eqcr_ci, eqcr_pi, half_mask, full_mask;
809*4882a593Smuzhiyun int i, num_enqueued = 0;
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun half_mask = (s->eqcr.pi_ci_mask>>1);
812*4882a593Smuzhiyun full_mask = s->eqcr.pi_ci_mask;
813*4882a593Smuzhiyun if (!s->eqcr.available) {
814*4882a593Smuzhiyun eqcr_ci = s->eqcr.ci;
815*4882a593Smuzhiyun p = s->addr_cena + QBMAN_CENA_SWP_EQCR_CI;
816*4882a593Smuzhiyun s->eqcr.ci = qbman_read_register(s, QBMAN_CINH_SWP_EQCR_CI);
817*4882a593Smuzhiyun s->eqcr.available = qm_cyc_diff(s->eqcr.pi_ring_size,
818*4882a593Smuzhiyun eqcr_ci, s->eqcr.ci);
819*4882a593Smuzhiyun if (!s->eqcr.available)
820*4882a593Smuzhiyun return 0;
821*4882a593Smuzhiyun }
822*4882a593Smuzhiyun
823*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
824*4882a593Smuzhiyun num_enqueued = (s->eqcr.available < num_frames) ?
825*4882a593Smuzhiyun s->eqcr.available : num_frames;
826*4882a593Smuzhiyun s->eqcr.available -= num_enqueued;
827*4882a593Smuzhiyun /* Fill in the EQCR ring */
828*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++) {
829*4882a593Smuzhiyun p = (s->addr_cena + QBMAN_CENA_SWP_EQCR(eqcr_pi & half_mask));
830*4882a593Smuzhiyun cl = (uint32_t *)(&d[i]);
831*4882a593Smuzhiyun /* Skip copying the verb */
832*4882a593Smuzhiyun memcpy(&p[1], &cl[1], EQ_DESC_SIZE_WITHOUT_FD - 1);
833*4882a593Smuzhiyun memcpy(&p[EQ_DESC_SIZE_FD_START/sizeof(uint32_t)],
834*4882a593Smuzhiyun &fd[i], sizeof(*fd));
835*4882a593Smuzhiyun eqcr_pi++;
836*4882a593Smuzhiyun }
837*4882a593Smuzhiyun
838*4882a593Smuzhiyun dma_wmb();
839*4882a593Smuzhiyun
840*4882a593Smuzhiyun /* Set the verb byte, have to substitute in the valid-bit */
841*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
842*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++) {
843*4882a593Smuzhiyun p = (s->addr_cena + QBMAN_CENA_SWP_EQCR(eqcr_pi & half_mask));
844*4882a593Smuzhiyun cl = (uint32_t *)(&d[i]);
845*4882a593Smuzhiyun p[0] = cl[0] | s->eqcr.pi_vb;
846*4882a593Smuzhiyun eqcr_pi++;
847*4882a593Smuzhiyun if (!(eqcr_pi & half_mask))
848*4882a593Smuzhiyun s->eqcr.pi_vb ^= QB_VALID_BIT;
849*4882a593Smuzhiyun }
850*4882a593Smuzhiyun
851*4882a593Smuzhiyun /* Flush all the cacheline without load/store in between */
852*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
853*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++)
854*4882a593Smuzhiyun eqcr_pi++;
855*4882a593Smuzhiyun s->eqcr.pi = eqcr_pi & full_mask;
856*4882a593Smuzhiyun
857*4882a593Smuzhiyun return num_enqueued;
858*4882a593Smuzhiyun }
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun /**
861*4882a593Smuzhiyun * qbman_swp_enqueue_multiple_desc_mem_back() - Issue a multi enqueue command
862*4882a593Smuzhiyun * using multiple enqueue descriptor
863*4882a593Smuzhiyun * @s: the software portal used for enqueue
864*4882a593Smuzhiyun * @d: table of minimal enqueue descriptor
865*4882a593Smuzhiyun * @fd: table pointer of frame descriptor table to be enqueued
866*4882a593Smuzhiyun * @num_frames: number of fd to be enqueued
867*4882a593Smuzhiyun *
868*4882a593Smuzhiyun * Return the number of fd enqueued, or a negative error number.
869*4882a593Smuzhiyun */
870*4882a593Smuzhiyun static
qbman_swp_enqueue_multiple_desc_mem_back(struct qbman_swp * s,const struct qbman_eq_desc * d,const struct dpaa2_fd * fd,int num_frames)871*4882a593Smuzhiyun int qbman_swp_enqueue_multiple_desc_mem_back(struct qbman_swp *s,
872*4882a593Smuzhiyun const struct qbman_eq_desc *d,
873*4882a593Smuzhiyun const struct dpaa2_fd *fd,
874*4882a593Smuzhiyun int num_frames)
875*4882a593Smuzhiyun {
876*4882a593Smuzhiyun uint32_t *p;
877*4882a593Smuzhiyun const uint32_t *cl;
878*4882a593Smuzhiyun uint32_t eqcr_ci, eqcr_pi, half_mask, full_mask;
879*4882a593Smuzhiyun int i, num_enqueued = 0;
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun half_mask = (s->eqcr.pi_ci_mask>>1);
882*4882a593Smuzhiyun full_mask = s->eqcr.pi_ci_mask;
883*4882a593Smuzhiyun if (!s->eqcr.available) {
884*4882a593Smuzhiyun eqcr_ci = s->eqcr.ci;
885*4882a593Smuzhiyun p = s->addr_cena + QBMAN_CENA_SWP_EQCR_CI_MEMBACK;
886*4882a593Smuzhiyun s->eqcr.ci = *p & full_mask;
887*4882a593Smuzhiyun s->eqcr.available = qm_cyc_diff(s->eqcr.pi_ring_size,
888*4882a593Smuzhiyun eqcr_ci, s->eqcr.ci);
889*4882a593Smuzhiyun if (!s->eqcr.available)
890*4882a593Smuzhiyun return 0;
891*4882a593Smuzhiyun }
892*4882a593Smuzhiyun
893*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
894*4882a593Smuzhiyun num_enqueued = (s->eqcr.available < num_frames) ?
895*4882a593Smuzhiyun s->eqcr.available : num_frames;
896*4882a593Smuzhiyun s->eqcr.available -= num_enqueued;
897*4882a593Smuzhiyun /* Fill in the EQCR ring */
898*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++) {
899*4882a593Smuzhiyun p = (s->addr_cena + QBMAN_CENA_SWP_EQCR(eqcr_pi & half_mask));
900*4882a593Smuzhiyun cl = (uint32_t *)(&d[i]);
901*4882a593Smuzhiyun /* Skip copying the verb */
902*4882a593Smuzhiyun memcpy(&p[1], &cl[1], EQ_DESC_SIZE_WITHOUT_FD - 1);
903*4882a593Smuzhiyun memcpy(&p[EQ_DESC_SIZE_FD_START/sizeof(uint32_t)],
904*4882a593Smuzhiyun &fd[i], sizeof(*fd));
905*4882a593Smuzhiyun eqcr_pi++;
906*4882a593Smuzhiyun }
907*4882a593Smuzhiyun
908*4882a593Smuzhiyun /* Set the verb byte, have to substitute in the valid-bit */
909*4882a593Smuzhiyun eqcr_pi = s->eqcr.pi;
910*4882a593Smuzhiyun for (i = 0; i < num_enqueued; i++) {
911*4882a593Smuzhiyun p = (s->addr_cena + QBMAN_CENA_SWP_EQCR(eqcr_pi & half_mask));
912*4882a593Smuzhiyun cl = (uint32_t *)(&d[i]);
913*4882a593Smuzhiyun p[0] = cl[0] | s->eqcr.pi_vb;
914*4882a593Smuzhiyun eqcr_pi++;
915*4882a593Smuzhiyun if (!(eqcr_pi & half_mask))
916*4882a593Smuzhiyun s->eqcr.pi_vb ^= QB_VALID_BIT;
917*4882a593Smuzhiyun }
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun s->eqcr.pi = eqcr_pi & full_mask;
920*4882a593Smuzhiyun
921*4882a593Smuzhiyun dma_wmb();
922*4882a593Smuzhiyun qbman_write_register(s, QBMAN_CINH_SWP_EQCR_PI,
923*4882a593Smuzhiyun (QB_RT_BIT)|(s->eqcr.pi)|s->eqcr.pi_vb);
924*4882a593Smuzhiyun
925*4882a593Smuzhiyun return num_enqueued;
926*4882a593Smuzhiyun }
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun /* Static (push) dequeue */
929*4882a593Smuzhiyun
930*4882a593Smuzhiyun /**
931*4882a593Smuzhiyun * qbman_swp_push_get() - Get the push dequeue setup
932*4882a593Smuzhiyun * @p: the software portal object
933*4882a593Smuzhiyun * @channel_idx: the channel index to query
934*4882a593Smuzhiyun * @enabled: returned boolean to show whether the push dequeue is enabled
935*4882a593Smuzhiyun * for the given channel
936*4882a593Smuzhiyun */
qbman_swp_push_get(struct qbman_swp * s,u8 channel_idx,int * enabled)937*4882a593Smuzhiyun void qbman_swp_push_get(struct qbman_swp *s, u8 channel_idx, int *enabled)
938*4882a593Smuzhiyun {
939*4882a593Smuzhiyun u16 src = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
940*4882a593Smuzhiyun
941*4882a593Smuzhiyun WARN_ON(channel_idx > 15);
942*4882a593Smuzhiyun *enabled = src | (1 << channel_idx);
943*4882a593Smuzhiyun }
944*4882a593Smuzhiyun
945*4882a593Smuzhiyun /**
946*4882a593Smuzhiyun * qbman_swp_push_set() - Enable or disable push dequeue
947*4882a593Smuzhiyun * @p: the software portal object
948*4882a593Smuzhiyun * @channel_idx: the channel index (0 to 15)
949*4882a593Smuzhiyun * @enable: enable or disable push dequeue
950*4882a593Smuzhiyun */
qbman_swp_push_set(struct qbman_swp * s,u8 channel_idx,int enable)951*4882a593Smuzhiyun void qbman_swp_push_set(struct qbman_swp *s, u8 channel_idx, int enable)
952*4882a593Smuzhiyun {
953*4882a593Smuzhiyun u16 dqsrc;
954*4882a593Smuzhiyun
955*4882a593Smuzhiyun WARN_ON(channel_idx > 15);
956*4882a593Smuzhiyun if (enable)
957*4882a593Smuzhiyun s->sdq |= 1 << channel_idx;
958*4882a593Smuzhiyun else
959*4882a593Smuzhiyun s->sdq &= ~(1 << channel_idx);
960*4882a593Smuzhiyun
961*4882a593Smuzhiyun /* Read make the complete src map. If no channels are enabled
962*4882a593Smuzhiyun * the SDQCR must be 0 or else QMan will assert errors
963*4882a593Smuzhiyun */
964*4882a593Smuzhiyun dqsrc = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
965*4882a593Smuzhiyun if (dqsrc != 0)
966*4882a593Smuzhiyun qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, s->sdq);
967*4882a593Smuzhiyun else
968*4882a593Smuzhiyun qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, 0);
969*4882a593Smuzhiyun }
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun #define QB_VDQCR_VERB_DCT_SHIFT 0
972*4882a593Smuzhiyun #define QB_VDQCR_VERB_DT_SHIFT 2
973*4882a593Smuzhiyun #define QB_VDQCR_VERB_RLS_SHIFT 4
974*4882a593Smuzhiyun #define QB_VDQCR_VERB_WAE_SHIFT 5
975*4882a593Smuzhiyun
976*4882a593Smuzhiyun enum qb_pull_dt_e {
977*4882a593Smuzhiyun qb_pull_dt_channel,
978*4882a593Smuzhiyun qb_pull_dt_workqueue,
979*4882a593Smuzhiyun qb_pull_dt_framequeue
980*4882a593Smuzhiyun };
981*4882a593Smuzhiyun
982*4882a593Smuzhiyun /**
983*4882a593Smuzhiyun * qbman_pull_desc_clear() - Clear the contents of a descriptor to
984*4882a593Smuzhiyun * default/starting state
985*4882a593Smuzhiyun * @d: the pull dequeue descriptor to be cleared
986*4882a593Smuzhiyun */
qbman_pull_desc_clear(struct qbman_pull_desc * d)987*4882a593Smuzhiyun void qbman_pull_desc_clear(struct qbman_pull_desc *d)
988*4882a593Smuzhiyun {
989*4882a593Smuzhiyun memset(d, 0, sizeof(*d));
990*4882a593Smuzhiyun }
991*4882a593Smuzhiyun
992*4882a593Smuzhiyun /**
993*4882a593Smuzhiyun * qbman_pull_desc_set_storage()- Set the pull dequeue storage
994*4882a593Smuzhiyun * @d: the pull dequeue descriptor to be set
995*4882a593Smuzhiyun * @storage: the pointer of the memory to store the dequeue result
996*4882a593Smuzhiyun * @storage_phys: the physical address of the storage memory
997*4882a593Smuzhiyun * @stash: to indicate whether write allocate is enabled
998*4882a593Smuzhiyun *
999*4882a593Smuzhiyun * If not called, or if called with 'storage' as NULL, the result pull dequeues
1000*4882a593Smuzhiyun * will produce results to DQRR. If 'storage' is non-NULL, then results are
1001*4882a593Smuzhiyun * produced to the given memory location (using the DMA address which
1002*4882a593Smuzhiyun * the caller provides in 'storage_phys'), and 'stash' controls whether or not
1003*4882a593Smuzhiyun * those writes to main-memory express a cache-warming attribute.
1004*4882a593Smuzhiyun */
qbman_pull_desc_set_storage(struct qbman_pull_desc * d,struct dpaa2_dq * storage,dma_addr_t storage_phys,int stash)1005*4882a593Smuzhiyun void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
1006*4882a593Smuzhiyun struct dpaa2_dq *storage,
1007*4882a593Smuzhiyun dma_addr_t storage_phys,
1008*4882a593Smuzhiyun int stash)
1009*4882a593Smuzhiyun {
1010*4882a593Smuzhiyun /* save the virtual address */
1011*4882a593Smuzhiyun d->rsp_addr_virt = (u64)(uintptr_t)storage;
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun if (!storage) {
1014*4882a593Smuzhiyun d->verb &= ~(1 << QB_VDQCR_VERB_RLS_SHIFT);
1015*4882a593Smuzhiyun return;
1016*4882a593Smuzhiyun }
1017*4882a593Smuzhiyun d->verb |= 1 << QB_VDQCR_VERB_RLS_SHIFT;
1018*4882a593Smuzhiyun if (stash)
1019*4882a593Smuzhiyun d->verb |= 1 << QB_VDQCR_VERB_WAE_SHIFT;
1020*4882a593Smuzhiyun else
1021*4882a593Smuzhiyun d->verb &= ~(1 << QB_VDQCR_VERB_WAE_SHIFT);
1022*4882a593Smuzhiyun
1023*4882a593Smuzhiyun d->rsp_addr = cpu_to_le64(storage_phys);
1024*4882a593Smuzhiyun }
1025*4882a593Smuzhiyun
1026*4882a593Smuzhiyun /**
1027*4882a593Smuzhiyun * qbman_pull_desc_set_numframes() - Set the number of frames to be dequeued
1028*4882a593Smuzhiyun * @d: the pull dequeue descriptor to be set
1029*4882a593Smuzhiyun * @numframes: number of frames to be set, must be between 1 and 16, inclusive
1030*4882a593Smuzhiyun */
qbman_pull_desc_set_numframes(struct qbman_pull_desc * d,u8 numframes)1031*4882a593Smuzhiyun void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes)
1032*4882a593Smuzhiyun {
1033*4882a593Smuzhiyun d->numf = numframes - 1;
1034*4882a593Smuzhiyun }
1035*4882a593Smuzhiyun
1036*4882a593Smuzhiyun /*
1037*4882a593Smuzhiyun * Exactly one of the following descriptor "actions" should be set. (Calling any
1038*4882a593Smuzhiyun * one of these will replace the effect of any prior call to one of these.)
1039*4882a593Smuzhiyun * - pull dequeue from the given frame queue (FQ)
1040*4882a593Smuzhiyun * - pull dequeue from any FQ in the given work queue (WQ)
1041*4882a593Smuzhiyun * - pull dequeue from any FQ in any WQ in the given channel
1042*4882a593Smuzhiyun */
1043*4882a593Smuzhiyun
1044*4882a593Smuzhiyun /**
1045*4882a593Smuzhiyun * qbman_pull_desc_set_fq() - Set fqid from which the dequeue command dequeues
1046*4882a593Smuzhiyun * @fqid: the frame queue index of the given FQ
1047*4882a593Smuzhiyun */
qbman_pull_desc_set_fq(struct qbman_pull_desc * d,u32 fqid)1048*4882a593Smuzhiyun void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid)
1049*4882a593Smuzhiyun {
1050*4882a593Smuzhiyun d->verb |= 1 << QB_VDQCR_VERB_DCT_SHIFT;
1051*4882a593Smuzhiyun d->verb |= qb_pull_dt_framequeue << QB_VDQCR_VERB_DT_SHIFT;
1052*4882a593Smuzhiyun d->dq_src = cpu_to_le32(fqid);
1053*4882a593Smuzhiyun }
1054*4882a593Smuzhiyun
1055*4882a593Smuzhiyun /**
1056*4882a593Smuzhiyun * qbman_pull_desc_set_wq() - Set wqid from which the dequeue command dequeues
1057*4882a593Smuzhiyun * @wqid: composed of channel id and wqid within the channel
1058*4882a593Smuzhiyun * @dct: the dequeue command type
1059*4882a593Smuzhiyun */
qbman_pull_desc_set_wq(struct qbman_pull_desc * d,u32 wqid,enum qbman_pull_type_e dct)1060*4882a593Smuzhiyun void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
1061*4882a593Smuzhiyun enum qbman_pull_type_e dct)
1062*4882a593Smuzhiyun {
1063*4882a593Smuzhiyun d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
1064*4882a593Smuzhiyun d->verb |= qb_pull_dt_workqueue << QB_VDQCR_VERB_DT_SHIFT;
1065*4882a593Smuzhiyun d->dq_src = cpu_to_le32(wqid);
1066*4882a593Smuzhiyun }
1067*4882a593Smuzhiyun
1068*4882a593Smuzhiyun /**
1069*4882a593Smuzhiyun * qbman_pull_desc_set_channel() - Set channelid from which the dequeue command
1070*4882a593Smuzhiyun * dequeues
1071*4882a593Smuzhiyun * @chid: the channel id to be dequeued
1072*4882a593Smuzhiyun * @dct: the dequeue command type
1073*4882a593Smuzhiyun */
qbman_pull_desc_set_channel(struct qbman_pull_desc * d,u32 chid,enum qbman_pull_type_e dct)1074*4882a593Smuzhiyun void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
1075*4882a593Smuzhiyun enum qbman_pull_type_e dct)
1076*4882a593Smuzhiyun {
1077*4882a593Smuzhiyun d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
1078*4882a593Smuzhiyun d->verb |= qb_pull_dt_channel << QB_VDQCR_VERB_DT_SHIFT;
1079*4882a593Smuzhiyun d->dq_src = cpu_to_le32(chid);
1080*4882a593Smuzhiyun }
1081*4882a593Smuzhiyun
1082*4882a593Smuzhiyun /**
1083*4882a593Smuzhiyun * qbman_swp_pull_direct() - Issue the pull dequeue command
1084*4882a593Smuzhiyun * @s: the software portal object
1085*4882a593Smuzhiyun * @d: the software portal descriptor which has been configured with
1086*4882a593Smuzhiyun * the set of qbman_pull_desc_set_*() calls
1087*4882a593Smuzhiyun *
1088*4882a593Smuzhiyun * Return 0 for success, and -EBUSY if the software portal is not ready
1089*4882a593Smuzhiyun * to do pull dequeue.
1090*4882a593Smuzhiyun */
1091*4882a593Smuzhiyun static
qbman_swp_pull_direct(struct qbman_swp * s,struct qbman_pull_desc * d)1092*4882a593Smuzhiyun int qbman_swp_pull_direct(struct qbman_swp *s, struct qbman_pull_desc *d)
1093*4882a593Smuzhiyun {
1094*4882a593Smuzhiyun struct qbman_pull_desc *p;
1095*4882a593Smuzhiyun
1096*4882a593Smuzhiyun if (!atomic_dec_and_test(&s->vdq.available)) {
1097*4882a593Smuzhiyun atomic_inc(&s->vdq.available);
1098*4882a593Smuzhiyun return -EBUSY;
1099*4882a593Smuzhiyun }
1100*4882a593Smuzhiyun s->vdq.storage = (void *)(uintptr_t)d->rsp_addr_virt;
1101*4882a593Smuzhiyun if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
1102*4882a593Smuzhiyun p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR);
1103*4882a593Smuzhiyun else
1104*4882a593Smuzhiyun p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR_MEM);
1105*4882a593Smuzhiyun p->numf = d->numf;
1106*4882a593Smuzhiyun p->tok = QMAN_DQ_TOKEN_VALID;
1107*4882a593Smuzhiyun p->dq_src = d->dq_src;
1108*4882a593Smuzhiyun p->rsp_addr = d->rsp_addr;
1109*4882a593Smuzhiyun p->rsp_addr_virt = d->rsp_addr_virt;
1110*4882a593Smuzhiyun dma_wmb();
1111*4882a593Smuzhiyun /* Set the verb byte, have to substitute in the valid-bit */
1112*4882a593Smuzhiyun p->verb = d->verb | s->vdq.valid_bit;
1113*4882a593Smuzhiyun s->vdq.valid_bit ^= QB_VALID_BIT;
1114*4882a593Smuzhiyun
1115*4882a593Smuzhiyun return 0;
1116*4882a593Smuzhiyun }
1117*4882a593Smuzhiyun
1118*4882a593Smuzhiyun /**
1119*4882a593Smuzhiyun * qbman_swp_pull_mem_back() - Issue the pull dequeue command
1120*4882a593Smuzhiyun * @s: the software portal object
1121*4882a593Smuzhiyun * @d: the software portal descriptor which has been configured with
1122*4882a593Smuzhiyun * the set of qbman_pull_desc_set_*() calls
1123*4882a593Smuzhiyun *
1124*4882a593Smuzhiyun * Return 0 for success, and -EBUSY if the software portal is not ready
1125*4882a593Smuzhiyun * to do pull dequeue.
1126*4882a593Smuzhiyun */
1127*4882a593Smuzhiyun static
qbman_swp_pull_mem_back(struct qbman_swp * s,struct qbman_pull_desc * d)1128*4882a593Smuzhiyun int qbman_swp_pull_mem_back(struct qbman_swp *s, struct qbman_pull_desc *d)
1129*4882a593Smuzhiyun {
1130*4882a593Smuzhiyun struct qbman_pull_desc *p;
1131*4882a593Smuzhiyun
1132*4882a593Smuzhiyun if (!atomic_dec_and_test(&s->vdq.available)) {
1133*4882a593Smuzhiyun atomic_inc(&s->vdq.available);
1134*4882a593Smuzhiyun return -EBUSY;
1135*4882a593Smuzhiyun }
1136*4882a593Smuzhiyun s->vdq.storage = (void *)(uintptr_t)d->rsp_addr_virt;
1137*4882a593Smuzhiyun if ((s->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_5000)
1138*4882a593Smuzhiyun p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR);
1139*4882a593Smuzhiyun else
1140*4882a593Smuzhiyun p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR_MEM);
1141*4882a593Smuzhiyun p->numf = d->numf;
1142*4882a593Smuzhiyun p->tok = QMAN_DQ_TOKEN_VALID;
1143*4882a593Smuzhiyun p->dq_src = d->dq_src;
1144*4882a593Smuzhiyun p->rsp_addr = d->rsp_addr;
1145*4882a593Smuzhiyun p->rsp_addr_virt = d->rsp_addr_virt;
1146*4882a593Smuzhiyun
1147*4882a593Smuzhiyun /* Set the verb byte, have to substitute in the valid-bit */
1148*4882a593Smuzhiyun p->verb = d->verb | s->vdq.valid_bit;
1149*4882a593Smuzhiyun s->vdq.valid_bit ^= QB_VALID_BIT;
1150*4882a593Smuzhiyun dma_wmb();
1151*4882a593Smuzhiyun qbman_write_register(s, QBMAN_CINH_SWP_VDQCR_RT, QMAN_RT_MODE);
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun return 0;
1154*4882a593Smuzhiyun }
1155*4882a593Smuzhiyun
1156*4882a593Smuzhiyun #define QMAN_DQRR_PI_MASK 0xf
1157*4882a593Smuzhiyun
1158*4882a593Smuzhiyun /**
1159*4882a593Smuzhiyun * qbman_swp_dqrr_next_direct() - Get an valid DQRR entry
1160*4882a593Smuzhiyun * @s: the software portal object
1161*4882a593Smuzhiyun *
1162*4882a593Smuzhiyun * Return NULL if there are no unconsumed DQRR entries. Return a DQRR entry
1163*4882a593Smuzhiyun * only once, so repeated calls can return a sequence of DQRR entries, without
1164*4882a593Smuzhiyun * requiring they be consumed immediately or in any particular order.
1165*4882a593Smuzhiyun */
qbman_swp_dqrr_next_direct(struct qbman_swp * s)1166*4882a593Smuzhiyun const struct dpaa2_dq *qbman_swp_dqrr_next_direct(struct qbman_swp *s)
1167*4882a593Smuzhiyun {
1168*4882a593Smuzhiyun u32 verb;
1169*4882a593Smuzhiyun u32 response_verb;
1170*4882a593Smuzhiyun u32 flags;
1171*4882a593Smuzhiyun struct dpaa2_dq *p;
1172*4882a593Smuzhiyun
1173*4882a593Smuzhiyun /* Before using valid-bit to detect if something is there, we have to
1174*4882a593Smuzhiyun * handle the case of the DQRR reset bug...
1175*4882a593Smuzhiyun */
1176*4882a593Smuzhiyun if (unlikely(s->dqrr.reset_bug)) {
1177*4882a593Smuzhiyun /*
1178*4882a593Smuzhiyun * We pick up new entries by cache-inhibited producer index,
1179*4882a593Smuzhiyun * which means that a non-coherent mapping would require us to
1180*4882a593Smuzhiyun * invalidate and read *only* once that PI has indicated that
1181*4882a593Smuzhiyun * there's an entry here. The first trip around the DQRR ring
1182*4882a593Smuzhiyun * will be much less efficient than all subsequent trips around
1183*4882a593Smuzhiyun * it...
1184*4882a593Smuzhiyun */
1185*4882a593Smuzhiyun u8 pi = qbman_read_register(s, QBMAN_CINH_SWP_DQPI) &
1186*4882a593Smuzhiyun QMAN_DQRR_PI_MASK;
1187*4882a593Smuzhiyun
1188*4882a593Smuzhiyun /* there are new entries if pi != next_idx */
1189*4882a593Smuzhiyun if (pi == s->dqrr.next_idx)
1190*4882a593Smuzhiyun return NULL;
1191*4882a593Smuzhiyun
1192*4882a593Smuzhiyun /*
1193*4882a593Smuzhiyun * if next_idx is/was the last ring index, and 'pi' is
1194*4882a593Smuzhiyun * different, we can disable the workaround as all the ring
1195*4882a593Smuzhiyun * entries have now been DMA'd to so valid-bit checking is
1196*4882a593Smuzhiyun * repaired. Note: this logic needs to be based on next_idx
1197*4882a593Smuzhiyun * (which increments one at a time), rather than on pi (which
1198*4882a593Smuzhiyun * can burst and wrap-around between our snapshots of it).
1199*4882a593Smuzhiyun */
1200*4882a593Smuzhiyun if (s->dqrr.next_idx == (s->dqrr.dqrr_size - 1)) {
1201*4882a593Smuzhiyun pr_debug("next_idx=%d, pi=%d, clear reset bug\n",
1202*4882a593Smuzhiyun s->dqrr.next_idx, pi);
1203*4882a593Smuzhiyun s->dqrr.reset_bug = 0;
1204*4882a593Smuzhiyun }
1205*4882a593Smuzhiyun prefetch(qbman_get_cmd(s,
1206*4882a593Smuzhiyun QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
1207*4882a593Smuzhiyun }
1208*4882a593Smuzhiyun
1209*4882a593Smuzhiyun p = qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
1210*4882a593Smuzhiyun verb = p->dq.verb;
1211*4882a593Smuzhiyun
1212*4882a593Smuzhiyun /*
1213*4882a593Smuzhiyun * If the valid-bit isn't of the expected polarity, nothing there. Note,
1214*4882a593Smuzhiyun * in the DQRR reset bug workaround, we shouldn't need to skip these
1215*4882a593Smuzhiyun * check, because we've already determined that a new entry is available
1216*4882a593Smuzhiyun * and we've invalidated the cacheline before reading it, so the
1217*4882a593Smuzhiyun * valid-bit behaviour is repaired and should tell us what we already
1218*4882a593Smuzhiyun * knew from reading PI.
1219*4882a593Smuzhiyun */
1220*4882a593Smuzhiyun if ((verb & QB_VALID_BIT) != s->dqrr.valid_bit) {
1221*4882a593Smuzhiyun prefetch(qbman_get_cmd(s,
1222*4882a593Smuzhiyun QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
1223*4882a593Smuzhiyun return NULL;
1224*4882a593Smuzhiyun }
1225*4882a593Smuzhiyun /*
1226*4882a593Smuzhiyun * There's something there. Move "next_idx" attention to the next ring
1227*4882a593Smuzhiyun * entry (and prefetch it) before returning what we found.
1228*4882a593Smuzhiyun */
1229*4882a593Smuzhiyun s->dqrr.next_idx++;
1230*4882a593Smuzhiyun s->dqrr.next_idx &= s->dqrr.dqrr_size - 1; /* Wrap around */
1231*4882a593Smuzhiyun if (!s->dqrr.next_idx)
1232*4882a593Smuzhiyun s->dqrr.valid_bit ^= QB_VALID_BIT;
1233*4882a593Smuzhiyun
1234*4882a593Smuzhiyun /*
1235*4882a593Smuzhiyun * If this is the final response to a volatile dequeue command
1236*4882a593Smuzhiyun * indicate that the vdq is available
1237*4882a593Smuzhiyun */
1238*4882a593Smuzhiyun flags = p->dq.stat;
1239*4882a593Smuzhiyun response_verb = verb & QBMAN_RESULT_MASK;
1240*4882a593Smuzhiyun if ((response_verb == QBMAN_RESULT_DQ) &&
1241*4882a593Smuzhiyun (flags & DPAA2_DQ_STAT_VOLATILE) &&
1242*4882a593Smuzhiyun (flags & DPAA2_DQ_STAT_EXPIRED))
1243*4882a593Smuzhiyun atomic_inc(&s->vdq.available);
1244*4882a593Smuzhiyun
1245*4882a593Smuzhiyun prefetch(qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
1246*4882a593Smuzhiyun
1247*4882a593Smuzhiyun return p;
1248*4882a593Smuzhiyun }
1249*4882a593Smuzhiyun
1250*4882a593Smuzhiyun /**
1251*4882a593Smuzhiyun * qbman_swp_dqrr_next_mem_back() - Get an valid DQRR entry
1252*4882a593Smuzhiyun * @s: the software portal object
1253*4882a593Smuzhiyun *
1254*4882a593Smuzhiyun * Return NULL if there are no unconsumed DQRR entries. Return a DQRR entry
1255*4882a593Smuzhiyun * only once, so repeated calls can return a sequence of DQRR entries, without
1256*4882a593Smuzhiyun * requiring they be consumed immediately or in any particular order.
1257*4882a593Smuzhiyun */
qbman_swp_dqrr_next_mem_back(struct qbman_swp * s)1258*4882a593Smuzhiyun const struct dpaa2_dq *qbman_swp_dqrr_next_mem_back(struct qbman_swp *s)
1259*4882a593Smuzhiyun {
1260*4882a593Smuzhiyun u32 verb;
1261*4882a593Smuzhiyun u32 response_verb;
1262*4882a593Smuzhiyun u32 flags;
1263*4882a593Smuzhiyun struct dpaa2_dq *p;
1264*4882a593Smuzhiyun
1265*4882a593Smuzhiyun /* Before using valid-bit to detect if something is there, we have to
1266*4882a593Smuzhiyun * handle the case of the DQRR reset bug...
1267*4882a593Smuzhiyun */
1268*4882a593Smuzhiyun if (unlikely(s->dqrr.reset_bug)) {
1269*4882a593Smuzhiyun /*
1270*4882a593Smuzhiyun * We pick up new entries by cache-inhibited producer index,
1271*4882a593Smuzhiyun * which means that a non-coherent mapping would require us to
1272*4882a593Smuzhiyun * invalidate and read *only* once that PI has indicated that
1273*4882a593Smuzhiyun * there's an entry here. The first trip around the DQRR ring
1274*4882a593Smuzhiyun * will be much less efficient than all subsequent trips around
1275*4882a593Smuzhiyun * it...
1276*4882a593Smuzhiyun */
1277*4882a593Smuzhiyun u8 pi = qbman_read_register(s, QBMAN_CINH_SWP_DQPI) &
1278*4882a593Smuzhiyun QMAN_DQRR_PI_MASK;
1279*4882a593Smuzhiyun
1280*4882a593Smuzhiyun /* there are new entries if pi != next_idx */
1281*4882a593Smuzhiyun if (pi == s->dqrr.next_idx)
1282*4882a593Smuzhiyun return NULL;
1283*4882a593Smuzhiyun
1284*4882a593Smuzhiyun /*
1285*4882a593Smuzhiyun * if next_idx is/was the last ring index, and 'pi' is
1286*4882a593Smuzhiyun * different, we can disable the workaround as all the ring
1287*4882a593Smuzhiyun * entries have now been DMA'd to so valid-bit checking is
1288*4882a593Smuzhiyun * repaired. Note: this logic needs to be based on next_idx
1289*4882a593Smuzhiyun * (which increments one at a time), rather than on pi (which
1290*4882a593Smuzhiyun * can burst and wrap-around between our snapshots of it).
1291*4882a593Smuzhiyun */
1292*4882a593Smuzhiyun if (s->dqrr.next_idx == (s->dqrr.dqrr_size - 1)) {
1293*4882a593Smuzhiyun pr_debug("next_idx=%d, pi=%d, clear reset bug\n",
1294*4882a593Smuzhiyun s->dqrr.next_idx, pi);
1295*4882a593Smuzhiyun s->dqrr.reset_bug = 0;
1296*4882a593Smuzhiyun }
1297*4882a593Smuzhiyun prefetch(qbman_get_cmd(s,
1298*4882a593Smuzhiyun QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
1299*4882a593Smuzhiyun }
1300*4882a593Smuzhiyun
1301*4882a593Smuzhiyun p = qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR_MEM(s->dqrr.next_idx));
1302*4882a593Smuzhiyun verb = p->dq.verb;
1303*4882a593Smuzhiyun
1304*4882a593Smuzhiyun /*
1305*4882a593Smuzhiyun * If the valid-bit isn't of the expected polarity, nothing there. Note,
1306*4882a593Smuzhiyun * in the DQRR reset bug workaround, we shouldn't need to skip these
1307*4882a593Smuzhiyun * check, because we've already determined that a new entry is available
1308*4882a593Smuzhiyun * and we've invalidated the cacheline before reading it, so the
1309*4882a593Smuzhiyun * valid-bit behaviour is repaired and should tell us what we already
1310*4882a593Smuzhiyun * knew from reading PI.
1311*4882a593Smuzhiyun */
1312*4882a593Smuzhiyun if ((verb & QB_VALID_BIT) != s->dqrr.valid_bit) {
1313*4882a593Smuzhiyun prefetch(qbman_get_cmd(s,
1314*4882a593Smuzhiyun QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
1315*4882a593Smuzhiyun return NULL;
1316*4882a593Smuzhiyun }
1317*4882a593Smuzhiyun /*
1318*4882a593Smuzhiyun * There's something there. Move "next_idx" attention to the next ring
1319*4882a593Smuzhiyun * entry (and prefetch it) before returning what we found.
1320*4882a593Smuzhiyun */
1321*4882a593Smuzhiyun s->dqrr.next_idx++;
1322*4882a593Smuzhiyun s->dqrr.next_idx &= s->dqrr.dqrr_size - 1; /* Wrap around */
1323*4882a593Smuzhiyun if (!s->dqrr.next_idx)
1324*4882a593Smuzhiyun s->dqrr.valid_bit ^= QB_VALID_BIT;
1325*4882a593Smuzhiyun
1326*4882a593Smuzhiyun /*
1327*4882a593Smuzhiyun * If this is the final response to a volatile dequeue command
1328*4882a593Smuzhiyun * indicate that the vdq is available
1329*4882a593Smuzhiyun */
1330*4882a593Smuzhiyun flags = p->dq.stat;
1331*4882a593Smuzhiyun response_verb = verb & QBMAN_RESULT_MASK;
1332*4882a593Smuzhiyun if ((response_verb == QBMAN_RESULT_DQ) &&
1333*4882a593Smuzhiyun (flags & DPAA2_DQ_STAT_VOLATILE) &&
1334*4882a593Smuzhiyun (flags & DPAA2_DQ_STAT_EXPIRED))
1335*4882a593Smuzhiyun atomic_inc(&s->vdq.available);
1336*4882a593Smuzhiyun
1337*4882a593Smuzhiyun prefetch(qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx)));
1338*4882a593Smuzhiyun
1339*4882a593Smuzhiyun return p;
1340*4882a593Smuzhiyun }
1341*4882a593Smuzhiyun
1342*4882a593Smuzhiyun /**
1343*4882a593Smuzhiyun * qbman_swp_dqrr_consume() - Consume DQRR entries previously returned from
1344*4882a593Smuzhiyun * qbman_swp_dqrr_next().
1345*4882a593Smuzhiyun * @s: the software portal object
1346*4882a593Smuzhiyun * @dq: the DQRR entry to be consumed
1347*4882a593Smuzhiyun */
qbman_swp_dqrr_consume(struct qbman_swp * s,const struct dpaa2_dq * dq)1348*4882a593Smuzhiyun void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq)
1349*4882a593Smuzhiyun {
1350*4882a593Smuzhiyun qbman_write_register(s, QBMAN_CINH_SWP_DCAP, QBMAN_IDX_FROM_DQRR(dq));
1351*4882a593Smuzhiyun }
1352*4882a593Smuzhiyun
1353*4882a593Smuzhiyun /**
1354*4882a593Smuzhiyun * qbman_result_has_new_result() - Check and get the dequeue response from the
1355*4882a593Smuzhiyun * dq storage memory set in pull dequeue command
1356*4882a593Smuzhiyun * @s: the software portal object
1357*4882a593Smuzhiyun * @dq: the dequeue result read from the memory
1358*4882a593Smuzhiyun *
1359*4882a593Smuzhiyun * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
1360*4882a593Smuzhiyun * dequeue result.
1361*4882a593Smuzhiyun *
1362*4882a593Smuzhiyun * Only used for user-provided storage of dequeue results, not DQRR. For
1363*4882a593Smuzhiyun * efficiency purposes, the driver will perform any required endianness
1364*4882a593Smuzhiyun * conversion to ensure that the user's dequeue result storage is in host-endian
1365*4882a593Smuzhiyun * format. As such, once the user has called qbman_result_has_new_result() and
1366*4882a593Smuzhiyun * been returned a valid dequeue result, they should not call it again on
1367*4882a593Smuzhiyun * the same memory location (except of course if another dequeue command has
1368*4882a593Smuzhiyun * been executed to produce a new result to that location).
1369*4882a593Smuzhiyun */
qbman_result_has_new_result(struct qbman_swp * s,const struct dpaa2_dq * dq)1370*4882a593Smuzhiyun int qbman_result_has_new_result(struct qbman_swp *s, const struct dpaa2_dq *dq)
1371*4882a593Smuzhiyun {
1372*4882a593Smuzhiyun if (dq->dq.tok != QMAN_DQ_TOKEN_VALID)
1373*4882a593Smuzhiyun return 0;
1374*4882a593Smuzhiyun
1375*4882a593Smuzhiyun /*
1376*4882a593Smuzhiyun * Set token to be 0 so we will detect change back to 1
1377*4882a593Smuzhiyun * next time the looping is traversed. Const is cast away here
1378*4882a593Smuzhiyun * as we want users to treat the dequeue responses as read only.
1379*4882a593Smuzhiyun */
1380*4882a593Smuzhiyun ((struct dpaa2_dq *)dq)->dq.tok = 0;
1381*4882a593Smuzhiyun
1382*4882a593Smuzhiyun /*
1383*4882a593Smuzhiyun * Determine whether VDQCR is available based on whether the
1384*4882a593Smuzhiyun * current result is sitting in the first storage location of
1385*4882a593Smuzhiyun * the busy command.
1386*4882a593Smuzhiyun */
1387*4882a593Smuzhiyun if (s->vdq.storage == dq) {
1388*4882a593Smuzhiyun s->vdq.storage = NULL;
1389*4882a593Smuzhiyun atomic_inc(&s->vdq.available);
1390*4882a593Smuzhiyun }
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun return 1;
1393*4882a593Smuzhiyun }
1394*4882a593Smuzhiyun
1395*4882a593Smuzhiyun /**
1396*4882a593Smuzhiyun * qbman_release_desc_clear() - Clear the contents of a descriptor to
1397*4882a593Smuzhiyun * default/starting state.
1398*4882a593Smuzhiyun */
qbman_release_desc_clear(struct qbman_release_desc * d)1399*4882a593Smuzhiyun void qbman_release_desc_clear(struct qbman_release_desc *d)
1400*4882a593Smuzhiyun {
1401*4882a593Smuzhiyun memset(d, 0, sizeof(*d));
1402*4882a593Smuzhiyun d->verb = 1 << 5; /* Release Command Valid */
1403*4882a593Smuzhiyun }
1404*4882a593Smuzhiyun
1405*4882a593Smuzhiyun /**
1406*4882a593Smuzhiyun * qbman_release_desc_set_bpid() - Set the ID of the buffer pool to release to
1407*4882a593Smuzhiyun */
qbman_release_desc_set_bpid(struct qbman_release_desc * d,u16 bpid)1408*4882a593Smuzhiyun void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid)
1409*4882a593Smuzhiyun {
1410*4882a593Smuzhiyun d->bpid = cpu_to_le16(bpid);
1411*4882a593Smuzhiyun }
1412*4882a593Smuzhiyun
1413*4882a593Smuzhiyun /**
1414*4882a593Smuzhiyun * qbman_release_desc_set_rcdi() - Determines whether or not the portal's RCDI
1415*4882a593Smuzhiyun * interrupt source should be asserted after the release command is completed.
1416*4882a593Smuzhiyun */
qbman_release_desc_set_rcdi(struct qbman_release_desc * d,int enable)1417*4882a593Smuzhiyun void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable)
1418*4882a593Smuzhiyun {
1419*4882a593Smuzhiyun if (enable)
1420*4882a593Smuzhiyun d->verb |= 1 << 6;
1421*4882a593Smuzhiyun else
1422*4882a593Smuzhiyun d->verb &= ~(1 << 6);
1423*4882a593Smuzhiyun }
1424*4882a593Smuzhiyun
1425*4882a593Smuzhiyun #define RAR_IDX(rar) ((rar) & 0x7)
1426*4882a593Smuzhiyun #define RAR_VB(rar) ((rar) & 0x80)
1427*4882a593Smuzhiyun #define RAR_SUCCESS(rar) ((rar) & 0x100)
1428*4882a593Smuzhiyun
1429*4882a593Smuzhiyun /**
1430*4882a593Smuzhiyun * qbman_swp_release_direct() - Issue a buffer release command
1431*4882a593Smuzhiyun * @s: the software portal object
1432*4882a593Smuzhiyun * @d: the release descriptor
1433*4882a593Smuzhiyun * @buffers: a pointer pointing to the buffer address to be released
1434*4882a593Smuzhiyun * @num_buffers: number of buffers to be released, must be less than 8
1435*4882a593Smuzhiyun *
1436*4882a593Smuzhiyun * Return 0 for success, -EBUSY if the release command ring is not ready.
1437*4882a593Smuzhiyun */
qbman_swp_release_direct(struct qbman_swp * s,const struct qbman_release_desc * d,const u64 * buffers,unsigned int num_buffers)1438*4882a593Smuzhiyun int qbman_swp_release_direct(struct qbman_swp *s,
1439*4882a593Smuzhiyun const struct qbman_release_desc *d,
1440*4882a593Smuzhiyun const u64 *buffers, unsigned int num_buffers)
1441*4882a593Smuzhiyun {
1442*4882a593Smuzhiyun int i;
1443*4882a593Smuzhiyun struct qbman_release_desc *p;
1444*4882a593Smuzhiyun u32 rar;
1445*4882a593Smuzhiyun
1446*4882a593Smuzhiyun if (!num_buffers || (num_buffers > 7))
1447*4882a593Smuzhiyun return -EINVAL;
1448*4882a593Smuzhiyun
1449*4882a593Smuzhiyun rar = qbman_read_register(s, QBMAN_CINH_SWP_RAR);
1450*4882a593Smuzhiyun if (!RAR_SUCCESS(rar))
1451*4882a593Smuzhiyun return -EBUSY;
1452*4882a593Smuzhiyun
1453*4882a593Smuzhiyun /* Start the release command */
1454*4882a593Smuzhiyun p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR(RAR_IDX(rar)));
1455*4882a593Smuzhiyun
1456*4882a593Smuzhiyun /* Copy the caller's buffer pointers to the command */
1457*4882a593Smuzhiyun for (i = 0; i < num_buffers; i++)
1458*4882a593Smuzhiyun p->buf[i] = cpu_to_le64(buffers[i]);
1459*4882a593Smuzhiyun p->bpid = d->bpid;
1460*4882a593Smuzhiyun
1461*4882a593Smuzhiyun /*
1462*4882a593Smuzhiyun * Set the verb byte, have to substitute in the valid-bit
1463*4882a593Smuzhiyun * and the number of buffers.
1464*4882a593Smuzhiyun */
1465*4882a593Smuzhiyun dma_wmb();
1466*4882a593Smuzhiyun p->verb = d->verb | RAR_VB(rar) | num_buffers;
1467*4882a593Smuzhiyun
1468*4882a593Smuzhiyun return 0;
1469*4882a593Smuzhiyun }
1470*4882a593Smuzhiyun
1471*4882a593Smuzhiyun /**
1472*4882a593Smuzhiyun * qbman_swp_release_mem_back() - Issue a buffer release command
1473*4882a593Smuzhiyun * @s: the software portal object
1474*4882a593Smuzhiyun * @d: the release descriptor
1475*4882a593Smuzhiyun * @buffers: a pointer pointing to the buffer address to be released
1476*4882a593Smuzhiyun * @num_buffers: number of buffers to be released, must be less than 8
1477*4882a593Smuzhiyun *
1478*4882a593Smuzhiyun * Return 0 for success, -EBUSY if the release command ring is not ready.
1479*4882a593Smuzhiyun */
qbman_swp_release_mem_back(struct qbman_swp * s,const struct qbman_release_desc * d,const u64 * buffers,unsigned int num_buffers)1480*4882a593Smuzhiyun int qbman_swp_release_mem_back(struct qbman_swp *s,
1481*4882a593Smuzhiyun const struct qbman_release_desc *d,
1482*4882a593Smuzhiyun const u64 *buffers, unsigned int num_buffers)
1483*4882a593Smuzhiyun {
1484*4882a593Smuzhiyun int i;
1485*4882a593Smuzhiyun struct qbman_release_desc *p;
1486*4882a593Smuzhiyun u32 rar;
1487*4882a593Smuzhiyun
1488*4882a593Smuzhiyun if (!num_buffers || (num_buffers > 7))
1489*4882a593Smuzhiyun return -EINVAL;
1490*4882a593Smuzhiyun
1491*4882a593Smuzhiyun rar = qbman_read_register(s, QBMAN_CINH_SWP_RAR);
1492*4882a593Smuzhiyun if (!RAR_SUCCESS(rar))
1493*4882a593Smuzhiyun return -EBUSY;
1494*4882a593Smuzhiyun
1495*4882a593Smuzhiyun /* Start the release command */
1496*4882a593Smuzhiyun p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR_MEM(RAR_IDX(rar)));
1497*4882a593Smuzhiyun
1498*4882a593Smuzhiyun /* Copy the caller's buffer pointers to the command */
1499*4882a593Smuzhiyun for (i = 0; i < num_buffers; i++)
1500*4882a593Smuzhiyun p->buf[i] = cpu_to_le64(buffers[i]);
1501*4882a593Smuzhiyun p->bpid = d->bpid;
1502*4882a593Smuzhiyun
1503*4882a593Smuzhiyun p->verb = d->verb | RAR_VB(rar) | num_buffers;
1504*4882a593Smuzhiyun dma_wmb();
1505*4882a593Smuzhiyun qbman_write_register(s, QBMAN_CINH_SWP_RCR_AM_RT +
1506*4882a593Smuzhiyun RAR_IDX(rar) * 4, QMAN_RT_MODE);
1507*4882a593Smuzhiyun
1508*4882a593Smuzhiyun return 0;
1509*4882a593Smuzhiyun }
1510*4882a593Smuzhiyun
1511*4882a593Smuzhiyun struct qbman_acquire_desc {
1512*4882a593Smuzhiyun u8 verb;
1513*4882a593Smuzhiyun u8 reserved;
1514*4882a593Smuzhiyun __le16 bpid;
1515*4882a593Smuzhiyun u8 num;
1516*4882a593Smuzhiyun u8 reserved2[59];
1517*4882a593Smuzhiyun };
1518*4882a593Smuzhiyun
1519*4882a593Smuzhiyun struct qbman_acquire_rslt {
1520*4882a593Smuzhiyun u8 verb;
1521*4882a593Smuzhiyun u8 rslt;
1522*4882a593Smuzhiyun __le16 reserved;
1523*4882a593Smuzhiyun u8 num;
1524*4882a593Smuzhiyun u8 reserved2[3];
1525*4882a593Smuzhiyun __le64 buf[7];
1526*4882a593Smuzhiyun };
1527*4882a593Smuzhiyun
1528*4882a593Smuzhiyun /**
1529*4882a593Smuzhiyun * qbman_swp_acquire() - Issue a buffer acquire command
1530*4882a593Smuzhiyun * @s: the software portal object
1531*4882a593Smuzhiyun * @bpid: the buffer pool index
1532*4882a593Smuzhiyun * @buffers: a pointer pointing to the acquired buffer addresses
1533*4882a593Smuzhiyun * @num_buffers: number of buffers to be acquired, must be less than 8
1534*4882a593Smuzhiyun *
1535*4882a593Smuzhiyun * Return 0 for success, or negative error code if the acquire command
1536*4882a593Smuzhiyun * fails.
1537*4882a593Smuzhiyun */
qbman_swp_acquire(struct qbman_swp * s,u16 bpid,u64 * buffers,unsigned int num_buffers)1538*4882a593Smuzhiyun int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
1539*4882a593Smuzhiyun unsigned int num_buffers)
1540*4882a593Smuzhiyun {
1541*4882a593Smuzhiyun struct qbman_acquire_desc *p;
1542*4882a593Smuzhiyun struct qbman_acquire_rslt *r;
1543*4882a593Smuzhiyun int i;
1544*4882a593Smuzhiyun
1545*4882a593Smuzhiyun if (!num_buffers || (num_buffers > 7))
1546*4882a593Smuzhiyun return -EINVAL;
1547*4882a593Smuzhiyun
1548*4882a593Smuzhiyun /* Start the management command */
1549*4882a593Smuzhiyun p = qbman_swp_mc_start(s);
1550*4882a593Smuzhiyun
1551*4882a593Smuzhiyun if (!p)
1552*4882a593Smuzhiyun return -EBUSY;
1553*4882a593Smuzhiyun
1554*4882a593Smuzhiyun /* Encode the caller-provided attributes */
1555*4882a593Smuzhiyun p->bpid = cpu_to_le16(bpid);
1556*4882a593Smuzhiyun p->num = num_buffers;
1557*4882a593Smuzhiyun
1558*4882a593Smuzhiyun /* Complete the management command */
1559*4882a593Smuzhiyun r = qbman_swp_mc_complete(s, p, QBMAN_MC_ACQUIRE);
1560*4882a593Smuzhiyun if (unlikely(!r)) {
1561*4882a593Smuzhiyun pr_err("qbman: acquire from BPID %d failed, no response\n",
1562*4882a593Smuzhiyun bpid);
1563*4882a593Smuzhiyun return -EIO;
1564*4882a593Smuzhiyun }
1565*4882a593Smuzhiyun
1566*4882a593Smuzhiyun /* Decode the outcome */
1567*4882a593Smuzhiyun WARN_ON((r->verb & 0x7f) != QBMAN_MC_ACQUIRE);
1568*4882a593Smuzhiyun
1569*4882a593Smuzhiyun /* Determine success or failure */
1570*4882a593Smuzhiyun if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
1571*4882a593Smuzhiyun pr_err("qbman: acquire from BPID 0x%x failed, code=0x%02x\n",
1572*4882a593Smuzhiyun bpid, r->rslt);
1573*4882a593Smuzhiyun return -EIO;
1574*4882a593Smuzhiyun }
1575*4882a593Smuzhiyun
1576*4882a593Smuzhiyun WARN_ON(r->num > num_buffers);
1577*4882a593Smuzhiyun
1578*4882a593Smuzhiyun /* Copy the acquired buffers to the caller's array */
1579*4882a593Smuzhiyun for (i = 0; i < r->num; i++)
1580*4882a593Smuzhiyun buffers[i] = le64_to_cpu(r->buf[i]);
1581*4882a593Smuzhiyun
1582*4882a593Smuzhiyun return (int)r->num;
1583*4882a593Smuzhiyun }
1584*4882a593Smuzhiyun
1585*4882a593Smuzhiyun struct qbman_alt_fq_state_desc {
1586*4882a593Smuzhiyun u8 verb;
1587*4882a593Smuzhiyun u8 reserved[3];
1588*4882a593Smuzhiyun __le32 fqid;
1589*4882a593Smuzhiyun u8 reserved2[56];
1590*4882a593Smuzhiyun };
1591*4882a593Smuzhiyun
1592*4882a593Smuzhiyun struct qbman_alt_fq_state_rslt {
1593*4882a593Smuzhiyun u8 verb;
1594*4882a593Smuzhiyun u8 rslt;
1595*4882a593Smuzhiyun u8 reserved[62];
1596*4882a593Smuzhiyun };
1597*4882a593Smuzhiyun
1598*4882a593Smuzhiyun #define ALT_FQ_FQID_MASK 0x00FFFFFF
1599*4882a593Smuzhiyun
qbman_swp_alt_fq_state(struct qbman_swp * s,u32 fqid,u8 alt_fq_verb)1600*4882a593Smuzhiyun int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
1601*4882a593Smuzhiyun u8 alt_fq_verb)
1602*4882a593Smuzhiyun {
1603*4882a593Smuzhiyun struct qbman_alt_fq_state_desc *p;
1604*4882a593Smuzhiyun struct qbman_alt_fq_state_rslt *r;
1605*4882a593Smuzhiyun
1606*4882a593Smuzhiyun /* Start the management command */
1607*4882a593Smuzhiyun p = qbman_swp_mc_start(s);
1608*4882a593Smuzhiyun if (!p)
1609*4882a593Smuzhiyun return -EBUSY;
1610*4882a593Smuzhiyun
1611*4882a593Smuzhiyun p->fqid = cpu_to_le32(fqid & ALT_FQ_FQID_MASK);
1612*4882a593Smuzhiyun
1613*4882a593Smuzhiyun /* Complete the management command */
1614*4882a593Smuzhiyun r = qbman_swp_mc_complete(s, p, alt_fq_verb);
1615*4882a593Smuzhiyun if (unlikely(!r)) {
1616*4882a593Smuzhiyun pr_err("qbman: mgmt cmd failed, no response (verb=0x%x)\n",
1617*4882a593Smuzhiyun alt_fq_verb);
1618*4882a593Smuzhiyun return -EIO;
1619*4882a593Smuzhiyun }
1620*4882a593Smuzhiyun
1621*4882a593Smuzhiyun /* Decode the outcome */
1622*4882a593Smuzhiyun WARN_ON((r->verb & QBMAN_RESULT_MASK) != alt_fq_verb);
1623*4882a593Smuzhiyun
1624*4882a593Smuzhiyun /* Determine success or failure */
1625*4882a593Smuzhiyun if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
1626*4882a593Smuzhiyun pr_err("qbman: ALT FQID %d failed: verb = 0x%08x code = 0x%02x\n",
1627*4882a593Smuzhiyun fqid, r->verb, r->rslt);
1628*4882a593Smuzhiyun return -EIO;
1629*4882a593Smuzhiyun }
1630*4882a593Smuzhiyun
1631*4882a593Smuzhiyun return 0;
1632*4882a593Smuzhiyun }
1633*4882a593Smuzhiyun
1634*4882a593Smuzhiyun struct qbman_cdan_ctrl_desc {
1635*4882a593Smuzhiyun u8 verb;
1636*4882a593Smuzhiyun u8 reserved;
1637*4882a593Smuzhiyun __le16 ch;
1638*4882a593Smuzhiyun u8 we;
1639*4882a593Smuzhiyun u8 ctrl;
1640*4882a593Smuzhiyun __le16 reserved2;
1641*4882a593Smuzhiyun __le64 cdan_ctx;
1642*4882a593Smuzhiyun u8 reserved3[48];
1643*4882a593Smuzhiyun
1644*4882a593Smuzhiyun };
1645*4882a593Smuzhiyun
1646*4882a593Smuzhiyun struct qbman_cdan_ctrl_rslt {
1647*4882a593Smuzhiyun u8 verb;
1648*4882a593Smuzhiyun u8 rslt;
1649*4882a593Smuzhiyun __le16 ch;
1650*4882a593Smuzhiyun u8 reserved[60];
1651*4882a593Smuzhiyun };
1652*4882a593Smuzhiyun
qbman_swp_CDAN_set(struct qbman_swp * s,u16 channelid,u8 we_mask,u8 cdan_en,u64 ctx)1653*4882a593Smuzhiyun int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
1654*4882a593Smuzhiyun u8 we_mask, u8 cdan_en,
1655*4882a593Smuzhiyun u64 ctx)
1656*4882a593Smuzhiyun {
1657*4882a593Smuzhiyun struct qbman_cdan_ctrl_desc *p = NULL;
1658*4882a593Smuzhiyun struct qbman_cdan_ctrl_rslt *r = NULL;
1659*4882a593Smuzhiyun
1660*4882a593Smuzhiyun /* Start the management command */
1661*4882a593Smuzhiyun p = qbman_swp_mc_start(s);
1662*4882a593Smuzhiyun if (!p)
1663*4882a593Smuzhiyun return -EBUSY;
1664*4882a593Smuzhiyun
1665*4882a593Smuzhiyun /* Encode the caller-provided attributes */
1666*4882a593Smuzhiyun p->ch = cpu_to_le16(channelid);
1667*4882a593Smuzhiyun p->we = we_mask;
1668*4882a593Smuzhiyun if (cdan_en)
1669*4882a593Smuzhiyun p->ctrl = 1;
1670*4882a593Smuzhiyun else
1671*4882a593Smuzhiyun p->ctrl = 0;
1672*4882a593Smuzhiyun p->cdan_ctx = cpu_to_le64(ctx);
1673*4882a593Smuzhiyun
1674*4882a593Smuzhiyun /* Complete the management command */
1675*4882a593Smuzhiyun r = qbman_swp_mc_complete(s, p, QBMAN_WQCHAN_CONFIGURE);
1676*4882a593Smuzhiyun if (unlikely(!r)) {
1677*4882a593Smuzhiyun pr_err("qbman: wqchan config failed, no response\n");
1678*4882a593Smuzhiyun return -EIO;
1679*4882a593Smuzhiyun }
1680*4882a593Smuzhiyun
1681*4882a593Smuzhiyun WARN_ON((r->verb & 0x7f) != QBMAN_WQCHAN_CONFIGURE);
1682*4882a593Smuzhiyun
1683*4882a593Smuzhiyun /* Determine success or failure */
1684*4882a593Smuzhiyun if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
1685*4882a593Smuzhiyun pr_err("qbman: CDAN cQID %d failed: code = 0x%02x\n",
1686*4882a593Smuzhiyun channelid, r->rslt);
1687*4882a593Smuzhiyun return -EIO;
1688*4882a593Smuzhiyun }
1689*4882a593Smuzhiyun
1690*4882a593Smuzhiyun return 0;
1691*4882a593Smuzhiyun }
1692*4882a593Smuzhiyun
1693*4882a593Smuzhiyun #define QBMAN_RESPONSE_VERB_MASK 0x7f
1694*4882a593Smuzhiyun #define QBMAN_FQ_QUERY_NP 0x45
1695*4882a593Smuzhiyun #define QBMAN_BP_QUERY 0x32
1696*4882a593Smuzhiyun
1697*4882a593Smuzhiyun struct qbman_fq_query_desc {
1698*4882a593Smuzhiyun u8 verb;
1699*4882a593Smuzhiyun u8 reserved[3];
1700*4882a593Smuzhiyun __le32 fqid;
1701*4882a593Smuzhiyun u8 reserved2[56];
1702*4882a593Smuzhiyun };
1703*4882a593Smuzhiyun
qbman_fq_query_state(struct qbman_swp * s,u32 fqid,struct qbman_fq_query_np_rslt * r)1704*4882a593Smuzhiyun int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
1705*4882a593Smuzhiyun struct qbman_fq_query_np_rslt *r)
1706*4882a593Smuzhiyun {
1707*4882a593Smuzhiyun struct qbman_fq_query_desc *p;
1708*4882a593Smuzhiyun void *resp;
1709*4882a593Smuzhiyun
1710*4882a593Smuzhiyun p = (struct qbman_fq_query_desc *)qbman_swp_mc_start(s);
1711*4882a593Smuzhiyun if (!p)
1712*4882a593Smuzhiyun return -EBUSY;
1713*4882a593Smuzhiyun
1714*4882a593Smuzhiyun /* FQID is a 24 bit value */
1715*4882a593Smuzhiyun p->fqid = cpu_to_le32(fqid & 0x00FFFFFF);
1716*4882a593Smuzhiyun resp = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY_NP);
1717*4882a593Smuzhiyun if (!resp) {
1718*4882a593Smuzhiyun pr_err("qbman: Query FQID %d NP fields failed, no response\n",
1719*4882a593Smuzhiyun fqid);
1720*4882a593Smuzhiyun return -EIO;
1721*4882a593Smuzhiyun }
1722*4882a593Smuzhiyun *r = *(struct qbman_fq_query_np_rslt *)resp;
1723*4882a593Smuzhiyun /* Decode the outcome */
1724*4882a593Smuzhiyun WARN_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_FQ_QUERY_NP);
1725*4882a593Smuzhiyun
1726*4882a593Smuzhiyun /* Determine success or failure */
1727*4882a593Smuzhiyun if (r->rslt != QBMAN_MC_RSLT_OK) {
1728*4882a593Smuzhiyun pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
1729*4882a593Smuzhiyun p->fqid, r->rslt);
1730*4882a593Smuzhiyun return -EIO;
1731*4882a593Smuzhiyun }
1732*4882a593Smuzhiyun
1733*4882a593Smuzhiyun return 0;
1734*4882a593Smuzhiyun }
1735*4882a593Smuzhiyun
qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt * r)1736*4882a593Smuzhiyun u32 qbman_fq_state_frame_count(const struct qbman_fq_query_np_rslt *r)
1737*4882a593Smuzhiyun {
1738*4882a593Smuzhiyun return (le32_to_cpu(r->frm_cnt) & 0x00FFFFFF);
1739*4882a593Smuzhiyun }
1740*4882a593Smuzhiyun
qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt * r)1741*4882a593Smuzhiyun u32 qbman_fq_state_byte_count(const struct qbman_fq_query_np_rslt *r)
1742*4882a593Smuzhiyun {
1743*4882a593Smuzhiyun return le32_to_cpu(r->byte_cnt);
1744*4882a593Smuzhiyun }
1745*4882a593Smuzhiyun
1746*4882a593Smuzhiyun struct qbman_bp_query_desc {
1747*4882a593Smuzhiyun u8 verb;
1748*4882a593Smuzhiyun u8 reserved;
1749*4882a593Smuzhiyun __le16 bpid;
1750*4882a593Smuzhiyun u8 reserved2[60];
1751*4882a593Smuzhiyun };
1752*4882a593Smuzhiyun
qbman_bp_query(struct qbman_swp * s,u16 bpid,struct qbman_bp_query_rslt * r)1753*4882a593Smuzhiyun int qbman_bp_query(struct qbman_swp *s, u16 bpid,
1754*4882a593Smuzhiyun struct qbman_bp_query_rslt *r)
1755*4882a593Smuzhiyun {
1756*4882a593Smuzhiyun struct qbman_bp_query_desc *p;
1757*4882a593Smuzhiyun void *resp;
1758*4882a593Smuzhiyun
1759*4882a593Smuzhiyun p = (struct qbman_bp_query_desc *)qbman_swp_mc_start(s);
1760*4882a593Smuzhiyun if (!p)
1761*4882a593Smuzhiyun return -EBUSY;
1762*4882a593Smuzhiyun
1763*4882a593Smuzhiyun p->bpid = cpu_to_le16(bpid);
1764*4882a593Smuzhiyun resp = qbman_swp_mc_complete(s, p, QBMAN_BP_QUERY);
1765*4882a593Smuzhiyun if (!resp) {
1766*4882a593Smuzhiyun pr_err("qbman: Query BPID %d fields failed, no response\n",
1767*4882a593Smuzhiyun bpid);
1768*4882a593Smuzhiyun return -EIO;
1769*4882a593Smuzhiyun }
1770*4882a593Smuzhiyun *r = *(struct qbman_bp_query_rslt *)resp;
1771*4882a593Smuzhiyun /* Decode the outcome */
1772*4882a593Smuzhiyun WARN_ON((r->verb & QBMAN_RESPONSE_VERB_MASK) != QBMAN_BP_QUERY);
1773*4882a593Smuzhiyun
1774*4882a593Smuzhiyun /* Determine success or failure */
1775*4882a593Smuzhiyun if (r->rslt != QBMAN_MC_RSLT_OK) {
1776*4882a593Smuzhiyun pr_err("Query fields of BPID 0x%x failed, code=0x%02x\n",
1777*4882a593Smuzhiyun bpid, r->rslt);
1778*4882a593Smuzhiyun return -EIO;
1779*4882a593Smuzhiyun }
1780*4882a593Smuzhiyun
1781*4882a593Smuzhiyun return 0;
1782*4882a593Smuzhiyun }
1783*4882a593Smuzhiyun
qbman_bp_info_num_free_bufs(struct qbman_bp_query_rslt * a)1784*4882a593Smuzhiyun u32 qbman_bp_info_num_free_bufs(struct qbman_bp_query_rslt *a)
1785*4882a593Smuzhiyun {
1786*4882a593Smuzhiyun return le32_to_cpu(a->fill);
1787*4882a593Smuzhiyun }
1788