From patchwork Tue Jul 1 08:08:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 32846 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6D151203C0 for ; Tue, 1 Jul 2014 08:03:26 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id t59sf22505387yho.2 for ; Tue, 01 Jul 2014 01:03:26 -0700 (PDT) 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:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=LkThfXywFr9R8ophTuWaBZhiSdAMs8p/FaMRCPUOsvg=; b=G0yhgxKHyHTcRQu5YGfS8KNmAs5wUd9G0hfSDFSvwdQBzQsTi9rQ/ylr+uxdnicRSD m2EL/f4rfZcPTenhGaX9BYfJn6l1kyYs4ewgKct/xX8GrkUDB7NvkDsETwBWVPJhELbz 9q2OCmuQSEZMC2W0oaXgE5IuTQ25+jLBpfkP/5+IhVWSMUljw+dIiekPx3Ae0AeSNZ9z WEOF2Aam1B5PS+xX+5rPLI04e1gQzKH3YmsaghTBFOEPhuFo14bLpA8yklqURSkJ6Uj8 cT5uOEUs7HpUymwRkb7vI4e1FG+h5HJjx+uBujvzS6YJ7w+j8coM9x+eCGhivNR354HX onFw== X-Gm-Message-State: ALoCoQmqa4zCnhD4iGe7DlaFYhgpS6K+WinM/Owu/CLu7PfJ41hCB6ZR5DLN3jAfQIfLRLXz+R4l X-Received: by 10.236.228.98 with SMTP id e92mr2682730yhq.58.1404201806141; Tue, 01 Jul 2014 01:03:26 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.81.39 with SMTP id e36ls1725000qgd.24.gmail; Tue, 01 Jul 2014 01:03:26 -0700 (PDT) X-Received: by 10.58.56.102 with SMTP id z6mr41675193vep.7.1404201806064; Tue, 01 Jul 2014 01:03:26 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id hf3si11114691veb.101.2014.07.01.01.03.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Jul 2014 01:03:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id ik5so8555321vcb.21 for ; Tue, 01 Jul 2014 01:03:26 -0700 (PDT) X-Received: by 10.58.153.4 with SMTP id vc4mr13491214veb.19.1404201805947; Tue, 01 Jul 2014 01:03:25 -0700 (PDT) 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.221.37.5 with SMTP id tc5csp197465vcb; Tue, 1 Jul 2014 01:03:18 -0700 (PDT) X-Received: by 10.140.95.215 with SMTP id i81mr20889943qge.6.1404201798609; Tue, 01 Jul 2014 01:03:18 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id m1si28300341qaa.43.2014.07.01.01.03.17 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 01 Jul 2014 01:03:18 -0700 (PDT) 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-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1X1t06-00053C-Er; Tue, 01 Jul 2014 08:01:14 +0000 Received: from mail-qg0-f52.google.com ([209.85.192.52]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1X1t01-000537-Di for lng-odp@lists.linaro.org; Tue, 01 Jul 2014 08:01:09 +0000 Received: by mail-qg0-f52.google.com with SMTP id f51so3018355qge.11 for ; Tue, 01 Jul 2014 01:03:07 -0700 (PDT) X-Received: by 10.140.20.247 with SMTP id 110mr28640992qgj.49.1404201787555; Tue, 01 Jul 2014 01:03:07 -0700 (PDT) Received: from localhost.localdomain (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id i10sm35311124qaq.22.2014.07.01.01.03.05 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Jul 2014 01:03:06 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Tue, 1 Jul 2014 11:08:27 +0300 Message-Id: <1404202107-3244-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.0.0 X-Topics: patch Subject: [lng-odp] [PATCH] Packet segment API started 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: petri.savolainen@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.220.176 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 Started buffer/packet/SG-list API harmonizartion. New API terminology is introduced first in segments (SG list) API and buffer/packet APIs are changed to use same terms in following patches. Segments are introduced for packet type buffers only at this phase. Term summary: - xxx_addr = segment start address - xxx_size = segment size - xxx_data = data pointer (data start inside the segment) - xxx_data_len = data length Signed-off-by: Petri Savolainen --- include/helper/odp_packet_helper.h | 14 --- include/odp_buffer.h | 11 -- include/odp_buffer_pool.h | 9 +- include/odp_packet.h | 148 ++++++++++++++++++++++++ platform/linux-generic/source/odp_buffer.c | 11 -- platform/linux-generic/source/odp_buffer_pool.c | 9 ++ platform/linux-generic/source/odp_packet.c | 20 ++++ 7 files changed, 185 insertions(+), 37 deletions(-) diff --git a/include/helper/odp_packet_helper.h b/include/helper/odp_packet_helper.h index eed866e..db12028 100644 --- a/include/helper/odp_packet_helper.h +++ b/include/helper/odp_packet_helper.h @@ -89,20 +89,6 @@ static inline size_t odp_packet_buf_size(odp_packet_t pkt) return odp_buffer_size(buf); } -/** - * Helper: Tests if packet is part of a scatter/gather list - * - * @param pkt Packet handle - * - * @return 1 if belongs to a scatter list, otherwise 0 - */ -static inline int odp_packet_is_scatter(odp_packet_t pkt) -{ - odp_buffer_t buf = odp_buffer_from_packet(pkt); - - return odp_buffer_is_scatter(buf); -} - #ifdef __cplusplus } diff --git a/include/odp_buffer.h b/include/odp_buffer.h index b3d6f4a..d8577fd 100644 --- a/include/odp_buffer.h +++ b/include/odp_buffer.h @@ -19,13 +19,10 @@ extern "C" { #endif - #include - - /** * ODP buffer */ @@ -68,14 +65,6 @@ int odp_buffer_type(odp_buffer_t buf); #define ODP_BUFFER_TYPE_PACKET 2 /**< Packet buffer */ #define ODP_BUFFER_TYPE_TIMEOUT 3 /**< Timeout buffer */ -/** - * Tests if buffer is part of a scatter/gather list - * - * @param buf Buffer handle - * - * @return 1 if belongs to a scatter list, otherwise 0 - */ -int odp_buffer_is_scatter(odp_buffer_t buf); /** * Tests if buffer is valid diff --git a/include/odp_buffer_pool.h b/include/odp_buffer_pool.h index 9112489..69155cc 100644 --- a/include/odp_buffer_pool.h +++ b/include/odp_buffer_pool.h @@ -70,7 +70,6 @@ odp_buffer_pool_t odp_buffer_pool_lookup(const char *name); void odp_buffer_pool_print(odp_buffer_pool_t pool); - /** * Buffer alloc * @@ -90,6 +89,14 @@ odp_buffer_t odp_buffer_alloc(odp_buffer_pool_t pool); void odp_buffer_free(odp_buffer_t buf); +/** + * Buffer pool of the buffer + * + * @param buf Buffer handle + * + * @return Buffer pool the buffer was allocated from + */ +odp_buffer_pool_t odp_buffer_pool(odp_buffer_t buf); #ifdef __cplusplus diff --git a/include/odp_packet.h b/include/odp_packet.h index 59759bb..8ae6410 100644 --- a/include/odp_packet.h +++ b/include/odp_packet.h @@ -220,6 +220,154 @@ void odp_packet_print(odp_packet_t pkt); */ int odp_packet_copy(odp_packet_t pkt_dst, odp_packet_t pkt_src); +/** + * Tests if packet is segmented (a scatter/gather list) + * + * @param pkt Packet handle + * + * @return Non-zero if packet is segmented, otherwise 0 + */ +int odp_packet_is_segmented(odp_packet_t pkt); + +/** + * Segment count + * + * Returns number of segments in the packet. A packet has always at least one + * segment (the packet buffer itself). + * + * @param pkt Packet handle + * + * @return Segment count + */ +int odp_packet_seg_count(odp_packet_t pkt); + +/** + * Segment start address + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * + * @return Segment start address + */ +void *odp_packet_seg_addr(odp_packet_t pkt, int seg); + +/** + * Segment maximum data size + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * + * @return Segment maximum data size + */ +size_t odp_packet_seg_size(odp_packet_t pkt, int seg); + +/** + * Segment data address + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * + * @return Segment data address + */ +void *odp_packet_seg_data(odp_packet_t pkt, int seg); + +/** + * Segment data length + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * + * @return Segment data length + */ +size_t odp_packet_seg_data_len(odp_packet_t pkt, int seg); + +/** + * Segment headroom + * + * seg_headroom = seg_data - seg_addr + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * + * @return Number of octets from seg_addr to seg_data + */ +size_t odp_packet_seg_headroom(odp_packet_t pkt, int seg); + +/** + * Segment tailroom + * + * seg_tailroom = seg_size - seg_headroom - seg_data_len + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * + * @return Number of octets from end-of-data to end-of-segment + */ +size_t odp_packet_seg_tailroom(odp_packet_t pkt, int seg); + +/** + * Push out segment head + * + * Push out segment data address (away from data) and increase data length. + * + * seg_data -= len + * seg_data_len += len + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * @param len Number of octets to push head (0 ... seg_headroom) + * + * @return New segment data address, or NULL on an error + */ +void *odp_packet_seg_push_head(odp_packet_t pkt, int seg, size_t len); + +/** + * Pull in segment head + * + * Pull in segment data address (towards data) and decrease data length. + * + * seg_data += len + * seg_data_len -= len + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * @param len Number of octets to pull head (0 ... seg_data_len) + * + * @return New segment data address, or NULL on an error + */ +void *odp_packet_seg_pull_head(odp_packet_t pkt, int seg, size_t len); + +/** + * Push out segment tail + * + * Increase segment data length. + * + * seg_data_len += len + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * @param len Number of octets to push tail (0 ... seg_tailroom) + * + * @return New segment data length, or -1 on an error + */ +int odp_packet_seg_push_tail(odp_packet_t pkt, int seg, size_t len); + +/** + * Pull in segment tail + * + * Decrease segment data length. + * + * seg_data_len -= len + * + * @param pkt Packet handle + * @param seg Segment index (0 ... seg_count-1) + * @param len Number of octets to pull tail (0 ... seg_data_len) + * + * @return New segment data length, or -1 on an error + */ +int odp_packet_seg_pull_tail(odp_packet_t pkt, int seg, size_t len); + + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/source/odp_buffer.c b/platform/linux-generic/source/odp_buffer.c index afbe96a..0169eec 100644 --- a/platform/linux-generic/source/odp_buffer.c +++ b/platform/linux-generic/source/odp_buffer.c @@ -36,17 +36,6 @@ int odp_buffer_type(odp_buffer_t buf) } -int odp_buffer_is_scatter(odp_buffer_t buf) -{ - odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf); - - if (hdr->scatter.num_bufs == 0) - return 0; - else - return 1; -} - - int odp_buffer_is_valid(odp_buffer_t buf) { odp_buffer_bits_t handle; diff --git a/platform/linux-generic/source/odp_buffer_pool.c b/platform/linux-generic/source/odp_buffer_pool.c index 25c9565..b73cbb2 100644 --- a/platform/linux-generic/source/odp_buffer_pool.c +++ b/platform/linux-generic/source/odp_buffer_pool.c @@ -491,6 +491,15 @@ void odp_buffer_free(odp_buffer_t buf) } +odp_buffer_pool_t odp_buffer_pool(odp_buffer_t buf) +{ + odp_buffer_hdr_t *hdr; + + hdr = odp_buf_to_hdr(buf); + return hdr->pool; +} + + void odp_buffer_pool_print(odp_buffer_pool_t pool_id) { pool_entry_t *pool; diff --git a/platform/linux-generic/source/odp_packet.c b/platform/linux-generic/source/odp_packet.c index 99fcc6d..13e2471 100644 --- a/platform/linux-generic/source/odp_packet.c +++ b/platform/linux-generic/source/odp_packet.c @@ -127,6 +127,26 @@ void odp_packet_set_l4_offset(odp_packet_t pkt, size_t offset) odp_packet_hdr(pkt)->l4_offset = offset; } + +int odp_packet_is_segmented(odp_packet_t pkt) +{ + odp_buffer_hdr_t *buf_hdr = odp_buf_to_hdr((odp_buffer_t)pkt); + + if (buf_hdr->scatter.num_bufs == 0) + return 0; + else + return 1; +} + + +int odp_packet_seg_count(odp_packet_t pkt) +{ + odp_buffer_hdr_t *buf_hdr = odp_buf_to_hdr((odp_buffer_t)pkt); + + return (int)buf_hdr->scatter.num_bufs + 1; +} + + /** * Simple packet parser: eth, VLAN, IP, TCP/UDP/ICMP *