From patchwork Tue Dec 16 12:30:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42324 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BE6862456A for ; Tue, 16 Dec 2014 12:31:21 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id r20sf4866405wiv.9 for ; Tue, 16 Dec 2014 04:31:21 -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=z6sapxOPet0hnLLgoeMEjvAcw+MxTFIxTkw08g44qGA=; b=lVCbC4FqwFAZ/wQ8pDh8AAOYePKfO/MAyvv6ZNgKQKKqCT0gawTuhRbN7eC9ZoTOqf KrRqHGRNDWiOWl7/938oVGFRnAcuG5Ptj6NNpJJFXzjdIuSa/XW6WfayZLjVBbUWxc6p oitSwrPgUU3uMXo3Rc5klXdeonIul/KjXxs7nd4v3u5wzWSeiUiRTDoMHtxuyIkYp5ho 7DvcJDLfICKN8KdOH29zVqxedHDsDoU3j+lRfqFXflvVwZCTUlDzkLgKKedGuGuumfS5 AETPJbwp1d9g0SdTsTskMgRwd9mJ8a7d5hVuwZTF/8J0Mja5rP7FDCw0eDTzZzWg60L0 wbpA== X-Gm-Message-State: ALoCoQkQz4r26ld2IPB2yFCjH92kEyAVhscM5g0qTiTMxHct+IrB1LyOIZyPHn8tihgb0OvPWu3j X-Received: by 10.180.189.116 with SMTP id gh20mr424965wic.2.1418733081071; Tue, 16 Dec 2014 04:31:21 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.133 with SMTP id k5ls130599lah.48.gmail; Tue, 16 Dec 2014 04:31:20 -0800 (PST) X-Received: by 10.153.11.170 with SMTP id ej10mr35495433lad.24.1418733080775; Tue, 16 Dec 2014 04:31:20 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id v20si716736laz.0.2014.12.16.04.31.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Dec 2014 04:31:20 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id 10so10802672lbg.19 for ; Tue, 16 Dec 2014 04:31:20 -0800 (PST) X-Received: by 10.152.2.41 with SMTP id 9mr34469993lar.47.1418733080643; Tue, 16 Dec 2014 04:31:20 -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 ru5csp1019859lbb; Tue, 16 Dec 2014 04:31:19 -0800 (PST) X-Received: by 10.140.104.169 with SMTP id a38mr61989166qgf.35.1418733079016; Tue, 16 Dec 2014 04:31:19 -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 m3si666203qao.39.2014.12.16.04.31.18 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 16 Dec 2014 04:31:19 -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 1Y0rHY-0006XW-Ay; Tue, 16 Dec 2014 12:31:16 +0000 Received: from mail-la0-f51.google.com ([209.85.215.51]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y0rHI-0006UO-Pg for lng-odp@lists.linaro.org; Tue, 16 Dec 2014 12:31:01 +0000 Received: by mail-la0-f51.google.com with SMTP id ms9so11042831lab.24 for ; Tue, 16 Dec 2014 04:30:55 -0800 (PST) X-Received: by 10.112.219.37 with SMTP id pl5mr32680423lbc.25.1418733055093; Tue, 16 Dec 2014 04:30:55 -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.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Dec 2014 04:30:53 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Tue, 16 Dec 2014 14:30:34 +0200 Message-Id: <1418733042-18047-2-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 1/9] api: packet: move helper functions to public API 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.217.174 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/generator/odp_generator.c | 5 +- example/ipsec/odp_ipsec.c | 3 +- example/ipsec/odp_ipsec_stream.c | 3 +- example/l2fwd/odp_l2fwd.c | 3 +- example/packet/odp_pktio.c | 3 +- helper/include/odph_packet.h | 97 ------------------------- platform/linux-generic/Makefile.am | 1 - platform/linux-generic/include/api/odp_packet.h | 41 +++++++++++ platform/linux-generic/odp_crypto.c | 4 +- platform/linux-generic/odp_packet.c | 36 +++++++++ platform/linux-generic/odp_packet_socket.c | 35 ++++----- 11 files changed, 103 insertions(+), 128 deletions(-) delete mode 100644 helper/include/odph_packet.h diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index a67910e..5ded85c 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -503,13 +502,13 @@ static void *gen_recv_thread(void *arg) pkt = odp_packet_from_buffer(buf); /* Drop packets with errors */ if (odp_unlikely(odp_packet_error(pkt))) { - odph_packet_free(pkt); + odp_packet_free(pkt); continue; } print_pkts(thr, &pkt, 1); - odph_packet_free(pkt); + odp_packet_free(pkt); } return arg; diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index 4b5a21c..cd73682 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -1148,7 +1147,7 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED) /* Check for drop */ if (PKT_DROP == rc) - odph_packet_free(pkt); + odp_packet_free(pkt); /* Print packet counts every once in a while */ if (PKT_DONE == rc) { diff --git a/example/ipsec/odp_ipsec_stream.c b/example/ipsec/odp_ipsec_stream.c index 8e002b6..91eba88 100644 --- a/example/ipsec/odp_ipsec_stream.c +++ b/example/ipsec/odp_ipsec_stream.c @@ -16,7 +16,6 @@ #include -#include #include #include #include @@ -549,7 +548,7 @@ bool verify_stream_db_outputs(void) good = verify_ipv4_packet(stream, pkt); if (good) stream->verified++; - odph_packet_free(pkt); + odp_packet_free(pkt); } } diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c index 3c1fd6a..9721ab7 100644 --- a/example/l2fwd/odp_l2fwd.c +++ b/example/l2fwd/odp_l2fwd.c @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -476,7 +475,7 @@ static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len) pkt = pkt_tbl[i]; if (odp_unlikely(odp_packet_error(pkt))) { - odph_packet_free(pkt); /* Drop */ + odp_packet_free(pkt); /* Drop */ pkt_cnt--; } else if (odp_unlikely(i != j++)) { pkt_tbl[j-1] = pkt; diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index 5ac8398..10b79d7 100644 --- a/example/packet/odp_pktio.c +++ b/example/packet/odp_pktio.c @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -455,7 +454,7 @@ static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len) pkt = pkt_tbl[i]; if (odp_unlikely(odp_packet_error(pkt))) { - odph_packet_free(pkt); /* Drop */ + odp_packet_free(pkt); /* Drop */ pkt_cnt--; } else if (odp_unlikely(i != j++)) { pkt_tbl[j-1] = pkt; diff --git a/helper/include/odph_packet.h b/helper/include/odph_packet.h deleted file mode 100644 index 3d53593..0000000 --- a/helper/include/odph_packet.h +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright (c) 2014, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - - -/** - * @file - * - * Optional ODP packet helper functions - */ - -#ifndef ODPH_PACKET_HELPER_H_ -#define ODPH_PACKET_HELPER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/** - * Helper: Tests if packet is valid - * - * Allows for more thorough checking than "if (pkt == ODP_PACKET_INVALID)" - * - * @param pkt Packet handle - * - * @return 1 if valid, otherwise 0 - */ -static inline int odph_packet_is_valid(odp_packet_t pkt) -{ - odp_buffer_t buf = odp_packet_to_buffer(pkt); - - return odp_buffer_is_valid(buf); -} - -/** - * Helper: Allocate and initialize a packet buffer from a packet pool - * - * @param pool_id Pool handle - * - * @note The pool must have been created with 'buf_type=ODP_BUFFER_TYPE_PACKET' - * - * @return Packet handle or ODP_PACKET_INVALID - */ -static inline odp_packet_t odph_packet_alloc(odp_buffer_pool_t pool_id) -{ - odp_packet_t pkt; - odp_buffer_t buf; - - buf = odp_buffer_alloc(pool_id); - if (odp_unlikely(!odp_buffer_is_valid(buf))) - return ODP_PACKET_INVALID; - - pkt = odp_packet_from_buffer(buf); - odp_packet_init(pkt); - - return pkt; -} - -/** - * Helper: Free a packet buffer back into the packet pool - * - * @param pkt Packet handle - */ -static inline void odph_packet_free(odp_packet_t pkt) -{ - odp_buffer_t buf = odp_packet_to_buffer(pkt); - - odp_buffer_free(buf); -} - -/** - * Helper: Packet buffer maximum data size - * - * @note odp_packet_buf_size(pkt) != odp_packet_get_len(pkt), the former returns - * the max length of the buffer, the latter the size of a received packet. - * - * @param pkt Packet handle - * - * @return Packet buffer maximum data size - */ -static inline size_t odph_packet_buf_size(odp_packet_t pkt) -{ - odp_buffer_t buf = odp_packet_to_buffer(pkt); - - return odp_buffer_size(buf); -} - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index cc78de3..911f925 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -47,7 +47,6 @@ subdirheaders_HEADERS = \ $(top_srcdir)/helper/include/odph_ip.h \ $(top_srcdir)/helper/include/odph_ipsec.h \ $(top_srcdir)/helper/include/odph_linux.h \ - $(top_srcdir)/helper/include/odph_packet.h \ $(top_srcdir)/helper/include/odph_ring.h \ $(top_srcdir)/helper/include/odph_udp.h diff --git a/platform/linux-generic/include/api/odp_packet.h b/platform/linux-generic/include/api/odp_packet.h index 5298fa0..9e2e542 100644 --- a/platform/linux-generic/include/api/odp_packet.h +++ b/platform/linux-generic/include/api/odp_packet.h @@ -27,6 +27,24 @@ extern "C" { /** + * Allocate and initialize a packet buffer from a packet pool + * + * @param pool_id Pool handle + * + * @note The pool must have been created with 'buf_type=ODP_BUFFER_TYPE_PACKET' + * + * @return Packet handle or ODP_PACKET_INVALID + */ +odp_packet_t odp_packet_alloc(odp_buffer_pool_t pool_id); + +/** + * Free a packet buffer back into the packet pool + * + * @param pkt Packet handle + */ +void odp_packet_free(odp_packet_t pkt); + +/** * Initialize the packet * * Needs to be called if the user allocates a packet buffer, i.e. the packet @@ -109,6 +127,18 @@ void *odp_packet_get_ctx(odp_packet_t buf); uint8_t *odp_packet_addr(odp_packet_t pkt); /** + * Packet buffer maximum data size + * + * @note odp_packet_buf_size(pkt) != odp_packet_get_len(pkt), the former returns + * the max length of the buffer, the latter the size of a received packet. + * + * @param pkt Packet handle + * + * @return Packet buffer maximum data size + */ +size_t odp_packet_buf_size(odp_packet_t pkt); + +/** * Packet data address * * Returns the current packet data address. When a packet is received from @@ -417,6 +447,17 @@ int odp_packet_seg_pull_tail(odp_packet_t pkt, odp_packet_seg_t seg, size_t len); /** + * Tests if packet is valid + * + * Allows for more thorough checking than "if (pkt == ODP_PACKET_INVALID)" + * + * @param pkt Packet handle + * + * @return 1 if valid, otherwise 0 + */ +int odp_packet_is_valid(odp_packet_t pkt); + +/** * @} */ diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index d3cdec7..4c584fc 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include @@ -360,7 +360,7 @@ odp_crypto_operation(odp_crypto_op_params_t *params, if (completion_event == odp_packet_to_buffer(params->pkt)) completion_event = odp_packet_to_buffer(params->out_pkt); - odph_packet_free(params->pkt); + odp_packet_free(params->pkt); params->pkt = ODP_PACKET_INVALID; } diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 726e086..8a941ce 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -21,6 +21,28 @@ 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) +{ + odp_packet_t pkt; + odp_buffer_t buf; + + buf = odp_buffer_alloc(pool_id); + if (odp_unlikely(!odp_buffer_is_valid(buf))) + return ODP_PACKET_INVALID; + + pkt = odp_packet_from_buffer(buf); + odp_packet_init(pkt); + + return pkt; +} + +void odp_packet_free(odp_packet_t pkt) +{ + odp_buffer_t buf = odp_packet_to_buffer(pkt); + + odp_buffer_free(buf); +} + void odp_packet_init(odp_packet_t pkt) { odp_packet_hdr_t *const pkt_hdr = odp_packet_hdr(pkt); @@ -368,3 +390,17 @@ void *odp_packet_get_ctx(odp_packet_t pkt) { return (void *)(intptr_t)odp_packet_hdr(pkt)->user_ctx; } + +int odp_packet_is_valid(odp_packet_t pkt) +{ + odp_buffer_t buf = odp_packet_to_buffer(pkt); + + return odp_buffer_is_valid(buf); +} + +size_t odp_packet_buf_size(odp_packet_t pkt) +{ + odp_buffer_t buf = odp_packet_to_buffer(pkt); + + return odp_buffer_size(buf); +} diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c index f96d5bf..b11aa1c 100644 --- a/platform/linux-generic/odp_packet_socket.c +++ b/platform/linux-generic/odp_packet_socket.c @@ -42,7 +42,8 @@ #include #include -#include +#include +#include /** Provide a sendmmsg wrapper for systems with no libc or kernel support. * As it is implemented as a weak symbol, it has zero effect on systems @@ -214,8 +215,8 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const char *netdev, return -1; pkt_sock->pool = pool; - pkt = odph_packet_alloc(pool); - if (!odph_packet_is_valid(pkt)) + pkt = odp_packet_alloc(pool); + if (!odp_packet_is_valid(pkt)) return -1; pkt_buf = odp_packet_addr(pkt); @@ -223,11 +224,11 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const char *netdev, /* Store eth buffer offset for pkt buffers from this pool */ pkt_sock->frame_offset = (uintptr_t)l2_hdr - (uintptr_t)pkt_buf; /* pkt buffer size */ - pkt_sock->buf_size = odph_packet_buf_size(pkt); + pkt_sock->buf_size = odp_packet_buf_size(pkt); /* max frame len taking into account the l2-offset */ pkt_sock->max_frame_len = pkt_sock->buf_size - pkt_sock->frame_offset; - odph_packet_free(pkt); + odp_packet_free(pkt); odp_spinlock_lock(&raw_sockets_lock); @@ -331,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 = odph_packet_alloc(pkt_sock->pool); + pkt = odp_packet_alloc(pkt_sock->pool); if (odp_unlikely(pkt == ODP_PACKET_INVALID)) break; } @@ -358,7 +359,7 @@ int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock, } /* end for() */ if (odp_unlikely(pkt != ODP_PACKET_INVALID)) - odph_packet_free(pkt); + odp_packet_free(pkt); return nb_rx; } @@ -402,7 +403,7 @@ int send_pkt_sock_basic(pkt_sock_t *const pkt_sock, nb_tx = i; for (i = 0; i < len; i++) - odph_packet_free(pkt_table[i]); + odp_packet_free(pkt_table[i]); return nb_tx; } @@ -429,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] = odph_packet_alloc(pkt_sock->pool); + pkt_table[i] = odp_packet_alloc(pkt_sock->pool); if (odp_unlikely(pkt_table[i] == ODP_PACKET_INVALID)) break; @@ -451,7 +452,7 @@ int recv_pkt_sock_mmsg(pkt_sock_t *const pkt_sock, /* Don't receive packets sent by ourselves */ if (odp_unlikely(ethaddrs_equal(pkt_sock->if_mac, eth_hdr->h_source))) { - odph_packet_free(pkt_table[i]); + odp_packet_free(pkt_table[i]); continue; } @@ -465,7 +466,7 @@ int recv_pkt_sock_mmsg(pkt_sock_t *const pkt_sock, /* Free unused pkt buffers */ for (; i < msgvec_len; i++) - odph_packet_free(pkt_table[i]); + odp_packet_free(pkt_table[i]); return nb_rx; } @@ -507,7 +508,7 @@ int send_pkt_sock_mmsg(pkt_sock_t *const pkt_sock, } for (i = 0; i < len; i++) - odph_packet_free(pkt_table[i]); + odp_packet_free(pkt_table[i]); return len; } @@ -604,7 +605,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring, continue; } - pkt_table[i] = odph_packet_alloc(pool); + pkt_table[i] = odp_packet_alloc(pool); if (odp_unlikely(pkt_table[i] == ODP_PACKET_INVALID)) break; @@ -658,7 +659,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring, mmap_tx_user_ready(ppd.raw); - odph_packet_free(pkt_table[i]); + odp_packet_free(pkt_table[i]); frame_num = next_frame_num; i++; } else { @@ -850,8 +851,8 @@ int setup_pkt_sock_mmap(pkt_sock_mmap_t *const pkt_sock, const char *netdev, if (pool == ODP_BUFFER_POOL_INVALID) return -1; - pkt = odph_packet_alloc(pool); - if (!odph_packet_is_valid(pkt)) + pkt = odp_packet_alloc(pool); + if (!odp_packet_is_valid(pkt)) return -1; pkt_buf = odp_packet_addr(pkt); @@ -859,7 +860,7 @@ int setup_pkt_sock_mmap(pkt_sock_mmap_t *const pkt_sock, const char *netdev, /* Store eth buffer offset for pkt buffers from this pool */ pkt_sock->frame_offset = (uintptr_t)l2_hdr - (uintptr_t)pkt_buf; - odph_packet_free(pkt); + odp_packet_free(pkt); pkt_sock->pool = pool; pkt_sock->sockfd = mmap_pkt_socket();