Blog
Community
Development
Documentation
CNDP
22.08.0
Toggle main menu visibility
Loading...
Searching...
No Matches
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
13
20
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
68
struct
cne_ipv4_tuple
{
69
uint32_t src_addr;
70
uint32_t dst_addr;
71
CNE_STD_C11
72
union
{
73
struct
{
74
uint16_t dport;
75
uint16_t sport;
76
};
77
uint32_t sctp_tag;
78
};
79
};
80
86
struct
cne_ipv6_tuple
{
87
uint8_t src_addr[16];
88
uint8_t dst_addr[16];
89
CNE_STD_C11
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 */
cne_byteorder.h
cne_common.h
CNE_STD_C11
#define CNE_STD_C11
Definition
cne_common.h:91
cne_ip.h
cne_convert_rss_key
static void cne_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len)
Definition
cne_thash.h:114
cne_thash_load_v6_addrs
static void cne_thash_load_v6_addrs(const struct cne_ipv6_hdr *orig, union cne_thash_tuple *targ)
Definition
cne_thash.h:131
cne_thash_ipv6_bswap_mask
static const __m128i cne_thash_ipv6_bswap_mask
Definition
cne_thash.h:34
cne_softrss
static uint32_t cne_softrss(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition
cne_thash.h:151
cne_softrss_be
static uint32_t cne_softrss_be(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key)
Definition
cne_thash.h:179
cne_vect.h
cne_ipv4_tuple
Definition
cne_thash.h:68
cne_ipv6_hdr
Definition
cne_ip.h:372
cne_ipv6_hdr::dst_addr
uint8_t dst_addr[16]
Definition
cne_ip.h:378
cne_ipv6_hdr::src_addr
uint8_t src_addr[16]
Definition
cne_ip.h:377
cne_ipv6_tuple
Definition
cne_thash.h:86
lib
core
hash
cne_thash.h
Generated by
1.18.0