From patchwork Thu Jul 27 13:08:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 108847 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2369746qge; Thu, 27 Jul 2017 10:50:33 -0700 (PDT) X-Received: by 10.200.35.215 with SMTP id r23mr7789533qtr.229.1501177833895; Thu, 27 Jul 2017 10:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501177833; cv=none; d=google.com; s=arc-20160816; b=CYaR09i0FlnZ+vNZPOGTr9+eYMI4c9aNN5EdVbvLYMrECWitdBKjs+AHS6AOYky4FH IF20dnucTsZiHJll54/RftkbBtjHgY0QvPwOcLFLGXalMErvtlnInrD+JH5tKlACrKrS y6xEOPFFFYbuQKi2A/eqii+May14ze8jyy15Zy9V8sO5n62ZmbBo+pcdLd1ipe1RTpas UXQmKUZYEr3va1ppRwmHczo2HJ00ZmJ0VV6JzlEQSQwRElE+GvdinMJpH41nMfGtts93 CFEUzkByo3cK0tZgfFdcz13cm4wphIg0KZWkzMpyQmHABKFZgqbgOE7KJQ4UfCVwSxBl eWfg== 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=gUEB4p8CWbcQgIyOIEgFXE2wTOk+mzwS5vtnLXRhZZO76nSIE1ZHqsPgRlFH8wjIyZ 7CHilVFUWzbBc3wMiLafmRCMCZeLC5+xOceceT6yDS8YWxwgjWB0e/PIgytZGwDgr9Og ftWTsaynssN439fmJCuyLlf7+qG9BIPwjSu8Y/Qp7CO0fh02GHRt8zvuFF9sRJ80KzFo 86ED41gbtODFKm1TMPAEPQH5t6XuJyLFeR0Uho97vSxA1J1vyLTRxOsXsOy2CgGgl3Qg bloL2zxYqP1Mh1CVIUZEdpz3wx/dV6PwIzgMm3WmScjjpaoy4nd5/VbIUDwvta2MU6qn tk7g== 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 c37si2029248qtd.212.2017.07.27.10.50.33; Thu, 27 Jul 2017 10:50:33 -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 6CD5865BFA; Thu, 27 Jul 2017 17:50:33 +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=0.2 required=5.0 tests=BAYES_00, DATE_IN_PAST_03_06, 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 9EE4F65BFE; Thu, 27 Jul 2017 17:50:30 +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 E95F765C00; Thu, 27 Jul 2017 17:50:27 +0000 (UTC) Received: from mail-pg0-f45.google.com (mail-pg0-f45.google.com [74.125.83.45]) by lists.linaro.org (Postfix) with ESMTPS id 9510865C00 for ; Thu, 27 Jul 2017 17:49:52 +0000 (UTC) Received: by mail-pg0-f45.google.com with SMTP id 123so100818056pgj.1 for ; Thu, 27 Jul 2017 10:49:52 -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=Z21oxJrgm+/9puB9+/dWCwEU7twnIVXZiv+eOMMA6fButjZyhgpLVzLYGQveuBaH9g k+VZKjirDnwnf3e0RaMxGPE3iOTIG7Mnvuy/2vdaruMgh89zNj0ujT9FJpIVW0qIJJLy 73v8I9OTch2O4ZBPdfiwDcYeLKrd/IcJd+AGH6CbYVdUp6Vc1tywDrjM9tzLRln7dTSY E1lZ1vGX9JWP07tDLLk3JtEMyYxBu9OmKsO3I6jk02cVXkb87zpmmRrEdEEppXklT2s4 51TdoQvUH60HHKIggUySpqkvhEOHi4b+wqBSaqNzxWe6LWdJBILdym0dacISRU+j97XB ulbA== X-Gm-Message-State: AIVw113WLM3CH7bfu0WVDp0dWFbhDGeKx7HvDbKaOeUiuHlZ8qkot5Zo 6QIQAj84Slkbb0KkplRrOmUY X-Received: by 10.99.119.206 with SMTP id s197mr4887588pgc.439.1501177791575; Thu, 27 Jul 2017 10:49:51 -0700 (PDT) Received: from bala.domain.name ([117.199.137.21]) by smtp.gmail.com with ESMTPSA id 10sm39229655pfo.134.2017.07.27.10.49.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Jul 2017 10:49:51 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Thu, 27 Jul 2017 06:08:22 -0700 Message-Id: <1501160903-25098-2-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501160903-25098-1-git-send-email-bala.manoharan@linaro.org> References: <1501160903-25098-1-git-send-email-bala.manoharan@linaro.org> Subject: [lng-odp] [API-NEXTv5 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