DPDK  25.03.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_common.h>
15 #include <rte_acl_osdep.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #define RTE_ACL_MAX_CATEGORIES 16
22 
23 #define RTE_ACL_RESULTS_MULTIPLIER (XMM_SIZE / sizeof(uint32_t))
24 
25 #define RTE_ACL_MAX_LEVELS 64
26 #define RTE_ACL_MAX_FIELDS 64
27 
28 union rte_acl_field_types {
29  uint8_t u8;
30  uint16_t u16;
31  uint32_t u32;
32  uint64_t u64;
33 };
34 
35 enum {
36  RTE_ACL_FIELD_TYPE_MASK = 0,
37  RTE_ACL_FIELD_TYPE_RANGE,
38  RTE_ACL_FIELD_TYPE_BITMASK
39 };
40 
53  uint8_t type;
54  uint8_t size;
55  uint8_t field_index;
56  uint8_t input_index;
57  uint32_t offset;
58 };
59 
65  uint32_t num_categories;
66  uint32_t num_fields;
67  struct rte_acl_field_def defs[RTE_ACL_MAX_FIELDS];
69  size_t max_size;
71 };
72 
76 struct rte_acl_field {
77  union rte_acl_field_types value;
79  union rte_acl_field_types mask_range;
86 };
87 
88 enum {
89  RTE_ACL_TYPE_SHIFT = 29,
90  RTE_ACL_MAX_INDEX = RTE_LEN2MASK(RTE_ACL_TYPE_SHIFT, uint32_t),
91  RTE_ACL_MAX_PRIORITY = RTE_ACL_MAX_INDEX,
92  RTE_ACL_MIN_PRIORITY = 1,
93 };
94 
95 #define RTE_ACL_MASKLEN_TO_BITMASK(v, s) \
96 ((v) == 0 ? (v) : (typeof(v))((uint64_t)-1 << ((s) * CHAR_BIT - (v))))
97 
102  uint32_t category_mask;
103  int32_t priority;
104  uint32_t userdata;
105 };
106 
112 #define RTE_ACL_RULE_DEF(name, fld_num) struct name {\
113  struct rte_acl_rule_data data; \
114  struct rte_acl_field field[fld_num]; \
115 }
116 
117 RTE_ACL_RULE_DEF(rte_acl_rule,);
118 
119 #define RTE_ACL_RULE_SZ(fld_num) \
120  (sizeof(struct rte_acl_rule) + sizeof(struct rte_acl_field) * (fld_num))
121 
122 
124 #define RTE_ACL_NAMESIZE 32
125 
130  const char *name;
131  int socket_id;
132  uint32_t rule_size;
133  uint32_t max_rule_num;
134 };
135 
137 struct rte_acl_ctx;
138 
146 void
147 rte_acl_free(struct rte_acl_ctx *ctx);
148 
160 struct rte_acl_ctx *
161 rte_acl_create(const struct rte_acl_param *param)
163 
174 struct rte_acl_ctx *
175 rte_acl_find_existing(const char *name);
176 
196 int
197 rte_acl_add_rules(struct rte_acl_ctx *ctx, const struct rte_acl_rule *rules,
198  uint32_t num);
199 
208 void
209 rte_acl_reset_rules(struct rte_acl_ctx *ctx);
210 
225 int
226 rte_acl_build(struct rte_acl_ctx *ctx, const struct rte_acl_config *cfg);
227 
236 void
237 rte_acl_reset(struct rte_acl_ctx *ctx);
238 
243  RTE_ACL_CLASSIFY_DEFAULT = 0,
251 };
252 
282 extern int
283 rte_acl_classify(const struct rte_acl_ctx *ctx,
284  const uint8_t **data,
285  uint32_t *results, uint32_t num,
286  uint32_t categories);
287 
322 extern int
323 rte_acl_classify_alg(const struct rte_acl_ctx *ctx,
324  const uint8_t **data,
325  uint32_t *results, uint32_t num,
326  uint32_t categories,
327  enum rte_acl_classify_alg alg);
328 
329 /*
330  * Override the default classifier function for a given ACL context.
331  * @param ctx
332  * ACL context to change classify function for.
333  * @param alg
334  * New default classify algorithm for given ACL context.
335  * It is the caller responsibility to ensure that the value refers to the
336  * existing algorithm, and that it could be run on the given CPU.
337  * The max SIMD bitwidth value in EAL must also allow for the chosen algorithm.
338  * @return
339  * - -EINVAL if the parameters are invalid.
340  * - -ENOTSUP requested algorithm is not supported by given platform.
341  * - Zero if operation completed successfully.
342  */
343 extern int
344 rte_acl_set_ctx_classify(struct rte_acl_ctx *ctx,
345  enum rte_acl_classify_alg alg);
346 
353 void
354 rte_acl_dump(const struct rte_acl_ctx *ctx);
355 
359 void
360 rte_acl_list_dump(void);
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 
366 #endif /* _RTE_ACL_H_ */
uint32_t offset
Definition: rte_acl.h:57
union rte_acl_field_types value
Definition: rte_acl.h:77
rte_acl_classify_alg
Definition: rte_acl.h:242
uint8_t field_index
Definition: rte_acl.h:55
void rte_acl_dump(const struct rte_acl_ctx *ctx)
const char * name
Definition: rte_acl.h:130
int socket_id
Definition: rte_acl.h:131
uint8_t size
Definition: rte_acl.h:54
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:67
#define RTE_LEN2MASK(ln, tp)
Definition: rte_common.h:867
uint32_t num_categories
Definition: rte_acl.h:65
size_t max_size
Definition: rte_acl.h:69
uint32_t userdata
Definition: rte_acl.h:104
int32_t priority
Definition: rte_acl.h:103
void rte_acl_list_dump(void)
#define __rte_dealloc(dealloc, argno)
Definition: rte_common.h:305
struct rte_acl_ctx * rte_acl_create(const struct rte_acl_param *param) __rte_malloc __rte_dealloc(rte_acl_free
#define __rte_malloc
Definition: rte_common.h:294
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:66
uint32_t rule_size
Definition: rte_acl.h:132
union rte_acl_field_types mask_range
Definition: rte_acl.h:79
#define RTE_ACL_RULE_DEF(name, fld_num)
Definition: rte_acl.h:112
uint8_t type
Definition: rte_acl.h:53
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)
struct rte_acl_ctx struct rte_acl_ctx * rte_acl_find_existing(const char *name)
uint8_t input_index
Definition: rte_acl.h:56
uint32_t max_rule_num
Definition: rte_acl.h:133
uint32_t category_mask
Definition: rte_acl.h:102