net/mlx5: fs, add support for dest flow sampler HWS action
authorMoshe Shemesh <moshe@nvidia.com>
Sun, 9 Mar 2025 18:07:43 +0000 (20:07 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Mon, 17 Mar 2025 17:57:17 +0000 (18:57 +0100)
Add support for HW Steering action of flow sampler destination. For each
flow sampler created cache the hws action by sampler id as a key. Hold
refcount for each rule using the cached action.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://patch.msgid.link/1741543663-22123-4-git-send-email-tariqt@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h

index edf7db1e6e9c8e07a2d9e175868903d00ceb8387..1b787cd66e6fd3c0ad5c8710005e4a1fdc3fa152 100644 (file)
@@ -67,6 +67,7 @@ static int mlx5_fs_init_hws_actions_pool(struct mlx5_core_dev *dev,
        xa_init(&hws_pool->vport_dests);
        xa_init(&hws_pool->vport_vhca_dests);
        xa_init(&hws_pool->aso_meters);
+       xa_init(&hws_pool->sample_dests);
        return 0;
 
 cleanup_insert_hdr:
@@ -94,6 +95,9 @@ static void mlx5_fs_cleanup_hws_actions_pool(struct mlx5_fs_hws_context *fs_ctx)
        struct mlx5_fs_pool *pool;
        unsigned long i;
 
+       xa_for_each(&hws_pool->sample_dests, i, fs_hws_data)
+               kfree(fs_hws_data);
+       xa_destroy(&hws_pool->sample_dests);
        xa_for_each(&hws_pool->aso_meters, i, fs_hws_data)
                kfree(fs_hws_data);
        xa_destroy(&hws_pool->aso_meters);
@@ -528,6 +532,42 @@ static void mlx5_fs_put_action_aso_meter(struct mlx5_fs_hws_context *fs_ctx,
        return mlx5_fs_put_hws_action(meter_hws_data);
 }
 
+static struct mlx5hws_action *
+mlx5_fs_get_dest_action_sampler(struct mlx5_fs_hws_context *fs_ctx,
+                               struct mlx5_flow_rule *dst)
+{
+       struct mlx5_fs_hws_create_action_ctx create_ctx;
+       struct mlx5hws_context *ctx = fs_ctx->hws_ctx;
+       struct mlx5_fs_hws_data *sampler_hws_data;
+       u32 id = dst->dest_attr.sampler_id;
+       struct xarray *sampler_xa;
+
+       sampler_xa = &fs_ctx->hws_pool.sample_dests;
+       sampler_hws_data = mlx5_fs_get_cached_hws_data(sampler_xa, id);
+       if (!sampler_hws_data)
+               return NULL;
+
+       create_ctx.hws_ctx = ctx;
+       create_ctx.actions_type = MLX5HWS_ACTION_TYP_SAMPLER;
+       create_ctx.id = id;
+
+       return mlx5_fs_get_hws_action(sampler_hws_data, &create_ctx);
+}
+
+static void mlx5_fs_put_dest_action_sampler(struct mlx5_fs_hws_context *fs_ctx,
+                                           u32 sampler_id)
+{
+       struct mlx5_fs_hws_data *sampler_hws_data;
+       struct xarray *sampler_xa;
+
+       sampler_xa = &fs_ctx->hws_pool.sample_dests;
+       sampler_hws_data = xa_load(sampler_xa, sampler_id);
+       if (!sampler_hws_data)
+               return;
+
+       mlx5_fs_put_hws_action(sampler_hws_data);
+}
+
 static struct mlx5hws_action *
 mlx5_fs_create_action_dest_array(struct mlx5hws_context *ctx,
                                 struct mlx5hws_action_dest_attr *dests,
@@ -602,6 +642,9 @@ mlx5_fs_create_hws_action(struct mlx5_fs_hws_create_action_ctx *create_ctx)
                                                       create_ctx->id,
                                                       create_ctx->return_reg_id,
                                                       flags);
+       case MLX5HWS_ACTION_TYP_SAMPLER:
+               return mlx5hws_action_create_flow_sampler(create_ctx->hws_ctx,
+                                                         create_ctx->id, flags);
        default:
                return NULL;
        }
@@ -662,6 +705,9 @@ static void mlx5_fs_destroy_fs_action(struct mlx5_flow_root_namespace *ns,
        case MLX5HWS_ACTION_TYP_ASO_METER:
                mlx5_fs_put_action_aso_meter(fs_ctx, fs_action->exe_aso);
                break;
+       case MLX5HWS_ACTION_TYP_SAMPLER:
+               mlx5_fs_put_dest_action_sampler(fs_ctx, fs_action->sampler_id);
+               break;
        default:
                mlx5hws_action_destroy(fs_action->action);
        }
@@ -939,6 +985,14 @@ static int mlx5_fs_fte_get_hws_actions(struct mlx5_flow_root_namespace *ns,
                                dest_action = mlx5_fs_get_dest_action_vport(fs_ctx, dst,
                                                                            type_uplink);
                                break;
+                       case MLX5_FLOW_DESTINATION_TYPE_FLOW_SAMPLER:
+                               dest_action =
+                                       mlx5_fs_get_dest_action_sampler(fs_ctx,
+                                                                       dst);
+                               fs_actions[num_fs_actions].action = dest_action;
+                               fs_actions[num_fs_actions++].sampler_id =
+                                                       dst->dest_attr.sampler_id;
+                               break;
                        default:
                                err = -EOPNOTSUPP;
                                goto free_actions;
index 6970b1aa9540bd4635bbe82748513f356a8f4869..8b56298288da2dee5d1f8d85b45d318ef5d6ba13 100644 (file)
@@ -23,6 +23,7 @@ struct mlx5_fs_hws_actions_pool {
        struct xarray vport_vhca_dests;
        struct xarray vport_dests;
        struct xarray aso_meters;
+       struct xarray sample_dests;
 };
 
 struct mlx5_fs_hws_context {
@@ -51,6 +52,7 @@ struct mlx5_fs_hws_rule_action {
        union {
                struct mlx5_fc *counter;
                struct mlx5_exe_aso *exe_aso;
+               u32 sampler_id;
        };
 };