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 bool
tc_act_can_offload_sample(struct mlx5e_tc_act_parse_state * parse_state,const struct flow_action_entry * act,int act_index,struct mlx5_flow_attr * attr)10 tc_act_can_offload_sample(struct mlx5e_tc_act_parse_state *parse_state,
11 const struct flow_action_entry *act,
12 int act_index,
13 struct mlx5_flow_attr *attr)
14 {
15 struct netlink_ext_ack *extack = parse_state->extack;
16 bool ct_nat;
17
18 ct_nat = attr->ct_attr.ct_action & TCA_CT_ACT_NAT;
19
20 if (flow_flag_test(parse_state->flow, CT) && ct_nat) {
21 NL_SET_ERR_MSG_MOD(extack, "Sample action with CT NAT is not supported");
22 return false;
23 }
24
25 return true;
26 }
27
28 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)29 tc_act_parse_sample(struct mlx5e_tc_act_parse_state *parse_state,
30 const struct flow_action_entry *act,
31 struct mlx5e_priv *priv,
32 struct mlx5_flow_attr *attr)
33 {
34 struct mlx5e_sample_attr *sample_attr = &attr->sample_attr;
35
36 sample_attr->rate = act->sample.rate;
37 sample_attr->group_num = act->sample.psample_group->group_num;
38
39 if (act->sample.truncate)
40 sample_attr->trunc_size = act->sample.trunc_size;
41
42 attr->flags |= MLX5_ATTR_FLAG_SAMPLE;
43 flow_flag_set(parse_state->flow, SAMPLE);
44
45 return 0;
46 }
47
48 bool
mlx5e_tc_act_sample_is_multi_table(struct mlx5_core_dev * mdev,struct mlx5_flow_attr * attr)49 mlx5e_tc_act_sample_is_multi_table(struct mlx5_core_dev *mdev,
50 struct mlx5_flow_attr *attr)
51 {
52 if (MLX5_CAP_GEN(mdev, reg_c_preserve) ||
53 attr->action & MLX5_FLOW_CONTEXT_ACTION_DECAP)
54 return true;
55
56 return false;
57 }
58
59 static bool
tc_act_is_multi_table_act_sample(struct mlx5e_priv * priv,const struct flow_action_entry * act,struct mlx5_flow_attr * attr)60 tc_act_is_multi_table_act_sample(struct mlx5e_priv *priv,
61 const struct flow_action_entry *act,
62 struct mlx5_flow_attr *attr)
63 {
64 return mlx5e_tc_act_sample_is_multi_table(priv->mdev, attr);
65 }
66
67 struct mlx5e_tc_act mlx5e_tc_act_sample = {
68 .can_offload = tc_act_can_offload_sample,
69 .parse_action = tc_act_parse_sample,
70 .is_multi_table_act = tc_act_is_multi_table_act_sample,
71 };
72