From patchwork Fri Dec 22 11:00:10 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: 122640 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2091358qgn; Fri, 22 Dec 2017 03:00:28 -0800 (PST) X-Google-Smtp-Source: ACJfBossey0dC035ct6d3z5jdqK0fz8MmnAj4BiqCtnws7nbZB7uCGPwnJH1VsW9I99n0FH+Yn+T X-Received: by 10.237.42.100 with SMTP id k33mr19362176qtf.222.1513940428420; Fri, 22 Dec 2017 03:00:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513940428; cv=none; d=google.com; s=arc-20160816; b=cc5t56oaivbvj9wpxK0/w+YjEryX2cn+UPLz4dRocp2hR+q68gEBjvyo+mLTkpWzQ+ fq1Bnu6PHzQlC2pF2A4BOrFXvQ6VN7nU9oT2qAps6Gd+JT4d6bnsskJjPSvM1B9KXXkO 6CBdOB2nSQ/KYRxtw09gEOlh4w9nTcWMTGMWjxXTPjcPG5THwtB/BQZd2M2RrEYQDsZo hIVh4lHObyB1mF1hXnRZUOZrITeCSeQizoAGOJ38EOrPSwFwvUZpjRVX+m7RCraPZd7d mZPn+xPROAPCv2Sddw55L26/0MCTqQNgaMslbiJYGitblXQ6N0Di1gRQdWXHOFZPiCtJ iYEw== 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=C/tBYVuGVE1yKvif8X5FMn1VS/I0+mudKu4JoCKxyho=; b=AXfh12HtAkQx1DI9aOSADCW2aN6s2vogtNJw3IX+5dSIKWS3yawRP93fpac5b5gx8v Tvu/LJXj5xJZ1AH4dlQaxbqgQe6IpFNlmfNZuu91Krz3vlgMnWZhfmk9+pz/fYJ9AccQ SDih5WYLBQ2QSMcMFNmGBBjOrOBK0z8uI5Yj6lYCp5+sjx/XonCgHEqO2BxM2MB4DFHL LdQEJvyr5kkMcjaOgjMpnyfGJEA/cRP4Iqn7fChjDCUNNaPe74WigXY6HRZcQHe3CD1R JeOCpPFzAKet83/9EquFZ4JtkwGUN6Yzrrbyl9D4fVuiveIVef5LYGil70A3yI5CcYur 2Shw== 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 u194si145522qka.471.2017.12.22.03.00.27; Fri, 22 Dec 2017 03:00:28 -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 927A26151D; Fri, 22 Dec 2017 11:00:27 +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 6597061504; Fri, 22 Dec 2017 11:00:20 +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 6974B61508; Fri, 22 Dec 2017 11:00:16 +0000 (UTC) Received: from forward104j.mail.yandex.net (forward104j.mail.yandex.net [5.45.198.247]) by lists.linaro.org (Postfix) with ESMTPS id EEE1A6096F for ; Fri, 22 Dec 2017 11:00:14 +0000 (UTC) Received: from mxback13j.mail.yandex.net (mxback13j.mail.yandex.net [IPv6:2a02:6b8:0:1619::88]) by forward104j.mail.yandex.net (Yandex) with ESMTP id 621CB430C6 for ; Fri, 22 Dec 2017 14:00:13 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback13j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id VVdGARCdp0-0Dd49V5K; Fri, 22 Dec 2017 14:00:13 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 5dFT3KYfjc-0CLuHvdk; Fri, 22 Dec 2017 14:00:12 +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: Fri, 22 Dec 2017 14:00:10 +0300 Message-Id: <1513940411-8696-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513940411-8696-1-git-send-email-odpbot@yandex.ru> References: <1513940411-8696-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 360 Subject: [lng-odp] [PATCH v2 1/2] linux-gen: packet: inline layer offsets 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 Inline L2/L3/L4 offset read functions. Always use the inlined version within the implementation itself. Signed-off-by: Petri Savolainen --- /** Email created from pull request 360 (psavol:master-packet-offset-inline) ** https://github.com/Linaro/odp/pull/360 ** Patch: https://github.com/Linaro/odp/pull/360.patch ** Base sha: 4c4052f894b8df5784d2aae2e36b96796ee020fd ** Merge commit sha: cc413d8b2e49b3b0093687631e61988b04afc917 **/ .../include/odp/api/plat/packet_inlines.h | 18 +++++++++++++++ .../include/odp/api/plat/packet_inlines_api.h | 15 +++++++++++++ .../include/odp/api/plat/packet_types.h | 6 +++++ platform/linux-generic/odp_packet.c | 26 +++------------------- platform/linux-generic/odp_traffic_mngr.c | 5 +++-- 5 files changed, 45 insertions(+), 25 deletions(-) diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h index c808f2d6f..aa9ba812f 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h @@ -108,6 +108,24 @@ static inline uint32_t _odp_packet_user_area_size(odp_packet_t pkt) return _odp_pool_get(pool, uint32_t, uarea_size); } +/** @internal Inline function @param pkt @return */ +static inline uint32_t _odp_packet_l2_offset(odp_packet_t pkt) +{ + return _odp_pkt_get(pkt, uint16_t, l2_offset); +} + +/** @internal Inline function @param pkt @return */ +static inline uint32_t _odp_packet_l3_offset(odp_packet_t pkt) +{ + return _odp_pkt_get(pkt, uint16_t, l3_offset); +} + +/** @internal Inline function @param pkt @return */ +static inline uint32_t _odp_packet_l4_offset(odp_packet_t pkt) +{ + return _odp_pkt_get(pkt, uint16_t, l4_offset); +} + /** @internal Inline function @param pkt @return */ static inline uint32_t _odp_packet_flow_hash(odp_packet_t pkt) { diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h index 233bc8761..84b4f08ab 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h @@ -68,6 +68,21 @@ _ODP_INLINE uint32_t odp_packet_user_area_size(odp_packet_t pkt) return _odp_packet_user_area_size(pkt); } +_ODP_INLINE uint32_t odp_packet_l2_offset(odp_packet_t pkt) +{ + return _odp_packet_l2_offset(pkt); +} + +_ODP_INLINE uint32_t odp_packet_l3_offset(odp_packet_t pkt) +{ + return _odp_packet_l3_offset(pkt); +} + +_ODP_INLINE uint32_t odp_packet_l4_offset(odp_packet_t pkt) +{ + return _odp_packet_l4_offset(pkt); +} + _ODP_INLINE uint32_t odp_packet_flow_hash(odp_packet_t pkt) { return _odp_packet_flow_hash(pkt); diff --git a/platform/linux-generic/include/odp/api/plat/packet_types.h b/platform/linux-generic/include/odp/api/plat/packet_types.h index 009a3aa7c..5b44c09c8 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_types.h +++ b/platform/linux-generic/include/odp/api/plat/packet_types.h @@ -94,6 +94,12 @@ typedef struct _odp_packet_inline_offset_t { /** @internal field offset */ uint16_t user_area; /** @internal field offset */ + uint16_t l2_offset; + /** @internal field offset */ + uint16_t l3_offset; + /** @internal field offset */ + uint16_t l4_offset; + /** @internal field offset */ uint16_t flow_hash; /** @internal field offset */ uint16_t timestamp; diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 04f1f33bb..3f0d764f6 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -37,6 +37,9 @@ const _odp_packet_inline_offset_t _odp_packet_inline ODP_ALIGNED_CACHE = { .segcount = offsetof(odp_packet_hdr_t, buf_hdr.segcount), .user_ptr = offsetof(odp_packet_hdr_t, buf_hdr.buf_ctx), .user_area = offsetof(odp_packet_hdr_t, buf_hdr.uarea_addr), + .l2_offset = offsetof(odp_packet_hdr_t, p.l2_offset), + .l3_offset = offsetof(odp_packet_hdr_t, p.l3_offset), + .l4_offset = offsetof(odp_packet_hdr_t, p.l4_offset), .flow_hash = offsetof(odp_packet_hdr_t, flow_hash), .timestamp = offsetof(odp_packet_hdr_t, timestamp), .input_flags = offsetof(odp_packet_hdr_t, p.input_flags) @@ -1213,15 +1216,6 @@ void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len) return packet_map(pkt_hdr, pkt_hdr->p.l2_offset, len, NULL); } -uint32_t odp_packet_l2_offset(odp_packet_t pkt) -{ - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - - if (!packet_hdr_has_l2(pkt_hdr)) - return ODP_PACKET_OFFSET_INVALID; - return pkt_hdr->p.l2_offset; -} - int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); @@ -1241,13 +1235,6 @@ void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len) return packet_map(pkt_hdr, pkt_hdr->p.l3_offset, len, NULL); } -uint32_t odp_packet_l3_offset(odp_packet_t pkt) -{ - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - - return pkt_hdr->p.l3_offset; -} - int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); @@ -1266,13 +1253,6 @@ void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len) return packet_map(pkt_hdr, pkt_hdr->p.l4_offset, len, NULL); } -uint32_t odp_packet_l4_offset(odp_packet_t pkt) -{ - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - - return pkt_hdr->p.l4_offset; -} - int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); diff --git a/platform/linux-generic/odp_traffic_mngr.c b/platform/linux-generic/odp_traffic_mngr.c index ab06b3c0d..e22a33f29 100644 --- a/platform/linux-generic/odp_traffic_mngr.c +++ b/platform/linux-generic/odp_traffic_mngr.c @@ -26,6 +26,7 @@ #include #include #include +#include /* Local vars */ static const @@ -1966,7 +1967,7 @@ static void egress_ipv4_tos_marking(tm_tos_marking_t *tos_marking, uint32_t hdr_len, l3_offset, old_chksum, ones_compl_sum, tos_diff; uint8_t old_tos, new_tos, ecn; - l3_offset = odp_packet_l3_offset(odp_pkt); + l3_offset = _odp_packet_l3_offset(odp_pkt); ipv4_hdr_ptr = odp_packet_l3_ptr(odp_pkt, &hdr_len); /* If the split_hdr variable below is TRUE, then this indicates that @@ -2032,7 +2033,7 @@ static void egress_ipv6_tc_marking(tm_tos_marking_t *tos_marking, uint32_t hdr_len, old_ver_tc_flow, new_ver_tc_flow, l3_offset; uint8_t old_tc, new_tc, ecn; - l3_offset = odp_packet_l3_offset(odp_pkt); + l3_offset = _odp_packet_l3_offset(odp_pkt); ipv6_hdr_ptr = odp_packet_l3_ptr(odp_pkt, &hdr_len); /* If the split_hdr variable below is TRUE, then this indicates that From patchwork Fri Dec 22 11:00:11 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: 122641 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2093012qgn; Fri, 22 Dec 2017 03:01:42 -0800 (PST) X-Google-Smtp-Source: ACJfBoviUiF4k+LwXu5nGiRl30JkWoILc0NKg3/VE7FJyi5gsm7lz/38fezuLsuYJ+hDSpe832r1 X-Received: by 10.55.110.69 with SMTP id j66mr18687708qkc.227.1513940502363; Fri, 22 Dec 2017 03:01:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513940502; cv=none; d=google.com; s=arc-20160816; b=yaTkd+HKQyPaVnAxEKnSgUtEWb/DbOIAmiv2QcDS/irFu7TRWOCIKL8v7J+kMi6oUx PFABaC8VH927ovL2IYFW3yzWe3B/1oiR5hz6qh/BCcfmz3YPWOtlwQFwUGD50ovWiheM 68OTA4ZeVO/4fTdofhECaJFjajwuI88gIcJPx3aIUCXzbgy0XNfT9PjEHCl95J3Xw43P U9D343St2IZxicPXczDKrzx8DtuxTuU+1+87RbVa/6OoEQhHOVMWfd4FvR1ZHShcjvlO QHRhlPTPA8FP9L0F6Y1H+Ff1vjb1qG3fd2PyzDWybcbT1X4f+k76SUTfu3Dv9/njkNif 2wKg== 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=HgkNKHEWy8IuoP+4Oi0j4e41cm9vm4HaFMc/F+TrqZY=; b=uoYl/zM8Hrh4I9+pK/bEtXL/kfG0tZYOv8VK5EQYGobX/718xsVd+HHdvoBml6/UHL UXt9ssDk43pyY/NBdmvVTpwvcjhLdje+mj6B/NrpgmXdulXX0rJLgnMsEgnFAcf/F/fi XsDJgtZGR0WfBoSB8bUf9luVrEGqHFnYeJst32iAzOFLRWhTMtOlrgQkB2bwVsYK1beG 0q5PAjYHKjdRwLfZ9d/O6qR4RB0FlIoJbb4LMtq7KAAIE3HkEECHX8ddk0nscCJ5kEt9 OXgkc5leAPkQ2XtfqK3WKKsA+X7Ph2R7GCucwqU7eVULM05SgoFxP8cfJ3cHAmyaXqCB AWIg== 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 u11si2231374qkl.1.2017.12.22.03.01.41; Fri, 22 Dec 2017 03:01:42 -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 D864B61720; Fri, 22 Dec 2017 11:01:41 +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 B1FC661514; Fri, 22 Dec 2017 11:00:25 +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 D73AA61504; Fri, 22 Dec 2017 11:00:18 +0000 (UTC) Received: from forward105o.mail.yandex.net (forward105o.mail.yandex.net [37.140.190.183]) by lists.linaro.org (Postfix) with ESMTPS id 1F5AF60997 for ; Fri, 22 Dec 2017 11:00:16 +0000 (UTC) Received: from mxback8j.mail.yandex.net (mxback8j.mail.yandex.net [IPv6:2a02:6b8:0:1619::111]) by forward105o.mail.yandex.net (Yandex) with ESMTP id 1C461444307B for ; Fri, 22 Dec 2017 14:00:14 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback8j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id uGzsulMI5a-0DxCxuPC; Fri, 22 Dec 2017 14:00:14 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 5dFT3KYfjc-0DLKKZ4M; Fri, 22 Dec 2017 14:00:13 +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: Fri, 22 Dec 2017 14:00:11 +0300 Message-Id: <1513940411-8696-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513940411-8696-1-git-send-email-odpbot@yandex.ru> References: <1513940411-8696-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 360 Subject: [lng-odp] [PATCH v2 2/2] linux-gen: packet: inline layer pointers 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 Inline L2/L3/L4 pointer functions. Packet map function is exported to backup the unlikely case when offset is not within the first segment. Always use the inlined version within the implementation itself. Signed-off-by: Petri Savolainen --- /** Email created from pull request 360 (psavol:master-packet-offset-inline) ** https://github.com/Linaro/odp/pull/360 ** Patch: https://github.com/Linaro/odp/pull/360.patch ** Base sha: 4c4052f894b8df5784d2aae2e36b96796ee020fd ** Merge commit sha: cc413d8b2e49b3b0093687631e61988b04afc917 **/ .../include/odp/api/plat/packet_inlines.h | 62 ++++++++++++++++++++++ .../include/odp/api/plat/packet_inlines_api.h | 15 ++++++ platform/linux-generic/odp_packet.c | 40 ++++++-------- platform/linux-generic/odp_traffic_mngr.c | 6 +-- 4 files changed, 95 insertions(+), 28 deletions(-) diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h index aa9ba812f..4314619ab 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h @@ -18,6 +18,11 @@ #include #include +/** @internal Inline function @param pkt_ptr @param offset @param seg_len + * @param seg_idx @return */ +void *_odp_packet_map(void *pkt_ptr, uint32_t offset, uint32_t *seg_len, + int *seg_idx); + /** @internal Inline function offsets */ extern const _odp_packet_inline_offset_t _odp_packet_inline; @@ -126,6 +131,63 @@ static inline uint32_t _odp_packet_l4_offset(odp_packet_t pkt) return _odp_pkt_get(pkt, uint16_t, l4_offset); } +/** @internal Inline function @param pkt @param len @return */ +static inline void *_odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len) +{ + uint32_t offset = _odp_packet_l2_offset(pkt); + uint32_t seg_len = _odp_packet_seg_len(pkt); + uint8_t *data = (uint8_t *)_odp_packet_data(pkt); + + if (odp_unlikely(offset >= seg_len)) { + void *pkt_hdr = (void *)pkt; + + return _odp_packet_map(pkt_hdr, offset, len, NULL); + } + + if (len) + *len = seg_len - offset; + + return data + offset; +} + +/** @internal Inline function @param pkt @param len @return */ +static inline void *_odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len) +{ + uint32_t offset = _odp_packet_l3_offset(pkt); + uint32_t seg_len = _odp_packet_seg_len(pkt); + uint8_t *data = (uint8_t *)_odp_packet_data(pkt); + + if (odp_unlikely(offset >= seg_len)) { + void *pkt_hdr = (void *)pkt; + + return _odp_packet_map(pkt_hdr, offset, len, NULL); + } + + if (len) + *len = seg_len - offset; + + return data + offset; +} + +/** @internal Inline function @param pkt @param len @return */ +static inline void *_odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len) +{ + uint32_t offset = _odp_packet_l4_offset(pkt); + uint32_t seg_len = _odp_packet_seg_len(pkt); + uint8_t *data = (uint8_t *)_odp_packet_data(pkt); + + if (odp_unlikely(offset >= seg_len)) { + void *pkt_hdr = (void *)pkt; + + return _odp_packet_map(pkt_hdr, offset, len, NULL); + } + + if (len) + *len = seg_len - offset; + + return data + offset; +} + /** @internal Inline function @param pkt @return */ static inline uint32_t _odp_packet_flow_hash(odp_packet_t pkt) { diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h index 84b4f08ab..c90a69c52 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h @@ -83,6 +83,21 @@ _ODP_INLINE uint32_t odp_packet_l4_offset(odp_packet_t pkt) return _odp_packet_l4_offset(pkt); } +_ODP_INLINE void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len) +{ + return _odp_packet_l2_ptr(pkt, len); +} + +_ODP_INLINE void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len) +{ + return _odp_packet_l3_ptr(pkt, len); +} + +_ODP_INLINE void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len) +{ + return _odp_packet_l4_ptr(pkt, len); +} + _ODP_INLINE uint32_t odp_packet_flow_hash(odp_packet_t pkt) { return _odp_packet_flow_hash(pkt); diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 3f0d764f6..446d8efaa 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -278,11 +278,12 @@ static inline void packet_seg_copy_md(odp_packet_hdr_t *dst, */ } -static inline void *packet_map(odp_packet_hdr_t *pkt_hdr, - uint32_t offset, uint32_t *seg_len, int *seg_idx) +static inline void *packet_map(void *pkt_ptr, uint32_t offset, + uint32_t *seg_len, int *seg_idx) { void *addr; uint32_t len; + odp_packet_hdr_t *pkt_hdr = pkt_ptr; int seg_id = 0; int seg_count = pkt_hdr->buf_hdr.segcount; @@ -323,6 +324,18 @@ static inline void *packet_map(odp_packet_hdr_t *pkt_hdr, return addr; } +#include + +/* This file uses the inlined version directly. Inlined API calls use this when + * offset does not point to the first segment. */ +void *_odp_packet_map(void *pkt_ptr, uint32_t offset, uint32_t *seg_len, + int *seg_idx) +{ + return packet_map(pkt_ptr, offset, seg_len, seg_idx); +} + +#include + void packet_parse_reset(odp_packet_hdr_t *pkt_hdr) { /* Reset parser metadata before new parse */ @@ -1207,15 +1220,6 @@ void odp_packet_user_ptr_set(odp_packet_t pkt, const void *ctx) packet_hdr(pkt)->buf_hdr.buf_cctx = ctx; } -void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len) -{ - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - - if (!packet_hdr_has_l2(pkt_hdr)) - return NULL; - return packet_map(pkt_hdr, pkt_hdr->p.l2_offset, len, NULL); -} - int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); @@ -1228,13 +1232,6 @@ int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset) return 0; } -void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len) -{ - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - - return packet_map(pkt_hdr, pkt_hdr->p.l3_offset, len, NULL); -} - int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); @@ -1246,13 +1243,6 @@ int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset) return 0; } -void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len) -{ - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - - return packet_map(pkt_hdr, pkt_hdr->p.l4_offset, len, NULL); -} - int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); diff --git a/platform/linux-generic/odp_traffic_mngr.c b/platform/linux-generic/odp_traffic_mngr.c index e22a33f29..556b2a1f2 100644 --- a/platform/linux-generic/odp_traffic_mngr.c +++ b/platform/linux-generic/odp_traffic_mngr.c @@ -1928,7 +1928,7 @@ static void egress_vlan_marking(tm_vlan_marking_t *vlan_marking, uint32_t hdr_len; uint16_t old_tci, new_tci; - ether_hdr_ptr = odp_packet_l2_ptr(odp_pkt, &hdr_len); + ether_hdr_ptr = _odp_packet_l2_ptr(odp_pkt, &hdr_len); vlan_hdr_ptr = (_odp_vlanhdr_t *)(ether_hdr_ptr + 1); /* If the split_hdr variable below is TRUE, then this indicates that @@ -1968,7 +1968,7 @@ static void egress_ipv4_tos_marking(tm_tos_marking_t *tos_marking, uint8_t old_tos, new_tos, ecn; l3_offset = _odp_packet_l3_offset(odp_pkt); - ipv4_hdr_ptr = odp_packet_l3_ptr(odp_pkt, &hdr_len); + ipv4_hdr_ptr = _odp_packet_l3_ptr(odp_pkt, &hdr_len); /* If the split_hdr variable below is TRUE, then this indicates that * for this odp (output) packet the IPv4 header is not all in the same @@ -2034,7 +2034,7 @@ static void egress_ipv6_tc_marking(tm_tos_marking_t *tos_marking, uint8_t old_tc, new_tc, ecn; l3_offset = _odp_packet_l3_offset(odp_pkt); - ipv6_hdr_ptr = odp_packet_l3_ptr(odp_pkt, &hdr_len); + ipv6_hdr_ptr = _odp_packet_l3_ptr(odp_pkt, &hdr_len); /* If the split_hdr variable below is TRUE, then this indicates that * for this odp (output) packet the IPv6 header is not all in the same