From patchwork Wed Mar 19 18:21:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shukla X-Patchwork-Id: 26607 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A58C420534 for ; Wed, 19 Mar 2014 18:21:36 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id j7sf19382066qaq.2 for ; Wed, 19 Mar 2014 11:21:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe:content-type; bh=odckwnJadAnME0m2b1H/VoO2EOxKlAAAyP2YONhQ5GM=; b=FYOQOtZ3nbWbvOFvQmQ/4QAHdb2YEIZZZQ404oM8BhxOrl7Vl1OMi1tqqVLEzcEtW9 XCV3mYeFB3kXDRt6eJOyW5ZDcER1wppjEFO5wcDKN8ICj5XPCzT0bCX66awPkExWR12E 9xRdi5sxsjSJnkYopNHgIuvfIgRS6wZGR7UFL0sBjbiJdoQKSZF/uwQk41rNWZlPebqE CySSZ0WL3xC85GpNJtYiDa8NnA/cyWn5Yrw/nYV6TwdD81UFwSG8ALO+Q/M7Ch3GuM3N xiLYocFa2Ebpt3WZS8Rrnq0zWwsvFCxF2YxlLzfYu1o0LU9Bncuf5VYn23ZjqJHmsbYZ 49Ig== X-Gm-Message-State: ALoCoQlTt7E7ORJ3HL30HVzyyNL+9ispBctmWkiZvA0ZnwGJa2tABiSoaGdUmdQA/UDS+cve2b0m X-Received: by 10.52.187.41 with SMTP id fp9mr13331296vdc.5.1395253296329; Wed, 19 Mar 2014 11:21:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.50.80.7 with SMTP id n7ls2603850igx.33.canary; Wed, 19 Mar 2014 11:21:35 -0700 (PDT) X-Received: by 10.50.83.38 with SMTP id n6mr26571678igy.30.1395253295906; Wed, 19 Mar 2014 11:21:35 -0700 (PDT) Received: from mail-ig0-f181.google.com (mail-ig0-f181.google.com [209.85.213.181]) by mx.google.com with ESMTPS id yf9si31677976igb.36.2014.03.19.11.21.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Mar 2014 11:21:35 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.213.181 is neither permitted nor denied by best guess record for domain of santosh.shukla@linaro.org) client-ip=209.85.213.181; Received: by mail-ig0-f181.google.com with SMTP id h18so12522235igc.2 for ; Wed, 19 Mar 2014 11:21:35 -0700 (PDT) X-Received: by 10.50.92.102 with SMTP id cl6mr26474067igb.44.1395253295740; Wed, 19 Mar 2014 11:21:35 -0700 (PDT) Received: from santosh-Latitude-E5530-non-vPro.mvista.com (64.2.3.195.ptr.us.xo.net. [64.2.3.195]) by mx.google.com with ESMTPSA id ro10sm34557324igb.6.2014.03.19.11.21.29 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Mar 2014 11:21:34 -0700 (PDT) From: Santosh Shukla To: lng-odp@linaro.org Cc: santosh shukla Subject: [lng-odp] [ODP/PATCH] chksum: move chksum calculation from ipv4 header file Date: Wed, 19 Mar 2014 11:21:17 -0700 Message-Id: <1395253277-9177-1-git-send-email-santosh.shukla@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Original-Sender: santosh.shukla@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.213.181 is neither permitted nor denied by best guess record for domain of santosh.shukla@linaro.org) smtp.mail=santosh.shukla@linaro.org Precedence: list Mailing-list: list lng-odp@linaro.org; contact lng-odp+owners@linaro.org List-ID: X-Google-Group-Id: 474323889996 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: santosh shukla created new chksum file in include/helper directory and added chksum function there. Signed-off-by: santosh shukla --- include/helper/odp_chksum.h | 54 +++++++++++++++++++++++++++++++++++++++++++ include/helper/odp_ip.h | 23 +++--------------- 2 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 include/helper/odp_chksum.h diff --git a/include/helper/odp_chksum.h b/include/helper/odp_chksum.h new file mode 100644 index 0000000..89ba8a2 --- /dev/null +++ b/include/helper/odp_chksum.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + +/** + * @file + * + * ODP Checksum + */ +#ifndef ODP_CHKSUM_H_ +#define ODP_CHKSUM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * Checksum + * + * @param buffer calculate chksum for buffer + * @param len buffer length + * + * @return checksum value + */ +static inline uint16_t odp_chksum(void *buffer, int len) +{ + uint16_t *buf = buffer; + unsigned int sum = 0; + uint16_t result; + + for (sum = 0; len > 1; len -= 2) + sum += *buf++; + + if (len == 1) + sum += *(unsigned char *)buf; + + sum = (sum >> 16) + (sum & 0xFFFF); + sum += (sum >> 16); + result = ~sum; + + return result; +} + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/helper/odp_ip.h b/include/helper/odp_ip.h index b13262c..af6d23b 100644 --- a/include/helper/odp_ip.h +++ b/include/helper/odp_ip.h @@ -21,6 +21,7 @@ extern "C" { #include #include #include +#include "odp_chksum.h" #include @@ -53,7 +54,6 @@ ODP_ASSERT(sizeof(odp_ipv4hdr_t) == ODP_IPV4HDR_LEN, ODP_IPV4HDR_T__SIZE_ERROR); static inline int odp_ipv4_csum_valid(odp_packet_t pkt) { - int sum = 0; uint16be_t res = 0; uint16_t *w; int nleft = sizeof(odp_ipv4hdr_t); @@ -68,21 +68,13 @@ static inline int odp_ipv4_csum_valid(odp_packet_t pkt) chksum = ip.chksum; ip.chksum = 0x0; - while (nleft > 1) { - sum += *w++; - nleft -= 2; - } - - sum = (sum >> 16) + (sum & 0xFFFF); - sum += sum >> 16; - res = ~sum; + res = odp_chksum(w, nleft); return (res == chksum) ? 1 : 0; } static inline uint16be_t odp_ipv4_csum_update(odp_packet_t pkt) { - int sum = 0; uint16be_t res = 0; uint16_t *w; odp_ipv4hdr_t *ip; @@ -93,16 +85,7 @@ static inline uint16be_t odp_ipv4_csum_update(odp_packet_t pkt) ip = (odp_ipv4hdr_t *)odp_packet_l3(pkt); w = (uint16_t *)(void *)ip; - ip->chksum = 0x0; - - while (nleft > 1) { - sum += *w++; - nleft -= 2; - } - - sum = (sum >> 16) + (sum & 0xFFFF); - sum += sum >> 16; - res = ~sum; + res = odp_chksum(w, nleft); ip->chksum = res; return res; }