DPDK  20.08.0
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,
244  RTE_ACL_CLASSIFY_NUM /* should always be the last one. */
245 };
246 
276 extern int
277 rte_acl_classify(const struct rte_acl_ctx *ctx,
278  const uint8_t **data,
279  uint32_t *results, uint32_t num,
280  uint32_t categories);
281 
316 extern int
317 rte_acl_classify_alg(const struct rte_acl_ctx *ctx,
318  const uint8_t **data,
319  uint32_t *results, uint32_t num,
320  uint32_t categories,
321  enum rte_acl_classify_alg alg);
322 
323 /*
324  * Override the default classifier function for a given ACL context.
325  * @param ctx
326  * ACL context to change classify function for.
327  * @param alg
328  * New default classify algorithm for given ACL context.
329  * It is the caller responsibility to ensure that the value refers to the
330  * existing algorithm, and that it could be run on the given CPU.
331  * @return
332  * - -EINVAL if the parameters are invalid.
333  * - Zero if operation completed successfully.
334  */
335 extern int
336 rte_acl_set_ctx_classify(struct rte_acl_ctx *ctx,
337  enum rte_acl_classify_alg alg);
338 
345 void
346 rte_acl_dump(const struct rte_acl_ctx *ctx);
347 
351 void
352 rte_acl_list_dump(void);
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 
358 #endif /* _RTE_ACL_H_ */
uint32_t offset
Definition: rte_acl.h:56
union rte_acl_field_types value
Definition: rte_acl.h:76
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)
struct rte_acl_field_def defs[RTE_ACL_MAX_FIELDS]
Definition: rte_acl.h:66
#define RTE_LEN2MASK(ln, tp)
Definition: rte_common.h:781
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)
union rte_acl_field_types mask_range
Definition: rte_acl.h:78
#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