xref: /freebsd/sys/dev/mlx5/fs.h (revision 2008043f386721d58158e37e0d7e50df8095942d)
1 /*-
2  * Copyright (c) 2013-2017, Mellanox Technologies, Ltd.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25 
26 #ifndef _MLX5_FS_
27 #define _MLX5_FS_
28 
29 #include <linux/list.h>
30 
31 #include <dev/mlx5/mlx5_ifc.h>
32 #include <dev/mlx5/device.h>
33 #include <dev/mlx5/driver.h>
34 
35 enum {
36 	MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO	= 1 << 16,
37 };
38 
39 /*Flow tag*/
40 enum {
41 	MLX5_FS_DEFAULT_FLOW_TAG  = 0xFFFFFF,
42 	MLX5_FS_ETH_FLOW_TAG  = 0xFFFFFE,
43 	MLX5_FS_SNIFFER_FLOW_TAG  = 0xFFFFFD,
44 };
45 
46 enum {
47 	MLX5_FS_FLOW_TAG_MASK = 0xFFFFFF,
48 };
49 
50 #define FS_MAX_TYPES		10
51 #define FS_MAX_ENTRIES		32000U
52 
53 enum mlx5_flow_namespace_type {
54 	MLX5_FLOW_NAMESPACE_BYPASS,
55 	MLX5_FLOW_NAMESPACE_OFFLOADS,
56 	MLX5_FLOW_NAMESPACE_KERNEL,
57 	MLX5_FLOW_NAMESPACE_LEFTOVERS,
58 	MLX5_FLOW_NAMESPACE_SNIFFER_RX,
59 	MLX5_FLOW_NAMESPACE_SNIFFER_TX,
60 	MLX5_FLOW_NAMESPACE_FDB,
61 	MLX5_FLOW_NAMESPACE_ESW_EGRESS,
62 	MLX5_FLOW_NAMESPACE_ESW_INGRESS,
63 };
64 
65 struct mlx5_flow_table;
66 struct mlx5_flow_group;
67 struct mlx5_flow_rule;
68 struct mlx5_flow_namespace;
69 
70 struct mlx5_flow_spec {
71 	u8   match_criteria_enable;
72 	u32  match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
73 	u32  match_value[MLX5_ST_SZ_DW(fte_match_param)];
74 };
75 
76 struct mlx5_flow_destination {
77 	u32	type;
78 	union {
79 		u32			tir_num;
80 		struct mlx5_flow_table	*ft;
81 		u32			vport_num;
82 	};
83 };
84 
85 #define FT_NAME_STR_SZ 20
86 #define LEFTOVERS_RULE_NUM 2
87 static inline void build_leftovers_ft_param(char *name,
88 	unsigned int *priority,
89 	int *n_ent,
90 	int *n_grp)
91 {
92 	snprintf(name, FT_NAME_STR_SZ, "leftovers");
93 	*priority = 0; /*Priority of leftovers_prio-0*/
94 	*n_ent = LEFTOVERS_RULE_NUM + 1; /*1: star rules*/
95 	*n_grp = LEFTOVERS_RULE_NUM;
96 }
97 
98 static inline bool outer_header_zero(u32 *match_criteria)
99 {
100 	int size = MLX5_ST_SZ_BYTES(fte_match_param);
101 	char *outer_headers_c = MLX5_ADDR_OF(fte_match_param, match_criteria,
102 					     outer_headers);
103 
104 	return outer_headers_c[0] == 0 && !memcmp(outer_headers_c,
105 						  outer_headers_c + 1,
106 						  size - 1);
107 }
108 
109 struct mlx5_flow_namespace *
110 mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
111 			enum mlx5_flow_namespace_type type);
112 
113 /* The underlying implementation create two more entries for
114  * chaining flow tables. the user should be aware that if he pass
115  * max_num_ftes as 2^N it will result in doubled size flow table
116  */
117 struct mlx5_flow_table *
118 mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
119 				    int prio,
120 				    const char *name,
121 				    int num_flow_table_entries,
122 				    int max_num_groups);
123 
124 struct mlx5_flow_table *
125 mlx5_create_vport_flow_table(struct mlx5_flow_namespace *ns,
126 							 u16 vport,
127 							 int prio,
128 							 const char *name,
129 							 int num_flow_table_entries);
130 
131 struct mlx5_flow_table *
132 mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
133 		       int prio,
134 		       const char *name,
135 		       int num_flow_table_entries);
136 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft);
137 
138 /* inbox should be set with the following values:
139  * start_flow_index
140  * end_flow_index
141  * match_criteria_enable
142  * match_criteria
143  */
144 struct mlx5_flow_group *
145 mlx5_create_flow_group(struct mlx5_flow_table *ft, u32 *in);
146 void mlx5_destroy_flow_group(struct mlx5_flow_group *fg);
147 
148 /* Single destination per rule.
149  * Group ID is implied by the match criteria.
150  */
151 struct mlx5_flow_rule *
152 mlx5_add_flow_rule(struct mlx5_flow_table *ft,
153 		   u8 match_criteria_enable,
154 		   u32 *match_criteria,
155 		   u32 *match_value,
156 		   u32 action,
157 		   u32 flow_tag,
158 		   struct mlx5_flow_destination *dest);
159 void mlx5_del_flow_rule(struct mlx5_flow_rule **);
160 
161 /*The following API is for sniffer*/
162 typedef int (*rule_event_fn)(struct mlx5_flow_rule *rule,
163 			     bool ctx_changed,
164 			     void *client_data,
165 			     void *context);
166 
167 struct mlx5_flow_handler;
168 
169 struct flow_client_priv_data;
170 
171 void mlx5e_sniffer_roce_mode_notify(
172 	struct mlx5_core_dev *mdev,
173 	int action);
174 
175 int mlx5_set_rule_private_data(struct mlx5_flow_rule *rule, struct
176 			       mlx5_flow_handler *handler,  void
177 			       *client_data);
178 
179 struct mlx5_flow_handler *mlx5_register_rule_notifier(struct mlx5_core_dev *dev,
180 						      enum mlx5_flow_namespace_type ns_type,
181 						      rule_event_fn add_cb,
182 						      rule_event_fn del_cb,
183 						      void *context);
184 
185 void mlx5_unregister_rule_notifier(struct mlx5_flow_handler *handler);
186 
187 void mlx5_flow_iterate_existing_rules(struct mlx5_flow_namespace *ns,
188 					     rule_event_fn cb,
189 					     void *context);
190 
191 void mlx5_get_match_criteria(u32 *match_criteria,
192 			     struct mlx5_flow_rule *rule);
193 
194 void mlx5_get_match_value(u32 *match_value,
195 			  struct mlx5_flow_rule *rule);
196 
197 u8 mlx5_get_match_criteria_enable(struct mlx5_flow_rule *rule);
198 
199 struct mlx5_flow_rules_list *get_roce_flow_rules(u8 roce_mode);
200 
201 void mlx5_del_flow_rules_list(struct mlx5_flow_rules_list *rules_list);
202 
203 struct mlx5_flow_rules_list {
204 	struct list_head head;
205 };
206 
207 struct mlx5_flow_rule_node {
208 	struct	list_head list;
209 	u32	match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
210 	u32	match_value[MLX5_ST_SZ_DW(fte_match_param)];
211 	u8	match_criteria_enable;
212 };
213 
214 struct mlx5_core_fs_mask {
215 	u8	match_criteria_enable;
216 	u32	match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
217 };
218 
219 bool fs_match_exact_val(
220 		struct mlx5_core_fs_mask *mask,
221 		void *val1,
222 		void *val2);
223 
224 bool fs_match_exact_mask(
225 		u8 match_criteria_enable1,
226 		u8 match_criteria_enable2,
227 		void *mask1,
228 		void *mask2);
229 /**********end API for sniffer**********/
230 
231 #endif
232