From patchwork Tue Apr 29 09:02:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weilong Chen X-Patchwork-Id: 29315 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5C3BE202DD for ; Tue, 29 Apr 2014 09:03:06 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id y10sf6375415pdj.4 for ; Tue, 29 Apr 2014 02:03:05 -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=psTJ6ben661CvxwU9lLbyxYIAC8Q9E7G6BgzMY1DEIY=; b=eCPnAw4NY/TW0HtS54JNYOBv5MHqKyOlIflTagNuMBmh+KXhugmZK3t0SWw3tnKRZK 5hZexunR3xMrR0d+iRAoZ7W7Jks/HVwK/Eda+M8QnC60PR7uRMWK7G6r+AxdKH9i9X9m LLdYP+RV+3BUTU90L+zN9QjntnVCTNO99x/p/1P0VME+M5E9Z0xPFzswXufdw7TUQGv9 KyUHAOqZi+0CqMMgo8gm3X20j5XwL0Rv6s/dDN6xfr/EZGEqs+0XEkntzPyT/EQw8LSQ VIpxsrFNC6V5+4xDHe2plg0dEL6ImKOkrOtcN/QIk5VXlD2H1y/1kC1GcnEruxtepPOs PeAA== X-Gm-Message-State: ALoCoQkmdLqdrqrGNJrYzwh952bWZbnbAn0zFjz2eujmfdZndwS+DY5aBMuqEfagDKnY1SaEGDOZ X-Received: by 10.66.232.229 with SMTP id tr5mr4132767pac.16.1398762185641; Tue, 29 Apr 2014 02:03:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.70 with SMTP id u64ls5057qgd.80.gmail; Tue, 29 Apr 2014 02:03:05 -0700 (PDT) X-Received: by 10.221.27.8 with SMTP id ro8mr723530vcb.30.1398762185446; Tue, 29 Apr 2014 02:03:05 -0700 (PDT) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id w10si4352327vei.124.2014.04.29.02.03.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Apr 2014 02:03:05 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.171; Received: by mail-ve0-f171.google.com with SMTP id jy13so9436413veb.16 for ; Tue, 29 Apr 2014 02:03:05 -0700 (PDT) X-Received: by 10.220.147.16 with SMTP id j16mr28518511vcv.14.1398762185355; Tue, 29 Apr 2014 02:03:05 -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 ib8csp180620vcb; Tue, 29 Apr 2014 02:03:05 -0700 (PDT) X-Received: by 10.140.32.97 with SMTP id g88mr38159503qgg.17.1398762184909; Tue, 29 Apr 2014 02:03:04 -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 c108si3467010qgc.80.2014.04.29.02.03.04 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 29 Apr 2014 02:03:04 -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 1Wf3vu-0001HV-HT; Tue, 29 Apr 2014 09:02:34 +0000 Received: from mail-pd0-f171.google.com ([209.85.192.171]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wf3vo-0001HQ-M9 for lng-odp@lists.linaro.org; Tue, 29 Apr 2014 09:02:28 +0000 Received: by mail-pd0-f171.google.com with SMTP id r10so510202pdi.2 for ; Tue, 29 Apr 2014 02:02:52 -0700 (PDT) X-Received: by 10.68.240.99 with SMTP id vz3mr31139197pbc.93.1398762172294; Tue, 29 Apr 2014 02:02:52 -0700 (PDT) Received: from localhost.localdomain ([218.17.215.175]) by mx.google.com with ESMTPSA id av2sm40331821pbc.16.2014.04.29.02.02.49 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Apr 2014 02:02:51 -0700 (PDT) From: Weilong Chen To: lng-odp@lists.linaro.org Date: Tue, 29 Apr 2014 17:02:08 +0800 Message-Id: <1398762128-17677-1-git-send-email-weilong.chen@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCHv3] 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: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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 | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h index 738470e..c4ce4b8 100644 --- a/include/helper/odp_udp.h +++ b/include/helper/odp_udp.h @@ -33,6 +33,62 @@ typedef struct ODP_PACKED { uint16be_t chksum; /**< UDP header and data checksum (0 if not used)*/ } odp_udphdr_t; +/** + * UDP checksum + * + * This function uses odp packet to calc checksum + * + * @param pkt calculate chksum for pkt + * @return checksum value + */ +static inline uint16_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; + uint16_t chksum; + + 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; + + 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 */ + chksum = ((unsigned short)sum == 0x0) ? 0xFFFF + : (unsigned short)sum; + + return chksum; +} /** @internal Compile time assert */ ODP_ASSERT(sizeof(odp_udphdr_t) == ODP_UDPHDR_LEN, ODP_UDPHDR_T__SIZE_ERROR);