diff mbox series

[API-NEXT,v3,1/3] api: chksum: add ones complement sum function

Message ID 1506560407-16273-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v3,1/3] api: chksum: add ones complement sum function | expand

Commit Message

Github ODP bot Sept. 28, 2017, 1 a.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


This is a low level function for IP/UDP/TCP checksum calculations
on SW. HW cannot always calculate checksums, for that or other
reasons application may need calculate ones compelement sums.

This kind of low level function is easy to optimize e.g. with CPU
vector instructions. In addition to this, there may be higher
(packet) level functions introduced later.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 193 (psavol:next-ip-checksum)
 ** https://github.com/Linaro/odp/pull/193
 ** Patch: https://github.com/Linaro/odp/pull/193.patch
 ** Base sha: e04e5f90df69e3031622b77fb5273b85d47eb966
 ** Merge commit sha: 35da9ad1d0193b6fbd07e2de97d9569279e68cf8
 **/
 include/odp/api/spec/chksum.h                   | 53 +++++++++++++++++++++++++
 include/odp_api.h                               |  1 +
 platform/Makefile.inc                           |  1 +
 platform/linux-generic/Makefile.am              |  1 +
 platform/linux-generic/include/odp/api/chksum.h | 34 ++++++++++++++++
 5 files changed, 90 insertions(+)
 create mode 100644 include/odp/api/spec/chksum.h
 create mode 100644 platform/linux-generic/include/odp/api/chksum.h
diff mbox series

Patch

diff --git a/include/odp/api/spec/chksum.h b/include/odp/api/spec/chksum.h
new file mode 100644
index 000000000..e523ac286
--- /dev/null
+++ b/include/odp/api/spec/chksum.h
@@ -0,0 +1,53 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:	BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP Hash functions
+ */
+
+#ifndef ODP_API_CHKSUM_H_
+#define ODP_API_CHKSUM_H_
+#include <odp/visibility_begin.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <odp/api/std_types.h>
+
+/** @defgroup odp_chksum ODP CHECKSUM
+ *  ODP checksum functions
+ *  @{
+ */
+
+/**
+ * Ones' complement sum of 16-bit words
+ *
+ * Calculates 16-bit ones' complement sum over the data. In case of odd number
+ * of bytes, calculation uses a zero byte as padding at the end. This algorithm
+ * may be used as part of e.g. IPv4/UDP/TCP checksum generation and checking.
+ *
+ * @param data       Pointer to data. Data address must be 16-bit aligned
+ *                   in minimum.
+ * @param data_len   Data length in bytes. In case of an odd number, calculation
+ *                   includes one byte of padding.
+ *
+ * @return Ones' complement sum
+ */
+uint16_t odp_chksum_ones_comp16(const void *data, uint32_t data_len);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#include <odp/visibility_end.h>
+#endif
diff --git a/include/odp_api.h b/include/odp_api.h
index 86232ee10..069ec9d1e 100644
--- a/include/odp_api.h
+++ b/include/odp_api.h
@@ -24,6 +24,7 @@  extern "C" {
 #include <odp/api/compiler.h>
 #include <odp/api/align.h>
 #include <odp/api/hash.h>
+#include <odp/api/chksum.h>
 #include <odp/api/hints.h>
 #include <odp/api/debug.h>
 #include <odp/api/byteorder.h>
diff --git a/platform/Makefile.inc b/platform/Makefile.inc
index ac5cd765d..2699142db 100644
--- a/platform/Makefile.inc
+++ b/platform/Makefile.inc
@@ -22,6 +22,7 @@  odpapispecinclude_HEADERS = \
 		  $(top_srcdir)/include/odp/api/spec/barrier.h \
 		  $(top_srcdir)/include/odp/api/spec/buffer.h \
 		  $(top_srcdir)/include/odp/api/spec/byteorder.h \
+		  $(top_srcdir)/include/odp/api/spec/chksum.h \
 		  $(top_srcdir)/include/odp/api/spec/classification.h \
 		  $(top_srcdir)/include/odp/api/spec/compiler.h \
 		  $(top_srcdir)/include/odp/api/spec/cpu.h \
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index 3e26aab4c..994bbbeee 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -36,6 +36,7 @@  odpapiinclude_HEADERS = \
 		  $(srcdir)/include/odp/api/byteorder.h \
 		  $(srcdir)/include/odp/api/classification.h \
 		  $(srcdir)/include/odp/api/compiler.h \
+		  $(srcdir)/include/odp/api/chksum.h \
 		  $(srcdir)/include/odp/api/cpu.h \
 		  $(srcdir)/include/odp/api/cpumask.h \
 		  $(srcdir)/include/odp/api/crypto.h \
diff --git a/platform/linux-generic/include/odp/api/chksum.h b/platform/linux-generic/include/odp/api/chksum.h
new file mode 100644
index 000000000..18dcb6d11
--- /dev/null
+++ b/platform/linux-generic/include/odp/api/chksum.h
@@ -0,0 +1,34 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP checksum functions
+ */
+
+#ifndef ODP_PLAT_CHKSUM_H_
+#define ODP_PLAT_CHKSUM_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @ingroup odp_chksum
+ *  @{
+ */
+
+/**
+ * @}
+ */
+
+#include <odp/api/spec/chksum.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif