From patchwork Sun Sep 24 00:16:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 9967715 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 C0071604D3 for ; Sun, 24 Sep 2017 00:19:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A90AF29033 for ; Sun, 24 Sep 2017 00:19:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D45F2923A; Sun, 24 Sep 2017 00:19:28 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3636729033 for ; Sun, 24 Sep 2017 00:19:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UveBDJbeJnXSp+Gz5cKukCy3Z4RM/rPzPqFEAlYejHQ=; b=PvYTQunUBa1N7hfC8UPSNXQ5wv zAUdTtt6VeB1xFl8HgM4/8NZhouKvcfL/oVYvNPydv+JqunjFYM4bVJnvsY9l4cqBJaak6vNDhchL 9Qx54ICC1gRnSQDwcHeF+Pvk7XAdOHaqTwGb/1z+UFKCUJmWVmlMlQnvcKdisqHjhpcFzVyKrcbH0 AR7CLsyTzMl6mkFTyLEAaZ/5MoTxOtdtbRzzHQvx5DqIcJ+XEGaCavoIJMXfUZmz1GgAF1SFe8wx7 1XcQYzh/4ZsxKHilujDYJVcCUCzgpS9NHNNbznCmfSW3610wCjxshslcyiHp1CYAyBUHA4oHzHQwY etSZYnfw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dvud7-0005GG-Ft; Sun, 24 Sep 2017 00:18:41 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dvubw-0004Ak-JJ for linux-arm-kernel@lists.infradead.org; Sun, 24 Sep 2017 00:17:32 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 59CDF60729; Sun, 24 Sep 2017 00:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1506212228; bh=0gEb3ulVTFEGzvj++6sYjZ9eFLPPkC76kVxbkB5CeRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a4DENfkNUcCUxiVK93Y0q1dovYtlplbWv2XIOEhgWqYGdNketOL8SYEET0u3h3YOC Imzji6AwQBcSWGM/wIbA2gUOtDxtGZEcx1PnGyQ4ZLTAv8Rjq5ajQ8lwUk3vUk7xpr UTk8O4NpcDPfWdZB10w+Ui5Gb62B7mhGSucVIYzQ= 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 E4C5660710; Sun, 24 Sep 2017 00:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1506212227; bh=0gEb3ulVTFEGzvj++6sYjZ9eFLPPkC76kVxbkB5CeRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SuZkwYmgZEACjYcxlgSGiO0d9oNXZGFOmtg3Rbi9e8OlVJtBPBOCpLtKnKSkMwvHQ xpTb+WvZgsHGGAG7wBLfXyLgwjSZjL7M1h8B/nBc5acrXkI1dMiExg+U5U7qTOsKv7 GJmD8vhcnDvTK2yii3UUcK70rdZe5XK/1I4DiPD4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E4C5660710 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, alex.williamson@redhat.com Subject: [PATCH 2/5] PCI: handle FLR failure and allow other reset types Date: Sat, 23 Sep 2017 20:16:55 -0400 Message-Id: <1506212218-29103-2-git-send-email-okaya@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1506212218-29103-1-git-send-email-okaya@codeaurora.org> References: <1506212218-29103-1-git-send-email-okaya@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170923_171728_748687_225E9866 X-CRM114-Status: GOOD ( 13.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sinan Kaya , linux-arm-msm@vger.kernel.org, Bjorn Helgaas , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 --- 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 23681f4..27ec45d 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3820,7 +3820,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; @@ -3849,7 +3849,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) @@ -3863,6 +3863,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; } /** @@ -3891,13 +3893,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); @@ -3930,8 +3932,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); } /** @@ -4203,8 +4204,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 f68c58a..104224f7 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1088,7 +1088,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(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev); int pci_reset_function(struct pci_dev *dev);