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;
12 extern const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops;
16 * Get OS enforced flow type. MLX5_FLOW_TYPE_MAX means "non enforced type".
19 * Flow type (MLX5_FLOW_TYPE_MAX)
21 static inline enum mlx5_flow_drv_type
22 mlx5_flow_os_get_type(void)
24 return MLX5_FLOW_TYPE_MAX;
28 * Check if item type is supported.
34 * True is this item type is supported, false if not supported.
37 mlx5_flow_os_item_supported(int item __rte_unused)
43 * Check if action type is supported.
46 * Action type to check.
49 * True is this action type is supported, false if not supported.
52 mlx5_flow_os_action_supported(int action __rte_unused)
61 * Pointer to match mask structure.
62 * @param[in] match_value
63 * Pointer to match value structure.
64 * @param[in] num_actions
65 * Number of actions in flow rule.
67 * Pointer to array of flow rule actions.
69 * Pointer to a valid flow rule object on success, NULL otherwise.
72 * 0 on success, or -1 on failure and errno is set.
75 mlx5_flow_os_create_flow(void *matcher, void *match_value,
76 size_t num_actions, void *actions[], void **flow)
78 *flow = mlx5_glue->dv_create_flow(matcher, match_value,
79 num_actions, actions);
80 return (*flow) ? 0 : -1;
86 * @param[in] drv_flow_ptr
87 * Pointer to flow rule object.
90 * 0 on success, or the value of errno on failure.
93 mlx5_flow_os_destroy_flow(void *drv_flow_ptr)
95 return mlx5_glue->dv_destroy_flow(drv_flow_ptr);
102 * Pointer to relevant domain.
103 * @param[in] table_id
106 * Pointer to a valid flow table object on success, NULL otherwise.
109 * 0 on success, or -1 on failure and errno is set.
112 mlx5_flow_os_create_flow_tbl(void *domain, uint32_t table_id, void **table)
114 *table = mlx5_glue->dr_create_flow_tbl(domain, table_id);
115 return (*table) ? 0 : -1;
119 * Destroy flow table.
122 * Pointer to table object to destroy.
125 * 0 on success, or the value of errno on failure.
128 mlx5_flow_os_destroy_flow_tbl(void *table)
130 return mlx5_glue->dr_destroy_flow_tbl(table);
134 * Create flow matcher in a flow table.
137 * Pointer to relevant device context.
139 * Pointer to relevant attributes.
141 * Pointer to table object.
142 * @param[out] matcher
143 * Pointer to a valid flow matcher object on success, NULL otherwise.
146 * 0 on success, or -1 on failure and errno is set.
149 mlx5_flow_os_create_flow_matcher(void *ctx, void *attr, void *table,
152 *matcher = mlx5_glue->dv_create_flow_matcher(ctx, attr, table);
153 return (*matcher) ? 0 : -1;
157 * Destroy flow matcher.
160 * Pointer to matcher object to destroy.
163 * 0 on success, or the value of errno on failure.
166 mlx5_flow_os_destroy_flow_matcher(void *matcher)
168 return mlx5_glue->dv_destroy_flow_matcher(matcher);
172 * Create flow action: packet reformat.
175 * Pointer to relevant device context.
177 * Pointer to domain handler.
178 * @param[in] resource
179 * Pointer to action data resource.
181 * Pointer to a valid action on success, NULL otherwise.
185 * 0 on success, or -1 on failure and errno is set.
188 mlx5_flow_os_create_flow_action_packet_reformat(void *ctx, void *domain,
189 void *resource, void **action)
191 struct mlx5_flow_dv_encap_decap_resource *res =
192 (struct mlx5_flow_dv_encap_decap_resource *)resource;
194 *action = mlx5_glue->dv_create_flow_action_packet_reformat
195 (ctx, res->reformat_type, res->ft_type,
196 domain, res->flags, res->size,
197 (res->size ? res->buf : NULL));
198 return (*action) ? 0 : -1;
202 * Create flow action: modify header.
205 * Pointer to relevant device context.
207 * Pointer to domain handler.
208 * @param[in] resource
209 * Pointer to action data resource.
210 * @param[in] actions_len
211 * Total length of actions data in resource.
213 * Pointer to a valid action on success, NULL otherwise.
217 * 0 on success, or -1 on failure and errno is set.
220 mlx5_flow_os_create_flow_action_modify_header(void *ctx, void *domain,
222 uint32_t actions_len,
225 struct mlx5_flow_dv_modify_hdr_resource *res =
226 (struct mlx5_flow_dv_modify_hdr_resource *)resource;
228 *action = mlx5_glue->dv_create_flow_action_modify_header
229 (ctx, res->ft_type, domain, res->root ?
230 MLX5DV_DR_ACTION_FLAGS_ROOT_LEVEL : 0,
231 actions_len, (uint64_t *)res->actions);
232 return (*action) ? 0 : -1;
236 * Create flow action: destination flow table.
239 * Pointer to destination table object.
241 * Pointer to a valid action on success, NULL otherwise.
244 * 0 on success, or -1 on failure and errno is set.
247 mlx5_flow_os_create_flow_action_dest_flow_tbl(void *tbl_obj, void **action)
249 *action = mlx5_glue->dr_create_flow_action_dest_flow_tbl(tbl_obj);
250 return (*action) ? 0 : -1;
254 * Create flow action: destination port.
257 * Pointer to domain handler.
259 * Destination port ID.
261 * Pointer to a valid action on success, NULL otherwise.
264 * 0 on success, or -1 on failure and errno is set.
267 mlx5_flow_os_create_flow_action_dest_port(void *domain, uint32_t port_id,
271 * Depending on rdma_core version the glue routine calls
272 * either mlx5dv_dr_action_create_dest_ib_port(domain, dev_port)
273 * or mlx5dv_dr_action_create_dest_vport(domain, vport_id).
275 *action = mlx5_glue->dr_create_flow_action_dest_port(domain, port_id);
276 return (*action) ? 0 : -1;
280 * Create flow action: push vlan.
283 * Pointer to domain handler.
284 * @param[in] vlan_tag
287 * Pointer to a valid action on success, NULL otherwise.
290 * 0 on success, or -1 on failure and errno is set.
293 mlx5_flow_os_create_flow_action_push_vlan(void *domain, rte_be32_t vlan_tag,
296 *action = mlx5_glue->dr_create_flow_action_push_vlan(domain, vlan_tag);
297 return (*action) ? 0 : -1;
301 * Create flow action: count.
304 * Pointer to DevX counter object.
306 * Offset of counter in array.
308 * Pointer to a valid action on success, NULL otherwise.
311 * 0 on success, or -1 on failure and errno is set.
314 mlx5_flow_os_create_flow_action_count(void *cnt_obj, uint16_t offset,
317 *action = mlx5_glue->dv_create_flow_action_counter(cnt_obj, offset);
318 return (*action) ? 0 : -1;
322 * Create flow action: tag.
327 * Pointer to a valid action on success, NULL otherwise.
330 * 0 on success, or -1 on failure and errno is set.
333 mlx5_flow_os_create_flow_action_tag(uint32_t tag, void **action)
335 *action = mlx5_glue->dv_create_flow_action_tag(tag);
336 return (*action) ? 0 : -1;
340 * Create flow action: drop.
343 * Pointer to a valid action on success, NULL otherwise.
346 * 0 on success, or -1 on failure and errno is set.
349 mlx5_flow_os_create_flow_action_drop(void **action)
351 *action = mlx5_glue->dr_create_flow_action_drop();
352 return (*action) ? 0 : -1;
356 * Create flow action: default miss.
359 * Pointer to a valid action on success, NULL otherwise.
362 * 0 on success, or -1 on failure and errno is set.
365 mlx5_flow_os_create_flow_action_default_miss(void **action)
367 *action = mlx5_glue->dr_create_flow_action_default_miss();
368 return (*action) ? 0 : -1;
372 * Create flow action: dest_devx_tir
375 * Pointer to DevX tir object
377 * Pointer to a valid action on success, NULL otherwise.
380 * 0 on success, or -1 on failure and errno is set.
383 mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir,
386 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
387 *action = mlx5_glue->dv_create_flow_action_dest_devx_tir(tir->obj);
388 return (*action) ? 0 : -1;
390 /* If no DV support - skip the operation and return success */
398 * Create flow action: sampler
401 * Pointer to sampler attribute
403 * Pointer to a valid action on success, NULL otherwise.
406 * 0 on success, or -1 on failure and errno is set.
409 mlx5_os_flow_dr_create_flow_action_sampler
410 (struct mlx5dv_dr_flow_sampler_attr *attr,
413 *action = mlx5_glue->dr_create_flow_action_sampler(attr);
414 return (*action) ? 0 : -1;
418 * Create flow action: dest_array
421 * Pointer to relevant domain.
422 * @param[in] num_dest
423 * Number of destinations array.
425 * Array of destination attributes.
427 * Pointer to a valid action on success, NULL otherwise.
430 * 0 on success, or -1 on failure and errno is set.
433 mlx5_os_flow_dr_create_flow_action_dest_array
436 struct mlx5dv_dr_action_dest_attr *dests[],
439 *action = mlx5_glue->dr_create_flow_action_dest_array(
440 domain, num_dest, dests);
441 return (*action) ? 0 : -1;
445 * Destroy flow action.
448 * Pointer to action object to destroy.
451 * 0 on success, or the value of errno on failure.
454 mlx5_flow_os_destroy_flow_action(void *action)
456 return mlx5_glue->destroy_flow_action(action);
460 * OS wrapper over Verbs API.
461 * Adjust flow priority based on the highest layer and the request priority.
464 * Pointer to the Ethernet device structure.
465 * @param[in] priority
466 * The rule base priority.
467 * @param[in] subpriority
468 * The priority based on the items.
473 static inline uint32_t
474 mlx5_os_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
475 uint32_t subpriority)
477 return mlx5_flow_adjust_priority(dev, priority, subpriority);
481 mlx5_os_flow_dr_sync_domain(void *domain, uint32_t flags)
483 return mlx5_glue->dr_sync_domain(domain, flags);
485 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */