1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 // Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
4 #include "act.h"
5 #include "en/tc_priv.h"
6 #include "en/tc_ct.h"
7
8 static bool
tc_act_can_offload_ct(struct mlx5e_tc_act_parse_state * parse_state,const struct flow_action_entry * act,int act_index,struct mlx5_flow_attr * attr)9 tc_act_can_offload_ct(struct mlx5e_tc_act_parse_state *parse_state,
10 const struct flow_action_entry *act,
11 int act_index,
12 struct mlx5_flow_attr *attr)
13 {
14 return !((act->ct.action & TCA_CT_ACT_COMMIT) &&
15 flow_action_is_last_entry(parse_state->flow_action, act));
16 }
17
18 static int
tc_act_parse_ct(struct mlx5e_tc_act_parse_state * parse_state,const struct flow_action_entry * act,struct mlx5e_priv * priv,struct mlx5_flow_attr * attr)19 tc_act_parse_ct(struct mlx5e_tc_act_parse_state *parse_state,
20 const struct flow_action_entry *act,
21 struct mlx5e_priv *priv,
22 struct mlx5_flow_attr *attr)
23 {
24 int err;
25
26 err = mlx5_tc_ct_parse_action(parse_state->ct_priv, attr, act, parse_state->extack);
27 if (err)
28 return err;
29
30 if (mlx5e_is_eswitch_flow(parse_state->flow)) {
31 attr->esw_attr->split_count = attr->esw_attr->out_count;
32 parse_state->if_count = 0;
33 }
34
35 attr->flags |= MLX5_ATTR_FLAG_CT;
36
37 return 0;
38 }
39
40 static int
tc_act_post_parse_ct(struct mlx5e_tc_act_parse_state * parse_state,struct mlx5e_priv * priv,struct mlx5_flow_attr * attr)41 tc_act_post_parse_ct(struct mlx5e_tc_act_parse_state *parse_state,
42 struct mlx5e_priv *priv,
43 struct mlx5_flow_attr *attr)
44 {
45 if (!(attr->flags & MLX5_ATTR_FLAG_CT))
46 return 0;
47
48 return mlx5_tc_ct_flow_offload(parse_state->ct_priv, attr);
49 }
50
51 static bool
tc_act_is_multi_table_act_ct(struct mlx5e_priv * priv,const struct flow_action_entry * act,struct mlx5_flow_attr * attr)52 tc_act_is_multi_table_act_ct(struct mlx5e_priv *priv,
53 const struct flow_action_entry *act,
54 struct mlx5_flow_attr *attr)
55 {
56 if (act->ct.action & TCA_CT_ACT_CLEAR)
57 return false;
58
59 return true;
60 }
61
62 static bool
tc_act_is_missable_ct(const struct flow_action_entry * act)63 tc_act_is_missable_ct(const struct flow_action_entry *act)
64 {
65 return !(act->ct.action & TCA_CT_ACT_CLEAR);
66 }
67
68 struct mlx5e_tc_act mlx5e_tc_act_ct = {
69 .can_offload = tc_act_can_offload_ct,
70 .parse_action = tc_act_parse_ct,
71 .post_parse = tc_act_post_parse_ct,
72 .is_multi_table_act = tc_act_is_multi_table_act_ct,
73 .is_missable = tc_act_is_missable_ct,
74 };
75
76