1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
5 #ifndef RTE_PMD_MLX5_FLOW_OS_H_
6 #define RTE_PMD_MLX5_FLOW_OS_H_
10 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
11 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
15 * Get OS enforced flow type. MLX5_FLOW_TYPE_MAX means "non enforced type".
18 * Flow type (MLX5_FLOW_TYPE_MAX)
20 static inline enum mlx5_flow_drv_type
21 mlx5_flow_os_get_type(void)
23 return MLX5_FLOW_TYPE_MAX;
27 * Check if item type is supported.
33 * True is this item type is supported, false if not supported.
36 mlx5_flow_os_item_supported(int item __rte_unused)
42 * Check if action type is supported.
45 * Action type to check.
48 * True is this action type is supported, false if not supported.
51 mlx5_flow_os_action_supported(int action __rte_unused)
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.
66 * Pointer to array of flow rule actions.
68 * Pointer to a valid flow rule object on success, NULL otherwise.
71 * 0 on success, or -1 on failure and errno is set.
74 mlx5_flow_os_create_flow(void *matcher, void *match_value,
75 size_t num_actions, void *actions[], void **flow)
77 *flow = mlx5_glue->dv_create_flow(matcher, match_value,
78 num_actions, actions);
79 return (*flow) ? 0 : -1;
85 * @param[in] drv_flow_ptr
86 * Pointer to flow rule object.
89 * 0 on success, or the value of errno on failure.
92 mlx5_flow_os_destroy_flow(void *drv_flow_ptr)
94 return mlx5_glue->dv_destroy_flow(drv_flow_ptr);
101 * Pointer to relevant domain.
102 * @param[in] table_id
105 * Pointer to a valid flow table object on success, NULL otherwise.
108 * 0 on success, or -1 on failure and errno is set.
111 mlx5_flow_os_create_flow_tbl(void *domain, uint32_t table_id, void **table)
113 *table = mlx5_glue->dr_create_flow_tbl(domain, table_id);
114 return (*table) ? 0 : -1;
118 * Destroy flow table.
121 * Pointer to table object to destroy.
124 * 0 on success, or the value of errno on failure.
127 mlx5_flow_os_destroy_flow_tbl(void *table)
129 return mlx5_glue->dr_destroy_flow_tbl(table);
133 * Create flow matcher in a flow table.
136 * Pointer to relevant device context.
138 * Pointer to relevant attributes.
140 * Pointer to table object.
141 * @param[out] matcher
142 * Pointer to a valid flow matcher object on success, NULL otherwise.
145 * 0 on success, or -1 on failure and errno is set.
148 mlx5_flow_os_create_flow_matcher(void *ctx, void *attr, void *table,
151 *matcher = mlx5_glue->dv_create_flow_matcher(ctx, attr, table);
152 return (*matcher) ? 0 : -1;
156 * Destroy flow matcher.
159 * Pointer to matcher object to destroy.
162 * 0 on success, or the value of errno on failure.
165 mlx5_flow_os_destroy_flow_matcher(void *matcher)
167 return mlx5_glue->dv_destroy_flow_matcher(matcher);
171 * Create flow action: packet reformat.
174 * Pointer to relevant device context.
176 * Pointer to domain handler.
177 * @param[in] resource
178 * Pointer to action data resource.
180 * Pointer to a valid action on success, NULL otherwise.
184 * 0 on success, or -1 on failure and errno is set.
187 mlx5_flow_os_create_flow_action_packet_reformat(void *ctx, void *domain,
188 void *resource, void **action)
190 struct mlx5_flow_dv_encap_decap_resource *res =
191 (struct mlx5_flow_dv_encap_decap_resource *)resource;
193 *action = mlx5_glue->dv_create_flow_action_packet_reformat
194 (ctx, res->reformat_type, res->ft_type,
195 domain, res->flags, res->size,
196 (res->size ? res->buf : NULL));
197 return (*action) ? 0 : -1;
201 * Create flow action: modify header.
204 * Pointer to relevant device context.
206 * Pointer to domain handler.
207 * @param[in] resource
208 * Pointer to action data resource.
209 * @param[in] actions_len
210 * Total length of actions data in resource.
212 * Pointer to a valid action on success, NULL otherwise.
216 * 0 on success, or -1 on failure and errno is set.
219 mlx5_flow_os_create_flow_action_modify_header(void *ctx, void *domain,
221 uint32_t actions_len,
224 struct mlx5_flow_dv_modify_hdr_resource *res =
225 (struct mlx5_flow_dv_modify_hdr_resource *)resource;
227 *action = mlx5_glue->dv_create_flow_action_modify_header
228 (ctx, res->ft_type, domain, res->root ?
229 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL : 0,
230 actions_len, (uint64_t *)res->actions);
231 return (*action) ? 0 : -1;
235 * Create flow action: destination flow table.
238 * Pointer to destination table object.
240 * Pointer to a valid action on success, NULL otherwise.
243 * 0 on success, or -1 on failure and errno is set.
246 mlx5_flow_os_create_flow_action_dest_flow_tbl(void *tbl_obj, void **action)
248 *action = mlx5_glue->dr_create_flow_action_dest_flow_tbl(tbl_obj);
249 return (*action) ? 0 : -1;
253 * Create flow action: destination port.
256 * Pointer to domain handler.
258 * Destination port ID.
260 * Pointer to a valid action on success, NULL otherwise.
263 * 0 on success, or -1 on failure and errno is set.
266 mlx5_flow_os_create_flow_action_dest_port(void *domain, uint32_t port_id,
270 * Depending on rdma_core version the glue routine calls
271 * either mlx5dv_dr_action_create_dest_ib_port(domain, dev_port)
272 * or mlx5dv_dr_action_create_dest_vport(domain, vport_id).
274 *action = mlx5_glue->dr_create_flow_action_dest_port(domain, port_id);
275 return (*action) ? 0 : -1;
279 * Create flow action: push vlan.
282 * Pointer to domain handler.
283 * @param[in] vlan_tag
286 * Pointer to a valid action on success, NULL otherwise.
289 * 0 on success, or -1 on failure and errno is set.
292 mlx5_flow_os_create_flow_action_push_vlan(void *domain, rte_be32_t vlan_tag,
295 *action = mlx5_glue->dr_create_flow_action_push_vlan(domain, vlan_tag);
296 return (*action) ? 0 : -1;
300 * Create flow action: count.
303 * Pointer to DevX counter object.
305 * Offset of counter in array.
307 * Pointer to a valid action on success, NULL otherwise.
310 * 0 on success, or -1 on failure and errno is set.
313 mlx5_flow_os_create_flow_action_count(void *cnt_obj, uint16_t offset,
316 *action = mlx5_glue->dv_create_flow_action_counter(cnt_obj, offset);
317 return (*action) ? 0 : -1;
321 * Create flow action: tag.
326 * Pointer to a valid action on success, NULL otherwise.
329 * 0 on success, or -1 on failure and errno is set.
332 mlx5_flow_os_create_flow_action_tag(uint32_t tag, void **action)
334 *action = mlx5_glue->dv_create_flow_action_tag(tag);
335 return (*action) ? 0 : -1;
339 * Create flow action: drop.
342 * Pointer to a valid action on success, NULL otherwise.
345 * 0 on success, or -1 on failure and errno is set.
348 mlx5_flow_os_create_flow_action_drop(void **action)
350 *action = mlx5_glue->dr_create_flow_action_drop();
351 return (*action) ? 0 : -1;
355 * Create flow action: default miss.
358 * Pointer to a valid action on success, NULL otherwise.
361 * 0 on success, or -1 on failure and errno is set.
364 mlx5_flow_os_create_flow_action_default_miss(void **action)
366 *action = mlx5_glue->dr_create_flow_action_default_miss();
367 return (*action) ? 0 : -1;
371 * Create flow action: dest_devx_tir
374 * Pointer to DevX tir object
376 * Pointer to a valid action on success, NULL otherwise.
379 * 0 on success, or -1 on failure and errno is set.
382 mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir,
385 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
386 *action = mlx5_glue->dv_create_flow_action_dest_devx_tir(tir->obj);
387 return (*action) ? 0 : -1;
389 /* If no DV support - skip the operation and return success */
397 * Create flow action: sampler
400 * Pointer to sampler attribute
402 * Pointer to a valid action on success, NULL otherwise.
405 * 0 on success, or -1 on failure and errno is set.
408 mlx5_os_flow_dr_create_flow_action_sampler
409 (struct mlx5dv_dr_flow_sampler_attr *attr,
412 *action = mlx5_glue->dr_create_flow_action_sampler(attr);
413 return (*action) ? 0 : -1;
417 * Create flow action: dest_array
420 * Pointer to relevant domain.
421 * @param[in] num_dest
422 * Number of destinations array.
424 * Array of destination attributes.
426 * Pointer to a valid action on success, NULL otherwise.
429 * 0 on success, or -1 on failure and errno is set.
432 mlx5_os_flow_dr_create_flow_action_dest_array
435 struct mlx5dv_dr_action_dest_attr *dests[],
438 *action = mlx5_glue->dr_create_flow_action_dest_array(
439 domain, num_dest, dests);
440 return (*action) ? 0 : -1;
444 * Destroy flow action.
447 * Pointer to action object to destroy.
450 * 0 on success, or the value of errno on failure.
453 mlx5_flow_os_destroy_flow_action(void *action)
455 return mlx5_glue->destroy_flow_action(action);
459 * OS wrapper over Verbs API.
460 * Adjust flow priority based on the highest layer and the request priority.
463 * Pointer to the Ethernet device structure.
464 * @param[in] priority
465 * The rule base priority.
466 * @param[in] subpriority
467 * The priority based on the items.
472 static inline uint32_t
473 mlx5_os_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
474 uint32_t subpriority)
476 return mlx5_flow_adjust_priority(dev, priority, subpriority);
480 mlx5_os_flow_dr_sync_domain(void *domain, uint32_t flags)
482 return mlx5_glue->dr_sync_domain(domain, flags);
484 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */