From patchwork Mon May 12 12:40:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weilong Chen X-Patchwork-Id: 29972 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B9DBD238EB for ; Mon, 12 May 2014 12:40:50 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id rd18sf15391129iec.7 for ; Mon, 12 May 2014 05:40:49 -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=0H09SXal8I8R5ApN97vPHsojw2h04Ryb2BwkIEq1hRE=; b=VG8jYACFgUoXV1t7nJPgN34wDzCTYF1ifrJRCaof+BoqzCaUNssdFln2Rvi0nFi/cB 2eEhZoNoLm8OR945mhgk/oa/jj/apEtZW0pivZhGrKPa7NYPggM8EZEagOj4F/JOfl6x jQ76JAmGALEKLmLiVPTK5F/IELYek7cSfotfbiMptITV94F7reKXLgidzrDSU9QBGiMh oSVjFaeMDKsDtBuxo+3KhsrdlOd3UCjQTCJsxoCSU1+xpSsyQuSZbIZQaa/ZSJtj0Jkk G9y+XdF5RYFBdWqE9hkIljzvT4P+CFCzh/kvsmPbw1PVNRiTh7EXW97QyoHBzBYrf5JF H1cg== X-Gm-Message-State: ALoCoQm4e8HrvKAvx5FeaogxDjXCOC4su4eBGYJ6/lLHI5QRB2uLchdwOwt1QCgATyZIaTR81F3R X-Received: by 10.43.94.71 with SMTP id bx7mr11836155icc.2.1399898449742; Mon, 12 May 2014 05:40:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.82.37 with SMTP id g34ls225904qgd.64.gmail; Mon, 12 May 2014 05:40:49 -0700 (PDT) X-Received: by 10.52.228.134 with SMTP id si6mr19111181vdc.5.1399898449586; Mon, 12 May 2014 05:40:49 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id tx4si366302vdc.94.2014.05.12.05.40.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 May 2014 05:40:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.178 as permitted sender) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id sa20so8639408veb.37 for ; Mon, 12 May 2014 05:40:49 -0700 (PDT) X-Received: by 10.220.253.132 with SMTP id na4mr520732vcb.39.1399898449519; Mon, 12 May 2014 05:40:49 -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.220.221.72 with SMTP id ib8csp65782vcb; Mon, 12 May 2014 05:40:49 -0700 (PDT) X-Received: by 10.140.88.241 with SMTP id t104mr35320788qgd.29.1399898448982; Mon, 12 May 2014 05:40:48 -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 m6si5898595qay.218.2014.05.12.05.40.48 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 12 May 2014 05:40:48 -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 1WjpWR-0007jz-5P; Mon, 12 May 2014 12:39:59 +0000 Received: from mail-pa0-f41.google.com ([209.85.220.41]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WjpWJ-0007jC-Mx for lng-odp@lists.linaro.org; Mon, 12 May 2014 12:39:51 +0000 Received: by mail-pa0-f41.google.com with SMTP id lj1so8495989pab.28 for ; Mon, 12 May 2014 05:40:34 -0700 (PDT) X-Received: by 10.66.189.106 with SMTP id gh10mr55887998pac.31.1399898434664; Mon, 12 May 2014 05:40:34 -0700 (PDT) Received: from localhost.localdomain ([218.17.215.175]) by mx.google.com with ESMTPSA id pl5sm22674004pbc.90.2014.05.12.05.40.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 May 2014 05:40:34 -0700 (PDT) From: Weilong Chen To: lng-odp@lists.linaro.org Date: Mon, 12 May 2014 20:40:22 +0800 Message-Id: <1399898422-16527-1-git-send-email-weilong.chen@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCHv2] Use odp_chksum to compute checksum of udp header and data 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: weilong.chen@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.128.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 Signed-off-by: Weilong Chen --- include/helper/odp_udp.h | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h index 28313ab..c984dc0 100644 --- a/include/helper/odp_udp.h +++ b/include/helper/odp_udp.h @@ -33,6 +33,14 @@ typedef struct ODP_PACKED { uint16be_t chksum; /**< UDP header and data checksum (0 if not used)*/ } odp_udphdr_t; +/** UDP pseudo header */ +typedef struct ODP_PACKET { + uint32be_t src_addr; + uint32be_t dst_addr; + uint8_t pad; + uint8_t proto; + uint16be_t length; +} odp_udpphdr_t; /** * UDP checksum * @@ -43,7 +51,8 @@ typedef struct ODP_PACKED { */ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) { - uint32_t sum = 0; + uint32_t sum; + odp_udpphdr_t phdr; odp_udphdr_t *udph; odp_ipv4hdr_t *iph; uint16_t udplen; @@ -59,23 +68,24 @@ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) udplen = odp_be_to_cpu_16(udph->length); /* the source ip */ - sum += (iph->src_addr >> 16) & 0xFFFF; - sum += (iph->src_addr) & 0xFFFF; + phdr.src_addr = iph->src_addr; /* the dest ip */ - sum += (iph->dst_addr >> 16) & 0xFFFF; - sum += (iph->dst_addr) & 0xFFFF; + phdr.dst_addr = iph->dst_addr; /* proto */ - sum += odp_cpu_to_be_16(ODP_IPPROTO_UDP); + phdr.pad = 0; + phdr.proto = ODP_IPPROTO_UDP; /* the length */ - sum += udph->length; + phdr.length = udph->length; + + sum = odp_chksum(&phdr, sizeof(odp_udpphdr_t)); + /* calc udp header and data chksum */ + sum += odp_chksum(udph, udplen); + /* Fold sum to 16 bits: add carrier to result */ while ((sum >> 16) != 0) sum = (sum & 0xFFFF) + (sum >> 16); - /* calc udp header and data chksum */ - sum += ~(odp_chksum(udph, udplen)); - - return (uint16_t)(~sum); + return (uint16_t)sum; } /** @internal Compile time assert */