Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 : : *
3 : : * Copyright 2008-2016 Freescale Semiconductor Inc.
4 : : * Copyright 2017,2026 NXP
5 : : *
6 : : */
7 : :
8 : : #include "qman_priv.h"
9 : :
10 : : #define GENMASK(h, l) \
11 : : (((~0U) >> (sizeof(u32) * 8 - ((h) - (l) + 1))) << (l))
12 : :
13 : : /***************************/
14 : : /* Portal register assists */
15 : : /***************************/
16 : : #define QM_REG_EQCR_PI_CINH 0x3000
17 : : #define QM_REG_EQCR_CI_CINH 0x3040
18 : : #define QM_REG_EQCR_ITR 0x3080
19 : : #define QM_REG_DQRR_PI_CINH 0x3100
20 : : #define QM_REG_DQRR_CI_CINH 0x3140
21 : : #define QM_REG_DQRR_ITR 0x3180
22 : : #define QM_REG_DQRR_DCAP 0x31C0
23 : : #define QM_REG_DQRR_SDQCR 0x3200
24 : : #define QM_REG_DQRR_VDQCR 0x3240
25 : : #define QM_REG_DQRR_PDQCR 0x3280
26 : : #define QM_REG_MR_PI_CINH 0x3300
27 : : #define QM_REG_MR_CI_CINH 0x3340
28 : : #define QM_REG_MR_ITR 0x3380
29 : : #define QM_REG_CFG 0x3500
30 : : #define QM_REG_ISR 0x3600
31 : : #define QM_REG_IIR 0x36C0
32 : : #define QM_REG_ITPR 0x3740
33 : :
34 : : /* Cache-enabled register offsets */
35 : : #define QM_CL_EQCR 0x0000
36 : : #define QM_CL_DQRR 0x1000
37 : : #define QM_CL_MR 0x2000
38 : : #define QM_CL_EQCR_PI_CENA 0x3000
39 : : #define QM_CL_EQCR_CI_CENA 0x3040
40 : : #define QM_CL_DQRR_PI_CENA 0x3100
41 : : #define QM_CL_DQRR_CI_CENA 0x3140
42 : : #define QM_CL_MR_PI_CENA 0x3300
43 : : #define QM_CL_MR_CI_CENA 0x3340
44 : : #define QM_CL_CR 0x3800
45 : : #define QM_CL_RR0 0x3900
46 : : #define QM_CL_RR1 0x3940
47 : :
48 : : #define QM_FQD_CHAN_OFF 3
49 : : #define QM_FQD_WQ_MASK GENMASK(2, 0)
50 : : /* 'fqid' is a 24-bit field in every h/w descriptor */
51 : : #define QM_FQID_MASK GENMASK(23, 0)
52 : :
53 : : #define qm_fqid_set(p, v) ((p)->fqid = cpu_to_be32((v) & QM_FQID_MASK))
54 : : #define qm_fqid_get(p) (be32_to_cpu((p)->fqid) & QM_FQID_MASK)
55 : :
56 : : /* BTW, the drivers (and h/w programming model) already obtain the required
57 : : * synchronisation for portal accesses via lwsync(), hwsync(), and
58 : : * data-dependencies. Use of barrier()s or other order-preserving primitives
59 : : * simply degrade performance. Hence the use of the __raw_*() interfaces, which
60 : : * simply ensure that the compiler treats the portal registers as volatile (ie.
61 : : * non-coherent).
62 : : */
63 : :
64 : : /* Cache-inhibited register access. */
65 : : #define __qm_in(qm, o) be32_to_cpu(__raw_readl((qm)->ci + (o)))
66 : : #define __qm_out(qm, o, val) __raw_writel((cpu_to_be32(val)), \
67 : : (qm)->ci + (o))
68 : : #define qm_in(reg) __qm_in(&portal->addr, QM_REG_##reg)
69 : : #define qm_out(reg, val) __qm_out(&portal->addr, QM_REG_##reg, val)
70 : :
71 : : /* Cache-enabled (index) register access */
72 : : #define __qm_cl_touch_ro(qm, o) dcbt_ro((qm)->ce + (o))
73 : : #define __qm_cl_touch_rw(qm, o) dcbt_rw((qm)->ce + (o))
74 : : #define __qm_cl_in(qm, o) be32_to_cpu(__raw_readl((qm)->ce + (o)))
75 : : #define __qm_cl_out(qm, o, val) \
76 : : do { \
77 : : u32 *__tmpclout = (qm)->ce + (o); \
78 : : __raw_writel(cpu_to_be32(val), __tmpclout); \
79 : : dcbf(__tmpclout); \
80 : : } while (0)
81 : : #define __qm_cl_invalidate(qm, o) dccivac((qm)->ce + (o))
82 : : #define qm_cl_touch_ro(reg) __qm_cl_touch_ro(&portal->addr, QM_CL_##reg##_CENA)
83 : : #define qm_cl_touch_rw(reg) __qm_cl_touch_rw(&portal->addr, QM_CL_##reg##_CENA)
84 : : #define qm_cl_in(reg) __qm_cl_in(&portal->addr, QM_CL_##reg##_CENA)
85 : : #define qm_cl_out(reg, val) __qm_cl_out(&portal->addr, QM_CL_##reg##_CENA, val)
86 : : #define qm_cl_invalidate(reg)\
87 : : __qm_cl_invalidate(&portal->addr, QM_CL_##reg##_CENA)
88 : :
89 : : /* Cache-enabled ring access */
90 : : #define qm_cl(base, idx) ((void *)base + ((idx) << 6))
91 : :
92 : : /* Cyclic helper for rings. FIXME: once we are able to do fine-grain perf
93 : : * analysis, look at using the "extra" bit in the ring index registers to avoid
94 : : * cyclic issues.
95 : : */
96 : : static inline u8 qm_cyc_diff(u8 ringsize, u8 first, u8 last)
97 : : {
98 : : /* 'first' is included, 'last' is excluded */
99 [ # # # # : 0 : if (first <= last)
# # # # #
# ]
100 : 0 : return last - first;
101 : 0 : return ringsize + last - first;
102 : : }
103 : :
104 : : /* Portal modes.
105 : : * Enum types;
106 : : * pmode == production mode
107 : : * cmode == consumption mode,
108 : : * dmode == h/w dequeue mode.
109 : : * Enum values use 3 letter codes. First letter matches the portal mode,
110 : : * remaining two letters indicate;
111 : : * ci == cache-inhibited portal register
112 : : * ce == cache-enabled portal register
113 : : * vb == in-band valid-bit (cache-enabled)
114 : : * dc == DCA (Discrete Consumption Acknowledgment), DQRR-only
115 : : * As for "enum qm_dqrr_dmode", it should be self-explanatory.
116 : : */
117 : : enum qm_eqcr_pmode { /* matches QCSP_CFG::EPM */
118 : : qm_eqcr_pci = 0, /* PI index, cache-inhibited */
119 : : qm_eqcr_pce = 1, /* PI index, cache-enabled */
120 : : qm_eqcr_pvb = 2 /* valid-bit */
121 : : };
122 : :
123 : : enum qm_dqrr_dmode { /* matches QCSP_CFG::DP */
124 : : qm_dqrr_dpush = 0, /* SDQCR + VDQCR */
125 : : qm_dqrr_dpull = 1 /* PDQCR */
126 : : };
127 : :
128 : : enum qm_dqrr_pmode { /* s/w-only */
129 : : qm_dqrr_pci, /* reads DQRR_PI_CINH */
130 : : qm_dqrr_pce, /* reads DQRR_PI_CENA */
131 : : qm_dqrr_pvb /* reads valid-bit */
132 : : };
133 : :
134 : : enum qm_dqrr_cmode { /* matches QCSP_CFG::DCM */
135 : : qm_dqrr_cci = 0, /* CI index, cache-inhibited */
136 : : qm_dqrr_cce = 1, /* CI index, cache-enabled */
137 : : qm_dqrr_cdc = 2 /* Discrete Consumption Acknowledgment */
138 : : };
139 : :
140 : : enum qm_mr_pmode { /* s/w-only */
141 : : qm_mr_pci, /* reads MR_PI_CINH */
142 : : qm_mr_pce, /* reads MR_PI_CENA */
143 : : qm_mr_pvb /* reads valid-bit */
144 : : };
145 : :
146 : : enum qm_mr_cmode { /* matches QCSP_CFG::MM */
147 : : qm_mr_cci = 0, /* CI index, cache-inhibited */
148 : : qm_mr_cce = 1 /* CI index, cache-enabled */
149 : : };
150 : :
151 : : /* ------------------------- */
152 : : /* --- Portal structures --- */
153 : :
154 : : #define QM_EQCR_SIZE 8
155 : : #define QM_DQRR_SIZE 16
156 : : #define QM_MR_SIZE 8
157 : :
158 : : struct qm_eqcr {
159 : : struct qm_eqcr_entry *ring, *cursor;
160 : : u8 ci, available, ithresh, vbit;
161 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
162 : : u32 busy;
163 : : enum qm_eqcr_pmode pmode;
164 : : #endif
165 : : };
166 : :
167 : : struct qm_dqrr {
168 : : struct qm_dqrr_entry *ring, *cursor;
169 : : u8 pi, ci, fill, ithresh, vbit;
170 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
171 : : enum qm_dqrr_dmode dmode;
172 : : enum qm_dqrr_pmode pmode;
173 : : enum qm_dqrr_cmode cmode;
174 : : #endif
175 : : };
176 : :
177 : : struct qm_mr {
178 : : const struct qm_mr_entry *ring, *cursor;
179 : : u8 pi, ci, fill, ithresh, vbit;
180 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
181 : : enum qm_mr_pmode pmode;
182 : : enum qm_mr_cmode cmode;
183 : : #endif
184 : : };
185 : :
186 : : struct qm_mc {
187 : : struct qm_mc_command *cr;
188 : : struct qm_mc_result *rr;
189 : : u8 rridx, vbit;
190 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
191 : : enum {
192 : : /* Can be _mc_start()ed */
193 : : qman_mc_idle,
194 : : /* Can be _mc_commit()ed or _mc_abort()ed */
195 : : qman_mc_user,
196 : : /* Can only be _mc_retry()ed */
197 : : qman_mc_hw
198 : : } state;
199 : : #endif
200 : : };
201 : :
202 : : #define QM_PORTAL_ALIGNMENT ____cacheline_aligned
203 : :
204 : : struct qm_addr {
205 : : void __iomem *ce; /* cache-enabled */
206 : : void __iomem *ci; /* cache-inhibited */
207 : : };
208 : :
209 : : struct qm_portal {
210 : : struct qm_addr addr;
211 : : struct qm_eqcr eqcr;
212 : : struct qm_dqrr dqrr;
213 : : struct qm_mr mr;
214 : : struct qm_mc mc;
215 : : } QM_PORTAL_ALIGNMENT;
216 : :
217 : : /* Bit-wise logic to wrap a ring pointer by clearing the "carry bit" */
218 : : #define EQCR_CARRYCLEAR(p) \
219 : : (void *)((unsigned long)(p) & (~(unsigned long)(QM_EQCR_SIZE << 6)))
220 : :
221 : : extern dma_addr_t rte_mem_virt2iova(const void *addr);
222 : :
223 : : /* Bit-wise logic to convert a ring pointer to a ring index */
224 : : static inline u8 EQCR_PTR2IDX(struct qm_eqcr_entry *e)
225 : : {
226 [ # # # # ]: 0 : return ((uintptr_t)e >> 6) & (QM_EQCR_SIZE - 1);
227 : : }
228 : :
229 : : /* Increment the 'cursor' ring pointer, taking 'vbit' into account */
230 : : static inline void EQCR_INC(struct qm_eqcr *eqcr)
231 : : {
232 : : /* NB: this is odd-looking, but experiments show that it generates fast
233 : : * code with essentially no branching overheads. We increment to the
234 : : * next EQCR pointer and handle overflow and 'vbit'.
235 : : */
236 : 0 : struct qm_eqcr_entry *partial = eqcr->cursor + 1;
237 : :
238 : 0 : eqcr->cursor = EQCR_CARRYCLEAR(partial);
239 : 0 : if (partial != eqcr->cursor)
240 : 0 : eqcr->vbit ^= QM_EQCR_VERB_VBIT;
241 : : }
242 : :
243 : : static inline struct qm_eqcr_entry *qm_eqcr_start_no_stash(struct qm_portal
244 : : *portal)
245 : : {
246 : : register struct qm_eqcr *eqcr = &portal->eqcr;
247 : :
248 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
249 : : DPAA_ASSERT(!eqcr->busy);
250 : : #endif
251 [ # # ]: 0 : if (!eqcr->available)
252 : : return NULL;
253 : :
254 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
255 : : eqcr->busy = 1;
256 : : #endif
257 : :
258 : 0 : return eqcr->cursor;
259 : : }
260 : :
261 : : static inline struct qm_eqcr_entry *qm_eqcr_start_stash(struct qm_portal
262 : : *portal)
263 : : {
264 : : register struct qm_eqcr *eqcr = &portal->eqcr;
265 : : u8 diff, old_ci;
266 : :
267 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
268 : : DPAA_ASSERT(!eqcr->busy);
269 : : #endif
270 [ # # ]: 0 : if (!eqcr->available) {
271 : 0 : old_ci = eqcr->ci;
272 [ # # ]: 0 : eqcr->ci = qm_cl_in(EQCR_CI) & (QM_EQCR_SIZE - 1);
273 : : diff = qm_cyc_diff(QM_EQCR_SIZE, old_ci, eqcr->ci);
274 : 0 : eqcr->available += diff;
275 [ # # ]: 0 : if (!diff)
276 : : return NULL;
277 : : }
278 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
279 : : eqcr->busy = 1;
280 : : #endif
281 : 0 : return eqcr->cursor;
282 : : }
283 : :
284 : : static inline void qm_eqcr_abort(struct qm_portal *portal)
285 : : {
286 : : __maybe_unused register struct qm_eqcr *eqcr = &portal->eqcr;
287 : :
288 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
289 : : DPAA_ASSERT(eqcr->busy);
290 : : eqcr->busy = 0;
291 : : #endif
292 : : }
293 : :
294 : : static inline struct qm_eqcr_entry *qm_eqcr_pend_and_next(
295 : : struct qm_portal *portal, u8 myverb)
296 : : {
297 : : register struct qm_eqcr *eqcr = &portal->eqcr;
298 : :
299 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
300 : : DPAA_ASSERT(eqcr->busy);
301 : : DPAA_ASSERT(eqcr->pmode != qm_eqcr_pvb);
302 : : #endif
303 : : if (eqcr->available == 1)
304 : : return NULL;
305 : : eqcr->cursor->__dont_write_directly__verb = myverb | eqcr->vbit;
306 : : dcbf(eqcr->cursor);
307 : : EQCR_INC(eqcr);
308 : : eqcr->available--;
309 : : return eqcr->cursor;
310 : : }
311 : :
312 : : #define EQCR_COMMIT_CHECKS(eqcr) \
313 : : do { \
314 : : DPAA_ASSERT(eqcr->busy); \
315 : : DPAA_ASSERT(eqcr->cursor->orp == (eqcr->cursor->orp & 0x00ffffff)); \
316 : : DPAA_ASSERT(eqcr->cursor->fqid == (eqcr->cursor->fqid & 0x00ffffff)); \
317 : : } while (0)
318 : :
319 : : static inline void qm_eqcr_pci_commit(struct qm_portal *portal, u8 myverb)
320 : : {
321 : : register struct qm_eqcr *eqcr = &portal->eqcr;
322 : :
323 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
324 : : EQCR_COMMIT_CHECKS(eqcr);
325 : : DPAA_ASSERT(eqcr->pmode == qm_eqcr_pci);
326 : : #endif
327 : : eqcr->cursor->__dont_write_directly__verb = myverb | eqcr->vbit;
328 : : EQCR_INC(eqcr);
329 : : eqcr->available--;
330 : : dcbf(eqcr->cursor);
331 : : hwsync();
332 : : qm_out(EQCR_PI_CINH, EQCR_PTR2IDX(eqcr->cursor));
333 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
334 : : eqcr->busy = 0;
335 : : #endif
336 : : }
337 : :
338 : : static inline void qm_eqcr_pce_prefetch(struct qm_portal *portal)
339 : : {
340 : : __maybe_unused register struct qm_eqcr *eqcr = &portal->eqcr;
341 : :
342 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
343 : : DPAA_ASSERT(eqcr->pmode == qm_eqcr_pce);
344 : : #endif
345 : : qm_cl_invalidate(EQCR_PI);
346 : : qm_cl_touch_rw(EQCR_PI);
347 : : }
348 : :
349 : : static inline void qm_eqcr_pce_commit(struct qm_portal *portal, u8 myverb)
350 : : {
351 : : register struct qm_eqcr *eqcr = &portal->eqcr;
352 : :
353 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
354 : : EQCR_COMMIT_CHECKS(eqcr);
355 : : DPAA_ASSERT(eqcr->pmode == qm_eqcr_pce);
356 : : #endif
357 : : eqcr->cursor->__dont_write_directly__verb = myverb | eqcr->vbit;
358 : : EQCR_INC(eqcr);
359 : : eqcr->available--;
360 : : dcbf(eqcr->cursor);
361 : : lwsync();
362 : : qm_cl_out(EQCR_PI, EQCR_PTR2IDX(eqcr->cursor));
363 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
364 : : eqcr->busy = 0;
365 : : #endif
366 : : }
367 : :
368 : : static inline void qm_eqcr_pvb_commit(struct qm_portal *portal, u8 myverb)
369 : : {
370 : : register struct qm_eqcr *eqcr = &portal->eqcr;
371 : : struct qm_eqcr_entry *eqcursor;
372 : :
373 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
374 : : EQCR_COMMIT_CHECKS(eqcr);
375 : : DPAA_ASSERT(eqcr->pmode == qm_eqcr_pvb);
376 : : #endif
377 : : lwsync();
378 : 0 : eqcursor = eqcr->cursor;
379 [ # # # # ]: 0 : eqcursor->__dont_write_directly__verb = myverb | eqcr->vbit;
380 : : dcbf(eqcursor);
381 : : EQCR_INC(eqcr);
382 : 0 : eqcr->available--;
383 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
384 : : eqcr->busy = 0;
385 : : #endif
386 : : }
387 : :
388 : : static inline u8 qm_eqcr_cci_update(struct qm_portal *portal)
389 : : {
390 : : register struct qm_eqcr *eqcr = &portal->eqcr;
391 : : u8 diff, old_ci = eqcr->ci;
392 : :
393 : : eqcr->ci = qm_in(EQCR_CI_CINH) & (QM_EQCR_SIZE - 1);
394 : : diff = qm_cyc_diff(QM_EQCR_SIZE, old_ci, eqcr->ci);
395 : : eqcr->available += diff;
396 : : return diff;
397 : : }
398 : :
399 : : static inline void qm_eqcr_cce_prefetch(struct qm_portal *portal)
400 : : {
401 : : __maybe_unused register struct qm_eqcr *eqcr = &portal->eqcr;
402 : :
403 : 0 : qm_cl_touch_ro(EQCR_CI);
404 : 0 : }
405 : :
406 : : static inline u8 qm_eqcr_cce_update(struct qm_portal *portal)
407 : : {
408 : : register struct qm_eqcr *eqcr = &portal->eqcr;
409 : 0 : u8 diff, old_ci = eqcr->ci;
410 : :
411 [ # # # # : 0 : eqcr->ci = qm_cl_in(EQCR_CI) & (QM_EQCR_SIZE - 1);
# # # # #
# # # ]
412 : : qm_cl_invalidate(EQCR_CI);
413 : : diff = qm_cyc_diff(QM_EQCR_SIZE, old_ci, eqcr->ci);
414 : 0 : eqcr->available += diff;
415 : 0 : return diff;
416 : : }
417 : :
418 : : static inline u8 qm_eqcr_get_ithresh(struct qm_portal *portal)
419 : : {
420 : : register struct qm_eqcr *eqcr = &portal->eqcr;
421 : :
422 : : return eqcr->ithresh;
423 : : }
424 : :
425 : : static inline void qm_eqcr_set_ithresh(struct qm_portal *portal, u8 ithresh)
426 : : {
427 : : register struct qm_eqcr *eqcr = &portal->eqcr;
428 : :
429 : 0 : eqcr->ithresh = ithresh;
430 : 0 : qm_out(EQCR_ITR, ithresh);
431 : 0 : }
432 : :
433 : : static inline u8 qm_eqcr_get_avail(struct qm_portal *portal)
434 : : {
435 : : register struct qm_eqcr *eqcr = &portal->eqcr;
436 : :
437 [ # # ]: 0 : return eqcr->available;
438 : : }
439 : :
440 : : static inline u8 qm_eqcr_get_fill(struct qm_portal *portal)
441 : : {
442 : : register struct qm_eqcr *eqcr = &portal->eqcr;
443 : :
444 : 0 : return QM_EQCR_SIZE - 1 - eqcr->available;
445 : : }
446 : :
447 : : #define DQRR_CARRYCLEAR(p) \
448 : : (void *)((unsigned long)(p) & (~(unsigned long)(QM_DQRR_SIZE << 6)))
449 : :
450 : : static inline u8 DQRR_PTR2IDX(const struct qm_dqrr_entry *e)
451 : : {
452 [ # # # # : 0 : return ((uintptr_t)e >> 6) & (QM_DQRR_SIZE - 1);
# # # # #
# ]
453 : : }
454 : :
455 : : static inline struct qm_dqrr_entry *DQRR_INC(
456 : : const struct qm_dqrr_entry *e)
457 : : {
458 : 0 : return DQRR_CARRYCLEAR(e + 1);
459 : : }
460 : :
461 : : static inline void qm_dqrr_set_maxfill(struct qm_portal *portal, u8 mf)
462 : : {
463 : 0 : qm_out(CFG, (qm_in(CFG) & 0xff0fffff) |
464 : : ((mf & (QM_DQRR_SIZE - 1)) << 20));
465 : 0 : }
466 : :
467 : : static inline const struct qm_dqrr_entry *qm_dqrr_current(
468 : : struct qm_portal *portal)
469 : : {
470 : : register struct qm_dqrr *dqrr = &portal->dqrr;
471 : :
472 [ # # # # : 0 : if (!dqrr->fill)
# # # # ]
473 : : return NULL;
474 [ # # # # : 0 : return dqrr->cursor;
# # # # ]
475 : : }
476 : :
477 : : static inline u8 qm_dqrr_cursor(struct qm_portal *portal)
478 : : {
479 : : register struct qm_dqrr *dqrr = &portal->dqrr;
480 : :
481 : : return DQRR_PTR2IDX(dqrr->cursor);
482 : : }
483 : :
484 : : static inline u8 qm_dqrr_next(struct qm_portal *portal)
485 : : {
486 : : register struct qm_dqrr *dqrr = &portal->dqrr;
487 : :
488 : : DPAA_ASSERT(dqrr->fill);
489 : 0 : dqrr->cursor = DQRR_INC(dqrr->cursor);
490 [ # # # # : 0 : return --dqrr->fill;
# # ]
491 : : }
492 : :
493 : : static inline u8 qm_dqrr_pci_update(struct qm_portal *portal)
494 : : {
495 : : register struct qm_dqrr *dqrr = &portal->dqrr;
496 : : u8 diff, old_pi = dqrr->pi;
497 : :
498 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
499 : : DPAA_ASSERT(dqrr->pmode == qm_dqrr_pci);
500 : : #endif
501 : : dqrr->pi = qm_in(DQRR_PI_CINH) & (QM_DQRR_SIZE - 1);
502 : : diff = qm_cyc_diff(QM_DQRR_SIZE, old_pi, dqrr->pi);
503 : : dqrr->fill += diff;
504 : : return diff;
505 : : }
506 : :
507 : : static inline void qm_dqrr_pce_prefetch(struct qm_portal *portal)
508 : : {
509 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
510 : :
511 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
512 : : DPAA_ASSERT(dqrr->pmode == qm_dqrr_pce);
513 : : #endif
514 : : qm_cl_invalidate(DQRR_PI);
515 : : qm_cl_touch_ro(DQRR_PI);
516 : : }
517 : :
518 : : static inline u8 qm_dqrr_pce_update(struct qm_portal *portal)
519 : : {
520 : : register struct qm_dqrr *dqrr = &portal->dqrr;
521 : : u8 diff, old_pi = dqrr->pi;
522 : :
523 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
524 : : DPAA_ASSERT(dqrr->pmode == qm_dqrr_pce);
525 : : #endif
526 : : dqrr->pi = qm_cl_in(DQRR_PI) & (QM_DQRR_SIZE - 1);
527 : : diff = qm_cyc_diff(QM_DQRR_SIZE, old_pi, dqrr->pi);
528 : : dqrr->fill += diff;
529 : : return diff;
530 : : }
531 : :
532 : : static inline void qm_dqrr_pvb_update(struct qm_portal *portal)
533 : : {
534 : : register struct qm_dqrr *dqrr = &portal->dqrr;
535 : 0 : const struct qm_dqrr_entry *res = qm_cl(dqrr->ring, dqrr->pi);
536 : :
537 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
538 : : DPAA_ASSERT(dqrr->pmode == qm_dqrr_pvb);
539 : : #endif
540 : : /* when accessing 'verb', use __raw_readb() to ensure that compiler
541 : : * inlining doesn't try to optimise out "excess reads".
542 : : */
543 [ # # # # : 0 : if ((__raw_readb(&res->verb) & QM_DQRR_VERB_VBIT) == dqrr->vbit) {
# # # # #
# ]
544 : 0 : dqrr->pi = (dqrr->pi + 1) & (QM_DQRR_SIZE - 1);
545 [ # # # # : 0 : if (!dqrr->pi)
# # # # #
# # # ]
546 : 0 : dqrr->vbit ^= QM_DQRR_VERB_VBIT;
547 : 0 : dqrr->fill++;
548 : : }
549 : : }
550 : :
551 : : static inline void qm_dqrr_cci_consume(struct qm_portal *portal, u8 num)
552 : : {
553 : : register struct qm_dqrr *dqrr = &portal->dqrr;
554 : :
555 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
556 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cci);
557 : : #endif
558 : : dqrr->ci = (dqrr->ci + num) & (QM_DQRR_SIZE - 1);
559 : : qm_out(DQRR_CI_CINH, dqrr->ci);
560 : : }
561 : :
562 : : static inline void qm_dqrr_cci_consume_to_current(struct qm_portal *portal)
563 : : {
564 : : register struct qm_dqrr *dqrr = &portal->dqrr;
565 : :
566 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
567 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cci);
568 : : #endif
569 : : dqrr->ci = DQRR_PTR2IDX(dqrr->cursor);
570 : : qm_out(DQRR_CI_CINH, dqrr->ci);
571 : : }
572 : :
573 : : static inline void qm_dqrr_cce_prefetch(struct qm_portal *portal)
574 : : {
575 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
576 : :
577 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
578 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cce);
579 : : #endif
580 : : qm_cl_invalidate(DQRR_CI);
581 : : qm_cl_touch_rw(DQRR_CI);
582 : : }
583 : :
584 : : static inline void qm_dqrr_cce_consume(struct qm_portal *portal, u8 num)
585 : : {
586 : : register struct qm_dqrr *dqrr = &portal->dqrr;
587 : :
588 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
589 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cce);
590 : : #endif
591 : : dqrr->ci = (dqrr->ci + num) & (QM_DQRR_SIZE - 1);
592 : : qm_cl_out(DQRR_CI, dqrr->ci);
593 : : }
594 : :
595 : : static inline void qm_dqrr_cce_consume_to_current(struct qm_portal *portal)
596 : : {
597 : : register struct qm_dqrr *dqrr = &portal->dqrr;
598 : :
599 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
600 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cce);
601 : : #endif
602 : : dqrr->ci = DQRR_PTR2IDX(dqrr->cursor);
603 : : qm_cl_out(DQRR_CI, dqrr->ci);
604 : : }
605 : :
606 : : static inline void qm_dqrr_cdc_consume_1(struct qm_portal *portal, u8 idx,
607 : : int park)
608 : : {
609 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
610 : :
611 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
612 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cdc);
613 : : #endif
614 : : DPAA_ASSERT(idx < QM_DQRR_SIZE);
615 [ # # # # ]: 0 : qm_out(DQRR_DCAP, (0 << 8) | /* S */
616 : : ((park ? 1 : 0) << 6) | /* PK */
617 : : idx); /* DCAP_CI */
618 : : }
619 : :
620 : : static inline void qm_dqrr_cdc_consume_1ptr(struct qm_portal *portal,
621 : : const struct qm_dqrr_entry *dq,
622 : : int park)
623 : : {
624 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
625 : : u8 idx = DQRR_PTR2IDX(dq);
626 : :
627 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
628 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cdc);
629 : : #endif
630 : : DPAA_ASSERT(idx < QM_DQRR_SIZE);
631 [ # # # # : 0 : qm_out(DQRR_DCAP, (0 << 8) | /* DQRR_DCAP::S */
# # # # #
# # # # #
# # # # ]
632 : : ((park ? 1 : 0) << 6) | /* DQRR_DCAP::PK */
633 : : idx); /* DQRR_DCAP::DCAP_CI */
634 : 0 : }
635 : :
636 : : static inline void qm_dqrr_cdc_consume_n(struct qm_portal *portal, u16 bitmask)
637 : : {
638 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
639 : :
640 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
641 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cdc);
642 : : #endif
643 : 0 : qm_out(DQRR_DCAP, (1 << 8) | /* DQRR_DCAP::S */
644 : : ((u32)bitmask << 16)); /* DQRR_DCAP::DCAP_CI */
645 : 0 : dqrr->ci = qm_in(DQRR_CI_CINH) & (QM_DQRR_SIZE - 1);
646 [ # # ]: 0 : dqrr->fill = qm_cyc_diff(QM_DQRR_SIZE, dqrr->ci, dqrr->pi);
647 : 0 : }
648 : :
649 : : static inline u8 qm_dqrr_cdc_cci(struct qm_portal *portal)
650 : : {
651 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
652 : :
653 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
654 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cdc);
655 : : #endif
656 : : return qm_in(DQRR_CI_CINH) & (QM_DQRR_SIZE - 1);
657 : : }
658 : :
659 : : static inline void qm_dqrr_cdc_cce_prefetch(struct qm_portal *portal)
660 : : {
661 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
662 : :
663 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
664 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cdc);
665 : : #endif
666 : : qm_cl_invalidate(DQRR_CI);
667 : : qm_cl_touch_ro(DQRR_CI);
668 : : }
669 : :
670 : : static inline u8 qm_dqrr_cdc_cce(struct qm_portal *portal)
671 : : {
672 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
673 : :
674 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
675 : : DPAA_ASSERT(dqrr->cmode == qm_dqrr_cdc);
676 : : #endif
677 : : return qm_cl_in(DQRR_CI) & (QM_DQRR_SIZE - 1);
678 : : }
679 : :
680 : : static inline u8 qm_dqrr_get_ci(struct qm_portal *portal)
681 : : {
682 : : register struct qm_dqrr *dqrr = &portal->dqrr;
683 : :
684 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
685 : : DPAA_ASSERT(dqrr->cmode != qm_dqrr_cdc);
686 : : #endif
687 : : return dqrr->ci;
688 : : }
689 : :
690 : : static inline void qm_dqrr_park(struct qm_portal *portal, u8 idx)
691 : : {
692 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
693 : :
694 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
695 : : DPAA_ASSERT(dqrr->cmode != qm_dqrr_cdc);
696 : : #endif
697 : : qm_out(DQRR_DCAP, (0 << 8) | /* S */
698 : : (1 << 6) | /* PK */
699 : : (idx & (QM_DQRR_SIZE - 1))); /* DCAP_CI */
700 : : }
701 : :
702 : : static inline void qm_dqrr_park_current(struct qm_portal *portal)
703 : : {
704 : : register struct qm_dqrr *dqrr = &portal->dqrr;
705 : :
706 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
707 : : DPAA_ASSERT(dqrr->cmode != qm_dqrr_cdc);
708 : : #endif
709 : : qm_out(DQRR_DCAP, (0 << 8) | /* S */
710 : : (1 << 6) | /* PK */
711 : : DQRR_PTR2IDX(dqrr->cursor)); /* DCAP_CI */
712 : : }
713 : :
714 : : static inline void qm_dqrr_sdqcr_set(struct qm_portal *portal, u32 sdqcr)
715 : : {
716 [ # # # # : 0 : qm_out(DQRR_SDQCR, sdqcr);
# # # # #
# # # ]
717 : 0 : }
718 : :
719 : : static inline u32 qm_dqrr_sdqcr_get(struct qm_portal *portal)
720 : : {
721 : : return qm_in(DQRR_SDQCR);
722 : : }
723 : :
724 : : static inline void qm_dqrr_vdqcr_set(struct qm_portal *portal, u32 vdqcr)
725 : : {
726 [ # # # # : 0 : qm_out(DQRR_VDQCR, vdqcr);
# # ]
727 : 0 : }
728 : :
729 : : static inline u32 qm_dqrr_vdqcr_get(struct qm_portal *portal)
730 : : {
731 : : return qm_in(DQRR_VDQCR);
732 : : }
733 : :
734 : : static inline u8 qm_dqrr_get_ithresh(struct qm_portal *portal)
735 : : {
736 : : register struct qm_dqrr *dqrr = &portal->dqrr;
737 : :
738 : : return dqrr->ithresh;
739 : : }
740 : :
741 : : static inline void qm_dqrr_set_ithresh(struct qm_portal *portal, u8 ithresh)
742 : : {
743 : 0 : qm_out(DQRR_ITR, ithresh);
744 : : }
745 : :
746 : : static inline u8 qm_dqrr_get_maxfill(struct qm_portal *portal)
747 : : {
748 : : return (qm_in(CFG) & 0x00f00000) >> 20;
749 : : }
750 : :
751 : : /* -------------- */
752 : : /* --- MR API --- */
753 : :
754 : : #define MR_CARRYCLEAR(p) \
755 : : (void *)((unsigned long)(p) & (~(unsigned long)(QM_MR_SIZE << 6)))
756 : :
757 : : static inline u8 MR_PTR2IDX(const struct qm_mr_entry *e)
758 : : {
759 : 0 : return ((uintptr_t)e >> 6) & (QM_MR_SIZE - 1);
760 : : }
761 : :
762 : : static inline const struct qm_mr_entry *MR_INC(const struct qm_mr_entry *e)
763 : : {
764 : 0 : return MR_CARRYCLEAR(e + 1);
765 : : }
766 : :
767 : 0 : static inline void qm_mr_finish(struct qm_portal *portal)
768 : : {
769 : : register struct qm_mr *mr = &portal->mr;
770 : :
771 [ # # ]: 0 : if (mr->ci != MR_PTR2IDX(mr->cursor))
772 : 0 : pr_crit("Ignoring completed MR entries\n");
773 : 0 : }
774 : :
775 : : static inline const struct qm_mr_entry *qm_mr_current(struct qm_portal *portal)
776 : : {
777 : : register struct qm_mr *mr = &portal->mr;
778 : :
779 [ # # # # : 0 : if (!mr->fill)
# # # # #
# # # # #
# # ]
780 : : return NULL;
781 [ # # # # : 0 : return mr->cursor;
# # # # ]
782 : : }
783 : :
784 : : static inline u8 qm_mr_next(struct qm_portal *portal)
785 : : {
786 : : register struct qm_mr *mr = &portal->mr;
787 : :
788 : : DPAA_ASSERT(mr->fill);
789 : 0 : mr->cursor = MR_INC(mr->cursor);
790 [ # # ]: 0 : return --mr->fill;
791 : : }
792 : :
793 : : static inline void qm_mr_cci_consume(struct qm_portal *portal, u8 num)
794 : : {
795 : : register struct qm_mr *mr = &portal->mr;
796 : :
797 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
798 : : DPAA_ASSERT(mr->cmode == qm_mr_cci);
799 : : #endif
800 : 0 : mr->ci = (mr->ci + num) & (QM_MR_SIZE - 1);
801 [ # # # # : 0 : qm_out(MR_CI_CINH, mr->ci);
# # ]
802 : 0 : }
803 : :
804 : : static inline void qm_mr_cci_consume_to_current(struct qm_portal *portal)
805 : : {
806 : : register struct qm_mr *mr = &portal->mr;
807 : :
808 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
809 : : DPAA_ASSERT(mr->cmode == qm_mr_cci);
810 : : #endif
811 : 0 : mr->ci = MR_PTR2IDX(mr->cursor);
812 [ # # # # ]: 0 : qm_out(MR_CI_CINH, mr->ci);
813 : : }
814 : :
815 : : static inline void qm_mr_set_ithresh(struct qm_portal *portal, u8 ithresh)
816 : : {
817 : 0 : qm_out(MR_ITR, ithresh);
818 : : }
819 : :
820 : : /* ------------------------------ */
821 : : /* --- Management command API --- */
822 : : static inline int qm_mc_init(struct qm_portal *portal)
823 : : {
824 : : register struct qm_mc *mc = &portal->mc;
825 : :
826 : 0 : mc->cr = portal->addr.ce + QM_CL_CR;
827 : 0 : mc->rr = portal->addr.ce + QM_CL_RR0;
828 : 0 : mc->rridx = (__raw_readb(&mc->cr->__dont_write_directly__verb) &
829 : 0 : QM_MCC_VERB_VBIT) ? 0 : 1;
830 [ # # # # ]: 0 : mc->vbit = mc->rridx ? QM_MCC_VERB_VBIT : 0;
831 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
832 : : mc->state = qman_mc_idle;
833 : : #endif
834 : : return 0;
835 : : }
836 : :
837 : : static inline void qm_mc_finish(struct qm_portal *portal)
838 : : {
839 : : __maybe_unused register struct qm_mc *mc = &portal->mc;
840 : :
841 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
842 : : DPAA_ASSERT(mc->state == qman_mc_idle);
843 : : if (mc->state != qman_mc_idle)
844 : : pr_crit("Losing incomplete MC command\n");
845 : : #endif
846 : : }
847 : :
848 : : static inline struct qm_mc_command *qm_mc_start(struct qm_portal *portal)
849 : : {
850 : : register struct qm_mc *mc = &portal->mc;
851 : :
852 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
853 : : DPAA_ASSERT(mc->state == qman_mc_idle);
854 : : mc->state = qman_mc_user;
855 : : #endif
856 : : dcbz_64(mc->cr);
857 [ # # # # : 0 : return mc->cr;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
858 : : }
859 : :
860 : : static inline void qm_mc_commit(struct qm_portal *portal, u8 myverb)
861 : : {
862 : : register struct qm_mc *mc = &portal->mc;
863 : : struct qm_mc_result *rr = mc->rr + mc->rridx;
864 : :
865 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
866 : : DPAA_ASSERT(mc->state == qman_mc_user);
867 : : #endif
868 : : lwsync();
869 : 0 : mc->cr->__dont_write_directly__verb = myverb | mc->vbit;
870 : : dcbf(mc->cr);
871 : : dcbit_ro(rr);
872 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
873 : : mc->state = qman_mc_hw;
874 : : #endif
875 : 0 : }
876 : :
877 : : static inline struct qm_mc_result *qm_mc_result(struct qm_portal *portal)
878 : : {
879 : : register struct qm_mc *mc = &portal->mc;
880 : 0 : struct qm_mc_result *rr = mc->rr + mc->rridx;
881 : :
882 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
883 : : DPAA_ASSERT(mc->state == qman_mc_hw);
884 : : #endif
885 : : /* The inactive response register's verb byte always returns zero until
886 : : * its command is submitted and completed. This includes the valid-bit,
887 : : * in case you were wondering.
888 : : */
889 [ # # # # : 0 : if (!__raw_readb(&rr->verb)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
890 : : dcbit_ro(rr);
891 : : return NULL;
892 : : }
893 : 0 : mc->rridx ^= 1;
894 [ # # # # : 0 : mc->vbit ^= QM_MCC_VERB_VBIT;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
895 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
896 : : mc->state = qman_mc_idle;
897 : : #endif
898 : 0 : return rr;
899 : : }
900 : :
901 : : /* Portal interrupt register API */
902 : : static inline void qm_isr_set_iperiod(struct qm_portal *portal, u16 iperiod)
903 : : {
904 : 0 : qm_out(ITPR, iperiod);
905 : : }
906 : :
907 : : static inline u32 __qm_isr_read(struct qm_portal *portal, enum qm_isr_reg n)
908 : : {
909 : : #if defined(RTE_ARCH_ARM64)
910 : : return __qm_in(&portal->addr, QM_REG_ISR + (n << 6));
911 : : #else
912 : 0 : return __qm_in(&portal->addr, QM_REG_ISR + (n << 2));
913 : : #endif
914 : : }
915 : :
916 : : static inline void __qm_isr_write(struct qm_portal *portal, enum qm_isr_reg n,
917 : : u32 val)
918 : : {
919 : : #if defined(RTE_ARCH_ARM64)
920 : : __qm_out(&portal->addr, QM_REG_ISR + (n << 6), val);
921 : : #else
922 [ # # # # : 0 : __qm_out(&portal->addr, QM_REG_ISR + (n << 2), val);
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
923 : : #endif
924 : : }
925 : :
926 : : static inline int qm_fqd_get_chan(const struct qm_fqd *fqd)
927 : : {
928 [ # # ]: 0 : return be16_to_cpu(fqd->dest_wq) >> QM_FQD_CHAN_OFF;
929 : : }
930 : :
931 : : static inline int qm_fqd_get_wq(const struct qm_fqd *fqd)
932 : : {
933 : : return be16_to_cpu(fqd->dest_wq) & QM_FQD_WQ_MASK;
934 : : }
|