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 "mlx5_core.h"
7 
8 /* Must be aligned with enum flow_action_id. */
9 static struct mlx5e_tc_act *tc_acts_fdb[NUM_FLOW_ACTIONS] = {
10 	&mlx5e_tc_act_accept,
11 	&mlx5e_tc_act_drop,
12 	&mlx5e_tc_act_trap,
13 	&mlx5e_tc_act_goto,
14 	&mlx5e_tc_act_mirred,
15 	&mlx5e_tc_act_mirred,
16 	&mlx5e_tc_act_redirect_ingress,
17 	NULL, /* FLOW_ACTION_MIRRED_INGRESS, */
18 	&mlx5e_tc_act_vlan,
19 	&mlx5e_tc_act_vlan,
20 	&mlx5e_tc_act_vlan_mangle,
21 	&mlx5e_tc_act_tun_encap,
22 	&mlx5e_tc_act_tun_decap,
23 	&mlx5e_tc_act_pedit,
24 	&mlx5e_tc_act_pedit,
25 	&mlx5e_tc_act_csum,
26 	NULL, /* FLOW_ACTION_MARK, */
27 	&mlx5e_tc_act_ptype,
28 	NULL, /* FLOW_ACTION_PRIORITY, */
29 	NULL, /* FLOW_ACTION_WAKE, */
30 	NULL, /* FLOW_ACTION_QUEUE, */
31 	&mlx5e_tc_act_sample,
32 	NULL, /* FLOW_ACTION_POLICE, */
33 	&mlx5e_tc_act_ct,
34 	NULL, /* FLOW_ACTION_CT_METADATA, */
35 	&mlx5e_tc_act_mpls_push,
36 	&mlx5e_tc_act_mpls_pop,
37 };
38 
39 /* Must be aligned with enum flow_action_id. */
40 static struct mlx5e_tc_act *tc_acts_nic[NUM_FLOW_ACTIONS] = {
41 	&mlx5e_tc_act_accept,
42 	&mlx5e_tc_act_drop,
43 	NULL, /* FLOW_ACTION_TRAP, */
44 	&mlx5e_tc_act_goto,
45 	&mlx5e_tc_act_mirred_nic,
46 	NULL, /* FLOW_ACTION_MIRRED, */
47 	NULL, /* FLOW_ACTION_REDIRECT_INGRESS, */
48 	NULL, /* FLOW_ACTION_MIRRED_INGRESS, */
49 	NULL, /* FLOW_ACTION_VLAN_PUSH, */
50 	NULL, /* FLOW_ACTION_VLAN_POP, */
51 	NULL, /* FLOW_ACTION_VLAN_MANGLE, */
52 	NULL, /* FLOW_ACTION_TUNNEL_ENCAP, */
53 	NULL, /* FLOW_ACTION_TUNNEL_DECAP, */
54 	&mlx5e_tc_act_pedit,
55 	&mlx5e_tc_act_pedit,
56 	&mlx5e_tc_act_csum,
57 	&mlx5e_tc_act_mark,
58 	NULL, /* FLOW_ACTION_PTYPE, */
59 	NULL, /* FLOW_ACTION_PRIORITY, */
60 	NULL, /* FLOW_ACTION_WAKE, */
61 	NULL, /* FLOW_ACTION_QUEUE, */
62 	NULL, /* FLOW_ACTION_SAMPLE, */
63 	NULL, /* FLOW_ACTION_POLICE, */
64 	&mlx5e_tc_act_ct,
65 };
66 
67 /**
68  * mlx5e_tc_act_get() - Get an action parser for an action id.
69  * @act_id: Flow action id.
70  * @ns_type: flow namespace type.
71  */
72 struct mlx5e_tc_act *
73 mlx5e_tc_act_get(enum flow_action_id act_id,
74 		 enum mlx5_flow_namespace_type ns_type)
75 {
76 	struct mlx5e_tc_act **tc_acts;
77 
78 	tc_acts = ns_type == MLX5_FLOW_NAMESPACE_FDB ? tc_acts_fdb : tc_acts_nic;
79 
80 	return tc_acts[act_id];
81 }
82 
83 /**
84  * mlx5e_tc_act_init_parse_state() - Init a new parse_state.
85  * @parse_state: Parsing state.
86  * @flow:        mlx5e tc flow being handled.
87  * @flow_action: flow action to parse.
88  * @extack:      to set an error msg.
89  *
90  * The same parse_state should be passed to action parsers
91  * for tracking the current parsing state.
92  */
93 void
94 mlx5e_tc_act_init_parse_state(struct mlx5e_tc_act_parse_state *parse_state,
95 			      struct mlx5e_tc_flow *flow,
96 			      struct flow_action *flow_action,
97 			      struct netlink_ext_ack *extack)
98 {
99 	memset(parse_state, 0, sizeof(*parse_state));
100 	parse_state->flow = flow;
101 	parse_state->num_actions = flow_action->num_entries;
102 	parse_state->extack = extack;
103 }
104