1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
3 */
4
5 #ifndef RTE_PMD_MLX5_FLOW_OS_H_
6 #define RTE_PMD_MLX5_FLOW_OS_H_
7
8 #include "mlx5_flow.h"
9 #include "mlx5_malloc.h"
10
11 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
12 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
13 extern const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops;
14 #endif
15
16 /**
17 * Get OS enforced flow type. MLX5_FLOW_TYPE_MAX means "non enforced type".
18 *
19 * @return
20 * Flow type (MLX5_FLOW_TYPE_MAX)
21 */
22 static inline enum mlx5_flow_drv_type
mlx5_flow_os_get_type(void)23 mlx5_flow_os_get_type(void)
24 {
25 return MLX5_FLOW_TYPE_DV;
26 }
27
28 /**
29 * Check if item type is supported.
30 *
31 * @param item
32 * Item type to check.
33 *
34 * @return
35 * True is this item type is supported, false if not supported.
36 */
37 static inline bool
mlx5_flow_os_item_supported(int item)38 mlx5_flow_os_item_supported(int item)
39 {
40 switch (item) {
41 case RTE_FLOW_ITEM_TYPE_END:
42 case RTE_FLOW_ITEM_TYPE_VOID:
43 case RTE_FLOW_ITEM_TYPE_ETH:
44 case RTE_FLOW_ITEM_TYPE_IPV4:
45 case RTE_FLOW_ITEM_TYPE_UDP:
46 case RTE_FLOW_ITEM_TYPE_TCP:
47 case RTE_FLOW_ITEM_TYPE_IPV6:
48 case RTE_FLOW_ITEM_TYPE_VLAN:
49 case RTE_FLOW_ITEM_TYPE_ESP:
50 return true;
51 default:
52 return false;
53 }
54 }
55
56 /**
57 * Check if action type is supported.
58 *
59 * @param action
60 * Action type to check.
61 *
62 * @return
63 * True is this action type is supported, false if not supported.
64 */
65 static inline bool
mlx5_flow_os_action_supported(int action)66 mlx5_flow_os_action_supported(int action)
67 {
68 switch (action) {
69 case RTE_FLOW_ACTION_TYPE_END:
70 case RTE_FLOW_ACTION_TYPE_VOID:
71 case RTE_FLOW_ACTION_TYPE_QUEUE:
72 case RTE_FLOW_ACTION_TYPE_RSS:
73 return true;
74 default:
75 return false;
76 }
77 }
78
79 /**
80 * Create flow table.
81 *
82 * @param[in] domain
83 * Pointer to relevant domain.
84 * @param[in] table_id
85 * Table ID.
86 * @param[out] table
87 * NULL (no table object required)
88 *
89 * @return
90 * 0 if table_id is 0, negative value otherwise and errno is set.
91 */
92 static inline int
mlx5_flow_os_create_flow_tbl(void * domain,uint32_t table_id,void ** table)93 mlx5_flow_os_create_flow_tbl(void *domain, uint32_t table_id, void **table)
94 {
95 RTE_SET_USED(domain);
96 *table = NULL;
97 if (table_id) {
98 rte_errno = ENOTSUP;
99 return -rte_errno;
100 }
101 return 0;
102 }
103
104 /**
105 * Destroy flow table.
106 *
107 * @param table
108 * Pointer to table to destroy.
109 *
110 * @return
111 * 0 on success (silently ignored).
112 */
113 static inline int
mlx5_flow_os_destroy_flow_tbl(void * table)114 mlx5_flow_os_destroy_flow_tbl(void *table)
115 {
116 RTE_SET_USED(table);
117 /* Silently ignore */
118 return 0;
119 }
120
121 /**
122 * Create flow action: packet reformat.
123 *
124 * @param[in] ctx
125 * Pointer to relevant device context.
126 * @param[in] domain
127 * Pointer to domain handler.
128 * @param[in] resource
129 * Pointer to action data resource.
130 * @param[out] action
131 * Pointer to a valid action on success, NULL otherwise.
132 *
133 *
134 * @return
135 * 0 on success, or negative value on failure and errno is set.
136 */
137 static inline int
mlx5_flow_os_create_flow_action_packet_reformat(void * ctx,void * domain,void * resource,void ** action)138 mlx5_flow_os_create_flow_action_packet_reformat(void *ctx, void *domain,
139 void *resource, void **action)
140 {
141 RTE_SET_USED(ctx);
142 RTE_SET_USED(domain);
143 RTE_SET_USED(resource);
144 RTE_SET_USED(action);
145 rte_errno = ENOTSUP;
146 return -rte_errno;
147 }
148
149 /**
150 * Create flow action: modify header.
151 *
152 * @param[in] ctx
153 * Pointer to relevant device context.
154 * @param[in] domain
155 * Pointer to domain handler.
156 * @param[in] resource
157 * Pointer to action data resource.
158 * @param[in] actions_len
159 * Total length of actions data in resource.
160 * @param[out] action
161 * Pointer to a valid action on success, NULL otherwise.
162 *
163 *
164 * @return
165 * 0 on success, or -1 on failure and errno is set.
166 */
167 static inline int
mlx5_flow_os_create_flow_action_modify_header(void * ctx,void * domain,void * resource,uint32_t actions_len,void ** action)168 mlx5_flow_os_create_flow_action_modify_header(void *ctx,
169 void *domain,
170 void *resource,
171 uint32_t actions_len,
172 void **action)
173 {
174 RTE_SET_USED(ctx);
175 RTE_SET_USED(domain);
176 RTE_SET_USED(resource);
177 RTE_SET_USED(actions_len);
178 RTE_SET_USED(action);
179 rte_errno = ENOTSUP;
180 return -rte_errno;
181 }
182
183 /**
184 * Create flow action: destination flow table.
185 *
186 * @param[in] tbl_obj
187 * Pointer to destination table object.
188 * @param[out] action
189 * Pointer to a valid action on success, NULL otherwise.
190 *
191 * @return
192 * 0 on success, or negative value on failure and errno is set.
193 */
194 static inline int
mlx5_flow_os_create_flow_action_dest_flow_tbl(void * tbl_obj,void ** action)195 mlx5_flow_os_create_flow_action_dest_flow_tbl(void *tbl_obj, void **action)
196 {
197 RTE_SET_USED(tbl_obj);
198 RTE_SET_USED(action);
199 rte_errno = ENOTSUP;
200 return -rte_errno;
201 }
202
203 /**
204 * Create flow action: destination port.
205 *
206 * @param[in] domain
207 * Pointer to domain handler.
208 * @param[in] port_id
209 * Destination port ID.
210 * @param[out] action
211 * Pointer to a valid action on success, NULL otherwise.
212 *
213 * @return
214 * 0 on success, or negative value on failure and errno is set.
215 */
216 static inline int
mlx5_flow_os_create_flow_action_dest_port(void * domain,uint32_t port_id,void ** action)217 mlx5_flow_os_create_flow_action_dest_port(void *domain, uint32_t port_id,
218 void **action)
219 {
220 RTE_SET_USED(domain);
221 RTE_SET_USED(port_id);
222 *action = NULL;
223 rte_errno = ENOTSUP;
224 return -rte_errno;
225 }
226
227 /**
228 * Create flow action: push vlan.
229 *
230 * @param[in] domain
231 * Pointer to domain handler.
232 * @param[in] vlan_tag
233 * VLAN tag value.
234 * @param[out] action
235 * Pointer to a valid action on success, NULL otherwise.
236 *
237 * @return
238 * 0 on success, or negative value on failure and errno is set.
239 */
240 static inline int
mlx5_flow_os_create_flow_action_push_vlan(void * domain,rte_be32_t vlan_tag,void ** action)241 mlx5_flow_os_create_flow_action_push_vlan(void *domain, rte_be32_t vlan_tag,
242 void **action)
243 {
244 RTE_SET_USED(domain);
245 RTE_SET_USED(vlan_tag);
246 *action = NULL;
247 rte_errno = ENOTSUP;
248 return -rte_errno;
249 }
250
251 /**
252 * Create flow action: count.
253 *
254 * @param[in] cnt_obj
255 * Pointer to DevX counter object.
256 * @param[in] offset
257 * Offset of counter in array.
258 * @param[out] action
259 * Pointer to a valid action on success, NULL otherwise.
260 *
261 * @return
262 * 0 on success, or negative value on failure and errno is set.
263 */
264 static inline int
mlx5_flow_os_create_flow_action_count(void * cnt_obj,uint16_t offset,void ** action)265 mlx5_flow_os_create_flow_action_count(void *cnt_obj, uint16_t offset,
266 void **action)
267 {
268 RTE_SET_USED(cnt_obj);
269 RTE_SET_USED(offset);
270 *action = NULL;
271 rte_errno = ENOTSUP;
272 return -rte_errno;
273 }
274
275 /**
276 * Create flow action: tag.
277 *
278 * @param[in] tag
279 * Tag value.
280 * @param[out] action
281 * Pointer to a valid action on success, NULL otherwise.
282 *
283 * @return
284 * 0 on success, or negative value on failure and errno is set.
285 */
286 static inline int
mlx5_flow_os_create_flow_action_tag(uint32_t tag,void ** action)287 mlx5_flow_os_create_flow_action_tag(uint32_t tag, void **action)
288 {
289 RTE_SET_USED(tag);
290 *action = NULL;
291 rte_errno = ENOTSUP;
292 return -rte_errno;
293 }
294
295 /**
296 * Create flow action: drop.
297 *
298 * @param[out] action
299 * Pointer to a valid action on success, NULL otherwise.
300 *
301 * @return
302 * 0 on success, or negative value on failure and errno is set.
303 */
304 static inline int
mlx5_flow_os_create_flow_action_drop(void ** action)305 mlx5_flow_os_create_flow_action_drop(void **action)
306 {
307 *action = NULL;
308 rte_errno = ENOTSUP;
309 return -rte_errno;
310 }
311
312 /**
313 * Create flow action: default miss.
314 *
315 * @param[out] action
316 * NULL action pointer.
317 *
318 * @return
319 * 0 as success.
320 */
321 static inline int
mlx5_flow_os_create_flow_action_default_miss(void ** action)322 mlx5_flow_os_create_flow_action_default_miss(void **action)
323 {
324 *action = 0;
325 /* Silently ignore */
326 return 0;
327 }
328
329 /**
330 * Create flow action: send_to_kernel.
331 *
332 * @param[in] tbl
333 * Pointer to destination root table.
334 * @param[in] priority
335 * Priority to which traffic will arrive.
336 * @param[out] action
337 * Pointer to a valid action on success, NULL otherwise.
338 *
339 * @return
340 * 0 on success, or -1 on failure and errno is set.
341 */
342 static inline int
mlx5_flow_os_create_flow_action_send_to_kernel(void * tbl,uint16_t priority,void ** action)343 mlx5_flow_os_create_flow_action_send_to_kernel(void *tbl, uint16_t priority,
344 void **action)
345 {
346 RTE_SET_USED(tbl);
347 RTE_SET_USED(priority);
348 *action = NULL;
349 rte_errno = ENOTSUP;
350 return -rte_errno;
351 }
352
353 /**
354 * Create flow action: sampler
355 *
356 * @param[in] attr
357 * Pointer to sampler attribute
358 * @param[out] action
359 * Pointer to a valid action on success, NULL otherwise.
360 *
361 * @return
362 * 0 on success, or -1 on failure and errno is set.
363 */
364 static inline int
mlx5_os_flow_dr_create_flow_action_sampler(struct mlx5dv_dr_flow_sampler_attr * attr,void ** action)365 mlx5_os_flow_dr_create_flow_action_sampler
366 (struct mlx5dv_dr_flow_sampler_attr *attr,
367 void **action)
368 {
369 RTE_SET_USED(attr);
370 *action = NULL;
371 rte_errno = ENOTSUP;
372 return -rte_errno;
373 }
374
375 /**
376 * Create flow action: dest_array
377 *
378 * @param[in] domain
379 * Pointer to relevant domain.
380 * @param[in] num_dest
381 * Number of destinations array.
382 * @param[in] dests
383 * Array of destination attributes.
384 * @param[out] action
385 * Pointer to a valid action on success, NULL otherwise.
386 *
387 * @return
388 * 0 on success, or -1 on failure and errno is set.
389 */
390 static inline int
mlx5_os_flow_dr_create_flow_action_dest_array(void * domain,size_t num_dest,struct mlx5dv_dr_action_dest_attr * dests[],void ** action)391 mlx5_os_flow_dr_create_flow_action_dest_array
392 (void *domain,
393 size_t num_dest,
394 struct mlx5dv_dr_action_dest_attr *dests[],
395 void **action)
396 {
397 RTE_SET_USED(domain);
398 RTE_SET_USED(num_dest);
399 RTE_SET_USED(dests);
400 *action = NULL;
401 rte_errno = ENOTSUP;
402 return -rte_errno;
403 }
404
405 /**
406 * OS stub for mlx5_flow_adjust_priority() API.
407 * Windows only supports flow priority 0 that cannot be adjusted.
408 *
409 * @param[in] dev
410 * Pointer to the Ethernet device structure.
411 * @param[in] priority
412 * The rule base priority.
413 * @param[in] subpriority
414 * The priority based on the items.
415 *
416 * @return
417 * 0
418 */
419 static inline uint32_t
mlx5_os_flow_adjust_priority(struct rte_eth_dev * dev,int32_t priority,uint32_t subpriority)420 mlx5_os_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
421 uint32_t subpriority)
422 {
423 RTE_SET_USED(dev);
424 RTE_SET_USED(priority);
425 RTE_SET_USED(subpriority);
426 return 0;
427 }
428
429 static inline int
mlx5_os_flow_dr_sync_domain(void * domain,uint32_t flags)430 mlx5_os_flow_dr_sync_domain(void *domain, uint32_t flags)
431 {
432 RTE_SET_USED(domain);
433 RTE_SET_USED(flags);
434 errno = ENOTSUP;
435 return errno;
436 }
437
438 int mlx5_flow_os_validate_flow_attributes(struct rte_eth_dev *dev,
439 const struct rte_flow_attr *attributes,
440 bool external,
441 struct rte_flow_error *error);
442 int mlx5_flow_os_create_flow_matcher(void *ctx,
443 void *attr,
444 void *table,
445 void **matcher);
446 int mlx5_flow_os_destroy_flow_matcher(void *matcher);
447 int mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir,
448 void **action);
449 int mlx5_flow_os_destroy_flow_action(void *action);
450 int mlx5_flow_os_create_flow(void *matcher, void *match_value,
451 size_t num_actions,
452 void *actions[], void **flow);
453 int mlx5_flow_os_destroy_flow(void *drv_flow_ptr);
454
455 /**
456 * Validate ESP item.
457 *
458 * @param[in] item
459 * Item specification.
460 * @param[in] item_flags
461 * Bit-fields that holds the items detected until now.
462 * @param[in] target_protocol
463 * The next protocol in the previous item.
464 * @param[out] error
465 * Pointer to error structure.
466 *
467 * @return
468 * 0 on success, a negative errno value otherwise and rte_errno is set.
469 */
470 int
471 mlx5_flow_os_validate_item_esp(const struct rte_eth_dev *dev,
472 const struct rte_flow_item *item,
473 uint64_t item_flags,
474 uint8_t target_protocol,
475 struct rte_flow_error *error);
476
477 /**
478 * Add per thread workspace to the global list for garbage collection.
479 *
480 * @param[in] ws
481 * Pointer to the flow workspace.
482 */
483 void mlx5_flow_os_workspace_gc_add(struct mlx5_flow_workspace *ws);
484
485 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */
486