From patchwork Mon Mar 25 12:26:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 230692 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 3F6502C00A7 for ; Mon, 25 Mar 2013 23:27:07 +1100 (EST) Received: from localhost ([::1]:39947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK6UT-0003G6-Cl for incoming@patchwork.ozlabs.org; Mon, 25 Mar 2013 08:27:05 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK6Tv-0003AM-Va for qemu-devel@nongnu.org; Mon, 25 Mar 2013 08:26:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UK6Tr-0004A9-AC for qemu-devel@nongnu.org; Mon, 25 Mar 2013 08:26:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42811) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK6Tq-00049x-QC for qemu-devel@nongnu.org; Mon, 25 Mar 2013 08:26:27 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2PCQOYN010583 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Mar 2013 08:26:25 -0400 Received: from localhost (ovpn-112-26.ams2.redhat.com [10.36.112.26]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2PCQNn5007781; Mon, 25 Mar 2013 08:26:24 -0400 From: Stefan Hajnoczi To: Date: Mon, 25 Mar 2013 13:26:09 +0100 Message-Id: <1364214373-2444-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1364214373-2444-1-git-send-email-stefanha@redhat.com> References: <1364214373-2444-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Dmitry Fleytman , Yan Vugenfirer , Anthony Liguori , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 3/7] 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 From: Dmitry Fleytman Signed-off-by: Dmitry Fleytman Signed-off-by: Yan Vugenfirer Signed-off-by: Stefan Hajnoczi --- 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; +}