net/bnxt: use appropriate type for Rx ring
[dpdk.git] / drivers / net / mlx5 / mlx5_devx.c
index b1b3037..3e81fcc 100644 (file)
@@ -609,77 +609,57 @@ error:
 }
 
 /**
- * Create an indirection table.
+ * Create RQT using DevX API as a filed of indirection table.
  *
  * @param dev
  *   Pointer to Ethernet device.
- * @param queues
- *   Queues entering in the indirection table.
- * @param queues_n
- *   Number of queues in the array.
+ * @param log_n
+ *   Log of number of queues in the array.
+ * @param ind_tbl
+ *   DevX indirection table object.
  *
  * @return
- *   The DevX object initialized, NULL otherwise and rte_errno is set.
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-static struct mlx5_ind_table_obj *
-mlx5_devx_ind_table_obj_new(struct rte_eth_dev *dev, const uint16_t *queues,
-                           uint32_t queues_n)
+static int
+mlx5_devx_ind_table_new(struct rte_eth_dev *dev, const unsigned int log_n,
+                       struct mlx5_ind_table_obj *ind_tbl)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_ind_table_obj *ind_tbl;
        struct mlx5_devx_rqt_attr *rqt_attr = NULL;
-       const unsigned int rqt_n = 1 << (rte_is_power_of_2(queues_n) ?
-                                  log2above(queues_n) :
-                                  log2above(priv->config.ind_table_max_size));
-       unsigned int i = 0, j = 0, k = 0;
-
-       ind_tbl = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*ind_tbl) +
-                             queues_n * sizeof(uint16_t), 0, SOCKET_ID_ANY);
-       if (!ind_tbl) {
-               rte_errno = ENOMEM;
-               return NULL;
-       }
-       ind_tbl->type = MLX5_IND_TBL_TYPE_DEVX;
+       const unsigned int rqt_n = 1 << log_n;
+       unsigned int i, j;
+
+       MLX5_ASSERT(ind_tbl);
        rqt_attr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rqt_attr) +
                              rqt_n * sizeof(uint32_t), 0, SOCKET_ID_ANY);
        if (!rqt_attr) {
                DRV_LOG(ERR, "Port %u cannot allocate RQT resources.",
                        dev->data->port_id);
                rte_errno = ENOMEM;
-               goto error;
+               return -rte_errno;
        }
        rqt_attr->rqt_max_size = priv->config.ind_table_max_size;
        rqt_attr->rqt_actual_size = rqt_n;
-       for (i = 0; i != queues_n; ++i) {
-               struct mlx5_rxq_ctrl *rxq = mlx5_rxq_get(dev, queues[i]);
-               if (!rxq) {
-                       mlx5_free(rqt_attr);
-                       goto error;
-               }
-               rqt_attr->rq_list[i] = rxq->obj->rq->id;
-               ind_tbl->queues[i] = queues[i];
+       for (i = 0; i != ind_tbl->queues_n; ++i) {
+               struct mlx5_rxq_data *rxq = (*priv->rxqs)[ind_tbl->queues[i]];
+               struct mlx5_rxq_ctrl *rxq_ctrl =
+                               container_of(rxq, struct mlx5_rxq_ctrl, rxq);
+
+               rqt_attr->rq_list[i] = rxq_ctrl->obj->rq->id;
        }
-       k = i; /* Retain value of i for use in error case. */
-       for (j = 0; k != rqt_n; ++k, ++j)
-               rqt_attr->rq_list[k] = rqt_attr->rq_list[j];
+       MLX5_ASSERT(i > 0);
+       for (j = 0; i != rqt_n; ++j, ++i)
+               rqt_attr->rq_list[i] = rqt_attr->rq_list[j];
        ind_tbl->rqt = mlx5_devx_cmd_create_rqt(priv->sh->ctx, rqt_attr);
        mlx5_free(rqt_attr);
        if (!ind_tbl->rqt) {
                DRV_LOG(ERR, "Port %u cannot create DevX RQT.",
                        dev->data->port_id);
                rte_errno = errno;
-               goto error;
+               return -rte_errno;
        }
-       ind_tbl->queues_n = queues_n;
-       rte_atomic32_inc(&ind_tbl->refcnt);
-       LIST_INSERT_HEAD(&priv->ind_tbls, ind_tbl, next);
-       return ind_tbl;
-error:
-       for (j = 0; j < i; j++)
-               mlx5_rxq_release(dev, ind_tbl->queues[j]);
-       mlx5_free(ind_tbl);
-       DEBUG("Port %u cannot create indirection table.", dev->data->port_id);
-       return NULL;
+       return 0;
 }
 
 /**
@@ -689,7 +669,7 @@ error:
  *   Indirection table to release.
  */
 static void
-mlx5_devx_ind_table_obj_destroy(struct mlx5_ind_table_obj *ind_tbl)
+mlx5_devx_ind_table_destroy(struct mlx5_ind_table_obj *ind_tbl)
 {
        claim_zero(mlx5_devx_cmd_destroy(ind_tbl->rqt));
 }
@@ -699,55 +679,33 @@ mlx5_devx_ind_table_obj_destroy(struct mlx5_ind_table_obj *ind_tbl)
  *
  * @param dev
  *   Pointer to Ethernet device.
- * @param rss_key
- *   RSS key for the Rx hash queue.
- * @param rss_key_len
- *   RSS key length.
- * @param hash_fields
- *   Verbs protocol hash field to make the RSS on.
- * @param queues
- *   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.
+ * @param hrxq
+ *   Pointer to Rx Hash queue.
  * @param tunnel
  *   Tunnel type.
  *
  * @return
- *   The DevX object initialized index, 0 otherwise and rte_errno is set.
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-static uint32_t
-mlx5_devx_hrxq_new(struct rte_eth_dev *dev,
-                  const uint8_t *rss_key, uint32_t rss_key_len,
-                  uint64_t hash_fields,
-                  const uint16_t *queues, uint32_t queues_n,
+static int
+mlx5_devx_hrxq_new(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
                   int tunnel __rte_unused)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_hrxq *hrxq = NULL;
-       uint32_t hrxq_idx = 0;
-       struct mlx5_ind_table_obj *ind_tbl;
-       struct mlx5_devx_obj *tir = NULL;
-       struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[queues[0]];
+       struct mlx5_ind_table_obj *ind_tbl = hrxq->ind_table;
+       struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[ind_tbl->queues[0]];
        struct mlx5_rxq_ctrl *rxq_ctrl =
                container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
        struct mlx5_devx_tir_attr tir_attr;
-       int err;
-       uint32_t i;
+       const uint8_t *rss_key = hrxq->rss_key;
+       uint64_t hash_fields = hrxq->hash_fields;
        bool lro = true;
+       uint32_t i;
+       int err;
 
-       queues_n = hash_fields ? queues_n : 1;
-       ind_tbl = mlx5_ind_table_obj_get(dev, queues, queues_n);
-       if (!ind_tbl)
-               ind_tbl = priv->obj_ops->ind_table_obj_new(dev, queues,
-                                                          queues_n);
-       if (!ind_tbl) {
-               rte_errno = ENOMEM;
-               return 0;
-       }
        /* Enable TIR LRO only if all the queues were configured for. */
-       for (i = 0; i < queues_n; ++i) {
-               if (!(*priv->rxqs)[queues[i]]->lro) {
+       for (i = 0; i < ind_tbl->queues_n; ++i) {
+               if (!(*priv->rxqs)[ind_tbl->queues[i]]->lro) {
                        lro = false;
                        break;
                }
@@ -797,18 +755,13 @@ mlx5_devx_hrxq_new(struct rte_eth_dev *dev,
                tir_attr.lro_enable_mask = MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
                                           MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO;
        }
-       tir = mlx5_devx_cmd_create_tir(priv->sh->ctx, &tir_attr);
-       if (!tir) {
+       hrxq->tir = mlx5_devx_cmd_create_tir(priv->sh->ctx, &tir_attr);
+       if (!hrxq->tir) {
                DRV_LOG(ERR, "Port %u cannot create DevX TIR.",
                        dev->data->port_id);
                rte_errno = errno;
                goto error;
        }
-       hrxq = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_HRXQ], &hrxq_idx);
-       if (!hrxq)
-               goto error;
-       hrxq->ind_table = ind_tbl;
-       hrxq->tir = tir;
 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
        hrxq->action = mlx5_glue->dv_create_flow_action_dest_devx_tir
                                                               (hrxq->tir->obj);
@@ -817,22 +770,13 @@ mlx5_devx_hrxq_new(struct rte_eth_dev *dev,
                goto error;
        }
 #endif
-       hrxq->rss_key_len = rss_key_len;
-       hrxq->hash_fields = hash_fields;
-       memcpy(hrxq->rss_key, rss_key, rss_key_len);
-       rte_atomic32_inc(&hrxq->refcnt);
-       ILIST_INSERT(priv->sh->ipool[MLX5_IPOOL_HRXQ], &priv->hrxqs, hrxq_idx,
-                    hrxq, next);
-       return hrxq_idx;
+       return 0;
 error:
        err = rte_errno; /* Save rte_errno before cleanup. */
-       mlx5_ind_table_obj_release(dev, ind_tbl);
-       if (tir)
-               claim_zero(mlx5_devx_cmd_destroy(tir));
-       if (hrxq)
-               mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_HRXQ], hrxq_idx);
+       if (hrxq->tir)
+               claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
        rte_errno = err; /* Restore rte_errno. */
-       return 0;
+       return -rte_errno;
 }
 
 /**
@@ -847,14 +791,48 @@ mlx5_devx_tir_destroy(struct mlx5_hrxq *hrxq)
        claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
 }
 
+/**
+ * Create a DevX drop action for Rx Hash queue.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+mlx5_devx_drop_action_create(struct rte_eth_dev *dev)
+{
+       (void)dev;
+       DRV_LOG(ERR, "DevX drop action is not supported yet");
+       rte_errno = ENOTSUP;
+       return -rte_errno;
+}
+
+/**
+ * Release a drop hash Rx queue.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ */
+static void
+mlx5_devx_drop_action_destroy(struct rte_eth_dev *dev)
+{
+       (void)dev;
+       DRV_LOG(ERR, "DevX drop action is not supported yet");
+       rte_errno = ENOTSUP;
+}
+
 struct mlx5_obj_ops devx_obj_ops = {
        .rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_rq_vlan_strip,
        .rxq_obj_new = mlx5_rxq_devx_obj_new,
        .rxq_event_get = mlx5_rx_devx_get_event,
        .rxq_obj_modify = mlx5_devx_modify_rq,
        .rxq_obj_release = mlx5_rxq_devx_obj_release,
-       .ind_table_obj_new = mlx5_devx_ind_table_obj_new,
-       .ind_table_obj_destroy = mlx5_devx_ind_table_obj_destroy,
+       .ind_table_new = mlx5_devx_ind_table_new,
+       .ind_table_destroy = mlx5_devx_ind_table_destroy,
        .hrxq_new = mlx5_devx_hrxq_new,
        .hrxq_destroy = mlx5_devx_tir_destroy,
+       .drop_action_create = mlx5_devx_drop_action_create,
+       .drop_action_destroy = mlx5_devx_drop_action_destroy,
 };