From patchwork Wed Feb 12 07:27:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 3634551 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 874729F369 for ; Wed, 12 Feb 2014 07:28:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D6B920142 for ; Wed, 12 Feb 2014 07:28:56 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F03320123 for ; Wed, 12 Feb 2014 07:28:55 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDUFW-0006KR-EH; Wed, 12 Feb 2014 07:28:50 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDUFU-0008CY-3b; Wed, 12 Feb 2014 07:28:48 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDUFP-0008Bh-9H for linux-arm-kernel@lists.infradead.org; Wed, 12 Feb 2014 07:28:44 +0000 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1WDUEu-0002Y9-HO; Wed, 12 Feb 2014 08:28:12 +0100 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.82) (envelope-from ) id 1WDUEs-00062u-RR; Wed, 12 Feb 2014 08:28:10 +0100 From: Sascha Hauer To: linux-pci@vger.kernel.org Subject: [PATCH] PCI: imx6: Fix link_up detection Date: Wed, 12 Feb 2014 08:27:55 +0100 Message-Id: <1392190075-23204-1-git-send-email-s.hauer@pengutronix.de> X-Mailer: git-send-email 1.8.5.3 X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140212_022843_778767_DFD17641 X-CRM114-Status: GOOD ( 18.56 ) X-Spam-Score: -2.5 (--) Cc: Richard Zhu , Marek Vasut , Sascha Hauer , kernel@pengutronix.de, Bjorn Helgaas , Shawn Guo , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is broken since: | commit e6daf4a5e1b813bc7f85507ec83b8c2452c121e6 | Author: Marek Vasut | Date: Thu Dec 12 22:49:59 2013 +0100 | | PCI: imx6: Report "link up" only after link training completes | | While waiting for the PHY to report the PCIe link is up, we might hit a | situation where the link training is still in progress, while the PHY | already reports the link is up. Add additional check for this condition. | | Signed-off-by: Marek Vasut | Signed-off-by: Bjorn Helgaas | Acked-by: Shawn Guo The problem is: Before the above commit only the PCIE_PHY_DEBUG_R1_XMLH_LINK_UP bit was used to determine whether the link is up or not. Since the above commit also the PCIE_PHY_DEBUG_R1_XMLH_LINK_IN_TRAINING is used. This means a link still being trained is as link down. The designware driver changes the PORT_LOGIC_SPEED_CHANGE bit in dw_pcie_host_init() which causes the link to be retrained. During the next call to dw_pcie_rd_conf() the link is then reported being down and the function returns PCIBIOS_DEVICE_NOT_FOUND resulting in nonfunctioning PCIe. This patch fixes this by waiting until the link training has finished before testing the PCIE_PHY_DEBUG_R1_XMLH_LINK_UP bit. This is hardly the correct solution, but I don't know what should be done instead. Signed-off-by: Sascha Hauer Cc: Richard Zhu (maintainer:PCI DRIVER FOR IMX6) Cc: Shawn Guo (maintainer:PCI DRIVER FOR IMX6) Cc: Bjorn Helgaas (supporter:PCI SUBSYSTEM) Cc: linux-pci@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: Marek Vasut --- drivers/pci/host/pci-imx6.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/pci/host/pci-imx6.c b/drivers/pci/host/pci-imx6.c index 866bdc7..9b6b501 100644 --- a/drivers/pci/host/pci-imx6.c +++ b/drivers/pci/host/pci-imx6.c @@ -449,6 +449,7 @@ static void imx6_pcie_reset_phy(struct pcie_port *pp) static int imx6_pcie_link_up(struct pcie_port *pp) { u32 rc, ltssm, rx_valid; + int count = 1000; /* * Test if the PHY reports that the link is up and also that @@ -458,8 +459,13 @@ static int imx6_pcie_link_up(struct pcie_port *pp) * as well here. */ rc = readl(pp->dbi_base + PCIE_PHY_DEBUG_R1); - if ((rc & PCIE_PHY_DEBUG_R1_XMLH_LINK_UP) && - !(rc & PCIE_PHY_DEBUG_R1_XMLH_LINK_IN_TRAINING)) + while (rc & PCIE_PHY_DEBUG_R1_XMLH_LINK_IN_TRAINING) { + if (!count--) + return 0; + rc = readl(pp->dbi_base + PCIE_PHY_DEBUG_R1); + } + + if (rc & PCIE_PHY_DEBUG_R1_XMLH_LINK_UP) return 1; /*