@@ -225,7 +225,7 @@
mlx5_alloc_shared_dr(struct mlx5_priv *priv)
{
struct mlx5_dev_ctx_shared *sh = priv->sh;
- char s[MLX5_HLIST_NAMESIZE];
+ char s[MLX5_HLIST_NAMESIZE] __rte_unused;
int err = 0;
if (!sh->flow_tbls)
@@ -240,12 +240,14 @@
/* Create tags hash list table. */
snprintf(s, sizeof(s), "%s_tags", sh->ibdev_name);
sh->tag_table = mlx5_hlist_create(s, MLX5_TAGS_HLIST_ARRAY_SIZE, 0,
- false, NULL, NULL, NULL);
+ true, flow_dv_tag_create_cb, NULL,
+ flow_dv_tag_remove_cb);
if (!sh->tag_table) {
DRV_LOG(ERR, "tags with hash creation failed.");
err = ENOMEM;
goto error;
}
+ sh->tag_table->ctx = sh;
snprintf(s, sizeof(s), "%s_hdr_modify", sh->ibdev_name);
sh->modify_cmds = mlx5_hlist_create(s, MLX5_FLOW_HDR_MODIFY_HTABLE_SZ,
0, false, NULL, NULL, NULL);
@@ -1091,4 +1091,9 @@ struct mlx5_flow_tbl_resource *flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
uint32_t table_id, uint8_t egress, uint8_t transfer,
uint8_t dummy, struct rte_flow_error *error);
+struct mlx5_hlist_entry *flow_dv_tag_create_cb(struct mlx5_hlist *list,
+ uint64_t key, void *cb_ctx);
+void flow_dv_tag_remove_cb(struct mlx5_hlist *list,
+ struct mlx5_hlist_entry *entry);
+
#endif /* RTE_PMD_MLX5_FLOW_H_ */
@@ -7825,6 +7825,35 @@ struct mlx5_flow_tbl_resource *
return 0;
}
+struct mlx5_hlist_entry *
+flow_dv_tag_create_cb(struct mlx5_hlist *list, uint64_t key, void *ctx)
+{
+ struct mlx5_dev_ctx_shared *sh = list->ctx;
+ struct rte_flow_error *error = ctx;
+ struct mlx5_flow_dv_tag_resource *entry;
+ uint32_t idx = 0;
+ int ret;
+
+ entry = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG], &idx);
+ if (!entry) {
+ rte_flow_error_set(error, ENOMEM,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+ "cannot allocate resource memory");
+ return NULL;
+ }
+ entry->idx = idx;
+ ret = mlx5_flow_os_create_flow_action_tag(key,
+ &entry->action);
+ if (ret) {
+ mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], idx);
+ rte_flow_error_set(error, ENOMEM,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+ NULL, "cannot create action");
+ return NULL;
+ }
+ return &entry->entry;
+}
+
/**
* Find existing tag resource or create and register a new one.
*
@@ -7848,54 +7877,32 @@ struct mlx5_flow_tbl_resource *
struct rte_flow_error *error)
{
struct mlx5_priv *priv = dev->data->dev_private;
- struct mlx5_dev_ctx_shared *sh = priv->sh;
struct mlx5_flow_dv_tag_resource *cache_resource;
struct mlx5_hlist_entry *entry;
- int ret;
- /* Lookup a matching resource from cache. */
- entry = mlx5_hlist_lookup(sh->tag_table, (uint64_t)tag_be24, NULL);
+ entry = mlx5_hlist_register(priv->sh->tag_table, tag_be24, error);
if (entry) {
cache_resource = container_of
(entry, struct mlx5_flow_dv_tag_resource, entry);
- rte_atomic32_inc(&cache_resource->refcnt);
dev_flow->handle->dvh.rix_tag = cache_resource->idx;
dev_flow->dv.tag_resource = cache_resource;
- DRV_LOG(DEBUG, "cached tag resource %p: refcnt now %d++",
- (void *)cache_resource,
- rte_atomic32_read(&cache_resource->refcnt));
return 0;
}
- /* Register new resource. */
- cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_TAG],
- &dev_flow->handle->dvh.rix_tag);
- if (!cache_resource)
- return rte_flow_error_set(error, ENOMEM,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
- "cannot allocate resource memory");
- cache_resource->entry.key = (uint64_t)tag_be24;
- ret = mlx5_flow_os_create_flow_action_tag(tag_be24,
- &cache_resource->action);
- if (ret) {
- mlx5_free(cache_resource);
- return rte_flow_error_set(error, ENOMEM,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
- NULL, "cannot create action");
- }
- rte_atomic32_init(&cache_resource->refcnt);
- rte_atomic32_inc(&cache_resource->refcnt);
- if (mlx5_hlist_insert(sh->tag_table, &cache_resource->entry)) {
- mlx5_flow_os_destroy_flow_action(cache_resource->action);
- mlx5_free(cache_resource);
- return rte_flow_error_set(error, EEXIST,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
- NULL, "cannot insert tag");
- }
- dev_flow->dv.tag_resource = cache_resource;
- DRV_LOG(DEBUG, "new tag resource %p: refcnt now %d++",
- (void *)cache_resource,
- rte_atomic32_read(&cache_resource->refcnt));
- return 0;
+ return -rte_errno;
+}
+
+void
+flow_dv_tag_remove_cb(struct mlx5_hlist *list,
+ struct mlx5_hlist_entry *entry)
+{
+ struct mlx5_dev_ctx_shared *sh = list->ctx;
+ struct mlx5_flow_dv_tag_resource *tag =
+ container_of(entry, struct mlx5_flow_dv_tag_resource, entry);
+
+ MLX5_ASSERT(tag && sh && tag->action);
+ claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
+ DRV_LOG(DEBUG, "tag %p: removed", (void *)tag);
+ mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TAG], tag->idx);
}
/**
@@ -7914,24 +7921,14 @@ struct mlx5_flow_tbl_resource *
uint32_t tag_idx)
{
struct mlx5_priv *priv = dev->data->dev_private;
- struct mlx5_dev_ctx_shared *sh = priv->sh;
struct mlx5_flow_dv_tag_resource *tag;
tag = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
if (!tag)
return 0;
DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--",
- dev->data->port_id, (void *)tag,
- rte_atomic32_read(&tag->refcnt));
- if (rte_atomic32_dec_and_test(&tag->refcnt)) {
- claim_zero(mlx5_flow_os_destroy_flow_action(tag->action));
- mlx5_hlist_remove(sh->tag_table, &tag->entry);
- DRV_LOG(DEBUG, "port %u tag %p: removed",
- dev->data->port_id, (void *)tag);
- mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_TAG], tag_idx);
- return 0;
- }
- return 1;
+ dev->data->port_id, (void *)tag, tag->entry.ref_cnt);
+ return mlx5_hlist_unregister(priv->sh->tag_table, &tag->entry);
}
/**