From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by dpdk.org (Postfix) with ESMTP id 50351952 for ; Mon, 6 Mar 2017 11:00:51 +0100 (CET) Received: by mail-wr0-f196.google.com with SMTP id g10so21000281wrg.0 for ; Mon, 06 Mar 2017 02:00:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=JW7y2jUQZOy2UyxUhcN21IEFJZBz7FdjgsNtWRjjrnw=; b=iNhbu55I/fusdNVNOnk744TW96I5oh5UmTjRSBhKnJVrRnkm4vdjWQoS/ZK9f0n+qK mB1COyBYtboWR93TIA4b6jB2j0zz2MFhBiMFOciis1y7VnNnN4TCOp/vcn77YXBed90+ mraCZVMXDSC9gTezKsk2wYdGCbGcEkF05FQhHI76iY8Cz8a4W3bhDXzVvjD0Vukp2CMq 2mZ1hRfgIeSQ+sc/lf6CcTE5+cvnp9YimY/AEP1538HD7RnHKs73yu7He//E7HnzoH6R DytOcgVQ+uQ2oKlBfM7kqaTkUOMEQXz+b6xw/EK9taF3v5uZO+txVQ1zmQp1qjOWoGM8 Besw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=JW7y2jUQZOy2UyxUhcN21IEFJZBz7FdjgsNtWRjjrnw=; b=i8zpbyy1nVorjdJtLYDsr1lxBILkyybSEFwOuOZO+MPkiw1h6gqDpe+yy32LZV+kbj j8SaAb6p0Ik+SmQsfE/GNcxORT+BcxRzyxB0mNKohpvb5l1f6/bV89aZbuu147B6wWvT VXHknVpd/aaq/+mi5yxY8pPXvrvcWYwrIl5J4PKMjZty/X9DyxhucTXs0nGPeQ71zHDi ChjSI3bMqV73rlSX8UU6Jc4TZERUVY6vgLYOZ5umRHJ2iNamj5AvJrZLcZKs9jpz+f7y 6BbwIVytjZVU2Ns4c39QSwu1KRlZYDhHwhHdwwl5WpaCbAtQeSTacYaCgcmFnHuhLGyT 6xuA== X-Gm-Message-State: AMke39lPYWckZFdrX4I1knhpFosItX8mk+nIE2LsUCGwzpMEljMlZ++lHLire74J+YdHiA== X-Received: by 10.223.160.115 with SMTP id l48mr3469557wrl.24.1488794450712; Mon, 06 Mar 2017 02:00:50 -0800 (PST) Received: from weierstrass.local.net ([91.200.109.169]) by smtp.gmail.com with ESMTPSA id u145sm3829237wmu.1.2017.03.06.02.00.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Mar 2017 02:00:49 -0800 (PST) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Date: Mon, 6 Mar 2017 10:59:57 +0100 Message-Id: <1488794430-25179-6-git-send-email-jblunck@infradead.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488794430-25179-1-git-send-email-jblunck@infradead.org> References: <1488794430-25179-1-git-send-email-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH 05/38] ether: add allocation helper for virtual drivers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Mar 2017 10:00:51 -0000 This helper should be used by ethdev drivers supporting virtual devices to help allocating a new ethdev and properly filling the default fields. Signed-off-by: Jan Blunck --- lib/librte_ether/Makefile | 1 + lib/librte_ether/rte_ethdev_vdev.h | 85 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 lib/librte_ether/rte_ethdev_vdev.h diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile index 1d095a9..31e6ba7 100644 --- a/lib/librte_ether/Makefile +++ b/lib/librte_ether/Makefile @@ -50,6 +50,7 @@ SRCS-y += rte_flow.c # Export include files # SYMLINK-y-include += rte_ethdev.h +SYMLINK-y-include += rte_ethdev_vdev.h SYMLINK-y-include += rte_eth_ctrl.h SYMLINK-y-include += rte_dev_info.h SYMLINK-y-include += rte_flow.h diff --git a/lib/librte_ether/rte_ethdev_vdev.h b/lib/librte_ether/rte_ethdev_vdev.h new file mode 100644 index 0000000..0b47535 --- /dev/null +++ b/lib/librte_ether/rte_ethdev_vdev.h @@ -0,0 +1,85 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Brocade Communications Systems, Inc. + * Author: Jan Blunck + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTE_ETHDEV_VDEV_H_ +#define _RTE_ETHDEV_VDEV_H_ + +#include +#include +#include + +/** + * @internal + * Allocates a new ethdev slot for an ethernet device and returns the pointer + * to that slot for the driver to use. + * + * @param dev + * Pointer to virtual device + * + * @param private_data_size + * Size of private data structure + * + * @return + * A pointer to a rte_eth_dev or NULL if allocation failed. + */ +static inline struct rte_eth_dev * +rte_eth_vdev_allocate(struct rte_vdev_device *dev, size_t private_data_size) +{ + struct rte_eth_dev *eth_dev; + const char *name = rte_vdev_device_name(dev); + + eth_dev = rte_eth_dev_allocate(name); + if (!eth_dev) + return NULL; + + if (private_data_size) { + eth_dev->data->dev_private = rte_zmalloc_socket(name, + private_data_size, RTE_CACHE_LINE_SIZE, + dev->device.numa_node); + if (!eth_dev->data->dev_private) { + rte_eth_dev_release_port(eth_dev); + return NULL; + } + } + + eth_dev->device = &dev->device; + eth_dev->driver = NULL; + eth_dev->intr_handle = NULL; + + eth_dev->data->kdrv = RTE_KDRV_NONE; + eth_dev->data->numa_node = dev->device.numa_node; + eth_dev->data->drv_name = dev->device.driver->name; + return eth_dev; +} + +#endif /* _RTE_ETHDEV_VDEV_H_ */ -- 2.7.4