From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by dpdk.org (Postfix) with ESMTP id B44D55A99 for ; Wed, 25 Feb 2015 20:33:04 +0100 (CET) Received: by paceu11 with SMTP id eu11so7528259pac.10 for ; Wed, 25 Feb 2015 11:33:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JdfTQrBuUtlR1fDsyPMazyxkLsxHthHoViOQdUiiAeI=; b=b29/D6mE/lcBfa5J1WYZ/QnQNyU5IRg4bNa/jkj6jzIF0aF/xRDV/hWDCpVfe2NRji 2F941jf29LuPMnXD9HH+5v9G9hx6fqkHsjPCav1h+6SAk6nLIYybF7Je/iULklLFIlBv YrTqboZICKt+d/qPrI3Z+v5exPFN/EN6Xnxl/51rqe3nVdE4TDrq5Svp89x80qeViWZC NRge0/7ivH9G6r6FGPjKcAhIcE9B064qptAfqf6z5VmxQKa8qfffSBypC0JaQ5FXy4br Dab/RTfvIwY8bxt3ZLzmcMoAL093siDjujgyYzLS16IpJ6ziZdUI/L72GLaSFCIuksCQ 1eNw== X-Gm-Message-State: ALoCoQnzv7GvcZnU7bTp9K9Mcietm3wUBTiLcsmyMeTOHYFjX3wCOwOOQU+bET4gHrWh8R0JrJlE X-Received: by 10.68.57.162 with SMTP id j2mr8258205pbq.120.1424892784163; Wed, 25 Feb 2015 11:33:04 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id ux7sm39997444pab.19.2015.02.25.11.33.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Feb 2015 11:33:03 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Thu, 26 Feb 2015 04:32:23 +0900 Message-Id: <1424892749-31862-10-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424892749-31862-1-git-send-email-mukawa@igel.co.jp> References: <1424837093-5661-13-git-send-email-mukawa@igel.co.jp> <1424892749-31862-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v15 09/13] eal/pci: Add probe and close functions of pci driver X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Feb 2015 19:33:05 -0000 - Add pci_close_all_drivers() The function tries to find a driver for the specified device, and then close the driver. - Add rte_eal_pci_probe_one() and rte_eal_pci_close_one() The functions are used for probe and close a device. First the function tries to find a device that has the specified PCI address. Then, probe or close the device. v15: - Fix version.map. v9: - Fix commit title. - Remove RTE_EAL_INVOKE_TYPE_PROBE/CLOSE. (Thanks to Thomas Monjalon) - Implement pci_unmap_device() in this patch. v5: - Remove RTE_EAL_INVOKE_TYPE_UNKNOWN, because it's unused. v4: - Fix parameter checking. - Fix indent of 'if' statement. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/eal_common_pci.c | 98 ++++++++++++++++++++++++- lib/librte_eal/common/eal_private.h | 15 ++++ lib/librte_eal/common/include/rte_pci.h | 32 ++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 94 ++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 + lib/librte_ether/rte_ethdev.c | 6 +- 6 files changed, 243 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index bf2793f..5b6b55d 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -108,7 +108,10 @@ static int pci_probe_all_drivers(struct rte_pci_device *dev) { struct rte_pci_driver *dr = NULL; - int rc; + int rc = 0; + + if (dev == NULL) + return -1; TAILQ_FOREACH(dr, &pci_driver_list, next) { rc = rte_eal_pci_probe_one_driver(dr, dev); @@ -123,6 +126,99 @@ pci_probe_all_drivers(struct rte_pci_device *dev) return 1; } +#ifdef RTE_LIBRTE_EAL_HOTPLUG +/* + * If vendor/device ID match, call the devuninit() function of all + * registered driver for the given device. Return -1 if initialization + * failed, return 1 if no driver is found for this device. + */ +static int +pci_close_all_drivers(struct rte_pci_device *dev) +{ + struct rte_pci_driver *dr = NULL; + int rc = 0; + + if (dev == NULL) + return -1; + + TAILQ_FOREACH(dr, &pci_driver_list, next) { + rc = rte_eal_pci_close_one_driver(dr, dev); + if (rc < 0) + /* negative value is an error */ + return -1; + if (rc > 0) + /* positive value means driver not found */ + continue; + return 0; + } + return 1; +} + +/* + * Find the pci device specified by pci address, then invoke probe function of + * the driver of the devive. + */ +int +rte_eal_pci_probe_one(struct rte_pci_addr *addr) +{ + struct rte_pci_device *dev = NULL; + int ret = 0; + + if (addr == NULL) + return -1; + + TAILQ_FOREACH(dev, &pci_device_list, next) { + if (rte_eal_compare_pci_addr(&dev->addr, addr)) + continue; + + ret = pci_probe_all_drivers(dev); + if (ret < 0) + goto err_return; + return 0; + } + return -1; + +err_return: + RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT + " cannot be used\n", dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + return -1; +} + +/* + * Find the pci device specified by pci address, then invoke close function of + * the driver of the devive. + */ +int +rte_eal_pci_close_one(struct rte_pci_addr *addr) +{ + struct rte_pci_device *dev = NULL; + int ret = 0; + + if (addr == NULL) + return -1; + + TAILQ_FOREACH(dev, &pci_device_list, next) { + if (rte_eal_compare_pci_addr(&dev->addr, addr)) + continue; + + ret = pci_close_all_drivers(dev); + if (ret < 0) + goto err_return; + + TAILQ_REMOVE(&pci_device_list, dev, next); + return 0; + } + return -1; + +err_return: + RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT + " cannot be used\n", dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + return -1; +} +#endif /* RTE_LIBRTE_EAL_HOTPLUG */ + /* * Scan the content of the PCI bus, and call the devinit() function for * all registered drivers that have a matching entry in its id_table diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 159cd66..4acf5a0 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -165,6 +165,21 @@ int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev); /** + * Munmap memory for single PCI device + * + * This function is private to EAL. + * + * @param dr + * The pointer to the pci driver structure + * @param dev + * The pointer to the pci device structure + * @return + * 0 on success, negative on error + */ +int rte_eal_pci_close_one_driver(struct rte_pci_driver *dr, + struct rte_pci_device *dev); + +/** * Init tail queues for non-EAL library structures. This is to allow * the rings, mempools, etc. lists to be shared among multiple processes * diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index ecde36f..ac30925 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -325,6 +325,38 @@ rte_eal_compare_pci_addr(struct rte_pci_addr *addr, struct rte_pci_addr *addr2) */ int rte_eal_pci_probe(void); +#ifdef RTE_LIBRTE_EAL_HOTPLUG +/** + * Probe the single PCI device. + * + * Scan the content of the PCI bus, and find the pci device specified by pci + * address, then call the probe() function for registered driver that has a + * matching entry in its id_table for discovered device. + * + * @param addr + * The PCI Bus-Device-Function address to probe. + * @return + * - 0 on success. + * - Negative on error. + */ +int rte_eal_pci_probe_one(struct rte_pci_addr *addr); + +/** + * Close the single PCI device. + * + * Scan the content of the PCI bus, and find the pci device specified by pci + * address, then call the close() function for registered driver that has a + * matching entry in its id_table for discovered device. + * + * @param addr + * The PCI Bus-Device-Function address to close. + * @return + * - 0 on success. + * - Negative on error. + */ +int rte_eal_pci_close_one(struct rte_pci_addr *addr); +#endif /* RTE_LIBRTE_EAL_HOTPLUG */ + /** * Dump the content of the PCI bus. * diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index d03429c..f880f90 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -595,6 +595,31 @@ pci_map_device(struct rte_pci_device *dev) return ret; } +#ifdef RTE_LIBRTE_EAL_HOTPLUG +static void +pci_unmap_device(struct rte_pci_device *dev) +{ + if (dev == NULL) + return; + + /* try unmapping the NIC resources using VFIO if it exists */ + switch (dev->pt_driver) { + case RTE_PT_VFIO: + RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n"); + break; + case RTE_PT_IGB_UIO: + case RTE_PT_UIO_GENERIC: + /* unmap resources for devices that use uio */ + pci_uio_unmap_resource(dev); + break; + default: + RTE_LOG(DEBUG, EAL, " Not managed by known pt driver," + " skipped\n"); + break; + } +} +#endif /* RTE_LIBRTE_EAL_HOTPLUG */ + /* * If vendor/device ID match, call the devinit() function of the * driver. @@ -666,6 +691,75 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d return 1; } +#ifdef RTE_LIBRTE_EAL_HOTPLUG +/* + * If vendor/device ID match, call the devuninit() function of the + * driver. + */ +int +rte_eal_pci_close_one_driver(struct rte_pci_driver *dr, + struct rte_pci_device *dev) +{ + struct rte_pci_id *id_table; + + if ((dr == NULL) || (dev == NULL)) + return -EINVAL; + + for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) { + + /* check if device's identifiers match the driver's ones */ + if (id_table->vendor_id != dev->id.vendor_id && + id_table->vendor_id != PCI_ANY_ID) + continue; + if (id_table->device_id != dev->id.device_id && + id_table->device_id != PCI_ANY_ID) + continue; + if (id_table->subsystem_vendor_id != + dev->id.subsystem_vendor_id && + id_table->subsystem_vendor_id != PCI_ANY_ID) + continue; + if (id_table->subsystem_device_id != + dev->id.subsystem_device_id && + id_table->subsystem_device_id != PCI_ANY_ID) + continue; + + struct rte_pci_addr *loc = &dev->addr; + + RTE_LOG(DEBUG, EAL, + "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", + loc->domain, loc->bus, loc->devid, + loc->function, dev->numa_node); + + RTE_LOG(DEBUG, EAL, " remove driver: %x:%x %s\n", + dev->id.vendor_id, dev->id.device_id, + dr->name); + + /* call the driver devuninit() function */ + if (dr->devuninit && (dr->devuninit(dev) < 0)) + return -1; /* negative value is an error */ + + /* clear driver structure */ + dev->driver = NULL; + + if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) + /* unmap resources for devices that use igb_uio */ + pci_unmap_device(dev); + + return 0; + } + /* return positive value if driver is not found */ + return 1; +} +#else /* RTE_LIBRTE_EAL_HOTPLUG */ +int +rte_eal_pci_close_one_driver(struct rte_pci_driver *dr __rte_unused, + struct rte_pci_device *dev __rte_unused) +{ + RTE_LOG(ERR, EAL, "Hotplug support isn't enabled\n"); + return -1; +} +#endif /* RTE_LIBRTE_EAL_HOTPLUG */ + /* Init the PCI EAL subsystem */ int rte_eal_pci_init(void) diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 17515a9..5478492 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -38,8 +38,10 @@ DPDK_2.0 { rte_eal_lcore_role; rte_eal_mp_remote_launch; rte_eal_mp_wait_lcore; + rte_eal_pci_close_one; rte_eal_pci_dump; rte_eal_pci_probe; + rte_eal_pci_probe_one; rte_eal_pci_register; rte_eal_pci_unregister; rte_eal_process_type; diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index a26af75..0ca7147 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -286,7 +286,7 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) static int rte_eth_dev_init(struct rte_pci_driver *pci_drv, - struct rte_pci_device *pci_dev) + struct rte_pci_device *pci_dev) { struct eth_driver *eth_drv; struct rte_eth_dev *eth_dev; @@ -306,8 +306,8 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv, if (rte_eal_process_type() == RTE_PROC_PRIMARY){ eth_dev->data->dev_private = rte_zmalloc("ethdev private structure", - eth_drv->dev_private_size, - RTE_CACHE_LINE_SIZE); + eth_drv->dev_private_size, + RTE_CACHE_LINE_SIZE); if (eth_dev->data->dev_private == NULL) rte_panic("Cannot allocate memzone for private port data\n"); } -- 1.9.1