diff mbox series

[API-NEXT,v3,3/3] linux-gen: ipsec: use new odp checksum API

Message ID 1511190013-8520-4-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v3,1/3] example: switch to using ODP chksum API | expand

Commit Message

Github ODP bot Nov. 20, 2017, 3 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Use odp_chksum_ones_comp16 which may be platform-optimized.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 280 (lumag:chksum)
 ** https://github.com/Linaro/odp/pull/280
 ** Patch: https://github.com/Linaro/odp/pull/280.patch
 ** Base sha: d4b364849c4abb4c71e0c5260e1a793ebb8dc97d
 ** Merge commit sha: 9fda6f107cef0c4074880995a90b30cbeac27ce8
 **/
 platform/linux-generic/odp_ipsec.c | 31 ++-----------------------------
 1 file changed, 2 insertions(+), 29 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/odp_ipsec.c b/platform/linux-generic/odp_ipsec.c
index 0ebc65341..32aae1719 100644
--- a/platform/linux-generic/odp_ipsec.c
+++ b/platform/linux-generic/odp_ipsec.c
@@ -7,6 +7,7 @@ 
 #include "config.h"
 
 #include <odp/api/ipsec.h>
+#include <odp/api/chksum.h>
 
 #include <odp/api/plat/packet_inlines.h>
 
@@ -103,34 +104,6 @@  static odp_ipsec_packet_result_t *ipsec_pkt_result(odp_packet_t packet)
 	return &odp_packet_hdr(packet)->ipsec_ctx;
 }
 
-/**
- * Checksum
- *
- * @param buffer calculate chksum for buffer
- * @param len    buffer length
- *
- * @return checksum value in network order
- */
-static inline
-odp_u16sum_t _odp_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;
-}
-
 static inline int _odp_ipv4_csum(odp_packet_t pkt,
 				 uint32_t offset,
 				 _odp_ipv4hdr_t *ip,
@@ -150,7 +123,7 @@  static inline int _odp_ipv4_csum(odp_packet_t pkt,
 	if (odp_unlikely(res < 0))
 		return res;
 
-	*chksum = _odp_chksum(buf, nleft);
+	*chksum = ~odp_chksum_ones_comp16(buf, nleft);
 
 	return 0;
 }