DPDK 25.03.0-rc0
rte_thash.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2019 Vladimir Medvedkin <medvedkinv@gmail.com>
3 * Copyright(c) 2021 Intel Corporation
4 */
5
6#ifndef _RTE_THASH_H
7#define _RTE_THASH_H
8
18#include <stdint.h>
19
20#include <rte_byteorder.h>
21#include <rte_ip.h>
22#include <rte_common.h>
23#include <rte_thash_gfni.h>
24
25#if defined(RTE_ARCH_X86) || defined(__ARM_NEON)
26#include <rte_vect.h>
27#endif
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#ifdef RTE_ARCH_X86
34/* Byte swap mask used for converting IPv6 address
35 * 4-byte chunks to CPU byte order
36 */
37static const __m128i rte_thash_ipv6_bswap_mask = {
38 0x0405060700010203ULL, 0x0C0D0E0F08090A0BULL};
39#endif
40
45#define RTE_THASH_V4_L3_LEN ((sizeof(struct rte_ipv4_tuple) - \
46 sizeof(((struct rte_ipv4_tuple *)0)->sctp_tag)) / 4)
47
53#define RTE_THASH_V4_L4_LEN ((sizeof(struct rte_ipv4_tuple)) / 4)
54
59#define RTE_THASH_V6_L3_LEN ((sizeof(struct rte_ipv6_tuple) - \
60 sizeof(((struct rte_ipv6_tuple *)0)->sctp_tag)) / 4)
61
67#define RTE_THASH_V6_L4_LEN ((sizeof(struct rte_ipv6_tuple)) / 4)
68
74 uint32_t src_addr;
75 uint32_t dst_addr;
76 union {
77 struct {
78 uint16_t dport;
79 uint16_t sport;
80 };
81 uint32_t sctp_tag;
82 };
83};
84
91 struct rte_ipv6_addr src_addr;
92 struct rte_ipv6_addr dst_addr;
93 union {
94 struct {
95 uint16_t dport;
96 uint16_t sport;
97 };
98 uint32_t sctp_tag;
99 };
100};
101
102#ifdef RTE_ARCH_X86
103union __rte_aligned(XMM_SIZE) rte_thash_tuple {
104#else
105union rte_thash_tuple {
106#endif
107 struct rte_ipv4_tuple v4;
108 struct rte_ipv6_tuple v6;
109};
110
120__rte_internal
121uint32_t
122thash_get_rand_poly(uint32_t poly_degree);
123
133static inline void
134rte_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
135{
136 int i;
137
138 for (i = 0; i < (len >> 2); i++)
139 targ[i] = rte_be_to_cpu_32(orig[i]);
140}
141
150static inline void
151rte_thash_load_v6_addrs(const struct rte_ipv6_hdr *orig,
152 union rte_thash_tuple *targ)
153{
154#ifdef RTE_ARCH_X86
155 __m128i ipv6 = _mm_loadu_si128((const __m128i *)&orig->src_addr);
156 *(__m128i *)&targ->v6.src_addr =
157 _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
158 ipv6 = _mm_loadu_si128((const __m128i *)&orig->dst_addr);
159 *(__m128i *)&targ->v6.dst_addr =
160 _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
161#elif defined(__ARM_NEON)
162 uint8x16_t ipv6 = vld1q_u8(orig->src_addr.a);
163 vst1q_u8(targ->v6.src_addr.a, vrev32q_u8(ipv6));
164 ipv6 = vld1q_u8(orig->dst_addr.a);
165 vst1q_u8(targ->v6.dst_addr.a, vrev32q_u8(ipv6));
166#else
167 int i;
168 for (i = 0; i < 4; i++) {
169 *((uint32_t *)&targ->v6.src_addr + i) =
170 rte_be_to_cpu_32(*((const uint32_t *)&orig->src_addr + i));
171 *((uint32_t *)&targ->v6.dst_addr + i) =
172 rte_be_to_cpu_32(*((const uint32_t *)&orig->dst_addr + i));
173 }
174#endif
175}
176
188static inline uint32_t
189rte_softrss(uint32_t *input_tuple, uint32_t input_len,
190 const uint8_t *rss_key)
191{
192 uint32_t i, j, map, ret = 0;
193
194 for (j = 0; j < input_len; j++) {
195 for (map = input_tuple[j]; map; map &= (map - 1)) {
196 i = rte_bsf32(map);
197 ret ^= rte_cpu_to_be_32(((const uint32_t *)rss_key)[j]) << (31 - i) |
198 (uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t *)rss_key)[j + 1])) >>
199 (i + 1));
200 }
201 }
202 return ret;
203}
204
218static inline uint32_t
219rte_softrss_be(uint32_t *input_tuple, uint32_t input_len,
220 const uint8_t *rss_key)
221{
222 uint32_t i, j, map, ret = 0;
223
224 for (j = 0; j < input_len; j++) {
225 for (map = input_tuple[j]; map; map &= (map - 1)) {
226 i = rte_bsf32(map);
227 ret ^= ((const uint32_t *)rss_key)[j] << (31 - i) |
228 (uint32_t)((uint64_t)(((const uint32_t *)rss_key)[j + 1]) >> (i + 1));
229 }
230 }
231 return ret;
232}
233
241int
243
256void
257rte_thash_complete_matrix(uint64_t *matrixes, const uint8_t *rss_key,
258 int size);
259
261#define RTE_THASH_RETA_SZ_MIN 2U
263#define RTE_THASH_RETA_SZ_MAX 16U
264
269#define RTE_THASH_IGNORE_PERIOD_OVERFLOW 0x1
274#define RTE_THASH_MINIMAL_SEQ 0x2
275
277struct rte_thash_ctx;
279struct rte_thash_subtuple_helper;
280
303struct rte_thash_ctx *
304rte_thash_init_ctx(const char *name, uint32_t key_len, uint32_t reta_sz,
305 uint8_t *key, uint32_t flags);
306
317struct rte_thash_ctx *
318rte_thash_find_existing(const char *name);
319
326void
327rte_thash_free_ctx(struct rte_thash_ctx *ctx);
328
348int
349rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,
350 uint32_t offset);
351
362struct rte_thash_subtuple_helper *
363rte_thash_get_helper(struct rte_thash_ctx *ctx, const char *name);
364
380uint32_t
381rte_thash_get_complement(struct rte_thash_subtuple_helper *h,
382 uint32_t hash, uint32_t desired_hash);
383
394const uint8_t *
395rte_thash_get_key(struct rte_thash_ctx *ctx);
396
409const uint64_t *
410rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx);
411
428typedef int (*rte_thash_check_tuple_t)(void *userdata, uint8_t *tuple);
429
456int
457rte_thash_adjust_tuple(struct rte_thash_ctx *ctx,
458 struct rte_thash_subtuple_helper *h,
459 uint8_t *tuple, unsigned int tuple_len,
460 uint32_t desired_value, unsigned int attempts,
461 rte_thash_check_tuple_t fn, void *userdata);
462
487__rte_experimental
488int
489rte_thash_gen_key(uint8_t *key, size_t key_len, size_t reta_sz_log,
490 uint32_t entropy_start, size_t entropy_sz);
491
492#ifdef __cplusplus
493}
494#endif
495
496#endif /* _RTE_THASH_H */
static uint32_t rte_bsf32(uint32_t v)
Definition: rte_bitops.h:1106
static uint32_t rte_be_to_cpu_32(rte_be32_t x)
static rte_be32_t rte_cpu_to_be_32(uint32_t x)
static uint32_t rte_softrss_be(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition: rte_thash.h:219
uint32_t rte_thash_get_complement(struct rte_thash_subtuple_helper *h, uint32_t hash, uint32_t desired_hash)
static uint32_t rte_softrss(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition: rte_thash.h:189
__rte_experimental int rte_thash_gen_key(uint8_t *key, size_t key_len, size_t reta_sz_log, uint32_t entropy_start, size_t entropy_sz)
void rte_thash_complete_matrix(uint64_t *matrixes, const uint8_t *rss_key, int size)
static void rte_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
Definition: rte_thash.h:134
const uint8_t * rte_thash_get_key(struct rte_thash_ctx *ctx)
const uint64_t * rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx)
int rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len, uint32_t offset)
int rte_thash_adjust_tuple(struct rte_thash_ctx *ctx, struct rte_thash_subtuple_helper *h, uint8_t *tuple, unsigned int tuple_len, uint32_t desired_value, unsigned int attempts, rte_thash_check_tuple_t fn, void *userdata)
struct rte_thash_ctx * rte_thash_init_ctx(const char *name, uint32_t key_len, uint32_t reta_sz, uint8_t *key, uint32_t flags)
struct rte_thash_ctx * rte_thash_find_existing(const char *name)
int rte_thash_gfni_supported(void)
struct rte_thash_subtuple_helper * rte_thash_get_helper(struct rte_thash_ctx *ctx, const char *name)
int(* rte_thash_check_tuple_t)(void *userdata, uint8_t *tuple)
Definition: rte_thash.h:428
static void rte_thash_load_v6_addrs(const struct rte_ipv6_hdr *orig, union rte_thash_tuple *targ)
Definition: rte_thash.h:151
void rte_thash_free_ctx(struct rte_thash_ctx *ctx)