From patchwork Sun Apr 10 15:14:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 8789461 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 C1EA59F39A for ; Sun, 10 Apr 2016 15:18:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1DFB4201B9 for ; Sun, 10 Apr 2016 15:18:05 +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 7383B200DE for ; Sun, 10 Apr 2016 15:18:04 +0000 (UTC) Received: from localhost ([::1]:35248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apH7j-0003f0-Op for patchwork-qemu-devel@patchwork.kernel.org; Sun, 10 Apr 2016 11:18:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apH5N-0007bm-Mr for qemu-devel@nongnu.org; Sun, 10 Apr 2016 11:15:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1apH5K-00086B-EU for qemu-devel@nongnu.org; Sun, 10 Apr 2016 11:15:37 -0400 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:34729) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apH5J-00085i-TW for qemu-devel@nongnu.org; Sun, 10 Apr 2016 11:15:34 -0400 Received: by mail-wm0-x233.google.com with SMTP id l6so116303071wml.1 for ; Sun, 10 Apr 2016 08:15:33 -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=WOEJ/a6CI9gRtaAkhEDDOTv0mpD5au+CqCwiBY3iprM=; b=tmD63wy3wfNanSs4taewxzNMO1d0iBgHcM4YsWXMgj+MYw/tWn3IlY1Lqfx49HfmIO CnqHg4z81jaXuvfNXSFG4MQfM1vDR4fCy6zY2hlO34m951llGhKCOMoeN3EpUvZ32h5j jGdwpqZpx1nMJ1Q5dtT46387K40haKKfzhuANd1xqw9Yr4kpbYdP0wBjGjv+L2tAFApC a97V3Ym3nfKRHMbxtdq7zHFfESR/bHnhdAJLN/CzbOuVMFJi5FXdre8X8vZZmilBvAKT MOnjItXx4El+x3yOJdguxx5I1ptiTb0TVWWUAFnQRc/oDU2AvLhsVOYgM1TR/QJI8avi X7jQ== 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=WOEJ/a6CI9gRtaAkhEDDOTv0mpD5au+CqCwiBY3iprM=; b=NH5TjK31uyZPZmlGX9i9i2FDLT5y6oMojFzJNb1xu20HDQ87LteVy92U/uxyT5N015 /HuQhHRBBXIRg+VyOagt5gPSFT7In1BLuatZ+fOR3VBRKh3SgCUMtJTeVli7LK/23ADa arJY+JPl6crwT5s2p6JQj8SjDd8lZdq29YfTo4x7MZ0vAZzbcHycn1MPIjpHU56HmdWs IAwJiMiASj9b08sSR7BtSRkHEYwIadulTKqA76ECmNL5EgOdcJ4+UBZSF4YFJI/q3TsV GmsNc2t4jeKwi13t+Wg01JmpvnfRB5WPuX/8sAC9oamk5YenkPqsL79/Ohcg4Nzp8XGQ cO6g== X-Gm-Message-State: AD7BkJIRp/Z2drdfxP4uetiiNLUVO/CJIMIFhe1lpZsMFBW7sOLGpOcDyKtAZRAtKe+pkw== X-Received: by 10.194.120.229 with SMTP id lf5mr21213373wjb.151.1460301333417; Sun, 10 Apr 2016 08:15:33 -0700 (PDT) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id j71sm12685874wmj.21.2016.04.10.08.15.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Apr 2016 08:15:32 -0700 (PDT) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Sun, 10 Apr 2016 18:14:55 +0300 Message-Id: <1460301305-5321-7-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460301305-5321-1-git-send-email-dmitry@daynix.com> References: <1460301305-5321-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::233 Subject: [Qemu-devel] [PATCH v4 06/16] 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-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 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 */