1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2024 NVIDIA Corporation & Affiliates */
3 
4 #ifndef MLX5HWS_H_
5 #define MLX5HWS_H_
6 
7 struct mlx5hws_context;
8 struct mlx5hws_table;
9 struct mlx5hws_matcher;
10 struct mlx5hws_rule;
11 
12 enum mlx5hws_table_type {
13 	MLX5HWS_TABLE_TYPE_FDB,
14 	MLX5HWS_TABLE_TYPE_MAX,
15 };
16 
17 enum mlx5hws_matcher_resource_mode {
18 	/* Allocate resources based on number of rules with minimal failure probability */
19 	MLX5HWS_MATCHER_RESOURCE_MODE_RULE,
20 	/* Allocate fixed size hash table based on given column and rows */
21 	MLX5HWS_MATCHER_RESOURCE_MODE_HTABLE,
22 };
23 
24 enum mlx5hws_action_type {
25 	MLX5HWS_ACTION_TYP_LAST,
26 	MLX5HWS_ACTION_TYP_REFORMAT_TNL_L2_TO_L2,
27 	MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L2,
28 	MLX5HWS_ACTION_TYP_REFORMAT_TNL_L3_TO_L2,
29 	MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L3,
30 	MLX5HWS_ACTION_TYP_DROP,
31 	MLX5HWS_ACTION_TYP_MISS,
32 	MLX5HWS_ACTION_TYP_TBL,
33 	MLX5HWS_ACTION_TYP_CTR,
34 	MLX5HWS_ACTION_TYP_TAG,
35 	MLX5HWS_ACTION_TYP_MODIFY_HDR,
36 	MLX5HWS_ACTION_TYP_VPORT,
37 	MLX5HWS_ACTION_TYP_POP_VLAN,
38 	MLX5HWS_ACTION_TYP_PUSH_VLAN,
39 	MLX5HWS_ACTION_TYP_ASO_METER,
40 	MLX5HWS_ACTION_TYP_INSERT_HEADER,
41 	MLX5HWS_ACTION_TYP_REMOVE_HEADER,
42 	MLX5HWS_ACTION_TYP_RANGE,
43 	MLX5HWS_ACTION_TYP_SAMPLER,
44 	MLX5HWS_ACTION_TYP_DEST_ARRAY,
45 	MLX5HWS_ACTION_TYP_MAX,
46 };
47 
48 enum mlx5hws_action_flags {
49 	MLX5HWS_ACTION_FLAG_HWS_FDB = 1 << 0,
50 	/* Shared action can be used over a few threads, since the
51 	 * data is written only once at the creation of the action.
52 	 */
53 	MLX5HWS_ACTION_FLAG_SHARED = 1 << 1,
54 };
55 
56 enum mlx5hws_action_aso_meter_color {
57 	MLX5HWS_ACTION_ASO_METER_COLOR_RED = 0x0,
58 	MLX5HWS_ACTION_ASO_METER_COLOR_YELLOW = 0x1,
59 	MLX5HWS_ACTION_ASO_METER_COLOR_GREEN = 0x2,
60 	MLX5HWS_ACTION_ASO_METER_COLOR_UNDEFINED = 0x3,
61 };
62 
63 enum mlx5hws_send_queue_actions {
64 	/* Start executing all pending queued rules */
65 	MLX5HWS_SEND_QUEUE_ACTION_DRAIN_ASYNC = 1 << 0,
66 	/* Start executing all pending queued rules wait till completion */
67 	MLX5HWS_SEND_QUEUE_ACTION_DRAIN_SYNC = 1 << 1,
68 };
69 
70 struct mlx5hws_context_attr {
71 	u16 queues;
72 	u16 queue_size;
73 };
74 
75 struct mlx5hws_table_attr {
76 	enum mlx5hws_table_type type;
77 	u32 level;
78 };
79 
80 enum mlx5hws_matcher_flow_src {
81 	MLX5HWS_MATCHER_FLOW_SRC_ANY = 0x0,
82 	MLX5HWS_MATCHER_FLOW_SRC_WIRE = 0x1,
83 	MLX5HWS_MATCHER_FLOW_SRC_VPORT = 0x2,
84 };
85 
86 enum mlx5hws_matcher_insert_mode {
87 	MLX5HWS_MATCHER_INSERT_BY_HASH = 0x0,
88 	MLX5HWS_MATCHER_INSERT_BY_INDEX = 0x1,
89 };
90 
91 enum mlx5hws_matcher_distribute_mode {
92 	MLX5HWS_MATCHER_DISTRIBUTE_BY_HASH = 0x0,
93 	MLX5HWS_MATCHER_DISTRIBUTE_BY_LINEAR = 0x1,
94 };
95 
96 struct mlx5hws_matcher_attr {
97 	/* Processing priority inside table */
98 	u32 priority;
99 	/* Provide all rules with unique rule_idx in num_log range to reduce locking */
100 	bool optimize_using_rule_idx;
101 	/* Resource mode and corresponding size */
102 	enum mlx5hws_matcher_resource_mode mode;
103 	/* Optimize insertion in case packet origin is the same for all rules */
104 	enum mlx5hws_matcher_flow_src optimize_flow_src;
105 	/* Define the insertion and distribution modes for this matcher */
106 	enum mlx5hws_matcher_insert_mode insert_mode;
107 	enum mlx5hws_matcher_distribute_mode distribute_mode;
108 	/* Define whether the created matcher supports resizing into a bigger matcher */
109 	bool resizable;
110 	union {
111 		struct {
112 			u8 sz_row_log;
113 			u8 sz_col_log;
114 		} table;
115 
116 		struct {
117 			u8 num_log;
118 		} rule;
119 	};
120 	/* Optional AT attach configuration - Max number of additional AT */
121 	u8 max_num_of_at_attach;
122 };
123 
124 struct mlx5hws_rule_attr {
125 	void *user_data;
126 	/* Valid if matcher optimize_using_rule_idx is set or
127 	 * if matcher is configured to insert rules by index.
128 	 */
129 	u32 rule_idx;
130 	u32 flow_source;
131 	u16 queue_id;
132 	u32 burst:1;
133 };
134 
135 /* In actions that take offset, the offset is unique, pointing to a single
136  * resource and the user should not reuse the same index because data changing
137  * is not atomic.
138  */
139 struct mlx5hws_rule_action {
140 	struct mlx5hws_action *action;
141 	union {
142 		struct {
143 			u32 value;
144 		} tag;
145 
146 		struct {
147 			u32 offset;
148 		} counter;
149 
150 		struct {
151 			u32 offset;
152 			u8 *data;
153 		} modify_header;
154 
155 		struct {
156 			u32 offset;
157 			u8 hdr_idx;
158 			u8 *data;
159 		} reformat;
160 
161 		struct {
162 			__be32 vlan_hdr;
163 		} push_vlan;
164 
165 		struct {
166 			u32 offset;
167 			enum mlx5hws_action_aso_meter_color init_color;
168 		} aso_meter;
169 	};
170 };
171 
172 struct mlx5hws_action_reformat_header {
173 	size_t sz;
174 	void *data;
175 };
176 
177 struct mlx5hws_action_insert_header {
178 	struct mlx5hws_action_reformat_header hdr;
179 	/* PRM start anchor to which header will be inserted */
180 	u8 anchor;
181 	/* Header insertion offset in bytes, from the start
182 	 * anchor to the location where new header will be inserted.
183 	 */
184 	u8 offset;
185 	/* Indicates this header insertion adds encapsulation header to the packet,
186 	 * requiring device to update offloaded fields (for example IPv4 total length).
187 	 */
188 	bool encap;
189 };
190 
191 struct mlx5hws_action_remove_header_attr {
192 	/* PRM start anchor from which header will be removed */
193 	u8 anchor;
194 	/* Header remove offset in bytes, from the start
195 	 * anchor to the location where remove header starts.
196 	 */
197 	u8 offset;
198 	/* Indicates the removed header size in bytes */
199 	size_t size;
200 };
201 
202 struct mlx5hws_action_mh_pattern {
203 	/* Byte size of modify actions provided by "data" */
204 	size_t sz;
205 	/* PRM format modify actions pattern */
206 	__be64 *data;
207 };
208 
209 struct mlx5hws_action_dest_attr {
210 	/* Required destination action to forward the packet */
211 	struct mlx5hws_action *dest;
212 	/* Optional reformat action */
213 	struct mlx5hws_action *reformat;
214 };
215 
216 /**
217  * mlx5hws_is_supported - Check whether HWS is supported
218  *
219  * @mdev: The device to check.
220  *
221  * Return: true if supported, false otherwise.
222  */
mlx5hws_is_supported(struct mlx5_core_dev * mdev)223 static inline bool mlx5hws_is_supported(struct mlx5_core_dev *mdev)
224 {
225 	u8 ignore_flow_level_rtc_valid;
226 	u8 wqe_based_flow_table_update;
227 
228 	wqe_based_flow_table_update =
229 		MLX5_CAP_GEN(mdev, wqe_based_flow_table_update_cap);
230 	ignore_flow_level_rtc_valid =
231 		MLX5_CAP_FLOWTABLE(mdev,
232 				   flow_table_properties_nic_receive.ignore_flow_level_rtc_valid);
233 
234 	return wqe_based_flow_table_update && ignore_flow_level_rtc_valid;
235 }
236 
237 /**
238  * mlx5hws_context_open - Open a context used for direct rule insertion
239  * using hardware steering.
240  *
241  * @mdev: The device to be used for HWS.
242  * @attr: Attributes used for context open.
243  *
244  * Return: pointer to mlx5hws_context on success NULL otherwise.
245  */
246 struct mlx5hws_context *
247 mlx5hws_context_open(struct mlx5_core_dev *mdev,
248 		     struct mlx5hws_context_attr *attr);
249 
250 /**
251  * mlx5hws_context_close - Close a context used for direct hardware steering.
252  *
253  * @ctx: mlx5hws context to close.
254  *
255  * Return: zero on success non zero otherwise.
256  */
257 int mlx5hws_context_close(struct mlx5hws_context *ctx);
258 
259 /**
260  * mlx5hws_context_set_peer - Set a peer context.
261  * Each context can have multiple contexts as peers.
262  *
263  * @ctx: The context in which the peer_ctx will be peered to it.
264  * @peer_ctx: The peer context.
265  * @peer_vhca_id: The peer context vhca id.
266  */
267 void mlx5hws_context_set_peer(struct mlx5hws_context *ctx,
268 			      struct mlx5hws_context *peer_ctx,
269 			      u16 peer_vhca_id);
270 
271 /**
272  * mlx5hws_table_create - Create a new direct rule table.
273  * Each table can contain multiple matchers.
274  *
275  * @ctx: The context in which the new table will be opened.
276  * @attr: Attributes used for table creation.
277  *
278  * Return: pointer to mlx5hws_table on success NULL otherwise.
279  */
280 struct mlx5hws_table *
281 mlx5hws_table_create(struct mlx5hws_context *ctx,
282 		     struct mlx5hws_table_attr *attr);
283 
284 /**
285  * mlx5hws_table_destroy - Destroy direct rule table.
286  *
287  * @tbl: Table to destroy.
288  *
289  * Return: zero on success non zero otherwise.
290  */
291 int mlx5hws_table_destroy(struct mlx5hws_table *tbl);
292 
293 /**
294  * mlx5hws_table_get_id() - Get ID of the flow table.
295  *
296  * @tbl:Table to get ID of.
297  *
298  * Return: ID of the table.
299  */
300 u32 mlx5hws_table_get_id(struct mlx5hws_table *tbl);
301 
302 /**
303  * mlx5hws_table_set_default_miss - Set default miss table for mlx5hws_table
304  * by using another mlx5hws_table.
305  * Traffic which all table matchers miss will be forwarded to miss table.
306  *
307  * @tbl: Source table
308  * @miss_tbl: Target (miss) table, or NULL to remove current miss table
309  *
310  * Return: zero on success non zero otherwise.
311  */
312 int mlx5hws_table_set_default_miss(struct mlx5hws_table *tbl,
313 				   struct mlx5hws_table *miss_tbl);
314 
315 /**
316  * mlx5hws_match_template_create - Create a new match template based on items mask.
317  * The match template will be used for matcher creation.
318  *
319  * @ctx: The context in which the new template will be created.
320  * @match_param: Describe the mask based on PRM match parameters.
321  * @match_param_sz: Size of match param buffer.
322  * @match_criteria_enable: Bitmap for each sub-set in match_criteria buffer.
323  *
324  * Return: Pointer to mlx5hws_match_template on success, NULL otherwise.
325  */
326 struct mlx5hws_match_template *
327 mlx5hws_match_template_create(struct mlx5hws_context *ctx,
328 			      u32 *match_param,
329 			      u32 match_param_sz,
330 			      u8 match_criteria_enable);
331 
332 /**
333  * mlx5hws_match_template_destroy - Destroy a match template.
334  *
335  * @mt: Match template to destroy.
336  *
337  * Return: Zero on success, non-zero otherwise.
338  */
339 int mlx5hws_match_template_destroy(struct mlx5hws_match_template *mt);
340 
341 /**
342  * mlx5hws_action_template_create - Create a new action template based on an action_type array.
343  *
344  * @action_type: An array of actions based on the order of actions which will be provided
345  *               with rule_actions to mlx5hws_rule_create. The last action is marked
346  *               using MLX5HWS_ACTION_TYP_LAST.
347  *
348  * Return: Pointer to mlx5hws_action_template on success, NULL otherwise.
349  */
350 struct mlx5hws_action_template *
351 mlx5hws_action_template_create(enum mlx5hws_action_type action_type[]);
352 
353 /**
354  * mlx5hws_action_template_destroy - Destroy action template.
355  *
356  * @at: Action template to destroy.
357  *
358  * Return: zero on success non zero otherwise.
359  */
360 int mlx5hws_action_template_destroy(struct mlx5hws_action_template *at);
361 
362 /**
363  * mlx5hws_matcher_create - Create a new direct rule matcher.
364  *
365  * Each matcher can contain multiple rules. Matchers on the table will be
366  * processed by priority. Matching fields and mask are described by the
367  * match template. In some cases, multiple match templates can be used on
368  * the same matcher.
369  *
370  * @table: The table in which the new matcher will be opened.
371  * @mt: Array of match templates to be used on matcher.
372  * @num_of_mt: Number of match templates in mt array.
373  * @at: Array of action templates to be used on matcher.
374  * @num_of_at: Number of action templates in at array.
375  * @attr: Attributes used for matcher creation.
376  *
377  * Return: Pointer to mlx5hws_matcher on success, NULL otherwise.
378  *
379  */
380 struct mlx5hws_matcher *
381 mlx5hws_matcher_create(struct mlx5hws_table *table,
382 		       struct mlx5hws_match_template *mt[],
383 		       u8 num_of_mt,
384 		       struct mlx5hws_action_template *at[],
385 		       u8 num_of_at,
386 		       struct mlx5hws_matcher_attr *attr);
387 
388 /**
389  * mlx5hws_matcher_destroy - Destroy a direct rule matcher.
390  *
391  * @matcher: Matcher to destroy.
392  *
393  * Return: Zero on success, non-zero otherwise.
394  */
395 int mlx5hws_matcher_destroy(struct mlx5hws_matcher *matcher);
396 
397 /**
398  * mlx5hws_matcher_attach_at - Attach a new action template to a direct rule matcher.
399  *
400  * @matcher: Matcher to attach the action template to.
401  * @at: Action template to be attached to the matcher.
402  *
403  * Return: Zero on success, non-zero otherwise.
404  */
405 int mlx5hws_matcher_attach_at(struct mlx5hws_matcher *matcher,
406 			      struct mlx5hws_action_template *at);
407 
408 /**
409  * mlx5hws_matcher_resize_set_target - Link two matchers and enable moving rules.
410  *
411  * Both matchers must be in the same table type, must be created with the
412  * 'resizable' property, and should have the same characteristics (e.g., same
413  * match templates and action templates). It is the user's responsibility to
414  * ensure that the destination matcher is allocated with the appropriate size.
415  *
416  * Once the function is completed, the user is:
417  * - Allowed to move rules from the source into the destination matcher.
418  * - No longer allowed to insert rules into the source matcher.
419  *
420  * The user is always allowed to insert rules into the destination matcher and
421  * to delete rules from any matcher.
422  *
423  * @src_matcher: Source matcher for moving rules from.
424  * @dst_matcher: Destination matcher for moving rules to.
425  *
426  * Return: Zero on successful move, non-zero otherwise.
427  */
428 int mlx5hws_matcher_resize_set_target(struct mlx5hws_matcher *src_matcher,
429 				      struct mlx5hws_matcher *dst_matcher);
430 
431 /**
432  * mlx5hws_matcher_resize_rule_move - Enqueue moving rule operation.
433  *
434  * This function enqueues the operation of moving a rule from the source
435  * matcher to the destination matcher.
436  *
437  * @src_matcher: Matcher that the rule belongs to.
438  * @rule: The rule to move.
439  * @attr: Rule attributes.
440  *
441  * Return: Zero on success, non-zero otherwise.
442  */
443 int mlx5hws_matcher_resize_rule_move(struct mlx5hws_matcher *src_matcher,
444 				     struct mlx5hws_rule *rule,
445 				     struct mlx5hws_rule_attr *attr);
446 
447 /**
448  * mlx5hws_rule_create - Enqueue create rule operation.
449  *
450  * @matcher: The matcher in which the new rule will be created.
451  * @mt_idx: Match template index to create the match with.
452  * @match_param: The match parameter PRM buffer used for value matching.
453  * @at_idx: Action template index to apply the actions with.
454  * @rule_actions: Rule actions to be executed on match.
455  * @attr: Rule creation attributes.
456  * @rule_handle: A valid rule handle. The handle doesn't require any initialization.
457  *
458  * Return: Zero on successful enqueue, non-zero otherwise.
459  */
460 int mlx5hws_rule_create(struct mlx5hws_matcher *matcher,
461 			u8 mt_idx,
462 			u32 *match_param,
463 			u8 at_idx,
464 			struct mlx5hws_rule_action rule_actions[],
465 			struct mlx5hws_rule_attr *attr,
466 			struct mlx5hws_rule *rule_handle);
467 
468 /**
469  * mlx5hws_rule_destroy - Enqueue destroy rule operation.
470  *
471  * @rule: The rule destruction to enqueue.
472  * @attr: Rule destruction attributes.
473  *
474  * Return: Zero on successful enqueue, non-zero otherwise.
475  */
476 int mlx5hws_rule_destroy(struct mlx5hws_rule *rule,
477 			 struct mlx5hws_rule_attr *attr);
478 
479 /**
480  * mlx5hws_rule_action_update - Enqueue update actions on an existing rule.
481  *
482  * @rule: A valid rule handle to update.
483  * @at_idx: Action template index to update the actions with.
484  * @rule_actions: Rule actions to be executed on match.
485  * @attr: Rule update attributes.
486  *
487  * Return: Zero on successful enqueue, non-zero otherwise.
488  */
489 int mlx5hws_rule_action_update(struct mlx5hws_rule *rule,
490 			       u8 at_idx,
491 			       struct mlx5hws_rule_action rule_actions[],
492 			       struct mlx5hws_rule_attr *attr);
493 
494 /**
495  * mlx5hws_action_get_type - Get action type.
496  *
497  * @action: The action to get the type of.
498  *
499  * Return: action type.
500  */
501 enum mlx5hws_action_type
502 mlx5hws_action_get_type(struct mlx5hws_action *action);
503 
504 /**
505  * mlx5hws_action_create_dest_drop - Create a direct rule drop action.
506  *
507  * @ctx: The context in which the new action will be created.
508  * @flags: Action creation flags (enum mlx5hws_action_flags).
509  *
510  * Return: Pointer to mlx5hws_action on success, NULL otherwise.
511  */
512 struct mlx5hws_action *
513 mlx5hws_action_create_dest_drop(struct mlx5hws_context *ctx,
514 				u32 flags);
515 
516 /**
517  * mlx5hws_action_create_default_miss - Create a direct rule default miss action.
518  * Defaults are RX: Drop, TX: Wire.
519  *
520  * @ctx: The context in which the new action will be created.
521  * @flags: Action creation flags (enum mlx5hws_action_flags).
522  *
523  * Return: Pointer to mlx5hws_action on success, NULL otherwise.
524  */
525 struct mlx5hws_action *
526 mlx5hws_action_create_default_miss(struct mlx5hws_context *ctx,
527 				   u32 flags);
528 
529 /**
530  * mlx5hws_action_create_dest_table - Create direct rule goto table action.
531  *
532  * @ctx: The context in which the new action will be created.
533  * @tbl: Destination table.
534  * @flags: Action creation flags (enum mlx5hws_action_flags).
535  *
536  * Return: pointer to mlx5hws_action on success NULL otherwise.
537  */
538 struct mlx5hws_action *
539 mlx5hws_action_create_dest_table(struct mlx5hws_context *ctx,
540 				 struct mlx5hws_table *tbl,
541 				 u32 flags);
542 
543 /**
544  * mlx5hws_action_create_dest_table_num - Create direct rule goto table number action.
545  *
546  * @ctx: The context in which the new action will be created.
547  * @tbl_num: Destination table number.
548  * @flags: Action creation flags (enum mlx5hws_action_flags).
549  *
550  * Return: pointer to mlx5hws_action on success NULL otherwise.
551  */
552 struct mlx5hws_action *
553 mlx5hws_action_create_dest_table_num(struct mlx5hws_context *ctx,
554 				     u32 tbl_num, u32 flags);
555 
556 /**
557  * mlx5hws_action_create_dest_match_range - Create direct rule range match action.
558  *
559  * @ctx: The context in which the new action will be created.
560  * @field: Field to comapare the value.
561  * @hit_ft: Flow table to go to on hit.
562  * @miss_ft: Flow table to go to on miss.
563  * @min: Minimal value of the field to be considered as hit.
564  * @max: Maximal value of the field to be considered as hit.
565  * @flags: Action creation flags (enum mlx5hws_action_flags).
566  *
567  * Return: pointer to mlx5hws_action on success NULL otherwise.
568  */
569 struct mlx5hws_action *
570 mlx5hws_action_create_dest_match_range(struct mlx5hws_context *ctx,
571 				       u32 field,
572 				       struct mlx5_flow_table *hit_ft,
573 				       struct mlx5_flow_table *miss_ft,
574 				       u32 min, u32 max, u32 flags);
575 
576 /**
577  * mlx5hws_action_create_flow_sampler - Create direct rule flow sampler action.
578  *
579  * @ctx: The context in which the new action will be created.
580  * @sampler_id: Flow sampler object ID.
581  * @flags: Action creation flags (enum mlx5hws_action_flags).
582  *
583  * Return: pointer to mlx5hws_action on success NULL otherwise.
584  */
585 struct mlx5hws_action *
586 mlx5hws_action_create_flow_sampler(struct mlx5hws_context *ctx,
587 				   u32 sampler_id, u32 flags);
588 
589 /**
590  * mlx5hws_action_create_dest_vport - Create direct rule goto vport action.
591  *
592  * @ctx: The context in which the new action will be created.
593  * @vport_num: Destination vport number.
594  * @vhca_id_valid: Tells if the vhca_id parameter is valid.
595  * @vhca_id: VHCA ID of the destination vport.
596  * @flags: Action creation flags (enum mlx5hws_action_flags).
597  *
598  * Return: pointer to mlx5hws_action on success NULL otherwise.
599  */
600 struct mlx5hws_action *
601 mlx5hws_action_create_dest_vport(struct mlx5hws_context *ctx,
602 				 u16 vport_num,
603 				 bool vhca_id_valid,
604 				 u16 vhca_id,
605 				 u32 flags);
606 
607 /**
608  * mlx5hws_action_create_tag - Create direct rule TAG action.
609  *
610  * @ctx: The context in which the new action will be created.
611  * @flags: Action creation flags (enum mlx5hws_action_flags).
612  *
613  * Return: pointer to mlx5hws_action on success NULL otherwise.
614  */
615 struct mlx5hws_action *
616 mlx5hws_action_create_tag(struct mlx5hws_context *ctx, u32 flags);
617 
618 /**
619  * mlx5hws_action_create_counter - Create direct rule counter action.
620  *
621  * @ctx: The context in which the new action will be created.
622  * @obj_id: Direct rule counter object ID.
623  * @flags: Action creation flags (enum mlx5hws_action_flags).
624  *
625  * Return: pointer to mlx5hws_action on success NULL otherwise.
626  */
627 struct mlx5hws_action *
628 mlx5hws_action_create_counter(struct mlx5hws_context *ctx,
629 			      u32 obj_id,
630 			      u32 flags);
631 
632 /**
633  * mlx5hws_action_create_reformat - Create direct rule reformat action.
634  *
635  * @ctx: The context in which the new action will be created.
636  * @reformat_type: Type of reformat prefixed with MLX5HWS_ACTION_TYP_REFORMAT.
637  * @num_of_hdrs: Number of provided headers in "hdrs" array.
638  * @hdrs: Headers array containing header information.
639  * @log_bulk_size: Number of unique values used with this reformat.
640  * @flags: Action creation flags (enum mlx5hws_action_flags).
641  *
642  * Return: pointer to mlx5hws_action on success NULL otherwise.
643  */
644 struct mlx5hws_action *
645 mlx5hws_action_create_reformat(struct mlx5hws_context *ctx,
646 			       enum mlx5hws_action_type reformat_type,
647 			       u8 num_of_hdrs,
648 			       struct mlx5hws_action_reformat_header *hdrs,
649 			       u32 log_bulk_size,
650 			       u32 flags);
651 
652 /**
653  * mlx5hws_action_create_modify_header - Create direct rule modify header action.
654  *
655  * @ctx: The context in which the new action will be created.
656  * @num_of_patterns: Number of provided patterns in "patterns" array.
657  * @patterns: Patterns array containing pattern information.
658  * @log_bulk_size: Number of unique values used with this pattern.
659  * @flags: Action creation flags (enum mlx5hws_action_flags).
660  *
661  * Return: pointer to mlx5hws_action on success NULL otherwise.
662  */
663 struct mlx5hws_action *
664 mlx5hws_action_create_modify_header(struct mlx5hws_context *ctx,
665 				    u8 num_of_patterns,
666 				    struct mlx5hws_action_mh_pattern *patterns,
667 				    u32 log_bulk_size,
668 				    u32 flags);
669 
670 /**
671  * mlx5hws_action_create_aso_meter - Create direct rule ASO flow meter action.
672  *
673  * @ctx: The context in which the new action will be created.
674  * @obj_id: ASO object ID.
675  * @return_reg_c: Copy the ASO object value into this reg_c,
676  *		  after a packet hits a rule with this ASO object.
677  * @flags: Action creation flags (enum mlx5hws_action_flags).
678  *
679  * Return: pointer to mlx5hws_action on success NULL otherwise.
680  */
681 struct mlx5hws_action *
682 mlx5hws_action_create_aso_meter(struct mlx5hws_context *ctx,
683 				u32 obj_id,
684 				u8 return_reg_c,
685 				u32 flags);
686 
687 /**
688  * mlx5hws_action_create_pop_vlan - Create direct rule pop vlan action.
689  *
690  * @ctx: The context in which the new action will be created.
691  * @flags: Action creation flags (enum mlx5hws_action_flags).
692  *
693  * Return: pointer to mlx5hws_action on success NULL otherwise.
694  */
695 struct mlx5hws_action *
696 mlx5hws_action_create_pop_vlan(struct mlx5hws_context *ctx, u32 flags);
697 
698 /**
699  * mlx5hws_action_create_push_vlan - Create direct rule push vlan action.
700  *
701  * @ctx: The context in which the new action will be created.
702  * @flags: Action creation flags (enum mlx5hws_action_flags).
703  *
704  * Return: pointer to mlx5hws_action on success NULL otherwise.
705  */
706 struct mlx5hws_action *
707 mlx5hws_action_create_push_vlan(struct mlx5hws_context *ctx, u32 flags);
708 
709 /**
710  * mlx5hws_action_create_dest_array - Create a dest array action, this action can
711  * duplicate packets and forward to multiple destinations in the destination list.
712  *
713  * @ctx: The context in which the new action will be created.
714  * @num_dest: The number of dests attributes.
715  * @dests: The destination array. Each contains a destination action and can
716  *	   have additional actions.
717  * @ignore_flow_level: Whether to turn on 'ignore_flow_level' for this dest.
718  * @flow_source: Source port of the traffic for this actions.
719  * @flags: Action creation flags (enum mlx5hws_action_flags).
720  *
721  * Return: pointer to mlx5hws_action on success NULL otherwise.
722  */
723 struct mlx5hws_action *
724 mlx5hws_action_create_dest_array(struct mlx5hws_context *ctx,
725 				 size_t num_dest,
726 				 struct mlx5hws_action_dest_attr *dests,
727 				 bool ignore_flow_level,
728 				 u32 flow_source,
729 				 u32 flags);
730 
731 /**
732  * mlx5hws_action_create_insert_header - Create insert header action.
733  *
734  * @ctx: The context in which the new action will be created.
735  * @num_of_hdrs: Number of provided headers in "hdrs" array.
736  * @hdrs: Headers array containing header information.
737  * @log_bulk_size: Number of unique values used with this insert header.
738  * @flags: Action creation flags. (enum mlx5hws_action_flags)
739  *
740  * Return: pointer to mlx5hws_action on success NULL otherwise.
741  */
742 struct mlx5hws_action *
743 mlx5hws_action_create_insert_header(struct mlx5hws_context *ctx,
744 				    u8 num_of_hdrs,
745 				    struct mlx5hws_action_insert_header *hdrs,
746 				    u32 log_bulk_size,
747 				    u32 flags);
748 
749 /**
750  * mlx5hws_action_create_remove_header - Create remove header action.
751  *
752  * @ctx: The context in which the new action will be created.
753  * @attr: attributes that specifie the remove header type, PRM start anchor and
754  *	  the PRM end anchor or the PRM start anchor and remove size in bytes.
755  * @flags: Action creation flags. (enum mlx5hws_action_flags)
756  *
757  * Return: pointer to mlx5hws_action on success NULL otherwise.
758  */
759 struct mlx5hws_action *
760 mlx5hws_action_create_remove_header(struct mlx5hws_context *ctx,
761 				    struct mlx5hws_action_remove_header_attr *attr,
762 				    u32 flags);
763 
764 /**
765  * mlx5hws_action_create_last - Create direct rule LAST action.
766  *
767  * @ctx: The context in which the new action will be created.
768  * @flags: Action creation flags. (enum mlx5hws_action_flags)
769  *
770  * Return: pointer to mlx5hws_action on success NULL otherwise.
771  */
772 struct mlx5hws_action *
773 mlx5hws_action_create_last(struct mlx5hws_context *ctx, u32 flags);
774 
775 /**
776  * mlx5hws_action_destroy - Destroy direct rule action.
777  *
778  * @action: The action to destroy.
779  *
780  * Return: zero on success non zero otherwise.
781  */
782 int mlx5hws_action_destroy(struct mlx5hws_action *action);
783 
784 enum mlx5hws_flow_op_status {
785 	MLX5HWS_FLOW_OP_SUCCESS,
786 	MLX5HWS_FLOW_OP_ERROR,
787 };
788 
789 struct mlx5hws_flow_op_result {
790 	enum mlx5hws_flow_op_status status;
791 	void *user_data;
792 };
793 
794 /**
795  * mlx5hws_send_queue_poll - Poll queue for rule creation and deletions completions.
796  *
797  * @ctx: The context to which the queue belong to.
798  * @queue_id: The id of the queue to poll.
799  * @res: Completion array.
800  * @res_nb: Maximum number of results to return.
801  *
802  * Return: negative number on failure, the number of completions otherwise.
803  */
804 int mlx5hws_send_queue_poll(struct mlx5hws_context *ctx,
805 			    u16 queue_id,
806 			    struct mlx5hws_flow_op_result res[],
807 			    u32 res_nb);
808 
809 /**
810  * mlx5hws_send_queue_action - Perform an action on the queue
811  *
812  * @ctx: The context to which the queue belong to.
813  * @queue_id: The id of the queue to perform the action on.
814  * @actions: Actions to perform on the queue (enum mlx5hws_send_queue_actions)
815  *
816  * Return: zero on success non zero otherwise.
817  */
818 int mlx5hws_send_queue_action(struct mlx5hws_context *ctx,
819 			      u16 queue_id,
820 			      u32 actions);
821 
822 /**
823  * mlx5hws_debug_dump - Dump HWS info
824  *
825  * @ctx: The context which to dump the info from.
826  *
827  * Return: zero on success non zero otherwise.
828  */
829 int mlx5hws_debug_dump(struct mlx5hws_context *ctx);
830 
831 struct mlx5hws_bwc_matcher;
832 struct mlx5hws_bwc_rule;
833 
834 struct mlx5hws_match_parameters {
835 	size_t match_sz;
836 	u32 *match_buf; /* Device spec format */
837 };
838 
839 /**
840  * mlx5hws_bwc_matcher_create - Create a new BWC direct rule matcher.
841  *
842  * This function does the following:
843  *   - creates match template based on flow items
844  *   - creates an empty action template
845  *   - creates a usual mlx5hws_matcher with these mt and at, setting
846  *     its size to minimal
847  * Notes:
848  *   - table->ctx must have BWC support
849  *   - complex rules are not supported
850  *
851  * @table: The table in which the new matcher will be opened
852  * @priority: Priority for this BWC matcher
853  * @match_criteria_enable: Bitmask that defines matching criteria
854  * @mask: Match parameters
855  *
856  * Return: pointer to mlx5hws_bwc_matcher on success or NULL otherwise.
857  */
858 struct mlx5hws_bwc_matcher *
859 mlx5hws_bwc_matcher_create(struct mlx5hws_table *table,
860 			   u32 priority,
861 			   u8 match_criteria_enable,
862 			   struct mlx5hws_match_parameters *mask);
863 
864 /**
865  * mlx5hws_bwc_matcher_destroy - Destroy BWC direct rule matcher.
866  *
867  * @bwc_matcher: Matcher to destroy
868  *
869  * Return: zero on success, non zero otherwise
870  */
871 int mlx5hws_bwc_matcher_destroy(struct mlx5hws_bwc_matcher *bwc_matcher);
872 
873 /**
874  * mlx5hws_bwc_rule_create - Create a new BWC rule.
875  *
876  * Unlike the usual rule creation function, this one is blocking: when the
877  * function returns, the rule is written to its place (no need to poll).
878  * This function does the following:
879  *   - finds matching action template based on the provided rule_actions, or
880  *     creates new action template if matching action template doesn't exist
881  *   - updates corresponding BWC matcher stats
882  *   - if needed, the function performs rehash:
883  *       - creates a new matcher based on mt, at, new_sz
884  *       - moves all the existing matcher rules to the new matcher
885  *       - removes the old matcher
886  *   - inserts new rule
887  *   - polls till completion is received
888  * Notes:
889  *   - matcher->tbl->ctx must have BWC support
890  *   - separate BWC ctx queues are used
891  *
892  * @bwc_matcher: The BWC matcher in which the new rule will be created.
893  * @params: Match perameters
894  * @flow_source: Flow source for this rule
895  * @rule_actions: Rule action to be executed on match
896  *
897  * Return: valid BWC rule handle on success, NULL otherwise
898  */
899 struct mlx5hws_bwc_rule *
900 mlx5hws_bwc_rule_create(struct mlx5hws_bwc_matcher *bwc_matcher,
901 			struct mlx5hws_match_parameters *params,
902 			u32 flow_source,
903 			struct mlx5hws_rule_action rule_actions[]);
904 
905 /**
906  * mlx5hws_bwc_rule_destroy - Destroy BWC direct rule.
907  *
908  * @bwc_rule: Rule to destroy.
909  *
910  * Return: zero on success, non zero otherwise.
911  */
912 int mlx5hws_bwc_rule_destroy(struct mlx5hws_bwc_rule *bwc_rule);
913 
914 /**
915  * mlx5hws_bwc_rule_action_update - Update actions on an existing BWC rule.
916  *
917  * @bwc_rule: Rule to update
918  * @rule_actions: Rule action to update with
919  *
920  * Return: zero on successful update, non zero otherwise.
921  */
922 int mlx5hws_bwc_rule_action_update(struct mlx5hws_bwc_rule *bwc_rule,
923 				   struct mlx5hws_rule_action rule_actions[]);
924 
925 #endif
926