From patchwork Thu Feb 18 10:07:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 8348291 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CE90AC0553 for ; Thu, 18 Feb 2016 10:14:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D0A5201F5 for ; Thu, 18 Feb 2016 10:14:35 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 7EF72201F4 for ; Thu, 18 Feb 2016 10:14:34 +0000 (UTC) Received: from localhost ([::1]:39464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWLbV-00080n-OO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Feb 2016 05:14:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWLVI-0006Vr-L0 for qemu-devel@nongnu.org; Thu, 18 Feb 2016 05:08:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWLVH-0001Rw-6z for qemu-devel@nongnu.org; Thu, 18 Feb 2016 05:08:08 -0500 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:34657) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWLVG-0001Rl-W3 for qemu-devel@nongnu.org; Thu, 18 Feb 2016 05:08:07 -0500 Received: by mail-wm0-x22d.google.com with SMTP id b205so17432985wmb.1 for ; Thu, 18 Feb 2016 02:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ravellosystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q+MZ/ytqvuc0LvHuhzPMysDd5xnuL0crIE8OIORW+2g=; b=f8naMEDiGBTVW4NXJehRPs393+ZOooSAoAHoCbgOUGGZqxiSARPPsNIJ4kYc0fmycH GqK+VOLmVxYlw/ufojw/uzbVb6uJfEIxX7qDsO+Q92t1ZcigC5QbIz616RknMP+ev53O cCaaN99LBhZJz0HnVJlfAqKY3QbqlxZveUeO4wQuw54eZCreYLaETvxT9UkoRkItlDSg RH3Zeg1CXSotfnqhEsLkZ1wpa6XBqTi115zSH55I3aRx+Th+w3n/9oNidGSeJ57VXBvB nk0zrxC7Pw0WikK5utGKH79C3289UWtxNbGP/NsYo5M+9GonJJ8ha8EbXFhV9O1an3o9 I+gQ== 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=q+MZ/ytqvuc0LvHuhzPMysDd5xnuL0crIE8OIORW+2g=; b=hY7djcVIbnGlmDAN/+SnSxX7IYUayrKiIHa6wzKAK1RxCvCATrkdOe2S13J7vB39dU DdPHQnn/lTRmc9aUp1AhjiPjBGm4cg/nUanEpTW8QrH5PFAONHvfjG588RXuaVxV8tSm bItCgMnSlBXFGVVegdQSmn+y7zfUIpkfnePKuONUN0nZWLghngo6zwyAuxQFqLfnOBIw LlHbLoES42JJLWmMpf1J7PNFtW5JjWfbR3tkZFXdTQ5huqMudxx3Wjwn2hLcbZzOPc2F kd9+mE3b+hMOcW4wwAvNnHUa3BiHdAlsFqYZ9uEr+SYbMS4DaN6MrOG7148sZJyi9qmz 1QJg== X-Gm-Message-State: AG10YOQHFrCjR0uhmvZngkzaVHc97qSlqtF2dD59lrn7JLjsSqi7nS+0jwzayff8CyfpU6sZ X-Received: by 10.194.59.233 with SMTP id c9mr6345161wjr.88.1455790086500; Thu, 18 Feb 2016 02:08:06 -0800 (PST) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id x65sm2214799wmg.4.2016.02.18.02.08.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Feb 2016 02:08:05 -0800 (PST) From: Leonid Bloch To: qemu-devel@nongnu.org Date: Thu, 18 Feb 2016 12:07:27 +0200 Message-Id: <1455790054-1952-7-git-send-email-leonid.bloch@ravellosystems.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455790054-1952-1-git-send-email-leonid.bloch@ravellosystems.com> References: <1455790054-1952-1-git-send-email-leonid.bloch@ravellosystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22d Cc: Dmitry Fleytman , Jason Wang , Leonid Bloch , Shmulik Ladkani , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH 06/13] net: Introduce Toeplitz hash calculator X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Fleytman Signed-off-by: Dmitry Fleytman Signed-off-by: Leonid Bloch --- include/net/checksum.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/net/checksum.h b/include/net/checksum.h index 2d7a363..77d226f 100644 --- a/include/net/checksum.h +++ b/include/net/checksum.h @@ -19,6 +19,7 @@ #define QEMU_NET_CHECKSUM_H #include +#include "qemu/bswap.h" struct iovec; uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq); @@ -51,4 +52,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 */