From patchwork Wed Feb 1 13:14:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 93026 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2410963qgi; Wed, 1 Feb 2017 05:18:01 -0800 (PST) X-Received: by 10.200.48.172 with SMTP id v41mr2458614qta.54.1485955081801; Wed, 01 Feb 2017 05:18:01 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c185si14388712qkd.294.2017.02.01.05.18.01; Wed, 01 Feb 2017 05:18:01 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 76FC162D30; Wed, 1 Feb 2017 13:18:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 3CA2D62D57; Wed, 1 Feb 2017 13:14:44 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E908C62D00; Wed, 1 Feb 2017 13:14:21 +0000 (UTC) Received: from mail-qt0-f175.google.com (mail-qt0-f175.google.com [209.85.216.175]) by lists.linaro.org (Postfix) with ESMTPS id 9018862CE1 for ; Wed, 1 Feb 2017 13:14:20 +0000 (UTC) Received: by mail-qt0-f175.google.com with SMTP id k15so264019091qtg.3 for ; Wed, 01 Feb 2017 05:14:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+BI4aFq+HSrRqkLUv4N5sBgF+PhW0s5BMZNvZ8Wafxo=; b=jcLo2zVhBlxtkSCqGmtL+mwvgPjlISQYmY/zadTmrWYmUIAi1OewAWPdXXG4UN+bY+ kIfI9qxfvdPW1TIrD0W3d4YmMUMziTigaqlxGHVDEe0l5nZQACbNXXT5QJWPu6WJfC1W CfTQSFO+G0IY1qCTDCivNcPphLBUTSA6lHq6tlVtHx1SdziOcjSdnXpA6lSPonrc5R0t Of2VENlBcpwZDCgT0361etap8ZBGUalFN4kOKrf80QdlnTKynimZWOvp55DPl8T9i+6Y EJvhW0UyFPz0waTFA2L4WeYo8D1/bTmXmV9GgWy934Vm38SwCMBmIxBiyOtfnV/ww5mZ SfGg== X-Gm-Message-State: AIkVDXIHZTvls96viXsYglYCVbwntegZcAlt+lAHh9ae4dLWNbZxxwniMhGUUI62qTZhM5r3hy8= X-Received: by 10.237.41.229 with SMTP id o92mr2409350qtd.223.1485954859892; Wed, 01 Feb 2017 05:14:19 -0800 (PST) Received: from localhost (c-98-221-136-245.hsd1.nj.comcast.net. [98.221.136.245]) by smtp.gmail.com with ESMTPSA id b190sm18557590qkg.32.2017.02.01.05.14.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Feb 2017 05:14:18 -0800 (PST) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Wed, 1 Feb 2017 08:14:08 -0500 Message-Id: <20170201131409.26631-5-mike.holmes@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170201131409.26631-1-mike.holmes@linaro.org> References: <20170201131409.26631-1-mike.holmes@linaro.org> Subject: [lng-odp] [PATCH 4/5] helper: use ABI mode for chksum X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Mike Holmes --- 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 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 #include +#if ODP_ABI_COMPAT == 1 +#include +#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 +#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 +#include + +_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