Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (c) 2022 NVIDIA Corporation & Affiliates 3 : : */ 4 : : 5 : : #ifndef MLX5DR_MATCHER_H_ 6 : : #define MLX5DR_MATCHER_H_ 7 : : 8 : : /* Max supported match template */ 9 : : #define MLX5DR_MATCHER_MAX_MT_ROOT 1 10 : : 11 : : /* We calculated that concatenating a collision table to the main table with 12 : : * 3% of the main table rows will be enough resources for high insertion 13 : : * success probability. 14 : : * 15 : : * The calculation: log2(2^x * 3 / 100) = log2(2^x) + log2(3/100) = x - 5.05 ~ 5 16 : : */ 17 : : #define MLX5DR_MATCHER_ASSURED_ROW_RATIO 5 18 : : /* Thrashold to determine if amount of rules require a collision table */ 19 : : #define MLX5DR_MATCHER_ASSURED_RULES_TH 10 20 : : /* Required depth of an assured collision table */ 21 : : #define MLX5DR_MATCHER_ASSURED_COL_TBL_DEPTH 4 22 : : /* Required depth of the main large table */ 23 : : #define MLX5DR_MATCHER_ASSURED_MAIN_TBL_DEPTH 2 24 : : 25 : : enum mlx5dr_matcher_flags { 26 : : MLX5DR_MATCHER_FLAGS_RANGE_DEFINER = 1 << 0, 27 : : MLX5DR_MATCHER_FLAGS_HASH_DEFINER = 1 << 1, 28 : : MLX5DR_MATCHER_FLAGS_COLLISION = 1 << 2, 29 : : MLX5DR_MATCHER_FLAGS_RESIZABLE = 1 << 3, 30 : : MLX5DR_MATCHER_FLAGS_COMPARE = 1 << 4, 31 : : MLX5DR_MATCHER_FLAGS_STE_ARRAY = 1 << 5, 32 : : }; 33 : : 34 : : struct mlx5dr_match_template { 35 : : struct rte_flow_item *items; 36 : : struct mlx5dr_definer *definer; 37 : : struct mlx5dr_definer *range_definer; 38 : : struct mlx5dr_definer_fc *fc; 39 : : struct mlx5dr_definer_fc *fcr; 40 : : uint16_t fc_sz; 41 : : uint16_t fcr_sz; 42 : : uint64_t item_flags; 43 : : uint8_t vport_item_id; 44 : : enum mlx5dr_match_template_flags flags; 45 : : }; 46 : : 47 : : struct mlx5dr_matcher_match_ste { 48 : : struct mlx5dr_pool_chunk ste; 49 : : struct mlx5dr_devx_obj *rtc_0; 50 : : struct mlx5dr_devx_obj *rtc_1; 51 : : struct mlx5dr_pool *pool; 52 : : /* Currently not support FDB aliased */ 53 : : struct mlx5dr_devx_obj *aliased_rtc_0; 54 : : }; 55 : : 56 : : struct mlx5dr_matcher_action_ste { 57 : : struct mlx5dr_pool_chunk ste; 58 : : struct mlx5dr_pool_chunk stc; 59 : : struct mlx5dr_devx_obj *rtc_0; 60 : : struct mlx5dr_devx_obj *rtc_1; 61 : : struct mlx5dr_pool *pool; 62 : : uint8_t max_stes; 63 : : }; 64 : : 65 : : struct mlx5dr_matcher_resize_data { 66 : : struct mlx5dr_pool_chunk ste; 67 : : struct mlx5dr_pool_chunk stc; 68 : : struct mlx5dr_devx_obj *action_ste_rtc_0; 69 : : struct mlx5dr_devx_obj *action_ste_rtc_1; 70 : : struct mlx5dr_pool *action_ste_pool; 71 : : uint8_t max_stes; 72 : : LIST_ENTRY(mlx5dr_matcher_resize_data) next; 73 : : }; 74 : : 75 : : struct mlx5dr_matcher { 76 : : struct mlx5dr_table *tbl; 77 : : struct mlx5dr_matcher_attr attr; 78 : : struct mlx5dv_flow_matcher *dv_matcher; 79 : : struct mlx5dr_match_template *mt; 80 : : uint8_t num_of_mt; 81 : : struct mlx5dr_action_template *at; 82 : : uint8_t num_of_at; 83 : : /* enum mlx5dr_matcher_flags */ 84 : : uint8_t flags; 85 : : struct mlx5dr_devx_obj *end_ft; 86 : : struct mlx5dr_matcher *col_matcher; 87 : : struct mlx5dr_matcher *resize_dst; 88 : : struct mlx5dr_matcher_match_ste match_ste; 89 : : struct mlx5dr_matcher_action_ste action_ste; 90 : : struct mlx5dr_definer *hash_definer; 91 : : LIST_ENTRY(mlx5dr_matcher) next; 92 : : LIST_HEAD(resize_data_head, mlx5dr_matcher_resize_data) resize_data; 93 : : }; 94 : : 95 : : static inline bool 96 : : mlx5dr_matcher_mt_is_jumbo(struct mlx5dr_match_template *mt) 97 : : { 98 [ # # # # : 0 : return mlx5dr_definer_is_jumbo(mt->definer); # # ] 99 : : } 100 : : 101 : : static inline bool 102 : : mlx5dr_matcher_mt_is_range(struct mlx5dr_match_template *mt) 103 : : { 104 [ # # # # ]: 0 : return (!!mt->range_definer); 105 : : } 106 : : 107 : : static inline bool mlx5dr_matcher_is_resizable(struct mlx5dr_matcher *matcher) 108 : : { 109 [ # # # # : 0 : return !!(matcher->flags & MLX5DR_MATCHER_FLAGS_RESIZABLE); # # # # ] 110 : : } 111 : : 112 : : static inline bool mlx5dr_matcher_is_in_resize(struct mlx5dr_matcher *matcher) 113 : : { 114 [ # # # # : 0 : return !!matcher->resize_dst; # # # # ] 115 : : } 116 : : 117 : : static inline bool 118 : : mlx5dr_matcher_is_compare(struct mlx5dr_matcher *matcher) 119 : : { 120 [ # # # # ]: 0 : return !!(matcher->flags & MLX5DR_MATCHER_FLAGS_COMPARE); 121 : : } 122 : : 123 : : static inline bool mlx5dr_matcher_req_fw_wqe(struct mlx5dr_matcher *matcher) 124 : : { 125 : : /* Currently HWS doesn't support hash different from match or range */ 126 [ # # # # : 0 : return unlikely(matcher->flags & # # # # # # # # # # # # ] 127 : : (MLX5DR_MATCHER_FLAGS_HASH_DEFINER | 128 : : MLX5DR_MATCHER_FLAGS_RANGE_DEFINER | 129 : : MLX5DR_MATCHER_FLAGS_COMPARE)); 130 : : } 131 : : 132 : : int mlx5dr_matcher_conv_items_to_prm(uint64_t *match_buf, 133 : : struct rte_flow_item *items, 134 : : uint8_t *match_criteria, 135 : : bool is_value); 136 : : 137 : : int mlx5dr_matcher_create_aliased_obj(struct mlx5dr_context *ctx, 138 : : struct ibv_context *ibv_owner, 139 : : struct ibv_context *ibv_allowed, 140 : : uint16_t vhca_id_to_be_accessed, 141 : : uint32_t aliased_object_id, 142 : : uint16_t object_type, 143 : : struct mlx5dr_devx_obj **obj); 144 : : 145 : : static inline bool mlx5dr_matcher_is_insert_by_idx(struct mlx5dr_matcher *matcher) 146 : : { 147 [ # # # # : 0 : return matcher->attr.insert_mode == MLX5DR_MATCHER_INSERT_BY_INDEX; # # # # # # # # # # # # ] 148 : : } 149 : : 150 : : static inline bool mlx5dr_matcher_is_always_hit(struct mlx5dr_matcher *matcher) 151 : : { 152 [ # # ]: 0 : return matcher->attr.match_mode == MLX5DR_MATCHER_MATCH_MODE_ALWAYS_HIT; 153 : : } 154 : : 155 : : int mlx5dr_matcher_free_rtc_pointing(struct mlx5dr_context *ctx, 156 : : uint32_t fw_ft_type, 157 : : enum mlx5dr_table_type type, 158 : : struct mlx5dr_devx_obj *devx_obj); 159 : : 160 : : int mlx5dr_matcher_validate_compare_attr(struct mlx5dr_matcher *matcher); 161 : : 162 : : #endif /* MLX5DR_MATCHER_H_ */