src/dpdk/drivers/net/mlx5/linux/mlx5_os.c
static int
mlx5_alloc_shared_dr(struct mlx5_priv *priv)
{
	struct mlx5_dev_ctx_shared *sh = priv->sh;
	char s[MLX5_HLIST_NAMESIZE] __rte_unused;
	int err;

	MLX5_ASSERT(sh && sh->refcnt);
	if (sh->refcnt > 1)
		return 0;
	err = mlx5_alloc_table_hash_list(priv);
	if (err)
		goto error;
	/* The resources below are only valid with DV support. */
#ifdef HAVE_IBV_FLOW_DV_SUPPORT
	/* Init port id action cache list. */
	snprintf(s, sizeof(s), "%s_port_id_action_cache", sh->ibdev_name);
	mlx5_cache_list_init(&sh->port_id_action_list, s, 0, sh,
			     flow_dv_port_id_create_cb,
			     flow_dv_port_id_match_cb,
			     flow_dv_port_id_remove_cb);
	/* Init push vlan action cache list. */
	snprintf(s, sizeof(s), "%s_push_vlan_action_cache", sh->ibdev_name);
	mlx5_cache_list_init(&sh->push_vlan_action_list, s, 0, sh,
			     flow_dv_push_vlan_create_cb,
			     flow_dv_push_vlan_match_cb,
			     flow_dv_push_vlan_remove_cb);
	/* Init sample action cache list. */
	snprintf(s, sizeof(s), "%s_sample_action_cache", sh->ibdev_name);
	mlx5_cache_list_init(&sh->sample_action_list, s, 0, sh,
			     flow_dv_sample_create_cb,
			     flow_dv_sample_match_cb,
			     flow_dv_sample_remove_cb);
	/* Init dest array action cache list. */
	snprintf(s, sizeof(s), "%s_dest_array_cache", sh->ibdev_name);
	mlx5_cache_list_init(&sh->dest_array_list, s, 0, sh,
			     flow_dv_dest_array_create_cb,
			     flow_dv_dest_array_match_cb,
			     flow_dv_dest_array_remove_cb);
	/* 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,
					  MLX5_HLIST_WRITE_MOST,
					  flow_dv_tag_create_cb,
					  flow_dv_tag_match_cb,
					  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, MLX5_HLIST_WRITE_MOST |
					    MLX5_HLIST_DIRECT_KEY,
					    flow_dv_modify_create_cb,
					    flow_dv_modify_match_cb,
					    flow_dv_modify_remove_cb);
	if (!sh->modify_cmds) {
		DRV_LOG(ERR, "hdr modify hash creation failed");
		err = ENOMEM;
		goto error;
	}
	sh->modify_cmds->ctx = sh;
	snprintf(s, sizeof(s), "%s_encaps_decaps", sh->ibdev_name);
	sh->encaps_decaps = mlx5_hlist_create(s,
					      MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
					      0, MLX5_HLIST_DIRECT_KEY |
					      MLX5_HLIST_WRITE_MOST,
					      flow_dv_encap_decap_create_cb,
					      flow_dv_encap_decap_match_cb,
					      flow_dv_encap_decap_remove_cb);
	if (!sh->encaps_decaps) {
		DRV_LOG(ERR, "encap decap hash creation failed");
		err = ENOMEM;
		goto error;
	}
	sh->encaps_decaps->ctx = sh;
#endif
#ifdef HAVE_MLX5DV_DR
	void *domain;

	/* Reference counter is zero, we should initialize structures. */
	domain = mlx5_glue->dr_create_domain(sh->ctx,
					     MLX5DV_DR_DOMAIN_TYPE_NIC_RX);
	if (!domain) {
		DRV_LOG(ERR, "ingress mlx5dv_dr_create_domain failed");
		err = errno;
		goto error;
	}
	sh->rx_domain = domain;
	domain = mlx5_glue->dr_create_domain(sh->ctx,
					     MLX5DV_DR_DOMAIN_TYPE_NIC_TX);
	if (!domain) {
		DRV_LOG(ERR, "egress mlx5dv_dr_create_domain failed");
		err = errno;
		goto error;
	}
	sh->tx_domain = domain;
#ifdef HAVE_MLX5DV_DR_ESWITCH
	if (priv->config.dv_esw_en) {
		domain  = mlx5_glue->dr_create_domain
			(sh->ctx, MLX5DV_DR_DOMAIN_TYPE_FDB);
		if (!domain) {
			DRV_LOG(ERR, "FDB mlx5dv_dr_create_domain failed");
			err = errno;
			goto error;
		}
		sh->fdb_domain = domain;
	}
	/*
	 * The drop action is just some dummy placeholder in rdma-core. It
	 * does not belong to domains and has no any attributes, and, can be
	 * shared by the entire device.
	 */
	sh->dr_drop_action = mlx5_glue->dr_create_flow_action_drop();
	if (!sh->dr_drop_action) {
		DRV_LOG(ERR, "FDB mlx5dv_dr_create_flow_action_drop");
		err = errno;
		goto error;
	}
#endif
	if (!sh->tunnel_hub)
		err = mlx5_alloc_tunnel_hub(sh);
	if (err) {
		DRV_LOG(ERR, "mlx5_alloc_tunnel_hub failed err=%d", err);
		goto error;
	}
	if (priv->config.reclaim_mode == MLX5_RCM_AGGR) {
		mlx5_glue->dr_reclaim_domain_memory(sh->rx_domain, 1);
		mlx5_glue->dr_reclaim_domain_memory(sh->tx_domain, 1);
		if (sh->fdb_domain)
			mlx5_glue->dr_reclaim_domain_memory(sh->fdb_domain, 1);
	}
	sh->pop_vlan_action = mlx5_glue->dr_create_flow_action_pop_vlan();
#endif /* HAVE_MLX5DV_DR */
	sh->default_miss_action =
			mlx5_glue->dr_create_flow_action_default_miss();
	if (!sh->default_miss_action)
		DRV_LOG(WARNING, "Default miss action is not supported.");
	return 0;
error:
	/* Rollback the created objects. */
	if (sh->rx_domain) {
		mlx5_glue->dr_destroy_domain(sh->rx_domain);
		sh->rx_domain = NULL;
	}
	if (sh->tx_domain) {
		mlx5_glue->dr_destroy_domain(sh->tx_domain);
		sh->tx_domain = NULL;
	}
	if (sh->fdb_domain) {
		mlx5_glue->dr_destroy_domain(sh->fdb_domain);
		sh->fdb_domain = NULL;
	}
	if (sh->dr_drop_action) {
		mlx5_glue->destroy_flow_action(sh->dr_drop_action);
		sh->dr_drop_action = NULL;
	}
	if (sh->pop_vlan_action) {
		mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
		sh->pop_vlan_action = NULL;
	}
	if (sh->encaps_decaps) {
		mlx5_hlist_destroy(sh->encaps_decaps);
		sh->encaps_decaps = NULL;
	}
	if (sh->modify_cmds) {
		mlx5_hlist_destroy(sh->modify_cmds);
		sh->modify_cmds = NULL;
	}
	if (sh->tag_table) {
		/* tags should be destroyed with flow before. */
		mlx5_hlist_destroy(sh->tag_table);
		sh->tag_table = NULL;
	}
	if (sh->tunnel_hub) {
		mlx5_release_tunnel_hub(sh, priv->dev_port);
		sh->tunnel_hub = NULL;
	}
	mlx5_free_table_hash_list(priv);
	return err;
}
/**
 * Initialize DR related data within private structure.
 * Routine checks the reference counter and does actual
 * resources creation/initialization only if counter is zero.
 *
 * @param[in] priv
 *   Pointer to the private device data structure.
 *
 * @return
 *   Zero on success, positive error code otherwise.
 */
Initialize DR related data within private structure.
Routine checks the reference counter and does actual
resources creation/initialization only if counter is zero.

@param[in] priv
Pointer to the private device data structure.

@return
Zero on success, positive error code otherwise.
Initialize DR related data within private structure . Routine checks the reference counter and does actual resources creation / initialization only if counter is zero . @param [ in ] priv Pointer to the private device data structure . @return Zero on success positive error code otherwise .
static int
mlx5_alloc_shared_dr(struct mlx5_priv *priv)
{
	struct mlx5_dev_ctx_shared *sh = priv->sh;
	char s[MLX5_HLIST_NAMESIZE] __rte_unused;
	int err;
	MLX5_ASSERT(sh && sh->refcnt);
	if (sh->refcnt > 1)
		return 0;
	err = mlx5_alloc_table_hash_list(priv);
	if (err)
		goto error;
#ifdef HAVE_IBV_FLOW_DV_SUPPORT
	snprintf(s, sizeof(s), "%s_port_id_action_cache", sh->ibdev_name);
	mlx5_cache_list_init(&sh->port_id_action_list, s, 0, sh,
			     flow_dv_port_id_create_cb,
			     flow_dv_port_id_match_cb,
			     flow_dv_port_id_remove_cb);
	snprintf(s, sizeof(s), "%s_push_vlan_action_cache", sh->ibdev_name);
	mlx5_cache_list_init(&sh->push_vlan_action_list, s, 0, sh,
			     flow_dv_push_vlan_create_cb,
			     flow_dv_push_vlan_match_cb,
			     flow_dv_push_vlan_remove_cb);
	snprintf(s, sizeof(s), "%s_sample_action_cache", sh->ibdev_name);
	mlx5_cache_list_init(&sh->sample_action_list, s, 0, sh,
			     flow_dv_sample_create_cb,
			     flow_dv_sample_match_cb,
			     flow_dv_sample_remove_cb);
	snprintf(s, sizeof(s), "%s_dest_array_cache", sh->ibdev_name);
	mlx5_cache_list_init(&sh->dest_array_list, s, 0, sh,
			     flow_dv_dest_array_create_cb,
			     flow_dv_dest_array_match_cb,
			     flow_dv_dest_array_remove_cb);
	snprintf(s, sizeof(s), "%s_tags", sh->ibdev_name);
	sh->tag_table = mlx5_hlist_create(s, MLX5_TAGS_HLIST_ARRAY_SIZE, 0,
					  MLX5_HLIST_WRITE_MOST,
					  flow_dv_tag_create_cb,
					  flow_dv_tag_match_cb,
					  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, MLX5_HLIST_WRITE_MOST |
					    MLX5_HLIST_DIRECT_KEY,
					    flow_dv_modify_create_cb,
					    flow_dv_modify_match_cb,
					    flow_dv_modify_remove_cb);
	if (!sh->modify_cmds) {
		DRV_LOG(ERR, "hdr modify hash creation failed");
		err = ENOMEM;
		goto error;
	}
	sh->modify_cmds->ctx = sh;
	snprintf(s, sizeof(s), "%s_encaps_decaps", sh->ibdev_name);
	sh->encaps_decaps = mlx5_hlist_create(s,
					      MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ,
					      0, MLX5_HLIST_DIRECT_KEY |
					      MLX5_HLIST_WRITE_MOST,
					      flow_dv_encap_decap_create_cb,
					      flow_dv_encap_decap_match_cb,
					      flow_dv_encap_decap_remove_cb);
	if (!sh->encaps_decaps) {
		DRV_LOG(ERR, "encap decap hash creation failed");
		err = ENOMEM;
		goto error;
	}
	sh->encaps_decaps->ctx = sh;
#endif
#ifdef HAVE_MLX5DV_DR
	void *domain;
	domain = mlx5_glue->dr_create_domain(sh->ctx,
					     MLX5DV_DR_DOMAIN_TYPE_NIC_RX);
	if (!domain) {
		DRV_LOG(ERR, "ingress mlx5dv_dr_create_domain failed");
		err = errno;
		goto error;
	}
	sh->rx_domain = domain;
	domain = mlx5_glue->dr_create_domain(sh->ctx,
					     MLX5DV_DR_DOMAIN_TYPE_NIC_TX);
	if (!domain) {
		DRV_LOG(ERR, "egress mlx5dv_dr_create_domain failed");
		err = errno;
		goto error;
	}
	sh->tx_domain = domain;
#ifdef HAVE_MLX5DV_DR_ESWITCH
	if (priv->config.dv_esw_en) {
		domain  = mlx5_glue->dr_create_domain
			(sh->ctx, MLX5DV_DR_DOMAIN_TYPE_FDB);
		if (!domain) {
			DRV_LOG(ERR, "FDB mlx5dv_dr_create_domain failed");
			err = errno;
			goto error;
		}
		sh->fdb_domain = domain;
	}
	sh->dr_drop_action = mlx5_glue->dr_create_flow_action_drop();
	if (!sh->dr_drop_action) {
		DRV_LOG(ERR, "FDB mlx5dv_dr_create_flow_action_drop");
		err = errno;
		goto error;
	}
#endif
	if (!sh->tunnel_hub)
		err = mlx5_alloc_tunnel_hub(sh);
	if (err) {
		DRV_LOG(ERR, "mlx5_alloc_tunnel_hub failed err=%d", err);
		goto error;
	}
	if (priv->config.reclaim_mode == MLX5_RCM_AGGR) {
		mlx5_glue->dr_reclaim_domain_memory(sh->rx_domain, 1);
		mlx5_glue->dr_reclaim_domain_memory(sh->tx_domain, 1);
		if (sh->fdb_domain)
			mlx5_glue->dr_reclaim_domain_memory(sh->fdb_domain, 1);
	}
	sh->pop_vlan_action = mlx5_glue->dr_create_flow_action_pop_vlan();
#endif 
	sh->default_miss_action =
			mlx5_glue->dr_create_flow_action_default_miss();
	if (!sh->default_miss_action)
		DRV_LOG(WARNING, "Default miss action is not supported.");
	return 0;
error:
	if (sh->rx_domain) {
		mlx5_glue->dr_destroy_domain(sh->rx_domain);
		sh->rx_domain = NULL;
	}
	if (sh->tx_domain) {
		mlx5_glue->dr_destroy_domain(sh->tx_domain);
		sh->tx_domain = NULL;
	}
	if (sh->fdb_domain) {
		mlx5_glue->dr_destroy_domain(sh->fdb_domain);
		sh->fdb_domain = NULL;
	}
	if (sh->dr_drop_action) {
		mlx5_glue->destroy_flow_action(sh->dr_drop_action);
		sh->dr_drop_action = NULL;
	}
	if (sh->pop_vlan_action) {
		mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
		sh->pop_vlan_action = NULL;
	}
	if (sh->encaps_decaps) {
		mlx5_hlist_destroy(sh->encaps_decaps);
		sh->encaps_decaps = NULL;
	}
	if (sh->modify_cmds) {
		mlx5_hlist_destroy(sh->modify_cmds);
		sh->modify_cmds = NULL;
	}
	if (sh->tag_table) {
		mlx5_hlist_destroy(sh->tag_table);
		sh->tag_table = NULL;
	}
	if (sh->tunnel_hub) {
		mlx5_release_tunnel_hub(sh, priv->dev_port);
		sh->tunnel_hub = NULL;
	}
	mlx5_free_table_hash_list(priv);
	return err;
}
static int mlx5_alloc_shared_dr ( struct mlx5_priv * priv ) { struct mlx5_dev_ctx_shared * sh = priv -> sh ; char s [ MLX5_HLIST_NAMESIZE ] __rte_unused ; int err ; MLX5_ASSERT ( sh && sh -> refcnt ) ; if ( sh -> refcnt > 1 ) return 0 ; err = mlx5_alloc_table_hash_list ( priv ) ; if ( err ) goto error ; #ifdef HAVE_IBV_FLOW_DV_SUPPORT snprintf ( s , sizeof ( s ) , " " , sh -> ibdev_name ) ; mlx5_cache_list_init ( & sh -> port_id_action_list , s , 0 , sh , flow_dv_port_id_create_cb , flow_dv_port_id_match_cb , flow_dv_port_id_remove_cb ) ; snprintf ( s , sizeof ( s ) , " " , sh -> ibdev_name ) ; mlx5_cache_list_init ( & sh -> push_vlan_action_list , s , 0 , sh , flow_dv_push_vlan_create_cb , flow_dv_push_vlan_match_cb , flow_dv_push_vlan_remove_cb ) ; snprintf ( s , sizeof ( s ) , " " , sh -> ibdev_name ) ; mlx5_cache_list_init ( & sh -> sample_action_list , s , 0 , sh , flow_dv_sample_create_cb , flow_dv_sample_match_cb , flow_dv_sample_remove_cb ) ; snprintf ( s , sizeof ( s ) , " " , sh -> ibdev_name ) ; mlx5_cache_list_init ( & sh -> dest_array_list , s , 0 , sh , flow_dv_dest_array_create_cb , flow_dv_dest_array_match_cb , flow_dv_dest_array_remove_cb ) ; snprintf ( s , sizeof ( s ) , " " , sh -> ibdev_name ) ; sh -> tag_table = mlx5_hlist_create ( s , MLX5_TAGS_HLIST_ARRAY_SIZE , 0 , MLX5_HLIST_WRITE_MOST , flow_dv_tag_create_cb , flow_dv_tag_match_cb , flow_dv_tag_remove_cb ) ; if ( ! sh -> tag_table ) { DRV_LOG ( ERR , " " ) ; err = ENOMEM ; goto error ; } sh -> tag_table -> ctx = sh ; snprintf ( s , sizeof ( s ) , " " , sh -> ibdev_name ) ; sh -> modify_cmds = mlx5_hlist_create ( s , MLX5_FLOW_HDR_MODIFY_HTABLE_SZ , 0 , MLX5_HLIST_WRITE_MOST | MLX5_HLIST_DIRECT_KEY , flow_dv_modify_create_cb , flow_dv_modify_match_cb , flow_dv_modify_remove_cb ) ; if ( ! sh -> modify_cmds ) { DRV_LOG ( ERR , " " ) ; err = ENOMEM ; goto error ; } sh -> modify_cmds -> ctx = sh ; snprintf ( s , sizeof ( s ) , " " , sh -> ibdev_name ) ; sh -> encaps_decaps = mlx5_hlist_create ( s , MLX5_FLOW_ENCAP_DECAP_HTABLE_SZ , 0 , MLX5_HLIST_DIRECT_KEY | MLX5_HLIST_WRITE_MOST , flow_dv_encap_decap_create_cb , flow_dv_encap_decap_match_cb , flow_dv_encap_decap_remove_cb ) ; if ( ! sh -> encaps_decaps ) { DRV_LOG ( ERR , " " ) ; err = ENOMEM ; goto error ; } sh -> encaps_decaps -> ctx = sh ; #endif #ifdef HAVE_MLX5DV_DR void * domain ; domain = mlx5_glue -> dr_create_domain ( sh -> ctx , MLX5DV_DR_DOMAIN_TYPE_NIC_RX ) ; if ( ! domain ) { DRV_LOG ( ERR , " " ) ; err = errno ; goto error ; } sh -> rx_domain = domain ; domain = mlx5_glue -> dr_create_domain ( sh -> ctx , MLX5DV_DR_DOMAIN_TYPE_NIC_TX ) ; if ( ! domain ) { DRV_LOG ( ERR , " " ) ; err = errno ; goto error ; } sh -> tx_domain = domain ; #ifdef HAVE_MLX5DV_DR_ESWITCH if ( priv -> config . dv_esw_en ) { domain = mlx5_glue -> dr_create_domain ( sh -> ctx , MLX5DV_DR_DOMAIN_TYPE_FDB ) ; if ( ! domain ) { DRV_LOG ( ERR , " " ) ; err = errno ; goto error ; } sh -> fdb_domain = domain ; } sh -> dr_drop_action = mlx5_glue -> dr_create_flow_action_drop ( ) ; if ( ! sh -> dr_drop_action ) { DRV_LOG ( ERR , " " ) ; err = errno ; goto error ; } #endif if ( ! sh -> tunnel_hub ) err = mlx5_alloc_tunnel_hub ( sh ) ; if ( err ) { DRV_LOG ( ERR , " " , err ) ; goto error ; } if ( priv -> config . reclaim_mode == MLX5_RCM_AGGR ) { mlx5_glue -> dr_reclaim_domain_memory ( sh -> rx_domain , 1 ) ; mlx5_glue -> dr_reclaim_domain_memory ( sh -> tx_domain , 1 ) ; if ( sh -> fdb_domain ) mlx5_glue -> dr_reclaim_domain_memory ( sh -> fdb_domain , 1 ) ; } sh -> pop_vlan_action = mlx5_glue -> dr_create_flow_action_pop_vlan ( ) ; #endif sh -> default_miss_action = mlx5_glue -> dr_create_flow_action_default_miss ( ) ; if ( ! sh -> default_miss_action ) DRV_LOG ( WARNING , " " ) ; return 0 ; error : if ( sh -> rx_domain ) { mlx5_glue -> dr_destroy_domain ( sh -> rx_domain ) ; sh -> rx_domain = NULL ; } if ( sh -> tx_domain ) { mlx5_glue -> dr_destroy_domain ( sh -> tx_domain ) ; sh -> tx_domain = NULL ; } if ( sh -> fdb_domain ) { mlx5_glue -> dr_destroy_domain ( sh -> fdb_domain ) ; sh -> fdb_domain = NULL ; } if ( sh -> dr_drop_action ) { mlx5_glue -> destroy_flow_action ( sh -> dr_drop_action ) ; sh -> dr_drop_action = NULL ; } if ( sh -> pop_vlan_action ) { mlx5_glue -> destroy_flow_action ( sh -> pop_vlan_action ) ; sh -> pop_vlan_action = NULL ; } if ( sh -> encaps_decaps ) { mlx5_hlist_destroy ( sh -> encaps_decaps ) ; sh -> encaps_decaps = NULL ; } if ( sh -> modify_cmds ) { mlx5_hlist_destroy ( sh -> modify_cmds ) ; sh -> modify_cmds = NULL ; } if ( sh -> tag_table ) { mlx5_hlist_destroy ( sh -> tag_table ) ; sh -> tag_table = NULL ; } if ( sh -> tunnel_hub ) { mlx5_release_tunnel_hub ( sh , priv -> dev_port ) ; sh -> tunnel_hub = NULL ; } mlx5_free_table_hash_list ( priv ) ; return err ; }
Initialize DR related data within private structure.
Initialize DR related data within private structure .
/* The resources below are only valid with DV support. */ /* Init port id action cache list. */ /* Init push vlan action cache list. */ /* Init sample action cache list. */ /* Init dest array action cache list. */ /* Create tags hash list table. */ /* Reference counter is zero, we should initialize structures. */ /*
	 * The drop action is just some dummy placeholder in rdma-core. It
	 * does not belong to domains and has no any attributes, and, can be
	 * shared by the entire device.
	 */ /* HAVE_MLX5DV_DR */ /* Rollback the created objects. */ /* tags should be destroyed with flow before. */