From patchwork Thu Feb 13 18:29:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Troy Kisky X-Patchwork-Id: 3647051 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@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 B2F369F1EE for ; Thu, 13 Feb 2014 18:29:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BAA6D20203 for ; Thu, 13 Feb 2014 18:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8474201EC for ; Thu, 13 Feb 2014 18:29:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753067AbaBMS3u (ORCPT ); Thu, 13 Feb 2014 13:29:50 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:38914 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753065AbaBMS3t (ORCPT ); Thu, 13 Feb 2014 13:29:49 -0500 Received: by mail-pa0-f54.google.com with SMTP id fa1so11218104pad.27 for ; Thu, 13 Feb 2014 10:29:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=fmGvJrYFVkhtXbc46HGB90pwsgUFgFNruOEMVgpCLRY=; b=EGCMX7SguB5adIu2ihf0osnAx1uFrGb3DtgcXCIX5r0Q8l+VEoatg1pwsukpMQllLK bODfCBgP5U8UxkIshJDa37aJt0suz422yC3dVOFS1tjrNo5au56kffE4DPrVDTiHIm+p 2Q2Glvp/Gz0bknvi3AZKBB0bJl5bNEy0cU6KOLEUrLuPSXAWi/+7WrahTFpECA9Wvqot SaOM5M3C8iiNSW+ogdzVTbukFZF1HP82ZVmH8RS6FZT9Y9JbMJ3b2G9rL2yzZDqiGcnn eFYX4CCnySu6otVThnPp6w1pu5llYhnqodvog9uSPxkPa5ivzXRzklGLwlOEytnFumOW N8fA== X-Gm-Message-State: ALoCoQnrNFDtJdRVicbCQgD7x6OubbJOyBWx3KRR72OyqMwRglJ0rAZjXBOeCctRyeNuZ+V0ggBU X-Received: by 10.68.244.103 with SMTP id xf7mr3546351pbc.50.1392316188504; Thu, 13 Feb 2014 10:29:48 -0800 (PST) Received: from [192.168.0.242] ([63.226.49.26]) by mx.google.com with ESMTPSA id n6sm8864204pbj.22.2014.02.13.10.29.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Feb 2014 10:29:47 -0800 (PST) Message-ID: <52FD0F1A.4000208@boundarydevices.com> Date: Thu, 13 Feb 2014 11:29:46 -0700 From: Troy Kisky User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Marek Vasut , Sascha Hauer CC: linux-pci@vger.kernel.org, kernel@pengutronix.de, Richard Zhu , Shawn Guo , Bjorn Helgaas , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] PCI: imx6: Fix link_up detection References: <1392190075-23204-1-git-send-email-s.hauer@pengutronix.de> <201402120836.16221.marex@denx.de> In-Reply-To: <201402120836.16221.marex@denx.de> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 On 2/12/2014 12:36 AM, Marek Vasut wrote: > On Wednesday, February 12, 2014 at 08:27:55 AM, Sascha Hauer wrote: > > +CC Troy Kisky, since I think he submitted something similar some time ago > already. > > Otherwise I agree this happens. > Sorry, I haven't submitted this yet, but was planning to today. Here's what would have been sent. From 32c560d33fe2c3945d69f3396689f0abb76f7e1f Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 25 Jan 2014 14:22:48 -0700 Subject: [PATCH 1/1] pci-imx6.c: wait for retraining This patch handles the case where the PCIe link is up and running, yet drops into the LTSSM training mode. The link spends short time in the LTSSM training mode, but the current code can misinterpret it as the link being stalled. Waiting for the LTSSM training to complete fixes the issue. Signed-off-by: Marek Vasut Tested-by: Troy Kisky Tested-by: Sascha Hauer Acked-by: Shawn Guo --- drivers/pci/host/pci-imx6.c | 47 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/pci/host/pci-imx6.c b/drivers/pci/host/pci-imx6.c index e8663a8..ee08250 100644 --- a/drivers/pci/host/pci-imx6.c +++ b/drivers/pci/host/pci-imx6.c @@ -424,20 +424,40 @@ 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; + u32 rc, debug_r0, rx_valid; + int count = 5; /* - * Test if the PHY reports that the link is up and also that - * the link training finished. It might happen that the PHY - * reports the link is already up, but the link training bit - * is still set, so make sure to check the training is done - * as well here. + * Test if the PHY reports that the link is up and also that the LTSSM + * training finished. There are three possible states of the link when + * this code is called: + * 1) The link is DOWN (unlikely) + * The link didn't come up yet for some reason. This usually means + * we have a real problem somewhere. Reset the PHY and exit. This + * state calls for inspection of the DEBUG registers. + * 2) The link is UP, but still in LTSSM training + * Wait for the training to finish, which should take a very short + * time. If the training does not finish, we have a problem and we + * need to inspect the DEBUG registers. If the training does finish, + * the link is up and operating correctly. + * 3) The link is UP and no longer in LTSSM training + * The link is up and operating correctly. */ - 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)) - return 1; - + while (1) { + rc = readl(pp->dbi_base + PCIE_PHY_DEBUG_R1); + if (!(rc & PCIE_PHY_DEBUG_R1_XMLH_LINK_UP)) + break; + if (!(rc & PCIE_PHY_DEBUG_R1_XMLH_LINK_IN_TRAINING)) + return 1; + if (!count--) + break; + dev_dbg(pp->dev, "Link is up, but still in training\n"); + /* + * Wait a little bit, then re-check if the link finished + * the training. + */ + usleep_range(1000, 2000); + } /* * From L0, initiate MAC entry to gen2 if EP/RC supports gen2. * Wait 2ms (LTSSM timeout is 24ms, PHY lock is ~5us in gen2). @@ -446,15 +466,16 @@ static int imx6_pcie_link_up(struct pcie_port *pp) * to gen2 is stuck */ pcie_phy_read(pp->dbi_base, PCIE_PHY_RX_ASIC_OUT, &rx_valid); - ltssm = readl(pp->dbi_base + PCIE_PHY_DEBUG_R0) & 0x3F; + debug_r0 = readl(pp->dbi_base + PCIE_PHY_DEBUG_R0); if (rx_valid & 0x01) return 0; - if (ltssm != 0x0d) + if ((debug_r0 & 0x3f) != 0x0d) return 0; dev_err(pp->dev, "transition to gen2 is stuck, reset PHY!\n"); + dev_dbg(pp->dev, "debug_r0=%08x debug_r1=%08x\n", debug_r0, rc); imx6_pcie_reset_phy(pp);