From patchwork Thu Jul 17 21:46:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 33812 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 40BF920CA0 for ; Thu, 17 Jul 2014 21:47:19 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rp18sf26888840iec.8 for ; Thu, 17 Jul 2014 14:47:18 -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=NPFuAAc0fbVSVsQE9aH8HS7QPmXa/o42us3rLAuCCWE=; b=T7WhLLegerDdHoTSytRlUtc0oma8Nl+J9+co6z13bGAruOKUZm/kZ0K5Wzl77ZpRk7 jk7zoQod7NQc4zJ4m2R9DWLdkVXJE8mN9iI2E9u9bVapoCO5LTna7msfyPjtZxnN9pYj qBlqtryN6/JEkUjc8c/hTmbtoPWjdbcKQn1JL/7oMrbtAxJme7jq/WJV/bhaRF/1Ia0W e07fCY2cfcnTE3LfLe5EHn0U7uvU36IZu64DugMnJc22NusrHOuLoCasippk8yxhlllM lowDbCBqe1zE9jldv45mWDgixvhXzU1f08bzI1LskwqSXCS16OwD237vRiYul3pd2M4z laUA== X-Gm-Message-State: ALoCoQlS12mNHyBNiSx5M7nyegg7EdDxLVpFiKPcLPPAGFcitu86FcrlZOvHxmGlRiaXunOSyJAQ X-Received: by 10.42.123.148 with SMTP id s20mr586097icr.8.1405633638746; Thu, 17 Jul 2014 14:47:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.233 with SMTP id j96ls6065qgd.80.gmail; Thu, 17 Jul 2014 14:47:18 -0700 (PDT) X-Received: by 10.236.223.36 with SMTP id u34mr61907yhp.79.1405633638631; Thu, 17 Jul 2014 14:47:18 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id j28si9744060yha.171.2014.07.17.14.47.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Jul 2014 14:47:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id id10so1219820vcb.35 for ; Thu, 17 Jul 2014 14:47:18 -0700 (PDT) X-Received: by 10.52.248.146 with SMTP id ym18mr312389vdc.8.1405633638423; Thu, 17 Jul 2014 14:47:18 -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 tc5csp69408vcb; Thu, 17 Jul 2014 14:47:18 -0700 (PDT) X-Received: by 10.140.16.67 with SMTP id 61mr401455qga.28.1405633637842; Thu, 17 Jul 2014 14:47:17 -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 o5si6115783qck.6.2014.07.17.14.47.17 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 17 Jul 2014 14:47:17 -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 1X7tTs-0008FN-LQ; Thu, 17 Jul 2014 21:44:48 +0000 Received: from mail-qg0-f51.google.com ([209.85.192.51]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1X7tTm-0008Dn-Vb for lng-odp@lists.linaro.org; Thu, 17 Jul 2014 21:44:42 +0000 Received: by mail-qg0-f51.google.com with SMTP id a108so2511303qge.24 for ; Thu, 17 Jul 2014 14:47:06 -0700 (PDT) X-Received: by 10.224.34.73 with SMTP id k9mr183251qad.11.1405633625956; Thu, 17 Jul 2014 14:47:05 -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 r4sm6475498qah.39.2014.07.17.14.47.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Jul 2014 14:47:05 -0700 (PDT) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Thu, 17 Jul 2014 17:46:53 -0400 Message-Id: <1405633613-48330-1-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCHv2] 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.176 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 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. Signed-off-by: Mike Holmes --- 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);