From patchwork Mon Apr 21 09:15:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weilong Chen X-Patchwork-Id: 28670 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 488F620341 for ; Mon, 21 Apr 2014 09:15:52 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id w8sf16421158qac.4 for ; Mon, 21 Apr 2014 02:15:52 -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:in-reply-to :references: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=aigdxYxk20FNZZExsACjcOnsvktGStAotob3F1TxZ3Y=; b=CfPKpa3Yb5dIvga+liPnjSydW0APPEmmJSzngved2alHNm++rh/2NDIeLZ59loujvJ 3luxCy8MVm+itzvMWoqoDD8Kv4dBR6T9khrtgE74nwQRnuVoT25Oh2C9pUBThriwpeuT 1mufawwkiqmFyZtkehRL+3aLUY7nAfxNMj7PkALF80EvAxAdyoElNejZxOiM18lVE0mR pqvfIqh2MZRK4quBBv3h4CVQdEHVzEOFcM4ew43moQzmQdatm0EWhqTWmbhIKAlhWE2Z W8ilEbb20MPcA2K2WXKS6LHS0Yo7pOo0R+BCHwjI4MBaMbF7fxUneYVaXa3d+i128ai2 8IEQ== X-Gm-Message-State: ALoCoQl8G249MG6aryu54bF51tD25A/pFQf9uv2POukA3C88fU/dfKLM2Hlc1ol+A4CJpUWmVQ45 X-Received: by 10.58.95.98 with SMTP id dj2mr17227338veb.30.1398071752039; Mon, 21 Apr 2014 02:15:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.80.145 with SMTP id c17ls2291993qgd.60.gmail; Mon, 21 Apr 2014 02:15:51 -0700 (PDT) X-Received: by 10.58.107.65 with SMTP id ha1mr33761407veb.1.1398071751921; Mon, 21 Apr 2014 02:15:51 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id gx4si6181064vcb.1.2014.04.21.02.15.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Apr 2014 02:15:51 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jx11so7677846veb.31 for ; Mon, 21 Apr 2014 02:15:51 -0700 (PDT) X-Received: by 10.52.123.39 with SMTP id lx7mr24762570vdb.22.1398071751810; Mon, 21 Apr 2014 02:15: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.220.221.72 with SMTP id ib8csp278529vcb; Mon, 21 Apr 2014 02:15:51 -0700 (PDT) X-Received: by 10.224.22.65 with SMTP id m1mr1031617qab.103.1398071751372; Mon, 21 Apr 2014 02:15:51 -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 t4si12294303qat.196.2014.04.21.02.15.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 21 Apr 2014 02:15:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) 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 1WcAK3-00084J-7m; Mon, 21 Apr 2014 09:15:31 +0000 Received: from mail-pa0-f42.google.com ([209.85.220.42]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WcAJt-00083j-Hy for lng-odp@lists.linaro.org; Mon, 21 Apr 2014 09:15:21 +0000 Received: by mail-pa0-f42.google.com with SMTP id fb1so3585493pad.1 for ; Mon, 21 Apr 2014 02:15:33 -0700 (PDT) X-Received: by 10.68.160.163 with SMTP id xl3mr37215162pbb.39.1398071733522; Mon, 21 Apr 2014 02:15:33 -0700 (PDT) Received: from localhost.localdomain ([218.17.215.175]) by mx.google.com with ESMTPSA id ha11sm76706923pbd.17.2014.04.21.02.15.31 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Apr 2014 02:15:33 -0700 (PDT) From: Weilong Chen To: lng-odp@lists.linaro.org Date: Mon, 21 Apr 2014 17:15:09 +0800 Message-Id: <1398071709-5807-3-git-send-email-weilong.chen@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1398071709-5807-1-git-send-email-weilong.chen@linaro.org> References: <1398071709-5807-1-git-send-email-weilong.chen@linaro.org> Subject: [lng-odp] [PATCH] Add odp helper function for udp checksum 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=neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h index 738470e..2070861 100644 --- a/include/helper/odp_udp.h +++ b/include/helper/odp_udp.h @@ -33,6 +33,55 @@ typedef struct ODP_PACKED { uint16be_t chksum; /**< UDP header and data checksum (0 if not used)*/ } odp_udphdr_t; +static inline uint16be_t odp_ipv4_udp_chksum(odp_packet_t pkt) +{ + unsigned long sum = 0; + odp_udphdr_t *udph; + odp_ipv4hdr_t *iph; + unsigned short *buf; + unsigned short udplen; + + if (!odp_packet_l3_offset(pkt)) + return 0; + + if (!odp_packet_l4_offset(pkt)) + return 0; + + iph = (odp_ipv4hdr_t *)odp_packet_l3(pkt); + udph = (odp_udphdr_t *)odp_packet_l4(pkt); + buf = (unsigned short *)udph; + udplen = odp_be_to_cpu_16(udph->length); + + /* the source ip */ + sum += (iph->src_addr >> 16) & 0xFFFF; + sum += (iph->src_addr) & 0xFFFF; + /* the dest ip */ + sum += (iph->dst_addr >> 16) & 0xFFFF; + sum += (iph->dst_addr) & 0xFFFF; + sum += odp_cpu_to_be_16(ODP_IPPROTO_UDP); + /* the length */ + sum += udph->length; + + /* initialize checksum to 0 */ + udph->chksum = 0; + while (udplen > 1) { + sum += *buf++; + udplen -= 2; + } + /* if any bytes left, pad the bytes and add */ + if (udplen > 0) + sum += ((*buf)&odp_cpu_to_be_16(0xFF00)); + + /* Fold sum to 16 bits: add carrier to result */ + while (sum >> 16) + sum = (sum & 0xFFFF) + (sum >> 16); + sum = ~sum; + /* set computation result */ + udph->chksum = ((unsigned short)sum == 0x0) ? 0xFFFF + : (unsigned short)sum; + + return udph->chksum; +} /** @internal Compile time assert */ ODP_ASSERT(sizeof(odp_udphdr_t) == ODP_UDPHDR_LEN, ODP_UDPHDR_T__SIZE_ERROR);