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