1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2024 NVIDIA Corporation & Affiliates */
3
4 #include "mlx5hws_internal.h"
5
mlx5hws_bwc_match_params_is_complex(struct mlx5hws_context * ctx,u8 match_criteria_enable,struct mlx5hws_match_parameters * mask)6 bool mlx5hws_bwc_match_params_is_complex(struct mlx5hws_context *ctx,
7 u8 match_criteria_enable,
8 struct mlx5hws_match_parameters *mask)
9 {
10 struct mlx5hws_definer match_layout = {0};
11 struct mlx5hws_match_template *mt;
12 bool is_complex = false;
13 int ret;
14
15 if (!match_criteria_enable)
16 return false; /* empty matcher */
17
18 mt = mlx5hws_match_template_create(ctx,
19 mask->match_buf,
20 mask->match_sz,
21 match_criteria_enable);
22 if (!mt) {
23 mlx5hws_err(ctx, "BWC: failed creating match template\n");
24 return false;
25 }
26
27 ret = mlx5hws_definer_calc_layout(ctx, mt, &match_layout);
28 if (ret) {
29 /* The only case that we're interested in is E2BIG,
30 * which means that the match parameters need to be
31 * split into complex martcher.
32 * For all other cases (good or bad) - just return true
33 * and let the usual match creation path handle it,
34 * both for good and bad flows.
35 */
36 if (ret == -E2BIG) {
37 is_complex = true;
38 mlx5hws_dbg(ctx, "Matcher definer layout: need complex matcher\n");
39 } else {
40 mlx5hws_err(ctx, "Failed to calculate matcher definer layout\n");
41 }
42 }
43
44 mlx5hws_match_template_destroy(mt);
45
46 return is_complex;
47 }
48
mlx5hws_bwc_matcher_create_complex(struct mlx5hws_bwc_matcher * bwc_matcher,struct mlx5hws_table * table,u32 priority,u8 match_criteria_enable,struct mlx5hws_match_parameters * mask)49 int mlx5hws_bwc_matcher_create_complex(struct mlx5hws_bwc_matcher *bwc_matcher,
50 struct mlx5hws_table *table,
51 u32 priority,
52 u8 match_criteria_enable,
53 struct mlx5hws_match_parameters *mask)
54 {
55 mlx5hws_err(table->ctx, "Complex matcher is not supported yet\n");
56 return -EOPNOTSUPP;
57 }
58
59 void
mlx5hws_bwc_matcher_destroy_complex(struct mlx5hws_bwc_matcher * bwc_matcher)60 mlx5hws_bwc_matcher_destroy_complex(struct mlx5hws_bwc_matcher *bwc_matcher)
61 {
62 /* nothing to do here */
63 }
64
mlx5hws_bwc_rule_create_complex(struct mlx5hws_bwc_rule * bwc_rule,struct mlx5hws_match_parameters * params,u32 flow_source,struct mlx5hws_rule_action rule_actions[],u16 bwc_queue_idx)65 int mlx5hws_bwc_rule_create_complex(struct mlx5hws_bwc_rule *bwc_rule,
66 struct mlx5hws_match_parameters *params,
67 u32 flow_source,
68 struct mlx5hws_rule_action rule_actions[],
69 u16 bwc_queue_idx)
70 {
71 mlx5hws_err(bwc_rule->bwc_matcher->matcher->tbl->ctx,
72 "Complex rule is not supported yet\n");
73 return -EOPNOTSUPP;
74 }
75
mlx5hws_bwc_rule_destroy_complex(struct mlx5hws_bwc_rule * bwc_rule)76 int mlx5hws_bwc_rule_destroy_complex(struct mlx5hws_bwc_rule *bwc_rule)
77 {
78 return 0;
79 }
80
mlx5hws_bwc_matcher_move_all_complex(struct mlx5hws_bwc_matcher * bwc_matcher)81 int mlx5hws_bwc_matcher_move_all_complex(struct mlx5hws_bwc_matcher *bwc_matcher)
82 {
83 mlx5hws_err(bwc_matcher->matcher->tbl->ctx,
84 "Moving complex rule is not supported yet\n");
85 return -EOPNOTSUPP;
86 }
87