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