Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3785608yba; Tue, 23 Apr 2019 09:33:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbP8DRowVjtKkeBerI5ewb4D9OZwoIhH/uByXQ2UAoNjfgtDLU4N/BjboIawZk2QPVNSzF X-Received: by 2002:a65:6392:: with SMTP id h18mr25254887pgv.273.1556037230247; Tue, 23 Apr 2019 09:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556037230; cv=none; d=google.com; s=arc-20160816; b=pogfRKVW571o5S7K7shsJRdHVhJrsSeD7ChWdVFYZLt9H/srNADe/pZ2T5R3gvoONf ivfigrCg6qQcsGpK6n6edpcF+WX+111nA7hEOq6D3tNF8Yxyvz+zq68PaHr07+mp6/FD nNeB7gqfglypdeoIB3EDHwFSHbiXWVt7BiEyBh37WzglZd4D1FN0dY+bKBsEr3PeQ/nA Y7wZYOegdTZCpWgdTnLf9ESoIX2tFyd3QjLKGdw7VMJvCqi6XQ28I1rmAgV4g0C/MLrA CA0lhbE45yMKKWjD+HRE7NsipZLBstnyGkLLib1E6C3P503Ra6ZMKQe7ckwOWW5cxgeW /rYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=sv64jJ3zXcMRmJhUmAxB1qyo6KeuB0z5l3LYg6YIUR0=; b=rpMYqXS5xnkQ1CYWiJUeYry6TXNLYmkSeqWjpRNVSuSA6AsLZfoc4Mb/Z74oS2Nl7h lABSci7Oq72CIfjt0HVvlz8cLqilfkOi61uYxeKbpEaX7KWqYyxacVX4SmyO0An4/8FK LCoVzT3dSaQi2pQP6+x1J8KS5h8NgVUmSTiPDh3EyiHlFeD7eFuQThAnmCK8d8bf80Ua 78JL2VGcaANwQJQdR5dnX0YV/IKNCfs4Lyvpm5GDmTQK+Ffqfj9lLylGAQSfNvMNr6G+ BPA8nZ9dWRTF8C+8wfvWx1vlwCBpUs6HzvXcz4ik9a0CjmrDX+uTLbsMM6F5EKWnqlat k5xQ== 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 j1si3585771pgb.401.2019.04.23.09.33.35; Tue, 23 Apr 2019 09:33:50 -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 S1729013AbfDWQcO (ORCPT + 99 others); Tue, 23 Apr 2019 12:32:14 -0400 Received: from foss.arm.com ([217.140.101.70]:59450 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728005AbfDWQcL (ORCPT ); Tue, 23 Apr 2019 12:32:11 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7FA2780D; Tue, 23 Apr 2019 09:32:10 -0700 (PDT) Received: from red-moon (unknown [10.1.197.39]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1A3C13F557; Tue, 23 Apr 2019 09:32:08 -0700 (PDT) Date: Tue, 23 Apr 2019 17:32:15 +0100 From: Lorenzo Pieralisi To: Remi Pommarel Cc: Thomas Petazzoni , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Miquel Raynal Subject: Re: [PATCH] pci: aardvark: Wait for endpoint to be ready before training link Message-ID: <20190423163215.GB26523@red-moon> References: <20190313213752.1246-1-repk@triplefau.lt> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190313213752.1246-1-repk@triplefau.lt> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 13, 2019 at 10:37:52PM +0100, Remi Pommarel wrote: > 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) Nit: I prefer the prototype to be in one line, I wrap it for you. I am wondering why you need to pass in ep_rdy_time parameter when you can easily compute it in the function itself. Regardless, I need Thomas's ACK to proceed, I can make these changes myself. Thanks, Lorenzo > { > + 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 >