bus/dpaa: fix inconsistent struct alignment
[dpdk.git] / drivers / bus / dpaa / base / qbman / qman.c
index 7e285a5..27d98cc 100644 (file)
@@ -8,6 +8,8 @@
 #include "qman.h"
 #include <rte_branch_prediction.h>
 #include <rte_dpaa_bus.h>
+#include <rte_eventdev.h>
+#include <rte_byteorder.h>
 
 /* Compilation constants */
 #define DQRR_MAXFILL   15
@@ -312,9 +314,9 @@ loop:
                if (!msg)
                        return 0;
        }
-       if ((msg->verb & QM_MR_VERB_TYPE_MASK) != QM_MR_VERB_FQRNI) {
+       if ((msg->ern.verb & QM_MR_VERB_TYPE_MASK) != QM_MR_VERB_FQRNI) {
                /* We aren't draining anything but FQRNIs */
-               pr_err("Found verb 0x%x in MR\n", msg->verb);
+               pr_err("Found verb 0x%x in MR\n", msg->ern.verb);
                return -1;
        }
        qm_mr_next(p);
@@ -481,7 +483,7 @@ static inline void qm_mr_pvb_update(struct qm_portal *portal)
        /* when accessing 'verb', use __raw_readb() to ensure that compiler
         * inlining doesn't try to optimise out "excess reads".
         */
-       if ((__raw_readb(&res->verb) & QM_MR_VERB_VBIT) == mr->vbit) {
+       if ((__raw_readb(&res->ern.verb) & QM_MR_VERB_VBIT) == mr->vbit) {
                mr->pi = (mr->pi + 1) & (QM_MR_SIZE - 1);
                if (!mr->pi)
                        mr->vbit ^= QM_MR_VERB_VBIT;
@@ -623,7 +625,7 @@ fail_eqcr:
 
 #define MAX_GLOBAL_PORTALS 8
 static struct qman_portal global_portals[MAX_GLOBAL_PORTALS];
-static int global_portals_used[MAX_GLOBAL_PORTALS];
+rte_atomic16_t global_portals_used[MAX_GLOBAL_PORTALS];
 
 static struct qman_portal *
 qman_alloc_global_portal(void)
@@ -631,10 +633,8 @@ qman_alloc_global_portal(void)
        unsigned int i;
 
        for (i = 0; i < MAX_GLOBAL_PORTALS; i++) {
-               if (global_portals_used[i] == 0) {
-                       global_portals_used[i] = 1;
+               if (rte_atomic16_test_and_set(&global_portals_used[i]))
                        return &global_portals[i];
-               }
        }
        pr_err("No portal available (%x)\n", MAX_GLOBAL_PORTALS);
 
@@ -648,7 +648,7 @@ qman_free_global_portal(struct qman_portal *portal)
 
        for (i = 0; i < MAX_GLOBAL_PORTALS; i++) {
                if (&global_portals[i] == portal) {
-                       global_portals_used[i] = 0;
+                       rte_atomic16_clear(&global_portals_used[i]);
                        return 0;
                }
        }
@@ -832,7 +832,7 @@ mr_loop:
                        goto mr_done;
                swapped_msg = *msg;
                hw_fd_to_cpu(&swapped_msg.ern.fd);
-               verb = msg->verb & QM_MR_VERB_TYPE_MASK;
+               verb = msg->ern.verb & QM_MR_VERB_TYPE_MASK;
                /* The message is a software ERN iff the 0x20 bit is set */
                if (verb & 0x20) {
                        switch (verb) {
@@ -1054,12 +1054,76 @@ u16 qman_affine_channel(int cpu)
 unsigned int qman_portal_poll_rx(unsigned int poll_limit,
                                 void **bufs,
                                 struct qman_portal *p)
+{
+       struct qm_portal *portal = &p->p;
+       register struct qm_dqrr *dqrr = &portal->dqrr;
+       struct qm_dqrr_entry *dq[QM_DQRR_SIZE], *shadow[QM_DQRR_SIZE];
+       struct qman_fq *fq[QM_DQRR_SIZE];
+       unsigned int limit = 0, rx_number = 0;
+       uint32_t consume = 0;
+
+       do {
+               qm_dqrr_pvb_update(&p->p);
+               if (!dqrr->fill)
+                       break;
+
+               dq[rx_number] = dqrr->cursor;
+               dqrr->cursor = DQRR_CARRYCLEAR(dqrr->cursor + 1);
+               /* Prefetch the next DQRR entry */
+               rte_prefetch0(dqrr->cursor);
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+               /* If running on an LE system the fields of the
+                * dequeue entry must be swapper.  Because the
+                * QMan HW will ignore writes the DQRR entry is
+                * copied and the index stored within the copy
+                */
+               shadow[rx_number] =
+                       &p->shadow_dqrr[DQRR_PTR2IDX(dq[rx_number])];
+               shadow[rx_number]->fd.opaque_addr =
+                       dq[rx_number]->fd.opaque_addr;
+               shadow[rx_number]->fd.addr =
+                       be40_to_cpu(dq[rx_number]->fd.addr);
+               shadow[rx_number]->fd.opaque =
+                       be32_to_cpu(dq[rx_number]->fd.opaque);
+#else
+               shadow[rx_number] = dq[rx_number];
+#endif
+
+               /* SDQCR: context_b points to the FQ */
+#ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
+               fq[rx_number] = qman_fq_lookup_table[be32_to_cpu(
+                                               dq[rx_number]->contextB)];
+#else
+               fq[rx_number] = (void *)be32_to_cpu(
+                                               dq[rx_number]->contextB);
+#endif
+               fq[rx_number]->cb.dqrr_prepare(shadow[rx_number],
+                                                &bufs[rx_number]);
+
+               consume |= (1 << (31 - DQRR_PTR2IDX(shadow[rx_number])));
+               rx_number++;
+               --dqrr->fill;
+       } while (++limit < poll_limit);
+
+       if (rx_number)
+               fq[0]->cb.dqrr_dpdk_pull_cb(fq, shadow, bufs, rx_number);
+
+       /* Consume all the DQRR enries together */
+       qm_out(DQRR_DCAP, (1 << 8) | consume);
+
+       return rx_number;
+}
+
+u32 qman_portal_dequeue(struct rte_event ev[], unsigned int poll_limit,
+                       void **bufs)
 {
        const struct qm_dqrr_entry *dq;
        struct qman_fq *fq;
        enum qman_cb_dqrr_result res;
        unsigned int limit = 0;
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+       struct qman_portal *p = get_affine_portal();
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
        struct qm_dqrr_entry *shadow;
 #endif
        unsigned int rx_number = 0;
@@ -1067,14 +1131,15 @@ unsigned int qman_portal_poll_rx(unsigned int poll_limit,
        do {
                qm_dqrr_pvb_update(&p->p);
                dq = qm_dqrr_current(&p->p);
-               if (unlikely(!dq))
+               if (!dq)
                        break;
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-       /* If running on an LE system the fields of the
-        * dequeue entry must be swapper.  Because the
-        * QMan HW will ignore writes the DQRR entry is
-        * copied and the index stored within the copy
-        */
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
+               /*
+                * If running on an LE system the fields of the
+                * dequeue entry must be swapper.  Because the
+                * QMan HW will ignore writes the DQRR entry is
+                * copied and the index stored within the copy
+                */
                shadow = &p->shadow_dqrr[DQRR_PTR2IDX(dq)];
                *shadow = *dq;
                dq = shadow;
@@ -1084,14 +1149,15 @@ unsigned int qman_portal_poll_rx(unsigned int poll_limit,
                hw_fd_to_cpu(&shadow->fd);
 #endif
 
-               /* SDQCR: context_b points to the FQ */
+              /* SDQCR: context_b points to the FQ */
 #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
                fq = get_fq_table_entry(dq->contextB);
 #else
                fq = (void *)(uintptr_t)dq->contextB;
 #endif
                /* Now let the callback do its stuff */
-               res = fq->cb.dqrr_dpdk_cb(NULL, p, fq, dq, &bufs[rx_number]);
+               res = fq->cb.dqrr_dpdk_cb(&ev[rx_number], p, fq,
+                                        dq, &bufs[rx_number]);
                rx_number++;
                /* Interpret 'dq' from a driver perspective. */
                /*
@@ -1101,7 +1167,9 @@ unsigned int qman_portal_poll_rx(unsigned int poll_limit,
                 */
                DPAA_ASSERT((dq->stat & QM_DQRR_STAT_FQ_HELDACTIVE) ||
                            (res != qman_cb_dqrr_park));
-               qm_dqrr_cdc_consume_1ptr(&p->p, dq, res == qman_cb_dqrr_park);
+               if (res != qman_cb_dqrr_defer)
+                       qm_dqrr_cdc_consume_1ptr(&p->p, dq,
+                                                res == qman_cb_dqrr_park);
                /* Move forward */
                qm_dqrr_next(&p->p);
                /*
@@ -1110,7 +1178,7 @@ unsigned int qman_portal_poll_rx(unsigned int poll_limit,
                 * entry, and we also exit if we reach our processing limit,
                 * so loop back only if neither of these conditions is met.
                 */
-       } while (likely(++limit < poll_limit));
+       } while (++limit < poll_limit);
 
        return limit;
 }
@@ -1233,13 +1301,20 @@ u32 qman_static_dequeue_get(struct qman_portal *qp)
        return p->sdqcr;
 }
 
-void qman_dca(struct qm_dqrr_entry *dq, int park_request)
+void qman_dca(const struct qm_dqrr_entry *dq, int park_request)
 {
        struct qman_portal *p = get_affine_portal();
 
        qm_dqrr_cdc_consume_1ptr(&p->p, dq, park_request);
 }
 
+void qman_dca_index(u8 index, int park_request)
+{
+       struct qman_portal *p = get_affine_portal();
+
+       qm_dqrr_cdc_consume_1(&p->p, index, park_request);
+}
+
 /* Frame queue API */
 static const char *mcr_result_str(u8 result)
 {
@@ -1591,7 +1666,7 @@ int qman_retire_fq(struct qman_fq *fq, u32 *flags)
                         */
                        struct qm_mr_entry msg;
 
-                       msg.verb = QM_MR_VERB_FQRNI;
+                       msg.ern.verb = QM_MR_VERB_FQRNI;
                        msg.fq.fqs = mcr->alterfq.fqs;
                        msg.fq.fqid = fq->fqid;
 #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
@@ -2088,8 +2163,8 @@ int qman_enqueue(struct qman_fq *fq, const struct qm_fd *fd, u32 flags)
 }
 
 int qman_enqueue_multi(struct qman_fq *fq,
-                      const struct qm_fd *fd,
-                      int frames_to_send)
+                      const struct qm_fd *fd, u32 *flags,
+               int frames_to_send)
 {
        struct qman_portal *p = get_affine_portal();
        struct qm_portal *portal = &p->p;
@@ -2097,7 +2172,7 @@ int qman_enqueue_multi(struct qman_fq *fq,
        register struct qm_eqcr *eqcr = &portal->eqcr;
        struct qm_eqcr_entry *eq = eqcr->cursor, *prev_eq;
 
-       u8 i, diff, old_ci, sent = 0;
+       u8 i = 0, diff, old_ci, sent = 0;
 
        /* Update the available entries if no entry is free */
        if (!eqcr->available) {
@@ -2121,6 +2196,76 @@ int qman_enqueue_multi(struct qman_fq *fq,
                eq->fd.addr = cpu_to_be40(fd->addr);
                eq->fd.status = cpu_to_be32(fd->status);
                eq->fd.opaque = cpu_to_be32(fd->opaque);
+               if (flags && (flags[i] & QMAN_ENQUEUE_FLAG_DCA)) {
+                       eq->dca = QM_EQCR_DCA_ENABLE |
+                               ((flags[i] >> 8) & QM_EQCR_DCA_IDXMASK);
+               }
+               i++;
+               eq = (void *)((unsigned long)(eq + 1) &
+                       (~(unsigned long)(QM_EQCR_SIZE << 6)));
+               eqcr->available--;
+               sent++;
+               fd++;
+       }
+       lwsync();
+
+       /* In order for flushes to complete faster, all lines are recorded in
+        * 32 bit word.
+        */
+       eq = eqcr->cursor;
+       for (i = 0; i < sent; i++) {
+               eq->__dont_write_directly__verb =
+                       QM_EQCR_VERB_CMD_ENQUEUE | eqcr->vbit;
+               prev_eq = eq;
+               eq = (void *)((unsigned long)(eq + 1) &
+                       (~(unsigned long)(QM_EQCR_SIZE << 6)));
+               if (unlikely((prev_eq + 1) != eq))
+                       eqcr->vbit ^= QM_EQCR_VERB_VBIT;
+       }
+
+       /* We need  to flush all the lines but without load/store operations
+        * between them
+        */
+       eq = eqcr->cursor;
+       for (i = 0; i < sent; i++) {
+               dcbf(eq);
+               eq = (void *)((unsigned long)(eq + 1) &
+                       (~(unsigned long)(QM_EQCR_SIZE << 6)));
+       }
+       /* Update cursor for the next call */
+       eqcr->cursor = eq;
+       return sent;
+}
+
+int
+qman_enqueue_multi_fq(struct qman_fq *fq[], const struct qm_fd *fd,
+                     int frames_to_send)
+{
+       struct qman_portal *p = get_affine_portal();
+       struct qm_portal *portal = &p->p;
+
+       register struct qm_eqcr *eqcr = &portal->eqcr;
+       struct qm_eqcr_entry *eq = eqcr->cursor, *prev_eq;
+
+       u8 i, diff, old_ci, sent = 0;
+
+       /* Update the available entries if no entry is free */
+       if (!eqcr->available) {
+               old_ci = eqcr->ci;
+               eqcr->ci = qm_cl_in(EQCR_CI) & (QM_EQCR_SIZE - 1);
+               diff = qm_cyc_diff(QM_EQCR_SIZE, old_ci, eqcr->ci);
+               eqcr->available += diff;
+               if (!diff)
+                       return 0;
+       }
+
+       /* try to send as many frames as possible */
+       while (eqcr->available && frames_to_send--) {
+               eq->fqid = fq[sent]->fqid_le;
+               eq->fd.opaque_addr = fd->opaque_addr;
+               eq->fd.addr = cpu_to_be40(fd->addr);
+               eq->fd.status = cpu_to_be32(fd->status);
+               eq->fd.opaque = cpu_to_be32(fd->opaque);
 
                eq = (void *)((unsigned long)(eq + 1) &
                        (~(unsigned long)(QM_EQCR_SIZE << 6)));
@@ -2498,7 +2643,7 @@ int qman_shutdown_fq(u32 fqid)
                                qm_mr_pvb_update(low_p);
                                msg = qm_mr_current(low_p);
                                while (msg) {
-                                       if ((msg->verb &
+                                       if ((msg->ern.verb &
                                             QM_MR_VERB_TYPE_MASK)
                                            == QM_MR_VERB_FQRN)
                                                found_fqrn = 1;
@@ -2566,7 +2711,7 @@ int qman_shutdown_fq(u32 fqid)
                        qm_mr_pvb_update(low_p);
                        msg = qm_mr_current(low_p);
                        while (msg) {
-                               if ((msg->verb & QM_MR_VERB_TYPE_MASK) ==
+                               if ((msg->ern.verb & QM_MR_VERB_TYPE_MASK) ==
                                    QM_MR_VERB_FQRL)
                                        orl_empty = 1;
                                qm_mr_next(low_p);