CNDP  22.08.0
cne_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 _CNE_THASH_H
6 #define _CNE_THASH_H
7 
21 #include <stdint.h>
22 #include <cne_byteorder.h>
23 #include <cne_common.h>
24 #include <cne_vect.h>
25 #include <net/cne_ip.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /* Byte swap mask used for converting IPv6 address
32  * 4-byte chunks to CPU byte order
33  */
34 static const __m128i cne_thash_ipv6_bswap_mask = {0x0405060700010203ULL, 0x0C0D0E0F08090A0BULL};
35 
40 #define CNE_THASH_V4_L3_LEN \
41  ((sizeof(struct cne_ipv4_tuple) - sizeof(((struct cne_ipv4_tuple *)0)->sctp_tag)) / 4)
42 
48 #define CNE_THASH_V4_L4_LEN ((sizeof(struct cne_ipv4_tuple)) / 4)
49 
54 #define CNE_THASH_V6_L3_LEN \
55  ((sizeof(struct cne_ipv6_tuple) - sizeof(((struct cne_ipv6_tuple *)0)->sctp_tag)) / 4)
56 
62 #define CNE_THASH_V6_L4_LEN ((sizeof(struct cne_ipv6_tuple)) / 4)
63 
69  uint32_t src_addr;
70  uint32_t dst_addr;
72  union {
73  struct {
74  uint16_t dport;
75  uint16_t sport;
76  };
77  uint32_t sctp_tag;
78  };
79 };
80 
87  uint8_t src_addr[16];
88  uint8_t dst_addr[16];
90  union {
91  struct {
92  uint16_t dport;
93  uint16_t sport;
94  };
95  uint32_t sctp_tag;
96  };
97 };
98 
99 union cne_thash_tuple {
100  struct cne_ipv4_tuple v4;
101  struct cne_ipv6_tuple v6;
102 } __attribute__((aligned(XMM_SIZE)));
103 
113 static inline void
114 cne_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
115 {
116  int i;
117 
118  for (i = 0; i < (len >> 2); i++)
119  targ[i] = be32toh(orig[i]);
120 }
121 
130 static inline void
131 cne_thash_load_v6_addrs(const struct cne_ipv6_hdr *orig, union cne_thash_tuple *targ)
132 {
133  __m128i ipv6 = _mm_loadu_si128((const __m128i *)orig->src_addr);
134  *(__m128i *)targ->v6.src_addr = _mm_shuffle_epi8(ipv6, cne_thash_ipv6_bswap_mask);
135  ipv6 = _mm_loadu_si128((const __m128i *)orig->dst_addr);
136  *(__m128i *)targ->v6.dst_addr = _mm_shuffle_epi8(ipv6, cne_thash_ipv6_bswap_mask);
137 }
138 
150 static inline uint32_t
151 cne_softrss(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
152 {
153  uint32_t i, j, map, ret = 0;
154 
155  for (j = 0; j < input_len; j++) {
156  for (map = input_tuple[j]; map; map &= (map - 1)) {
157  i = cne_bsf32(map);
158  ret ^= htobe32(((const uint32_t *)rss_key)[j]) << (31 - i) |
159  (uint32_t)((uint64_t)(htobe32(((const uint32_t *)rss_key)[j + 1])) >> (i + 1));
160  }
161  }
162  return ret;
163 }
164 
178 static inline uint32_t
179 cne_softrss_be(uint32_t *input_tuple, uint32_t input_len, 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 = cne_bsf32(map);
186  ret ^= ((const uint32_t *)rss_key)[j] << (31 - i) |
187  (uint32_t)((uint64_t)(((const uint32_t *)rss_key)[j + 1]) >> (i + 1));
188  }
189  }
190  return ret;
191 }
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 #endif /* _CNE_THASH_H */
#define CNE_STD_C11
Definition: cne_common.h:91
static uint32_t cne_bsf32(uint32_t v)
Definition: cne_common.h:581
static void cne_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
Definition: cne_thash.h:114
static void cne_thash_load_v6_addrs(const struct cne_ipv6_hdr *orig, union cne_thash_tuple *targ)
Definition: cne_thash.h:131
static const __m128i cne_thash_ipv6_bswap_mask
Definition: cne_thash.h:34
static uint32_t cne_softrss(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition: cne_thash.h:151
static uint32_t cne_softrss_be(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition: cne_thash.h:179
uint8_t dst_addr[16]
Definition: cne_ip.h:378
uint8_t src_addr[16]
Definition: cne_ip.h:377