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