From: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
To: Remi Pommarel <repk@triplefau.lt>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Bjorn Helgaas <bhelgaas@google.com>,
linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Miquel Raynal <miquel.raynal@bootlin.com>
Subject: Re: [PATCH] pci: aardvark: Wait for endpoint to be ready before training link
Date: Tue, 23 Apr 2019 17:32:15 +0100 [thread overview]
Message-ID: <20190423163215.GB26523@red-moon> (raw)
In-Reply-To: <20190313213752.1246-1-repk@triplefau.lt>
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 <repk@triplefau.lt>
> ---
> 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
>
next prev parent reply other threads:[~2019-04-23 16:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-13 21:37 [PATCH] pci: aardvark: Wait for endpoint to be ready before training link Remi Pommarel
2019-04-23 16:32 ` Lorenzo Pieralisi [this message]
2019-04-23 22:29 ` Remi Pommarel
2019-04-24 16:50 ` Lorenzo Pieralisi
2019-04-25 21:08 ` Remi Pommarel
2019-04-26 16:10 ` Bjorn Helgaas
2019-04-26 17:16 ` Lorenzo Pieralisi
2019-04-25 16:30 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190423163215.GB26523@red-moon \
--to=lorenzo.pieralisi@arm.com \
--cc=bhelgaas@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=repk@triplefau.lt \
--cc=thomas.petazzoni@bootlin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).