From patchwork Mon Feb 22 17:37:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 8381221 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 243D99F372 for ; Mon, 22 Feb 2016 17:44:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 755002042B for ; Mon, 22 Feb 2016 17:44:17 +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 C81D12041D for ; Mon, 22 Feb 2016 17:44:16 +0000 (UTC) Received: from localhost ([::1]:50820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXuWu-0006SY-4Y for patchwork-qemu-devel@patchwork.kernel.org; Mon, 22 Feb 2016 12:44:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXuR7-0004Gt-Fq for qemu-devel@nongnu.org; Mon, 22 Feb 2016 12:38:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXuR3-0007lq-02 for qemu-devel@nongnu.org; Mon, 22 Feb 2016 12:38:17 -0500 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:38300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXuR2-0007ll-QC for qemu-devel@nongnu.org; Mon, 22 Feb 2016 12:38:12 -0500 Received: by mail-wm0-x22b.google.com with SMTP id a4so173777642wme.1 for ; Mon, 22 Feb 2016 09:38:12 -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=Hkyl/VAVOtK+WPcfcutekfcUROgcMTby5SsWTQ0hKe+GYmCkr9m3mrpo/OIcLq2/bN 8QKv0ZB4U/2fEFPW6yT9T8pkzwnAZOvHv2MzlN4h39EvHYT6nZ+3b+e4lX021D9vnE7W V5g15SoaK7txYDErN6mBQwTnFSCjQykPyusgGKewEbNDg3ov7C1DI4UMZ96Om2fjLAEn rNLP7I2T+HKEZJx/SueM730cGNdw8An1BkaLk2Sz3nXhOq8rQYF6Sm+IiPV1PYd+PeHK vt+E3P/UJFrKaqN0k6JUtsdmwDH1JnXVbYpkY/7I9Pnl66tOSya+kAebnqZGwDIgq61/ Sngg== 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=iLleAfSQnEi1/hAm2+8C74mSOb0nQHbD6PfkMOK8A9TUhRF2TZSMsPqMnU/MfhxMdP 01sQhZQUIzKrw9FcESlTDi/di1bRb68N6SAdF7p3dLHpELoqXNwnAtNycAZ+4JZwPcGE jS7dOHIBazvROQW26/liR+J6Ms7Q1F2vGpSwCw59t9y88VoDw2uWf64g1KybaYa7Hqxi dXrA25PUDPx75bwN3qMaxRGeJKbDauwXAUZfldjITi83FX7lhD25NU3Up2+CiNwROlVL L248xcz4t7PRusMbZaCgSAuQY+8O7a4Y2rApWuCJ33awqtmAwQibrD743LGF7qihuAMZ 1y2g== X-Gm-Message-State: AG10YORw6bMdDTg7TphkAcqxrNn0mjEW6ITkebNkCXoiNKx95D15S1KjOrIWcN1vQhkf3QPL X-Received: by 10.28.9.71 with SMTP id 68mr13417245wmj.33.1456162692256; Mon, 22 Feb 2016 09:38:12 -0800 (PST) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id gb9sm25658085wjb.26.2016.02.22.09.38.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Feb 2016 09:38:11 -0800 (PST) From: Leonid Bloch To: qemu-devel@nongnu.org Date: Mon, 22 Feb 2016 19:37:24 +0200 Message-Id: <1456162651-22181-7-git-send-email-leonid.bloch@ravellosystems.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456162651-22181-1-git-send-email-leonid.bloch@ravellosystems.com> References: <1456162651-22181-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::22b Cc: Dmitry Fleytman , Jason Wang , Leonid Bloch , Shmulik Ladkani , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH v2 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 */