diff mbox series

[net-next,04/13] net/mlx5: fs, add HWS actions pool

Message ID 20250107060708.1610882-5-tariqt@nvidia.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series mlx5 HW-Managed Flow Steering in FS core level | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: linux-rdma@vger.kernel.org
netdev/build_clang success Errors and warnings before: 72 this patch: 72
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tariq Toukan Jan. 7, 2025, 6:06 a.m. UTC
From: Moshe Shemesh <moshe@nvidia.com>

The HW Steering actions pool will help utilize the option in HW Steering
to share steering actions among different rules.

Create pool on root namespace creation and add few HW Steering actions
that don't depend on the steering rule itself and thus can be shared
between rules, created on same namespace: tag, pop_vlan, push_vlan,
drop, decap l2.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/steering/hws/fs_hws.c  | 58 +++++++++++++++++++
 .../mellanox/mlx5/core/steering/hws/fs_hws.h  |  9 +++
 2 files changed, 67 insertions(+)

Comments

Przemek Kitszel Jan. 7, 2025, 11:36 a.m. UTC | #1
On 1/7/25 07:06, Tariq Toukan wrote:
> From: Moshe Shemesh <moshe@nvidia.com>
> 
> The HW Steering actions pool will help utilize the option in HW Steering
> to share steering actions among different rules.
> 
> Create pool on root namespace creation and add few HW Steering actions
> that don't depend on the steering rule itself and thus can be shared
> between rules, created on same namespace: tag, pop_vlan, push_vlan,
> drop, decap l2.
> 
> Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
> Reviewed-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
> Reviewed-by: Mark Bloch <mbloch@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
> ---
>   .../mellanox/mlx5/core/steering/hws/fs_hws.c  | 58 +++++++++++++++++++
>   .../mellanox/mlx5/core/steering/hws/fs_hws.h  |  9 +++
>   2 files changed, 67 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
> index c8064bc8a86c..eeaf4a84aafc 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
> @@ -9,9 +9,60 @@
>   #define MLX5HWS_CTX_MAX_NUM_OF_QUEUES 16
>   #define MLX5HWS_CTX_QUEUE_SIZE 256
>   
> +static int init_hws_actions_pool(struct mlx5_fs_hws_context *fs_ctx)
> +{
> +	u32 flags = MLX5HWS_ACTION_FLAG_HWS_FDB | MLX5HWS_ACTION_FLAG_SHARED;
> +	struct mlx5_fs_hws_actions_pool *hws_pool = &fs_ctx->hws_pool;
> +	struct mlx5hws_action_reformat_header reformat_hdr = {};
> +	struct mlx5hws_context *ctx = fs_ctx->hws_ctx;
> +	enum mlx5hws_action_type action_type;
> +
> +	hws_pool->tag_action = mlx5hws_action_create_tag(ctx, flags);
> +	if (!hws_pool->tag_action)
> +		return -ENOMEM;
> +	hws_pool->pop_vlan_action = mlx5hws_action_create_pop_vlan(ctx, flags);
> +	if (!hws_pool->pop_vlan_action)
> +		goto destroy_tag;
> +	hws_pool->push_vlan_action = mlx5hws_action_create_push_vlan(ctx, flags);
> +	if (!hws_pool->push_vlan_action)
> +		goto destroy_pop_vlan;
> +	hws_pool->drop_action = mlx5hws_action_create_dest_drop(ctx, flags);
> +	if (!hws_pool->drop_action)
> +		goto destroy_push_vlan;
> +	action_type = MLX5HWS_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
> +	hws_pool->decapl2_action =
> +		mlx5hws_action_create_reformat(ctx, action_type, 1,
> +					       &reformat_hdr, 0, flags);
> +	if (!hws_pool->decapl2_action)
> +		goto destroy_drop;
> +	return 0;
> +
> +destroy_drop:
> +	mlx5hws_action_destroy(hws_pool->drop_action);
> +destroy_push_vlan:
> +	mlx5hws_action_destroy(hws_pool->push_vlan_action);
> +destroy_pop_vlan:
> +	mlx5hws_action_destroy(hws_pool->pop_vlan_action);
> +destroy_tag:
> +	mlx5hws_action_destroy(hws_pool->tag_action);
> +	return -ENOMEM;

I would expect to get -ENOMEM only on k*alloc() family failures, but
your set of helpers does much more than just attempt to allocate memory.
-ENOSPC?
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
index c8064bc8a86c..eeaf4a84aafc 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
@@ -9,9 +9,60 @@ 
 #define MLX5HWS_CTX_MAX_NUM_OF_QUEUES 16
 #define MLX5HWS_CTX_QUEUE_SIZE 256
 
+static int init_hws_actions_pool(struct mlx5_fs_hws_context *fs_ctx)
+{
+	u32 flags = MLX5HWS_ACTION_FLAG_HWS_FDB | MLX5HWS_ACTION_FLAG_SHARED;
+	struct mlx5_fs_hws_actions_pool *hws_pool = &fs_ctx->hws_pool;
+	struct mlx5hws_action_reformat_header reformat_hdr = {};
+	struct mlx5hws_context *ctx = fs_ctx->hws_ctx;
+	enum mlx5hws_action_type action_type;
+
+	hws_pool->tag_action = mlx5hws_action_create_tag(ctx, flags);
+	if (!hws_pool->tag_action)
+		return -ENOMEM;
+	hws_pool->pop_vlan_action = mlx5hws_action_create_pop_vlan(ctx, flags);
+	if (!hws_pool->pop_vlan_action)
+		goto destroy_tag;
+	hws_pool->push_vlan_action = mlx5hws_action_create_push_vlan(ctx, flags);
+	if (!hws_pool->push_vlan_action)
+		goto destroy_pop_vlan;
+	hws_pool->drop_action = mlx5hws_action_create_dest_drop(ctx, flags);
+	if (!hws_pool->drop_action)
+		goto destroy_push_vlan;
+	action_type = MLX5HWS_ACTION_TYP_REFORMAT_TNL_L2_TO_L2;
+	hws_pool->decapl2_action =
+		mlx5hws_action_create_reformat(ctx, action_type, 1,
+					       &reformat_hdr, 0, flags);
+	if (!hws_pool->decapl2_action)
+		goto destroy_drop;
+	return 0;
+
+destroy_drop:
+	mlx5hws_action_destroy(hws_pool->drop_action);
+destroy_push_vlan:
+	mlx5hws_action_destroy(hws_pool->push_vlan_action);
+destroy_pop_vlan:
+	mlx5hws_action_destroy(hws_pool->pop_vlan_action);
+destroy_tag:
+	mlx5hws_action_destroy(hws_pool->tag_action);
+	return -ENOMEM;
+}
+
+static void cleanup_hws_actions_pool(struct mlx5_fs_hws_context *fs_ctx)
+{
+	struct mlx5_fs_hws_actions_pool *hws_pool = &fs_ctx->hws_pool;
+
+	mlx5hws_action_destroy(hws_pool->decapl2_action);
+	mlx5hws_action_destroy(hws_pool->drop_action);
+	mlx5hws_action_destroy(hws_pool->push_vlan_action);
+	mlx5hws_action_destroy(hws_pool->pop_vlan_action);
+	mlx5hws_action_destroy(hws_pool->tag_action);
+}
+
 static int mlx5_cmd_hws_create_ns(struct mlx5_flow_root_namespace *ns)
 {
 	struct mlx5hws_context_attr hws_ctx_attr = {};
+	int err;
 
 	hws_ctx_attr.queues = min_t(int, num_online_cpus(),
 				    MLX5HWS_CTX_MAX_NUM_OF_QUEUES);
@@ -23,11 +74,18 @@  static int mlx5_cmd_hws_create_ns(struct mlx5_flow_root_namespace *ns)
 		mlx5_core_err(ns->dev, "Failed to create hws flow namespace\n");
 		return -EOPNOTSUPP;
 	}
+	err = init_hws_actions_pool(&ns->fs_hws_context);
+	if (err) {
+		mlx5_core_err(ns->dev, "Failed to init hws actions pool\n");
+		mlx5hws_context_close(ns->fs_hws_context.hws_ctx);
+		return err;
+	}
 	return 0;
 }
 
 static int mlx5_cmd_hws_destroy_ns(struct mlx5_flow_root_namespace *ns)
 {
+	cleanup_hws_actions_pool(&ns->fs_hws_context);
 	return mlx5hws_context_close(ns->fs_hws_context.hws_ctx);
 }
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h
index da8094c66cd5..256be4234d92 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h
@@ -6,8 +6,17 @@ 
 
 #include "mlx5hws.h"
 
+struct mlx5_fs_hws_actions_pool {
+	struct mlx5hws_action *tag_action;
+	struct mlx5hws_action *pop_vlan_action;
+	struct mlx5hws_action *push_vlan_action;
+	struct mlx5hws_action *drop_action;
+	struct mlx5hws_action *decapl2_action;
+};
+
 struct mlx5_fs_hws_context {
 	struct mlx5hws_context	*hws_ctx;
+	struct mlx5_fs_hws_actions_pool hws_pool;
 };
 
 struct mlx5_fs_hws_table {