xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_matcher.h (revision 9410645520e9b820069761f3450ef6661418e279)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2024 NVIDIA Corporation & Affiliates */
3 
4 #ifndef MLX5HWS_MATCHER_H_
5 #define MLX5HWS_MATCHER_H_
6 
7 /* We calculated that concatenating a collision table to the main table with
8  * 3% of the main table rows will be enough resources for high insertion
9  * success probability.
10  *
11  * The calculation: log2(2^x * 3 / 100) = log2(2^x) + log2(3/100) = x - 5.05 ~ 5
12  */
13 #define MLX5HWS_MATCHER_ASSURED_ROW_RATIO 5
14 /* Threshold to determine if amount of rules require a collision table */
15 #define MLX5HWS_MATCHER_ASSURED_RULES_TH 10
16 /* Required depth of an assured collision table */
17 #define MLX5HWS_MATCHER_ASSURED_COL_TBL_DEPTH 4
18 /* Required depth of the main large table */
19 #define MLX5HWS_MATCHER_ASSURED_MAIN_TBL_DEPTH 2
20 
21 enum mlx5hws_matcher_offset {
22 	MLX5HWS_MATCHER_OFFSET_TAG_DW1 = 12,
23 	MLX5HWS_MATCHER_OFFSET_TAG_DW0 = 13,
24 };
25 
26 enum mlx5hws_matcher_flags {
27 	MLX5HWS_MATCHER_FLAGS_COLLISION = 1 << 2,
28 	MLX5HWS_MATCHER_FLAGS_RESIZABLE	= 1 << 3,
29 };
30 
31 struct mlx5hws_match_template {
32 	struct mlx5hws_definer *definer;
33 	struct mlx5hws_definer_fc *fc;
34 	u32 *match_param;
35 	u8 match_criteria_enable;
36 	u16 fc_sz;
37 };
38 
39 struct mlx5hws_matcher_match_ste {
40 	struct mlx5hws_pool_chunk ste;
41 	u32 rtc_0_id;
42 	u32 rtc_1_id;
43 	struct mlx5hws_pool *pool;
44 };
45 
46 struct mlx5hws_matcher_action_ste {
47 	struct mlx5hws_pool_chunk ste;
48 	struct mlx5hws_pool_chunk stc;
49 	u32 rtc_0_id;
50 	u32 rtc_1_id;
51 	struct mlx5hws_pool *pool;
52 	u8 max_stes;
53 };
54 
55 struct mlx5hws_matcher_resize_data_node {
56 	struct mlx5hws_pool_chunk stc;
57 	u32 rtc_0_id;
58 	u32 rtc_1_id;
59 	struct mlx5hws_pool *pool;
60 };
61 
62 struct mlx5hws_matcher_resize_data {
63 	struct mlx5hws_matcher_resize_data_node action_ste[2];
64 	u8 max_stes;
65 	struct list_head list_node;
66 };
67 
68 struct mlx5hws_matcher {
69 	struct mlx5hws_table *tbl;
70 	struct mlx5hws_matcher_attr attr;
71 	struct mlx5hws_match_template *mt;
72 	struct mlx5hws_action_template *at;
73 	u8 num_of_at;
74 	u8 num_of_mt;
75 	/* enum mlx5hws_matcher_flags */
76 	u8 flags;
77 	u32 end_ft_id;
78 	struct mlx5hws_matcher *col_matcher;
79 	struct mlx5hws_matcher *resize_dst;
80 	struct mlx5hws_matcher_match_ste match_ste;
81 	struct mlx5hws_matcher_action_ste action_ste[2];
82 	struct list_head list_node;
83 	struct list_head resize_data;
84 };
85 
86 static inline bool
mlx5hws_matcher_mt_is_jumbo(struct mlx5hws_match_template * mt)87 mlx5hws_matcher_mt_is_jumbo(struct mlx5hws_match_template *mt)
88 {
89 	return mlx5hws_definer_is_jumbo(mt->definer);
90 }
91 
mlx5hws_matcher_is_resizable(struct mlx5hws_matcher * matcher)92 static inline bool mlx5hws_matcher_is_resizable(struct mlx5hws_matcher *matcher)
93 {
94 	return !!(matcher->flags & MLX5HWS_MATCHER_FLAGS_RESIZABLE);
95 }
96 
mlx5hws_matcher_is_in_resize(struct mlx5hws_matcher * matcher)97 static inline bool mlx5hws_matcher_is_in_resize(struct mlx5hws_matcher *matcher)
98 {
99 	return !!matcher->resize_dst;
100 }
101 
mlx5hws_matcher_is_insert_by_idx(struct mlx5hws_matcher * matcher)102 static inline bool mlx5hws_matcher_is_insert_by_idx(struct mlx5hws_matcher *matcher)
103 {
104 	return matcher->attr.insert_mode == MLX5HWS_MATCHER_INSERT_BY_INDEX;
105 }
106 
107 #endif /* MLX5HWS_MATCHER_H_ */
108