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 : : }; 32 : : 33 : : struct mlx5dr_match_template { 34 : : struct rte_flow_item *items; 35 : : struct mlx5dr_definer *definer; 36 : : struct mlx5dr_definer *range_definer; 37 : : struct mlx5dr_definer_fc *fc; 38 : : struct mlx5dr_definer_fc *fcr; 39 : : uint16_t fc_sz; 40 : : uint16_t fcr_sz; 41 : : uint64_t item_flags; 42 : : uint8_t vport_item_id; 43 : : enum mlx5dr_match_template_flags flags; 44 : : }; 45 : : 46 : : struct mlx5dr_matcher_match_ste { 47 : : struct mlx5dr_pool_chunk ste; 48 : : struct mlx5dr_devx_obj *rtc_0; 49 : : struct mlx5dr_devx_obj *rtc_1; 50 : : struct mlx5dr_pool *pool; 51 : : /* Currently not support FDB aliased */ 52 : : struct mlx5dr_devx_obj *aliased_rtc_0; 53 : : }; 54 : : 55 : : struct mlx5dr_matcher_action_ste { 56 : : struct mlx5dr_pool_chunk ste; 57 : : struct mlx5dr_pool_chunk stc; 58 : : struct mlx5dr_devx_obj *rtc_0; 59 : : struct mlx5dr_devx_obj *rtc_1; 60 : : struct mlx5dr_pool *pool; 61 : : uint8_t max_stes; 62 : : }; 63 : : 64 : : struct mlx5dr_matcher_resize_data { 65 : : struct mlx5dr_pool_chunk stc; 66 : : struct mlx5dr_devx_obj *action_ste_rtc_0; 67 : : struct mlx5dr_devx_obj *action_ste_rtc_1; 68 : : struct mlx5dr_pool *action_ste_pool; 69 : : LIST_ENTRY(mlx5dr_matcher_resize_data) next; 70 : : }; 71 : : 72 : : struct mlx5dr_matcher { 73 : : struct mlx5dr_table *tbl; 74 : : struct mlx5dr_matcher_attr attr; 75 : : struct mlx5dv_flow_matcher *dv_matcher; 76 : : struct mlx5dr_match_template *mt; 77 : : uint8_t num_of_mt; 78 : : struct mlx5dr_action_template *at; 79 : : uint8_t num_of_at; 80 : : /* enum mlx5dr_matcher_flags */ 81 : : uint8_t flags; 82 : : struct mlx5dr_devx_obj *end_ft; 83 : : struct mlx5dr_matcher *col_matcher; 84 : : struct mlx5dr_matcher *resize_dst; 85 : : struct mlx5dr_matcher_match_ste match_ste; 86 : : struct mlx5dr_matcher_action_ste action_ste; 87 : : struct mlx5dr_definer *hash_definer; 88 : : LIST_ENTRY(mlx5dr_matcher) next; 89 : : LIST_HEAD(resize_data_head, mlx5dr_matcher_resize_data) resize_data; 90 : : }; 91 : : 92 : : static inline bool 93 : : mlx5dr_matcher_mt_is_jumbo(struct mlx5dr_match_template *mt) 94 : : { 95 [ # # # # : 0 : return mlx5dr_definer_is_jumbo(mt->definer); # # # # ] 96 : : } 97 : : 98 : : static inline bool 99 : : mlx5dr_matcher_mt_is_range(struct mlx5dr_match_template *mt) 100 : : { 101 [ # # # # ]: 0 : return (!!mt->range_definer); 102 : : } 103 : : 104 : : static inline bool mlx5dr_matcher_is_resizable(struct mlx5dr_matcher *matcher) 105 : : { 106 [ # # # # : 0 : return !!(matcher->flags & MLX5DR_MATCHER_FLAGS_RESIZABLE); # # ] 107 : : } 108 : : 109 : : static inline bool mlx5dr_matcher_is_in_resize(struct mlx5dr_matcher *matcher) 110 : : { 111 [ # # # # : 0 : return !!matcher->resize_dst; # # # # ] 112 : : } 113 : : 114 : : static inline bool 115 : : mlx5dr_matcher_is_compare(struct mlx5dr_matcher *matcher) 116 : : { 117 [ # # # # ]: 0 : return !!(matcher->flags & MLX5DR_MATCHER_FLAGS_COMPARE); 118 : : } 119 : : 120 : : static inline bool mlx5dr_matcher_req_fw_wqe(struct mlx5dr_matcher *matcher) 121 : : { 122 : : /* Currently HWS doesn't support hash different from match or range */ 123 [ # # # # : 0 : return unlikely(matcher->flags & # # # # # # # # # # ] 124 : : (MLX5DR_MATCHER_FLAGS_HASH_DEFINER | 125 : : MLX5DR_MATCHER_FLAGS_RANGE_DEFINER | 126 : : MLX5DR_MATCHER_FLAGS_COMPARE)); 127 : : } 128 : : 129 : : int mlx5dr_matcher_conv_items_to_prm(uint64_t *match_buf, 130 : : struct rte_flow_item *items, 131 : : uint8_t *match_criteria, 132 : : bool is_value); 133 : : 134 : : int mlx5dr_matcher_create_aliased_obj(struct mlx5dr_context *ctx, 135 : : struct ibv_context *ibv_owner, 136 : : struct ibv_context *ibv_allowed, 137 : : uint16_t vhca_id_to_be_accessed, 138 : : uint32_t aliased_object_id, 139 : : uint16_t object_type, 140 : : struct mlx5dr_devx_obj **obj); 141 : : 142 : : static inline bool mlx5dr_matcher_is_insert_by_idx(struct mlx5dr_matcher *matcher) 143 : : { 144 [ # # # # : 0 : return matcher->attr.insert_mode == MLX5DR_MATCHER_INSERT_BY_INDEX; # # # # # # # # # # # # # # ] 145 : : } 146 : : 147 : : int mlx5dr_matcher_free_rtc_pointing(struct mlx5dr_context *ctx, 148 : : uint32_t fw_ft_type, 149 : : enum mlx5dr_table_type type, 150 : : struct mlx5dr_devx_obj *devx_obj); 151 : : 152 : : int mlx5dr_matcher_validate_compare_attr(struct mlx5dr_matcher *matcher); 153 : : 154 : : #endif /* MLX5DR_MATCHER_H_ */