net/mlx5: add missing sanity checks for Tx completion queue
[dpdk.git] / drivers / net / mlx5 / mlx5_rxq.c
index ad741ef..a4cdd37 100644 (file)
@@ -242,8 +242,6 @@ mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
        int ret = 0;
 
        (void)conf;
-       if (mlx5_is_secondary())
-               return -E_RTE_SECONDARY;
        priv_lock(priv);
        if (!rte_is_power_of_2(desc)) {
                desc = 1 << log2above(desc);
@@ -294,9 +292,6 @@ mlx5_rx_queue_release(void *dpdk_rxq)
        struct mlx5_rxq_ctrl *rxq_ctrl;
        struct priv *priv;
 
-       if (mlx5_is_secondary())
-               return;
-
        if (rxq == NULL)
                return;
        rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq);
@@ -327,11 +322,10 @@ priv_rx_intr_vec_enable(struct priv *priv)
        unsigned int count = 0;
        struct rte_intr_handle *intr_handle = priv->dev->intr_handle;
 
-       assert(!mlx5_is_secondary());
        if (!priv->dev->data->dev_conf.intr_conf.rxq)
                return 0;
        priv_rx_intr_vec_disable(priv);
-       intr_handle->intr_vec = malloc(sizeof(intr_handle->intr_vec[rxqs_n]));
+       intr_handle->intr_vec = malloc(n * sizeof(intr_handle->intr_vec[0]));
        if (intr_handle->intr_vec == NULL) {
                ERROR("failed to allocate memory for interrupt vector,"
                      " Rx interrupts will not be supported");
@@ -396,6 +390,8 @@ priv_rx_intr_vec_disable(struct priv *priv)
 
        if (!priv->dev->data->dev_conf.intr_conf.rxq)
                return;
+       if (!intr_handle->intr_vec)
+               goto free;
        for (i = 0; i != n; ++i) {
                struct mlx5_rxq_ctrl *rxq_ctrl;
                struct mlx5_rxq_data *rxq_data;
@@ -411,8 +407,10 @@ priv_rx_intr_vec_disable(struct priv *priv)
                rxq_ctrl = container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
                mlx5_priv_rxq_ibv_release(priv, rxq_ctrl->ibv);
        }
+free:
        rte_intr_free_epoll_fd(intr_handle);
-       free(intr_handle->intr_vec);
+       if (intr_handle->intr_vec)
+               free(intr_handle->intr_vec);
        intr_handle->nb_efd = 0;
        intr_handle->intr_vec = NULL;
 }
@@ -456,7 +454,7 @@ mlx5_arm_cq(struct mlx5_rxq_data *rxq, int sq_n_rxq)
 int
 mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
-       struct priv *priv = mlx5_get_priv(dev);
+       struct priv *priv = dev->data->dev_private;
        struct mlx5_rxq_data *rxq_data;
        struct mlx5_rxq_ctrl *rxq_ctrl;
        int ret = 0;
@@ -500,7 +498,7 @@ exit:
 int
 mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
-       struct priv *priv = mlx5_get_priv(dev);
+       struct priv *priv = dev->data->dev_private;
        struct mlx5_rxq_data *rxq_data;
        struct mlx5_rxq_ctrl *rxq_ctrl;
        struct mlx5_rxq_ibv *rxq_ibv = NULL;
@@ -726,6 +724,9 @@ mlx5_priv_rxq_ibv_new(struct priv *priv, uint16_t idx)
        };
        rxq_data->cq_db = cq_info.dbrec;
        rxq_data->cqes = (volatile struct mlx5_cqe (*)[])(uintptr_t)cq_info.buf;
+       rxq_data->cq_uar = cq_info.cq_uar;
+       rxq_data->cqn = cq_info.cqn;
+       rxq_data->cq_arm_sn = 0;
        /* Update doorbell counter. */
        rxq_data->rq_ci = (1 << rxq_data->elts_n) >> rxq_data->sges_n;
        rte_wmb();
@@ -887,6 +888,7 @@ mlx5_priv_rxq_new(struct priv *priv, uint16_t idx, uint16_t desc,
                                 0, socket);
        if (!tmpl)
                return NULL;
+       tmpl->socket = socket;
        if (priv->dev->data->dev_conf.intr_conf.rxq)
                tmpl->irq = 1;
        /* Enable scattered packets support for this queue if necessary. */
@@ -1113,7 +1115,7 @@ mlx5_priv_ind_table_ibv_new(struct priv *priv, uint16_t queues[],
        struct mlx5_ind_table_ibv *ind_tbl;
        const unsigned int wq_n = rte_is_power_of_2(queues_n) ?
                log2above(queues_n) :
-               priv->ind_table_max_size;
+               log2above(priv->ind_table_max_size);
        struct ibv_wq *wq[1 << wq_n];
        unsigned int i;
        unsigned int j;
@@ -1258,7 +1260,8 @@ mlx5_priv_ind_table_ibv_verify(struct priv *priv)
  * @param hash_fields
  *   Verbs protocol hash field to make the RSS on.
  * @param queues
- *   Queues entering in hash queue.
+ *   Queues entering in hash queue. In case of empty hash_fields only the
+ *   first queue index will be taken for the indirection table.
  * @param queues_n
  *   Number of queues.
  *
@@ -1273,6 +1276,7 @@ mlx5_priv_hrxq_new(struct priv *priv, uint8_t *rss_key, uint8_t rss_key_len,
        struct mlx5_ind_table_ibv *ind_tbl;
        struct ibv_qp *qp;
 
+       queues_n = hash_fields ? queues_n : 1;
        ind_tbl = mlx5_priv_ind_table_ibv_get(priv, queues, queues_n);
        if (!ind_tbl)
                ind_tbl = mlx5_priv_ind_table_ibv_new(priv, queues, queues_n);
@@ -1325,7 +1329,8 @@ error:
  * @param rss_conf
  *   RSS configuration for the Rx hash queue.
  * @param queues
- *   Queues entering in hash queue.
+ *   Queues entering in hash queue. In case of empty hash_fields only the
+ *   first queue index will be taken for the indirection table.
  * @param queues_n
  *   Number of queues.
  *
@@ -1338,6 +1343,7 @@ mlx5_priv_hrxq_get(struct priv *priv, uint8_t *rss_key, uint8_t rss_key_len,
 {
        struct mlx5_hrxq *hrxq;
 
+       queues_n = hash_fields ? queues_n : 1;
        LIST_FOREACH(hrxq, &priv->hrxqs, next) {
                struct mlx5_ind_table_ibv *ind_tbl;