net/mlx5: add queue and RSS HW steering action
[dpdk.git] / drivers / net / mlx5 / linux / mlx5_flow_os.h
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
10 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
11 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
12 extern const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops;
13 #endif
14
15 /**
16  * Get OS enforced flow type. MLX5_FLOW_TYPE_MAX means "non enforced type".
17  *
18  * @return
19  *   Flow type (MLX5_FLOW_TYPE_MAX)
20  */
21 static inline enum mlx5_flow_drv_type
22 mlx5_flow_os_get_type(void)
23 {
24         return MLX5_FLOW_TYPE_MAX;
25 }
26
27 /**
28  * Check if item type is supported.
29  *
30  * @param item
31  *   Item type to check.
32  *
33  * @return
34  *   True is this item type is supported, false if not supported.
35  */
36 static inline bool
37 mlx5_flow_os_item_supported(int item __rte_unused)
38 {
39         return true;
40 }
41
42 /**
43  * Check if action type is supported.
44  *
45  * @param action
46  *   Action type to check.
47  *
48  * @return
49  *   True is this action type is supported, false if not supported.
50  */
51 static inline bool
52 mlx5_flow_os_action_supported(int action __rte_unused)
53 {
54         return true;
55 }
56
57 /**
58  * Create flow rule.
59  *
60  * @param[in] matcher
61  *   Pointer to match mask structure.
62  * @param[in] match_value
63  *   Pointer to match value structure.
64  * @param[in] num_actions
65  *   Number of actions in flow rule.
66  * @param[in] actions
67  *   Pointer to array of flow rule actions.
68  * @param[out] flow
69  *   Pointer to a valid flow rule object on success, NULL otherwise.
70  *
71  * @return
72  *   0 on success, or -1 on failure and errno is set.
73  */
74 static inline int
75 mlx5_flow_os_create_flow(void *matcher, void *match_value,
76                          size_t num_actions, void *actions[], void **flow)
77 {
78         *flow = mlx5_glue->dv_create_flow(matcher, match_value,
79                                           num_actions, actions);
80         return (*flow) ? 0 : -1;
81 }
82
83 /**
84  * Destroy flow rule.
85  *
86  * @param[in] drv_flow_ptr
87  *   Pointer to flow rule object.
88  *
89  * @return
90  *   0 on success, or the value of errno on failure.
91  */
92 static inline int
93 mlx5_flow_os_destroy_flow(void *drv_flow_ptr)
94 {
95         return mlx5_glue->dv_destroy_flow(drv_flow_ptr);
96 }
97
98 /**
99  * Create flow table.
100  *
101  * @param[in] domain
102  *   Pointer to relevant domain.
103  * @param[in] table_id
104  *   Table ID.
105  * @param[out] table
106  *   Pointer to a valid flow table object on success, NULL otherwise.
107  *
108  * @return
109  *   0 on success, or -1 on failure and errno is set.
110  */
111 static inline int
112 mlx5_flow_os_create_flow_tbl(void *domain, uint32_t table_id, void **table)
113 {
114         *table = mlx5_glue->dr_create_flow_tbl(domain, table_id);
115         return (*table) ? 0 : -1;
116 }
117
118 /**
119  * Destroy flow table.
120  *
121  * @param[in] table
122  *   Pointer to table object to destroy.
123  *
124  * @return
125  *   0 on success, or the value of errno on failure.
126  */
127 static inline int
128 mlx5_flow_os_destroy_flow_tbl(void *table)
129 {
130         return mlx5_glue->dr_destroy_flow_tbl(table);
131 }
132
133 /**
134  * Create flow matcher in a flow table.
135  *
136  * @param[in] ctx
137  *   Pointer to relevant device context.
138  * @param[in] attr
139  *   Pointer to relevant attributes.
140  * @param[in] table
141  *   Pointer to table object.
142  * @param[out] matcher
143  *   Pointer to a valid flow matcher object on success, NULL otherwise.
144  *
145  * @return
146  *   0 on success, or -1 on failure and errno is set.
147  */
148 static inline int
149 mlx5_flow_os_create_flow_matcher(void *ctx, void *attr, void *table,
150                                  void **matcher)
151 {
152         *matcher = mlx5_glue->dv_create_flow_matcher(ctx, attr, table);
153         return (*matcher) ? 0 : -1;
154 }
155
156 /**
157  * Destroy flow matcher.
158  *
159  * @param[in] matcher
160  *   Pointer to matcher object to destroy.
161  *
162  * @return
163  *   0 on success, or the value of errno on failure.
164  */
165 static inline int
166 mlx5_flow_os_destroy_flow_matcher(void *matcher)
167 {
168         return mlx5_glue->dv_destroy_flow_matcher(matcher);
169 }
170
171 /**
172  * Create flow action: packet reformat.
173  *
174  * @param[in] ctx
175  *   Pointer to relevant device context.
176  * @param[in] domain
177  *   Pointer to domain handler.
178  * @param[in] resource
179  *   Pointer to action data resource.
180  * @param[out] action
181  *   Pointer to a valid action on success, NULL otherwise.
182  *
183  *
184  * @return
185  *   0 on success, or -1 on failure and errno is set.
186  */
187 static inline int
188 mlx5_flow_os_create_flow_action_packet_reformat(void *ctx, void *domain,
189                                                 void *resource, void **action)
190 {
191         struct mlx5_flow_dv_encap_decap_resource *res =
192                         (struct mlx5_flow_dv_encap_decap_resource *)resource;
193
194         *action = mlx5_glue->dv_create_flow_action_packet_reformat
195                                         (ctx, res->reformat_type, res->ft_type,
196                                          domain, res->flags, res->size,
197                                          (res->size ? res->buf : NULL));
198         return (*action) ? 0 : -1;
199 }
200
201 /**
202  * Create flow action: modify header.
203  *
204  * @param[in] ctx
205  *   Pointer to relevant device context.
206  * @param[in] domain
207  *   Pointer to domain handler.
208  * @param[in] resource
209  *   Pointer to action data resource.
210  * @param[in] actions_len
211  *   Total length of actions data in resource.
212  * @param[out] action
213  *   Pointer to a valid action on success, NULL otherwise.
214  *
215  *
216  * @return
217  *   0 on success, or -1 on failure and errno is set.
218  */
219 static inline int
220 mlx5_flow_os_create_flow_action_modify_header(void *ctx, void *domain,
221                                               void *resource,
222                                               uint32_t actions_len,
223                                               void **action)
224 {
225         struct mlx5_flow_dv_modify_hdr_resource *res =
226                         (struct mlx5_flow_dv_modify_hdr_resource *)resource;
227
228         *action = mlx5_glue->dv_create_flow_action_modify_header
229                                         (ctx, res->ft_type, domain, res->root ?
230                                          MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL : 0,
231                                          actions_len, (uint64_t *)res->actions);
232         return (*action) ? 0 : -1;
233 }
234
235 /**
236  * Create flow action: destination flow table.
237  *
238  * @param[in] tbl_obj
239  *   Pointer to destination table object.
240  * @param[out] action
241  *   Pointer to a valid action on success, NULL otherwise.
242  *
243  * @return
244  *   0 on success, or -1 on failure and errno is set.
245  */
246 static inline int
247 mlx5_flow_os_create_flow_action_dest_flow_tbl(void *tbl_obj, void **action)
248 {
249         *action = mlx5_glue->dr_create_flow_action_dest_flow_tbl(tbl_obj);
250         return (*action) ? 0 : -1;
251 }
252
253 /**
254  * Create flow action: destination port.
255  *
256  * @param[in] domain
257  *   Pointer to domain handler.
258  * @param[in] port_id
259  *   Destination port ID.
260  * @param[out] action
261  *   Pointer to a valid action on success, NULL otherwise.
262  *
263  * @return
264  *   0 on success, or -1 on failure and errno is set.
265  */
266 static inline int
267 mlx5_flow_os_create_flow_action_dest_port(void *domain, uint32_t port_id,
268                                           void **action)
269 {
270         /*
271          * Depending on rdma_core version the glue routine calls
272          * either mlx5dv_dr_action_create_dest_ib_port(domain, dev_port)
273          * or mlx5dv_dr_action_create_dest_vport(domain, vport_id).
274          */
275         *action = mlx5_glue->dr_create_flow_action_dest_port(domain, port_id);
276         return (*action) ? 0 : -1;
277 }
278
279 /**
280  * Create flow action: push vlan.
281  *
282  * @param[in] domain
283  *   Pointer to domain handler.
284  * @param[in] vlan_tag
285  *   VLAN tag value.
286  * @param[out] action
287  *   Pointer to a valid action on success, NULL otherwise.
288  *
289  * @return
290  *   0 on success, or -1 on failure and errno is set.
291  */
292 static inline int
293 mlx5_flow_os_create_flow_action_push_vlan(void *domain, rte_be32_t vlan_tag,
294                                           void **action)
295 {
296         *action = mlx5_glue->dr_create_flow_action_push_vlan(domain, vlan_tag);
297         return (*action) ? 0 : -1;
298 }
299
300 /**
301  * Create flow action: count.
302  *
303  * @param[in] cnt_obj
304  *   Pointer to DevX counter object.
305  * @param[in] offset
306  *   Offset of counter in array.
307  * @param[out] action
308  *   Pointer to a valid action on success, NULL otherwise.
309  *
310  * @return
311  *   0 on success, or -1 on failure and errno is set.
312  */
313 static inline int
314 mlx5_flow_os_create_flow_action_count(void *cnt_obj, uint16_t offset,
315                                       void **action)
316 {
317         *action = mlx5_glue->dv_create_flow_action_counter(cnt_obj, offset);
318         return (*action) ? 0 : -1;
319 }
320
321 /**
322  * Create flow action: tag.
323  *
324  * @param[in] tag
325  *   Tag value.
326  * @param[out] action
327  *   Pointer to a valid action on success, NULL otherwise.
328  *
329  * @return
330  *   0 on success, or -1 on failure and errno is set.
331  */
332 static inline int
333 mlx5_flow_os_create_flow_action_tag(uint32_t tag, void **action)
334 {
335         *action = mlx5_glue->dv_create_flow_action_tag(tag);
336         return (*action) ? 0 : -1;
337 }
338
339 /**
340  * Create flow action: drop.
341  *
342  * @param[out] action
343  *   Pointer to a valid action on success, NULL otherwise.
344  *
345  * @return
346  *   0 on success, or -1 on failure and errno is set.
347  */
348 static inline int
349 mlx5_flow_os_create_flow_action_drop(void **action)
350 {
351         *action = mlx5_glue->dr_create_flow_action_drop();
352         return (*action) ? 0 : -1;
353 }
354
355 /**
356  * Create flow action: default miss.
357  *
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
365 mlx5_flow_os_create_flow_action_default_miss(void **action)
366 {
367         *action = mlx5_glue->dr_create_flow_action_default_miss();
368         return (*action) ? 0 : -1;
369 }
370
371 /**
372  * Create flow action: dest_devx_tir
373  *
374  * @param[in] tir
375  *   Pointer to DevX tir object
376  * @param[out] action
377  *   Pointer to a valid action on success, NULL otherwise.
378  *
379  * @return
380  *   0 on success, or -1 on failure and errno is set.
381  */
382 static inline int
383 mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir,
384                                               void **action)
385 {
386 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
387         *action = mlx5_glue->dv_create_flow_action_dest_devx_tir(tir->obj);
388         return (*action) ? 0 : -1;
389 #else
390         /* If no DV support - skip the operation and return success */
391         RTE_SET_USED(tir);
392         *action = 0;
393         return 0;
394 #endif
395 }
396
397 /**
398  * Create flow action: sampler
399  *
400  * @param[in] attr
401  *   Pointer to sampler attribute
402  * @param[out] action
403  *   Pointer to a valid action on success, NULL otherwise.
404  *
405  * @return
406  *   0 on success, or -1 on failure and errno is set.
407  */
408 static inline int
409 mlx5_os_flow_dr_create_flow_action_sampler
410                         (struct mlx5dv_dr_flow_sampler_attr *attr,
411                         void **action)
412 {
413         *action = mlx5_glue->dr_create_flow_action_sampler(attr);
414         return (*action) ? 0 : -1;
415 }
416
417 /**
418  * Create flow action: dest_array
419  *
420  * @param[in] domain
421  *   Pointer to relevant domain.
422  * @param[in] num_dest
423  *   Number of destinations array.
424  * @param[in] dests
425  *   Array of destination attributes.
426  * @param[out] action
427  *   Pointer to a valid action on success, NULL otherwise.
428  *
429  * @return
430  *   0 on success, or -1 on failure and errno is set.
431  */
432 static inline int
433 mlx5_os_flow_dr_create_flow_action_dest_array
434                         (void *domain,
435                          size_t num_dest,
436                          struct mlx5dv_dr_action_dest_attr *dests[],
437                          void **action)
438 {
439         *action = mlx5_glue->dr_create_flow_action_dest_array(
440                                                 domain, num_dest, dests);
441         return (*action) ? 0 : -1;
442 }
443
444 /**
445  * Destroy flow action.
446  *
447  * @param[in] action
448  *   Pointer to action object to destroy.
449  *
450  * @return
451  *   0 on success, or the value of errno on failure.
452  */
453 static inline int
454 mlx5_flow_os_destroy_flow_action(void *action)
455 {
456         return mlx5_glue->destroy_flow_action(action);
457 }
458
459 /**
460  * OS wrapper over Verbs API.
461  * Adjust flow priority based on the highest layer and the request priority.
462  *
463  * @param[in] dev
464  *    Pointer to the Ethernet device structure.
465  * @param[in] priority
466  *    The rule base priority.
467  * @param[in] subpriority
468  *    The priority based on the items.
469  *
470  * @return
471  *    The new priority.
472  */
473 static inline uint32_t
474 mlx5_os_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
475                           uint32_t subpriority)
476 {
477         return mlx5_flow_adjust_priority(dev, priority, subpriority);
478 }
479
480 static inline int
481 mlx5_os_flow_dr_sync_domain(void *domain, uint32_t flags)
482 {
483         return mlx5_glue->dr_sync_domain(domain, flags);
484 }
485 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */