From patchwork Fri Jan 8 20:29:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 59398 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp755067lbb; Fri, 8 Jan 2016 11:46:49 -0800 (PST) X-Received: by 10.140.92.35 with SMTP id a32mr146244270qge.92.1452282408887; Fri, 08 Jan 2016 11:46:48 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id a98si89933578qgf.112.2016.01.08.11.46.48; Fri, 08 Jan 2016 11:46:48 -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 6511861CE3; Fri, 8 Jan 2016 19:46:39 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=YmdLezsQ; 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_H2,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 C079B61CE2; Fri, 8 Jan 2016 19:33:56 +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 0425661D06; Fri, 8 Jan 2016 19:33:49 +0000 (UTC) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com [209.85.217.172]) by lists.linaro.org (Postfix) with ESMTPS id 9AF16617B2 for ; Fri, 8 Jan 2016 19:31:48 +0000 (UTC) Received: by mail-lb0-f172.google.com with SMTP id sv6so222383220lbb.0 for ; Fri, 08 Jan 2016 11:31:48 -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=hQi+DzelMlpFbnNt7Hb3Wd9zLUaNrMdRNbFdvOfLIUk=; b=YmdLezsQVBL+vhkSxQ6CC7JBWgsM2svE5GSfcrMpq1Lut1AjCmKsfXN/OCC0DoP2m6 Eevttcb8BMDswWqctcm/IQm1GArYFDYHpzzt8MzK12kly5gQcSlfyZPfUH9FQC2lCLrz qu6BNrcZjh+X5w88Kb2YP73lACuWHBFoeAq6o= 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=hQi+DzelMlpFbnNt7Hb3Wd9zLUaNrMdRNbFdvOfLIUk=; b=GB1GacEojIm/ng/+v9VgSYiBwropyhsjsE5KP0Gew5yCT0+UvxcmaxJ8XCYt5SICht NTDcapxzLFuv5ZsRuAWrglGO6FYJJtiI2mnlIAtB4/KneycFDtomgFdCIvbdyeyszXVq jFOtd7xiKCcirZbkOOmM8EE6ZWNHhysegwZ1S2KB1xv4P3b8jIhpVGd1Bx5R7Xfb8Dwg pvJ7mgUmTY7LzGMqb3/yacnb+y2YATCUJTfVkWgNeikifoeST8kcWyk9Jqsbk7RZwzQg XBD+qtIfaGmb0VsBpnxIop7EbX4labxeDfd1JFvGNgBbfr5+fQFAR91hirIF67UmVbgu uJ9w== X-Gm-Message-State: ALoCoQmPmCQuDkTsKawNA75phmq9DLmh4Ny0Fz1vAAxa45Y5q9fL0jAtaULVWczpzKQIybll1NMfjQx8So6Q+JfQpiIDlszLxQ== X-Received: by 10.112.166.2 with SMTP id zc2mr35353733lbb.34.1452281507568; Fri, 08 Jan 2016 11:31:47 -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.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 11:31:46 -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:55 +0100 Message-Id: <1452285014-60320-13-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 12/31] driver api: nic segments and segment pool 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" Nic drivers use NIC segments as basic "data unit" when receiving/sending data. NIC segments may match ODP packet fragments (and probably will in most cases) but may not (if ODP packets implementation is not directely manageable by the NIC HW, or simply if odp packet are not DMA mappable). This patch defines the segments and segment pool (where NIC segments are allocated from), as well as the different methods which can be used on those. Signed-off-by: Christophe Milard --- include/odp/api/nic.h | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/odp_driver.h | 1 + 2 files changed, 153 insertions(+) create mode 100644 include/odp/api/nic.h diff --git a/include/odp/api/nic.h b/include/odp/api/nic.h new file mode 100644 index 0000000..0b13afd --- /dev/null +++ b/include/odp/api/nic.h @@ -0,0 +1,152 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP API towards NIC ethernet drivers + */ + +#ifndef ODP_API_NIC_H_ +#define ODP_API_NIC_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @typedef odp_nic_sgmt_pool_t + * A nic segment pool. + * One pool of nic segments is allocatated by each driver for each queue + * at probe time. + * Nic segments are allocated from this pool by the driver on RX direction, + * and freeed by the driver on tx. + */ + +/** + * Create a pool of nic segment, to be used by drivers. + * Nic segments may match 1:1 to the underlaying ODP packets segments, + * but may not do so in case the ODP implementation does not provide + * DMA mappable ODP buffers, or when fragmentation occurs. + * In any case, the ODP implementation + * is responsible for the relationship (and possible conversion) between + * matching ODP packets and nic segments. + * + * @param pool odp packet pool "matching" the created segment pool. + * @return A newly created nic segment pool handle or + * ODP_NIC_SGMT_POOL_INVALID. + */ +odp_nic_sgmt_pool_t odp_nic_sgmt_pool_create(odp_pool_t pool_hdl); + +/** + * Create a pool of nic segment + * @param sgmt_pool_hdl handle to the pool to be destroyed as returned by + * odp_nic_sgmt_pool_create + */ +void odp_nic_sgmt_pool_destroy(odp_nic_sgmt_pool_t sgmt_pool_hdl); + +/** + * Nic segment Pool information struct + * Used to get information about a nic segment pool. + * Drivers use this function to know the maximum size that may be + * written into the allocated nic segments. + * If the packet_size returned here exceeds the segment size, the the driver + * will use (and chain) multiple segments to receive large packets. + */ +typedef struct odp_nic_sgmt_pool_info_t { + /**< max size (bytes) of segments from this pool */ + int nic_max_seg_size; + /**< max packet size (> nic_segment_size if scatter-jitter supported) */ + int nic_max_pkt_size; +} odp_nic_sgmt_pool_info_t; + +/** The function to retrieve segment pool information + * @param pool A odp nic segment poll handle + * @param info A pointer to a odp_pool_info_t to be filled + * @return a negative value on error + */ +int odp_nic_sgmt_pool_info(odp_nic_sgmt_pool_t pool, + odp_nic_sgmt_pool_info_t *info); + +/** The function to retrieve segment pool DMA information + * @param pool A odp nic segment poll handle + * This function will return a DMA map handle (odp_dma_map_t) -possibly + * linked to others if the DMA region is scattered. This descriptor can be used + * to gain DMA access to all NIC segments allocated from this + * buffer. + * @return An ODP DMA map descriptor handle + */ +odp_dma_map_t odp_nic_sgmt_pool_dma_map(odp_nic_sgmt_pool_t pool); + +/** + * @typedef odp_nic_sgmt_t + * A nic segment. + * Nic segments are the data elements exchanged between ODP + * and nic drivers (in both direction). + * They may match 1:1 to the underlaying ODP packets segments, + * but may not do so in case the ODP implementation does not provide + * DMA mappable ODP buffers. In any case, the ODP implementation + * is responsible for the relationship (and possible conversion) between + * ODP packets and nic segments. + * Each nic segment must be DMA mappable, ie must be contiguous in the DMA + * space (that is, it must be contiguous physical memory in the absence of + * iommu). + * Nic segments have a "next" pointer to allow chaining. The rx side of the + * driver should link segments in the case the rx packet is larger than the + * segment size (and the max packet size is larger than the segment size). + * The driver should also treat linked segments as single packet on tx. + */ + +/** + * Allocate a segment from a nic segment pool (for RX) + * @param pool Nic segment pool handle + * @return Handle of allocated segment + */ +odp_nic_sgmt_t odp_nic_sgmt_alloc(odp_nic_sgmt_pool_t pool); + +/** + * Free a segment + * @param Handle of allocated segment + */ +void odp_nic_sgmt_free(odp_nic_sgmt_t sgmt); + +/* operations on NIC segments: */ +/** returns the virtual userland address for the nic segment */ +void *odp_nic_sgmt_get_addr(odp_nic_sgmt_t segmt); + +/** returns the dma address (physical or iova) for the nic segment */ +odp_dma_addr_t odp_nic_sgmt_get_dma_addr(odp_nic_sgmt_t segmt); + +/** returns the length (writable length) of the nic segment */ +uint16_t odp_nic_sgmt_get_len(odp_nic_sgmt_t segmt); + +/** returns the length of the data contained in the nic segment */ +uint16_t odp_nic_sgmt_get_datalen(odp_nic_sgmt_t segmt); + +/** set the length of the data contained in the nic segment */ +void odp_nic_sgmt_set_datalen(odp_nic_sgmt_t segmt, uint16_t len); + +/** set the segment as last segment of the packet. */ +void odp_nic_sgmt_set_last(odp_nic_sgmt_t segmt); + +/** get the next segment of a segment chain (or ODP_NIC_SGMT_INVALID) */ +odp_nic_sgmt_t odp_nic_sgmt_get_next(odp_nic_sgmt_t segmt); + +/** set the next segment of a segment chain (may be ODP_NIC_SGMT_INVALID) */ +void odp_nic_sgmt_set_next(odp_nic_sgmt_t segmt, odp_nic_sgmt_t next); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ODP_API_NIC_H_ */ diff --git a/include/odp_driver.h b/include/odp_driver.h index 6c1eded..6fda613 100644 --- a/include/odp_driver.h +++ b/include/odp_driver.h @@ -23,6 +23,7 @@ extern "C" { #include #include #include +#include #include #include #include