DPDK  23.07.0
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 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include <stdint.h>
23 #include <rte_compat.h>
24 #include <rte_byteorder.h>
25 #include <rte_ip.h>
26 #include <rte_common.h>
27 #include <rte_thash_gfni.h>
28 
29 #if defined(RTE_ARCH_X86) || defined(__ARM_NEON)
30 #include <rte_vect.h>
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  */
37 static 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;
77  union {
78  struct {
79  uint16_t dport;
80  uint16_t sport;
81  };
82  uint32_t sctp_tag;
83  };
84 };
85 
92  uint8_t src_addr[16];
93  uint8_t dst_addr[16];
95  union {
96  struct {
97  uint16_t dport;
98  uint16_t sport;
99  };
100  uint32_t sctp_tag;
101  };
102 };
103 
104 union rte_thash_tuple {
105  struct rte_ipv4_tuple v4;
106  struct rte_ipv6_tuple v6;
107 #ifdef RTE_ARCH_X86
108 } __rte_aligned(XMM_SIZE);
109 #else
110 };
111 #endif
112 
122 static inline void
123 rte_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
124 {
125  int i;
126 
127  for (i = 0; i < (len >> 2); i++)
128  targ[i] = rte_be_to_cpu_32(orig[i]);
129 }
130 
139 static inline void
141  union rte_thash_tuple *targ)
142 {
143 #ifdef RTE_ARCH_X86
144  __m128i ipv6 = _mm_loadu_si128((const __m128i *)orig->src_addr);
145  *(__m128i *)targ->v6.src_addr =
146  _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
147  ipv6 = _mm_loadu_si128((const __m128i *)orig->dst_addr);
148  *(__m128i *)targ->v6.dst_addr =
149  _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
150 #elif defined(__ARM_NEON)
151  uint8x16_t ipv6 = vld1q_u8((uint8_t const *)orig->src_addr);
152  vst1q_u8((uint8_t *)targ->v6.src_addr, vrev32q_u8(ipv6));
153  ipv6 = vld1q_u8((uint8_t const *)orig->dst_addr);
154  vst1q_u8((uint8_t *)targ->v6.dst_addr, vrev32q_u8(ipv6));
155 #else
156  int i;
157  for (i = 0; i < 4; i++) {
158  *((uint32_t *)targ->v6.src_addr + i) =
159  rte_be_to_cpu_32(*((const uint32_t *)orig->src_addr + i));
160  *((uint32_t *)targ->v6.dst_addr + i) =
161  rte_be_to_cpu_32(*((const uint32_t *)orig->dst_addr + i));
162  }
163 #endif
164 }
165 
177 static inline uint32_t
178 rte_softrss(uint32_t *input_tuple, uint32_t input_len,
179  const uint8_t *rss_key)
180 {
181  uint32_t i, j, map, ret = 0;
182 
183  for (j = 0; j < input_len; j++) {
184  for (map = input_tuple[j]; map; map &= (map - 1)) {
185  i = rte_bsf32(map);
186  ret ^= rte_cpu_to_be_32(((const uint32_t *)rss_key)[j]) << (31 - i) |
187  (uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t *)rss_key)[j + 1])) >>
188  (i + 1));
189  }
190  }
191  return ret;
192 }
193 
207 static inline uint32_t
208 rte_softrss_be(uint32_t *input_tuple, uint32_t input_len,
209  const uint8_t *rss_key)
210 {
211  uint32_t i, j, map, ret = 0;
212 
213  for (j = 0; j < input_len; j++) {
214  for (map = input_tuple[j]; map; map &= (map - 1)) {
215  i = rte_bsf32(map);
216  ret ^= ((const uint32_t *)rss_key)[j] << (31 - i) |
217  (uint32_t)((uint64_t)(((const uint32_t *)rss_key)[j + 1]) >> (i + 1));
218  }
219  }
220  return ret;
221 }
222 
233 __rte_experimental
234 int
236 
252 __rte_experimental
253 void
254 rte_thash_complete_matrix(uint64_t *matrixes, const uint8_t *rss_key,
255  int size);
256 
258 #define RTE_THASH_RETA_SZ_MIN 2U
259 
260 #define RTE_THASH_RETA_SZ_MAX 16U
261 
266 #define RTE_THASH_IGNORE_PERIOD_OVERFLOW 0x1
267 
271 #define RTE_THASH_MINIMAL_SEQ 0x2
272 
274 struct rte_thash_ctx;
276 struct rte_thash_subtuple_helper;
277 
303 __rte_experimental
304 struct rte_thash_ctx *
305 rte_thash_init_ctx(const char *name, uint32_t key_len, uint32_t reta_sz,
306  uint8_t *key, uint32_t flags);
307 
321 __rte_experimental
322 struct rte_thash_ctx *
323 rte_thash_find_existing(const char *name);
324 
334 __rte_experimental
335 void
336 rte_thash_free_ctx(struct rte_thash_ctx *ctx);
337 
360 __rte_experimental
361 int
362 rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,
363  uint32_t offset);
364 
378 __rte_experimental
379 struct rte_thash_subtuple_helper *
380 rte_thash_get_helper(struct rte_thash_ctx *ctx, const char *name);
381 
397 __rte_experimental
398 uint32_t
399 rte_thash_get_complement(struct rte_thash_subtuple_helper *h,
400  uint32_t hash, uint32_t desired_hash);
401 
415 __rte_experimental
416 const uint8_t *
417 rte_thash_get_key(struct rte_thash_ctx *ctx);
418 
434 __rte_experimental
435 const uint64_t *
436 rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx);
437 
457 typedef int (*rte_thash_check_tuple_t)(void *userdata, uint8_t *tuple);
458 
488 __rte_experimental
489 int
490 rte_thash_adjust_tuple(struct rte_thash_ctx *ctx,
491  struct rte_thash_subtuple_helper *h,
492  uint8_t *tuple, unsigned int tuple_len,
493  uint32_t desired_value, unsigned int attempts,
494  rte_thash_check_tuple_t fn, void *userdata);
495 
496 #ifdef __cplusplus
497 }
498 #endif
499 
500 #endif /* _RTE_THASH_H */
struct rte_ether_addr src_addr
Definition: rte_ether.h:269
uint8_t dst_addr[16]
Definition: rte_ip.h:541
int(* rte_thash_check_tuple_t)(void *userdata, uint8_t *tuple)
Definition: rte_thash.h:457
static rte_be32_t rte_cpu_to_be_32(uint32_t x)
__rte_experimental int rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len, uint32_t offset)
static void rte_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
Definition: rte_thash.h:123
uint8_t src_addr[16]
Definition: rte_ip.h:540
struct rte_ether_addr dst_addr
Definition: rte_ether.h:268
__rte_experimental 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)
__rte_experimental void rte_thash_complete_matrix(uint64_t *matrixes, const uint8_t *rss_key, int size)
static uint32_t rte_bsf32(uint32_t v)
Definition: rte_common.h:644
static void rte_thash_load_v6_addrs(const struct rte_ipv6_hdr *orig, union rte_thash_tuple *targ)
Definition: rte_thash.h:140
static uint32_t rte_softrss(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition: rte_thash.h:178
__rte_experimental const uint64_t * rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx)
#define RTE_STD_C11
Definition: rte_common.h:39
static uint32_t rte_be_to_cpu_32(rte_be32_t x)
__rte_experimental int rte_thash_gfni_supported(void)
__rte_experimental struct rte_thash_ctx * rte_thash_find_existing(const char *name)
static uint32_t rte_softrss_be(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition: rte_thash.h:208
__rte_experimental uint32_t rte_thash_get_complement(struct rte_thash_subtuple_helper *h, uint32_t hash, uint32_t desired_hash)
__rte_experimental const uint8_t * rte_thash_get_key(struct rte_thash_ctx *ctx)
__rte_experimental void rte_thash_free_ctx(struct rte_thash_ctx *ctx)
__rte_experimental 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)
__rte_experimental struct rte_thash_subtuple_helper * rte_thash_get_helper(struct rte_thash_ctx *ctx, const char *name)
#define __rte_aligned(a)
Definition: rte_common.h:68