1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
3 
4 #ifndef __MLX5_EN_TC_ACT_H__
5 #define __MLX5_EN_TC_ACT_H__
6 
7 #include <net/tc_act/tc_pedit.h>
8 #include <net/flow_offload.h>
9 #include <linux/netlink.h>
10 #include "eswitch.h"
11 #include "pedit.h"
12 
13 struct mlx5_flow_attr;
14 
15 struct mlx5e_tc_act_parse_state {
16 	struct flow_action *flow_action;
17 	struct mlx5e_tc_flow *flow;
18 	struct netlink_ext_ack *extack;
19 	u32 actions;
20 	bool ct;
21 	bool ct_clear;
22 	bool encap;
23 	bool decap;
24 	bool mpls_push;
25 	bool eth_push;
26 	bool eth_pop;
27 	bool ptype_host;
28 	const struct ip_tunnel_info *tun_info;
29 	struct mlx5e_mpls_info mpls_info;
30 	int ifindexes[MLX5_MAX_FLOW_FWD_VPORTS];
31 	int if_count;
32 	struct mlx5_tc_ct_priv *ct_priv;
33 };
34 
35 struct mlx5e_tc_act_branch_ctrl {
36 	enum flow_action_id act_id;
37 	u32 extval;
38 };
39 
40 struct mlx5e_tc_act {
41 	bool (*can_offload)(struct mlx5e_tc_act_parse_state *parse_state,
42 			    const struct flow_action_entry *act,
43 			    int act_index,
44 			    struct mlx5_flow_attr *attr);
45 
46 	int (*parse_action)(struct mlx5e_tc_act_parse_state *parse_state,
47 			    const struct flow_action_entry *act,
48 			    struct mlx5e_priv *priv,
49 			    struct mlx5_flow_attr *attr);
50 
51 	int (*post_parse)(struct mlx5e_tc_act_parse_state *parse_state,
52 			  struct mlx5e_priv *priv,
53 			  struct mlx5_flow_attr *attr);
54 
55 	bool (*is_multi_table_act)(struct mlx5e_priv *priv,
56 				   const struct flow_action_entry *act,
57 				   struct mlx5_flow_attr *attr);
58 
59 	int (*offload_action)(struct mlx5e_priv *priv,
60 			      struct flow_offload_action *fl_act,
61 			      struct flow_action_entry *act);
62 
63 	int (*destroy_action)(struct mlx5e_priv *priv,
64 			      struct flow_offload_action *fl_act);
65 
66 	int (*stats_action)(struct mlx5e_priv *priv,
67 			    struct flow_offload_action *fl_act);
68 
69 	bool (*get_branch_ctrl)(const struct flow_action_entry *act,
70 				struct mlx5e_tc_act_branch_ctrl *cond_true,
71 				struct mlx5e_tc_act_branch_ctrl *cond_false);
72 
73 	bool is_terminating_action;
74 };
75 
76 struct mlx5e_tc_flow_action {
77 	unsigned int num_entries;
78 	struct flow_action_entry **entries;
79 };
80 
81 extern struct mlx5e_tc_act mlx5e_tc_act_drop;
82 extern struct mlx5e_tc_act mlx5e_tc_act_trap;
83 extern struct mlx5e_tc_act mlx5e_tc_act_accept;
84 extern struct mlx5e_tc_act mlx5e_tc_act_mark;
85 extern struct mlx5e_tc_act mlx5e_tc_act_goto;
86 extern struct mlx5e_tc_act mlx5e_tc_act_tun_encap;
87 extern struct mlx5e_tc_act mlx5e_tc_act_tun_decap;
88 extern struct mlx5e_tc_act mlx5e_tc_act_csum;
89 extern struct mlx5e_tc_act mlx5e_tc_act_pedit;
90 extern struct mlx5e_tc_act mlx5e_tc_act_vlan;
91 extern struct mlx5e_tc_act mlx5e_tc_act_vlan_mangle;
92 extern struct mlx5e_tc_act mlx5e_tc_act_mpls_push;
93 extern struct mlx5e_tc_act mlx5e_tc_act_mpls_pop;
94 extern struct mlx5e_tc_act mlx5e_tc_act_mirred;
95 extern struct mlx5e_tc_act mlx5e_tc_act_redirect;
96 extern struct mlx5e_tc_act mlx5e_tc_act_mirred_nic;
97 extern struct mlx5e_tc_act mlx5e_tc_act_ct;
98 extern struct mlx5e_tc_act mlx5e_tc_act_sample;
99 extern struct mlx5e_tc_act mlx5e_tc_act_ptype;
100 extern struct mlx5e_tc_act mlx5e_tc_act_redirect_ingress;
101 extern struct mlx5e_tc_act mlx5e_tc_act_police;
102 
103 struct mlx5e_tc_act *
104 mlx5e_tc_act_get(enum flow_action_id act_id,
105 		 enum mlx5_flow_namespace_type ns_type);
106 
107 void
108 mlx5e_tc_act_init_parse_state(struct mlx5e_tc_act_parse_state *parse_state,
109 			      struct mlx5e_tc_flow *flow,
110 			      struct flow_action *flow_action,
111 			      struct netlink_ext_ack *extack);
112 
113 void
114 mlx5e_tc_act_reorder_flow_actions(struct flow_action *flow_action,
115 				  struct mlx5e_tc_flow_action *flow_action_reorder);
116 
117 int
118 mlx5e_tc_act_post_parse(struct mlx5e_tc_act_parse_state *parse_state,
119 			struct flow_action *flow_action,
120 			struct mlx5_flow_attr *attr,
121 			enum mlx5_flow_namespace_type ns_type);
122 
123 int
124 mlx5e_tc_act_set_next_post_act(struct mlx5e_tc_flow *flow,
125 			       struct mlx5_flow_attr *attr,
126 			       struct mlx5_flow_attr *next_attr);
127 
128 #endif /* __MLX5_EN_TC_ACT_H__ */
129