net/mlx5: fix constant array size
[dpdk.git] / drivers / net / mlx5 / mlx5_txq.c
index 5ab50ec..d96abef 100644 (file)
@@ -154,6 +154,7 @@ txq_sync_cq(struct mlx5_txq_data *txq)
        /* Resync CQE and WQE (WQ in reset state). */
        rte_io_wmb();
        *txq->cq_db = rte_cpu_to_be_32(txq->cq_ci);
+       txq->cq_pi = txq->cq_ci;
        rte_io_wmb();
 }
 
@@ -253,7 +254,7 @@ mlx5_tx_queue_start_primary(struct rte_eth_dev *dev, uint16_t idx)
 
        MLX5_ASSERT(rte_eal_process_type() ==  RTE_PROC_PRIMARY);
        ret = priv->obj_ops.txq_obj_modify(txq_ctrl->obj,
-                                          MLX5_TXQ_MOD_RDY2RDY,
+                                          MLX5_TXQ_MOD_RST2RDY,
                                           (uint8_t)priv->dev_port);
        if (ret)
                return ret;
@@ -388,7 +389,6 @@ mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
        DRV_LOG(DEBUG, "port %u adding Tx queue %u to list",
                dev->data->port_id, idx);
        (*priv->txqs)[idx] = &txq_ctrl->txq;
-       dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
        return 0;
 }
 
@@ -421,15 +421,35 @@ mlx5_tx_hairpin_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
        res = mlx5_tx_queue_pre_setup(dev, idx, &desc);
        if (res)
                return res;
-       if (hairpin_conf->peer_count != 1 ||
-           hairpin_conf->peers[0].port != dev->data->port_id ||
-           hairpin_conf->peers[0].queue >= priv->rxqs_n) {
-               DRV_LOG(ERR, "port %u unable to setup hairpin queue index %u "
-                       " invalid hairpind configuration", dev->data->port_id,
-                       idx);
+       if (hairpin_conf->peer_count != 1) {
                rte_errno = EINVAL;
+               DRV_LOG(ERR, "port %u unable to setup Tx hairpin queue index %u"
+                       " peer count is %u", dev->data->port_id,
+                       idx, hairpin_conf->peer_count);
                return -rte_errno;
        }
+       if (hairpin_conf->peers[0].port == dev->data->port_id) {
+               if (hairpin_conf->peers[0].queue >= priv->rxqs_n) {
+                       rte_errno = EINVAL;
+                       DRV_LOG(ERR, "port %u unable to setup Tx hairpin queue"
+                               " index %u, Rx %u is larger than %u",
+                               dev->data->port_id, idx,
+                               hairpin_conf->peers[0].queue, priv->txqs_n);
+                       return -rte_errno;
+               }
+       } else {
+               if (hairpin_conf->manual_bind == 0 ||
+                   hairpin_conf->tx_explicit == 0) {
+                       rte_errno = EINVAL;
+                       DRV_LOG(ERR, "port %u unable to setup Tx hairpin queue"
+                               " index %u peer port %u with attributes %u %u",
+                               dev->data->port_id, idx,
+                               hairpin_conf->peers[0].port,
+                               hairpin_conf->manual_bind,
+                               hairpin_conf->tx_explicit);
+                       return -rte_errno;
+               }
+       }
        txq_ctrl = mlx5_txq_hairpin_new(dev, idx, desc, hairpin_conf);
        if (!txq_ctrl) {
                DRV_LOG(ERR, "port %u unable to allocate queue index %u",
@@ -1121,7 +1141,7 @@ mlx5_txq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
                rte_errno = ENOMEM;
                goto error;
        }
-       __atomic_add_fetch(&tmpl->refcnt, 1, __ATOMIC_RELAXED);
+       __atomic_fetch_add(&tmpl->refcnt, 1, __ATOMIC_RELAXED);
        tmpl->type = MLX5_TXQ_TYPE_STANDARD;
        LIST_INSERT_HEAD(&priv->txqsctrl, tmpl, next);
        return tmpl;
@@ -1165,7 +1185,7 @@ mlx5_txq_hairpin_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
        tmpl->txq.idx = idx;
        tmpl->hairpin_conf = *hairpin_conf;
        tmpl->type = MLX5_TXQ_TYPE_HAIRPIN;
-       __atomic_add_fetch(&tmpl->refcnt, 1, __ATOMIC_RELAXED);
+       __atomic_fetch_add(&tmpl->refcnt, 1, __ATOMIC_RELAXED);
        LIST_INSERT_HEAD(&priv->txqsctrl, tmpl, next);
        return tmpl;
 }
@@ -1190,7 +1210,7 @@ mlx5_txq_get(struct rte_eth_dev *dev, uint16_t idx)
 
        if (txq_data) {
                ctrl = container_of(txq_data, struct mlx5_txq_ctrl, txq);
-               __atomic_add_fetch(&ctrl->refcnt, 1, __ATOMIC_RELAXED);
+               __atomic_fetch_add(&ctrl->refcnt, 1, __ATOMIC_RELAXED);
        }
        return ctrl;
 }
@@ -1229,8 +1249,8 @@ mlx5_txq_release(struct rte_eth_dev *dev, uint16_t idx)
                        txq_ctrl->txq.fcqs = NULL;
                }
                txq_free_elts(txq_ctrl);
+               dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED;
        }
-       dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED;
        if (!__atomic_load_n(&txq_ctrl->refcnt, __ATOMIC_RELAXED)) {
                if (txq_ctrl->type == MLX5_TXQ_TYPE_STANDARD)
                        mlx5_mr_btree_free(&txq_ctrl->txq.mr_ctrl.cache_bh);