From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 1BC421B396 for ; Fri, 28 Sep 2018 18:40:48 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 9FB4121F8F; Fri, 28 Sep 2018 12:40:47 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 28 Sep 2018 12:40:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=mesmtp; bh=tkKJCaXko6iiNoss2PJeY1qrIUm6bQYDwzZ8ld XhIgE=; b=RYWZUxyr4J3ghft9EBIF8E5T4qYZCW9x6DeO/NR+Zo8iqlJSB5B8iw bVEhjN+MBWsd+sDw16b+niyA1j17MeA6t5AV/pF08o+fRmNAbef2J7kqe7VxSAQb E+k31q2cyYlwxX8IqMIED3J6yPRQNu4d5pFM+gCTKmtpW16aPd+T0= 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-sender:x-me-sender:x-sasl-enc; s=fm3; bh=tkKJCaXko6iiNoss2 PJeY1qrIUm6bQYDwzZ8ldXhIgE=; b=SO7y9cmpBDOiA5fQd96EtooAJ64Tcoi4U 5vMZkPUbFwOA6zhaXiMysCkdLizKv7OUjosDUrDM/U+ZMPv453KDF3wRq5hOVdGu nzyIWAHLRAMRto7Qs/gbYV/KPcPKmhPndDFRMJgm0OeuZgSL8L1PimviD0CBWVx0 5/qlYLZsKybZ/iMX+6CnFUMEkPtM+iQDVM37EWSf/9SjUdn1eyV+RpnBMGBbz2Z1 BMZB8UeYq37jAeW8wC+3VY+u3jlFoCsVI//xT52F+vDCP3pBnPqPEUL2+KOqC4hQ Fs7NfOIzUBn9U3K9LJ/gxJaiGJzhXxXQ1y6P3FWXIiLnahPFwBADA== X-ME-Proxy: X-ME-Sender: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 9DDA4102E0; Fri, 28 Sep 2018 12:40:46 -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: Fri, 28 Sep 2018 18:40:37 +0200 Message-Id: <20180928164039.2380-2-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928164039.2380-1-thomas@monjalon.net> References: <20180907230958.21402-1-thomas@monjalon.net> <20180928164039.2380-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 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: , X-List-Received-Date: Fri, 28 Sep 2018 16:40:48 -0000 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 --- 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 3ef035b7e..a20afb5c7 100644 --- a/drivers/bus/ifpga/ifpga_bus.c +++ b/drivers/bus/ifpga/ifpga_bus.c @@ -279,14 +279,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; } @@ -301,7 +300,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 7736b3f9c..a0adc99c8 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -162,14 +162,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; } } @@ -178,7 +176,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. @@ -186,6 +183,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; @@ -246,7 +245,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 390c2ce70..e7f321706 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -149,10 +149,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 f9f131611..1e9998278 100644 --- a/drivers/net/i40e/i40e_vf_representor.c +++ b/drivers/net/i40e/i40e_vf_representor.c @@ -486,9 +486,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 30d4e70a7..f5f3a3d19 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 ee77e4006..61542c7d1 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 associated after probing */ int numa_node; /**< NUMA node connection */ struct rte_devargs *devargs; /**< Device user arguments */ }; -- 2.19.0