From patchwork Wed May 3 09:25:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 98475 Delivered-To: patch@linaro.org Received: by 10.140.89.200 with SMTP id v66csp204886qgd; Wed, 3 May 2017 02:25:54 -0700 (PDT) X-Received: by 10.55.59.139 with SMTP id i133mr1820109qka.248.1493803554614; Wed, 03 May 2017 02:25:54 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id i10si2402754qtc.275.2017.05.03.02.25.54; Wed, 03 May 2017 02:25:54 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 091A560846; Wed, 3 May 2017 09:25:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_SPAM, RCVD_IN_SORBS_WEB autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 0D22460C5D; Wed, 3 May 2017 09:25:18 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 4CAA56085E; Wed, 3 May 2017 09:25:12 +0000 (UTC) Received: from mail-pg0-f47.google.com (mail-pg0-f47.google.com [74.125.83.47]) by lists.linaro.org (Postfix) with ESMTPS id 4ABF86081E for ; Wed, 3 May 2017 09:25:11 +0000 (UTC) Received: by mail-pg0-f47.google.com with SMTP id v1so75368310pgv.1 for ; Wed, 03 May 2017 02:25:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YaICWo7MPMzmqpFTqfGEVertu1TAuZ0WDBE+zPFe9HI=; b=QYXkHO9SWLuHdfz85z/8VlZuOgFyJtDnnglj0f6Bsso+w7upVum6CqegFOnB1Pc1yI U33/oXCHOXev+YYbapA9B0hMrgw4ujPf9oPGJkiIsxI48iI1sbgFNeKOpU2rUDzsbaXN F9yY/0ZAbe2z/FjPmOxpoAT4kRzLdsX7Wjjj7oZfrWcvmkFHYpHL+D9lk2Gol6F/ncrr +oqkghIyX9s+S04U1U5GNE/J48dGJJLrqZP3xjLYhTIHKdB70JRqTrRgFedVrl2Pldi+ QKzChk4srfnUx0W87ox1eRwbCYeg0zc7TZVJpqrRdYE631Rp2B6YsK2tDwmeJP+3GLgu 9/rg== X-Gm-Message-State: AN3rC/4pnesfPA4vccW/24llGqXJtvKnWPrbCRZWoXuTrvdJ/hS20+Hy hbGdWHCbX8H3Ayu62Hw= X-Received: by 10.84.224.77 with SMTP id a13mr27320314plt.132.1493803510520; Wed, 03 May 2017 02:25:10 -0700 (PDT) Received: from bala-Vostro-2520.caveonetworks.com ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id r77sm4024361pfe.105.2017.05.03.02.25.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 May 2017 02:25:10 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Wed, 3 May 2017 14:55:01 +0530 Message-Id: <1493803502-4500-2-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493803502-4500-1-git-send-email-bala.manoharan@linaro.org> References: <1493803502-4500-1-git-send-email-bala.manoharan@linaro.org> Subject: [lng-odp] [PATCH 2/3] linux-generic: add Toeplitz hash algorithm X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Implements Toeplitz hash algorithm for packet hashing Signed-off-by: Balasubramanian Manoharan --- platform/linux-generic/include/protocols/thash.h | 108 +++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 platform/linux-generic/include/protocols/thash.h -- 1.9.1 diff --git a/platform/linux-generic/include/protocols/thash.h b/platform/linux-generic/include/protocols/thash.h new file mode 100644 index 0000000..fe141e3 --- /dev/null +++ b/platform/linux-generic/include/protocols/thash.h @@ -0,0 +1,108 @@ +/* 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 + +/** 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 { + uint8_t src_addr[16]; + uint8_t dst_addr[16]; + 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++) { + *((uint32_t *)tuple->v6.src_addr + i) = + odp_be_to_cpu_32(*((const uint32_t *)ipv6->src_addr.u32 + i)); + + *((uint32_t *)tuple->v6.dst_addr + i) = + odp_be_to_cpu_32(*((const uint32_t *)ipv6->dst_addr.u32 + i)); + } +} + +static inline +uint32_t thash_softrss(uint32_t *tuple, uint8_t len, + const uint8_t *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)[j]) << i | (uint32_t)((uint64_t) + (odp_cpu_to_be_32(((const uint32_t *)key) + [j + 1])) >> (32 - i)); + } + } + } + + return ret; +} + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif