From patchwork Tue Jan 2 17:00:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 10141031 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.web.codeaurora.org (Postfix) with ESMTP id ACEF66034B for ; Tue, 2 Jan 2018 17:00:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F50228D32 for ; Tue, 2 Jan 2018 17:00:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DCBD28CC4; Tue, 2 Jan 2018 17:00: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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 03EFC28D32 for ; Tue, 2 Jan 2018 17:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751052AbeABRAh (ORCPT ); Tue, 2 Jan 2018 12:00:37 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:52552 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751170AbeABRAe (ORCPT ); Tue, 2 Jan 2018 12:00:34 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id AAE7D6024C; Tue, 2 Jan 2018 17:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1514912433; bh=189AX9wmXLgBmePyxZrtgLjK//i4SY97sDt5AahikFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J1DOump9cxAOP8JaUVPrIbUKOGU6Nu4DNG6inFSJ5GUV/IJuj1400H1jo+WhT+Y1j ayNm3z00batX4xDyQfLdSrg32SaPcODrg8nIaOJEhibJT//h3AawugbK+SW6recXk8 kPIm7WsXgrLR7Rwujadu/BZW4mSh7MbNY0OmydE0= Received: from drakthul.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 41A0860B67; Tue, 2 Jan 2018 17:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1514912433; bh=189AX9wmXLgBmePyxZrtgLjK//i4SY97sDt5AahikFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J1DOump9cxAOP8JaUVPrIbUKOGU6Nu4DNG6inFSJ5GUV/IJuj1400H1jo+WhT+Y1j ayNm3z00batX4xDyQfLdSrg32SaPcODrg8nIaOJEhibJT//h3AawugbK+SW6recXk8 kPIm7WsXgrLR7Rwujadu/BZW4mSh7MbNY0OmydE0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 41A0860B67 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=okaya@codeaurora.org From: Sinan Kaya To: linux-pci@vger.kernel.org, timur@codeaurora.org Cc: linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sinan Kaya , Bjorn Helgaas , linux-kernel@vger.kernel.org (open list) Subject: [PATCH V3 2/6] PCI: Handle FLR failure and allow other reset types Date: Tue, 2 Jan 2018 12:00:19 -0500 Message-Id: <1514912423-13341-3-git-send-email-okaya@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1514912423-13341-1-git-send-email-okaya@codeaurora.org> References: <1514912423-13341-1-git-send-email-okaya@codeaurora.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 pci_flr_wait() and pci_af_flr() functions assume graceful return even though the device is inaccessible under error conditions. Return -ENOTTY in error cases so that __pci_reset_function_locked() can try other reset types if AF_FLR/FLR reset fails. Signed-off-by: Sinan Kaya Reviewed-by: Christoph Hellwig --- drivers/pci/pci.c | 18 ++++++++++-------- include/linux/pci.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 463b32d..ef15162 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3945,7 +3945,7 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) } EXPORT_SYMBOL(pci_wait_for_pending_transaction); -static void pci_flr_wait(struct pci_dev *dev) +static int pci_flr_wait(struct pci_dev *dev) { int delay = 1, timeout = 60000; u32 id; @@ -3974,7 +3974,7 @@ static void pci_flr_wait(struct pci_dev *dev) if (delay > timeout) { dev_warn(&dev->dev, "not ready %dms after FLR; giving up\n", 100 + delay - 1); - return; + return -ENOTTY; } if (delay > 1000) @@ -3988,6 +3988,8 @@ static void pci_flr_wait(struct pci_dev *dev) if (delay > 1000) dev_info(&dev->dev, "ready %dms after FLR\n", 100 + delay - 1); + + return 0; } /** @@ -4016,13 +4018,13 @@ static bool pcie_has_flr(struct pci_dev *dev) * device supports FLR before calling this function, e.g. by using the * pcie_has_flr() helper. */ -void pcie_flr(struct pci_dev *dev) +int pcie_flr(struct pci_dev *dev) { if (!pci_wait_for_pending_transaction(dev)) dev_err(&dev->dev, "timed out waiting for pending transaction; performing function level reset anyway\n"); pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR); - pci_flr_wait(dev); + return pci_flr_wait(dev); } EXPORT_SYMBOL_GPL(pcie_flr); @@ -4055,8 +4057,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe) dev_err(&dev->dev, "timed out waiting for pending transaction; performing AF function level reset anyway\n"); pci_write_config_byte(dev, pos + PCI_AF_CTRL, PCI_AF_CTRL_FLR); - pci_flr_wait(dev); - return 0; + return pci_flr_wait(dev); } /** @@ -4307,8 +4308,9 @@ int __pci_reset_function_locked(struct pci_dev *dev) if (rc != -ENOTTY) return rc; if (pcie_has_flr(dev)) { - pcie_flr(dev); - return 0; + rc = pcie_flr(dev); + if (rc != -ENOTTY) + return rc; } rc = pci_af_flr(dev, 0); if (rc != -ENOTTY) diff --git a/include/linux/pci.h b/include/linux/pci.h index 66cca1c..0c1335a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1081,7 +1081,7 @@ static inline int pci_is_managed(struct pci_dev *pdev) int pcie_set_mps(struct pci_dev *dev, int mps); int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed, enum pcie_link_width *width); -void pcie_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(struct pci_dev *dev); int pci_reset_function_locked(struct pci_dev *dev);