From patchwork Mon Sep 25 22:00:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 114186 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3101983qgf; Mon, 25 Sep 2017 15:00:58 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBLEClyDE6ppKzjthIpOXa0TgQRlWyGOoEZ7BOlSDkbvHRS3jAuHnm0yhG+74b51vdwgaNp X-Received: by 10.107.53.89 with SMTP id c86mr12171703ioa.125.1506376858168; Mon, 25 Sep 2017 15:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506376858; cv=none; d=google.com; s=arc-20160816; b=t+lW8GShAfjWySOszYDBuGk+E6PPCbGQxsvFeJdJxyo3T50TAF3d19wq+lVoZXeOAV aD0rPBKsOZOjAAGrHzVHLRtYyVOozCRlP9Az4yN4lJOLhLxf0CtXoHvXhxb2vQqAOJks tICTHnRLCr4QEf6hsQdvXrhMPjc+G+1A+AqpdBquRUS9iCT4oS96gQElxlDh2gL16ipp WFmOI6dwDAx/fbfG2U+UKblI6J62wdQ84hgxr85rTcZt6UOEEvtcay4mRIreQ2RTMBWt 9Wq+Mp3VO4VBLK5JDgoSoYgqLYR39CMGGDwnCBigbau3FIM3L0DHY46empHLSLrfVxrb tYog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=DlVaj9d7tkHdCtCm44EYMG7gm0n+10dKIl3itafDtjY=; b=EdPlCJFXLqxQjiWTtelp7Px0wGAGQxi3naOx3hI2C3E7H7Gipig+xdQ1tH6+6Cg4MF C6S2ZTEXVjfuknk97thIrIlQNrgFUvCfEGa9VyQviq6OZ6E9szB3C7qFQL8KnRwPWrE7 foXW1ULTmTg2Ogojx8fN9EqLHHCFAF9duuPkeEFUrKYPCXxv/xenV7iQ6J7lRC8o0ScZ XBWMLI0GZVCkQOkjEASQvMHbE10zfoCO+Iy+wTWg3+/cNizxXla9TqV86/CuBst1V1df VhuwVGbTSDVDycmavqPJOeEqx3t1V79yt2aUTy8lY3n/BJv4YwcCfEb9ir93kJ7FDPPb sOaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 194si420787itz.55.2017.09.25.15.00.57; Mon, 25 Sep 2017 15:00:58 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id A904760BE3; Mon, 25 Sep 2017 22:00:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 1E50A609D5; Mon, 25 Sep 2017 22:00:24 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B8F306098D; Mon, 25 Sep 2017 22:00:19 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id 32C82607DD for ; Mon, 25 Sep 2017 22:00:18 +0000 (UTC) Received: from mxback13g.mail.yandex.net (mxback13g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:92]) by forward106o.mail.yandex.net (Yandex) with ESMTP id E2B967835B1 for ; Tue, 26 Sep 2017 01:00:16 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback13g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 4mFBUuz0rj-0GvS8F5V; Tue, 26 Sep 2017 01:00:16 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id YWIwh59QMn-0GF0tac7; Tue, 26 Sep 2017 01:00:16 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 26 Sep 2017 01:00:05 +0300 Message-Id: <1506376806-27771-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1506376806-27771-1-git-send-email-odpbot@yandex.ru> References: <1506376806-27771-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 193 Subject: [lng-odp] [PATCH API-NEXT v1 2/3] linux-gen: chksum: implement ones complement sum X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Petri Savolainen Add implementation of 16 bit ones complement sum function. This is non-performance optimized but simple and based on RFC 1071 and its errata. Signed-off-by: Petri Savolainen --- /** Email created from pull request 193 (psavol:next-ip-checksum) ** https://github.com/Linaro/odp/pull/193 ** Patch: https://github.com/Linaro/odp/pull/193.patch ** Base sha: 13322ca632f8ffba292bec058e597719bc54142d ** Merge commit sha: 405aaa1f3768170dd025f0a4c3bfdd63600f68df **/ platform/linux-generic/Makefile.am | 1 + platform/linux-generic/odp_chksum.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 platform/linux-generic/odp_chksum.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 994bbbeee..1117e3470 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -236,6 +236,7 @@ __LIB__libodp_linux_la_SOURCES = \ odp_bitmap.c \ odp_buffer.c \ odp_byteorder.c \ + odp_chksum.c \ odp_classification.c \ odp_cpu.c \ odp_cpumask.c \ diff --git a/platform/linux-generic/odp_chksum.c b/platform/linux-generic/odp_chksum.c new file mode 100644 index 000000000..349bdaf46 --- /dev/null +++ b/platform/linux-generic/odp_chksum.c @@ -0,0 +1,36 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +/* Simple implementation of ones complement sum. + * Based on RFC1071 and its errata. + */ +uint16_t odp_chksum_ones_comp16(const void *p, uint32_t len) +{ + uint32_t sum = 0; + const uint16_t *data = p; + + while (len > 1) { + sum += *data++; + len -= 2; + } + + /* Add left-over byte, if any */ + if (len > 0) { + uint16_t left_over; + + *(uint8_t *)&left_over = *(const uint8_t *)data; + sum += left_over; + } + + /* Fold 32-bit sum to 16 bits */ + while (sum >> 16) + sum = (sum & 0xffff) + (sum >> 16); + + return sum; +}