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 : : uint32_t hws_root_match_flags; 86 : : struct mlx5dr_devx_obj *end_ft; 87 : : struct mlx5dr_matcher *col_matcher; 88 : : struct mlx5dr_matcher *resize_dst; 89 : : struct mlx5dr_matcher_match_ste match_ste; 90 : : struct mlx5dr_matcher_action_ste action_ste; 91 : : struct mlx5dr_definer *hash_definer; 92 : : LIST_ENTRY(mlx5dr_matcher) next; 93 : : LIST_HEAD(resize_data_head, mlx5dr_matcher_resize_data) resize_data; 94 : : }; 95 : : 96 : : static inline bool 97 : : mlx5dr_matcher_mt_is_jumbo(struct mlx5dr_match_template *mt) 98 : : { 99 [ # # # # : 0 : return mlx5dr_definer_is_jumbo(mt->definer); # # ] 100 : : } 101 : : 102 : : static inline bool 103 : : mlx5dr_matcher_mt_is_range(struct mlx5dr_match_template *mt) 104 : : { 105 [ # # # # ]: 0 : return (!!mt->range_definer); 106 : : } 107 : : 108 : : static inline bool mlx5dr_matcher_is_resizable(struct mlx5dr_matcher *matcher) 109 : : { 110 [ # # # # : 0 : return !!(matcher->flags & MLX5DR_MATCHER_FLAGS_RESIZABLE); # # # # ] 111 : : } 112 : : 113 : : static inline bool mlx5dr_matcher_is_in_resize(struct mlx5dr_matcher *matcher) 114 : : { 115 [ # # # # : 0 : return !!matcher->resize_dst; # # # # ] 116 : : } 117 : : 118 : : static inline bool 119 : : mlx5dr_matcher_is_compare(struct mlx5dr_matcher *matcher) 120 : : { 121 [ # # # # ]: 0 : return !!(matcher->flags & MLX5DR_MATCHER_FLAGS_COMPARE); 122 : : } 123 : : 124 : : static inline bool mlx5dr_matcher_req_fw_wqe(struct mlx5dr_matcher *matcher) 125 : : { 126 : : /* Currently HWS doesn't support hash different from match or range */ 127 [ # # # # : 0 : return unlikely(matcher->flags & # # # # # # # # # # # # ] 128 : : (MLX5DR_MATCHER_FLAGS_HASH_DEFINER | 129 : : MLX5DR_MATCHER_FLAGS_RANGE_DEFINER | 130 : : MLX5DR_MATCHER_FLAGS_COMPARE)); 131 : : } 132 : : 133 : : int mlx5dr_matcher_conv_items_to_prm(uint64_t *match_buf, 134 : : struct rte_flow_item *items, 135 : : uint8_t *match_criteria, 136 : : bool is_value); 137 : : 138 : : int mlx5dr_matcher_create_aliased_obj(struct mlx5dr_context *ctx, 139 : : struct ibv_context *ibv_owner, 140 : : struct ibv_context *ibv_allowed, 141 : : uint16_t vhca_id_to_be_accessed, 142 : : uint32_t aliased_object_id, 143 : : uint16_t object_type, 144 : : struct mlx5dr_devx_obj **obj); 145 : : 146 : : static inline bool mlx5dr_matcher_is_insert_by_idx(struct mlx5dr_matcher *matcher) 147 : : { 148 [ # # # # : 0 : return matcher->attr.insert_mode == MLX5DR_MATCHER_INSERT_BY_INDEX; # # # # # # # # # # # # ] 149 : : } 150 : : 151 : : static inline bool mlx5dr_matcher_is_always_hit(struct mlx5dr_matcher *matcher) 152 : : { 153 [ # # ]: 0 : return matcher->attr.match_mode == MLX5DR_MATCHER_MATCH_MODE_ALWAYS_HIT; 154 : : } 155 : : 156 : : int mlx5dr_matcher_free_rtc_pointing(struct mlx5dr_context *ctx, 157 : : uint32_t fw_ft_type, 158 : : enum mlx5dr_table_type type, 159 : : struct mlx5dr_devx_obj *devx_obj); 160 : : 161 : : int mlx5dr_matcher_validate_compare_attr(struct mlx5dr_matcher *matcher); 162 : : 163 : : #endif /* MLX5DR_MATCHER_H_ */