net/mlx5: add reference counter on memory region
[dpdk.git] / drivers / net / mlx5 / mlx5_rxq.c
index b71f72f..0d645ec 100644 (file)
@@ -374,10 +374,10 @@ priv_create_hash_rxqs(struct priv *priv)
                      priv->reta_idx_n);
        }
        for (i = 0; (i != priv->reta_idx_n); ++i) {
-               struct rxq_ctrl *rxq_ctrl;
+               struct mlx5_rxq_ctrl *rxq_ctrl;
 
                rxq_ctrl = container_of((*priv->rxqs)[(*priv->reta_idx)[i]],
-                                       struct rxq_ctrl, rxq);
+                                       struct mlx5_rxq_ctrl, rxq);
                wqs[i] = rxq_ctrl->wq;
        }
        /* Get number of hash RX queues to configure. */
@@ -636,7 +636,7 @@ priv_rehash_flows(struct priv *priv)
  *   0 on success, errno value on failure.
  */
 static int
-rxq_alloc_elts(struct rxq_ctrl *rxq_ctrl, unsigned int elts_n)
+rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl, unsigned int elts_n)
 {
        const unsigned int sges_n = 1 << rxq_ctrl->rxq.sges_n;
        unsigned int i;
@@ -673,12 +673,12 @@ rxq_alloc_elts(struct rxq_ctrl *rxq_ctrl, unsigned int elts_n)
                        .addr =
                            rte_cpu_to_be_64(rte_pktmbuf_mtod(buf, uintptr_t)),
                        .byte_count = rte_cpu_to_be_32(DATA_LEN(buf)),
-                       .lkey = rte_cpu_to_be_32(rxq_ctrl->mr->lkey),
+                       .lkey = rxq_ctrl->mr->lkey,
                };
                (*rxq_ctrl->rxq.elts)[i] = buf;
        }
        if (rxq_check_vec_support(&rxq_ctrl->rxq) > 0) {
-               struct rxq *rxq = &rxq_ctrl->rxq;
+               struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
                struct rte_mbuf *mbuf_init = &rxq->fake_mbuf;
 
                assert(rxq->elts_n == rxq->cqe_n);
@@ -720,9 +720,9 @@ error:
  *   Pointer to RX queue structure.
  */
 static void
-rxq_free_elts(struct rxq_ctrl *rxq_ctrl)
+rxq_free_elts(struct mlx5_rxq_ctrl *rxq_ctrl)
 {
-       struct rxq *rxq = &rxq_ctrl->rxq;
+       struct mlx5_rxq_data *rxq = &rxq_ctrl->rxq;
        const uint16_t q_n = (1 << rxq->elts_n);
        const uint16_t q_mask = q_n - 1;
        uint16_t used = q_n - (rxq->rq_ci - rxq->rq_pi);
@@ -756,12 +756,10 @@ rxq_free_elts(struct rxq_ctrl *rxq_ctrl)
  *   Pointer to RX queue structure.
  */
 void
-rxq_cleanup(struct rxq_ctrl *rxq_ctrl)
+mlx5_rxq_cleanup(struct mlx5_rxq_ctrl *rxq_ctrl)
 {
        DEBUG("cleaning up %p", (void *)rxq_ctrl);
        rxq_free_elts(rxq_ctrl);
-       if (rxq_ctrl->fdir_queue != NULL)
-               priv_fdir_queue_destroy(rxq_ctrl->priv, rxq_ctrl->fdir_queue);
        if (rxq_ctrl->wq != NULL)
                claim_zero(ibv_destroy_wq(rxq_ctrl->wq));
        if (rxq_ctrl->cq != NULL)
@@ -769,7 +767,7 @@ rxq_cleanup(struct rxq_ctrl *rxq_ctrl)
        if (rxq_ctrl->channel != NULL)
                claim_zero(ibv_destroy_comp_channel(rxq_ctrl->channel));
        if (rxq_ctrl->mr != NULL)
-               claim_zero(ibv_dereg_mr(rxq_ctrl->mr));
+               priv_mr_release(rxq_ctrl->priv, rxq_ctrl->mr);
        memset(rxq_ctrl, 0, sizeof(*rxq_ctrl));
 }
 
@@ -783,7 +781,7 @@ rxq_cleanup(struct rxq_ctrl *rxq_ctrl)
  *   0 on success, errno value on failure.
  */
 static inline int
-rxq_setup(struct rxq_ctrl *tmpl)
+rxq_setup(struct mlx5_rxq_ctrl *tmpl)
 {
        struct ibv_cq *ibcq = tmpl->cq;
        struct mlx5dv_cq cq_info;
@@ -850,12 +848,12 @@ rxq_setup(struct rxq_ctrl *tmpl)
  *   0 on success, errno value on failure.
  */
 static int
-rxq_ctrl_setup(struct rte_eth_dev *dev, struct rxq_ctrl *rxq_ctrl,
+rxq_ctrl_setup(struct rte_eth_dev *dev, struct mlx5_rxq_ctrl *rxq_ctrl,
               uint16_t desc, unsigned int socket,
               const struct rte_eth_rxconf *conf, struct rte_mempool *mp)
 {
        struct priv *priv = dev->data->dev_private;
-       struct rxq_ctrl tmpl = {
+       struct mlx5_rxq_ctrl tmpl = {
                .priv = priv,
                .socket = socket,
                .rxq = {
@@ -931,12 +929,15 @@ rxq_ctrl_setup(struct rte_eth_dev *dev, struct rxq_ctrl *rxq_ctrl,
                tmpl.rxq.csum_l2tun =
                        !!dev->data->dev_conf.rxmode.hw_ip_checksum;
        /* Use the entire RX mempool as the memory region. */
-       tmpl.mr = mlx5_mp2mr(priv->pd, mp);
+       tmpl.mr = priv_mr_get(priv, mp);
        if (tmpl.mr == NULL) {
-               ret = EINVAL;
-               ERROR("%p: MR creation failure: %s",
-                     (void *)dev, strerror(ret));
-               goto error;
+               tmpl.mr = priv_mr_new(priv, mp);
+               if (tmpl.mr == NULL) {
+                       ret = EINVAL;
+                       ERROR("%p: MR creation failure: %s",
+                             (void *)dev, strerror(ret));
+                       goto error;
+               }
        }
        if (dev->data->dev_conf.intr_conf.rxq) {
                tmpl.channel = ibv_create_comp_channel(priv->ctx);
@@ -1074,7 +1075,7 @@ rxq_ctrl_setup(struct rte_eth_dev *dev, struct rxq_ctrl *rxq_ctrl,
        }
        /* Clean up rxq in case we're reinitializing it. */
        DEBUG("%p: cleaning-up old rxq just in case", (void *)rxq_ctrl);
-       rxq_cleanup(rxq_ctrl);
+       mlx5_rxq_cleanup(rxq_ctrl);
        /* Move mbuf pointers to dedicated storage area in RX queue. */
        elts = (void *)(rxq_ctrl + 1);
        rte_memcpy(elts, tmpl.rxq.elts, sizeof(*elts));
@@ -1093,7 +1094,7 @@ rxq_ctrl_setup(struct rte_eth_dev *dev, struct rxq_ctrl *rxq_ctrl,
        return 0;
 error:
        elts = tmpl.rxq.elts;
-       rxq_cleanup(&tmpl);
+       mlx5_rxq_cleanup(&tmpl);
        rte_free(elts);
        assert(ret > 0);
        return ret;
@@ -1124,8 +1125,9 @@ mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                    struct rte_mempool *mp)
 {
        struct priv *priv = dev->data->dev_private;
-       struct rxq *rxq = (*priv->rxqs)[idx];
-       struct rxq_ctrl *rxq_ctrl = container_of(rxq, struct rxq_ctrl, rxq);
+       struct mlx5_rxq_data *rxq = (*priv->rxqs)[idx];
+       struct mlx5_rxq_ctrl *rxq_ctrl =
+               container_of(rxq, struct mlx5_rxq_ctrl, rxq);
        const uint16_t desc_n =
                desc + priv->rx_vec_en * MLX5_VPMD_DESCS_PER_LOOP;
        int ret;
@@ -1151,12 +1153,12 @@ mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
        if (rxq != NULL) {
                DEBUG("%p: reusing already allocated queue index %u (%p)",
                      (void *)dev, idx, (void *)rxq);
-               if (priv->started) {
+               if (dev->data->dev_started) {
                        priv_unlock(priv);
                        return -EEXIST;
                }
                (*priv->rxqs)[idx] = NULL;
-               rxq_cleanup(rxq_ctrl);
+               mlx5_rxq_cleanup(rxq_ctrl);
                /* Resize if rxq size is changed. */
                if (rxq_ctrl->rxq.elts_n != log2above(desc)) {
                        rxq_ctrl = rte_realloc(rxq_ctrl,
@@ -1204,8 +1206,8 @@ mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
 void
 mlx5_rx_queue_release(void *dpdk_rxq)
 {
-       struct rxq *rxq = (struct rxq *)dpdk_rxq;
-       struct rxq_ctrl *rxq_ctrl;
+       struct mlx5_rxq_data *rxq = (struct mlx5_rxq_data *)dpdk_rxq;
+       struct mlx5_rxq_ctrl *rxq_ctrl;
        struct priv *priv;
        unsigned int i;
 
@@ -1214,7 +1216,7 @@ mlx5_rx_queue_release(void *dpdk_rxq)
 
        if (rxq == NULL)
                return;
-       rxq_ctrl = container_of(rxq, struct rxq_ctrl, rxq);
+       rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq);
        priv = rxq_ctrl->priv;
        priv_lock(priv);
        if (priv_flow_rxq_in_use(priv, rxq))
@@ -1227,7 +1229,7 @@ mlx5_rx_queue_release(void *dpdk_rxq)
                        (*priv->rxqs)[i] = NULL;
                        break;
                }
-       rxq_cleanup(rxq_ctrl);
+       mlx5_rxq_cleanup(rxq_ctrl);
        rte_free(rxq_ctrl);
        priv_unlock(priv);
 }
@@ -1262,9 +1264,9 @@ priv_rx_intr_vec_enable(struct priv *priv)
        }
        intr_handle->type = RTE_INTR_HANDLE_EXT;
        for (i = 0; i != n; ++i) {
-               struct rxq *rxq = (*priv->rxqs)[i];
-               struct rxq_ctrl *rxq_ctrl =
-                       container_of(rxq, struct rxq_ctrl, rxq);
+               struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];
+               struct mlx5_rxq_ctrl *rxq_ctrl =
+                       container_of(rxq, struct mlx5_rxq_ctrl, rxq);
                int fd;
                int flags;
                int rc;
@@ -1330,7 +1332,7 @@ priv_rx_intr_vec_disable(struct priv *priv)
  *     Sequence number per receive queue .
  */
 static inline void
-mlx5_arm_cq(struct rxq *rxq, int sq_n_rxq)
+mlx5_arm_cq(struct mlx5_rxq_data *rxq, int sq_n_rxq)
 {
        int sq_n = 0;
        uint32_t doorbell_hi;
@@ -1361,8 +1363,9 @@ int
 mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
        struct priv *priv = mlx5_get_priv(dev);
-       struct rxq *rxq = (*priv->rxqs)[rx_queue_id];
-       struct rxq_ctrl *rxq_ctrl = container_of(rxq, struct rxq_ctrl, rxq);
+       struct mlx5_rxq_data *rxq = (*priv->rxqs)[rx_queue_id];
+       struct mlx5_rxq_ctrl *rxq_ctrl =
+               container_of(rxq, struct mlx5_rxq_ctrl, rxq);
        int ret = 0;
 
        if (!rxq || !rxq_ctrl->channel) {
@@ -1390,8 +1393,9 @@ int
 mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
        struct priv *priv = mlx5_get_priv(dev);
-       struct rxq *rxq = (*priv->rxqs)[rx_queue_id];
-       struct rxq_ctrl *rxq_ctrl = container_of(rxq, struct rxq_ctrl, rxq);
+       struct mlx5_rxq_data *rxq = (*priv->rxqs)[rx_queue_id];
+       struct mlx5_rxq_ctrl *rxq_ctrl =
+               container_of(rxq, struct mlx5_rxq_ctrl, rxq);
        struct ibv_cq *ev_cq;
        void *ev_ctx;
        int ret;