From patchwork Thu Dec 21 16:00:09 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: 122577 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1076185qgn; Thu, 21 Dec 2017 08:02:57 -0800 (PST) X-Google-Smtp-Source: ACJfBouuu2Dra8l39bQptEqKUjCAFPxzTRvmLNzkMLVO6zHB1qR9rORrPJdtXbioZ2knOMXHrJrc X-Received: by 10.13.219.66 with SMTP id d63mr7538978ywe.347.1513872177296; Thu, 21 Dec 2017 08:02:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513872177; cv=none; d=google.com; s=arc-20160816; b=jY5qODyePPLoVuU7sV1KAdk+p/8HBX8LnJSb8tlup/MAVvqUNVZq1D7YwJFukF40u6 lekndz1DQdvEYrMu+9GYzJGMUwINd98C9S1fnyVRCM7y5VAuCb+83OGMc6RWkC6YFhZZ pza8T3yvTnQ+ML2uJqi8K4ep+0SKKJxeY5pyIhgfnLsmOHXciKwOWDB2Z9XxidUOUdy1 Sg+2FmElRojpy5JsPCh14FWAWHHQNagtDI8mB9aJ7VkoUWTvldKJCJ4zo3MnCjlDu3I1 Fy+iZcnb+xldXNmRwjG49KYU7RiqGt2uRybgYmpcU658lOWqJrI8lcwJlaPK64KNEIJf jjjg== 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=zwGnFImIHIiV2SIsE/4p2dK7DVPvTGZjC9FAO4fAKUY=; b=EW4rdsNJ6YbOwOQ+jhEbMqOY8oDcDgJqTv/KF7n2OFfZLCJcEZuhqtU5273DjC8k+D 80i4JiE+Gq08PoEW4z63P0wcmuvs6sQGGURJCpuGJDO9A22nAsJxza1G0EhnJ7EsNs98 6K1O9pQundNY534I4USuiZWUVBN4kEtfTOG2IvzjoDxolc5cHuLKMZbY4uQAHW2jUYz5 MxjKrUPq8T+u3Wp25IAVdFodaSZJvh81/1mrUUejUs/nuuLO1/nld0JWVLM0PsBMJ+Gd 4krdauZMQEd7IGkUqjybkweD3k0CG8JNXS2OLv29WSd00egjYvoiqanvHF9DPCJYocF9 3PGg== 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 b82si6420673qkc.477.2017.12.21.08.02.54; Thu, 21 Dec 2017 08:02:57 -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 74E3460975; Thu, 21 Dec 2017 16:02:54 +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, 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 7E3E860B11; Thu, 21 Dec 2017 16:01:16 +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 6B0556099A; Thu, 21 Dec 2017 16:01:07 +0000 (UTC) Received: from forward105o.mail.yandex.net (forward105o.mail.yandex.net [37.140.190.183]) by lists.linaro.org (Postfix) with ESMTPS id 37BAB609A2 for ; Thu, 21 Dec 2017 16:00:14 +0000 (UTC) Received: from mxback15g.mail.yandex.net (mxback15g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:94]) by forward105o.mail.yandex.net (Yandex) with ESMTP id 9B146444278B for ; Thu, 21 Dec 2017 19:00:12 +0300 (MSK) Received: from smtp3o.mail.yandex.net (smtp3o.mail.yandex.net [2a02:6b8:0:1a2d::27]) by mxback15g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id fImQtcFDb1-0CSSuVOI; Thu, 21 Dec 2017 19:00:12 +0300 Received: by smtp3o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9thSdAwhh7-0B7mGamn; Thu, 21 Dec 2017 19: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: Thu, 21 Dec 2017 19:00:09 +0300 Message-Id: <1513872010-2747-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513872010-2747-1-git-send-email-odpbot@yandex.ru> References: <1513872010-2747-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 360 Subject: [lng-odp] [PATCH v1 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: 3c02836d9d9ca16b1277bdd30e523779b9fe8374 ** Merge commit sha: 8a43dcccb105ee32ad867e39b8763d77c37b331e **/ .../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 Thu Dec 21 16: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: 122578 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1077956qgn; Thu, 21 Dec 2017 08:04:07 -0800 (PST) X-Google-Smtp-Source: ACJfBosBLkqr+yrDWu3kDreoYjlNiJW8BUeXSm5mGkDkRwJzt0vUkrumoJXgiOoV/en+PmL7HNMF X-Received: by 10.200.54.198 with SMTP id b6mr15466219qtc.48.1513872247470; Thu, 21 Dec 2017 08:04:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513872247; cv=none; d=google.com; s=arc-20160816; b=WQ1qPH57/tKE3WnadIv4XEC4awE7PGwQxvq/SoFgUIfuSwpZz6zy3caMCPtKvQrY8o 8LdXHWI2xQ1Y/A4xClTo7o5Ka2XK066BC1fbIszupmAwAyy8c/f4AD0CGdTbEkTrbudV QVMgtus/91K0gPAE/2Eg1Nlm+EQUwsORp5/aj6AIN1yPWZ0ZQtRJhD4M8x664+3TYU9M idlJPjnnULTJ85hnLtaDaZvVN+o0+1E7JfJyej6ezDgL/MlHk2RGOzzHmfZR2qXI4niq zXCAK3RCWquPjnr2hWgKauQJ6fZA5d1sdu+I5jQU6ywXe3l6DyInbWOSecipRVcqLUhd tuSw== 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=/FO1K7E9Yskz4irkRm6gsHTRa2/5MdVmeiJwFpG2pS0=; b=SDLoObUgu0/Oc+tVX2Qo092XqN7CG3q296TrDM+/1z/4A2vvQqoydFCs/gWg1+r6uB Wkr3diRoG3mgRFt9D8pcT2U5GfKG+UBeltEXC0djN2ohAN4w+c2NW2WDUrWDgff2CSA9 tEKGWHmSK/91Ab6yvnQq2/e91PYGxbAVxHHkD9oPd0kVrNqej9BJ4thZU2RuNxdh5xHs KUtepX5SKXBM666NQMEKJMyIHEkhiac7PtbOhYi6EriVS1zvyr4sgLsnDjrXO0eNU4Ot OwNSmfRshvpptn+RxfVp9LTe4GLMGhOGWIsxM+m1aJc3+4+NIZTL8cdeAz7tluSaG3LS CpaQ== 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 a41si1652556qte.405.2017.12.21.08.04.01; Thu, 21 Dec 2017 08:04:07 -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 980936150F; Thu, 21 Dec 2017 16:04:01 +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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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 BA26460C5E; Thu, 21 Dec 2017 16:01: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 AD2FD609A2; Thu, 21 Dec 2017 16:01:07 +0000 (UTC) Received: from forward103j.mail.yandex.net (forward103j.mail.yandex.net [5.45.198.246]) by lists.linaro.org (Postfix) with ESMTPS id C0F7160B0E for ; Thu, 21 Dec 2017 16:00:14 +0000 (UTC) Received: from mxback19j.mail.yandex.net (mxback19j.mail.yandex.net [IPv6:2a02:6b8:0:1619::95]) by forward103j.mail.yandex.net (Yandex) with ESMTP id 51C6434C4BAD for ; Thu, 21 Dec 2017 19:00:13 +0300 (MSK) Received: from smtp3o.mail.yandex.net (smtp3o.mail.yandex.net [2a02:6b8:0:1a2d::27]) by mxback19j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id YzbmH13gq1-0DsGe5b3; Thu, 21 Dec 2017 19:00:13 +0300 Received: by smtp3o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 9thSdAwhh7-0C7akdGP; Thu, 21 Dec 2017 19: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: Thu, 21 Dec 2017 19:00:10 +0300 Message-Id: <1513872010-2747-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513872010-2747-1-git-send-email-odpbot@yandex.ru> References: <1513872010-2747-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 360 Subject: [lng-odp] [PATCH v1 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: 3c02836d9d9ca16b1277bdd30e523779b9fe8374 ** Merge commit sha: 8a43dcccb105ee32ad867e39b8763d77c37b331e **/ .../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..2ace0ca37 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..0f4d32818 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 + * packet seg_len < offset. */ +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