1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2024 NVIDIA Corporation & Affiliates */
3 
4 #include "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 	} else {
43 		kfree(mt->fc);
44 	}
45 
46 	mlx5hws_match_template_destroy(mt);
47 
48 	return is_complex;
49 }
50 
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)51 int mlx5hws_bwc_matcher_create_complex(struct mlx5hws_bwc_matcher *bwc_matcher,
52 				       struct mlx5hws_table *table,
53 				       u32 priority,
54 				       u8 match_criteria_enable,
55 				       struct mlx5hws_match_parameters *mask)
56 {
57 	mlx5hws_err(table->ctx, "Complex matcher is not supported yet\n");
58 	return -EOPNOTSUPP;
59 }
60 
61 void
mlx5hws_bwc_matcher_destroy_complex(struct mlx5hws_bwc_matcher * bwc_matcher)62 mlx5hws_bwc_matcher_destroy_complex(struct mlx5hws_bwc_matcher *bwc_matcher)
63 {
64 	/* nothing to do here */
65 }
66 
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)67 int mlx5hws_bwc_rule_create_complex(struct mlx5hws_bwc_rule *bwc_rule,
68 				    struct mlx5hws_match_parameters *params,
69 				    u32 flow_source,
70 				    struct mlx5hws_rule_action rule_actions[],
71 				    u16 bwc_queue_idx)
72 {
73 	mlx5hws_err(bwc_rule->bwc_matcher->matcher->tbl->ctx,
74 		    "Complex rule is not supported yet\n");
75 	return -EOPNOTSUPP;
76 }
77 
mlx5hws_bwc_rule_destroy_complex(struct mlx5hws_bwc_rule * bwc_rule)78 int mlx5hws_bwc_rule_destroy_complex(struct mlx5hws_bwc_rule *bwc_rule)
79 {
80 	return 0;
81 }
82 
mlx5hws_bwc_matcher_move_all_complex(struct mlx5hws_bwc_matcher * bwc_matcher)83 int mlx5hws_bwc_matcher_move_all_complex(struct mlx5hws_bwc_matcher *bwc_matcher)
84 {
85 	mlx5hws_err(bwc_matcher->matcher->tbl->ctx,
86 		    "Moving complex rule is not supported yet\n");
87 	return -EOPNOTSUPP;
88 }
89