From: Anand Moon <linux.amoon@gmail.com>
To: "Bjorn Helgaas" <bhelgaas@google.com>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Jonathan Hunter" <jonathanh@nvidia.com>,
linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM),
devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND
FLATTENED DEVICE TREE BINDINGS),
linux-tegra@vger.kernel.org (open list:TEGRA ARCHITECTURE
SUPPORT), linux-kernel@vger.kernel.org (open list)
Cc: Anand Moon <linux.amoon@gmail.com>,
Mikko Perttunen <mperttunen@nvidia.com>
Subject: [PATCH v2 3/4] PCI: tegra: Use readl_poll_timeout() for link status polling
Date: Mon, 15 Dec 2025 19:45:36 +0530 [thread overview]
Message-ID: <20251215141603.6749-4-linux.amoon@gmail.com> (raw)
In-Reply-To: <20251215141603.6749-1-linux.amoon@gmail.com>
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>
Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v2: None
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 275d9295789a..336d2cf4d828 100644
--- a/drivers/pci/controller/pci-tegra.c
+++ b/drivers/pci/controller/pci-tegra.c
@@ -2156,37 +2156,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,
+ TEGRA_PCIE_LINKUP_TIMEOUT * 1000);
+ if (err) {
dev_dbg(dev, "link %u down, retrying\n", port->index);
goto retry;
}
- timeout = TEGRA_PCIE_LINKUP_TIMEOUT;
-
- do {
- value = readl(port->base + RP_LINK_CONTROL_STATUS);
-
- if (value & RP_LINK_CONTROL_STATUS_DL_LINK_ACTIVE)
- return true;
-
- usleep_range(1000, 2000);
- } while (--timeout);
+ err = readl_poll_timeout(port->base + RP_LINK_CONTROL_STATUS,
+ value,
+ value & RP_LINK_CONTROL_STATUS_DL_LINK_ACTIVE,
+ 1000, TEGRA_PCIE_LINKUP_TIMEOUT * 1000);
+ if (!err)
+ return true;
retry:
tegra_pcie_port_reset(port);
- } while (--retries);
+ }
return false;
}
--
2.50.1
next prev parent reply other threads:[~2025-12-15 14:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 14:15 [PATCH v2 0/4] PCI: tegra: A couple of cleanups Anand Moon
2025-12-15 14:15 ` [PATCH v2 1/4] dt-bindings: PCI: Convert nvidia,tegra-pcie to DT schema Anand Moon
2025-12-16 5:38 ` Krzysztof Kozlowski
2025-12-24 12:41 ` Anand Moon
2026-01-02 18:24 ` Jon Hunter
2026-01-08 7:08 ` Anand Moon
2025-12-22 19:35 ` kernel test robot
2025-12-15 14:15 ` [PATCH v2 2/4] PCI: tegra: Simplify clock handling by using clk_bulk*() functions Anand Moon
2025-12-15 14:15 ` Anand Moon [this message]
2025-12-15 14:15 ` [PATCH v2 4/4] PCI: tegra: Use BIT() and GENMASK() macros for register definitions 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=20251215141603.6749-4-linux.amoon@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.