1c4676082SAlex Vesker /* SPDX-License-Identifier: BSD-3-Clause 2c4676082SAlex Vesker * Copyright (c) 2022 NVIDIA Corporation & Affiliates 3c4676082SAlex Vesker */ 4c4676082SAlex Vesker 5c4676082SAlex Vesker #ifndef MLX5DR_MATCHER_H_ 6c4676082SAlex Vesker #define MLX5DR_MATCHER_H_ 7c4676082SAlex Vesker 8c4676082SAlex Vesker /* Max supported match template */ 9c4676082SAlex Vesker #define MLX5DR_MATCHER_MAX_MT_ROOT 1 10c4676082SAlex Vesker 11c4676082SAlex Vesker /* We calculated that concatenating a collision table to the main table with 12c4676082SAlex Vesker * 3% of the main table rows will be enough resources for high insertion 13c4676082SAlex Vesker * success probability. 14c4676082SAlex Vesker * 15c4676082SAlex Vesker * The calculation: log2(2^x * 3 / 100) = log2(2^x) + log2(3/100) = x - 5.05 ~ 5 16c4676082SAlex Vesker */ 17c4676082SAlex Vesker #define MLX5DR_MATCHER_ASSURED_ROW_RATIO 5 18c4676082SAlex Vesker /* Thrashold to determine if amount of rules require a collision table */ 19c4676082SAlex Vesker #define MLX5DR_MATCHER_ASSURED_RULES_TH 10 20c4676082SAlex Vesker /* Required depth of an assured collision table */ 21c4676082SAlex Vesker #define MLX5DR_MATCHER_ASSURED_COL_TBL_DEPTH 4 22c4676082SAlex Vesker /* Required depth of the main large table */ 23c4676082SAlex Vesker #define MLX5DR_MATCHER_ASSURED_MAIN_TBL_DEPTH 2 24c4676082SAlex Vesker 2527ac2da9SAlex Vesker enum mlx5dr_matcher_flags { 269732ffe1SAlex Vesker MLX5DR_MATCHER_FLAGS_RANGE_DEFINER = 1 << 0, 279732ffe1SAlex Vesker MLX5DR_MATCHER_FLAGS_HASH_DEFINER = 1 << 1, 289732ffe1SAlex Vesker MLX5DR_MATCHER_FLAGS_COLLISION = 1 << 2, 29762fecebSYevgeny Kliteynik MLX5DR_MATCHER_FLAGS_RESIZABLE = 1 << 3, 30a5230507SHamdan Igbaria MLX5DR_MATCHER_FLAGS_COMPARE = 1 << 4, 31*486f9aacSHamdan Igbaria MLX5DR_MATCHER_FLAGS_STE_ARRAY = 1 << 5, 3227ac2da9SAlex Vesker }; 3327ac2da9SAlex Vesker 34c4676082SAlex Vesker struct mlx5dr_match_template { 35c4676082SAlex Vesker struct rte_flow_item *items; 36c4676082SAlex Vesker struct mlx5dr_definer *definer; 3727ac2da9SAlex Vesker struct mlx5dr_definer *range_definer; 38c4676082SAlex Vesker struct mlx5dr_definer_fc *fc; 399732ffe1SAlex Vesker struct mlx5dr_definer_fc *fcr; 4027ac2da9SAlex Vesker uint16_t fc_sz; 419732ffe1SAlex Vesker uint16_t fcr_sz; 42c4676082SAlex Vesker uint64_t item_flags; 43c4676082SAlex Vesker uint8_t vport_item_id; 44c4676082SAlex Vesker enum mlx5dr_match_template_flags flags; 45c4676082SAlex Vesker }; 46c4676082SAlex Vesker 47c4676082SAlex Vesker struct mlx5dr_matcher_match_ste { 48c4676082SAlex Vesker struct mlx5dr_pool_chunk ste; 49c4676082SAlex Vesker struct mlx5dr_devx_obj *rtc_0; 50c4676082SAlex Vesker struct mlx5dr_devx_obj *rtc_1; 51c4676082SAlex Vesker struct mlx5dr_pool *pool; 52ce946c7dSErez Shitrit /* Currently not support FDB aliased */ 53ce946c7dSErez Shitrit struct mlx5dr_devx_obj *aliased_rtc_0; 54c4676082SAlex Vesker }; 55c4676082SAlex Vesker 56c4676082SAlex Vesker struct mlx5dr_matcher_action_ste { 57c4676082SAlex Vesker struct mlx5dr_pool_chunk ste; 58c4676082SAlex Vesker struct mlx5dr_pool_chunk stc; 59c4676082SAlex Vesker struct mlx5dr_devx_obj *rtc_0; 60c4676082SAlex Vesker struct mlx5dr_devx_obj *rtc_1; 61c4676082SAlex Vesker struct mlx5dr_pool *pool; 62c4676082SAlex Vesker uint8_t max_stes; 63c4676082SAlex Vesker }; 64c4676082SAlex Vesker 65762fecebSYevgeny Kliteynik struct mlx5dr_matcher_resize_data { 66fd821625SHamdan Igbaria struct mlx5dr_pool_chunk ste; 67762fecebSYevgeny Kliteynik struct mlx5dr_pool_chunk stc; 68762fecebSYevgeny Kliteynik struct mlx5dr_devx_obj *action_ste_rtc_0; 69762fecebSYevgeny Kliteynik struct mlx5dr_devx_obj *action_ste_rtc_1; 70762fecebSYevgeny Kliteynik struct mlx5dr_pool *action_ste_pool; 7119e9ad26SYevgeny Kliteynik uint8_t max_stes; 72762fecebSYevgeny Kliteynik LIST_ENTRY(mlx5dr_matcher_resize_data) next; 73762fecebSYevgeny Kliteynik }; 74762fecebSYevgeny Kliteynik 75c4676082SAlex Vesker struct mlx5dr_matcher { 76c4676082SAlex Vesker struct mlx5dr_table *tbl; 77c4676082SAlex Vesker struct mlx5dr_matcher_attr attr; 78c4676082SAlex Vesker struct mlx5dv_flow_matcher *dv_matcher; 79940b0ebaSAlex Vesker struct mlx5dr_match_template *mt; 80c4676082SAlex Vesker uint8_t num_of_mt; 81940b0ebaSAlex Vesker struct mlx5dr_action_template *at; 82c4676082SAlex Vesker uint8_t num_of_at; 8327ac2da9SAlex Vesker /* enum mlx5dr_matcher_flags */ 8427ac2da9SAlex Vesker uint8_t flags; 85c4676082SAlex Vesker struct mlx5dr_devx_obj *end_ft; 86c4676082SAlex Vesker struct mlx5dr_matcher *col_matcher; 87762fecebSYevgeny Kliteynik struct mlx5dr_matcher *resize_dst; 88c4676082SAlex Vesker struct mlx5dr_matcher_match_ste match_ste; 89c4676082SAlex Vesker struct mlx5dr_matcher_action_ste action_ste; 90238190f3SAlex Vesker struct mlx5dr_definer *hash_definer; 91c4676082SAlex Vesker LIST_ENTRY(mlx5dr_matcher) next; 92762fecebSYevgeny Kliteynik LIST_HEAD(resize_data_head, mlx5dr_matcher_resize_data) resize_data; 93c4676082SAlex Vesker }; 94c4676082SAlex Vesker 9527ac2da9SAlex Vesker static inline bool 9627ac2da9SAlex Vesker mlx5dr_matcher_mt_is_jumbo(struct mlx5dr_match_template *mt) 9727ac2da9SAlex Vesker { 9827ac2da9SAlex Vesker return mlx5dr_definer_is_jumbo(mt->definer); 9927ac2da9SAlex Vesker } 10027ac2da9SAlex Vesker 1019732ffe1SAlex Vesker static inline bool 1029732ffe1SAlex Vesker mlx5dr_matcher_mt_is_range(struct mlx5dr_match_template *mt) 1039732ffe1SAlex Vesker { 1049732ffe1SAlex Vesker return (!!mt->range_definer); 1059732ffe1SAlex Vesker } 1069732ffe1SAlex Vesker 107762fecebSYevgeny Kliteynik static inline bool mlx5dr_matcher_is_resizable(struct mlx5dr_matcher *matcher) 108762fecebSYevgeny Kliteynik { 109762fecebSYevgeny Kliteynik return !!(matcher->flags & MLX5DR_MATCHER_FLAGS_RESIZABLE); 110762fecebSYevgeny Kliteynik } 111762fecebSYevgeny Kliteynik 112762fecebSYevgeny Kliteynik static inline bool mlx5dr_matcher_is_in_resize(struct mlx5dr_matcher *matcher) 113762fecebSYevgeny Kliteynik { 114762fecebSYevgeny Kliteynik return !!matcher->resize_dst; 115762fecebSYevgeny Kliteynik } 116762fecebSYevgeny Kliteynik 117a5230507SHamdan Igbaria static inline bool 118a5230507SHamdan Igbaria mlx5dr_matcher_is_compare(struct mlx5dr_matcher *matcher) 119a5230507SHamdan Igbaria { 120a5230507SHamdan Igbaria return !!(matcher->flags & MLX5DR_MATCHER_FLAGS_COMPARE); 121a5230507SHamdan Igbaria } 122a5230507SHamdan Igbaria 123238190f3SAlex Vesker static inline bool mlx5dr_matcher_req_fw_wqe(struct mlx5dr_matcher *matcher) 124238190f3SAlex Vesker { 125238190f3SAlex Vesker /* Currently HWS doesn't support hash different from match or range */ 1269732ffe1SAlex Vesker return unlikely(matcher->flags & 1279732ffe1SAlex Vesker (MLX5DR_MATCHER_FLAGS_HASH_DEFINER | 128a5230507SHamdan Igbaria MLX5DR_MATCHER_FLAGS_RANGE_DEFINER | 129a5230507SHamdan Igbaria MLX5DR_MATCHER_FLAGS_COMPARE)); 130238190f3SAlex Vesker } 131238190f3SAlex Vesker 132c4676082SAlex Vesker int mlx5dr_matcher_conv_items_to_prm(uint64_t *match_buf, 133c4676082SAlex Vesker struct rte_flow_item *items, 134c4676082SAlex Vesker uint8_t *match_criteria, 135c4676082SAlex Vesker bool is_value); 136c4676082SAlex Vesker 137ce946c7dSErez Shitrit int mlx5dr_matcher_create_aliased_obj(struct mlx5dr_context *ctx, 138ce946c7dSErez Shitrit struct ibv_context *ibv_owner, 139ce946c7dSErez Shitrit struct ibv_context *ibv_allowed, 140ce946c7dSErez Shitrit uint16_t vhca_id_to_be_accessed, 141ce946c7dSErez Shitrit uint32_t aliased_object_id, 142ce946c7dSErez Shitrit uint16_t object_type, 143ce946c7dSErez Shitrit struct mlx5dr_devx_obj **obj); 14438b5bf64SYevgeny Kliteynik 14538b5bf64SYevgeny Kliteynik static inline bool mlx5dr_matcher_is_insert_by_idx(struct mlx5dr_matcher *matcher) 14638b5bf64SYevgeny Kliteynik { 14738b5bf64SYevgeny Kliteynik return matcher->attr.insert_mode == MLX5DR_MATCHER_INSERT_BY_INDEX; 14838b5bf64SYevgeny Kliteynik } 14938b5bf64SYevgeny Kliteynik 150*486f9aacSHamdan Igbaria static inline bool mlx5dr_matcher_is_always_hit(struct mlx5dr_matcher *matcher) 151*486f9aacSHamdan Igbaria { 152*486f9aacSHamdan Igbaria return matcher->attr.match_mode == MLX5DR_MATCHER_MATCH_MODE_ALWAYS_HIT; 153*486f9aacSHamdan Igbaria } 154*486f9aacSHamdan Igbaria 155b81f95caSItamar Gozlan int mlx5dr_matcher_free_rtc_pointing(struct mlx5dr_context *ctx, 156b81f95caSItamar Gozlan uint32_t fw_ft_type, 157b81f95caSItamar Gozlan enum mlx5dr_table_type type, 158b81f95caSItamar Gozlan struct mlx5dr_devx_obj *devx_obj); 159b81f95caSItamar Gozlan 160a5230507SHamdan Igbaria int mlx5dr_matcher_validate_compare_attr(struct mlx5dr_matcher *matcher); 161a5230507SHamdan Igbaria 162c4676082SAlex Vesker #endif /* MLX5DR_MATCHER_H_ */ 163