1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2 /* Copyright (c) 2024 NVIDIA Corporation & Affiliates */ 3 4 #ifndef HWS_BWC_COMPLEX_H_ 5 #define HWS_BWC_COMPLEX_H_ 6 7 #define MLX5HWS_BWC_COMPLEX_MAX_SUBMATCHERS 4 8 9 /* A matcher can't contain two rules with the same match tag, but it is possible 10 * that two different complex rules' subrules have the same match tag. In that 11 * case, those subrules correspond to a single rule, and we need to refcount. 12 */ 13 struct mlx5hws_bwc_complex_subrule_data { 14 struct mlx5hws_rule_match_tag match_tag; 15 refcount_t refcount; 16 /* The chain_id is what glues individual subrules into larger complex 17 * rules. It is the value that this subrule writes to register C6, and 18 * that the next subrule matches against. 19 */ 20 u32 chain_id; 21 u32 rtc_0; 22 u32 rtc_1; 23 /* During rehash we iterate through all the subrules to move them. But 24 * two or more subrules can share the same physical rule in the 25 * submatcher, so we use `was_moved` to keep track if a given rule was 26 * already moved. 27 */ 28 bool was_moved; 29 struct rhash_head hash_node; 30 }; 31 32 struct mlx5hws_bwc_complex_submatcher { 33 /* Isolated table that the matcher lives in. Not set for the first 34 * matcher, which lives in the original table. 35 */ 36 struct mlx5hws_table *tbl; 37 /* Match a rule with this action to go to `tbl`. This is set in all 38 * submatchers but the first. 39 */ 40 struct mlx5hws_action *action_tbl; 41 /* This submatcher's simple matcher. The first submatcher points to the 42 * outer (complex) matcher. 43 */ 44 struct mlx5hws_bwc_matcher *bwc_matcher; 45 struct rhashtable rules_hash; 46 struct ida chain_ida; 47 struct mutex hash_lock; /* Protect the hash and ida. */ 48 }; 49 50 struct mlx5hws_bwc_matcher_complex_data { 51 struct mlx5hws_bwc_complex_submatcher 52 submatchers[MLX5HWS_BWC_COMPLEX_MAX_SUBMATCHERS]; 53 int num_submatchers; 54 /* Actions used by all but the last submatcher to point to the next 55 * submatcher in the chain. The last submatcher uses the action template 56 * from the complex matcher, to perform the actions that the user 57 * originally requested. 58 */ 59 struct mlx5hws_action *action_metadata; 60 struct mlx5hws_action *action_last; 61 }; 62 63 bool mlx5hws_bwc_match_params_is_complex(struct mlx5hws_context *ctx, 64 u8 match_criteria_enable, 65 struct mlx5hws_match_parameters *mask); 66 67 int mlx5hws_bwc_matcher_create_complex(struct mlx5hws_bwc_matcher *bwc_matcher, 68 struct mlx5hws_table *table, 69 u32 priority, 70 u8 match_criteria_enable, 71 struct mlx5hws_match_parameters *mask); 72 73 void mlx5hws_bwc_matcher_destroy_complex(struct mlx5hws_bwc_matcher *bwc_matcher); 74 75 int mlx5hws_bwc_matcher_complex_move(struct mlx5hws_bwc_matcher *bwc_matcher); 76 77 int 78 mlx5hws_bwc_matcher_complex_move_first(struct mlx5hws_bwc_matcher *bwc_matcher); 79 80 int mlx5hws_bwc_rule_create_complex(struct mlx5hws_bwc_rule *bwc_rule, 81 struct mlx5hws_match_parameters *params, 82 u32 flow_source, 83 struct mlx5hws_rule_action rule_actions[], 84 u16 bwc_queue_idx); 85 86 int mlx5hws_bwc_rule_destroy_complex(struct mlx5hws_bwc_rule *bwc_rule); 87 88 #endif /* HWS_BWC_COMPLEX_H_ */ 89