[dpdk-dev,v5,11/12] pci: implement hotplug bus operation

Message ID 98e3e67ce4b581325398aa6167e4a9a3ab20a6e8.1498436062.git.gaetan.rivet@6wind.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Gaëtan Rivet June 26, 2017, 12:22 a.m. UTC
  Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_pci.c | 44 ++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
  

Comments

Bruce Richardson June 27, 2017, 1:49 p.m. UTC | #1
On Mon, Jun 26, 2017 at 02:22:09AM +0200, Gaetan Rivet wrote:
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/common/eal_common_pci.c | 44 ++++++++++++++++++++++++++++++++++
>  1 file changed, 44 insertions(+)
> 
> diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
> index 00d48d9..286357d 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -47,6 +47,7 @@
>  #include <rte_pci.h>
>  #include <rte_per_lcore.h>
>  #include <rte_memory.h>
> +#include <rte_memcpy.h>
>  #include <rte_memzone.h>
>  #include <rte_eal.h>
>  #include <rte_string_fns.h>
> @@ -500,11 +501,54 @@ pci_find_device(rte_dev_cmp_t cmp, const void *data)
>  	return NULL;
>  }
>  
> +static struct rte_device *
> +pci_plug(struct rte_devargs *da)
> +{
> +	struct rte_pci_device *pdev;
> +	struct rte_pci_addr *addr;
> +
> +	addr = &da->pci.addr;
> +	/*
> +	 * Update eventual pci device in global list.
> +	 * Insert it if none was found.
> +	 */
> +	if (pci_update_device(addr) < 0) {
> +		rte_errno = EIO;
> +		return NULL;
> +	}
> +	/* Find the current device holding this address in the bus. */
> +	FOREACH_DEVICE_ON_PCIBUS(pdev) {
> +		if (rte_eal_compare_pci_addr(&pdev->addr, addr) == 0) {
> +			if (rte_pci_probe_one(addr)) {

Please put the != 0, or == -1 in the condition, to make it clear it's an
error leg.

> +				rte_errno = ENODEV;
> +				return NULL;
> +			}
> +			break;
> +		}
> +	}
> +	return pdev ? &pdev->device : NULL;
> +}

Please put in explicit != NULL, as per coding standards here.

> +
> +static int
> +pci_unplug(struct rte_device *dev)
> +{
> +	struct rte_pci_device *pdev;
> +
> +	pdev = RTE_DEV_TO_PCI(dev);
> +	if (rte_pci_detach(&pdev->addr)) {

As above, please check for == or != some value.

> +		rte_errno = ENODEV;
> +		return -1;
> +	}
> +	return 0;
> +}
> +
>  struct rte_pci_bus rte_pci_bus = {
>  	.bus = {
>  		.scan = rte_pci_scan,
>  		.probe = rte_pci_probe,
>  		.find_device = pci_find_device,
> +		.plug = pci_plug,
> +		.unplug = pci_unplug,
>  	},
>  	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
>  	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
> -- 
> 2.1.4
> 
With above fixes,

Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  

Patch

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 00d48d9..286357d 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -47,6 +47,7 @@ 
 #include <rte_pci.h>
 #include <rte_per_lcore.h>
 #include <rte_memory.h>
+#include <rte_memcpy.h>
 #include <rte_memzone.h>
 #include <rte_eal.h>
 #include <rte_string_fns.h>
@@ -500,11 +501,54 @@  pci_find_device(rte_dev_cmp_t cmp, const void *data)
 	return NULL;
 }
 
+static struct rte_device *
+pci_plug(struct rte_devargs *da)
+{
+	struct rte_pci_device *pdev;
+	struct rte_pci_addr *addr;
+
+	addr = &da->pci.addr;
+	/*
+	 * Update eventual pci device in global list.
+	 * Insert it if none was found.
+	 */
+	if (pci_update_device(addr) < 0) {
+		rte_errno = EIO;
+		return NULL;
+	}
+	/* Find the current device holding this address in the bus. */
+	FOREACH_DEVICE_ON_PCIBUS(pdev) {
+		if (rte_eal_compare_pci_addr(&pdev->addr, addr) == 0) {
+			if (rte_pci_probe_one(addr)) {
+				rte_errno = ENODEV;
+				return NULL;
+			}
+			break;
+		}
+	}
+	return pdev ? &pdev->device : NULL;
+}
+
+static int
+pci_unplug(struct rte_device *dev)
+{
+	struct rte_pci_device *pdev;
+
+	pdev = RTE_DEV_TO_PCI(dev);
+	if (rte_pci_detach(&pdev->addr)) {
+		rte_errno = ENODEV;
+		return -1;
+	}
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
+		.plug = pci_plug,
+		.unplug = pci_unplug,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),