From patchwork Sat Jan 13 08:00:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 124415 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp65017lje; Sat, 13 Jan 2018 00:03:11 -0800 (PST) X-Google-Smtp-Source: ACJfBou0c0AeKmjiNIdzXzzvZshryb1VWyAeLi6J5GkD58aPkgJuSAdbrHQUt5/COjNIqzJWK4T2 X-Received: by 10.55.217.132 with SMTP id q4mr37670935qkl.236.1515830591270; Sat, 13 Jan 2018 00:03:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515830591; cv=none; d=google.com; s=arc-20160816; b=CRPDAkhPE+CWUyWI8KoQmL7rbCsaV/16GhY8TFv+mac4u2WnN6W3E1onzzGTONMgGD VKgBbC/Bk3NS0TAHXzIL8v3EhJWtN3v+vFKu0RAVNEyS1cC7NZMygYraz0DsTuyhtFYE llHG2TXtm1AbEEIeAMEHmSpz2tGDJb/G+syZ2TWGGo6DRyAd5MHROIwVZSrZ+UO04tTg QH0QiiAObIe0geAYWzQRggdQk9vTI4uUlgHJFpQcxtHMV5T/qJQ5Lr4BQVTzPYhgZYx1 x/U/yNBkKkiiYmfN76dIgb1Umgl4FQ/MxfTyQs+E49tksUX479ZF8r+p8I207eg7C2kd FEYg== 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=UVCmrCykghOCFTY5nzbUHW4wBbjfaKEkAY/qnoKrmPg=; b=KxMsSW4nsRuEeu32y4AfLJSpXT3oOjRAYnK0EYQAD2Ytrb58rgWIUh1k3k7T5+yqCc PtVuKAVlJXCDpJD+lbU8wOMEAfxoQMsIOIvXtgr+DfkPp7GUPMMkuqDZ2u7tJBwfwyOU bECUxUB6ia161TAynzkTECcjQIHk/g/oulxcLPk+fdlVjHcQOi7+Hjoe/RhQBVtJ0VpV wj5239iao5W0f+fLbNtAXMuLv2P+nTeFC7k8Ccn76KOkWlOC6sOIXXeb2AcDW2C+J3Wd AKk9GKYp2y97eKBmddX4DyVyexXCJSIlTVPdaCc7MuFuDiCg76IzJVB4z5vMl6+4oL40 gGAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id q17si7110312qte.468.2018.01.13.00.03.11; Sat, 13 Jan 2018 00:03:11 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 00B8E61751; Sat, 13 Jan 2018 08:03:10 +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_H2 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 AE10B616F7; Sat, 13 Jan 2018 08:00:38 +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 0C69461766; Sat, 13 Jan 2018 08:00:28 +0000 (UTC) Received: from forward102p.mail.yandex.net (forward102p.mail.yandex.net [77.88.28.102]) by lists.linaro.org (Postfix) with ESMTPS id 6EF39616B9 for ; Sat, 13 Jan 2018 08:00:13 +0000 (UTC) Received: from mxback12g.mail.yandex.net (mxback12g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:91]) by forward102p.mail.yandex.net (Yandex) with ESMTP id 06D1B430428A for ; Sat, 13 Jan 2018 11:00:12 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback12g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Bk6v7e1CX1-0BX8ZrfA; Sat, 13 Jan 2018 11:00:12 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 8Hzdfi2ypg-0BYquNR7; Sat, 13 Jan 2018 11:00:11 +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: Sat, 13 Jan 2018 11:00:05 +0300 Message-Id: <1515830407-13301-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515830407-13301-1-git-send-email-odpbot@yandex.ru> References: <1515830407-13301-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 389 Subject: [lng-odp] [PATCH v2][WIP 5/7] linux-gen: chksum: separate checksumming function 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: Dmitry Eremin-Solenikov Separate main checksumming code, it will be used for packet checksum validation. Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 389 (lumag:parse-checksums) ** https://github.com/Linaro/odp/pull/389 ** Patch: https://github.com/Linaro/odp/pull/389.patch ** Base sha: 49ebafae0edebbc750742d8874ad0a7588286dea ** Merge commit sha: 29d9c9fa8235c01897c72e823b57525e37f896d3 **/ platform/linux-generic/Makefile.am | 1 + .../linux-generic/include/odp_chksum_internal.h | 59 ++++++++++++++++++++++ platform/linux-generic/odp_chksum.c | 18 ++----- 3 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 platform/linux-generic/include/odp_chksum_internal.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 7e40448bd..9c7563fb1 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -134,6 +134,7 @@ noinst_HEADERS = \ include/odp_bitmap_internal.h \ include/odp_bitset.h \ include/odp_buffer_internal.h \ + include/odp_chksum_internal.h \ include/odp_classification_datamodel.h \ include/odp_classification_inlines.h \ include/odp_classification_internal.h \ diff --git a/platform/linux-generic/include/odp_chksum_internal.h b/platform/linux-generic/include/odp_chksum_internal.h new file mode 100644 index 000000000..779598bbf --- /dev/null +++ b/platform/linux-generic/include/odp_chksum_internal.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP checksum - implementation internal + */ + +#ifndef ODP_CHKSUM_INTERNAL_H_ +#define ODP_CHKSUM_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Simple implementation of ones complement sum. + * Based on RFC1071 and its errata. + */ +static uint32_t _odp_chksum_ones_comp16_32(const void *p, uint32_t len, + odp_bool_t odd_offset) + +{ + uint32_t sum = 0; + const uint16_t *data = p; + + if (odd_offset) { + uint16_t left_over = 0; + + *(uint8_t *)&left_over = *(const uint8_t *)data; + sum = left_over; + data++; + len--; + } + + while (len > 1) { + sum += *data++; + len -= 2; + } + + /* Add left-over byte, if any */ + if (len > 0) { + uint16_t left_over = 0; + + *(uint8_t *)&left_over = *(const uint8_t *)data; + sum += left_over; + } + + return sum; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/odp_chksum.c b/platform/linux-generic/odp_chksum.c index a792971ef..484b2b0ae 100644 --- a/platform/linux-generic/odp_chksum.c +++ b/platform/linux-generic/odp_chksum.c @@ -7,26 +7,14 @@ #include #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 = 0; - - *(uint8_t *)&left_over = *(const uint8_t *)data; - sum += left_over; - } + uint32_t sum = _odp_chksum_ones_comp16_32(p, len, false); /* Fold 32-bit sum to 16 bits */ while (sum >> 16)