net/mlx5: reposition event queue number field
[dpdk.git] / drivers / net / mlx5 / mlx5_txq.c
index 66ad368..c678971 100644 (file)
@@ -155,9 +155,9 @@ txq_sync_cq(struct mlx5_txq_data *txq)
                cqe->op_own = MLX5_CQE_INVALIDATE;
        }
        /* Resync CQE and WQE (WQ in reset state). */
-       rte_cio_wmb();
+       rte_io_wmb();
        *txq->cq_db = rte_cpu_to_be_32(txq->cq_ci);
-       rte_cio_wmb();
+       rte_io_wmb();
 }
 
 /**
@@ -244,7 +244,7 @@ mlx5_tx_queue_stop(struct rte_eth_dev *dev, uint16_t idx)
 {
        int ret;
 
-       if (dev->data->tx_queue_state[idx] == RTE_ETH_QUEUE_STATE_HAIRPIN) {
+       if (rte_eth_dev_is_tx_hairpin_queue(dev, idx)) {
                DRV_LOG(ERR, "Hairpin queue can't be stopped");
                rte_errno = EINVAL;
                return -EINVAL;
@@ -371,7 +371,7 @@ mlx5_tx_queue_start(struct rte_eth_dev *dev, uint16_t idx)
 {
        int ret;
 
-       if (dev->data->tx_queue_state[idx] == RTE_ETH_QUEUE_STATE_HAIRPIN) {
+       if (rte_eth_dev_is_tx_hairpin_queue(dev, idx)) {
                DRV_LOG(ERR, "Hairpin queue can't be started");
                rte_errno = EINVAL;
                return -EINVAL;
@@ -437,6 +437,7 @@ mlx5_tx_queue_pre_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t *desc)
        mlx5_txq_release(dev, idx);
        return 0;
 }
+
 /**
  * DPDK callback to configure a TX queue.
  *
@@ -833,146 +834,138 @@ mlx5_txq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx)
        }
        DRV_LOG(DEBUG, "port %u sxq %u updated with %p", dev->data->port_id,
                idx, (void *)&tmpl);
-       rte_atomic32_inc(&tmpl->refcnt);
        LIST_INSERT_HEAD(&priv->txqsobj, tmpl, next);
        return tmpl;
 }
 
 /**
- * Destroy the Tx queue DevX object.
+ * Release DevX SQ resources.
  *
- * @param txq_obj
- *   Txq object to destroy
+ * @param txq_ctrl
+ *   DevX Tx queue object.
  */
 static void
-txq_release_sq_resources(struct mlx5_txq_obj *txq_obj)
+txq_release_devx_sq_resources(struct mlx5_txq_obj *txq_obj)
 {
-       MLX5_ASSERT(txq_obj->type == MLX5_TXQ_OBJ_TYPE_DEVX_SQ);
-
        if (txq_obj->sq_devx)
                claim_zero(mlx5_devx_cmd_destroy(txq_obj->sq_devx));
-       if (txq_obj->sq_dbrec_page)
-               claim_zero(mlx5_release_dbr
-                               (&txq_obj->txq_ctrl->priv->dbrpgs,
-                               mlx5_os_get_umem_id
-                                       (txq_obj->sq_dbrec_page->umem),
-                               txq_obj->sq_dbrec_offset));
        if (txq_obj->sq_umem)
                claim_zero(mlx5_glue->devx_umem_dereg(txq_obj->sq_umem));
        if (txq_obj->sq_buf)
                mlx5_free(txq_obj->sq_buf);
+       if (txq_obj->sq_dbrec_page)
+               claim_zero(mlx5_release_dbr(&txq_obj->txq_ctrl->priv->dbrpgs,
+                                           mlx5_os_get_umem_id
+                                                (txq_obj->sq_dbrec_page->umem),
+                                           txq_obj->sq_dbrec_offset));
+}
+
+/**
+ * Release DevX Tx CQ resources.
+ *
+ * @param txq_ctrl
+ *   DevX Tx queue object.
+ */
+static void
+txq_release_devx_cq_resources(struct mlx5_txq_obj *txq_obj)
+{
        if (txq_obj->cq_devx)
                claim_zero(mlx5_devx_cmd_destroy(txq_obj->cq_devx));
-       if (txq_obj->cq_dbrec_page)
-               claim_zero(mlx5_release_dbr
-                               (&txq_obj->txq_ctrl->priv->dbrpgs,
-                               mlx5_os_get_umem_id
-                                       (txq_obj->cq_dbrec_page->umem),
-                               txq_obj->cq_dbrec_offset));
        if (txq_obj->cq_umem)
                claim_zero(mlx5_glue->devx_umem_dereg(txq_obj->cq_umem));
        if (txq_obj->cq_buf)
                mlx5_free(txq_obj->cq_buf);
+       if (txq_obj->cq_dbrec_page)
+               claim_zero(mlx5_release_dbr(&txq_obj->txq_ctrl->priv->dbrpgs,
+                                           mlx5_os_get_umem_id
+                                                (txq_obj->cq_dbrec_page->umem),
+                                           txq_obj->cq_dbrec_offset));
 }
 
 /**
- * Create the Tx queue DevX object.
+ * Destroy the Tx queue DevX object.
+ *
+ * @param txq_obj
+ *   Txq object to destroy
+ */
+static void
+txq_release_devx_resources(struct mlx5_txq_obj *txq_obj)
+{
+       MLX5_ASSERT(txq_obj->type == MLX5_TXQ_OBJ_TYPE_DEVX_SQ);
+
+       txq_release_devx_sq_resources(txq_obj);
+       txq_release_devx_cq_resources(txq_obj);
+}
+
+#ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
+/**
+ * Create a DevX CQ object for a Tx queue.
  *
  * @param dev
  *   Pointer to Ethernet device.
+ * @param cqe_n
+ *   Number of entries in the CQ.
  * @param idx
- *   Queue index in DPDK Tx queue array
+ *   Queue index in DPDK Tx queue array.
+ * @param type
+ *   Type of the Tx queue object to create.
  *
  * @return
- *   The DevX object initialised, NULL otherwise and rte_errno is set.
+ *   The DevX CQ object initialized, NULL otherwise and rte_errno is set.
  */
-static struct mlx5_txq_obj *
-mlx5_txq_obj_devx_new(struct rte_eth_dev *dev, uint16_t idx)
+static struct mlx5_devx_obj *
+mlx5_devx_cq_new(struct rte_eth_dev *dev, uint32_t cqe_n, uint16_t idx,
+                struct mlx5_txq_obj *txq_obj)
 {
-#ifndef HAVE_MLX5DV_DEVX_UAR_OFFSET
-       DRV_LOG(ERR, "port %u Tx queue %u cannot create with DevX, no UAR",
-                    dev->data->port_id, idx);
-       rte_errno = ENOMEM;
-       return NULL;
-#else
        struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_dev_ctx_shared *sh = priv->sh;
        struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
-       struct mlx5_txq_ctrl *txq_ctrl =
-               container_of(txq_data, struct mlx5_txq_ctrl, txq);
-       struct mlx5_devx_create_sq_attr sq_attr = { 0 };
-       struct mlx5_devx_modify_sq_attr msq_attr = { 0 };
+       struct mlx5_devx_obj *cq_obj = NULL;
        struct mlx5_devx_cq_attr cq_attr = { 0 };
-       struct mlx5_txq_obj *txq_obj = NULL;
-       size_t page_size;
        struct mlx5_cqe *cqe;
-       uint32_t i, nqe;
-       void *reg_addr;
-       size_t alignment = (size_t)-1;
-       int ret = 0;
+       size_t page_size;
+       size_t alignment;
+       uint32_t i;
+       int ret;
 
        MLX5_ASSERT(txq_data);
-       MLX5_ASSERT(!txq_ctrl->obj);
+       MLX5_ASSERT(txq_obj);
        page_size = rte_mem_page_size();
        if (page_size == (size_t)-1) {
                DRV_LOG(ERR, "Failed to get mem page size");
                rte_errno = ENOMEM;
                return NULL;
        }
-       txq_obj = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
-                             sizeof(struct mlx5_txq_obj), 0,
-                             txq_ctrl->socket);
-       if (!txq_obj) {
-               DRV_LOG(ERR,
-                       "port %u Tx queue %u cannot allocate memory resources",
-                       dev->data->port_id, txq_data->idx);
+       /* Allocate memory buffer for CQEs. */
+       alignment = MLX5_CQE_BUF_ALIGNMENT;
+       if (alignment == (size_t)-1) {
+               DRV_LOG(ERR, "Failed to get CQE buf alignment");
                rte_errno = ENOMEM;
                return NULL;
        }
-       txq_obj->type = MLX5_TXQ_OBJ_TYPE_DEVX_SQ;
-       txq_obj->txq_ctrl = txq_ctrl;
-       txq_obj->dev = dev;
-       /* Create the Completion Queue. */
-       nqe = (1UL << txq_data->elts_n) / MLX5_TX_COMP_THRESH +
-              1 + MLX5_TX_COMP_THRESH_INLINE_DIV;
-       nqe = 1UL << log2above(nqe);
-       if (nqe > UINT16_MAX) {
+       cqe_n = 1UL << log2above(cqe_n);
+       if (cqe_n > UINT16_MAX) {
                DRV_LOG(ERR,
                        "port %u Tx queue %u requests to many CQEs %u",
-                       dev->data->port_id, txq_data->idx, nqe);
+                       dev->data->port_id, txq_data->idx, cqe_n);
                rte_errno = EINVAL;
-               goto error;
-       }
-       /* Allocate memory buffer for CQEs. */
-       alignment = MLX5_CQE_BUF_ALIGNMENT;
-       if (alignment == (size_t)-1) {
-               DRV_LOG(ERR, "Failed to get mem page size");
-               rte_errno = ENOMEM;
-               goto error;
+               return NULL;
        }
        txq_obj->cq_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
-                                     nqe * sizeof(struct mlx5_cqe),
+                                     cqe_n * sizeof(struct mlx5_cqe),
                                      alignment,
-                                     sh->numa_node);
+                                     priv->sh->numa_node);
        if (!txq_obj->cq_buf) {
                DRV_LOG(ERR,
                        "port %u Tx queue %u cannot allocate memory (CQ)",
                        dev->data->port_id, txq_data->idx);
                rte_errno = ENOMEM;
-               goto error;
+               return NULL;
        }
-       txq_data->cqe_n = log2above(nqe);
-       txq_data->cqe_s = 1 << txq_data->cqe_n;
-       txq_data->cqe_m = txq_data->cqe_s - 1;
-       txq_data->cqes = (volatile struct mlx5_cqe *)txq_obj->cq_buf;
-       txq_data->cq_ci = 0;
-       txq_data->cq_pi = 0;
        /* Register allocated buffer in user space with DevX. */
-       txq_obj->cq_umem = mlx5_glue->devx_umem_reg
-                                       (sh->ctx,
-                                        (void *)txq_obj->cq_buf,
-                                        nqe * sizeof(struct mlx5_cqe),
-                                        IBV_ACCESS_LOCAL_WRITE);
+       txq_obj->cq_umem = mlx5_glue->devx_umem_reg(priv->sh->ctx,
+                                               (void *)txq_obj->cq_buf,
+                                               cqe_n * sizeof(struct mlx5_cqe),
+                                               IBV_ACCESS_LOCAL_WRITE);
        if (!txq_obj->cq_umem) {
                rte_errno = errno;
                DRV_LOG(ERR,
@@ -981,46 +974,88 @@ mlx5_txq_obj_devx_new(struct rte_eth_dev *dev, uint16_t idx)
                goto error;
        }
        /* Allocate doorbell record for completion queue. */
-       txq_obj->cq_dbrec_offset = mlx5_get_dbr(sh->ctx,
+       txq_obj->cq_dbrec_offset = mlx5_get_dbr(priv->sh->ctx,
                                                &priv->dbrpgs,
                                                &txq_obj->cq_dbrec_page);
-       if (txq_obj->cq_dbrec_offset < 0)
+       if (txq_obj->cq_dbrec_offset < 0) {
+               rte_errno = errno;
+               DRV_LOG(ERR, "Failed to allocate CQ door-bell.");
                goto error;
-       txq_data->cq_db = (volatile uint32_t *)(txq_obj->cq_dbrec_page->dbrs +
-                                               txq_obj->cq_dbrec_offset);
-       *txq_data->cq_db = 0;
-       /* Create completion queue object with DevX. */
+       }
        cq_attr.cqe_size = (sizeof(struct mlx5_cqe) == 128) ?
                            MLX5_CQE_SIZE_128B : MLX5_CQE_SIZE_64B;
-       cq_attr.uar_page_id = mlx5_os_get_devx_uar_page_id(sh->tx_uar);
-       cq_attr.eqn = sh->txpp.eqn;
+       cq_attr.uar_page_id = mlx5_os_get_devx_uar_page_id(priv->sh->tx_uar);
+       cq_attr.eqn = priv->sh->eqn;
        cq_attr.q_umem_valid = 1;
        cq_attr.q_umem_offset = (uintptr_t)txq_obj->cq_buf % page_size;
        cq_attr.q_umem_id = mlx5_os_get_umem_id(txq_obj->cq_umem);
        cq_attr.db_umem_valid = 1;
        cq_attr.db_umem_offset = txq_obj->cq_dbrec_offset;
        cq_attr.db_umem_id = mlx5_os_get_umem_id(txq_obj->cq_dbrec_page->umem);
-       cq_attr.log_cq_size = rte_log2_u32(nqe);
+       cq_attr.log_cq_size = rte_log2_u32(cqe_n);
        cq_attr.log_page_size = rte_log2_u32(page_size);
-       txq_obj->cq_devx = mlx5_devx_cmd_create_cq(sh->ctx, &cq_attr);
-       if (!txq_obj->cq_devx) {
+       /* Create completion queue object with DevX. */
+       cq_obj = mlx5_devx_cmd_create_cq(priv->sh->ctx, &cq_attr);
+       if (!cq_obj) {
                rte_errno = errno;
                DRV_LOG(ERR, "port %u Tx queue %u CQ creation failure",
                        dev->data->port_id, idx);
                goto error;
        }
+       txq_data->cqe_n = log2above(cqe_n);
+       txq_data->cqe_s = 1 << txq_data->cqe_n;
        /* Initial fill CQ buffer with invalid CQE opcode. */
        cqe = (struct mlx5_cqe *)txq_obj->cq_buf;
        for (i = 0; i < txq_data->cqe_s; i++) {
                cqe->op_own = (MLX5_CQE_INVALID << 4) | MLX5_CQE_OWNER_MASK;
                ++cqe;
        }
-       /* Create the Work Queue. */
-       nqe = RTE_MIN(1UL << txq_data->elts_n,
-                     (uint32_t)sh->device_attr.max_qp_wr);
+       return cq_obj;
+error:
+       ret = rte_errno;
+       txq_release_devx_cq_resources(txq_obj);
+       rte_errno = ret;
+       return NULL;
+}
+
+/**
+ * Create a SQ object using DevX.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param idx
+ *   Queue index in DPDK Tx queue array.
+ * @param type
+ *   Type of the Tx queue object to create.
+ *
+ * @return
+ *   The DevX object initialized, NULL otherwise and rte_errno is set.
+ */
+static struct mlx5_devx_obj *
+mlx5_devx_sq_new(struct rte_eth_dev *dev, uint16_t idx,
+                struct mlx5_txq_obj *txq_obj)
+{
+       struct mlx5_priv *priv = dev->data->dev_private;
+       struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
+       struct mlx5_devx_create_sq_attr sq_attr = { 0 };
+       struct mlx5_devx_obj *sq_obj = NULL;
+       size_t page_size;
+       uint32_t wqe_n;
+       int ret;
+
+       MLX5_ASSERT(txq_data);
+       MLX5_ASSERT(txq_obj);
+       page_size = rte_mem_page_size();
+       if (page_size == (size_t)-1) {
+               DRV_LOG(ERR, "Failed to get mem page size");
+               rte_errno = ENOMEM;
+               return NULL;
+       }
+       wqe_n = RTE_MIN(1UL << txq_data->elts_n,
+                       (uint32_t)priv->sh->device_attr.max_qp_wr);
        txq_obj->sq_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
-                                     nqe * sizeof(struct mlx5_wqe),
-                                     page_size, sh->numa_node);
+                                     wqe_n * sizeof(struct mlx5_wqe),
+                                     page_size, priv->sh->numa_node);
        if (!txq_obj->sq_buf) {
                DRV_LOG(ERR,
                        "port %u Tx queue %u cannot allocate memory (SQ)",
@@ -1028,20 +1063,11 @@ mlx5_txq_obj_devx_new(struct rte_eth_dev *dev, uint16_t idx)
                rte_errno = ENOMEM;
                goto error;
        }
-       txq_data->wqe_n = log2above(nqe);
-       txq_data->wqe_s = 1 << txq_data->wqe_n;
-       txq_data->wqe_m = txq_data->wqe_s - 1;
-       txq_data->wqes = (struct mlx5_wqe *)txq_obj->sq_buf;
-       txq_data->wqes_end = txq_data->wqes + txq_data->wqe_s;
-       txq_data->wqe_ci = 0;
-       txq_data->wqe_pi = 0;
-       txq_data->wqe_comp = 0;
-       txq_data->wqe_thres = txq_data->wqe_s / MLX5_TX_COMP_THRESH_INLINE_DIV;
        /* Register allocated buffer in user space with DevX. */
        txq_obj->sq_umem = mlx5_glue->devx_umem_reg
-                                       (sh->ctx,
+                                       (priv->sh->ctx,
                                         (void *)txq_obj->sq_buf,
-                                        nqe * sizeof(struct mlx5_wqe),
+                                        wqe_n * sizeof(struct mlx5_wqe),
                                         IBV_ACCESS_LOCAL_WRITE);
        if (!txq_obj->sq_umem) {
                rte_errno = errno;
@@ -1050,45 +1076,136 @@ mlx5_txq_obj_devx_new(struct rte_eth_dev *dev, uint16_t idx)
                        dev->data->port_id, txq_data->idx);
                goto error;
        }
-       /* Allocate doorbell record for completion queue. */
-       txq_obj->cq_dbrec_offset = mlx5_get_dbr(sh->ctx,
+       /* Allocate doorbell record for send queue. */
+       txq_obj->sq_dbrec_offset = mlx5_get_dbr(priv->sh->ctx,
                                                &priv->dbrpgs,
                                                &txq_obj->sq_dbrec_page);
-       if (txq_obj->sq_dbrec_offset < 0)
+       if (txq_obj->sq_dbrec_offset < 0) {
+               rte_errno = errno;
+               DRV_LOG(ERR, "Failed to allocate SQ door-bell.");
                goto error;
-       txq_data->qp_db = (volatile uint32_t *)
-                                       (txq_obj->sq_dbrec_page->dbrs +
-                                        txq_obj->sq_dbrec_offset +
-                                        MLX5_SND_DBR * sizeof(uint32_t));
-       *txq_data->qp_db = 0;
-       /* Create Send Queue object with DevX. */
+       }
        sq_attr.tis_lst_sz = 1;
-       sq_attr.tis_num = sh->tis->id;
+       sq_attr.tis_num = priv->sh->tis->id;
        sq_attr.state = MLX5_SQC_STATE_RST;
        sq_attr.cqn = txq_obj->cq_devx->id;
        sq_attr.flush_in_error_en = 1;
        sq_attr.allow_multi_pkt_send_wqe = !!priv->config.mps;
        sq_attr.allow_swp = !!priv->config.swp;
        sq_attr.min_wqe_inline_mode = priv->config.hca_attr.vport_inline_mode;
-       sq_attr.wq_attr.uar_page = mlx5_os_get_devx_uar_page_id(sh->tx_uar);
+       sq_attr.wq_attr.uar_page =
+                               mlx5_os_get_devx_uar_page_id(priv->sh->tx_uar);
        sq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
-       sq_attr.wq_attr.pd = sh->pdn;
+       sq_attr.wq_attr.pd = priv->sh->pdn;
        sq_attr.wq_attr.log_wq_stride = rte_log2_u32(MLX5_WQE_SIZE);
-       sq_attr.wq_attr.log_wq_sz = txq_data->wqe_n;
+       sq_attr.wq_attr.log_wq_sz = log2above(wqe_n);
        sq_attr.wq_attr.dbr_umem_valid = 1;
-       sq_attr.wq_attr.dbr_addr = txq_obj->cq_dbrec_offset;
+       sq_attr.wq_attr.dbr_addr = txq_obj->sq_dbrec_offset;
        sq_attr.wq_attr.dbr_umem_id =
-                       mlx5_os_get_umem_id(txq_obj->cq_dbrec_page->umem);
+                       mlx5_os_get_umem_id(txq_obj->sq_dbrec_page->umem);
        sq_attr.wq_attr.wq_umem_valid = 1;
        sq_attr.wq_attr.wq_umem_id = mlx5_os_get_umem_id(txq_obj->sq_umem);
        sq_attr.wq_attr.wq_umem_offset = (uintptr_t)txq_obj->sq_buf % page_size;
-       txq_obj->sq_devx = mlx5_devx_cmd_create_sq(sh->ctx, &sq_attr);
-       if (!txq_obj->sq_devx) {
+       /* Create Send Queue object with DevX. */
+       sq_obj = mlx5_devx_cmd_create_sq(priv->sh->ctx, &sq_attr);
+       if (!sq_obj) {
                rte_errno = errno;
                DRV_LOG(ERR, "port %u Tx queue %u SQ creation failure",
                        dev->data->port_id, idx);
                goto error;
        }
+       txq_data->wqe_n = log2above(wqe_n);
+       return sq_obj;
+error:
+       ret = rte_errno;
+       txq_release_devx_sq_resources(txq_obj);
+       rte_errno = ret;
+       return NULL;
+}
+#endif
+
+/**
+ * Create the Tx queue DevX object.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param idx
+ *   Queue index in DPDK Tx queue array.
+ *
+ * @return
+ *   The DevX object initialised, NULL otherwise and rte_errno is set.
+ */
+static struct mlx5_txq_obj *
+mlx5_txq_obj_devx_new(struct rte_eth_dev *dev, uint16_t idx)
+{
+#ifndef HAVE_MLX5DV_DEVX_UAR_OFFSET
+       DRV_LOG(ERR, "port %u Tx queue %u cannot create with DevX, no UAR",
+                    dev->data->port_id, idx);
+       rte_errno = ENOMEM;
+       return NULL;
+#else
+       struct mlx5_priv *priv = dev->data->dev_private;
+       struct mlx5_dev_ctx_shared *sh = priv->sh;
+       struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
+       struct mlx5_txq_ctrl *txq_ctrl =
+               container_of(txq_data, struct mlx5_txq_ctrl, txq);
+       struct mlx5_devx_modify_sq_attr msq_attr = { 0 };
+       struct mlx5_txq_obj *txq_obj = NULL;
+       void *reg_addr;
+       uint32_t cqe_n;
+       int ret = 0;
+
+       MLX5_ASSERT(txq_data);
+       MLX5_ASSERT(!txq_ctrl->obj);
+       txq_obj = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
+                             sizeof(struct mlx5_txq_obj), 0,
+                             txq_ctrl->socket);
+       if (!txq_obj) {
+               DRV_LOG(ERR,
+                       "port %u Tx queue %u cannot allocate memory resources",
+                       dev->data->port_id, txq_data->idx);
+               rte_errno = ENOMEM;
+               return NULL;
+       }
+       txq_obj->type = MLX5_TXQ_OBJ_TYPE_DEVX_SQ;
+       txq_obj->txq_ctrl = txq_ctrl;
+       txq_obj->dev = dev;
+       /* Create the Completion Queue. */
+       cqe_n = (1UL << txq_data->elts_n) / MLX5_TX_COMP_THRESH +
+               1 + MLX5_TX_COMP_THRESH_INLINE_DIV;
+       /* Create completion queue object with DevX. */
+       txq_obj->cq_devx = mlx5_devx_cq_new(dev, cqe_n, idx, txq_obj);
+       if (!txq_obj->cq_devx) {
+               rte_errno = errno;
+               goto error;
+       }
+       txq_data->cqe_m = txq_data->cqe_s - 1;
+       txq_data->cqes = (volatile struct mlx5_cqe *)txq_obj->cq_buf;
+       txq_data->cq_ci = 0;
+       txq_data->cq_pi = 0;
+       txq_data->cq_db = (volatile uint32_t *)(txq_obj->cq_dbrec_page->dbrs +
+                                               txq_obj->cq_dbrec_offset);
+       *txq_data->cq_db = 0;
+       /* Create Send Queue object with DevX. */
+       txq_obj->sq_devx = mlx5_devx_sq_new(dev, idx, txq_obj);
+       if (!txq_obj->sq_devx) {
+               rte_errno = errno;
+               goto error;
+       }
+       /* Create the Work Queue. */
+       txq_data->wqe_s = 1 << txq_data->wqe_n;
+       txq_data->wqe_m = txq_data->wqe_s - 1;
+       txq_data->wqes = (struct mlx5_wqe *)txq_obj->sq_buf;
+       txq_data->wqes_end = txq_data->wqes + txq_data->wqe_s;
+       txq_data->wqe_ci = 0;
+       txq_data->wqe_pi = 0;
+       txq_data->wqe_comp = 0;
+       txq_data->wqe_thres = txq_data->wqe_s / MLX5_TX_COMP_THRESH_INLINE_DIV;
+       txq_data->qp_db = (volatile uint32_t *)
+                                       (txq_obj->sq_dbrec_page->dbrs +
+                                        txq_obj->sq_dbrec_offset +
+                                        MLX5_SND_DBR * sizeof(uint32_t));
+       *txq_data->qp_db = 0;
        txq_data->qp_num_8s = txq_obj->sq_devx->id << 8;
        /* Change Send Queue state to Ready-to-Send. */
        msq_attr.sq_state = MLX5_SQC_STATE_RST;
@@ -1126,13 +1243,12 @@ mlx5_txq_obj_devx_new(struct rte_eth_dev *dev, uint16_t idx)
        txq_ctrl->bf_reg = reg_addr;
        txq_ctrl->uar_mmap_offset =
                mlx5_os_get_devx_uar_mmap_offset(sh->tx_uar);
-       rte_atomic32_set(&txq_obj->refcnt, 1);
        txq_uar_init(txq_ctrl);
        LIST_INSERT_HEAD(&priv->txqsobj, txq_obj, next);
        return txq_obj;
 error:
        ret = rte_errno; /* Save rte_errno before cleanup. */
-       txq_release_sq_resources(txq_obj);
+       txq_release_devx_resources(txq_obj);
        if (txq_data->fcqs) {
                mlx5_free(txq_data->fcqs);
                txq_data->fcqs = NULL;
@@ -1143,6 +1259,66 @@ error:
 #endif
 }
 
+/**
+ * Create a QP Verbs object.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param idx
+ *   Queue index in DPDK Tx queue array.
+ * @param rxq_obj
+ *   Pointer to Tx queue object data.
+ *
+ * @return
+ *   The QP Verbs object initialized, NULL otherwise and rte_errno is set.
+ */
+static struct ibv_qp *
+mlx5_ibv_qp_new(struct rte_eth_dev *dev, uint16_t idx,
+               struct mlx5_txq_obj *txq_obj)
+{
+       struct mlx5_priv *priv = dev->data->dev_private;
+       struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
+       struct mlx5_txq_ctrl *txq_ctrl =
+                       container_of(txq_data, struct mlx5_txq_ctrl, txq);
+       struct ibv_qp *qp_obj = NULL;
+       struct ibv_qp_init_attr_ex qp_attr = { 0 };
+       const int desc = 1 << txq_data->elts_n;
+
+       MLX5_ASSERT(!txq_ctrl->obj);
+       /* CQ to be associated with the send queue. */
+       qp_attr.send_cq = txq_obj->cq;
+       /* CQ to be associated with the receive queue. */
+       qp_attr.recv_cq = txq_obj->cq;
+       /* Max number of outstanding WRs. */
+       qp_attr.cap.max_send_wr = ((priv->sh->device_attr.max_qp_wr < desc) ?
+                                  priv->sh->device_attr.max_qp_wr : desc);
+       /*
+        * Max number of scatter/gather elements in a WR, must be 1 to prevent
+        * libmlx5 from trying to affect must be 1 to prevent libmlx5 from
+        * trying to affect too much memory. TX gather is not impacted by the
+        * device_attr.max_sge limit and will still work properly.
+        */
+       qp_attr.cap.max_send_sge = 1;
+       qp_attr.qp_type = IBV_QPT_RAW_PACKET,
+       /* Do *NOT* enable this, completions events are managed per Tx burst. */
+       qp_attr.sq_sig_all = 0;
+       qp_attr.pd = priv->sh->pd;
+       qp_attr.comp_mask = IBV_QP_INIT_ATTR_PD;
+       if (txq_data->inlen_send)
+               qp_attr.cap.max_inline_data = txq_ctrl->max_inline_data;
+       if (txq_data->tso_en) {
+               qp_attr.max_tso_header = txq_ctrl->max_tso_header;
+               qp_attr.comp_mask |= IBV_QP_INIT_ATTR_MAX_TSO_HEADER;
+       }
+       qp_obj = mlx5_glue->create_qp_ex(priv->sh->ctx, &qp_attr);
+       if (qp_obj == NULL) {
+               DRV_LOG(ERR, "port %u Tx queue %u QP creation failure",
+                       dev->data->port_id, idx);
+               rte_errno = errno;
+       }
+       return qp_obj;
+}
+
 /**
  * Create the Tx queue Verbs object.
  *
@@ -1166,11 +1342,7 @@ mlx5_txq_obj_new(struct rte_eth_dev *dev, uint16_t idx,
                container_of(txq_data, struct mlx5_txq_ctrl, txq);
        struct mlx5_txq_obj tmpl;
        struct mlx5_txq_obj *txq_obj = NULL;
-       union {
-               struct ibv_qp_init_attr_ex init;
-               struct ibv_cq_init_attr_ex cq;
-               struct ibv_qp_attr mod;
-       } attr;
+       struct ibv_qp_attr mod;
        unsigned int cqe_n;
        struct mlx5dv_qp qp = { .comp_mask = MLX5DV_QP_MASK_UAR_MMAP_OFFSET };
        struct mlx5dv_cq cq_info;
@@ -1198,9 +1370,6 @@ mlx5_txq_obj_new(struct rte_eth_dev *dev, uint16_t idx,
                return NULL;
        }
        memset(&tmpl, 0, sizeof(struct mlx5_txq_obj));
-       attr.cq = (struct ibv_cq_init_attr_ex){
-               .comp_mask = 0,
-       };
        cqe_n = desc / MLX5_TX_COMP_THRESH +
                1 + MLX5_TX_COMP_THRESH_INLINE_DIV;
        tmpl.cq = mlx5_glue->create_cq(priv->sh->ctx, cqe_n, NULL, NULL, 0);
@@ -1210,56 +1379,18 @@ mlx5_txq_obj_new(struct rte_eth_dev *dev, uint16_t idx,
                rte_errno = errno;
                goto error;
        }
-       attr.init = (struct ibv_qp_init_attr_ex){
-               /* CQ to be associated with the send queue. */
-               .send_cq = tmpl.cq,
-               /* CQ to be associated with the receive queue. */
-               .recv_cq = tmpl.cq,
-               .cap = {
-                       /* Max number of outstanding WRs. */
-                       .max_send_wr =
-                               ((priv->sh->device_attr.max_qp_wr <
-                                 desc) ?
-                                priv->sh->device_attr.max_qp_wr :
-                                desc),
-                       /*
-                        * Max number of scatter/gather elements in a WR,
-                        * must be 1 to prevent libmlx5 from trying to affect
-                        * too much memory. TX gather is not impacted by the
-                        * device_attr.max_sge limit and will still work
-                        * properly.
-                        */
-                       .max_send_sge = 1,
-               },
-               .qp_type = IBV_QPT_RAW_PACKET,
-               /*
-                * Do *NOT* enable this, completions events are managed per
-                * Tx burst.
-                */
-               .sq_sig_all = 0,
-               .pd = priv->sh->pd,
-               .comp_mask = IBV_QP_INIT_ATTR_PD,
-       };
-       if (txq_data->inlen_send)
-               attr.init.cap.max_inline_data = txq_ctrl->max_inline_data;
-       if (txq_data->tso_en) {
-               attr.init.max_tso_header = txq_ctrl->max_tso_header;
-               attr.init.comp_mask |= IBV_QP_INIT_ATTR_MAX_TSO_HEADER;
-       }
-       tmpl.qp = mlx5_glue->create_qp_ex(priv->sh->ctx, &attr.init);
+       tmpl.qp = mlx5_ibv_qp_new(dev, idx, &tmpl);
        if (tmpl.qp == NULL) {
-               DRV_LOG(ERR, "port %u Tx queue %u QP creation failure",
-                       dev->data->port_id, idx);
                rte_errno = errno;
                goto error;
        }
-       attr.mod = (struct ibv_qp_attr){
+       mod = (struct ibv_qp_attr){
                /* Move the QP to this state. */
                .qp_state = IBV_QPS_INIT,
                /* IB device port number. */
                .port_num = (uint8_t)priv->dev_port,
        };
-       ret = mlx5_glue->modify_qp(tmpl.qp, &attr.mod,
+       ret = mlx5_glue->modify_qp(tmpl.qp, &mod,
                                   (IBV_QP_STATE | IBV_QP_PORT));
        if (ret) {
                DRV_LOG(ERR,
@@ -1268,10 +1399,10 @@ mlx5_txq_obj_new(struct rte_eth_dev *dev, uint16_t idx,
                rte_errno = errno;
                goto error;
        }
-       attr.mod = (struct ibv_qp_attr){
+       mod = (struct ibv_qp_attr){
                .qp_state = IBV_QPS_RTR
        };
-       ret = mlx5_glue->modify_qp(tmpl.qp, &attr.mod, IBV_QP_STATE);
+       ret = mlx5_glue->modify_qp(tmpl.qp, &mod, IBV_QP_STATE);
        if (ret) {
                DRV_LOG(ERR,
                        "port %u Tx queue %u QP state to IBV_QPS_RTR failed",
@@ -1279,8 +1410,8 @@ mlx5_txq_obj_new(struct rte_eth_dev *dev, uint16_t idx,
                rte_errno = errno;
                goto error;
        }
-       attr.mod.qp_state = IBV_QPS_RTS;
-       ret = mlx5_glue->modify_qp(tmpl.qp, &attr.mod, IBV_QP_STATE);
+       mod.qp_state = IBV_QPS_RTS;
+       ret = mlx5_glue->modify_qp(tmpl.qp, &mod, IBV_QP_STATE);
        if (ret) {
                DRV_LOG(ERR,
                        "port %u Tx queue %u QP state to IBV_QPS_RTS failed",
@@ -1364,7 +1495,6 @@ mlx5_txq_obj_new(struct rte_eth_dev *dev, uint16_t idx,
 #endif
        txq_obj->qp = tmpl.qp;
        txq_obj->cq = tmpl.cq;
-       rte_atomic32_inc(&txq_obj->refcnt);
        txq_ctrl->bf_reg = qp.bf.reg;
        if (qp.comp_mask & MLX5DV_QP_MASK_UAR_MMAP_OFFSET) {
                txq_ctrl->uar_mmap_offset = qp.uar_mmap_offset;
@@ -1400,65 +1530,31 @@ error:
        return NULL;
 }
 
-/**
- * Get an Tx queue Verbs object.
- *
- * @param dev
- *   Pointer to Ethernet device.
- * @param idx
- *   Queue index in DPDK Tx queue array.
- *
- * @return
- *   The Verbs object if it exists.
- */
-struct mlx5_txq_obj *
-mlx5_txq_obj_get(struct rte_eth_dev *dev, uint16_t idx)
-{
-       struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_txq_ctrl *txq_ctrl;
-
-       if (idx >= priv->txqs_n)
-               return NULL;
-       if (!(*priv->txqs)[idx])
-               return NULL;
-       txq_ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
-       if (txq_ctrl->obj)
-               rte_atomic32_inc(&txq_ctrl->obj->refcnt);
-       return txq_ctrl->obj;
-}
-
 /**
  * Release an Tx verbs queue object.
  *
  * @param txq_obj
- *   Verbs Tx queue object.
- *
- * @return
- *   1 while a reference on it exists, 0 when freed.
+ *   Verbs Tx queue object..
  */
-int
+void
 mlx5_txq_obj_release(struct mlx5_txq_obj *txq_obj)
 {
        MLX5_ASSERT(txq_obj);
-       if (rte_atomic32_dec_and_test(&txq_obj->refcnt)) {
-               if (txq_obj->type == MLX5_TXQ_OBJ_TYPE_DEVX_HAIRPIN) {
-                       if (txq_obj->tis)
-                               claim_zero(mlx5_devx_cmd_destroy(txq_obj->tis));
-               } else if (txq_obj->type == MLX5_TXQ_OBJ_TYPE_DEVX_SQ) {
-                       txq_release_sq_resources(txq_obj);
-               } else {
-                       claim_zero(mlx5_glue->destroy_qp(txq_obj->qp));
-                       claim_zero(mlx5_glue->destroy_cq(txq_obj->cq));
-               }
-               if (txq_obj->txq_ctrl->txq.fcqs) {
-                       mlx5_free(txq_obj->txq_ctrl->txq.fcqs);
-                       txq_obj->txq_ctrl->txq.fcqs = NULL;
-               }
-               LIST_REMOVE(txq_obj, next);
-               mlx5_free(txq_obj);
-               return 0;
+       if (txq_obj->type == MLX5_TXQ_OBJ_TYPE_DEVX_HAIRPIN) {
+               if (txq_obj->tis)
+                       claim_zero(mlx5_devx_cmd_destroy(txq_obj->tis));
+       } else if (txq_obj->type == MLX5_TXQ_OBJ_TYPE_DEVX_SQ) {
+               txq_release_devx_resources(txq_obj);
+       } else {
+               claim_zero(mlx5_glue->destroy_qp(txq_obj->qp));
+               claim_zero(mlx5_glue->destroy_cq(txq_obj->cq));
        }
-       return 1;
+       if (txq_obj->txq_ctrl->txq.fcqs) {
+               mlx5_free(txq_obj->txq_ctrl->txq.fcqs);
+               txq_obj->txq_ctrl->txq.fcqs = NULL;
+       }
+       LIST_REMOVE(txq_obj, next);
+       mlx5_free(txq_obj);
 }
 
 /**
@@ -1971,12 +2067,11 @@ struct mlx5_txq_ctrl *
 mlx5_txq_get(struct rte_eth_dev *dev, uint16_t idx)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
+       struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
        struct mlx5_txq_ctrl *ctrl = NULL;
 
-       if ((*priv->txqs)[idx]) {
-               ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl,
-                                   txq);
-               mlx5_txq_obj_get(dev, idx);
+       if (txq_data) {
+               ctrl = container_of(txq_data, struct mlx5_txq_ctrl, txq);
                rte_atomic32_inc(&ctrl->refcnt);
        }
        return ctrl;
@@ -2002,18 +2097,19 @@ mlx5_txq_release(struct rte_eth_dev *dev, uint16_t idx)
        if (!(*priv->txqs)[idx])
                return 0;
        txq = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq);
-       if (txq->obj && !mlx5_txq_obj_release(txq->obj))
+       if (!rte_atomic32_dec_and_test(&txq->refcnt))
+               return 1;
+       if (txq->obj) {
+               mlx5_txq_obj_release(txq->obj);
                txq->obj = NULL;
-       if (rte_atomic32_dec_and_test(&txq->refcnt)) {
-               txq_free_elts(txq);
-               mlx5_mr_btree_free(&txq->txq.mr_ctrl.cache_bh);
-               LIST_REMOVE(txq, next);
-               mlx5_free(txq);
-               (*priv->txqs)[idx] = NULL;
-               dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED;
-               return 0;
        }
-       return 1;
+       txq_free_elts(txq);
+       mlx5_mr_btree_free(&txq->txq.mr_ctrl.cache_bh);
+       LIST_REMOVE(txq, next);
+       mlx5_free(txq);
+       (*priv->txqs)[idx] = NULL;
+       dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED;
+       return 0;
 }
 
 /**