From patchwork Fri May 8 14:02:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Badicioiu X-Patchwork-Id: 48169 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5B0FA2121F for ; Fri, 8 May 2015 14:03:13 +0000 (UTC) Received: by wghm4 with SMTP id m4sf22041847wgh.2 for ; Fri, 08 May 2015 07:03:12 -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:delivered-to:mime-version :in-reply-to:references:date:message-id:from:to:subject:precedence :list-id:list-unsubscribe:list-archive:list-post:list-help :list-subscribe:content-type:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=6MBhU2iS7emE2fbAXLvP4j6xA/ZJKitNxpYf0R23fKA=; b=H/3QVzo+i/eN7Fzyd2IGEqfpK/m4rOFRrTU1ufqp4PWw7vIempCOIXdbYjMJklxAQv ZogfObggJNG4Xv96A1zV0VgNZdhCWsrcZB/qQleEse+s3hngioGlS9j1txY8Sed8BLkS br28vrwsrXA3CKBURDC//iDUo9eL3sGMM4UW0YL4S1TIuzWb07CRvMNpjDPrzRRLSObT 7LhqHrGUSZkRICtthZXxyih8jk0yDOK9OFqyH7AK1fq7hPodmjrlajKacLqKl580NdDO rIGJ4dwMm/N3LuP0O52ocHlH7DDRllo0s+3v/3uf7yHwFzxjOc2CaMxZSSE2p8za5mh2 mEPA== X-Gm-Message-State: ALoCoQngjvFo/QN6WAHobDq/ZVK8lSkOHsj8jptuv5ff1xlnaQMVVeFekiG+G1RbCdpW8unQHrwq X-Received: by 10.180.160.197 with SMTP id xm5mr743543wib.1.1431093792680; Fri, 08 May 2015 07:03:12 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.100 with SMTP id j4ls357565lah.92.gmail; Fri, 08 May 2015 07:03:12 -0700 (PDT) X-Received: by 10.112.120.199 with SMTP id le7mr3022604lbb.48.1431093792509; Fri, 08 May 2015 07:03:12 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id aw7si3369528lbc.80.2015.05.08.07.03.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 May 2015 07:03:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbqq2 with SMTP id qq2so53857557lbb.3 for ; Fri, 08 May 2015 07:03:12 -0700 (PDT) X-Received: by 10.112.204.6 with SMTP id ku6mr2980220lbc.73.1431093792420; Fri, 08 May 2015 07:03:12 -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.112.108.230 with SMTP id hn6csp42360lbb; Fri, 8 May 2015 07:03:11 -0700 (PDT) X-Received: by 10.55.23.16 with SMTP id i16mr8500106qkh.14.1431093786799; Fri, 08 May 2015 07:03:06 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 81si5362380qgx.77.2015.05.08.07.03.06; Fri, 08 May 2015 07:03:06 -0700 (PDT) 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; Received: by lists.linaro.org (Postfix, from userid 109) id 1382161F3F; Fri, 8 May 2015 14:03:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 9E7CE61D9A; Fri, 8 May 2015 14:02:59 +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 38BB061D9E; Fri, 8 May 2015 14:02:58 +0000 (UTC) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com [209.85.217.170]) by lists.linaro.org (Postfix) with ESMTPS id E70A261D9A for ; Fri, 8 May 2015 14:02:56 +0000 (UTC) Received: by lbbzk7 with SMTP id zk7so53924287lbb.0 for ; Fri, 08 May 2015 07:02:55 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.169.42 with SMTP id ab10mr3031053lbc.3.1431093775799; Fri, 08 May 2015 07:02:55 -0700 (PDT) Received: by 10.152.129.105 with HTTP; Fri, 8 May 2015 07:02:55 -0700 (PDT) In-Reply-To: <1430827646-15525-1-git-send-email-alexandru.badicioiu@linaro.org> References: <1430827646-15525-1-git-send-email-alexandru.badicioiu@linaro.org> Date: Fri, 8 May 2015 17:02:55 +0300 Message-ID: From: Alexandru Badicioiu To: LNG ODP Mailman List X-Topics: patch Subject: [lng-odp] Fwd: [PATCH 1/1 v1] helpers: fix udp checksum computation X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alexandru.badicioiu@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.217.178 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 Ping. ---------- Forwarded message ---------- From: Date: 5 May 2015 at 15:07 Subject: [lng-odp][PATCH 1/1 v1] helpers: fix udp checksum computation To: lng-odp@lists.linaro.org Cc: Alexandru Badicioiu From: Alexandru Badicioiu v1 - fixed compile error due to -Wcast-align Signed-off-by: Alexandru Badicioiu --- helper/include/odp/helper/udp.h | 37 +++++++++++++------------------------ 1 files changed, 13 insertions(+), 24 deletions(-) * @@ -53,10 +44,10 @@ typedef struct ODPH_PACKET { static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt) { uint32_t sum = 0; - odph_udpphdr_t phdr; odph_udphdr_t *udph; odph_ipv4hdr_t *iph; uint16_t udplen; + uint8_t *buf; if (!odp_packet_l3_offset(pkt)) return 0; @@ -68,24 +59,22 @@ static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt) udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL); udplen = odp_be_to_cpu_16(udph->length); - /* the source ip */ - phdr.src_addr = iph->src_addr; - /* the dest ip */ - phdr.dst_addr = iph->dst_addr; - /* proto */ - phdr.pad = 0; - phdr.proto = ODPH_IPPROTO_UDP; - /* the length */ - phdr.length = udph->length; - - /* calc UDP pseudo header chksum */ - sum = (__odp_force uint32_t) odp_chksum(&phdr, sizeof(odph_udpphdr_t)); - /* calc udp header and data chksum */ - sum += (__odp_force uint32_t) odp_chksum(udph, udplen); + /* 32-bit sum of all 16-bit words covered by UDP chksum */ + sum = (iph->src_addr & 0xFFFF) + (iph->src_addr >> 16) + + (iph->dst_addr & 0xFFFF) + (iph->dst_addr >> 16) + + (uint16_t) iph->proto + udplen; + for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) { + sum += ((*buf << 8) + *(buf + 1)); + buf += 2; + } /* Fold sum to 16 bits: add carrier to result */ while (sum >> 16) sum = (sum & 0xFFFF) + (sum >> 16); + + /* 1's complement */ + sum = ~sum; + /* set computation result */ sum = (sum == 0x0) ? 0xFFFF : sum; -- 1.7.3.4 diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h index 99a96f2..d14cbef 100644 --- a/helper/include/odp/helper/udp.h +++ b/helper/include/odp/helper/udp.h @@ -33,15 +33,6 @@ typedef struct ODP_PACKED { uint16be_t chksum; /**< UDP header and data checksum (0 if not used)*/ } odph_udphdr_t; -/** UDP pseudo header */ -typedef struct ODPH_PACKET { - uint32be_t src_addr; /**< Source addr */ - uint32be_t dst_addr; /**< Destination addr */ - uint8_t pad; /**< pad byte */ - uint8_t proto; /**< UDP protocol */ - uint16be_t length; /**< data length */ -} odph_udpphdr_t; - /** * UDP checksum