From: Balasubramanian Manoharan <bala.manoha...@linaro.org>

Adds toeplitz hash algorithm implementation for RSS hashing

Signed-off-by: Balasubramanian Manoharan <bala.manoha...@linaro.org>
---
/** Email created from pull request 100 (bala-manoharan:cls-queue-hashing3)
 ** https://github.com/Linaro/odp/pull/100
 ** Patch: https://github.com/Linaro/odp/pull/100.patch
 ** Base sha: c16f1363303cd5fc11324acbc4dfebe0a9680a41
 ** Merge commit sha: 28aa7c613703fab9c13fd1a88f8a9eefa4d0a2cc
 **/
 platform/linux-generic/Makefile.am               |   1 +
 platform/linux-generic/include/protocols/thash.h | 114 +++++++++++++++++++++++
 2 files changed, 115 insertions(+)
 create mode 100644 platform/linux-generic/include/protocols/thash.h

diff --git a/platform/linux-generic/Makefile.am 
b/platform/linux-generic/Makefile.am
index f43e14be..cfccaa98 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -206,6 +206,7 @@ noinst_HEADERS = \
                  ${srcdir}/include/protocols/ip.h \
                  ${srcdir}/include/protocols/ipsec.h \
                  ${srcdir}/include/protocols/tcp.h \
+                 ${srcdir}/include/protocols/thash.h \
                  ${srcdir}/include/protocols/udp.h \
                  ${srcdir}/Makefile.inc
 
diff --git a/platform/linux-generic/include/protocols/thash.h 
b/platform/linux-generic/include/protocols/thash.h
new file mode 100644
index 00000000..82c318e1
--- /dev/null
+++ b/platform/linux-generic/include/protocols/thash.h
@@ -0,0 +1,114 @@
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP Toeplitz hash function
+ */
+
+#ifndef ODPH_THASH_H_
+#define ODPH_THASH_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <protocols/ip.h>
+
+/** rss data type */
+typedef union {
+       uint8_t u8[40];
+       uint32_t u32[10];
+} rss_key;
+
+/** IPv4 tuple
+ *
+ */
+typedef struct thash_ipv4_tuple {
+       uint32_t src_addr;
+       uint32_t dst_addr;
+       union {
+               struct {
+                       uint16_t sport;
+                       uint16_t dport;
+               };
+               uint32_t sctp_tag;
+       };
+} thash_ipv4_tuple_t;
+
+typedef struct thash_ipv6_tuple {
+       _odp_ipv6_addr_t src_addr;
+       _odp_ipv6_addr_t dst_addr;
+       union {
+               struct {
+                       uint16_t sport;
+                       uint16_t dport;
+               };
+               uint32_t sctp_tag;
+       };
+} thash_ipv6_tuple_t;
+
+#define ODP_THASH_V4_L4_LEN (sizeof(thash_ipv4_tuple_t) / 4)
+
+#define ODP_THASH_V4_L3_LEN ((sizeof(thash_ipv4_tuple_t) - \
+                       sizeof(((thash_ipv4_tuple_t *)0)->sctp_tag)) / 4)
+
+#define ODP_THASH_V6_L4_LEN (sizeof(thash_ipv6_tuple_t) / 4)
+
+#define ODP_THASH_V6_L3_LEN ((sizeof(thash_ipv6_tuple_t) - \
+                       sizeof(((thash_ipv6_tuple_t *)0)->sctp_tag)) / 4)
+
+typedef union {
+       thash_ipv4_tuple_t v4;
+       thash_ipv6_tuple_t v6;
+} thash_tuple_t;
+
+static inline
+void thash_load_ipv6_addr(const _odp_ipv6hdr_t *ipv6,
+                         thash_tuple_t *tuple)
+{
+       int i;
+
+       for (i = 0; i < 4; i++) {
+               *(tuple->v6.src_addr.u32 + i) =
+               odp_be_to_cpu_32(*(ipv6->src_addr.u32 + i));
+
+               *(tuple->v6.dst_addr.u32 + i) =
+               odp_be_to_cpu_32(*(ipv6->dst_addr.u32 + i));
+       }
+}
+
+static inline
+uint32_t thash_softrss(uint32_t *tuple, uint8_t len,
+                      const rss_key key)
+{
+       uint32_t i, j, ret;
+
+       ret = 0;
+       for (j = 0; j < len; j++) {
+               for (i = 0; i < 32; i++) {
+                       if (tuple[j] & (1 << (31 - i))) {
+                               ret ^= odp_cpu_to_be_32(((const uint32_t *)
+                               key.u32)[j]) << i | (uint32_t)((uint64_t)
+                               (odp_cpu_to_be_32(((const uint32_t *)key.u32)
+                               [j + 1])) >> (32 - i));
+                       }
+               }
+       }
+
+       return ret;
+}
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Reply via email to