From patchwork Sat Mar 2 12:44:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 224488 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 81F5E2C02FB for ; Sat, 2 Mar 2013 23:45:31 +1100 (EST) Received: from localhost ([::1]:32989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBlof-0005lV-O6 for incoming@patchwork.ozlabs.org; Sat, 02 Mar 2013 07:45:29 -0500 Received: from eggs.gnu.org ([208.118.235.92]:37861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBloA-0005jh-06 for qemu-devel@nongnu.org; Sat, 02 Mar 2013 07:45:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBlo5-0001L5-Ne for qemu-devel@nongnu.org; Sat, 02 Mar 2013 07:44:57 -0500 Received: from mail-wg0-f43.google.com ([74.125.82.43]:49508) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBlo5-0001KM-Gr for qemu-devel@nongnu.org; Sat, 02 Mar 2013 07:44:53 -0500 Received: by mail-wg0-f43.google.com with SMTP id e12so3066602wge.34 for ; Sat, 02 Mar 2013 04:44:52 -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=FwX6qTHBQ1cOLG10WSnCMsu1WkBXRFkNjbP58S/QCkxoN2gzsPEXoMuRFUA7LTP65W uAeK7RRCZU662bCJ7tAbfzffYzL6GY9ZlhYhr07dVYF11Cp9wEwoO/9hK/Q+NqIWLeI6 hxjkVDALfwGVRE0RupyoXn8M1c3D/yT5bkfhm4mLyr3eD6hkAPGQ15YgcEWzN/vdYWPf ZPoED5iLx6PnyzFtqGQeFPNfMLNeoNl82MZhl3vmfgqrz1WsOQFy59DX6l74Ecm42ve8 LDWr2Gf0alcaHh+9DJ2jZwWEO6WKIhzN9tSJyNqPnMwvZ2P64t1Es5damhSjjeu/KLwn 4Zgg== X-Received: by 10.194.92.231 with SMTP id cp7mr22700528wjb.19.1362228292794; Sat, 02 Mar 2013 04:44:52 -0800 (PST) Received: from Snarl.daynix ([91.205.155.63]) by mx.google.com with ESMTPS id cf8sm3317607wib.1.2013.03.02.04.44.50 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 02 Mar 2013 04:44:52 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Sat, 2 Mar 2013 14:44:36 +0200 Message-Id: <1362228279-12628-3-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1362228279-12628-1-git-send-email-dmitry@daynix.com> References: <1362228279-12628-1-git-send-email-dmitry@daynix.com> X-Gm-Message-State: ALoCoQlNTgMxXlAXmQn/aQDck2EzdQLsNC43qImGnCboEQxmGn0fryhc9BcLajaN/23HHYXhPkrJ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 74.125.82.43 Cc: Gerhard Wiesinger , Stefan Hajnoczi , Yan Vugenfirer , Anthony Liguori , Dmitry Fleytman , Paolo Bonzini Subject: [Qemu-devel] [PATCH V12 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; +}