xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/tun.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
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
tc_act_can_offload_tun_encap(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_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
tc_act_parse_tun_encap(struct mlx5e_tc_act_parse_state * parse_state,const struct flow_action_entry * act,struct mlx5e_priv * priv,struct mlx5_flow_attr * attr)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 int
tc_act_parse_tun_decap(struct mlx5e_tc_act_parse_state * parse_state,const struct flow_action_entry * act,struct mlx5e_priv * priv,struct mlx5_flow_attr * attr)36 tc_act_parse_tun_decap(struct mlx5e_tc_act_parse_state *parse_state,
37 		       const struct flow_action_entry *act,
38 		       struct mlx5e_priv *priv,
39 		       struct mlx5_flow_attr *attr)
40 {
41 	parse_state->decap = true;
42 
43 	return 0;
44 }
45 
46 struct mlx5e_tc_act mlx5e_tc_act_tun_encap = {
47 	.can_offload = tc_act_can_offload_tun_encap,
48 	.parse_action = tc_act_parse_tun_encap,
49 };
50 
51 struct mlx5e_tc_act mlx5e_tc_act_tun_decap = {
52 	.parse_action = tc_act_parse_tun_decap,
53 };
54