15 #include <sys/queue.h>
20 #include <rte_config.h>
31 #define RTE_LPM_NAMESIZE 32
34 #define RTE_LPM_MAX_DEPTH 32
37 #define RTE_LPM_TBL24_NUM_ENTRIES (1 << 24)
40 #define RTE_LPM_TBL8_GROUP_NUM_ENTRIES 256
43 #define RTE_LPM_MAX_TBL8_NUM_GROUPS (1 << 24)
46 #define RTE_LPM_TBL8_NUM_GROUPS 256
49 #define RTE_LPM_TBL8_NUM_ENTRIES (RTE_LPM_TBL8_NUM_GROUPS * \
50 RTE_LPM_TBL8_GROUP_NUM_ENTRIES)
53 #if defined(RTE_LIBRTE_LPM_DEBUG)
54 #define RTE_LPM_RETURN_IF_TRUE(cond, retval) do { \
55 if (cond) return (retval); \
58 #define RTE_LPM_RETURN_IF_TRUE(cond, retval)
62 #define RTE_LPM_VALID_EXT_ENTRY_BITMASK 0x03000000
65 #define RTE_LPM_LOOKUP_SUCCESS 0x01000000
68 #define RTE_LPM_RCU_DQ_RECLAIM_MAX 16
78 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
81 struct rte_lpm_tbl_entry {
87 uint32_t next_hop :24;
97 uint32_t valid_group :1;
104 struct rte_lpm_tbl_entry {
106 uint32_t valid_group :1;
108 uint32_t next_hop :24;
122 struct rte_lpm_rule {
128 struct rte_lpm_rule_info {
138 uint32_t number_tbl8s;
142 struct rte_lpm_tbl_entry tbl24[RTE_LPM_TBL24_NUM_ENTRIES]
144 struct rte_lpm_tbl_entry *tbl8;
145 struct rte_lpm_rule *rules_tbl;
150 struct rte_rcu_qsbr *v;
158 uint32_t reclaim_thd;
159 uint32_t reclaim_max;
247 rte_lpm_add(
struct rte_lpm *lpm, uint32_t ip, uint8_t depth, uint32_t next_hop);
307 unsigned tbl24_index = (ip >> 8);
309 const uint32_t *ptbl;
312 RTE_LPM_RETURN_IF_TRUE(((lpm == NULL) || (next_hop == NULL)), -EINVAL);
315 ptbl = (
const uint32_t *)(&lpm->tbl24[tbl24_index]);
323 if (
unlikely((tbl_entry & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
324 RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
326 unsigned tbl8_index = (uint8_t)ip +
327 (((uint32_t)tbl_entry & 0x00FFFFFF) *
328 RTE_LPM_TBL8_GROUP_NUM_ENTRIES);
330 ptbl = (
const uint32_t *)&lpm->tbl8[tbl8_index];
334 *next_hop = ((uint32_t)tbl_entry & 0x00FFFFFF);
358 #define rte_lpm_lookup_bulk(lpm, ips, next_hops, n) \
359 rte_lpm_lookup_bulk_func(lpm, ips, next_hops, n)
362 rte_lpm_lookup_bulk_func(
const struct rte_lpm *lpm,
const uint32_t *ips,
363 uint32_t *next_hops,
const unsigned n)
366 unsigned tbl24_indexes[n];
367 const uint32_t *ptbl;
370 RTE_LPM_RETURN_IF_TRUE(((lpm == NULL) || (ips == NULL) ||
371 (next_hops == NULL)), -EINVAL);
373 for (i = 0; i < n; i++) {
374 tbl24_indexes[i] = ips[i] >> 8;
377 for (i = 0; i < n; i++) {
379 ptbl = (
const uint32_t *)&lpm->tbl24[tbl24_indexes[i]];
380 next_hops[i] = *ptbl;
383 if (
unlikely((next_hops[i] & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
384 RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
386 unsigned tbl8_index = (uint8_t)ips[i] +
387 (((uint32_t)next_hops[i] & 0x00FFFFFF) *
388 RTE_LPM_TBL8_GROUP_NUM_ENTRIES);
390 ptbl = (
const uint32_t *)&lpm->tbl8[tbl8_index];
391 next_hops[i] = *ptbl;
398 #define RTE_LPM_MASKX4_RES UINT64_C(0x00ffffff00ffffff)
423 #if defined(RTE_ARCH_ARM) || defined(RTE_ARCH_ARM64)
424 #include "rte_lpm_neon.h"
425 #elif defined(RTE_ARCH_PPC_64)
426 #include "rte_lpm_altivec.h"
428 #include "rte_lpm_sse.h"
void rte_lpm_free(struct rte_lpm *lpm)
__rte_experimental int rte_lpm_rcu_qsbr_add(struct rte_lpm *lpm, struct rte_lpm_rcu_config *cfg)
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)
#define RTE_LPM_MAX_DEPTH
static int rte_lpm_lookup(struct rte_lpm *lpm, uint32_t ip, uint32_t *next_hop)
static void rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], uint32_t defv)
int rte_lpm_delete(struct rte_lpm *lpm, uint32_t ip, uint8_t depth)
#define __rte_cache_aligned
#define RTE_LPM_LOOKUP_SUCCESS
int rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth, uint32_t next_hop)
int rte_lpm_is_rule_present(struct rte_lpm *lpm, uint32_t ip, uint8_t depth, uint32_t *next_hop)
struct rte_lpm * rte_lpm_find_existing(const char *name)