From patchwork Fri Jul 14 09:12:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 107740 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp635639qge; Fri, 14 Jul 2017 02:13:09 -0700 (PDT) X-Received: by 10.55.145.6 with SMTP id t6mr9655830qkd.101.1500023589042; Fri, 14 Jul 2017 02:13:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500023589; cv=none; d=google.com; s=arc-20160816; b=cV6pvGIKQgpkAivqbiyetqwaR4kKQfGESfttzMWq+o9KxQXJbLMyDmgF2XcJkKXuWA 0NVKe1Cug1PdM9zUHz9cAY5PVZfKn4qKpf1C7hcqvyglZOFq8XQ7Jlguy6ePHuPmxUOy FIBJUAqQqLGwHpB2fIVG+ZjZtnQDF68t+PwF2dSjB+8PPz9R/7TvaQGcSHcZ5SJjbOUs 46I6J3NmHu5KkvQiLl7i9Wyk6PwUhyPaVDy3CGzCgE31s8gmvtamSBq0ueqs9y7Te1Uk h3Up9wyJJnB37FXo/V0YjSDNvZjdzbfDTJcQadnKbhIHY6FtyTGafm0McxoRTSqZHHVX tmCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:delivered-to:arc-authentication-results; bh=JsV1UihKziSf8a0Cwpc8P3OERtmvF3kAOQokhCdRMtY=; b=RivYgUboTqXbasje/hUkAE+gu24coExmjY2ZaVLbe5U93f2G5IZ0+pGkiclBeBHRU0 jTxTISZgKH9XFkEEk9k12U9iOND4NSnuHguhmA3kB5TnjwZZePD8xrHWd1L7z0PFqw9N zohzgEonnjdXsqzH8+TziAUFq7vHmN7FqFP8Bg42Q7DZEwdo/sKvqVdGC2AgH4uZYyqd tmMGmF2W57It/7GzNhj9SdJhty0jkr866o6OHW7LLLrhMaQXaRCjWcSo4nd8oG36Avu4 BmvoHisW67a2q8YFlQgjHMmfpEEeBwZSzUC1WBzdTLoJX3fh1UQtthDs8yCDlr7e67FD Shnw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id w65si7010937qte.120.2017.07.14.02.13.08; Fri, 14 Jul 2017 02:13:09 -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 B8A6D65BEE; Fri, 14 Jul 2017 09:13:08 +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=-3.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_WEB, URIBL_BLOCKED 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 1715760BE3; Fri, 14 Jul 2017 09:13:03 +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 9AD5C65BD3; Fri, 14 Jul 2017 09:13:00 +0000 (UTC) Received: from mail-pf0-f179.google.com (mail-pf0-f179.google.com [209.85.192.179]) by lists.linaro.org (Postfix) with ESMTPS id 1DBF360BE4 for ; Fri, 14 Jul 2017 09:12:21 +0000 (UTC) Received: by mail-pf0-f179.google.com with SMTP id c73so42777299pfk.2 for ; Fri, 14 Jul 2017 02:12:21 -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=JsV1UihKziSf8a0Cwpc8P3OERtmvF3kAOQokhCdRMtY=; b=YER+hG4Hrn/oot1XE6HD3MtGNk3ww+aCq5k4AX391WAnpa1uwnuJE9UDTv3/vx5QiW 2nuyJ2FfRNZDBIKK92+Rww6Mn2PQ9gCa0W0Md6zrOl8PBFQy7JEmGd2WjZbaTYRojkUz FGieM2/COBH1RPEiTGQp3AQ1jHlBeYUzEwRg+qANRFEdB6TUV7jPANIRzIvc5eeJpYtS +Y4/p7gko4vlWvBYGztW5/ZXNeev7BEXbZ/WrFQEWY4nUexm9sgGrPJPJlYE3Zddz4uT 9eGFTO/ebe/1c4/d5kLeghKTy45Zuhtmr78ta6cWh8CTSCFRe3Um9oWUygip4MCJldZM B77g== X-Gm-Message-State: AIVw112VAkp8pK7cDjWQPwrXv6quS0wdMYDLyKQp93Wlyd0cB1liEAF4 zFMfvOCvFInWMfWQFssAPYvW X-Received: by 10.99.112.92 with SMTP id a28mr13358987pgn.151.1500023540223; Fri, 14 Jul 2017 02:12:20 -0700 (PDT) Received: from cavium-desktop.caveonetworks.com ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id s9sm17381303pfe.67.2017.07.14.02.12.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 02:12:19 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Fri, 14 Jul 2017 14:42:09 +0530 Message-Id: <1500023530-29025-2-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1500023530-29025-1-git-send-email-bala.manoharan@linaro.org> References: <1500023530-29025-1-git-send-email-bala.manoharan@linaro.org> Subject: [lng-odp] [RFC/API-NEXTv3 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" 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.7.9.5 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