From patchwork Sun May 15 13:49:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 9096421 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 D6DE2BF29F for ; Sun, 15 May 2016 13:52:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 386FC202AE for ; Sun, 15 May 2016 13:52:47 +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 8627D202A1 for ; Sun, 15 May 2016 13:52:46 +0000 (UTC) Received: from localhost ([::1]:40414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1wTM-00037e-Qh for patchwork-qemu-devel@patchwork.kernel.org; Sun, 15 May 2016 09:52:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1wR4-0007St-J1 for qemu-devel@nongnu.org; Sun, 15 May 2016 09:50:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1wR1-0007Wh-Af for qemu-devel@nongnu.org; Sun, 15 May 2016 09:50:22 -0400 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35471) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1wR0-0007Wd-Le for qemu-devel@nongnu.org; Sun, 15 May 2016 09:50:19 -0400 Received: by mail-wm0-x236.google.com with SMTP id e201so72794484wme.0 for ; Sun, 15 May 2016 06:50:18 -0700 (PDT) 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=FkuVH2RmzhMvzSqE7aISQ9ln2QRvKnMckRTT4znVJN0=; b=GvLuKSaaDytEFZvf0MU23GCcdXXekkaW5BZFozHUIjuvgNucImXP1q+tigMj45K40G ReZAtQHLaB8wdXXpIQw7Yb8j6dHYfH+64fnarvlu15bGPe+mct/0jW5pYOCP7f6+cNNj rOkXMmixvJA7T7wiLWqczAIl/m3ok6FsfudaAEwzw6i3QlNB1PfIRA2eONJBYrDMuIdu f/eMc7dEF0pfqI49UFoVejNi7+fwijMUvx/4D3wehhoJzgY2gasq45N1ZCyn2nqTcZ8v ZUK1ba0IRzk8XtG/rXspttvAX8e4lYPJQ8BdRSuDoVDn/MtJ4VzxGW6HBQGSXDitvcGD YRaQ== 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=FkuVH2RmzhMvzSqE7aISQ9ln2QRvKnMckRTT4znVJN0=; b=KbKIA4/lBtIBCX25YRntWPbmbzr0fjg7wHfrfyZlgfvH3IcrHa0aiRQ+NQahhV6CgS 9miM7hL5IRBhzroTboZnFcdtLa/6Ap4y+bs6j+6BPoj8MaxLCUBIB/HuF/PJFhB9lzOJ 3msQh2yzRfztjl3N5Axj9mJMEGl3Dqx1WAkDOvXl0WuBqaDQT2XwU436dZkWLwpIcSja CcYSbHQgHvCo/eSFCtnQlOjmy7PnSdf7OJgasmKbsMtFO1Q+324WqOuwm4SW6/hFeJ5G QsNGUhrzNrWLcPz9WhI0FlQoCpydm1jMhZ+bnAgElAdvmBmp3L2mHhZ8/I+7137io2py EWEw== X-Gm-Message-State: AOPr4FW2/w3VBCoJPeHamQev+/0kai508OmMFnwhrX6r4kBL1jD9EUZayW70M3IFnmyhy5ZD X-Received: by 10.194.184.44 with SMTP id er12mr25778150wjc.83.1463320218013; Sun, 15 May 2016 06:50:18 -0700 (PDT) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id c4sm28742403wjm.24.2016.05.15.06.50.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 May 2016 06:50:17 -0700 (PDT) From: Leonid Bloch To: qemu-devel@nongnu.org Date: Sun, 15 May 2016 16:49:39 +0300 Message-Id: <1463320189-14108-7-git-send-email-leonid.bloch@ravellosystems.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1463320189-14108-1-git-send-email-leonid.bloch@ravellosystems.com> References: <1463320189-14108-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::236 Subject: [Qemu-devel] [PATCH v5 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: Dmitry Fleytman , 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 */