From patchwork Thu Feb 9 11:53:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 93695 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp208744qgi; Thu, 9 Feb 2017 03:56:59 -0800 (PST) X-Received: by 10.237.37.165 with SMTP id x34mr2244195qtc.218.1486641419612; Thu, 09 Feb 2017 03:56:59 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 12si7802974qtq.202.2017.02.09.03.56.59; Thu, 09 Feb 2017 03:56:59 -0800 (PST) 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 42ECE62EB2; Thu, 9 Feb 2017 11:56:59 +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, 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 9BA40634CE; Thu, 9 Feb 2017 11:54: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 46E9A62C7E; Thu, 9 Feb 2017 11:54:05 +0000 (UTC) Received: from mail-ot0-f181.google.com (mail-ot0-f181.google.com [74.125.82.181]) by lists.linaro.org (Postfix) with ESMTPS id A671F62C80 for ; Thu, 9 Feb 2017 11:53:59 +0000 (UTC) Received: by mail-ot0-f181.google.com with SMTP id f9so977723otd.1 for ; Thu, 09 Feb 2017 03:53:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cw86PMZKpykwM+YpoMt1ERPPKr5Srcd46D3orxPGgcc=; b=Rl+CDrgr5FYmCcK6VOU2OA+PAsN+spvCxR4nbklEssL0o76uyE7XXEWwuBY8M0fRLp OSSIYj0VvmHWPIRpXQI6d4MTZXOEo/f36Z3VewIzSerBkjQD+yBy9HARbpIoSXwXioDQ bdHs+lyB57MzI2q7CcVKp10ukM/H+9dIE6wW1MAfn/wlqYq7gOjYSNQZadMmwAHY2Pzj iMG3R4H89DvOgGZ4RGyjX4SGuEUhK4CtCxO0mMgY8UTgJCNcn9aCTEXtkqXLVJ9ImTK8 FKSvhttXSejm9Bwr5AIEUZ8IxhK2WcmPYJeBbvmlEzJCQyoTUKJCt1ynvMbA5TaUdfwm ht/Q== X-Gm-Message-State: AMke39m2DRiHzCCdB2KtobESwscZyUf93yBoS0ratq625yvQwapScwzULT2x83UDnR4e6xuOm8g= X-Received: by 10.157.15.220 with SMTP id m28mr1273042otd.67.1486641239015; Thu, 09 Feb 2017 03:53:59 -0800 (PST) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id t53sm5767383otd.6.2017.02.09.03.53.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Feb 2017 03:53:58 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 9 Feb 2017 05:53:50 -0600 Message-Id: <20170209115352.16271-4-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.11.0.295.gd7dffce In-Reply-To: <20170209115352.16271-1-bill.fischofer@linaro.org> References: <20170209115352.16271-1-bill.fischofer@linaro.org> Cc: Petri Savolainen Subject: [lng-odp] [API-NEXT PATCHv3 3/5] linux-gen: packet: packet handle is hdr pointer 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 Changed packet handle (odp_packet_t) to store pointer to the packet header, instead a bit field structure of pool and index. Buffer and event handles are not changed. Pointer as handle improves packet accessor function performance and enable accessor function inlining as mapping to pool/index is not needed. Signed-off-by: Petri Savolainen Signed-off-by: Bill Fischofer --- .../include/odp/api/plat/packet_types.h | 2 +- .../linux-generic/include/odp_packet_internal.h | 17 +- platform/linux-generic/odp_packet.c | 175 ++++++++++++--------- 3 files changed, 106 insertions(+), 88 deletions(-) -- 2.11.0.295.gd7dffce 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 34e5dd81..999130ec 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_types.h +++ b/platform/linux-generic/include/odp/api/plat/packet_types.h @@ -32,7 +32,7 @@ extern "C" { typedef ODP_HANDLE_T(odp_packet_t); -#define ODP_PACKET_INVALID _odp_cast_scalar(odp_packet_t, 0xffffffff) +#define ODP_PACKET_INVALID _odp_cast_scalar(odp_packet_t, 0) #define ODP_PACKET_OFFSET_INVALID (0x0fffffff) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 42df5ac8..d1c6d456 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -217,11 +217,11 @@ typedef struct odp_packet_hdr_t { */ static inline odp_packet_hdr_t *odp_packet_hdr(odp_packet_t pkt) { - return (odp_packet_hdr_t *)buf_hdl_to_hdr((odp_buffer_t)pkt); + return (odp_packet_hdr_t *)(uintptr_t)pkt; } -static inline odp_packet_hdr_t *odp_packet_last_hdr(odp_packet_t pkt, - uint32_t *offset) +static inline odp_packet_hdr_t *packet_last_hdr(odp_packet_t pkt, + uint32_t *offset) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); odp_packet_hdr_t *prev_hdr = pkt_hdr; @@ -242,9 +242,9 @@ static inline odp_packet_hdr_t *odp_packet_last_hdr(odp_packet_t pkt, return pkt_hdr; } -static inline odp_packet_hdr_t *odp_packet_prev_hdr(odp_packet_hdr_t *pkt_hdr, - odp_packet_hdr_t *cur_hdr, - uint32_t *offset) +static inline odp_packet_hdr_t *packet_prev_hdr(odp_packet_hdr_t *pkt_hdr, + odp_packet_hdr_t *cur_hdr, + uint32_t *offset) { uint32_t ref_offset = 0; odp_packet_hdr_t *prev_hdr = pkt_hdr; @@ -264,11 +264,6 @@ static inline odp_packet_hdr_t *odp_packet_prev_hdr(odp_packet_hdr_t *pkt_hdr, return pkt_hdr; } -static inline odp_packet_t _odp_packet_hdl(odp_packet_hdr_t *pkt_hdr) -{ - return (odp_packet_t)odp_hdr_to_buf(&pkt_hdr->buf_hdr); -} - static inline void copy_packet_parser_metadata(odp_packet_hdr_t *src_hdr, odp_packet_hdr_t *dst_hdr) { diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 4aa99cdd..cfed3d9b 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -23,9 +23,14 @@ /* Initial packet segment data length */ #define BASE_LEN CONFIG_PACKET_MAX_SEG_LEN +static inline odp_packet_hdr_t *packet_hdr(odp_packet_t pkt) +{ + return (odp_packet_hdr_t *)(uintptr_t)pkt; +} + static inline odp_packet_t packet_handle(odp_packet_hdr_t *pkt_hdr) { - return (odp_packet_t)pkt_hdr->buf_hdr.handle.handle; + return (odp_packet_t)pkt_hdr; } static inline odp_buffer_t buffer_handle(odp_packet_hdr_t *pkt_hdr) @@ -43,6 +48,11 @@ static inline uint32_t packet_ref_dec(odp_packet_hdr_t *pkt_hdr) return odp_atomic_fetch_dec_u32(&pkt_hdr->ref_count); } +static inline odp_packet_hdr_t *buf_to_packet_hdr(odp_buffer_t buf) +{ + return (odp_packet_hdr_t *)buf_hdl_to_hdr(buf); +} + static inline uint32_t packet_seg_len(odp_packet_hdr_t *pkt_hdr, uint32_t seg_idx) { @@ -534,8 +544,8 @@ static inline int packet_alloc(pool_t *pool, uint32_t len, int max_pkt, odp_packet_hdr_t *hdr; /* First buffer is the packet descriptor */ - pkt[i] = (odp_packet_t)buf[i * num_seg]; hdr = pkt_hdr[i * num_seg]; + pkt[i] = packet_handle(hdr); init_segments(&pkt_hdr[i * num_seg], num_seg); packet_init(hdr, len, parse); @@ -669,7 +679,7 @@ static inline void packet_free(odp_packet_hdr_t *pkt_hdr) void odp_packet_free(odp_packet_t pkt) { - packet_free(odp_packet_hdr(pkt)); + packet_free(packet_hdr(pkt)); } void odp_packet_free_multi(const odp_packet_t pkt[], int num) @@ -678,7 +688,7 @@ void odp_packet_free_multi(const odp_packet_t pkt[], int num) odp_buffer_t buf[nbufs]; int nfree = 0; int i = 0; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt[0]); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt[0]); uint32_t pool_id = pool_id_from_buf(pkt_hdr->buf_hdr.handle.handle); uint32_t next_pool; @@ -694,7 +704,7 @@ void odp_packet_free_multi(const odp_packet_t pkt[], int num) if (++i == num) break; - pkt_hdr = odp_packet_hdr(pkt[i]); + pkt_hdr = packet_hdr(pkt[i]); next_pool = pool_id_from_buf(pkt_hdr->buf_hdr.handle.handle); if (odp_unlikely(next_pool != pool_id)) { @@ -712,7 +722,7 @@ void odp_packet_free_multi(const odp_packet_t pkt[], int num) int odp_packet_reset(odp_packet_t pkt, uint32_t len) { - odp_packet_hdr_t *const pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *const pkt_hdr = packet_hdr(pkt); pool_t *pool = pool_entry_from_hdl(pkt_hdr->buf_hdr.pool_hdl); if (len > pool->headroom + pool->data_size + pool->tailroom) @@ -728,22 +738,34 @@ int odp_packet_reset(odp_packet_t pkt, uint32_t len) odp_packet_t _odp_packet_from_buffer(odp_buffer_t buf) { - return (odp_packet_t)buf; + if (odp_unlikely(buf == ODP_BUFFER_INVALID)) + return ODP_PACKET_INVALID; + + return (odp_packet_t)buf_to_packet_hdr(buf); } odp_buffer_t _odp_packet_to_buffer(odp_packet_t pkt) { - return (odp_buffer_t)pkt; + if (odp_unlikely(pkt == ODP_PACKET_INVALID)) + return ODP_BUFFER_INVALID; + + return buffer_handle(packet_hdr(pkt)); } odp_packet_t odp_packet_from_event(odp_event_t ev) { - return (odp_packet_t)ev; + if (odp_unlikely(ev == ODP_EVENT_INVALID)) + return ODP_PACKET_INVALID; + + return (odp_packet_t)buf_to_packet_hdr((odp_buffer_t)ev); } odp_event_t odp_packet_to_event(odp_packet_t pkt) { - return (odp_event_t)pkt; + if (odp_unlikely(pkt == ODP_PACKET_INVALID)) + return ODP_EVENT_INVALID; + + return (odp_event_t)buffer_handle(packet_hdr(pkt)); } /* @@ -755,14 +777,14 @@ odp_event_t odp_packet_to_event(odp_packet_t pkt) void *odp_packet_head(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return pkt_hdr->buf_hdr.seg[0].data - pkt_hdr->headroom; } uint32_t odp_packet_buf_len(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); uint32_t buf_len = 0; do { @@ -775,26 +797,26 @@ uint32_t odp_packet_buf_len(odp_packet_t pkt) void *odp_packet_data(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return packet_map(pkt_hdr, 0, NULL, NULL); } uint32_t odp_packet_seg_len(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return packet_first_seg_len(pkt_hdr); } uint32_t odp_packet_len(odp_packet_t pkt) { - return packet_len(odp_packet_hdr(pkt)); + return packet_len(packet_hdr(pkt)); } uint32_t odp_packet_unshared_len(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); uint32_t pkt_len = 0, offset = 0; do { @@ -819,24 +841,24 @@ uint32_t odp_packet_unshared_len(odp_packet_t pkt) uint32_t odp_packet_headroom(odp_packet_t pkt) { - return odp_packet_hdr(pkt)->headroom; + return packet_hdr(pkt)->headroom; } uint32_t odp_packet_tailroom(odp_packet_t pkt) { - return odp_packet_last_hdr(pkt, NULL)->tailroom; + return packet_last_hdr(pkt, NULL)->tailroom; } void *odp_packet_tail(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_last_hdr(pkt, NULL); + odp_packet_hdr_t *pkt_hdr = packet_last_hdr(pkt, NULL); return packet_tail(pkt_hdr); } void *odp_packet_push_head(odp_packet_t pkt, uint32_t len) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (len > pkt_hdr->headroom) return NULL; @@ -1021,7 +1043,7 @@ static inline void reset_seg(odp_packet_hdr_t *pkt_hdr, int first, int num) int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len, void **data_ptr, uint32_t *seg_len) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(*pkt); uint32_t frame_len = pkt_hdr->frame_len; uint32_t headroom = pkt_hdr->headroom; int ret = 0; @@ -1171,7 +1193,7 @@ int odp_packet_extend_head(odp_packet_t *pkt, uint32_t len, void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (len > pkt_hdr->frame_len) return NULL; @@ -1185,7 +1207,7 @@ void *odp_packet_pull_head(odp_packet_t pkt, uint32_t len) int odp_packet_trunc_head(odp_packet_t *pkt, uint32_t len, void **data_ptr, uint32_t *seg_len_out) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt), *nxt_hdr; + odp_packet_hdr_t *pkt_hdr = packet_hdr(*pkt), *nxt_hdr; uint32_t seg_len = packet_first_seg_len(pkt_hdr); int ret = 0; @@ -1243,7 +1265,7 @@ int odp_packet_trunc_head(odp_packet_t *pkt, uint32_t len, void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len) { - odp_packet_hdr_t *pkt_hdr = odp_packet_last_hdr(pkt, NULL); + odp_packet_hdr_t *pkt_hdr = packet_last_hdr(pkt, NULL); void *old_tail; if (len > pkt_hdr->tailroom) @@ -1260,7 +1282,7 @@ void *odp_packet_push_tail(odp_packet_t pkt, uint32_t len) int odp_packet_extend_tail(odp_packet_t *pkt, uint32_t len, void **data_ptr, uint32_t *seg_len_out) { - odp_packet_hdr_t *pkt_hdr = odp_packet_last_hdr(*pkt, NULL); + odp_packet_hdr_t *pkt_hdr = packet_last_hdr(*pkt, NULL); uint32_t frame_len = pkt_hdr->frame_len; uint32_t tailroom = pkt_hdr->tailroom; uint32_t tail_off = frame_len; @@ -1353,7 +1375,7 @@ int odp_packet_extend_tail(odp_packet_t *pkt, uint32_t len, void *odp_packet_pull_tail(odp_packet_t pkt, uint32_t len) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (len > packet_last_seg_len(pkt_hdr)) return NULL; @@ -1370,18 +1392,18 @@ int odp_packet_trunc_tail(odp_packet_t *pkt, uint32_t len, int last; uint32_t seg_len; uint32_t offset; - odp_packet_hdr_t *first_hdr = odp_packet_hdr(*pkt); + odp_packet_hdr_t *first_hdr = packet_hdr(*pkt); odp_packet_hdr_t *pkt_hdr, *prev_hdr; if (len > packet_len(first_hdr)) return -1; - pkt_hdr = odp_packet_last_hdr(*pkt, &offset); + pkt_hdr = packet_last_hdr(*pkt, &offset); /* Special processing for references */ while (len >= pkt_hdr->frame_len - offset && first_hdr->ref_hdr) { len -= (pkt_hdr->frame_len - offset); - prev_hdr = odp_packet_prev_hdr(first_hdr, pkt_hdr, &offset); + prev_hdr = packet_prev_hdr(first_hdr, pkt_hdr, &offset); ODP_ASSERT(packet_ref_count(prev_hdr) == 1); prev_hdr->ref_hdr = NULL; packet_free(pkt_hdr); @@ -1421,7 +1443,7 @@ void *odp_packet_offset(odp_packet_t pkt, uint32_t offset, uint32_t *len, odp_packet_seg_t *seg) { int seg_idx; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); void *addr = packet_map(pkt_hdr, offset, len, &seg_idx); if (addr != NULL && seg != NULL) @@ -1446,42 +1468,42 @@ void odp_packet_prefetch(odp_packet_t pkt ODP_UNUSED, odp_pool_t odp_packet_pool(odp_packet_t pkt) { - return odp_packet_hdr(pkt)->buf_hdr.pool_hdl; + return packet_hdr(pkt)->buf_hdr.pool_hdl; } odp_pktio_t odp_packet_input(odp_packet_t pkt) { - return odp_packet_hdr(pkt)->input; + return packet_hdr(pkt)->input; } int odp_packet_input_index(odp_packet_t pkt) { - return odp_pktio_index(odp_packet_hdr(pkt)->input); + return odp_pktio_index(packet_hdr(pkt)->input); } void *odp_packet_user_ptr(odp_packet_t pkt) { - return odp_packet_hdr(pkt)->buf_hdr.buf_ctx; + return packet_hdr(pkt)->buf_hdr.buf_ctx; } void odp_packet_user_ptr_set(odp_packet_t pkt, const void *ctx) { - odp_packet_hdr(pkt)->buf_hdr.buf_cctx = ctx; + packet_hdr(pkt)->buf_hdr.buf_cctx = ctx; } void *odp_packet_user_area(odp_packet_t pkt) { - return odp_packet_hdr(pkt)->buf_hdr.uarea_addr; + return packet_hdr(pkt)->buf_hdr.uarea_addr; } uint32_t odp_packet_user_area_size(odp_packet_t pkt) { - return odp_packet_hdr(pkt)->buf_hdr.uarea_size; + return packet_hdr(pkt)->buf_hdr.uarea_size; } void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (!packet_hdr_has_l2(pkt_hdr)) return NULL; @@ -1490,7 +1512,7 @@ void *odp_packet_l2_ptr(odp_packet_t pkt, uint32_t *len) uint32_t odp_packet_l2_offset(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (!packet_hdr_has_l2(pkt_hdr)) return ODP_PACKET_OFFSET_INVALID; @@ -1499,7 +1521,7 @@ uint32_t odp_packet_l2_offset(odp_packet_t pkt) int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (offset >= pkt_hdr->frame_len) return -1; @@ -1511,7 +1533,7 @@ int odp_packet_l2_offset_set(odp_packet_t pkt, uint32_t offset) void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (pkt_hdr->p.parsed_layers < LAYER_L3) packet_parse_layer(pkt_hdr, LAYER_L3); @@ -1520,7 +1542,7 @@ void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len) uint32_t odp_packet_l3_offset(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (pkt_hdr->p.parsed_layers < LAYER_L3) packet_parse_layer(pkt_hdr, LAYER_L3); @@ -1529,7 +1551,7 @@ uint32_t odp_packet_l3_offset(odp_packet_t pkt) int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (offset >= pkt_hdr->frame_len) return -1; @@ -1542,7 +1564,7 @@ int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset) void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (pkt_hdr->p.parsed_layers < LAYER_L4) packet_parse_layer(pkt_hdr, LAYER_L4); @@ -1551,7 +1573,7 @@ void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len) uint32_t odp_packet_l4_offset(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (pkt_hdr->p.parsed_layers < LAYER_L4) packet_parse_layer(pkt_hdr, LAYER_L4); @@ -1560,7 +1582,7 @@ uint32_t odp_packet_l4_offset(odp_packet_t pkt) int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (offset >= pkt_hdr->frame_len) return -1; @@ -1573,14 +1595,14 @@ int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset) uint32_t odp_packet_flow_hash(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return pkt_hdr->flow_hash; } void odp_packet_flow_hash_set(odp_packet_t pkt, uint32_t flow_hash) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); pkt_hdr->flow_hash = flow_hash; pkt_hdr->p.input_flags.flow_hash = 1; @@ -1588,14 +1610,14 @@ void odp_packet_flow_hash_set(odp_packet_t pkt, uint32_t flow_hash) odp_time_t odp_packet_ts(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return pkt_hdr->timestamp; } void odp_packet_ts_set(odp_packet_t pkt, odp_time_t timestamp) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); pkt_hdr->timestamp = timestamp; pkt_hdr->p.input_flags.timestamp = 1; @@ -1603,14 +1625,14 @@ void odp_packet_ts_set(odp_packet_t pkt, odp_time_t timestamp) int odp_packet_is_segmented(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return pkt_hdr->buf_hdr.segcount > 1 || pkt_hdr->ref_hdr != NULL; } int odp_packet_num_segs(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); uint32_t segcount = 0, i; uint32_t seg_offset = 0, offset; @@ -1644,7 +1666,7 @@ odp_packet_seg_t odp_packet_last_seg(odp_packet_t pkt) odp_packet_seg_t odp_packet_next_seg(odp_packet_t pkt, odp_packet_seg_t seg) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (odp_unlikely(seg >= packet_last_seg(pkt_hdr))) return ODP_PACKET_SEG_INVALID; @@ -1661,7 +1683,7 @@ odp_packet_seg_t odp_packet_next_seg(odp_packet_t pkt, odp_packet_seg_t seg) void *odp_packet_seg_data(odp_packet_t pkt, odp_packet_seg_t seg) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); uint32_t seg_offset = 0, offset = 0, i; while (seg >= pkt_hdr->buf_hdr.segcount - seg_offset && @@ -1686,7 +1708,7 @@ void *odp_packet_seg_data(odp_packet_t pkt, odp_packet_seg_t seg) uint32_t odp_packet_seg_data_len(odp_packet_t pkt, odp_packet_seg_t seg) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); uint32_t seg_offset = 0, offset = 0, i; while (seg >= pkt_hdr->buf_hdr.segcount - seg_offset && @@ -1719,7 +1741,7 @@ uint32_t odp_packet_seg_data_len(odp_packet_t pkt, odp_packet_seg_t seg) int odp_packet_add_data(odp_packet_t *pkt_ptr, uint32_t offset, uint32_t len) { odp_packet_t pkt = *pkt_ptr; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); uint32_t pktlen = packet_len(pkt_hdr); odp_packet_t newpkt; @@ -1750,7 +1772,7 @@ int odp_packet_add_data(odp_packet_t *pkt_ptr, uint32_t offset, uint32_t len) int odp_packet_rem_data(odp_packet_t *pkt_ptr, uint32_t offset, uint32_t len) { odp_packet_t pkt = *pkt_ptr; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); uint32_t pktlen = pkt_hdr->frame_len; odp_packet_t newpkt; @@ -1782,7 +1804,7 @@ int odp_packet_align(odp_packet_t *pkt, uint32_t offset, uint32_t len, int rc; uint32_t shift; uint32_t seglen = 0; /* GCC */ - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(*pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(*pkt); void *addr = packet_map(pkt_hdr, offset, &seglen, NULL); uint64_t uaddr = (uint64_t)(uintptr_t)addr; uint64_t misalign; @@ -1822,8 +1844,8 @@ int odp_packet_align(odp_packet_t *pkt, uint32_t offset, uint32_t len, int odp_packet_concat(odp_packet_t *dst, odp_packet_t src) { - odp_packet_hdr_t *dst_hdr = odp_packet_hdr(*dst); - odp_packet_hdr_t *src_hdr = odp_packet_hdr(src); + odp_packet_hdr_t *dst_hdr = packet_hdr(*dst); + odp_packet_hdr_t *src_hdr = packet_hdr(src); int dst_segs = dst_hdr->buf_hdr.segcount; int src_segs = src_hdr->buf_hdr.segcount; odp_pool_t dst_pool = dst_hdr->buf_hdr.pool_hdl; @@ -1922,12 +1944,12 @@ static inline odp_packet_t packet_splice(odp_packet_hdr_t *pkt_hdr, pkt_hdr->unshared_len = offset; packet_ref(pkt_hdr); - return _odp_packet_hdl(ref_hdr); + return packet_handle(ref_hdr); } odp_packet_t odp_packet_ref_static(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); pkt_hdr->unshared_len = 0; packet_ref(pkt_hdr); @@ -1942,7 +1964,7 @@ odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) if (pkt == ODP_PACKET_INVALID) return ODP_PACKET_INVALID; - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); if (offset >= packet_len(pkt_hdr)) return ODP_PACKET_INVALID; @@ -1951,7 +1973,7 @@ odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t offset) if (hdr == ODP_PACKET_INVALID) return ODP_PACKET_INVALID; - return packet_splice(pkt_hdr, offset, odp_packet_hdr(hdr)); + return packet_splice(pkt_hdr, offset, packet_hdr(hdr)); } odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, @@ -1966,16 +1988,16 @@ odp_packet_t odp_packet_ref_pkt(odp_packet_t pkt, uint32_t offset, ODP_ASSERT(odp_packet_has_ref(hdr) == 0); - pkt_hdr = odp_packet_hdr(pkt); + pkt_hdr = packet_hdr(pkt); if (offset >= packet_len(pkt_hdr)) return ODP_PACKET_INVALID; - return packet_splice(pkt_hdr, offset, odp_packet_hdr(hdr)); + return packet_splice(pkt_hdr, offset, packet_hdr(hdr)); } int odp_packet_has_ref(odp_packet_t pkt) { - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); return pkt_hdr->ref_hdr != NULL || packet_ref_count(pkt_hdr) > 1; } @@ -2026,7 +2048,7 @@ int odp_packet_copy_to_mem(odp_packet_t pkt, uint32_t offset, uint32_t seglen = 0; /* GCC */ uint32_t cpylen; uint8_t *dstaddr = (uint8_t *)dst; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (offset + len > packet_len(pkt_hdr)) return -1; @@ -2050,7 +2072,7 @@ int odp_packet_copy_from_mem(odp_packet_t pkt, uint32_t offset, uint32_t seglen = 0; /* GCC */ uint32_t cpylen; const uint8_t *srcaddr = (const uint8_t *)src; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); if (offset + len > packet_len(pkt_hdr)) return -1; @@ -2073,8 +2095,8 @@ int odp_packet_copy_from_pkt(odp_packet_t dst, uint32_t dst_offset, odp_packet_t src, uint32_t src_offset, uint32_t len) { - odp_packet_hdr_t *dst_hdr = odp_packet_hdr(dst); - odp_packet_hdr_t *src_hdr = odp_packet_hdr(src); + odp_packet_hdr_t *dst_hdr = packet_hdr(dst); + odp_packet_hdr_t *src_hdr = packet_hdr(src); void *dst_map; void *src_map; uint32_t cpylen, minseg; @@ -2153,10 +2175,11 @@ void odp_packet_print(odp_packet_t pkt) char str[max_len]; int len = 0; int n = max_len - 1; - odp_packet_hdr_t *hdr = odp_packet_hdr(pkt); + odp_packet_hdr_t *hdr = packet_hdr(pkt); + odp_buffer_t buf = _odp_packet_to_buffer(pkt); len += snprintf(&str[len], n - len, "Packet "); - len += odp_buffer_snprint(&str[len], n - len, (odp_buffer_t)pkt); + len += odp_buffer_snprint(&str[len], n - len, buf); len += snprintf(&str[len], n - len, " input_flags 0x%" PRIx64 "\n", hdr->p.input_flags.all); len += snprintf(&str[len], n - len, " error_flags 0x%" PRIx32 "\n", @@ -2201,7 +2224,7 @@ void odp_packet_print(odp_packet_t pkt) int odp_packet_is_valid(odp_packet_t pkt) { - if (odp_buffer_is_valid((odp_buffer_t)pkt) == 0) + if (odp_buffer_is_valid(_odp_packet_to_buffer(pkt)) == 0) return 0; if (odp_event_type(odp_packet_to_event(pkt)) != ODP_EVENT_PACKET) @@ -2219,8 +2242,8 @@ int odp_packet_is_valid(odp_packet_t pkt) int _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt) { - odp_packet_hdr_t *srchdr = odp_packet_hdr(srcpkt); - odp_packet_hdr_t *dsthdr = odp_packet_hdr(dstpkt); + odp_packet_hdr_t *srchdr = packet_hdr(srcpkt); + odp_packet_hdr_t *dsthdr = packet_hdr(dstpkt); dsthdr->input = srchdr->input; dsthdr->dst_queue = srchdr->dst_queue;