From patchwork Tue Dec 16 12:30:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42325 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B244E2456A for ; Tue, 16 Dec 2014 12:31:26 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf8557516wgh.9 for ; Tue, 16 Dec 2014 04:31:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=qIDCEXIQz+kjDiihaMK9wpcXjjtV17pTIaMJ3/ew5mM=; b=QNihMrzdNJVe1q/omt4dmma6byDTH4VibktbwmS2zspMG15VK+c2857oeTc6WCxZ4u lViG8YStIv1qTdaN2Y5chL4QltNxh0iXIiuwceJsc53QKwCsJifUEEpWnz0z7baXV7aG rPW9i0hhHAmT3t+E0KkmPXr2tMEkS30hIdzYs3O+nJIWoCScRFjPt22KyCnUUr120Ad0 5usRzDaeb2W91O0tA/PJNr7yR3VXNqtta9mHBVsofX7UtNfC//ZluDfaOcQV2Wvb/S9O 7CDrrXlWl27JQ7gAADq3smqaemsIJqlXiPHKnUejgPu9/Puh0gBr9LAwl/09ISyviDwz 51mg== X-Gm-Message-State: ALoCoQlIdcJcExU/5bbSeBrn7CZpkRptwXr7L4vVrx54jIe29RrIUwz9C7i4R2y8PKeCkeQKoRGG X-Received: by 10.194.92.34 with SMTP id cj2mr301853wjb.5.1418733085959; Tue, 16 Dec 2014 04:31:25 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.50 with SMTP id u18ls867271laz.96.gmail; Tue, 16 Dec 2014 04:31:25 -0800 (PST) X-Received: by 10.152.115.172 with SMTP id jp12mr35307634lab.33.1418733085767; Tue, 16 Dec 2014 04:31:25 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id la5si652784lac.64.2014.12.16.04.31.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Dec 2014 04:31:25 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id ms9so11043547lab.24 for ; Tue, 16 Dec 2014 04:31:25 -0800 (PST) X-Received: by 10.112.135.6 with SMTP id po6mr2149132lbb.69.1418733085655; Tue, 16 Dec 2014 04:31:25 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp1019885lbb; Tue, 16 Dec 2014 04:31:24 -0800 (PST) X-Received: by 10.224.89.70 with SMTP id d6mr13618339qam.76.1418733084170; Tue, 16 Dec 2014 04:31:24 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id j13si646108qaa.61.2014.12.16.04.31.23 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 16 Dec 2014 04:31:24 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0rHd-0006Xs-N8; Tue, 16 Dec 2014 12:31:21 +0000 Received: from mail-la0-f42.google.com ([209.85.215.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0rHJ-0006UP-RR for lng-odp@lists.linaro.org; Tue, 16 Dec 2014 12:31:01 +0000 Received: by mail-la0-f42.google.com with SMTP id gd6so11327272lab.15 for ; Tue, 16 Dec 2014 04:30:56 -0800 (PST) X-Received: by 10.112.157.104 with SMTP id wl8mr22044479lbb.96.1418733056224; Tue, 16 Dec 2014 04:30:56 -0800 (PST) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id eg2sm169516lbb.29.2014.12.16.04.30.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Dec 2014 04:30:55 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Tue, 16 Dec 2014 14:30:35 +0200 Message-Id: <1418733042-18047-3-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418733042-18047-1-git-send-email-taras.kondratiuk@linaro.org> References: <1418733042-18047-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv5 2/9] api: packet: change alloc/free X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: taras.kondratiuk@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Bill Fischofer Signed-off-by: Bill Fischofer Signed-off-by: Taras Kondratiuk --- example/ipsec/odp_ipsec_stream.c | 9 +-- platform/linux-generic/include/api/odp_packet.h | 65 ++++++++++++++++++---- .../linux-generic/include/odp_packet_internal.h | 1 + platform/linux-generic/odp_packet.c | 64 ++++++++++++++++----- platform/linux-generic/odp_packet_socket.c | 10 ++-- 5 files changed, 113 insertions(+), 36 deletions(-) diff --git a/example/ipsec/odp_ipsec_stream.c b/example/ipsec/odp_ipsec_stream.c index 91eba88..15cdb3d 100644 --- a/example/ipsec/odp_ipsec_stream.c +++ b/example/ipsec/odp_ipsec_stream.c @@ -175,7 +175,6 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, odp_buffer_pool_t pkt_pool) { ipsec_cache_entry_t *entry = stream->input.entry; - odp_buffer_t bfr; odp_packet_t pkt; uint8_t *base; uint8_t *data; @@ -187,12 +186,10 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, stream_pkt_hdr_t *test; uint i; - /* Get buffer */ - bfr = odp_buffer_alloc(pkt_pool); - if (ODP_BUFFER_INVALID == bfr) + /* Get packet */ + pkt = odp_packet_alloc(pkt_pool, 0); + if (ODP_PACKET_INVALID == pkt) return ODP_PACKET_INVALID; - pkt = odp_packet_from_buffer(bfr); - odp_packet_init(pkt); base = odp_packet_data(pkt); data = odp_packet_data(pkt); diff --git a/platform/linux-generic/include/api/odp_packet.h b/platform/linux-generic/include/api/odp_packet.h index 9e2e542..9a15114 100644 --- a/platform/linux-generic/include/api/odp_packet.h +++ b/platform/linux-generic/include/api/odp_packet.h @@ -19,6 +19,7 @@ extern "C" { #endif #include +#include /** @defgroup odp_packet ODP PACKET * Operations on a packet. @@ -26,33 +27,73 @@ extern "C" { */ +/* + * Packet API v0.5 notes + * - Push/pull operations only on packet level + * - Push/pull within limits of segment headroom/tailroom/data lengths + * - Segment data length must be always at least one byte (i.e. there are no + * empty segments) + * - Head/tailroom content belong to packet content (in addition to data + * and meta-data) and thus is preserved over packet ownership changes. + * - _addr refer to a fixed address, which operations do not modify + * - _ptr refer to pointer to data, which may be modified by operations + */ + + +/* + * + * Alloc and free + * ******************************************************** + * + */ + /** - * Allocate and initialize a packet buffer from a packet pool + * Allocate a packet from a buffer pool * - * @param pool_id Pool handle + * Allocates a packet of the requested length from the specified buffer pool. + * Pool must have been created with buffer type ODP_BUFFER_TYPE_PACKET. The + * packet is initialized with data pointers and lengths set according to the + * specified len, and the default headroom and tailroom length settings. All + * other packet metadata are set to their default values. * - * @note The pool must have been created with 'buf_type=ODP_BUFFER_TYPE_PACKET' + * @param pool Pool handle + * @param len Packet data length * - * @return Packet handle or ODP_PACKET_INVALID + * @return Handle of allocated packet + * @retval ODP_PACKET_INVALID Packet could not be allocated + * + * @note The default headroom and tailroom used for packets is specified by + * the ODP_CONFIG_PACKET_HEADROOM and ODP_CONFIG_PACKET_TAILROOM defines in + * odp_config.h. */ -odp_packet_t odp_packet_alloc(odp_buffer_pool_t pool_id); +odp_packet_t odp_packet_alloc(odp_buffer_pool_t pool, uint32_t len); /** - * Free a packet buffer back into the packet pool + * Free packet * - * @param pkt Packet handle + * Frees the packet into the buffer pool it was allocated from. + * + * @param pkt Packet handle */ void odp_packet_free(odp_packet_t pkt); /** - * Initialize the packet + * Reset packet * - * Needs to be called if the user allocates a packet buffer, i.e. the packet - * has not been received from I/O through ODP. + * Resets all packet meta-data to their default values. Packet length is used + * to initialize pointers and lengths. It must be less than the total buffer + * length of the packet minus the default headroom length. Packet is not + * modified on failure. * - * @param pkt Packet handle + * @param pkt Packet handle + * @param len Packet data length + * + * @retval 0 Success + * @retval Non-zero Failure + * + * @see odp_packet_buf_len() */ -void odp_packet_init(odp_packet_t pkt); +int odp_packet_reset(odp_packet_t pkt, uint32_t len); /** * Convert a buffer handle to a packet handle diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index f34a83d..9553f13 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -169,6 +169,7 @@ static inline void packet_init(pool_entry_t *pool, (pool->s.headroom + size); } +odp_packet_t _odp_packet_alloc(odp_buffer_pool_t pool_hdl); #ifdef __cplusplus } diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 8a941ce..a4ad3e8 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -21,34 +21,54 @@ static inline uint8_t parse_ipv4(odp_packet_hdr_t *pkt_hdr, static inline uint8_t parse_ipv6(odp_packet_hdr_t *pkt_hdr, odph_ipv6hdr_t *ipv6, size_t *offset_out); -odp_packet_t odp_packet_alloc(odp_buffer_pool_t pool_id) +/* + * + * Alloc and free + * ******************************************************** + * + */ + +odp_packet_t odp_packet_alloc(odp_buffer_pool_t pool_hdl, uint32_t len) { - odp_packet_t pkt; - odp_buffer_t buf; + pool_entry_t *pool = odp_pool_to_entry(pool_hdl); - buf = odp_buffer_alloc(pool_id); - if (odp_unlikely(!odp_buffer_is_valid(buf))) + if (pool->s.params.buf_type != ODP_BUFFER_TYPE_PACKET) return ODP_PACKET_INVALID; - pkt = odp_packet_from_buffer(buf); - odp_packet_init(pkt); + /* Handle special case for zero-length packets */ + if (len == 0) { + odp_packet_t pkt = + (odp_packet_t)buffer_alloc(pool_hdl, + pool->s.params.buf_size); + if (pkt != ODP_PACKET_INVALID) { + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + uint32_t buf_size = pool->s.params.buf_size; + pkt_hdr->tailroom += buf_size; + pkt_hdr->frame_len -= buf_size; + } - return pkt; + return pkt; + } + + return (odp_packet_t)buffer_alloc(pool_hdl, len); } void odp_packet_free(odp_packet_t pkt) { - odp_buffer_t buf = odp_packet_to_buffer(pkt); - - odp_buffer_free(buf); + odp_buffer_free((odp_buffer_t)pkt); } -void odp_packet_init(odp_packet_t pkt) +int odp_packet_reset(odp_packet_t pkt, uint32_t len) { odp_packet_hdr_t *const pkt_hdr = odp_packet_hdr(pkt); pool_entry_t *pool = odp_buf_to_pool(&pkt_hdr->buf_hdr); + uint32_t totsize = pool->s.headroom + len + pool->s.tailroom; + + if (totsize > pkt_hdr->buf_hdr.size) + return -1; - packet_init(pool, pkt_hdr, 0); + packet_init(pool, pkt_hdr, len); + return 0; } odp_packet_t odp_packet_from_buffer(odp_buffer_t buf) @@ -404,3 +424,21 @@ size_t odp_packet_buf_size(odp_packet_t pkt) return odp_buffer_size(buf); } + +/* + * + * Internal Use Routines + * ******************************************************** + * + */ + +odp_packet_t _odp_packet_alloc(odp_buffer_pool_t pool_hdl) +{ + pool_entry_t *pool = odp_pool_to_entry(pool_hdl); + + if (pool->s.params.buf_type != ODP_BUFFER_TYPE_PACKET) + return ODP_PACKET_INVALID; + + return (odp_packet_t)buffer_alloc(pool_hdl, + pool->s.params.buf_size); +} diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c index b11aa1c..76e437a 100644 --- a/platform/linux-generic/odp_packet_socket.c +++ b/platform/linux-generic/odp_packet_socket.c @@ -215,7 +215,7 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const char *netdev, return -1; pkt_sock->pool = pool; - pkt = odp_packet_alloc(pool); + pkt = _odp_packet_alloc(pool); if (!odp_packet_is_valid(pkt)) return -1; @@ -332,7 +332,7 @@ int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock, for (i = 0; i < len; i++) { if (odp_likely(pkt == ODP_PACKET_INVALID)) { - pkt = odp_packet_alloc(pkt_sock->pool); + pkt = _odp_packet_alloc(pkt_sock->pool); if (odp_unlikely(pkt == ODP_PACKET_INVALID)) break; } @@ -430,7 +430,7 @@ int recv_pkt_sock_mmsg(pkt_sock_t *const pkt_sock, memset(msgvec, 0, sizeof(msgvec)); for (i = 0; i < (int)len; i++) { - pkt_table[i] = odp_packet_alloc(pkt_sock->pool); + pkt_table[i] = _odp_packet_alloc(pkt_sock->pool); if (odp_unlikely(pkt_table[i] == ODP_PACKET_INVALID)) break; @@ -605,7 +605,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring, continue; } - pkt_table[i] = odp_packet_alloc(pool); + pkt_table[i] = _odp_packet_alloc(pool); if (odp_unlikely(pkt_table[i] == ODP_PACKET_INVALID)) break; @@ -851,7 +851,7 @@ int setup_pkt_sock_mmap(pkt_sock_mmap_t *const pkt_sock, const char *netdev, if (pool == ODP_BUFFER_POOL_INVALID) return -1; - pkt = odp_packet_alloc(pool); + pkt = _odp_packet_alloc(pool); if (!odp_packet_is_valid(pkt)) return -1;