DPDK  20.11.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  */
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 #ifdef RTE_ARCH_NO_VECTOR
163  int i;
164  for (i = 0; i < 4; i++) {
165  *((uint32_t *)targ->v6.src_addr + i) =
166  rte_be_to_cpu_32(*((const uint32_t *)orig->src_addr + i));
167  *((uint32_t *)targ->v6.dst_addr + i) =
168  rte_be_to_cpu_32(*((const uint32_t *)orig->dst_addr + i));
169  }
170 #else
171  //TODO add vec support
172 #endif
173 #else
174  int i;
175  for (i = 0; i < 4; i++) {
176  *((uint32_t *)targ->v6.src_addr + i) =
177  rte_be_to_cpu_32(*((const uint32_t *)orig->src_addr + i));
178  *((uint32_t *)targ->v6.dst_addr + i) =
179  rte_be_to_cpu_32(*((const uint32_t *)orig->dst_addr + i));
180  }
181 #endif
182 }
183 
195 static inline uint32_t
196 rte_softrss(uint32_t *input_tuple, uint32_t input_len,
197  const uint8_t *rss_key)
198 {
199  uint32_t i, j, map, ret = 0;
200 
201  for (j = 0; j < input_len; j++) {
202  for (map = input_tuple[j]; map; map &= (map - 1)) {
203  i = rte_bsf32(map);
204  ret ^= rte_cpu_to_be_32(((const uint32_t *)rss_key)[j]) << (31 - i) |
205  (uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t *)rss_key)[j + 1])) >>
206  (i + 1));
207  }
208  }
209  return ret;
210 }
211 
225 static inline uint32_t
226 rte_softrss_be(uint32_t *input_tuple, uint32_t input_len,
227  const uint8_t *rss_key)
228 {
229  uint32_t i, j, map, ret = 0;
230 
231  for (j = 0; j < input_len; j++) {
232  for (map = input_tuple[j]; map; map &= (map - 1)) {
233  i = rte_bsf32(map);
234  ret ^= ((const uint32_t *)rss_key)[j] << (31 - i) |
235  (uint32_t)((uint64_t)(((const uint32_t *)rss_key)[j + 1]) >> (i + 1));
236  }
237  }
238  return ret;
239 }
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 #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:196
#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:226
__extension__ struct rte_eth_link __rte_aligned(8)