From patchwork Sun Oct 7 22:09:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 46224 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D654E378B; Mon, 8 Oct 2018 00:09:41 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id AA0A3DE3 for ; Mon, 8 Oct 2018 00:09:38 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4662E21F1E; Sun, 7 Oct 2018 18:09:38 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 07 Oct 2018 18:09:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=Nyph7GKMOg w50LCVv4eYrWVs6ToU5X0b3Uf7xMRhwd0=; b=OoFw1J222bbZWx8fnErUqq73GJ XBwAFiT1O2W4UatrBpcEPcg7x/UP3lcCArBOsO8i6FYxa0cKxCpDlDsTE1sFPWeR EDLw5nC+8qvVteZQXUfK9CIKuOsOqTbumDArLpB3iqapl2qK8duqcpmo89jAnwf3 ZKtxzzRvBy4XLNwCE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=Nyph7GKMOgw50LCVv4eYrWVs6ToU5X0b3Uf7xMRhwd0=; b=N0g5QjC6 uXyEXUJvmpStei25KI9b8B7WPIHUQU/oSgl7RtsASNrChN6SpMIEyeJ74cjxDIE0 v6KfLTduwsxh5HONo910te9ONCVe8jcAKaI5mX8qxIdhFM5iWBu+e5DpLtYGLl8N 108jx0MKi8iRMcdvU7+k+ByDulcLADMtNAxlVJ/cg4e2CJ+HjmPkayQtCdohncBV tmc8NjNul2k5ocO8gqqgAD7b3ts2SKA2XbODnFCU3DYn2+IxGDyW7gefxfAaEJhu UT4soZ6HfBk9bP2YN0ZBhcnarSQfzcVko+mRLKir+oI/w7B9MRJFJfl19lgSFFfC a3QJpJm85K8i1A== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 3F00F102DE; Sun, 7 Oct 2018 18:09:37 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, qi.z.zhang@intel.com, ferruh.yigit@intel.com Date: Mon, 8 Oct 2018 00:09:31 +0200 Message-Id: <20181007220933.4533-2-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181007220933.4533-1-thomas@monjalon.net> References: <20180907230958.21402-1-thomas@monjalon.net> <20181007220933.4533-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 1/3] drivers/bus: move driver assignment to end of probing 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The PCI mapping requires to know the PCI driver to use, even before the probing is done. That's why the PCI driver is referenced early inside the PCI device structure. See 1d20a073fa5e ("bus/pci: reference driver structure before mapping") However the rte_driver does not need to be referenced in rte_device before the device probing is done. By moving back this assignment at the end of the device probing, it becomes possible to make clear the status of a rte_device. Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- drivers/bus/ifpga/ifpga_bus.c | 9 ++++----- drivers/bus/pci/pci_common.c | 7 +++---- drivers/bus/pci/rte_bus_pci.h | 2 +- drivers/bus/vdev/vdev.c | 5 ++--- drivers/bus/vmbus/vmbus_common.c | 5 +++-- drivers/net/i40e/i40e_vf_representor.c | 3 --- drivers/net/mlx4/mlx4.c | 1 - drivers/net/mlx5/mlx5.c | 1 - lib/librte_eal/common/include/rte_dev.h | 2 +- 9 files changed, 14 insertions(+), 21 deletions(-) diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c index 80663328a..fca2dbace 100644 --- a/drivers/bus/ifpga/ifpga_bus.c +++ b/drivers/bus/ifpga/ifpga_bus.c @@ -280,14 +280,13 @@ ifpga_probe_one_driver(struct rte_afu_driver *drv, /* reference driver structure */ afu_dev->driver = drv; - afu_dev->device.driver = &drv->driver; /* call the driver probe() function */ ret = drv->probe(afu_dev); - if (ret) { + if (ret) afu_dev->driver = NULL; - afu_dev->device.driver = NULL; - } + else + afu_dev->device.driver = &drv->driver; return ret; } @@ -302,7 +301,7 @@ ifpga_probe_all_drivers(struct rte_afu_device *afu_dev) return -1; /* Check if a driver is already loaded */ - if (afu_dev->driver != NULL) + if (afu_dev->device.driver != NULL) return 0; TAILQ_FOREACH(drv, &ifpga_afu_drv_list, next) { diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index c7695d108..d63e68045 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -160,14 +160,12 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr, * driver flags for adjusting configuration. */ dev->driver = dr; - dev->device.driver = &dr->driver; if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { /* map resources for devices that use igb_uio */ ret = rte_pci_map_device(dev); if (ret != 0) { dev->driver = NULL; - dev->device.driver = NULL; return ret; } } @@ -176,7 +174,6 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr, ret = dr->probe(dr, dev); if (ret) { dev->driver = NULL; - dev->device.driver = NULL; if ((dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) && /* Don't unmap if device is unsupported and * driver needs mapped resources. @@ -184,6 +181,8 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr, !(ret > 0 && (dr->drv_flags & RTE_PCI_DRV_KEEP_MAPPED_RES))) rte_pci_unmap_device(dev); + } else { + dev->device.driver = &dr->driver; } return ret; @@ -244,7 +243,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev) return -1; /* Check if a driver is already loaded */ - if (dev->driver != NULL) + if (dev->device.driver != NULL) return 0; FOREACH_DRIVER_ON_PCIBUS(dr) { diff --git a/drivers/bus/pci/rte_bus_pci.h b/drivers/bus/pci/rte_bus_pci.h index 0d1955ffe..984df2b37 100644 --- a/drivers/bus/pci/rte_bus_pci.h +++ b/drivers/bus/pci/rte_bus_pci.h @@ -62,7 +62,7 @@ struct rte_pci_device { struct rte_mem_resource mem_resource[PCI_MAX_RESOURCE]; /**< PCI Memory Resource */ struct rte_intr_handle intr_handle; /**< Interrupt handle */ - struct rte_pci_driver *driver; /**< Associated driver */ + struct rte_pci_driver *driver; /**< PCI driver used in probing */ uint16_t max_vfs; /**< sriov enable if not zero */ enum rte_kernel_driver kdrv; /**< Kernel driver passthrough */ char name[PCI_PRI_STR_SIZE+1]; /**< PCI location (ASCII) */ diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index 0142fb2c8..3f27f3510 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -150,10 +150,9 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev) if (vdev_parse(name, &driver)) return -1; - dev->device.driver = &driver->driver; ret = driver->probe(dev); - if (ret) - dev->device.driver = NULL; + if (ret == 0) + dev->device.driver = &driver->driver; return ret; } diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c index e3ceb6906..de5548aa4 100644 --- a/drivers/bus/vmbus/vmbus_common.c +++ b/drivers/bus/vmbus/vmbus_common.c @@ -111,7 +111,6 @@ vmbus_probe_one_driver(struct rte_vmbus_driver *dr, /* reference driver structure */ dev->driver = dr; - dev->device.driver = &dr->driver; if (dev->device.numa_node < 0) { VMBUS_LOG(WARNING, " Invalid NUMA socket, default to 0"); @@ -124,6 +123,8 @@ vmbus_probe_one_driver(struct rte_vmbus_driver *dr, if (ret) { dev->driver = NULL; rte_vmbus_unmap_device(dev); + } else { + dev->device.driver = &dr->driver; } return ret; @@ -142,7 +143,7 @@ vmbus_probe_all_drivers(struct rte_vmbus_device *dev) int rc; /* Check if a driver is already loaded */ - if (dev->driver != NULL) { + if (dev->device.driver != NULL) { VMBUS_LOG(DEBUG, "VMBUS driver already loaded"); return 0; } diff --git a/drivers/net/i40e/i40e_vf_representor.c b/drivers/net/i40e/i40e_vf_representor.c index 0bfbb4f60..24751d13c 100644 --- a/drivers/net/i40e/i40e_vf_representor.c +++ b/drivers/net/i40e/i40e_vf_representor.c @@ -487,9 +487,6 @@ i40e_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params) if (representor->vf_id >= pf->vf_num) return -ENODEV; - /** representor shares the same driver as it's PF device */ - ethdev->device->driver = representor->adapter->eth_dev->device->driver; - /* Set representor device ops */ ethdev->dev_ops = &i40e_representor_dev_ops; diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index defc0d4b0..3de7bc53e 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -734,7 +734,6 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) eth_dev->data->mac_addrs = priv->mac; eth_dev->device = &pci_dev->device; rte_eth_copy_pci_info(eth_dev, pci_dev); - eth_dev->device->driver = &mlx4_driver.driver; /* Initialize local interrupt handle for current port. */ priv->intr_handle = (struct rte_intr_handle){ .fd = -1, diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index fd89e2af3..cf258345f 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1081,7 +1081,6 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, priv->dev_data = eth_dev->data; eth_dev->data->mac_addrs = priv->mac; eth_dev->device = dpdk_dev; - eth_dev->device->driver = &mlx5_driver.driver; err = mlx5_uar_init_primary(eth_dev); if (err) { err = rte_errno; diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 036180ff3..5084c645b 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -156,7 +156,7 @@ struct rte_driver { struct rte_device { TAILQ_ENTRY(rte_device) next; /**< Next device */ const char *name; /**< Device name */ - const struct rte_driver *driver;/**< Associated driver */ + const struct rte_driver *driver; /**< Driver assigned after probing */ const struct rte_bus *bus; /**< Bus handle assigned on scan */ int numa_node; /**< NUMA node connection */ struct rte_devargs *devargs; /**< Device user arguments */ From patchwork Sun Oct 7 22:09:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 46225 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D18F03977; Mon, 8 Oct 2018 00:09:43 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 7D0C1DE3 for ; Mon, 8 Oct 2018 00:09:39 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 1750221C82; Sun, 7 Oct 2018 18:09:39 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 07 Oct 2018 18:09:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=jYRjq6K8be LeN2SfZhodDHTibs9T+k1I2lU94hBNDdc=; b=Q0ytgb9/x24ETLNyEIs3jAGQsD qEGhSXO8o7RIBF9JFhJEOVVEMC+paGZ09736OI9Kskh6mYzRHzZCdAZnh1koaAII Ns0tceUF1vsrFLp6YutgVUjQ3VG7jJfdqqR9neq2kw3udTBYqCb3Sg6vkn2Qj+Jb YJe3jP2Mwp8X5neQI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=jYRjq6K8beLeN2SfZhodDHTibs9T+k1I2lU94hBNDdc=; b=eAJfyrdJ xspPgNC1E2WDdrKkwe8xtxuElbzPFHMT1O1bA83KYtyjh3GDZBBoupn/jMROadsu BAQ7UvLd/mLObwlwSq3vRZlLlH6ICo6UA/WQituEnJGz+KKjUc0QqH4rcrfPgt6q T3TW2P3+VAwKvqkm5YnkJEOUIPP0r1F8xHEL7S7c0bZsyXfoDwQ7DRHMdPGkWKye 8qes1E84GNvRUvITNcJakMQ5Fjtl7islt4dzFie1/XTTkzxFiTOy6MYJm5eLmOs1 sZjYEv+CY7kCUOctH+EEQfU/iJhSpTFfQURevdLLg4BNFydPDd7eA1/cXYZ8K4QS K5wTcDE1CqlTmw== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 143BB102E2; Sun, 7 Oct 2018 18:09:37 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, qi.z.zhang@intel.com, ferruh.yigit@intel.com Date: Mon, 8 Oct 2018 00:09:32 +0200 Message-Id: <20181007220933.4533-3-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181007220933.4533-1-thomas@monjalon.net> References: <20180907230958.21402-1-thomas@monjalon.net> <20181007220933.4533-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 2/3] eal: add function to query device status 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The function rte_dev_is_probed() is added in order to improve semantic and enforce proper check of the probing status of a device. It will answer this rte_device query: Is it already successfully probed or not? Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- drivers/bus/ifpga/ifpga_bus.c | 4 ++-- drivers/bus/pci/pci_common.c | 2 +- drivers/bus/vdev/vdev.c | 2 +- drivers/bus/vmbus/vmbus_common.c | 2 +- lib/librte_eal/common/eal_common_dev.c | 9 ++++++++- lib/librte_eal/common/include/rte_dev.h | 14 ++++++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c index fca2dbace..2ca1efa72 100644 --- a/drivers/bus/ifpga/ifpga_bus.c +++ b/drivers/bus/ifpga/ifpga_bus.c @@ -301,7 +301,7 @@ ifpga_probe_all_drivers(struct rte_afu_device *afu_dev) return -1; /* Check if a driver is already loaded */ - if (afu_dev->device.driver != NULL) + if (rte_dev_is_probed(&afu_dev->device)) return 0; TAILQ_FOREACH(drv, &ifpga_afu_drv_list, next) { @@ -325,7 +325,7 @@ ifpga_probe(void) int ret = 0; TAILQ_FOREACH(afu_dev, &ifpga_afu_dev_list, next) { - if (afu_dev->device.driver) + if (rte_dev_is_probed(&afu_dev->device)) continue; ret = ifpga_probe_all_drivers(afu_dev); diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index d63e68045..62b17fba9 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -243,7 +243,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev) return -1; /* Check if a driver is already loaded */ - if (dev->device.driver != NULL) + if (rte_dev_is_probed(&dev->device)) return 0; FOREACH_DRIVER_ON_PCIBUS(dr) { diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index 3f27f3510..f666099e6 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -481,7 +481,7 @@ vdev_probe(void) * we call each driver probe. */ - if (dev->device.driver) + if (rte_dev_is_probed(&dev->device)) continue; if (vdev_probe_all_drivers(dev)) { diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c index de5548aa4..48a219f73 100644 --- a/drivers/bus/vmbus/vmbus_common.c +++ b/drivers/bus/vmbus/vmbus_common.c @@ -143,7 +143,7 @@ vmbus_probe_all_drivers(struct rte_vmbus_device *dev) int rc; /* Check if a driver is already loaded */ - if (dev->device.driver != NULL) { + if (rte_dev_is_probed(&dev->device)) { VMBUS_LOG(DEBUG, "VMBUS driver already loaded"); return 0; } diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 7663eaa3f..7e8a9b260 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -74,6 +74,13 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name) return strcmp(dev->name, name); } +int __rte_experimental +rte_dev_is_probed(const struct rte_device *dev) +{ + /* The field driver should be set only when the probe is successful. */ + return dev->driver != NULL; +} + int rte_eal_dev_attach(const char *name, const char *devargs) { struct rte_bus *bus; @@ -189,7 +196,7 @@ rte_dev_probe(const char *devargs) goto err_devarg; } - if (dev->driver != NULL) { + if (rte_dev_is_probed(dev)) { RTE_LOG(ERR, EAL, "Device is already plugged\n"); return -EEXIST; } diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 5084c645b..9f169e3b3 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -162,6 +162,20 @@ struct rte_device { struct rte_devargs *devargs; /**< Device user arguments */ }; +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Query status of a device. + * + * @param dev + * Generic device pointer. + * @return + * (int)true if already probed successfully, 0 otherwise. + */ +__rte_experimental +int rte_dev_is_probed(const struct rte_device *dev); + /** * Attach a device to a registered driver. * diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 2ea7a870a..dddcb81ea 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -279,6 +279,7 @@ EXPERIMENTAL { rte_dev_event_callback_unregister; rte_dev_event_monitor_start; rte_dev_event_monitor_stop; + rte_dev_is_probed; rte_dev_iterator_init; rte_dev_iterator_next; rte_dev_probe; From patchwork Sun Oct 7 22:09:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 46226 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C63FD4C8D; Mon, 8 Oct 2018 00:09:45 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 570E73576 for ; Mon, 8 Oct 2018 00:09:40 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 024E321F21; Sun, 7 Oct 2018 18:09:40 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 07 Oct 2018 18:09:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=xwWGlDIzoc yoWftVSmfIoRAHW6aRKfLCJ8bitHfCg1s=; b=W9y7+h6/mZOR/CUesEWnfAhpG6 3TUsMbj/fPKw6K4Cl6t9RM3Iiak48M9QTjCtFjYIcgXDjtoun0jculeDJlfKJ1pE dUjiHpvGk3bkff9OAvYJu+nbduE+vuxU9nUSp4hnX96FM8DXnISUZvfwjWJnwiLN KsovrfqN2Gbg1Nd5g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=xwWGlDIzocyoWftVSmfIoRAHW6aRKfLCJ8bitHfCg1s=; b=lHlcMUGw u2RFXVDS/E0pLWxMvqMvKg0/grhl9j12bqgAy0ckI29ibOIx/+PhiHT9AiQ3lLjY KD6QZtlE5P2eJJBzIQ22s4WldOWHISQBigSTost840TEEdBc84Z2M9B6/6d5czBE zF9vxoI2Z1r0f6VYJx98zFoD8SLZIwrR2HF7TBP7ycT+kp+k/QLe2uNOAal5N0Ml pWT7A7po9Jht4V466lsoWMQ31vwuD6uGgQ/C1QbVLthTcU/TlW6YzJpQ1htoZ3C3 ILtuoEt4lRR/O/9UFoZzrwDfGm1EvzXikkBsPuq6+hcWh4eN13kpfBlCMrz98SSr IuBVEKI8Z1aOuw== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id DD9B8102DE; Sun, 7 Oct 2018 18:09:38 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, qi.z.zhang@intel.com, ferruh.yigit@intel.com Date: Mon, 8 Oct 2018 00:09:33 +0200 Message-Id: <20181007220933.4533-4-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181007220933.4533-1-thomas@monjalon.net> References: <20180907230958.21402-1-thomas@monjalon.net> <20181007220933.4533-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 3/3] eal: allow probing a device again 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In the devargs syntax for device representors, it is possible to add several devices at once: -w dbdf,representor=[0-3] It will become a more frequent case when introducing wildcards and ranges in the new devargs syntax. If a devargs string is provided for probing, and updated with a bigger range for a new probing, then we do not want it to fail because part of this range was already probed previously. There can be new ports to create from an existing rte_device. That's why the check for an already probed device is moved as bus responsibility. In the case of vdev, a global check is kept in insert_vdev(), assuming that a vdev will always have only one port. In the case of ifpga and vmbus, already probed devices are checked. In the case of NXP buses, the probing is done only once (no hotplug), though a check is added at bus level for consistency. In the case of PCI, a driver flag is added to allow PMD probing again. Only the PMD knows the ports attached to one rte_device. As another consequence of being able to probe in several steps, the field rte_device.devargs must not be considered as a full representation of the rte_device, but only the latest probing args. Anyway, the field rte_device.devargs is used only for probing. Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- drivers/bus/dpaa/dpaa_bus.c | 3 +++ drivers/bus/fslmc/fslmc_bus.c | 3 +++ drivers/bus/ifpga/ifpga_bus.c | 14 ++++++----- drivers/bus/pci/pci_common.c | 33 ++++++++++++++++--------- drivers/bus/pci/rte_bus_pci.h | 4 ++- drivers/bus/vdev/vdev.c | 5 ++++ lib/librte_eal/common/eal_common_dev.c | 7 ++---- lib/librte_eal/common/include/rte_dev.h | 2 +- 8 files changed, 47 insertions(+), 24 deletions(-) diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c index 138e0f98d..89d1e415d 100644 --- a/drivers/bus/dpaa/dpaa_bus.c +++ b/drivers/bus/dpaa/dpaa_bus.c @@ -555,6 +555,9 @@ rte_dpaa_bus_probe(void) if (ret) continue; + if (rte_dev_is_probed(&dev->device)) + continue; + if (!drv->probe || (dev->device.devargs && dev->device.devargs->policy == RTE_DEV_BLACKLISTED)) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index 960f55071..7ebd980aa 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -386,6 +386,9 @@ rte_fslmc_probe(void) if (!drv->probe) continue; + if (rte_dev_is_probed(&dev->device)) + continue; + if (dev->device.devargs && dev->device.devargs->policy == RTE_DEV_BLACKLISTED) { DPAA2_BUS_LOG(DEBUG, "%s Blacklisted, skipping", diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c index 2ca1efa72..5f23ed8b4 100644 --- a/drivers/bus/ifpga/ifpga_bus.c +++ b/drivers/bus/ifpga/ifpga_bus.c @@ -301,8 +301,11 @@ ifpga_probe_all_drivers(struct rte_afu_device *afu_dev) return -1; /* Check if a driver is already loaded */ - if (rte_dev_is_probed(&afu_dev->device)) - return 0; + if (rte_dev_is_probed(&afu_dev->device)) { + IFPGA_BUS_DEBUG("Device %s is already probed\n", + rte_ifpga_device_name(afu_dev)); + return -EEXIST; + } TAILQ_FOREACH(drv, &ifpga_afu_drv_list, next) { if (ifpga_probe_one_driver(drv, afu_dev)) { @@ -325,14 +328,13 @@ ifpga_probe(void) int ret = 0; TAILQ_FOREACH(afu_dev, &ifpga_afu_dev_list, next) { - if (rte_dev_is_probed(&afu_dev->device)) - continue; - ret = ifpga_probe_all_drivers(afu_dev); + if (ret == -EEXIST) + continue; if (ret < 0) IFPGA_BUS_ERR("failed to initialize %s device\n", rte_ifpga_device_name(afu_dev)); - } + } return ret; } diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 62b17fba9..11c5da587 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -121,6 +122,7 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) { int ret; + bool already_probed; struct rte_pci_addr *loc; if ((dr == NULL) || (dev == NULL)) @@ -151,6 +153,13 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr, dev->device.numa_node = 0; } + already_probed = rte_dev_is_probed(&dev->device); + if (already_probed && !(dr->drv_flags & RTE_PCI_DRV_PROBE_AGAIN)) { + RTE_LOG(DEBUG, EAL, "Device %s is already probed\n", + dev->device.name); + return -EEXIST; + } + RTE_LOG(INFO, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id, dev->id.device_id, dr->driver.name); @@ -159,9 +168,10 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr, * This needs to be before rte_pci_map_device(), as it enables to use * driver flags for adjusting configuration. */ - dev->driver = dr; + if (!already_probed) + dev->driver = dr; - if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) { + if (!already_probed && (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)) { /* map resources for devices that use igb_uio */ ret = rte_pci_map_device(dev); if (ret != 0) { @@ -172,6 +182,8 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr, /* call the driver probe() function */ ret = dr->probe(dr, dev); + if (already_probed) + return ret; /* no rollback if already succeeded earlier */ if (ret) { dev->driver = NULL; if ((dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) && @@ -242,10 +254,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev) if (dev == NULL) return -1; - /* Check if a driver is already loaded */ - if (rte_dev_is_probed(&dev->device)) - return 0; - FOREACH_DRIVER_ON_PCIBUS(dr) { rc = rte_pci_probe_one_driver(dr, dev); if (rc < 0) @@ -287,11 +295,14 @@ rte_pci_probe(void) devargs->policy == RTE_DEV_WHITELISTED) ret = pci_probe_all_drivers(dev); if (ret < 0) { - RTE_LOG(ERR, EAL, "Requested device " PCI_PRI_FMT - " cannot be used\n", dev->addr.domain, dev->addr.bus, - dev->addr.devid, dev->addr.function); - rte_errno = errno; - failed++; + if (ret != -EEXIST) { + RTE_LOG(ERR, EAL, "Requested device " + PCI_PRI_FMT " cannot be used\n", + dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + rte_errno = errno; + failed++; + } ret = 0; } } diff --git a/drivers/bus/pci/rte_bus_pci.h b/drivers/bus/pci/rte_bus_pci.h index 984df2b37..a3baa2895 100644 --- a/drivers/bus/pci/rte_bus_pci.h +++ b/drivers/bus/pci/rte_bus_pci.h @@ -121,7 +121,7 @@ struct rte_pci_driver { pci_probe_t *probe; /**< Device Probe function. */ pci_remove_t *remove; /**< Device Remove function. */ const struct rte_pci_id *id_table; /**< ID table, NULL terminated. */ - uint32_t drv_flags; /**< Flags contolling handling of device. */ + uint32_t drv_flags; /**< Flags RTE_PCI_DRV_*. */ }; /** @@ -137,6 +137,8 @@ struct rte_pci_bus { #define RTE_PCI_DRV_NEED_MAPPING 0x0001 /** Device needs PCI BAR mapping with enabled write combining (wc) */ #define RTE_PCI_DRV_WC_ACTIVATE 0x0002 +/** Device already probed can be probed again to check for new ports. */ +#define RTE_PCI_DRV_PROBE_AGAIN 0x0004 /** Device driver supports link state interrupt */ #define RTE_PCI_DRV_INTR_LSC 0x0008 /** Device driver supports device removal interrupt */ diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index f666099e6..06f314843 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -226,6 +226,11 @@ insert_vdev(const char *name, const char *args, struct rte_vdev_device **p_dev) dev->device.name = devargs->name; if (find_vdev(name)) { + /* + * A vdev is expected to have only one port. + * So there is no reason to try probing again, + * even with new arguments. + */ ret = -EEXIST; goto fail; } diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 7e8a9b260..e733eb779 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -196,13 +196,10 @@ rte_dev_probe(const char *devargs) goto err_devarg; } - if (rte_dev_is_probed(dev)) { - RTE_LOG(ERR, EAL, "Device is already plugged\n"); - return -EEXIST; - } - ret = dev->bus->plug(dev); if (ret) { + if (rte_dev_is_probed(dev)) /* if already succeeded earlier */ + return ret; /* no rollback */ RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", dev->name); goto err_devarg; diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 9f169e3b3..a7ec8ec25 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -159,7 +159,7 @@ struct rte_device { const struct rte_driver *driver; /**< Driver assigned after probing */ const struct rte_bus *bus; /**< Bus handle assigned on scan */ int numa_node; /**< NUMA node connection */ - struct rte_devargs *devargs; /**< Device user arguments */ + struct rte_devargs *devargs; /**< Arguments for latest probing */ }; /**