From patchwork Tue Apr 29 08:13:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weilong Chen X-Patchwork-Id: 29301 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 932F0202FE for ; Tue, 29 Apr 2014 08:13:45 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id lg15sf29168225vcb.7 for ; Tue, 29 Apr 2014 01:13:45 -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=cSM/4Utfd+MX03MKxgb4PQD69JuHGtjbO2e6h0EJz30=; b=dvLZ6OhpScOiOyT5EpKBvOdmajBTE/I8whY46SmdHVQEYOym7xsqktgUuHcKGF8cRA tu6x5A+kCYnpnkdqpGyMOQ+/dFhnTzwet9sWv+rOzab4cFVLVThLBWm4tjaruwumY2A7 +kTJSbslA61FB3DODaAKBKxYkD8pjA/qKM3yOY4fR0L5ASLd4hiCYh83fjCRoWjKc+Kv O9fFIZz/jrgjNMMz96pHdrBXyIb03Cn65z5Tut017Ee7ZojoDzOkr8gExmb4TA2cdWuK 8mM8jemJHPBh0fUU5eBUz3UztQkF4WycWE/JdcZORSkGjF7LcfOJpw48gUgtAKfXSUlg 3gfw== X-Gm-Message-State: ALoCoQk0I4NhEHDXEhC9LSQ4TYGUKoytMUJyP899CbK77S7WLc3yk54gWOBFAokyb2Gupr8nMvry X-Received: by 10.236.127.35 with SMTP id c23mr11757692yhi.51.1398759225345; Tue, 29 Apr 2014 01:13:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.72 with SMTP id k66ls330982qgd.96.gmail; Tue, 29 Apr 2014 01:13:45 -0700 (PDT) X-Received: by 10.220.161.8 with SMTP id p8mr28167100vcx.4.1398759225210; Tue, 29 Apr 2014 01:13:45 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id bp12si4340447veb.81.2014.04.29.01.13.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Apr 2014 01:13:45 -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.179; Received: by mail-ve0-f179.google.com with SMTP id db12so9346758veb.38 for ; Tue, 29 Apr 2014 01:13:45 -0700 (PDT) X-Received: by 10.58.154.10 with SMTP id vk10mr28678618veb.18.1398759225037; Tue, 29 Apr 2014 01:13:45 -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 ib8csp177762vcb; Tue, 29 Apr 2014 01:13:44 -0700 (PDT) X-Received: by 10.140.96.51 with SMTP id j48mr38311940qge.24.1398759224213; Tue, 29 Apr 2014 01:13:44 -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 a3si2039267qas.272.2014.04.29.01.13.42 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 29 Apr 2014 01:13:44 -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 1Wf3A9-0000F6-3m; Tue, 29 Apr 2014 08:13:13 +0000 Received: from mail-pd0-f175.google.com ([209.85.192.175]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wf3A2-0000F1-PP for lng-odp@lists.linaro.org; Tue, 29 Apr 2014 08:13:06 +0000 Received: by mail-pd0-f175.google.com with SMTP id fp1so4531941pdb.34 for ; Tue, 29 Apr 2014 01:13:30 -0700 (PDT) X-Received: by 10.68.224.198 with SMTP id re6mr34904770pbc.8.1398759210313; Tue, 29 Apr 2014 01:13:30 -0700 (PDT) Received: from localhost.localdomain ([218.17.215.175]) by mx.google.com with ESMTPSA id yw3sm39961080pbc.69.2014.04.29.01.13.28 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Apr 2014 01:13:29 -0700 (PDT) From: Weilong Chen To: lng-odp@lists.linaro.org Date: Tue, 29 Apr 2014 16:13:03 +0800 Message-Id: <1398759183-17547-1-git-send-email-weilong.chen@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCHv2] 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 | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h index 738470e..257db5f 100644 --- a/include/helper/odp_udp.h +++ b/include/helper/odp_udp.h @@ -33,6 +33,61 @@ 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 +* +*/ +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);