From patchwork Fri Jan 8 20:29:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 59399 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp755383lbb; Fri, 8 Jan 2016 11:47:33 -0800 (PST) X-Received: by 10.140.106.37 with SMTP id d34mr150499965qgf.77.1452282453009; Fri, 08 Jan 2016 11:47:33 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v188si17609488qka.9.2016.01.08.11.47.32; Fri, 08 Jan 2016 11:47:32 -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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 8D6DF61783; Fri, 8 Jan 2016 19:47:32 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=HlPjYtNI; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, 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 96C0361648; Fri, 8 Jan 2016 19:37: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 3DE87619C0; Fri, 8 Jan 2016 19:34:01 +0000 (UTC) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com [209.85.217.174]) by lists.linaro.org (Postfix) with ESMTPS id 04F6B619D8 for ; Fri, 8 Jan 2016 19:31:50 +0000 (UTC) Received: by mail-lb0-f174.google.com with SMTP id cl12so12574661lbc.1 for ; Fri, 08 Jan 2016 11:31:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sNCQn2Qse9mDXJolX9C4f1rgXIEpt/NnQ4fRG0eue04=; b=HlPjYtNIRUlCc4dQC86VXkB9jS9SW25xAcPHrmLzF6soXcacvikai6+n5WzpRQspLR RpmqBs1HPZlc3oTwqisuj+G53d+qwoPXBGtEXmaG8aQ2S+4J0EcKwe3Txos1DsAUzxh+ tihOsOgAD6pirO9HxhOoAGHXpoFxoK0tLKttc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sNCQn2Qse9mDXJolX9C4f1rgXIEpt/NnQ4fRG0eue04=; b=E8vFUOLW9qkqHxHcbhzGgABCCZRS1oZ5bs/6GfOV5xREh1O7qwzx6dB/m9ZLkwHMeF xmPlmW0dRlejsr7GYXwC0IrdxWx3GSB8z101552G7HceWo7H6AcX49YFSvyTebhhy51Z u6A0tulx/MKJaxCf8ZLvqMPGwAFbAkUy5QFRVucovv9Ax4lh/nw2bKh1BcBuIgzMphx4 a10hooUwohUrrtukQFJXqysn6qROUZRIDC/nVBpztd/p9uqeMHP4Ss7ePr24omzi/tZ+ gv+oIueoExiX+Q2Zeq6eOwN4kwRSZyvjXZxxei1y5mkqyZ8D0JaAibTgRCba2ngn5IDt 8ElQ== X-Gm-Message-State: ALoCoQmNOkBAgXUh6DZHbhMRZv3wgqISCohUN8FuoFPTK23QuR8mVO2o3q+RCZUUuhXAN336Sjsw0jNtE+8d9uugrBhQWfDrrw== X-Received: by 10.112.50.134 with SMTP id c6mr41804772lbo.14.1452281508932; Fri, 08 Jan 2016 11:31:48 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id l204sm2085534lfg.49.2016.01.08.11.31.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 11:31:48 -0800 (PST) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, stuart.haslam@linaro.org, maxim.uvarov@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org, edavis@broadcom.com Date: Fri, 8 Jan 2016 21:29:56 +0100 Message-Id: <1452285014-60320-14-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> References: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [API-NEXT RFC 13/31] linux-generic: nic driver segment implementation 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Implementation for NIC driver segments and segment pool and related methods. As in linux generic, nic segments matches ODP packets, most of these functions are just wrappers around packet function equivalents. Signed-off-by: Christophe Milard --- include/odp/api/nic.h | 5 + platform/linux-generic/Makefile.am | 3 + platform/linux-generic/include/odp/nic.h | 39 +++++ .../linux-generic/include/odp/plat/nic_types.h | 46 ++++++ .../linux-generic/include/odp/plat/pool_types.h | 3 +- platform/linux-generic/odp_nic.c | 163 +++++++++++++++++++++ 6 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 platform/linux-generic/include/odp/nic.h create mode 100644 platform/linux-generic/include/odp/plat/nic_types.h create mode 100644 platform/linux-generic/odp_nic.c diff --git a/include/odp/api/nic.h b/include/odp/api/nic.h index 0b13afd..3846608 100644 --- a/include/odp/api/nic.h +++ b/include/odp/api/nic.h @@ -20,6 +20,11 @@ extern "C" { #endif +/** @defgroup odp_drivers ODP DRIVERS + * Interface ODP-driver + * @{ + */ + /** * @typedef odp_nic_sgmt_pool_t * A nic segment pool. diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index a070cb3..c47bf52 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -34,6 +34,7 @@ odpinclude_HEADERS = \ $(srcdir)/include/odp/hash.h \ $(srcdir)/include/odp/hints.h \ $(srcdir)/include/odp/init.h \ + $(srcdir)/include/odp/nic.h \ $(srcdir)/include/odp/packet_flags.h \ $(srcdir)/include/odp/packet.h \ $(srcdir)/include/odp/packet_io.h \ @@ -71,6 +72,7 @@ odpplatinclude_HEADERS = \ $(srcdir)/include/odp/plat/crypto_types.h \ $(srcdir)/include/odp/plat/dma_types.h \ $(srcdir)/include/odp/plat/event_types.h \ + $(srcdir)/include/odp/plat/nic_types.h \ $(srcdir)/include/odp/plat/packet_types.h \ $(srcdir)/include/odp/plat/packet_io_types.h \ $(srcdir)/include/odp/plat/pci_types.h \ @@ -143,6 +145,7 @@ __LIB__libodp_la_SOURCES = \ odp_init.c \ odp_impl.c \ odp_name_table.c \ + odp_nic.c \ odp_packet.c \ odp_packet_flags.c \ odp_packet_io.c \ diff --git a/platform/linux-generic/include/odp/nic.h b/platform/linux-generic/include/odp/nic.h new file mode 100644 index 0000000..b991bc3 --- /dev/null +++ b/platform/linux-generic/include/odp/nic.h @@ -0,0 +1,39 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP nic driver interface + */ + +#ifndef ODP_PLAT_NIC_H_ +#define ODP_PLAT_NIC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +/** @ingroup odp_nic + * @{ + */ + +/** + * @} + */ + +#include + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/plat/nic_types.h b/platform/linux-generic/include/odp/plat/nic_types.h new file mode 100644 index 0000000..2cec1b4 --- /dev/null +++ b/platform/linux-generic/include/odp/plat/nic_types.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP NIC driver interface + */ + +#ifndef ODP_NIC_TYPES_H_ +#define ODP_NIC_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** @addtogroup odp_nic + * @{ + */ + +/** Nic segment pool */ +typedef ODP_HANDLE_T(odp_nic_sgmt_pool_t); +/** Invalid nic segment pool */ +#define ODP_NIC_SGMT_POOL_INVALID _odp_cast_scalar(odp_nic_sgmt_pool_t, -1) + +/** Nic segment */ +typedef ODP_HANDLE_T(odp_nic_sgmt_t); +/** Invalid nic segment */ +#define ODP_NIC_SGMT_INVALID _odp_cast_scalar(odp_nic_sgmt_t, -1) + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/plat/pool_types.h b/platform/linux-generic/include/odp/plat/pool_types.h index 4b32c29..c77e6be 100644 --- a/platform/linux-generic/include/odp/plat/pool_types.h +++ b/platform/linux-generic/include/odp/plat/pool_types.h @@ -28,7 +28,8 @@ extern "C" { typedef ODP_HANDLE_T(odp_pool_t); -#define ODP_POOL_INVALID _odp_cast_scalar(odp_pool_t, 0xffffffff) +#define ODP_POOL_INVALID _odp_cast_scalar(odp_pool_t, 0xffffffff) +#define ODP_POOL_ALL_PKTS _odp_cast_scalar(odp_pool_t, 0xfffffffe) /** * Pool type diff --git a/platform/linux-generic/odp_nic.c b/platform/linux-generic/odp_nic.c new file mode 100644 index 0000000..0cd1c19 --- /dev/null +++ b/platform/linux-generic/odp_nic.c @@ -0,0 +1,163 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include + +/* operations on NIC segments pools: */ +odp_nic_sgmt_pool_t odp_nic_sgmt_pool_create(odp_pool_t pool_hdl) +{ + odp_pool_info_t info; + + if (pool_hdl == ODP_POOL_ALL_PKTS) + return (odp_nic_sgmt_pool_t)pool_hdl; + + if (odp_pool_info(pool_hdl, &info) < 0) + return ODP_NIC_SGMT_POOL_INVALID; + + if (info.params.type != ODP_POOL_PACKET) + return ODP_NIC_SGMT_POOL_INVALID; + + /* in the linux implementation, segment pools maps packet pools: */ + return (odp_nic_sgmt_pool_t)pool_hdl; +} + +void odp_nic_sgmt_pool_destroy(odp_nic_sgmt_pool_t sgmt_pool_hdl ODP_UNUSED) +{ + /* nothing to do on this linux implementation */ +} + +int odp_nic_sgmt_pool_info(odp_nic_sgmt_pool_t pool, + odp_nic_sgmt_pool_info_t *info) +{ + odp_pool_info_t pool_info; + + if (!info) + return -1; + + if ((odp_pool_t)pool == ODP_POOL_ALL_PKTS) + return -1; + + if (odp_pool_info((odp_pool_t)pool, &pool_info) < 0) + return -1; + + if (pool_info.params.type != ODP_POOL_PACKET) + return -1; + + /* + * in linux generic, the packet are not really fragmented: + * one segment covers the whole packet. + * therefore the size of the segment is the size of the packet + * minus the default tail and headroom + */ + info->nic_max_seg_size = pool_info.params.pkt.len + - ODP_CONFIG_PACKET_HEADROOM + - ODP_CONFIG_PACKET_TAILROOM; + info->nic_max_pkt_size = info->nic_max_seg_size; + + return 0; +} + +odp_dma_map_t odp_nic_sgmt_pool_dma_map(odp_nic_sgmt_pool_t pool) +{ + odp_pool_info_t pool_info; + + if ((odp_pool_t)pool == ODP_POOL_ALL_PKTS) + return _odp_pool_get_dma_map((odp_pool_t)pool); + + if (odp_pool_info((odp_pool_t)pool, &pool_info) < 0) + return ODP_DMA_REGION_INVALID; + + if (pool_info.params.type != ODP_POOL_PACKET) + return ODP_DMA_REGION_INVALID; + + return _odp_pool_get_dma_map((odp_pool_t)pool); +} + +/* operations on NIC segments: */ +odp_nic_sgmt_t odp_nic_sgmt_alloc(odp_nic_sgmt_pool_t pool) +{ + odp_packet_t packet; + odp_pool_t packet_pool; + + /* in the linux implementation, nic segments 1:1 map to odp packets */ + packet_pool = (odp_pool_t)pool; + packet = packet_alloc(packet_pool, 0, 1); + if (odp_likely(packet != ODP_PACKET_INVALID)) { + /* following call is empty on linux, but just as a reminder...*/ + odp_nic_sgmt_set_next((odp_nic_sgmt_t)packet, + ODP_NIC_SGMT_INVALID); + return (odp_nic_sgmt_t)packet; + } else { + return ODP_NIC_SGMT_INVALID; + } +} + +void odp_nic_sgmt_free(odp_nic_sgmt_t sgmt) +{ + if (odp_likely(sgmt != ODP_NIC_SGMT_INVALID)) + odp_packet_free((odp_packet_t)sgmt); +} + +/** returns the virtual userland address for the segment */ +void *odp_nic_sgmt_get_addr(odp_nic_sgmt_t segmt) +{ + return odp_packet_data((odp_packet_t)segmt); +} + +/** returns the dma address for the segment */ +odp_dma_addr_t odp_nic_sgmt_get_dma_addr(odp_nic_sgmt_t segmt) +{ + /*FIXME: using the virtual address as dma address will only work + with iommu and a single process. */ + return (odp_dma_addr_t)odp_packet_data((odp_packet_t)segmt); +} + +/** returns the writable length for the segment */ +uint16_t odp_nic_sgmt_get_len(odp_nic_sgmt_t segmt) +{ + return odp_packet_buf_len((odp_packet_t)segmt) - + odp_packet_headroom((odp_packet_t)segmt); +} + +/** returns the data length (in bytes) for the segment */ +uint16_t odp_nic_sgmt_get_datalen(odp_nic_sgmt_t segmt) +{ + return odp_packet_len((odp_packet_t)segmt); +} + +/** set the data length (in bytes) for the segment */ +void odp_nic_sgmt_set_datalen(odp_nic_sgmt_t segmt, uint16_t len) +{ + odp_packet_pull_tail((odp_packet_t)segmt, + odp_packet_len((odp_packet_t)segmt) - len); +} + +/** get the next segment of a segment chain (or ODP_NIC_SGMT_INVALID) */ +odp_nic_sgmt_t odp_nic_sgmt_get_next( + __attribute__((__unused__)) odp_nic_sgmt_t segmt) +{ + /* not needed on linux generic as packet are contiguous */ + return ODP_NIC_SGMT_INVALID; +} + +/** set the next segment of a segment chain (may be ODP_NIC_SGMT_INVALID) */ +void odp_nic_sgmt_set_next( + __attribute__((__unused__)) odp_nic_sgmt_t segmt, + __attribute__((__unused__)) odp_nic_sgmt_t next) +{ + /* not needed on linux generic as packet are contiguous */ +} + +/** set the segment as last segment of the packet. */ +void odp_nic_sgmt_set_last(odp_nic_sgmt_t segmt) +{ + odp_packet_hdr_t *pkt_hdr; + + pkt_hdr = odp_packet_hdr((odp_packet_t)segmt); + packet_parse_l2(pkt_hdr); +}