From patchwork Wed Mar 6 07:21:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 225377 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 50EA82C033F for ; Wed, 6 Mar 2013 18:24:15 +1100 (EST) Received: from localhost ([::1]:52084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD8hx-0000eI-GZ for incoming@patchwork.ozlabs.org; Wed, 06 Mar 2013 02:24:13 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD8fw-00066H-AO for qemu-devel@nongnu.org; Wed, 06 Mar 2013 02:22:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UD8fs-00011X-M5 for qemu-devel@nongnu.org; Wed, 06 Mar 2013 02:22:08 -0500 Received: from mail-we0-x233.google.com ([2a00:1450:400c:c03::233]:43804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UD8fs-00011H-1M for qemu-devel@nongnu.org; Wed, 06 Mar 2013 02:22:04 -0500 Received: by mail-we0-f179.google.com with SMTP id p43so7290471wea.38 for ; Tue, 05 Mar 2013 23:22:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=c+yh0heEWoVAvbbPqCnxpmIt0cWheqR/WBNYYcsnFfA=; b=dr1D3AXx/qJ7Ld3ALbIdyBh/7HTODysemxV6mfrd99vg/iC1Kyyl6lv2FGd/wkj/3h qf+cyjDqkUdBe90P5blkfoq8E+EXpkiS1EUwyWnZW0umzsBr2MQZjfGUqjqC5RDwL/8I 5DsWZa7QfNHmMkBwHR0yJKjKHs8f8WSO32S7Ykk9mNiv0+6kddqjJ3/Z9K3rMJ4RQyvz 3gCa/3WYvDWjX3cScKAB04bkkizpAQIU3utdhSUZb04BA+jFe5waSRTR9QUpruutNVRR Zqc2YlVkvPBVOHZvKIftvR19o7YaSpJ36R9Y40fL4wiYoiaVNrO2odFR4EF231IYR1Ys Ar/A== X-Received: by 10.194.88.138 with SMTP id bg10mr44716014wjb.13.1362554523280; Tue, 05 Mar 2013 23:22:03 -0800 (PST) Received: from Snarl.daynix ([91.205.155.63]) by mx.google.com with ESMTPS id n2sm24918122wiy.6.2013.03.05.23.22.01 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 05 Mar 2013 23:22:02 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2013 09:21:39 +0200 Message-Id: <1362554502-15248-3-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1362554502-15248-1-git-send-email-dmitry@daynix.com> References: <1362554502-15248-1-git-send-email-dmitry@daynix.com> X-Gm-Message-State: ALoCoQlX7ckbYxtnpgleLww8iGyuUra7yyiBUUgjhoA6Pf5Cm0/PXcPw0xw2BpVJjSDiH/+jblO+ X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::233 Cc: Gerhard Wiesinger , Stefan Hajnoczi , Yan Vugenfirer , Anthony Liguori , Dmitry Fleytman , Paolo Bonzini Subject: [Qemu-devel] [PATCH v13 2/5] net: iovec checksum 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 Signed-off-by: Dmitry Fleytman Signed-off-by: Yan Vugenfirer --- include/net/checksum.h | 12 ++++++++++++ net/checksum.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/net/checksum.h b/include/net/checksum.h index 3e7b93d..80203fb 100644 --- a/include/net/checksum.h +++ b/include/net/checksum.h @@ -38,4 +38,16 @@ net_raw_checksum(uint8_t *data, int length) return net_checksum_finish(net_checksum_add(length, data)); } +/** + * net_checksum_add_iov: scatter-gather vector checksumming + * + * @iov: input scatter-gather array + * @iov_cnt: number of array elements + * @iov_off: starting iov offset for checksumming + * @size: length of data to be checksummed + */ +uint32_t net_checksum_add_iov(const struct iovec *iov, + const unsigned int iov_cnt, + uint32_t iov_off, uint32_t size); + #endif /* QEMU_NET_CHECKSUM_H */ diff --git a/net/checksum.c b/net/checksum.c index 4fa5563..14c0855 100644 --- a/net/checksum.c +++ b/net/checksum.c @@ -15,6 +15,7 @@ * along with this program; if not, see . */ +#include "qemu-common.h" #include "net/checksum.h" #define PROTO_TCP 6 @@ -84,3 +85,31 @@ void net_checksum_calculate(uint8_t *data, int length) data[14+hlen+csum_offset] = csum >> 8; data[14+hlen+csum_offset+1] = csum & 0xff; } + +uint32_t +net_checksum_add_iov(const struct iovec *iov, const unsigned int iov_cnt, + uint32_t iov_off, uint32_t size) +{ + size_t iovec_off, buf_off; + unsigned int i; + uint32_t res = 0; + uint32_t seq = 0; + + iovec_off = 0; + buf_off = 0; + for (i = 0; i < iov_cnt && size; i++) { + if (iov_off < (iovec_off + iov[i].iov_len)) { + size_t len = MIN((iovec_off + iov[i].iov_len) - iov_off , size); + void *chunk_buf = iov[i].iov_base + (iov_off - iovec_off); + + res += net_checksum_add_cont(len, chunk_buf, seq); + seq += len; + + buf_off += len; + iov_off += len; + size -= len; + } + iovec_off += iov[i].iov_len; + } + return res; +}