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