From: Jan Blunck Date: Fri, 30 Jun 2017 18:19:42 +0000 (+0200) Subject: ethdev: use device handle to detach X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=cbb4c648c5dfff6fced96c5c76166a3e0e048fa4;p=dpdk.git ethdev: use device handle to detach This is changing the API of rte_eal_dev_detach(). Signed-off-by: Jan Blunck Signed-off-by: Thomas Monjalon --- diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index b3ad83b1ee..0a23d823e5 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -1824,7 +1824,7 @@ rmv_event_callback(void *arg) else if (da->type == RTE_DEVTYPE_WHITELISTED_PCI) rte_pci_device_name(&da->pci.addr, name, sizeof(name)); printf("removing device %s\n", name); - rte_eal_dev_detach(name); + rte_eal_dev_detach(dev->device); dev->state = RTE_ETH_DEV_UNUSED; } diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 36063329af..ede68e4bda 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -90,27 +90,33 @@ err: return -EINVAL; } -int rte_eal_dev_detach(const char *name) +int rte_eal_dev_detach(struct rte_device *dev) { - struct rte_pci_addr addr; + struct rte_bus *bus; + int ret; - if (name == NULL) { + if (dev == NULL) { RTE_LOG(ERR, EAL, "Invalid device provided.\n"); return -EINVAL; } - if (eal_parse_pci_DomBDF(name, &addr) == 0) { - if (rte_pci_detach(&addr) < 0) - goto err; - } else { - if (rte_vdev_uninit(name)) - goto err; + bus = rte_bus_find_by_device(dev); + if (bus == NULL) { + RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", + dev->name); + return -EINVAL; } - return 0; -err: - RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", name); - return -EINVAL; + if (bus->unplug == NULL) { + RTE_LOG(ERR, EAL, "Bus function not supported\n"); + return -ENOTSUP; + } + + ret = bus->unplug(dev); + if (ret) + RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", + dev->name); + return ret; } int rte_eal_hotplug_add(const char *busname, const char *devname, diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index a0d67d0032..9f2765d514 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -183,13 +183,12 @@ int rte_eal_dev_attach(const char *name, const char *devargs); /** * Detach a device from its driver. * - * @param name - * Same description as for rte_eal_dev_attach(). - * Here, eal will call the driver detaching function. + * @param dev + * A pointer to a rte_device structure. * @return * 0 on success, negative on error. */ -int rte_eal_dev_detach(const char *name); +int rte_eal_dev_detach(struct rte_device *dev); /** * @warning diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 71a576cedb..798af41e6c 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -440,7 +440,8 @@ rte_eth_dev_detach(uint8_t port_id, char *name) snprintf(name, sizeof(rte_eth_devices[port_id].data->name), "%s", rte_eth_devices[port_id].data->name); - ret = rte_eal_dev_detach(name); + + ret = rte_eal_dev_detach(rte_eth_devices[port_id].device); if (ret < 0) goto err;