From patchwork Thu Apr 30 09:24:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Badicioiu X-Patchwork-Id: 47790 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 67C9B20553 for ; Thu, 30 Apr 2015 09:26:52 +0000 (UTC) Received: by wgin8 with SMTP id n8sf13340593wgi.0 for ; Thu, 30 Apr 2015 02:26:51 -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=4LabmtPiGS4W+kveTfDyq9eyXl3EhWB1WUqIIssEtH4=; b=nLU2fB7w+wQsidVSoDoshobzJkJhXFJ3aRSURPZ1yI+u3Hy1Rd5RpiJ5c6fM54Hg2K ZvidAYb2M6rQ6cjL94WLMyCDWfpN71ZPu5u+UKLPQCZbgJj8pMaLdWRN3AhkkoR6iQVq P87Gri8U36esDUehPBx5NC5GbFkKsu//5wVF4lc2xBvcs9IEUeshIJNXqcm+CLFVj/9J UYQGMUH+BS8D67Q31rWrI0LibRKw+MgmeCFtzRuQpa0YqF0Sh4Ijpa32/lKD/puRMJqp Pcfz8PeLfxdXEP9aT+GGHKoqmPUVyLpvOb7y49PdyXF1D3FmUM80OMK70mxWUsTOpnBQ Vc/w== X-Gm-Message-State: ALoCoQnxOK9mPUwy+/CCyqdS60eJGnzGWDshjzMlQWNgQwBP3sANET4LUpGYixtUAcRsvvpA253b X-Received: by 10.180.211.168 with SMTP id nd8mr1217510wic.4.1430386011673; Thu, 30 Apr 2015 02:26:51 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.225.134 with SMTP id rk6ls349156lac.83.gmail; Thu, 30 Apr 2015 02:26:51 -0700 (PDT) X-Received: by 10.152.37.201 with SMTP id a9mr2926576lak.120.1430386011508; Thu, 30 Apr 2015 02:26:51 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id s7si1334593las.80.2015.04.30.02.26.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Apr 2015 02:26:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbcga7 with SMTP id ga7so39887129lbc.1 for ; Thu, 30 Apr 2015 02:26:51 -0700 (PDT) X-Received: by 10.112.150.100 with SMTP id uh4mr2942957lbb.112.1430386011412; Thu, 30 Apr 2015 02:26:51 -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 l1csp2995887lbt; Thu, 30 Apr 2015 02:26:50 -0700 (PDT) X-Received: by 10.140.22.147 with SMTP id 19mr3290630qgn.52.1430386001470; Thu, 30 Apr 2015 02:26:41 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id kh2si1321974qcb.6.2015.04.30.02.26.40; Thu, 30 Apr 2015 02:26:41 -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 6C3A561D0F; Thu, 30 Apr 2015 09:26:40 +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=unavailable autolearn_force=no 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 6289F61CC5; Thu, 30 Apr 2015 09:26:36 +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 CC1FF61CFA; Thu, 30 Apr 2015 09:26:34 +0000 (UTC) Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0073.outbound.protection.outlook.com [207.46.100.73]) by lists.linaro.org (Postfix) with ESMTPS id D647461CC5 for ; Thu, 30 Apr 2015 09:26:33 +0000 (UTC) Received: from DM2PR03CA0039.namprd03.prod.outlook.com (10.141.96.38) by BLUPR03MB615.namprd03.prod.outlook.com (10.255.124.43) with Microsoft SMTP Server (TLS) id 15.1.154.19; Thu, 30 Apr 2015 09:26:32 +0000 Received: from BL2FFO11FD041.protection.gbl (2a01:111:f400:7c09::193) by DM2PR03CA0039.outlook.office365.com (2a01:111:e400:2428::38) with Microsoft SMTP Server (TLS) id 15.1.148.16 via Frontend Transport; Thu, 30 Apr 2015 09:26:32 +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 BL2FFO11FD041.mail.protection.outlook.com (10.173.161.137) with Microsoft SMTP Server (TLS) id 15.1.154.14 via Frontend Transport; Thu, 30 Apr 2015 09:26:31 +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 t3U9QTcP007548; Thu, 30 Apr 2015 02:26:30 -0700 From: To: Date: Thu, 30 Apr 2015 12:24:18 +0300 Message-ID: <1430385858-29414-1-git-send-email-alexandru.badicioiu@linaro.org> X-Mailer: git-send-email 1.7.3.4 X-EOPAttributedMessage: 0 X-Matching-Connectors: 130748595920691598; (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)(77096005)(47776003)(50226001)(62966003)(33646002)(87936001)(92566002)(77156002)(110136002)(86152002)(104016003)(229853001)(48376002)(50986999)(86362001)(2351001)(6806004)(19580405001)(19580395003)(106466001)(50466002)(5001920100001)(36756003)(46102003)(105596002)(5001960100002); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR03MB615; 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:BLUPR03MB615; 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:BLUPR03MB615; BCL:0; PCL:0; RULEID:(400006); SRVR:BLUPR03MB615; X-Forefront-PRVS: 056297E276 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2015 09:26:31.8039 (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: BLUPR03MB615 X-Topics: patch Subject: [lng-odp] [PATCH 1/1] 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.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 From: Alexandru Badicioiu Signed-off-by: Alexandru Badicioiu --- helper/include/odp/helper/udp.h | 35 +++++++++++------------------------ 1 files changed, 11 insertions(+), 24 deletions(-) diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h index 99a96f2..8565bab 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; + uint16_t *buf; if (!odp_packet_l3_offset(pkt)) return 0; @@ -68,24 +59,20 @@ 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 = (uint16_t *)udph; udplen > 1; udplen -= 2) + sum += *buf++; /* 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;