From patchwork Wed Sep 5 16:08:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10589173 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 9D6D5175A for ; Wed, 5 Sep 2018 16:08:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94F202894D for ; Wed, 5 Sep 2018 16:08:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88E7E2A1B2; Wed, 5 Sep 2018 16:08:16 +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 E71B82894D for ; Wed, 5 Sep 2018 16:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727501AbeIEUjG (ORCPT ); Wed, 5 Sep 2018 16:39:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:54810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbeIEUjG (ORCPT ); Wed, 5 Sep 2018 16:39:06 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.76.78.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2758E2075C; Wed, 5 Sep 2018 16:08:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1536163694; bh=q5YQ+/5iV0VgdeiJqI81CaxcuKYuSf7jY6QlWovX8a4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S1FqbHJTRNArLuP80qiGhqoX2G/yKgeLboLoc1PZE0QXPvY+lUWzgbNRfl6bQLNjw xbhm5Vc69y2XYx0jGq919sEGX/v7yGTWhw4gEH+Nh5/6BMCL/Ea4BW41Nv0REPZzCq LUg6k++xp9mOa0xPxOoDwmDr3ZiOVDeYtXueEasE= 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 for-rc v2 2/3] PCI: Request reset type as part of function reset Date: Wed, 5 Sep 2018 16:08:04 +0000 Message-Id: <20180905160805.5680-2-okaya@kernel.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180905160805.5680-1-okaya@kernel.org> References: <20180905160805.5680-1-okaya@kernel.org> 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. Fixes: 811c5cb37df4 ("PCI: Unify try slot and bus reset API") Link: https://bugzilla.kernel.org/show_bug.cgi?id=200985 Suggested-by: Alex Williamson Signed-off-by: Sinan Kaya Reviewed-by: Boris Ostrovsky --- .../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 | 13 +++- 4 files changed, 55 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 30b260332a10..43a4b0969153 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4672,6 +4672,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 @@ -4687,9 +4688,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 = 0; might_sleep(); @@ -4701,24 +4702,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); @@ -4783,7 +4802,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); @@ -4818,7 +4837,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); @@ -4843,7 +4862,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 e72ca8dd6241..6924d837c959 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -849,6 +849,17 @@ enum { PCI_SCAN_ALL_PCIE_DEVS = 0x00000040, /* Scan all, not just dev 0 */ }; +#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 +1122,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);