CNDP  22.08.0
cne_acl.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2010-2022 Intel Corporation
3  */
4 
5 #ifndef _CNE_ACL_H_
6 #define _CNE_ACL_H_
7 
14 #include <cne_acl_osdep.h>
15 #include <limits.h> // for CHAR_BIT
16 #include <stddef.h> // for size_t
17 #include <stdint.h> // for uint32_t, uint8_t, int32_t, uint16_t, uint64_t
18 
19 #include "cne_common.h" // for CNE_LEN2MASK
20 #include "cne_vect.h" // for XMM_SIZE
21 
22 struct cne_acl_ctx;
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define CNE_ACL_MAX_CATEGORIES 16
29 
30 #define CNE_ACL_RESULTS_MULTIPLIER (XMM_SIZE / sizeof(uint32_t))
31 
32 #define CNE_ACL_MAX_LEVELS 64
33 #define CNE_ACL_MAX_FIELDS 64
34 
35 union cne_acl_field_types {
36  uint8_t u8;
37  uint16_t u16;
38  uint32_t u32;
39  uint64_t u64;
40 };
41 
42 enum { CNE_ACL_FIELD_TYPE_MASK = 0, CNE_ACL_FIELD_TYPE_RANGE, CNE_ACL_FIELD_TYPE_BITMASK };
43 
56  uint8_t type;
57  uint8_t size;
58  uint8_t field_index;
59  uint8_t input_index;
60  uint32_t offset;
61 };
62 
68  uint32_t num_categories;
69  uint32_t num_fields;
70  struct cne_acl_field_def defs[CNE_ACL_MAX_FIELDS];
72  size_t max_size;
74 };
75 
79 struct cne_acl_field {
80  union cne_acl_field_types value;
82  union cne_acl_field_types mask_range;
89 };
90 
91 enum {
92  CNE_ACL_TYPE_SHIFT = 29,
93  CNE_ACL_MAX_INDEX = CNE_LEN2MASK(CNE_ACL_TYPE_SHIFT, uint32_t),
94  CNE_ACL_MAX_PRIORITY = CNE_ACL_MAX_INDEX,
95  CNE_ACL_MIN_PRIORITY = 1,
96 };
97 
98 #define CNE_ACL_MASKLEN_TO_BITMASK(v, s) \
99  ((v) == 0 ? (v) : (typeof(v))((uint64_t)-1 << ((s)*CHAR_BIT - (v))))
100 
105  uint32_t category_mask;
106  int32_t priority;
107  uint32_t userdata;
108 };
109 
115 #define CNE_ACL_RULE_DEF(name, fld_num) \
116  struct name { \
117  struct cne_acl_rule_data data; \
118  struct cne_acl_field field[fld_num]; \
119  }
120 
121 CNE_ACL_RULE_DEF(cne_acl_rule, );
122 
123 #define CNE_ACL_RULE_SZ(fld_num) \
124  (sizeof(struct cne_acl_rule) + sizeof(struct cne_acl_field) * (fld_num))
125 
127 #define CNE_ACL_NAMESIZE 32
128 
133  const char *name;
134  uint32_t rule_size;
135  uint32_t max_rule_num;
136 };
141  CNE_ACL_CLASSIFY_DEFAULT = 0,
149  CNE_ACL_CLASSIFY_NUM /* should always be the last one. */
150 };
151 
163 struct cne_acl_ctx *cne_acl_create(const struct cne_acl_param *param);
164 
171 void cne_acl_free(struct cne_acl_ctx *ctx);
172 
192 int cne_acl_add_rules(struct cne_acl_ctx *ctx, const struct cne_acl_rule *rules, uint32_t num);
193 
202 void cne_acl_reset_rules(struct cne_acl_ctx *ctx);
203 
218 int cne_acl_build(struct cne_acl_ctx *ctx, const struct cne_acl_config *cfg);
219 
228 void cne_acl_reset(struct cne_acl_ctx *ctx);
229 
240 void cne_acl_set_algo(struct cne_acl_ctx *ctx, enum cne_acl_classify_alg algo);
241 
271 extern int cne_acl_classify(const struct cne_acl_ctx *ctx, const uint8_t **data, uint32_t *results,
272  uint32_t num, uint32_t categories);
273 
308 extern int cne_acl_classify_alg(const struct cne_acl_ctx *ctx, const uint8_t **data,
309  uint32_t *results, uint32_t num, uint32_t categories,
310  enum cne_acl_classify_alg alg);
311 
312 /*
313  * Override the default classifier function for a given ACL context.
314  * @param ctx
315  * ACL context to change classify function for.
316  * @param alg
317  * New default classify algorithm for given ACL context.
318  * It is the caller responsibility to ensure that the value refers to the
319  * existing algorithm, and that it could be run on the given CPU.
320  * @return
321  * - -EINVAL if the parameters are invalid.
322  * - Zero if operation completed successfully.
323  */
324 extern int cne_acl_set_ctx_classify(struct cne_acl_ctx *ctx, enum cne_acl_classify_alg alg);
325 
332 void cne_acl_dump(const struct cne_acl_ctx *ctx);
333 
334 #ifdef __cplusplus
335 }
336 #endif
337 
338 #endif /* _CNE_ACL_H_ */
cne_acl_classify_alg
Definition: cne_acl.h:140
@ CNE_ACL_CLASSIFY_NEON
Definition: cne_acl.h:145
@ CNE_ACL_CLASSIFY_AVX512X32
Definition: cne_acl.h:148
@ CNE_ACL_CLASSIFY_AVX512X16
Definition: cne_acl.h:147
@ CNE_ACL_CLASSIFY_SSE
Definition: cne_acl.h:143
@ CNE_ACL_CLASSIFY_SCALAR
Definition: cne_acl.h:142
@ CNE_ACL_CLASSIFY_AVX2
Definition: cne_acl.h:144
@ CNE_ACL_CLASSIFY_ALTIVEC
Definition: cne_acl.h:146
#define CNE_ACL_RULE_DEF(name, fld_num)
Definition: cne_acl.h:115
int cne_acl_add_rules(struct cne_acl_ctx *ctx, const struct cne_acl_rule *rules, uint32_t num)
void cne_acl_free(struct cne_acl_ctx *ctx)
void cne_acl_reset(struct cne_acl_ctx *ctx)
void cne_acl_set_algo(struct cne_acl_ctx *ctx, enum cne_acl_classify_alg algo)
void cne_acl_dump(const struct cne_acl_ctx *ctx)
struct cne_acl_ctx * cne_acl_create(const struct cne_acl_param *param)
int cne_acl_build(struct cne_acl_ctx *ctx, const struct cne_acl_config *cfg)
int cne_acl_classify(const struct cne_acl_ctx *ctx, const uint8_t **data, uint32_t *results, uint32_t num, uint32_t categories)
void cne_acl_reset_rules(struct cne_acl_ctx *ctx)
#define CNE_LEN2MASK(ln, tp)
Definition: cne_common.h:775
uint32_t num_fields
Definition: cne_acl.h:69
struct cne_acl_field_def defs[CNE_ACL_MAX_FIELDS]
Definition: cne_acl.h:70
uint32_t num_categories
Definition: cne_acl.h:68
size_t max_size
Definition: cne_acl.h:72
uint8_t type
Definition: cne_acl.h:56
uint32_t offset
Definition: cne_acl.h:60
uint8_t input_index
Definition: cne_acl.h:59
uint8_t field_index
Definition: cne_acl.h:58
uint8_t size
Definition: cne_acl.h:57
union cne_acl_field_types value
Definition: cne_acl.h:80
union cne_acl_field_types mask_range
Definition: cne_acl.h:82
const char * name
Definition: cne_acl.h:133
uint32_t max_rule_num
Definition: cne_acl.h:135
uint32_t rule_size
Definition: cne_acl.h:134
int32_t priority
Definition: cne_acl.h:106
uint32_t userdata
Definition: cne_acl.h:107
uint32_t category_mask
Definition: cne_acl.h:105