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