DPDK  16.04.0
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 = 0,
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, 0);
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,
274  RTE_ACL_CLASSIFY_NUM /* should always be the last one. */
275 };
276 
306 extern int
307 rte_acl_classify(const struct rte_acl_ctx *ctx,
308  const uint8_t **data,
309  uint32_t *results, uint32_t num,
310  uint32_t categories);
311 
346 extern int
347 rte_acl_classify_alg(const struct rte_acl_ctx *ctx,
348  const uint8_t **data,
349  uint32_t *results, uint32_t num,
350  uint32_t categories,
351  enum rte_acl_classify_alg alg);
352 
353 /*
354  * Override the default classifier function for a given ACL context.
355  * @param ctx
356  * ACL context to change classify function for.
357  * @param alg
358  * New default classify algorithm for given ACL context.
359  * It is the caller responsibility to ensure that the value refers to the
360  * existing algorithm, and that it could be run on the given CPU.
361  * @return
362  * - -EINVAL if the parameters are invalid.
363  * - Zero if operation completed successfully.
364  */
365 extern int
366 rte_acl_set_ctx_classify(struct rte_acl_ctx *ctx,
367  enum rte_acl_classify_alg alg);
368 
375 void
376 rte_acl_dump(const struct rte_acl_ctx *ctx);
377 
381 void
382 rte_acl_list_dump(void);
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 
388 #endif /* _RTE_ACL_H_ */