DPDK  20.11.2
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  */
4 
5 #ifndef _RTE_THASH_H
6 #define _RTE_THASH_H
7 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
25 #include <stdint.h>
26 #include <rte_byteorder.h>
27 #include <rte_config.h>
28 #include <rte_ip.h>
29 #include <rte_common.h>
30 
31 #if defined(RTE_ARCH_X86) || defined(__ARM_NEON) || \
32  defined(RTE_ARCH_LOONGARCH_64)
33 #include <rte_vect.h>
34 #endif
35 
36 #ifdef RTE_ARCH_X86
37 /* Byte swap mask used for converting IPv6 address
38  * 4-byte chunks to CPU byte order
39  */
40 static const __m128i rte_thash_ipv6_bswap_mask = {
41  0x0405060700010203ULL, 0x0C0D0E0F08090A0BULL};
42 #elif defined(RTE_ARCH_LOONGARCH_64)
43 static const xmm_t rte_thash_ipv6_bswap_mask = (xmm_t){.u64 = {
44  0x0405060700010203ULL, 0x0C0D0E0F08090A0BULL,} };
45 #endif
46 
51 #define RTE_THASH_V4_L3_LEN ((sizeof(struct rte_ipv4_tuple) - \
52  sizeof(((struct rte_ipv4_tuple *)0)->sctp_tag)) / 4)
53 
59 #define RTE_THASH_V4_L4_LEN ((sizeof(struct rte_ipv4_tuple)) / 4)
60 
65 #define RTE_THASH_V6_L3_LEN ((sizeof(struct rte_ipv6_tuple) - \
66  sizeof(((struct rte_ipv6_tuple *)0)->sctp_tag)) / 4)
67 
73 #define RTE_THASH_V6_L4_LEN ((sizeof(struct rte_ipv6_tuple)) / 4)
74 
80  uint32_t src_addr;
81  uint32_t dst_addr;
83  union {
84  struct {
85  uint16_t dport;
86  uint16_t sport;
87  };
88  uint32_t sctp_tag;
89  };
90 };
91 
98  uint8_t src_addr[16];
99  uint8_t dst_addr[16];
101  union {
102  struct {
103  uint16_t dport;
104  uint16_t sport;
105  };
106  uint32_t sctp_tag;
107  };
108 };
109 
110 union rte_thash_tuple {
111  struct rte_ipv4_tuple v4;
112  struct rte_ipv6_tuple v6;
113 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_LOONGARCH_64)
114 } __rte_aligned(XMM_SIZE);
115 #else
116 };
117 #endif
118 
128 static inline void
129 rte_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
130 {
131  int i;
132 
133  for (i = 0; i < (len >> 2); i++)
134  targ[i] = rte_be_to_cpu_32(orig[i]);
135 }
136 
145 static inline void
147  union rte_thash_tuple *targ)
148 {
149 #ifdef RTE_ARCH_X86
150  __m128i ipv6 = _mm_loadu_si128((const __m128i *)orig->src_addr);
151  *(__m128i *)targ->v6.src_addr =
152  _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
153  ipv6 = _mm_loadu_si128((const __m128i *)orig->dst_addr);
154  *(__m128i *)targ->v6.dst_addr =
155  _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
156 #elif defined(__ARM_NEON)
157  uint8x16_t ipv6 = vld1q_u8((uint8_t const *)orig->src_addr);
158  vst1q_u8((uint8_t *)targ->v6.src_addr, vrev32q_u8(ipv6));
159  ipv6 = vld1q_u8((uint8_t const *)orig->dst_addr);
160  vst1q_u8((uint8_t *)targ->v6.dst_addr, vrev32q_u8(ipv6));
161 #elif defined(RTE_ARCH_LOONGARCH_64)
162  __m128i ipv6 = __lsx_vld((const __m128i *)orig->src_addr, 0);
163  __m128i xtmp = __lsx_vldi(0);
164  *(__m128i *)targ->v6.src_addr =
165  __lsx_vshuf_b(xtmp, ipv6, rte_thash_ipv6_bswap_mask.m128i);
166  ipv6 = __lsx_vld((const __m128i *)orig->dst_addr, 0);
167  *(__m128i *)targ->v6.dst_addr =
168  __lsx_vshuf_b(xtmp, ipv6, rte_thash_ipv6_bswap_mask.m128i);
169 #else
170  int i;
171  for (i = 0; i < 4; i++) {
172  *((uint32_t *)targ->v6.src_addr + i) =
173  rte_be_to_cpu_32(*((const uint32_t *)orig->src_addr + i));
174  *((uint32_t *)targ->v6.dst_addr + i) =
175  rte_be_to_cpu_32(*((const uint32_t *)orig->dst_addr + i));
176  }
177 #endif
178 }
179 
191 static inline uint32_t
192 rte_softrss(uint32_t *input_tuple, uint32_t input_len,
193  const uint8_t *rss_key)
194 {
195  uint32_t i, j, map, ret = 0;
196 
197  for (j = 0; j < input_len; j++) {
198  for (map = input_tuple[j]; map; map &= (map - 1)) {
199  i = rte_bsf32(map);
200  ret ^= rte_cpu_to_be_32(((const uint32_t *)rss_key)[j]) << (31 - i) |
201  (uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t *)rss_key)[j + 1])) >>
202  (i + 1));
203  }
204  }
205  return ret;
206 }
207 
221 static inline uint32_t
222 rte_softrss_be(uint32_t *input_tuple, uint32_t input_len,
223  const uint8_t *rss_key)
224 {
225  uint32_t i, j, map, ret = 0;
226 
227  for (j = 0; j < input_len; j++) {
228  for (map = input_tuple[j]; map; map &= (map - 1)) {
229  i = rte_bsf32(map);
230  ret ^= ((const uint32_t *)rss_key)[j] << (31 - i) |
231  (uint32_t)((uint64_t)(((const uint32_t *)rss_key)[j + 1]) >> (i + 1));
232  }
233  }
234  return ret;
235 }
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #endif /* _RTE_THASH_H */
uint8_t dst_addr[16]
Definition: rte_ip.h:393
static rte_be32_t rte_cpu_to_be_32(uint32_t x)
static void rte_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
Definition: rte_thash.h:129
uint8_t src_addr[16]
Definition: rte_ip.h:392
static uint32_t rte_bsf32(uint32_t v)
Definition: rte_common.h:604
static void rte_thash_load_v6_addrs(const struct rte_ipv6_hdr *orig, union rte_thash_tuple *targ)
Definition: rte_thash.h:146
static uint32_t rte_softrss(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition: rte_thash.h:192
#define RTE_STD_C11
Definition: rte_common.h:40
static uint32_t rte_be_to_cpu_32(rte_be32_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:222
__extension__ struct rte_eth_link __rte_aligned(8)