From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Dmitry Fleytman <dmitry@daynix.com>,
Yan Vugenfirer <yan@daynix.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 3/7] net: iovec checksum calculator
Date: Mon, 25 Mar 2013 13:26:09 +0100 [thread overview]
Message-ID: <1364214373-2444-4-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1364214373-2444-1-git-send-email-stefanha@redhat.com>
From: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Yan Vugenfirer <yan@daynix.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
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 <http://www.gnu.org/licenses/>.
*/
+#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;
+}
--
1.8.1.4
next prev parent reply other threads:[~2013-03-25 12:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-25 12:26 [Qemu-devel] [PULL 0/7] Net patches Stefan Hajnoczi
2013-03-25 12:26 ` [Qemu-devel] [PATCH 1/7] net: use socket_set_nodelay() for -netdev socket Stefan Hajnoczi
2013-03-25 12:26 ` [Qemu-devel] [PATCH 2/7] Checksum-related utility functions Stefan Hajnoczi
2013-03-25 12:26 ` Stefan Hajnoczi [this message]
2013-03-25 12:26 ` [Qemu-devel] [PATCH 4/7] Common definitions for VMWARE devices Stefan Hajnoczi
2013-03-25 12:26 ` [Qemu-devel] [PATCH 5/7] Packet abstraction for VMWARE network devices Stefan Hajnoczi
2013-03-25 12:26 ` [Qemu-devel] [PATCH 6/7] VMXNET3 device implementation Stefan Hajnoczi
2013-03-25 12:26 ` [Qemu-devel] [PATCH 7/7] net: increase buffer size to accommodate Jumbo frame pkts Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364214373-2444-4-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=dmitry@daynix.com \
--cc=qemu-devel@nongnu.org \
--cc=yan@daynix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).