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 
7 static bool
tc_act_can_offload_trap(struct mlx5e_tc_act_parse_state * parse_state,const struct flow_action_entry * act,int act_index,struct mlx5_flow_attr * attr)8 tc_act_can_offload_trap(struct mlx5e_tc_act_parse_state *parse_state,
9 			const struct flow_action_entry *act,
10 			int act_index,
11 			struct mlx5_flow_attr *attr)
12 {
13 	struct netlink_ext_ack *extack = parse_state->extack;
14 
15 	if (parse_state->flow_action->num_entries != 1) {
16 		NL_SET_ERR_MSG_MOD(extack, "action trap is supported as a sole action only");
17 		return false;
18 	}
19 
20 	return true;
21 }
22 
23 static int
tc_act_parse_trap(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_trap(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 	attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
30 	attr->flags |= MLX5_ATTR_FLAG_SLOW_PATH;
31 
32 	return 0;
33 }
34 
35 struct mlx5e_tc_act mlx5e_tc_act_trap = {
36 	.can_offload = tc_act_can_offload_trap,
37 	.parse_action = tc_act_parse_trap,
38 };
39