4 * Copyright(c) 2015 Vladimir Medvedkin <medvedkinv@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_common.h>
40 #include <rte_thash.h>
42 struct test_thash_v4 {
51 struct test_thash_v6 {
60 /*From 82599 Datasheet 7.1.2.8.3 RSS Verification Suite*/
61 struct test_thash_v4 v4_tbl[] = {
62 {RTE_IPV4(161, 142, 100, 80), RTE_IPV4(66, 9, 149, 187),
63 1766, 2794, 0x323e8fc2, 0x51ccc178},
64 {RTE_IPV4(65, 69, 140, 83), RTE_IPV4(199, 92, 111, 2),
65 4739, 14230, 0xd718262a, 0xc626b0ea},
66 {RTE_IPV4(12, 22, 207, 184), RTE_IPV4(24, 19, 198, 95),
67 38024, 12898, 0xd2d0a5de, 0x5c2b394a},
68 {RTE_IPV4(209, 142, 163, 6), RTE_IPV4(38, 27, 205, 30),
69 2217, 48228, 0x82989176, 0xafc7327f},
70 {RTE_IPV4(202, 188, 127, 2), RTE_IPV4(153, 39, 163, 191),
71 1303, 44251, 0x5d1809c5, 0x10e828a2},
74 struct test_thash_v6 v6_tbl[] = {
75 /*3ffe:2501:200:3::1*/
76 {{0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x00, 0x03,
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
78 /*3ffe:2501:200:1fff::7*/
79 {0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x1f, 0xff,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,},
81 1766, 2794, 0x2cc18cd5, 0x40207d3d},
83 {{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
85 /*3ffe:501:8::260:97ff:fe40:efab*/
86 {0x3f, 0xfe, 0x05, 0x01, 0x00, 0x08, 0x00, 0x00,
87 0x02, 0x60, 0x97, 0xff, 0xfe, 0x40, 0xef, 0xab,},
88 4739, 14230, 0x0f0c461c, 0xdde51bbf},
89 /*fe80::200:f8ff:fe21:67cf*/
90 {{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
92 /*3ffe:1900:4545:3:200:f8ff:fe21:67cf*/
93 {0x3f, 0xfe, 0x19, 0x00, 0x45, 0x45, 0x00, 0x03,
94 0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
95 38024, 44251, 0x4b61e985, 0x02d1feef},
98 uint8_t default_rss_key[] = {
99 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
100 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
101 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
102 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
103 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
110 union rte_thash_tuple tuple;
111 uint32_t rss_l3, rss_l3l4;
112 uint8_t rss_key_be[RTE_DIM(default_rss_key)];
113 struct rte_ipv6_hdr ipv6_hdr;
116 rte_convert_rss_key((uint32_t *)&default_rss_key,
117 (uint32_t *)rss_key_be, RTE_DIM(default_rss_key));
120 for (i = 0; i < RTE_DIM(v4_tbl); i++) {
121 tuple.v4.src_addr = v4_tbl[i].src_ip;
122 tuple.v4.dst_addr = v4_tbl[i].dst_ip;
123 tuple.v4.sport = v4_tbl[i].src_port;
124 tuple.v4.dport = v4_tbl[i].dst_port;
125 /*Calculate hash with original key*/
126 rss_l3 = rte_softrss((uint32_t *)&tuple,
127 RTE_THASH_V4_L3_LEN, default_rss_key);
128 rss_l3l4 = rte_softrss((uint32_t *)&tuple,
129 RTE_THASH_V4_L4_LEN, default_rss_key);
130 if ((rss_l3 != v4_tbl[i].hash_l3) ||
131 (rss_l3l4 != v4_tbl[i].hash_l3l4))
133 /*Calculate hash with converted key*/
134 rss_l3 = rte_softrss_be((uint32_t *)&tuple,
135 RTE_THASH_V4_L3_LEN, rss_key_be);
136 rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
137 RTE_THASH_V4_L4_LEN, rss_key_be);
138 if ((rss_l3 != v4_tbl[i].hash_l3) ||
139 (rss_l3l4 != v4_tbl[i].hash_l3l4))
142 for (i = 0; i < RTE_DIM(v6_tbl); i++) {
144 for (j = 0; j < RTE_DIM(ipv6_hdr.src_addr); j++)
145 ipv6_hdr.src_addr[j] = v6_tbl[i].src_ip[j];
146 for (j = 0; j < RTE_DIM(ipv6_hdr.dst_addr); j++)
147 ipv6_hdr.dst_addr[j] = v6_tbl[i].dst_ip[j];
148 /*Load and convert ipv6 address into tuple*/
149 rte_thash_load_v6_addrs(&ipv6_hdr, &tuple);
150 tuple.v6.sport = v6_tbl[i].src_port;
151 tuple.v6.dport = v6_tbl[i].dst_port;
152 /*Calculate hash with original key*/
153 rss_l3 = rte_softrss((uint32_t *)&tuple,
154 RTE_THASH_V6_L3_LEN, default_rss_key);
155 rss_l3l4 = rte_softrss((uint32_t *)&tuple,
156 RTE_THASH_V6_L4_LEN, default_rss_key);
157 if ((rss_l3 != v6_tbl[i].hash_l3) ||
158 (rss_l3l4 != v6_tbl[i].hash_l3l4))
160 /*Calculate hash with converted key*/
161 rss_l3 = rte_softrss_be((uint32_t *)&tuple,
162 RTE_THASH_V6_L3_LEN, rss_key_be);
163 rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
164 RTE_THASH_V6_L4_LEN, rss_key_be);
165 if ((rss_l3 != v6_tbl[i].hash_l3) ||
166 (rss_l3l4 != v6_tbl[i].hash_l3l4))
172 REGISTER_TEST_COMMAND(thash_autotest, test_thash);