DPDK 23.11.2
Loading...
Searching...
No Matches
rte_lpm.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
3 * Copyright(c) 2020 Arm Limited
4 */
5
6#ifndef _RTE_LPM_H_
7#define _RTE_LPM_H_
8
14#include <errno.h>
15#include <stdint.h>
16
18#include <rte_byteorder.h>
19#include <rte_common.h>
20#include <rte_vect.h>
21#include <rte_rcu_qsbr.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
28#define RTE_LPM_NAMESIZE 32
29
31#define RTE_LPM_MAX_DEPTH 32
32
34#define RTE_LPM_TBL24_NUM_ENTRIES (1 << 24)
35
37#define RTE_LPM_TBL8_GROUP_NUM_ENTRIES 256
38
40#define RTE_LPM_MAX_TBL8_NUM_GROUPS (1 << 24)
41
43#define RTE_LPM_TBL8_NUM_GROUPS 256
44
46#define RTE_LPM_TBL8_NUM_ENTRIES (RTE_LPM_TBL8_NUM_GROUPS * \
47 RTE_LPM_TBL8_GROUP_NUM_ENTRIES)
48
50#if defined(RTE_LIBRTE_LPM_DEBUG)
51#define RTE_LPM_RETURN_IF_TRUE(cond, retval) do { \
52 if (cond) return (retval); \
53} while (0)
54#else
55#define RTE_LPM_RETURN_IF_TRUE(cond, retval)
56#endif
57
59#define RTE_LPM_VALID_EXT_ENTRY_BITMASK 0x03000000
60
62#define RTE_LPM_LOOKUP_SUCCESS 0x01000000
63
65#define RTE_LPM_RCU_DQ_RECLAIM_MAX 16
66
74
75#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
77__extension__
78struct rte_lpm_tbl_entry {
84 uint32_t next_hop :24;
85 /* Using single uint8_t to store 3 values. */
86 uint32_t valid :1;
94 uint32_t valid_group :1;
95 uint32_t depth :6;
96};
97
98#else
99
100__extension__
101struct rte_lpm_tbl_entry {
102 uint32_t depth :6;
103 uint32_t valid_group :1;
104 uint32_t valid :1;
105 uint32_t next_hop :24;
106
107};
108
109#endif
110
113 uint32_t max_rules;
114 uint32_t number_tbl8s;
115 int flags;
116};
117
119struct rte_lpm {
120 /* LPM Tables. */
121 struct rte_lpm_tbl_entry tbl24[RTE_LPM_TBL24_NUM_ENTRIES]
123 struct rte_lpm_tbl_entry *tbl8;
124};
125
128 struct rte_rcu_qsbr *v; /* RCU QSBR variable. */
129 /* Mode of RCU QSBR. RTE_LPM_QSBR_MODE_xxx
130 * '0' for default: create defer queue for reclaim.
131 */
132 enum rte_lpm_qsbr_mode mode;
133 uint32_t dq_size; /* RCU defer queue size.
134 * default: lpm->number_tbl8s.
135 */
136 uint32_t reclaim_thd; /* Threshold to trigger auto reclaim. */
137 uint32_t reclaim_max; /* Max entries to reclaim in one go.
138 * default: RTE_LPM_RCU_DQ_RECLAIM_MAX.
139 */
140};
141
161struct rte_lpm *
162rte_lpm_create(const char *name, int socket_id,
163 const struct rte_lpm_config *config);
164
175struct rte_lpm *
176rte_lpm_find_existing(const char *name);
177
185void
186rte_lpm_free(struct rte_lpm *lpm);
187
203int rte_lpm_rcu_qsbr_add(struct rte_lpm *lpm, struct rte_lpm_rcu_config *cfg);
204
219int
220rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth, uint32_t next_hop);
221
237int
238rte_lpm_is_rule_present(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
239uint32_t *next_hop);
240
253int
254rte_lpm_delete(struct rte_lpm *lpm, uint32_t ip, uint8_t depth);
255
262void
263rte_lpm_delete_all(struct rte_lpm *lpm);
264
277static inline int
278rte_lpm_lookup(const struct rte_lpm *lpm, uint32_t ip, uint32_t *next_hop)
279{
280 unsigned tbl24_index = (ip >> 8);
281 uint32_t tbl_entry;
282 const uint32_t *ptbl;
283
284 /* DEBUG: Check user input arguments. */
285 RTE_LPM_RETURN_IF_TRUE(((lpm == NULL) || (next_hop == NULL)), -EINVAL);
286
287 /* Copy tbl24 entry */
288 ptbl = (const uint32_t *)(&lpm->tbl24[tbl24_index]);
289 tbl_entry = *ptbl;
290
291 /* Memory ordering is not required in lookup. Because dataflow
292 * dependency exists, compiler or HW won't be able to re-order
293 * the operations.
294 */
295 /* Copy tbl8 entry (only if needed) */
296 if (unlikely((tbl_entry & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
297 RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
298
299 unsigned tbl8_index = (uint8_t)ip +
300 (((uint32_t)tbl_entry & 0x00FFFFFF) *
301 RTE_LPM_TBL8_GROUP_NUM_ENTRIES);
302
303 ptbl = (const uint32_t *)&lpm->tbl8[tbl8_index];
304 tbl_entry = *ptbl;
305 }
306
307 *next_hop = ((uint32_t)tbl_entry & 0x00FFFFFF);
308 return (tbl_entry & RTE_LPM_LOOKUP_SUCCESS) ? 0 : -ENOENT;
309}
310
331#define rte_lpm_lookup_bulk(lpm, ips, next_hops, n) \
332 rte_lpm_lookup_bulk_func(lpm, ips, next_hops, n)
333
334static inline int
335rte_lpm_lookup_bulk_func(const struct rte_lpm *lpm, const uint32_t *ips,
336 uint32_t *next_hops, const unsigned n)
337{
338 unsigned i;
339 unsigned tbl24_indexes[n];
340 const uint32_t *ptbl;
341
342 /* DEBUG: Check user input arguments. */
343 RTE_LPM_RETURN_IF_TRUE(((lpm == NULL) || (ips == NULL) ||
344 (next_hops == NULL)), -EINVAL);
345
346 for (i = 0; i < n; i++) {
347 tbl24_indexes[i] = ips[i] >> 8;
348 }
349
350 for (i = 0; i < n; i++) {
351 /* Simply copy tbl24 entry to output */
352 ptbl = (const uint32_t *)&lpm->tbl24[tbl24_indexes[i]];
353 next_hops[i] = *ptbl;
354
355 /* Overwrite output with tbl8 entry if needed */
356 if (unlikely((next_hops[i] & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
357 RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
358
359 unsigned tbl8_index = (uint8_t)ips[i] +
360 (((uint32_t)next_hops[i] & 0x00FFFFFF) *
361 RTE_LPM_TBL8_GROUP_NUM_ENTRIES);
362
363 ptbl = (const uint32_t *)&lpm->tbl8[tbl8_index];
364 next_hops[i] = *ptbl;
365 }
366 }
367 return 0;
368}
369
370/* Mask four results. */
371#define RTE_LPM_MASKX4_RES UINT64_C(0x00ffffff00ffffff)
372
392static inline void
393rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4],
394 uint32_t defv);
395
396#if defined(RTE_ARCH_ARM)
397#ifdef RTE_HAS_SVE_ACLE
398#include "rte_lpm_sve.h"
399#undef rte_lpm_lookup_bulk
400#define rte_lpm_lookup_bulk(lpm, ips, next_hops, n) \
401 __rte_lpm_lookup_vec(lpm, ips, next_hops, n)
402#endif
403#include "rte_lpm_neon.h"
404#elif defined(RTE_ARCH_PPC_64)
405#include "rte_lpm_altivec.h"
406#elif defined(RTE_ARCH_X86)
407#include "rte_lpm_sse.h"
408#else
409#include "rte_lpm_scalar.h"
410#endif
411
412#ifdef __cplusplus
413}
414#endif
415
416#endif /* _RTE_LPM_H_ */
#define unlikely(x)
#define __rte_cache_aligned
Definition rte_common.h:524
int rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth, uint32_t next_hop)
int rte_lpm_rcu_qsbr_add(struct rte_lpm *lpm, struct rte_lpm_rcu_config *cfg)
int rte_lpm_delete(struct rte_lpm *lpm, uint32_t ip, uint8_t depth)
void rte_lpm_free(struct rte_lpm *lpm)
static void rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], uint32_t defv)
#define RTE_LPM_LOOKUP_SUCCESS
Definition rte_lpm.h:62
rte_lpm_qsbr_mode
Definition rte_lpm.h:68
@ RTE_LPM_QSBR_MODE_DQ
Definition rte_lpm.h:70
@ RTE_LPM_QSBR_MODE_SYNC
Definition rte_lpm.h:72
struct rte_lpm * rte_lpm_create(const char *name, int socket_id, const struct rte_lpm_config *config)
void rte_lpm_delete_all(struct rte_lpm *lpm)
int rte_lpm_is_rule_present(struct rte_lpm *lpm, uint32_t ip, uint8_t depth, uint32_t *next_hop)
static int rte_lpm_lookup(const struct rte_lpm *lpm, uint32_t ip, uint32_t *next_hop)
Definition rte_lpm.h:278
struct rte_lpm * rte_lpm_find_existing(const char *name)
uint32_t number_tbl8s
Definition rte_lpm.h:114
uint32_t max_rules
Definition rte_lpm.h:113