1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2021 NVIDIA CORPORATION. All rights reserved.
10 struct mlx5dr_context;
12 struct mlx5dr_matcher;
15 enum mlx5dr_table_type {
16 MLX5DR_TABLE_TYPE_NIC_RX,
17 MLX5DR_TABLE_TYPE_NIC_TX,
18 MLX5DR_TABLE_TYPE_FDB,
19 MLX5DR_TABLE_TYPE_MAX,
22 enum mlx5dr_matcher_resource_mode {
23 /* Allocate resources based on number of rules with minimal failure probability */
24 MLX5DR_MATCHER_RESOURCE_MODE_RULE,
25 /* Allocate fixed size hash table based on given column and rows */
26 MLX5DR_MATCHER_RESOURCE_MODE_HTABLE,
29 enum mlx5dr_action_flags {
30 MLX5DR_ACTION_FLAG_ROOT_RX = 1 << 0,
31 MLX5DR_ACTION_FLAG_ROOT_TX = 1 << 1,
32 MLX5DR_ACTION_FLAG_ROOT_FDB = 1 << 2,
33 MLX5DR_ACTION_FLAG_HWS_RX = 1 << 3,
34 MLX5DR_ACTION_FLAG_HWS_TX = 1 << 4,
35 MLX5DR_ACTION_FLAG_HWS_FDB = 1 << 5,
36 MLX5DR_ACTION_FLAG_INLINE = 1 << 6,
39 enum mlx5dr_action_reformat_type {
40 MLX5DR_ACTION_REFORMAT_TYPE_TNL_L2_TO_L2,
41 MLX5DR_ACTION_REFORMAT_TYPE_L2_TO_TNL_L2,
42 MLX5DR_ACTION_REFORMAT_TYPE_TNL_L3_TO_L2,
43 MLX5DR_ACTION_REFORMAT_TYPE_L2_TO_TNL_L3,
46 enum mlx5dr_match_template_flags {
47 /* Allow relaxed matching by skipping derived dependent match fields. */
48 MLX5DR_MATCH_TEMPLATE_FLAG_RELAXED_MATCH = 1,
51 enum mlx5dr_send_queue_actions {
52 /* Start executing all pending queued rules and write to HW */
53 MLX5DR_SEND_QUEUE_ACTION_DRAIN = 1 << 0,
56 struct mlx5dr_context_attr {
59 size_t initial_log_ste_memory;
60 /* Optional PD used for allocating res ources */
64 struct mlx5dr_table_attr {
65 enum mlx5dr_table_type type;
69 struct mlx5dr_matcher_attr {
71 enum mlx5dr_matcher_resource_mode mode;
84 struct mlx5dr_rule_attr {
90 struct mlx5dr_devx_obj {
91 struct mlx5dv_devx_obj *obj;
95 struct mlx5dr_rule_action {
96 struct mlx5dr_action *action;
123 MLX5DR_MATCH_TAG_SZ = 32,
124 MLX5DR_JAMBO_TAG_SZ = 44,
127 enum mlx5dr_rule_status {
128 MLX5DR_RULE_STATUS_UNKNOWN,
129 MLX5DR_RULE_STATUS_CREATING,
130 MLX5DR_RULE_STATUS_CREATED,
131 MLX5DR_RULE_STATUS_DELETING,
132 MLX5DR_RULE_STATUS_DELETED,
133 MLX5DR_RULE_STATUS_FAILED,
137 struct mlx5dr_matcher *matcher;
139 uint8_t match_tag[MLX5DR_MATCH_TAG_SZ];
140 struct ibv_flow *flow;
142 enum mlx5dr_rule_status status;
143 uint32_t rtc_used; /* The RTC into which the STE was inserted */
146 /* Open a context used for direct rule insertion using hardware steering.
147 * Each context can contain multiple tables of different types.
150 * The ibv context to used for HWS.
152 * Attributes used for context open.
153 * @return pointer to mlx5dr_context on success NULL otherwise.
155 struct mlx5dr_context *
156 mlx5dr_context_open(void *ibv_ctx,
157 struct mlx5dr_context_attr *attr);
159 /* Close a context used for direct hardware steering.
162 * mlx5dr context to close.
163 * @return zero on success non zero otherwise.
165 int mlx5dr_context_close(struct mlx5dr_context *ctx);
167 /* Create a new direct rule table. Each table can contain multiple matchers.
170 * The context in which the new table will be opened.
172 * Attributes used for table creation.
173 * @return pointer to mlx5dr_table on success NULL otherwise.
175 struct mlx5dr_table *
176 mlx5dr_table_create(struct mlx5dr_context *ctx,
177 struct mlx5dr_table_attr *attr);
179 /* Destroy direct rule table.
182 * mlx5dr table to destroy.
183 * @return zero on success non zero otherwise.
185 int mlx5dr_table_destroy(struct mlx5dr_table *tbl);
187 /* Create new match template based on items mask, the match template
188 * will be used for matcher creation.
191 * Describe the mask for template creation
193 * Template creation flags
194 * @return pointer to mlx5dr_match_template on success NULL otherwise
196 struct mlx5dr_match_template *
197 mlx5dr_match_template_create(const struct rte_flow_item items[],
198 enum mlx5dr_match_template_flags flags);
200 /* Destroy match template.
203 * Match template to destroy.
204 * @return zero on success non zero otherwise.
206 int mlx5dr_match_template_destroy(struct mlx5dr_match_template *mt);
208 /* Create a new direct rule matcher. Each matcher can contain multiple rules.
209 * Matchers on the table will be processed by priority. Matching fields and
210 * mask are described by the match template. In some cases multiple match
211 * templates can be used on the same matcher.
214 * The table in which the new matcher will be opened.
216 * Array of match templates to be used on matcher.
217 * @param[in] num_of_mt
218 * Number of match templates in mt array.
220 * Attributes used for matcher creation.
221 * @return pointer to mlx5dr_matcher on success NULL otherwise.
223 struct mlx5dr_matcher *
224 mlx5dr_matcher_create(struct mlx5dr_table *table,
225 struct mlx5dr_match_template *mt[],
227 struct mlx5dr_matcher_attr *attr);
229 /* Destroy direct rule matcher.
232 * Matcher to destroy.
233 * @return zero on success non zero otherwise.
235 int mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher);
237 /* Get the size of the rule handle (mlx5dr_rule) to be used on rule creation.
239 * @return size in bytes of rule handle struct.
241 size_t mlx5dr_rule_get_handle_size(void);
243 /* Enqueue create rule operation.
246 * The matcher in which the new rule will be created.
248 * Match template index to create the rule with.
250 * The items used for the value matching.
251 * @param[in] rule_actions
252 * Rule action to be executed on match.
253 * @param[in] num_of_actions
254 * Number of rule actions.
256 * Rule creation attributes.
257 * @param[in, out] rule_handle
258 * A valid rule handle. The handle doesn't require any initialization.
259 * @return zero on successful enqueue non zero otherwise.
261 int mlx5dr_rule_create(struct mlx5dr_matcher *matcher,
263 const struct rte_flow_item items[],
264 struct mlx5dr_rule_action rule_actions[],
265 uint8_t num_of_actions,
266 struct mlx5dr_rule_attr *attr,
267 struct mlx5dr_rule *rule_handle);
269 /* Enqueue destroy rule operation.
272 * The rule destruction to enqueue.
274 * Rule destruction attributes.
275 * @return zero on successful enqueue non zero otherwise.
277 int mlx5dr_rule_destroy(struct mlx5dr_rule *rule,
278 struct mlx5dr_rule_attr *attr);
280 /* Create direct rule drop action.
283 * The context in which the new action will be created.
285 * Action creation flags. (enum mlx5dr_action_flags)
286 * @return pointer to mlx5dr_action on success NULL otherwise.
288 struct mlx5dr_action *
289 mlx5dr_action_create_dest_drop(struct mlx5dr_context *ctx,
292 /* Create direct rule default miss action.
293 * Defaults are RX: Drop TX: Wire.
296 * The context in which the new action will be created.
298 * Action creation flags. (enum mlx5dr_action_flags)
299 * @return pointer to mlx5dr_action on success NULL otherwise.
301 struct mlx5dr_action *
302 mlx5dr_action_create_default_miss(struct mlx5dr_context *ctx,
305 /* Create direct rule goto table action.
308 * The context in which the new action will be created.
312 * Action creation flags. (enum mlx5dr_action_flags)
313 * @return pointer to mlx5dr_action on success NULL otherwise.
315 struct mlx5dr_action *
316 mlx5dr_action_create_dest_table(struct mlx5dr_context *ctx,
317 struct mlx5dr_table *tbl,
320 /* Create direct rule goto TIR action.
323 * The context in which the new action will be created.
325 * Direct rule TIR devx object.
327 * Action creation flags. (enum mlx5dr_action_flags)
328 * @return pointer to mlx5dr_action on success NULL otherwise.
330 struct mlx5dr_action *
331 mlx5dr_action_create_dest_tir(struct mlx5dr_context *ctx,
332 struct mlx5dr_devx_obj *obj,
335 /* Create direct rule TAG action.
338 * The context in which the new action will be created.
340 * Action creation flags. (enum mlx5dr_action_flags)
341 * @return pointer to mlx5dr_action on success NULL otherwise.
343 struct mlx5dr_action *
344 mlx5dr_action_create_tag(struct mlx5dr_context *ctx,
347 /* Create direct rule counter action.
350 * The context in which the new action will be created.
352 * Direct rule counter devx object.
354 * Action creation flags. (enum mlx5dr_action_flags)
355 * @return pointer to mlx5dr_action on success NULL otherwise.
357 struct mlx5dr_action *
358 mlx5dr_action_create_counter(struct mlx5dr_context *ctx,
359 struct mlx5dr_devx_obj *obj,
362 /* Create direct rule reformat action.
365 * The context in which the new action will be created.
366 * @param[in] reformat_type
369 * Size in bytes of data.
370 * @param[in] inline_data
371 * Header data array in case of inline action.
372 * @param[in] log_bulk_size
373 * Number of unique values used with this pattern.
375 * Action creation flags. (enum mlx5dr_action_flags)
376 * @return pointer to mlx5dr_action on success NULL otherwise.
378 struct mlx5dr_action *
379 mlx5dr_action_create_reformat(struct mlx5dr_context *ctx,
380 enum mlx5dr_action_reformat_type reformat_type,
383 uint32_t log_bulk_size,
386 /* Create direct rule modify header action.
389 * The context in which the new action will be created.
390 * @param[in] pattern_sz
391 * Byte size of the pattern array.
393 * PRM format modify pattern action array.
394 * @param[in] log_bulk_size
395 * Number of unique values used with this pattern.
397 * Action creation flags. (enum mlx5dr_action_flags)
398 * @return pointer to mlx5dr_action on success NULL otherwise.
400 struct mlx5dr_action *
401 mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx,
403 rte_be64_t pattern[],
404 uint32_t log_bulk_size,
407 /* Destroy direct rule action.
410 * The action to destroy.
411 * @return zero on success non zero otherwise.
413 int mlx5dr_action_destroy(struct mlx5dr_action *action);
415 /* Poll queue for rule creation and deletions completions.
418 * The context to which the queue belong to.
419 * @param[in] queue_id
420 * The id of the queue to poll.
421 * @param[in, out] res
424 * Maximum number of results to return.
425 * @return negative number on failure, the number of completions otherwise.
427 int mlx5dr_send_queue_poll(struct mlx5dr_context *ctx,
429 struct rte_flow_op_result res[],
432 /* Perform an action on the queue
435 * The context to which the queue belong to.
436 * @param[in] queue_id
437 * The id of the queue to perform the action on.
439 * Actions to perform on the queue. (enum mlx5dr_send_queue_actions)
440 * @return zero on success non zero otherwise.
442 int mlx5dr_send_queue_action(struct mlx5dr_context *ctx,
449 * The context which to dump the info from.
451 * The file to write the dump to.
452 * @return zero on success non zero otherwise.
454 int mlx5dr_debug_dump(struct mlx5dr_context *ctx, FILE *f);