From patchwork Thu Jul 17 16:08:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 33790 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 27FA820CA0 for ; Thu, 17 Jul 2014 16:09:10 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id y10sf16799604pdj.8 for ; Thu, 17 Jul 2014 09:09:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=KU8Vlb+XXdh39qbE1JS+YJrRkmypie+tUAx9jmFCTCk=; b=Da5K6A8RJmz8KWasG9uNVUzwhRmgMZ16uyWmZ43SuWK7yRhL/56f6B9JruETqQATb7 q16Dq04F9NVRBxKn//KQjyI9dCwygDdIa3VdR/mzai/2OJXt5s4FCvBzk+ZswG+1upB1 dBUp2kI4z1nODDgbLs8HLVyxUH59rRDPW/b47z+/tywLmXHtHGvyZtMEFQ9DW9JWlb++ WaBMwrnT8tdDwv0wjjsdS0+McdU0s9y59lRGUS0YYCt9fOAj9XVDvt9iYUEFJzEmHcQ7 kml//tsOJ2T0SWx/ZQo2phIOtDc6VI208F8D3oGwog2ooBAF/Q5eAGykG5ICKmtwSap7 oNJg== X-Gm-Message-State: ALoCoQmodFxqrngGpwTBwkC7MXgZ04qVm3ELXnhmnh6ZRM9izWPHG+9SjUNzIKJ1jvkKYWNIMuc3 X-Received: by 10.70.140.138 with SMTP id rg10mr18586266pdb.1.1405613349370; Thu, 17 Jul 2014 09:09:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.24.74 with SMTP id 68ls743399qgq.98.gmail; Thu, 17 Jul 2014 09:09:09 -0700 (PDT) X-Received: by 10.52.246.101 with SMTP id xv5mr16307153vdc.73.1405613349265; Thu, 17 Jul 2014 09:09:09 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id cz8si3058279vcb.88.2014.07.17.09.09.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Jul 2014 09:09:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id hu12so4887591vcb.20 for ; Thu, 17 Jul 2014 09:09:01 -0700 (PDT) X-Received: by 10.220.15.8 with SMTP id i8mr19544951vca.45.1405613340994; Thu, 17 Jul 2014 09:09:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp48786vcb; Thu, 17 Jul 2014 09:09:00 -0700 (PDT) X-Received: by 10.140.19.176 with SMTP id 45mr57999899qgh.46.1405613340505; Thu, 17 Jul 2014 09:09:00 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id e5si5720852qaf.27.2014.07.17.09.08.58 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 17 Jul 2014 09:09:00 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1X7oCU-0008K8-Gj; Thu, 17 Jul 2014 16:06:30 +0000 Received: from mail-qg0-f47.google.com ([209.85.192.47]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1X7oCP-0008Jt-16 for lng-odp@lists.linaro.org; Thu, 17 Jul 2014 16:06:25 +0000 Received: by mail-qg0-f47.google.com with SMTP id i50so2203234qgf.34 for ; Thu, 17 Jul 2014 09:08:47 -0700 (PDT) X-Received: by 10.140.98.195 with SMTP id o61mr55746490qge.41.1405613327629; Thu, 17 Jul 2014 09:08:47 -0700 (PDT) Received: from fedora1.holmesfamily.ws (c-98-221-136-245.hsd1.nj.comcast.net. [98.221.136.245]) by mx.google.com with ESMTPSA id w9sm5117165qag.48.2014.07.17.09.08.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Jul 2014 09:08:47 -0700 (PDT) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Thu, 17 Jul 2014 12:08:36 -0400 Message-Id: <1405613316-14656-1-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCH] Introduce sum type to solve sparse warnings X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mike.holmes@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Mike Holmes --- ODP follows the linux kernel with the use of sparse and BE data type checking. This patch introduces the sum type which is used by Linux but was not part of ODP see: http://lxr.free-electrons.com/source/include/uapi/linux/icmp.h#L71 This patch allows SPARSE to pass cleanly and the odp_generator test case also passes. Note 1 The bitwise attribute forbids arithmetic so the checksum code uses regular types and forces the result in the return from the function. Note 2 The timer ping code is an application that uses a different structure definition that does not have the bitwise attribute and so this application is left issuing a sparse warning and is a separate issue. --- include/helper/odp_chksum.h | 9 +++------ include/helper/odp_icmp.h | 2 +- include/helper/odp_ip.h | 10 ++++------ include/helper/odp_udp.h | 4 ++-- include/odp_byteorder.h | 3 ++- test/generator/odp_generator.c | 4 ++-- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/helper/odp_chksum.h b/include/helper/odp_chksum.h index 37078b6..710711a 100644 --- a/include/helper/odp_chksum.h +++ b/include/helper/odp_chksum.h @@ -22,18 +22,15 @@ 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 in host cpu order */ -static inline uint16_t odp_chksum(void *buffer, int len) +static inline uint16sum_t odp_chksum(void *buffer, int len) { uint16_t *buf = buffer; - unsigned int sum = 0; + uint32_t sum = 0; uint16_t result; for (sum = 0; len > 1; len -= 2) @@ -46,7 +43,7 @@ static inline uint16_t odp_chksum(void *buffer, int len) sum += (sum >> 16); result = ~sum; - return result; + return (__odp_force uint16sum_t) result; } #ifdef __cplusplus diff --git a/include/helper/odp_icmp.h b/include/helper/odp_icmp.h index f34b68e..ab8c409 100644 --- a/include/helper/odp_icmp.h +++ b/include/helper/odp_icmp.h @@ -29,7 +29,7 @@ extern "C" { typedef struct ODP_PACKED { uint8_t type; /**< message type */ uint8_t code; /**< type sub-code */ - uint16be_t chksum; /**< checksum of icmp header */ + uint16sum_t chksum; /**< checksum of icmp header */ union { struct { uint16be_t id; diff --git a/include/helper/odp_ip.h b/include/helper/odp_ip.h index d8366bb..6f4e028 100644 --- a/include/helper/odp_ip.h +++ b/include/helper/odp_ip.h @@ -56,7 +56,7 @@ typedef struct ODP_PACKED { uint16be_t frag_offset; /**< Fragmentation offset */ uint8_t ttl; /**< Time to live */ uint8_t proto; /**< Protocol */ - uint16be_t chksum; /**< Checksum */ + uint16sum_t chksum; /**< Checksum */ uint32be_t src_addr; /**< Source address */ uint32be_t dst_addr; /**< Destination address */ } odp_ipv4hdr_t; @@ -101,9 +101,8 @@ static inline int odp_ipv4_csum_valid(odp_packet_t pkt) * * @return IPv4 checksum in host cpu order, or 0 on failure */ -static inline uint16_t odp_ipv4_csum_update(odp_packet_t pkt) +static inline uint16sum_t odp_ipv4_csum_update(odp_packet_t pkt) { - uint16_t res = 0; uint16_t *w; odp_ipv4hdr_t *ip; int nleft = sizeof(odp_ipv4hdr_t); @@ -113,9 +112,8 @@ static inline uint16_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 = odp_cpu_to_be_16(res); - return res; + ip->chksum = odp_chksum(w, nleft); + return ip->chksum; } /** IPv6 version */ diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h index ae31f6b..0ad1541 100644 --- a/include/helper/odp_udp.h +++ b/include/helper/odp_udp.h @@ -79,9 +79,9 @@ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) phdr.length = udph->length; /* calc UDP pseudo header chksum */ - sum = odp_chksum(&phdr, sizeof(odp_udpphdr_t)); + sum = (__odp_force uint32_t) odp_chksum(&phdr, sizeof(odp_udpphdr_t)); /* calc udp header and data chksum */ - sum += odp_chksum(udph, udplen); + sum += (__odp_force uint32_t) odp_chksum(udph, udplen); /* Fold sum to 16 bits: add carrier to result */ while (sum >> 16) diff --git a/include/odp_byteorder.h b/include/odp_byteorder.h index 80f6081..e0f7a17 100644 --- a/include/odp_byteorder.h +++ b/include/odp_byteorder.h @@ -71,7 +71,8 @@ typedef uint32_t __odp_bitwise uint32be_t; /**< unsigned 32bit big endian */ typedef uint64_t __odp_bitwise uint64le_t; /**< unsigned 64bit little endian */ typedef uint64_t __odp_bitwise uint64be_t; /**< unsigned 64bit big endian */ - +typedef uint16_t __odp_bitwise uint16sum_t; /**< unsigned 16bit bitwise */ +typedef uint32_t __odp_bitwise uint32sum_t; /**< unsigned 32bit bitwise */ /* * Big Endian -> CPU byte order: */ diff --git a/test/generator/odp_generator.c b/test/generator/odp_generator.c index 8f6ad49..e4a72fa 100644 --- a/test/generator/odp_generator.c +++ b/test/generator/odp_generator.c @@ -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_cpu_to_be_16(odp_chksum(icmp, args->appl.payload + - ODP_ICMPHDR_LEN)); + icmp->chksum = 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);