net/octeontx: handle port reconfiguration
[dpdk.git] / drivers / net / mlx5 / mlx5_dr.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2021 NVIDIA CORPORATION. All rights reserved.
3  */
4 #include <rte_flow.h>
5
6 #include "mlx5_defs.h"
7 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
8 #include "mlx5_dr.h"
9
10 /*
11  * The following null stubs are prepared in order not to break the linkage
12  * before the HW steering low-level implementation is added.
13  */
14
15 /* Open a context used for direct rule insertion using hardware steering.
16  * Each context can contain multiple tables of different types.
17  *
18  * @param[in] ibv_ctx
19  *      The ibv context to used for HWS.
20  * @param[in] attr
21  *      Attributes used for context open.
22  * @return pointer to mlx5dr_context on success NULL otherwise.
23  */
24 __rte_weak struct mlx5dr_context *
25 mlx5dr_context_open(void *ibv_ctx,
26                     struct mlx5dr_context_attr *attr)
27 {
28         (void)ibv_ctx;
29         (void)attr;
30         return NULL;
31 }
32
33 /* Close a context used for direct hardware steering.
34  *
35  * @param[in] ctx
36  *      mlx5dr context to close.
37  * @return zero on success non zero otherwise.
38  */
39 __rte_weak int
40 mlx5dr_context_close(struct mlx5dr_context *ctx)
41 {
42         (void)ctx;
43         return 0;
44 }
45
46 /* Create a new direct rule table. Each table can contain multiple matchers.
47  *
48  * @param[in] ctx
49  *      The context in which the new table will be opened.
50  * @param[in] attr
51  *      Attributes used for table creation.
52  * @return pointer to mlx5dr_table on success NULL otherwise.
53  */
54 __rte_weak struct mlx5dr_table *
55 mlx5dr_table_create(struct mlx5dr_context *ctx,
56                     struct mlx5dr_table_attr *attr)
57 {
58         (void)ctx;
59         (void)attr;
60         return NULL;
61 }
62
63 /* Destroy direct rule table.
64  *
65  * @param[in] tbl
66  *      mlx5dr table to destroy.
67  * @return zero on success non zero otherwise.
68  */
69 __rte_weak int mlx5dr_table_destroy(struct mlx5dr_table *tbl)
70 {
71         (void)tbl;
72         return 0;
73 }
74
75 /* Create new match template based on items mask, the match template
76  * will be used for matcher creation.
77  *
78  * @param[in] items
79  *      Describe the mask for template creation
80  * @param[in] flags
81  *      Template creation flags
82  * @return pointer to mlx5dr_match_template on success NULL otherwise
83  */
84 __rte_weak struct mlx5dr_match_template *
85 mlx5dr_match_template_create(const struct rte_flow_item items[],
86                              enum mlx5dr_match_template_flags flags)
87 {
88         (void)items;
89         (void)flags;
90         return NULL;
91 }
92
93 /* Destroy match template.
94  *
95  * @param[in] mt
96  *      Match template to destroy.
97  * @return zero on success non zero otherwise.
98  */
99 __rte_weak int
100 mlx5dr_match_template_destroy(struct mlx5dr_match_template *mt)
101 {
102         (void)mt;
103         return 0;
104 }
105
106 /* Create a new direct rule matcher. Each matcher can contain multiple rules.
107  * Matchers on the table will be processed by priority. Matching fields and
108  * mask are described by the match template. In some cases multiple match
109  * templates can be used on the same matcher.
110  *
111  * @param[in] table
112  *      The table in which the new matcher will be opened.
113  * @param[in] mt
114  *      Array of match templates to be used on matcher.
115  * @param[in] num_of_mt
116  *      Number of match templates in mt array.
117  * @param[in] attr
118  *      Attributes used for matcher creation.
119  * @return pointer to mlx5dr_matcher on success NULL otherwise.
120  */
121 __rte_weak struct mlx5dr_matcher *
122 mlx5dr_matcher_create(struct mlx5dr_table *table __rte_unused,
123                       struct mlx5dr_match_template *mt[] __rte_unused,
124                       uint8_t num_of_mt __rte_unused,
125                       struct mlx5dr_matcher_attr *attr __rte_unused)
126 {
127         return NULL;
128 }
129
130 /* Destroy direct rule matcher.
131  *
132  * @param[in] matcher
133  *      Matcher to destroy.
134  * @return zero on success non zero otherwise.
135  */
136 __rte_weak int
137 mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher __rte_unused)
138 {
139         return 0;
140 }
141
142 /* Enqueue create rule operation.
143  *
144  * @param[in] matcher
145  *      The matcher in which the new rule will be created.
146  * @param[in] mt_idx
147  *      Match template index to create the rule with.
148  * @param[in] items
149  *      The items used for the value matching.
150  * @param[in] rule_actions
151  *      Rule action to be executed on match.
152  * @param[in] num_of_actions
153  *      Number of rule actions.
154  * @param[in] attr
155  *      Rule creation attributes.
156  * @param[in, out] rule_handle
157  *      A valid rule handle. The handle doesn't require any initialization.
158  * @return zero on successful enqueue non zero otherwise.
159  */
160 __rte_weak int
161 mlx5dr_rule_create(struct mlx5dr_matcher *matcher __rte_unused,
162                    uint8_t mt_idx __rte_unused,
163                    const struct rte_flow_item items[] __rte_unused,
164                    struct mlx5dr_rule_action rule_actions[] __rte_unused,
165                    uint8_t num_of_actions __rte_unused,
166                    struct mlx5dr_rule_attr *attr __rte_unused,
167                    struct mlx5dr_rule *rule_handle __rte_unused)
168 {
169         return 0;
170 }
171
172 /* Enqueue destroy rule operation.
173  *
174  * @param[in] rule
175  *      The rule destruction to enqueue.
176  * @param[in] attr
177  *      Rule destruction attributes.
178  * @return zero on successful enqueue non zero otherwise.
179  */
180 __rte_weak int
181 mlx5dr_rule_destroy(struct mlx5dr_rule *rule __rte_unused,
182                     struct mlx5dr_rule_attr *attr __rte_unused)
183 {
184         return 0;
185 }
186
187 /* Create direct rule drop action.
188  *
189  * @param[in] ctx
190  *      The context in which the new action will be created.
191  * @param[in] flags
192  *      Action creation flags. (enum mlx5dr_action_flags)
193  * @return pointer to mlx5dr_action on success NULL otherwise.
194  */
195 __rte_weak struct mlx5dr_action *
196 mlx5dr_action_create_dest_drop(struct mlx5dr_context *ctx __rte_unused,
197                                uint32_t flags __rte_unused)
198 {
199         return NULL;
200 }
201
202 /* Create direct rule default miss action.
203  * Defaults are RX: Drop TX: Wire.
204  *
205  * @param[in] ctx
206  *      The context in which the new action will be created.
207  * @param[in] flags
208  *      Action creation flags. (enum mlx5dr_action_flags)
209  * @return pointer to mlx5dr_action on success NULL otherwise.
210  */
211 __rte_weak struct mlx5dr_action *
212 mlx5dr_action_create_default_miss(struct mlx5dr_context *ctx __rte_unused,
213                                   uint32_t flags __rte_unused)
214 {
215         return NULL;
216 }
217
218 /* Create direct rule goto table action.
219  *
220  * @param[in] ctx
221  *      The context in which the new action will be created.
222  * @param[in] tbl
223  *      Destination table.
224  * @param[in] flags
225  *      Action creation flags. (enum mlx5dr_action_flags)
226  * @return pointer to mlx5dr_action on success NULL otherwise.
227  */
228 __rte_weak struct mlx5dr_action *
229 mlx5dr_action_create_dest_table(struct mlx5dr_context *ctx __rte_unused,
230                                 struct mlx5dr_table *tbl __rte_unused,
231                                 uint32_t flags __rte_unused)
232 {
233         return NULL;
234 }
235
236 /*  Create direct rule goto TIR action.
237  *
238  * @param[in] ctx
239  *      The context in which the new action will be created.
240  * @param[in] obj
241  *      Direct rule TIR devx object.
242  * @param[in] flags
243  *      Action creation flags. (enum mlx5dr_action_flags)
244  * @return pointer to mlx5dr_action on success NULL otherwise.
245  */
246 __rte_weak struct mlx5dr_action *
247 mlx5dr_action_create_dest_tir(struct mlx5dr_context *ctx __rte_unused,
248                               struct mlx5dr_devx_obj *obj __rte_unused,
249                               uint32_t flags __rte_unused)
250 {
251         return NULL;
252 }
253
254 /* Create direct rule TAG action.
255  *
256  * @param[in] ctx
257  *      The context in which the new action will be created.
258  * @param[in] flags
259  *      Action creation flags. (enum mlx5dr_action_flags)
260  * @return pointer to mlx5dr_action on success NULL otherwise.
261  */
262 __rte_weak struct mlx5dr_action *
263 mlx5dr_action_create_tag(struct mlx5dr_context *ctx __rte_unused,
264                          uint32_t flags __rte_unused)
265 {
266         return NULL;
267 }
268
269 /* Create direct rule counter action.
270  *
271  * @param[in] ctx
272  *      The context in which the new action will be created.
273  * @param[in] obj
274  *      Direct rule counter devx object.
275  * @param[in] flags
276  *      Action creation flags. (enum mlx5dr_action_flags)
277  * @return pointer to mlx5dr_action on success NULL otherwise.
278  */
279 __rte_weak struct mlx5dr_action *
280 mlx5dr_action_create_counter(struct mlx5dr_context *ctx,
281                              struct mlx5dr_devx_obj *obj,
282                              uint32_t flags);
283
284 /* Create direct rule reformat action.
285  *
286  * @param[in] ctx
287  *      The context in which the new action will be created.
288  * @param[in] reformat_type
289  *      Type of reformat.
290  * @param[in] data_sz
291  *      Size in bytes of data.
292  * @param[in] inline_data
293  *      Header data array in case of inline action.
294  * @param[in] log_bulk_size
295  *      Number of unique values used with this pattern.
296  * @param[in] flags
297  *      Action creation flags. (enum mlx5dr_action_flags)
298  * @return pointer to mlx5dr_action on success NULL otherwise.
299  */
300 __rte_weak struct mlx5dr_action *
301 mlx5dr_action_create_reformat(struct mlx5dr_context *ctx __rte_unused,
302               enum mlx5dr_action_reformat_type reformat_type __rte_unused,
303                               size_t data_sz __rte_unused,
304                               void *inline_data __rte_unused,
305                               uint32_t log_bulk_size __rte_unused,
306                               uint32_t flags __rte_unused)
307 {
308         return NULL;
309 }
310
311 /* Create direct rule modify header action.
312  *
313  * @param[in] ctx
314  *      The context in which the new action will be created.
315  * @param[in] pattern_sz
316  *      Byte size of the pattern array.
317  * @param[in] pattern
318  *      PRM format modify pattern action array.
319  * @param[in] log_bulk_size
320  *      Number of unique values used with this pattern.
321  * @param[in] flags
322  *      Action creation flags. (enum mlx5dr_action_flags)
323  * @return pointer to mlx5dr_action on success NULL otherwise.
324  */
325 __rte_weak struct mlx5dr_action *
326 mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx,
327                                    size_t pattern_sz,
328                                    rte_be64_t pattern[],
329                                    uint32_t log_bulk_size,
330                                    uint32_t flags);
331
332 /* Destroy direct rule action.
333  *
334  * @param[in] action
335  *      The action to destroy.
336  * @return zero on success non zero otherwise.
337  */
338 __rte_weak int
339 mlx5dr_action_destroy(struct mlx5dr_action *action __rte_unused)
340 {
341         return 0;
342 }
343
344 /* Poll queue for rule creation and deletions completions.
345  *
346  * @param[in] ctx
347  *      The context to which the queue belong to.
348  * @param[in] queue_id
349  *      The id of the queue to poll.
350  * @param[in, out] res
351  *      Completion array.
352  * @param[in] res_nb
353  *      Maximum number of results to return.
354  * @return negative number on failure, the number of completions otherwise.
355  */
356 __rte_weak int
357 mlx5dr_send_queue_poll(struct mlx5dr_context *ctx __rte_unused,
358                        uint16_t queue_id __rte_unused,
359                        struct rte_flow_op_result res[] __rte_unused,
360                        uint32_t res_nb __rte_unused)
361 {
362         return 0;
363 }
364
365 /* Perform an action on the queue
366  *
367  * @param[in] ctx
368  *      The context to which the queue belong to.
369  * @param[in] queue_id
370  *      The id of the queue to perform the action on.
371  * @param[in] actions
372  *      Actions to perform on the queue. (enum mlx5dr_send_queue_actions)
373  * @return zero on success non zero otherwise.
374  */
375 __rte_weak int
376 mlx5dr_send_queue_action(struct mlx5dr_context *ctx __rte_unused,
377                          uint16_t queue_id __rte_unused,
378                          uint32_t actions __rte_unused)
379 {
380         return 0;
381 }
382
383 #endif