From patchwork Wed Jun 1 08:23:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 9146371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8836460761 for ; Wed, 1 Jun 2016 08:33:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 781CA22473 for ; Wed, 1 Jun 2016 08:33:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C99426785; Wed, 1 Jun 2016 08:33:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 15CFE22473 for ; Wed, 1 Jun 2016 08:33:49 +0000 (UTC) Received: from localhost ([::1]:40874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b81b2-0000IZ-6w for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Jun 2016 04:33:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b81Rj-0000nx-Sf for qemu-devel@nongnu.org; Wed, 01 Jun 2016 04:24:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b81Rf-0000A0-QR for qemu-devel@nongnu.org; Wed, 01 Jun 2016 04:24:11 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b81Rf-00009u-Jb for qemu-devel@nongnu.org; Wed, 01 Jun 2016 04:24:07 -0400 Received: by mail-wm0-x243.google.com with SMTP id a136so4500073wme.0 for ; Wed, 01 Jun 2016 01:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XSvENe8lizfpfmtFoo17Ca+83HDGSkbMknkYAjm6ePE=; b=hGr6Y5B/nrz+9vkeSyFwOZodPyiV/kc06uJ4Sfvtyu6mhANHMY6x9fs7UJo0ZGqKZ2 /J7WJfzdhz8J6Wp49xHHIUYDYKyj3Z43fSRkk7nQd5ql4J4oABPaGrkj3DYTOG33KPib D8bmaUGi0mRGEH48a2S1jZ65MOeQu/50b0KPqlTTNFlzYKQDuKzlT2d3pBYnEqFN4aYG 8Pt8hMQ8G0fR/k6obWQEn66KtOodu9yYQwumZ8a0q5EQ3mH7kLfRSqIjkAsuLhYrgrII ka6M/YwLC+smfjF9/KTKtGXjUUgnHkSRKXsHAX2wf4LwJEzll/JEHGnqbsZnmgRXX25Q Gg8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XSvENe8lizfpfmtFoo17Ca+83HDGSkbMknkYAjm6ePE=; b=eYL70JdZIFJCSSkjEiAogbgC1DCSjTc3LDFjaZLgz/lcVL5ou5sgKJos/QMJmeHtnF ongJfD1z/4ew71UGpj6IzKN9+ErE+KZaoAk8+ozR+ixt1cFbFSi8mZNUAiVOh5Vu/10n j5gJsOSB20wzAmiRZ/N2HYlo3hN7xAqhZd7iYV6ZPMBShk1LK0AmVVUIw3FuQGurwaDH 4biLiwEogme12KrROwfgSIulffUkO91SD1TFvHcYUb9wM2nVKyhB8FUsApmk5rAshToo H7mZ3F30vXP5ldjJB2kQskwYVIVcM7Ka9QHJAgG3TjcUD3X8BeULERzEy51u1/q/TLGK zEtQ== X-Gm-Message-State: ALyK8tIMLPmk5H/+7XBXg/NE2wl7nd9Btd1+EhAjh4MmW1XqZWoL4QDeGc5YCvV8YGZT6Q== X-Received: by 10.28.148.210 with SMTP id w201mr21433930wmd.63.1464769446965; Wed, 01 Jun 2016 01:24:06 -0700 (PDT) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id o10sm29242719wjz.37.2016.06.01.01.24.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2016 01:24:06 -0700 (PDT) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Wed, 1 Jun 2016 11:23:36 +0300 Message-Id: <1464769426-22276-8-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464769426-22276-1-git-send-email-dmitry@daynix.com> References: <1464769426-22276-1-git-send-email-dmitry@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH v8 07/17] net: Introduce Toeplitz hash calculator X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Jason Wang , Leonid Bloch , Shmulik Ladkani , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Fleytman Signed-off-by: Dmitry Fleytman Signed-off-by: Leonid Bloch Reviewed-by: Michael S. Tsirkin --- include/net/checksum.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/net/checksum.h b/include/net/checksum.h index 7de1acb..dd8b4f6 100644 --- a/include/net/checksum.h +++ b/include/net/checksum.h @@ -18,6 +18,7 @@ #ifndef QEMU_NET_CHECKSUM_H #define QEMU_NET_CHECKSUM_H +#include "qemu/bswap.h" struct iovec; uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq); @@ -50,4 +51,48 @@ uint32_t net_checksum_add_iov(const struct iovec *iov, const unsigned int iov_cnt, uint32_t iov_off, uint32_t size); +typedef struct toeplitz_key_st { + uint32_t leftmost_32_bits; + uint8_t *next_byte; +} net_toeplitz_key; + +static inline +void net_toeplitz_key_init(net_toeplitz_key *key, uint8_t *key_bytes) +{ + key->leftmost_32_bits = be32_to_cpu(*(uint32_t *)key_bytes); + key->next_byte = key_bytes + sizeof(uint32_t); +} + +static inline +void net_toeplitz_add(uint32_t *result, + uint8_t *input, + uint32_t len, + net_toeplitz_key *key) +{ + register uint32_t accumulator = *result; + register uint32_t leftmost_32_bits = key->leftmost_32_bits; + register uint32_t byte; + + for (byte = 0; byte < len; byte++) { + register uint8_t input_byte = input[byte]; + register uint8_t key_byte = *(key->next_byte++); + register uint8_t bit; + + for (bit = 0; bit < 8; bit++) { + if (input_byte & (1 << 7)) { + accumulator ^= leftmost_32_bits; + } + + leftmost_32_bits = + (leftmost_32_bits << 1) | ((key_byte & (1 << 7)) >> 7); + + input_byte <<= 1; + key_byte <<= 1; + } + } + + key->leftmost_32_bits = leftmost_32_bits; + *result = accumulator; +} + #endif /* QEMU_NET_CHECKSUM_H */