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_tun_encap.h"
6 #include "en/tc_priv.h"
7 
8 static bool
9 tc_act_can_offload_tun_encap(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 	if (!act->tunnel) {
15 		NL_SET_ERR_MSG_MOD(parse_state->extack,
16 				   "Zero tunnel attributes is not supported");
17 		return false;
18 	}
19 
20 	return true;
21 }
22 
23 static int
24 tc_act_parse_tun_encap(struct mlx5e_tc_act_parse_state *parse_state,
25 		       const struct flow_action_entry *act,
26 		       struct mlx5e_priv *priv,
27 		       struct mlx5_flow_attr *attr)
28 {
29 	parse_state->tun_info = act->tunnel;
30 	parse_state->encap = true;
31 
32 	return 0;
33 }
34 
35 static bool
36 tc_act_can_offload_tun_decap(struct mlx5e_tc_act_parse_state *parse_state,
37 			     const struct flow_action_entry *act,
38 			     int act_index,
39 			     struct mlx5_flow_attr *attr)
40 {
41 	return true;
42 }
43 
44 static int
45 tc_act_parse_tun_decap(struct mlx5e_tc_act_parse_state *parse_state,
46 		       const struct flow_action_entry *act,
47 		       struct mlx5e_priv *priv,
48 		       struct mlx5_flow_attr *attr)
49 {
50 	parse_state->decap = true;
51 
52 	return 0;
53 }
54 
55 struct mlx5e_tc_act mlx5e_tc_act_tun_encap = {
56 	.can_offload = tc_act_can_offload_tun_encap,
57 	.parse_action = tc_act_parse_tun_encap,
58 };
59 
60 struct mlx5e_tc_act mlx5e_tc_act_tun_decap = {
61 	.can_offload = tc_act_can_offload_tun_decap,
62 	.parse_action = tc_act_parse_tun_decap,
63 };
64