From patchwork Tue Mar 3 13:28:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418001 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E8D314B7 for ; Tue, 3 Mar 2020 13:29:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E88820848 for ; Tue, 3 Mar 2020 13:29:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="RPHNXHKi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728291AbgCCN3h (ORCPT ); Tue, 3 Mar 2020 08:29:37 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:43826 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727663AbgCCN3h (ORCPT ); Tue, 3 Mar 2020 08:29:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242177; x=1614778177; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SXJONBdcDukonc95OMH4eVS6Q98vylWW4QxZSA+zyc4=; b=RPHNXHKiIBgnEYX7tukHHwcfXpELVgTbenEJeV9udVCkuOPZOKG1tC05 n8ADYfiCWxLAYcMkmS+F/r+U4y1hLKDvxEiDMubQ7dsph5kWN3RG9SyXh Ji3GxKGVmxWFYf/1sgYMrODFWPpEADEJCMzo8Upa60vqhBEbdtTMYSMtK A=; IronPort-SDR: ZHfOmyRtvoKrNrSuFDx5WZe5K7G5pEeGhfrcw0ctxWbpHGi9tj3QUrjkD5nXjNMZwtJrr5pSlI Q7xH843pL4XA== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="28866224" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 03 Mar 2020 13:29:34 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com (Postfix) with ESMTPS id 7FD5EA2FCE; Tue, 3 Mar 2020 13:29:33 +0000 (UTC) Received: from EX13D12EUC002.ant.amazon.com (10.43.164.134) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:29:33 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUC002.ant.amazon.com (10.43.164.134) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:29:31 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:29:29 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 01/17] PCI: Fall back to slot/bus reset if softer methods timeout Date: Tue, 3 Mar 2020 14:28:36 +0100 Message-ID: <20200303132852.13184-2-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov Previously, if a device never came back (i.e., never started returning Successful Completions for Configuration Requests) after a reset, they would return -ENOTTY, causing __pci_reset_function_locked to move on to the next reset method. However, up until slot/bus reset, all of them rely on the device being responsive and are therefore not safe to attempt in this situation. This patch introduces ETIMEDOUT as a new, specially handled return value for the reset methods (which all end in "return pci_dev_wait"), to allow skipping to slot/bus reset where appropriate. Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index d828ca835a98..ac8504d75c32 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1043,7 +1043,7 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout) if (delay > timeout) { pci_warn(dev, "not ready %dms after %s; giving up\n", delay - 1, reset_type); - return -ENOTTY; + return -ETIMEDOUT; } if (delay > 1000) @@ -4845,6 +4845,7 @@ static int pci_parent_bus_reset(struct pci_dev *dev, int probe) if (probe) return 0; + /* XXX: Shouldn't this lock the bus? */ return pci_bridge_secondary_bus_reset(dev->bus->self); } @@ -4979,25 +4980,37 @@ int __pci_reset_function_locked(struct pci_dev *dev) /* * A reset method returns -ENOTTY if it doesn't support this device * and we should try the next method. + * It returns -ETIMEDOUT if the device never became responsive after + * the reset: we jump to the reset types that do not rely on config + * space access (if any are left). * - * If it returns 0 (success), we're finished. If it returns any - * other error, we're also finished: this indicates that further - * reset mechanisms might be broken on the device. + * If it returns 0 (success), we are finished. + * If it returns any other error, we are finished (something must have + * went terribly wrong and it is not safe to continue reset attempts). */ rc = pci_dev_specific_reset(dev, 0); + if (rc == -ETIMEDOUT) + goto unresponsive; if (rc != -ENOTTY) return rc; if (pcie_has_flr(dev)) { rc = pcie_flr(dev); + if (rc == -ETIMEDOUT) + goto unresponsive; if (rc != -ENOTTY) return rc; } rc = pci_af_flr(dev, 0); + if (rc == -ETIMEDOUT) + goto unresponsive; if (rc != -ENOTTY) return rc; rc = pci_pm_reset(dev, 0); + if (rc == -ETIMEDOUT) + goto unresponsive; if (rc != -ENOTTY) return rc; +unresponsive: rc = pci_dev_reset_slot_function(dev, 0); if (rc != -ENOTTY) return rc; From patchwork Tue Mar 3 13:28:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418011 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CFF2F14B7 for ; Tue, 3 Mar 2020 13:30:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B035920838 for ; Tue, 3 Mar 2020 13:30:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Cgx7GVRh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729058AbgCCNaO (ORCPT ); Tue, 3 Mar 2020 08:30:14 -0500 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:16728 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728915AbgCCNaN (ORCPT ); Tue, 3 Mar 2020 08:30:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242213; x=1614778213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Cbndvv3qCssTnIgDUBDG4qXe8hnk+TGR5JEIQeTw7KA=; b=Cgx7GVRhT9CG8NsydXG98erpUyfdBdOPNkO0O8vdXes7z7gCM+U0xqKQ tLo+D8ijNFhoWPhck7Jr8S2OYWzkOo1Ahh90fe59E8UsaOcis7VuPbnqn yAPwSF6dOIwoEffrDhRekmImZ1P3bBo/b9+KwVwytX6XJup7Vqde0vXrl M=; IronPort-SDR: hVVg2IxgfCqsQmQEvFd//MhJ8n2GbgjwmW1a1XTjO36eTFV2aABndg/dA9InMgN71P3MQ5mAKn GRi20oa/lZ3w== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="19548917" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-55156cd4.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 03 Mar 2020 13:30:00 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-55156cd4.us-west-2.amazon.com (Postfix) with ESMTPS id 225B2A2E6D; Tue, 3 Mar 2020 13:29:58 +0000 (UTC) Received: from EX13D12EUA004.ant.amazon.com (10.43.165.162) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:29:46 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUA004.ant.amazon.com (10.43.165.162) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:29:45 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:29:42 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 02/17] PCI: Remove unused PCI_PM_BUS_WAIT Date: Tue, 3 Mar 2020 14:28:37 +0100 Message-ID: <20200303132852.13184-3-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov The last usage of this constant was removed by: commit 476e7faefc43 ("PCI PM: Do not wait for buses in B2 or B3 during resume") Signed-off-by: Stanislav Spassov --- drivers/pci/pci.h | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 6394e7746fb5..659ab3f9042a 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -46,7 +46,6 @@ int pci_bus_error_reset(struct pci_dev *dev); #define PCI_PM_D2_DELAY 200 #define PCI_PM_D3_WAIT 10 #define PCI_PM_D3COLD_WAIT 100 -#define PCI_PM_BUS_WAIT 50 /** * struct pci_platform_pm_ops - Firmware PM callbacks From patchwork Tue Mar 3 13:28:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418023 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E14A14B7 for ; Tue, 3 Mar 2020 13:30:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D45A20842 for ; Tue, 3 Mar 2020 13:30:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="HQBCxKOH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727894AbgCCNa2 (ORCPT ); Tue, 3 Mar 2020 08:30:28 -0500 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:21163 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728068AbgCCNa2 (ORCPT ); Tue, 3 Mar 2020 08:30:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242227; x=1614778227; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Gz6pfLMfGNZpaFxwlrBNkkqcP/vdNODzuYge/T20qto=; b=HQBCxKOHQt8BFgjPadIT56uojQmu9TgLHXc+f6XvVhqYcTnhr86m2Cm4 nQp4syemLJjggSq940AbPPli52Y6yA7wDOkHbNlBjCvJZlaAE3TN/ZQLv CK0Ov0hJ2wTN7CPn/bbbm5XrXoU8VDlAkpZFnCVbari7I3ed7s6apYbXc o=; IronPort-SDR: FHWoXQAaMNLcqoTOhhHlOg33oQbd0JRg7pw5S6KyEKhcilo89yKsSNHnrucJPkxcNe0PNN2cuY EATC/f881HJA== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="19279361" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-22cc717f.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 03 Mar 2020 13:30:01 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-22cc717f.us-west-2.amazon.com (Postfix) with ESMTPS id 88C55A2785; Tue, 3 Mar 2020 13:30:00 +0000 (UTC) Received: from EX13D12EUA004.ant.amazon.com (10.43.165.162) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:29:49 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUA004.ant.amazon.com (10.43.165.162) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:29:48 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:29:46 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 03/17] PCI: Use pci_bridge_wait_for_secondary_bus after SBR Date: Tue, 3 Mar 2020 14:28:38 +0100 Message-ID: <20200303132852.13184-4-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov So far, pci_bridge_wait_for_secondary_bus() was only invoked by PM code after (runtime) resume of devices, but it naturally makes sense for handling post-SBR waiting as well. It uses the PCI_PM_D3COLD_WAIT value (100ms), potentially overridden on a per-device basis to a lower-value, as the basis for determining how long to wait, and handles special cases such as legacy PCI devices (requiring Trhfa), and the different starting points for the waiting time depending on PCIe port speed. On PCI Express, there will be cases where the new code sleeps far less than the 1s being replaced by this patch. This should be okay, because PCI Express Base Specification Revision 5.0 Version 1.0 (May 22, 2019) in Section 6.6.1 "Conventional Reset" only notes 100ms as the minimum waiting time. After this time, the OS is permitted to issue Configuration Requests, but it is possible that the device responds with Configuration Request Retry Status (CRS) Completions, rather than Successful Completion. Returning CRS can go on for up to 1 second after a Conventional Reset (such as SBR) before the OS can consider the device broken. This additional wait is handled by pci_dev_wait. Currently, the only callchain that lands in the function modified by this patch starts at pci_bridge_secondary_bus_reset which invokes one out of two versions of pcibios_reset_secondary_bus that both end with a call to pci_reset_secondary_bus. Afterwards, pci_bridge_secondary_bus_reset always invokes pci_dev_wait. Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index ac8504d75c32..c1a866f733e9 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4800,14 +4800,7 @@ void pci_reset_secondary_bus(struct pci_dev *dev) ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET; pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl); - /* - * Trhfa for conventional PCI is 2^25 clock cycles. - * Assuming a minimum 33MHz clock this results in a 1s - * delay before we can consider subordinate devices to - * be re-initialized. PCIe has some ways to shorten this, - * but we don't make use of them yet. - */ - ssleep(1); + pci_bridge_wait_for_secondary_bus(dev); } void __weak pcibios_reset_secondary_bus(struct pci_dev *dev) From patchwork Tue Mar 3 13:28:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418007 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 10C7314B7 for ; Tue, 3 Mar 2020 13:30:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4B8320842 for ; Tue, 3 Mar 2020 13:30:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="onAKr0+t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728850AbgCCNaJ (ORCPT ); Tue, 3 Mar 2020 08:30:09 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:61587 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728068AbgCCNaJ (ORCPT ); Tue, 3 Mar 2020 08:30:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242208; x=1614778208; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7WM9yX1OJkKXJJaN0Bul5znh9nhHO2FbDkre7Td3gO0=; b=onAKr0+ts16dbD2+VkV/undi3EfSN346NAQHhV56k2/qSY6xi9yzm4MI O46QCb5LmCSPhEryy4ZGPDhsQ9yh/cs9CGI322jSEpjnVW+mqft7E4GFk g5HpKEzUICUU5KKRfqO0UxSoNqc1a+m4FTtebd9p3fbwjtnezOPBN61mF I=; IronPort-SDR: mdqZXfd6/iJ+37fvCK9FrLPkkeAsXdUvL1PNWQ85fyeOBxPFqFSXt6UG5vhZxLyjggZVvqa3Ft 4x9mXvfNyDFA== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="30249617" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2c-397e131e.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 03 Mar 2020 13:30:06 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-397e131e.us-west-2.amazon.com (Postfix) with ESMTPS id E118AA34C5; Tue, 3 Mar 2020 13:30:04 +0000 (UTC) Received: from EX13D12EUA003.ant.amazon.com (10.43.165.147) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:29:53 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUA003.ant.amazon.com (10.43.165.147) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:29:52 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:29:49 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 04/17] PCI: Do not override delay for D0->D3hot transition Date: Tue, 3 Mar 2020 14:28:39 +0100 Message-ID: <20200303132852.13184-5-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov Both specifications that document mechanisms for overriding the D3hot->D0 waiting time only speak of this specific direction. Nothing is mentioned about the opposite (D*->D3hot) except for the default value of 10ms in PCI Express Base Specification r5.0 (May 22, 2019), Section 5.9 "State Transition Recovery Time Requirements". Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index c1a866f733e9..03103bb15b42 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4589,7 +4589,7 @@ static int pci_pm_reset(struct pci_dev *dev, int probe) csr &= ~PCI_PM_CTRL_STATE_MASK; csr |= PCI_D3hot; pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr); - pci_dev_d3_sleep(dev); + msleep(PCI_PM_D3_WAIT); csr &= ~PCI_PM_CTRL_STATE_MASK; csr |= PCI_D0; From patchwork Tue Mar 3 13:28:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4621B138D for ; Tue, 3 Mar 2020 13:30:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2521020842 for ; Tue, 3 Mar 2020 13:30:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="FyjDdLQw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728846AbgCCNaY (ORCPT ); Tue, 3 Mar 2020 08:30:24 -0500 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:64941 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728068AbgCCNaY (ORCPT ); Tue, 3 Mar 2020 08:30:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242224; x=1614778224; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hin5pnYLRZeeL4R19g+s7EtcXGJQv8ECPkAJzZhQii0=; b=FyjDdLQwrbKhAYzXBiPaKbEuHt2n/4UiIMxGFQUwWOOy/XA6XQFG4DmO myHbOnZRbA1Gxh7O/2nEitWh9Jpj0jP/xv0bL3a/1eE5rqqOmfSDaVTX1 ZNdRHtNl49Yar/PjfqNDjpF9EbIfivTldInIrSJDA/n0fLj/Bkf8mR+bR U=; IronPort-SDR: TABliuHYPdbFXhfkdhfm4OBVi+lLJ7DEGMqGJ/ndPVTp+aGvZNcXX1kmwiS9mFTOYiBy21KFw/ VXukI0vJUF9g== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="19806525" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2c-397e131e.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 03 Mar 2020 13:30:10 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-397e131e.us-west-2.amazon.com (Postfix) with ESMTPS id ADD57A34C9; Tue, 3 Mar 2020 13:30:08 +0000 (UTC) Received: from EX13D04EUB001.ant.amazon.com (10.43.166.190) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:29:57 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D04EUB001.ant.amazon.com (10.43.166.190) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:29:55 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:29:53 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 05/17] PCI: Fix handling of _DSM 8 (avoiding reset delays) Date: Tue, 3 Mar 2020 14:28:40 +0100 Message-ID: <20200303132852.13184-6-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov On Sx Resume (boot from ACPI S5, resume from ACPI S4 or S3), platform firmware may enforce that sufficient time has passed to cover the mandatory (per PCI Express Specification) power-on reset delays of all PCI devices before control is handed over to the operating system. To avoid duplicated waiting by the OS, the firmware uses _DSM 8 in the ACPI scope of a PCI host bus to inform the OS that for the whole PCI subsystem underneath that host bridge, power-on reset delays are being covered by firmware. Previously, the kernel used _DSM 8 to override the d3cold_delay value stored in struct pci_dev to 0. However, the assumption that the delay is covered by firmware when _DSM 8 returns 1 only holds for the firmware-initiated resets as part of Sx Resume flows. If an OS has the ability to apply Conventional Reset to devices without system firmware involvement, then it still needs to adhere to the usual reset delays. Runtime Device Power Management triggering a D3cold->D0 transition is an existing example of the kernel not involving system firmware. Another example is the OS triggering Secondary Bus Reset by setting the SBR bit in the Bridge Control register of any Port device. In preparation for future work to improve post-reset delays, this patch preserves the value of d3cold_delay even when _DSM 8 returns 1. The decision not to wait after resume is instead taken at a higher level in pci_bridge_wait_for_secondary_bus based on a new parameter that indicates whether the waiting is due to an Sx Resume event. Signed-off-by: Stanislav Spassov --- drivers/pci/pci-acpi.c | 65 ++++++++++++++++++++++++++++++---------- drivers/pci/pci-driver.c | 4 +-- drivers/pci/pci.c | 11 +++++-- drivers/pci/pci.h | 2 +- include/linux/pci-acpi.h | 8 ++--- include/linux/pci.h | 4 ++- 6 files changed, 67 insertions(+), 27 deletions(-) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 0c02d500158f..a8fa13d6089d 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -1120,21 +1120,35 @@ void acpi_pci_add_bus(struct pci_bus *bus) acpi_pci_slot_enumerate(bus); acpiphp_enumerate_slots(bus); - /* - * For a host bridge, check its _DSM for function 8 and if - * that is available, mark it in pci_host_bridge. + /* For a host bridge, check _DSM function 8 and if that returns 1, + * mark it in the pci_host_bridge. + * + * Function 8, "Avoid Power-On Reset Delay Duplication on Sx Resume" + * applies to the entire hierarchy below a PCI host bridge. + * If it returns one, the OS may assume that all devices in the + * hierarchy have already completed power-on reset delays + * before FW handed over control to the OS on Sx Resume (such as boot + * from ACPI S5, or resume from ACPI S4 or S3 states). + * This _DSM is applicable whether reductions in device readiness + * timing, via Readiness Notification or _DSM function 9, are available + * or not. + * + * This _DSM function is defined by the PCI Firmware Specification + * Revision 3.2 (January 26, 2015), after originally introduced by a + * draft ECN of January 28, 2014, titled "ACPI additions for FW latency + * optimizations." */ if (!pci_is_root_bus(bus)) return; obj = acpi_evaluate_dsm(ACPI_HANDLE(bus->bridge), &pci_acpi_dsm_guid, 3, - RESET_DELAY_DSM, NULL); + IGNORE_RESET_DELAY_ON_SX_RESUME_DSM, NULL); if (!obj) return; if (obj->type == ACPI_TYPE_INTEGER && obj->integer.value == 1) { bridge = pci_find_host_bridge(bus); - bridge->ignore_reset_delay = 1; + bridge->ignore_reset_delay_on_sx_resume = 1; } ACPI_FREE(obj); } @@ -1168,19 +1182,38 @@ static struct acpi_device *acpi_pci_find_companion(struct device *dev) * @handle: ACPI handle of this device * * Update the d3_delay and d3cold_delay of a PCI device from the ACPI _DSM - * control method of either the device itself or the PCI host bridge. - * - * Function 8, "Reset Delay," applies to the entire hierarchy below a PCI - * host bridge. If it returns one, the OS may assume that all devices in - * the hierarchy have already completed power-on reset delays. + * Function 9 of the device, and cache the parent host bridge's flag for + * ignoring reset delay upon Sx Resume (the flag is originally set in + * acpi_pci_add_bus through _DSM Function 8). * * Function 9, "Device Readiness Durations," applies only to the object * where it is located. It returns delay durations required after various - * events if the device requires less time than the spec requires. Delays - * from this function take precedence over the Reset Delay function. + * events if the device requires less time than the spec requires. + * Values provided by this function can only be used to lower (reduce) the + * latency required by specification or values discovered from device. + * + * This _DSM function is defined by the PCI Firmware Specification Rev 3.2 + * (January 26, 2015), after originally introduced by a draft ECN of + * January 28, 2014, titled "ACPI additions for FW latency optimizations." * - * These _DSM functions are defined by the draft ECN of January 28, 2014, - * titled "ACPI additions for FW latency optimizations." + * XXX The PCI Firmware Specification contradicts itself by stating, in addition + * to the above "can only be used to lower (reduce)", that also: + * Values must be interpreted as overriding any Configuration Ready indicator + * from hardware, whether increasing or decreasing required delays. This + * includes ignoring FRS and DRS notifications where overridden by this + * _DSM function, as well as ignoring values specified in the Readiness Time + * Reporting Extended Capability, if present. + * Meanwhile, the PCI Express Base Specification Revision 5.0 Version 1.0 + * (22 May 2019) states in section 7.9.17 Readiness Time Reporting Extended + * Capability: + * Software is permitted to issue requests upon the earliest of: + * - Receiving a Readiness Notification messages + * - Waiting the appropriate time as per relevant specifications + * - Waiting the time indicated in the associated field of this capability + * - Waiting the time defined by system software or firmware + * The kernel does not yet support Readiness Notifications, and does not yet + * use a Readiness Time Reporting capability if present, so we do not need to + * worry about the prioritization for now. */ static void pci_acpi_optimize_delay(struct pci_dev *pdev, acpi_handle handle) @@ -1189,8 +1222,8 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev, int value; union acpi_object *obj, *elements; - if (bridge->ignore_reset_delay) - pdev->d3cold_delay = 0; + pdev->ignore_reset_delay_on_sx_resume = + bridge->ignore_reset_delay_on_sx_resume; obj = acpi_evaluate_dsm(handle, &pci_acpi_dsm_guid, 3, FUNCTION_DELAY_DSM, NULL); diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 0454ca0e4e3f..7e8ca8115c4f 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -917,7 +917,7 @@ static int pci_pm_resume_noirq(struct device *dev) pcie_pme_root_status_cleanup(pci_dev); if (!skip_bus_pm && prev_state == PCI_D3cold) - pci_bridge_wait_for_secondary_bus(pci_dev); + pci_bridge_wait_for_secondary_bus(pci_dev, true); if (pci_has_legacy_pm_support(pci_dev)) return 0; @@ -1321,7 +1321,7 @@ static int pci_pm_runtime_resume(struct device *dev) pci_pm_default_resume(pci_dev); if (prev_state == PCI_D3cold) - pci_bridge_wait_for_secondary_bus(pci_dev); + pci_bridge_wait_for_secondary_bus(pci_dev, false); if (pm && pm->runtime_resume) error = pm->runtime_resume(dev); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 03103bb15b42..4899b12b5a38 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2843,6 +2843,7 @@ void pci_pm_init(struct pci_dev *dev) } dev->pm_cap = pm; + dev->ignore_reset_delay_on_sx_resume = 0; dev->d3_delay = PCI_PM_D3_WAIT; dev->d3cold_delay = PCI_PM_D3COLD_WAIT; dev->bridge_d3 = pci_bridge_d3_possible(dev); @@ -4698,7 +4699,7 @@ static int pci_bus_max_d3cold_delay(const struct pci_bus *bus) * conventional PCI it means Tpvrh + Trhfa specified in PCI 3.0 section * 4.3.2. */ -void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev) +void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, bool sx_resume) { struct pci_dev *child; int delay; @@ -4723,7 +4724,11 @@ void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev) } /* Take d3cold_delay requirements into account */ - delay = pci_bus_max_d3cold_delay(dev->subordinate); + if (sx_resume && dev->ignore_reset_delay_on_sx_resume) + delay = 0; + else + delay = pci_bus_max_d3cold_delay(dev->subordinate); + if (!delay) { up_read(&pci_bus_sem); return; @@ -4800,7 +4805,7 @@ void pci_reset_secondary_bus(struct pci_dev *dev) ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET; pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl); - pci_bridge_wait_for_secondary_bus(dev); + pci_bridge_wait_for_secondary_bus(dev, false); } void __weak pcibios_reset_secondary_bus(struct pci_dev *dev) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 659ab3f9042a..c4c3ba926f45 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -107,7 +107,7 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev); void pci_free_cap_save_buffers(struct pci_dev *dev); bool pci_bridge_d3_possible(struct pci_dev *dev); void pci_bridge_d3_update(struct pci_dev *dev); -void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev); +void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, bool sx_resume); static inline void pci_wakeup_event(struct pci_dev *dev) { diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h index 62b7fdcc661c..99865773d65e 100644 --- a/include/linux/pci-acpi.h +++ b/include/linux/pci-acpi.h @@ -107,10 +107,10 @@ static inline void acpiphp_check_host_bridge(struct acpi_device *adev) { } #endif extern const guid_t pci_acpi_dsm_guid; -#define IGNORE_PCI_BOOT_CONFIG_DSM 0x05 -#define DEVICE_LABEL_DSM 0x07 -#define RESET_DELAY_DSM 0x08 -#define FUNCTION_DELAY_DSM 0x09 +#define IGNORE_PCI_BOOT_CONFIG_DSM 0x05 +#define DEVICE_LABEL_DSM 0x07 +#define IGNORE_RESET_DELAY_ON_SX_RESUME_DSM 0x08 +#define FUNCTION_DELAY_DSM 0x09 #else /* CONFIG_ACPI */ static inline void acpi_pci_add_bus(struct pci_bus *bus) { } diff --git a/include/linux/pci.h b/include/linux/pci.h index 3840a541a9de..22a5b7164c32 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -354,6 +354,8 @@ struct pci_dev { user sysfs */ unsigned int clear_retrain_link:1; /* Need to clear Retrain Link bit manually */ + unsigned int ignore_reset_delay_on_sx_resume:1; /* Cached value from + pci_host_bridge */ unsigned int d3_delay; /* D3->D0 transition time in ms */ unsigned int d3cold_delay; /* D3cold->D0 transition time in ms */ @@ -503,7 +505,7 @@ struct pci_host_bridge { void (*release_fn)(struct pci_host_bridge *); void *release_data; struct msi_controller *msi; - unsigned int ignore_reset_delay:1; /* For entire hierarchy */ + unsigned int ignore_reset_delay_on_sx_resume:1; /* For entire hierarchy */ unsigned int no_ext_tags:1; /* No Extended Tags */ unsigned int native_aer:1; /* OS may use PCIe AER */ unsigned int native_pcie_hotplug:1; /* OS may use PCIe hotplug */ From patchwork Tue Mar 3 13:28:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418019 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06EB014B7 for ; Tue, 3 Mar 2020 13:30:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB8E620848 for ; Tue, 3 Mar 2020 13:30:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="i63vrdyS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728972AbgCCNa1 (ORCPT ); Tue, 3 Mar 2020 08:30:27 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:35759 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727894AbgCCNa1 (ORCPT ); Tue, 3 Mar 2020 08:30:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242227; x=1614778227; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cBJBPVv+W+4p/cV1qgaUlMz0GLi1QkM2dp9VSDEJ5WE=; b=i63vrdySja3C21tsj0n2XdUT8yr1dDXn0t2QN6GL6Y4o6wq9gYtSq4Wi dmVMLmNyBHigGiaTW9EXeFBI8zDvEd2Pw5Tkv0tX73WiKyTmjEDRdCkWU tNmkHC8pUmd7GFvjxADFlVg9XI1eh7+z7Lwk+24Pumtiwa/7WuAyhPWZV 8=; IronPort-SDR: OrsuFgpYPMr5SbJBD+toVXzyOEkDAGU89gWRolDuCVaKx8Hh4OMKekdIfl6SXN4p7Nhzko2dFD 9Ntw2kvZbytg== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="20717872" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 03 Mar 2020 13:30:13 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2c-4e7c8266.us-west-2.amazon.com (Postfix) with ESMTPS id 79C41A2E44; Tue, 3 Mar 2020 13:30:11 +0000 (UTC) Received: from EX13D12EUC001.ant.amazon.com (10.43.164.45) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:00 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUC001.ant.amazon.com (10.43.164.45) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:29:58 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:29:56 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 06/17] PCI: Fix us->ms conversion in pci_acpi_optimize_delay Date: Tue, 3 Mar 2020 14:28:41 +0100 Message-ID: <20200303132852.13184-7-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov _DSM Function 9 returns device readiness durations in microseconds. Without this fix, integer truncation could cause msleep()-ing for up to 999us less than actually requested by the firmware. Specifically, if the firmware specifies a 500us delay, msleep(0) would be invoked by the users of the delay values optimized here. Signed-off-by: Stanislav Spassov --- drivers/pci/pci-acpi.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index a8fa13d6089d..b147b61c6668 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -1219,6 +1219,11 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev, acpi_handle handle) { struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus); + /* + * _DSM 9 provides values in microseconds, but the kernel uses msleep() + * when waiting, so the code below rounds up when setting value in ms + */ + u64 value_us; int value; union acpi_object *obj, *elements; @@ -1233,12 +1238,18 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev, if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 5) { elements = obj->package.elements; if (elements[0].type == ACPI_TYPE_INTEGER) { - value = (int)elements[0].integer.value / 1000; + value_us = elements[0].integer.value; + value = (int)value_us / 1000; + if ((int)value_us % 1000 > 0) + value++; if (value < PCI_PM_D3COLD_WAIT) pdev->d3cold_delay = value; } if (elements[3].type == ACPI_TYPE_INTEGER) { - value = (int)elements[3].integer.value / 1000; + value_us = elements[3].integer.value; + value = (int)value_us / 1000; + if ((int)value_us % 1000 > 0) + value++; if (value < PCI_PM_D3_WAIT) pdev->d3_delay = value; } From patchwork Tue Mar 3 13:28:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418027 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13062924 for ; Tue, 3 Mar 2020 13:30:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E725820842 for ; Tue, 3 Mar 2020 13:30:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="CP9ng6IP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728068AbgCCNat (ORCPT ); Tue, 3 Mar 2020 08:30:49 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:31467 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727862AbgCCNat (ORCPT ); Tue, 3 Mar 2020 08:30:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242248; x=1614778248; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m9UC6YMrCEkdQKApcmjI1lOwtfkDHyrdWMSJSbIlTXI=; b=CP9ng6IPINxn/+NRTGoRXKs8x0N5sGvks0jZF8wIkPna8SHjnoX4qSVj GG1MyIkcvSDIduwJwrxdOP3Pwhi2bZLECeprvKFMNZW3rilE/vTACmLYG 0XyZ9v5odiCSK3q409lK5FQakFkDKOj24a7mazqWf5UkoxgO24NQzf/df s=; IronPort-SDR: VT0rCqnUvfwE/Cq6jTl9TgJjfOlKwfQKuSOQX1Fyv/VI5ahEKIBJDbjAYbD7CcZWUbyYVjBvJE euQGgxZlUsFQ== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="20496287" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 03 Mar 2020 13:30:47 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com (Postfix) with ESMTPS id 63879A2F96; Tue, 3 Mar 2020 13:30:45 +0000 (UTC) Received: from EX13D12EUC004.ant.amazon.com (10.43.164.129) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:16 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUC004.ant.amazon.com (10.43.164.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:13 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:09 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot , , Thomas Petazzoni , Lorenzo Pieralisi , Andrew Murray , Jason Cooper , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v3 07/17] PCI: Clean up and document PM/reset delays Date: Tue, 3 Mar 2020 14:28:42 +0100 Message-ID: <20200303132852.13184-8-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov ...and replace several "magic numbers" scattered throughout the code. Signed-off-by: Stanislav Spassov --- drivers/pci/controller/pci-aardvark.c | 2 +- drivers/pci/controller/pci-mvebu.c | 2 +- drivers/pci/iov.c | 4 +- drivers/pci/pci-acpi.c | 4 +- drivers/pci/pci.c | 21 ++------ drivers/pci/pci.h | 72 +++++++++++++++++++++++++-- 6 files changed, 80 insertions(+), 25 deletions(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 2a20b649f40c..2ece24abf751 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -344,7 +344,7 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) * fundamental reset. As required by PCI Express spec a delay for at * least 100ms after such a reset before link training is needed. */ - msleep(PCI_PM_D3COLD_WAIT); + msleep(PCI_RESET_DELAY); /* Start link training */ reg = advk_readl(pcie, PCIE_CORE_LINK_CTRL_STAT_REG); diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c index 153a64676bc9..c1cd1b7cf7ee 100644 --- a/drivers/pci/controller/pci-mvebu.c +++ b/drivers/pci/controller/pci-mvebu.c @@ -927,7 +927,7 @@ static int mvebu_pcie_powerup(struct mvebu_pcie_port *port) return ret; if (port->reset_gpio) { - u32 reset_udelay = PCI_PM_D3COLD_WAIT * 1000; + u32 reset_udelay = PCI_RESET_DELAY * 1000; of_property_read_u32(port->dn, "reset-delay-us", &reset_udelay); diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 4d1f392b05f9..d4e4a0c0a97f 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -524,7 +524,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) iov->ctrl |= PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE; pci_cfg_access_lock(dev); pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); - msleep(100); + msleep(PCI_VF_ENABLE_DELAY); pci_cfg_access_unlock(dev); rc = sriov_add_vfs(dev, initial); @@ -735,7 +735,7 @@ static void sriov_restore_state(struct pci_dev *dev) pci_iov_set_numvfs(dev, iov->num_VFs); pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); if (iov->ctrl & PCI_SRIOV_CTRL_VFE) - msleep(100); + msleep(PCI_VF_ENABLE_DELAY); } /** diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index b147b61c6668..0ece144ac9c5 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -1242,7 +1242,7 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev, value = (int)value_us / 1000; if ((int)value_us % 1000 > 0) value++; - if (value < PCI_PM_D3COLD_WAIT) + if (value < PCI_RESET_DELAY) pdev->d3cold_delay = value; } if (elements[3].type == ACPI_TYPE_INTEGER) { @@ -1250,7 +1250,7 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev, value = (int)value_us / 1000; if ((int)value_us % 1000 > 0) value++; - if (value < PCI_PM_D3_WAIT) + if (value < PCI_PM_D3HOT_DELAY) pdev->d3_delay = value; } } diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 4899b12b5a38..aaef00578487 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2844,8 +2844,8 @@ void pci_pm_init(struct pci_dev *dev) dev->pm_cap = pm; dev->ignore_reset_delay_on_sx_resume = 0; - dev->d3_delay = PCI_PM_D3_WAIT; - dev->d3cold_delay = PCI_PM_D3COLD_WAIT; + dev->d3_delay = PCI_PM_D3HOT_DELAY; + dev->d3cold_delay = PCI_RESET_DELAY; dev->bridge_d3 = pci_bridge_d3_possible(dev); dev->d3cold_allowed = true; @@ -4500,12 +4500,7 @@ int pcie_flr(struct pci_dev *dev) if (dev->imm_ready) return 0; - /* - * Per PCIe r4.0, sec 6.6.2, a device must complete an FLR within - * 100ms, but may silently discard requests while the FLR is in - * progress. Wait 100ms before trying to access the device. - */ - msleep(100); + msleep(PCI_FLR_DELAY); return pci_dev_wait(dev, "FLR", PCIE_RESET_READY_POLL_MS); } @@ -4544,13 +4539,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe) if (dev->imm_ready) return 0; - /* - * Per Advanced Capabilities for Conventional PCI ECN, 13 April 2006, - * updated 27 July 2006; a device must complete an FLR within - * 100ms, but may silently discard requests while the FLR is in - * progress. Wait 100ms before trying to access the device. - */ - msleep(100); + msleep(PCI_FLR_DELAY); return pci_dev_wait(dev, "AF_FLR", PCIE_RESET_READY_POLL_MS); } @@ -4590,7 +4579,7 @@ static int pci_pm_reset(struct pci_dev *dev, int probe) csr &= ~PCI_PM_CTRL_STATE_MASK; csr |= PCI_D3hot; pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr); - msleep(PCI_PM_D3_WAIT); + msleep(PCI_PM_D3HOT_DELAY); csr &= ~PCI_PM_CTRL_STATE_MASK; csr |= PCI_D0; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index c4c3ba926f45..9b5dd6ea2f52 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -43,9 +43,75 @@ int pci_probe_reset_function(struct pci_dev *dev); int pci_bridge_secondary_bus_reset(struct pci_dev *dev); int pci_bus_error_reset(struct pci_dev *dev); -#define PCI_PM_D2_DELAY 200 -#define PCI_PM_D3_WAIT 10 -#define PCI_PM_D3COLD_WAIT 100 +/* + * These constants represent the minimum amounts of time mandated by the + * PCI Express Base specification that software needs to wait after + * various PCI device events involving (re-)initialization. Only after + * the appropriate delay has elapsed, is software permitted to issue + * Configuration Requests targeting the affected device. + * + * Relevant sections in PCI Express Base Specification r5.0 (May 22, 2019): + * - 6.6.1 "Conventional Reset" for PCI_RESET_DELAY and PCI_DL_UP_DELAY + * - 6.6.2 "Function Level Reset" for PCI_FLR_DELAY + * - 5.9 "State Transition Recovery Time Requirements" for PCI_PM_D3HOT_DELAY + * and PCI_PM_D2_DELAY + * - 9.3.3.3.1 "VF Enable" for PCI_VF_ENABLE_DELAY + * + * There are mechanisms to reduce some of the delay values for specific devices: + * - a device may expose the Readiness Time Reporting Extended Capability from: + * PCI Express Base Specification r4.0 (September 27, 2017), sec 7.9.17 + * (This is currently not supported by the kernel.) + * - system firmware may provide overrides using an ACPI _DSM Function 9: + * PCI Firmware Specification r3.2 (January 26, 2015), sec 4.6.9 + * (see pci_acpi_optimize_delay) + * + * Unless overridden by _DSM Function 9, other mechanisms may be used to reduce + * or completely avoid some of the delays: + * - Readiness Notifications (DRS and FRS) + * - the Immediate Readiness bit of the Status Register in the PCI header + * - the Immediate_Readiness_on_Return_to_D0 in the Power Management + * Capabilities Register in the PCI Power Management Capability + * (None of these are currently supported by the kernel.) + * + * Note: While devices are required to be responsive to Configuration + * Requests after these delays, they may not respond with Successful + * Completion status until they complete potentially lengthy internal + * initialization sequences. Instead, devices respond with Configuration + * Request Retry Status (CRS) Completions. Therefore, additional waiting + * is necessary as handled by pci_dev_wait(). + */ +/* + * Conventional (non-FLR) reset delay, including D3cold->D0 transitions, + * Secondary Bus Reset, and any platform-specific means of triggering + * a Conventional Reset. + * + * According to PCI Firmware spec r3.2, sec 4.6.9, for devices beneath + * downstream ports supporting the Data Link Layer Active Reporting + * capability, this delay should not be used (see PCI_DL_UP_DELAY). + */ +#define PCI_RESET_DELAY 100 +/* + * Post-DL_Up (Data Link Layer Active) delay applicable for devices immediately + * under a Downstream Port that is capable of reporting Data Link Layer Ready. + * Not to be confused with how much time it takes for the link itself to become + * active (see pcie_wait_for_link_delay). + */ +#define PCI_DL_UP_DELAY 100 +/* + * Post-FLR delay + * Also applies to legacy devices supporting AF_FLR per Advanced Capabilities + * for Conventional PCI ECN, 13 April 2006, updated 27 July 2006) + */ +#define PCI_FLR_DELAY 100 +/* + * D0/D1/D2->D3hot and D3hot->D0 delay + * The specifications do *not* mention overridability of the ->D3hot direction + */ +#define PCI_PM_D3HOT_DELAY 10 +/* Post-VF_Enable delay */ +#define PCI_VF_ENABLE_DELAY 100 +/* D0/D1->D2 and D2->D0 delay */ +#define PCI_PM_D2_DELAY 200 /** * struct pci_platform_pm_ops - Firmware PM callbacks From patchwork Tue Mar 3 13:28:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418035 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 452A314B7 for ; Tue, 3 Mar 2020 13:30:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1AC942146E for ; Tue, 3 Mar 2020 13:30:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="i3X+5gQQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728456AbgCCNay (ORCPT ); Tue, 3 Mar 2020 08:30:54 -0500 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:16868 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729248AbgCCNay (ORCPT ); Tue, 3 Mar 2020 08:30:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242253; x=1614778253; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M4Mq+kGW1CQpyKKaKoDNRHW6u/EcyxIqrqhm+IZ3770=; b=i3X+5gQQQZn2aozuzfqtJAS2Vfem6E8EqyR4EURg41uiAP+7EDLMA0BT Im3FY6aXhBZdazfc20GRMzsuUIvNZEE+Yv6hZhWffYTMiYUH3fnPKiIWm uUe7lryflrgcpzhZGicMqLAKyP/Q9BXLRkeMfQoYOQO7PK5Zx+ZOYE5Na U=; IronPort-SDR: WjBzMKVnoyope+/qXJuPJhTve87gE+154PVcYxNn3GVsN77mw+IeZZW+ip/D0TgGG3/Jp85orL s4Osfj5JzFdA== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="19549035" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-55156cd4.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 03 Mar 2020 13:30:50 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-55156cd4.us-west-2.amazon.com (Postfix) with ESMTPS id AFF36A2E75; Tue, 3 Mar 2020 13:30:47 +0000 (UTC) Received: from EX13D12EUC002.ant.amazon.com (10.43.164.134) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:19 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUC002.ant.amazon.com (10.43.164.134) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:17 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:14 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot , "Rafael J. Wysocki" , , Len Brown , Pavel Machek , Ingo Molnar , Borislav Petkov , , Srinivas Pandruvada , Jiri Kosina , Benjamin Tissoires , Lee Jones , Mirko Lindner , "Stephen Hemminger" , "David S. Miller" Subject: [PATCH v3 08/17] PCI: Add more delay overrides to struct pci_dev Date: Tue, 3 Mar 2020 14:28:43 +0100 Message-ID: <20200303132852.13184-9-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov Almost all of the PCI_*_DELAY constants declared in drivers/pci/pci.h can be overridden on a per-device basis, as explained in the constants' comments. To allow storing per-device values, this patch introduces a type to describe the various "initialization events": enum pci_init_event and an array in struct pci_dev, with an override for each event. This array is initially populated with the PCI_*_DELAY constants, but can be later overridden by pci_acpi_optimize_delay. Quirks and drivers may also end up tweaking the values. The new array replaces two previous members: d3_delay and d3cold_delay Direct mentions of PCI_*_DELAY are replaced with the per-device override where applicable. Signed-off-by: Stanislav Spassov --- Documentation/power/pci.rst | 4 ++- arch/x86/pci/intel_mid_pci.c | 2 +- drivers/hid/intel-ish-hid/ipc/ipc.c | 2 +- drivers/mfd/intel-lpss-pci.c | 2 +- drivers/net/ethernet/marvell/sky2.c | 2 +- drivers/pci/iov.c | 4 +-- drivers/pci/pci-acpi.c | 42 ++++++++++++++++------------- drivers/pci/pci.c | 36 ++++++++++++++++++------- drivers/pci/quirks.c | 9 ++++--- include/linux/pci.h | 35 ++++++++++++++++++++++-- 10 files changed, 97 insertions(+), 41 deletions(-) diff --git a/Documentation/power/pci.rst b/Documentation/power/pci.rst index 0924d29636ad..8136c8a4b150 100644 --- a/Documentation/power/pci.rst +++ b/Documentation/power/pci.rst @@ -320,7 +320,9 @@ that these callbacks operate on:: unsigned int d2_support:1; /* Low power state D2 is supported */ unsigned int no_d1d2:1; /* D1 and D2 are forbidden */ unsigned int wakeup_prepared:1; /* Device prepared for wake up */ - unsigned int d3_delay; /* D3->D0 transition time in ms */ + unsigned int delay[PCI_INIT_EVENT_COUNT]; /* minimum waiting time + after various events + in ms */ ... }; diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c index 00c62115f39c..b42b14cd0e00 100644 --- a/arch/x86/pci/intel_mid_pci.c +++ b/arch/x86/pci/intel_mid_pci.c @@ -322,7 +322,7 @@ static void pci_d3delay_fixup(struct pci_dev *dev) */ if (type1_access_ok(dev->bus->number, dev->devfn, PCI_DEVICE_ID)) return; - dev->d3_delay = 0; + dev->delay[PCI_INIT_EVENT_D3HOT_TO_D0] = 0; } DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_d3delay_fixup); diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index 8f8dfdf64833..a209b954fbe8 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c @@ -755,7 +755,7 @@ static int _ish_hw_reset(struct ishtp_device *dev) csr |= PCI_D3hot; pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr); - mdelay(pdev->d3_delay); + mdelay(pdev->delay[PCI_INIT_EVENT_D3HOT_TO_D0]); csr &= ~PCI_PM_CTRL_STATE_MASK; csr |= PCI_D0; diff --git a/drivers/mfd/intel-lpss-pci.c b/drivers/mfd/intel-lpss-pci.c index c40a6c7d0cf8..5b9e458d0ab1 100644 --- a/drivers/mfd/intel-lpss-pci.c +++ b/drivers/mfd/intel-lpss-pci.c @@ -35,7 +35,7 @@ static int intel_lpss_pci_probe(struct pci_dev *pdev, info->mem = &pdev->resource[0]; info->irq = pdev->irq; - pdev->d3cold_delay = 0; + pdev->delay[PCI_INIT_EVENT_RESET] = 0; /* Probably it is enough to set this for iDMA capable devices only */ pci_set_master(pdev); diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c index ebfd0ceac884..f808562e389d 100644 --- a/drivers/net/ethernet/marvell/sky2.c +++ b/drivers/net/ethernet/marvell/sky2.c @@ -5100,7 +5100,7 @@ static int sky2_probe(struct pci_dev *pdev, const struct pci_device_id *ent) INIT_WORK(&hw->restart_work, sky2_restart); pci_set_drvdata(pdev, hw); - pdev->d3_delay = 300; + pdev->delay[PCI_INIT_EVENT_D3HOT_TO_D0] = 300; return 0; diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index d4e4a0c0a97f..f71fc28b69e6 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -524,7 +524,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) iov->ctrl |= PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE; pci_cfg_access_lock(dev); pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); - msleep(PCI_VF_ENABLE_DELAY); + msleep(dev->delay[PCI_INIT_EVENT_VF_ENABLE]); pci_cfg_access_unlock(dev); rc = sriov_add_vfs(dev, initial); @@ -735,7 +735,7 @@ static void sriov_restore_state(struct pci_dev *dev) pci_iov_set_numvfs(dev, iov->num_VFs); pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); if (iov->ctrl & PCI_SRIOV_CTRL_VFE) - msleep(PCI_VF_ENABLE_DELAY); + msleep(dev->delay[PCI_INIT_EVENT_VF_ENABLE]); } /** diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 0ece144ac9c5..5b95785c5bb5 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -1177,11 +1177,11 @@ static struct acpi_device *acpi_pci_find_companion(struct device *dev) } /** - * pci_acpi_optimize_delay - optimize PCI D3 and D3cold delay from ACPI - * @pdev: the PCI device whose delay is to be updated + * pci_acpi_optimize_delay - optimize PCI readiness delays from ACPI + * @pdev: the PCI device whose delays are to be updated * @handle: ACPI handle of this device * - * Update the d3_delay and d3cold_delay of a PCI device from the ACPI _DSM + * Update the readiness delays of a PCI device from the ACPI _DSM * Function 9 of the device, and cache the parent host bridge's flag for * ignoring reset delay upon Sx Resume (the flag is originally set in * acpi_pci_add_bus through _DSM Function 8). @@ -1226,6 +1226,7 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev, u64 value_us; int value; union acpi_object *obj, *elements; + int i; pdev->ignore_reset_delay_on_sx_resume = bridge->ignore_reset_delay_on_sx_resume; @@ -1237,21 +1238,26 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev, if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 5) { elements = obj->package.elements; - if (elements[0].type == ACPI_TYPE_INTEGER) { - value_us = elements[0].integer.value; - value = (int)value_us / 1000; - if ((int)value_us % 1000 > 0) - value++; - if (value < PCI_RESET_DELAY) - pdev->d3cold_delay = value; - } - if (elements[3].type == ACPI_TYPE_INTEGER) { - value_us = elements[3].integer.value; - value = (int)value_us / 1000; - if ((int)value_us % 1000 > 0) - value++; - if (value < PCI_PM_D3HOT_DELAY) - pdev->d3_delay = value; + for (i = 0; i < 5; i++) { + if (elements[i].type == ACPI_TYPE_INTEGER) { + value_us = elements[i].integer.value; + value = (int)value_us / 1000; + if ((int)value_us % 1000 > 0) + value++; + /* + * XXX This relies on the initial values in the + * delay array being set using the PCI_*_DELAY + * macros in drivers/pci/pci.h + * Once the kernel has support for Readiness + * Time Reporting Extended Capability, this + * needs fixing to honor prioritization of + * overrides. Also, a flag would need to be + * set to disable the use of Readiness + * Notifications at some point. + */ + if (value < pdev->delay[i]) + pdev->delay[i] = value; + } } } ACPI_FREE(obj); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index aaef00578487..ba54164652cc 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -43,6 +43,15 @@ const char *pci_power_names[] = { }; EXPORT_SYMBOL_GPL(pci_power_names); +const char *pci_init_event_names[] = { + [PCI_INIT_EVENT_RESET] = "conventional reset", + [PCI_INIT_EVENT_DL_UP] = "DL Up", + [PCI_INIT_EVENT_FLR] = "FLR", + [PCI_INIT_EVENT_D3HOT_TO_D0] = "PM D3hot->D0", + [PCI_INIT_EVENT_VF_ENABLE] = "VF Enable", +}; +EXPORT_SYMBOL_GPL(pci_init_event_names); + int isa_dma_bridge_buggy; EXPORT_SYMBOL(isa_dma_bridge_buggy); @@ -66,7 +75,7 @@ struct pci_pme_device { static void pci_dev_d3_sleep(struct pci_dev *dev) { - unsigned int delay = dev->d3_delay; + unsigned int delay = dev->delay[PCI_INIT_EVENT_D3HOT_TO_D0]; if (delay < pci_pm_d3_delay) delay = pci_pm_d3_delay; @@ -2844,8 +2853,11 @@ void pci_pm_init(struct pci_dev *dev) dev->pm_cap = pm; dev->ignore_reset_delay_on_sx_resume = 0; - dev->d3_delay = PCI_PM_D3HOT_DELAY; - dev->d3cold_delay = PCI_RESET_DELAY; + dev->delay[PCI_INIT_EVENT_RESET] = PCI_RESET_DELAY; + dev->delay[PCI_INIT_EVENT_DL_UP] = PCI_DL_UP_DELAY; + dev->delay[PCI_INIT_EVENT_FLR] = PCI_FLR_DELAY; + dev->delay[PCI_INIT_EVENT_D3HOT_TO_D0] = PCI_PM_D3HOT_DELAY; + dev->delay[PCI_INIT_EVENT_VF_ENABLE] = PCI_VF_ENABLE_DELAY; dev->bridge_d3 = pci_bridge_d3_possible(dev); dev->d3cold_allowed = true; @@ -4500,7 +4512,7 @@ int pcie_flr(struct pci_dev *dev) if (dev->imm_ready) return 0; - msleep(PCI_FLR_DELAY); + msleep(dev->delay[PCI_INIT_EVENT_FLR]); return pci_dev_wait(dev, "FLR", PCIE_RESET_READY_POLL_MS); } @@ -4539,7 +4551,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe) if (dev->imm_ready) return 0; - msleep(PCI_FLR_DELAY); + msleep(dev->delay[PCI_INIT_EVENT_FLR]); return pci_dev_wait(dev, "AF_FLR", PCIE_RESET_READY_POLL_MS); } @@ -4556,7 +4568,9 @@ static int pci_af_flr(struct pci_dev *dev, int probe) * * NOTE: This causes the caller to sleep for twice the device power transition * cooldown period, which for the D0->D3hot and D3hot->D0 transitions is 10 ms - * by default (i.e. unless the @dev's d3_delay field has a different value). + * by default (i.e. unless the @dev's delay[PCI_INIT_EVENT_D3HOT_TO_D0] field + * has a different value). + * * Moreover, only devices in D0 can be reset by this function. */ static int pci_pm_reset(struct pci_dev *dev, int probe) @@ -4666,12 +4680,14 @@ static int pci_bus_max_d3cold_delay(const struct pci_bus *bus) const struct pci_dev *pdev; int min_delay = 100; int max_delay = 0; + int delay; list_for_each_entry(pdev, &bus->devices, bus_list) { - if (pdev->d3cold_delay < min_delay) - min_delay = pdev->d3cold_delay; - if (pdev->d3cold_delay > max_delay) - max_delay = pdev->d3cold_delay; + delay = pdev->delay[PCI_INIT_EVENT_RESET]; + if (delay < min_delay) + min_delay = delay; + if (delay > max_delay) + max_delay = delay; } return max(min_delay, max_delay); diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 29f473ebf20f..12f22af0cbef 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -1873,12 +1873,13 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260b, quirk_intel_pcie_pm); static void quirk_d3hot_delay(struct pci_dev *dev, unsigned int delay) { - if (dev->d3_delay >= delay) + + if (dev->delay[PCI_INIT_EVENT_D3HOT_TO_D0] >= delay) return; - dev->d3_delay = delay; + dev->delay[PCI_INIT_EVENT_D3HOT_TO_D0] = delay; pci_info(dev, "extending delay after power-on from D3hot to %d msec\n", - dev->d3_delay); + dev->delay[PCI_INIT_EVENT_D3HOT_TO_D0]); } static void quirk_radeon_pm(struct pci_dev *dev) @@ -3310,7 +3311,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0152, disable_igfx_irq); */ static void quirk_remove_d3_delay(struct pci_dev *dev) { - dev->d3_delay = 0; + dev->delay[PCI_INIT_EVENT_D3HOT_TO_D0] = 0; } /* C600 Series devices do not need 10ms d3_delay */ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0412, quirk_remove_d3_delay); diff --git a/include/linux/pci.h b/include/linux/pci.h index 22a5b7164c32..16dbfff2092e 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -268,6 +268,36 @@ enum pci_bus_speed { enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev); enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev); +/* + * The first five constants correspond to delays specified in both: + * PCI Firmware Specification Rev. 3.2 (January 26, 2015), + * Section 4.6.9. "_DSM for Specifying Device Readiness Durations", and + * PCI Express Base Specification Revision 5.0 Version 1.0 (May 22, 2019) + * Section 7.9.17 "Readiness Time Reporting Extended Capability" + * + * The code assumes these constants are in the same order as in the + * PCI Firmware Specification. + */ +enum pci_init_event { + PCI_INIT_EVENT_RESET = 0, /* D3cold->D0, SBR */ + PCI_INIT_EVENT_DL_UP = 1, + PCI_INIT_EVENT_FLR = 2, + PCI_INIT_EVENT_D3HOT_TO_D0 = 3, + PCI_INIT_EVENT_VF_ENABLE = 4, + PCI_INIT_EVENT_COUNT /* Keep this as last element */ +}; + +/* Remember to update this when the list above changes! */ +extern const char *pci_init_event_names[]; + +static inline const char *pci_init_event_name(enum pci_init_event event) +{ + if (event >= PCI_INIT_EVENT_COUNT) + return ""; + else + return pci_init_event_names[event]; +} + struct pci_cap_saved_data { u16 cap_nr; bool cap_extended; @@ -356,8 +386,9 @@ struct pci_dev { bit manually */ unsigned int ignore_reset_delay_on_sx_resume:1; /* Cached value from pci_host_bridge */ - unsigned int d3_delay; /* D3->D0 transition time in ms */ - unsigned int d3cold_delay; /* D3cold->D0 transition time in ms */ + unsigned int delay[PCI_INIT_EVENT_COUNT]; /* minimum waiting time + after various events + in ms */ #ifdef CONFIG_PCIEASPM struct pcie_link_state *link_state; /* ASPM link state */ From patchwork Tue Mar 3 13:28:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418031 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCC7914B7 for ; Tue, 3 Mar 2020 13:30:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9C53C20842 for ; Tue, 3 Mar 2020 13:30:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="piCrJYkF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729327AbgCCNax (ORCPT ); Tue, 3 Mar 2020 08:30:53 -0500 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:65027 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727862AbgCCNaw (ORCPT ); Tue, 3 Mar 2020 08:30:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242253; x=1614778253; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f1H7XOSMeRzetd59oqKV+/fQ2SI/DghKGu3MCc/evPI=; b=piCrJYkF1uj0162E7+rA/GbdoWZ+9YIVvnk+QZ+9e3qxgFFmHgwoMW77 Zc0EhzzCXjnLp0RTM1faCVly9VS4TGCqCssFeSGT18iuQ0aXvA6aEiem1 IfGCagLrwluHItXfTJ3mZaw9K56UH65lsAX9mhdD8LS19KZDHj9tomJDC 4=; IronPort-SDR: qTro6rTEC6aDeS82mdhYKYFPgA8o4/Wt6mrb58PHZGqytmTgqsY5uTldji1Y+1mfSzRMN+uX4k E2ge8zYH4DSw== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="19806614" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2b-4e24fd92.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 03 Mar 2020 13:30:51 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-4e24fd92.us-west-2.amazon.com (Postfix) with ESMTPS id 99206A2E11; Tue, 3 Mar 2020 13:30:49 +0000 (UTC) Received: from EX13D12EUC001.ant.amazon.com (10.43.164.45) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:21 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUC001.ant.amazon.com (10.43.164.45) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:20 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:18 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 09/17] PCI: Generalize pci_bus_max_d3cold_delay to pci_bus_max_delay Date: Tue, 3 Mar 2020 14:28:44 +0100 Message-ID: <20200303132852.13184-10-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov This allows determining the maximum of any of the several delay values stored in struct pci_dev. Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index ba54164652cc..e4840dbf2d1c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4669,21 +4669,26 @@ bool pcie_wait_for_link(struct pci_dev *pdev, bool active) } /* - * Find maximum D3cold delay required by all the devices on the bus. The - * spec says 100 ms, but firmware can lower it and we allow drivers to - * increase it as well. + * Find maximum delay required by all the devices on the bus after the + * given initialization event. * * Called with @pci_bus_sem locked for reading. + * + * XXX: It is not clear if this should descend down across bridges (if any) */ -static int pci_bus_max_d3cold_delay(const struct pci_bus *bus) +static int pci_bus_max_delay(const struct pci_bus *bus, + enum pci_init_event event, int default_delay) { const struct pci_dev *pdev; - int min_delay = 100; + int min_delay = default_delay; int max_delay = 0; int delay; + if (event >= PCI_INIT_EVENT_COUNT) + return default_delay; + list_for_each_entry(pdev, &bus->devices, bus_list) { - delay = pdev->delay[PCI_INIT_EVENT_RESET]; + delay = pdev->delay[event]; if (delay < min_delay) min_delay = delay; if (delay > max_delay) @@ -4728,11 +4733,13 @@ void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, bool sx_resume) return; } - /* Take d3cold_delay requirements into account */ + /* Take delay requirements into account */ if (sx_resume && dev->ignore_reset_delay_on_sx_resume) delay = 0; else - delay = pci_bus_max_d3cold_delay(dev->subordinate); + delay = pci_bus_max_delay(dev->subordinate, + PCI_INIT_EVENT_RESET, + PCI_RESET_DELAY); if (!delay) { up_read(&pci_bus_sem); From patchwork Tue Mar 3 13:28:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418041 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C31314B7 for ; Tue, 3 Mar 2020 13:30:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E44A2146E for ; Tue, 3 Mar 2020 13:30:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="XRE/d/ls" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728311AbgCCNa4 (ORCPT ); Tue, 3 Mar 2020 08:30:56 -0500 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:16894 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727862AbgCCNaz (ORCPT ); Tue, 3 Mar 2020 08:30:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242255; x=1614778255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9xqMD1N8mF24q9FbAWh4uDveX6H7dYjjMS/baY775kQ=; b=XRE/d/lsA6moDiV/m/euLztL02OMMVvGfZc2Hb0neyX4JmJkc37G8kfY lQaYc+4+3FWkYY917sznS2UCb5Afm02tqwzOuvsO16iv++w1KN3dRF/nT TIGK8KMKMFOEz28yzdjB6m5Au3t7HxGn48oLPZLZLwb423iG8UpSFyktu A=; IronPort-SDR: QXgtJ4opWTT+69jwBRvSBdm/7QPp6001D3PSirDHQy1f7YmKzHwZO/d4FuxLVC6B0ggAAf9Y6V yxKBhzp8ipAw== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="19549048" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 03 Mar 2020 13:30:53 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-f14f4a47.us-west-2.amazon.com (Postfix) with ESMTPS id C1C4DA2FF8; Tue, 3 Mar 2020 13:30:51 +0000 (UTC) Received: from EX13D04EUA002.ant.amazon.com (10.43.165.75) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:23 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D04EUA002.ant.amazon.com (10.43.165.75) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:23 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:20 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 10/17] PCI: Use correct delay in pci_bridge_wait_for_secondary_bus Date: Tue, 3 Mar 2020 14:28:45 +0100 Message-ID: <20200303132852.13184-11-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov PCI Express Base Specification r5.0 (May 22, 2019) details the rules for device reset in Section 6.6. For a Downstream Port that does not support Link speeds greater than 5.0 GT/s, the minimum waiting period before software is permitted to send a Configuration Request after a Conventional Reset is 100ms (PCI_RESET_DELAY). For a Downstream Port that supports Link speeds greater than 5.0 GT/s (such ports are required to be Data Link Layer Link Active Reporting capable), the period is again 100ms but measured after the link has become active (PCI_DL_UP_DELAY). The delays for both cases above can be overridden independently, and pci_bridge_wait_for_secondary_bus should use the appropriate one. Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e4840dbf2d1c..7e08c5f38190 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4736,6 +4736,12 @@ void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, bool sx_resume) /* Take delay requirements into account */ if (sx_resume && dev->ignore_reset_delay_on_sx_resume) delay = 0; + else if (pcie_downstream_port(dev) && + pcie_get_speed_cap(dev) > PCIE_SPEED_5_0GT && + dev->link_active_reporting) + delay = pci_bus_max_delay(dev->subordinate, + PCI_INIT_EVENT_DL_UP, + PCI_DL_UP_DELAY); else delay = pci_bus_max_delay(dev->subordinate, PCI_INIT_EVENT_RESET, From patchwork Tue Mar 3 13:28:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418045 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C733318B8 for ; Tue, 3 Mar 2020 13:30:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A72B22166E for ; Tue, 3 Mar 2020 13:30:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="vLyGIpi8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727862AbgCCNa4 (ORCPT ); Tue, 3 Mar 2020 08:30:56 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:61783 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729248AbgCCNa4 (ORCPT ); Tue, 3 Mar 2020 08:30:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242256; x=1614778256; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JNPVRg0IXhKYsKVgVhd2+6miS3vS/5AexheE4GJwtE0=; b=vLyGIpi8Q3XL5TKo2lSMWpfDwb5ZYBf4vX2NsDVAjs2U9/CNISyxf4o9 GI8aHnZD95/jtCi/b7Ch8FlomXfZcRv33mGVmZiUxvksAiPZPNHfaHeu4 3nFYa1ooQjsmHYAbH1R4BIpQOppYNB/IwRlPO0aqflFI3oojTEOBUGz4U g=; IronPort-SDR: jVg/e8oI4DlucrkV6r/lIpmtz56apX5RpLNM1aN8MgrRlvxPI1rCcCA/GZy6pyMkW/AlaA27pO sZuNxmc698gA== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="30249779" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-4e24fd92.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 03 Mar 2020 13:30:55 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-4e24fd92.us-west-2.amazon.com (Postfix) with ESMTPS id 39E60A2E10; Tue, 3 Mar 2020 13:30:54 +0000 (UTC) Received: from EX13D12EUC001.ant.amazon.com (10.43.164.45) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:27 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUC001.ant.amazon.com (10.43.164.45) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:25 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:23 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 11/17] PCI: Refactor pci_dev_wait to remove timeout parameter Date: Tue, 3 Mar 2020 14:28:46 +0100 Message-ID: <20200303132852.13184-12-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov Currently, all callers supply the same value, and in the future pci_dev_wait itself could determine the appropriate timeout based on values stored in struct pci_dev, and the reset type. Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7e08c5f38190..9435e2b19f7b 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1030,8 +1030,9 @@ void pci_wakeup_bus(struct pci_bus *bus) pci_walk_bus(bus, pci_wakeup, NULL); } -static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout) +static int pci_dev_wait(struct pci_dev *dev, char *reset_type) { + int timeout = PCIE_RESET_READY_POLL_MS; int delay = 1; u32 id; @@ -4514,7 +4515,7 @@ int pcie_flr(struct pci_dev *dev) msleep(dev->delay[PCI_INIT_EVENT_FLR]); - return pci_dev_wait(dev, "FLR", PCIE_RESET_READY_POLL_MS); + return pci_dev_wait(dev, "FLR"); } EXPORT_SYMBOL_GPL(pcie_flr); @@ -4553,7 +4554,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe) msleep(dev->delay[PCI_INIT_EVENT_FLR]); - return pci_dev_wait(dev, "AF_FLR", PCIE_RESET_READY_POLL_MS); + return pci_dev_wait(dev, "AF_FLR"); } /** @@ -4600,7 +4601,7 @@ static int pci_pm_reset(struct pci_dev *dev, int probe) pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr); pci_dev_d3_sleep(dev); - return pci_dev_wait(dev, "PM D3hot->D0", PCIE_RESET_READY_POLL_MS); + return pci_dev_wait(dev, "PM D3hot->D0"); } /** @@ -4842,7 +4843,7 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev) { pcibios_reset_secondary_bus(dev); - return pci_dev_wait(dev, "bus reset", PCIE_RESET_READY_POLL_MS); + return pci_dev_wait(dev, "bus reset"); } EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset); From patchwork Tue Mar 3 13:28:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418055 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D2C1B924 for ; Tue, 3 Mar 2020 13:31:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B387B20CC7 for ; Tue, 3 Mar 2020 13:31:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="P2FGXDZE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729425AbgCCNbF (ORCPT ); Tue, 3 Mar 2020 08:31:05 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:31533 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728976AbgCCNbF (ORCPT ); Tue, 3 Mar 2020 08:31:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242264; x=1614778264; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=boi/zS9lyKDU1FKDZKAWPh9nzOZgJ/80+f/6R2sG+NE=; b=P2FGXDZED0ac5+03mV3JTTGOiucIaekkaCQVxJblm7ZLRw1GKR8vFQq9 rfdLWDImAG6cChUEqqM8pqlGKYpF8XPDfM9nN5nZx8pe10eoJXqxsZJIv +SuCue7ehkrdaHfJk6es99jUqtBvzBc0CGIffh7OEIs1tMax4D0u6zeoE 0=; IronPort-SDR: jrV2DrcuNPLZWeYiENljQ7/td2WFpkEfdAeSmx0K6UisKqnzFBQSVTx2luIYTaoMqWMiYw5rwl HfrSh1IV1zmA== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="20496345" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-baacba05.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 03 Mar 2020 13:30:57 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-baacba05.us-west-2.amazon.com (Postfix) with ESMTPS id B58C3A18F5; Tue, 3 Mar 2020 13:30:55 +0000 (UTC) Received: from EX13D04EUB004.ant.amazon.com (10.43.166.59) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:29 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D04EUB004.ant.amazon.com (10.43.166.59) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:28 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:25 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 12/17] PCI: Refactor pci_dev_wait to take pci_init_event Date: Tue, 3 Mar 2020 14:28:47 +0100 Message-ID: <20200303132852.13184-13-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov Knowing what kind of event knocked the device out could be useful not only for log output, but also to use different timeout/waiting behavior. Note: we do lose some specificity in log output due to the aliasing of FLR and AF_FLR, but it is doubtful the distinction is worthwhile. Also, "bus reset" does not exactly match the more generic name for PCI_INIT_EVENT_RESET, which could break programs that scrape kernel output for overly specific patterns. Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 9435e2b19f7b..5d62d4841d68 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1030,8 +1030,9 @@ void pci_wakeup_bus(struct pci_bus *bus) pci_walk_bus(bus, pci_wakeup, NULL); } -static int pci_dev_wait(struct pci_dev *dev, char *reset_type) +static int pci_dev_wait(struct pci_dev *dev, enum pci_init_event event) { + const char *event_name = pci_init_event_name(event); int timeout = PCIE_RESET_READY_POLL_MS; int delay = 1; u32 id; @@ -1052,13 +1053,13 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type) while (id == ~0) { if (delay > timeout) { pci_warn(dev, "not ready %dms after %s; giving up\n", - delay - 1, reset_type); + delay - 1, event_name); return -ETIMEDOUT; } if (delay > 1000) pci_info(dev, "not ready %dms after %s; waiting\n", - delay - 1, reset_type); + delay - 1, event_name); msleep(delay); delay *= 2; @@ -1067,7 +1068,7 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type) if (delay > 1000) pci_info(dev, "ready %dms after %s\n", delay - 1, - reset_type); + event_name); return 0; } @@ -4515,7 +4516,7 @@ int pcie_flr(struct pci_dev *dev) msleep(dev->delay[PCI_INIT_EVENT_FLR]); - return pci_dev_wait(dev, "FLR"); + return pci_dev_wait(dev, PCI_INIT_EVENT_FLR); } EXPORT_SYMBOL_GPL(pcie_flr); @@ -4554,7 +4555,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe) msleep(dev->delay[PCI_INIT_EVENT_FLR]); - return pci_dev_wait(dev, "AF_FLR"); + return pci_dev_wait(dev, PCI_INIT_EVENT_FLR); } /** @@ -4601,7 +4602,7 @@ static int pci_pm_reset(struct pci_dev *dev, int probe) pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr); pci_dev_d3_sleep(dev); - return pci_dev_wait(dev, "PM D3hot->D0"); + return pci_dev_wait(dev, PCI_INIT_EVENT_D3HOT_TO_D0); } /** @@ -4843,7 +4844,7 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev) { pcibios_reset_secondary_bus(dev); - return pci_dev_wait(dev, "bus reset"); + return pci_dev_wait(dev, PCI_INIT_EVENT_RESET); } EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset); From patchwork Tue Mar 3 13:28:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DFC1924 for ; Tue, 3 Mar 2020 13:31:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2E6B120842 for ; Tue, 3 Mar 2020 13:31:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="iJItasEo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729068AbgCCNbB (ORCPT ); Tue, 3 Mar 2020 08:31:01 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:35902 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729248AbgCCNbB (ORCPT ); Tue, 3 Mar 2020 08:31:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242260; x=1614778260; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zo+xgKja6kmPxHfkNHFXpC45vKnXxIgJgU/su5JdReI=; b=iJItasEo8mWdwMJOJTxEE+qFmXdKSxn+m7IKVQwixjyN4QVh8i7wNV8e Onag4eCv3Op8khUPMFiu8T2HO61bXAlcAWmPmIq7xsKsHFY60HABLgdxJ sjzmV2Ggu3nlHeebNL58k86TkO6h14qIdoXQo4tS7284X+NymKuJdLur3 Y=; IronPort-SDR: 20iqOC4jwvUhe9AChWG7nY6tjhxgZd/f5FFOXXqf2Nm+sVXTWaytkmG3c72mP0SOTqHiXu9N3F MX+BuA8zLgrw== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="20718008" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-81e76b79.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 03 Mar 2020 13:30:58 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-81e76b79.us-west-2.amazon.com (Postfix) with ESMTPS id 6BB0FA1FAE; Tue, 3 Mar 2020 13:30:57 +0000 (UTC) Received: from EX13D04EUA003.ant.amazon.com (10.43.165.148) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:32 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D04EUA003.ant.amazon.com (10.43.165.148) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:31 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:28 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 13/17] PCI: Cache CRS Software Visibiliy in struct pci_dev Date: Tue, 3 Mar 2020 14:28:48 +0100 Message-ID: <20200303132852.13184-14-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov Arguably, since CRS SV is a capability of Root Ports and determines how Root Ports will handle incoming CRS Completions, it makes more sense to store this flag in the struct pci bus that represents the port's secondary bus, and to cache it in any buses further down the hierarchy. However, storing the flag in struct pci_dev allows individual devices to be marked as not supporting CRS properly even when CRS SV is enabled on their parent Root Port. This way, future code that relies on the new flag will not be misled that it is safe to probe a device by relying on CRS SV to not cause platform timeouts (See the note on CRS SV on p. 553 of PCI Express Base Specification r5.0 from May 22, 2019). Note: Endpoints integrated into the Root Complex (RCiEP) may also be capable of using CRS. In that case, the software visibility is controlled using a Root Complex Register Block (RCRB). This is currently not supported by the kernel. The code introduced here would simply not set the newly introduced flag for RCiEP as for those bus->self is NULL. Signed-off-by: Stanislav Spassov --- drivers/pci/probe.c | 8 +++++++- include/linux/pci.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 512cb4312ddd..eeff8a07f330 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1080,9 +1080,11 @@ static void pci_enable_crs(struct pci_dev *pdev) /* Enable CRS Software Visibility if supported */ pcie_capability_read_word(pdev, PCI_EXP_RTCAP, &root_cap); - if (root_cap & PCI_EXP_RTCAP_CRSVIS) + if (root_cap & PCI_EXP_RTCAP_CRSVIS) { pcie_capability_set_word(pdev, PCI_EXP_RTCTL, PCI_EXP_RTCTL_CRSSVE); + pdev->crssv_enabled = true; + } } static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, @@ -2414,6 +2416,10 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) list_add_tail(&dev->bus_list, &bus->devices); up_write(&pci_bus_sem); + /* Propagate CRS Software Visibility bit from the parent bridge */ + if (bus->self) + dev->crssv_enabled = bus->self->crssv_enabled; + ret = pcibios_add_device(dev); WARN_ON(ret < 0); diff --git a/include/linux/pci.h b/include/linux/pci.h index 16dbfff2092e..1763e98625b9 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -386,6 +386,9 @@ struct pci_dev { bit manually */ unsigned int ignore_reset_delay_on_sx_resume:1; /* Cached value from pci_host_bridge */ + unsigned int crssv_enabled:1; /* Configuration Request Retry + Status Software Visibility + enabled on (parent) bridge */ unsigned int delay[PCI_INIT_EVENT_COUNT]; /* minimum waiting time after various events in ms */ From patchwork Tue Mar 3 13:28:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418059 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4090514B7 for ; Tue, 3 Mar 2020 13:31:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 20E3920873 for ; Tue, 3 Mar 2020 13:31:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Cyg+/LWT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729432AbgCCNbG (ORCPT ); Tue, 3 Mar 2020 08:31:06 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:31533 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729248AbgCCNbG (ORCPT ); Tue, 3 Mar 2020 08:31:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242266; x=1614778266; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KTszniR1B8GtjTWJyYnBLjmuCmS7g4iBL/oem8tvWpM=; b=Cyg+/LWTlyj5KQi3zGnSJhDavgEYf9XZd/zoAKBHJIVooL2m5JEm90e8 Inqt6ihKWRxjsRnu8EOpE7CVmBUxRKtN4SCiY5EPEO9FHq2vLxhXBnS3h 16xZvQ3K/HMTNJjBP1H3HvZxQ1PfLM+FdmlnoUIlw9dFSmQYmQa9QHRU1 4=; IronPort-SDR: iS4ibjMdT1pjGJAt6zmzGDbztuJJpl2ESA6Q2gfiT559hxsCjQ56JwpiDh/gzYpd5gISU6U6BY /zATVOTrRXNA== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="20496350" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-81e76b79.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 03 Mar 2020 13:30:59 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-81e76b79.us-west-2.amazon.com (Postfix) with ESMTPS id 1D8C1A17D1; Tue, 3 Mar 2020 13:30:58 +0000 (UTC) Received: from EX13D12EUA001.ant.amazon.com (10.43.165.48) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:34 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUA001.ant.amazon.com (10.43.165.48) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:33 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:31 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 14/17] PCI: Introduce per-device reset_ready_poll override Date: Tue, 3 Mar 2020 14:28:49 +0100 Message-ID: <20200303132852.13184-15-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov A broken device may never become responsive after reset, hence the need for a timeout. However, waiting for too long can have unintended side effects such as triggering hung task timeouts for processes waiting on a lock held during the reset. Locks that are shared across multiple devices, such as VFIO's per-bus reflck, are especially problematic, because a single broken VF can cause hangs for processes working with other VFs on the same bus. To allow lowering the global default post-reset timeout, while still accommodating devices that require more time, this patch introduces a per-device override that can be configured via a quirk. Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 5 +---- drivers/pci/pci.h | 3 +++ drivers/pci/probe.c | 2 ++ include/linux/pci.h | 3 +++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 5d62d4841d68..e81fd3b53bd0 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -157,9 +157,6 @@ static int __init pcie_port_pm_setup(char *str) } __setup("pcie_port_pm=", pcie_port_pm_setup); -/* Time to wait after a reset for device to become responsive */ -#define PCIE_RESET_READY_POLL_MS 60000 - /** * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children * @bus: pointer to PCI bus structure to search @@ -1033,7 +1030,7 @@ void pci_wakeup_bus(struct pci_bus *bus) static int pci_dev_wait(struct pci_dev *dev, enum pci_init_event event) { const char *event_name = pci_init_event_name(event); - int timeout = PCIE_RESET_READY_POLL_MS; + int timeout = dev->reset_ready_poll_ms; int delay = 1; u32 id; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 9b5dd6ea2f52..d8043d4dbe2f 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -113,6 +113,9 @@ int pci_bus_error_reset(struct pci_dev *dev); /* D0/D1->D2 and D2->D0 delay */ #define PCI_PM_D2_DELAY 200 +/* Time to wait after a reset for device to become responsive */ +#define PCIE_RESET_READY_POLL_MS 60000 + /** * struct pci_platform_pm_ops - Firmware PM callbacks * diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index eeff8a07f330..50b7219406ed 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2168,6 +2168,8 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus) if (!dev) return NULL; + dev->reset_ready_poll_ms = PCIE_RESET_READY_POLL_MS; + INIT_LIST_HEAD(&dev->bus_list); dev->dev.type = &pci_dev_type; dev->bus = pci_bus_get(bus); diff --git a/include/linux/pci.h b/include/linux/pci.h index 1763e98625b9..978ede89741e 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -392,6 +392,9 @@ struct pci_dev { unsigned int delay[PCI_INIT_EVENT_COUNT]; /* minimum waiting time after various events in ms */ + unsigned int reset_ready_poll_ms; /* Timeout for polling after + reset before the device is + deemed broken. */ #ifdef CONFIG_PCIEASPM struct pcie_link_state *link_state; /* ASPM link state */ From patchwork Tue Mar 3 13:28:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418063 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB6E81820 for ; Tue, 3 Mar 2020 13:31:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB6F6215A4 for ; Tue, 3 Mar 2020 13:31:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Zd7OCKNg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729248AbgCCNbH (ORCPT ); Tue, 3 Mar 2020 08:31:07 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:31561 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728976AbgCCNbG (ORCPT ); Tue, 3 Mar 2020 08:31:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242266; x=1614778266; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j4m+zq3gvOi1+9w1LAeWgb10VdG3HMJ9oTkeRMpYQqM=; b=Zd7OCKNgGyFMB7kRyrlfKSZfVSZAsEInkHgsYUgCpo62tYZj6o0q/XzJ mlJFG9AyyL7yD78I4W6J09za5WAogQbmZbWJAieVYXC8UGVwfB7mzYqDp mrwwGZt81VI59opay6ETaSyrYepEe/fkbjGpKqmnR1CEoHQqSgFPT2SH5 E=; IronPort-SDR: Dc1bk1pyjzKQGu6X0PdY6Fk7iS1GxR3Pu664xP/NBSQFYBZjfN9oJx2FfeMV0EgRZL0SFn6HHr Wt+WE3UiseYw== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="20496357" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-81e76b79.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 03 Mar 2020 13:31:01 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-81e76b79.us-west-2.amazon.com (Postfix) with ESMTPS id EAAAAA18EA; Tue, 3 Mar 2020 13:30:59 +0000 (UTC) Received: from EX13D12EUC001.ant.amazon.com (10.43.164.45) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:37 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUC001.ant.amazon.com (10.43.164.45) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:35 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:33 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 15/17] PCI: Refactor polling loop out of pci_dev_wait Date: Tue, 3 Mar 2020 14:28:50 +0100 Message-ID: <20200303132852.13184-16-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov This patch does not (intentionally) introduce any observable difference in runtime behavior. Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 71 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e81fd3b53bd0..f1ba931b0ead 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1027,27 +1027,28 @@ void pci_wakeup_bus(struct pci_bus *bus) pci_walk_bus(bus, pci_wakeup, NULL); } -static int pci_dev_wait(struct pci_dev *dev, enum pci_init_event event) +/* + * Performs DWORD Configuration Reads at a specific offset until the value read + * (with mask applied) is not equal to bad_value. + */ +static inline int pci_dev_poll_until_not_equal(struct pci_dev *dev, int where, + u32 mask, u32 bad_value, + const char *event_name, + int timeout, int *waited, + u32 *final_value) { - const char *event_name = pci_init_event_name(event); - int timeout = dev->reset_ready_poll_ms; int delay = 1; - u32 id; + u32 value; - /* - * After reset, the device should not silently discard config - * requests, but it may still indicate that it needs more time by - * responding to them with CRS completions. The Root Port will - * generally synthesize ~0 data to complete the read (except when - * CRS SV is enabled and the read was for the Vendor ID; in that - * case it synthesizes 0x0001 data). - * - * Wait for the device to return a non-CRS completion. Read the - * Command register instead of Vendor ID so we don't have to - * contend with the CRS SV value. - */ - pci_read_config_dword(dev, PCI_COMMAND, &id); - while (id == ~0) { + if (!event_name) + event_name = ""; + + if (waited) + delay = *waited + 1; + + pci_read_config_dword(dev, where, &value); + + while ((value & mask) == bad_value) { if (delay > timeout) { pci_warn(dev, "not ready %dms after %s; giving up\n", delay - 1, event_name); @@ -1060,16 +1061,44 @@ static int pci_dev_wait(struct pci_dev *dev, enum pci_init_event event) msleep(delay); delay *= 2; - pci_read_config_dword(dev, PCI_COMMAND, &id); + + pci_read_config_dword(dev, where, &value); } if (delay > 1000) - pci_info(dev, "ready %dms after %s\n", delay - 1, - event_name); + pci_info(dev, "ready %dms after %s\n", delay - 1, event_name); + + if (waited) + *waited = delay - 1; + + if (final_value) + *final_value = value; return 0; } +static int pci_dev_wait(struct pci_dev *dev, enum pci_init_event event) +{ + const char *event_name = pci_init_event_name(event); + int timeout = dev->reset_ready_poll_ms; + + /* + * After reset, the device should not silently discard config + * requests, but it may still indicate that it needs more time by + * responding to them with CRS completions. The Root Port will + * generally synthesize ~0 data to complete the read (except when + * CRS SV is enabled and the read was for the Vendor ID; in that + * case it synthesizes 0x0001 data). + * + * Wait for the device to return a non-CRS completion. Read the + * Command register instead of Vendor ID so we don't have to + * contend with the CRS SV value. + */ + return pci_dev_poll_until_not_equal(dev, PCI_COMMAND, ~0, ~0, + event_name, timeout, NULL, + NULL); +} + /** * pci_power_up - Put the given device into D0 * @dev: PCI device to power up From patchwork Tue Mar 3 13:28:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418067 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E9FF924 for ; Tue, 3 Mar 2020 13:31:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 75B2120866 for ; Tue, 3 Mar 2020 13:31:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="CDglZWsU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729436AbgCCNbH (ORCPT ); Tue, 3 Mar 2020 08:31:07 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:35902 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728661AbgCCNbH (ORCPT ); Tue, 3 Mar 2020 08:31:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242266; x=1614778266; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l0e3JJTqLxOZqhNDS1pf36rN/WmV38VFKlUXk+nl89w=; b=CDglZWsUtSTdOg4/8TJPdnGz4adZoF9M62aro85lkSA0GeKtKnE5RFqF Dbee35FEpH5Ey+yvQQQvO5ARYsQJgLqr1o5ZF04UI2KZsR3igEk9ToOAS Kgg/VBIFSciFOY/KXeiMd5r6PZ70KUI1AHKrFyH5agMq1QKfCMHVEKM2S U=; IronPort-SDR: YLyNGElTUdCgotd3cjqef6Tug0NLgJBtO6qkiCqITQ7GTTXbZiBam6S3lrwNvArSub5qRwUssN G6zju1ivgj7Q== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="20718021" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-69849ee2.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 03 Mar 2020 13:31:05 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-69849ee2.us-west-2.amazon.com (Postfix) with ESMTPS id 68482A3445; Tue, 3 Mar 2020 13:31:01 +0000 (UTC) Received: from EX13D12EUA001.ant.amazon.com (10.43.165.48) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:40 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D12EUA001.ant.amazon.com (10.43.165.48) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:38 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:36 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 16/17] PCI: Add CRS handling to pci_dev_wait() Date: Tue, 3 Mar 2020 14:28:51 +0100 Message-ID: <20200303132852.13184-17-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov The PCI Express specification dictates minimal amounts of time that the host needs to wait after triggering different kinds of resets before it is allowed to attempt accessing the device. After this waiting period, devices are required to be responsive to Configuration Space reads. However, if a device needs more time to actually complete the reset operation internally, it may respond to the read with a Completion Request Retry Status (CRS), and keep doing so on subsequent reads for as long as necessary. If the device is broken, it may even keep responding with CRS indefinitely. The specification also mandates that any Root Port that supports CRS and has CRS Software Visibility (CRS SV) enabled will synthesize the special value 0x0001 for the Vendor ID and set any other bits to 1 upon receiving a CRS Completion for a Configuration Read Request that includes both bytes of the Vendor ID (offset 0). IF CRS is supported by Root Port but CRS SV is not enabled, the request is retried autonomously by the Root Port. Platform-specific configuration registers may exist to limit the number of or time taken by such retries. If CRS is not supported, or a different register (not Vendor ID) is polled, or the device is responding with CA/UR Completions (rather than CRS), the behavior is platform-dependent, but generally the Root Port synthesizes ~0 to complete the software read. Previously, pci_dev_wait() avoided taking advantage of CRS. However, on platforms where no limit/timeout can be configured as explained above, a device responding with CRS for too long (e.g. because it is stuck and cannot complete its reset) may trigger more severe error conditions (e.g. TOR timeout, 3-strike CPU CATERR), because the Root Port never reports back to the lower-level component requesting the transaction. This patch introduces special handling when CRS is available, and otherwise falls back to the previous behavior of polling COMMAND. Signed-off-by: Stanislav Spassov --- drivers/pci/pci.c | 52 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index f1ba931b0ead..1a504419e0de 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1081,18 +1081,54 @@ static int pci_dev_wait(struct pci_dev *dev, enum pci_init_event event) { const char *event_name = pci_init_event_name(event); int timeout = dev->reset_ready_poll_ms; + int waited = 0; + int rc = 0; + /* * After reset, the device should not silently discard config * requests, but it may still indicate that it needs more time by - * responding to them with CRS completions. The Root Port will - * generally synthesize ~0 data to complete the read (except when - * CRS SV is enabled and the read was for the Vendor ID; in that - * case it synthesizes 0x0001 data). - * - * Wait for the device to return a non-CRS completion. Read the - * Command register instead of Vendor ID so we don't have to - * contend with the CRS SV value. + * responding to them with CRS completions. For such completions: + * - If CRS SV is enabled on the Root Port, and the read request + * covers both bytes of the Vendor ID register, the Root Port + * will synthesize the value 0x0001 (and set any extra requested + * bytes to 0xff) + * - If CRS SV is not enabled on the Root Port, the Root Port must + * re-issue the Configuration Request as a new Request. + * Depending on platform-specific Root Complex configurations, + * the Root Port may stop retrying after a set number of attempts, + * or a configured timeout is hit, or continue indefinitely + * (ultimately resulting in non-PCI-specific platform errors, such as + * a TOR timeout). + */ + if (dev->crssv_enabled) { + u32 id; + + rc = pci_dev_poll_until_not_equal(dev, PCI_VENDOR_ID, 0xffff, + 0x0001, event_name, timeout, + &waited, &id); + if (rc) + return rc; + + /* + * If Vendor/Device ID is valid, the device must be ready. + * Note: SR-IOV VFs return ~0 for reads to Vendor/Device + * ID and will not be recognized as ready by this check. + */ + if (id != 0x0000ffff && id != 0xffff0000 && + id != 0x00000000 && id != 0xffffffff) + return 0; + } + + /* + * Root Ports will generally indicate error scenarios (e.g. + * internal timeouts, or received Completion with CA/UR) by + * synthesizing an 'all bits set' value (~0). + * In case CRS is not supported/enabled, as well as for SR-IOV VFs, + * fall back to polling a different register that cannot validly + * contain ~0. As of PCIe 5.0, bits 11-15 of COMMAND are still RsvdP + * and must return 0 when read. + * XXX: These bits might become meaningful in the future */ return pci_dev_poll_until_not_equal(dev, PCI_COMMAND, ~0, ~0, event_name, timeout, NULL, From patchwork Tue Mar 3 13:28:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Spassov X-Patchwork-Id: 11418069 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C772C1820 for ; Tue, 3 Mar 2020 13:31:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A7BD420842 for ; Tue, 3 Mar 2020 13:31:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="TLmUNrgr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729437AbgCCNbH (ORCPT ); Tue, 3 Mar 2020 08:31:07 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:31533 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729430AbgCCNbH (ORCPT ); Tue, 3 Mar 2020 08:31:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1583242267; x=1614778267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NwisI3KTsm/OiywhsK6dC5HAgpMIY4oSgnpSsD8E7Hk=; b=TLmUNrgrSvTQ8GvkFQtp5HDjfmy+sN1tiNG84DurEcDf4QnxhG9LWqvs kcgQx/XDx2avLQh79eBr/Ta5mATHkgBqg6I7zYuzvErU55/G0/k2bkeMl /OpbCu3Dz3abhXCvne0ITUGoY3WQImyGfFsZmLMSASHHDtQNUXg5m11Za A=; IronPort-SDR: Y0/7gX+4Lclg7Uo0HvObMxoar77IBMo0iWbtQeW+ZBm9cbbsxI0fFLcDZenZJ16U5zH8TbMB8X hMoiHtCKfzFw== X-IronPort-AV: E=Sophos;i="5.70,511,1574121600"; d="scan'208";a="20496361" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-c5104f52.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 03 Mar 2020 13:31:03 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-c5104f52.us-west-2.amazon.com (Postfix) with ESMTPS id 59758A2BBB; Tue, 3 Mar 2020 13:31:02 +0000 (UTC) Received: from EX13D04EUA002.ant.amazon.com (10.43.165.75) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 3 Mar 2020 13:30:42 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D04EUA002.ant.amazon.com (10.43.165.75) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 3 Mar 2020 13:30:41 +0000 Received: from u961addbe640f56.ant.amazon.com (10.28.84.111) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 3 Mar 2020 13:30:39 +0000 From: Stanislav Spassov To: CC: Stanislav Spassov , , Bjorn Helgaas , Thomas Gleixner , Andrew Morton , =?utf-8?q?Jan_H_=2E_Sch=C3=B6nhe?= =?utf-8?q?rr?= , "Jonathan Corbet" , Ashok Raj , Alex Williamson , Sinan Kaya , Rajat Jain , kbuild test robot Subject: [PATCH v3 17/17] PCI: Lower PCIE_RESET_READY_POLL_MS from 1m to 1s Date: Tue, 3 Mar 2020 14:28:52 +0100 Message-ID: <20200303132852.13184-18-stanspas@amazon.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303132852.13184-1-stanspas@amazon.com> References: <20200303132852.13184-1-stanspas@amazon.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Stanislav Spassov PCI Express Base specification r5.0 (May 22, 2019), sec 6.6.1 mentions on more than one occasion that the appropriate waiting time before deeming a device broken if it is not able to return Successful Completion for valid Configuration Requests is 1 second after a Conventional Reset (which should be the lengthiest of resets). For devices that take longer than 1s to complete initialization, quirks can override the waiting time via the reset_ready_poll_ms field in struct pci_dev. Note: This timeout is used in pci_dev_wait for the polling that happens after we have already waited for the required post-reset times mandated by the spec. All devices are expected to be responsive to Configuration Requests at that point. "Completing initialization" here means that the device is not only responsive, but actually returns Successful Completions rather than CRS Completions (or any other error). Signed-off-by: Stanislav Spassov --- drivers/pci/pci.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index d8043d4dbe2f..1c6722b5c3ee 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -113,8 +113,11 @@ int pci_bus_error_reset(struct pci_dev *dev); /* D0/D1->D2 and D2->D0 delay */ #define PCI_PM_D2_DELAY 200 -/* Time to wait after a reset for device to become responsive */ -#define PCIE_RESET_READY_POLL_MS 60000 +/* + * Time to wait (in addition to the delays above) for a device to start + * returning Successful Completions before OS can deem it broken + */ +#define PCIE_RESET_READY_POLL_MS 1000 /** * struct pci_platform_pm_ops - Firmware PM callbacks