xref: /dpdk/drivers/net/mlx5/hws/mlx5dr.h (revision e9fd1ebf981f361844aea9ec94e17f4bda5e1479)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2022 NVIDIA Corporation & Affiliates
3  */
4 
5 #ifndef MLX5DR_H_
6 #define MLX5DR_H_
7 
8 #include <rte_flow.h>
9 
10 struct mlx5dr_context;
11 struct mlx5dr_table;
12 struct mlx5dr_matcher;
13 struct mlx5dr_rule;
14 struct ibv_context;
15 
16 enum mlx5dr_table_type {
17 	MLX5DR_TABLE_TYPE_NIC_RX,
18 	MLX5DR_TABLE_TYPE_NIC_TX,
19 	MLX5DR_TABLE_TYPE_FDB,
20 	MLX5DR_TABLE_TYPE_MAX,
21 };
22 
23 enum mlx5dr_matcher_resource_mode {
24 	/* Allocate resources based on number of rules with minimal failure probability */
25 	MLX5DR_MATCHER_RESOURCE_MODE_RULE,
26 	/* Allocate fixed size hash table based on given column and rows */
27 	MLX5DR_MATCHER_RESOURCE_MODE_HTABLE,
28 };
29 
30 enum mlx5dr_action_type {
31 	MLX5DR_ACTION_TYP_LAST,
32 	MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2,
33 	MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2,
34 	MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2,
35 	MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3,
36 	MLX5DR_ACTION_TYP_DROP,
37 	MLX5DR_ACTION_TYP_TIR,
38 	MLX5DR_ACTION_TYP_TBL,
39 	MLX5DR_ACTION_TYP_CTR,
40 	MLX5DR_ACTION_TYP_TAG,
41 	MLX5DR_ACTION_TYP_MODIFY_HDR,
42 	MLX5DR_ACTION_TYP_VPORT,
43 	MLX5DR_ACTION_TYP_MISS,
44 	MLX5DR_ACTION_TYP_POP_VLAN,
45 	MLX5DR_ACTION_TYP_PUSH_VLAN,
46 	MLX5DR_ACTION_TYP_ASO_METER,
47 	MLX5DR_ACTION_TYP_ASO_CT,
48 	MLX5DR_ACTION_TYP_INSERT_HEADER,
49 	MLX5DR_ACTION_TYP_REMOVE_HEADER,
50 	MLX5DR_ACTION_TYP_DEST_ROOT,
51 	MLX5DR_ACTION_TYP_DEST_ARRAY,
52 	MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT,
53 	MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT,
54 	MLX5DR_ACTION_TYP_MAX,
55 };
56 
57 enum mlx5dr_action_flags {
58 	MLX5DR_ACTION_FLAG_ROOT_RX = 1 << 0,
59 	MLX5DR_ACTION_FLAG_ROOT_TX = 1 << 1,
60 	MLX5DR_ACTION_FLAG_ROOT_FDB = 1 << 2,
61 	MLX5DR_ACTION_FLAG_HWS_RX = 1 << 3,
62 	MLX5DR_ACTION_FLAG_HWS_TX = 1 << 4,
63 	MLX5DR_ACTION_FLAG_HWS_FDB = 1 << 5,
64 	/* Shared action can be used over a few threads, since data is written
65 	 * only once at the creation of the action.
66 	 */
67 	MLX5DR_ACTION_FLAG_SHARED = 1 << 6,
68 };
69 
70 enum mlx5dr_action_aso_meter_color {
71 	MLX5DR_ACTION_ASO_METER_COLOR_RED = 0x0,
72 	MLX5DR_ACTION_ASO_METER_COLOR_YELLOW = 0x1,
73 	MLX5DR_ACTION_ASO_METER_COLOR_GREEN = 0x2,
74 	MLX5DR_ACTION_ASO_METER_COLOR_UNDEFINED = 0x3,
75 };
76 
77 enum mlx5dr_action_aso_ct_flags {
78 	MLX5DR_ACTION_ASO_CT_DIRECTION_INITIATOR = 0 << 0,
79 	MLX5DR_ACTION_ASO_CT_DIRECTION_RESPONDER = 1 << 0,
80 };
81 
82 enum mlx5dr_match_template_flags {
83 	/* Allow relaxed matching by skipping derived dependent match fields. */
84 	MLX5DR_MATCH_TEMPLATE_FLAG_RELAXED_MATCH = 1,
85 };
86 
87 enum mlx5dr_send_queue_actions {
88 	/* Start executing all pending queued rules */
89 	MLX5DR_SEND_QUEUE_ACTION_DRAIN_ASYNC = 1 << 0,
90 	/* Start executing all pending queued rules wait till completion */
91 	MLX5DR_SEND_QUEUE_ACTION_DRAIN_SYNC = 1 << 1,
92 };
93 
94 struct mlx5dr_context_attr {
95 	uint16_t queues;
96 	uint16_t queue_size;
97 	size_t initial_log_ste_memory; /* Currently not in use */
98 	/* Optional PD used for allocating res ources */
99 	struct ibv_pd *pd;
100 	/* Optional other ctx for resources allocation, all objects will be created on it */
101 	struct ibv_context *shared_ibv_ctx;
102 };
103 
104 struct mlx5dr_table_attr {
105 	enum mlx5dr_table_type type;
106 	uint32_t level;
107 };
108 
109 enum mlx5dr_matcher_flow_src {
110 	MLX5DR_MATCHER_FLOW_SRC_ANY = 0x0,
111 	MLX5DR_MATCHER_FLOW_SRC_WIRE = 0x1,
112 	MLX5DR_MATCHER_FLOW_SRC_VPORT = 0x2,
113 };
114 
115 enum mlx5dr_matcher_insert_mode {
116 	MLX5DR_MATCHER_INSERT_BY_HASH = 0x0,
117 	MLX5DR_MATCHER_INSERT_BY_INDEX = 0x1,
118 };
119 
120 enum mlx5dr_matcher_distribute_mode {
121 	MLX5DR_MATCHER_DISTRIBUTE_BY_HASH = 0x0,
122 	MLX5DR_MATCHER_DISTRIBUTE_BY_LINEAR = 0x1,
123 };
124 
125 enum mlx5dr_rule_hash_calc_mode {
126 	MLX5DR_RULE_HASH_CALC_MODE_RAW,
127 	MLX5DR_RULE_HASH_CALC_MODE_IDX,
128 };
129 
130 struct mlx5dr_matcher_attr {
131 	/* Processing priority inside table */
132 	uint32_t priority;
133 	/* Provide all rules with unique rule_idx in num_log range to reduce locking */
134 	bool optimize_using_rule_idx;
135 	/* Resource mode and corresponding size */
136 	enum mlx5dr_matcher_resource_mode mode;
137 	/* Optimize insertion in case packet origin is the same for all rules */
138 	enum mlx5dr_matcher_flow_src optimize_flow_src;
139 	/* Define the insertion and distribution modes for this matcher */
140 	enum mlx5dr_matcher_insert_mode insert_mode;
141 	enum mlx5dr_matcher_distribute_mode distribute_mode;
142 	union {
143 		struct {
144 			uint8_t sz_row_log;
145 			uint8_t sz_col_log;
146 		} table;
147 
148 		struct {
149 			uint8_t num_log;
150 		} rule;
151 	};
152 	/* Optional AT attach configuration - Max number of additional AT */
153 	uint8_t max_num_of_at_attach;
154 };
155 
156 struct mlx5dr_rule_attr {
157 	uint16_t queue_id;
158 	void *user_data;
159 	/* Valid if matcher optimize_using_rule_idx is set or
160 	 * if matcher is configured to insert rules by index.
161 	 */
162 	uint32_t rule_idx;
163 	uint32_t burst:1;
164 };
165 
166 struct mlx5dr_devx_obj {
167 	struct mlx5dv_devx_obj *obj;
168 	uint32_t id;
169 };
170 
171 struct mlx5dr_action_reformat_header {
172 	size_t sz;
173 	void *data;
174 };
175 
176 struct mlx5dr_action_insert_header {
177 	struct mlx5dr_action_reformat_header hdr;
178 	/* PRM start anchor to which header will be inserted */
179 	uint8_t anchor;
180 	/* Header insertion offset in bytes, from the start
181 	 * anchor to the location where new header will be inserted.
182 	 */
183 	uint8_t offset;
184 	/* Indicates this header insertion adds encapsulation header to the packet,
185 	 * requiring device to update offloaded fields (for example IPv4 total length).
186 	 */
187 	bool encap;
188 };
189 
190 enum mlx5dr_action_remove_header_type {
191 	MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_OFFSET,
192 	MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER,
193 };
194 
195 struct mlx5dr_action_remove_header_attr {
196 	enum mlx5dr_action_remove_header_type type;
197 	union {
198 		struct {
199 			/* PRM start anchor from which header will be removed */
200 			uint8_t start_anchor;
201 			/* PRM end anchor till which header will be removed */
202 			uint8_t end_anchor;
203 			bool decap;
204 		} by_anchor;
205 		struct {
206 			/* PRM start anchor from which header will be removed */
207 			uint8_t start_anchor;
208 			uint8_t size;
209 		} by_offset;
210 	};
211 };
212 
213 struct mlx5dr_action_mh_pattern {
214 	/* Byte size of modify actions provided by "data" */
215 	size_t sz;
216 	/* PRM format modify actions pattern */
217 	__be64 *data;
218 };
219 
220 /* In actions that take offset, the offset is unique, pointing to a single
221  * resource and the user should not reuse the same index because data changing
222  * is not atomic.
223  */
224 struct mlx5dr_rule_action {
225 	struct mlx5dr_action *action;
226 	union {
227 		struct {
228 			uint32_t value;
229 		} tag;
230 
231 		struct {
232 			uint32_t offset;
233 		} counter;
234 
235 		struct {
236 			uint32_t offset;
237 			uint8_t pattern_idx;
238 			uint8_t *data;
239 		} modify_header;
240 
241 		struct {
242 			uint32_t offset;
243 			uint8_t hdr_idx;
244 			uint8_t *data;
245 		} reformat;
246 
247 		struct {
248 			uint32_t offset;
249 			uint8_t *header;
250 		} ipv6_ext;
251 
252 		struct {
253 			rte_be32_t vlan_hdr;
254 		} push_vlan;
255 
256 		struct {
257 			uint32_t offset;
258 			enum mlx5dr_action_aso_meter_color init_color;
259 		} aso_meter;
260 
261 		struct {
262 			uint32_t offset;
263 			enum mlx5dr_action_aso_ct_flags direction;
264 		} aso_ct;
265 	};
266 };
267 
268 struct mlx5dr_action_dest_attr {
269 	/* Required action combination */
270 	enum mlx5dr_action_type *action_type;
271 
272 	/* Required destination action to forward the packet */
273 	struct mlx5dr_action *dest;
274 
275 	/* Optional reformat data */
276 	struct {
277 		size_t reformat_data_sz;
278 		void *reformat_data;
279 	} reformat;
280 };
281 
282 union mlx5dr_crc_encap_entropy_hash_ip_field {
283 	uint8_t  ipv6_addr[16];
284 	struct {
285 		uint8_t  reserved[12];
286 		rte_be32_t  ipv4_addr;
287 	};
288 };
289 
290 struct mlx5dr_crc_encap_entropy_hash_fields {
291 	union mlx5dr_crc_encap_entropy_hash_ip_field dst;
292 	union mlx5dr_crc_encap_entropy_hash_ip_field src;
293 	uint8_t next_protocol;
294 	rte_be16_t dst_port;
295 	rte_be16_t src_port;
296 } __rte_packed;
297 
298 enum mlx5dr_crc_encap_entropy_hash_size {
299 	MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8,
300 	MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16,
301 };
302 
303 /* Open a context used for direct rule insertion using hardware steering.
304  * Each context can contain multiple tables of different types.
305  *
306  * @param[in] ibv_ctx
307  *	The ibv context to used for HWS.
308  * @param[in] attr
309  *	Attributes used for context open.
310  * @return pointer to mlx5dr_context on success NULL otherwise.
311  */
312 struct mlx5dr_context *
313 mlx5dr_context_open(struct ibv_context *ibv_ctx,
314 		    struct mlx5dr_context_attr *attr);
315 
316 /* Close a context used for direct hardware steering.
317  *
318  * @param[in] ctx
319  *	mlx5dr context to close.
320  * @return zero on success non zero otherwise.
321  */
322 int mlx5dr_context_close(struct mlx5dr_context *ctx);
323 
324 /* Create a new direct rule table. Each table can contain multiple matchers.
325  *
326  * @param[in] ctx
327  *	The context in which the new table will be opened.
328  * @param[in] attr
329  *	Attributes used for table creation.
330  * @return pointer to mlx5dr_table on success NULL otherwise.
331  */
332 struct mlx5dr_table *
333 mlx5dr_table_create(struct mlx5dr_context *ctx,
334 		    struct mlx5dr_table_attr *attr);
335 
336 /* Destroy direct rule table.
337  *
338  * @param[in] tbl
339  *	mlx5dr table to destroy.
340  * @return zero on success non zero otherwise.
341  */
342 int mlx5dr_table_destroy(struct mlx5dr_table *tbl);
343 
344 /* Set default miss table for mlx5dr_table by using another mlx5dr_table
345  * Traffic which all table matchers miss will be forwarded to miss table.
346  *
347  * @param[in] tbl
348  *	source mlx5dr table
349  * @param[in] miss_tbl
350  *	target (miss) mlx5dr table, or NULL to remove current miss table
351  * @return zero on success non zero otherwise.
352  */
353 int mlx5dr_table_set_default_miss(struct mlx5dr_table *tbl,
354 				  struct mlx5dr_table *miss_tbl);
355 
356 /* Create new match template based on items mask, the match template
357  * will be used for matcher creation.
358  *
359  * @param[in] items
360  *	Describe the mask for template creation
361  * @param[in] flags
362  *	Template creation flags
363  * @return pointer to mlx5dr_match_template on success NULL otherwise
364  */
365 struct mlx5dr_match_template *
366 mlx5dr_match_template_create(const struct rte_flow_item items[],
367 			     enum mlx5dr_match_template_flags flags);
368 
369 /* Destroy match template.
370  *
371  * @param[in] mt
372  *	Match template to destroy.
373  * @return zero on success non zero otherwise.
374  */
375 int mlx5dr_match_template_destroy(struct mlx5dr_match_template *mt);
376 
377 /* Create new action template based on action_type array, the action template
378  * will be used for matcher creation.
379  *
380  * @param[in] action_type
381  *	An array of actions based on the order of actions which will be provided
382  *	with rule_actions to mlx5dr_rule_create. The last action is marked
383  *	using MLX5DR_ACTION_TYP_LAST.
384  * @return pointer to mlx5dr_action_template on success NULL otherwise
385  */
386 struct mlx5dr_action_template *
387 mlx5dr_action_template_create(const enum mlx5dr_action_type action_type[]);
388 
389 /* Destroy action template.
390  *
391  * @param[in] at
392  *	Action template to destroy.
393  * @return zero on success non zero otherwise.
394  */
395 int mlx5dr_action_template_destroy(struct mlx5dr_action_template *at);
396 
397 /* Create a new direct rule matcher. Each matcher can contain multiple rules.
398  * Matchers on the table will be processed by priority. Matching fields and
399  * mask are described by the match template. In some cases multiple match
400  * templates can be used on the same matcher.
401  *
402  * @param[in] table
403  *	The table in which the new matcher will be opened.
404  * @param[in] mt
405  *	Array of match templates to be used on matcher.
406  * @param[in] num_of_mt
407  *	Number of match templates in mt array.
408  * @param[in] at
409  *	Array of action templates to be used on matcher.
410  * @param[in] num_of_at
411  *	Number of action templates in mt array.
412  * @param[in] attr
413  *	Attributes used for matcher creation.
414  * @return pointer to mlx5dr_matcher on success NULL otherwise.
415  */
416 struct mlx5dr_matcher *
417 mlx5dr_matcher_create(struct mlx5dr_table *table,
418 		      struct mlx5dr_match_template *mt[],
419 		      uint8_t num_of_mt,
420 		      struct mlx5dr_action_template *at[],
421 		      uint8_t num_of_at,
422 		      struct mlx5dr_matcher_attr *attr);
423 
424 /* Destroy direct rule matcher.
425  *
426  * @param[in] matcher
427  *	Matcher to destroy.
428  * @return zero on success non zero otherwise.
429  */
430 int mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher);
431 
432 /* Attach new action template to direct rule matcher.
433  *
434  * @param[in] matcher
435  *	Matcher to attach at to.
436  * @param[in] at
437  *	Action template to be attached to the matcher.
438  * @return zero on success non zero otherwise.
439  */
440 int mlx5dr_matcher_attach_at(struct mlx5dr_matcher *matcher,
441 			     struct mlx5dr_action_template *at);
442 
443 /* Get the size of the rule handle (mlx5dr_rule) to be used on rule creation.
444  *
445  * @return size in bytes of rule handle struct.
446  */
447 size_t mlx5dr_rule_get_handle_size(void);
448 
449 /* Enqueue create rule operation.
450  *
451  * @param[in] matcher
452  *	The matcher in which the new rule will be created.
453  * @param[in] mt_idx
454  *	Match template index to create the match with.
455  * @param[in] items
456  *	The items used for the value matching.
457  * @param[in] rule_actions
458  *	Rule action to be executed on match.
459  * @param[in] at_idx
460  *	Action template index to apply the actions with.
461  * @param[in] num_of_actions
462  *	Number of rule actions.
463  * @param[in] attr
464  *	Rule creation attributes.
465  * @param[in, out] rule_handle
466  *	A valid rule handle. The handle doesn't require any initialization.
467  * @return zero on successful enqueue non zero otherwise.
468  */
469 int mlx5dr_rule_create(struct mlx5dr_matcher *matcher,
470 		       uint8_t mt_idx,
471 		       const struct rte_flow_item items[],
472 		       uint8_t at_idx,
473 		       struct mlx5dr_rule_action rule_actions[],
474 		       struct mlx5dr_rule_attr *attr,
475 		       struct mlx5dr_rule *rule_handle);
476 
477 /* Enqueue destroy rule operation.
478  *
479  * @param[in] rule
480  *	The rule destruction to enqueue.
481  * @param[in] attr
482  *	Rule destruction attributes.
483  * @return zero on successful enqueue non zero otherwise.
484  */
485 int mlx5dr_rule_destroy(struct mlx5dr_rule *rule,
486 			struct mlx5dr_rule_attr *attr);
487 
488 /* Enqueue update actions on an existing rule.
489  *
490  * @param[in, out] rule_handle
491  *	A valid rule handle to update.
492  * @param[in] at_idx
493  *	Action template index to update the actions with.
494  *  @param[in] rule_actions
495  *	Rule action to be executed on match.
496  * @param[in] attr
497  *	Rule update attributes.
498  * @return zero on successful enqueue non zero otherwise.
499  */
500 int mlx5dr_rule_action_update(struct mlx5dr_rule *rule_handle,
501 			      uint8_t at_idx,
502 			      struct mlx5dr_rule_action rule_actions[],
503 			      struct mlx5dr_rule_attr *attr);
504 
505 /* Calculate hash for a given set of items, which indicates rule location in
506  * the hash table.
507  *
508  * @param[in] matcher
509  *	The matcher of the created rule.
510  * @param[in] items
511  *	Matching pattern item definition.
512  * @param[in] mt_idx
513  *	Match template index that the match was created with.
514  * @param[in] mode
515  *	Hash calculation mode
516  * @param[in, out] ret_hash
517  *	Returned calculated hash result
518  * @return zero on success non zero otherwise.
519  */
520 int mlx5dr_rule_hash_calculate(struct mlx5dr_matcher *matcher,
521 			       const struct rte_flow_item items[],
522 			       uint8_t mt_idx,
523 			       enum mlx5dr_rule_hash_calc_mode mode,
524 			       uint32_t *ret_hash);
525 
526 /* Create direct rule drop action.
527  *
528  * @param[in] ctx
529  *	The context in which the new action will be created.
530  * @param[in] flags
531  *	Action creation flags. (enum mlx5dr_action_flags)
532  * @return pointer to mlx5dr_action on success NULL otherwise.
533  */
534 struct mlx5dr_action *
535 mlx5dr_action_create_dest_drop(struct mlx5dr_context *ctx,
536 			       uint32_t flags);
537 
538 /* Create direct rule default miss action.
539  * Defaults are RX: Drop TX: Wire.
540  *
541  * @param[in] ctx
542  *	The context in which the new action will be created.
543  * @param[in] flags
544  *	Action creation flags. (enum mlx5dr_action_flags)
545  * @return pointer to mlx5dr_action on success NULL otherwise.
546  */
547 struct mlx5dr_action *
548 mlx5dr_action_create_default_miss(struct mlx5dr_context *ctx,
549 				  uint32_t flags);
550 
551 /* Create direct rule goto table action.
552  *
553  * @param[in] ctx
554  *	The context in which the new action will be created.
555  * @param[in] tbl
556  *	Destination table.
557  * @param[in] flags
558  *	Action creation flags. (enum mlx5dr_action_flags)
559  * @return pointer to mlx5dr_action on success NULL otherwise.
560  */
561 struct mlx5dr_action *
562 mlx5dr_action_create_dest_table(struct mlx5dr_context *ctx,
563 				struct mlx5dr_table *tbl,
564 				uint32_t flags);
565 
566 /* Create direct rule goto vport action.
567  *
568  * @param[in] ctx
569  *	The context in which the new action will be created.
570  * @param[in] ib_port_num
571  *	Destination ib_port number.
572  * @param[in] flags
573  *	Action creation flags. (enum mlx5dr_action_flags)
574  * @return pointer to mlx5dr_action on success NULL otherwise.
575  */
576 struct mlx5dr_action *
577 mlx5dr_action_create_dest_vport(struct mlx5dr_context *ctx,
578 				uint32_t ib_port_num,
579 				uint32_t flags);
580 
581 /*  Create direct rule goto TIR action.
582  *
583  * @param[in] ctx
584  *	The context in which the new action will be created.
585  * @param[in] obj
586  *	Direct rule TIR devx object.
587  * @param[in] flags
588  *	Action creation flags. (enum mlx5dr_action_flags)
589  * @param[in] is_local
590  *	indicates where the tir object was created, local gvmi or other gvmi
591  * @return pointer to mlx5dr_action on success NULL otherwise.
592  */
593 struct mlx5dr_action *
594 mlx5dr_action_create_dest_tir(struct mlx5dr_context *ctx,
595 			      struct mlx5dr_devx_obj *obj,
596 			      uint32_t flags,
597 			      bool is_local);
598 
599 /* Create direct rule TAG action.
600  *
601  * @param[in] ctx
602  *	The context in which the new action will be created.
603  * @param[in] flags
604  *	Action creation flags. (enum mlx5dr_action_flags)
605  * @return pointer to mlx5dr_action on success NULL otherwise.
606  */
607 struct mlx5dr_action *
608 mlx5dr_action_create_tag(struct mlx5dr_context *ctx,
609 			 uint32_t flags);
610 
611 /* Create direct rule counter action.
612  *
613  * @param[in] ctx
614  *	The context in which the new action will be created.
615  * @param[in] obj
616  *	Direct rule counter devx object.
617  * @param[in] flags
618  *	Action creation flags. (enum mlx5dr_action_flags)
619  * @return pointer to mlx5dr_action on success NULL otherwise.
620  */
621 struct mlx5dr_action *
622 mlx5dr_action_create_counter(struct mlx5dr_context *ctx,
623 			     struct mlx5dr_devx_obj *obj,
624 			     uint32_t flags);
625 
626 /* Create direct rule reformat action.
627  *
628  * @param[in] ctx
629  *	The context in which the new action will be created.
630  * @param[in] reformat_type
631  *	Type of reformat prefixed with MLX5DR_ACTION_TYP_REFORMAT.
632  * @param[in] num_of_hdrs
633  *	Number of provided headers in "hdrs" array.
634  * @param[in] hdrs
635  *	Headers array containing header information.
636  * @param[in] log_bulk_size
637  *	Number of unique values used with this reformat.
638  * @param[in] flags
639  *	Action creation flags. (enum mlx5dr_action_flags)
640  * @return pointer to mlx5dr_action on success NULL otherwise.
641  */
642 struct mlx5dr_action *
643 mlx5dr_action_create_reformat(struct mlx5dr_context *ctx,
644 			      enum mlx5dr_action_type reformat_type,
645 			      uint8_t num_of_hdrs,
646 			      struct mlx5dr_action_reformat_header *hdrs,
647 			      uint32_t log_bulk_size,
648 			      uint32_t flags);
649 
650 /* Create direct rule modify header action.
651  *
652  * @param[in] ctx
653  *	The context in which the new action will be created.
654  * @param[in] num_of_patterns
655  *	Number of provided patterns in "patterns" array.
656  * @param[in] patterns
657  *	Patterns array containing pattern information.
658  * @param[in] log_bulk_size
659  *	Number of unique values used with this pattern.
660  * @param[in] flags
661  *	Action creation flags. (enum mlx5dr_action_flags)
662  * @return pointer to mlx5dr_action on success NULL otherwise.
663  */
664 struct mlx5dr_action *
665 mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx,
666 				   uint8_t num_of_patterns,
667 				   struct mlx5dr_action_mh_pattern *patterns,
668 				   uint32_t log_bulk_size,
669 				   uint32_t flags);
670 
671 /* Create direct rule ASO flow meter action.
672  *
673  * @param[in] ctx
674  *	The context in which the new action will be created.
675  * @param[in] devx_obj
676  *	The DEVX ASO object.
677  * @param[in] return_reg_c
678  *	Copy the ASO object value into this reg_c, after a packet hits a rule with this ASO object.
679  * @param[in] flags
680  *	Action creation flags. (enum mlx5dr_action_flags)
681  * @return pointer to mlx5dr_action on success NULL otherwise.
682  */
683 struct mlx5dr_action *
684 mlx5dr_action_create_aso_meter(struct mlx5dr_context *ctx,
685 			       struct mlx5dr_devx_obj *devx_obj,
686 			       uint8_t return_reg_c,
687 			       uint32_t flags);
688 
689 /* Create direct rule ASO CT action.
690  *
691  * @param[in] ctx
692  *	The context in which the new action will be created.
693  * @param[in] devx_obj
694  *	The DEVX ASO object.
695  * @param[in] return_reg_id
696  *	Copy the ASO object value into this reg_id, after a packet hits a rule with this ASO object.
697  * @param[in] flags
698  *	Action creation flags. (enum mlx5dr_action_flags)
699  * @return pointer to mlx5dr_action on success NULL otherwise.
700  */
701 struct mlx5dr_action *
702 mlx5dr_action_create_aso_ct(struct mlx5dr_context *ctx,
703 			    struct mlx5dr_devx_obj *devx_obj,
704 			    uint8_t return_reg_id,
705 			    uint32_t flags);
706 
707 /* Create direct rule pop vlan action.
708  * @param[in] ctx
709  *	The context in which the new action will be created.
710  * @param[in] flags
711  *	Action creation flags. (enum mlx5dr_action_flags)
712  * @return pointer to mlx5dr_action on success NULL otherwise.
713  */
714 struct mlx5dr_action *
715 mlx5dr_action_create_pop_vlan(struct mlx5dr_context *ctx, uint32_t flags);
716 
717 /* Create direct rule push vlan action.
718  * @param[in] ctx
719  *	The context in which the new action will be created.
720  * @param[in] flags
721  *	Action creation flags. (enum mlx5dr_action_flags)
722  * @return pointer to mlx5dr_action on success NULL otherwise.
723  */
724 struct mlx5dr_action *
725 mlx5dr_action_create_push_vlan(struct mlx5dr_context *ctx, uint32_t flags);
726 
727 /* Create a dest array action, this action can duplicate packets and forward to
728  * multiple destinations in the destination list.
729  * @param[in] ctx
730  *     The context in which the new action will be created.
731  * @param[in] num_dest
732  *     The number of dests attributes.
733  * @param[in] dests
734  *     The destination array. Each contains a destination action and can have
735  *     additional actions.
736  * @param[in] flags
737  *     Action creation flags. (enum mlx5dr_action_flags)
738  * @return pointer to mlx5dr_action on success NULL otherwise.
739  */
740 struct mlx5dr_action *
741 mlx5dr_action_create_dest_array(struct mlx5dr_context *ctx,
742 				size_t num_dest,
743 				struct mlx5dr_action_dest_attr *dests,
744 				uint32_t flags);
745 
746 /* Create dest root table, this action will jump to root table according
747  * the given priority.
748  * @param[in] ctx
749  *	The context in which the new action will be created.
750  * @param[in] priority
751  *	The priority of matcher in the root table to jump to.
752  * @param[in] flags
753  *	Action creation flags. (enum mlx5dr_action_flags).
754  * @return pointer to mlx5dr_action on success NULL otherwise.
755  */
756 struct mlx5dr_action *
757 mlx5dr_action_create_dest_root(struct mlx5dr_context *ctx,
758 				uint16_t priority,
759 				uint32_t flags);
760 
761 /* Create insert header action.
762  *
763  * @param[in] ctx
764  *	The context in which the new action will be created.
765  * @param[in] num_of_hdrs
766  *	Number of provided headers in "hdrs" array.
767  * @param[in] hdrs
768  *	Headers array containing header information.
769  * @param[in] log_bulk_size
770  *	Number of unique values used with this insert header.
771  * @param[in] flags
772  *	Action creation flags. (enum mlx5dr_action_flags)
773  * @return pointer to mlx5dr_action on success NULL otherwise.
774  */
775 struct mlx5dr_action *
776 mlx5dr_action_create_insert_header(struct mlx5dr_context *ctx,
777 				   uint8_t num_of_hdrs,
778 				   struct mlx5dr_action_insert_header *hdrs,
779 				   uint32_t log_bulk_size,
780 				   uint32_t flags);
781 
782 /* Create remove header action.
783  *
784  * @param[in] ctx
785  *	The context in which the new action will be created.
786  * @param[in] attr
787  *	attributes: specifies the remove header type, PRM start anchor and
788  *	the PRM end anchor or the PRM start anchor and remove size in bytes.
789  * @param[in] flags
790  *	Action creation flags. (enum mlx5dr_action_flags)
791  * @return pointer to mlx5dr_action on success NULL otherwise.
792  */
793 struct mlx5dr_action *
794 mlx5dr_action_create_remove_header(struct mlx5dr_context *ctx,
795 				   struct mlx5dr_action_remove_header_attr *attr,
796 				   uint32_t flags);
797 
798 /* Create action to push or remove IPv6 extension header.
799  *
800  * @param[in] ctx
801  *	The context in which the new action will be created.
802  * @param[in] type
803  *	Type of direct rule action: MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT or
804  *	MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT.
805  * @param[in] hdr
806  *	Header for packet reformat.
807  * @param[in] log_bulk_size
808  *	Number of unique values used with this pattern.
809  * @param[in] flags
810  *	Action creation flags. (enum mlx5dr_action_flags)
811  * @return pointer to mlx5dr_action on success NULL otherwise.
812  */
813 struct mlx5dr_action *
814 mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx,
815 				       enum mlx5dr_action_type type,
816 				       struct mlx5dr_action_reformat_header *hdr,
817 				       uint32_t log_bulk_size,
818 				       uint32_t flags);
819 
820 /* Destroy direct rule action.
821  *
822  * @param[in] action
823  *	The action to destroy.
824  * @return zero on success non zero otherwise.
825  */
826 int mlx5dr_action_destroy(struct mlx5dr_action *action);
827 
828 /* Poll queue for rule creation and deletions completions.
829  *
830  * @param[in] ctx
831  *	The context to which the queue belong to.
832  * @param[in] queue_id
833  *	The id of the queue to poll.
834  * @param[in, out] res
835  *	Completion array.
836  * @param[in] res_nb
837  *	Maximum number of results to return.
838  * @return negative number on failure, the number of completions otherwise.
839  */
840 int mlx5dr_send_queue_poll(struct mlx5dr_context *ctx,
841 			   uint16_t queue_id,
842 			   struct rte_flow_op_result res[],
843 			   uint32_t res_nb);
844 
845 /* Perform an action on the queue
846  *
847  * @param[in] ctx
848  *	The context to which the queue belong to.
849  * @param[in] queue_id
850  *	The id of the queue to perform the action on.
851  * @param[in] actions
852  *	Actions to perform on the queue. (enum mlx5dr_send_queue_actions)
853  * @return zero on success non zero otherwise.
854  */
855 int mlx5dr_send_queue_action(struct mlx5dr_context *ctx,
856 			     uint16_t queue_id,
857 			     uint32_t actions);
858 
859 /* Dump HWS info
860  *
861  * @param[in] ctx
862  *	The context which to dump the info from.
863  * @param[in] f
864  *	The file to write the dump to.
865  * @return zero on success non zero otherwise.
866  */
867 int mlx5dr_debug_dump(struct mlx5dr_context *ctx, FILE *f);
868 
869 /* Calculate encap entropy hash value
870  *
871  * @param[in] ctx
872  *	The context to get from it's capabilities the entropy hash type.
873  * @param[in] data
874  *	The fields for the hash calculation.
875  * @param[in] entropy_res
876  *	An array to store the hash value to it.
877  * @param[in] res_size
878  *	The result size.
879  * @return zero on success non zero otherwise.
880  */
881 int mlx5dr_crc_encap_entropy_hash_calc(struct mlx5dr_context *ctx,
882 				       struct mlx5dr_crc_encap_entropy_hash_fields *data,
883 				       uint8_t entropy_res[],
884 				       enum mlx5dr_crc_encap_entropy_hash_size res_size);
885 
886 #endif
887