git: e073fccf1456 - stable/14 - mlx5: add ability to attach flow counter to steering rule

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 22 Nov 2023 01:52:00 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=e073fccf14569f61b312078d0cee9a6f6eb17a37

commit e073fccf14569f61b312078d0cee9a6f6eb17a37
Author:     Mark Bloch <mbloch@nvidia.com>
AuthorDate: 2023-02-22 05:44:56 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-11-22 01:40:28 +0000

    mlx5: add ability to attach flow counter to steering rule
    
    (cherry picked from commit ad744541311bfddd74ea3c5d49d52a4c366b9762)
---
 sys/dev/mlx5/fs.h                     |  2 ++
 sys/dev/mlx5/mlx5_core/mlx5_fs_cmd.c  | 19 +++++++++++++++++--
 sys/dev/mlx5/mlx5_core/mlx5_fs_tree.c |  3 +++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/sys/dev/mlx5/fs.h b/sys/dev/mlx5/fs.h
index 65d38b9ee67a..8aaa0e201f4a 100644
--- a/sys/dev/mlx5/fs.h
+++ b/sys/dev/mlx5/fs.h
@@ -94,6 +94,7 @@ enum mlx5_flow_act_actions {
 	MLX5_FLOW_ACT_ACTIONS_FLOW_TAG = 1 << 0,
 	MLX5_FLOW_ACT_ACTIONS_MODIFY_HDR = 1 << 1,
 	MLX5_FLOW_ACT_ACTIONS_PACKET_REFORMAT = 1 << 2,
+	MLX5_FLOW_ACT_ACTIONS_COUNT = 1 << 3,
 };
 
 enum MLX5_FLOW_ACT_FLAGS {
@@ -106,6 +107,7 @@ struct mlx5_flow_act {
 	u32 flow_tag;
 	struct mlx5_modify_hdr *modify_hdr;
 	struct mlx5_pkt_reformat *pkt_reformat;
+	struct mlx5_fc *counter;
 };
 
 #define FT_NAME_STR_SZ 20
diff --git a/sys/dev/mlx5/mlx5_core/mlx5_fs_cmd.c b/sys/dev/mlx5/mlx5_core/mlx5_fs_cmd.c
index 8032d1a632e5..0f827f0e69d3 100644
--- a/sys/dev/mlx5/mlx5_core/mlx5_fs_cmd.c
+++ b/sys/dev/mlx5/mlx5_core/mlx5_fs_cmd.c
@@ -182,6 +182,7 @@ int mlx5_cmd_fs_set_fte(struct mlx5_core_dev *dev,
 	int modify_mask = 0;
 	int atomic_mod_cap;
 	u32 prm_action = 0;
+	int count_list = 0;
 
 	if (sw_action != MLX5_FLOW_RULE_FWD_ACTION_DEST)
 		dest_size = 0;
@@ -195,8 +196,13 @@ int mlx5_cmd_fs_set_fte(struct mlx5_core_dev *dev,
 	if (sw_action & MLX5_FLOW_RULE_FWD_ACTION_DEST)
 		prm_action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
 
+	if (flow_act->actions & MLX5_FLOW_ACT_ACTIONS_COUNT) {
+		prm_action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
+		count_list = 1;
+	}
+
 	inlen = MLX5_ST_SZ_BYTES(set_fte_in) +
-		dest_size * MLX5_ST_SZ_BYTES(dest_format_struct);
+		(dest_size + count_list) * MLX5_ST_SZ_BYTES(dest_format_struct);
 
 	if (!dev)
 		return -EINVAL;
@@ -248,8 +254,10 @@ int mlx5_cmd_fs_set_fte(struct mlx5_core_dev *dev,
 	in_match_value = MLX5_ADDR_OF(flow_context, in_flow_context,
 				      match_value);
 	memcpy(in_match_value, match_val, MLX5_ST_SZ_BYTES(fte_match_param));
+
+	in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination);
+
 	if (dest_size) {
-		in_dests = MLX5_ADDR_OF(flow_context, in_flow_context, destination);
 		list_for_each_entry(dst, dests, base.list) {
 			unsigned int id;
 
@@ -265,6 +273,13 @@ int mlx5_cmd_fs_set_fte(struct mlx5_core_dev *dev,
 		}
 	}
 
+	if (flow_act->actions & MLX5_FLOW_ACT_ACTIONS_COUNT) {
+		MLX5_SET(dest_format_struct, in_dests, destination_id,
+			 mlx5_fc_id(flow_act->counter));
+		in_dests += MLX5_ST_SZ_BYTES(dest_format_struct);
+		MLX5_SET(flow_context, in_flow_context, flow_counter_list_size, 1);
+	}
+
 	MLX5_SET(flow_context, in_flow_context, action, prm_action);
 	err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
 	if (!err)
diff --git a/sys/dev/mlx5/mlx5_core/mlx5_fs_tree.c b/sys/dev/mlx5/mlx5_core/mlx5_fs_tree.c
index 91543d3878ef..5966a73c58d1 100644
--- a/sys/dev/mlx5/mlx5_core/mlx5_fs_tree.c
+++ b/sys/dev/mlx5/mlx5_core/mlx5_fs_tree.c
@@ -1788,6 +1788,9 @@ static bool check_conflicting_actions(const struct mlx5_flow_act *act1,
 	if (action1 & MLX5_FLOW_ACT_ACTIONS_PACKET_REFORMAT)
 		return true;
 
+	if (action1 & MLX5_FLOW_ACT_ACTIONS_COUNT)
+		return true;
+
 	return false;
 }