From patchwork Mon Jul 31 13:00:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 109031 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp207682qge; Mon, 31 Jul 2017 06:15:10 -0700 (PDT) X-Received: by 10.55.79.151 with SMTP id d145mr19554365qkb.37.1501506910517; Mon, 31 Jul 2017 06:15:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501506910; cv=none; d=google.com; s=arc-20160816; b=aYqXVffY8023MvPtonSs31b0X2vOvPDhZVZ+N3O2+JMwmIKWArWW4UNUjFO7EApYdk Q0BlyRXN+FF2sWPikkBgEO+GRpJiPGjkW5NhyzYBqwP9/xF+kKZFT6ur3RhodhCpsejB k87Dmt6Ieq4R/UTRkrf6kUCD11+GHeNUC+BtVd6Vom2jCTVTW61gFtqqBAHdgEuU9KfS qc+j4utWGQHjacT4XPTWpnoCZO418qKRMAPN3Z7kdJgV1XG4/6KXoQ0/H7radJdCHPio cdsQ36vAKw2yjiO/iIaqIBjDHmRmsc2oTka40UnN4dvx4w7kPUJuNlBcgn0DrbkLipHb aCwA== 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:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=65tcvmwLRColsaYWI8sYi2yNO1EmVt+jPlWr6MPn2vs=; b=ftYx4d3YOFIdlEGbgkmJdyMHAZkDGXxyDoAG6jeRybtigXEltmWsgiVdyWotozirB8 rmUFOnmKh0nFwZ3XkjVP7dKcqMqnzNHZs79RdyxpFGJ0Id1Vy3rMZinNo/YBWagdacqP 0RNuGJMO/JRxywEJNxTIJha8CeH03nAlQNo7bY6DLPqFeIXCl/4t5ezejJoN/pCgEYIo /93r71qCyhqwql/RRJ+0N2bB8kNZOaRFzQgry78uLzIQK61VVvWJ7L4RvZ0/fksK3AGL BNNLQueNzqVEHBrO7TCLmWjtusocgHiQAuc3onIdHyKutv7TXf1Y5IIEzQ4/O/ZY3Xj2 vFoQ== 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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p35si22635790qte.361.2017.07.31.06.15.10; Mon, 31 Jul 2017 06:15:10 -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=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 1E7686356E; Mon, 31 Jul 2017 13:15:10 +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.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 0C199644A9; Mon, 31 Jul 2017 13:02:29 +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 94D93644A8; Mon, 31 Jul 2017 13:02:24 +0000 (UTC) Received: from forward5p.cmail.yandex.net (forward5p.cmail.yandex.net [77.88.31.20]) by lists.linaro.org (Postfix) with ESMTPS id A5EA16447E for ; Mon, 31 Jul 2017 13:00:53 +0000 (UTC) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b6:6]) by forward5p.cmail.yandex.net (Yandex) with ESMTP id C2F1020CF5 for ; Mon, 31 Jul 2017 16:00:51 +0300 (MSK) Received: from smtp1p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp1p.mail.yandex.net (Yandex) with ESMTP id 63E6E1780B12 for ; Mon, 31 Jul 2017 16:00:40 +0300 (MSK) Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id NLn3FAt8kT-0d9mAGBP; Mon, 31 Jul 2017 16:00:40 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Mon, 31 Jul 2017 16:00:25 +0300 Message-Id: <1501506026-29942-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501506026-29942-1-git-send-email-odpbot@yandex.ru> References: <1501506026-29942-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 93 Subject: [lng-odp] [PATCH API-NEXT v1 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" From: Balasubramanian Manoharan Adds toeplitz hash algorithm implementation for RSS hashing Signed-off-by: Balasubramanian Manoharan --- /** Email created from pull request 93 (bala-manoharan:api-next) ** https://github.com/Linaro/odp/pull/93 ** Patch: https://github.com/Linaro/odp/pull/93.patch ** Base sha: c16f1363303cd5fc11324acbc4dfebe0a9680a41 ** Merge commit sha: None **/ platform/linux-generic/include/protocols/thash.h | 108 +++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 platform/linux-generic/include/protocols/thash.h diff --git a/platform/linux-generic/include/protocols/thash.h b/platform/linux-generic/include/protocols/thash.h new file mode 100644 index 00000000..fe141e3e --- /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