Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3310016imc; Wed, 13 Mar 2019 14:29:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqx995NrKf00S2n7ElzFRDzddoZprtXg2L9Ibq++03p34Y62dVeGF9j5oBBgxAckfFuCbU4r X-Received: by 2002:a63:e90f:: with SMTP id i15mr42106548pgh.430.1552512598001; Wed, 13 Mar 2019 14:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552512597; cv=none; d=google.com; s=arc-20160816; b=aMO6RIARB5ifcJ64W+IYV3aXgNeEfMJ4KJNtGSRkKt6UNeWcHruCIELsJRznVDwOZA 8CLPVi4IONL2DOtlTh789WhHfSMrpPOCYwp3OHfoX9wxGKGzT5KPzwZqE2e9t/lv5c7L lUs+QdRybfijHOHmWHAAbOAGSE1LIhtCpZn3PdA7YJ2reIAh0qSYTbE8hAYsIuVpRpM0 mXKqMlolnX2k2iI0dilIYXENSsjk9RVfB9bFk6Kr7yq6r2s38hO/HLhGNAGb+MKVsUF/ BViyYz+KNJPTXfpKfwVdFdMWHLXvmvKhczXLOyJB18zc9IR1iZi8qJZiQMCP+dNtjlj/ 9cng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ZGsxPTG17ISz5jdeRLcVbsKs4LrojS4TNEyMeWTcJpU=; b=YzObMnmWTVM/TP+qFBQ/pf3DKZgc7d/YhpIQ9yLniYkPBvPFUEen734us78xSL0QHc uZ16CXR4TL6Q9V47aCtZnmGon2n8/CuyLSM+43FVv2A2BKmWQm/W0McSHRknPcA3ibQH gIpwdY1KCmwiM9H8m690NL0SJJ4PHBGw89NRMEPCWGenW+Ed2wnn+mc9i37opjwZiAfI I1SjGIwXUl4OgGsIEdhEjeuPXxJEmSda75+hJ/QKgZFJUUWMC7FpFp6N1Nxf3zLS2qTT jPW/ggasICkIhHrR67SGk/mwp0x5TkDlyoQyRzVm1iu6VmeAGU1l2oXGEywfZveTLbVV ptCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v17si1336130pff.214.2019.03.13.14.29.41; Wed, 13 Mar 2019 14:29:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727455AbfCMV3U (ORCPT + 99 others); Wed, 13 Mar 2019 17:29:20 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:57321 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726772AbfCMV3T (ORCPT ); Wed, 13 Mar 2019 17:29:19 -0400 X-Originating-IP: 88.190.179.123 Received: from localhost (unknown [88.190.179.123]) (Authenticated sender: repk@triplefau.lt) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 74E1860003; Wed, 13 Mar 2019 21:29:16 +0000 (UTC) From: Remi Pommarel To: Thomas Petazzoni , Lorenzo Pieralisi , Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Miquel Raynal , Remi Pommarel Subject: [PATCH] pci: aardvark: Wait for endpoint to be ready before training link Date: Wed, 13 Mar 2019 22:37:52 +0100 Message-Id: <20190313213752.1246-1-repk@triplefau.lt> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When configuring pcie reset pin from gpio (e.g. initially set by u-boot) to pcie function this pin goes low for a brief moment asserting the PERST# signal. Thus connected device enters fundamental reset process and link configuration can only begin after a minimal 100ms delay (see [1]). This makes sure that link is configured after at least 100ms from beginning of probe() callback (shortly after the reset pin function configuration switch through pinctrl subsytem). [1] "PCI Express Base Specification", REV. 2.1 PCI Express, March 4 2009, 6.6.1 Conventional Reset Signed-off-by: Remi Pommarel --- drivers/pci/controller/pci-aardvark.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index a30ae7cf8e7e..70a1023d0ef1 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -177,6 +177,9 @@ #define PIO_TIMEOUT_MS 1 +/* Endpoint can take up to 100ms to be ready after a reset */ +#define ENDPOINT_RST_MS 100 + #define LINK_WAIT_MAX_RETRIES 10 #define LINK_WAIT_USLEEP_MIN 90000 #define LINK_WAIT_USLEEP_MAX 100000 @@ -242,8 +245,10 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie) return -ETIMEDOUT; } -static void advk_pcie_setup_hw(struct advk_pcie *pcie) +static void +advk_pcie_setup_hw(struct advk_pcie *pcie, unsigned long ep_rdy_time) { + unsigned long now; u32 reg; /* Set to Direct mode */ @@ -327,9 +332,12 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) reg |= PIO_CTRL_ADDR_WIN_DISABLE; advk_writel(pcie, reg, PIO_CTRL); - /* Start link training */ + /* Wait for endpoint to exit reset state and start link training */ reg = advk_readl(pcie, PCIE_CORE_LINK_CTRL_STAT_REG); reg |= PCIE_CORE_LINK_TRAINING; + now = jiffies; + if (time_before(now, ep_rdy_time)) + msleep(jiffies_to_msecs(ep_rdy_time - now)); advk_writel(pcie, reg, PCIE_CORE_LINK_CTRL_STAT_REG); advk_pcie_wait_for_link(pcie); @@ -993,8 +1001,11 @@ static int advk_pcie_probe(struct platform_device *pdev) struct advk_pcie *pcie; struct resource *res; struct pci_host_bridge *bridge; + unsigned long ep_rdy_time; int ret, irq; + ep_rdy_time = jiffies + msecs_to_jiffies(ENDPOINT_RST_MS); + bridge = devm_pci_alloc_host_bridge(dev, sizeof(struct advk_pcie)); if (!bridge) return -ENOMEM; @@ -1022,7 +1033,7 @@ static int advk_pcie_probe(struct platform_device *pdev) return ret; } - advk_pcie_setup_hw(pcie); + advk_pcie_setup_hw(pcie, ep_rdy_time); advk_sw_pci_bridge_init(pcie); -- 2.20.1