DPDK  17.11.10
rte_acl.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_ACL_H_
35 #define _RTE_ACL_H_
36 
43 #include <rte_acl_osdep.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #define RTE_ACL_MAX_CATEGORIES 16
50 
51 #define RTE_ACL_RESULTS_MULTIPLIER (XMM_SIZE / sizeof(uint32_t))
52 
53 #define RTE_ACL_MAX_LEVELS 64
54 #define RTE_ACL_MAX_FIELDS 64
55 
56 union rte_acl_field_types {
57  uint8_t u8;
58  uint16_t u16;
59  uint32_t u32;
60  uint64_t u64;
61 };
62 
63 enum {
64  RTE_ACL_FIELD_TYPE_MASK = 0,
65  RTE_ACL_FIELD_TYPE_RANGE,
66  RTE_ACL_FIELD_TYPE_BITMASK
67 };
68 
81  uint8_t type;
82  uint8_t size;
83  uint8_t field_index;
84  uint8_t input_index;
85  uint32_t offset;
86 };
87 
93  uint32_t num_categories;
94  uint32_t num_fields;
95  struct rte_acl_field_def defs[RTE_ACL_MAX_FIELDS];
97  size_t max_size;
99 };
100 
105  union rte_acl_field_types value;
107  union rte_acl_field_types mask_range;
114 };
115 
116 enum {
117  RTE_ACL_TYPE_SHIFT = 29,
118  RTE_ACL_MAX_INDEX = RTE_LEN2MASK(RTE_ACL_TYPE_SHIFT, uint32_t),
119  RTE_ACL_MAX_PRIORITY = RTE_ACL_MAX_INDEX,
120  RTE_ACL_MIN_PRIORITY = 1,
121 };
122 
123 #define RTE_ACL_MASKLEN_TO_BITMASK(v, s) \
124 ((v) == 0 ? (v) : (typeof(v))((uint64_t)-1 << ((s) * CHAR_BIT - (v))))
125 
130  uint32_t category_mask;
131  int32_t priority;
132  uint32_t userdata;
133 };
134 
140 #define RTE_ACL_RULE_DEF(name, fld_num) struct name {\
141  struct rte_acl_rule_data data; \
142  struct rte_acl_field field[fld_num]; \
143 }
144 
145 RTE_ACL_RULE_DEF(rte_acl_rule,);
146 
147 #define RTE_ACL_RULE_SZ(fld_num) \
148  (sizeof(struct rte_acl_rule) + sizeof(struct rte_acl_field) * (fld_num))
149 
150 
152 #define RTE_ACL_NAMESIZE 32
153 
158  const char *name;
159  int socket_id;
160  uint32_t rule_size;
161  uint32_t max_rule_num;
162 };
163 
164 
176 struct rte_acl_ctx *
177 rte_acl_create(const struct rte_acl_param *param);
178 
189 struct rte_acl_ctx *
190 rte_acl_find_existing(const char *name);
191 
198 void
199 rte_acl_free(struct rte_acl_ctx *ctx);
200 
220 int
221 rte_acl_add_rules(struct rte_acl_ctx *ctx, const struct rte_acl_rule *rules,
222  uint32_t num);
223 
232 void
233 rte_acl_reset_rules(struct rte_acl_ctx *ctx);
234 
249 int
250 rte_acl_build(struct rte_acl_ctx *ctx, const struct rte_acl_config *cfg);
251 
260 void
261 rte_acl_reset(struct rte_acl_ctx *ctx);
262 
267  RTE_ACL_CLASSIFY_DEFAULT = 0,
273  RTE_ACL_CLASSIFY_NUM /* should always be the last one. */
274 };
275 
305 extern int
306 rte_acl_classify(const struct rte_acl_ctx *ctx,
307  const uint8_t **data,
308  uint32_t *results, uint32_t num,
309  uint32_t categories);
310 
345 extern int
346 rte_acl_classify_alg(const struct rte_acl_ctx *ctx,
347  const uint8_t **data,
348  uint32_t *results, uint32_t num,
349  uint32_t categories,
350  enum rte_acl_classify_alg alg);
351 
352 /*
353  * Override the default classifier function for a given ACL context.
354  * @param ctx
355  * ACL context to change classify function for.
356  * @param alg
357  * New default classify algorithm for given ACL context.
358  * It is the caller responsibility to ensure that the value refers to the
359  * existing algorithm, and that it could be run on the given CPU.
360  * @return
361  * - -EINVAL if the parameters are invalid.
362  * - Zero if operation completed successfully.
363  */
364 extern int
365 rte_acl_set_ctx_classify(struct rte_acl_ctx *ctx,
366  enum rte_acl_classify_alg alg);
367 
374 void
375 rte_acl_dump(const struct rte_acl_ctx *ctx);
376 
380 void
381 rte_acl_list_dump(void);
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 
387 #endif /* _RTE_ACL_H_ */
uint32_t offset
Definition: rte_acl.h:85
union rte_acl_field_types value
Definition: rte_acl.h:105
struct rte_acl_ctx * rte_acl_create(const struct rte_acl_param *param)
rte_acl_classify_alg
Definition: rte_acl.h:266
uint8_t field_index
Definition: rte_acl.h:83
void rte_acl_dump(const struct rte_acl_ctx *ctx)
const char * name
Definition: rte_acl.h:158
int socket_id
Definition: rte_acl.h:159
uint8_t size
Definition: rte_acl.h:82
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:95
#define RTE_LEN2MASK(ln, tp)
Definition: rte_common.h:424
uint32_t num_categories
Definition: rte_acl.h:93
size_t max_size
Definition: rte_acl.h:97
uint32_t userdata
Definition: rte_acl.h:132
int32_t priority
Definition: rte_acl.h:131
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:94
uint32_t rule_size
Definition: rte_acl.h:160
struct rte_acl_ctx * rte_acl_find_existing(const char *name)
union rte_acl_field_types mask_range
Definition: rte_acl.h:107
#define RTE_ACL_RULE_DEF(name, fld_num)
Definition: rte_acl.h:140
uint8_t type
Definition: rte_acl.h:81
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:84
uint32_t max_rule_num
Definition: rte_acl.h:161
uint32_t category_mask
Definition: rte_acl.h:130