DPDK  16.11.11
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_INVALID_USERDATA 0
124 
125 #define RTE_ACL_MASKLEN_TO_BITMASK(v, s) \
126 ((v) == 0 ? (v) : (typeof(v))((uint64_t)-1 << ((s) * CHAR_BIT - (v))))
127 
132  uint32_t category_mask;
133  int32_t priority;
134  uint32_t userdata;
135 };
136 
142 #define RTE_ACL_RULE_DEF(name, fld_num) struct name {\
143  struct rte_acl_rule_data data; \
144  struct rte_acl_field field[fld_num]; \
145 }
146 
147 RTE_ACL_RULE_DEF(rte_acl_rule,);
148 
149 #define RTE_ACL_RULE_SZ(fld_num) \
150  (sizeof(struct rte_acl_rule) + sizeof(struct rte_acl_field) * (fld_num))
151 
152 
154 #define RTE_ACL_NAMESIZE 32
155 
160  const char *name;
161  int socket_id;
162  uint32_t rule_size;
163  uint32_t max_rule_num;
164 };
165 
166 
178 struct rte_acl_ctx *
179 rte_acl_create(const struct rte_acl_param *param);
180 
191 struct rte_acl_ctx *
192 rte_acl_find_existing(const char *name);
193 
200 void
201 rte_acl_free(struct rte_acl_ctx *ctx);
202 
222 int
223 rte_acl_add_rules(struct rte_acl_ctx *ctx, const struct rte_acl_rule *rules,
224  uint32_t num);
225 
234 void
235 rte_acl_reset_rules(struct rte_acl_ctx *ctx);
236 
251 int
252 rte_acl_build(struct rte_acl_ctx *ctx, const struct rte_acl_config *cfg);
253 
262 void
263 rte_acl_reset(struct rte_acl_ctx *ctx);
264 
269  RTE_ACL_CLASSIFY_DEFAULT = 0,
275  RTE_ACL_CLASSIFY_NUM /* should always be the last one. */
276 };
277 
307 extern int
308 rte_acl_classify(const struct rte_acl_ctx *ctx,
309  const uint8_t **data,
310  uint32_t *results, uint32_t num,
311  uint32_t categories);
312 
347 extern int
348 rte_acl_classify_alg(const struct rte_acl_ctx *ctx,
349  const uint8_t **data,
350  uint32_t *results, uint32_t num,
351  uint32_t categories,
352  enum rte_acl_classify_alg alg);
353 
354 /*
355  * Override the default classifier function for a given ACL context.
356  * @param ctx
357  * ACL context to change classify function for.
358  * @param alg
359  * New default classify algorithm for given ACL context.
360  * It is the caller responsibility to ensure that the value refers to the
361  * existing algorithm, and that it could be run on the given CPU.
362  * @return
363  * - -EINVAL if the parameters are invalid.
364  * - Zero if operation completed successfully.
365  */
366 extern int
367 rte_acl_set_ctx_classify(struct rte_acl_ctx *ctx,
368  enum rte_acl_classify_alg alg);
369 
376 void
377 rte_acl_dump(const struct rte_acl_ctx *ctx);
378 
382 void
383 rte_acl_list_dump(void);
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 
389 #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:268
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:160
int socket_id
Definition: rte_acl.h:161
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:356
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:134
int32_t priority
Definition: rte_acl.h:133
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:162
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:142
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:163
uint32_t category_mask
Definition: rte_acl.h:132