From patchwork Thu Oct 11 04:49:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982238 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="w/uwjanx"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz6h5JGtz9s9J for ; Thu, 11 Oct 2018 15:50:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726666AbeJKMPl (ORCPT ); Thu, 11 Oct 2018 08:15:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:53948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726212AbeJKMPl (ORCPT ); Thu, 11 Oct 2018 08:15:41 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 48F2320841; Thu, 11 Oct 2018 04:50:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233412; bh=mcdQlOBAxTEQO9t2dxJbJrMITXp7TYCcr+dlDHny344=; h=From:To:Cc:Subject:Date:From; b=w/uwjanx5BfSdn3d42uX67ORaCL/pMsRFKfARMresadYAm4Mv8uBmwVvEfTC26yVK Gu3Lev11R1z1OivCKQNGorWbdG7UcppUiAgSScos/RIWZL7COn6opss/jyzlsxFo08 4QXnT3Mrignho/PettJ5FCIZPTkYm8QBu9FZcaXk= 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 v5 01/11] PCI: Expose reset_type to users of __pci_reset_function_locked() Date: Thu, 11 Oct 2018 04:49:53 +0000 Message-Id: <20181011045008.32212-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 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 | 56 +++++++++++++++++- 4 files changed, 98 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..0967e6bad421 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -849,6 +849,60 @@ 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 and assumes hotplug capability from a platform + * This option should only be used for advanced use-cases. + * Not recommended for scalability. Please refer to PCI_RESET_LINK. + * + * 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 above. + */ +#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 +1165,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 Thu Oct 11 04:49:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982239 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="K9N6IHQ8"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz6k1Zpbz9s9h for ; Thu, 11 Oct 2018 15:50:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbeJKMPo (ORCPT ); Thu, 11 Oct 2018 08:15:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:54022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726212AbeJKMPo (ORCPT ); Thu, 11 Oct 2018 08:15:44 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8A86B20865; Thu, 11 Oct 2018 04:50:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233416; bh=Ci8jIKd7vTgdu/WylF+ANMNbDBEJ7P/ZHwYr8FfQy2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K9N6IHQ84wgbUdNrePniC7Eem4nQllqpl+WehwHwKqSFyIVI3l+RL/s8LfZx9ZhHu nuskGuLDGdgi0lghCYUozDG4fhds7PxTBmjyw2F+trBxxyW79ugBrjMnvDAFeALGm2 joZgFL/KCbdajyWirHhWoQrp7ML8ZFEoPyMdH8yE= 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 v5 02/11] PCI: Expose reset_type to users of pci_reset_function() Date: Thu, 11 Oct 2018 04:49:54 +0000 Message-Id: <20181011045008.32212-2-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 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 0967e6bad421..b72689f869db 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1166,7 +1166,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 Thu Oct 11 04:49:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982240 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="AiQhYUIM"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz6l0dzWz9sC2 for ; Thu, 11 Oct 2018 15:50:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726870AbeJKMPp (ORCPT ); Thu, 11 Oct 2018 08:15:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:54056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726212AbeJKMPp (ORCPT ); Thu, 11 Oct 2018 08:15:45 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 62E042087A; Thu, 11 Oct 2018 04:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233416; bh=k4fgdw5WtatJLLbpzHV+K9lV999vPez3vItbpP3yn40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AiQhYUIM0xHD87W3i/Y15137ne1zWL1mwjclfakrvPGgz5Y+7deaP4QYBu7emIR9z P0Lv/cTfgVsmo+5yu2B8vDl8tKleUDuxz8MD9ML9b4K1Ld3gbqhL2G7ETkYtG4VbW5 MDnZBJ9t1yJoY0REJQr+i2Na9Vn3aIGr+KcEIxcU= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Bjorn Helgaas Subject: [PATCH v5 03/11] PCI: Expose reset_type to users of pci_reset_function_locked() Date: Thu, 11 Oct 2018 04:49:55 +0000 Message-Id: <20181011045008.32212-3-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 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 b72689f869db..e1d1328172fa 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1167,7 +1167,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 Thu Oct 11 04:49:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982241 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="fCSuBL6i"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz6m5Xsrz9s9h for ; Thu, 11 Oct 2018 15:50:24 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726907AbeJKMPu (ORCPT ); Thu, 11 Oct 2018 08:15:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:54166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726212AbeJKMPu (ORCPT ); Thu, 11 Oct 2018 08:15:50 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 381D520841; Thu, 11 Oct 2018 04:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233421; bh=FyVs9x4DukV6x1VgYaf+w9ZVBZHmyJAtgMTK6cg44bE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fCSuBL6i57iYA2s9ro4q4wn3nMPLsg8T+3EeR57LWHLYMRNr/oaRnL/LtLpxiieSC 2qXqUnaL5KkUg/5srqSil+H2L0ECIGUNJj7LssbntssB+3Od3EN4nBRoDQbv8a6O6V q9eyOH0YTWfKtziQQ8RdQBakHJWLdg1IFS2mN0OA= 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 v5 04/11] PCI: Expose reset type to users of pci_try_reset_function() Date: Thu, 11 Oct 2018 04:49:56 +0000 Message-Id: <20181011045008.32212-4-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 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 e1d1328172fa..1c120cf00dd8 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1168,7 +1168,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 Thu Oct 11 04:49:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982242 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="frvUtMru"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz6n3Xk7z9sC2 for ; Thu, 11 Oct 2018 15:50:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726212AbeJKMPv (ORCPT ); Thu, 11 Oct 2018 08:15:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:54186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726906AbeJKMPu (ORCPT ); Thu, 11 Oct 2018 08:15:50 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4CB582087A; Thu, 11 Oct 2018 04:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233422; bh=vp9qC3YiLnSl3Q92dXbgn7jZasg7kOOVChQZcHo90dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=frvUtMru22dgMQyD+EOxQcimcplYQCjMJNea2CGvESQ8rx+6Drqq6OwIEHzoSCeOU cd4lW9ssdN8i9OvSSRu3jimKFkAzUfxj4xCiCKxyN5ym4n2dE6Kz7HCcAU5xYtJm75 CR5+L7K0gBD61B3ub5cje7ONlwoEYkBmWifg0Kr0= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Bjorn Helgaas Subject: [PATCH v5 05/11] PCI: Expose reset type to users of pci_probe_reset_function() Date: Thu, 11 Oct 2018 04:49:57 +0000 Message-Id: <20181011045008.32212-5-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 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 Thu Oct 11 04:49:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982243 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="CMPXA4Jt"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz6q23wjz9s9h for ; Thu, 11 Oct 2018 15:50:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726911AbeJKMPy (ORCPT ); Thu, 11 Oct 2018 08:15:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:54264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726906AbeJKMPy (ORCPT ); Thu, 11 Oct 2018 08:15:54 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1BC912087A; Thu, 11 Oct 2018 04:50:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233425; bh=o7OTh+ogjKMEY34Ww41kwnhbBc1CSDn6otmqFzfid2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CMPXA4Jt9AGOKhqb3wraNCGJHVvvMN1K2IFIiBdDfFIUZhdYkSd6sCloPEN8FoAX8 L2G5Mobx3riyZvjS9oSLO95qRlR813cVoQU2+cFR+vnGQolZVFejB9MtzWvDrHQA7J hXvuZdBxtQ3g8FRj5FFToPP0weIUzAPhgz4H4kfM= 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 v5 06/11] PCI: Expose reset type to users of pci_reset_bus() Date: Thu, 11 Oct 2018 04:49:58 +0000 Message-Id: <20181011045008.32212-6-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 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 | 17 ++++++++++++++--- drivers/vfio/pci/vfio_pci.c | 6 ++++-- include/linux/pci.h | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index a1a7dd6988be..a3a1c2a5e0cf 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5236,13 +5236,24 @@ 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_LINK) == PCI_RESET_LINK) + return (!pci_probe_reset_slot(pdev->slot)) ? + __pci_reset_slot(pdev->slot) : + __pci_reset_bus(pdev->bus); + + if ((reset_type & PCI_RESET_BUS) == PCI_RESET_BUS) + return __pci_reset_bus(pdev->bus); + + if ((reset_type & PCI_RESET_SLOT) == PCI_RESET_SLOT) + return __pci_reset_slot(pdev->slot); + + 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 1c120cf00dd8..cf1e847ea02e 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1171,7 +1171,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 Thu Oct 11 04:49:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982244 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="anzz0xEa"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz6r0hHBz9sC2 for ; Thu, 11 Oct 2018 15:50:28 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726942AbeJKMPy (ORCPT ); Thu, 11 Oct 2018 08:15:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:54284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726906AbeJKMPy (ORCPT ); Thu, 11 Oct 2018 08:15:54 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 278D72087D; Thu, 11 Oct 2018 04:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233426; bh=nKyK3MiTrb88AkY8yeTu3MRQLBpj4IMYoZE4VxsHNmQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=anzz0xEarrgP6cWDvOHK5o4IgZFIWX1tYp2zuQNPXT/Wt/u1eMnw8QSiuQTCVuWOD VB1TJ9idAE5A7Mcz0EZ4UAfkrNMwrTuOpp9L4fWAJujLX9iS7+n0D94tURJdVpgkt1 n4D3nWbMg99zBX7Y7CIPDvTAaw6PsACFDSdmz7ko= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Mike Marciniszyn , Dennis Dalessandro , Doug Ledford , Jason Gunthorpe , Bjorn Helgaas Subject: [PATCH v5 07/11] IB/hfi1, PCI: switch to __pci_function_locked() for reset request Date: Thu, 11 Oct 2018 04:49:59 +0000 Message-Id: <20181011045008.32212-7-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 Start using the new reset API rather than the workaround. Signed-off-by: Sinan Kaya --- 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 cf1e847ea02e..d4acdc400ef2 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1289,9 +1289,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; \ From patchwork Thu Oct 11 04:50:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982245 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="xPDNhKQU"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz6x0tsqz9s9J for ; Thu, 11 Oct 2018 15:50:33 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726944AbeJKMQA (ORCPT ); Thu, 11 Oct 2018 08:16:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:54358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726906AbeJKMP7 (ORCPT ); Thu, 11 Oct 2018 08:15:59 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A6E820865; Thu, 11 Oct 2018 04:50:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233430; bh=gmr4JOyZxX8cerSJwTD7RkaSwnoQlYXn9HcGliuYVrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xPDNhKQUm5X1xQR6Ds4Ma6306ZF2K58ERK8TjKx+yy7YXRQX7lLSH1FAOMEuGAG2v 9nnTMalMqzQDYRgEeWcM/Fi14O9HJC4cD5cAB9x/VSCno+tv7YsxFUixgZE/uj1Ht3 svq1eLey7CmB85QKSgivPVlOMXnGCDFBS9w5Hj8g= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Mike Marciniszyn , Dennis Dalessandro , Doug Ledford , Jason Gunthorpe , Derek Chickles , Satanand Burla , Felix Manlunas , Raghu Vatsavayi , "David S. Miller" , Bjorn Helgaas , Boris Ostrovsky , Juergen Gross , Jia-Ju Bai Subject: [PATCH v5 08/11] PCI: Unify pci_reset_function_locked() and __pci_reset_function_locked() Date: Thu, 11 Oct 2018 04:50:00 +0000 Message-Id: <20181011045008.32212-8-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 The difference between pci_reset_function_locked() and __pci_reset_function_locked() is the saving and restoring of the registers. Unify these API by adding saverestore argument that caller passes. Signed-off-by: Sinan Kaya --- drivers/infiniband/hw/hfi1/pcie.c | 2 +- drivers/net/ethernet/cavium/liquidio/lio_main.c | 2 +- drivers/pci/pci.c | 10 +++++++--- drivers/pci/pci.h | 1 + drivers/xen/xen-pciback/pci_stub.c | 6 +++--- include/linux/pci.h | 4 ++-- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/pcie.c b/drivers/infiniband/hw/hfi1/pcie.c index 38f96192e5f0..73eced9c5523 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_reset_function_locked(dev, PCI_RESET_LINK); + return pci_reset_function_locked(dev, PCI_RESET_LINK, false); } /* diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/ethernet/cavium/liquidio/lio_main.c index 0ff76722734d..7e001382ad93 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, PCI_RESET_ANY); + rc = pci_reset_function_locked(oct->pci_dev, PCI_RESET_ANY, false); 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 a3a1c2a5e0cf..97328dc8e476 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4835,6 +4835,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 + * @saverestore: Flag indicating whether device context should be saved. * * Some devices allow an individual function to be reset without affecting * other functions in the same device. The PCI device must be responsive @@ -4849,18 +4850,21 @@ 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, u32 reset_type) +int pci_reset_function_locked(struct pci_dev *dev, u32 reset_type, + bool saverestore) { int rc; if (!dev->reset_fn) return -ENOTTY; - pci_dev_save_and_disable(dev); + if (saverestore) + pci_dev_save_and_disable(dev); rc = __pci_reset_function_locked(dev, reset_type); - pci_dev_restore(dev); + if (saverestore) + pci_dev_restore(dev); return rc; } diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 0444bfa51b52..fbfb44fb32b7 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -35,6 +35,7 @@ int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai, int pci_probe_reset_function(struct pci_dev *dev, u32 reset_type); int pci_bridge_secondary_bus_reset(struct pci_dev *dev); +int __pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); /** * struct pci_platform_pm_ops - Firmware PM callbacks diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c index 6dfb805bcb19..b68e811ab27f 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_ANY); + pci_reset_function_locked(dev, PCI_RESET_ANY, false); 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_ANY); + pci_reset_function_locked(dev, PCI_RESET_ANY, false); 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_ANY); + pci_reset_function_locked(dev, PCI_RESET_ANY, false); 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 d4acdc400ef2..84d08a9a01e3 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1165,9 +1165,9 @@ 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, 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_reset_function_locked(struct pci_dev *dev, u32 reset_type, + bool saverestore); 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); From patchwork Thu Oct 11 04:50:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982246 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="xXJ7kMPo"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz706PCyz9s9J for ; Thu, 11 Oct 2018 15:50:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbeJKMQD (ORCPT ); Thu, 11 Oct 2018 08:16:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:54432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726906AbeJKMQD (ORCPT ); Thu, 11 Oct 2018 08:16:03 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 062162098A; Thu, 11 Oct 2018 04:50:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233434; bh=67IAdhrBvdhPEFKXrVF0RmDcGU0D6KjfWaRRqJWC0ok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xXJ7kMPoe1yzyitZk14VVL3yO7pMKKM9Pv/khCwLx+C0UApHtBOXA+zUZgmmJYf6T qeG3ioIqxqP/Z7k5y6PrMi7MOQvc3dqdOsrX6WTG4Vk+LgKJ3YMRbmwHRonjrvD3wP NadYwSvExMrE4Eo9g2V+iHZjQtuTQy3bVtgubqbQ= 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 v5 09/11] PCI: Add options to pci_reset_function Date: Thu, 11 Oct 2018 04:50:01 +0000 Message-Id: <20181011045008.32212-9-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 Getting ready to deprecate pci_reset_function_locked(). Add saverestore and locked parameters to pci_reset_function() function and add saverestore = true and locked = false to all existing callers. Signed-off-by: Sinan Kaya --- drivers/hid/intel-ish-hid/ipc/ipc.c | 2 +- drivers/misc/genwqe/card_base.c | 2 +- .../net/ethernet/qlogic/qlcnic/qlcnic_ctx.c | 2 +- drivers/net/ethernet/sfc/mcdi.c | 3 ++- drivers/pci/pci-sysfs.c | 2 +- drivers/pci/pci.c | 20 ++++++++++++++----- include/linux/pci.h | 3 ++- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index 18312969f1b3..5fa7cdd136fe 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, PCI_RESET_ANY); + rv = pci_reset_function(pdev, PCI_RESET_ANY, true, false); 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 cc78ef28ee38..85eb3ca55ccb 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, PCI_RESET_ANY); + rc = pci_reset_function(pci_dev, PCI_RESET_ANY, true, false); 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 bb737725f175..4fb3ea301af8 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_ANY); + pci_reset_function(dev->pdev, PCI_RESET_ANY, true, false); dev->flags &= ~QLCNIC_NEED_FLR; } diff --git a/drivers/net/ethernet/sfc/mcdi.c b/drivers/net/ethernet/sfc/mcdi.c index 7f95e17b8a48..2406cd38f258 100644 --- a/drivers/net/ethernet/sfc/mcdi.c +++ b/drivers/net/ethernet/sfc/mcdi.c @@ -1862,7 +1862,8 @@ 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, PCI_RESET_ANY); + rc = pci_reset_function(efx->pci_dev, PCI_RESET_ANY, true, + false); if (rc) return rc; /* Re-enable polled MCDI completion */ diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 9569664ec4b2..939de1d323ad 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, PCI_RESET_ANY); + result = pci_reset_function(pdev, PCI_RESET_ANY, true, false); pm_runtime_put(dev); if (result < 0) return result; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 97328dc8e476..b34909376221 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4799,6 +4799,9 @@ int pci_probe_reset_function(struct pci_dev *dev, u32 reset_type) * pci_reset_function - quiesce and reset a PCI device function * @dev: PCI device to reset * @reset_type: reset type to apply + * @saverestore: flag for save/restore the device state before and after reset + * @locked: flag for obtaining device lock. true if caller is already holding + * the lock. * * Some devices allow an individual function to be reset without affecting * other functions in the same device. The PCI device must be responsive @@ -4812,20 +4815,27 @@ int pci_probe_reset_function(struct pci_dev *dev, u32 reset_type) * 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, u32 reset_type) +int pci_reset_function(struct pci_dev *dev, u32 reset_type, bool saverestore, + bool locked) { int rc; if (!dev->reset_fn) return -ENOTTY; - pci_dev_lock(dev); - pci_dev_save_and_disable(dev); + if (!locked) + pci_dev_lock(dev); + + if (saverestore) + pci_dev_save_and_disable(dev); rc = __pci_reset_function_locked(dev, reset_type); - pci_dev_restore(dev); - pci_dev_unlock(dev); + if (saverestore) + pci_dev_restore(dev); + + if (!locked) + pci_dev_unlock(dev); return rc; } diff --git a/include/linux/pci.h b/include/linux/pci.h index 84d08a9a01e3..82b326eb624b 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1165,7 +1165,8 @@ 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(struct pci_dev *dev, u32 reset_type); +int pci_reset_function(struct pci_dev *dev, u32 reset_type, bool saverestore, + bool locked); int pci_reset_function_locked(struct pci_dev *dev, u32 reset_type, bool saverestore); int pci_try_reset_function(struct pci_dev *dev, u32 reset_type); From patchwork Thu Oct 11 04:50:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982247 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="i1PKaN0e"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz743zGlz9s9J for ; Thu, 11 Oct 2018 15:50:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbeJKMQH (ORCPT ); Thu, 11 Oct 2018 08:16:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:54500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726906AbeJKMQH (ORCPT ); Thu, 11 Oct 2018 08:16:07 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 12C4420865; Thu, 11 Oct 2018 04:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233438; bh=bbyp/khQgsZnlS7qiJm2pVo5r2Zew9Nap9FGUELtuFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i1PKaN0e8SkjYf/BBSi6iUnQfOZcZLVORNZtEA3L10f9dlZlaGaiPIsovswx7CdvS lrKNda9ce2C0TLHqyv3RX3KUMMdbxueUw/3BhyAldy/6yHwCprPOtUv4hpPlfn129H rcv0Gm9c8F5Xn5ji2r43lYtWH4UkHCBiMKXoPuhY= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Mike Marciniszyn , Dennis Dalessandro , Doug Ledford , Jason Gunthorpe , Derek Chickles , Satanand Burla , Felix Manlunas , Raghu Vatsavayi , "David S. Miller" , Bjorn Helgaas , Boris Ostrovsky , Juergen Gross , Jia-Ju Bai Subject: [PATCH v5 10/11] PCI: Hide pci_reset_function_locked() Date: Thu, 11 Oct 2018 04:50:02 +0000 Message-Id: <20181011045008.32212-10-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 It is time to hide pci_reset_function_locked() since pci_reset_function() provides the same functionality. One less API to expose to the users. Signed-off-by: Sinan Kaya --- drivers/infiniband/hw/hfi1/pcie.c | 2 +- drivers/net/ethernet/cavium/liquidio/lio_main.c | 2 +- drivers/pci/pci.h | 2 ++ drivers/xen/xen-pciback/pci_stub.c | 6 +++--- include/linux/pci.h | 2 -- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/pcie.c b/drivers/infiniband/hw/hfi1/pcie.c index 73eced9c5523..8fbcde36353d 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_reset_function_locked(dev, PCI_RESET_LINK, false); + return pci_reset_function(dev, PCI_RESET_LINK, false, true); } /* diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/ethernet/cavium/liquidio/lio_main.c index 7e001382ad93..e1ff9818ed6b 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, PCI_RESET_ANY, false); + rc = pci_reset_function(oct->pci_dev, PCI_RESET_ANY, false, true); if (rc != 0) dev_err(&oct->pci_dev->dev, "Error %d resetting PCI function %d\n", diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index fbfb44fb32b7..737fdc36fe36 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -36,6 +36,8 @@ int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai, int pci_probe_reset_function(struct pci_dev *dev, u32 reset_type); int pci_bridge_secondary_bus_reset(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); +int pci_reset_function_locked(struct pci_dev *dev, u32 reset_type, + bool saverestore); /** * struct pci_platform_pm_ops - Firmware PM callbacks diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c index b68e811ab27f..6806a58c30d5 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_ANY, false); + pci_reset_function(dev, PCI_RESET_ANY, false, true); 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_ANY, false); + pci_reset_function(dev, PCI_RESET_ANY, false, true); 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_ANY, false); + pci_reset_function(dev, PCI_RESET_ANY, false, true); 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 82b326eb624b..95efffd09690 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1167,8 +1167,6 @@ bool pcie_has_flr(struct pci_dev *dev); int pcie_flr(struct pci_dev *dev); int pci_reset_function(struct pci_dev *dev, u32 reset_type, bool saverestore, bool locked); -int pci_reset_function_locked(struct pci_dev *dev, u32 reset_type, - bool saverestore); 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); From patchwork Thu Oct 11 04:50:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 982248 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="K7gDKriQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Vz7759RYz9s9J for ; Thu, 11 Oct 2018 15:50:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727056AbeJKMQK (ORCPT ); Thu, 11 Oct 2018 08:16:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:54552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726906AbeJKMQK (ORCPT ); Thu, 11 Oct 2018 08:16:10 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.87.4.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 88BCB2087D; Thu, 11 Oct 2018 04:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539233441; bh=CSnqAGu13KmiV5j4jbf7KPA6wAiK7iw2ki8po81ui00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K7gDKriQtcBLJNERoswF22962LF5HWroAShCtJHZAbq7XAxK3nbReJ/AmbF1ms+J4 lb51ndRqttk17meus8IqFtsHaHPgMCZ8f4z1LfFsQDoAJd6f/xC4pkvR+UQRRBdRuS btktWj8MQ02Ie4QNBJG+y/qSLMD7Xr+CCNmTA0AY= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: Sinan Kaya , Giovanni Cabiddu , Herbert Xu , "David S. Miller" , Mike Marciniszyn , Dennis Dalessandro , Doug Ledford , Jason Gunthorpe , Derek Chickles , Satanand Burla , Felix Manlunas , Raghu Vatsavayi , Jeff Kirsher , Bjorn Helgaas , Jia-Ju Bai Subject: [PATCH v5 11/11] PCI: Hide pcie_flr() in favor of pci_reset_function() Date: Thu, 11 Oct 2018 04:50:03 +0000 Message-Id: <20181011045008.32212-11-okaya@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181011045008.32212-1-okaya@kernel.org> References: <20181011045008.32212-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 Now that we have a unified API for device reset, let's eliminate one duplication by hiding pcie_flr(). Signed-off-by: Sinan Kaya --- drivers/crypto/qat/qat_common/adf_aer.c | 3 ++- drivers/infiniband/hw/hfi1/chip.c | 5 +++-- drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 3 ++- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 6 ++++-- drivers/pci/pci.h | 1 + include/linux/pci.h | 1 - 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/qat/qat_common/adf_aer.c b/drivers/crypto/qat/qat_common/adf_aer.c index 9225d060e18f..9326685dd89f 100644 --- a/drivers/crypto/qat/qat_common/adf_aer.c +++ b/drivers/crypto/qat/qat_common/adf_aer.c @@ -109,7 +109,8 @@ EXPORT_SYMBOL_GPL(adf_reset_sbr); void adf_reset_flr(struct adf_accel_dev *accel_dev) { - pcie_flr(accel_to_pci_dev(accel_dev)); + pci_reset_function(accel_to_pci_dev(accel_dev), PCI_RESET_FLR, + false, true); } EXPORT_SYMBOL_GPL(adf_reset_flr); diff --git a/drivers/infiniband/hw/hfi1/chip.c b/drivers/infiniband/hw/hfi1/chip.c index e1668bcc2d13..12bc5ef81e12 100644 --- a/drivers/infiniband/hw/hfi1/chip.c +++ b/drivers/infiniband/hw/hfi1/chip.c @@ -14077,7 +14077,7 @@ static int init_chip(struct hfi1_devdata *dd) dd_dev_info(dd, "Resetting CSRs with FLR\n"); /* do the FLR, the DC reset will remain */ - pcie_flr(dd->pcidev); + pci_reset_function(dd->pcidev, PCI_RESET_FLR, false, true); /* restore command and BARs */ ret = restore_pci_variables(dd); @@ -14089,7 +14089,8 @@ static int init_chip(struct hfi1_devdata *dd) if (is_ax(dd)) { dd_dev_info(dd, "Resetting CSRs with FLR\n"); - pcie_flr(dd->pcidev); + pci_reset_function(dd->pcidev, PCI_RESET_FLR, false, + true); ret = restore_pci_variables(dd); if (ret) { dd_dev_err(dd, "%s: Could not restore PCI variables\n", diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c index b77835724dc8..6af086337359 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c @@ -438,7 +438,8 @@ static void octeon_pci_flr(struct octeon_device *oct) pci_write_config_word(oct->pci_dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE); - pcie_flr(oct->pci_dev); + pci_reset_function(oct->pci_dev, PCI_RESET_FUNCTION, + false, true); pci_cfg_access_unlock(oct->pci_dev); diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c index f27d73a7bf16..6345c2c11c62 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c @@ -7539,7 +7539,8 @@ static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) pci_read_config_word(vfdev, PCI_STATUS, &status_reg); if (status_reg != IXGBE_FAILED_READ_CFG_WORD && status_reg & PCI_STATUS_REC_MASTER_ABORT) - pcie_flr(vfdev); + pci_reset_function(vfdev, PCI_RESET_FLR, false + true); } } @@ -11046,7 +11047,8 @@ static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev, * VFLR. Just clean up the AER in that case. */ if (vfdev) { - pcie_flr(vfdev); + pci_reset_function(vfdev, PCI_RESET_FUNCTION, false, + true); /* Free device reference count */ pci_dev_put(vfdev); } diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 737fdc36fe36..c1dc92b1cc1e 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -38,6 +38,7 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev, u32 reset_type); int pci_reset_function_locked(struct pci_dev *dev, u32 reset_type, bool saverestore); +int pcie_flr(struct pci_dev *dev); /** * struct pci_platform_pm_ops - Firmware PM callbacks diff --git a/include/linux/pci.h b/include/linux/pci.h index 95efffd09690..acaf115841cc 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1164,7 +1164,6 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev, enum pcie_link_width *width); 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(struct pci_dev *dev, u32 reset_type, bool saverestore, bool locked); int pci_try_reset_function(struct pci_dev *dev, u32 reset_type);