1
2
3
4
5#ifndef _ACL_H_
6#define _ACL_H_
7
8#ifdef __cplusplus
9extern"C" {
10#endif
11
12#define RTE_ACL_QUAD_MAX 5
13#define RTE_ACL_QUAD_SIZE 4
14#define RTE_ACL_QUAD_SINGLE UINT64_C(0x7f7f7f7f00000000)
15
16#define RTE_ACL_SINGLE_TRIE_SIZE 2000
17
18#define RTE_ACL_DFA_MAX UINT8_MAX
19#define RTE_ACL_DFA_SIZE (UINT8_MAX + 1)
20
21#define RTE_ACL_DFA_GR64_SIZE 64
22#define RTE_ACL_DFA_GR64_NUM (RTE_ACL_DFA_SIZE / RTE_ACL_DFA_GR64_SIZE)
23#define RTE_ACL_DFA_GR64_BIT \
24 (CHAR_BIT * sizeof(uint32_t) / RTE_ACL_DFA_GR64_NUM)
25
26typedef int bits_t;
27
28#define RTE_ACL_BIT_SET_SIZE ((UINT8_MAX + 1) / (sizeof(bits_t) * CHAR_BIT))
29
30struct rte_acl_bitset {
31 bits_t bits[RTE_ACL_BIT_SET_SIZE];
32};
33
34#define RTE_ACL_NODE_DFA (0 << RTE_ACL_TYPE_SHIFT)
35#define RTE_ACL_NODE_SINGLE (1U << RTE_ACL_TYPE_SHIFT)
36#define RTE_ACL_NODE_QRANGE (3U << RTE_ACL_TYPE_SHIFT)
37#define RTE_ACL_NODE_MATCH (4U << RTE_ACL_TYPE_SHIFT)
38#define RTE_ACL_NODE_TYPE (7U << RTE_ACL_TYPE_SHIFT)
39#define RTE_ACL_NODE_UNDEFINED UINT32_MAX
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#define RTE_ACL_IDLE_NODE (RTE_ACL_DFA_SIZE | RTE_ACL_NODE_SINGLE)
85
86
87
88
89
90struct rte_acl_ptr_set {
91 struct rte_acl_bitset values;
92 struct rte_acl_node *ptr;
93};
94
95struct rte_acl_classifier_results {
96 int results[RTE_ACL_MAX_CATEGORIES];
97};
98
99struct rte_acl_match_results {
100 uint32_t results[RTE_ACL_MAX_CATEGORIES];
101 int32_t priority[RTE_ACL_MAX_CATEGORIES];
102};
103
104struct rte_acl_node {
105 uint64_t node_index;
106 uint32_t level;
107 uint32_t ref_count;
108 struct rte_acl_bitset values;
109
110
111
112 uint32_t num_ptrs;
113 uint32_t max_ptrs;
114 uint32_t min_add;
115 struct rte_acl_ptr_set *ptrs;
116 int32_t match_flag;
117 int32_t match_index;
118 uint32_t node_type;
119 int32_t fanout;
120
121 int32_t id;
122 struct rte_acl_match_results *mrt;
123 union {
124 char transitions[RTE_ACL_QUAD_SIZE];
125
126 uint8_t dfa_gr64[RTE_ACL_DFA_GR64_NUM];
127 };
128 struct rte_acl_node *next;
129
130 struct rte_acl_node *prev;
131
132};
133
134
135
136
137enum {
138 RTE_ACL_FULL_TRIE = 0,
139 RTE_ACL_NOSRC_TRIE = 1,
140 RTE_ACL_NODST_TRIE = 2,
141 RTE_ACL_NOPORTS_TRIE = 4,
142 RTE_ACL_NOVLAN_TRIE = 8,
143 RTE_ACL_UNUSED_TRIE = 0x80000000
144};
145
146
147
148#define RTE_ACL_MAX_TRIES 8
149
150
151#define RTE_ACL_NAMESIZE 32
152
153
154struct rte_acl_trie {
155 uint32_t type;
156 uint32_t count;
157 uint32_t root_index;
158 const uint32_t *data_index;
159 uint32_t num_data_indexes;
160};
161
162struct rte_acl_bld_trie {
163 struct rte_acl_node *trie;
164};
165
166struct rte_acl_ctx {
167 char name[RTE_ACL_NAMESIZE];
168
169 int32_t socket_id;
170
171 enum rte_acl_classify_alg alg;
172 uint32_t first_load_sz;
173 void *rules;
174 uint32_t max_rules;
175 uint32_t rule_sz;
176 uint32_t num_rules;
177 uint32_t num_categories;
178 uint32_t num_tries;
179 uint32_t match_index;
180 uint64_t no_match;
181 uint64_t idle;
182 uint64_t *trans_table;
183 uint32_t *data_indexes;
184 struct rte_acl_trie trie[RTE_ACL_MAX_TRIES];
185 void *mem;
186 size_t mem_sz;
187 struct rte_acl_config config;
188};
189
190int rte_acl_gen(struct rte_acl_ctx *ctx, struct rte_acl_trie *trie,
191 struct rte_acl_bld_trie *node_bld_trie, uint32_t num_tries,
192 uint32_t num_categories, uint32_t data_index_sz, size_t max_size);
193
194typedef int (*rte_acl_classify_t)
195(const struct rte_acl_ctx *, const uint8_t **, uint32_t *, uint32_t, uint32_t);
196
197
198
199
200int
201rte_acl_classify_scalar(const struct rte_acl_ctx *ctx, const uint8_t **data,
202 uint32_t *results, uint32_t num, uint32_t categories);
203
204int
205rte_acl_classify_sse(const struct rte_acl_ctx *ctx, const uint8_t **data,
206 uint32_t *results, uint32_t num, uint32_t categories);
207
208int
209rte_acl_classify_avx2(const struct rte_acl_ctx *ctx, const uint8_t **data,
210 uint32_t *results, uint32_t num, uint32_t categories);
211
212int
213rte_acl_classify_avx512x16(const struct rte_acl_ctx *ctx, const uint8_t **data,
214 uint32_t *results, uint32_t num, uint32_t categories);
215
216int
217rte_acl_classify_avx512x32(const struct rte_acl_ctx *ctx, const uint8_t **data,
218 uint32_t *results, uint32_t num, uint32_t categories);
219
220int
221rte_acl_classify_neon(const struct rte_acl_ctx *ctx, const uint8_t **data,
222 uint32_t *results, uint32_t num, uint32_t categories);
223
224int
225rte_acl_classify_altivec(const struct rte_acl_ctx *ctx, const uint8_t **data,
226 uint32_t *results, uint32_t num, uint32_t categories);
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif
233