net/mlx5: create flow matcher object on Windows
[dpdk.git] / drivers / net / mlx5 / windows / mlx5_flow_os.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4
5 #include "mlx5_flow_os.h"
6 #include "mlx5_win_ext.h"
7
8 /**
9  * Verify the @p attributes will be correctly understood by the NIC and store
10  * them in the @p flow if everything is correct.
11  *
12  * @param[in] dev
13  *   Pointer to dev struct.
14  * @param[in] attributes
15  *   Pointer to flow attributes
16  * @param[in] external
17  *   This flow rule is created by request external to PMD.
18  * @param[out] error
19  *   Pointer to error structure.
20  *
21  * @return
22  *   - 0 on success and non root table (not a valid option for Windows yet).
23  *   - 1 on success and root table.
24  *   - a negative errno value otherwise and rte_errno is set.
25  */
26 int
27 mlx5_flow_os_validate_flow_attributes(struct rte_eth_dev *dev,
28                                       const struct rte_flow_attr *attributes,
29                                       bool external,
30                                       struct rte_flow_error *error)
31 {
32         int ret = 1;
33
34         RTE_SET_USED(dev);
35         RTE_SET_USED(external);
36         if (attributes->group)
37                 return rte_flow_error_set(error, ENOTSUP,
38                                           RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
39                                           NULL,
40                                           "groups are not supported");
41         if (attributes->priority)
42                 return rte_flow_error_set(error, ENOTSUP,
43                                           RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
44                                           NULL,
45                                           "priorities are not supported");
46         if (attributes->transfer)
47                 return rte_flow_error_set(error, ENOTSUP,
48                                           RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
49                                           NULL,
50                                           "transfer not supported");
51         if (!(attributes->ingress))
52                 return rte_flow_error_set(error, ENOTSUP,
53                                           RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
54                                           NULL, "must specify ingress only");
55         return ret;
56 }
57
58 /**
59  * Create flow matcher in a flow table.
60  *
61  * @param[in] ctx
62  *   Pointer to relevant device context.
63  * @param[in] attr
64  *   Pointer to relevant attributes.
65  * @param[in] table
66  *   Pointer to table object.
67  * @param[out] matcher
68  *   Pointer to a valid flow matcher object on success, NULL otherwise.
69  *
70  * @return
71  *   0 on success, or errno on failure.
72  */
73 int
74 mlx5_flow_os_create_flow_matcher(void *ctx,
75                                  void *attr,
76                                  void *table,
77                                  void **matcher)
78 {
79         struct mlx5dv_flow_matcher_attr *mattr;
80
81         RTE_SET_USED(table);
82         *matcher = NULL;
83         mattr = attr;
84         if (mattr->type != IBV_FLOW_ATTR_NORMAL) {
85                 rte_errno = ENOTSUP;
86                 return -rte_errno;
87         }
88         struct mlx5_matcher *mlx5_matcher =
89                 mlx5_malloc(MLX5_MEM_ZERO,
90                        sizeof(struct mlx5_matcher) +
91                        MLX5_ST_SZ_BYTES(fte_match_param),
92                        0, SOCKET_ID_ANY);
93         if (!mlx5_matcher) {
94                 rte_errno = ENOMEM;
95                 return -rte_errno;
96         }
97         mlx5_matcher->ctx = ctx;
98         memcpy(&mlx5_matcher->attr, attr, sizeof(mlx5_matcher->attr));
99         memcpy(&mlx5_matcher->match_buf,
100                mattr->match_mask->match_buf,
101                MLX5_ST_SZ_BYTES(fte_match_param));
102         *matcher = mlx5_matcher;
103         return 0;
104 }
105
106 /**
107  * Destroy flow matcher.
108  *
109  * @param[in] matcher
110  *   Pointer to matcher object to destroy.
111  *
112  * @return
113  *   0 on success, or the value of errno on failure.
114  */
115 int
116 mlx5_flow_os_destroy_flow_matcher(void *matcher)
117 {
118         mlx5_free(matcher);
119         return 0;
120 }
121
122 /**
123  * Create flow action: dest_devx_tir
124  *
125  * @param[in] tir
126  *   Pointer to DevX tir object
127  * @param[out] action
128  *   Pointer to a valid action on success, NULL otherwise.
129  *
130  * @return
131  *   0 on success, or errno on failure.
132  */
133 int
134 mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir,
135                                               void **action)
136 {
137         RTE_SET_USED(tir);
138         *action = NULL;
139         rte_errno = ENOTSUP;
140         return -rte_errno;
141 }
142
143 /**
144  * Destroy flow action.
145  *
146  * @param[in] action
147  *   Pointer to action object to destroy.
148  *
149  * @return
150  *   0 on success, or the value of errno on failure.
151  */
152 int
153 mlx5_flow_os_destroy_flow_action(void *action)
154 {
155         RTE_SET_USED(action);
156         rte_errno = ENOTSUP;
157         return -rte_errno;
158 }
159
160 /**
161  * Create flow rule.
162  *
163  * @param[in] matcher
164  *   Pointer to match mask structure.
165  * @param[in] match_value
166  *   Pointer to match value structure.
167  * @param[in] num_actions
168  *   Number of actions in flow rule.
169  * @param[in] actions
170  *   Pointer to array of flow rule actions.
171  * @param[out] flow
172  *   Pointer to a valid flow rule object on success, NULL otherwise.
173  *
174  * @return
175  *   0 on success, or errno on failure.
176  */
177 int
178 mlx5_flow_os_create_flow(void *matcher, void *match_value,
179                          size_t num_actions,
180                          void *actions[], void **flow)
181 {
182         RTE_SET_USED(matcher);
183         RTE_SET_USED(match_value);
184         RTE_SET_USED(num_actions);
185         RTE_SET_USED(actions);
186         *flow = NULL;
187         rte_errno = ENOTSUP;
188         return -rte_errno;
189 }
190
191 /**
192  * Destroy flow rule.
193  *
194  * @param[in] drv_flow_ptr
195  *   Pointer to flow rule object.
196  *
197  * @return
198  *   0 on success, errno on failure.
199  */
200 int
201 mlx5_flow_os_destroy_flow(void *drv_flow_ptr)
202 {
203         RTE_SET_USED(dev_flow_ptr);
204         rte_errno = ENOTSUP;
205         return -rte_errno;
206 }