[PATCH v2 2/7] PCI: Replace msleep(1) with fsleep() for precise link status checking

Hans Zhang posted 7 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v2 2/7] PCI: Replace msleep(1) with fsleep() for precise link status checking
Posted by Hans Zhang 1 month, 1 week ago
The msleep(1) in pcie_wait_for_link_status() may sleep longer than
intended due to timer granularity, which can cause unnecessary delays in
link status monitoring. Replace it with fsleep() for a more precise delay
of exactly 1ms.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/pci.c | 2 +-
 drivers/pci/pci.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index fb4aff520f64..fff49982b2a9 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4683,7 +4683,7 @@ static int pcie_wait_for_link_status(struct pci_dev *pdev,
 		pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
 		if ((lnksta & lnksta_mask) == lnksta_match)
 			return 0;
-		msleep(1);
+		fsleep(PCIE_LINK_STATUS_CHECK_US);
 	} while (time_before(jiffies, end_jiffies));
 
 	return -ETIMEDOUT;
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 471dae45e46a..e9360d8ff81d 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -16,6 +16,7 @@ struct pcie_tlp_log;
 #define PCI_VSEC_ID_INTEL_TBT	0x1234	/* Thunderbolt */
 
 #define PCIE_LINK_RETRAIN_TIMEOUT_MS	1000
+#define PCIE_LINK_STATUS_CHECK_US	1000
 
 /*
  * Power stable to PERST# inactive.
-- 
2.25.1