From patchwork Fri Sep 14 21:18:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10601237 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 8FF2914BD for ; Fri, 14 Sep 2018 21:18:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 742ED2B9B6 for ; Fri, 14 Sep 2018 21:18:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 685982B9C1; Fri, 14 Sep 2018 21:18:32 +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 1131B2B9B6 for ; Fri, 14 Sep 2018 21:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728196AbeIOCeo (ORCPT ); Fri, 14 Sep 2018 22:34:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:37718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728198AbeIOCeo (ORCPT ); Fri, 14 Sep 2018 22:34:44 -0400 Received: from sinanubuntu1604.mkjiurmyylmellclgttazegk5f.bx.internal.cloudapp.net (unknown [40.76.90.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 465F221476; Fri, 14 Sep 2018 21:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1536959910; bh=3oHTlEC6qzgbZnQpYjLmPosjgp90aWQGhqH2+DsGHDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P05dAxNwzP4QRrQbjec3wUtn/mN4wIovGUaVTk20zxpxvfG6Dw5/ZZtcAL6WUzXcC k/WSi4U7demU0/CfxM6ayPN3EFT7RKrdkkQ6UQTwgK1MzkPqeVXQvqBZafHyK75Ssh mx9lf6bOa2asAdP70bkGtdOibkVV1BUB3T89aMEM= From: Sinan Kaya To: linux-pci@vger.kernel.org Cc: alex.williamson@redhat.com, Sinan Kaya , Bjorn Helgaas Subject: [PATCH v2 5/6] PCI: Expose reset type to users of pci_probe_reset_function() Date: Fri, 14 Sep 2018 21:18:07 +0000 Message-Id: <20180914211808.2564-6-okaya@kernel.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180914211808.2564-1-okaya@kernel.org> References: <20180914211808.2564-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 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 | 51 ++++++++++++++++++++++++++++++--------------- drivers/pci/pci.h | 2 +- drivers/pci/probe.c | 2 +- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index c216ab56dbcc..32b367937cc1 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4753,28 +4753,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 ec784009a36b..cbce5420431b 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2332,7 +2332,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; }