From patchwork Mon May 12 11:47:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weilong Chen X-Patchwork-Id: 29967 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 59F9E238EB for ; Mon, 12 May 2014 11:48:34 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id m20sf23460818qcx.1 for ; Mon, 12 May 2014 04:48:34 -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=0H09SXal8I8R5ApN97vPHsojw2h04Ryb2BwkIEq1hRE=; b=fF+kU5MpM7epinRi+hTZ9KK7PgKxsQLK/uLFzCk7Fv2hyszv7rsW0tepo8doGkpGdx WSxXkRw7wpPpmAy9oApbrN3pVsjkxA0rqx11E406W9alZdss1U33RJf6vdDX7+Xov6Bx BDkoA6sAh+RFSdoAPs3YhX5vLlHD8ZhW/K62+eoTE/5jZzK5RumzOSpBuUHdTzTe+p4H JKs/GnDawmwaTIY7qGRfShae3XkkJ0YXHE0/yyf5LGd8yD91rrLF3UaiukNtqLpL+wHj h5p/uUl9FDUMcrzGl3sn3/kwfyEXK36XesYwfF9ic94Xwcq8+rvloC5p2yOMtLbHa8UT V/nw== X-Gm-Message-State: ALoCoQnErRZLXcpEMhGfMx+S3rXRTFJHVgMpooqEiK9sY4WN/sh3LYB+oa+tyUgcWkAIRUBzbGYg X-Received: by 10.236.203.113 with SMTP id e77mr11541426yho.15.1399895314556; Mon, 12 May 2014 04:48:34 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.72 with SMTP id i66ls1306813qgf.78.gmail; Mon, 12 May 2014 04:48:34 -0700 (PDT) X-Received: by 10.52.120.77 with SMTP id la13mr310123vdb.45.1399895314460; Mon, 12 May 2014 04:48:34 -0700 (PDT) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id vl10si602592vec.128.2014.05.12.04.48.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 May 2014 04:48:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.180 as permitted sender) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id db12so8492197veb.39 for ; Mon, 12 May 2014 04:48:34 -0700 (PDT) X-Received: by 10.58.38.40 with SMTP id d8mr204920vek.61.1399895314346; Mon, 12 May 2014 04:48:34 -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 ib8csp62322vcb; Mon, 12 May 2014 04:48:34 -0700 (PDT) X-Received: by 10.224.134.194 with SMTP id k2mr36799507qat.5.1399895313893; Mon, 12 May 2014 04:48:33 -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 c4si5834376qad.118.2014.05.12.04.48.32 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 12 May 2014 04:48:33 -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 1Wjohs-0006lT-0I; Mon, 12 May 2014 11:47:44 +0000 Received: from mail-pa0-f47.google.com ([209.85.220.47]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Wjohl-0006lO-9W for lng-odp@lists.linaro.org; Mon, 12 May 2014 11:47:37 +0000 Received: by mail-pa0-f47.google.com with SMTP id lf10so5841287pab.34 for ; Mon, 12 May 2014 04:48:20 -0700 (PDT) X-Received: by 10.66.228.37 with SMTP id sf5mr55378873pac.19.1399895300358; Mon, 12 May 2014 04:48:20 -0700 (PDT) Received: from localhost.localdomain ([218.17.215.175]) by mx.google.com with ESMTPSA id ga1sm22434502pbb.82.2014.05.12.04.48.17 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 May 2014 04:48:19 -0700 (PDT) From: Weilong Chen To: lng-odp@lists.linaro.org Date: Mon, 12 May 2014 19:47:43 +0800 Message-Id: <1399895263-20162-1-git-send-email-weilong.chen@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCH] 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.128.180 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 | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/include/helper/odp_udp.h b/include/helper/odp_udp.h index 28313ab..c984dc0 100644 --- a/include/helper/odp_udp.h +++ b/include/helper/odp_udp.h @@ -33,6 +33,14 @@ 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; + uint32be_t dst_addr; + uint8_t pad; + uint8_t proto; + uint16be_t length; +} odp_udpphdr_t; /** * UDP checksum * @@ -43,7 +51,8 @@ typedef struct ODP_PACKED { */ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) { - uint32_t sum = 0; + uint32_t sum; + odp_udpphdr_t phdr; odp_udphdr_t *udph; odp_ipv4hdr_t *iph; uint16_t udplen; @@ -59,23 +68,24 @@ static inline uint16_t odp_ipv4_udp_chksum(odp_packet_t pkt) 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; + phdr.dst_addr = iph->dst_addr; /* proto */ - sum += odp_cpu_to_be_16(ODP_IPPROTO_UDP); + phdr.pad = 0; + phdr.proto = ODP_IPPROTO_UDP; /* the length */ - sum += udph->length; + phdr.length = udph->length; + + 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) != 0) sum = (sum & 0xFFFF) + (sum >> 16); - /* calc udp header and data chksum */ - sum += ~(odp_chksum(udph, udplen)); - - return (uint16_t)(~sum); + return (uint16_t)sum; } /** @internal Compile time assert */