diff mbox series

[3/5] helper: use ABI mode for ip

Message ID 20170201131409.26631-4-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/include/odp/helper/ip.h         | 48 +++++--------------------
 helper/include/odp/helper/ip_inlines.h | 65 ++++++++++++++++++++++++++++++++++
 helper/ip.c                            |  4 +++
 4 files changed, 79 insertions(+), 39 deletions(-)
 create mode 100644 helper/include/odp/helper/ip_inlines.h

-- 
2.9.3

Comments

Bill Fischofer Feb. 2, 2017, 4:03 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/include/odp/helper/ip.h         | 48 +++++--------------------

>  helper/include/odp/helper/ip_inlines.h | 65 ++++++++++++++++++++++++++++++++++

>  helper/ip.c                            |  4 +++

>  4 files changed, 79 insertions(+), 39 deletions(-)

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

>

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

> index 69531d6..140f2f4 100644

> --- a/helper/Makefile.am

> +++ b/helper/Makefile.am

> @@ -19,6 +19,7 @@ helperinclude_HEADERS = \

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

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

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

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

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

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

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

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

> index 08af794..0afb184 100644

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

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

> @@ -17,47 +17,24 @@

>  extern "C" {

>  #endif

>

> -#include <odp_api.h>

>  #include <odp/helper/ip_types.h>

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

>

> -#include <string.h>

> -

>  /** @addtogroup odph_header ODPH HEADER

>   *  @{

>   */

>

>  /**

> + * @fn odph_ipv4_csum_valid(odp_packet_t pkt)

>   * Check if IPv4 checksum is valid

>   *

>   * @param pkt  ODP packet

>   *

>   * @return 1 if checksum is valid, otherwise 0

>   */

> -static inline int odph_ipv4_csum_valid(odp_packet_t pkt)

> -{

> -       uint32_t offset;

> -       odp_u16be_t res = 0;

> -       uint16_t *w;

> -       int nleft = sizeof(odph_ipv4hdr_t);

> -       odph_ipv4hdr_t ip;

> -       odp_u16be_t chksum;

>

> -       offset = odp_packet_l3_offset(pkt);

> -       if (offset == ODP_PACKET_OFFSET_INVALID)

> -               return 0;

> -

> -       odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip);

> -

> -       w = (uint16_t *)(void *)&ip;

> -       chksum = ip.chksum;

> -       ip.chksum = 0x0;

> -

> -       res = odph_chksum(w, nleft);

> -       return (res == chksum) ? 1 : 0;

> -}

> -

> -/**

> + /**

> + * @fn odph_ipv4_csum_update(odp_packet_t pkt)

>   * Calculate and fill in IPv4 checksum

>   *

>   * @note when using this api to populate data destined for the wire

> @@ -67,20 +44,13 @@ static inline int odph_ipv4_csum_valid(odp_packet_t pkt)

>   *

>   * @return IPv4 checksum in host cpu order, or 0 on failure

>   */

> -static inline odp_u16sum_t odph_ipv4_csum_update(odp_packet_t pkt)

> -{

> -       uint16_t *w;

> -       odph_ipv4hdr_t *ip;

> -       int nleft = sizeof(odph_ipv4hdr_t);

>

> -       ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);

> -       if (ip == NULL)

> -               return 0;

> -

> -       w = (uint16_t *)(void *)ip;

> -       ip->chksum = odph_chksum(w, nleft);

> -       return ip->chksum;

> -}

> +#if ODP_HELPER_ABI_COMPAT == 0

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

> +#else

> +int odph_ipv4_csum_valid(odp_packet_t pkt);

> +odp_u16sum_t odph_ipv4_csum_update(odp_packet_t pkt);

> +#endif

>

>  /**

>   * Parse IPv4 address from a string

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

> new file mode 100644

> index 0000000..b72d18c

> --- /dev/null

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

> @@ -0,0 +1,65 @@

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

> + * All rights reserved.

> + *

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

> + */

> +

> +/**

> + * @file

> + *

> + * ODP IP inline header

> + */

> +

> +#ifndef ODPH_IP_INLINES_H_

> +#define ODPH_IP_INLINES_H_

> +

> +#ifdef __cplusplus

> +extern "C" {

> +#endif

> +

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

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

> +

> +_HELPER_STATIC int odph_ipv4_csum_valid(odp_packet_t pkt)

> +{

> +       uint32_t offset;

> +       odp_u16be_t res = 0;

> +       uint16_t *w;

> +       int nleft = sizeof(odph_ipv4hdr_t);

> +       odph_ipv4hdr_t ip;

> +       odp_u16be_t chksum;

> +

> +       offset = odp_packet_l3_offset(pkt);

> +       if (offset == ODP_PACKET_OFFSET_INVALID)

> +               return 0;

> +

> +       odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip);

> +

> +       w = (uint16_t *)(void *)&ip;

> +       chksum = ip.chksum;

> +       ip.chksum = 0x0;

> +

> +       res = odph_chksum(w, nleft);

> +       return (res == chksum) ? 1 : 0;

> +}

> +

> +_HELPER_STATIC odp_u16sum_t odph_ipv4_csum_update(odp_packet_t pkt)

> +{

> +       uint16_t *w;

> +       odph_ipv4hdr_t *ip;

> +       int nleft = sizeof(odph_ipv4hdr_t);

> +

> +       ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);

> +       if (ip == NULL)

> +               return 0;

> +

> +       w = (uint16_t *)(void *)ip;

> +       ip->chksum = odph_chksum(w, nleft);

> +       return ip->chksum;

> +}

> +

> +#ifdef __cplusplus

> +}

> +#endif

> +

> +#endif

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

> index eb73e5a..77dc42c 100644

> --- a/helper/ip.c

> +++ b/helper/ip.c

> @@ -9,6 +9,10 @@

>  #include <stdio.h>

>  #include <string.h>

>

> +#if ODP_ABI_COMPAT == 1


Another case of using ODP_ABI_COMPAT, which suggests that _STATIC
rather than _HELPER_STATIC should be used for consistency.

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

> +#endif

> +

>  int odph_ipv4_addr_parse(uint32_t *ip_addr, const char *str)

>  {

>         unsigned byte[ODPH_IPV4ADDR_LEN];

> --

> 2.9.3

>
diff mbox series

Patch

diff --git a/helper/Makefile.am b/helper/Makefile.am
index 69531d6..140f2f4 100644
--- a/helper/Makefile.am
+++ b/helper/Makefile.am
@@ -19,6 +19,7 @@  helperinclude_HEADERS = \
 		  $(srcdir)/include/odp/helper/eth.h\
 		  $(srcdir)/include/odp/helper/icmp.h\
 		  $(srcdir)/include/odp/helper/ip.h\
+		  $(srcdir)/include/odp/helper/ip_inlines.h\
 		  $(srcdir)/include/odp/helper/ip_types.h\
 		  $(srcdir)/include/odp/helper/ipsec.h\
 		  $(srcdir)/include/odp/helper/odph_api.h\
diff --git a/helper/include/odp/helper/ip.h b/helper/include/odp/helper/ip.h
index 08af794..0afb184 100644
--- a/helper/include/odp/helper/ip.h
+++ b/helper/include/odp/helper/ip.h
@@ -17,47 +17,24 @@ 
 extern "C" {
 #endif
 
-#include <odp_api.h>
 #include <odp/helper/ip_types.h>
 #include <odp/helper/chksum.h>
 
-#include <string.h>
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
 
 /**
+ * @fn odph_ipv4_csum_valid(odp_packet_t pkt)
  * Check if IPv4 checksum is valid
  *
  * @param pkt  ODP packet
  *
  * @return 1 if checksum is valid, otherwise 0
  */
-static inline int odph_ipv4_csum_valid(odp_packet_t pkt)
-{
-	uint32_t offset;
-	odp_u16be_t res = 0;
-	uint16_t *w;
-	int nleft = sizeof(odph_ipv4hdr_t);
-	odph_ipv4hdr_t ip;
-	odp_u16be_t chksum;
 
-	offset = odp_packet_l3_offset(pkt);
-	if (offset == ODP_PACKET_OFFSET_INVALID)
-		return 0;
-
-	odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip);
-
-	w = (uint16_t *)(void *)&ip;
-	chksum = ip.chksum;
-	ip.chksum = 0x0;
-
-	res = odph_chksum(w, nleft);
-	return (res == chksum) ? 1 : 0;
-}
-
-/**
+ /**
+ * @fn odph_ipv4_csum_update(odp_packet_t pkt)
  * Calculate and fill in IPv4 checksum
  *
  * @note when using this api to populate data destined for the wire
@@ -67,20 +44,13 @@  static inline int odph_ipv4_csum_valid(odp_packet_t pkt)
  *
  * @return IPv4 checksum in host cpu order, or 0 on failure
  */
-static inline odp_u16sum_t odph_ipv4_csum_update(odp_packet_t pkt)
-{
-	uint16_t *w;
-	odph_ipv4hdr_t *ip;
-	int nleft = sizeof(odph_ipv4hdr_t);
 
-	ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
-	if (ip == NULL)
-		return 0;
-
-	w = (uint16_t *)(void *)ip;
-	ip->chksum = odph_chksum(w, nleft);
-	return ip->chksum;
-}
+#if ODP_HELPER_ABI_COMPAT == 0
+#include <odp/helper/ip_inlines.h>
+#else
+int odph_ipv4_csum_valid(odp_packet_t pkt);
+odp_u16sum_t odph_ipv4_csum_update(odp_packet_t pkt);
+#endif
 
 /**
  * Parse IPv4 address from a string
diff --git a/helper/include/odp/helper/ip_inlines.h b/helper/include/odp/helper/ip_inlines.h
new file mode 100644
index 0000000..b72d18c
--- /dev/null
+++ b/helper/include/odp/helper/ip_inlines.h
@@ -0,0 +1,65 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP IP inline header
+ */
+
+#ifndef ODPH_IP_INLINES_H_
+#define ODPH_IP_INLINES_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <odp/helper/static_inline.h>
+#include <odp/helper/chksum.h>
+
+_HELPER_STATIC int odph_ipv4_csum_valid(odp_packet_t pkt)
+{
+	uint32_t offset;
+	odp_u16be_t res = 0;
+	uint16_t *w;
+	int nleft = sizeof(odph_ipv4hdr_t);
+	odph_ipv4hdr_t ip;
+	odp_u16be_t chksum;
+
+	offset = odp_packet_l3_offset(pkt);
+	if (offset == ODP_PACKET_OFFSET_INVALID)
+		return 0;
+
+	odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip);
+
+	w = (uint16_t *)(void *)&ip;
+	chksum = ip.chksum;
+	ip.chksum = 0x0;
+
+	res = odph_chksum(w, nleft);
+	return (res == chksum) ? 1 : 0;
+}
+
+_HELPER_STATIC odp_u16sum_t odph_ipv4_csum_update(odp_packet_t pkt)
+{
+	uint16_t *w;
+	odph_ipv4hdr_t *ip;
+	int nleft = sizeof(odph_ipv4hdr_t);
+
+	ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
+	if (ip == NULL)
+		return 0;
+
+	w = (uint16_t *)(void *)ip;
+	ip->chksum = odph_chksum(w, nleft);
+	return ip->chksum;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/helper/ip.c b/helper/ip.c
index eb73e5a..77dc42c 100644
--- a/helper/ip.c
+++ b/helper/ip.c
@@ -9,6 +9,10 @@ 
 #include <stdio.h>
 #include <string.h>
 
+#if ODP_ABI_COMPAT == 1
+#include <odp/helper/ip_inlines.h>
+#endif
+
 int odph_ipv4_addr_parse(uint32_t *ip_addr, const char *str)
 {
 	unsigned byte[ODPH_IPV4ADDR_LEN];