1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2 /* Copyright (c) 2024 NVIDIA Corporation & Affiliates */ 3 4 #ifndef HWS_MATCHER_H_ 5 #define HWS_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 /* Action RTC size multiplier that is required in order 22 * to support rule update for rules with action STEs. 23 */ 24 #define MLX5HWS_MATCHER_ACTION_RTC_UPDATE_MULT 1 25 26 enum mlx5hws_matcher_offset { 27 MLX5HWS_MATCHER_OFFSET_TAG_DW1 = 12, 28 MLX5HWS_MATCHER_OFFSET_TAG_DW0 = 13, 29 }; 30 31 enum mlx5hws_matcher_flags { 32 MLX5HWS_MATCHER_FLAGS_COLLISION = 1 << 2, 33 MLX5HWS_MATCHER_FLAGS_RESIZABLE = 1 << 3, 34 }; 35 36 struct mlx5hws_match_template { 37 struct mlx5hws_definer *definer; 38 struct mlx5hws_definer_fc *fc; 39 u32 *match_param; 40 u8 match_criteria_enable; 41 u16 fc_sz; 42 }; 43 44 struct mlx5hws_matcher_match_ste { 45 struct mlx5hws_pool_chunk ste; 46 u32 rtc_0_id; 47 u32 rtc_1_id; 48 struct mlx5hws_pool *pool; 49 }; 50 51 struct mlx5hws_matcher_action_ste { 52 struct mlx5hws_pool_chunk ste; 53 struct mlx5hws_pool_chunk stc; 54 u32 rtc_0_id; 55 u32 rtc_1_id; 56 struct mlx5hws_pool *pool; 57 u8 max_stes; 58 }; 59 60 struct mlx5hws_matcher_resize_data { 61 struct mlx5hws_pool_chunk stc; 62 u32 rtc_0_id; 63 u32 rtc_1_id; 64 struct mlx5hws_pool *pool; 65 u8 max_stes; 66 struct list_head list_node; 67 }; 68 69 struct mlx5hws_matcher { 70 struct mlx5hws_table *tbl; 71 struct mlx5hws_matcher_attr attr; 72 struct mlx5hws_match_template *mt; 73 struct mlx5hws_action_template *at; 74 u8 num_of_at; 75 u8 num_of_mt; 76 /* enum mlx5hws_matcher_flags */ 77 u8 flags; 78 u32 end_ft_id; 79 struct mlx5hws_matcher *col_matcher; 80 struct mlx5hws_matcher *resize_dst; 81 struct mlx5hws_matcher_match_ste match_ste; 82 struct mlx5hws_matcher_action_ste action_ste; 83 struct list_head list_node; 84 struct list_head resize_data; 85 }; 86 87 static inline bool mlx5hws_matcher_mt_is_jumbo(struct mlx5hws_match_template * mt)88mlx5hws_matcher_mt_is_jumbo(struct mlx5hws_match_template *mt) 89 { 90 return mlx5hws_definer_is_jumbo(mt->definer); 91 } 92 mlx5hws_matcher_is_resizable(struct mlx5hws_matcher * matcher)93static inline bool mlx5hws_matcher_is_resizable(struct mlx5hws_matcher *matcher) 94 { 95 return !!(matcher->flags & MLX5HWS_MATCHER_FLAGS_RESIZABLE); 96 } 97 mlx5hws_matcher_is_in_resize(struct mlx5hws_matcher * matcher)98static inline bool mlx5hws_matcher_is_in_resize(struct mlx5hws_matcher *matcher) 99 { 100 return !!matcher->resize_dst; 101 } 102 mlx5hws_matcher_is_insert_by_idx(struct mlx5hws_matcher * matcher)103static inline bool mlx5hws_matcher_is_insert_by_idx(struct mlx5hws_matcher *matcher) 104 { 105 return matcher->attr.insert_mode == MLX5HWS_MATCHER_INSERT_BY_INDEX; 106 } 107 108 #endif /* HWS_MATCHER_H_ */ 109