xref: /dpdk/lib/ethdev/rte_flow_driver.h (revision 2df20a1d345a5fc0a1b6dc0317d11fc7b1fda7e7)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016 6WIND S.A.
3  * Copyright 2016 Mellanox Technologies, Ltd
4  */
5 
6 #ifndef RTE_FLOW_DRIVER_H_
7 #define RTE_FLOW_DRIVER_H_
8 
9 /**
10  * @file
11  * RTE generic flow API (driver side)
12  *
13  * This file provides implementation helpers for internal use by PMDs, they
14  * are not intended to be exposed to applications and are not subject to ABI
15  * versioning.
16  */
17 
18 #include <stdint.h>
19 
20 #include "rte_ethdev.h"
21 #include "ethdev_driver.h"
22 #include "rte_flow.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /**
29  * Generic flow operations structure implemented and returned by PMDs.
30  *
31  * These callback functions are not supposed to be used by applications
32  * directly, which must rely on the API defined in rte_flow.h.
33  *
34  * Public-facing wrapper functions perform a few consistency checks so that
35  * unimplemented (i.e. NULL) callbacks simply return -ENOTSUP. These
36  * callbacks otherwise only differ by their first argument (with port ID
37  * already resolved to a pointer to struct rte_eth_dev).
38  */
39 struct rte_flow_ops {
40 	/** See rte_flow_validate(). */
41 	int (*validate)
42 		(struct rte_eth_dev *,
43 		 const struct rte_flow_attr *,
44 		 const struct rte_flow_item [],
45 		 const struct rte_flow_action [],
46 		 struct rte_flow_error *);
47 	/** See rte_flow_create(). */
48 	struct rte_flow *(*create)
49 		(struct rte_eth_dev *,
50 		 const struct rte_flow_attr *,
51 		 const struct rte_flow_item [],
52 		 const struct rte_flow_action [],
53 		 struct rte_flow_error *);
54 	/** See rte_flow_destroy(). */
55 	int (*destroy)
56 		(struct rte_eth_dev *,
57 		 struct rte_flow *,
58 		 struct rte_flow_error *);
59 	/** See rte_flow_flush(). */
60 	int (*flush)
61 		(struct rte_eth_dev *,
62 		 struct rte_flow_error *);
63 	/** See rte_flow_query(). */
64 	int (*query)
65 		(struct rte_eth_dev *,
66 		 struct rte_flow *,
67 		 const struct rte_flow_action *,
68 		 void *,
69 		 struct rte_flow_error *);
70 	/** See rte_flow_isolate(). */
71 	int (*isolate)
72 		(struct rte_eth_dev *,
73 		 int,
74 		 struct rte_flow_error *);
75 	/** See rte_flow_dev_dump(). */
76 	int (*dev_dump)
77 		(struct rte_eth_dev *dev,
78 		 struct rte_flow *flow,
79 		 FILE *file,
80 		 struct rte_flow_error *error);
81 	/** See rte_flow_get_aged_flows() */
82 	int (*get_aged_flows)
83 		(struct rte_eth_dev *dev,
84 		 void **context,
85 		 uint32_t nb_contexts,
86 		 struct rte_flow_error *err);
87 	/** See rte_flow_get_q_aged_flows() */
88 	int (*get_q_aged_flows)
89 		(struct rte_eth_dev *dev,
90 		 uint32_t queue_id,
91 		 void **contexts,
92 		 uint32_t nb_contexts,
93 		 struct rte_flow_error *error);
94 	/** See rte_flow_action_handle_create() */
95 	struct rte_flow_action_handle *(*action_handle_create)
96 		(struct rte_eth_dev *dev,
97 		 const struct rte_flow_indir_action_conf *conf,
98 		 const struct rte_flow_action *action,
99 		 struct rte_flow_error *error);
100 	/** See rte_flow_action_handle_destroy() */
101 	int (*action_handle_destroy)
102 		(struct rte_eth_dev *dev,
103 		 struct rte_flow_action_handle *handle,
104 		 struct rte_flow_error *error);
105 	/** See rte_flow_action_handle_update() */
106 	int (*action_handle_update)
107 		(struct rte_eth_dev *dev,
108 		 struct rte_flow_action_handle *handle,
109 		 const void *update,
110 		 struct rte_flow_error *error);
111 	/** See rte_flow_action_handle_query() */
112 	int (*action_handle_query)
113 		(struct rte_eth_dev *dev,
114 		 const struct rte_flow_action_handle *handle,
115 		 void *data,
116 		 struct rte_flow_error *error);
117 	/** See rte_flow_action_handle_query_update() */
118 	int (*action_handle_query_update)
119 		(struct rte_eth_dev *dev,
120 		 struct rte_flow_action_handle *handle,
121 		 const void *update, void *query,
122 		 enum rte_flow_query_update_mode qu_mode,
123 		 struct rte_flow_error *error);
124 	/** @see rte_flow_action_list_handle_create() */
125 	struct rte_flow_action_list_handle *(*action_list_handle_create)
126 		(struct rte_eth_dev *dev,
127 		 const struct rte_flow_indir_action_conf *conf,
128 		 const struct rte_flow_action actions[],
129 		 struct rte_flow_error *error);
130 	/** @see rte_flow_action_list_handle_destroy() */
131 	int (*action_list_handle_destroy)
132 		(struct rte_eth_dev *dev,
133 		 struct rte_flow_action_list_handle *handle,
134 		 struct rte_flow_error *error);
135 	/** See rte_flow_tunnel_decap_set() */
136 	int (*tunnel_decap_set)
137 		(struct rte_eth_dev *dev,
138 		 struct rte_flow_tunnel *tunnel,
139 		 struct rte_flow_action **pmd_actions,
140 		 uint32_t *num_of_actions,
141 		 struct rte_flow_error *err);
142 	/** See rte_flow_tunnel_match() */
143 	int (*tunnel_match)
144 		(struct rte_eth_dev *dev,
145 		 struct rte_flow_tunnel *tunnel,
146 		 struct rte_flow_item **pmd_items,
147 		 uint32_t *num_of_items,
148 		 struct rte_flow_error *err);
149 	/** See rte_flow_get_rte_flow_restore_info() */
150 	int (*get_restore_info)
151 		(struct rte_eth_dev *dev,
152 		 struct rte_mbuf *m,
153 		 struct rte_flow_restore_info *info,
154 		 struct rte_flow_error *err);
155 	/** See rte_flow_action_tunnel_decap_release() */
156 	int (*tunnel_action_decap_release)
157 		(struct rte_eth_dev *dev,
158 		 struct rte_flow_action *pmd_actions,
159 		 uint32_t num_of_actions,
160 		 struct rte_flow_error *err);
161 	/** See rte_flow_item_release() */
162 	int (*tunnel_item_release)
163 		(struct rte_eth_dev *dev,
164 		 struct rte_flow_item *pmd_items,
165 		 uint32_t num_of_items,
166 		 struct rte_flow_error *err);
167 	/** See rte_flow_pick_transfer_proxy() */
168 	int (*pick_transfer_proxy)
169 		(struct rte_eth_dev *dev,
170 		 uint16_t *proxy_port_id,
171 		 struct rte_flow_error *error);
172 	struct rte_flow_item_flex_handle *(*flex_item_create)
173 		(struct rte_eth_dev *dev,
174 		 const struct rte_flow_item_flex_conf *conf,
175 		 struct rte_flow_error *error);
176 	int (*flex_item_release)
177 		(struct rte_eth_dev *dev,
178 		 const struct rte_flow_item_flex_handle *handle,
179 		 struct rte_flow_error *error);
180 	/** See rte_flow_info_get() */
181 	int (*info_get)
182 		(struct rte_eth_dev *dev,
183 		 struct rte_flow_port_info *port_info,
184 		 struct rte_flow_queue_info *queue_info,
185 		 struct rte_flow_error *err);
186 	/** See rte_flow_configure() */
187 	int (*configure)
188 		(struct rte_eth_dev *dev,
189 		 const struct rte_flow_port_attr *port_attr,
190 		 uint16_t nb_queue,
191 		 const struct rte_flow_queue_attr *queue_attr[],
192 		 struct rte_flow_error *err);
193 	/** See rte_flow_pattern_template_create() */
194 	struct rte_flow_pattern_template *(*pattern_template_create)
195 		(struct rte_eth_dev *dev,
196 		 const struct rte_flow_pattern_template_attr *template_attr,
197 		 const struct rte_flow_item pattern[],
198 		 struct rte_flow_error *err);
199 	/** See rte_flow_pattern_template_destroy() */
200 	int (*pattern_template_destroy)
201 		(struct rte_eth_dev *dev,
202 		 struct rte_flow_pattern_template *pattern_template,
203 		 struct rte_flow_error *err);
204 	/** See rte_flow_actions_template_create() */
205 	struct rte_flow_actions_template *(*actions_template_create)
206 		(struct rte_eth_dev *dev,
207 		 const struct rte_flow_actions_template_attr *template_attr,
208 		 const struct rte_flow_action actions[],
209 		 const struct rte_flow_action masks[],
210 		 struct rte_flow_error *err);
211 	/** See rte_flow_actions_template_destroy() */
212 	int (*actions_template_destroy)
213 		(struct rte_eth_dev *dev,
214 		 struct rte_flow_actions_template *actions_template,
215 		 struct rte_flow_error *err);
216 	/** See rte_flow_template_table_create() */
217 	struct rte_flow_template_table *(*template_table_create)
218 		(struct rte_eth_dev *dev,
219 		 const struct rte_flow_template_table_attr *table_attr,
220 		 struct rte_flow_pattern_template *pattern_templates[],
221 		 uint8_t nb_pattern_templates,
222 		 struct rte_flow_actions_template *actions_templates[],
223 		 uint8_t nb_actions_templates,
224 		 struct rte_flow_error *err);
225 	/** See rte_flow_template_table_destroy() */
226 	int (*template_table_destroy)
227 		(struct rte_eth_dev *dev,
228 		 struct rte_flow_template_table *template_table,
229 		 struct rte_flow_error *err);
230 	/** See rte_flow_group_set_miss_actions() */
231 	int (*group_set_miss_actions)
232 		(struct rte_eth_dev *dev,
233 		 uint32_t group_id,
234 		 const struct rte_flow_group_attr *attr,
235 		 const struct rte_flow_action actions[],
236 		 struct rte_flow_error *err);
237 	/** See rte_flow_async_create() */
238 	struct rte_flow *(*async_create)
239 		(struct rte_eth_dev *dev,
240 		 uint32_t queue_id,
241 		 const struct rte_flow_op_attr *op_attr,
242 		 struct rte_flow_template_table *template_table,
243 		 const struct rte_flow_item pattern[],
244 		 uint8_t pattern_template_index,
245 		 const struct rte_flow_action actions[],
246 		 uint8_t actions_template_index,
247 		 void *user_data,
248 		 struct rte_flow_error *err);
249 	/** See rte_flow_async_create_by_index() */
250 	struct rte_flow *(*async_create_by_index)
251 		(struct rte_eth_dev *dev,
252 		 uint32_t queue_id,
253 		 const struct rte_flow_op_attr *op_attr,
254 		 struct rte_flow_template_table *template_table,
255 		 uint32_t rule_index,
256 		 const struct rte_flow_action actions[],
257 		 uint8_t actions_template_index,
258 		 void *user_data,
259 		 struct rte_flow_error *err);
260 	/** See rte_flow_async_destroy() */
261 	int (*async_destroy)
262 		(struct rte_eth_dev *dev,
263 		 uint32_t queue_id,
264 		 const struct rte_flow_op_attr *op_attr,
265 		 struct rte_flow *flow,
266 		 void *user_data,
267 		 struct rte_flow_error *err);
268 	/** See rte_flow_push() */
269 	int (*push)
270 		(struct rte_eth_dev *dev,
271 		 uint32_t queue_id,
272 		 struct rte_flow_error *err);
273 	/** See rte_flow_pull() */
274 	int (*pull)
275 		(struct rte_eth_dev *dev,
276 		 uint32_t queue_id,
277 		 struct rte_flow_op_result res[],
278 		 uint16_t n_res,
279 		 struct rte_flow_error *error);
280 	/** See rte_flow_async_action_handle_create() */
281 	struct rte_flow_action_handle *(*async_action_handle_create)
282 		(struct rte_eth_dev *dev,
283 		 uint32_t queue_id,
284 		 const struct rte_flow_op_attr *op_attr,
285 		 const struct rte_flow_indir_action_conf *indir_action_conf,
286 		 const struct rte_flow_action *action,
287 		 void *user_data,
288 		 struct rte_flow_error *err);
289 	/** See rte_flow_async_action_handle_destroy() */
290 	int (*async_action_handle_destroy)
291 		(struct rte_eth_dev *dev,
292 		 uint32_t queue_id,
293 		 const struct rte_flow_op_attr *op_attr,
294 		 struct rte_flow_action_handle *action_handle,
295 		 void *user_data,
296 		 struct rte_flow_error *error);
297 	/** See rte_flow_async_action_handle_update() */
298 	int (*async_action_handle_update)
299 		(struct rte_eth_dev *dev,
300 		 uint32_t queue_id,
301 		 const struct rte_flow_op_attr *op_attr,
302 		 struct rte_flow_action_handle *action_handle,
303 		 const void *update,
304 		 void *user_data,
305 		 struct rte_flow_error *error);
306 	/** See rte_flow_async_action_handle_query() */
307 	int (*async_action_handle_query)
308 		(struct rte_eth_dev *dev,
309 		 uint32_t queue_id,
310 		 const struct rte_flow_op_attr *op_attr,
311 		 const struct rte_flow_action_handle *action_handle,
312 		 void *data,
313 		 void *user_data,
314 		 struct rte_flow_error *error);
315 	/** See rte_flow_async_action_handle_query_update */
316 	int (*async_action_handle_query_update)
317 		(struct rte_eth_dev *dev, uint32_t queue_id,
318 		 const struct rte_flow_op_attr *op_attr,
319 		 struct rte_flow_action_handle *action_handle,
320 		 const void *update, void *query,
321 		 enum rte_flow_query_update_mode qu_mode,
322 		 void *user_data, struct rte_flow_error *error);
323 	/** See rte_flow_actions_update(). */
324 	int (*actions_update)
325 		(struct rte_eth_dev *dev,
326 		 struct rte_flow *flow,
327 		 const struct rte_flow_action actions[],
328 		 struct rte_flow_error *error);
329 	/** See rte_flow_async_actions_update() */
330 	int (*async_actions_update)
331 		(struct rte_eth_dev *dev,
332 		 uint32_t queue_id,
333 		 const struct rte_flow_op_attr *op_attr,
334 		 struct rte_flow *flow,
335 		 const struct rte_flow_action actions[],
336 		 uint8_t actions_template_index,
337 		 void *user_data,
338 		 struct rte_flow_error *error);
339 	/** @see rte_flow_async_action_list_handle_create() */
340 	struct rte_flow_action_list_handle *
341 	(*async_action_list_handle_create)
342 		(struct rte_eth_dev *dev, uint32_t queue_id,
343 		 const struct rte_flow_op_attr *attr,
344 		 const struct rte_flow_indir_action_conf *conf,
345 		 const struct rte_flow_action *actions,
346 		 void *user_data, struct rte_flow_error *error);
347 	/** @see rte_flow_async_action_list_handle_destroy() */
348 	int (*async_action_list_handle_destroy)
349 		(struct rte_eth_dev *dev, uint32_t queue_id,
350 		 const struct rte_flow_op_attr *op_attr,
351 		 struct rte_flow_action_list_handle *action_handle,
352 		 void *user_data, struct rte_flow_error *error);
353 	/** @see rte_flow_action_list_handle_query_update() */
354 	int (*action_list_handle_query_update)
355 		(struct rte_eth_dev *dev,
356 		 const struct rte_flow_action_list_handle *handle,
357 		 const void **update, void **query,
358 		 enum rte_flow_query_update_mode mode,
359 		 struct rte_flow_error *error);
360 	/** @see rte_flow_async_action_list_handle_query_update() */
361 	int (*async_action_list_handle_query_update)
362 		(struct rte_eth_dev *dev, uint32_t queue_id,
363 		 const struct rte_flow_op_attr *attr,
364 		 const struct rte_flow_action_list_handle *handle,
365 		 const void **update, void **query,
366 		 enum rte_flow_query_update_mode mode,
367 		 void *user_data, struct rte_flow_error *error);
368 	/** @see rte_flow_calc_table_hash() */
369 	int (*flow_calc_table_hash)
370 		(struct rte_eth_dev *dev, const struct rte_flow_template_table *table,
371 		 const struct rte_flow_item pattern[], uint8_t pattern_template_index,
372 		 uint32_t *hash, struct rte_flow_error *error);
373 };
374 
375 /**
376  * Get generic flow operations structure from a port.
377  *
378  * @param port_id
379  *   Port identifier to query.
380  * @param[out] error
381  *   Pointer to flow error structure.
382  *
383  * @return
384  *   The flow operations structure associated with port_id, NULL in case of
385  *   error, in which case rte_errno is set and the error structure contains
386  *   additional details.
387  */
388 const struct rte_flow_ops *
389 rte_flow_ops_get(uint16_t port_id, struct rte_flow_error *error);
390 
391 /**
392  * Register mbuf dynamic flag for rte_flow_get_restore_info.
393  */
394 int
395 rte_flow_restore_info_dynflag_register(void);
396 
397 #ifdef __cplusplus
398 }
399 #endif
400 
401 #endif /* RTE_FLOW_DRIVER_H_ */
402