From patchwork Tue Jun 21 08:53:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ley Foon Tan X-Patchwork-Id: 9190045 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 068156075E for ; Tue, 21 Jun 2016 09:28:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8BFA28047 for ; Tue, 21 Jun 2016 09:28:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC40A28066; Tue, 21 Jun 2016 09:28:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 406C028047 for ; Tue, 21 Jun 2016 09:28:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751772AbcFUJ2q (ORCPT ); Tue, 21 Jun 2016 05:28:46 -0400 Received: from mail-bl2on0085.outbound.protection.outlook.com ([65.55.169.85]:49376 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751763AbcFUJ2l (ORCPT ); Tue, 21 Jun 2016 05:28:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=altera.onmicrosoft.com; s=selector1-altera-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Z2/j/ljheiF9VrTkOmm+FsYu68twWL/x3yPNP4QA1Do=; b=AkdYpGX7rQwPy8esK6s261Ay4RP0URWDEnI5p5IyYz1y9S3U7aupxLHOWCI99ySYi0ZkqE6/u9q7IUWN76GSO2S0NahuzfUfYt+d2oRn8WXIP4duPRWZ7Oif0Hu1n1P/3HhixiOm9fi3E+UD8DEtUsvUVa4SdCs7GAETDeC1Nbw= Received: from DM2PR03CA0053.namprd03.prod.outlook.com (10.141.96.52) by BL2PR03MB100.namprd03.prod.outlook.com (10.255.230.25) with Microsoft SMTP Server (TLS) id 15.1.497.12; Tue, 21 Jun 2016 08:53:30 +0000 Received: from BY2FFO11FD017.protection.gbl (2a01:111:f400:7c0c::155) by DM2PR03CA0053.outlook.office365.com (2a01:111:e400:2428::52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12 via Frontend Transport; Tue, 21 Jun 2016 08:53:30 +0000 Authentication-Results: spf=softfail (sender IP is 66.35.236.227) smtp.mailfrom=altera.com; vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=altera.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning altera.com discourages use of 66.35.236.227 as permitted sender) Received: from sj-itexedge03.altera.priv.altera.com (66.35.236.227) by BY2FFO11FD017.mail.protection.outlook.com (10.1.14.105) with Microsoft SMTP Server (TLS) id 15.1.517.7 via Frontend Transport; Tue, 21 Jun 2016 08:53:29 +0000 Received: from sj-mail01.altera.com (137.57.1.6) by webmail.altera.com (66.35.236.227) with Microsoft SMTP Server (TLS) id 14.3.174.1; Tue, 21 Jun 2016 01:53:11 -0700 Received: from ubuntu (pg-lftan-440b.altera.priv.altera.com [137.57.162.7]) by sj-mail01.altera.com (8.13.7+Sun/8.13.7) with SMTP id u5L8rMEd026183; Tue, 21 Jun 2016 01:53:23 -0700 (PDT) Received: by ubuntu (sSMTP sendmail emulation); Tue, 21 Jun 2016 16:53:22 +0800 From: Ley Foon Tan To: Bjorn Helgaas CC: , , Ley Foon Tan , Ley Foon Tan Subject: [PATCH 2/2] PCI: altera: Polling for link up status after retrain the link Date: Tue, 21 Jun 2016 16:53:13 +0800 Message-ID: <1466499193-1987-3-git-send-email-lftan@altera.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466499193-1987-1-git-send-email-lftan@altera.com> References: <1466499193-1987-1-git-send-email-lftan@altera.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:66.35.236.227; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(199003)(189002)(48376002)(76176999)(4001430100002)(50466002)(6806005)(2950100001)(47776003)(4326007)(81156014)(81166006)(8676002)(7846002)(2906002)(50986999)(105596002)(356003)(33646002)(106466001)(68736007)(586003)(87936001)(97736004)(19580395003)(107886002)(189998001)(92566002)(229853001)(5003940100001)(8936002)(42186005)(86362001)(11100500001)(50226002)(110136002)(19580405001)(36756003)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR03MB100; H:sj-itexedge03.altera.priv.altera.com; FPR:; SPF:SoftFail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD017; 1:okh1iqp7QC5qC8RW2feU/ahbDiXKJV4Bg9yd2kU1SORIs2mFRonjUf8v/STmHvBqHjI8DA3fPd0gsnRUYWFSh4QD0TxR+adI1WfW8ZCTZfBLgp1SJmLgaNctLatAyIrYlh/PAaCXkZJVrua5fjx9w66W1A+0/KPy8ss/NAQ7Z6auEYLH+t7EcX1AWOYGbzeEc+V7ick7EUoQBnG5TkaJrvbnXgSA8uhRUu4v6z36dNKZpfKxCXaAAz41RPT2i0hwoLq9fbbkPNuHHCjFVk0xPQwpjL/ZCikc8/+I8zhSPdVEf/VS5z2H2hexaoW9VSBAYhD0SksYvmGhkxv7wSURedmRfxNqg1J4d2LysquUu0HsIJg4P5P5veNQgVVbtpUcme2VB/jbLwL0H+uYnXS9eIlBHR4tyo8h0yGGdvwrmZQlnSWxKdJg4fN11jd/gs4p9t6jKhT6Bl+w9XMBQKWYCG+7hKeI8FQ/+ewYUFprTEymHFS3jc4bHgVqa9zbohHK7MAMfVlj837SS/Z5wdmvnQ== X-MS-Office365-Filtering-Correlation-Id: f631171e-c4ce-491c-fe0d-08d399b18451 X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB100; 2:8k/uM2+iZDo4sTBoN090uqJtEM1pYKioWpASZJdZRoo3fArmgGOL/4wtdu8R4YmSNCazgXUsuk4pLWAAOF1gGxfbbwx4gApkcTaY74abvcqHTpSyxzTpvdFqBSMyzhisLvRem15w4RDsk+KIN65eN+vVqCblhPhq7gq35v+S8NSCasb/RaTV55HtV72bNulj; 3:uaBn6VkR17vWcTNLZVkgCFdlDsGg455Ol4cx9H+QDX89nBUR3xHd6z2/uJtHCbYwF+sR2ByRX1xCZocD7TgNgO56p32ztPvXIbz1VUHdO930D5/0TnZTcEGrOwdAAm4AgoC+Zl+8KuC1+k9aCV5d561qT8t4omTmGdhSx78fogxWDrLkSLPk9pmIpSMW2yczDo+xbaJKo18ZxOF0uCeX/ynyxeK6Il/ZSpnqHe5thac= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB100; X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB100; 25:2bBohAH3pNqAQAKGHP5ncBV33V8e+6NQAEKXw1wnTCZon4ukgz+DiVotI/tMOKQDweqKhhuzIocgcrdfGON45UxtueH17yL72GLHGySggHZgNaIwU5o0nTltyf3qySDxHccuU4RGd2naSd/NcG2M966glY6V94i/FqJkrB1qlO1cQTpUZYb6fLtfWpiWYJTvZ7hblAV8uTZTA0GUmPrL9IjRL53Cteqk2uDR0m3ARTkvh50rz2RnEexkdwBRG3Ie+vnLf6s04HpkGzNK/RjHaRGq6vAm+Qv/LQ/76ELSqdtFT0DUfiNYH+DN82nEcBtfSLAskl+r9qu1ndlJEzmGTOuBbKjnu/RZVSuI8Lsp2TcIOX6cmH3rUgO6VeYBBuin6qpCi4kdpiFGCVijfJTnsGNlj6LlVCPDGlv7Ji7ZrU+rjEAVhugWlE455zvjeZYCqwOuGmeXuvn3n0Rqxzq3e5xz86KzynKefGjrzKT3nkSSDwMgZVxby5sfazWPi8257YZP6WmCthE9XiLpX87jekm4ywH+wOYbB8B4uCwtZZudg4Gpp2KozgvEpsrHG9171YmjEqQE9uHkIhWK9OgfwHDHCEOYByTTN0hFXic/jIfGCC9pQe6FjlKxHLdX6hDGXIud5iXG/D/mvAxcdsXAphGcSdX/rX/xtame9KYz/8l8FPSHvtas0Ri06cNhm9J9WpY0xUhbhzyrAhfGXWmVNgVCKI6md3tOLIOdS5HSx5cC0UPORx0Dl5/M0AqqEf9MLAwoKfZVN9EsLGzdRfUWrw==; 20:bLDGvhH0vNbO/hD+daBFXUOjMvWo/fRo06ABmBEbVAs8wn3vg13ve7hiZI3CVI7JGSZ7ut8SoGGI+lMo3IC1lJOi6xuJMC66UtGeSzjPX50E3upcSjCm0pCWWOaiQdn+jg+4qLyTt3W09p NjPbNV80BSMdx14neAstY6JGooi5o= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(80048183373757); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13018025)(13017025)(13024025)(13023025)(13015025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:BL2PR03MB100; BCL:0; PCL:0; RULEID:; SRVR:BL2PR03MB100; X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB100; 4:TbKTK2KfUUodqQwnTHZbDOeCkHlMX1sktOB4Y3nOqGLR7UerRzS9fMNkX5LUGEtiPAlT66M7Xj6K8Z9MnfbwPL2BwOoC9/ygwrEy+4RsTqP/F6nYLmV5c0PDRITVS6uTln1M1SdHD7y0eiO6KB+DnRio9TPlGztHDVZRRGmrmNa7lL+6U7sHmvtQryr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q6XjIRJUUVIF1bNC6AnpIr9SD1qzNIh9LhH90eRNn1+aQ3qOKI/fuXcgBvngkV56nbbABg5LM4PY4j94yxRKfC72uvCEmyuQLMXxv5UhDL6KxVlMx0VW8bvPVIim+gNm8Q==; 20:Xmi6FURfqZCa86AR9mrqkJ/ufCgjlR8tWtp5JibktnyrrBYReVNeY7qQqyMEyKWVuS6M1z1DnAS+EsclJCKVWOEZ3rlXWsTu1gpx8u8vLWBY+Txu2p4yddagsh/BrjR7WgjYiKzHHvpQSVPH9b5BbuvzIT7CO9B5OI50grZ+OP0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: altera.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2016 08:53:29.5570 (UTC) X-MS-Exchange-CrossTenant-Id: fbd72e03-d4a5-4110-adce-614d51f2077a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fbd72e03-d4a5-4110-adce-614d51f2077a; Ip=[66.35.236.227]; Helo=[sj-itexedge03.altera.priv.altera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB100 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some PCIe devices take longer time to reach link up state after retrain. This patch polling for link up status after retrain the link. This is to make sure the link is stable and up before we access to configuration space registers after this. Signed-off-by: Ley Foon Tan --- drivers/pci/host/pcie-altera.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/pci/host/pcie-altera.c b/drivers/pci/host/pcie-altera.c index 78f77e1..a9de2a0 100644 --- a/drivers/pci/host/pcie-altera.c +++ b/drivers/pci/host/pcie-altera.c @@ -61,6 +61,8 @@ #define TLP_LOOP 500 #define RP_DEVFN 0 +#define LINK_UP_TIMEOUT 5000 + #define INTX_NUM 4 #define DWORD_MASK 3 @@ -101,6 +103,7 @@ static void altera_pcie_retrain(struct pci_dev *dev) { u16 linkcap, linkstat; struct altera_pcie *pcie = dev->bus->sysdata; + int timeout = 0; if(!altera_pcie_link_is_up(pcie)) return; @@ -115,9 +118,16 @@ static void altera_pcie_retrain(struct pci_dev *dev) return; pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &linkstat); - if ((linkstat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB) + if ((linkstat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB) { pcie_capability_set_word(dev, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_RL); + while(!altera_pcie_link_is_up(pcie)) { + timeout++; + if (timeout > LINK_UP_TIMEOUT) + break; + udelay(5); + } + } } DECLARE_PCI_FIXUP_EARLY(0x1172, PCI_ANY_ID, altera_pcie_retrain);