From patchwork Wed Apr 6 08:37:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 606896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3qfzm64WzDz9s9x for ; Wed, 6 Apr 2016 18:44:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b=gUXgayTf; dkim-atps=neutral Received: from localhost ([::1]:41722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anj4G-0000OS-Ow for incoming@patchwork.ozlabs.org; Wed, 06 Apr 2016 04:44:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aniyY-0005kj-T8 for qemu-devel@nongnu.org; Wed, 06 Apr 2016 04:38:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aniyV-0000Kf-Mo for qemu-devel@nongnu.org; Wed, 06 Apr 2016 04:38:10 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33942) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aniyV-0000KZ-GW for qemu-devel@nongnu.org; Wed, 06 Apr 2016 04:38:07 -0400 Received: by mail-wm0-x241.google.com with SMTP id n3so11082809wmn.1 for ; Wed, 06 Apr 2016 01:38:07 -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=gUXgayTfXKwrinjCdmOVw4N5RaqP6fCsOBoDTg8RU4jV6qzeiP3+OQIx3nPIJ3tGcI FZUPZO6QV71nol9QOEgPal/eFItc6e5+irMMUiqjVD8NnwR3yCeZvUzp9mgv4hqYPdYS XiYgqpuMNtehbtfSml8L9UBJy/0fvpYgUilB8q+CbRV9NFYPZT/s1d+/Wsl60ur41WBK JU0lYSVvpKkOrHHInhvk9tssfbeqqwIPczXsdn5KI1ZaE8DT6+7frTpf52YFJKpfzzol OOvY9ogtZS8W0SODgY5GzKQYYJLjqeYQGLKU9tI1ecsRvB+XAPChKKT+mB6TiTMibNyU jR3g== 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=TV6aDI735sK1/7ygKt9TmnJJ3jHpLmtbdLLDj8XxH7lhBl4Fgy9qdxr0Xo9xdg1n1w ptEiRGRxH8Loe6IA/bYFR/YxXmNAKK8tZ8OA4nA5bSKlGZ10kjYw5/UCgBzdhkQT1ziX ft3+FDixGkvBkZrKjeGk3Zix2NlubcLLn5PHQO3a4nwYYHf9MvfHEQknCMUoTTN+V1YR 2eEpLOdmaLNDnMOdluPoCkW/hSEG+JVA38jsFjCslkxL5urIYNF/NjyVn+QtKbsPEo7M qXOqcZo5CI03ZaSLEoDLd7QiDxhBYpUaZTMTwu+1jemwi4lNELK1GMTpzuVNRXHUT6ST Km8g== X-Gm-Message-State: AD7BkJLOh8EIMNCiMcwdJJ4l0F8zV2zJ4PItpiJgTnn3aBY2gylU9kg5zP2qrBxtngE3QQ== X-Received: by 10.194.22.97 with SMTP id c1mr22275262wjf.19.1459931886858; Wed, 06 Apr 2016 01:38:06 -0700 (PDT) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id w186sm2436154wmd.20.2016.04.06.01.38.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Apr 2016 01:38:06 -0700 (PDT) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Wed, 6 Apr 2016 11:37:19 +0300 Message-Id: <1459931849-29336-7-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459931849-29336-1-git-send-email-dmitry@daynix.com> References: <1459931849-29336-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::241 Cc: Yan Vugenfirer , Jason Wang , Leonid Bloch , Shmulik Ladkani , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH v3 06/16] 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 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 */