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 {
36 	bool (*can_offload)(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 	int (*parse_action)(struct mlx5e_tc_act_parse_state *parse_state,
42 			    const struct flow_action_entry *act,
43 			    struct mlx5e_priv *priv,
44 			    struct mlx5_flow_attr *attr);
45 
46 	int (*post_parse)(struct mlx5e_tc_act_parse_state *parse_state,
47 			  struct mlx5e_priv *priv,
48 			  struct mlx5_flow_attr *attr);
49 
50 	bool (*is_multi_table_act)(struct mlx5e_priv *priv,
51 				   const struct flow_action_entry *act,
52 				   struct mlx5_flow_attr *attr);
53 
54 	int (*offload_action)(struct mlx5e_priv *priv,
55 			      struct flow_offload_action *fl_act,
56 			      struct flow_action_entry *act);
57 
58 	int (*destroy_action)(struct mlx5e_priv *priv,
59 			      struct flow_offload_action *fl_act);
60 
61 	int (*stats_action)(struct mlx5e_priv *priv,
62 			    struct flow_offload_action *fl_act);
63 };
64 
65 struct mlx5e_tc_flow_action {
66 	unsigned int num_entries;
67 	struct flow_action_entry **entries;
68 };
69 
70 extern struct mlx5e_tc_act mlx5e_tc_act_drop;
71 extern struct mlx5e_tc_act mlx5e_tc_act_trap;
72 extern struct mlx5e_tc_act mlx5e_tc_act_accept;
73 extern struct mlx5e_tc_act mlx5e_tc_act_mark;
74 extern struct mlx5e_tc_act mlx5e_tc_act_goto;
75 extern struct mlx5e_tc_act mlx5e_tc_act_tun_encap;
76 extern struct mlx5e_tc_act mlx5e_tc_act_tun_decap;
77 extern struct mlx5e_tc_act mlx5e_tc_act_csum;
78 extern struct mlx5e_tc_act mlx5e_tc_act_pedit;
79 extern struct mlx5e_tc_act mlx5e_tc_act_vlan;
80 extern struct mlx5e_tc_act mlx5e_tc_act_vlan_mangle;
81 extern struct mlx5e_tc_act mlx5e_tc_act_mpls_push;
82 extern struct mlx5e_tc_act mlx5e_tc_act_mpls_pop;
83 extern struct mlx5e_tc_act mlx5e_tc_act_mirred;
84 extern struct mlx5e_tc_act mlx5e_tc_act_mirred_nic;
85 extern struct mlx5e_tc_act mlx5e_tc_act_ct;
86 extern struct mlx5e_tc_act mlx5e_tc_act_sample;
87 extern struct mlx5e_tc_act mlx5e_tc_act_ptype;
88 extern struct mlx5e_tc_act mlx5e_tc_act_redirect_ingress;
89 extern struct mlx5e_tc_act mlx5e_tc_act_police;
90 
91 struct mlx5e_tc_act *
92 mlx5e_tc_act_get(enum flow_action_id act_id,
93 		 enum mlx5_flow_namespace_type ns_type);
94 
95 void
96 mlx5e_tc_act_init_parse_state(struct mlx5e_tc_act_parse_state *parse_state,
97 			      struct mlx5e_tc_flow *flow,
98 			      struct flow_action *flow_action,
99 			      struct netlink_ext_ack *extack);
100 
101 void
102 mlx5e_tc_act_reorder_flow_actions(struct flow_action *flow_action,
103 				  struct mlx5e_tc_flow_action *flow_action_reorder);
104 
105 int
106 mlx5e_tc_act_post_parse(struct mlx5e_tc_act_parse_state *parse_state,
107 			struct flow_action *flow_action,
108 			struct mlx5_flow_attr *attr,
109 			enum mlx5_flow_namespace_type ns_type);
110 
111 int
112 mlx5e_tc_act_set_next_post_act(struct mlx5e_tc_flow *flow,
113 			       struct mlx5_flow_attr *attr,
114 			       struct mlx5_flow_attr *next_attr);
115 
116 #endif /* __MLX5_EN_TC_ACT_H__ */
117