DPDK patches and discussions
 help / color / mirror / Atom feed
From: nipun.gupta@nxp.com
To: dev@dpdk.org
Cc: thomas@monjalon.net, ferruh.yigit@intel.com,
	hemant.agrawal@nxp.com, sachin.saxena@nxp.com
Subject: [dpdk-dev] [PATCH v1 06/11] net/dpaa2: add function to generate HW hash key
Date: Mon, 27 Sep 2021 18:55:14 +0530	[thread overview]
Message-ID: <20210927132519.19264-7-nipun.gupta@nxp.com> (raw)
In-Reply-To: <20210927132519.19264-1-nipun.gupta@nxp.com>

From: Hemant Agrawal <hemant.agrawal@nxp.com>

This patch add support to generate the hash key in software
equivalent to WRIOP key generation.

Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
 drivers/net/dpaa2/base/dpaa2_tlu_hash.c | 153 ++++++++++++++++++++++++
 drivers/net/dpaa2/meson.build           |   1 +
 drivers/net/dpaa2/rte_pmd_dpaa2.h       |  19 +++
 drivers/net/dpaa2/version.map           |   2 +
 4 files changed, 175 insertions(+)
 create mode 100644 drivers/net/dpaa2/base/dpaa2_tlu_hash.c

diff --git a/drivers/net/dpaa2/base/dpaa2_tlu_hash.c b/drivers/net/dpaa2/base/dpaa2_tlu_hash.c
new file mode 100644
index 0000000000..9eb127c07c
--- /dev/null
+++ b/drivers/net/dpaa2/base/dpaa2_tlu_hash.c
@@ -0,0 +1,153 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 NXP
+ */
+#include <stdio.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <rte_pmd_dpaa2.h>
+
+static unsigned int sbox(unsigned int x)
+{
+	unsigned int a, b, c, d;
+	unsigned int oa, ob, oc, od;
+
+	a = x & 0x1;
+	b = (x >> 1) & 0x1;
+	c = (x >> 2) & 0x1;
+	d = (x >> 3) & 0x1;
+
+	oa = ((a & ~b & ~c & d) | (~a & b) | (~a & ~c & ~d) | (b & c)) & 0x1;
+	ob = ((a & ~b & d) | (~a & c & ~d) | (b & ~c)) & 0x1;
+	oc = ((a & ~b & c) | (a & ~b & ~d) | (~a & b & ~d) | (~a & c & ~d) |
+	     (b & c & d)) & 0x1;
+	od = ((a & ~b & c) | (~a & b & ~c) | (a & b & ~d) | (~a & c & d)) & 0x1;
+
+	return ((od << 3) | (oc << 2) | (ob << 1) | oa);
+}
+
+static unsigned int sbox_tbl[16];
+
+static int pbox_tbl[16] = {5, 9, 0, 13,
+			7, 2, 11, 14,
+			1, 4, 12, 8,
+			3, 15, 6, 10 };
+
+static unsigned int mix_tbl[8][16];
+
+static unsigned int stage(unsigned int input)
+{
+	int sbox_out = 0;
+	int pbox_out = 0;
+	int i;
+
+	/* mix */
+	input ^= input >> 16; /* xor lower */
+	input ^= input << 16; /* move original lower to upper */
+
+	for (i = 0; i < 32; i += 4) /* sbox stage */
+		sbox_out |= (sbox_tbl[(input >> i) & 0xf]) << i;
+
+	/* permutation */
+	for (i = 0; i < 16; i++)
+		pbox_out |= ((sbox_out >> i) & 0x10001) << pbox_tbl[i];
+
+	return pbox_out;
+}
+
+static unsigned int fast_stage(unsigned int input)
+{
+	int pbox_out = 0;
+	int i;
+
+	/* mix */
+	input ^= input >> 16; /* xor lower */
+	input ^= input << 16; /* move original lower to upper */
+
+	for (i = 0; i < 32; i += 4) /* sbox stage */
+		pbox_out |= mix_tbl[i >> 2][(input >> i) & 0xf];
+
+	return pbox_out;
+}
+
+static unsigned int fast_hash32(unsigned int x)
+{
+	int i;
+
+	for (i = 0; i < 4; i++)
+		x = fast_stage(x);
+	return x;
+}
+
+static unsigned int
+byte_crc32(unsigned char data /* new byte for the crc calculation */,
+	   unsigned old_crc /* crc result of the last iteration */)
+{
+	int i;
+	unsigned int crc, polynom = 0xedb88320;
+	/* the polynomial is built on the reversed version of
+	 * the CRC polynomial with out the x64 element.
+	 */
+
+	crc = old_crc;
+	for (i = 0; i < 8; i++, data >>= 1)
+		crc = (crc >> 1) ^ (((crc ^ data) & 0x1) ? polynom : 0);
+		/* xor with polynomial is lsb of crc^data is 1 */
+
+	return crc;
+}
+
+static unsigned int crc32_table[256];
+
+static void init_crc32_table(void)
+{
+	int i;
+
+	for (i = 0; i < 256; i++)
+		crc32_table[i] = byte_crc32((unsigned char)i, 0LL);
+}
+
+static unsigned int
+crc32_string(unsigned char *data,
+	     int size, unsigned int old_crc)
+{
+	unsigned int crc;
+	int i;
+
+	crc = old_crc;
+	for (i = 0; i < size; i++)
+		crc = (crc >> 8) ^ crc32_table[(crc ^ data[i]) & 0xff];
+
+	return crc;
+}
+
+static void hash_init(void)
+{
+	init_crc32_table();
+	int i, j;
+
+	for (i = 0; i < 16; i++)
+		sbox_tbl[i] = sbox(i);
+
+	for (i = 0; i < 32; i += 4)
+		for (j = 0; j < 16; j++) {
+			/* (a,b)
+			 * (b,a^b)=(X,Y)
+			 * (X^Y,X)
+			 */
+			unsigned int input = (0x88888888 ^ (8 << i)) | (j << i);
+
+			input ^= input << 16; /* (X^Y,Y) */
+			input ^= input >> 16; /* (X^Y,X) */
+			mix_tbl[i >> 2][j] = stage(input);
+		}
+}
+
+uint32_t rte_pmd_dpaa2_get_tlu_hash(uint8_t *data, int size)
+{
+	static int init;
+
+	if (~init)
+		hash_init();
+	init = 1;
+	return fast_hash32(crc32_string(data, size, 0x0));
+}
diff --git a/drivers/net/dpaa2/meson.build b/drivers/net/dpaa2/meson.build
index 20eaf0b8e4..4a6397d09e 100644
--- a/drivers/net/dpaa2/meson.build
+++ b/drivers/net/dpaa2/meson.build
@@ -20,6 +20,7 @@ sources = files(
         'mc/dpkg.c',
         'mc/dpdmux.c',
         'mc/dpni.c',
+	'base/dpaa2_tlu_hash.c',
 )
 
 includes += include_directories('base', 'mc')
diff --git a/drivers/net/dpaa2/rte_pmd_dpaa2.h b/drivers/net/dpaa2/rte_pmd_dpaa2.h
index a68244c974..8ea42ee130 100644
--- a/drivers/net/dpaa2/rte_pmd_dpaa2.h
+++ b/drivers/net/dpaa2/rte_pmd_dpaa2.h
@@ -82,4 +82,23 @@ __rte_experimental
 void
 rte_pmd_dpaa2_thread_init(void);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Generate the DPAA2 WRIOP based hash value
+ *
+ * @param key
+ *    Array of key data
+ * @param size
+ *    Size of the hash input key in bytes
+ *
+ * @return
+ *   - 0 if successful.
+ *   - Negative in case of failure.
+ */
+
+__rte_experimental
+uint32_t
+rte_pmd_dpaa2_get_tlu_hash(uint8_t *key, int size);
 #endif /* _RTE_PMD_DPAA2_H */
diff --git a/drivers/net/dpaa2/version.map b/drivers/net/dpaa2/version.map
index f9786af7e4..2059fc5ae8 100644
--- a/drivers/net/dpaa2/version.map
+++ b/drivers/net/dpaa2/version.map
@@ -10,6 +10,8 @@ DPDK_22 {
 EXPERIMENTAL {
 	global:
 
+	# added in 21.11
+	rte_pmd_dpaa2_get_tlu_hash;
 	# added in 21.05
 	rte_pmd_dpaa2_mux_rx_frame_len;
 	# added in 21.08
-- 
2.17.1


  parent reply	other threads:[~2021-09-27 13:26 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 12:26 [dpdk-dev] [PATCH 00/11] NXP DPAAx Bus and PMD changes nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 01/11] bus/fslmc: updated MC FW to 10.28 nipun.gupta
2021-10-06 13:28   ` Hemant Agrawal
2021-09-27 12:26 ` [dpdk-dev] [PATCH 02/11] net/dpaa2: support Tx flow redirection action nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 03/11] bus/fslmc: add qbman debug APIs support nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 04/11] net/dpaa2: support multiple Tx queues enqueue for ordered nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 05/11] net/dpaa2: add debug print for MTU set for jumbo nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 06/11] net/dpaa2: add function to generate HW hash key nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 07/11] net/dpaa2: update RSS to support additional distributions nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 08/11] net/dpaa: add comments to explain driver behaviour nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 09/11] raw/dpaa2_qdma: use correct params for config and queue setup nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 10/11] raw/dpaa2_qdma: remove checks for lcore ID nipun.gupta
2021-09-27 12:26 ` [dpdk-dev] [PATCH 11/11] common/dpaax: fix paddr to vaddr invalid conversion nipun.gupta
2021-09-27 13:25 ` [dpdk-dev] [PATCH v1 00/11] NXP DPAAx Bus and PMD changes nipun.gupta
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 01/11] bus/fslmc: updated MC FW to 10.28 nipun.gupta
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 02/11] net/dpaa2: support Tx flow redirection action nipun.gupta
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 03/11] bus/fslmc: add qbman debug APIs support nipun.gupta
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 04/11] net/dpaa2: support multiple Tx queues enqueue for ordered nipun.gupta
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 05/11] net/dpaa2: add debug print for MTU set for jumbo nipun.gupta
2021-09-27 13:25   ` nipun.gupta [this message]
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 07/11] net/dpaa2: update RSS to support additional distributions nipun.gupta
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 08/11] net/dpaa: add comments to explain driver behaviour nipun.gupta
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 09/11] raw/dpaa2_qdma: use correct params for config and queue setup nipun.gupta
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 10/11] raw/dpaa2_qdma: remove checks for lcore ID nipun.gupta
2021-09-27 13:25   ` [dpdk-dev] [PATCH v1 11/11] common/dpaax: fix paddr to vaddr invalid conversion nipun.gupta
2021-10-06 12:10 ` [dpdk-dev] [PATCH v2 00/10] NXP DPAAx Bus and PMD changes nipun.gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 01/10] bus/fslmc: updated MC FW to 10.28 nipun.gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 02/10] net/dpaa2: support Tx flow redirection action nipun.gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 03/10] bus/fslmc: add qbman debug APIs support nipun.gupta
2021-10-06 13:31     ` Thomas Monjalon
2021-10-06 17:02       ` Nipun Gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 04/10] net/dpaa2: add debug print for MTU set for jumbo nipun.gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 05/10] net/dpaa2: add function to generate HW hash key nipun.gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 06/10] net/dpaa2: update RSS to support additional distributions nipun.gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 07/10] net/dpaa: add comments to explain driver behaviour nipun.gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 08/10] raw/dpaa2_qdma: use correct params for config and queue setup nipun.gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 09/10] raw/dpaa2_qdma: remove checks for lcore ID nipun.gupta
2021-10-06 12:10   ` [dpdk-dev] [PATCH v2 10/10] common/dpaax: fix paddr to vaddr invalid conversion nipun.gupta
2021-10-06 17:01 ` [dpdk-dev] [PATCH v3 00/10] NXP DPAAx Bus and PMD changes nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 01/10] bus/fslmc: updated MC FW to 10.28 nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 02/10] net/dpaa2: support Tx flow redirection action nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 03/10] bus/fslmc: add qbman debug APIs support nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 04/10] net/dpaa2: add debug print for MTU set for jumbo nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 05/10] net/dpaa2: add function to generate HW hash key nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 06/10] net/dpaa2: update RSS to support additional distributions nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 07/10] net/dpaa: add comments to explain driver behaviour nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 08/10] raw/dpaa2_qdma: use correct params for config and queue setup nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 09/10] raw/dpaa2_qdma: remove checks for lcore ID nipun.gupta
2021-10-06 17:01   ` [dpdk-dev] [PATCH v3 10/10] common/dpaax: fix paddr to vaddr invalid conversion nipun.gupta
2021-10-07  7:37   ` [dpdk-dev] [PATCH v3 00/10] NXP DPAAx Bus and PMD changes Thomas Monjalon
2021-10-07  9:38     ` Thomas Monjalon
2021-10-07  9:46       ` Nipun Gupta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210927132519.19264-7-nipun.gupta@nxp.com \
    --to=nipun.gupta@nxp.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=hemant.agrawal@nxp.com \
    --cc=sachin.saxena@nxp.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).