mlx5: add ability to attach flow counter to steering rule

Expose a way to attach a counter to a flow rule.

Signed-off-by: Mark Bloch <mbloch@nvidia.com>
Sponsored by:	NVidia networking
MFC after:	1 week
This commit is contained in:
Mark Bloch 2023-02-22 05:44:56 +00:00 committed by Konstantin Belousov
parent 35bbcf0916
commit ad74454131
3 changed files with 22 additions and 2 deletions

View file

@ -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

View file

@ -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)

View file

@ -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;
}