net/mlx5: add external Rx queue mapping API
[dpdk.git] / drivers / net / mlx5 / windows / 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 #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
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
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                 return true;
50         default:
51                 return false;
52         }
53 }
54
55 /**
56  * Check if action type is supported.
57  *
58  * @param action
59  *   Action type to check.
60  *
61  * @return
62  *   True is this action type is supported, false if not supported.
63  */
64 static inline bool
65 mlx5_flow_os_action_supported(int action)
66 {
67         switch (action) {
68         case RTE_FLOW_ACTION_TYPE_END:
69         case RTE_FLOW_ACTION_TYPE_VOID:
70         case RTE_FLOW_ACTION_TYPE_QUEUE:
71         case RTE_FLOW_ACTION_TYPE_RSS:
72                 return true;
73         default:
74                 return false;
75         }
76 }
77
78 /**
79  * Create flow table.
80  *
81  * @param[in] domain
82  *   Pointer to relevant domain.
83  * @param[in] table_id
84  *   Table ID.
85  * @param[out] table
86  *   NULL (no table object required)
87  *
88  * @return
89  *   0 if table_id is 0, negative value otherwise and errno is set.
90  */
91 static inline int
92 mlx5_flow_os_create_flow_tbl(void *domain, uint32_t table_id, void **table)
93 {
94         RTE_SET_USED(domain);
95         *table = NULL;
96         if (table_id) {
97                 rte_errno = ENOTSUP;
98                 return -rte_errno;
99         }
100         return 0;
101 }
102
103 /**
104  * Destroy flow table.
105  *
106  * @param table
107  *   Pointer to table to destroy.
108  *
109  * @return
110  *   0 on success (silently ignored).
111  */
112 static inline int
113 mlx5_flow_os_destroy_flow_tbl(void *table)
114 {
115         RTE_SET_USED(table);
116         /* Silently ignore */
117         return 0;
118 }
119
120 /**
121  * Create flow action: packet reformat.
122  *
123  * @param[in] ctx
124  *   Pointer to relevant device context.
125  * @param[in] domain
126  *   Pointer to domain handler.
127  * @param[in] resource
128  *   Pointer to action data resource.
129  * @param[out] action
130  *   Pointer to a valid action on success, NULL otherwise.
131  *
132  *
133  * @return
134  *   0 on success, or negative value on failure and errno is set.
135  */
136 static inline int
137 mlx5_flow_os_create_flow_action_packet_reformat(void *ctx, void *domain,
138                                                 void *resource, void **action)
139 {
140         RTE_SET_USED(ctx);
141         RTE_SET_USED(domain);
142         RTE_SET_USED(resource);
143         RTE_SET_USED(action);
144         rte_errno = ENOTSUP;
145         return -rte_errno;
146 }
147
148 /**
149  * Create flow action: modify header.
150  *
151  * @param[in] ctx
152  *   Pointer to relevant device context.
153  * @param[in] domain
154  *   Pointer to domain handler.
155  * @param[in] resource
156  *   Pointer to action data resource.
157  * @param[in] actions_len
158  *   Total length of actions data in resource.
159  * @param[out] action
160  *   Pointer to a valid action on success, NULL otherwise.
161  *
162  *
163  * @return
164  *   0 on success, or -1 on failure and errno is set.
165  */
166 static inline int
167 mlx5_flow_os_create_flow_action_modify_header(void *ctx,
168                                               void *domain,
169                                               void *resource,
170                                               uint32_t actions_len,
171                                               void **action)
172 {
173         RTE_SET_USED(ctx);
174         RTE_SET_USED(domain);
175         RTE_SET_USED(resource);
176         RTE_SET_USED(actions_len);
177         RTE_SET_USED(action);
178         rte_errno = ENOTSUP;
179         return -rte_errno;
180 }
181
182 /**
183  * Create flow action: destination flow table.
184  *
185  * @param[in] tbl_obj
186  *   Pointer to destination table object.
187  * @param[out] action
188  *   Pointer to a valid action on success, NULL otherwise.
189  *
190  * @return
191  *   0 on success, or negative value on failure and errno is set.
192  */
193 static inline int
194 mlx5_flow_os_create_flow_action_dest_flow_tbl(void *tbl_obj, void **action)
195 {
196         RTE_SET_USED(tbl_obj);
197         RTE_SET_USED(action);
198         rte_errno = ENOTSUP;
199         return -rte_errno;
200 }
201
202 /**
203  * Create flow action: destination port.
204  *
205  * @param[in] domain
206  *   Pointer to domain handler.
207  * @param[in] port_id
208  *   Destination port ID.
209  * @param[out] action
210  *   Pointer to a valid action on success, NULL otherwise.
211  *
212  * @return
213  *   0 on success, or negative value on failure and errno is set.
214  */
215 static inline int
216 mlx5_flow_os_create_flow_action_dest_port(void *domain, uint32_t port_id,
217                                           void **action)
218 {
219         RTE_SET_USED(domain);
220         RTE_SET_USED(port_id);
221         *action = NULL;
222         rte_errno = ENOTSUP;
223         return -rte_errno;
224 }
225
226 /**
227  * Create flow action: push vlan.
228  *
229  * @param[in] domain
230  *   Pointer to domain handler.
231  * @param[in] vlan_tag
232  *   VLAN tag value.
233  * @param[out] action
234  *   Pointer to a valid action on success, NULL otherwise.
235  *
236  * @return
237  *   0 on success, or negative value on failure and errno is set.
238  */
239 static inline int
240 mlx5_flow_os_create_flow_action_push_vlan(void *domain, rte_be32_t vlan_tag,
241                                           void **action)
242 {
243         RTE_SET_USED(domain);
244         RTE_SET_USED(vlan_tag);
245         *action = NULL;
246         rte_errno = ENOTSUP;
247         return -rte_errno;
248 }
249
250 /**
251  * Create flow action: count.
252  *
253  * @param[in] cnt_obj
254  *   Pointer to DevX counter object.
255  * @param[in] offset
256  *   Offset of counter in array.
257  * @param[out] action
258  *   Pointer to a valid action on success, NULL otherwise.
259  *
260  * @return
261  *   0 on success, or negative value on failure and errno is set.
262  */
263 static inline int
264 mlx5_flow_os_create_flow_action_count(void *cnt_obj, uint16_t offset,
265                                       void **action)
266 {
267         RTE_SET_USED(cnt_obj);
268         RTE_SET_USED(offset);
269         *action = NULL;
270         rte_errno = ENOTSUP;
271         return -rte_errno;
272 }
273
274 /**
275  * Create flow action: tag.
276  *
277  * @param[in] tag
278  *   Tag value.
279  * @param[out] action
280  *   Pointer to a valid action on success, NULL otherwise.
281  *
282  * @return
283  *   0 on success, or negative value on failure and errno is set.
284  */
285 static inline int
286 mlx5_flow_os_create_flow_action_tag(uint32_t tag, void **action)
287 {
288         RTE_SET_USED(tag);
289         *action = NULL;
290         rte_errno = ENOTSUP;
291         return -rte_errno;
292 }
293
294 /**
295  * Create flow action: drop.
296  *
297  * @param[out] action
298  *   Pointer to a valid action on success, NULL otherwise.
299  *
300  * @return
301  *   0 on success, or negative value on failure and errno is set.
302  */
303 static inline int
304 mlx5_flow_os_create_flow_action_drop(void **action)
305 {
306         *action = NULL;
307         rte_errno = ENOTSUP;
308         return -rte_errno;
309 }
310
311 /**
312  * Create flow action: default miss.
313  *
314  * @param[out] action
315  *   NULL action pointer.
316  *
317  * @return
318  *   0 as success.
319  */
320 static inline int
321 mlx5_flow_os_create_flow_action_default_miss(void **action)
322 {
323         *action = 0;
324         /* Silently ignore */
325         return 0;
326 }
327
328 /**
329  * Create flow action: sampler
330  *
331  * @param[in] attr
332  *   Pointer to sampler attribute
333  * @param[out] action
334  *   Pointer to a valid action on success, NULL otherwise.
335  *
336  * @return
337  *   0 on success, or -1 on failure and errno is set.
338  */
339 static inline int
340 mlx5_os_flow_dr_create_flow_action_sampler
341                         (struct mlx5dv_dr_flow_sampler_attr *attr,
342                         void **action)
343 {
344         RTE_SET_USED(attr);
345         *action = NULL;
346         rte_errno = ENOTSUP;
347         return -rte_errno;
348 }
349
350 /**
351  * Create flow action: dest_array
352  *
353  * @param[in] domain
354  *   Pointer to relevant domain.
355  * @param[in] num_dest
356  *   Number of destinations array.
357  * @param[in] dests
358  *   Array of destination attributes.
359  * @param[out] action
360  *   Pointer to a valid action on success, NULL otherwise.
361  *
362  * @return
363  *   0 on success, or -1 on failure and errno is set.
364  */
365 static inline int
366 mlx5_os_flow_dr_create_flow_action_dest_array
367                         (void *domain,
368                          size_t num_dest,
369                          struct mlx5dv_dr_action_dest_attr *dests[],
370                          void **action)
371 {
372         RTE_SET_USED(domain);
373         RTE_SET_USED(num_dest);
374         RTE_SET_USED(dests);
375         *action = NULL;
376         rte_errno = ENOTSUP;
377         return -rte_errno;
378 }
379
380 /**
381  * OS stub for mlx5_flow_adjust_priority() API.
382  * Windows only supports flow priority 0 that cannot be adjusted.
383  *
384  * @param[in] dev
385  *    Pointer to the Ethernet device structure.
386  * @param[in] priority
387  *    The rule base priority.
388  * @param[in] subpriority
389  *    The priority based on the items.
390  *
391  * @return
392  *    0
393  */
394 static inline uint32_t
395 mlx5_os_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
396                           uint32_t subpriority)
397 {
398         RTE_SET_USED(dev);
399         RTE_SET_USED(priority);
400         RTE_SET_USED(subpriority);
401         return 0;
402 }
403
404 static inline int
405 mlx5_os_flow_dr_sync_domain(void *domain, uint32_t flags)
406 {
407         RTE_SET_USED(domain);
408         RTE_SET_USED(flags);
409         errno = ENOTSUP;
410         return errno;
411 }
412
413 int mlx5_flow_os_validate_flow_attributes(struct rte_eth_dev *dev,
414                                         const struct rte_flow_attr *attributes,
415                                         bool external,
416                                         struct rte_flow_error *error);
417 int mlx5_flow_os_create_flow_matcher(void *ctx,
418                                      void *attr,
419                                      void *table,
420                                      void **matcher);
421 int mlx5_flow_os_destroy_flow_matcher(void *matcher);
422 int mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir,
423                                                   void **action);
424 int mlx5_flow_os_destroy_flow_action(void *action);
425 int mlx5_flow_os_create_flow(void *matcher, void *match_value,
426                              size_t num_actions,
427                              void *actions[], void **flow);
428 int mlx5_flow_os_destroy_flow(void *drv_flow_ptr);
429 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */