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,2019-2025 NXP
5 : : *
6 : : */
7 : :
8 : : #include "qman.h"
9 : : #include <rte_branch_prediction.h>
10 : : #include <bus_dpaa_driver.h>
11 : : #include <rte_eventdev.h>
12 : : #include <rte_byteorder.h>
13 : : #include <rte_dpaa_logs.h>
14 : : #include <rte_stdatomic.h>
15 : : #include <eal_export.h>
16 : : #include <dpaa_bits.h>
17 : :
18 : : /* Compilation constants */
19 : : #define DQRR_MAXFILL 15
20 : : #define EQCR_ITHRESH 4 /* if EQCR congests, interrupt threshold */
21 : : #define IRQNAME "QMan portal %d"
22 : : #define MAX_IRQNAME 16 /* big enough for "QMan portal %d" */
23 : : /* maximum number of DQRR entries to process in qman_poll() */
24 : : #define FSL_QMAN_POLL_LIMIT 8
25 : :
26 : : /* Lock/unlock frame queues, subject to the "LOCKED" flag. This is about
27 : : * inter-processor locking only.
28 : : */
29 : : #define FQLOCK(fq) fq_lock(fq)
30 : : #define FQUNLOCK(fq) fq_unlock(fq)
31 : :
32 : : static qman_cb_free_mbuf qman_free_mbuf_cb;
33 : :
34 : : static inline void fq_set(struct qman_fq *fq, u32 mask)
35 : : {
36 : : dpaa_set_bits(mask, &fq->flags);
37 : 0 : }
38 : :
39 : : static inline void fq_clear(struct qman_fq *fq, u32 mask)
40 : : {
41 : : dpaa_clear_bits(mask, &fq->flags);
42 : 0 : }
43 : :
44 : : static inline int fq_isset(struct qman_fq *fq, u32 mask)
45 : : {
46 : 0 : return fq->flags & mask;
47 : : }
48 : :
49 : : static inline void fq_lock(struct qman_fq *fq)
50 : : __rte_acquire_capability(&fq->fqlock)
51 : : __rte_no_thread_safety_analysis
52 : : {
53 [ # # # # : 0 : if (fq_isset(fq, QMAN_FQ_FLAG_LOCKED))
# # # # #
# # # #
# ]
54 : 0 : spin_lock(&fq->fqlock);
55 : : }
56 : :
57 : : static inline void fq_unlock(struct qman_fq *fq)
58 : : __rte_release_capability(&fq->fqlock)
59 : : __rte_no_thread_safety_analysis
60 : : {
61 [ # # # # : 0 : if (fq_isset(fq, QMAN_FQ_FLAG_LOCKED))
# # # # #
# # # # #
# # ]
62 : 0 : spin_unlock(&fq->fqlock);
63 : : }
64 : :
65 : : static inline int fq_isclear(struct qman_fq *fq, u32 mask)
66 : : {
67 : 0 : return !(fq->flags & mask);
68 : : }
69 : :
70 : : struct qman_portal {
71 : : struct qm_portal p;
72 : : /* PORTAL_BITS_*** - dynamic, strictly internal */
73 : : unsigned long bits;
74 : : /* interrupt sources processed by portal_isr(), configurable */
75 : : unsigned long irq_sources;
76 : : u32 use_eqcr_ci_stashing;
77 : : /* only 1 volatile dequeue at a time */
78 : : struct qman_fq *vdqcr_owned;
79 : : u32 sdqcr;
80 : : int dqrr_disable_ref;
81 : : /* A portal-specific handler for DCP ERNs. If this is NULL, the global
82 : : * handler is called instead.
83 : : */
84 : : qman_cb_dc_ern cb_dc_ern;
85 : : /* When the cpu-affine portal is activated, this is non-NULL */
86 : : const struct qm_portal_config *config;
87 : : struct dpa_rbtree retire_table;
88 : : char irqname[MAX_IRQNAME];
89 : : /* 2-element array. cgrs[0] is mask, cgrs[1] is snapshot. */
90 : : struct qman_cgrs *cgrs;
91 : : /* linked-list of CSCN handlers. */
92 : : struct list_head cgr_cbs;
93 : : /* list lock */
94 : : spinlock_t cgr_lock;
95 : : /* track if memory was allocated by the driver */
96 : : #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
97 : : /* Keep a shadow copy of the DQRR on LE systems as the SW needs to
98 : : * do byte swaps of DQRR read only memory. First entry must be aligned
99 : : * to 2 ** 10 to ensure DQRR index calculations based shadow copy
100 : : * address (6 bits for address shift + 4 bits for the DQRR size).
101 : : */
102 : : alignas(1024) struct qm_dqrr_entry shadow_dqrr[QM_DQRR_SIZE];
103 : : #endif
104 : : };
105 : :
106 : : /* Global handler for DCP ERNs. Used when the portal receiving the message does
107 : : * not have a portal-specific handler.
108 : : */
109 : : static qman_cb_dc_ern cb_dc_ern;
110 : :
111 : : static cpumask_t affine_mask;
112 : : static DEFINE_SPINLOCK(affine_mask_lock);
113 : : static u16 affine_channels[NR_CPUS];
114 : : static RTE_DEFINE_PER_LCORE(struct qman_portal, qman_affine_portal);
115 : :
116 : : static inline struct qman_portal *get_affine_portal(void)
117 : : {
118 : : return &RTE_PER_LCORE(qman_affine_portal);
119 : : }
120 : :
121 : : /* This gives a FQID->FQ lookup to cover the fact that we can't directly demux
122 : : * retirement notifications (the fact they are sometimes h/w-consumed means that
123 : : * contextB isn't always a s/w demux - and as we can't know which case it is
124 : : * when looking at the notification, we have to use the slow lookup for all of
125 : : * them). NB, it's possible to have multiple FQ objects refer to the same FQID
126 : : * (though at most one of them should be the consumer), so this table isn't for
127 : : * all FQs - FQs are added when retirement commands are issued, and removed when
128 : : * they complete, which also massively reduces the size of this table.
129 : : */
130 [ # # # # : 0 : IMPLEMENT_DPAA_RBTREE(fqtree, struct qman_fq, node, fqid);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
131 : : /*
132 : : * This is what everything can wait on, even if it migrates to a different cpu
133 : : * to the one whose affine portal it is waiting on.
134 : : */
135 : : static DECLARE_WAIT_QUEUE_HEAD(affine_queue);
136 : :
137 : 0 : static inline int table_push_fq(struct qman_portal *p, struct qman_fq *fq)
138 : : {
139 : 0 : int ret = fqtree_push(&p->retire_table, fq);
140 : :
141 [ # # ]: 0 : if (ret)
142 : 0 : DPAA_BUS_ERR("ERROR: double FQ-retirement %d", fq->fqid);
143 : 0 : return ret;
144 : : }
145 : :
146 : : static inline void table_del_fq(struct qman_portal *p, struct qman_fq *fq)
147 : : {
148 : : fqtree_del(&p->retire_table, fq);
149 : : }
150 : :
151 : : static inline struct qman_fq *table_find_fq(struct qman_portal *p, u32 fqid)
152 : : {
153 : : return fqtree_find(&p->retire_table, fqid);
154 : : }
155 : :
156 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
157 : : static void **qman_fq_lookup_table;
158 : : static size_t qman_fq_lookup_table_size;
159 : :
160 : 0 : int qman_setup_fq_lookup_table(size_t num_entries)
161 : : {
162 : 0 : num_entries++;
163 : : /* Allocate 1 more entry since the first entry is not used */
164 : 0 : qman_fq_lookup_table = vmalloc((num_entries * sizeof(void *)));
165 [ # # ]: 0 : if (!qman_fq_lookup_table) {
166 : 0 : DPAA_BUS_ERR("QMan: Could not allocate fq lookup table");
167 : 0 : return -ENOMEM;
168 : : }
169 : : memset(qman_fq_lookup_table, 0, num_entries * sizeof(void *));
170 : 0 : qman_fq_lookup_table_size = num_entries;
171 : 0 : DPAA_BUS_ERR("QMan: Allocated lookup table at %p, entry count %lu",
172 : : qman_fq_lookup_table,
173 : : (unsigned long)qman_fq_lookup_table_size);
174 : 0 : return 0;
175 : : }
176 : :
177 : 0 : void qman_set_fq_lookup_table(void **fq_table)
178 : : {
179 : 0 : qman_fq_lookup_table = fq_table;
180 : 0 : }
181 : :
182 : : /* global structure that maintains fq object mapping */
183 : : static DEFINE_SPINLOCK(fq_hash_table_lock);
184 : :
185 : 0 : static int find_empty_fq_table_entry(u32 *entry, struct qman_fq *fq)
186 : : {
187 : : u32 i;
188 : :
189 : : spin_lock(&fq_hash_table_lock);
190 : : /* Can't use index zero because this has special meaning
191 : : * in context_b field.
192 : : */
193 [ # # ]: 0 : for (i = 1; i < qman_fq_lookup_table_size; i++) {
194 [ # # ]: 0 : if (qman_fq_lookup_table[i] == NULL) {
195 : 0 : *entry = i;
196 : 0 : qman_fq_lookup_table[i] = fq;
197 : : spin_unlock(&fq_hash_table_lock);
198 : 0 : return 0;
199 : : }
200 : : }
201 : : spin_unlock(&fq_hash_table_lock);
202 : 0 : return -ENOMEM;
203 : : }
204 : :
205 : 0 : static void clear_fq_table_entry(u32 entry)
206 : : {
207 : : spin_lock(&fq_hash_table_lock);
208 : : DPAA_BUG_ON(entry >= qman_fq_lookup_table_size);
209 : 0 : qman_fq_lookup_table[entry] = NULL;
210 : : spin_unlock(&fq_hash_table_lock);
211 : 0 : }
212 : :
213 : : static inline struct qman_fq *get_fq_table_entry(u32 entry)
214 : : {
215 : : DPAA_BUG_ON(entry >= qman_fq_lookup_table_size);
216 : 0 : return qman_fq_lookup_table[entry];
217 : : }
218 : : #endif
219 : :
220 : 0 : static inline void cpu_to_hw_fqd(struct qm_fqd *fqd)
221 : : {
222 : : /* Byteswap the FQD to HW format */
223 [ # # ]: 0 : fqd->fq_ctrl = cpu_to_be16(fqd->fq_ctrl);
224 [ # # ]: 0 : fqd->dest_wq = cpu_to_be16(fqd->dest_wq);
225 [ # # ]: 0 : fqd->ics_cred = cpu_to_be16(fqd->ics_cred);
226 [ # # ]: 0 : fqd->context_b = cpu_to_be32(fqd->context_b);
227 [ # # ]: 0 : fqd->context_a.opaque = cpu_to_be64(fqd->context_a.opaque);
228 [ # # ]: 0 : fqd->opaque_td = cpu_to_be16(fqd->opaque_td);
229 : 0 : }
230 : :
231 : 0 : static inline void hw_fqd_to_cpu(struct qm_fqd *fqd)
232 : : {
233 : : /* Byteswap the FQD to CPU format */
234 [ # # ]: 0 : fqd->fq_ctrl = be16_to_cpu(fqd->fq_ctrl);
235 [ # # ]: 0 : fqd->dest_wq = be16_to_cpu(fqd->dest_wq);
236 [ # # ]: 0 : fqd->ics_cred = be16_to_cpu(fqd->ics_cred);
237 [ # # ]: 0 : fqd->context_b = be32_to_cpu(fqd->context_b);
238 [ # # ]: 0 : fqd->context_a.opaque = be64_to_cpu(fqd->context_a.opaque);
239 : 0 : }
240 : :
241 : 0 : static inline void cpu_to_hw_fd(struct qm_fd *fd)
242 : : {
243 [ # # ]: 0 : fd->addr = cpu_to_be40(fd->addr);
244 [ # # ]: 0 : fd->status = cpu_to_be32(fd->status);
245 [ # # ]: 0 : fd->opaque = cpu_to_be32(fd->opaque);
246 : 0 : }
247 : :
248 : 0 : static inline void hw_fd_to_cpu(struct qm_fd *fd)
249 : : {
250 [ # # ]: 0 : fd->addr = be40_to_cpu(fd->addr);
251 [ # # ]: 0 : fd->status = be32_to_cpu(fd->status);
252 [ # # ]: 0 : fd->opaque = be32_to_cpu(fd->opaque);
253 : 0 : }
254 : :
255 : : /* In the case that slow- and fast-path handling are both done by qman_poll()
256 : : * (ie. because there is no interrupt handling), we ought to balance how often
257 : : * we do the fast-path poll versus the slow-path poll. We'll use two decrementer
258 : : * sources, so we call the fast poll 'n' times before calling the slow poll
259 : : * once. The idle decrementer constant is used when the last slow-poll detected
260 : : * no work to do, and the busy decrementer constant when the last slow-poll had
261 : : * work to do.
262 : : */
263 : : #define SLOW_POLL_IDLE 1000
264 : : #define SLOW_POLL_BUSY 10
265 : : static u32 __poll_portal_slow(struct qman_portal *p, u32 is);
266 : : static inline unsigned int __poll_portal_fast(struct qman_portal *p,
267 : : unsigned int poll_limit);
268 : :
269 : : /* Portal interrupt handler */
270 : 0 : static irqreturn_t portal_isr(__always_unused int irq, void *ptr)
271 : : {
272 : : struct qman_portal *p = ptr;
273 : : /*
274 : : * The CSCI/CCSCI source is cleared inside __poll_portal_slow(), because
275 : : * it could race against a Query Congestion State command also given
276 : : * as part of the handling of this interrupt source. We mustn't
277 : : * clear it a second time in this top-level function.
278 : : */
279 : 0 : u32 clear = QM_DQAVAIL_MASK | (p->irq_sources &
280 : : ~(QM_PIRQ_CSCI | QM_PIRQ_CCSCI));
281 : 0 : u32 is = qm_isr_status_read(&p->p) & p->irq_sources;
282 : : /* DQRR-handling if it's interrupt-driven */
283 [ # # ]: 0 : if (is & QM_PIRQ_DQRI)
284 : 0 : __poll_portal_fast(p, FSL_QMAN_POLL_LIMIT);
285 : : /* Handling of anything else that's interrupt-driven */
286 [ # # ]: 0 : clear |= __poll_portal_slow(p, is);
287 : : qm_isr_status_clear(&p->p, clear);
288 : 0 : return IRQ_HANDLED;
289 : : }
290 : :
291 : : /* This inner version is used privately by qman_create_affine_portal(), as well
292 : : * as by the exported qman_stop_dequeues().
293 : : */
294 : : static inline void qman_stop_dequeues_ex(struct qman_portal *p)
295 : : {
296 : 0 : if (!(p->dqrr_disable_ref++))
297 : : qm_dqrr_set_maxfill(&p->p, 0);
298 : : }
299 : :
300 : : static inline void qm_mr_pvb_update(struct qm_portal *portal)
301 : : {
302 : : register struct qm_mr *mr = &portal->mr;
303 : 0 : const struct qm_mr_entry *res = qm_cl(mr->ring, mr->pi);
304 : :
305 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
306 : : DPAA_ASSERT(mr->pmode == qm_mr_pvb);
307 : : #endif
308 : : /* when accessing 'verb', use __raw_readb() to ensure that compiler
309 : : * inlining doesn't try to optimise out "excess reads".
310 : : */
311 [ # # # # : 0 : if ((__raw_readb(&res->ern.verb) & QM_MR_VERB_VBIT) == mr->vbit) {
# # ]
312 : 0 : mr->pi = (mr->pi + 1) & (QM_MR_SIZE - 1);
313 [ # # # # : 0 : if (!mr->pi)
# # # # #
# # # #
# ]
314 : 0 : mr->vbit ^= QM_MR_VERB_VBIT;
315 : 0 : mr->fill++;
316 : : res = MR_INC(res);
317 : : }
318 : : dcbit_ro(res);
319 : : }
320 : :
321 : 0 : static int drain_mr_fqrni(struct qm_portal *p)
322 : : {
323 : : const struct qm_mr_entry *msg;
324 [ # # ]: 0 : loop:
325 : : qm_mr_pvb_update(p);
326 : : msg = qm_mr_current(p);
327 [ # # ]: 0 : if (!msg) {
328 : : /*
329 : : * if MR was full and h/w had other FQRNI entries to produce, we
330 : : * need to allow it time to produce those entries once the
331 : : * existing entries are consumed. A worst-case situation
332 : : * (fully-loaded system) means h/w sequencers may have to do 3-4
333 : : * other things before servicing the portal's MR pump, each of
334 : : * which (if slow) may take ~50 qman cycles (which is ~200
335 : : * processor cycles). So rounding up and then multiplying this
336 : : * worst-case estimate by a factor of 10, just to be
337 : : * ultra-paranoid, goes as high as 10,000 cycles. NB, we consume
338 : : * one entry at a time, so h/w has an opportunity to produce new
339 : : * entries well before the ring has been fully consumed, so
340 : : * we're being *really* paranoid here.
341 : : */
342 : : u64 now, then = mfatb();
343 : :
344 : : do {
345 : : now = mfatb();
346 [ # # ]: 0 : } while ((then + 10000) > now);
347 : : qm_mr_pvb_update(p);
348 : : msg = qm_mr_current(p);
349 [ # # ]: 0 : if (!msg)
350 : : return 0;
351 : : }
352 [ # # ]: 0 : if ((msg->ern.verb & QM_MR_VERB_TYPE_MASK) != QM_MR_VERB_FQRNI) {
353 : : /* We aren't draining anything but FQRNIs */
354 : 0 : DPAA_BUS_ERR("Found verb 0x%x and after mask = 0x%x in MR",
355 : : msg->ern.verb, msg->ern.verb & QM_MR_VERB_TYPE_MASK);
356 : 0 : return -1;
357 : : }
358 : : qm_mr_next(p);
359 : : qm_mr_cci_consume(p, 1);
360 : 0 : goto loop;
361 : : }
362 : :
363 : 0 : static inline int qm_eqcr_init(struct qm_portal *portal,
364 : : enum qm_eqcr_pmode pmode,
365 : : unsigned int eq_stash_thresh,
366 : : int eq_stash_prio)
367 : : {
368 : : /* This use of 'register', as well as all other occurrences, is because
369 : : * it has been observed to generate much faster code with gcc than is
370 : : * otherwise the case.
371 : : */
372 : : register struct qm_eqcr *eqcr = &portal->eqcr;
373 : : u32 cfg;
374 : : u8 pi;
375 : :
376 : 0 : eqcr->ring = portal->addr.ce + QM_CL_EQCR;
377 : 0 : eqcr->ci = qm_in(EQCR_CI_CINH) & (QM_EQCR_SIZE - 1);
378 : : qm_cl_invalidate(EQCR_CI);
379 : 0 : pi = qm_in(EQCR_PI_CINH) & (QM_EQCR_SIZE - 1);
380 : 0 : eqcr->cursor = eqcr->ring + pi;
381 [ # # # # ]: 0 : eqcr->vbit = (qm_in(EQCR_PI_CINH) & QM_EQCR_SIZE) ?
382 : : QM_EQCR_VERB_VBIT : 0;
383 : 0 : eqcr->available = QM_EQCR_SIZE - 1 -
384 : : qm_cyc_diff(QM_EQCR_SIZE, eqcr->ci, pi);
385 : 0 : eqcr->ithresh = qm_in(EQCR_ITR);
386 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
387 : : eqcr->busy = 0;
388 : : eqcr->pmode = pmode;
389 : : #endif
390 : 0 : cfg = (qm_in(CFG) & 0x00ffffff) |
391 : 0 : (eq_stash_thresh << 28) | /* QCSP_CFG: EST */
392 : 0 : (eq_stash_prio << 26) | /* QCSP_CFG: EP */
393 : 0 : ((pmode & 0x3) << 24); /* QCSP_CFG::EPM */
394 [ # # ]: 0 : qm_out(CFG, cfg);
395 : 0 : return 0;
396 : : }
397 : :
398 : 0 : static inline void qm_eqcr_finish(struct qm_portal *portal)
399 : : {
400 : : register struct qm_eqcr *eqcr = &portal->eqcr;
401 : : u8 pi, ci;
402 : : u32 cfg;
403 : :
404 : : /*
405 : : * Disable EQCI stashing because the QMan only
406 : : * presents the value it previously stashed to
407 : : * maintain coherency. Setting the stash threshold
408 : : * to 1 then 0 ensures that QMan has resyncronized
409 : : * its internal copy so that the portal is clean
410 : : * when it is reinitialized in the future
411 : : */
412 : 0 : cfg = (qm_in(CFG) & 0x0fffffff) |
413 : : (1 << 28); /* QCSP_CFG: EST */
414 [ # # ]: 0 : qm_out(CFG, cfg);
415 : : cfg &= 0x0fffffff; /* stash threshold = 0 */
416 [ # # ]: 0 : qm_out(CFG, cfg);
417 : :
418 : 0 : pi = qm_in(EQCR_PI_CINH) & (QM_EQCR_SIZE - 1);
419 : 0 : ci = qm_in(EQCR_CI_CINH) & (QM_EQCR_SIZE - 1);
420 : :
421 : : /* Refresh EQCR CI cache value */
422 : 0 : qm_cl_invalidate(EQCR_CI);
423 : 0 : eqcr->ci = qm_cl_in(EQCR_CI) & (QM_EQCR_SIZE - 1);
424 : :
425 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
426 : : DPAA_ASSERT(!eqcr->busy);
427 : : #endif
428 [ # # ]: 0 : if (pi != EQCR_PTR2IDX(eqcr->cursor))
429 : 0 : DPAA_BUS_ERR("losing uncommitted EQCR entries");
430 [ # # ]: 0 : if (ci != eqcr->ci)
431 : 0 : DPAA_BUS_ERR("missing existing EQCR completions");
432 [ # # ]: 0 : if (eqcr->ci != EQCR_PTR2IDX(eqcr->cursor))
433 : 0 : DPAA_BUS_ERR("EQCR destroyed unquiesced");
434 : 0 : }
435 : :
436 : 0 : static inline int qm_dqrr_init(struct qm_portal *portal,
437 : : __maybe_unused const struct qm_portal_config *config,
438 : : enum qm_dqrr_dmode dmode,
439 : : __maybe_unused enum qm_dqrr_pmode pmode,
440 : : enum qm_dqrr_cmode cmode, u8 max_fill)
441 : : {
442 : : register struct qm_dqrr *dqrr = &portal->dqrr;
443 : : u32 cfg;
444 : :
445 : : /* Make sure the DQRR will be idle when we enable */
446 : 0 : qm_out(DQRR_SDQCR, 0);
447 : 0 : qm_out(DQRR_VDQCR, 0);
448 : 0 : qm_out(DQRR_PDQCR, 0);
449 : 0 : dqrr->ring = portal->addr.ce + QM_CL_DQRR;
450 : 0 : dqrr->pi = qm_in(DQRR_PI_CINH) & (QM_DQRR_SIZE - 1);
451 : 0 : dqrr->ci = qm_in(DQRR_CI_CINH) & (QM_DQRR_SIZE - 1);
452 [ # # ]: 0 : dqrr->cursor = dqrr->ring + dqrr->ci;
453 : 0 : dqrr->fill = qm_cyc_diff(QM_DQRR_SIZE, dqrr->ci, dqrr->pi);
454 [ # # ]: 0 : dqrr->vbit = (qm_in(DQRR_PI_CINH) & QM_DQRR_SIZE) ?
455 : : QM_DQRR_VERB_VBIT : 0;
456 : 0 : dqrr->ithresh = qm_in(DQRR_ITR);
457 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
458 : : dqrr->dmode = dmode;
459 : : dqrr->pmode = pmode;
460 : : dqrr->cmode = cmode;
461 : : #endif
462 : : /* Invalidate every ring entry before beginning */
463 : : for (cfg = 0; cfg < QM_DQRR_SIZE; cfg++)
464 : : dccivac(qm_cl(dqrr->ring, cfg));
465 : 0 : cfg = (qm_in(CFG) & 0xff000f00) |
466 : 0 : ((max_fill & (QM_DQRR_SIZE - 1)) << 20) | /* DQRR_MF */
467 : 0 : ((dmode & 1) << 18) | /* DP */
468 : 0 : ((cmode & 3) << 16) | /* DCM */
469 : : 0xa0 | /* RE+SE */
470 : : (0 ? 0x40 : 0) | /* Ignore RP */
471 : : (0 ? 0x10 : 0); /* Ignore SP */
472 [ # # ]: 0 : qm_out(CFG, cfg);
473 : : qm_dqrr_set_maxfill(portal, max_fill);
474 : 0 : return 0;
475 : : }
476 : :
477 : : static inline void qm_dqrr_finish(struct qm_portal *portal)
478 : : {
479 : : __maybe_unused register struct qm_dqrr *dqrr = &portal->dqrr;
480 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
481 : : if ((dqrr->cmode != qm_dqrr_cdc) &&
482 : : (dqrr->ci != DQRR_PTR2IDX(dqrr->cursor)))
483 : : DPAA_BUS_WARN("Ignoring completed DQRR entries");
484 : : #endif
485 : : }
486 : :
487 : 0 : static inline int qm_mr_init(struct qm_portal *portal,
488 : : __maybe_unused enum qm_mr_pmode pmode,
489 : : enum qm_mr_cmode cmode)
490 : : {
491 : : register struct qm_mr *mr = &portal->mr;
492 : : u32 cfg;
493 : :
494 : 0 : mr->ring = portal->addr.ce + QM_CL_MR;
495 : 0 : mr->pi = qm_in(MR_PI_CINH) & (QM_MR_SIZE - 1);
496 : 0 : mr->ci = qm_in(MR_CI_CINH) & (QM_MR_SIZE - 1);
497 [ # # ]: 0 : mr->cursor = mr->ring + mr->ci;
498 : 0 : mr->fill = qm_cyc_diff(QM_MR_SIZE, mr->ci, mr->pi);
499 [ # # ]: 0 : mr->vbit = (qm_in(MR_PI_CINH) & QM_MR_SIZE) ? QM_MR_VERB_VBIT : 0;
500 : 0 : mr->ithresh = qm_in(MR_ITR);
501 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
502 : : mr->pmode = pmode;
503 : : mr->cmode = cmode;
504 : : #endif
505 : 0 : cfg = (qm_in(CFG) & 0xfffff0ff) |
506 : 0 : ((cmode & 1) << 8); /* QCSP_CFG:MM */
507 [ # # ]: 0 : qm_out(CFG, cfg);
508 : 0 : return 0;
509 : : }
510 : :
511 : : struct qman_portal *
512 : 0 : qman_init_portal(struct qman_portal *portal,
513 : : const struct qm_portal_config *c,
514 : : const struct qman_cgrs *cgrs)
515 : : {
516 : : struct qm_portal *p;
517 : : char buf[16];
518 : : int ret;
519 : : u32 isdr;
520 : :
521 : 0 : p = &portal->p;
522 : :
523 [ # # ]: 0 : if (!c)
524 : 0 : c = portal->config;
525 : :
526 [ # # ]: 0 : if (dpaa_soc_ver() == SVR_LS1043A_FAMILY) {
527 : 0 : portal->use_eqcr_ci_stashing = 3;
528 : : } else {
529 : 0 : portal->use_eqcr_ci_stashing =
530 : 0 : (qman_ip_rev >= QMAN_REV30 ? 1 : 0);
531 : : }
532 : :
533 : : /*
534 : : * prep the low-level portal struct with the mapped addresses from the
535 : : * config, everything that follows depends on it and "config" is more
536 : : * for (de)reference
537 : : */
538 : 0 : p->addr.ce = c->addr_virt[DPAA_PORTAL_CE];
539 : 0 : p->addr.ci = c->addr_virt[DPAA_PORTAL_CI];
540 : : /*
541 : : * If CI-stashing is used, the current defaults use a threshold of 3,
542 : : * and stash with high-than-DQRR priority.
543 : : */
544 [ # # ]: 0 : if (qm_eqcr_init(p, qm_eqcr_pvb,
545 : : portal->use_eqcr_ci_stashing, 1)) {
546 : 0 : DPAA_BUS_ERR("Qman EQCR initialisation failed");
547 : 0 : goto fail_eqcr;
548 : : }
549 [ # # ]: 0 : if (qm_dqrr_init(p, c, qm_dqrr_dpush, qm_dqrr_pvb,
550 : : qm_dqrr_cdc, DQRR_MAXFILL)) {
551 : 0 : DPAA_BUS_ERR("Qman DQRR initialisation failed");
552 : 0 : goto fail_dqrr;
553 : : }
554 [ # # ]: 0 : if (qm_mr_init(p, qm_mr_pvb, qm_mr_cci)) {
555 : 0 : DPAA_BUS_ERR("Qman MR initialisation failed");
556 : 0 : goto fail_mr;
557 : : }
558 : : if (qm_mc_init(p)) {
559 : : DPAA_BUS_ERR("Qman MC initialisation failed");
560 : : goto fail_mc;
561 : : }
562 : :
563 : : /* Reset portal before use */
564 : 0 : DPAA_BUS_DEBUG("Reset portal = %p", p);
565 : : qm_dqrr_sdqcr_set(p, 0);
566 : : qm_eqcr_cce_update(p);
567 : : qm_eqcr_cce_update(p);
568 : : qm_mc_finish(p);
569 : 0 : qm_mr_finish(p);
570 : : qm_dqrr_finish(p);
571 : 0 : qm_eqcr_finish(p);
572 : :
573 : 0 : p->addr.ce = c->addr_virt[DPAA_PORTAL_CE];
574 : 0 : p->addr.ci = c->addr_virt[DPAA_PORTAL_CI];
575 : : /*
576 : : * If CI-stashing is used, the current defaults use a threshold of 3,
577 : : * and stash with high-than-DQRR priority.
578 : : */
579 [ # # ]: 0 : if (qm_eqcr_init(p, qm_eqcr_pvb,
580 : : portal->use_eqcr_ci_stashing, 1)) {
581 : 0 : DPAA_BUS_ERR("Qman EQCR initialisation failed");
582 : 0 : goto fail_eqcr;
583 : : }
584 [ # # ]: 0 : if (qm_dqrr_init(p, c, qm_dqrr_dpush, qm_dqrr_pvb,
585 : : qm_dqrr_cdc, DQRR_MAXFILL)) {
586 : 0 : DPAA_BUS_ERR("Qman DQRR initialisation failed");
587 : 0 : goto fail_dqrr;
588 : : }
589 [ # # ]: 0 : if (qm_mr_init(p, qm_mr_pvb, qm_mr_cci)) {
590 : 0 : DPAA_BUS_ERR("Qman MR initialisation failed");
591 : 0 : goto fail_mr;
592 : : }
593 : : if (qm_mc_init(p)) {
594 : : DPAA_BUS_ERR("Qman MC initialisation failed");
595 : : goto fail_mc;
596 : : }
597 : :
598 : :
599 : : /* static interrupt-gating controls */
600 : : qm_dqrr_set_ithresh(p, 0);
601 : : qm_mr_set_ithresh(p, 0);
602 : : qm_isr_set_iperiod(p, 0);
603 : 0 : portal->cgrs = kmalloc(2 * sizeof(*cgrs), GFP_KERNEL);
604 [ # # ]: 0 : if (!portal->cgrs) {
605 : 0 : DPAA_BUS_ERR("CGRS allocation fails");
606 : 0 : goto fail_cgrs;
607 : : }
608 : : /* initial snapshot is no-depletion */
609 [ # # ]: 0 : qman_cgrs_init(&portal->cgrs[1]);
610 [ # # ]: 0 : if (cgrs)
611 : 0 : portal->cgrs[0] = *cgrs;
612 : : else
613 : : /* if the given mask is NULL, assume all CGRs can be seen */
614 : 0 : qman_cgrs_fill(&portal->cgrs[0]);
615 : 0 : INIT_LIST_HEAD(&portal->cgr_cbs);
616 : : spin_lock_init(&portal->cgr_lock);
617 : 0 : portal->bits = 0;
618 : 0 : portal->sdqcr = QM_SDQCR_SOURCE_CHANNELS | QM_SDQCR_COUNT_UPTO3 |
619 : : QM_SDQCR_DEDICATED_PRECEDENCE | QM_SDQCR_TYPE_PRIO_QOS |
620 : : QM_SDQCR_TOKEN_SET(0xab) | QM_SDQCR_CHANNELS_DEDICATED;
621 : 0 : portal->dqrr_disable_ref = 0;
622 : 0 : portal->cb_dc_ern = NULL;
623 : 0 : sprintf(buf, "qportal-%d", c->channel);
624 : 0 : DPAA_BUS_DEBUG("PORTAL ID = %d and %p", c->channel, p);
625 : : dpa_rbtree_init(&portal->retire_table);
626 : : isdr = 0xffffffff;
627 : : qm_isr_disable_write(p, isdr);
628 : 0 : portal->irq_sources = 0;
629 : : qm_isr_enable_write(p, portal->irq_sources);
630 : : qm_isr_status_clear(p, 0xffffffff);
631 : 0 : snprintf(portal->irqname, MAX_IRQNAME, IRQNAME, c->cpu);
632 [ # # ]: 0 : if (request_irq(c->irq, portal_isr, 0, portal->irqname,
633 : : portal)) {
634 : 0 : DPAA_BUS_ERR("request_irq() failed");
635 : 0 : goto fail_irq;
636 : : }
637 : :
638 : : /* Need EQCR to be empty before continuing */
639 : : isdr &= ~QM_PIRQ_EQCI;
640 : : qm_isr_disable_write(p, isdr);
641 : : ret = qm_eqcr_get_fill(p);
642 [ # # ]: 0 : if (ret) {
643 : 0 : DPAA_BUS_ERR("Qman EQCR unclean");
644 : 0 : goto fail_eqcr_empty;
645 : : }
646 : : isdr &= ~(QM_PIRQ_DQRI | QM_PIRQ_MRI);
647 : : qm_isr_disable_write(p, isdr);
648 [ # # ]: 0 : if (qm_dqrr_current(p)) {
649 : 0 : DPAA_BUS_ERR("Qman DQRR unclean");
650 : : qm_dqrr_cdc_consume_n(p, 0xffff);
651 : : }
652 [ # # # # ]: 0 : if (qm_mr_current(p) && drain_mr_fqrni(p)) {
653 : : /* special handling, drain just in case it's a few FQRNIs */
654 : 0 : DPAA_BUS_ERR("Draining MR FQRNI");
655 [ # # ]: 0 : if (drain_mr_fqrni(p)) {
656 : 0 : DPAA_BUS_ERR("Draining MR FQRNI fails");
657 : 0 : goto fail_dqrr_mr_empty;
658 : : }
659 : : }
660 : : /* Success */
661 [ # # ]: 0 : portal->config = c;
662 : : qm_isr_disable_write(p, 0);
663 : : qm_isr_uninhibit(p);
664 : : /* Write a sane SDQCR */
665 [ # # ]: 0 : qm_dqrr_sdqcr_set(p, portal->sdqcr);
666 : 0 : return portal;
667 : : fail_dqrr_mr_empty:
668 : 0 : fail_eqcr_empty:
669 : 0 : free_irq(c->irq, portal);
670 : 0 : fail_irq:
671 : 0 : kfree(portal->cgrs);
672 : : spin_lock_destroy(&portal->cgr_lock);
673 : 0 : fail_cgrs:
674 : : qm_mc_finish(p);
675 : : fail_mc:
676 : 0 : qm_mr_finish(p);
677 : : fail_mr:
678 : : qm_dqrr_finish(p);
679 : 0 : fail_dqrr:
680 : 0 : qm_eqcr_finish(p);
681 : : fail_eqcr:
682 : : return NULL;
683 : : }
684 : :
685 : : #define MAX_GLOBAL_PORTALS 8
686 : : static struct qman_portal global_portals[MAX_GLOBAL_PORTALS];
687 : : static RTE_ATOMIC(bool) global_portals_used[MAX_GLOBAL_PORTALS];
688 : :
689 : : struct qman_portal *
690 : 0 : qman_alloc_global_portal(struct qm_portal_config *q_pcfg)
691 : : {
692 : : unsigned int i;
693 : :
694 [ # # ]: 0 : for (i = 0; i < MAX_GLOBAL_PORTALS; i++) {
695 [ # # ]: 0 : if (!rte_atomic_exchange_explicit(&global_portals_used[i], true,
696 : : rte_memory_order_acquire)) {
697 : 0 : global_portals[i].config = q_pcfg;
698 : 0 : return &global_portals[i];
699 : : }
700 : : }
701 : 0 : DPAA_BUS_ERR("No portal available (%x)", MAX_GLOBAL_PORTALS);
702 : :
703 : 0 : return NULL;
704 : : }
705 : :
706 : : int
707 : 0 : qman_free_global_portal(struct qman_portal *portal)
708 : : {
709 : : unsigned int i;
710 : :
711 [ # # ]: 0 : for (i = 0; i < MAX_GLOBAL_PORTALS; i++) {
712 [ # # ]: 0 : if (&global_portals[i] == portal) {
713 : 0 : rte_atomic_store_explicit(&global_portals_used[i], false,
714 : : rte_memory_order_release);
715 : 0 : return 0;
716 : : }
717 : : }
718 : : return -1;
719 : : }
720 : :
721 : : void
722 : 0 : qman_portal_uninhibit_isr(struct qman_portal *portal)
723 : : {
724 : : qm_isr_uninhibit(&portal->p);
725 : 0 : }
726 : :
727 : 0 : struct qman_portal *qman_create_affine_portal(const struct qm_portal_config *c,
728 : : const struct qman_cgrs *cgrs)
729 : : {
730 : : struct qman_portal *res;
731 : : struct qman_portal *portal = get_affine_portal();
732 : :
733 : : /* A criteria for calling this function (from qman_driver.c) is that
734 : : * we're already affine to the cpu and won't schedule onto another cpu.
735 : : */
736 : 0 : res = qman_init_portal(portal, c, cgrs);
737 [ # # ]: 0 : if (res) {
738 : : spin_lock(&affine_mask_lock);
739 [ # # ]: 0 : CPU_SET(c->cpu, &affine_mask);
740 : 0 : affine_channels[c->cpu] =
741 : 0 : c->channel;
742 : : spin_unlock(&affine_mask_lock);
743 : : }
744 : 0 : return res;
745 : : }
746 : :
747 : : static inline
748 : 0 : void qman_destroy_portal(struct qman_portal *qm)
749 : : {
750 : : const struct qm_portal_config *pcfg;
751 : :
752 : : /* Stop dequeues on the portal */
753 : : qm_dqrr_sdqcr_set(&qm->p, 0);
754 : :
755 : : /*
756 : : * NB we do this to "quiesce" EQCR. If we add enqueue-completions or
757 : : * something related to QM_PIRQ_EQCI, this may need fixing.
758 : : * Also, due to the prefetching model used for CI updates in the enqueue
759 : : * path, this update will only invalidate the CI cacheline *after*
760 : : * working on it, so we need to call this twice to ensure a full update
761 : : * irrespective of where the enqueue processing was at when the teardown
762 : : * began.
763 : : */
764 : 0 : qm_eqcr_cce_update(&qm->p);
765 : : qm_eqcr_cce_update(&qm->p);
766 : 0 : pcfg = qm->config;
767 : :
768 : 0 : free_irq(pcfg->irq, qm);
769 : :
770 : 0 : kfree(qm->cgrs);
771 : : qm_mc_finish(&qm->p);
772 : 0 : qm_mr_finish(&qm->p);
773 : : qm_dqrr_finish(&qm->p);
774 : 0 : qm_eqcr_finish(&qm->p);
775 : :
776 : 0 : qm->config = NULL;
777 : :
778 : : spin_lock_destroy(&qm->cgr_lock);
779 : 0 : }
780 : :
781 : : const struct qm_portal_config *
782 : 0 : qman_destroy_affine_portal(struct qman_portal *qp)
783 : : {
784 : : /* We don't want to redirect if we're a slave, use "raw" */
785 : : struct qman_portal *qm;
786 : : const struct qm_portal_config *pcfg;
787 : : int cpu;
788 : :
789 [ # # ]: 0 : if (qp == NULL)
790 : : qm = get_affine_portal();
791 : : else
792 : : qm = qp;
793 : 0 : pcfg = qm->config;
794 : 0 : cpu = pcfg->cpu;
795 : :
796 : 0 : qman_destroy_portal(qm);
797 : :
798 : : spin_lock(&affine_mask_lock);
799 [ # # ]: 0 : CPU_CLR(cpu, &affine_mask);
800 : : spin_unlock(&affine_mask_lock);
801 : :
802 : 0 : qman_free_global_portal(qm);
803 : :
804 : 0 : return pcfg;
805 : : }
806 : :
807 : 0 : int qman_get_portal_index(void)
808 : : {
809 : : struct qman_portal *p = get_affine_portal();
810 : 0 : return p->config->index;
811 : : }
812 : :
813 : : /* Inline helper to reduce nesting in __poll_portal_slow() */
814 [ # # ]: 0 : static inline void fq_state_change(struct qman_portal *p, struct qman_fq *fq,
815 : : const struct qm_mr_entry *msg, u8 verb)
816 : : {
817 : : FQLOCK(fq);
818 [ # # # # ]: 0 : switch (verb) {
819 : : case QM_MR_VERB_FQRL:
820 : : DPAA_ASSERT(fq_isset(fq, QMAN_FQ_STATE_ORL));
821 : : fq_clear(fq, QMAN_FQ_STATE_ORL);
822 : : table_del_fq(p, fq);
823 : : break;
824 : : case QM_MR_VERB_FQRN:
825 : : DPAA_ASSERT((fq->state == qman_fq_state_parked) ||
826 : : (fq->state == qman_fq_state_sched));
827 : : DPAA_ASSERT(fq_isset(fq, QMAN_FQ_STATE_CHANGING));
828 : : fq_clear(fq, QMAN_FQ_STATE_CHANGING);
829 [ # # ]: 0 : if (msg->fq.fqs & QM_MR_FQS_NOTEMPTY)
830 : : fq_set(fq, QMAN_FQ_STATE_NE);
831 [ # # ]: 0 : if (msg->fq.fqs & QM_MR_FQS_ORLPRESENT)
832 : : fq_set(fq, QMAN_FQ_STATE_ORL);
833 : : else
834 : : table_del_fq(p, fq);
835 : 0 : fq->state = qman_fq_state_retired;
836 : 0 : break;
837 : 0 : case QM_MR_VERB_FQPN:
838 : : DPAA_ASSERT(fq->state == qman_fq_state_sched);
839 : : DPAA_ASSERT(fq_isclear(fq, QMAN_FQ_STATE_CHANGING));
840 : 0 : fq->state = qman_fq_state_parked;
841 : : }
842 : : FQUNLOCK(fq);
843 : 0 : }
844 : :
845 : : void
846 : 0 : qman_ern_register_cb(qman_cb_free_mbuf cb)
847 : : {
848 : 0 : qman_free_mbuf_cb = cb;
849 : 0 : }
850 : :
851 : :
852 : : void
853 [ # # ]: 0 : qman_ern_poll_free(void)
854 : : {
855 : : struct qman_portal *p = get_affine_portal();
856 : : u8 verb, num = 0;
857 : : const struct qm_mr_entry *msg;
858 : : const struct qm_fd *fd;
859 : : struct qm_mr_entry swapped_msg;
860 : :
861 : : qm_mr_pvb_update(&p->p);
862 : : msg = qm_mr_current(&p->p);
863 : :
864 [ # # ]: 0 : while (msg != NULL) {
865 : 0 : swapped_msg = *msg;
866 : 0 : hw_fd_to_cpu(&swapped_msg.ern.fd);
867 : 0 : verb = msg->ern.verb & QM_MR_VERB_TYPE_MASK;
868 : : fd = &swapped_msg.ern.fd;
869 : :
870 [ # # ]: 0 : if (unlikely(verb & 0x20)) {
871 : 0 : DPAA_BUS_WARN("HW ERN notification, Nothing to do");
872 : : } else {
873 [ # # ]: 0 : if ((fd->bpid & 0xff) != 0xff)
874 : 0 : qman_free_mbuf_cb(fd);
875 : : }
876 : :
877 [ # # ]: 0 : num++;
878 : : qm_mr_next(&p->p);
879 : : qm_mr_pvb_update(&p->p);
880 : : msg = qm_mr_current(&p->p);
881 : : }
882 : :
883 : : qm_mr_cci_consume(&p->p, num);
884 : 0 : }
885 : :
886 : 0 : static u32 __poll_portal_slow(struct qman_portal *p, u32 is)
887 : : {
888 : : const struct qm_mr_entry *msg;
889 : : struct qm_mr_entry swapped_msg;
890 : :
891 [ # # ]: 0 : if (is & QM_PIRQ_CSCI) {
892 : : struct qman_cgrs rr, c;
893 : : struct qm_mc_result *mcr;
894 : : struct qman_cgr *cgr;
895 : :
896 : 0 : spin_lock(&p->cgr_lock);
897 : : /*
898 : : * The CSCI bit must be cleared _before_ issuing the
899 : : * Query Congestion State command, to ensure that a long
900 : : * CGR State Change callback cannot miss an intervening
901 : : * state change.
902 : : */
903 : : qm_isr_status_clear(&p->p, QM_PIRQ_CSCI);
904 : : qm_mc_start(&p->p);
905 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYCONGESTION);
906 : : while (!(mcr = qm_mc_result(&p->p)))
907 : 0 : cpu_relax();
908 : : /* mask out the ones I'm not interested in */
909 : : qman_cgrs_and(&rr, (const struct qman_cgrs *)
910 : 0 : &mcr->querycongestion.state, &p->cgrs[0]);
911 : : /* check previous snapshot for delta, enter/exit congestion */
912 : : qman_cgrs_xor(&c, &rr, &p->cgrs[1]);
913 : : /* update snapshot */
914 : 0 : qman_cgrs_cp(&p->cgrs[1], &rr);
915 : : /* Invoke callback */
916 [ # # ]: 0 : list_for_each_entry(cgr, &p->cgr_cbs, node)
917 [ # # # # ]: 0 : if (cgr->cb && qman_cgrs_get(&c, cgr->cgrid))
918 : 0 : cgr->cb(p, cgr, qman_cgrs_get(&rr, cgr->cgrid));
919 : : spin_unlock(&p->cgr_lock);
920 : : }
921 : :
922 [ # # ]: 0 : if (is & QM_PIRQ_EQRI) {
923 : : qm_eqcr_cce_update(&p->p);
924 : : qm_eqcr_set_ithresh(&p->p, 0);
925 : : wake_up(&affine_queue);
926 : : }
927 : :
928 [ # # ]: 0 : if (is & QM_PIRQ_MRI) {
929 : : struct qman_fq *fq;
930 : : u8 verb, num = 0;
931 [ # # ]: 0 : mr_loop:
932 : : qm_mr_pvb_update(&p->p);
933 : : msg = qm_mr_current(&p->p);
934 [ # # ]: 0 : if (!msg)
935 [ # # ]: 0 : goto mr_done;
936 : 0 : swapped_msg = *msg;
937 : 0 : hw_fd_to_cpu(&swapped_msg.ern.fd);
938 : 0 : verb = msg->ern.verb & QM_MR_VERB_TYPE_MASK;
939 : : /* The message is a software ERN iff the 0x20 bit is set */
940 [ # # ]: 0 : if (verb & 0x20) {
941 [ # # # # : 0 : switch (verb) {
# ]
942 : : case QM_MR_VERB_FQRNI:
943 : : /* nada, we drop FQRNIs on the floor */
944 : : break;
945 : 0 : case QM_MR_VERB_FQRN:
946 : : case QM_MR_VERB_FQRL:
947 : : /* Lookup in the retirement table */
948 : 0 : fq = table_find_fq(p,
949 [ # # ]: 0 : be32_to_cpu(msg->fq.fqid));
950 : : DPAA_BUG_ON(fq != NULL);
951 : 0 : fq_state_change(p, fq, &swapped_msg, verb);
952 [ # # ]: 0 : if (fq->cb.fqs)
953 : 0 : fq->cb.fqs(p, fq, &swapped_msg);
954 : : break;
955 : 0 : case QM_MR_VERB_FQPN:
956 : : /* Parked */
957 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
958 : 0 : fq = get_fq_table_entry(msg->fq.contextB);
959 : : #else
960 : : fq = (void *)(uintptr_t)msg->fq.contextB;
961 : : #endif
962 : : DPAA_BUG_ON(fq != NULL);
963 : 0 : fq_state_change(p, fq, msg, verb);
964 [ # # ]: 0 : if (fq->cb.fqs)
965 : 0 : fq->cb.fqs(p, fq, &swapped_msg);
966 : : break;
967 : 0 : case QM_MR_VERB_DC_ERN:
968 : : /* DCP ERN */
969 [ # # ]: 0 : if (p->cb_dc_ern)
970 : 0 : p->cb_dc_ern(p, msg);
971 [ # # ]: 0 : else if (cb_dc_ern)
972 : 0 : cb_dc_ern(p, msg);
973 : : else {
974 : : static int warn_once;
975 : :
976 [ # # ]: 0 : if (!warn_once) {
977 : 0 : DPAA_BUS_WARN("Leaking DCP ERNs!");
978 : 0 : warn_once = 1;
979 : : }
980 : : }
981 : : break;
982 : 0 : default:
983 : 0 : DPAA_BUS_ERR("Invalid MR verb 0x%02x", verb);
984 : : }
985 : : } else {
986 : : /* Its a software ERN */
987 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
988 [ # # ]: 0 : fq = get_fq_table_entry(be32_to_cpu(msg->ern.tag));
989 : : #else
990 : : fq = (void *)(uintptr_t)be32_to_cpu(msg->ern.tag);
991 : : #endif
992 : 0 : fq->cb.ern(p, fq, &swapped_msg);
993 : : }
994 : 0 : num++;
995 : : qm_mr_next(&p->p);
996 : 0 : goto mr_loop;
997 : : mr_done:
998 : : qm_mr_cci_consume(&p->p, num);
999 : : }
1000 : : /*
1001 : : * QM_PIRQ_CSCI/CCSCI has already been cleared, as part of its specific
1002 : : * processing. If that interrupt source has meanwhile been re-asserted,
1003 : : * we mustn't clear it here (or in the top-level interrupt handler).
1004 : : */
1005 : 0 : return is & (QM_PIRQ_EQCI | QM_PIRQ_EQRI | QM_PIRQ_MRI);
1006 : : }
1007 : :
1008 : : /*
1009 : : * remove some slowish-path stuff from the "fast path" and make sure it isn't
1010 : : * inlined.
1011 : : */
1012 : 0 : static noinline void clear_vdqcr(struct qman_portal *p, struct qman_fq *fq)
1013 : : {
1014 [ # # ]: 0 : p->vdqcr_owned = NULL;
1015 : : FQLOCK(fq);
1016 : : fq_clear(fq, QMAN_FQ_STATE_VDQCR);
1017 : : FQUNLOCK(fq);
1018 : : wake_up(&affine_queue);
1019 : 0 : }
1020 : :
1021 : : /*
1022 : : * The only states that would conflict with other things if they ran at the
1023 : : * same time on the same cpu are:
1024 : : *
1025 : : * (i) setting/clearing vdqcr_owned, and
1026 : : * (ii) clearing the NE (Not Empty) flag.
1027 : : *
1028 : : * Both are safe. Because;
1029 : : *
1030 : : * (i) this clearing can only occur after qman_set_vdq() has set the
1031 : : * vdqcr_owned field (which it does before setting VDQCR), and
1032 : : * qman_volatile_dequeue() blocks interrupts and preemption while this is
1033 : : * done so that we can't interfere.
1034 : : * (ii) the NE flag is only cleared after qman_retire_fq() has set it, and as
1035 : : * with (i) that API prevents us from interfering until it's safe.
1036 : : *
1037 : : * The good thing is that qman_set_vdq() and qman_retire_fq() run far
1038 : : * less frequently (ie. per-FQ) than __poll_portal_fast() does, so the nett
1039 : : * advantage comes from this function not having to "lock" anything at all.
1040 : : *
1041 : : * Note also that the callbacks are invoked at points which are safe against the
1042 : : * above potential conflicts, but that this function itself is not re-entrant
1043 : : * (this is because the function tracks one end of each FIFO in the portal and
1044 : : * we do *not* want to lock that). So the consequence is that it is safe for
1045 : : * user callbacks to call into any QMan API.
1046 : : */
1047 : 0 : static inline unsigned int __poll_portal_fast(struct qman_portal *p,
1048 : : unsigned int poll_limit)
1049 : : {
1050 : : const struct qm_dqrr_entry *dq;
1051 : : struct qman_fq *fq;
1052 : : enum qman_cb_dqrr_result res;
1053 : : unsigned int limit = 0;
1054 : : #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1055 : : struct qm_dqrr_entry *shadow;
1056 : : #endif
1057 : : do {
1058 : : qm_dqrr_pvb_update(&p->p);
1059 : : dq = qm_dqrr_current(&p->p);
1060 [ # # ]: 0 : if (unlikely(!dq))
1061 : : break;
1062 : : #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1063 : : /* If running on an LE system the fields of the
1064 : : * dequeue entry must be swapper. Because the
1065 : : * QMan HW will ignore writes the DQRR entry is
1066 : : * copied and the index stored within the copy
1067 : : */
1068 : 0 : shadow = &p->shadow_dqrr[DQRR_PTR2IDX(dq)];
1069 : 0 : *shadow = *dq;
1070 : : dq = shadow;
1071 [ # # ]: 0 : shadow->fqid = be32_to_cpu(shadow->fqid);
1072 [ # # ]: 0 : shadow->seqnum = be16_to_cpu(shadow->seqnum);
1073 : 0 : hw_fd_to_cpu(&shadow->fd);
1074 : : #endif
1075 : :
1076 [ # # ]: 0 : if (dq->stat & QM_DQRR_STAT_UNSCHEDULED) {
1077 : : /*
1078 : : * VDQCR: don't trust context_b as the FQ may have
1079 : : * been configured for h/w consumption and we're
1080 : : * draining it post-retirement.
1081 : : */
1082 : 0 : fq = p->vdqcr_owned;
1083 : : /*
1084 : : * We only set QMAN_FQ_STATE_NE when retiring, so we
1085 : : * only need to check for clearing it when doing
1086 : : * volatile dequeues. It's one less thing to check
1087 : : * in the critical path (SDQCR).
1088 : : */
1089 [ # # ]: 0 : if (dq->stat & QM_DQRR_STAT_FQ_EMPTY)
1090 : : fq_clear(fq, QMAN_FQ_STATE_NE);
1091 : : /*
1092 : : * This is duplicated from the SDQCR code, but we
1093 : : * have stuff to do before *and* after this callback,
1094 : : * and we don't want multiple if()s in the critical
1095 : : * path (SDQCR).
1096 : : */
1097 : 0 : res = fq->cb.dqrr(p, fq, dq);
1098 [ # # ]: 0 : if (res == qman_cb_dqrr_stop)
1099 : : break;
1100 : : /* Check for VDQCR completion */
1101 [ # # ]: 0 : if (dq->stat & QM_DQRR_STAT_DQCR_EXPIRED)
1102 : 0 : clear_vdqcr(p, fq);
1103 : : } else {
1104 : : /* SDQCR: context_b points to the FQ */
1105 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
1106 : 0 : fq = get_fq_table_entry(dq->contextB);
1107 : : #else
1108 : : fq = (void *)(uintptr_t)dq->contextB;
1109 : : #endif
1110 : : /* Now let the callback do its stuff */
1111 : 0 : res = fq->cb.dqrr(p, fq, dq);
1112 : : /*
1113 : : * The callback can request that we exit without
1114 : : * consuming this entry nor advancing;
1115 : : */
1116 [ # # ]: 0 : if (res == qman_cb_dqrr_stop)
1117 : : break;
1118 : : }
1119 : : /* Interpret 'dq' from a driver perspective. */
1120 : : /*
1121 : : * Parking isn't possible unless HELDACTIVE was set. NB,
1122 : : * FORCEELIGIBLE implies HELDACTIVE, so we only need to
1123 : : * check for HELDACTIVE to cover both.
1124 : : */
1125 : : DPAA_ASSERT((dq->stat & QM_DQRR_STAT_FQ_HELDACTIVE) ||
1126 : : (res != qman_cb_dqrr_park));
1127 : : /* just means "skip it, I'll consume it myself later on" */
1128 [ # # ]: 0 : if (res != qman_cb_dqrr_defer)
1129 : : qm_dqrr_cdc_consume_1ptr(&p->p, dq,
1130 : : res == qman_cb_dqrr_park);
1131 : : /* Move forward */
1132 : : qm_dqrr_next(&p->p);
1133 : : /*
1134 : : * Entry processed and consumed, increment our counter. The
1135 : : * callback can request that we exit after consuming the
1136 : : * entry, and we also exit if we reach our processing limit,
1137 : : * so loop back only if neither of these conditions is met.
1138 : : */
1139 [ # # # # ]: 0 : } while (++limit < poll_limit && res != qman_cb_dqrr_consume_stop);
1140 : :
1141 : 0 : return limit;
1142 : : }
1143 : :
1144 : 0 : int qman_irqsource_add(u32 bits)
1145 : : {
1146 : : struct qman_portal *p = get_affine_portal();
1147 : :
1148 [ # # ]: 0 : bits = bits & QM_PIRQ_VISIBLE;
1149 : :
1150 : : /* Clear any previously remaining interrupt conditions in
1151 : : * QCSP_ISR. This prevents raising a false interrupt when
1152 : : * interrupt conditions are enabled in QCSP_IER.
1153 : : */
1154 : : qm_isr_status_clear(&p->p, bits);
1155 [ # # ]: 0 : dpaa_set_bits(bits, &p->irq_sources);
1156 [ # # ]: 0 : qm_isr_enable_write(&p->p, p->irq_sources);
1157 : :
1158 : 0 : return 0;
1159 : : }
1160 : :
1161 : 0 : int qman_fq_portal_irqsource_add(struct qman_portal *p, u32 bits)
1162 : : {
1163 [ # # ]: 0 : bits = bits & QM_PIRQ_VISIBLE;
1164 : :
1165 : : /* Clear any previously remaining interrupt conditions in
1166 : : * QCSP_ISR. This prevents raising a false interrupt when
1167 : : * interrupt conditions are enabled in QCSP_IER.
1168 : : */
1169 : : qm_isr_status_clear(&p->p, bits);
1170 [ # # ]: 0 : dpaa_set_bits(bits, &p->irq_sources);
1171 [ # # ]: 0 : qm_isr_enable_write(&p->p, p->irq_sources);
1172 : :
1173 : 0 : return 0;
1174 : : }
1175 : :
1176 : 0 : int qman_irqsource_remove(u32 bits)
1177 : : {
1178 : : struct qman_portal *p = get_affine_portal();
1179 : : u32 ier;
1180 : :
1181 : : /* Our interrupt handler only processes+clears status register bits that
1182 : : * are in p->irq_sources. As we're trimming that mask, if one of them
1183 : : * were to assert in the status register just before we remove it from
1184 : : * the enable register, there would be an interrupt-storm when we
1185 : : * release the IRQ lock. So we wait for the enable register update to
1186 : : * take effect in h/w (by reading it back) and then clear all other bits
1187 : : * in the status register. Ie. we clear them from ISR once it's certain
1188 : : * IER won't allow them to reassert.
1189 : : */
1190 : :
1191 : 0 : bits &= QM_PIRQ_VISIBLE;
1192 [ # # ]: 0 : dpaa_clear_bits(bits, &p->irq_sources);
1193 [ # # ]: 0 : qm_isr_enable_write(&p->p, p->irq_sources);
1194 : : ier = qm_isr_enable_read(&p->p);
1195 : : /* Using "~ier" (rather than "bits" or "~p->irq_sources") creates a
1196 : : * data-dependency, ie. to protect against re-ordering.
1197 : : */
1198 [ # # ]: 0 : qm_isr_status_clear(&p->p, ~ier);
1199 : 0 : return 0;
1200 : : }
1201 : :
1202 : 0 : int qman_fq_portal_irqsource_remove(struct qman_portal *p, u32 bits)
1203 : : {
1204 : : u32 ier;
1205 : :
1206 : : /* Our interrupt handler only processes+clears status register bits that
1207 : : * are in p->irq_sources. As we're trimming that mask, if one of them
1208 : : * were to assert in the status register just before we remove it from
1209 : : * the enable register, there would be an interrupt-storm when we
1210 : : * release the IRQ lock. So we wait for the enable register update to
1211 : : * take effect in h/w (by reading it back) and then clear all other bits
1212 : : * in the status register. Ie. we clear them from ISR once it's certain
1213 : : * IER won't allow them to reassert.
1214 : : */
1215 : :
1216 : 0 : bits &= QM_PIRQ_VISIBLE;
1217 [ # # ]: 0 : dpaa_clear_bits(bits, &p->irq_sources);
1218 [ # # ]: 0 : qm_isr_enable_write(&p->p, p->irq_sources);
1219 : : ier = qm_isr_enable_read(&p->p);
1220 : : /* Using "~ier" (rather than "bits" or "~p->irq_sources") creates a
1221 : : * data-dependency, ie. to protect against re-ordering.
1222 : : */
1223 [ # # ]: 0 : qm_isr_status_clear(&p->p, ~ier);
1224 : 0 : return 0;
1225 : : }
1226 : :
1227 : 0 : u16 qman_affine_channel(int cpu)
1228 : : {
1229 [ # # ]: 0 : if (cpu < 0) {
1230 : : struct qman_portal *portal = get_affine_portal();
1231 : :
1232 : 0 : cpu = portal->config->cpu;
1233 : : }
1234 : : DPAA_BUG_ON(!CPU_ISSET(cpu, &affine_mask));
1235 : 0 : return affine_channels[cpu];
1236 : : }
1237 : :
1238 : : uint32_t
1239 : 0 : qman_portal_poll_rx(uint32_t poll_limit, void **bufs,
1240 : : struct qman_portal *p, struct qman_fq_cb *cb)
1241 : : {
1242 : : struct qm_portal *portal = &p->p;
1243 : : register struct qm_dqrr *dqrr = &portal->dqrr;
1244 : : struct qm_dqrr_entry *dq[QM_DQRR_SIZE], *shadow[QM_DQRR_SIZE];
1245 : : struct qman_fq *fq[QM_DQRR_SIZE];
1246 : : unsigned int limit = 0, rx_number = 0;
1247 : : uint32_t consume = 0;
1248 : :
1249 : : do {
1250 : : qm_dqrr_pvb_update(&p->p);
1251 [ # # ]: 0 : if (!dqrr->fill)
1252 : : break;
1253 : :
1254 : 0 : dq[rx_number] = dqrr->cursor;
1255 : 0 : dqrr->cursor = DQRR_CARRYCLEAR(dqrr->cursor + 1);
1256 : : /* Prefetch the next DQRR entry */
1257 : : rte_prefetch0(dqrr->cursor);
1258 : :
1259 : : #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1260 : : /* If running on an LE system the fields of the
1261 : : * dequeue entry must be swapper. Because the
1262 : : * QMan HW will ignore writes the DQRR entry is
1263 : : * copied and the index stored within the copy
1264 : : */
1265 : 0 : shadow[rx_number] =
1266 : 0 : &p->shadow_dqrr[DQRR_PTR2IDX(dq[rx_number])];
1267 : 0 : shadow[rx_number]->fd.opaque_addr =
1268 : 0 : dq[rx_number]->fd.opaque_addr;
1269 : 0 : shadow[rx_number]->fd.addr =
1270 [ # # ]: 0 : be40_to_cpu(dq[rx_number]->fd.addr);
1271 : 0 : shadow[rx_number]->fd.opaque =
1272 [ # # ]: 0 : be32_to_cpu(dq[rx_number]->fd.opaque);
1273 : : #else
1274 : : shadow[rx_number] = dq[rx_number];
1275 : : #endif
1276 : :
1277 : : /* SDQCR: context_b points to the FQ */
1278 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
1279 : 0 : fq[rx_number] = qman_fq_lookup_table[dq[rx_number]->contextB];
1280 : : #else
1281 : : fq[rx_number] = (void *)dq[rx_number]->contextB;
1282 : : #endif
1283 [ # # ]: 0 : if (fq[rx_number]->cb.dqrr_prepare)
1284 : 0 : fq[rx_number]->cb.dqrr_prepare(shadow[rx_number],
1285 : 0 : &bufs[rx_number]);
1286 : :
1287 [ # # ]: 0 : consume |= (1 << (31 - DQRR_PTR2IDX(shadow[rx_number])));
1288 : 0 : rx_number++;
1289 : 0 : --dqrr->fill;
1290 [ # # ]: 0 : } while (++limit < poll_limit);
1291 : :
1292 [ # # ]: 0 : if (rx_number)
1293 : 0 : cb->dqrr_dpdk_pull_cb(fq, shadow, bufs, rx_number);
1294 : :
1295 : : /* Consume all the DQRR enries together */
1296 [ # # ]: 0 : qm_out(DQRR_DCAP, (1 << 8) | consume);
1297 : :
1298 : 0 : return rx_number;
1299 : : }
1300 : :
1301 : 0 : void qman_clear_irq(void)
1302 : : {
1303 : : struct qman_portal *p = get_affine_portal();
1304 [ # # ]: 0 : u32 clear = QM_DQAVAIL_MASK | (p->irq_sources &
1305 : : ~(QM_PIRQ_CSCI | QM_PIRQ_CCSCI));
1306 : : qm_isr_status_clear(&p->p, clear);
1307 : 0 : }
1308 : :
1309 : 0 : u32 qman_portal_dequeue(struct rte_event ev[], unsigned int poll_limit,
1310 : : void **bufs)
1311 : : {
1312 : : const struct qm_dqrr_entry *dq;
1313 : : struct qman_fq *fq;
1314 : : enum qman_cb_dqrr_result res;
1315 : : unsigned int limit = 0;
1316 : : struct qman_portal *p = get_affine_portal();
1317 : : #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1318 : : struct qm_dqrr_entry *shadow;
1319 : : #endif
1320 : : unsigned int rx_number = 0;
1321 : :
1322 : : do {
1323 : : qm_dqrr_pvb_update(&p->p);
1324 : : dq = qm_dqrr_current(&p->p);
1325 [ # # ]: 0 : if (!dq)
1326 : : break;
1327 : : #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1328 : : /*
1329 : : * If running on an LE system the fields of the
1330 : : * dequeue entry must be swapper. Because the
1331 : : * QMan HW will ignore writes the DQRR entry is
1332 : : * copied and the index stored within the copy
1333 : : */
1334 : 0 : shadow = &p->shadow_dqrr[DQRR_PTR2IDX(dq)];
1335 : 0 : *shadow = *dq;
1336 : : dq = shadow;
1337 [ # # ]: 0 : shadow->fqid = be32_to_cpu(shadow->fqid);
1338 [ # # ]: 0 : shadow->seqnum = be16_to_cpu(shadow->seqnum);
1339 : 0 : hw_fd_to_cpu(&shadow->fd);
1340 : : #endif
1341 : :
1342 : : /* SDQCR: context_b points to the FQ */
1343 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
1344 : 0 : fq = get_fq_table_entry(dq->contextB);
1345 : : #else
1346 : : fq = (void *)(uintptr_t)dq->contextB;
1347 : : #endif
1348 : : /* Now let the callback do its stuff */
1349 : 0 : res = fq->cb.dqrr_dpdk_cb(&ev[rx_number], p, fq,
1350 : 0 : dq, &bufs[rx_number]);
1351 : 0 : rx_number++;
1352 : : /* Interpret 'dq' from a driver perspective. */
1353 : : /*
1354 : : * Parking isn't possible unless HELDACTIVE was set. NB,
1355 : : * FORCEELIGIBLE implies HELDACTIVE, so we only need to
1356 : : * check for HELDACTIVE to cover both.
1357 : : */
1358 : : DPAA_ASSERT((dq->stat & QM_DQRR_STAT_FQ_HELDACTIVE) ||
1359 : : (res != qman_cb_dqrr_park));
1360 [ # # ]: 0 : if (res != qman_cb_dqrr_defer)
1361 : : qm_dqrr_cdc_consume_1ptr(&p->p, dq,
1362 : : res == qman_cb_dqrr_park);
1363 : : /* Move forward */
1364 : : qm_dqrr_next(&p->p);
1365 : : /*
1366 : : * Entry processed and consumed, increment our counter. The
1367 : : * callback can request that we exit after consuming the
1368 : : * entry, and we also exit if we reach our processing limit,
1369 : : * so loop back only if neither of these conditions is met.
1370 : : */
1371 [ # # ]: 0 : } while (++limit < poll_limit);
1372 : :
1373 : 0 : return limit;
1374 : : }
1375 : :
1376 [ # # ]: 0 : struct qm_dqrr_entry *qman_dequeue(struct qman_fq *fq)
1377 : : {
1378 : : struct qman_portal *p = get_affine_portal();
1379 : : const struct qm_dqrr_entry *dq;
1380 : : #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1381 : : struct qm_dqrr_entry *shadow;
1382 : : #endif
1383 : :
1384 : : qm_dqrr_pvb_update(&p->p);
1385 : : dq = qm_dqrr_current(&p->p);
1386 [ # # ]: 0 : if (!dq)
1387 : : return NULL;
1388 : :
1389 [ # # ]: 0 : if (!(dq->stat & QM_DQRR_STAT_FD_VALID)) {
1390 : : /* Invalid DQRR - put the portal and consume the DQRR.
1391 : : * Return NULL to user as no packet is seen.
1392 : : */
1393 : 0 : qman_dqrr_consume(fq, (struct qm_dqrr_entry *)dq);
1394 : 0 : return NULL;
1395 : : }
1396 : :
1397 : : #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1398 : 0 : shadow = &p->shadow_dqrr[DQRR_PTR2IDX(dq)];
1399 : 0 : *shadow = *dq;
1400 : : dq = shadow;
1401 [ # # ]: 0 : shadow->fqid = be32_to_cpu(shadow->fqid);
1402 [ # # ]: 0 : shadow->seqnum = be16_to_cpu(shadow->seqnum);
1403 : 0 : hw_fd_to_cpu(&shadow->fd);
1404 : : #endif
1405 : :
1406 [ # # ]: 0 : if (dq->stat & QM_DQRR_STAT_FQ_EMPTY)
1407 : : fq_clear(fq, QMAN_FQ_STATE_NE);
1408 : :
1409 : : return (struct qm_dqrr_entry *)dq;
1410 : : }
1411 : :
1412 : 0 : void qman_dqrr_consume(struct qman_fq *fq,
1413 : : struct qm_dqrr_entry *dq)
1414 : : {
1415 : : struct qman_portal *p = get_affine_portal();
1416 : :
1417 [ # # ]: 0 : if (dq->stat & QM_DQRR_STAT_DQCR_EXPIRED)
1418 : 0 : clear_vdqcr(p, fq);
1419 : :
1420 : : qm_dqrr_cdc_consume_1ptr(&p->p, dq, 0);
1421 : : qm_dqrr_next(&p->p);
1422 : 0 : }
1423 : :
1424 [ # # ]: 0 : void qman_stop_dequeues(void)
1425 : : {
1426 : : struct qman_portal *p = get_affine_portal();
1427 : :
1428 : : qman_stop_dequeues_ex(p);
1429 : 0 : }
1430 : :
1431 : 0 : void qman_start_dequeues(void)
1432 : : {
1433 : : struct qman_portal *p = get_affine_portal();
1434 : :
1435 : : DPAA_ASSERT(p->dqrr_disable_ref > 0);
1436 [ # # ]: 0 : if (!(--p->dqrr_disable_ref))
1437 : : qm_dqrr_set_maxfill(&p->p, DQRR_MAXFILL);
1438 : 0 : }
1439 : :
1440 : 0 : void qman_static_dequeue_add(u32 pools, struct qman_portal *qp)
1441 : : {
1442 [ # # ]: 0 : struct qman_portal *p = qp ? qp : get_affine_portal();
1443 : :
1444 : 0 : pools &= p->config->pools;
1445 [ # # ]: 0 : p->sdqcr |= pools;
1446 : : qm_dqrr_sdqcr_set(&p->p, p->sdqcr);
1447 : 0 : }
1448 : :
1449 : 0 : void qman_static_dequeue_del(u32 pools, struct qman_portal *qp)
1450 : : {
1451 [ # # ]: 0 : struct qman_portal *p = qp ? qp : get_affine_portal();
1452 : :
1453 : 0 : pools &= p->config->pools;
1454 [ # # ]: 0 : p->sdqcr &= ~pools;
1455 : : qm_dqrr_sdqcr_set(&p->p, p->sdqcr);
1456 : 0 : }
1457 : :
1458 : 0 : u32 qman_static_dequeue_get(struct qman_portal *qp)
1459 : : {
1460 [ # # ]: 0 : struct qman_portal *p = qp ? qp : get_affine_portal();
1461 : 0 : return p->sdqcr;
1462 : : }
1463 : :
1464 [ # # ]: 0 : void qman_dca(const struct qm_dqrr_entry *dq, int park_request)
1465 : : {
1466 : : struct qman_portal *p = get_affine_portal();
1467 : :
1468 : : qm_dqrr_cdc_consume_1ptr(&p->p, dq, park_request);
1469 : 0 : }
1470 : :
1471 : 0 : void qman_dca_index(u8 index, int park_request)
1472 : : {
1473 : : struct qman_portal *p = get_affine_portal();
1474 : :
1475 [ # # ]: 0 : qm_dqrr_cdc_consume_1(&p->p, index, park_request);
1476 : 0 : }
1477 : :
1478 : : /* Frame queue API */
1479 : : static const char *mcr_result_str(u8 result)
1480 : : {
1481 [ # # # # : 0 : switch (result) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1482 : : case QM_MCR_RESULT_NULL:
1483 : : return "QM_MCR_RESULT_NULL";
1484 : : case QM_MCR_RESULT_OK:
1485 : : return "QM_MCR_RESULT_OK";
1486 : 0 : case QM_MCR_RESULT_ERR_FQID:
1487 : 0 : return "QM_MCR_RESULT_ERR_FQID";
1488 : 0 : case QM_MCR_RESULT_ERR_FQSTATE:
1489 : 0 : return "QM_MCR_RESULT_ERR_FQSTATE";
1490 : 0 : case QM_MCR_RESULT_ERR_NOTEMPTY:
1491 : 0 : return "QM_MCR_RESULT_ERR_NOTEMPTY";
1492 : 0 : case QM_MCR_RESULT_PENDING:
1493 : 0 : return "QM_MCR_RESULT_PENDING";
1494 : 0 : case QM_MCR_RESULT_ERR_BADCOMMAND:
1495 : 0 : return "QM_MCR_RESULT_ERR_BADCOMMAND";
1496 : : }
1497 : 0 : return "<unknown MCR result>";
1498 : : }
1499 : :
1500 : 0 : int qman_create_fq(u32 fqid, u32 flags, struct qman_fq *fq)
1501 : : {
1502 : : struct qm_fqd fqd;
1503 : : struct qm_mcr_queryfq_np np;
1504 : : struct qm_mc_command *mcc;
1505 : : struct qm_mc_result *mcr;
1506 : : struct qman_portal *p;
1507 : :
1508 [ # # ]: 0 : if (flags & QMAN_FQ_FLAG_DYNAMIC_FQID) {
1509 : : int ret = qman_alloc_fqid(&fqid);
1510 : :
1511 [ # # ]: 0 : if (ret)
1512 : : return ret;
1513 : : }
1514 : : spin_lock_init(&fq->fqlock);
1515 : 0 : fq->fqid = fqid;
1516 [ # # ]: 0 : fq->fqid_be = cpu_to_be32(fqid);
1517 : 0 : fq->flags = flags;
1518 : 0 : fq->state = qman_fq_state_oos;
1519 : 0 : fq->cgr_groupid = 0;
1520 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
1521 [ # # ]: 0 : if (unlikely(find_empty_fq_table_entry(&fq->key, fq))) {
1522 : 0 : DPAA_BUS_ERR("Find empty table entry failed");
1523 : 0 : return -ENOMEM;
1524 : : }
1525 : 0 : fq->qman_fq_lookup_table = qman_fq_lookup_table;
1526 : : #endif
1527 [ # # ]: 0 : if (!(flags & QMAN_FQ_FLAG_AS_IS) || (flags & QMAN_FQ_FLAG_NO_MODIFY))
1528 : : return 0;
1529 : : /* Everything else is AS_IS support */
1530 : : p = get_affine_portal();
1531 : : mcc = qm_mc_start(&p->p);
1532 [ # # ]: 0 : mcc->queryfq.fqid = cpu_to_be32(fqid);
1533 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYFQ);
1534 : : while (!(mcr = qm_mc_result(&p->p)))
1535 : 0 : cpu_relax();
1536 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCC_VERB_QUERYFQ);
1537 [ # # ]: 0 : if (mcr->result != QM_MCR_RESULT_OK) {
1538 : 0 : DPAA_BUS_ERR("QUERYFQ failed: %s", mcr_result_str(mcr->result));
1539 : 0 : goto err;
1540 : : }
1541 : 0 : fqd = mcr->queryfq.fqd;
1542 : 0 : hw_fqd_to_cpu(&fqd);
1543 : : mcc = qm_mc_start(&p->p);
1544 [ # # ]: 0 : mcc->queryfq_np.fqid = cpu_to_be32(fqid);
1545 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYFQ_NP);
1546 : : while (!(mcr = qm_mc_result(&p->p)))
1547 : 0 : cpu_relax();
1548 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCC_VERB_QUERYFQ_NP);
1549 [ # # ]: 0 : if (mcr->result != QM_MCR_RESULT_OK) {
1550 : 0 : DPAA_BUS_ERR("QUERYFQ_NP failed: %s", mcr_result_str(mcr->result));
1551 : 0 : goto err;
1552 : : }
1553 : 0 : np = mcr->queryfq_np;
1554 : : /* Phew, have queryfq and queryfq_np results, stitch together
1555 : : * the FQ object from those.
1556 : : */
1557 : 0 : fq->cgr_groupid = fqd.cgid;
1558 [ # # # # ]: 0 : switch (np.state & QM_MCR_NP_STATE_MASK) {
1559 : : case QM_MCR_NP_STATE_OOS:
1560 : : break;
1561 : 0 : case QM_MCR_NP_STATE_RETIRED:
1562 : 0 : fq->state = qman_fq_state_retired;
1563 [ # # ]: 0 : if (np.frm_cnt)
1564 : : fq_set(fq, QMAN_FQ_STATE_NE);
1565 : : break;
1566 : 0 : case QM_MCR_NP_STATE_TEN_SCHED:
1567 : : case QM_MCR_NP_STATE_TRU_SCHED:
1568 : : case QM_MCR_NP_STATE_ACTIVE:
1569 : 0 : fq->state = qman_fq_state_sched;
1570 [ # # ]: 0 : if (np.state & QM_MCR_NP_STATE_R)
1571 : : fq_set(fq, QMAN_FQ_STATE_CHANGING);
1572 : : break;
1573 : 0 : case QM_MCR_NP_STATE_PARKED:
1574 : 0 : fq->state = qman_fq_state_parked;
1575 : 0 : break;
1576 : 0 : default:
1577 : : DPAA_ASSERT(NULL == "invalid FQ state");
1578 : : }
1579 [ # # ]: 0 : if (fqd.fq_ctrl & QM_FQCTRL_CGE)
1580 : 0 : fq->state |= QMAN_FQ_STATE_CGR_EN;
1581 : : return 0;
1582 : 0 : err:
1583 [ # # ]: 0 : if (flags & QMAN_FQ_FLAG_DYNAMIC_FQID)
1584 : 0 : qman_release_fqid(fqid);
1585 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
1586 : 0 : clear_fq_table_entry(fq->key);
1587 : : #endif
1588 : 0 : return -EIO;
1589 : : }
1590 : :
1591 : 0 : void qman_destroy_fq(struct qman_fq *fq, u32 flags __maybe_unused)
1592 : : {
1593 : : /*
1594 : : * We don't need to lock the FQ as it is a pre-condition that the FQ be
1595 : : * quiesced. Instead, run some checks.
1596 : : */
1597 [ # # ]: 0 : switch (fq->state) {
1598 : : case qman_fq_state_parked:
1599 : : DPAA_ASSERT(flags & QMAN_FQ_DESTROY_PARKED);
1600 : : /* Fallthrough */
1601 : : case qman_fq_state_oos:
1602 [ # # ]: 0 : if (fq_isset(fq, QMAN_FQ_FLAG_DYNAMIC_FQID))
1603 : 0 : qman_release_fqid(fq->fqid);
1604 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
1605 : 0 : clear_fq_table_entry(fq->key);
1606 : : #endif
1607 : 0 : return;
1608 : : default:
1609 : : break;
1610 : : }
1611 : : DPAA_ASSERT(NULL == "qman_free_fq() on unquiesced FQ!");
1612 : : }
1613 : :
1614 : 0 : u32 qman_fq_fqid(struct qman_fq *fq)
1615 : : {
1616 : 0 : return fq->fqid;
1617 : : }
1618 : :
1619 : 0 : void qman_fq_state(struct qman_fq *fq, enum qman_fq_state *state, u32 *flags)
1620 : : {
1621 [ # # ]: 0 : if (state)
1622 : 0 : *state = fq->state;
1623 [ # # ]: 0 : if (flags)
1624 : 0 : *flags = fq->flags;
1625 : 0 : }
1626 : :
1627 : 0 : int qman_init_fq(struct qman_fq *fq, u32 flags, struct qm_mcc_initfq *opts)
1628 : : {
1629 : : struct qm_mc_command *mcc;
1630 : : struct qm_mc_result *mcr;
1631 : : struct qman_portal *p;
1632 : :
1633 [ # # ]: 0 : u8 res, myverb = (flags & QMAN_INITFQ_FLAG_SCHED) ?
1634 : : QM_MCC_VERB_INITFQ_SCHED : QM_MCC_VERB_INITFQ_PARKED;
1635 : :
1636 [ # # ]: 0 : if ((fq->state != qman_fq_state_oos) &&
1637 : : (fq->state != qman_fq_state_parked))
1638 : : return -EINVAL;
1639 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
1640 : : if (unlikely(fq_isset(fq, QMAN_FQ_FLAG_NO_MODIFY)))
1641 : : return -EINVAL;
1642 : : #endif
1643 [ # # # # ]: 0 : if (opts && (opts->we_mask & QM_INITFQ_WE_OAC)) {
1644 : : /* And can't be set at the same time as TDTHRESH */
1645 [ # # ]: 0 : if (opts->we_mask & QM_INITFQ_WE_TDTHRESH)
1646 : : return -EINVAL;
1647 : : }
1648 : : /* Issue an INITFQ_[PARKED|SCHED] management command */
1649 : : p = get_affine_portal();
1650 : : FQLOCK(fq);
1651 [ # # # # ]: 0 : if (unlikely((fq_isset(fq, QMAN_FQ_STATE_CHANGING)) ||
1652 : : ((fq->state != qman_fq_state_oos) &&
1653 : : (fq->state != qman_fq_state_parked)))) {
1654 : : FQUNLOCK(fq);
1655 : 0 : return -EBUSY;
1656 : : }
1657 : : mcc = qm_mc_start(&p->p);
1658 [ # # ]: 0 : if (opts)
1659 : 0 : mcc->initfq = *opts;
1660 [ # # ]: 0 : mcc->initfq.fqid = cpu_to_be32(fq->fqid);
1661 : 0 : mcc->initfq.count = 0;
1662 : : /*
1663 : : * If the FQ does *not* have the TO_DCPORTAL flag, context_b is set as a
1664 : : * demux pointer. Otherwise, the caller-provided value is allowed to
1665 : : * stand, don't overwrite it.
1666 : : */
1667 [ # # ]: 0 : if (fq_isclear(fq, QMAN_FQ_FLAG_TO_DCPORTAL)) {
1668 : : dma_addr_t phys_fq;
1669 : :
1670 : 0 : mcc->initfq.we_mask |= QM_INITFQ_WE_CONTEXTB;
1671 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
1672 [ # # ]: 0 : mcc->initfq.fqd.context_b = cpu_to_be32(fq->key);
1673 : : #else
1674 : : mcc->initfq.fqd.context_b = (u32)(uintptr_t)fq;
1675 : : #endif
1676 : : /*
1677 : : * and the physical address - NB, if the user wasn't trying to
1678 : : * set CONTEXTA, clear the stashing settings.
1679 : : */
1680 [ # # ]: 0 : if (!(mcc->initfq.we_mask & QM_INITFQ_WE_CONTEXTA)) {
1681 : 0 : mcc->initfq.we_mask |= QM_INITFQ_WE_CONTEXTA;
1682 : 0 : memset(&mcc->initfq.fqd.context_a, 0,
1683 : : sizeof(mcc->initfq.fqd.context_a));
1684 : : } else {
1685 : 0 : phys_fq = rte_mem_virt2iova(fq);
1686 : : qm_fqd_stashing_set64(&mcc->initfq.fqd, phys_fq);
1687 : : }
1688 : : }
1689 [ # # ]: 0 : if (flags & QMAN_INITFQ_FLAG_LOCAL) {
1690 : 0 : mcc->initfq.fqd.dest.channel = p->config->channel;
1691 [ # # ]: 0 : if (!(mcc->initfq.we_mask & QM_INITFQ_WE_DESTWQ)) {
1692 : 0 : mcc->initfq.we_mask |= QM_INITFQ_WE_DESTWQ;
1693 : 0 : mcc->initfq.fqd.dest.wq = 4;
1694 : : }
1695 : : }
1696 [ # # ]: 0 : mcc->initfq.we_mask = cpu_to_be16(mcc->initfq.we_mask);
1697 : 0 : cpu_to_hw_fqd(&mcc->initfq.fqd);
1698 : : qm_mc_commit(&p->p, myverb);
1699 : : while (!(mcr = qm_mc_result(&p->p)))
1700 : 0 : cpu_relax();
1701 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == myverb);
1702 : 0 : res = mcr->result;
1703 [ # # ]: 0 : if (res != QM_MCR_RESULT_OK) {
1704 : : FQUNLOCK(fq);
1705 : 0 : return -EIO;
1706 : : }
1707 [ # # ]: 0 : if (opts) {
1708 [ # # ]: 0 : if (opts->we_mask & QM_INITFQ_WE_FQCTRL) {
1709 [ # # ]: 0 : if (opts->fqd.fq_ctrl & QM_FQCTRL_CGE)
1710 : : fq_set(fq, QMAN_FQ_STATE_CGR_EN);
1711 : : else
1712 : : fq_clear(fq, QMAN_FQ_STATE_CGR_EN);
1713 : : }
1714 [ # # ]: 0 : if (opts->we_mask & QM_INITFQ_WE_CGID)
1715 : 0 : fq->cgr_groupid = opts->fqd.cgid;
1716 : : }
1717 [ # # ]: 0 : fq->state = (flags & QMAN_INITFQ_FLAG_SCHED) ?
1718 [ # # ]: 0 : qman_fq_state_sched : qman_fq_state_parked;
1719 : : FQUNLOCK(fq);
1720 : : return 0;
1721 : : }
1722 : :
1723 : 0 : int qman_schedule_fq(struct qman_fq *fq)
1724 : : {
1725 : : struct qm_mc_command *mcc;
1726 : : struct qm_mc_result *mcr;
1727 : : struct qman_portal *p;
1728 : :
1729 : : int ret = 0;
1730 : : u8 res;
1731 : :
1732 [ # # ]: 0 : if (fq->state != qman_fq_state_parked)
1733 : : return -EINVAL;
1734 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
1735 : : if (unlikely(fq_isset(fq, QMAN_FQ_FLAG_NO_MODIFY)))
1736 : : return -EINVAL;
1737 : : #endif
1738 : : /* Issue a ALTERFQ_SCHED management command */
1739 : : p = get_affine_portal();
1740 : :
1741 : : FQLOCK(fq);
1742 [ # # # # ]: 0 : if (unlikely((fq_isset(fq, QMAN_FQ_STATE_CHANGING)) ||
1743 : : (fq->state != qman_fq_state_parked))) {
1744 : : ret = -EBUSY;
1745 : 0 : goto out;
1746 : : }
1747 : : mcc = qm_mc_start(&p->p);
1748 [ # # ]: 0 : mcc->alterfq.fqid = cpu_to_be32(fq->fqid);
1749 : : qm_mc_commit(&p->p, QM_MCC_VERB_ALTER_SCHED);
1750 : : while (!(mcr = qm_mc_result(&p->p)))
1751 : 0 : cpu_relax();
1752 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCR_VERB_ALTER_SCHED);
1753 : 0 : res = mcr->result;
1754 [ # # ]: 0 : if (res != QM_MCR_RESULT_OK) {
1755 : : ret = -EIO;
1756 : 0 : goto out;
1757 : : }
1758 : 0 : fq->state = qman_fq_state_sched;
1759 [ # # ]: 0 : out:
1760 : : FQUNLOCK(fq);
1761 : :
1762 : : return ret;
1763 : : }
1764 : :
1765 : 0 : int qman_retire_fq(struct qman_fq *fq, u32 *flags)
1766 : : {
1767 : : struct qm_mc_command *mcc;
1768 : : struct qm_mc_result *mcr;
1769 : : struct qman_portal *p;
1770 : :
1771 : : int rval;
1772 : : u8 res;
1773 : :
1774 : : /* Queue is already in retire or oos state */
1775 [ # # ]: 0 : if ((fq->state != qman_fq_state_parked) &&
1776 : : (fq->state != qman_fq_state_sched))
1777 : : return 0;
1778 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
1779 : : if (unlikely(fq_isset(fq, QMAN_FQ_FLAG_NO_MODIFY)))
1780 : : return -EINVAL;
1781 : : #endif
1782 : : p = get_affine_portal();
1783 : :
1784 : : FQLOCK(fq);
1785 [ # # # # : 0 : if (unlikely((fq_isset(fq, QMAN_FQ_STATE_CHANGING)) ||
# # ]
1786 : : (fq->state == qman_fq_state_retired) ||
1787 : : (fq->state == qman_fq_state_oos))) {
1788 : : rval = -EBUSY;
1789 : 0 : goto out;
1790 : : }
1791 : 0 : rval = table_push_fq(p, fq);
1792 [ # # ]: 0 : if (rval)
1793 : 0 : goto out;
1794 : : mcc = qm_mc_start(&p->p);
1795 [ # # ]: 0 : mcc->alterfq.fqid = cpu_to_be32(fq->fqid);
1796 : : qm_mc_commit(&p->p, QM_MCC_VERB_ALTER_RETIRE);
1797 : : while (!(mcr = qm_mc_result(&p->p)))
1798 : 0 : cpu_relax();
1799 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCR_VERB_ALTER_RETIRE);
1800 : 0 : res = mcr->result;
1801 : : /*
1802 : : * "Elegant" would be to treat OK/PENDING the same way; set CHANGING,
1803 : : * and defer the flags until FQRNI or FQRN (respectively) show up. But
1804 : : * "Friendly" is to process OK immediately, and not set CHANGING. We do
1805 : : * friendly, otherwise the caller doesn't necessarily have a fully
1806 : : * "retired" FQ on return even if the retirement was immediate. However
1807 : : * this does mean some code duplication between here and
1808 : : * fq_state_change().
1809 : : */
1810 [ # # ]: 0 : if (likely(res == QM_MCR_RESULT_OK)) {
1811 : : rval = 0;
1812 : : /* Process 'fq' right away, we'll ignore FQRNI */
1813 [ # # ]: 0 : if (mcr->alterfq.fqs & QM_MCR_FQS_NOTEMPTY)
1814 : : fq_set(fq, QMAN_FQ_STATE_NE);
1815 [ # # ]: 0 : if (mcr->alterfq.fqs & QM_MCR_FQS_ORLPRESENT)
1816 : : fq_set(fq, QMAN_FQ_STATE_ORL);
1817 : : else
1818 : : table_del_fq(p, fq);
1819 [ # # ]: 0 : if (flags)
1820 : 0 : *flags = fq->flags;
1821 : 0 : fq->state = qman_fq_state_retired;
1822 [ # # ]: 0 : if (fq->cb.fqs) {
1823 : : /*
1824 : : * Another issue with supporting "immediate" retirement
1825 : : * is that we're forced to drop FQRNIs, because by the
1826 : : * time they're seen it may already be "too late" (the
1827 : : * fq may have been OOS'd and free()'d already). But if
1828 : : * the upper layer wants a callback whether it's
1829 : : * immediate or not, we have to fake a "MR" entry to
1830 : : * look like an FQRNI...
1831 : : */
1832 : : struct qm_mr_entry msg;
1833 : :
1834 : 0 : msg.ern.verb = QM_MR_VERB_FQRNI;
1835 : 0 : msg.fq.fqs = mcr->alterfq.fqs;
1836 : 0 : msg.fq.fqid = fq->fqid;
1837 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
1838 : 0 : msg.fq.contextB = fq->key;
1839 : : #else
1840 : : msg.fq.contextB = (u32)(uintptr_t)fq;
1841 : : #endif
1842 : 0 : fq->cb.fqs(p, fq, &msg);
1843 : : }
1844 [ # # ]: 0 : } else if (res == QM_MCR_RESULT_PENDING) {
1845 : : rval = 1;
1846 : : fq_set(fq, QMAN_FQ_STATE_CHANGING);
1847 : : } else {
1848 : : rval = -EIO;
1849 : : table_del_fq(p, fq);
1850 : : }
1851 [ # # ]: 0 : out:
1852 : : FQUNLOCK(fq);
1853 : : /* Draining FQRNIs, if any */
1854 : 0 : drain_mr_fqrni(&p->p);
1855 : 0 : return rval;
1856 : : }
1857 : :
1858 : 0 : int qman_oos_fq(struct qman_fq *fq)
1859 : : {
1860 : : struct qm_mc_command *mcc;
1861 : : struct qm_mc_result *mcr;
1862 : : struct qman_portal *p;
1863 : :
1864 : : int ret = 0;
1865 : : u8 res;
1866 : :
1867 [ # # ]: 0 : if (fq->state != qman_fq_state_retired)
1868 : : return -EINVAL;
1869 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
1870 : : if (unlikely(fq_isset(fq, QMAN_FQ_FLAG_NO_MODIFY)))
1871 : : return -EINVAL;
1872 : : #endif
1873 : : p = get_affine_portal();
1874 : : FQLOCK(fq);
1875 [ # # # # ]: 0 : if (unlikely((fq_isset(fq, QMAN_FQ_STATE_BLOCKOOS)) ||
1876 : : (fq->state != qman_fq_state_retired))) {
1877 : : ret = -EBUSY;
1878 : 0 : goto out;
1879 : : }
1880 : : mcc = qm_mc_start(&p->p);
1881 [ # # ]: 0 : mcc->alterfq.fqid = cpu_to_be32(fq->fqid);
1882 : : qm_mc_commit(&p->p, QM_MCC_VERB_ALTER_OOS);
1883 : : while (!(mcr = qm_mc_result(&p->p)))
1884 : 0 : cpu_relax();
1885 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCR_VERB_ALTER_OOS);
1886 : 0 : res = mcr->result;
1887 [ # # ]: 0 : if (res != QM_MCR_RESULT_OK) {
1888 : : ret = -EIO;
1889 : 0 : goto out;
1890 : : }
1891 : 0 : fq->state = qman_fq_state_oos;
1892 [ # # ]: 0 : out:
1893 : : FQUNLOCK(fq);
1894 : : return ret;
1895 : : }
1896 : :
1897 : 0 : int qman_fq_flow_control(struct qman_fq *fq, int xon)
1898 : : {
1899 : : struct qm_mc_command *mcc;
1900 : : struct qm_mc_result *mcr;
1901 : : struct qman_portal *p;
1902 : :
1903 : : int ret = 0;
1904 : : u8 res;
1905 : : u8 myverb;
1906 : :
1907 [ # # ]: 0 : if ((fq->state == qman_fq_state_oos) ||
1908 [ # # ]: 0 : (fq->state == qman_fq_state_retired) ||
1909 : : (fq->state == qman_fq_state_parked))
1910 : : return -EINVAL;
1911 : :
1912 : : #ifdef RTE_LIBRTE_DPAA_HWDEBUG
1913 : : if (unlikely(fq_isset(fq, QMAN_FQ_FLAG_NO_MODIFY)))
1914 : : return -EINVAL;
1915 : : #endif
1916 : : /* Issue a ALTER_FQXON or ALTER_FQXOFF management command */
1917 : : p = get_affine_portal();
1918 : : FQLOCK(fq);
1919 [ # # # # : 0 : if (unlikely((fq_isset(fq, QMAN_FQ_STATE_CHANGING)) ||
# # # # ]
1920 : : (fq->state == qman_fq_state_parked) ||
1921 : : (fq->state == qman_fq_state_oos) ||
1922 : : (fq->state == qman_fq_state_retired))) {
1923 : : ret = -EBUSY;
1924 : 0 : goto out;
1925 : : }
1926 : : mcc = qm_mc_start(&p->p);
1927 : 0 : mcc->alterfq.fqid = fq->fqid_be;
1928 : 0 : mcc->alterfq.count = 0;
1929 [ # # ]: 0 : myverb = xon ? QM_MCC_VERB_ALTER_FQXON : QM_MCC_VERB_ALTER_FQXOFF;
1930 : :
1931 : : qm_mc_commit(&p->p, myverb);
1932 : : while (!(mcr = qm_mc_result(&p->p)))
1933 : 0 : cpu_relax();
1934 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == myverb);
1935 : :
1936 : 0 : res = mcr->result;
1937 [ # # ]: 0 : if (res != QM_MCR_RESULT_OK) {
1938 : : ret = -EIO;
1939 : 0 : goto out;
1940 : : }
1941 [ # # ]: 0 : out:
1942 : : FQUNLOCK(fq);
1943 : : return ret;
1944 : : }
1945 : :
1946 [ # # ]: 0 : int qman_query_fq(struct qman_fq *fq, struct qm_fqd *fqd)
1947 : : {
1948 : : struct qm_mc_command *mcc;
1949 : : struct qm_mc_result *mcr;
1950 : : struct qman_portal *p = get_affine_portal();
1951 : :
1952 : : u8 res;
1953 : :
1954 : : mcc = qm_mc_start(&p->p);
1955 [ # # ]: 0 : mcc->queryfq.fqid = cpu_to_be32(fq->fqid);
1956 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYFQ);
1957 : : while (!(mcr = qm_mc_result(&p->p)))
1958 : 0 : cpu_relax();
1959 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCR_VERB_QUERYFQ);
1960 : 0 : res = mcr->result;
1961 [ # # ]: 0 : if (res != QM_MCR_RESULT_OK)
1962 : : return -EIO;
1963 : :
1964 : 0 : *fqd = mcr->queryfq.fqd;
1965 : 0 : hw_fqd_to_cpu(fqd);
1966 : 0 : return 0;
1967 : : }
1968 : :
1969 [ # # ]: 0 : int qman_query_fq_has_pkts(struct qman_fq *fq)
1970 : : {
1971 : : struct qm_mc_command *mcc;
1972 : : struct qm_mc_result *mcr;
1973 : : struct qman_portal *p = get_affine_portal();
1974 : :
1975 : : int ret = 0;
1976 : : u8 res;
1977 : :
1978 : : mcc = qm_mc_start(&p->p);
1979 [ # # ]: 0 : mcc->queryfq.fqid = cpu_to_be32(fq->fqid);
1980 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYFQ_NP);
1981 : : while (!(mcr = qm_mc_result(&p->p)))
1982 : 0 : cpu_relax();
1983 : 0 : res = mcr->result;
1984 [ # # ]: 0 : if (res == QM_MCR_RESULT_OK)
1985 : 0 : ret = !!mcr->queryfq_np.frm_cnt;
1986 : 0 : return ret;
1987 : : }
1988 : :
1989 [ # # ]: 0 : int qman_query_fq_np(struct qman_fq *fq, struct qm_mcr_queryfq_np *np)
1990 : : {
1991 : : struct qm_mc_command *mcc;
1992 : : struct qm_mc_result *mcr;
1993 : : struct qman_portal *p = get_affine_portal();
1994 : :
1995 : : u8 res;
1996 : :
1997 : : mcc = qm_mc_start(&p->p);
1998 [ # # ]: 0 : mcc->queryfq.fqid = cpu_to_be32(fq->fqid);
1999 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYFQ_NP);
2000 : : while (!(mcr = qm_mc_result(&p->p)))
2001 : 0 : cpu_relax();
2002 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCR_VERB_QUERYFQ_NP);
2003 : 0 : res = mcr->result;
2004 [ # # ]: 0 : if (res == QM_MCR_RESULT_OK) {
2005 : 0 : *np = mcr->queryfq_np;
2006 [ # # ]: 0 : np->fqd_link = be24_to_cpu(np->fqd_link);
2007 [ # # ]: 0 : np->odp_seq = be16_to_cpu(np->odp_seq);
2008 [ # # ]: 0 : np->orp_nesn = be16_to_cpu(np->orp_nesn);
2009 [ # # ]: 0 : np->orp_ea_hseq = be16_to_cpu(np->orp_ea_hseq);
2010 [ # # ]: 0 : np->orp_ea_tseq = be16_to_cpu(np->orp_ea_tseq);
2011 [ # # ]: 0 : np->orp_ea_hptr = be24_to_cpu(np->orp_ea_hptr);
2012 : 0 : np->orp_ea_tptr = be24_to_cpu(np->orp_ea_tptr);
2013 : 0 : np->pfdr_hptr = be24_to_cpu(np->pfdr_hptr);
2014 : 0 : np->pfdr_tptr = be24_to_cpu(np->pfdr_tptr);
2015 [ # # ]: 0 : np->ics_surp = be16_to_cpu(np->ics_surp);
2016 [ # # ]: 0 : np->byte_cnt = be32_to_cpu(np->byte_cnt);
2017 [ # # ]: 0 : np->frm_cnt = be24_to_cpu(np->frm_cnt);
2018 [ # # ]: 0 : np->ra1_sfdr = be16_to_cpu(np->ra1_sfdr);
2019 [ # # ]: 0 : np->ra2_sfdr = be16_to_cpu(np->ra2_sfdr);
2020 [ # # ]: 0 : np->od1_sfdr = be16_to_cpu(np->od1_sfdr);
2021 [ # # ]: 0 : np->od2_sfdr = be16_to_cpu(np->od2_sfdr);
2022 [ # # ]: 0 : np->od3_sfdr = be16_to_cpu(np->od3_sfdr);
2023 : : }
2024 [ # # ]: 0 : if (res == QM_MCR_RESULT_ERR_FQID)
2025 : : return -ERANGE;
2026 [ # # ]: 0 : else if (res != QM_MCR_RESULT_OK)
2027 : 0 : return -EIO;
2028 : : return 0;
2029 : : }
2030 : :
2031 [ # # ]: 0 : int qman_query_fq_frm_cnt(struct qman_fq *fq, u32 *frm_cnt)
2032 : : {
2033 : : struct qm_mc_command *mcc;
2034 : : struct qm_mc_result *mcr;
2035 : : struct qman_portal *p = get_affine_portal();
2036 : :
2037 : : mcc = qm_mc_start(&p->p);
2038 [ # # ]: 0 : mcc->queryfq.fqid = cpu_to_be32(fq->fqid);
2039 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYFQ_NP);
2040 : : while (!(mcr = qm_mc_result(&p->p)))
2041 : 0 : cpu_relax();
2042 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCR_VERB_QUERYFQ_NP);
2043 : :
2044 [ # # ]: 0 : if (mcr->result == QM_MCR_RESULT_OK)
2045 : 0 : *frm_cnt = be24_to_cpu(mcr->queryfq_np.frm_cnt);
2046 [ # # ]: 0 : else if (mcr->result == QM_MCR_RESULT_ERR_FQID)
2047 : : return -ERANGE;
2048 : : else if (mcr->result != QM_MCR_RESULT_OK)
2049 : 0 : return -EIO;
2050 : 0 : return 0;
2051 : : }
2052 : :
2053 : 0 : int qman_query_wq(u8 query_dedicated, struct qm_mcr_querywq *wq)
2054 : : {
2055 : : struct qm_mc_command *mcc;
2056 : : struct qm_mc_result *mcr;
2057 : : struct qman_portal *p = get_affine_portal();
2058 : :
2059 : : u8 res, myverb;
2060 : :
2061 [ # # ]: 0 : myverb = (query_dedicated) ? QM_MCR_VERB_QUERYWQ_DEDICATED :
2062 : : QM_MCR_VERB_QUERYWQ;
2063 : : mcc = qm_mc_start(&p->p);
2064 [ # # ]: 0 : mcc->querywq.channel.id = cpu_to_be16(wq->channel.id);
2065 : : qm_mc_commit(&p->p, myverb);
2066 : : while (!(mcr = qm_mc_result(&p->p)))
2067 : 0 : cpu_relax();
2068 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == myverb);
2069 : 0 : res = mcr->result;
2070 [ # # ]: 0 : if (res == QM_MCR_RESULT_OK) {
2071 : : int i, array_len;
2072 : :
2073 [ # # ]: 0 : wq->channel.id = be16_to_cpu(mcr->querywq.channel.id);
2074 : : array_len = ARRAY_SIZE(mcr->querywq.wq_len);
2075 [ # # ]: 0 : for (i = 0; i < array_len; i++)
2076 [ # # ]: 0 : wq->wq_len[i] = be32_to_cpu(mcr->querywq.wq_len[i]);
2077 : : }
2078 [ # # ]: 0 : if (res != QM_MCR_RESULT_OK) {
2079 : 0 : DPAA_BUS_ERR("QUERYWQ failed: %s", mcr_result_str(res));
2080 : 0 : return -EIO;
2081 : : }
2082 : : return 0;
2083 : : }
2084 : :
2085 : 0 : int qman_testwrite_cgr(struct qman_cgr *cgr, u64 i_bcnt,
2086 : : struct qm_mcr_cgrtestwrite *result)
2087 : : {
2088 : : struct qm_mc_command *mcc;
2089 : : struct qm_mc_result *mcr;
2090 : : struct qman_portal *p = get_affine_portal();
2091 : :
2092 : : u8 res;
2093 : :
2094 : : mcc = qm_mc_start(&p->p);
2095 : 0 : mcc->cgrtestwrite.cgid = cgr->cgrid;
2096 : 0 : mcc->cgrtestwrite.i_bcnt_hi = (u8)(i_bcnt >> 32);
2097 : 0 : mcc->cgrtestwrite.i_bcnt_lo = (u32)i_bcnt;
2098 : : qm_mc_commit(&p->p, QM_MCC_VERB_CGRTESTWRITE);
2099 : : while (!(mcr = qm_mc_result(&p->p)))
2100 : 0 : cpu_relax();
2101 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCC_VERB_CGRTESTWRITE);
2102 : 0 : res = mcr->result;
2103 [ # # ]: 0 : if (res == QM_MCR_RESULT_OK)
2104 : 0 : *result = mcr->cgrtestwrite;
2105 [ # # ]: 0 : if (res != QM_MCR_RESULT_OK) {
2106 : 0 : DPAA_BUS_ERR("CGR TEST WRITE failed: %s", mcr_result_str(res));
2107 : 0 : return -EIO;
2108 : : }
2109 : : return 0;
2110 : : }
2111 : :
2112 : 0 : int qman_query_cgr(struct qman_cgr *cgr, struct qm_mcr_querycgr *cgrd)
2113 : : {
2114 : : struct qm_mc_command *mcc;
2115 : : struct qm_mc_result *mcr;
2116 : : struct qman_portal *p = get_affine_portal();
2117 : : u8 res;
2118 : : unsigned int i;
2119 : :
2120 : : mcc = qm_mc_start(&p->p);
2121 : 0 : mcc->querycgr.cgid = cgr->cgrid;
2122 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYCGR);
2123 : : while (!(mcr = qm_mc_result(&p->p)))
2124 : 0 : cpu_relax();
2125 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == QM_MCC_VERB_QUERYCGR);
2126 : 0 : res = mcr->result;
2127 [ # # ]: 0 : if (res == QM_MCR_RESULT_OK)
2128 : 0 : *cgrd = mcr->querycgr;
2129 [ # # ]: 0 : if (res != QM_MCR_RESULT_OK) {
2130 : 0 : DPAA_BUS_ERR("QUERY_CGR failed: %s", mcr_result_str(res));
2131 : 0 : return -EIO;
2132 : : }
2133 : 0 : cgrd->cgr.wr_parm_g.word =
2134 [ # # ]: 0 : be32_to_cpu(cgrd->cgr.wr_parm_g.word);
2135 : 0 : cgrd->cgr.wr_parm_y.word =
2136 [ # # ]: 0 : be32_to_cpu(cgrd->cgr.wr_parm_y.word);
2137 : 0 : cgrd->cgr.wr_parm_r.word =
2138 [ # # ]: 0 : be32_to_cpu(cgrd->cgr.wr_parm_r.word);
2139 [ # # ]: 0 : cgrd->cgr.cscn_targ = be32_to_cpu(cgrd->cgr.cscn_targ);
2140 [ # # ]: 0 : cgrd->cgr.__cs_thres = be16_to_cpu(cgrd->cgr.__cs_thres);
2141 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(cgrd->cscn_targ_swp); i++)
2142 : 0 : cgrd->cscn_targ_swp[i] =
2143 [ # # ]: 0 : be32_to_cpu(cgrd->cscn_targ_swp[i]);
2144 : : return 0;
2145 : : }
2146 : :
2147 : 0 : int qman_query_congestion(struct qm_mcr_querycongestion *congestion)
2148 : : {
2149 : : struct qm_mc_result *mcr;
2150 : : struct qman_portal *p = get_affine_portal();
2151 : : u8 res;
2152 : : unsigned int i;
2153 : :
2154 : : qm_mc_start(&p->p);
2155 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYCONGESTION);
2156 : : while (!(mcr = qm_mc_result(&p->p)))
2157 : 0 : cpu_relax();
2158 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) ==
2159 : : QM_MCC_VERB_QUERYCONGESTION);
2160 : 0 : res = mcr->result;
2161 [ # # ]: 0 : if (res == QM_MCR_RESULT_OK)
2162 : 0 : *congestion = mcr->querycongestion;
2163 [ # # ]: 0 : if (res != QM_MCR_RESULT_OK) {
2164 : 0 : DPAA_BUS_ERR("QUERY_CONGESTION failed: %s", mcr_result_str(res));
2165 : 0 : return -EIO;
2166 : : }
2167 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(congestion->state.state); i++)
2168 : 0 : congestion->state.state[i] =
2169 [ # # ]: 0 : be32_to_cpu(congestion->state.state[i]);
2170 : : return 0;
2171 : : }
2172 : :
2173 : 0 : int qman_set_vdq(struct qman_fq *fq, u16 num, uint32_t vdqcr_flags)
2174 : : {
2175 : : struct qman_portal *p = get_affine_portal();
2176 : : uint32_t vdqcr;
2177 : : int ret = -EBUSY;
2178 : :
2179 : : vdqcr = vdqcr_flags;
2180 : 0 : vdqcr |= QM_VDQCR_NUMFRAMES_SET(num);
2181 : :
2182 [ # # ]: 0 : if ((fq->state != qman_fq_state_parked) &&
2183 : : (fq->state != qman_fq_state_retired)) {
2184 : : ret = -EINVAL;
2185 : 0 : goto out;
2186 : : }
2187 [ # # ]: 0 : if (fq_isset(fq, QMAN_FQ_STATE_VDQCR)) {
2188 : : ret = -EBUSY;
2189 : 0 : goto out;
2190 : : }
2191 : 0 : vdqcr = (vdqcr & ~QM_VDQCR_FQID_MASK) | fq->fqid;
2192 : :
2193 [ # # ]: 0 : if (!p->vdqcr_owned) {
2194 : : FQLOCK(fq);
2195 [ # # ]: 0 : if (fq_isset(fq, QMAN_FQ_STATE_VDQCR)) {
2196 : : FQUNLOCK(fq);
2197 : 0 : goto escape;
2198 : : }
2199 : : fq_set(fq, QMAN_FQ_STATE_VDQCR);
2200 : : FQUNLOCK(fq);
2201 [ # # ]: 0 : p->vdqcr_owned = fq;
2202 : : ret = 0;
2203 : : }
2204 : 0 : escape:
2205 : : if (!ret)
2206 : : qm_dqrr_vdqcr_set(&p->p, vdqcr);
2207 : :
2208 : 0 : out:
2209 : 0 : return ret;
2210 : : }
2211 : :
2212 : 0 : int qman_volatile_dequeue(struct qman_fq *fq, u32 flags __maybe_unused,
2213 : : u32 vdqcr)
2214 : : {
2215 : : struct qman_portal *p;
2216 : : int ret = -EBUSY;
2217 : :
2218 [ # # ]: 0 : if ((fq->state != qman_fq_state_parked) &&
2219 : : (fq->state != qman_fq_state_retired))
2220 : : return -EINVAL;
2221 [ # # ]: 0 : if (vdqcr & QM_VDQCR_FQID_MASK)
2222 : : return -EINVAL;
2223 [ # # ]: 0 : if (fq_isset(fq, QMAN_FQ_STATE_VDQCR))
2224 : : return -EBUSY;
2225 : 0 : vdqcr = (vdqcr & ~QM_VDQCR_FQID_MASK) | fq->fqid;
2226 : :
2227 : : p = get_affine_portal();
2228 : :
2229 [ # # ]: 0 : if (!p->vdqcr_owned) {
2230 : : FQLOCK(fq);
2231 [ # # ]: 0 : if (fq_isset(fq, QMAN_FQ_STATE_VDQCR)) {
2232 : : FQUNLOCK(fq);
2233 : 0 : goto escape;
2234 : : }
2235 : : fq_set(fq, QMAN_FQ_STATE_VDQCR);
2236 : : FQUNLOCK(fq);
2237 [ # # ]: 0 : p->vdqcr_owned = fq;
2238 : : ret = 0;
2239 : : }
2240 : 0 : escape:
2241 : : if (ret)
2242 : 0 : return ret;
2243 : :
2244 : : /* VDQCR is set */
2245 : : qm_dqrr_vdqcr_set(&p->p, vdqcr);
2246 : 0 : return 0;
2247 : : }
2248 : :
2249 : 0 : static noinline void update_eqcr_ci(struct qman_portal *p, u8 avail)
2250 : : {
2251 [ # # ]: 0 : if (avail)
2252 : : qm_eqcr_cce_prefetch(&p->p);
2253 : : else
2254 : : qm_eqcr_cce_update(&p->p);
2255 : 0 : }
2256 : :
2257 : 0 : int qman_eqcr_is_empty(void)
2258 : : {
2259 : : struct qman_portal *p = get_affine_portal();
2260 : : u8 avail;
2261 : :
2262 : 0 : update_eqcr_ci(p, 0);
2263 : : avail = qm_eqcr_get_fill(&p->p);
2264 : 0 : return (avail == 0);
2265 : : }
2266 : :
2267 : 0 : void qman_set_dc_ern(qman_cb_dc_ern handler, int affine)
2268 : : {
2269 [ # # ]: 0 : if (affine) {
2270 : : struct qman_portal *p = get_affine_portal();
2271 : :
2272 : 0 : p->cb_dc_ern = handler;
2273 : : } else
2274 : 0 : cb_dc_ern = handler;
2275 : 0 : }
2276 : :
2277 : 0 : static inline struct qm_eqcr_entry *try_p_eq_start(struct qman_portal *p,
2278 : : struct qman_fq *fq,
2279 : : const struct qm_fd *fd,
2280 : : u32 flags)
2281 : : {
2282 : : struct qm_eqcr_entry *eq;
2283 : : u8 avail;
2284 : :
2285 [ # # ]: 0 : if (p->use_eqcr_ci_stashing) {
2286 : : /*
2287 : : * The stashing case is easy, only update if we need to in
2288 : : * order to try and liberate ring entries.
2289 : : */
2290 : : eq = qm_eqcr_start_stash(&p->p);
2291 : : } else {
2292 : : /*
2293 : : * The non-stashing case is harder, need to prefetch ahead of
2294 : : * time.
2295 : : */
2296 : : avail = qm_eqcr_get_avail(&p->p);
2297 [ # # ]: 0 : if (avail < 2)
2298 : 0 : update_eqcr_ci(p, avail);
2299 : : eq = qm_eqcr_start_no_stash(&p->p);
2300 : : }
2301 : :
2302 [ # # ]: 0 : if (unlikely(!eq))
2303 : : return NULL;
2304 : :
2305 [ # # ]: 0 : if (flags & QMAN_ENQUEUE_FLAG_DCA)
2306 : 0 : eq->dca = QM_EQCR_DCA_ENABLE |
2307 : : ((flags & QMAN_ENQUEUE_FLAG_DCA_PARK) ?
2308 : 0 : QM_EQCR_DCA_PARK : 0) |
2309 : : ((flags >> 8) & QM_EQCR_DCA_IDXMASK);
2310 [ # # ]: 0 : eq->fqid = cpu_to_be32(fq->fqid);
2311 : : #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
2312 [ # # ]: 0 : eq->tag = cpu_to_be32(fq->key);
2313 : : #else
2314 : : eq->tag = cpu_to_be32((u32)(uintptr_t)fq);
2315 : : #endif
2316 : 0 : eq->fd = *fd;
2317 : 0 : cpu_to_hw_fd(&eq->fd);
2318 : 0 : return eq;
2319 : : }
2320 : :
2321 : 0 : int qman_enqueue(struct qman_fq *fq, const struct qm_fd *fd, u32 flags)
2322 : : {
2323 : : struct qman_portal *p = get_affine_portal();
2324 : : struct qm_eqcr_entry *eq;
2325 : :
2326 : 0 : eq = try_p_eq_start(p, fq, fd, flags);
2327 [ # # ]: 0 : if (!eq)
2328 : : return -EBUSY;
2329 : : /* Note: QM_EQCR_VERB_INTERRUPT == QMAN_ENQUEUE_FLAG_WAIT_SYNC */
2330 : 0 : qm_eqcr_pvb_commit(&p->p, QM_EQCR_VERB_CMD_ENQUEUE |
2331 : 0 : (flags & (QM_EQCR_VERB_COLOUR_MASK | QM_EQCR_VERB_INTERRUPT)));
2332 : : /* Factor the below out, it's used from qman_enqueue_orp() too */
2333 : 0 : return 0;
2334 : : }
2335 : :
2336 : 0 : int qman_enqueue_multi(struct qman_fq *fq,
2337 : : const struct qm_fd *fd, u32 *flags,
2338 : : int frames_to_send)
2339 : : {
2340 : : struct qman_portal *p = get_affine_portal();
2341 : : struct qm_portal *portal = &p->p;
2342 : :
2343 : : register struct qm_eqcr *eqcr = &portal->eqcr;
2344 : 0 : struct qm_eqcr_entry *eq = eqcr->cursor;
2345 : :
2346 : : u8 i = 0, diff, old_ci, sent = 0;
2347 : :
2348 : : /* Update the available entries if no entry is free */
2349 [ # # ]: 0 : if (!eqcr->available) {
2350 : 0 : old_ci = eqcr->ci;
2351 [ # # ]: 0 : eqcr->ci = qm_cl_in(EQCR_CI) & (QM_EQCR_SIZE - 1);
2352 : : diff = qm_cyc_diff(QM_EQCR_SIZE, old_ci, eqcr->ci);
2353 : 0 : eqcr->available += diff;
2354 [ # # ]: 0 : if (!diff)
2355 : : return 0;
2356 : : }
2357 : :
2358 : : /* try to send as many frames as possible */
2359 [ # # # # ]: 0 : while (eqcr->available && frames_to_send--) {
2360 : 0 : eq->fqid = fq->fqid_be;
2361 : 0 : eq->fd.opaque_addr = fd->opaque_addr;
2362 [ # # ]: 0 : eq->fd.addr = cpu_to_be40(fd->addr);
2363 [ # # ]: 0 : eq->fd.status = cpu_to_be32(fd->status);
2364 [ # # ]: 0 : eq->fd.opaque = cpu_to_be32(fd->opaque);
2365 [ # # # # ]: 0 : if (flags && (flags[i] & QMAN_ENQUEUE_FLAG_DCA)) {
2366 : 0 : eq->dca = QM_EQCR_DCA_ENABLE |
2367 : 0 : ((flags[i] >> 8) & QM_EQCR_DCA_IDXMASK);
2368 : : }
2369 : 0 : i++;
2370 : 0 : eq++;
2371 [ # # ]: 0 : if (unlikely(eq >= (eqcr->ring + QM_EQCR_SIZE)))
2372 : : eq = eqcr->ring;
2373 : 0 : eqcr->available--;
2374 : : sent++;
2375 : 0 : fd++;
2376 : : }
2377 : : lwsync();
2378 : :
2379 : : /* In order for flushes to complete faster, all lines are recorded in
2380 : : * 32 bit word.
2381 : : */
2382 : 0 : eq = eqcr->cursor;
2383 [ # # ]: 0 : for (i = 0; i < sent; i++) {
2384 : 0 : eq->__dont_write_directly__verb =
2385 : 0 : QM_EQCR_VERB_CMD_ENQUEUE | eqcr->vbit;
2386 : 0 : eq++;
2387 [ # # ]: 0 : if (unlikely(eq >= (eqcr->ring + QM_EQCR_SIZE))) {
2388 : 0 : eqcr->vbit ^= QM_EQCR_VERB_VBIT;
2389 : : eq = eqcr->ring;
2390 : : }
2391 : : }
2392 : :
2393 : : /* We need to flush all the lines but without load/store operations
2394 : : * between them
2395 : : */
2396 : : eq = eqcr->cursor;
2397 [ # # ]: 0 : for (i = 0; i < sent; i++) {
2398 : : dcbf(eq);
2399 : 0 : eq = (void *)((unsigned long)(eq + 1) &
2400 : : (~(unsigned long)(QM_EQCR_SIZE << 6)));
2401 : : }
2402 : : /* Update cursor for the next call */
2403 : 0 : eqcr->cursor = eq;
2404 : 0 : return sent;
2405 : : }
2406 : :
2407 : : int
2408 : 0 : qman_enqueue_multi_fq(struct qman_fq *fq[], const struct qm_fd *fd,
2409 : : u32 *flags, int frames_to_send)
2410 : : {
2411 : : struct qman_portal *p = get_affine_portal();
2412 : : struct qm_portal *portal = &p->p;
2413 : :
2414 : : register struct qm_eqcr *eqcr = &portal->eqcr;
2415 : 0 : struct qm_eqcr_entry *eq = eqcr->cursor;
2416 : :
2417 : : u8 i = 0, diff, old_ci, sent = 0;
2418 : :
2419 : : /* Update the available entries if no entry is free */
2420 [ # # ]: 0 : if (!eqcr->available) {
2421 : 0 : old_ci = eqcr->ci;
2422 [ # # ]: 0 : eqcr->ci = qm_cl_in(EQCR_CI) & (QM_EQCR_SIZE - 1);
2423 : : diff = qm_cyc_diff(QM_EQCR_SIZE, old_ci, eqcr->ci);
2424 : 0 : eqcr->available += diff;
2425 [ # # ]: 0 : if (!diff)
2426 : : return 0;
2427 : : }
2428 : :
2429 : : /* try to send as many frames as possible */
2430 [ # # # # ]: 0 : while (eqcr->available && frames_to_send--) {
2431 : 0 : eq->fqid = fq[sent]->fqid_be;
2432 : 0 : eq->fd.opaque_addr = fd->opaque_addr;
2433 [ # # ]: 0 : eq->fd.addr = cpu_to_be40(fd->addr);
2434 [ # # ]: 0 : eq->fd.status = cpu_to_be32(fd->status);
2435 [ # # ]: 0 : eq->fd.opaque = cpu_to_be32(fd->opaque);
2436 [ # # # # ]: 0 : if (flags && (flags[i] & QMAN_ENQUEUE_FLAG_DCA)) {
2437 : 0 : eq->dca = QM_EQCR_DCA_ENABLE |
2438 : 0 : ((flags[i] >> 8) & QM_EQCR_DCA_IDXMASK);
2439 : : }
2440 : 0 : i++;
2441 : :
2442 : 0 : eq++;
2443 [ # # ]: 0 : if (unlikely(eq >= (eqcr->ring + QM_EQCR_SIZE)))
2444 : : eq = eqcr->ring;
2445 : 0 : eqcr->available--;
2446 : : sent++;
2447 : 0 : fd++;
2448 : : }
2449 : : lwsync();
2450 : :
2451 : : /* In order for flushes to complete faster, all lines are recorded in
2452 : : * 32 bit word.
2453 : : */
2454 : 0 : eq = eqcr->cursor;
2455 [ # # ]: 0 : for (i = 0; i < sent; i++) {
2456 : 0 : eq->__dont_write_directly__verb =
2457 : 0 : QM_EQCR_VERB_CMD_ENQUEUE | eqcr->vbit;
2458 : 0 : eq++;
2459 [ # # ]: 0 : if (unlikely(eq >= (eqcr->ring + QM_EQCR_SIZE))) {
2460 : 0 : eqcr->vbit ^= QM_EQCR_VERB_VBIT;
2461 : : eq = eqcr->ring;
2462 : : }
2463 : : }
2464 : :
2465 : : /* We need to flush all the lines but without load/store operations
2466 : : * between them
2467 : : */
2468 : : eq = eqcr->cursor;
2469 [ # # ]: 0 : for (i = 0; i < sent; i++) {
2470 : : dcbf(eq);
2471 : 0 : eq++;
2472 [ # # ]: 0 : if (unlikely(eq >= (eqcr->ring + QM_EQCR_SIZE)))
2473 : : eq = eqcr->ring;
2474 : : }
2475 : : /* Update cursor for the next call */
2476 : 0 : eqcr->cursor = eq;
2477 : 0 : return sent;
2478 : : }
2479 : :
2480 : 0 : int qman_enqueue_orp(struct qman_fq *fq, const struct qm_fd *fd, u32 flags,
2481 : : struct qman_fq *orp, u16 orp_seqnum)
2482 : : {
2483 : : struct qman_portal *p = get_affine_portal();
2484 : : struct qm_eqcr_entry *eq;
2485 : :
2486 : 0 : eq = try_p_eq_start(p, fq, fd, flags);
2487 [ # # ]: 0 : if (!eq)
2488 : : return -EBUSY;
2489 : : /* Process ORP-specifics here */
2490 [ # # ]: 0 : if (flags & QMAN_ENQUEUE_FLAG_NLIS)
2491 : 0 : orp_seqnum |= QM_EQCR_SEQNUM_NLIS;
2492 : : else {
2493 : 0 : orp_seqnum &= ~QM_EQCR_SEQNUM_NLIS;
2494 [ # # ]: 0 : if (flags & QMAN_ENQUEUE_FLAG_NESN)
2495 : 0 : orp_seqnum |= QM_EQCR_SEQNUM_NESN;
2496 : : else
2497 : : /* No need to check 4 QMAN_ENQUEUE_FLAG_HOLE */
2498 : 0 : orp_seqnum &= ~QM_EQCR_SEQNUM_NESN;
2499 : : }
2500 [ # # ]: 0 : eq->seqnum = cpu_to_be16(orp_seqnum);
2501 [ # # ]: 0 : eq->orp = cpu_to_be32(orp->fqid);
2502 : : /* Note: QM_EQCR_VERB_INTERRUPT == QMAN_ENQUEUE_FLAG_WAIT_SYNC */
2503 : : qm_eqcr_pvb_commit(&p->p, QM_EQCR_VERB_ORP |
2504 : 0 : ((flags & (QMAN_ENQUEUE_FLAG_HOLE | QMAN_ENQUEUE_FLAG_NESN)) ?
2505 [ # # ]: 0 : 0 : QM_EQCR_VERB_CMD_ENQUEUE) |
2506 : 0 : (flags & (QM_EQCR_VERB_COLOUR_MASK | QM_EQCR_VERB_INTERRUPT)));
2507 : :
2508 : 0 : return 0;
2509 : : }
2510 : :
2511 [ # # ]: 0 : int qman_modify_cgr(struct qman_cgr *cgr, u32 flags,
2512 : : struct qm_mcc_initcgr *opts)
2513 : : {
2514 : : struct qm_mc_command *mcc;
2515 : : struct qm_mc_result *mcr;
2516 : : struct qman_portal *p = get_affine_portal();
2517 : :
2518 : : u8 res;
2519 : : u8 verb = QM_MCC_VERB_MODIFYCGR;
2520 : :
2521 : : mcc = qm_mc_start(&p->p);
2522 [ # # ]: 0 : if (opts)
2523 : 0 : mcc->initcgr = *opts;
2524 [ # # ]: 0 : mcc->initcgr.we_mask = cpu_to_be16(mcc->initcgr.we_mask);
2525 : 0 : mcc->initcgr.cgr.wr_parm_g.word =
2526 [ # # ]: 0 : cpu_to_be32(mcc->initcgr.cgr.wr_parm_g.word);
2527 : 0 : mcc->initcgr.cgr.wr_parm_y.word =
2528 [ # # ]: 0 : cpu_to_be32(mcc->initcgr.cgr.wr_parm_y.word);
2529 : 0 : mcc->initcgr.cgr.wr_parm_r.word =
2530 [ # # ]: 0 : cpu_to_be32(mcc->initcgr.cgr.wr_parm_r.word);
2531 [ # # ]: 0 : mcc->initcgr.cgr.cscn_targ = cpu_to_be32(mcc->initcgr.cgr.cscn_targ);
2532 [ # # ]: 0 : mcc->initcgr.cgr.__cs_thres = cpu_to_be16(mcc->initcgr.cgr.__cs_thres);
2533 : :
2534 : 0 : mcc->initcgr.cgid = cgr->cgrid;
2535 [ # # ]: 0 : if (flags & QMAN_CGR_FLAG_USE_INIT)
2536 : : verb = QM_MCC_VERB_INITCGR;
2537 : : qm_mc_commit(&p->p, verb);
2538 : : while (!(mcr = qm_mc_result(&p->p)))
2539 : 0 : cpu_relax();
2540 : :
2541 : : DPAA_ASSERT((mcr->verb & QM_MCR_VERB_MASK) == verb);
2542 : 0 : res = mcr->result;
2543 [ # # ]: 0 : return (res == QM_MCR_RESULT_OK) ? 0 : -EIO;
2544 : : }
2545 : :
2546 : : #define TARG_MASK(n) (0x80000000 >> (n->config->channel - \
2547 : : QM_CHANNEL_SWPORTAL0))
2548 : : #define TARG_DCP_MASK(n) (0x80000000 >> (10 + n))
2549 : : #define PORTAL_IDX(n) (n->config->channel - QM_CHANNEL_SWPORTAL0)
2550 : :
2551 : 0 : int qman_create_cgr(struct qman_cgr *cgr, u32 flags,
2552 : : struct qm_mcc_initcgr *opts)
2553 : : {
2554 : : struct qm_mcr_querycgr cgr_state;
2555 : : struct qm_mcc_initcgr local_opts;
2556 : : int ret;
2557 : : struct qman_portal *p;
2558 : :
2559 : : /* We have to check that the provided CGRID is within the limits of the
2560 : : * data-structures, for obvious reasons. However we'll let h/w take
2561 : : * care of determining whether it's within the limits of what exists on
2562 : : * the SoC.
2563 : : */
2564 [ # # ]: 0 : if (cgr->cgrid >= __CGR_NUM)
2565 : : return -EINVAL;
2566 : :
2567 : : p = get_affine_portal();
2568 : :
2569 : : memset(&local_opts, 0, sizeof(struct qm_mcc_initcgr));
2570 : 0 : cgr->chan = p->config->channel;
2571 : : spin_lock(&p->cgr_lock);
2572 : :
2573 : : /* if no opts specified, just add it to the list */
2574 [ # # ]: 0 : if (!opts)
2575 : 0 : goto add_list;
2576 : :
2577 : 0 : ret = qman_query_cgr(cgr, &cgr_state);
2578 [ # # ]: 0 : if (ret)
2579 : 0 : goto release_lock;
2580 : : if (opts)
2581 : 0 : local_opts = *opts;
2582 [ # # ]: 0 : if ((qman_ip_rev & 0xFF00) >= QMAN_REV30)
2583 : 0 : local_opts.cgr.cscn_targ_upd_ctrl =
2584 : 0 : QM_CGR_TARG_UDP_CTRL_WRITE_BIT | PORTAL_IDX(p);
2585 : : else
2586 : : /* Overwrite TARG */
2587 : 0 : local_opts.cgr.cscn_targ = cgr_state.cgr.cscn_targ |
2588 : 0 : TARG_MASK(p);
2589 : 0 : local_opts.we_mask |= QM_CGR_WE_CSCN_TARG;
2590 : :
2591 : : /* send init if flags indicate so */
2592 [ # # ]: 0 : if (opts && (flags & QMAN_CGR_FLAG_USE_INIT))
2593 : 0 : ret = qman_modify_cgr(cgr, QMAN_CGR_FLAG_USE_INIT, &local_opts);
2594 : : else
2595 : 0 : ret = qman_modify_cgr(cgr, 0, &local_opts);
2596 [ # # ]: 0 : if (ret)
2597 : 0 : goto release_lock;
2598 : 0 : add_list:
2599 : 0 : list_add(&cgr->node, &p->cgr_cbs);
2600 : :
2601 : : /* Determine if newly added object requires its callback to be called */
2602 : 0 : ret = qman_query_cgr(cgr, &cgr_state);
2603 [ # # ]: 0 : if (ret) {
2604 : : /* we can't go back, so proceed and return success, but screen
2605 : : * and wail to the log file.
2606 : : */
2607 : 0 : DPAA_BUS_ERR("CGR HW state partially modified");
2608 : : ret = 0;
2609 : 0 : goto release_lock;
2610 : : }
2611 [ # # # # ]: 0 : if (cgr->cb && cgr_state.cgr.cscn_en && qman_cgrs_get(&p->cgrs[1],
2612 [ # # ]: 0 : cgr->cgrid))
2613 : 0 : cgr->cb(p, cgr, 1);
2614 : 0 : release_lock:
2615 : : spin_unlock(&p->cgr_lock);
2616 : 0 : return ret;
2617 : : }
2618 : :
2619 : 0 : int qman_create_cgr_to_dcp(struct qman_cgr *cgr, u32 flags, u16 dcp_portal,
2620 : : struct qm_mcc_initcgr *opts)
2621 : : {
2622 : : struct qm_mcc_initcgr local_opts;
2623 : : struct qm_mcr_querycgr cgr_state;
2624 : : int ret;
2625 : :
2626 [ # # ]: 0 : if ((qman_ip_rev & 0xFF00) < QMAN_REV30) {
2627 : 0 : DPAA_BUS_WARN("QMan version doesn't support CSCN => DCP portal");
2628 : 0 : return -EINVAL;
2629 : : }
2630 : : /* We have to check that the provided CGRID is within the limits of the
2631 : : * data-structures, for obvious reasons. However we'll let h/w take
2632 : : * care of determining whether it's within the limits of what exists on
2633 : : * the SoC.
2634 : : */
2635 [ # # ]: 0 : if (cgr->cgrid >= __CGR_NUM)
2636 : : return -EINVAL;
2637 : :
2638 : 0 : ret = qman_query_cgr(cgr, &cgr_state);
2639 [ # # ]: 0 : if (ret)
2640 : : return ret;
2641 : :
2642 : : memset(&local_opts, 0, sizeof(struct qm_mcc_initcgr));
2643 [ # # ]: 0 : if (opts)
2644 : 0 : local_opts = *opts;
2645 : :
2646 [ # # ]: 0 : if ((qman_ip_rev & 0xFF00) >= QMAN_REV30)
2647 : 0 : local_opts.cgr.cscn_targ_upd_ctrl =
2648 : : QM_CGR_TARG_UDP_CTRL_WRITE_BIT |
2649 : : QM_CGR_TARG_UDP_CTRL_DCP | dcp_portal;
2650 : : else
2651 : 0 : local_opts.cgr.cscn_targ = cgr_state.cgr.cscn_targ |
2652 : 0 : TARG_DCP_MASK(dcp_portal);
2653 : 0 : local_opts.we_mask |= QM_CGR_WE_CSCN_TARG;
2654 : :
2655 : : /* send init if flags indicate so */
2656 [ # # # # ]: 0 : if (opts && (flags & QMAN_CGR_FLAG_USE_INIT))
2657 : 0 : ret = qman_modify_cgr(cgr, QMAN_CGR_FLAG_USE_INIT,
2658 : : &local_opts);
2659 : : else
2660 : 0 : ret = qman_modify_cgr(cgr, 0, &local_opts);
2661 : :
2662 : : return ret;
2663 : : }
2664 : :
2665 : 0 : int qman_delete_cgr(struct qman_cgr *cgr)
2666 : : {
2667 : : struct qm_mcr_querycgr cgr_state;
2668 : : struct qm_mcc_initcgr local_opts;
2669 : : int ret = 0;
2670 : : struct qman_cgr *i;
2671 : : struct qman_portal *p = get_affine_portal();
2672 : :
2673 [ # # ]: 0 : if (cgr->chan != p->config->channel) {
2674 : 0 : DPAA_BUS_ERR("Attempting to delete cgr from different portal than"
2675 : : " it was create: create 0x%x, delete 0x%x",
2676 : : cgr->chan, p->config->channel);
2677 : : ret = -EINVAL;
2678 : 0 : goto put_portal;
2679 : : }
2680 : : memset(&local_opts, 0, sizeof(struct qm_mcc_initcgr));
2681 : : spin_lock(&p->cgr_lock);
2682 : 0 : list_del(&cgr->node);
2683 : : /*
2684 : : * If there are no other CGR objects for this CGRID in the list,
2685 : : * update CSCN_TARG accordingly
2686 : : */
2687 [ # # ]: 0 : list_for_each_entry(i, &p->cgr_cbs, node)
2688 [ # # # # ]: 0 : if ((i->cgrid == cgr->cgrid) && i->cb)
2689 : 0 : goto release_lock;
2690 : 0 : ret = qman_query_cgr(cgr, &cgr_state);
2691 [ # # ]: 0 : if (ret) {
2692 : : /* add back to the list */
2693 : 0 : list_add(&cgr->node, &p->cgr_cbs);
2694 : 0 : goto release_lock;
2695 : : }
2696 : : /* Overwrite TARG */
2697 : 0 : local_opts.we_mask = QM_CGR_WE_CSCN_TARG;
2698 [ # # ]: 0 : if ((qman_ip_rev & 0xFF00) >= QMAN_REV30)
2699 : 0 : local_opts.cgr.cscn_targ_upd_ctrl = PORTAL_IDX(p);
2700 : : else
2701 : 0 : local_opts.cgr.cscn_targ = cgr_state.cgr.cscn_targ &
2702 : 0 : ~(TARG_MASK(p));
2703 : 0 : ret = qman_modify_cgr(cgr, 0, &local_opts);
2704 [ # # ]: 0 : if (ret)
2705 : : /* add back to the list */
2706 : 0 : list_add(&cgr->node, &p->cgr_cbs);
2707 : 0 : release_lock:
2708 : : spin_unlock(&p->cgr_lock);
2709 : 0 : put_portal:
2710 : 0 : return ret;
2711 : : }
2712 : :
2713 : : #define GENMASK(h, l) \
2714 : : (((~0U) >> (sizeof(unsigned int) * 8 - ((h) - (l) + 1))) << (l))
2715 : :
2716 : : /* 'fqid' is a 24-bit field in every h/w descriptor */
2717 : : #define QM_FQID_MASK GENMASK(23, 0)
2718 : : #define qm_fqid_set(p, v) ((p)->fqid = cpu_to_be32((v) & QM_FQID_MASK))
2719 : : #define qm_fqid_get(p) (be32_to_cpu((p)->fqid) & QM_FQID_MASK)
2720 : :
2721 : : static int
2722 [ # # ]: 0 : _qm_mr_consume_and_match_verb(struct qm_portal *p, int v)
2723 : : {
2724 : : const struct qm_mr_entry *msg;
2725 : : int found = 0;
2726 : :
2727 : : qm_mr_pvb_update(p);
2728 : : msg = qm_mr_current(p);
2729 [ # # ]: 0 : while (msg) {
2730 [ # # ]: 0 : if ((msg->ern.verb & QM_MR_VERB_TYPE_MASK) == v)
2731 : : found = 1;
2732 : : qm_mr_next(p);
2733 : : qm_mr_cci_consume_to_current(p);
2734 : : qm_mr_pvb_update(p);
2735 : : msg = qm_mr_current(p);
2736 : : }
2737 : 0 : return found;
2738 : : }
2739 : :
2740 : : static int
2741 : 0 : _qm_dqrr_consume_and_match(struct qm_portal *p, u32 fqid, int s,
2742 : : bool wait)
2743 : : {
2744 : : const struct qm_dqrr_entry *dqrr;
2745 : : int found = 0;
2746 : :
2747 : : do {
2748 : : qm_dqrr_pvb_update(p);
2749 : : dqrr = qm_dqrr_current(p);
2750 [ # # ]: 0 : if (!dqrr)
2751 : 0 : cpu_relax();
2752 [ # # ]: 0 : } while (wait && !dqrr);
2753 : :
2754 [ # # ]: 0 : while (dqrr) {
2755 [ # # # # : 0 : if (qm_fqid_get(dqrr) == fqid && (dqrr->stat & s))
# # ]
2756 : : found = 1;
2757 : :
2758 : : qm_dqrr_cdc_consume_1ptr(p, dqrr, 0);
2759 : : qm_dqrr_pvb_update(p);
2760 : : qm_dqrr_next(p);
2761 : : dqrr = qm_dqrr_current(p);
2762 : : }
2763 : 0 : return found;
2764 : : }
2765 : :
2766 : : #define QM_MCR_TIMEOUT 10000 /* us */
2767 : :
2768 : : static inline int
2769 : 0 : qm_mc_result_timeout(struct qm_portal *portal,
2770 : : struct qm_mc_result **mcr)
2771 : : {
2772 : : int timeout = QM_MCR_TIMEOUT;
2773 : :
2774 : : do {
2775 : 0 : *mcr = qm_mc_result(portal);
2776 [ # # ]: 0 : if (*mcr)
2777 : : break;
2778 : 0 : usleep(1);
2779 [ # # ]: 0 : } while (--timeout);
2780 : :
2781 : 0 : return timeout;
2782 : : }
2783 : :
2784 : : #define qm_mr_drain(p, V) \
2785 : : _qm_mr_consume_and_match_verb(p, QM_MR_VERB_##V)
2786 : :
2787 : : #define qm_dqrr_drain(p, f, S) \
2788 : : _qm_dqrr_consume_and_match(p, f, QM_DQRR_STAT_##S, false)
2789 : :
2790 : : #define qm_dqrr_drain_wait(p, f, S) \
2791 : : _qm_dqrr_consume_and_match(p, f, QM_DQRR_STAT_##S, true)
2792 : :
2793 : : #define qm_dqrr_drain_nomatch(p) \
2794 : : _qm_dqrr_consume_and_match(p, 0, 0, false)
2795 : :
2796 : : RTE_EXPORT_INTERNAL_SYMBOL(qman_shutdown_fq)
2797 : : int
2798 : 0 : qman_shutdown_fq(u32 fqid)
2799 : : {
2800 : : struct qman_portal *p;
2801 : : struct qm_mc_command *mcc;
2802 : : struct qm_mc_result *mcr;
2803 : : int orl_empty, drain = 0, ret = 0;
2804 : : u32 res;
2805 : : u8 state;
2806 : : u32 channel, wq;
2807 : : u16 dest_wq;
2808 : :
2809 : 0 : DPAA_BUS_DEBUG("In shutdown for queue = %x", fqid);
2810 : : p = get_affine_portal();
2811 : : /* Determine the state of the FQID */
2812 : : mcc = qm_mc_start(&p->p);
2813 [ # # ]: 0 : mcc->queryfq_np.fqid = cpu_to_be32(fqid);
2814 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYFQ_NP);
2815 [ # # ]: 0 : if (!qm_mc_result_timeout(&p->p, &mcr)) {
2816 : 0 : DPAA_BUS_ERR("QUERYFQ_NP timeout");
2817 : : ret = -ETIMEDOUT;
2818 : 0 : goto out;
2819 : : }
2820 : 0 : state = mcr->queryfq_np.state & QM_MCR_NP_STATE_MASK;
2821 [ # # ]: 0 : if (state == QM_MCR_NP_STATE_OOS) {
2822 : 0 : DPAA_BUS_ERR("Already in OOS");
2823 : 0 : goto out; /* Already OOS, no need to do anymore checks */
2824 : : }
2825 : :
2826 : : /* Query which channel the FQ is using */
2827 : : mcc = qm_mc_start(&p->p);
2828 [ # # ]: 0 : mcc->queryfq.fqid = cpu_to_be32(fqid);
2829 : : qm_mc_commit(&p->p, QM_MCC_VERB_QUERYFQ);
2830 [ # # ]: 0 : if (!qm_mc_result_timeout(&p->p, &mcr)) {
2831 : 0 : DPAA_BUS_ERR("QUERYFQ timeout");
2832 : : ret = -ETIMEDOUT;
2833 : 0 : goto out;
2834 : : }
2835 : :
2836 : : /* Need to store these since the MCR gets reused */
2837 [ # # ]: 0 : dest_wq = be16_to_cpu(mcr->queryfq.fqd.dest_wq);
2838 : 0 : channel = dest_wq & 0x7;
2839 : : wq = dest_wq >> 3;
2840 : :
2841 [ # # # ]: 0 : switch (state) {
2842 : 0 : case QM_MCR_NP_STATE_TEN_SCHED:
2843 : : case QM_MCR_NP_STATE_TRU_SCHED:
2844 : : case QM_MCR_NP_STATE_ACTIVE:
2845 : : case QM_MCR_NP_STATE_PARKED:
2846 : 0 : DPAA_BUS_DEBUG("In shutdown state is %d", state);
2847 : : orl_empty = 0;
2848 : : mcc = qm_mc_start(&p->p);
2849 [ # # ]: 0 : mcc->alterfq.fqid = cpu_to_be32(fqid);
2850 : : qm_mc_commit(&p->p, QM_MCC_VERB_ALTER_RETIRE);
2851 [ # # ]: 0 : if (!qm_mc_result_timeout(&p->p, &mcr)) {
2852 : 0 : DPAA_BUS_ERR("ALTER_RETIRE timeout");
2853 : : ret = -ETIMEDOUT;
2854 : 0 : goto out;
2855 : : }
2856 : 0 : res = mcr->result; /* Make a copy as we reuse MCR below */
2857 : :
2858 [ # # ]: 0 : if (res == QM_MCR_RESULT_OK)
2859 : 0 : drain_mr_fqrni(&p->p);
2860 : :
2861 [ # # ]: 0 : if (res == QM_MCR_RESULT_PENDING) {
2862 : : /*
2863 : : * Need to wait for the FQRN in the message ring, which
2864 : : * will only occur once the FQ has been drained. In
2865 : : * order for the FQ to drain the portal needs to be set
2866 : : * to dequeue from the channel the FQ is scheduled on
2867 : : */
2868 : : int found_fqrn = 0;
2869 : :
2870 : : /* Flag that we need to drain FQ */
2871 : : drain = 1;
2872 : :
2873 : : __maybe_unused u16 dequeue_wq = 0;
2874 [ # # ]: 0 : if (channel >= qm_channel_pool1 &&
2875 : : channel < (u16)(qm_channel_pool1 + 15)) {
2876 : : /* Pool channel, enable the bit in the portal */
2877 : : dequeue_wq = (channel -
2878 : : qm_channel_pool1 + 1) << 4 | wq;
2879 [ # # ]: 0 : } else if (channel < qm_channel_pool1) {
2880 : : /* Dedicated channel */
2881 : : dequeue_wq = wq;
2882 : : } else {
2883 : 0 : DPAA_BUS_ERR("Can't recover FQ 0x%x, ch: 0x%x",
2884 : : fqid, channel);
2885 : : ret = -EBUSY;
2886 : 0 : goto out;
2887 : : }
2888 : : /* Set the sdqcr to drain this channel */
2889 [ # # ]: 0 : if (channel < qm_channel_pool1)
2890 : : qm_dqrr_sdqcr_set(&p->p,
2891 : : QM_SDQCR_TYPE_ACTIVE |
2892 : : QM_SDQCR_CHANNELS_DEDICATED);
2893 : : else
2894 [ # # ]: 0 : qm_dqrr_sdqcr_set(&p->p,
2895 : : QM_SDQCR_TYPE_ACTIVE |
2896 : 0 : QM_SDQCR_CHANNELS_POOL_CONV
2897 : : (channel));
2898 : : do {
2899 : : /* Keep draining DQRR while checking the MR*/
2900 : 0 : qm_dqrr_drain_nomatch(&p->p);
2901 : : /* Process message ring too */
2902 : 0 : found_fqrn = qm_mr_drain(&p->p,
2903 : : FQRN);
2904 : 0 : cpu_relax();
2905 [ # # ]: 0 : } while (!found_fqrn);
2906 : : /* Restore SDQCR */
2907 [ # # ]: 0 : qm_dqrr_sdqcr_set(&p->p,
2908 : : p->sdqcr);
2909 : : }
2910 : 0 : if (res != QM_MCR_RESULT_OK &&
2911 [ # # ]: 0 : res != QM_MCR_RESULT_PENDING) {
2912 : 0 : DPAA_BUS_ERR("retire_fq failed: FQ 0x%x, res=0x%x",
2913 : : fqid, res);
2914 : : ret = -EIO;
2915 : 0 : goto out;
2916 : : }
2917 [ # # ]: 0 : if (!(mcr->alterfq.fqs & QM_MCR_FQS_ORLPRESENT)) {
2918 : : /*
2919 : : * ORL had no entries, no need to wait until the
2920 : : * ERNs come in
2921 : : */
2922 : : orl_empty = 1;
2923 : : }
2924 : : /*
2925 : : * Retirement succeeded, check to see if FQ needs
2926 : : * to be drained
2927 : : */
2928 [ # # # # ]: 0 : if (drain || mcr->alterfq.fqs & QM_MCR_FQS_NOTEMPTY) {
2929 : : /* FQ is Not Empty, drain using volatile DQ commands */
2930 : : do {
2931 [ # # ]: 0 : u32 vdqcr = fqid | QM_VDQCR_NUMFRAMES_SET(3);
2932 : :
2933 : : qm_dqrr_vdqcr_set(&p->p, vdqcr);
2934 : : /*
2935 : : * Wait for a dequeue and process the dequeues,
2936 : : * making sure to empty the ring completely
2937 : : */
2938 [ # # ]: 0 : } while (!qm_dqrr_drain_wait(&p->p, fqid, FQ_EMPTY));
2939 : : }
2940 [ # # ]: 0 : while (!orl_empty) {
2941 : : /* Wait for the ORL to have been completely drained */
2942 : 0 : orl_empty = qm_mr_drain(&p->p, FQRL);
2943 : 0 : cpu_relax();
2944 : : }
2945 : : mcc = qm_mc_start(&p->p);
2946 [ # # ]: 0 : mcc->alterfq.fqid = cpu_to_be32(fqid);
2947 : : qm_mc_commit(&p->p, QM_MCC_VERB_ALTER_OOS);
2948 [ # # ]: 0 : if (!qm_mc_result_timeout(&p->p, &mcr)) {
2949 : 0 : DPAA_BUS_ERR("OOS Timeout");
2950 : : ret = -ETIMEDOUT;
2951 : 0 : goto out;
2952 : : }
2953 : :
2954 [ # # ]: 0 : if (mcr->result != QM_MCR_RESULT_OK) {
2955 : 0 : DPAA_BUS_ERR("OOS after drain fail: FQ 0x%x (0x%x)",
2956 : : fqid, mcr->result);
2957 : : ret = -EIO;
2958 : 0 : goto out;
2959 : : }
2960 : : break;
2961 : :
2962 [ # # ]: 0 : case QM_MCR_NP_STATE_RETIRED:
2963 : : /* Send OOS Command */
2964 : : mcc = qm_mc_start(&p->p);
2965 [ # # ]: 0 : mcc->alterfq.fqid = cpu_to_be32(fqid);
2966 : : qm_mc_commit(&p->p, QM_MCC_VERB_ALTER_OOS);
2967 [ # # ]: 0 : if (!qm_mc_result_timeout(&p->p, &mcr)) {
2968 : 0 : DPAA_BUS_ERR("In RTEIRED to OOS timeout");
2969 : : ret = -ETIMEDOUT;
2970 : 0 : goto out;
2971 : : }
2972 : :
2973 [ # # ]: 0 : if (mcr->result != QM_MCR_RESULT_OK) {
2974 : 0 : DPAA_BUS_ERR("OOS fail: FQ 0x%x (0x%x)",
2975 : : fqid, mcr->result);
2976 : : ret = -EIO;
2977 : 0 : goto out;
2978 : : }
2979 : : break;
2980 : :
2981 : : case QM_MCR_NP_STATE_OOS:
2982 : : /* Done */
2983 : : break;
2984 : :
2985 : : default:
2986 : : ret = -EIO;
2987 : : }
2988 : :
2989 : 0 : out:
2990 : 0 : return ret;
2991 : : }
|