From patchwork Wed May 7 11:43:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weilong Chen X-Patchwork-Id: 29756 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B253220534 for ; Wed, 7 May 2014 11:44:10 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id db11sf2838968veb.0 for ; Wed, 07 May 2014 04:44:10 -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=YoVtU4ClvoQ75Ouk6m38J1pDFMQI9gnQnDI9IVvZGt4=; b=hTVHUhTLWUey2HRb2fx5FGpyKKyjvWGJe4vnSWj03JCHjwZU+bYnjkvgaS+cQpB5xz VLARfeQSlkjgIP3sHoXyhVVhuELSBPd2KLr5SdECtQskXseD1ApN55PlFd++IPAT04aY vheQkK/YfMEXOvfr0lqHnw9WLDGs6LUg/PlSno8I+2zxK978ws6qBny0fObmId09tm5M o6Vx5WtwC5yR6Y64AZ7+p8+2/XrCECibZ3wB6qmf3EXkqm+QmUZLFg03piA7HjcYzpMg fUUS2K7vtuBDr04fGxWC3f6XhHAqQo083vZUTnd1QjYGRoywCeuijSpn/ufY5hV2KvL0 wghQ== X-Gm-Message-State: ALoCoQnrKEFONWShVsWa6bXpTN6fS723NUdBaVh+Sa2/l66eiSro3IfkgSSUx0G/s5evcVEs0s8l X-Received: by 10.236.127.35 with SMTP id c23mr3386915yhi.51.1399463050476; Wed, 07 May 2014 04:44:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.24.42 with SMTP id 39ls3420445qgq.26.gmail; Wed, 07 May 2014 04:44:10 -0700 (PDT) X-Received: by 10.52.163.145 with SMTP id yi17mr1268137vdb.46.1399463050398; Wed, 07 May 2014 04:44:10 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id oo7si2850540vcb.130.2014.05.07.04.44.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 May 2014 04:44:10 -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.220.177; Received: by mail-vc0-f177.google.com with SMTP id if11so1059980vcb.36 for ; Wed, 07 May 2014 04:44:10 -0700 (PDT) X-Received: by 10.58.216.163 with SMTP id or3mr31506vec.80.1399463050320; Wed, 07 May 2014 04:44:10 -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 ib8csp301380vcb; Wed, 7 May 2014 04:44:10 -0700 (PDT) X-Received: by 10.140.89.18 with SMTP id u18mr58682267qgd.78.1399463049501; Wed, 07 May 2014 04:44:09 -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 m6si6555118qay.241.2014.05.07.04.44.08 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 07 May 2014 04:44:09 -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 1Wi0Fy-0002mH-Rh; Wed, 07 May 2014 11:43:26 +0000 Received: from mail-pa0-f49.google.com ([209.85.220.49]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wi0Fs-0002kj-EH for lng-odp@lists.linaro.org; Wed, 07 May 2014 11:43:20 +0000 Received: by mail-pa0-f49.google.com with SMTP id lj1so1083311pab.8 for ; Wed, 07 May 2014 04:43:56 -0700 (PDT) X-Received: by 10.66.248.228 with SMTP id yp4mr18020759pac.94.1399463035325; Wed, 07 May 2014 04:43:55 -0700 (PDT) Received: from localhost.localdomain ([218.17.215.175]) by mx.google.com with ESMTPSA id gc6sm6560895pac.43.2014.05.07.04.43.52 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 May 2014 04:43:54 -0700 (PDT) From: Weilong Chen To: lng-odp@lists.linaro.org Date: Wed, 7 May 2014 19:43:39 +0800 Message-Id: <1399463020-14182-1-git-send-email-weilong.chen@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCHv4 1/2] 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..9905d55 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; + uint8_t *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 = (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; + /* 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 -= 1; + } + /* 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);