From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f171.google.com (mail-wr0-f171.google.com [209.85.128.171]) by dpdk.org (Postfix) with ESMTP id 7D3F7D210 for ; Tue, 11 Apr 2017 17:45:08 +0200 (CEST) Received: by mail-wr0-f171.google.com with SMTP id z109so707278wrb.1 for ; Tue, 11 Apr 2017 08:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=hVTfaJIeeA131eFVyhWQa6w+Xl5y4fFwIiMyQXPzLbc=; b=mUv6TTvSKs9OxFhQBw5DNpzU71iVEEefQkj0V3FB2PC5ZMZ/Ln90OsfaoYS+Tb2SuH KJnH/sFelY8LYFDnX2jGH+jDFogdTDwAAqmydjUTKulK5wE/TbPUOmqqrVBA4/imk7UK +MitUNMTRO02pxUJRIrFi3CfgsnpToMM71lqp8lEAS4z0Z7pIlCg9OhtjumYdfjgplCL 3KN8i1kt8s3obVK5DuURVExsjOMrosdrRDL5sFciGvzLne/W99YrRB4tvjkDKiPguGuQ R6RfvJNSVYRuFBykjLge1cxunL5ntatcOFuTV+aTRKItKVaQm4xghWs67cZCIDxPtJwJ uIWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=hVTfaJIeeA131eFVyhWQa6w+Xl5y4fFwIiMyQXPzLbc=; b=ilS13L/MJZbtPi1of7gO6d//YuXpgFB5ofPZatUykC5bWLQ6nFh6P/tV3yi6FzKjM8 iaQ25UQYxE+ruaO0PQ7bkRmTSa55lLXX7CNNJZnphuVWxT9AnMIexseXbJLJjzI1/QOe lAtsjj+FAdxztB656VY4j6nLMEHuh5W+EWGxkHT56KtKV3YK4VXH6y2DkXZODXhB0NDK ne+IC6LRRPmZAVKNhHs4IvzY2wWVSbjL8hdjTcJa4O4rOS56URrb0VBdhoJ/YFZvDZBd 3Z2TPyWcDX+nzjoGOgiENPskWiliy8eY1JW/Tp87QkL/1a8vwCe76DxJSTPEqEHiZS6B 9adQ== X-Gm-Message-State: AFeK/H0jfdwfjRC+HijbCA01vbNCWJp36jxCTqYdJ3PQzclDJ9/EOZVTRlcefiBmts7qJodm X-Received: by 10.223.164.141 with SMTP id g13mr41682661wrb.82.1491925507751; Tue, 11 Apr 2017 08:45:07 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id u63sm2933738wmu.22.2017.04.11.08.45.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 08:45:06 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck Date: Tue, 11 Apr 2017 17:44:11 +0200 Message-Id: <2fae626040eab99aabdd7816cbe499cd09695604.1491924900.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: <1488794430-25179-1-git-send-email-jblunck@infradead.org> In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 04/42] 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: Tue, 11 Apr 2017 15:45:08 -0000 From: Jan Blunck 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 066114b..d0017b8 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.1.4