From patchwork Sat Mar 9 09:21:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 226321 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 9BA252C033A for ; Sat, 9 Mar 2013 20:23:33 +1100 (EST) Received: from localhost ([::1]:34541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEG03-0002dU-Ol for incoming@patchwork.ozlabs.org; Sat, 09 Mar 2013 04:23:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEFy5-0008Np-3R for qemu-devel@nongnu.org; Sat, 09 Mar 2013 04:21:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UEFxy-0001Lf-DC for qemu-devel@nongnu.org; Sat, 09 Mar 2013 04:21:29 -0500 Received: from mail-wi0-x22c.google.com ([2a00:1450:400c:c05::22c]:45411) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEFxy-0001LZ-6W for qemu-devel@nongnu.org; Sat, 09 Mar 2013 04:21:22 -0500 Received: by mail-wi0-f172.google.com with SMTP id ez12so142589wid.5 for ; Sat, 09 Mar 2013 01:21:21 -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=BS8yddlyXtcsa3eUGK5nFIvd7Jr3j/UEaWlykz9QLhB00VEvG2vDtZyecnJA5LKmEV GNe53GFNHOl4hhKfPsKutkxforYUoHa/9Ht2fk1uvRLiaNy9R74bq9y3qD5zVWs6rtA9 fC1Cc1UApD4rXGYFgNFXOwrG9/hD++wfXfg1suFfX9cOitRejk0PMd1nC6zSJlZJ9dlX 0GMO0BT7wjTRXgNkSKdtRs6aySrLPUlQpdC4iypZwidHOePJtqdR8Z4xx53VHU97lOGu tdas5e6lxTNFKXubz2lAx0lcUaVZGbNJZvPAgQtUWty4C4huAfPMrea99CsaNZ/hXC8w iM4g== X-Received: by 10.194.20.72 with SMTP id l8mr8996902wje.36.1362820881525; Sat, 09 Mar 2013 01:21:21 -0800 (PST) Received: from Snarl.daynix ([91.205.155.63]) by mx.google.com with ESMTPS id er3sm2966932wib.1.2013.03.09.01.21.19 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 09 Mar 2013 01:21:20 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Sat, 9 Mar 2013 11:21:03 +0200 Message-Id: <1362820866-23426-3-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1362820866-23426-1-git-send-email-dmitry@daynix.com> References: <1362820866-23426-1-git-send-email-dmitry@daynix.com> X-Gm-Message-State: ALoCoQnNXyzwO06JeqgZ651t5ZaZZPCAPCNqkSDIDJwdWK5O94AiQIvLzurBviqGe8zwlKHFIcVj X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22c Cc: Gerhard Wiesinger , Stefan Hajnoczi , Yan Vugenfirer , Anthony Liguori , Dmitry Fleytman , Paolo Bonzini Subject: [Qemu-devel] [PATCH V14 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; +}