linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Moon <linux.amoon@gmail.com>
To: Manivannan Sadhasivam <mani@kernel.org>
Cc: "Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Thierry Reding" <thierry.reding@gmail.com>,
	"Jonathan Hunter" <jonathanh@nvidia.com>,
	"open list:PCI NATIVE HOST BRIDGE AND ENDPOINT DRIVERS"
	<linux-pci@vger.kernel.org>,
	"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
	<devicetree@vger.kernel.org>,
	"open list:TEGRA ARCHITECTURE SUPPORT"
	<linux-tegra@vger.kernel.org>,
	"open list" <linux-kernel@vger.kernel.org>,
	"Mikko Perttunen" <mperttunen@nvidia.com>
Subject: Re: [PATCH v1 3/5] PCI: tegra: Use readl_poll_timeout() for link status polling
Date: Fri, 24 Oct 2025 11:47:02 +0530	[thread overview]
Message-ID: <CANAwSgSeOrVjkuFbPKAPXDnCrsApcgePEs3D6MWwtsu9nYNesw@mail.gmail.com> (raw)
In-Reply-To: <6eqqafz2dojo533fw2j7say3p37simug5bol2s5dvcpac77jzb@2x22ekyl4qdq>

Hi Manivannan,

On Tue, 21 Oct 2025 at 07:13, Manivannan Sadhasivam <mani@kernel.org> wrote:
>
> On Mon, Oct 20, 2025 at 05:47:15PM +0530, Anand Moon wrote:
> > Hi Manivannan,
> >
> > Thanks for your review comment.
> >
> > On Sun, 19 Oct 2025 at 13:20, Manivannan Sadhasivam <mani@kernel.org> wrote:
> > >
> > > On Fri, Sep 26, 2025 at 12:57:44PM +0530, Anand Moon wrote:
> > > > Replace the manual `do-while` polling loops with the readl_poll_timeout()
> > > > helper when checking the link DL_UP and DL_LINK_ACTIVE status bits
> > > > during link bring-up. This simplifies the code by removing the open-coded
> > > > timeout logic in favor of the standard, more robust iopoll framework.
> > > > The change improves readability and reduces code duplication.
> > > >
> > > > Cc: Thierry Reding <thierry.reding@gmail.com>
> > > > Cc: Mikko Perttunen <mperttunen@nvidia.com>
> > > > Signed-off-by: Anand Moon <linux.amoon@gmail.com>
> > > > ---
> > > > v1: dropped the include  <linux/iopoll.h> header file.
> > > > ---
> > > >  drivers/pci/controller/pci-tegra.c | 37 +++++++++++-------------------
> > > >  1 file changed, 14 insertions(+), 23 deletions(-)
> > > >
> > > > diff --git a/drivers/pci/controller/pci-tegra.c b/drivers/pci/controller/pci-tegra.c
> > > > index 07a61d902eae..b0056818a203 100644
> > > > --- a/drivers/pci/controller/pci-tegra.c
> > > > +++ b/drivers/pci/controller/pci-tegra.c
> > > > @@ -2169,37 +2169,28 @@ static bool tegra_pcie_port_check_link(struct tegra_pcie_port *port)
> > > >       value |= RP_PRIV_MISC_PRSNT_MAP_EP_PRSNT;
> > > >       writel(value, port->base + RP_PRIV_MISC);
> > > >
> > > > -     do {
> > > > -             unsigned int timeout = TEGRA_PCIE_LINKUP_TIMEOUT;
> > > > +     while (retries--) {
> > > > +             int err;
> > > >
> > > > -             do {
> > > > -                     value = readl(port->base + RP_VEND_XP);
> > > > -
> > > > -                     if (value & RP_VEND_XP_DL_UP)
> > > > -                             break;
> > > > -
> > > > -                     usleep_range(1000, 2000);
> > > > -             } while (--timeout);
> > > > -
> > > > -             if (!timeout) {
> > > > +             err = readl_poll_timeout(port->base + RP_VEND_XP, value,
> > > > +                                      value & RP_VEND_XP_DL_UP,
> > > > +                                      1000,
> > >
> > > The delay between the iterations had range of (1000, 2000), now it will become
> > > (250, 1000). How can you ensure that this delay is sufficient?
> > >
> > I asked if the timeout should be increased for the loops, but Mikko
> > Perttunen said that 200ms delay is fine.
> >
>
> readl_poll_timeout() internally uses usleep_range(), which transforms the 1000us
> delay into, usleep_range(251, 1000). So the delay *could* theoretically be 251us
> * 200 = ~50ms.
>
> So I doubt it will be sifficient, as from the old code, it looks like the
> hardware could take around 200ms to complete link up.
>
Instead of implementing a busy-waiting while loop with udelay, a more
efficient and responsive approach is to use the readl_poll_timeout()
function. This function periodically polls a memory-mapped address, waiting
for a condition to be met or for a specified timeout to occur.

If there are any issues with HW, we could extend the timeout to compensate.
> - Mani
Thanks
-Anand
>
> --
> மணிவண்ணன் சதாசிவம்

  reply	other threads:[~2025-10-24  6:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-26  7:27 [PATCH v1 0/5] PCI: tegra: A couple of cleanups Anand Moon
2025-09-26  7:27 ` [PATCH v1 1/5] dt-bindings: PCI: Convert the existing nvidia,tegra-pcie.txt bindings documentation into a YAML schema Anand Moon
2025-09-26 13:56   ` Rob Herring
2025-09-29  7:39     ` Anand Moon
2025-09-29 13:48       ` Rob Herring
2025-09-29 15:25         ` Anand Moon
2025-09-30 14:37           ` Rob Herring
2025-09-30 16:32             ` Anand Moon
2025-10-01 15:33               ` Rob Herring
2025-10-01 18:57                 ` Anand Moon
2025-09-26  7:27 ` [PATCH v1 2/5] PCI: tegra: Simplify clock handling by using clk_bulk*() functions Anand Moon
2025-09-26 18:12   ` Frank Li
2025-09-27  5:50     ` Anand Moon
2025-09-29 14:01       ` Manivannan Sadhasivam
2025-09-29 16:12         ` Anand Moon
2025-09-26  7:27 ` [PATCH v1 3/5] PCI: tegra: Use readl_poll_timeout() for link status polling Anand Moon
2025-10-19  7:50   ` Manivannan Sadhasivam
2025-10-20 12:17     ` Anand Moon
2025-10-21  1:43       ` Manivannan Sadhasivam
2025-10-24  6:17         ` Anand Moon [this message]
2025-09-26  7:27 ` [PATCH v1 4/5] PCI: tegra: Use BIT() and GENMASK() macros for register definitions Anand Moon
2025-09-26  7:27 ` [PATCH v1 5/5] PCI: tegra: Document map_lock and mask_lock usage Anand Moon

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=CANAwSgSeOrVjkuFbPKAPXDnCrsApcgePEs3D6MWwtsu9nYNesw@mail.gmail.com \
    --to=linux.amoon@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=krzk+dt@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=mperttunen@nvidia.com \
    --cc=robh@kernel.org \
    --cc=thierry.reding@gmail.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).