net/mlx5: reorganize flow API structure
[dpdk.git] / drivers / net / mlx5 / mlx5.c
index f8b134c..cc13e44 100644 (file)
@@ -198,6 +198,120 @@ struct mlx5_dev_spawn_data {
 static LIST_HEAD(, mlx5_ibv_shared) mlx5_ibv_list = LIST_HEAD_INITIALIZER();
 static pthread_mutex_t mlx5_ibv_list_mutex = PTHREAD_MUTEX_INITIALIZER;
 
+static struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {
+#ifdef HAVE_IBV_FLOW_DV_SUPPORT
+       {
+               .size = sizeof(struct mlx5_flow_dv_encap_decap_resource),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_encap_decap_ipool",
+       },
+       {
+               .size = sizeof(struct mlx5_flow_dv_push_vlan_action_resource),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_push_vlan_ipool",
+       },
+       {
+               .size = sizeof(struct mlx5_flow_dv_tag_resource),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_tag_ipool",
+       },
+       {
+               .size = sizeof(struct mlx5_flow_dv_port_id_action_resource),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_port_id_ipool",
+       },
+       {
+               .size = sizeof(struct mlx5_flow_tbl_data_entry),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_jump_ipool",
+       },
+#endif
+       {
+               .size = sizeof(struct mlx5_flow_meter),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_meter_ipool",
+       },
+       {
+               .size = sizeof(struct mlx5_flow_mreg_copy_resource),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_mcp_ipool",
+       },
+       {
+               .size = (sizeof(struct mlx5_hrxq) + MLX5_RSS_HASH_KEY_LEN),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_hrxq_ipool",
+       },
+       {
+               .size = sizeof(struct mlx5_flow_handle),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_flow_handle_ipool",
+       },
+       {
+               .size = sizeof(struct rte_flow),
+               .trunk_size = 4096,
+               .need_lock = 1,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "rte_flow_ipool",
+       },
+};
+
+
 #define MLX5_FLOW_MIN_ID_POOL_SIZE 512
 #define MLX5_ID_GENERATION_ARRAY_FACTOR 16
 
@@ -416,6 +530,49 @@ mlx5_flow_counters_mng_close(struct mlx5_ibv_shared *sh)
        memset(&sh->cmng, 0, sizeof(sh->cmng));
 }
 
+/**
+ * Initialize the flow resources' indexed mempool.
+ *
+ * @param[in] sh
+ *   Pointer to mlx5_ibv_shared object.
+ * @param[in] sh
+ *   Pointer to user dev config.
+ */
+static void
+mlx5_flow_ipool_create(struct mlx5_ibv_shared *sh,
+                      const struct mlx5_dev_config *config __rte_unused)
+{
+       uint8_t i;
+
+#ifdef HAVE_IBV_FLOW_DV_SUPPORT
+       /*
+        * While DV is supported, user chooses the verbs mode,
+        * the mlx5 flow handle size is different with the
+        * MLX5_FLOW_HANDLE_VERBS_SIZE.
+        */
+       if (!config->dv_flow_en)
+               mlx5_ipool_cfg[MLX5_IPOOL_MLX5_FLOW].size =
+                                       MLX5_FLOW_HANDLE_VERBS_SIZE;
+#endif
+       for (i = 0; i < MLX5_IPOOL_MAX; ++i)
+               sh->ipool[i] = mlx5_ipool_create(&mlx5_ipool_cfg[i]);
+}
+
+/**
+ * Release the flow resources' indexed mempool.
+ *
+ * @param[in] sh
+ *   Pointer to mlx5_ibv_shared object.
+ */
+static void
+mlx5_flow_ipool_destroy(struct mlx5_ibv_shared *sh)
+{
+       uint8_t i;
+
+       for (i = 0; i < MLX5_IPOOL_MAX; ++i)
+               mlx5_ipool_destroy(sh->ipool[i]);
+}
+
 /**
  * Extract pdn of PD object using DV API.
  *
@@ -607,7 +764,8 @@ mlx5_alloc_shared_ibctx(const struct mlx5_dev_spawn_data *spawn,
                        goto error;
                }
        }
-       sh->flow_id_pool = mlx5_flow_id_pool_alloc(UINT32_MAX);
+       sh->flow_id_pool = mlx5_flow_id_pool_alloc
+                                       ((1 << HAIRPIN_FLOW_ID_BITS) - 1);
        if (!sh->flow_id_pool) {
                DRV_LOG(ERR, "can't create flow id pool");
                err = ENOMEM;
@@ -631,6 +789,7 @@ mlx5_alloc_shared_ibctx(const struct mlx5_dev_spawn_data *spawn,
                goto error;
        }
        mlx5_flow_counters_mng_init(sh);
+       mlx5_flow_ipool_create(sh, config);
        /* Add device to memory callback list. */
        rte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock);
        LIST_INSERT_HEAD(&mlx5_shared_data->mem_event_cb_list,
@@ -703,6 +862,7 @@ mlx5_free_shared_ibctx(struct mlx5_ibv_shared *sh)
         *  Only primary process handles async device events.
         **/
        mlx5_flow_counters_mng_close(sh);
+       mlx5_flow_ipool_destroy(sh);
        MLX5_ASSERT(!sh->intr_cnt);
        if (sh->intr_cnt)
                mlx5_intr_callback_unregister
@@ -1301,16 +1461,6 @@ mlx5_dev_close(struct rte_eth_dev *dev)
                close(priv->nl_socket_rdma);
        if (priv->vmwa_context)
                mlx5_vlan_vmwa_exit(priv->vmwa_context);
-       if (priv->sh) {
-               /*
-                * Free the shared context in last turn, because the cleanup
-                * routines above may use some shared fields, like
-                * mlx5_nl_mac_addr_flush() uses ibdev_path for retrieveing
-                * ifindex if Netlink fails.
-                */
-               mlx5_free_shared_ibctx(priv->sh);
-               priv->sh = NULL;
-       }
        ret = mlx5_hrxq_verify(dev);
        if (ret)
                DRV_LOG(WARNING, "port %u some hash Rx queue still remain",
@@ -1339,6 +1489,16 @@ mlx5_dev_close(struct rte_eth_dev *dev)
        if (ret)
                DRV_LOG(WARNING, "port %u some flows still remain",
                        dev->data->port_id);
+       if (priv->sh) {
+               /*
+                * Free the shared context in last turn, because the cleanup
+                * routines above may use some shared fields, like
+                * mlx5_nl_mac_addr_flush() uses ibdev_path for retrieveing
+                * ifindex if Netlink fails.
+                */
+               mlx5_free_shared_ibctx(priv->sh);
+               priv->sh = NULL;
+       }
        if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
                unsigned int c = 0;
                uint16_t port_id;
@@ -2735,8 +2895,8 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
                                      mlx5_ifindex(eth_dev),
                                      eth_dev->data->mac_addrs,
                                      MLX5_MAX_MAC_ADDRESSES);
-       TAILQ_INIT(&priv->flows);
-       TAILQ_INIT(&priv->ctrl_flows);
+       priv->flows = 0;
+       priv->ctrl_flows = 0;
        TAILQ_INIT(&priv->flow_meters);
        TAILQ_INIT(&priv->flow_meter_profiles);
        /* Hint libmlx5 to use PMD allocator for data plane resources */