diff mbox series

[4/5] helper: use ABI mode for chksum

Message ID 20170201131409.26631-5-mike.holmes@linaro.org
State New
Headers show
Series Add ABI compatibility to helper lib | expand

Commit Message

Mike Holmes Feb. 1, 2017, 1:14 p.m. UTC
Signed-off-by: Mike Holmes <mike.holmes@linaro.org>

---
 helper/Makefile.am                         |  1 +
 helper/chksum.c                            |  4 ++
 helper/include/odp/helper/chksum.h         | 59 ++++++-----------------
 helper/include/odp/helper/chksum_inlines.h | 77 ++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 45 deletions(-)
 create mode 100644 helper/include/odp/helper/chksum_inlines.h

-- 
2.9.3

Comments

Bill Fischofer Feb. 2, 2017, 4:01 a.m. UTC | #1
On Wed, Feb 1, 2017 at 7:14 AM, Mike Holmes <mike.holmes@linaro.org> wrote:
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>

> ---

>  helper/Makefile.am                         |  1 +

>  helper/chksum.c                            |  4 ++

>  helper/include/odp/helper/chksum.h         | 59 ++++++-----------------

>  helper/include/odp/helper/chksum_inlines.h | 77 ++++++++++++++++++++++++++++++

>  4 files changed, 96 insertions(+), 45 deletions(-)

>  create mode 100644 helper/include/odp/helper/chksum_inlines.h

>

> diff --git a/helper/Makefile.am b/helper/Makefile.am

> index 140f2f4..6820532 100644

> --- a/helper/Makefile.am

> +++ b/helper/Makefile.am

> @@ -15,6 +15,7 @@ AM_LDFLAGS += -version-number '$(ODPHELPER_LIBSO_VERSION)'

>  helperincludedir = $(includedir)/odp/helper/

>  helperinclude_HEADERS = \

>                   $(srcdir)/include/odp/helper/chksum.h\

> +                 $(srcdir)/include/odp/helper/chksum_inlines.h\

>                   $(srcdir)/include/odp/helper/chksum_types.h\

>                   $(srcdir)/include/odp/helper/eth.h\

>                   $(srcdir)/include/odp/helper/icmp.h\

> diff --git a/helper/chksum.c b/helper/chksum.c

> index f740618..c809bc0 100644

> --- a/helper/chksum.c

> +++ b/helper/chksum.c

> @@ -12,6 +12,10 @@

>  #include <stddef.h>

>  #include <stdbool.h>

>

> +#if ODP_ABI_COMPAT == 1

> +#include <odp/helper/chksum_inlines.h>

> +#endif


I agree that using ODP_ABI_COMPAT here makes sense, but this seems to
contradict having defined ODP_HELPER_ABI_COMPAT in Part 1.

> +

>  /* The following union type is used to "view" an ordered set of bytes (either

>   * 2 or 4) as 1 or 2 16-bit quantities - using host endian order. */

>  typedef union {

> diff --git a/helper/include/odp/helper/chksum.h b/helper/include/odp/helper/chksum.h

> index 94c9305..ddca0e1 100644

> --- a/helper/include/odp/helper/chksum.h

> +++ b/helper/include/odp/helper/chksum.h

> @@ -24,6 +24,7 @@ extern "C" {

>   */

>

>  /**

> + * @fn odph_chksum(void *buffer, int len)

>   * Checksum

>   *

>   * @param buffer calculate chksum for buffer

> @@ -31,24 +32,6 @@ extern "C" {

>   *

>   * @return checksum value in host cpu order

>   */

> -static inline odp_u16sum_t odph_chksum(void *buffer, int len)

> -{

> -       uint16_t *buf = (uint16_t *)buffer;

> -       uint32_t sum = 0;

> -       uint16_t result;

> -

> -       for (sum = 0; len > 1; len -= 2)

> -               sum += *buf++;

> -

> -       if (len == 1)

> -               sum += *(unsigned char *)buf;

> -

> -       sum = (sum >> 16) + (sum & 0xFFFF);

> -       sum += (sum >> 16);

> -       result = ~sum;

> -

> -       return  (__odp_force odp_u16sum_t) result;

> -}

>

>  /**

>   * General Purpose TCP/UDP checksum function

> @@ -94,6 +77,7 @@ int odph_udp_tcp_chksum(odp_packet_t     odp_pkt,

>                         uint16_t        *chksum_ptr);

>

>  /**

> + * @fn odph_tcp_chksum_set(odp_packet_t odp_pkt)

>   * Generate TCP checksum

>   *

>   * This function supports TCP over either IPv4 or IPV6 - including handling

> @@ -112,15 +96,9 @@ int odph_udp_tcp_chksum(odp_packet_t     odp_pkt,

>   *                     be over IPv4 or IPv6.

>   * @return             0 upon success and < 0 upon failure.

>   */

> -static inline int odph_tcp_chksum_set(odp_packet_t odp_pkt)

> -{

> -       if (!odp_packet_has_tcp(odp_pkt))

> -               return -1;

> -

> -       return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_GENERATE, NULL);

> -}

>

>  /**

> + * @fn odph_udp_chksum_set(odp_packet_t odp_pkt)

>   * Generate UDP checksum

>   *

>   * This function supports UDP over either IPv4 or IPV6 - including handling

> @@ -139,15 +117,9 @@ static inline int odph_tcp_chksum_set(odp_packet_t odp_pkt)

>   *                     be over IPv4 or IPv6.

>   * @return             0 upon success and < 0 upon failure.

>   */

> -static inline int odph_udp_chksum_set(odp_packet_t odp_pkt)

> -{

> -       if (!odp_packet_has_udp(odp_pkt))

> -               return -1;

> -

> -       return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_GENERATE, NULL);

> -}

>

>  /**

> + * @fn odph_tcp_chksum_verify(odp_packet_t odp_pkt)

>   * Verify TCP checksum

>   *

>   * This function supports TCP over either IPv4 or IPV6 - including handling

> @@ -167,15 +139,9 @@ static inline int odph_udp_chksum_set(odp_packet_t odp_pkt)

>   *                     the incoming chksum field is correct, else returns 2

>   *                     when the chksum field is incorrect or 0.

>   */

> -static inline int odph_tcp_chksum_verify(odp_packet_t odp_pkt)

> -{

> -       if (!odp_packet_has_tcp(odp_pkt))

> -               return -1;

> -

> -       return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_VERIFY, NULL);

> -}

>

>  /**

> + * @fn odph_udp_chksum_verify(odp_packet_t odp_pkt)

>   * Verify UDP checksum

>   *

>   * This function supports UDP over either IPv4 or IPV6 - including handling

> @@ -197,13 +163,16 @@ static inline int odph_tcp_chksum_verify(odp_packet_t odp_pkt)

>   *                     if the incoming chksum field is correct, else returns 2

>   *                     when the chksum field is incorrect.

>   */

> -static inline int odph_udp_chksum_verify(odp_packet_t odp_pkt)

> -{

> -       if (!odp_packet_has_udp(odp_pkt))

> -               return -1;

>

> -       return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_VERIFY, NULL);

> -}

> +#if ODP_HELPER_ABI_COMPAT == 0


Above uses ODP_ABI_COMPAT, here it's ODP_HELPER_ABI_COMPAT. The former
seems sufficient.

> +#include <odp/helper/chksum_inlines.h>

> +#else

> +odp_u16sum_t odph_chksum(void *buffer, int len);

> +int odph_tcp_chksum_set(odp_packet_t odp_pkt);

> +int odph_udp_chksum_set(odp_packet_t odp_pkt);

> +int odph_tcp_chksum_verify(odp_packet_t odp_pkt);

> +int odph_udp_chksum_verify(odp_packet_t odp_pkt);

> +#endif

>

>  /**

>   * @}

> diff --git a/helper/include/odp/helper/chksum_inlines.h b/helper/include/odp/helper/chksum_inlines.h

> new file mode 100644

> index 0000000..c022061

> --- /dev/null

> +++ b/helper/include/odp/helper/chksum_inlines.h

> @@ -0,0 +1,77 @@

> +/* Copyright (c) 2017, Linaro Limited

> + * All rights reserved.

> + *

> + * SPDX-License-Identifier:     BSD-3-Clause

> + */

> +

> +/**

> + * @file

> + *

> + * ODP checksum inlne helper

> + */

> +#ifndef ODPH_CHKSUM_INLINE_H_

> +#define ODPH_CHKSUM_INLINE_H_

> +

> +#ifdef __cplusplus

> +extern "C" {

> +#endif

> +

> +#include <odp/helper/static_inline.h>

> +#include <odp/helper/chksum.h>

> +

> +_HELPER_STATIC odp_u16sum_t odph_chksum(void *buffer, int len)


If we're going to use ODP_ABI_COMPAT then _STATIC would seem
sufficient here rather than needing a separate _HELPER_STATIC macro
that does the same thing.

> +{

> +       uint16_t *buf = (uint16_t *)buffer;

> +       uint32_t sum = 0;

> +       uint16_t result;

> +

> +       for (sum = 0; len > 1; len -= 2)

> +               sum += *buf++;

> +

> +       if (len == 1)

> +               sum += *(unsigned char *)buf;

> +

> +       sum = (sum >> 16) + (sum & 0xFFFF);

> +       sum += (sum >> 16);

> +       result = ~sum;

> +

> +       return  (__odp_force odp_u16sum_t) result;

> +}

> +

> +_HELPER_STATIC int odph_tcp_chksum_set(odp_packet_t odp_pkt)

> +{

> +       if (!odp_packet_has_tcp(odp_pkt))

> +               return -1;

> +

> +       return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_GENERATE, NULL);

> +}

> +

> +_HELPER_STATIC int odph_udp_chksum_set(odp_packet_t odp_pkt)

> +{

> +       if (!odp_packet_has_udp(odp_pkt))

> +               return -1;

> +

> +       return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_GENERATE, NULL);

> +}

> +

> +_HELPER_STATIC int odph_tcp_chksum_verify(odp_packet_t odp_pkt)

> +{

> +       if (!odp_packet_has_tcp(odp_pkt))

> +               return -1;

> +

> +       return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_VERIFY, NULL);

> +}

> +

> +_HELPER_STATIC int odph_udp_chksum_verify(odp_packet_t odp_pkt)

> +{

> +       if (!odp_packet_has_udp(odp_pkt))

> +               return -1;

> +

> +       return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_VERIFY, NULL);

> +}

> +

> +#ifdef __cplusplus

> +}

> +#endif

> +

> +#endif

> --

> 2.9.3

>
diff mbox series

Patch

diff --git a/helper/Makefile.am b/helper/Makefile.am
index 140f2f4..6820532 100644
--- a/helper/Makefile.am
+++ b/helper/Makefile.am
@@ -15,6 +15,7 @@  AM_LDFLAGS += -version-number '$(ODPHELPER_LIBSO_VERSION)'
 helperincludedir = $(includedir)/odp/helper/
 helperinclude_HEADERS = \
 		  $(srcdir)/include/odp/helper/chksum.h\
+		  $(srcdir)/include/odp/helper/chksum_inlines.h\
 		  $(srcdir)/include/odp/helper/chksum_types.h\
 		  $(srcdir)/include/odp/helper/eth.h\
 		  $(srcdir)/include/odp/helper/icmp.h\
diff --git a/helper/chksum.c b/helper/chksum.c
index f740618..c809bc0 100644
--- a/helper/chksum.c
+++ b/helper/chksum.c
@@ -12,6 +12,10 @@ 
 #include <stddef.h>
 #include <stdbool.h>
 
+#if ODP_ABI_COMPAT == 1
+#include <odp/helper/chksum_inlines.h>
+#endif
+
 /* The following union type is used to "view" an ordered set of bytes (either
  * 2 or 4) as 1 or 2 16-bit quantities - using host endian order. */
 typedef union {
diff --git a/helper/include/odp/helper/chksum.h b/helper/include/odp/helper/chksum.h
index 94c9305..ddca0e1 100644
--- a/helper/include/odp/helper/chksum.h
+++ b/helper/include/odp/helper/chksum.h
@@ -24,6 +24,7 @@  extern "C" {
  */
 
 /**
+ * @fn odph_chksum(void *buffer, int len)
  * Checksum
  *
  * @param buffer calculate chksum for buffer
@@ -31,24 +32,6 @@  extern "C" {
  *
  * @return checksum value in host cpu order
  */
-static inline odp_u16sum_t odph_chksum(void *buffer, int len)
-{
-	uint16_t *buf = (uint16_t *)buffer;
-	uint32_t sum = 0;
-	uint16_t result;
-
-	for (sum = 0; len > 1; len -= 2)
-		sum += *buf++;
-
-	if (len == 1)
-		sum += *(unsigned char *)buf;
-
-	sum = (sum >> 16) + (sum & 0xFFFF);
-	sum += (sum >> 16);
-	result = ~sum;
-
-	return  (__odp_force odp_u16sum_t) result;
-}
 
 /**
  * General Purpose TCP/UDP checksum function
@@ -94,6 +77,7 @@  int odph_udp_tcp_chksum(odp_packet_t     odp_pkt,
 			uint16_t        *chksum_ptr);
 
 /**
+ * @fn odph_tcp_chksum_set(odp_packet_t odp_pkt)
  * Generate TCP checksum
  *
  * This function supports TCP over either IPv4 or IPV6 - including handling
@@ -112,15 +96,9 @@  int odph_udp_tcp_chksum(odp_packet_t     odp_pkt,
  *                     be over IPv4 or IPv6.
  * @return             0 upon success and < 0 upon failure.
  */
-static inline int odph_tcp_chksum_set(odp_packet_t odp_pkt)
-{
-	if (!odp_packet_has_tcp(odp_pkt))
-		return -1;
-
-	return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_GENERATE, NULL);
-}
 
 /**
+ * @fn odph_udp_chksum_set(odp_packet_t odp_pkt)
  * Generate UDP checksum
  *
  * This function supports UDP over either IPv4 or IPV6 - including handling
@@ -139,15 +117,9 @@  static inline int odph_tcp_chksum_set(odp_packet_t odp_pkt)
  *                     be over IPv4 or IPv6.
  * @return             0 upon success and < 0 upon failure.
  */
-static inline int odph_udp_chksum_set(odp_packet_t odp_pkt)
-{
-	if (!odp_packet_has_udp(odp_pkt))
-		return -1;
-
-	return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_GENERATE, NULL);
-}
 
 /**
+ * @fn odph_tcp_chksum_verify(odp_packet_t odp_pkt)
  * Verify TCP checksum
  *
  * This function supports TCP over either IPv4 or IPV6 - including handling
@@ -167,15 +139,9 @@  static inline int odph_udp_chksum_set(odp_packet_t odp_pkt)
  *                     the incoming chksum field is correct, else returns 2
  *                     when the chksum field is incorrect or 0.
  */
-static inline int odph_tcp_chksum_verify(odp_packet_t odp_pkt)
-{
-	if (!odp_packet_has_tcp(odp_pkt))
-		return -1;
-
-	return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_VERIFY, NULL);
-}
 
 /**
+ * @fn odph_udp_chksum_verify(odp_packet_t odp_pkt)
  * Verify UDP checksum
  *
  * This function supports UDP over either IPv4 or IPV6 - including handling
@@ -197,13 +163,16 @@  static inline int odph_tcp_chksum_verify(odp_packet_t odp_pkt)
  *                     if the incoming chksum field is correct, else returns 2
  *                     when the chksum field is incorrect.
  */
-static inline int odph_udp_chksum_verify(odp_packet_t odp_pkt)
-{
-	if (!odp_packet_has_udp(odp_pkt))
-		return -1;
 
-	return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_VERIFY, NULL);
-}
+#if ODP_HELPER_ABI_COMPAT == 0
+#include <odp/helper/chksum_inlines.h>
+#else
+odp_u16sum_t odph_chksum(void *buffer, int len);
+int odph_tcp_chksum_set(odp_packet_t odp_pkt);
+int odph_udp_chksum_set(odp_packet_t odp_pkt);
+int odph_tcp_chksum_verify(odp_packet_t odp_pkt);
+int odph_udp_chksum_verify(odp_packet_t odp_pkt);
+#endif
 
 /**
  * @}
diff --git a/helper/include/odp/helper/chksum_inlines.h b/helper/include/odp/helper/chksum_inlines.h
new file mode 100644
index 0000000..c022061
--- /dev/null
+++ b/helper/include/odp/helper/chksum_inlines.h
@@ -0,0 +1,77 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP checksum inlne helper
+ */
+#ifndef ODPH_CHKSUM_INLINE_H_
+#define ODPH_CHKSUM_INLINE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <odp/helper/static_inline.h>
+#include <odp/helper/chksum.h>
+
+_HELPER_STATIC odp_u16sum_t odph_chksum(void *buffer, int len)
+{
+	uint16_t *buf = (uint16_t *)buffer;
+	uint32_t sum = 0;
+	uint16_t result;
+
+	for (sum = 0; len > 1; len -= 2)
+		sum += *buf++;
+
+	if (len == 1)
+		sum += *(unsigned char *)buf;
+
+	sum = (sum >> 16) + (sum & 0xFFFF);
+	sum += (sum >> 16);
+	result = ~sum;
+
+	return  (__odp_force odp_u16sum_t) result;
+}
+
+_HELPER_STATIC int odph_tcp_chksum_set(odp_packet_t odp_pkt)
+{
+	if (!odp_packet_has_tcp(odp_pkt))
+		return -1;
+
+	return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_GENERATE, NULL);
+}
+
+_HELPER_STATIC int odph_udp_chksum_set(odp_packet_t odp_pkt)
+{
+	if (!odp_packet_has_udp(odp_pkt))
+		return -1;
+
+	return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_GENERATE, NULL);
+}
+
+_HELPER_STATIC int odph_tcp_chksum_verify(odp_packet_t odp_pkt)
+{
+	if (!odp_packet_has_tcp(odp_pkt))
+		return -1;
+
+	return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_VERIFY, NULL);
+}
+
+_HELPER_STATIC int odph_udp_chksum_verify(odp_packet_t odp_pkt)
+{
+	if (!odp_packet_has_udp(odp_pkt))
+		return -1;
+
+	return odph_udp_tcp_chksum(odp_pkt, ODPH_CHKSUM_VERIFY, NULL);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif