DPDK  22.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_byteorder.h>
24 #include <rte_ip.h>
25 #include <rte_common.h>
26 #include <rte_thash_gfni.h>
27 
28 #if defined(RTE_ARCH_X86) || defined(__ARM_NEON)
29 #include <rte_vect.h>
30 #endif
31 
32 #ifdef RTE_ARCH_X86
33 /* Byte swap mask used for converting IPv6 address
34  * 4-byte chunks to CPU byte order
35  */
36 static const __m128i rte_thash_ipv6_bswap_mask = {
37  0x0405060700010203ULL, 0x0C0D0E0F08090A0BULL};
38 #endif
39 
44 #define RTE_THASH_V4_L3_LEN ((sizeof(struct rte_ipv4_tuple) - \
45  sizeof(((struct rte_ipv4_tuple *)0)->sctp_tag)) / 4)
46 
52 #define RTE_THASH_V4_L4_LEN ((sizeof(struct rte_ipv4_tuple)) / 4)
53 
58 #define RTE_THASH_V6_L3_LEN ((sizeof(struct rte_ipv6_tuple) - \
59  sizeof(((struct rte_ipv6_tuple *)0)->sctp_tag)) / 4)
60 
66 #define RTE_THASH_V6_L4_LEN ((sizeof(struct rte_ipv6_tuple)) / 4)
67 
73  uint32_t src_addr;
74  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  uint8_t src_addr[16];
92  uint8_t dst_addr[16];
94  union {
95  struct {
96  uint16_t dport;
97  uint16_t sport;
98  };
99  uint32_t sctp_tag;
100  };
101 };
102 
103 union rte_thash_tuple {
104  struct rte_ipv4_tuple v4;
105  struct rte_ipv6_tuple v6;
106 #ifdef RTE_ARCH_X86
107 } __rte_aligned(XMM_SIZE);
108 #else
109 };
110 #endif
111 
121 static inline void
122 rte_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
123 {
124  int i;
125 
126  for (i = 0; i < (len >> 2); i++)
127  targ[i] = rte_be_to_cpu_32(orig[i]);
128 }
129 
138 static inline void
140  union rte_thash_tuple *targ)
141 {
142 #ifdef RTE_ARCH_X86
143  __m128i ipv6 = _mm_loadu_si128((const __m128i *)orig->src_addr);
144  *(__m128i *)targ->v6.src_addr =
145  _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
146  ipv6 = _mm_loadu_si128((const __m128i *)orig->dst_addr);
147  *(__m128i *)targ->v6.dst_addr =
148  _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
149 #elif defined(__ARM_NEON)
150  uint8x16_t ipv6 = vld1q_u8((uint8_t const *)orig->src_addr);
151  vst1q_u8((uint8_t *)targ->v6.src_addr, vrev32q_u8(ipv6));
152  ipv6 = vld1q_u8((uint8_t const *)orig->dst_addr);
153  vst1q_u8((uint8_t *)targ->v6.dst_addr, vrev32q_u8(ipv6));
154 #else
155  int i;
156  for (i = 0; i < 4; i++) {
157  *((uint32_t *)targ->v6.src_addr + i) =
158  rte_be_to_cpu_32(*((const uint32_t *)orig->src_addr + i));
159  *((uint32_t *)targ->v6.dst_addr + i) =
160  rte_be_to_cpu_32(*((const uint32_t *)orig->dst_addr + i));
161  }
162 #endif
163 }
164 
176 static inline uint32_t
177 rte_softrss(uint32_t *input_tuple, uint32_t input_len,
178  const uint8_t *rss_key)
179 {
180  uint32_t i, j, map, ret = 0;
181 
182  for (j = 0; j < input_len; j++) {
183  for (map = input_tuple[j]; map; map &= (map - 1)) {
184  i = rte_bsf32(map);
185  ret ^= rte_cpu_to_be_32(((const uint32_t *)rss_key)[j]) << (31 - i) |
186  (uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t *)rss_key)[j + 1])) >>
187  (i + 1));
188  }
189  }
190  return ret;
191 }
192 
206 static inline uint32_t
207 rte_softrss_be(uint32_t *input_tuple, uint32_t input_len,
208  const uint8_t *rss_key)
209 {
210  uint32_t i, j, map, ret = 0;
211 
212  for (j = 0; j < input_len; j++) {
213  for (map = input_tuple[j]; map; map &= (map - 1)) {
214  i = rte_bsf32(map);
215  ret ^= ((const uint32_t *)rss_key)[j] << (31 - i) |
216  (uint32_t)((uint64_t)(((const uint32_t *)rss_key)[j + 1]) >> (i + 1));
217  }
218  }
219  return ret;
220 }
221 
232 __rte_experimental
233 int
235 
251 __rte_experimental
252 void
253 rte_thash_complete_matrix(uint64_t *matrixes, const uint8_t *rss_key,
254  int size);
255 
257 #define RTE_THASH_RETA_SZ_MIN 2U
258 
259 #define RTE_THASH_RETA_SZ_MAX 16U
260 
265 #define RTE_THASH_IGNORE_PERIOD_OVERFLOW 0x1
266 
270 #define RTE_THASH_MINIMAL_SEQ 0x2
271 
273 struct rte_thash_ctx;
275 struct rte_thash_subtuple_helper;
276 
302 __rte_experimental
303 struct rte_thash_ctx *
304 rte_thash_init_ctx(const char *name, uint32_t key_len, uint32_t reta_sz,
305  uint8_t *key, uint32_t flags);
306 
320 __rte_experimental
321 struct rte_thash_ctx *
322 rte_thash_find_existing(const char *name);
323 
335 __rte_experimental
336 void
337 rte_thash_free_ctx(struct rte_thash_ctx *ctx);
338 
361 __rte_experimental
362 int
363 rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,
364  uint32_t offset);
365 
379 __rte_experimental
380 struct rte_thash_subtuple_helper *
381 rte_thash_get_helper(struct rte_thash_ctx *ctx, const char *name);
382 
398 __rte_experimental
399 uint32_t
400 rte_thash_get_complement(struct rte_thash_subtuple_helper *h,
401  uint32_t hash, uint32_t desired_hash);
402 
416 __rte_experimental
417 const uint8_t *
418 rte_thash_get_key(struct rte_thash_ctx *ctx);
419 
435 __rte_experimental
436 const uint64_t *
437 rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx);
438 
458 typedef int (*rte_thash_check_tuple_t)(void *userdata, uint8_t *tuple);
459 
489 __rte_experimental
490 int
491 rte_thash_adjust_tuple(struct rte_thash_ctx *ctx,
492  struct rte_thash_subtuple_helper *h,
493  uint8_t *tuple, unsigned int tuple_len,
494  uint32_t desired_value, unsigned int attempts,
495  rte_thash_check_tuple_t fn, void *userdata);
496 
497 #ifdef __cplusplus
498 }
499 #endif
500 
501 #endif /* _RTE_THASH_H */
struct rte_ether_addr src_addr
Definition: rte_ether.h:269
uint8_t dst_addr[16]
Definition: rte_ip.h:537
int(* rte_thash_check_tuple_t)(void *userdata, uint8_t *tuple)
Definition: rte_thash.h:458
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:122
uint8_t src_addr[16]
Definition: rte_ip.h:536
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:649
static void rte_thash_load_v6_addrs(const struct rte_ipv6_hdr *orig, union rte_thash_tuple *targ)
Definition: rte_thash.h:139
static uint32_t rte_softrss(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition: rte_thash.h:177
__rte_experimental const uint64_t * rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx)
#define RTE_STD_C11
Definition: rte_common.h:42
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:207
__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:71