New upstream version 16.11.3
[deb_dpdk.git] / drivers / net / mlx5 / mlx5_txq.c
index 6fe61c4..d0c4dce 100644 (file)
 /* Verbs header. */
 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
 #ifdef PEDANTIC
-#pragma GCC diagnostic ignored "-pedantic"
+#pragma GCC diagnostic ignored "-Wpedantic"
 #endif
 #include <infiniband/verbs.h>
 #ifdef PEDANTIC
-#pragma GCC diagnostic error "-pedantic"
+#pragma GCC diagnostic error "-Wpedantic"
 #endif
 
 /* DPDK headers don't like -pedantic. */
 #ifdef PEDANTIC
-#pragma GCC diagnostic ignored "-pedantic"
+#pragma GCC diagnostic ignored "-Wpedantic"
 #endif
 #include <rte_mbuf.h>
 #include <rte_malloc.h>
 #include <rte_ethdev.h>
 #include <rte_common.h>
 #ifdef PEDANTIC
-#pragma GCC diagnostic error "-pedantic"
+#pragma GCC diagnostic error "-Wpedantic"
 #endif
 
 #include "mlx5_utils.h"
@@ -81,8 +81,8 @@ txq_alloc_elts(struct txq_ctrl *txq_ctrl, unsigned int elts_n)
 
        for (i = 0; (i != elts_n); ++i)
                (*txq_ctrl->txq.elts)[i] = NULL;
-       for (i = 0; (i != txq_ctrl->txq.wqe_n); ++i) {
-               volatile union mlx5_wqe *wqe = &(*txq_ctrl->txq.wqes)[i];
+       for (i = 0; (i != (1u << txq_ctrl->txq.wqe_n)); ++i) {
+               volatile struct mlx5_wqe64 *wqe = &(*txq_ctrl->txq.wqes)[i];
 
                memset((void *)(uintptr_t)wqe, 0x0, sizeof(*wqe));
        }
@@ -101,7 +101,7 @@ txq_alloc_elts(struct txq_ctrl *txq_ctrl, unsigned int elts_n)
 static void
 txq_free_elts(struct txq_ctrl *txq_ctrl)
 {
-       unsigned int elts_n = txq_ctrl->txq.elts_n;
+       unsigned int elts_n = 1 << txq_ctrl->txq.elts_n;
        unsigned int elts_head = txq_ctrl->txq.elts_head;
        unsigned int elts_tail = txq_ctrl->txq.elts_tail;
        struct rte_mbuf *(*elts)[elts_n] = txq_ctrl->txq.elts;
@@ -115,7 +115,7 @@ txq_free_elts(struct txq_ctrl *txq_ctrl)
                struct rte_mbuf *elt = (*elts)[elts_tail];
 
                assert(elt != NULL);
-               rte_pktmbuf_free(elt);
+               rte_pktmbuf_free_seg(elt);
 #ifndef NDEBUG
                /* Poisoning. */
                memset(&(*elts)[elts_tail],
@@ -205,29 +205,31 @@ txq_setup(struct txq_ctrl *tmpl, struct txq_ctrl *txq_ctrl)
 {
        struct mlx5_qp *qp = to_mqp(tmpl->qp);
        struct ibv_cq *ibcq = tmpl->cq;
-       struct mlx5_cq *cq = to_mxxx(cq, cq);
+       struct ibv_mlx5_cq_info cq_info;
 
-       if (cq->cqe_sz != RTE_CACHE_LINE_SIZE) {
+       if (ibv_mlx5_exp_get_cq_info(ibcq, &cq_info)) {
+               ERROR("Unable to query CQ info. check your OFED.");
+               return ENOTSUP;
+       }
+       if (cq_info.cqe_size != RTE_CACHE_LINE_SIZE) {
                ERROR("Wrong MLX5_CQE_SIZE environment variable value: "
                      "it should be set to %u", RTE_CACHE_LINE_SIZE);
                return EINVAL;
        }
-       tmpl->txq.cqe_n = ibcq->cqe + 1;
+       tmpl->txq.cqe_n = log2above(cq_info.cqe_cnt);
        tmpl->txq.qp_num_8s = qp->ctrl_seg.qp_num << 8;
        tmpl->txq.wqes =
-               (volatile union mlx5_wqe (*)[])
+               (volatile struct mlx5_wqe64 (*)[])
                (uintptr_t)qp->gen_data.sqstart;
-       tmpl->txq.wqe_n = qp->sq.wqe_cnt;
+       tmpl->txq.wqe_n = log2above(qp->sq.wqe_cnt);
        tmpl->txq.qp_db = &qp->gen_data.db[MLX5_SND_DBR];
        tmpl->txq.bf_reg = qp->gen_data.bf->reg;
-       tmpl->txq.bf_offset = qp->gen_data.bf->offset;
-       tmpl->txq.bf_buf_size = qp->gen_data.bf->buf_size;
-       tmpl->txq.cq_db = cq->dbrec;
+       tmpl->txq.cq_db = cq_info.dbrec;
        tmpl->txq.cqes =
                (volatile struct mlx5_cqe (*)[])
-               (uintptr_t)cq->active_buf->buf;
+               (uintptr_t)cq_info.buf;
        tmpl->txq.elts =
-               (struct rte_mbuf *(*)[tmpl->txq.elts_n])
+               (struct rte_mbuf *(*)[1 << tmpl->txq.elts_n])
                ((uintptr_t)txq_ctrl + sizeof(*txq_ctrl));
        return 0;
 }
@@ -277,7 +279,7 @@ txq_ctrl_setup(struct rte_eth_dev *dev, struct txq_ctrl *txq_ctrl,
        }
        (void)conf; /* Thresholds configuration (ignored). */
        assert(desc > MLX5_TX_COMP_THRESH);
-       tmpl.txq.elts_n = desc;
+       tmpl.txq.elts_n = log2above(desc);
        /* MRs will be registered in mp2mr[] later. */
        attr.rd = (struct ibv_exp_res_domain_init_attr){
                .comp_mask = (IBV_EXP_RES_DOMAIN_THREAD_MODEL |
@@ -338,9 +340,12 @@ txq_ctrl_setup(struct rte_eth_dev *dev, struct txq_ctrl *txq_ctrl,
                .comp_mask = (IBV_EXP_QP_INIT_ATTR_PD |
                              IBV_EXP_QP_INIT_ATTR_RES_DOMAIN),
        };
-       if (priv->txq_inline && priv->txqs_n >= priv->txqs_inline) {
-               tmpl.txq.max_inline = priv->txq_inline;
-               attr.init.cap.max_inline_data = tmpl.txq.max_inline;
+       if (priv->txq_inline && (priv->txqs_n >= priv->txqs_inline)) {
+               tmpl.txq.max_inline =
+                       ((priv->txq_inline + (RTE_CACHE_LINE_SIZE - 1)) /
+                        RTE_CACHE_LINE_SIZE);
+               attr.init.cap.max_inline_data =
+                       tmpl.txq.max_inline * RTE_CACHE_LINE_SIZE;
        }
        tmpl.qp = ibv_exp_create_qp(priv->ctx, &attr.init);
        if (tmpl.qp == NULL) {
@@ -495,6 +500,19 @@ mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                }
                (*priv->txqs)[idx] = NULL;
                txq_cleanup(txq_ctrl);
+               /* Resize if txq size is changed. */
+               if (txq_ctrl->txq.elts_n != log2above(desc)) {
+                       txq_ctrl = rte_realloc(txq_ctrl,
+                                              sizeof(*txq_ctrl) +
+                                              desc * sizeof(struct rte_mbuf *),
+                                              RTE_CACHE_LINE_SIZE);
+                       if (!txq_ctrl) {
+                               ERROR("%p: unable to reallocate queue index %u",
+                                       (void *)dev, idx);
+                               priv_unlock(priv);
+                               return -ENOMEM;
+                       }
+               }
        } else {
                txq_ctrl =
                        rte_calloc_socket("TXQ", 1,