From: Dmitry Eremin-Solenikov <dmitry.ereminsoleni...@linaro.org>

Separate main checksumming code, it will be used for packet checksum
validation.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsoleni...@linaro.org>
---
/** Email created from pull request 389 (lumag:parse-checksums)
 ** https://github.com/Linaro/odp/pull/389
 ** Patch: https://github.com/Linaro/odp/pull/389.patch
 ** Base sha: 49ebafae0edebbc750742d8874ad0a7588286dea
 ** Merge commit sha: ab214b82da2a920444a5e65d029f3f42a98ec314
 **/
 platform/linux-generic/Makefile.am                 |  1 +
 .../linux-generic/include/odp_chksum_internal.h    | 59 ++++++++++++++++++++++
 platform/linux-generic/odp_chksum.c                | 18 ++-----
 3 files changed, 63 insertions(+), 15 deletions(-)
 create mode 100644 platform/linux-generic/include/odp_chksum_internal.h

diff --git a/platform/linux-generic/Makefile.am 
b/platform/linux-generic/Makefile.am
index 7e40448bd..9c7563fb1 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -134,6 +134,7 @@ noinst_HEADERS = \
                  include/odp_bitmap_internal.h \
                  include/odp_bitset.h \
                  include/odp_buffer_internal.h \
+                 include/odp_chksum_internal.h \
                  include/odp_classification_datamodel.h \
                  include/odp_classification_inlines.h \
                  include/odp_classification_internal.h \
diff --git a/platform/linux-generic/include/odp_chksum_internal.h 
b/platform/linux-generic/include/odp_chksum_internal.h
new file mode 100644
index 000000000..779598bbf
--- /dev/null
+++ b/platform/linux-generic/include/odp_chksum_internal.h
@@ -0,0 +1,59 @@
+/* Copyright (c) 2013, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP checksum - implementation internal
+ */
+
+#ifndef ODP_CHKSUM_INTERNAL_H_
+#define ODP_CHKSUM_INTERNAL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Simple implementation of ones complement sum.
+ * Based on RFC1071 and its errata.
+ */
+static uint32_t _odp_chksum_ones_comp16_32(const void *p, uint32_t len,
+                                          odp_bool_t odd_offset)
+
+{
+       uint32_t sum = 0;
+       const uint16_t *data = p;
+
+       if (odd_offset) {
+               uint16_t left_over = 0;
+
+               *(uint8_t *)&left_over = *(const uint8_t *)data;
+               sum = left_over;
+               data++;
+               len--;
+       }
+
+       while (len > 1) {
+               sum += *data++;
+               len -= 2;
+       }
+
+       /* Add left-over byte, if any */
+       if (len > 0) {
+               uint16_t left_over = 0;
+
+               *(uint8_t *)&left_over = *(const uint8_t *)data;
+               sum += left_over;
+       }
+
+       return sum;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/platform/linux-generic/odp_chksum.c 
b/platform/linux-generic/odp_chksum.c
index a792971ef..484b2b0ae 100644
--- a/platform/linux-generic/odp_chksum.c
+++ b/platform/linux-generic/odp_chksum.c
@@ -7,26 +7,14 @@
 #include <odp/api/chksum.h>
 #include <odp/api/std_types.h>
 
+#include <odp_chksum_internal.h>
+
 /* Simple implementation of ones complement sum.
  * Based on RFC1071 and its errata.
  */
 uint16_t odp_chksum_ones_comp16(const void *p, uint32_t len)
 {
-       uint32_t sum = 0;
-       const uint16_t *data = p;
-
-       while (len > 1) {
-               sum += *data++;
-               len -= 2;
-       }
-
-       /* Add left-over byte, if any */
-       if (len > 0) {
-               uint16_t left_over = 0;
-
-               *(uint8_t *)&left_over = *(const uint8_t *)data;
-               sum += left_over;
-       }
+       uint32_t sum = _odp_chksum_ones_comp16_32(p, len, false);
 
        /* Fold 32-bit sum to 16 bits */
        while (sum >> 16)

Reply via email to