- if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
- ns = sh->fdb_domain;
- else if (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_NIC_TX)
- ns = sh->tx_domain;
- else
- ns = sh->rx_domain;
- /* Lookup a matching resource from cache. */
- actions_len = resource->actions_num * sizeof(resource->actions[0]);
- hdr_mod_key.cksum = __rte_raw_cksum(resource->actions, actions_len, 0);
- resource->entry.key = hdr_mod_key.v64;
- entry = mlx5_hlist_lookup_ex(sh->modify_cmds, resource->entry.key,
- flow_dv_modify_hdr_resource_match,
- (void *)resource);
- if (entry) {
- cache_resource = container_of(entry,
- struct mlx5_flow_dv_modify_hdr_resource,
- entry);
- DRV_LOG(DEBUG, "modify-header resource %p: refcnt %d++",
- (void *)cache_resource,
- __atomic_load_n(&cache_resource->refcnt,
- __ATOMIC_RELAXED));
- __atomic_fetch_add(&cache_resource->refcnt, 1,
- __ATOMIC_RELAXED);
- dev_flow->handle->dvh.modify_hdr = cache_resource;
- return 0;
-
- }
- /* Register new modify-header resource. */
- cache_resource = mlx5_malloc(MLX5_MEM_ZERO,
- sizeof(*cache_resource) + actions_len, 0,
- SOCKET_ID_ANY);
- if (!cache_resource)
- return rte_flow_error_set(error, ENOMEM,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
- "cannot allocate resource memory");
- *cache_resource = *resource;
- rte_memcpy(cache_resource->actions, resource->actions, actions_len);
- ret = mlx5_flow_os_create_flow_action_modify_header
- (sh->ctx, ns, cache_resource,
- actions_len, &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");
- }
- __atomic_store_n(&cache_resource->refcnt, 1, __ATOMIC_RELAXED);
- if (mlx5_hlist_insert_ex(sh->modify_cmds, &cache_resource->entry,
- flow_dv_modify_hdr_resource_match,
- (void *)cache_resource)) {
- claim_zero(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, "action exist");
- }
- dev_flow->handle->dvh.modify_hdr = cache_resource;
- DRV_LOG(DEBUG, "new modify-header resource %p: refcnt %d++",
- (void *)cache_resource,
- __atomic_load_n(&cache_resource->refcnt, __ATOMIC_RELAXED));