From patchwork Mon Feb 25 20:11:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 223028 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 081E92C0091 for ; Tue, 26 Feb 2013 07:11:56 +1100 (EST) Received: from localhost ([::1]:33688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UA4Ow-0007rm-1w for incoming@patchwork.ozlabs.org; Mon, 25 Feb 2013 15:11:54 -0500 Received: from eggs.gnu.org ([208.118.235.92]:44078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UA4OZ-0007Vq-1l for qemu-devel@nongnu.org; Mon, 25 Feb 2013 15:11:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UA4OU-0002lm-5p for qemu-devel@nongnu.org; Mon, 25 Feb 2013 15:11:30 -0500 Received: from mail-we0-x235.google.com ([2a00:1450:400c:c03::235]:37364) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UA4OT-0002lT-Sf for qemu-devel@nongnu.org; Mon, 25 Feb 2013 15:11:25 -0500 Received: by mail-we0-f181.google.com with SMTP id t44so2849318wey.40 for ; Mon, 25 Feb 2013 12:11:25 -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=nTKlT6eTQ5lvS8sXn9KeJWyQh+QxIuq9H0afCPSqa5s=; b=khCiEWYZ1o+eYk0Cs3n3uJWej0lvlQ1Yi6tH3vvzrOBuQL/AcMZd82mdEdeA2s6v8l IorMLYUrFF6FsWe7HE4jK/UCSaULY1pNqx7sgtCWA52fZvjYx0IVina9bh2GIUF55iWG z5wCSzVQq3G5vwvAtrO6k38qRRfrcEKZm5BC/Zw6l0n+0+l/nC3ir0alRsfu3Eje+skO oa4+DRy/VkDeEfs1GFxi5wdr0kupaDYyhzYuuw1JyIHd/HTrmHAX+pcb/541SdcKcRPv 3gC6SNdgI1hcr6y2xH7iS4MZJcbkJJ/odTRcEvmNml6XgzWNH5UwUwlfFDlwbRezMODr 8uyw== X-Received: by 10.180.93.168 with SMTP id cv8mr14832764wib.5.1361823085033; Mon, 25 Feb 2013 12:11:25 -0800 (PST) Received: from Snarl.daynix ([91.205.155.63]) by mx.google.com with ESMTPS id eo1sm17080048wib.8.2013.02.25.12.11.22 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 25 Feb 2013 12:11:24 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Mon, 25 Feb 2013 22:11:00 +0200 Message-Id: <1361823063-26713-3-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1361823063-26713-1-git-send-email-dmitry@daynix.com> References: <1361823063-26713-1-git-send-email-dmitry@daynix.com> X-Gm-Message-State: ALoCoQkh4bzfxpe+OT2OWh97FApdSy9qSgcWsrgRx8g6mwlHsIfI8xMlFUIDaU1wUykRkCyK3W6R X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::235 Cc: Gerhard Wiesinger , Stefan Hajnoczi , Yan Vugenfirer , Anthony Liguori , Dmitry Fleytman , Paolo Bonzini Subject: [Qemu-devel] [PATCH v11 2/5] iovec checksum calculation fuction 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 | 8 ++++++++ net/checksum.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/net/checksum.h b/include/net/checksum.h index 3e7b93d..b1cf18a 100644 --- a/include/net/checksum.h +++ b/include/net/checksum.h @@ -19,6 +19,7 @@ #define QEMU_NET_CHECKSUM_H #include +#include "qemu-common.h" uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq); uint16_t net_checksum_finish(uint32_t sum); @@ -38,4 +39,11 @@ net_raw_checksum(uint8_t *data, int length) return net_checksum_finish(net_checksum_add(length, data)); } +/** + * Checksum calculation for scatter-gather vector + */ +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..9c813ff 100644 --- a/net/checksum.c +++ b/net/checksum.c @@ -84,3 +84,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; +}