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: 586430 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 792181409A0 for ; Tue, 23 Feb 2016 04:44:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ravellosystems-com.20150623.gappssmtp.com header.i=@ravellosystems-com.20150623.gappssmtp.com header.b=Hkyl/VAV; dkim-atps=neutral Received: from localhost ([::1]:50826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXuXF-0007VF-Sj for incoming@patchwork.ozlabs.org; Mon, 22 Feb 2016 12:44:37 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 */