LCOV - code coverage report
Current view: top level - drivers/bus/dpaa/base/qbman - qman.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1007 0.0 %
Date: 2024-02-14 00:53:57 Functions: 0 81 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 938 0.0 %

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

Generated by: LCOV version 1.14