1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 // Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 
4 #include <net/psample.h>
5 #include "act.h"
6 #include "en/tc_priv.h"
7 #include "en/tc/act/sample.h"
8 
9 static int
tc_act_parse_sample(struct mlx5e_tc_act_parse_state * parse_state,const struct flow_action_entry * act,struct mlx5e_priv * priv,struct mlx5_flow_attr * attr)10 tc_act_parse_sample(struct mlx5e_tc_act_parse_state *parse_state,
11 		    const struct flow_action_entry *act,
12 		    struct mlx5e_priv *priv,
13 		    struct mlx5_flow_attr *attr)
14 {
15 	struct mlx5e_sample_attr *sample_attr = &attr->sample_attr;
16 
17 	sample_attr->rate = act->sample.rate;
18 	sample_attr->group_num = act->sample.psample_group->group_num;
19 
20 	if (act->sample.truncate)
21 		sample_attr->trunc_size = act->sample.trunc_size;
22 
23 	attr->flags |= MLX5_ATTR_FLAG_SAMPLE;
24 	flow_flag_set(parse_state->flow, SAMPLE);
25 
26 	return 0;
27 }
28 
29 bool
mlx5e_tc_act_sample_is_multi_table(struct mlx5_core_dev * mdev,struct mlx5_flow_attr * attr)30 mlx5e_tc_act_sample_is_multi_table(struct mlx5_core_dev *mdev,
31 				   struct mlx5_flow_attr *attr)
32 {
33 	if (MLX5_CAP_GEN(mdev, reg_c_preserve) ||
34 	    attr->action & MLX5_FLOW_CONTEXT_ACTION_DECAP)
35 		return true;
36 
37 	return false;
38 }
39 
40 static bool
tc_act_is_multi_table_act_sample(struct mlx5e_priv * priv,const struct flow_action_entry * act,struct mlx5_flow_attr * attr)41 tc_act_is_multi_table_act_sample(struct mlx5e_priv *priv,
42 				 const struct flow_action_entry *act,
43 				 struct mlx5_flow_attr *attr)
44 {
45 	return mlx5e_tc_act_sample_is_multi_table(priv->mdev, attr);
46 }
47 
48 struct mlx5e_tc_act mlx5e_tc_act_sample = {
49 	.parse_action = tc_act_parse_sample,
50 	.is_multi_table_act = tc_act_is_multi_table_act_sample,
51 };
52