From patchwork Fri Oct 19 02:11:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10648567 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC570157A for ; Fri, 19 Oct 2018 02:11:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBA7F28D20 for ; Fri, 19 Oct 2018 02:11:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF1A428D28; Fri, 19 Oct 2018 02:11:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DB6528D20 for ; Fri, 19 Oct 2018 02:11:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726667AbeJSKPd (ORCPT ); Fri, 19 Oct 2018 06:15:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:39298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726562AbeJSKPd (ORCPT ); Fri, 19 Oct 2018 06:15:33 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.117.90.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BDD4620C0E; Fri, 19 Oct 2018 02:11:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539915097; bh=7Bw9BAD3dnrJ4c/qQu2mn0qi3to8fMTZjzgajDSHZKE=; h=From:To:Cc:Subject:Date:From; b=zBGqww0HRQWSsvhSe6VHVtzRDYM8gR9ufcoVq/im0uevcB/pO8wJ8qRFfJcMSyfra YSXmSZpWLfIXFNPGUdjpM9oZYOw7fuvQRZN3cw0wAt9WKhPTICjViGU0NJMpmejR1h 75ac3kFZrL6d2KnTn/aTbuOkrg1H9De09f0xlcqk= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Derek Chickles , Satanand Burla , Felix Manlunas , Raghu Vatsavayi , "David S. Miller" , Bjorn Helgaas , Boris Ostrovsky , Juergen Gross , Jia-Ju Bai Subject: [PATCH v6 1/7] PCI: Expose reset_type to users of __pci_reset_function_locked() Date: Fri, 19 Oct 2018 02:11:21 +0000 Message-Id: <20181019021132.14743-1-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We need a contract between the reset API users and the PCI core about the types of reset that a user needs vs. what PCI core can do internally. If a platform supports hotplug, we need to do hotplug reset as an example. Expose the reset types to the drivers and try different reset types based on the new reset_type parameter. Most users are expected to use PCI_RESET_ANY, PCI_RESET_FUNC or PCI_RESET_LINK parameters. Link: https://www.spinics.net/lists/linux-pci/msg75828.html Suggested-by: Alex Williamson Signed-off-by: Sinan Kaya --- .../net/ethernet/cavium/liquidio/lio_main.c | 2 +- drivers/pci/pci.c | 59 ++++++++++++------- drivers/xen/xen-pciback/pci_stub.c | 6 +- include/linux/pci.h | 58 +++++++++++++++++- 4 files changed, 100 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/ethernet/cavium/liquidio/lio_main.c index 6fb13fa73b27..0ff76722734d 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c @@ -989,7 +989,7 @@ static void octeon_pci_flr(struct octeon_device *oct) pci_write_config_word(oct->pci_dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE); - rc = __pci_reset_function_locked(oct->pci_dev); + rc = __pci_reset_function_locked(oct->pci_dev, PCI_RESET_ANY); if (rc != 0) dev_err(&oct->pci_dev->dev, "Error %d resetting PCI function %d\n", diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 1835f3a7aa8d..e292ea589d3e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4673,6 +4673,7 @@ static void pci_dev_restore(struct pci_dev *dev) * __pci_reset_function_locked - reset a PCI device function while holding * the @dev mutex lock. * @dev: PCI device to reset + * @reset_type: reset mask to try * * Some devices allow an individual function to be reset without affecting * other functions in the same device. The PCI device must be responsive @@ -4688,9 +4689,9 @@ static void pci_dev_restore(struct pci_dev *dev) * Returns 0 if the device function was successfully reset or negative if the * device doesn't support resetting a single function. */ -int __pci_reset_function_locked(struct pci_dev *dev) +int __pci_reset_function_locked(struct pci_dev *dev, u32 reset_type) { - int rc; + int rc = -EINVAL; might_sleep(); @@ -4702,24 +4703,42 @@ int __pci_reset_function_locked(struct pci_dev *dev) * other error, we're also finished: this indicates that further * reset mechanisms might be broken on the device. */ - rc = pci_dev_specific_reset(dev, 0); - if (rc != -ENOTTY) - return rc; - if (pcie_has_flr(dev)) { - rc = pcie_flr(dev); + if (reset_type & PCI_RESET_DEV_SPECIFIC) { + rc = pci_dev_specific_reset(dev, 0); if (rc != -ENOTTY) return rc; } - rc = pci_af_flr(dev, 0); - if (rc != -ENOTTY) - return rc; - rc = pci_pm_reset(dev, 0); - if (rc != -ENOTTY) - return rc; - rc = pci_dev_reset_slot_function(dev, 0); - if (rc != -ENOTTY) - return rc; - return pci_parent_bus_reset(dev, 0); + + if (reset_type & PCI_RESET_FLR) { + if (pcie_has_flr(dev)) { + rc = pcie_flr(dev); + if (rc != -ENOTTY) + return rc; + } + rc = pci_af_flr(dev, 0); + if (rc != -ENOTTY) + return rc; + } + + if (reset_type & PCI_RESET_PM) { + rc = pci_pm_reset(dev, 0); + if (rc != -ENOTTY) + return rc; + } + + if (reset_type & PCI_RESET_SLOT) { + rc = pci_dev_reset_slot_function(dev, 0); + if (rc != -ENOTTY) + return rc; + } + + if (reset_type & PCI_RESET_BUS) { + rc = pci_parent_bus_reset(dev, 0); + if (rc != -ENOTTY) + return rc; + } + + return rc; } EXPORT_SYMBOL_GPL(__pci_reset_function_locked); @@ -4784,7 +4803,7 @@ int pci_reset_function(struct pci_dev *dev) pci_dev_lock(dev); pci_dev_save_and_disable(dev); - rc = __pci_reset_function_locked(dev); + rc = __pci_reset_function_locked(dev, PCI_RESET_ANY); pci_dev_restore(dev); pci_dev_unlock(dev); @@ -4819,7 +4838,7 @@ int pci_reset_function_locked(struct pci_dev *dev) pci_dev_save_and_disable(dev); - rc = __pci_reset_function_locked(dev); + rc = __pci_reset_function_locked(dev, PCI_RESET_ANY); pci_dev_restore(dev); @@ -4844,7 +4863,7 @@ int pci_try_reset_function(struct pci_dev *dev) return -EAGAIN; pci_dev_save_and_disable(dev); - rc = __pci_reset_function_locked(dev); + rc = __pci_reset_function_locked(dev, PCI_RESET_ANY); pci_dev_restore(dev); pci_dev_unlock(dev); diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c index 59661db144e5..6dfb805bcb19 100644 --- a/drivers/xen/xen-pciback/pci_stub.c +++ b/drivers/xen/xen-pciback/pci_stub.c @@ -105,7 +105,7 @@ static void pcistub_device_release(struct kref *kref) /* Call the reset function which does not take lock as this * is called from "unbind" which takes a device_lock mutex. */ - __pci_reset_function_locked(dev); + __pci_reset_function_locked(dev, PCI_RESET_ANY); if (pci_load_and_free_saved_state(dev, &dev_data->pci_saved_state)) dev_info(&dev->dev, "Could not reload PCI state\n"); else @@ -283,7 +283,7 @@ void pcistub_put_pci_dev(struct pci_dev *dev) * (so it's ready for the next domain) */ device_lock_assert(&dev->dev); - __pci_reset_function_locked(dev); + __pci_reset_function_locked(dev, PCI_RESET_ANY); dev_data = pci_get_drvdata(dev); ret = pci_load_saved_state(dev, dev_data->pci_saved_state); @@ -417,7 +417,7 @@ static int pcistub_init_device(struct pci_dev *dev) dev_err(&dev->dev, "Could not store PCI conf saved state!\n"); else { dev_dbg(&dev->dev, "resetting (FLR, D3, etc) the device\n"); - __pci_reset_function_locked(dev); + __pci_reset_function_locked(dev, PCI_RESET_ANY); pci_restore_state(dev); } /* Now disable the device (this also ensures some private device diff --git a/include/linux/pci.h b/include/linux/pci.h index 6925828f9f25..7ace46b3e479 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -849,6 +849,62 @@ enum { PCI_SCAN_ALL_PCIE_DEVS = 0x00000040, /* Scan all, not just dev 0 */ }; +/* + * A common theme here is that the driver wants some degree of + * control of the type of reset used, vfio specifically wants to specify a + * bus or slot reset while hfi1 just wants to specify that the link is + * reset and doesn't care if it's a bus or slot reset that accomplishes + * that. The right "unified" interface is one that takes a parameter + * allowing the caller to specify the scope or type of reset + * with aliases so drivers can ignore the hotplug interface if they wish + * for special cases. + * + * PCI_RESET_ANY tries all reset type one by one until device is successfully + * reset. Under normal circumstances, most drivers are expected to use + * PCI_RESET_ANY as they don't usually care about the type of reset as long + * as device is reset. + * + * PCI_RESET_FUNC is useful when you want to reset one particular PCI device + * but you don't want to impact other devices or cause a temporary service + * outage. + * + * PCI_RESET_LINK can be used to cause a link retraining. This operation will + * cause service outage for the PCI bus if there are other devices on the same + * bus. PCI_RESET_LINK determines if a platform supports hotplug or not and + * suppresses hotplug interrupts during secondary bus reset. + * + * PCI_RESET_DEV_SPECIFIC can be used to reset a device by help from the + * device driver. Not all device drivers support this option. + * + * PCI_RESET_FLR can be used to issue a Function Level Reset to a device. This + * option will fail if FLR is not supported. + * + * PCI_RESET_PM can be used to reset the device via D3->D0 and D0->D3 sleep + * transition. This assumes that device supports PM based reset. + * + * PCI_RESET_SLOT forces a slot/hotplug reset. This will not work on platforms + * without hotplug capability. This option should only be used for advanced + * use-cases where driver developer absolutely knows that the device will never + * be used on non-hotplug environments. + * Not recommended for scalability. Please refer to PCI_RESET_LINK and let the + * PCI core do the hotplug detection. + * + * PCI_RESET_BUS performs a secondary bus reset on the link and causes a link + * recovery. Using this option directly and bypassing hotplug driver may + * cause a deadlock if platform supports hotplug. Please refer to + * PCI_RESET_LINK and let the PCI core do the hotplug detection. + */ +#define PCI_RESET_DEV_SPECIFIC (1 << 0) +#define PCI_RESET_FLR (1 << 1) +#define PCI_RESET_PM (1 << 2) +#define PCI_RESET_SLOT (1 << 3) +#define PCI_RESET_BUS (1 << 4) + +#define PCI_RESET_ANY (~0) +#define PCI_RESET_FUNC (PCI_RESET_DEV_SPECIFIC | \ + PCI_RESET_FLR | PCI_RESET_PM) +#define PCI_RESET_LINK (PCI_RESET_SLOT | PCI_RESET_BUS) + /* These external functions are only available when PCI support is enabled */ #ifdef CONFIG_PCI @@ -1111,7 +1167,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev, void pcie_print_link_status(struct pci_dev *dev); bool pcie_has_flr(struct pci_dev *dev); int pcie_flr(struct pci_dev *dev); -int __pci_reset_function_locked(struct pci_dev *dev); +int __pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); int pci_reset_function(struct pci_dev *dev); int pci_reset_function_locked(struct pci_dev *dev); int pci_try_reset_function(struct pci_dev *dev); From patchwork Fri Oct 19 02:11:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10648571 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6AF917DE for ; Fri, 19 Oct 2018 02:11:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7F4528D20 for ; Fri, 19 Oct 2018 02:11:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C49828D28; Fri, 19 Oct 2018 02:11:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E4E228D20 for ; Fri, 19 Oct 2018 02:11:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726675AbeJSKPh (ORCPT ); Fri, 19 Oct 2018 06:15:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:39332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726562AbeJSKPh (ORCPT ); Fri, 19 Oct 2018 06:15:37 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.117.90.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1BD6021476; Fri, 19 Oct 2018 02:11:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539915101; bh=zvBp+b/C2s+Ahiz8MyUHA+EAxqPaQeywC22Qo/a8tcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qxFaJfsXXAy95zknm7TZfYiow1DG1ZttaCOi/Ze+9yXbMilx2AjK2P7hiyzhofQgl HOcn3M0QeWPnS1zWS0LJeM2U2NMzxEW0ewERluhlDK3cB2O5ZKAk2IRb7VJnsbnxGw F11xi6h3Tr/Q/rq1/I+tRilmSd1cPK9FbpX9FcZY= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Srinivas Pandruvada , Jiri Kosina , Benjamin Tissoires , Frank Haverkamp , "Guilherme G. Piccoli" , Arnd Bergmann , Greg Kroah-Hartman , Harish Patil , Manish Chopra , Dept-GELinuxNICDev@cavium.com, "David S. Miller" , Solarflare linux maintainers , Edward Cree , Bert Kenward , Bjorn Helgaas , Anton Vasilyev Subject: [PATCH v6 2/7] PCI: Expose reset_type to users of pci_reset_function() Date: Fri, 19 Oct 2018 02:11:22 +0000 Message-Id: <20181019021132.14743-2-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181019021132.14743-1-okaya@kernel.org> References: <20181019021132.14743-1-okaya@kernel.org> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Looking to have more control between the users of the API vs. what the API can do internally. The new reset_type tells the PCI core about the bounds of the request. PCI_RESET_ANY was chosen to match the existing behavior in the code. Current pci_reset_function() tries all reset types one by one until it returns 0. By specifying PCI_RESET_ANY, we get the same behavior like before. Signed-off-by: Sinan Kaya Acked-by: Srinivas Pandruvada (drivers/hid/intel-ish-hid/ipc/ipc.c) --- drivers/hid/intel-ish-hid/ipc/ipc.c | 2 +- drivers/misc/genwqe/card_base.c | 2 +- drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 2 +- drivers/net/ethernet/sfc/mcdi.c | 2 +- drivers/pci/pci-sysfs.c | 2 +- drivers/pci/pci.c | 5 +++-- include/linux/pci.h | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index bfbca7ec54ce..18312969f1b3 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c @@ -754,7 +754,7 @@ static int _ish_hw_reset(struct ishtp_device *dev) if (!pdev) return -ENODEV; - rv = pci_reset_function(pdev); + rv = pci_reset_function(pdev, PCI_RESET_ANY); if (!rv) dev->dev_state = ISHTP_DEV_RESETTING; diff --git a/drivers/misc/genwqe/card_base.c b/drivers/misc/genwqe/card_base.c index c7cd3675bcd1..cc78ef28ee38 100644 --- a/drivers/misc/genwqe/card_base.c +++ b/drivers/misc/genwqe/card_base.c @@ -201,7 +201,7 @@ static int genwqe_bus_reset(struct genwqe_dev *cd) * restored by the pci_reset_function(). */ dev_dbg(&pci_dev->dev, "[%s] pci_reset function ...\n", __func__); - rc = pci_reset_function(pci_dev); + rc = pci_reset_function(pci_dev, PCI_RESET_ANY); if (rc) { dev_err(&pci_dev->dev, "[%s] err: failed reset func (rc %d)\n", __func__, rc); diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c index d344e9d43832..bb737725f175 100644 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c @@ -629,7 +629,7 @@ int qlcnic_fw_create_ctx(struct qlcnic_adapter *dev) int i, err, ring; if (dev->flags & QLCNIC_NEED_FLR) { - pci_reset_function(dev->pdev); + pci_reset_function(dev->pdev, PCI_RESET_ANY); dev->flags &= ~QLCNIC_NEED_FLR; } diff --git a/drivers/net/ethernet/sfc/mcdi.c b/drivers/net/ethernet/sfc/mcdi.c index dfad93fca0a6..7f95e17b8a48 100644 --- a/drivers/net/ethernet/sfc/mcdi.c +++ b/drivers/net/ethernet/sfc/mcdi.c @@ -1862,7 +1862,7 @@ int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method) /* If MCDI is down, we can't handle_assertion */ if (method == RESET_TYPE_MCDI_TIMEOUT) { - rc = pci_reset_function(efx->pci_dev); + rc = pci_reset_function(efx->pci_dev, PCI_RESET_ANY); if (rc) return rc; /* Re-enable polled MCDI completion */ diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 9ecfe13157c0..9569664ec4b2 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1449,7 +1449,7 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr, return -EINVAL; pm_runtime_get_sync(dev); - result = pci_reset_function(pdev); + result = pci_reset_function(pdev, PCI_RESET_ANY); pm_runtime_put(dev); if (result < 0) return result; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e292ea589d3e..66f102b7ed4e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4780,6 +4780,7 @@ int pci_probe_reset_function(struct pci_dev *dev) /** * pci_reset_function - quiesce and reset a PCI device function * @dev: PCI device to reset + * @reset_type: reset type to apply * * Some devices allow an individual function to be reset without affecting * other functions in the same device. The PCI device must be responsive @@ -4793,7 +4794,7 @@ int pci_probe_reset_function(struct pci_dev *dev) * Returns 0 if the device function was successfully reset or negative if the * device doesn't support resetting a single function. */ -int pci_reset_function(struct pci_dev *dev) +int pci_reset_function(struct pci_dev *dev, u32 reset_type) { int rc; @@ -4803,7 +4804,7 @@ int pci_reset_function(struct pci_dev *dev) pci_dev_lock(dev); pci_dev_save_and_disable(dev); - rc = __pci_reset_function_locked(dev, PCI_RESET_ANY); + rc = __pci_reset_function_locked(dev, reset_type); pci_dev_restore(dev); pci_dev_unlock(dev); diff --git a/include/linux/pci.h b/include/linux/pci.h index 7ace46b3e479..927e60660b96 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1168,7 +1168,7 @@ void pcie_print_link_status(struct pci_dev *dev); bool pcie_has_flr(struct pci_dev *dev); int pcie_flr(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); -int pci_reset_function(struct pci_dev *dev); +int pci_reset_function(struct pci_dev *dev, u32 reset_type); int pci_reset_function_locked(struct pci_dev *dev); int pci_try_reset_function(struct pci_dev *dev); int pci_probe_reset_slot(struct pci_slot *slot); From patchwork Fri Oct 19 02:11:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10648569 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED82F17DE for ; Fri, 19 Oct 2018 02:11:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF9E028D20 for ; Fri, 19 Oct 2018 02:11:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3B2228D28; Fri, 19 Oct 2018 02:11:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80AB628D20 for ; Fri, 19 Oct 2018 02:11:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726698AbeJSKPh (ORCPT ); Fri, 19 Oct 2018 06:15:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:39362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726675AbeJSKPg (ORCPT ); Fri, 19 Oct 2018 06:15:36 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.117.90.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC51620C0E; Fri, 19 Oct 2018 02:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539915102; bh=NeF7DSWYJhs8JiwwkzwyNQYsENT5suUO2Jk1v/zjfIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0+wmqPw4r3TpjnjGkhvkW0cNkW3n6bvs7Se+f16dOBvfPOVTMWt3/m3arIafvHB5S SAT8nBbuWSq+OhJ2kyOeyo3LkXal2J3YlPNPW2a/s59UmvX0hnBHs+gOYbe/W580e/ KfVh2+PwxBIXcSYohcSSIgzFxCb30U0V76GT7aDQ= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Bjorn Helgaas Subject: [PATCH v6 3/7] PCI: Expose reset_type to users of pci_reset_function_locked() Date: Fri, 19 Oct 2018 02:11:23 +0000 Message-Id: <20181019021132.14743-3-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181019021132.14743-1-okaya@kernel.org> References: <20181019021132.14743-1-okaya@kernel.org> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Looking to have more control between the users of the API vs. what the API can do internally. The new reset_type tells the PCI core about the bounds of the request. Signed-off-by: Sinan Kaya --- drivers/pci/pci.c | 5 +++-- include/linux/pci.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 66f102b7ed4e..9a649d1adb13 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4816,6 +4816,7 @@ EXPORT_SYMBOL_GPL(pci_reset_function); /** * pci_reset_function_locked - quiesce and reset a PCI device function * @dev: PCI device to reset + * @reset_type: reset type to apply * * Some devices allow an individual function to be reset without affecting * other functions in the same device. The PCI device must be responsive @@ -4830,7 +4831,7 @@ EXPORT_SYMBOL_GPL(pci_reset_function); * Returns 0 if the device function was successfully reset or negative if the * device doesn't support resetting a single function. */ -int pci_reset_function_locked(struct pci_dev *dev) +int pci_reset_function_locked(struct pci_dev *dev, u32 reset_type) { int rc; @@ -4839,7 +4840,7 @@ int pci_reset_function_locked(struct pci_dev *dev) pci_dev_save_and_disable(dev); - rc = __pci_reset_function_locked(dev, PCI_RESET_ANY); + rc = __pci_reset_function_locked(dev, reset_type); pci_dev_restore(dev); diff --git a/include/linux/pci.h b/include/linux/pci.h index 927e60660b96..9103ac1b3c31 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1169,7 +1169,7 @@ bool pcie_has_flr(struct pci_dev *dev); int pcie_flr(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); int pci_reset_function(struct pci_dev *dev, u32 reset_type); -int pci_reset_function_locked(struct pci_dev *dev); +int pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); int pci_try_reset_function(struct pci_dev *dev); int pci_probe_reset_slot(struct pci_slot *slot); int pci_probe_reset_bus(struct pci_bus *bus); From patchwork Fri Oct 19 02:11:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10648573 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD594157A for ; Fri, 19 Oct 2018 02:11:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE8CB28D26 for ; Fri, 19 Oct 2018 02:11:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2A1C28D29; Fri, 19 Oct 2018 02:11:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DEC928D26 for ; Fri, 19 Oct 2018 02:11:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726634AbeJSKPn (ORCPT ); Fri, 19 Oct 2018 06:15:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:39388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726562AbeJSKPm (ORCPT ); Fri, 19 Oct 2018 06:15:42 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.117.90.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D7F2520C0E; Fri, 19 Oct 2018 02:11:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539915107; bh=y4r3AvkjjrZMBQE2Q3H97tXiGtUujmmkQe62oub6yxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HeCDyJ46wNo7TptAl8mu14Te0KTLi6BU5JFRe+7z/YHbjk0fROiB2CyYj4/bLSfpj XQRipNWMJ5rj9gXBCt3a3BJxa6MOfUkVwL7ugMd4RdBs4x2zhmlY20nj5VQXDxnG1O KfwJbEH1SIF6bMCeqqfXU3grSkM7H9Aezm9snyEo= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Bjorn Helgaas , Alex Williamson , Alexey Kardashevskiy , Peter Xu , "Gustavo A. R. Silva" Subject: [PATCH v6 4/7] PCI: Expose reset type to users of pci_try_reset_function() Date: Fri, 19 Oct 2018 02:11:24 +0000 Message-Id: <20181019021132.14743-4-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181019021132.14743-1-okaya@kernel.org> References: <20181019021132.14743-1-okaya@kernel.org> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Looking to have more control between the users of the API vs. what the API can do internally. The new reset_type tells the PCI core about the bounds of the request. Signed-off-by: Sinan Kaya --- drivers/pci/pci.c | 5 +++-- drivers/vfio/pci/vfio_pci.c | 7 ++++--- drivers/vfio/pci/vfio_pci_config.c | 4 ++-- include/linux/pci.h | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 9a649d1adb13..7739f28988ae 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4851,10 +4851,11 @@ EXPORT_SYMBOL_GPL(pci_reset_function_locked); /** * pci_try_reset_function - quiesce and reset a PCI device function * @dev: PCI device to reset + * @reset_type: reset type to apply * * Same as above, except return -EAGAIN if unable to lock device. */ -int pci_try_reset_function(struct pci_dev *dev) +int pci_try_reset_function(struct pci_dev *dev, u32 reset_type) { int rc; @@ -4865,7 +4866,7 @@ int pci_try_reset_function(struct pci_dev *dev) return -EAGAIN; pci_dev_save_and_disable(dev); - rc = __pci_reset_function_locked(dev, PCI_RESET_ANY); + rc = __pci_reset_function_locked(dev, reset_type); pci_dev_restore(dev); pci_dev_unlock(dev); diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index cddb453a1ba5..fe7ada997c51 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -228,7 +228,7 @@ static int vfio_pci_enable(struct vfio_pci_device *vdev) return ret; /* If reset fails because of the device lock, fail this path entirely */ - ret = pci_try_reset_function(pdev); + ret = pci_try_reset_function(pdev, PCI_RESET_ANY); if (ret == -EAGAIN) { pci_disable_device(pdev); return ret; @@ -376,7 +376,7 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev) * Try to reset the device. The success of this is dependent on * being able to lock the device, which is not always possible. */ - if (vdev->reset_works && !pci_try_reset_function(pdev)) + if (vdev->reset_works && !pci_try_reset_function(pdev, PCI_RESET_ANY)) vdev->needs_reset = false; pci_restore_state(pdev); @@ -844,7 +844,8 @@ static long vfio_pci_ioctl(void *device_data, } else if (cmd == VFIO_DEVICE_RESET) { return vdev->reset_works ? - pci_try_reset_function(vdev->pdev) : -EINVAL; + pci_try_reset_function(vdev->pdev, PCI_RESET_ANY) : + -EINVAL; } else if (cmd == VFIO_DEVICE_GET_PCI_HOT_RESET_INFO) { struct vfio_pci_hot_reset_info hdr; diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 115a36f6f403..0d66bac66211 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -831,7 +831,7 @@ static int vfio_exp_config_write(struct vfio_pci_device *vdev, int pos, &cap); if (!ret && (cap & PCI_EXP_DEVCAP_FLR)) - pci_try_reset_function(vdev->pdev); + pci_try_reset_function(vdev->pdev, PCI_RESET_ANY); } /* @@ -910,7 +910,7 @@ static int vfio_af_config_write(struct vfio_pci_device *vdev, int pos, &cap); if (!ret && (cap & PCI_AF_CAP_FLR) && (cap & PCI_AF_CAP_TP)) - pci_try_reset_function(vdev->pdev); + pci_try_reset_function(vdev->pdev, PCI_RESET_ANY); } return count; diff --git a/include/linux/pci.h b/include/linux/pci.h index 9103ac1b3c31..cde63e0a85ea 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1170,7 +1170,7 @@ int pcie_flr(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); int pci_reset_function(struct pci_dev *dev, u32 reset_type); int pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); -int pci_try_reset_function(struct pci_dev *dev); +int pci_try_reset_function(struct pci_dev *dev, u32 reset_type); int pci_probe_reset_slot(struct pci_slot *slot); int pci_probe_reset_bus(struct pci_bus *bus); int pci_reset_bus(struct pci_dev *dev); From patchwork Fri Oct 19 02:11:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10648575 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C6989157A for ; Fri, 19 Oct 2018 02:11:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B910F28D26 for ; Fri, 19 Oct 2018 02:11:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD5BE28D29; Fri, 19 Oct 2018 02:11:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DF7728D26 for ; Fri, 19 Oct 2018 02:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726747AbeJSKPn (ORCPT ); Fri, 19 Oct 2018 06:15:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:39400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbeJSKPn (ORCPT ); Fri, 19 Oct 2018 06:15:43 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.117.90.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EFB5521476; Fri, 19 Oct 2018 02:11:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539915108; bh=vp9qC3YiLnSl3Q92dXbgn7jZasg7kOOVChQZcHo90dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SWbZFACmcMQVwZVRK+wadNUZHb9TNkt4/zquFiUpSynTXK2Lvo9ztCE0XVj8ggL4X ELgelJp3Sr0LcmSdLlZdRtuxRSLOaXx2OKKrsL8VUeYWcDt6aDxb2dGd0hL0lf+5Sf MAPGcbwOZ5vGdfKy2VOfQ8hzKQ6aXSnfg/xTWTgo= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Bjorn Helgaas Subject: [PATCH v6 5/7] PCI: Expose reset type to users of pci_probe_reset_function() Date: Fri, 19 Oct 2018 02:11:25 +0000 Message-Id: <20181019021132.14743-5-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181019021132.14743-1-okaya@kernel.org> References: <20181019021132.14743-1-okaya@kernel.org> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Looking to have more control between the users of the API vs. what the API can do internally. The new reset_type tells the PCI core about the bounds of the request. Signed-off-by: Sinan Kaya --- drivers/pci/pci.c | 52 ++++++++++++++++++++++++++++++--------------- drivers/pci/pci.h | 2 +- drivers/pci/probe.c | 2 +- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7739f28988ae..a1a7dd6988be 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4745,6 +4745,7 @@ EXPORT_SYMBOL_GPL(__pci_reset_function_locked); /** * pci_probe_reset_function - check whether the device can be safely reset * @dev: PCI device to reset + * @reset_type: reset type to apply * * Some devices allow an individual function to be reset without affecting * other functions in the same device. The PCI device must be responsive @@ -4753,28 +4754,45 @@ EXPORT_SYMBOL_GPL(__pci_reset_function_locked); * Returns 0 if the device function can be reset or negative if the * device doesn't support resetting a single function. */ -int pci_probe_reset_function(struct pci_dev *dev) +int pci_probe_reset_function(struct pci_dev *dev, u32 reset_type) { - int rc; + int rc = 0; might_sleep(); - rc = pci_dev_specific_reset(dev, 1); - if (rc != -ENOTTY) - return rc; - if (pcie_has_flr(dev)) - return 0; - rc = pci_af_flr(dev, 1); - if (rc != -ENOTTY) - return rc; - rc = pci_pm_reset(dev, 1); - if (rc != -ENOTTY) - return rc; - rc = pci_dev_reset_slot_function(dev, 1); - if (rc != -ENOTTY) - return rc; + if (reset_type & PCI_RESET_DEV_SPECIFIC) { + rc = pci_dev_specific_reset(dev, 1); + if (rc != -ENOTTY) + return rc; + } + + if (reset_type & PCI_RESET_FLR) { + if (pcie_has_flr(dev)) + return 0; + rc = pci_af_flr(dev, 1); + if (rc != -ENOTTY) + return rc; + } - return pci_parent_bus_reset(dev, 1); + if (reset_type & PCI_RESET_PM) { + rc = pci_pm_reset(dev, 1); + if (rc != -ENOTTY) + return rc; + } + + if (reset_type & PCI_RESET_SLOT) { + rc = pci_dev_reset_slot_function(dev, 1); + if (rc != -ENOTTY) + return rc; + } + + if (reset_type & PCI_RESET_BUS) { + rc = pci_parent_bus_reset(dev, 1); + if (rc != -ENOTTY) + return rc; + } + + return rc; } /** diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 6e0d1528d471..0444bfa51b52 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -33,7 +33,7 @@ enum pci_mmap_api { int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai, enum pci_mmap_api mmap_api); -int pci_probe_reset_function(struct pci_dev *dev); +int pci_probe_reset_function(struct pci_dev *dev, u32 reset_type); int pci_bridge_secondary_bus_reset(struct pci_dev *dev); /** diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 201f9e5ff55c..6c8f6af2d4aa 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2335,7 +2335,7 @@ static void pci_init_capabilities(struct pci_dev *dev) pcie_report_downtraining(dev); - if (pci_probe_reset_function(dev) == 0) + if (pci_probe_reset_function(dev, PCI_RESET_ANY) == 0) dev->reset_fn = 1; } From patchwork Fri Oct 19 02:11:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10648579 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 346C8157A for ; Fri, 19 Oct 2018 02:11:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27FB128D26 for ; Fri, 19 Oct 2018 02:11:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C6A128D2B; Fri, 19 Oct 2018 02:11:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B259E28D26 for ; Fri, 19 Oct 2018 02:11:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726979AbeJSKPr (ORCPT ); Fri, 19 Oct 2018 06:15:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:39452 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726562AbeJSKPq (ORCPT ); Fri, 19 Oct 2018 06:15:46 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.117.90.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CEB6921476; Fri, 19 Oct 2018 02:11:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539915111; bh=gDfHFcT1tvEtfqc2+yETFJCZ3pXbiWpsG2CJkUPQW6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OniIPY3WtMx3mFmBBEIpA7tZz6YFVYCv05901h7bSUQp5HTcjjdbVDp2+b11G2dl1 jZCH+zTmWWVerMD9MTGqm42O6Q+8Vs45L6QmmeCwdBLIBsD9FWAcHVI8gcBIzNaUDd ON6Fy4q0mLyYZ7oKTS4xVGRFKz5zd82Sqf5EwgCA= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Bjorn Helgaas , Alex Williamson , Alexey Kardashevskiy , Peter Xu , "Gustavo A. R. Silva" Subject: [PATCH v6 6/7] PCI: Expose reset type to users of pci_reset_bus() Date: Fri, 19 Oct 2018 02:11:26 +0000 Message-Id: <20181019021132.14743-6-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181019021132.14743-1-okaya@kernel.org> References: <20181019021132.14743-1-okaya@kernel.org> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Looking to have more control between the users of the API vs. what the API can do internally. The new reset_type tells the PCI core about the bounds of the request. pci_reset_bus() calls different slot reset mechanisms based on given mask. Slot based reset is prioritized over bus reset. Users are expected to use PCI_RESET_SLOT mask by default. Signed-off-by: Sinan Kaya --- drivers/pci/pci.c | 12 +++++++++--- drivers/vfio/pci/vfio_pci.c | 6 ++++-- include/linux/pci.h | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index a1a7dd6988be..1feecbb7f85d 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5236,13 +5236,19 @@ static int __pci_reset_bus(struct pci_bus *bus) /** * pci_reset_bus - Try to reset a PCI bus * @pdev: top level PCI device to reset via slot/bus + * @reset_type: resets to try * * Same as above except return -EAGAIN if the bus cannot be locked */ -int pci_reset_bus(struct pci_dev *pdev) +int pci_reset_bus(struct pci_dev *pdev, u32 reset_type) { - return (!pci_probe_reset_slot(pdev->slot)) ? - __pci_reset_slot(pdev->slot) : __pci_reset_bus(pdev->bus); + if ((reset_type & PCI_RESET_SLOT) && !pci_probe_reset_slot(pdev->slot)) + return __pci_reset_slot(pdev->slot); + + if ((reset_type & PCI_RESET_BUS) && !pci_probe_reset_bus(pdev->bus)) + return __pci_reset_bus(pdev->bus); + + return -EINVAL; } EXPORT_SYMBOL_GPL(pci_reset_bus); diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index fe7ada997c51..0e80c72b1eaa 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -1015,7 +1015,8 @@ static long vfio_pci_ioctl(void *device_data, &info, slot); if (!ret) /* User has access, do the reset */ - ret = pci_reset_bus(vdev->pdev); + ret = pci_reset_bus(vdev->pdev, + slot ? PCI_RESET_SLOT : PCI_RESET_BUS); hot_reset_release: for (i--; i >= 0; i--) @@ -1390,7 +1391,8 @@ static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev) } if (needs_reset) - ret = pci_reset_bus(vdev->pdev); + ret = pci_reset_bus(vdev->pdev, + slot ? PCI_RESET_SLOT : PCI_RESET_BUS); put_devs: for (i = 0; i < devs.cur_index; i++) { diff --git a/include/linux/pci.h b/include/linux/pci.h index cde63e0a85ea..8ee4e3c177fe 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1173,7 +1173,7 @@ int pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); int pci_try_reset_function(struct pci_dev *dev, u32 reset_type); int pci_probe_reset_slot(struct pci_slot *slot); int pci_probe_reset_bus(struct pci_bus *bus); -int pci_reset_bus(struct pci_dev *dev); +int pci_reset_bus(struct pci_dev *dev, u32 reset_type); void pci_reset_secondary_bus(struct pci_dev *dev); void pcibios_reset_secondary_bus(struct pci_dev *dev); void pci_update_resource(struct pci_dev *dev, int resno); From patchwork Fri Oct 19 02:11:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10648577 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC69F17DE for ; Fri, 19 Oct 2018 02:11:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCA7628D28 for ; Fri, 19 Oct 2018 02:11:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACB8028D29; Fri, 19 Oct 2018 02:11:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BEAB28D26 for ; Fri, 19 Oct 2018 02:11:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725934AbeJSKPr (ORCPT ); Fri, 19 Oct 2018 06:15:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:39484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726979AbeJSKPr (ORCPT ); Fri, 19 Oct 2018 06:15:47 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.117.90.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D89DB21477; Fri, 19 Oct 2018 02:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539915112; bh=l3v8vKI0V8kjFjpRwnfw1GSPx+uqJiQZWnJo40XoNas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G5Ej2xgDA7+QBJJI6dNaz9fbdDEXUQU+KyoCmhxvSZgAhGgqBKO+b0eLAHpz/4XWJ ELpOJeai2H71wO8rHE2X7dD7+LTIegqT8vMJ2WQX9ze06YTC954LPArSvU5pqBEEZ6 YWCKSYvyGjulh0qeUkiCfl+DXStXqO7Ho7tfqw2Y= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Mike Marciniszyn , Dennis Dalessandro , Doug Ledford , Jason Gunthorpe , Bjorn Helgaas Subject: [PATCH v6 7/7] IB/hfi1,PCI: switch to __pci_function_locked() for reset request Date: Fri, 19 Oct 2018 02:11:27 +0000 Message-Id: <20181019021132.14743-7-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181019021132.14743-1-okaya@kernel.org> References: <20181019021132.14743-1-okaya@kernel.org> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Start using the new reset API rather than the workaround. Signed-off-by: Sinan Kaya Acked-by: Doug Ledford --- drivers/infiniband/hw/hfi1/pcie.c | 2 +- include/linux/pci.h | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/pcie.c b/drivers/infiniband/hw/hfi1/pcie.c index 6c967dde58e7..38f96192e5f0 100644 --- a/drivers/infiniband/hw/hfi1/pcie.c +++ b/drivers/infiniband/hw/hfi1/pcie.c @@ -897,7 +897,7 @@ static int trigger_sbr(struct hfi1_devdata *dd) * to be implemented to have cleaner interface but this fixes the * current brokenness */ - return pci_bridge_secondary_bus_reset(dev->bus->self); + return __pci_reset_function_locked(dev, PCI_RESET_LINK); } /* diff --git a/include/linux/pci.h b/include/linux/pci.h index 8ee4e3c177fe..cfb1018d774e 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1291,9 +1291,6 @@ void pci_bus_remove_resources(struct pci_bus *bus); int devm_request_pci_bus_resources(struct device *dev, struct list_head *resources); -/* Temporary until new and working PCI SBR API in place */ -int pci_bridge_secondary_bus_reset(struct pci_dev *dev); - #define pci_bus_for_each_resource(bus, res, i) \ for (i = 0; \ (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \