xref: /dpdk/drivers/net/mlx5/hws/mlx5dr.h (revision e77506397fc8005c5129e22e9e2d15d5876790fd)
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_NAT64,
55 	MLX5DR_ACTION_TYP_JUMP_TO_MATCHER,
56 	MLX5DR_ACTION_TYP_MAX,
57 };
58 
59 enum mlx5dr_action_flags {
60 	MLX5DR_ACTION_FLAG_ROOT_RX = 1 << 0,
61 	MLX5DR_ACTION_FLAG_ROOT_TX = 1 << 1,
62 	MLX5DR_ACTION_FLAG_ROOT_FDB = 1 << 2,
63 	MLX5DR_ACTION_FLAG_HWS_RX = 1 << 3,
64 	MLX5DR_ACTION_FLAG_HWS_TX = 1 << 4,
65 	MLX5DR_ACTION_FLAG_HWS_FDB = 1 << 5,
66 	/* Shared action can be used over a few threads, since data is written
67 	 * only once at the creation of the action.
68 	 */
69 	MLX5DR_ACTION_FLAG_SHARED = 1 << 6,
70 };
71 
72 enum mlx5dr_action_aso_meter_color {
73 	MLX5DR_ACTION_ASO_METER_COLOR_RED = 0x0,
74 	MLX5DR_ACTION_ASO_METER_COLOR_YELLOW = 0x1,
75 	MLX5DR_ACTION_ASO_METER_COLOR_GREEN = 0x2,
76 	MLX5DR_ACTION_ASO_METER_COLOR_UNDEFINED = 0x3,
77 };
78 
79 enum mlx5dr_action_aso_ct_flags {
80 	MLX5DR_ACTION_ASO_CT_DIRECTION_INITIATOR = 0 << 0,
81 	MLX5DR_ACTION_ASO_CT_DIRECTION_RESPONDER = 1 << 0,
82 };
83 
84 enum mlx5dr_match_template_flags {
85 	MLX5DR_MATCH_TEMPLATE_FLAG_NONE = 0,
86 	/* Allow relaxed matching by skipping derived dependent match fields. */
87 	MLX5DR_MATCH_TEMPLATE_FLAG_RELAXED_MATCH = 1,
88 };
89 
90 enum mlx5dr_action_template_flags {
91 	/* Allow relaxed actions order. */
92 	MLX5DR_ACTION_TEMPLATE_FLAG_RELAXED_ORDER = 1 << 0,
93 };
94 
95 enum mlx5dr_send_queue_actions {
96 	/* Start executing all pending queued rules */
97 	MLX5DR_SEND_QUEUE_ACTION_DRAIN_ASYNC = 1 << 0,
98 	/* Start executing all pending queued rules wait till completion */
99 	MLX5DR_SEND_QUEUE_ACTION_DRAIN_SYNC = 1 << 1,
100 };
101 
102 struct mlx5dr_context_attr {
103 	uint16_t queues;
104 	uint16_t queue_size;
105 	size_t initial_log_ste_memory; /* Currently not in use */
106 	/* Optional PD used for allocating resources */
107 	struct ibv_pd *pd;
108 	/* Optional the STC array size for that context */
109 	size_t initial_log_stc_memory;
110 	/* Optional other ctx for resources allocation, all objects will be created on it */
111 	struct ibv_context *shared_ibv_ctx;
112 	bool bwc; /* add support for backward compatible API*/
113 };
114 
115 struct mlx5dr_table_attr {
116 	enum mlx5dr_table_type type;
117 	uint32_t level;
118 };
119 
120 enum mlx5dr_matcher_flow_src {
121 	MLX5DR_MATCHER_FLOW_SRC_ANY = 0x0,
122 	MLX5DR_MATCHER_FLOW_SRC_WIRE = 0x1,
123 	MLX5DR_MATCHER_FLOW_SRC_VPORT = 0x2,
124 };
125 
126 enum mlx5dr_matcher_insert_mode {
127 	MLX5DR_MATCHER_INSERT_BY_HASH = 0x0,
128 	MLX5DR_MATCHER_INSERT_BY_INDEX = 0x1,
129 };
130 
131 enum mlx5dr_matcher_distribute_mode {
132 	MLX5DR_MATCHER_DISTRIBUTE_BY_HASH = 0x0,
133 	MLX5DR_MATCHER_DISTRIBUTE_BY_LINEAR = 0x1,
134 };
135 
136 /* Match mode describes the behavior of the matcher STE's when a packet arrives */
137 enum mlx5dr_matcher_match_mode {
138 	/* Packet arriving at this matcher STE's will match according it's tag and match definer */
139 	MLX5DR_MATCHER_MATCH_MODE_DEFAULT = 0x0,
140 	/* Packet arriving at this matcher STE's will always hit and perform the actions */
141 	MLX5DR_MATCHER_MATCH_MODE_ALWAYS_HIT = 0x1,
142 };
143 
144 enum mlx5dr_rule_hash_calc_mode {
145 	MLX5DR_RULE_HASH_CALC_MODE_RAW,
146 	MLX5DR_RULE_HASH_CALC_MODE_IDX,
147 };
148 
149 struct mlx5dr_matcher_attr {
150 	/* Processing priority inside table */
151 	uint32_t priority;
152 	/* Provide all rules with unique rule_idx in num_log range to reduce locking */
153 	bool optimize_using_rule_idx;
154 	/* Resource mode and corresponding size */
155 	enum mlx5dr_matcher_resource_mode mode;
156 	/* Optimize insertion in case packet origin is the same for all rules */
157 	enum mlx5dr_matcher_flow_src optimize_flow_src;
158 	/* Define the insertion, distribution and match modes for this matcher */
159 	enum mlx5dr_matcher_insert_mode insert_mode;
160 	enum mlx5dr_matcher_distribute_mode distribute_mode;
161 	enum mlx5dr_matcher_match_mode match_mode;
162 	/* Define whether the created matcher supports resizing into a bigger matcher */
163 	bool resizable;
164 	/* This will imply that this matcher is not part of the matchers chain of parent table */
165 	bool isolated;
166 	union {
167 		struct {
168 			uint8_t sz_row_log;
169 			uint8_t sz_col_log;
170 		} table;
171 
172 		struct {
173 			uint8_t num_log;
174 		} rule;
175 	};
176 	/* Optional AT attach configuration - Max number of additional AT */
177 	uint8_t max_num_of_at_attach;
178 };
179 
180 struct mlx5dr_rule_attr {
181 	uint16_t queue_id;
182 	void *user_data;
183 	/* Valid if matcher optimize_using_rule_idx is set or
184 	 * if matcher is configured to insert rules by index.
185 	 */
186 	uint32_t rule_idx;
187 	uint32_t burst:1;
188 };
189 
190 struct mlx5dr_devx_obj {
191 	struct mlx5dv_devx_obj *obj;
192 	uint32_t id;
193 };
194 
195 struct mlx5dr_action_reformat_header {
196 	size_t sz;
197 	void *data;
198 };
199 
200 struct mlx5dr_action_insert_header {
201 	struct mlx5dr_action_reformat_header hdr;
202 	/* PRM start anchor to which header will be inserted */
203 	uint8_t anchor;
204 	/* Header insertion offset in bytes, from the start
205 	 * anchor to the location where new header will be inserted.
206 	 */
207 	uint8_t offset;
208 	/* Indicates this header insertion adds encapsulation header to the packet,
209 	 * requiring device to update offloaded fields (for example IPv4 total length).
210 	 */
211 	bool encap;
212 	/* It must be set when adding ESP header.
213 	 * It's also sets the next_protocol value in the ipsec trailer.
214 	 */
215 	bool push_esp;
216 };
217 
218 enum mlx5dr_action_remove_header_type {
219 	MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_OFFSET,
220 	MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER,
221 };
222 
223 struct mlx5dr_action_remove_header_attr {
224 	enum mlx5dr_action_remove_header_type type;
225 	union {
226 		struct {
227 			/* PRM start anchor from which header will be removed */
228 			uint8_t start_anchor;
229 			/* PRM end anchor till which header will be removed */
230 			uint8_t end_anchor;
231 			bool decap;
232 		} by_anchor;
233 		struct {
234 			/* PRM start anchor from which header will be removed */
235 			uint8_t start_anchor;
236 			uint8_t size;
237 		} by_offset;
238 	};
239 };
240 
241 struct mlx5dr_action_mh_pattern {
242 	/* Byte size of modify actions provided by "data" */
243 	size_t sz;
244 	/* PRM format modify actions pattern */
245 	__be64 *data;
246 };
247 
248 /* In actions that take offset, the offset is unique, pointing to a single
249  * resource and the user should not reuse the same index because data changing
250  * is not atomic.
251  */
252 struct mlx5dr_rule_action {
253 	struct mlx5dr_action *action;
254 	union {
255 		struct {
256 			uint32_t value;
257 		} tag;
258 
259 		struct {
260 			uint32_t offset;
261 		} counter;
262 
263 		struct {
264 			uint32_t offset;
265 			uint8_t pattern_idx;
266 			uint8_t *data;
267 		} modify_header;
268 
269 		struct {
270 			uint32_t offset;
271 			uint8_t hdr_idx;
272 			uint8_t *data;
273 		} reformat;
274 
275 		struct {
276 			uint32_t offset;
277 			uint8_t *header;
278 		} ipv6_ext;
279 
280 		struct {
281 			rte_be32_t vlan_hdr;
282 		} push_vlan;
283 
284 		struct {
285 			uint32_t offset;
286 			enum mlx5dr_action_aso_meter_color init_color;
287 		} aso_meter;
288 
289 		struct {
290 			uint32_t offset;
291 			enum mlx5dr_action_aso_ct_flags direction;
292 		} aso_ct;
293 
294 		struct {
295 			uint32_t offset;
296 		} jump_to_matcher;
297 	};
298 };
299 
300 struct mlx5dr_action_dest_attr {
301 	/* Required action combination */
302 	enum mlx5dr_action_type *action_type;
303 
304 	/* Required destination action to forward the packet */
305 	struct mlx5dr_action *dest;
306 
307 	/* Optional reformat data */
308 	struct {
309 		size_t reformat_data_sz;
310 		void *reformat_data;
311 	} reformat;
312 };
313 
314 enum mlx5dr_action_jump_to_matcher_type {
315 	MLX5DR_ACTION_JUMP_TO_MATCHER_BY_INDEX,
316 };
317 
318 struct mlx5dr_action_jump_to_matcher_attr {
319 	enum mlx5dr_action_jump_to_matcher_type type;
320 	struct mlx5dr_matcher *matcher;
321 };
322 
323 union mlx5dr_crc_encap_entropy_hash_ip_field {
324 	uint8_t  ipv6_addr[16];
325 	struct {
326 		uint8_t  reserved[12];
327 		rte_be32_t  ipv4_addr;
328 	};
329 };
330 
331 struct __rte_packed_begin mlx5dr_crc_encap_entropy_hash_fields {
332 	union mlx5dr_crc_encap_entropy_hash_ip_field dst;
333 	union mlx5dr_crc_encap_entropy_hash_ip_field src;
334 	uint8_t next_protocol;
335 	rte_be16_t dst_port;
336 	rte_be16_t src_port;
337 } __rte_packed_end;
338 
339 enum mlx5dr_crc_encap_entropy_hash_size {
340 	MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8,
341 	MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16,
342 };
343 
344 /* Open a context used for direct rule insertion using hardware steering.
345  * Each context can contain multiple tables of different types.
346  *
347  * @param[in] ibv_ctx
348  *	The ibv context to used for HWS.
349  * @param[in] attr
350  *	Attributes used for context open.
351  * @return pointer to mlx5dr_context on success NULL otherwise.
352  */
353 struct mlx5dr_context *
354 mlx5dr_context_open(struct ibv_context *ibv_ctx,
355 		    struct mlx5dr_context_attr *attr);
356 
357 /* Close a context used for direct hardware steering.
358  *
359  * @param[in] ctx
360  *	mlx5dr context to close.
361  * @return zero on success non zero otherwise.
362  */
363 int mlx5dr_context_close(struct mlx5dr_context *ctx);
364 
365 /* Create a new direct rule table. Each table can contain multiple matchers.
366  *
367  * @param[in] ctx
368  *	The context in which the new table will be opened.
369  * @param[in] attr
370  *	Attributes used for table creation.
371  * @return pointer to mlx5dr_table on success NULL otherwise.
372  */
373 struct mlx5dr_table *
374 mlx5dr_table_create(struct mlx5dr_context *ctx,
375 		    struct mlx5dr_table_attr *attr);
376 
377 /* Destroy direct rule table.
378  *
379  * @param[in] tbl
380  *	mlx5dr table to destroy.
381  * @return zero on success non zero otherwise.
382  */
383 int mlx5dr_table_destroy(struct mlx5dr_table *tbl);
384 
385 /* Set default miss table for mlx5dr_table by using another mlx5dr_table
386  * Traffic which all table matchers miss will be forwarded to miss table.
387  *
388  * @param[in] tbl
389  *	source mlx5dr table
390  * @param[in] miss_tbl
391  *	target (miss) mlx5dr table, or NULL to remove current miss table
392  * @return zero on success non zero otherwise.
393  */
394 int mlx5dr_table_set_default_miss(struct mlx5dr_table *tbl,
395 				  struct mlx5dr_table *miss_tbl);
396 
397 /* Create new match template based on items mask, the match template
398  * will be used for matcher creation.
399  *
400  * @param[in] items
401  *	Describe the mask for template creation
402  * @param[in] flags
403  *	Template creation flags
404  * @return pointer to mlx5dr_match_template on success NULL otherwise
405  */
406 struct mlx5dr_match_template *
407 mlx5dr_match_template_create(const struct rte_flow_item items[],
408 			     enum mlx5dr_match_template_flags flags);
409 
410 /* Destroy match template.
411  *
412  * @param[in] mt
413  *	Match template to destroy.
414  * @return zero on success non zero otherwise.
415  */
416 int mlx5dr_match_template_destroy(struct mlx5dr_match_template *mt);
417 
418 /* Create new action template based on action_type array, the action template
419  * will be used for matcher creation.
420  *
421  * @param[in] action_type
422  *	An array of actions based on the order of actions which will be provided
423  *	with rule_actions to mlx5dr_rule_create. The last action is marked
424  *	using MLX5DR_ACTION_TYP_LAST.
425  * @param[in] flags
426  *	Template creation flags
427  * @return pointer to mlx5dr_action_template on success NULL otherwise
428  */
429 struct mlx5dr_action_template *
430 mlx5dr_action_template_create(const enum mlx5dr_action_type action_type[],
431 			      uint32_t flags);
432 
433 /* Destroy action template.
434  *
435  * @param[in] at
436  *	Action template to destroy.
437  * @return zero on success non zero otherwise.
438  */
439 int mlx5dr_action_template_destroy(struct mlx5dr_action_template *at);
440 
441 /* Create a new direct rule matcher. Each matcher can contain multiple rules.
442  * Matchers on the table will be processed by priority. Matching fields and
443  * mask are described by the match template. In some cases multiple match
444  * templates can be used on the same matcher.
445  *
446  * @param[in] table
447  *	The table in which the new matcher will be opened.
448  * @param[in] mt
449  *	Array of match templates to be used on matcher.
450  * @param[in] num_of_mt
451  *	Number of match templates in mt array.
452  * @param[in] at
453  *	Array of action templates to be used on matcher.
454  * @param[in] num_of_at
455  *	Number of action templates in mt array.
456  * @param[in] attr
457  *	Attributes used for matcher creation.
458  * @return pointer to mlx5dr_matcher on success NULL otherwise.
459  */
460 struct mlx5dr_matcher *
461 mlx5dr_matcher_create(struct mlx5dr_table *table,
462 		      struct mlx5dr_match_template *mt[],
463 		      uint8_t num_of_mt,
464 		      struct mlx5dr_action_template *at[],
465 		      uint8_t num_of_at,
466 		      struct mlx5dr_matcher_attr *attr);
467 
468 /* Destroy direct rule matcher.
469  *
470  * @param[in] matcher
471  *	Matcher to destroy.
472  * @return zero on success non zero otherwise.
473  */
474 int mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher);
475 
476 /* Attach new action template to direct rule matcher.
477  *
478  * @param[in] matcher
479  *	Matcher to attach at to.
480  * @param[in] at
481  *	Action template to be attached to the matcher.
482  * @return zero on success non zero otherwise.
483  */
484 int mlx5dr_matcher_attach_at(struct mlx5dr_matcher *matcher,
485 			     struct mlx5dr_action_template *at);
486 
487 /* Link two matchers and enable moving rules from src matcher to dst matcher.
488  * Both matchers must be in the same table type, must be created with 'resizable'
489  * property, and should have the same characteristics (e.g. same mt, same at).
490  *
491  * It is the user's responsibility to make sure that the dst matcher
492  * was allocated with the appropriate size.
493  *
494  * Once the function is completed, the user is:
495  *  - allowed to move rules from src into dst matcher
496  *  - no longer allowed to insert rules to the src matcher
497  *
498  * The user is always allowed to insert rules to the dst matcher and
499  * to delete rules from any matcher.
500  *
501  * @param[in] src_matcher
502  *	source matcher for moving rules from
503  * @param[in] dst_matcher
504  *	destination matcher for moving rules to
505  * @return zero on successful move, non zero otherwise.
506  */
507 int mlx5dr_matcher_resize_set_target(struct mlx5dr_matcher *src_matcher,
508 				     struct mlx5dr_matcher *dst_matcher);
509 
510 /* Enqueue moving rule operation: moving rule from src matcher to a dst matcher
511  *
512  * @param[in] src_matcher
513  *	matcher that the rule belongs to
514  * @param[in] rule
515  *	the rule to move
516  * @param[in] attr
517  *	rule attributes
518  * @return zero on success, non zero otherwise.
519  */
520 int mlx5dr_matcher_resize_rule_move(struct mlx5dr_matcher *src_matcher,
521 				    struct mlx5dr_rule *rule,
522 				    struct mlx5dr_rule_attr *attr);
523 
524 /* Check matcher ability to update existing rules
525  *
526  * @param[in] matcher
527  *	that the rule belongs to.
528  * @return true when the matcher is updatable false otherwise.
529  */
530 bool mlx5dr_matcher_is_updatable(struct mlx5dr_matcher *matcher);
531 
532 /* Check matcher if might contain rules that need complex structure
533  *
534  * @param[in] matcher
535  *	that the rule belongs to.
536  * @return true when the matcher is contains such rules, false otherwise.
537  */
538 bool mlx5dr_matcher_is_dependent(struct mlx5dr_matcher *matcher);
539 
540 /* Get the size of the rule handle (mlx5dr_rule) to be used on rule creation.
541  *
542  * @return size in bytes of rule handle struct.
543  */
544 size_t mlx5dr_rule_get_handle_size(void);
545 
546 /* Enqueue create rule operation.
547  *
548  * @param[in] matcher
549  *	The matcher in which the new rule will be created.
550  * @param[in] mt_idx
551  *	Match template index to create the match with.
552  * @param[in] items
553  *	The items used for the value matching.
554  * @param[in] rule_actions
555  *	Rule action to be executed on match.
556  * @param[in] at_idx
557  *	Action template index to apply the actions with.
558  * @param[in] num_of_actions
559  *	Number of rule actions.
560  * @param[in] attr
561  *	Rule creation attributes.
562  * @param[in, out] rule_handle
563  *	A valid rule handle. The handle doesn't require any initialization.
564  * @return zero on successful enqueue non zero otherwise.
565  */
566 int mlx5dr_rule_create(struct mlx5dr_matcher *matcher,
567 		       uint8_t mt_idx,
568 		       const struct rte_flow_item items[],
569 		       uint8_t at_idx,
570 		       struct mlx5dr_rule_action rule_actions[],
571 		       struct mlx5dr_rule_attr *attr,
572 		       struct mlx5dr_rule *rule_handle);
573 
574 /* Enqueue destroy rule operation.
575  *
576  * @param[in] rule
577  *	The rule destruction to enqueue.
578  * @param[in] attr
579  *	Rule destruction attributes.
580  * @return zero on successful enqueue non zero otherwise.
581  */
582 int mlx5dr_rule_destroy(struct mlx5dr_rule *rule,
583 			struct mlx5dr_rule_attr *attr);
584 
585 /* Enqueue update actions on an existing rule.
586  *
587  * @param[in, out] rule_handle
588  *	A valid rule handle to update.
589  * @param[in] at_idx
590  *	Action template index to update the actions with.
591  *  @param[in] rule_actions
592  *	Rule action to be executed on match.
593  * @param[in] attr
594  *	Rule update attributes.
595  * @return zero on successful enqueue non zero otherwise.
596  */
597 int mlx5dr_rule_action_update(struct mlx5dr_rule *rule_handle,
598 			      uint8_t at_idx,
599 			      struct mlx5dr_rule_action rule_actions[],
600 			      struct mlx5dr_rule_attr *attr);
601 
602 /* Calculate hash for a given set of items, which indicates rule location in
603  * the hash table.
604  *
605  * @param[in] matcher
606  *	The matcher of the created rule.
607  * @param[in] items
608  *	Matching pattern item definition.
609  * @param[in] mt_idx
610  *	Match template index that the match was created with.
611  * @param[in] mode
612  *	Hash calculation mode
613  * @param[in, out] ret_hash
614  *	Returned calculated hash result
615  * @return zero on success non zero otherwise.
616  */
617 int mlx5dr_rule_hash_calculate(struct mlx5dr_matcher *matcher,
618 			       const struct rte_flow_item items[],
619 			       uint8_t mt_idx,
620 			       enum mlx5dr_rule_hash_calc_mode mode,
621 			       uint32_t *ret_hash);
622 
623 /* Create direct rule drop action.
624  *
625  * @param[in] ctx
626  *	The context in which the new action will be created.
627  * @param[in] flags
628  *	Action creation flags. (enum mlx5dr_action_flags)
629  * @return pointer to mlx5dr_action on success NULL otherwise.
630  */
631 struct mlx5dr_action *
632 mlx5dr_action_create_dest_drop(struct mlx5dr_context *ctx,
633 			       uint32_t flags);
634 
635 /* Create direct rule default miss action.
636  * Defaults are RX: Drop TX: Wire.
637  *
638  * @param[in] ctx
639  *	The context in which the new action will be created.
640  * @param[in] flags
641  *	Action creation flags. (enum mlx5dr_action_flags)
642  * @return pointer to mlx5dr_action on success NULL otherwise.
643  */
644 struct mlx5dr_action *
645 mlx5dr_action_create_default_miss(struct mlx5dr_context *ctx,
646 				  uint32_t flags);
647 
648 /* Create direct rule goto table action.
649  *
650  * @param[in] ctx
651  *	The context in which the new action will be created.
652  * @param[in] tbl
653  *	Destination table.
654  * @param[in] flags
655  *	Action creation flags. (enum mlx5dr_action_flags)
656  * @return pointer to mlx5dr_action on success NULL otherwise.
657  */
658 struct mlx5dr_action *
659 mlx5dr_action_create_dest_table(struct mlx5dr_context *ctx,
660 				struct mlx5dr_table *tbl,
661 				uint32_t flags);
662 
663 /* Create direct rule goto vport action.
664  *
665  * @param[in] ctx
666  *	The context in which the new action will be created.
667  * @param[in] ib_port_num
668  *	Destination ib_port number.
669  * @param[in] flags
670  *	Action creation flags. (enum mlx5dr_action_flags)
671  * @return pointer to mlx5dr_action on success NULL otherwise.
672  */
673 struct mlx5dr_action *
674 mlx5dr_action_create_dest_vport(struct mlx5dr_context *ctx,
675 				uint32_t ib_port_num,
676 				uint32_t flags);
677 
678 /*  Create direct rule goto TIR action.
679  *
680  * @param[in] ctx
681  *	The context in which the new action will be created.
682  * @param[in] obj
683  *	Direct rule TIR devx object.
684  * @param[in] flags
685  *	Action creation flags. (enum mlx5dr_action_flags)
686  * @param[in] is_local
687  *	indicates where the tir object was created, local gvmi or other gvmi
688  * @return pointer to mlx5dr_action on success NULL otherwise.
689  */
690 struct mlx5dr_action *
691 mlx5dr_action_create_dest_tir(struct mlx5dr_context *ctx,
692 			      struct mlx5dr_devx_obj *obj,
693 			      uint32_t flags,
694 			      bool is_local);
695 
696 /* Create direct rule TAG action.
697  *
698  * @param[in] ctx
699  *	The context in which the new action will be created.
700  * @param[in] flags
701  *	Action creation flags. (enum mlx5dr_action_flags)
702  * @return pointer to mlx5dr_action on success NULL otherwise.
703  */
704 struct mlx5dr_action *
705 mlx5dr_action_create_tag(struct mlx5dr_context *ctx,
706 			 uint32_t flags);
707 
708 /* Create direct rule LAST action.
709  *
710  * @param[in] ctx
711  *	The context in which the new action will be created.
712  * @param[in] flags
713  *	Action creation flags. (enum mlx5dr_action_flags)
714  * @return pointer to mlx5dr_action on success NULL otherwise.
715  */
716 struct mlx5dr_action *
717 mlx5dr_action_create_last(struct mlx5dr_context *ctx,
718 			  uint32_t flags);
719 
720 /* Create direct rule counter action.
721  *
722  * @param[in] ctx
723  *	The context in which the new action will be created.
724  * @param[in] obj
725  *	Direct rule counter devx object.
726  * @param[in] flags
727  *	Action creation flags. (enum mlx5dr_action_flags)
728  * @return pointer to mlx5dr_action on success NULL otherwise.
729  */
730 struct mlx5dr_action *
731 mlx5dr_action_create_counter(struct mlx5dr_context *ctx,
732 			     struct mlx5dr_devx_obj *obj,
733 			     uint32_t flags);
734 
735 /* Create direct rule reformat action.
736  *
737  * @param[in] ctx
738  *	The context in which the new action will be created.
739  * @param[in] reformat_type
740  *	Type of reformat prefixed with MLX5DR_ACTION_TYP_REFORMAT.
741  * @param[in] num_of_hdrs
742  *	Number of provided headers in "hdrs" array.
743  * @param[in] hdrs
744  *	Headers array containing header information.
745  * @param[in] log_bulk_size
746  *	Number of unique values used with this reformat.
747  * @param[in] flags
748  *	Action creation flags. (enum mlx5dr_action_flags)
749  * @return pointer to mlx5dr_action on success NULL otherwise.
750  */
751 struct mlx5dr_action *
752 mlx5dr_action_create_reformat(struct mlx5dr_context *ctx,
753 			      enum mlx5dr_action_type reformat_type,
754 			      uint8_t num_of_hdrs,
755 			      struct mlx5dr_action_reformat_header *hdrs,
756 			      uint32_t log_bulk_size,
757 			      uint32_t flags);
758 
759 /* Create direct rule modify header action.
760  *
761  * @param[in] ctx
762  *	The context in which the new action will be created.
763  * @param[in] num_of_patterns
764  *	Number of provided patterns in "patterns" array.
765  * @param[in] patterns
766  *	Patterns array containing pattern information.
767  * @param[in] log_bulk_size
768  *	Number of unique values used with this pattern.
769  * @param[in] flags
770  *	Action creation flags. (enum mlx5dr_action_flags)
771  * @return pointer to mlx5dr_action on success NULL otherwise.
772  */
773 struct mlx5dr_action *
774 mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx,
775 				   uint8_t num_of_patterns,
776 				   struct mlx5dr_action_mh_pattern *patterns,
777 				   uint32_t log_bulk_size,
778 				   uint32_t flags);
779 
780 /* Create direct rule ASO flow meter action.
781  *
782  * @param[in] ctx
783  *	The context in which the new action will be created.
784  * @param[in] devx_obj
785  *	The DEVX ASO object.
786  * @param[in] return_reg_c
787  *	Copy the ASO object value into this reg_c, after a packet hits a rule with this ASO object.
788  * @param[in] flags
789  *	Action creation flags. (enum mlx5dr_action_flags)
790  * @return pointer to mlx5dr_action on success NULL otherwise.
791  */
792 struct mlx5dr_action *
793 mlx5dr_action_create_aso_meter(struct mlx5dr_context *ctx,
794 			       struct mlx5dr_devx_obj *devx_obj,
795 			       uint8_t return_reg_c,
796 			       uint32_t flags);
797 
798 /* Create direct rule ASO CT action.
799  *
800  * @param[in] ctx
801  *	The context in which the new action will be created.
802  * @param[in] devx_obj
803  *	The DEVX ASO object.
804  * @param[in] return_reg_id
805  *	Copy the ASO object value into this reg_id, after a packet hits a rule with this ASO object.
806  * @param[in] flags
807  *	Action creation flags. (enum mlx5dr_action_flags)
808  * @return pointer to mlx5dr_action on success NULL otherwise.
809  */
810 struct mlx5dr_action *
811 mlx5dr_action_create_aso_ct(struct mlx5dr_context *ctx,
812 			    struct mlx5dr_devx_obj *devx_obj,
813 			    uint8_t return_reg_id,
814 			    uint32_t flags);
815 
816 /* Create direct rule pop vlan action.
817  * @param[in] ctx
818  *	The context in which the new action will be created.
819  * @param[in] flags
820  *	Action creation flags. (enum mlx5dr_action_flags)
821  * @return pointer to mlx5dr_action on success NULL otherwise.
822  */
823 struct mlx5dr_action *
824 mlx5dr_action_create_pop_vlan(struct mlx5dr_context *ctx, uint32_t flags);
825 
826 /* Create direct rule push vlan action.
827  * @param[in] ctx
828  *	The context in which the new action will be created.
829  * @param[in] flags
830  *	Action creation flags. (enum mlx5dr_action_flags)
831  * @return pointer to mlx5dr_action on success NULL otherwise.
832  */
833 struct mlx5dr_action *
834 mlx5dr_action_create_push_vlan(struct mlx5dr_context *ctx, uint32_t flags);
835 
836 /* Create a dest array action, this action can duplicate packets and forward to
837  * multiple destinations in the destination list.
838  * @param[in] ctx
839  *     The context in which the new action will be created.
840  * @param[in] num_dest
841  *     The number of dests attributes.
842  * @param[in] dests
843  *     The destination array. Each contains a destination action and can have
844  *     additional actions.
845  * @param[in] flags
846  *     Action creation flags. (enum mlx5dr_action_flags)
847  * @return pointer to mlx5dr_action on success NULL otherwise.
848  */
849 struct mlx5dr_action *
850 mlx5dr_action_create_dest_array(struct mlx5dr_context *ctx,
851 				size_t num_dest,
852 				struct mlx5dr_action_dest_attr *dests,
853 				uint32_t flags);
854 
855 /* Create dest root table, this action will jump to root table according
856  * the given priority.
857  * @param[in] ctx
858  *	The context in which the new action will be created.
859  * @param[in] priority
860  *	The priority of matcher in the root table to jump to.
861  * @param[in] flags
862  *	Action creation flags. (enum mlx5dr_action_flags).
863  * @return pointer to mlx5dr_action on success NULL otherwise.
864  */
865 struct mlx5dr_action *
866 mlx5dr_action_create_dest_root(struct mlx5dr_context *ctx,
867 				uint16_t priority,
868 				uint32_t flags);
869 
870 /* Create insert header action.
871  *
872  * @param[in] ctx
873  *	The context in which the new action will be created.
874  * @param[in] num_of_hdrs
875  *	Number of provided headers in "hdrs" array.
876  * @param[in] hdrs
877  *	Headers array containing header information.
878  * @param[in] log_bulk_size
879  *	Number of unique values used with this insert header.
880  * @param[in] flags
881  *	Action creation flags. (enum mlx5dr_action_flags)
882  * @return pointer to mlx5dr_action on success NULL otherwise.
883  */
884 struct mlx5dr_action *
885 mlx5dr_action_create_insert_header(struct mlx5dr_context *ctx,
886 				   uint8_t num_of_hdrs,
887 				   struct mlx5dr_action_insert_header *hdrs,
888 				   uint32_t log_bulk_size,
889 				   uint32_t flags);
890 
891 /* Create remove header action.
892  *
893  * @param[in] ctx
894  *	The context in which the new action will be created.
895  * @param[in] attr
896  *	attributes: specifies the remove header type, PRM start anchor and
897  *	the PRM end anchor or the PRM start anchor and remove size in bytes.
898  * @param[in] flags
899  *	Action creation flags. (enum mlx5dr_action_flags)
900  * @return pointer to mlx5dr_action on success NULL otherwise.
901  */
902 struct mlx5dr_action *
903 mlx5dr_action_create_remove_header(struct mlx5dr_context *ctx,
904 				   struct mlx5dr_action_remove_header_attr *attr,
905 				   uint32_t flags);
906 
907 /* Create action to push or remove IPv6 extension header.
908  *
909  * @param[in] ctx
910  *	The context in which the new action will be created.
911  * @param[in] type
912  *	Type of direct rule action: MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT or
913  *	MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT.
914  * @param[in] hdr
915  *	Header for packet reformat.
916  * @param[in] log_bulk_size
917  *	Number of unique values used with this pattern.
918  * @param[in] flags
919  *	Action creation flags. (enum mlx5dr_action_flags)
920  * @return pointer to mlx5dr_action on success NULL otherwise.
921  */
922 struct mlx5dr_action *
923 mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx,
924 				       enum mlx5dr_action_type type,
925 				       struct mlx5dr_action_reformat_header *hdr,
926 				       uint32_t log_bulk_size,
927 				       uint32_t flags);
928 
929 enum mlx5dr_action_nat64_flags {
930 	MLX5DR_ACTION_NAT64_V4_TO_V6 = 1 << 0,
931 	MLX5DR_ACTION_NAT64_V6_TO_V4 = 1 << 1,
932 	/* Indicates if to backup ipv4 addresses in last two registers */
933 	MLX5DR_ACTION_NAT64_BACKUP_ADDR = 1 << 2,
934 };
935 
936 struct mlx5dr_action_nat64_attr {
937 	uint8_t num_of_registers;
938 	uint8_t *registers;
939 	enum mlx5dr_action_nat64_flags flags;
940 };
941 
942 /* Create direct rule nat64 action.
943  *
944  * @param[in] ctx
945  *	The context in which the new action will be created.
946  * @param[in] attr
947  *	The relevant attribute of the NAT action.
948  * @param[in] flags
949  *	Action creation flags. (enum mlx5dr_action_flags)
950  * @return pointer to mlx5dr_action on success NULL otherwise.
951  */
952 struct mlx5dr_action *
953 mlx5dr_action_create_nat64(struct mlx5dr_context *ctx,
954 			   struct mlx5dr_action_nat64_attr *attr,
955 			   uint32_t flags);
956 
957 /* Create direct rule jump to matcher action.
958  *
959  * @param[in] ctx
960  *	The context in which the new action will be created.
961  * @param[in] attr
962  *	The relevant attribute of the action.
963  * @param[in] flags
964  *	Action creation flags. (enum mlx5dr_action_flags)
965  * @return pointer to mlx5dr_action on success NULL otherwise.
966  */
967 struct mlx5dr_action *
968 mlx5dr_action_create_jump_to_matcher(struct mlx5dr_context *ctx,
969 				     struct mlx5dr_action_jump_to_matcher_attr *attr,
970 				     uint32_t flags);
971 
972 /* Destroy direct rule action.
973  *
974  * @param[in] action
975  *	The action to destroy.
976  * @return zero on success non zero otherwise.
977  */
978 int mlx5dr_action_destroy(struct mlx5dr_action *action);
979 
980 /* Poll queue for rule creation and deletions completions.
981  *
982  * @param[in] ctx
983  *	The context to which the queue belong to.
984  * @param[in] queue_id
985  *	The id of the queue to poll.
986  * @param[in, out] res
987  *	Completion array.
988  * @param[in] res_nb
989  *	Maximum number of results to return.
990  * @return negative number on failure, the number of completions otherwise.
991  */
992 int mlx5dr_send_queue_poll(struct mlx5dr_context *ctx,
993 			   uint16_t queue_id,
994 			   struct rte_flow_op_result res[],
995 			   uint32_t res_nb);
996 
997 /* Perform an action on the queue
998  *
999  * @param[in] ctx
1000  *	The context to which the queue belong to.
1001  * @param[in] queue_id
1002  *	The id of the queue to perform the action on.
1003  * @param[in] actions
1004  *	Actions to perform on the queue. (enum mlx5dr_send_queue_actions)
1005  * @return zero on success non zero otherwise.
1006  */
1007 int mlx5dr_send_queue_action(struct mlx5dr_context *ctx,
1008 			     uint16_t queue_id,
1009 			     uint32_t actions);
1010 
1011 /* Dump HWS info
1012  *
1013  * @param[in] ctx
1014  *	The context which to dump the info from.
1015  * @param[in] f
1016  *	The file to write the dump to.
1017  * @return zero on success non zero otherwise.
1018  */
1019 int mlx5dr_debug_dump(struct mlx5dr_context *ctx, FILE *f);
1020 
1021 /* Calculate encap entropy hash value
1022  *
1023  * @param[in] ctx
1024  *	The context to get from it's capabilities the entropy hash type.
1025  * @param[in] data
1026  *	The fields for the hash calculation.
1027  * @param[in] entropy_res
1028  *	An array to store the hash value to it.
1029  * @param[in] res_size
1030  *	The result size.
1031  * @return zero on success non zero otherwise.
1032  */
1033 int mlx5dr_crc_encap_entropy_hash_calc(struct mlx5dr_context *ctx,
1034 				       struct mlx5dr_crc_encap_entropy_hash_fields *data,
1035 				       uint8_t entropy_res[],
1036 				       enum mlx5dr_crc_encap_entropy_hash_size res_size);
1037 
1038 struct mlx5dr_bwc_matcher;
1039 struct mlx5dr_bwc_rule;
1040 
1041 /* Create a new BWC direct rule matcher.
1042  * This function does the following:
1043  *   - creates match template based on flow items
1044  *   - creates an empty action template
1045  *   - creates a usual mlx5dr_matcher with these mt and at, setting
1046  *     its size to minimal
1047  * Notes:
1048  *   - table->ctx must have BWC support
1049  *   - complex rules are not supported
1050  *
1051  * @param[in] table
1052  *	The table in which the new matcher will be opened
1053  * @param[in] priority
1054  *	Priority for this BWC matcher
1055  * @param[in] flow_items
1056  *	Array of flow items that serve as basis for match and action templates
1057  * @return pointer to mlx5dr_bwc_matcher on success or NULL otherwise.
1058  */
1059 struct mlx5dr_bwc_matcher *
1060 mlx5dr_bwc_matcher_create(struct mlx5dr_table *table,
1061 			  uint32_t priority,
1062 			  const struct rte_flow_item flow_items[]);
1063 
1064 /* Destroy BWC direct rule matcher.
1065  *
1066  * @param[in] bwc_matcher
1067  *	Matcher to destroy
1068  * @return zero on success, non zero otherwise
1069  */
1070 int mlx5dr_bwc_matcher_destroy(struct mlx5dr_bwc_matcher *bwc_matcher);
1071 
1072 /* Create a new BWC rule.
1073  * Unlike the usual rule creation function, this one is blocking: when the
1074  * function returns, the rule is written to its place (no need to poll).
1075  * This function does the following:
1076  *   - finds matching action template based on the provided rule_actions, or
1077  *     creates new action template if matching action template doesn't exist
1078  *   - updates corresponding BWC matcher stats
1079  *   - if needed, the function performs rehash:
1080  *       - creates a new matcher based on mt, at, new_sz
1081  *       - moves all the existing matcher rules to the new matcher
1082  *       - removes the old matcher
1083  *   - inserts new rule
1084  *   - polls till completion is received
1085  * Notes:
1086  *   - matcher->tbl->ctx must have BWC support
1087  *   - separate BWC ctx queues are used
1088  *
1089  * @param[in] bwc_matcher
1090  *	The BWC matcher in which the new rule will be created.
1091  * @param[in] flow_items
1092  *	Flow items to be used for the value matching
1093  * @param[in] rule_actions
1094  *	Rule action to be executed on match
1095  * @param[in, out] rule_handle
1096  *	A valid rule handle. The handle doesn't require any initialization
1097  * @return valid BWC rule handle on success, NULL otherwise
1098  */
1099 struct mlx5dr_bwc_rule *
1100 mlx5dr_bwc_rule_create(struct mlx5dr_bwc_matcher *bwc_matcher,
1101 		       const struct rte_flow_item flow_items[],
1102 		       struct mlx5dr_rule_action rule_actions[]);
1103 
1104 /* Destroy BWC direct rule.
1105  *
1106  * @param[in] bwc_rule
1107  *	Rule to destroy
1108  * @return zero on success, non zero otherwise
1109  */
1110 int mlx5dr_bwc_rule_destroy(struct mlx5dr_bwc_rule *bwc_rule);
1111 
1112 #endif
1113