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

Generated by: LCOV version 1.14