From patchwork Thu Jul 20 02:37:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 108567 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp3862219obm; Mon, 24 Jul 2017 06:36:57 -0700 (PDT) X-Received: by 10.55.114.1 with SMTP id n1mr20963182qkc.123.1500903417151; Mon, 24 Jul 2017 06:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500903417; cv=none; d=google.com; s=arc-20160816; b=GCkvpUeanAbJ1FrX1unIndk+iHNrpSYhxV1gWVuq0SEEzbimIDLfguDWyotuZvpPlK rGiy519KuaokQOG7xXjsBQd4UQhRPZ4EZlSDn4ML9LnIcNF71Z4SsPaeXcjX2UoTxXhR CgEXPA+dvZlErl0ezO/okMV5kvDEWkhhkLJks9c2oZabh3h06G+nwYZK0qwubMWJT1Iw 1ql4UPJkvSdk1quWeTeK6eXj5WAPDLo4drqex4dWcaUE7CIK+pG01H8AmfTENe5/QJ5t fbJprkQeRWTCSWrHUsdg4SZagTnSDy3e1zUJN0oCjwwajA04DZRYgPhJl7AJaG8qAHjm EJGw== 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=9hzgRGyQ2eEPDWGwyhrEL1EajRLj6OxfZZ+C/oJtP8c=; b=UDWFjkxQz5O5WcEMMuB8Owgpdn+q9cefX9FJhwiC7Cm+BSE4Vtlnn0jMMx1JrkDZxb nfiyIp8odtW9NiGyWorQYHhqIYtgZOLriZ5/aNhN+Ogl0+ESYA7s4uW6LjAmgasX2ZI+ +MiRS0GYqvrgDhVrUPRsXSnDOLtAVJt3pev65OFggeJt4vOJFV+zshml0C7MFTmgf1BE Pb/NEvNW2WO9IRutRGhbSyzCL9IkrPiu7feHCyrcibHrMCsgrVr/2PqLzw8x3c93/FmO +tMNx3YmTkw7Vso+/TmpPhQ3h8lNxuF+1N0v/NDjkaqo9v4vNjHZ3b9kPrgqEY7KJXvC yO4g== 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 p124si8803139qkb.502.2017.07.24.06.36.56; Mon, 24 Jul 2017 06:36:57 -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 BA4A264478; Mon, 24 Jul 2017 13:36:56 +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.0 required=5.0 tests=BAYES_00, DATE_IN_PAST_96_XX, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, 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 40C6D60CC1; Mon, 24 Jul 2017 13:36:53 +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 C0BCC60CC1; Mon, 24 Jul 2017 13:36:50 +0000 (UTC) Received: from mail-pg0-f42.google.com (mail-pg0-f42.google.com [74.125.83.42]) by lists.linaro.org (Postfix) with ESMTPS id AFED060CD1 for ; Mon, 24 Jul 2017 13:36:16 +0000 (UTC) Received: by mail-pg0-f42.google.com with SMTP id g14so8457992pgu.0 for ; Mon, 24 Jul 2017 06:36:16 -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=9hzgRGyQ2eEPDWGwyhrEL1EajRLj6OxfZZ+C/oJtP8c=; b=AmzKwsYd7GF5x0WJTVGIIFgP+TkwAD4X5YKhmfEh6VyC3gOw08hL/l+MTIv2FZDUhb 4cvWxn7hS+si04x7130lwbFr4zYqrypDyjdncxiRPg6ClJ6j8tsZ7rq3VCHP9lto8km5 t35bQxXwafdxDV9WFgsZTYIQFUX1vHSa2okW7pgDBWiW3YxqhLfQplCVAixCi5NwxCqI Cm6Q0JIMlFacnGTAqZk/FpDh+VK307s9/yfdXvC9tW6WRiecpJRZv5r74cQASkSbxwAK BP34tFw/mk5lVNJhqcn9iRcbMc4rlheNTbntkbAFq/EttsunhkwwSbkFJV+WIrxuZlgR ckDg== X-Gm-Message-State: AIVw113PxWnYuiDgFjWn/WYot9v64a+r2sROhR8+yaiiOEboVEgkmLwc lPXof1dHcLgKKj0jTzZeRCyb X-Received: by 10.98.46.131 with SMTP id u125mr15818392pfu.238.1500903375694; Mon, 24 Jul 2017 06:36:15 -0700 (PDT) Received: from localhost.localdomain ([122.171.79.37]) by smtp.gmail.com with ESMTPSA id j193sm21955917pfc.95.2017.07.24.06.36.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Jul 2017 06:36:15 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Wed, 19 Jul 2017 19:37:21 -0700 Message-Id: <1500518242-8898-2-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500518242-8898-1-git-send-email-bala.manoharan@linaro.org> References: <1500518242-8898-1-git-send-email-bala.manoharan@linaro.org> Subject: [lng-odp] [API-NEXTv4 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" Adds toeplitz hash algorithm implementation for RSS 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