1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
5 #include "mlx5_flow_os.h"
6 #include "mlx5_win_ext.h"
9 * Verify the @p attributes will be correctly understood by the NIC and store
10 * them in the @p flow if everything is correct.
13 * Pointer to dev struct.
14 * @param[in] attributes
15 * Pointer to flow attributes
17 * This flow rule is created by request external to PMD.
19 * Pointer to error structure.
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.
27 mlx5_flow_os_validate_flow_attributes(struct rte_eth_dev *dev,
28 const struct rte_flow_attr *attributes,
30 struct rte_flow_error *error)
35 RTE_SET_USED(external);
36 if (attributes->group)
37 return rte_flow_error_set(error, ENOTSUP,
38 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
40 "groups are not supported");
41 if (attributes->priority)
42 return rte_flow_error_set(error, ENOTSUP,
43 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
45 "priorities are not supported");
46 if (attributes->transfer)
47 return rte_flow_error_set(error, ENOTSUP,
48 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
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");
59 * Create flow matcher in a flow table.
62 * Pointer to relevant device context.
64 * Pointer to relevant attributes.
66 * Pointer to table object.
68 * Pointer to a valid flow matcher object on success, NULL otherwise.
71 * 0 on success, or errno on failure.
74 mlx5_flow_os_create_flow_matcher(void *ctx,
79 struct mlx5dv_flow_matcher_attr *mattr;
84 if (mattr->type != IBV_FLOW_ATTR_NORMAL) {
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),
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;
107 * Destroy flow matcher.
110 * Pointer to matcher object to destroy.
113 * 0 on success, or the value of errno on failure.
116 mlx5_flow_os_destroy_flow_matcher(void *matcher)
123 * Create flow action: dest_devx_tir
126 * Pointer to DevX tir object
128 * Pointer to a valid action on success, NULL otherwise.
131 * 0 on success, or errno on failure.
134 mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir,
137 struct mlx5_action *mlx5_action =
138 mlx5_malloc(MLX5_MEM_ZERO,
139 sizeof(struct mlx5_action),
146 mlx5_action->type = MLX5_FLOW_CONTEXT_DEST_TYPE_TIR;
147 mlx5_action->dest_tir.id = tir->id;
148 *action = mlx5_action;
153 * Destroy flow action.
156 * Pointer to action object to destroy.
159 * 0 on success, or the value of errno on failure.
162 mlx5_flow_os_destroy_flow_action(void *action)
172 * Pointer to match mask structure.
173 * @param[in] match_value
174 * Pointer to match value structure.
175 * @param[in] num_actions
176 * Number of actions in flow rule.
178 * Pointer to array of flow rule actions.
180 * Pointer to a valid flow rule object on success, NULL otherwise.
183 * 0 on success, or errno on failure.
186 mlx5_flow_os_create_flow(void *matcher, void *match_value,
188 void *actions[], void **flow)
190 struct mlx5_action *action;
192 struct mlx5_matcher *mlx5_matcher = matcher;
193 struct mlx5_flow_dv_match_params *mlx5_match_value = match_value;
194 uint32_t in[MLX5_ST_SZ_DW(devx_fs_rule_add_in)] = {0};
195 void *matcher_c = MLX5_ADDR_OF(devx_fs_rule_add_in, in,
197 void *matcher_v = MLX5_ADDR_OF(devx_fs_rule_add_in, in,
200 MLX5_ASSERT(mlx5_matcher->ctx);
201 memcpy(matcher_c, mlx5_matcher->match_buf,
202 mlx5_match_value->size);
203 /* Use mlx5_match_value->size for match criteria */
204 memcpy(matcher_v, mlx5_match_value->buf,
205 mlx5_match_value->size);
206 for (i = 0; i < num_actions; i++) {
208 switch (action->type) {
209 case MLX5_FLOW_CONTEXT_DEST_TYPE_TIR:
210 MLX5_SET(devx_fs_rule_add_in, in,
211 dest.destination_type,
212 MLX5_FLOW_CONTEXT_DEST_TYPE_TIR);
213 MLX5_SET(devx_fs_rule_add_in, in,
215 action->dest_tir.id);
220 MLX5_SET(devx_fs_rule_add_in, in, match_criteria_enable,
221 MLX5_MATCH_OUTER_HEADERS);
223 *flow = mlx5_glue->devx_fs_rule_add(mlx5_matcher->ctx, in, sizeof(in));
224 return (*flow) ? 0 : -1;
230 * @param[in] drv_flow_ptr
231 * Pointer to flow rule object.
234 * 0 on success, errno on failure.
237 mlx5_flow_os_destroy_flow(void *drv_flow_ptr)
239 return mlx5_glue->devx_fs_rule_del(drv_flow_ptr);