1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
/* Copyright (c) 2024 NVIDIA Corporation & Affiliates */

#ifndef HWS_MATCHER_H_
#define HWS_MATCHER_H_

/* We calculated that concatenating a collision table to the main table with
 * 3% of the main table rows will be enough resources for high insertion
 * success probability.
 *
 * The calculation: log2(2^x * 3 / 100) = log2(2^x) + log2(3/100) = x - 5.05 ~ 5
 */
#define MLX5HWS_MATCHER_ASSURED_ROW_RATIO 5
/* Threshold to determine if amount of rules require a collision table */
#define MLX5HWS_MATCHER_ASSURED_RULES_TH 10
/* Required depth of an assured collision table */
#define MLX5HWS_MATCHER_ASSURED_COL_TBL_DEPTH 4
/* Required depth of the main large table */
#define MLX5HWS_MATCHER_ASSURED_MAIN_TBL_DEPTH 2

/* Action RTC size multiplier that is required in order
 * to support rule update for rules with action STEs.
 */
#define MLX5HWS_MATCHER_ACTION_RTC_UPDATE_MULT 1

/* Maximum number of action templates that can be attached to a matcher. */
#define MLX5HWS_MATCHER_MAX_AT 128

enum mlx5hws_matcher_offset {
	MLX5HWS_MATCHER_OFFSET_TAG_DW1 = 12,
	MLX5HWS_MATCHER_OFFSET_TAG_DW0 = 13,
};

enum mlx5hws_matcher_flags {
	MLX5HWS_MATCHER_FLAGS_COLLISION = 1 << 2,
	MLX5HWS_MATCHER_FLAGS_RESIZABLE	= 1 << 3,
};

struct mlx5hws_match_template {
	struct mlx5hws_definer *definer;
	struct mlx5hws_definer_fc *fc;
	u32 *match_param;
	u8 match_criteria_enable;
	u16 fc_sz;
};

struct mlx5hws_matcher_match_ste {
	struct mlx5hws_pool_chunk ste;
	u32 rtc_0_id;
	u32 rtc_1_id;
	struct mlx5hws_pool *pool;
};

struct mlx5hws_matcher_action_ste {
	struct mlx5hws_pool_chunk ste;
	struct mlx5hws_pool_chunk stc;
	u32 rtc_0_id;
	u32 rtc_1_id;
	struct mlx5hws_pool *pool;
	u8 max_stes;
};

struct mlx5hws_matcher_resize_data {
	struct mlx5hws_pool_chunk stc;
	u32 rtc_0_id;
	u32 rtc_1_id;
	struct mlx5hws_pool *pool;
	u8 max_stes;
	struct list_head list_node;
};

struct mlx5hws_matcher {
	struct mlx5hws_table *tbl;
	struct mlx5hws_matcher_attr attr;
	struct mlx5hws_match_template *mt;
	struct mlx5hws_action_template *at;
	u8 num_of_at;
	u8 size_of_at_array;
	u8 num_of_mt;
	/* enum mlx5hws_matcher_flags */
	u8 flags;
	u32 end_ft_id;
	struct mlx5hws_matcher *col_matcher;
	struct mlx5hws_matcher *resize_dst;
	struct mlx5hws_matcher_match_ste match_ste;
	struct mlx5hws_matcher_action_ste action_ste;
	struct list_head list_node;
	struct list_head resize_data;
};

static inline bool
mlx5hws_matcher_mt_is_jumbo(struct mlx5hws_match_template *mt)
{
	return mlx5hws_definer_is_jumbo(mt->definer);
}

static inline bool mlx5hws_matcher_is_resizable(struct mlx5hws_matcher *matcher)
{
	return !!(matcher->flags & MLX5HWS_MATCHER_FLAGS_RESIZABLE);
}

static inline bool mlx5hws_matcher_is_in_resize(struct mlx5hws_matcher *matcher)
{
	return !!matcher->resize_dst;
}

static inline bool mlx5hws_matcher_is_insert_by_idx(struct mlx5hws_matcher *matcher)
{
	return matcher->attr.insert_mode == MLX5HWS_MATCHER_INSERT_BY_INDEX;
}

#endif /* HWS_MATCHER_H_ */
掌心的温暖 是你紧握著的光芒 透过了指缝 一星半点投奔向远方