From: Thomas Monjalon Date: Tue, 25 Sep 2018 20:55:27 +0000 (+0200) Subject: eal: add function to query device status X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=52897e7e702b96e4ff6835ead95075b20f65392b;p=dpdk.git eal: add function to query device status 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 Tested-by: Andrew Rybchenko --- diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c index fca2dbace8..2ca1efa72a 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 eb27e79922..9069003b20 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -244,7 +244,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 3f27f35107..f666099e61 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 de5548aa40..48a219f735 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 631e1749df..f6e490acae 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -76,6 +76,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; @@ -212,7 +219,7 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev) goto err_devarg; } - if (dev->driver != NULL) { + if (rte_dev_is_probed(dev)) { RTE_LOG(ERR, EAL, "Device is already plugged\n"); return -EEXIST; } @@ -355,11 +362,6 @@ local_dev_remove(struct rte_device *dev) { int ret; - if (dev->driver == NULL) { - RTE_LOG(ERR, EAL, "Device is already unplugged\n"); - return -ENOENT; - } - if (dev->bus->unplug == NULL) { RTE_LOG(ERR, EAL, "Function unplug not supported by bus (%s)\n", dev->bus->name); @@ -385,6 +387,11 @@ rte_dev_remove(struct rte_device *dev) char *devargs; int ret; + if (!rte_dev_is_probed(dev)) { + RTE_LOG(ERR, EAL, "Device is not probed\n"); + return -ENOENT; + } + ret = build_devargs(dev->devargs->bus->name, dev->name, "", &devargs); if (ret != 0) return ret; diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index efdd4a2e26..15a514bdd9 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 ff76c719d0..08e3bc2688 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -282,6 +282,7 @@ EXPERIMENTAL { rte_dev_event_monitor_stop; rte_dev_hotplug_handle_disable; rte_dev_hotplug_handle_enable; + rte_dev_is_probed; rte_dev_iterator_init; rte_dev_iterator_next; rte_dev_probe;