DPDK  20.11.10
rte_acl.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef _RTE_ACL_H_
6 #define _RTE_ACL_H_
7 
14 #include <rte_acl_osdep.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #define RTE_ACL_MAX_CATEGORIES 16
21 
22 #define RTE_ACL_RESULTS_MULTIPLIER (XMM_SIZE / sizeof(uint32_t))
23 
24 #define RTE_ACL_MAX_LEVELS 64
25 #define RTE_ACL_MAX_FIELDS 64
26 
27 union rte_acl_field_types {
28  uint8_t u8;
29  uint16_t u16;
30  uint32_t u32;
31  uint64_t u64;
32 };
33 
34 enum {
35  RTE_ACL_FIELD_TYPE_MASK = 0,
36  RTE_ACL_FIELD_TYPE_RANGE,
37  RTE_ACL_FIELD_TYPE_BITMASK
38 };
39 
52  uint8_t type;
53  uint8_t size;
54  uint8_t field_index;
55  uint8_t input_index;
56  uint32_t offset;
57 };
58 
64  uint32_t num_categories;
65  uint32_t num_fields;
66  struct rte_acl_field_def defs[RTE_ACL_MAX_FIELDS];
68  size_t max_size;
70 };
71 
75 struct rte_acl_field {
76  union rte_acl_field_types value;
78  union rte_acl_field_types mask_range;
85 };
86 
87 enum {
88  RTE_ACL_TYPE_SHIFT = 29,
89  RTE_ACL_MAX_INDEX = RTE_LEN2MASK(RTE_ACL_TYPE_SHIFT, uint32_t),
90  RTE_ACL_MAX_PRIORITY = RTE_ACL_MAX_INDEX,
91  RTE_ACL_MIN_PRIORITY = 1,
92 };
93 
94 #define RTE_ACL_MASKLEN_TO_BITMASK(v, s) \
95 ((v) == 0 ? (v) : (typeof(v))((uint64_t)-1 << ((s) * CHAR_BIT - (v))))
96 
101  uint32_t category_mask;
102  int32_t priority;
103  uint32_t userdata;
104 };
105 
111 #define RTE_ACL_RULE_DEF(name, fld_num) struct name {\
112  struct rte_acl_rule_data data; \
113  struct rte_acl_field field[fld_num]; \
114 }
115 
116 RTE_ACL_RULE_DEF(rte_acl_rule,);
117 
118 #define RTE_ACL_RULE_SZ(fld_num) \
119  (sizeof(struct rte_acl_rule) + sizeof(struct rte_acl_field) * (fld_num))
120 
121 
123 #define RTE_ACL_NAMESIZE 32
124 
129  const char *name;
130  int socket_id;
131  uint32_t rule_size;
132  uint32_t max_rule_num;
133 };
134 
135 
147 struct rte_acl_ctx *
148 rte_acl_create(const struct rte_acl_param *param);
149 
160 struct rte_acl_ctx *
161 rte_acl_find_existing(const char *name);
162 
169 void
170 rte_acl_free(struct rte_acl_ctx *ctx);
171 
191 int
192 rte_acl_add_rules(struct rte_acl_ctx *ctx, const struct rte_acl_rule *rules,
193  uint32_t num);
194 
203 void
204 rte_acl_reset_rules(struct rte_acl_ctx *ctx);
205 
220 int
221 rte_acl_build(struct rte_acl_ctx *ctx, const struct rte_acl_config *cfg);
222 
231 void
232 rte_acl_reset(struct rte_acl_ctx *ctx);
233 
238  RTE_ACL_CLASSIFY_DEFAULT = 0,
246 };
247 
277 extern int
278 rte_acl_classify(const struct rte_acl_ctx *ctx,
279  const uint8_t **data,
280  uint32_t *results, uint32_t num,
281  uint32_t categories);
282 
317 extern int
318 rte_acl_classify_alg(const struct rte_acl_ctx *ctx,
319  const uint8_t **data,
320  uint32_t *results, uint32_t num,
321  uint32_t categories,
322  enum rte_acl_classify_alg alg);
323 
324 /*
325  * Override the default classifier function for a given ACL context.
326  * @param ctx
327  * ACL context to change classify function for.
328  * @param alg
329  * New default classify algorithm for given ACL context.
330  * It is the caller responsibility to ensure that the value refers to the
331  * existing algorithm, and that it could be run on the given CPU.
332  * The max SIMD bitwidth value in EAL must also allow for the chosen algorithm.
333  * @return
334  * - -EINVAL if the parameters are invalid.
335  * - -ENOTSUP requested algorithm is not supported by given platform.
336  * - Zero if operation completed successfully.
337  */
338 extern int
339 rte_acl_set_ctx_classify(struct rte_acl_ctx *ctx,
340  enum rte_acl_classify_alg alg);
341 
348 void
349 rte_acl_dump(const struct rte_acl_ctx *ctx);
350 
354 void
355 rte_acl_list_dump(void);
356 
357 #ifdef __cplusplus
358 }
359 #endif
360 
361 #endif /* _RTE_ACL_H_ */
uint32_t offset
Definition: rte_acl.h:56
struct rte_acl_ctx * rte_acl_create(const struct rte_acl_param *param)
rte_acl_classify_alg
Definition: rte_acl.h:237
uint8_t field_index
Definition: rte_acl.h:54
void rte_acl_dump(const struct rte_acl_ctx *ctx)
const char * name
Definition: rte_acl.h:129
int socket_id
Definition: rte_acl.h:130
uint8_t size
Definition: rte_acl.h:53
void rte_acl_reset(struct rte_acl_ctx *ctx)
int rte_acl_build(struct rte_acl_ctx *ctx, const struct rte_acl_config *cfg)
#define RTE_LEN2MASK(ln, tp)
Definition: rte_common.h:810
uint32_t num_categories
Definition: rte_acl.h:64
size_t max_size
Definition: rte_acl.h:68
uint32_t userdata
Definition: rte_acl.h:103
int32_t priority
Definition: rte_acl.h:102
void rte_acl_list_dump(void)
void rte_acl_reset_rules(struct rte_acl_ctx *ctx)
void rte_acl_free(struct rte_acl_ctx *ctx)
uint32_t num_fields
Definition: rte_acl.h:65
uint32_t rule_size
Definition: rte_acl.h:131
struct rte_acl_ctx * rte_acl_find_existing(const char *name)
#define RTE_ACL_RULE_DEF(name, fld_num)
Definition: rte_acl.h:111
uint8_t type
Definition: rte_acl.h:52
int rte_acl_add_rules(struct rte_acl_ctx *ctx, const struct rte_acl_rule *rules, uint32_t num)
int rte_acl_classify(const struct rte_acl_ctx *ctx, const uint8_t **data, uint32_t *results, uint32_t num, uint32_t categories)
uint8_t input_index
Definition: rte_acl.h:55
uint32_t max_rule_num
Definition: rte_acl.h:132
uint32_t category_mask
Definition: rte_acl.h:101