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