From patchwork Tue May 20 05:59:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weilong Chen X-Patchwork-Id: 30407 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BC5D2203AB for ; Tue, 20 May 2014 06:00:44 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf35520148oag.8 for ; Mon, 19 May 2014 23:00:44 -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=YcVHTJZ9zj0RujZbtYPM7ksOIlSdUtvTZSDgM3LAukY=; b=L/00LRlxUOOieieaNtjfj+A6/kFzYBqUbogyE1Sal36l51aX+NRpHqnpTSgVWbyrs8 OthRBGHEAHz1LvLuiOMkIkRPJGm4GR3l01bKADxaRS+Zk2NiqKSZSM/HoPMwHxptAgx9 22pcqKBeFlFnzxffQnpdjmAZA/D58aHWbMgyGaA7REk9mIMlEzUzy3llM0yG8KN6rq+h W+zjSPGM088pcQoELiCqzIn1u5YGNl7ywKai3dJXYd2qdsDKZDDw2zWlYTIydLrFxrUE FVmYZflQZh7iQviYaUck1ZjRFdEFn1YXDIISwXt32QnZ/V8UYbE6IiEkRF5LSol8j61y oFVw== X-Gm-Message-State: ALoCoQl1QxXy60U+5TaUF3Ivled2qMkgxpdbnTGEYX84m3Xkx+hfg4SjUH2739o67wlrUQPq6yZG X-Received: by 10.182.19.231 with SMTP id i7mr18876268obe.25.1400565644305; Mon, 19 May 2014 23:00:44 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.74 with SMTP id w68ls105712qgw.53.gmail; Mon, 19 May 2014 23:00:44 -0700 (PDT) X-Received: by 10.53.12.229 with SMTP id et5mr1697569vdd.32.1400565644189; Mon, 19 May 2014 23:00:44 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id tb4si2336823vdc.37.2014.05.19.23.00.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 May 2014 23:00:44 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hr9so10902782vcb.3 for ; Mon, 19 May 2014 23:00:44 -0700 (PDT) X-Received: by 10.220.12.66 with SMTP id w2mr1956199vcw.15.1400565644064; Mon, 19 May 2014 23:00:44 -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 ib8csp3713vcb; Mon, 19 May 2014 23:00:43 -0700 (PDT) X-Received: by 10.224.79.207 with SMTP id q15mr53772820qak.40.1400565643088; Mon, 19 May 2014 23:00:43 -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 v9si3819516qab.121.2014.05.19.23.00.41 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 19 May 2014 23:00:43 -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 1Wmd5R-0004Mp-8P; Tue, 20 May 2014 05:59:41 +0000 Received: from mail-pb0-f51.google.com ([209.85.160.51]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wmd5K-0004Mk-U2 for lng-odp@lists.linaro.org; Tue, 20 May 2014 05:59:35 +0000 Received: by mail-pb0-f51.google.com with SMTP id ma3so6817827pbc.10 for ; Mon, 19 May 2014 23:00:29 -0700 (PDT) X-Received: by 10.68.181.67 with SMTP id du3mr48331478pbc.96.1400565629100; Mon, 19 May 2014 23:00:29 -0700 (PDT) Received: from localhost.localdomain ([218.17.215.175]) by mx.google.com with ESMTPSA id tg9sm1050547pbc.29.2014.05.19.23.00.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 May 2014 23:00:28 -0700 (PDT) From: Weilong Chen To: lng-odp@lists.linaro.org Date: Tue, 20 May 2014 13:59:48 +0800 Message-Id: <1400565588-8456-1-git-send-email-weilong.chen@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCHv3] 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.220.172 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 | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h index 9905d55..5aedb36 100644 --- a/include/helper/odp_udp.h +++ b/include/helper/odp_udp.h @@ -33,6 +33,15 @@ 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; /**< Source addr */ + uint32be_t dst_addr; /**< Destination addr */ + uint8_t pad; /**< pad byte */ + uint8_t proto; /**< UDP protocol */ + uint16be_t length; /**< data length */ +} odp_udpphdr_t; + /** * UDP checksum * @@ -43,12 +52,11 @@ typedef struct ODP_PACKED { */ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) { - unsigned long sum = 0; + uint32_t sum = 0; + odp_udpphdr_t phdr; odp_udphdr_t *udph; odp_ipv4hdr_t *iph; - uint8_t *buf; - unsigned short udplen; - uint16_t chksum; + uint16_t udplen; if (!odp_packet_l3_offset(pkt)) return 0; @@ -58,36 +66,30 @@ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) iph = (odp_ipv4hdr_t *)odp_packet_l3(pkt); udph = (odp_udphdr_t *)odp_packet_l4(pkt); - buf = (uint8_t *)udph; 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; - sum += odp_cpu_to_be_16(ODP_IPPROTO_UDP); + phdr.dst_addr = iph->dst_addr; + /* proto */ + phdr.pad = 0; + phdr.proto = ODP_IPPROTO_UDP; /* the length */ - sum += udph->length; + phdr.length = udph->length; - while (udplen > 1) { - sum += *buf++; - udplen -= 1; - } - /* if any bytes left, pad the bytes and add */ - if (udplen > 0) - sum += ((*buf)&odp_cpu_to_be_16(0xFF00)); + /* calc UDP pseudo header chksum */ + 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) sum = (sum & 0xFFFF) + (sum >> 16); - sum = ~sum; /* set computation result */ - chksum = ((unsigned short)sum == 0x0) ? 0xFFFF - : (unsigned short)sum; + sum = (sum == 0x0) ? 0xFFFF : sum; - return chksum; + return (uint16_t)sum; } /** @internal Compile time assert */