From patchwork Tue May 5 12:07:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Badicioiu X-Patchwork-Id: 48027 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6028F20553 for ; Tue, 5 May 2015 12:07:48 +0000 (UTC) Received: by wgin8 with SMTP id n8sf52141501wgi.0 for ; Tue, 05 May 2015 05:07:47 -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:from:to:date :message-id:mime-version:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=v6poD6Iez6zWvGBY9VPCfXnQ2zd2Cez2LT8RydzlqtQ=; b=mtzDUXPYIfPg9vO88C3/IDLBcLSdG1YF+jFVTSgJkzqVFIInB6I8BjlooLJImX/1Au fbVNDAHCsgq5PEsY6ugg7LS5XElAUXprVNbvF1eh7DgrznvWrfbb+EzDZCuyYNbioCZ/ qw21ukIz376TgbSK0laIYJrhm+48VoUBdwQh3/us52LlEfMs5P2s3YwhWWZzwKANsbcU o6caVquZ/SRagrWG7olEXmP7C7H9EOfHmWaVHMp66LuimfE+iVRId0ypuH3nRlZDHHBV upU372L/SJ0NCODibtVxIdHppl71x2UvucUXD96ukhl4SaEKZC4cb5Q0L0w5sCfYYQAa hLLA== X-Gm-Message-State: ALoCoQnmP9UW0x/Qy18EtU0eNdn5H9G3SZIoYkrlU8HLQSpa9aLfd33Ss0kkehYlhmw3p2lY99/O X-Received: by 10.112.53.102 with SMTP id a6mr21964540lbp.16.1430827667659; Tue, 05 May 2015 05:07:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.37 with SMTP id w5ls817514laa.77.gmail; Tue, 05 May 2015 05:07:47 -0700 (PDT) X-Received: by 10.152.3.130 with SMTP id c2mr23781553lac.81.1430827667510; Tue, 05 May 2015 05:07:47 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id e10si12315173lae.15.2015.05.05.05.07.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 May 2015 05:07:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by laat2 with SMTP id t2so125592664laa.1 for ; Tue, 05 May 2015 05:07:47 -0700 (PDT) X-Received: by 10.112.150.100 with SMTP id uh4mr23211799lbb.112.1430827667359; Tue, 05 May 2015 05:07:47 -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.67.65 with SMTP id l1csp2203486lbt; Tue, 5 May 2015 05:07:46 -0700 (PDT) X-Received: by 10.140.20.99 with SMTP id 90mr32210417qgi.87.1430827665993; Tue, 05 May 2015 05:07:45 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l92si15891879qgf.83.2015.05.05.05.07.45; Tue, 05 May 2015 05:07:45 -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 52B9F61D51; Tue, 5 May 2015 12:07:45 +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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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 0147061810; Tue, 5 May 2015 12:07:41 +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 547CA61816; Tue, 5 May 2015 12:07:34 +0000 (UTC) Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0071.outbound.protection.outlook.com [65.55.169.71]) by lists.linaro.org (Postfix) with ESMTPS id 3A76B61810 for ; Tue, 5 May 2015 12:07:33 +0000 (UTC) Received: from BL2PR03MB617.namprd03.prod.outlook.com (10.255.109.42) by BL2PR03MB275.namprd03.prod.outlook.com (10.255.231.22) with Microsoft SMTP Server (TLS) id 15.1.160.10; Tue, 5 May 2015 12:07:32 +0000 Received: from BLUPR0301CA0035.namprd03.prod.outlook.com (25.162.113.173) by BL2PR03MB617.namprd03.prod.outlook.com (10.255.109.42) with Microsoft SMTP Server (TLS) id 15.1.154.19; Tue, 5 May 2015 12:07:31 +0000 Received: from BY2FFO11OLC005.protection.gbl (2a01:111:f400:7c0c::159) by BLUPR0301CA0035.outlook.office365.com (2a01:111:e400:5259::45) with Microsoft SMTP Server (TLS) id 15.1.130.23 via Frontend Transport; Tue, 5 May 2015 12:07:31 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning linaro.org discourages use of 192.88.158.2 as permitted sender) Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11OLC005.mail.protection.outlook.com (10.1.14.145) with Microsoft SMTP Server (TLS) id 15.1.160.8 via Frontend Transport; Tue, 5 May 2015 12:07:30 +0000 Received: from fsr-fed1364-15.ea.freescale.net (fsr-fed1364-15.ea.freescale.net [10.171.81.144]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t45C7Srv004758; Tue, 5 May 2015 05:07:29 -0700 From: To: Date: Tue, 5 May 2015 15:07:26 +0300 Message-ID: <1430827646-15525-1-git-send-email-alexandru.badicioiu@linaro.org> X-Mailer: git-send-email 1.7.3.4 X-EOPAttributedMessage: 0 X-Matching-Connectors: 130753012509187926; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(19580405001)(19580395003)(50226001)(46102003)(36756003)(87936001)(2351001)(229853001)(47776003)(106466001)(86152002)(50986999)(33646002)(50466002)(86362001)(48376002)(104016003)(77096005)(105596002)(110136002)(5001960100002)(6806004)(62966003)(92566002)(5001920100001)(77156002); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR03MB617; H:az84smr01.freescale.net; FPR:; SPF:SoftFail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:BL2PR03MB617; UriScan:; BCL:0; PCL:0; RULEID:; SRVR:BL2PR03MB275; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:BL2PR03MB617; BCL:0; PCL:0; RULEID:(400006); SRVR:BL2PR03MB617; X-Forefront-PRVS: 0567A15835 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2015 12:07:30.6847 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB617 X-Topics: patch Subject: [lng-odp] [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.215.41 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 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(-) 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 * @@ -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;