diff mbox

[1/3] Fix uint16be_t sparse checksum errors

Message ID 1403733620-8426-1-git-send-email-mike.holmes@linaro.org
State Accepted
Commit acdbb05449d8d6f80caf39d035e6a6c7a5e2dabb
Headers show

Commit Message

Mike Holmes June 25, 2014, 10 p.m. UTC
Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 include/helper/odp_chksum.h    |  5 ++++-
 include/helper/odp_ip.h        | 11 +++++++----
 include/helper/odp_udp.h       |  2 +-
 test/generator/odp_generator.c |  6 +++---
 4 files changed, 15 insertions(+), 9 deletions(-)

Comments

Maxim Uvarov June 26, 2014, 6:01 p.m. UTC | #1
Applied, thanks!

Maxim.

On 06/26/2014 02:00 AM, Mike Holmes wrote:
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> ---
>   include/helper/odp_chksum.h    |  5 ++++-
>   include/helper/odp_ip.h        | 11 +++++++----
>   include/helper/odp_udp.h       |  2 +-
>   test/generator/odp_generator.c |  6 +++---
>   4 files changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/include/helper/odp_chksum.h b/include/helper/odp_chksum.h
> index 12ef61f..37078b6 100644
> --- a/include/helper/odp_chksum.h
> +++ b/include/helper/odp_chksum.h
> @@ -22,10 +22,13 @@ extern "C" {
>   /**
>    * Checksum
>    *
> + * @note when using this api to populate data destined for the wire
> + * odp_cpu_to_be_16() can be used to remove sparse warnings
> + *
>    * @param buffer calculate chksum for buffer
>    * @param len    buffer length
>    *
> - * @return checksum value
> + * @return checksum value in host cpu order
>    */
>   static inline uint16_t odp_chksum(void *buffer, int len)
>   {
> diff --git a/include/helper/odp_ip.h b/include/helper/odp_ip.h
> index a364049..d8366bb 100644
> --- a/include/helper/odp_ip.h
> +++ b/include/helper/odp_ip.h
> @@ -94,13 +94,16 @@ static inline int odp_ipv4_csum_valid(odp_packet_t pkt)
>   /**
>    * Calculate and fill in IPv4 checksum
>    *
> + * @note when using this api to populate data destined for the wire
> + * odp_cpu_to_be_16() can be used to remove sparse warnings
> + *
>    * @param pkt  ODP packet
>    *
> - * @return IPv4 checksum, or 0 on failure
> + * @return IPv4 checksum in host cpu order, or 0 on failure
>    */
> -static inline uint16be_t odp_ipv4_csum_update(odp_packet_t pkt)
> +static inline uint16_t odp_ipv4_csum_update(odp_packet_t pkt)
>   {
> -	uint16be_t res = 0;
> +	uint16_t res = 0;
>   	uint16_t *w;
>   	odp_ipv4hdr_t *ip;
>   	int nleft = sizeof(odp_ipv4hdr_t);
> @@ -111,7 +114,7 @@ static inline uint16be_t odp_ipv4_csum_update(odp_packet_t pkt)
>   	ip = (odp_ipv4hdr_t *)odp_packet_l3(pkt);
>   	w = (uint16_t *)(void *)ip;
>   	res = odp_chksum(w, nleft);
> -	ip->chksum = res;
> +	ip->chksum = odp_cpu_to_be_16(res);
>   	return res;
>   }
>   
> diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h
> index 5aedb36..ae31f6b 100644
> --- a/include/helper/odp_udp.h
> +++ b/include/helper/odp_udp.h
> @@ -89,7 +89,7 @@ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt)
>   	/* set computation result */
>   	sum = (sum == 0x0) ? 0xFFFF : sum;
>   
> -	return (uint16_t)sum;
> +	return sum;
>   }
>   
>   /** @internal Compile time assert */
> diff --git a/test/generator/odp_generator.c b/test/generator/odp_generator.c
> index ca84e4c..68c119e 100644
> --- a/test/generator/odp_generator.c
> +++ b/test/generator/odp_generator.c
> @@ -212,7 +212,7 @@ static void pack_udp_pkt(odp_buffer_t obuf)
>   	udp->dst_port = 0;
>   	udp->length = odp_cpu_to_be_16(args->appl.payload + ODP_UDPHDR_LEN);
>   	udp->chksum = 0;
> -	udp->chksum = odp_ipv4_udp_chksum(pkt);
> +	udp->chksum = odp_cpu_to_be_16(odp_ipv4_udp_chksum(pkt));
>   	odp_packet_set_len(pkt, args->appl.payload + ODP_UDPHDR_LEN +
>   			   ODP_IPV4HDR_LEN + ODP_ETHHDR_LEN);
>   }
> @@ -275,8 +275,8 @@ static void pack_icmp_pkt(odp_buffer_t obuf)
>   	gettimeofday(&tval, NULL);
>   	memcpy(tval_d, &tval, sizeof(struct timeval));
>   	icmp->chksum = 0;
> -	icmp->chksum = odp_chksum(icmp, args->appl.payload +
> -				  ODP_ICMPHDR_LEN);
> +	icmp->chksum = odp_cpu_to_be_16(odp_chksum(icmp, args->appl.payload +
> +				  ODP_ICMPHDR_LEN));
>   
>   	odp_packet_set_len(pkt, args->appl.payload + ODP_ICMPHDR_LEN +
>   			   ODP_IPV4HDR_LEN + ODP_ETHHDR_LEN);
diff mbox

Patch

diff --git a/include/helper/odp_chksum.h b/include/helper/odp_chksum.h
index 12ef61f..37078b6 100644
--- a/include/helper/odp_chksum.h
+++ b/include/helper/odp_chksum.h
@@ -22,10 +22,13 @@  extern "C" {
 /**
  * Checksum
  *
+ * @note when using this api to populate data destined for the wire
+ * odp_cpu_to_be_16() can be used to remove sparse warnings
+ *
  * @param buffer calculate chksum for buffer
  * @param len    buffer length
  *
- * @return checksum value
+ * @return checksum value in host cpu order
  */
 static inline uint16_t odp_chksum(void *buffer, int len)
 {
diff --git a/include/helper/odp_ip.h b/include/helper/odp_ip.h
index a364049..d8366bb 100644
--- a/include/helper/odp_ip.h
+++ b/include/helper/odp_ip.h
@@ -94,13 +94,16 @@  static inline int odp_ipv4_csum_valid(odp_packet_t pkt)
 /**
  * Calculate and fill in IPv4 checksum
  *
+ * @note when using this api to populate data destined for the wire
+ * odp_cpu_to_be_16() can be used to remove sparse warnings
+ *
  * @param pkt  ODP packet
  *
- * @return IPv4 checksum, or 0 on failure
+ * @return IPv4 checksum in host cpu order, or 0 on failure
  */
-static inline uint16be_t odp_ipv4_csum_update(odp_packet_t pkt)
+static inline uint16_t odp_ipv4_csum_update(odp_packet_t pkt)
 {
-	uint16be_t res = 0;
+	uint16_t res = 0;
 	uint16_t *w;
 	odp_ipv4hdr_t *ip;
 	int nleft = sizeof(odp_ipv4hdr_t);
@@ -111,7 +114,7 @@  static inline uint16be_t odp_ipv4_csum_update(odp_packet_t pkt)
 	ip = (odp_ipv4hdr_t *)odp_packet_l3(pkt);
 	w = (uint16_t *)(void *)ip;
 	res = odp_chksum(w, nleft);
-	ip->chksum = res;
+	ip->chksum = odp_cpu_to_be_16(res);
 	return res;
 }
 
diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h
index 5aedb36..ae31f6b 100644
--- a/include/helper/odp_udp.h
+++ b/include/helper/odp_udp.h
@@ -89,7 +89,7 @@  static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt)
 	/* set computation result */
 	sum = (sum == 0x0) ? 0xFFFF : sum;
 
-	return (uint16_t)sum;
+	return sum;
 }
 
 /** @internal Compile time assert */
diff --git a/test/generator/odp_generator.c b/test/generator/odp_generator.c
index ca84e4c..68c119e 100644
--- a/test/generator/odp_generator.c
+++ b/test/generator/odp_generator.c
@@ -212,7 +212,7 @@  static void pack_udp_pkt(odp_buffer_t obuf)
 	udp->dst_port = 0;
 	udp->length = odp_cpu_to_be_16(args->appl.payload + ODP_UDPHDR_LEN);
 	udp->chksum = 0;
-	udp->chksum = odp_ipv4_udp_chksum(pkt);
+	udp->chksum = odp_cpu_to_be_16(odp_ipv4_udp_chksum(pkt));
 	odp_packet_set_len(pkt, args->appl.payload + ODP_UDPHDR_LEN +
 			   ODP_IPV4HDR_LEN + ODP_ETHHDR_LEN);
 }
@@ -275,8 +275,8 @@  static void pack_icmp_pkt(odp_buffer_t obuf)
 	gettimeofday(&tval, NULL);
 	memcpy(tval_d, &tval, sizeof(struct timeval));
 	icmp->chksum = 0;
-	icmp->chksum = odp_chksum(icmp, args->appl.payload +
-				  ODP_ICMPHDR_LEN);
+	icmp->chksum = odp_cpu_to_be_16(odp_chksum(icmp, args->appl.payload +
+				  ODP_ICMPHDR_LEN));
 
 	odp_packet_set_len(pkt, args->appl.payload + ODP_ICMPHDR_LEN +
 			   ODP_IPV4HDR_LEN + ODP_ETHHDR_LEN);