15129044dSC.J. Collier/*-
25129044dSC.J. Collier *   BSD LICENSE
35129044dSC.J. Collier *
45129044dSC.J. Collier *   Copyright(c) 2015 Vladimir Medvedkin <medvedkinv@gmail.com>
55129044dSC.J. Collier *   All rights reserved.
65129044dSC.J. Collier *
75129044dSC.J. Collier *   Redistribution and use in source and binary forms, with or without
85129044dSC.J. Collier *   modification, are permitted provided that the following conditions
95129044dSC.J. Collier *   are met:
105129044dSC.J. Collier *
115129044dSC.J. Collier *     * Redistributions of source code must retain the above copyright
125129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer.
135129044dSC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
145129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer in
155129044dSC.J. Collier *       the documentation and/or other materials provided with the
165129044dSC.J. Collier *       distribution.
175129044dSC.J. Collier *     * Neither the name of Intel Corporation nor the names of its
185129044dSC.J. Collier *       contributors may be used to endorse or promote products derived
195129044dSC.J. Collier *       from this software without specific prior written permission.
205129044dSC.J. Collier *
215129044dSC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
225129044dSC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
235129044dSC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
245129044dSC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
255129044dSC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
265129044dSC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
275129044dSC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
285129044dSC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
295129044dSC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
305129044dSC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
315129044dSC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
325129044dSC.J. Collier */
335129044dSC.J. Collier
345129044dSC.J. Collier#include <rte_common.h>
355129044dSC.J. Collier#include <rte_eal.h>
365129044dSC.J. Collier#include <rte_ip.h>
375129044dSC.J. Collier
385129044dSC.J. Collier#include "test.h"
395129044dSC.J. Collier
405129044dSC.J. Collier#include <rte_thash.h>
415129044dSC.J. Collier
425129044dSC.J. Collierstruct test_thash_v4 {
435129044dSC.J. Collier	uint32_t	dst_ip;
445129044dSC.J. Collier	uint32_t	src_ip;
455129044dSC.J. Collier	uint16_t	dst_port;
465129044dSC.J. Collier	uint16_t	src_port;
475129044dSC.J. Collier	uint32_t	hash_l3;
485129044dSC.J. Collier	uint32_t	hash_l3l4;
495129044dSC.J. Collier};
505129044dSC.J. Collier
515129044dSC.J. Collierstruct test_thash_v6 {
525129044dSC.J. Collier	uint8_t		dst_ip[16];
535129044dSC.J. Collier	uint8_t		src_ip[16];
545129044dSC.J. Collier	uint16_t	dst_port;
555129044dSC.J. Collier	uint16_t	src_port;
565129044dSC.J. Collier	uint32_t	hash_l3;
575129044dSC.J. Collier	uint32_t	hash_l3l4;
585129044dSC.J. Collier};
595129044dSC.J. Collier
605129044dSC.J. Collier/*From 82599 Datasheet 7.1.2.8.3 RSS Verification Suite*/
615129044dSC.J. Collierstruct test_thash_v4 v4_tbl[] = {
625129044dSC.J. Collier{IPv4(161, 142, 100, 80), IPv4(66, 9, 149, 187),
635129044dSC.J. Collier	1766, 2794, 0x323e8fc2, 0x51ccc178},
645129044dSC.J. Collier{IPv4(65, 69, 140, 83), IPv4(199, 92, 111, 2),
655129044dSC.J. Collier	4739, 14230, 0xd718262a, 0xc626b0ea},
665129044dSC.J. Collier{IPv4(12, 22, 207, 184), IPv4(24, 19, 198, 95),
675129044dSC.J. Collier	38024, 12898, 0xd2d0a5de, 0x5c2b394a},
685129044dSC.J. Collier{IPv4(209, 142, 163, 6), IPv4(38, 27, 205, 30),
695129044dSC.J. Collier	2217, 48228, 0x82989176, 0xafc7327f},
705129044dSC.J. Collier{IPv4(202, 188, 127, 2), IPv4(153, 39, 163, 191),
715129044dSC.J. Collier	1303, 44251, 0x5d1809c5, 0x10e828a2},
725129044dSC.J. Collier};
735129044dSC.J. Collier
745129044dSC.J. Collierstruct test_thash_v6 v6_tbl[] = {
755129044dSC.J. Collier/*3ffe:2501:200:3::1*/
765129044dSC.J. Collier{{0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x00, 0x03,
775129044dSC.J. Collier0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
785129044dSC.J. Collier/*3ffe:2501:200:1fff::7*/
795129044dSC.J. Collier{0x3f, 0xfe, 0x25, 0x01, 0x02, 0x00, 0x1f, 0xff,
805129044dSC.J. Collier0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,},
815129044dSC.J. Collier1766, 2794, 0x2cc18cd5, 0x40207d3d},
825129044dSC.J. Collier/*ff02::1*/
835129044dSC.J. Collier{{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
845129044dSC.J. Collier0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,},
855129044dSC.J. Collier/*3ffe:501:8::260:97ff:fe40:efab*/
865129044dSC.J. Collier{0x3f, 0xfe, 0x05, 0x01, 0x00, 0x08, 0x00, 0x00,
875129044dSC.J. Collier0x02, 0x60, 0x97, 0xff, 0xfe, 0x40, 0xef, 0xab,},
885129044dSC.J. Collier4739, 14230, 0x0f0c461c, 0xdde51bbf},
895129044dSC.J. Collier/*fe80::200:f8ff:fe21:67cf*/
905129044dSC.J. Collier{{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
915129044dSC.J. Collier0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
925129044dSC.J. Collier/*3ffe:1900:4545:3:200:f8ff:fe21:67cf*/
935129044dSC.J. Collier{0x3f, 0xfe, 0x19, 0x00, 0x45, 0x45, 0x00, 0x03,
945129044dSC.J. Collier0x02, 0x00, 0xf8, 0xff, 0xfe, 0x21, 0x67, 0xcf,},
955129044dSC.J. Collier38024, 44251, 0x4b61e985, 0x02d1feef},
965129044dSC.J. Collier};
975129044dSC.J. Collier
985129044dSC.J. Collieruint8_t default_rss_key[] = {
995129044dSC.J. Collier0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
1005129044dSC.J. Collier0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
1015129044dSC.J. Collier0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
1025129044dSC.J. Collier0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
1035129044dSC.J. Collier0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
1045129044dSC.J. Collier};
1055129044dSC.J. Collier
1065129044dSC.J. Collierstatic int
1075129044dSC.J. Colliertest_thash(void)
1085129044dSC.J. Collier{
1095129044dSC.J. Collier	uint32_t i, j;
1105129044dSC.J. Collier	union rte_thash_tuple tuple;
1115129044dSC.J. Collier	uint32_t rss_l3, rss_l3l4;
1125129044dSC.J. Collier	uint8_t rss_key_be[RTE_DIM(default_rss_key)];
1135129044dSC.J. Collier	struct ipv6_hdr ipv6_hdr;
1145129044dSC.J. Collier
1155129044dSC.J. Collier	/* Convert RSS key*/
1165129044dSC.J. Collier	rte_convert_rss_key((uint32_t *)&default_rss_key,
1175129044dSC.J. Collier		(uint32_t *)rss_key_be, RTE_DIM(default_rss_key));
1185129044dSC.J. Collier
1195129044dSC.J. Collier
1205129044dSC.J. Collier	for (i = 0; i < RTE_DIM(v4_tbl); i++) {
1215129044dSC.J. Collier		tuple.v4.src_addr = v4_tbl[i].src_ip;
1225129044dSC.J. Collier		tuple.v4.dst_addr = v4_tbl[i].dst_ip;
1235129044dSC.J. Collier		tuple.v4.sport = v4_tbl[i].src_port;
1245129044dSC.J. Collier		tuple.v4.dport = v4_tbl[i].dst_port;
1255129044dSC.J. Collier		/*Calculate hash with original key*/
1265129044dSC.J. Collier		rss_l3 = rte_softrss((uint32_t *)&tuple,
1275129044dSC.J. Collier				RTE_THASH_V4_L3_LEN, default_rss_key);
1285129044dSC.J. Collier		rss_l3l4 = rte_softrss((uint32_t *)&tuple,
1295129044dSC.J. Collier				RTE_THASH_V4_L4_LEN, default_rss_key);
1305129044dSC.J. Collier		if ((rss_l3 != v4_tbl[i].hash_l3) ||
1315129044dSC.J. Collier				(rss_l3l4 != v4_tbl[i].hash_l3l4))
1325129044dSC.J. Collier			return -1;
1335129044dSC.J. Collier		/*Calculate hash with converted key*/
1345129044dSC.J. Collier		rss_l3 = rte_softrss_be((uint32_t *)&tuple,
1355129044dSC.J. Collier				RTE_THASH_V4_L3_LEN, rss_key_be);
1365129044dSC.J. Collier		rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
1375129044dSC.J. Collier				RTE_THASH_V4_L4_LEN, rss_key_be);
1385129044dSC.J. Collier		if ((rss_l3 != v4_tbl[i].hash_l3) ||
1395129044dSC.J. Collier				(rss_l3l4 != v4_tbl[i].hash_l3l4))
1405129044dSC.J. Collier			return -1;
1415129044dSC.J. Collier	}
1425129044dSC.J. Collier	for (i = 0; i < RTE_DIM(v6_tbl); i++) {
1435129044dSC.J. Collier		/*Fill ipv6 hdr*/
1445129044dSC.J. Collier		for (j = 0; j < RTE_DIM(ipv6_hdr.src_addr); j++)
1455129044dSC.J. Collier			ipv6_hdr.src_addr[j] = v6_tbl[i].src_ip[j];
1465129044dSC.J. Collier		for (j = 0; j < RTE_DIM(ipv6_hdr.dst_addr); j++)
1475129044dSC.J. Collier			ipv6_hdr.dst_addr[j] = v6_tbl[i].dst_ip[j];
1485129044dSC.J. Collier		/*Load and convert ipv6 address into tuple*/
1495129044dSC.J. Collier		rte_thash_load_v6_addrs(&ipv6_hdr, &tuple);
1505129044dSC.J. Collier		tuple.v6.sport = v6_tbl[i].src_port;
1515129044dSC.J. Collier		tuple.v6.dport = v6_tbl[i].dst_port;
1525129044dSC.J. Collier		/*Calculate hash with original key*/
1535129044dSC.J. Collier		rss_l3 = rte_softrss((uint32_t *)&tuple,
1545129044dSC.J. Collier				RTE_THASH_V6_L3_LEN, default_rss_key);
1555129044dSC.J. Collier		rss_l3l4 = rte_softrss((uint32_t *)&tuple,
1565129044dSC.J. Collier				RTE_THASH_V6_L4_LEN, default_rss_key);
1575129044dSC.J. Collier		if ((rss_l3 != v6_tbl[i].hash_l3) ||
1585129044dSC.J. Collier				(rss_l3l4 != v6_tbl[i].hash_l3l4))
1595129044dSC.J. Collier			return -1;
1605129044dSC.J. Collier		/*Calculate hash with converted key*/
1615129044dSC.J. Collier		rss_l3 = rte_softrss_be((uint32_t *)&tuple,
1625129044dSC.J. Collier				RTE_THASH_V6_L3_LEN, rss_key_be);
1635129044dSC.J. Collier		rss_l3l4 = rte_softrss_be((uint32_t *)&tuple,
1645129044dSC.J. Collier				RTE_THASH_V6_L4_LEN, rss_key_be);
1655129044dSC.J. Collier		if ((rss_l3 != v6_tbl[i].hash_l3) ||
1665129044dSC.J. Collier				(rss_l3l4 != v6_tbl[i].hash_l3l4))
1675129044dSC.J. Collier			return -1;
1685129044dSC.J. Collier	}
1695129044dSC.J. Collier	return 0;
1705129044dSC.J. Collier}
1715129044dSC.J. Collier
1729ecc306dSRicardo SalvetiREGISTER_TEST_COMMAND(thash_autotest, test_thash);
173