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