From patchwork Tue Jun 21 08:53:12 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: 9189955 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 56D9560756 for ; Tue, 21 Jun 2016 09:09:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4386C27FB7 for ; Tue, 21 Jun 2016 09:09:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 386BA27FC0; Tue, 21 Jun 2016 09:09:34 +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=unavailable 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 9A83327FB7 for ; Tue, 21 Jun 2016 09:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751498AbcFUJJ2 (ORCPT ); Tue, 21 Jun 2016 05:09:28 -0400 Received: from mail-bn1bon0087.outbound.protection.outlook.com ([157.56.111.87]:52747 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751139AbcFUJJD (ORCPT ); Tue, 21 Jun 2016 05:09:03 -0400 X-Greylist: delayed 882 seconds by postgrey-1.27 at vger.kernel.org; Tue, 21 Jun 2016 05:09:03 EDT 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=skfTg+tgzeD22BMbWdoGQe2WQVpCKaAA+toL3Wd7mq8=; b=i52EcUEUfOaJr5g+WHCaJ3kKz1fy9Q/hIlrPgLiok6FLoXB1tw/LZMmukr6H/9QN9jVY87g3lHMDcFxpKHwOKkQG9G5XWmsgWrC4kon/Hi4Y35FinoFt4l7kVtmB7t8S6L8Aij6g1xU17YIHYgZ194DJDFDk7qJFbMqOHEJDLKg= Received: from BN3PR0301CA0044.namprd03.prod.outlook.com (10.160.152.140) by DM2PR0301MB0877.namprd03.prod.outlook.com (10.160.216.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.511.8; Tue, 21 Jun 2016 08:53:25 +0000 Received: from BY2FFO11FD043.protection.gbl (2a01:111:f400:7c0c::126) by BN3PR0301CA0044.outlook.office365.com (2a01:111:e400:401e::12) 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:24 +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 BY2FFO11FD043.mail.protection.outlook.com (10.1.14.228) with Microsoft SMTP Server (TLS) id 15.1.517.7 via Frontend Transport; Tue, 21 Jun 2016 08:53:24 +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:05 -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 u5L8rIcN026179; Tue, 21 Jun 2016 01:53:19 -0700 (PDT) Received: by ubuntu (sSMTP sendmail emulation); Tue, 21 Jun 2016 16:53:18 +0800 From: Ley Foon Tan To: Bjorn Helgaas CC: , , Ley Foon Tan , Ley Foon Tan Subject: [PATCH 1/2] PCI: altera: check link status before retrain link Date: Tue, 21 Jun 2016 16:53:12 +0800 Message-ID: <1466499193-1987-2-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)(189002)(199003)(5003940100001)(4001430100002)(36756003)(87936001)(229853001)(19580395003)(33646002)(42186005)(6806005)(586003)(97736004)(50226002)(110136002)(81166006)(81156014)(107886002)(2950100001)(19580405001)(189998001)(50986999)(8676002)(50466002)(47776003)(92566002)(68736007)(356003)(86362001)(11100500001)(8936002)(7846002)(48376002)(105596002)(76176999)(106466001)(4326007)(2906002)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0877; H:sj-itexedge03.altera.priv.altera.com; FPR:; SPF:SoftFail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD043; 1:SV8uTISlk2RNKVNeAt6/mqBZwC0RJRAlBqPFtEwKzeN/mbkDxjpR6VHV9su7Gs/GHPJS/1tpLAEX+SRVzpEzJXQQgIEIfhKQkt8uK8OEMkKWJw2My4CB5rUwpL8gj1Xa8CuNSg389jhQtqTW3A/VO8Eyd/2ogusze0+zuLp62K2mBEIwGe7RrPr5hSGfDFu7KPJHITML1LbELmUSRfVk6qwOktV1qIBUtAgMY18ntJ/NMHcN4sI1czlhJ5Ku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XOPd8ns1nhOISCqTXAjM8bZIhq7uDam2cAJGcqwOMl8Gh+eMXD0gwflpESIA8ZPmwtht3bkUFIgjS3vLclrUSj4NwmrYOGSKw71DGK4wqepk2D9LAbXehAyKi0Nvp6X/WFIvXCuXzw+SSfhbwzx0VXBjC1vSN9sL6M= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0877; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0877; 20:/OrRam9WW3/diC+TTUYQCW1cpJjTcxbPaEqv4NsYTYXJTKoOCQS0LXuM88KxHEzbt+Wwcj2ul9daMN2ezHBNG4az5Gs9+T8TX4CYet/CA/B5ybt+p9W/gKHF3sonLnOUHEuvHQ49jLtJPktTru61Q6OXz2a2sfda7P8FMS8JJR4=; 4:WIFOVDY2hPKHpxsLA2gSpsFjyoBNbueSoZd9BNnVe7wFFLNNBmNun7e2JsTIep20tSOhW1GmTe1s2q65ComOMKPDz0YGp5DLnuBAFAlzuwWaHqgFW7CsGJvDYFdAUCmGx76fhvDFDcSCuFhOyk5ZwV7Se5+EqhXzZaJTJWQv7wnwJTioKKBllR1C3O9vOgIRWGjrYXO9FZNIXAOjJqV6q3XUy68/Vm87ipoYvx8xZG1ecsjuv9lvqTHj91LZHRat0wpf1EwbZQcukbDTosswvWucxlGQTXWnC97hSmdNye0t2BpervczCIwEmFq15gR/Jif2zis2dXUk6Hl2j6kciPDgQ3L7EIxgniVxmIcgHRGm2NZ3J9jbw/8GRPVr7XzThbCz/hJ3EF3htDxKEPGWSIUX4qC3HmXIWVAqPmaSJ7++FZvzKE6oM0ewrluRdrdu+5BmsUqZL5vZ0wfubOwf1B5S5tHPTtGZ9/mcxTH5oPp80jLJavp8nKlmwX8g5fKoTnSNarOzemwbPKYsJ/RDIA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(80048183373757); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13017025)(13023025)(5005006)(13024025)(13018025)(13015025)(8121501046)(10201501046)(3002001)(6055026); SRVR:DM2PR0301MB0877; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB0877; X-Forefront-PRVS: 098076C36C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB0877; 23:uTXCs2/fIIUBJWNGKl3aLSKknpdZkJ3IGN28d1A?= =?us-ascii?Q?tGo5HSr3PXIjETTTycKdM9LzzFO/SwXpRXeoyUSuoXZLdCvtWKWE3LFhvGWz?= =?us-ascii?Q?qen8+lHzhFBs2wgkBEqrSBO3FTiOmT5WAxFWUAuuU2VuW0SOJLmKZLiKCl57?= =?us-ascii?Q?w1UQ1OjeBEvMfvra4WZEWfQAeWzjGKrz6dOGOfCYxkLquubBBawuaBsMM+Gr?= =?us-ascii?Q?dZsvvvsIDQ4FMx2Pz4wrDGFuW7xl+sJhEaIjp0ybfTh7qnBzkvqXgDTZsE6L?= =?us-ascii?Q?jZyJzZ8/55Gwk7F4pr8okcW4u4goaPBvc2YQo7s013UBGEyBRt64DZ8sb9cs?= =?us-ascii?Q?yIZjOQ6Nh39OyyHQhFK2P9wPa8pyW+1Z5LfBTRlnnX5wydiLTiKhlATnkHvx?= =?us-ascii?Q?x5lIXSTQ6GQd4R/4I5N+8cHyxb0QxbItfTNV7ZKXA0bTFz3SRgZjRY2xHjKL?= =?us-ascii?Q?yP+YbK/Gal5NpTvJIjexiJsq0HhMP8Y1I7d8DQGwr1M3u7TfPxqBmH8ul78y?= =?us-ascii?Q?CT04ZTlaO1Afrim/ce/plbRPq4HShINndXGXwQeXDMEOCEikhD9dnY+94gp8?= =?us-ascii?Q?UgBRw3yQzN3UNTV3s/p2XJjOYgVxQGC73Z/CwyzkVIh2WDLEIHqhNfBBUqAp?= =?us-ascii?Q?aPckir4KAZ71kQQTkKBdvv9jhpglzbLkz9yIrYWTMuNA2Y+/SKDxrarKBwrt?= =?us-ascii?Q?UIEuK1IqKGmlST8JimoS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t8QAPkaTcBoc6xVqBKyvA656QFfrdXho7DNWUYodRTMCOVD6bgaoIyxtov5sVhduYEVenYAdclf4YcITXasjy3m4LA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: altera.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2016 08:53:24.1003 (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: DM2PR0301MB0877 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 Checking for link up status before retrain link. Note, moves altera_pcie_link_is_up() and its dependency functions to top of file. Signed-off-by: Ley Foon Tan --- drivers/pci/host/pcie-altera.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/pci/host/pcie-altera.c b/drivers/pci/host/pcie-altera.c index dbac6fb..78f77e1 100644 --- a/drivers/pci/host/pcie-altera.c +++ b/drivers/pci/host/pcie-altera.c @@ -81,9 +81,29 @@ struct tlp_rp_regpair_t { u32 reg1; }; +static inline void cra_writel(struct altera_pcie *pcie, const u32 value, + const u32 reg) +{ + writel_relaxed(value, pcie->cra_base + reg); +} + +static inline u32 cra_readl(struct altera_pcie *pcie, const u32 reg) +{ + return readl_relaxed(pcie->cra_base + reg); +} + +static bool altera_pcie_link_is_up(struct altera_pcie *pcie) +{ + return !!((cra_readl(pcie, RP_LTSSM) & RP_LTSSM_MASK) == LTSSM_L0); +} + static void altera_pcie_retrain(struct pci_dev *dev) { u16 linkcap, linkstat; + struct altera_pcie *pcie = dev->bus->sysdata; + + if(!altera_pcie_link_is_up(pcie)) + return; /* * Set the retrain bit if the PCIe rootport support > 2.5GB/s, but @@ -120,17 +140,6 @@ static bool altera_pcie_hide_rc_bar(struct pci_bus *bus, unsigned int devfn, return false; } -static inline void cra_writel(struct altera_pcie *pcie, const u32 value, - const u32 reg) -{ - writel_relaxed(value, pcie->cra_base + reg); -} - -static inline u32 cra_readl(struct altera_pcie *pcie, const u32 reg) -{ - return readl_relaxed(pcie->cra_base + reg); -} - static void tlp_write_tx(struct altera_pcie *pcie, struct tlp_rp_regpair_t *tlp_rp_regdata) { @@ -139,11 +148,6 @@ static void tlp_write_tx(struct altera_pcie *pcie, cra_writel(pcie, tlp_rp_regdata->ctrl, RP_TX_CNTRL); } -static bool altera_pcie_link_is_up(struct altera_pcie *pcie) -{ - return !!((cra_readl(pcie, RP_LTSSM) & RP_LTSSM_MASK) == LTSSM_L0); -} - static bool altera_pcie_valid_config(struct altera_pcie *pcie, struct pci_bus *bus, int dev) {