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
8static int
9tc_act_parse_ct(struct mlx5e_tc_act_parse_state *parse_state,
10		const struct flow_action_entry *act,
11		struct mlx5e_priv *priv,
12		struct mlx5_flow_attr *attr)
13{
14	int err;
15
16	err = mlx5_tc_ct_parse_action(parse_state->ct_priv, attr, act, parse_state->extack);
17	if (err)
18		return err;
19
20	if (mlx5e_is_eswitch_flow(parse_state->flow)) {
21		attr->esw_attr->split_count = attr->esw_attr->out_count;
22		parse_state->if_count = 0;
23	}
24
25	attr->flags |= MLX5_ATTR_FLAG_CT;
26
27	return 0;
28}
29
30static int
31tc_act_post_parse_ct(struct mlx5e_tc_act_parse_state *parse_state,
32		     struct mlx5e_priv *priv,
33		     struct mlx5_flow_attr *attr)
34{
35	if (!(attr->flags & MLX5_ATTR_FLAG_CT))
36		return 0;
37
38	return mlx5_tc_ct_flow_offload(parse_state->ct_priv, attr);
39}
40
41static bool
42tc_act_is_multi_table_act_ct(struct mlx5e_priv *priv,
43			     const struct flow_action_entry *act,
44			     struct mlx5_flow_attr *attr)
45{
46	if (act->ct.action & TCA_CT_ACT_CLEAR)
47		return false;
48
49	return true;
50}
51
52static bool
53tc_act_is_missable_ct(const struct flow_action_entry *act)
54{
55	return !(act->ct.action & TCA_CT_ACT_CLEAR);
56}
57
58struct mlx5e_tc_act mlx5e_tc_act_ct = {
59	.parse_action = tc_act_parse_ct,
60	.post_parse = tc_act_post_parse_ct,
61	.is_multi_table_act = tc_act_is_multi_table_act_ct,
62	.is_missable = tc_act_is_missable_ct,
63};
64
65