From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f176.google.com (mail-wr0-f176.google.com [209.85.128.176]) by dpdk.org (Postfix) with ESMTP id 99DCCD29E for ; Tue, 11 Apr 2017 17:45:20 +0200 (CEST) Received: by mail-wr0-f176.google.com with SMTP id z109so711026wrb.1 for ; Tue, 11 Apr 2017 08:45:20 -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=EWUE+coiETl2xmElgvj2C9Sej0iAuB95rQIYQgYpEEE=; b=aF/04gM61hUN43nvRoFlX/+l1RnhNpbZs3OJM/EU3/g/40N27zh8Y1dgJa1MbiEOMr H6MbQ2seB/2O8g9mBNLDqBFVEl4Fxzq7jOx47FxFe1zJFFZ95dIlC9TN3sIQmkKU6fjC tj6Gms5SWMgqe1sLA5OzDrtG1w9Spn3XhWnghDxHJvHXxJnc/NdLY0BZ2xyBSmuZ4muN w+giAdHbjshKeqgfeRyGBrrmiBlkEdjmluVNwb0qmGB2ius4B/FL+r7ItSZ3Z6cfJRaQ 7agYukuV5KKejGpnNs6sd18QK2xJqhm20cDRwlagsalHPA+F8UyTLsjOcgUEFPfzTyih j0lA== 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=EWUE+coiETl2xmElgvj2C9Sej0iAuB95rQIYQgYpEEE=; b=T2lBd+qUJiJqSPCVzScA1Fcov0u4FcArv3vtPDjIEmleH87MBd85/F5ILnxGtBqcde UsqmrNbGIyC+ObziOQ3bT8CQAzhufHOepOTuIgoA5EEfMYu1l7DfI4uLoF/JwMo1nofr oS+RiV0lZiKvpPQz/br6AeQ4QrgrFvSrvk3KHzu2jBDQ9mxWIvETfK2i8Hz7WuUXIbYP B50ZwxNxgW+QmNJQqLNi5HdvUlSqVZ/zGowcLOoLk3ubWr5X+vtyUsjPS5pt5+ssxHe5 9erZF/r+P2c0ph2Z+OpfaXqffrS5kFoZtZBKcZ609YScPYsYM2MTn5hfj70rn3nVcniL XCDw== X-Gm-Message-State: AN3rC/6CptB9DcyJWz9TN8Vmu/PVXESk+4S8oiJtXSy+lWcIw2/rl9cGke6ce7Uu3UFcmyYk X-Received: by 10.223.160.59 with SMTP id k56mr16008795wrk.0.1491925519892; Tue, 11 Apr 2017 08:45:19 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 08:45:19 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Jan Blunck Date: Tue, 11 Apr 2017 17:44:23 +0200 Message-Id: <3038aa23a34b51c2567338e512c82fea5a4559d6.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 16/42] ethdev: add PCI driver helpers 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:20 -0000 From: Jan Blunck This adds the following helper intended to be used by rte_pci_driver implementations working with ethdev: - rte_eth_dev_pci_allocate - rte_eth_dev_pci_release - rte_eth_dev_pci_generic_probe - rte_eth_dev_pci_generic_remove Signed-off-by: Jan Blunck --- lib/librte_ether/Makefile | 1 + lib/librte_ether/rte_ethdev_pci.h | 151 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 lib/librte_ether/rte_ethdev_pci.h diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile index d0017b8..93fdde1 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_pci.h SYMLINK-y-include += rte_ethdev_vdev.h SYMLINK-y-include += rte_eth_ctrl.h SYMLINK-y-include += rte_dev_info.h diff --git a/lib/librte_ether/rte_ethdev_pci.h b/lib/librte_ether/rte_ethdev_pci.h new file mode 100644 index 0000000..4b728db --- /dev/null +++ b/lib/librte_ether/rte_ethdev_pci.h @@ -0,0 +1,151 @@ +/*- + * 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_PCI_H_ +#define _RTE_ETHDEV_PCI_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 the PCI 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_dev_pci_allocate(struct rte_pci_device *dev, size_t private_data_size) +{ + struct rte_eth_dev *eth_dev; + const char *name; + + if (!dev) + return NULL; + + name = dev->device.name; + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + 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; + } + } + } else { + eth_dev = rte_eth_dev_attach_secondary(name); + if (!eth_dev) + return NULL; + } + + eth_dev->device = &dev->device; + eth_dev->driver = NULL; + eth_dev->intr_handle = &dev->intr_handle; + rte_eth_copy_pci_info(eth_dev, dev); + return eth_dev; +} + +static inline void +rte_eth_dev_pci_release(struct rte_eth_dev *eth_dev) +{ + /* free ether device */ + rte_eth_dev_release_port(eth_dev); + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + rte_free(eth_dev->data->dev_private); + + eth_dev->data->dev_private = NULL; + + eth_dev->device = NULL; + eth_dev->driver = NULL; + eth_dev->intr_handle = NULL; +} + +typedef int (*eth_dev_pci_callback_t)(struct rte_eth_dev *eth_dev); + +static inline int +rte_eth_dev_pci_generic_probe(struct rte_pci_device *pci_dev, + size_t private_data_size, eth_dev_pci_callback_t dev_init) +{ + struct rte_eth_dev *eth_dev; + int ret; + + eth_dev = rte_eth_dev_pci_allocate(pci_dev, private_data_size); + if (!eth_dev) + return -ENOMEM; + + RTE_FUNC_PTR_OR_ERR_RET(*dev_init, -EINVAL); + ret = dev_init(eth_dev); + if (ret) + rte_eth_dev_pci_release(eth_dev); + + return ret; +} + +static inline int +rte_eth_dev_pci_generic_remove(struct rte_pci_device *pci_dev, + eth_dev_pci_callback_t dev_uninit) +{ + struct rte_eth_dev *eth_dev; + int ret; + + eth_dev = rte_eth_dev_allocated(pci_dev->device.name); + if (!eth_dev) + return -ENODEV; + + if (dev_uninit) { + ret = dev_uninit(eth_dev); + if (ret) + return ret; + } + + rte_eth_dev_pci_release(eth_dev); + return 0; +} + +#endif /* _RTE_ETHDEV_PCI_H_ */ -- 2.1.4