2ce344c54bc62dac3eb800295b4c527fa3036d03
[dpdk.git] / drivers / net / mlx5 / linux / 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 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
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_MAX;
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 __rte_unused)
37 {
38         return true;
39 }
40
41 /**
42  * Check if action type is supported.
43  *
44  * @param action
45  *   Action type to check.
46  *
47  * @return
48  *   True is this action type is supported, false if not supported.
49  */
50 static inline bool
51 mlx5_flow_os_action_supported(int action __rte_unused)
52 {
53         return true;
54 }
55
56 /**
57  * Create flow rule.
58  *
59  * @param[in] matcher
60  *   Pointer to match mask structure.
61  * @param[in] match_value
62  *   Pointer to match value structure.
63  * @param[in] num_actions
64  *   Number of actions in flow rule.
65  * @param[in] actions
66  *   Pointer to array of flow rule actions.
67  * @param[out] flow
68  *   Pointer to a valid flow rule object on success, NULL otherwise.
69  *
70  * @return
71  *   0 on success, or -1 on failure and errno is set.
72  */
73 static inline int
74 mlx5_flow_os_create_flow(void *matcher, void *match_value,
75                          size_t num_actions, void *actions[], void **flow)
76 {
77         *flow = mlx5_glue->dv_create_flow(matcher, match_value,
78                                           num_actions, actions);
79         return (*flow) ? 0 : -1;
80 }
81
82 /**
83  * Destroy flow rule.
84  *
85  * @param[in] drv_flow_ptr
86  *   Pointer to flow rule object.
87  *
88  * @return
89  *   0 on success, or the value of errno on failure.
90  */
91 static inline int
92 mlx5_flow_os_destroy_flow(void *drv_flow_ptr)
93 {
94         return mlx5_glue->dv_destroy_flow(drv_flow_ptr);
95 }
96
97 /**
98  * Create flow table.
99  *
100  * @param[in] domain
101  *   Pointer to relevant domain.
102  * @param[in] table_id
103  *   Table ID.
104  * @param[out] table
105  *   Pointer to a valid flow table object on success, NULL otherwise.
106  *
107  * @return
108  *   0 on success, or -1 on failure and errno is set.
109  */
110 static inline int
111 mlx5_flow_os_create_flow_tbl(void *domain, uint32_t table_id, void **table)
112 {
113         *table = mlx5_glue->dr_create_flow_tbl(domain, table_id);
114         return (*table) ? 0 : -1;
115 }
116
117 /**
118  * Destroy flow table.
119  *
120  * @param[in] table
121  *   Pointer to table object to destroy.
122  *
123  * @return
124  *   0 on success, or the value of errno on failure.
125  */
126 static inline int
127 mlx5_flow_os_destroy_flow_tbl(void *table)
128 {
129         return mlx5_glue->dr_destroy_flow_tbl(table);
130 }
131
132 /**
133  * Create flow matcher in a flow table.
134  *
135  * @param[in] ctx
136  *   Pointer to relevant device context.
137  * @param[in] attr
138  *   Pointer to relevant attributes.
139  * @param[in] table
140  *   Pointer to table object.
141  * @param[out] matcher
142  *   Pointer to a valid flow matcher object on success, NULL otherwise.
143  *
144  * @return
145  *   0 on success, or -1 on failure and errno is set.
146  */
147 static inline int
148 mlx5_flow_os_create_flow_matcher(void *ctx, void *attr, void *table,
149                                  void **matcher)
150 {
151         *matcher = mlx5_glue->dv_create_flow_matcher(ctx, attr, table);
152         return (*matcher) ? 0 : -1;
153 }
154
155 /**
156  * Destroy flow matcher.
157  *
158  * @param[in] matcher
159  *   Pointer to matcher object to destroy.
160  *
161  * @return
162  *   0 on success, or the value of errno on failure.
163  */
164 static inline int
165 mlx5_flow_os_destroy_flow_matcher(void *matcher)
166 {
167         return mlx5_glue->dv_destroy_flow_matcher(matcher);
168 }
169
170 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */