xref: /freebsd/sys/dev/mlx5/fs.h (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
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  * $FreeBSD$
26  */
27 
28 #ifndef _MLX5_FS_
29 #define _MLX5_FS_
30 
31 #include <linux/list.h>
32 
33 #include <dev/mlx5/mlx5_ifc.h>
34 #include <dev/mlx5/device.h>
35 #include <dev/mlx5/driver.h>
36 
37 enum {
38 	MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO	= 1 << 16,
39 };
40 
41 /*Flow tag*/
42 enum {
43 	MLX5_FS_DEFAULT_FLOW_TAG  = 0xFFFFFF,
44 	MLX5_FS_ETH_FLOW_TAG  = 0xFFFFFE,
45 	MLX5_FS_SNIFFER_FLOW_TAG  = 0xFFFFFD,
46 };
47 
48 enum {
49 	MLX5_FS_FLOW_TAG_MASK = 0xFFFFFF,
50 };
51 
52 #define FS_MAX_TYPES		10
53 #define FS_MAX_ENTRIES		32000U
54 
55 enum mlx5_flow_namespace_type {
56 	MLX5_FLOW_NAMESPACE_BYPASS,
57 	MLX5_FLOW_NAMESPACE_OFFLOADS,
58 	MLX5_FLOW_NAMESPACE_KERNEL,
59 	MLX5_FLOW_NAMESPACE_LEFTOVERS,
60 	MLX5_FLOW_NAMESPACE_SNIFFER_RX,
61 	MLX5_FLOW_NAMESPACE_SNIFFER_TX,
62 	MLX5_FLOW_NAMESPACE_FDB,
63 	MLX5_FLOW_NAMESPACE_ESW_EGRESS,
64 	MLX5_FLOW_NAMESPACE_ESW_INGRESS,
65 };
66 
67 struct mlx5_flow_table;
68 struct mlx5_flow_group;
69 struct mlx5_flow_rule;
70 struct mlx5_flow_namespace;
71 
72 struct mlx5_flow_spec {
73 	u8   match_criteria_enable;
74 	u32  match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
75 	u32  match_value[MLX5_ST_SZ_DW(fte_match_param)];
76 };
77 
78 struct mlx5_flow_destination {
79 	u32	type;
80 	union {
81 		u32			tir_num;
82 		struct mlx5_flow_table	*ft;
83 		u32			vport_num;
84 	};
85 };
86 
87 #define FT_NAME_STR_SZ 20
88 #define LEFTOVERS_RULE_NUM 2
89 static inline void build_leftovers_ft_param(char *name,
90 	unsigned int *priority,
91 	int *n_ent,
92 	int *n_grp)
93 {
94 	snprintf(name, FT_NAME_STR_SZ, "leftovers");
95 	*priority = 0; /*Priority of leftovers_prio-0*/
96 	*n_ent = LEFTOVERS_RULE_NUM + 1; /*1: star rules*/
97 	*n_grp = LEFTOVERS_RULE_NUM;
98 }
99 
100 static inline bool outer_header_zero(u32 *match_criteria)
101 {
102 	int size = MLX5_ST_SZ_BYTES(fte_match_param);
103 	char *outer_headers_c = MLX5_ADDR_OF(fte_match_param, match_criteria,
104 					     outer_headers);
105 
106 	return outer_headers_c[0] == 0 && !memcmp(outer_headers_c,
107 						  outer_headers_c + 1,
108 						  size - 1);
109 }
110 
111 struct mlx5_flow_namespace *
112 mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
113 			enum mlx5_flow_namespace_type type);
114 
115 /* The underlying implementation create two more entries for
116  * chaining flow tables. the user should be aware that if he pass
117  * max_num_ftes as 2^N it will result in doubled size flow table
118  */
119 struct mlx5_flow_table *
120 mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
121 				    int prio,
122 				    const char *name,
123 				    int num_flow_table_entries,
124 				    int max_num_groups);
125 
126 struct mlx5_flow_table *
127 mlx5_create_vport_flow_table(struct mlx5_flow_namespace *ns,
128 							 u16 vport,
129 							 int prio,
130 							 const char *name,
131 							 int num_flow_table_entries);
132 
133 struct mlx5_flow_table *
134 mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
135 		       int prio,
136 		       const char *name,
137 		       int num_flow_table_entries);
138 int mlx5_destroy_flow_table(struct mlx5_flow_table *ft);
139 
140 /* inbox should be set with the following values:
141  * start_flow_index
142  * end_flow_index
143  * match_criteria_enable
144  * match_criteria
145  */
146 struct mlx5_flow_group *
147 mlx5_create_flow_group(struct mlx5_flow_table *ft, u32 *in);
148 void mlx5_destroy_flow_group(struct mlx5_flow_group *fg);
149 
150 /* Single destination per rule.
151  * Group ID is implied by the match criteria.
152  */
153 struct mlx5_flow_rule *
154 mlx5_add_flow_rule(struct mlx5_flow_table *ft,
155 		   u8 match_criteria_enable,
156 		   u32 *match_criteria,
157 		   u32 *match_value,
158 		   u32 action,
159 		   u32 flow_tag,
160 		   struct mlx5_flow_destination *dest);
161 void mlx5_del_flow_rule(struct mlx5_flow_rule *fr);
162 
163 /*The following API is for sniffer*/
164 typedef int (*rule_event_fn)(struct mlx5_flow_rule *rule,
165 			     bool ctx_changed,
166 			     void *client_data,
167 			     void *context);
168 
169 struct mlx5_flow_handler;
170 
171 struct flow_client_priv_data;
172 
173 void mlx5e_sniffer_roce_mode_notify(
174 	struct mlx5_core_dev *mdev,
175 	int action);
176 
177 int mlx5_set_rule_private_data(struct mlx5_flow_rule *rule, struct
178 			       mlx5_flow_handler *handler,  void
179 			       *client_data);
180 
181 struct mlx5_flow_handler *mlx5_register_rule_notifier(struct mlx5_core_dev *dev,
182 						      enum mlx5_flow_namespace_type ns_type,
183 						      rule_event_fn add_cb,
184 						      rule_event_fn del_cb,
185 						      void *context);
186 
187 void mlx5_unregister_rule_notifier(struct mlx5_flow_handler *handler);
188 
189 void mlx5_flow_iterate_existing_rules(struct mlx5_flow_namespace *ns,
190 					     rule_event_fn cb,
191 					     void *context);
192 
193 void mlx5_get_match_criteria(u32 *match_criteria,
194 			     struct mlx5_flow_rule *rule);
195 
196 void mlx5_get_match_value(u32 *match_value,
197 			  struct mlx5_flow_rule *rule);
198 
199 u8 mlx5_get_match_criteria_enable(struct mlx5_flow_rule *rule);
200 
201 struct mlx5_flow_rules_list *get_roce_flow_rules(u8 roce_mode);
202 
203 void mlx5_del_flow_rules_list(struct mlx5_flow_rules_list *rules_list);
204 
205 struct mlx5_flow_rules_list {
206 	struct list_head head;
207 };
208 
209 struct mlx5_flow_rule_node {
210 	struct	list_head list;
211 	u32	match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
212 	u32	match_value[MLX5_ST_SZ_DW(fte_match_param)];
213 	u8	match_criteria_enable;
214 };
215 
216 struct mlx5_core_fs_mask {
217 	u8	match_criteria_enable;
218 	u32	match_criteria[MLX5_ST_SZ_DW(fte_match_param)];
219 };
220 
221 bool fs_match_exact_val(
222 		struct mlx5_core_fs_mask *mask,
223 		void *val1,
224 		void *val2);
225 
226 bool fs_match_exact_mask(
227 		u8 match_criteria_enable1,
228 		u8 match_criteria_enable2,
229 		void *mask1,
230 		void *mask2);
231 /**********end API for sniffer**********/
232 
233 #endif
234