@@ -4586,8 +4586,8 @@ static int pci_pm_reset(struct pci_dev *dev, bool probe)
* @use_lt: Use the LT bit if TRUE, or the DLLLA bit if FALSE.
* @active: Waiting for active or inactive?
*
- * Return 0 if successful, or -ETIMEDOUT if status has not changed within
- * PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds.
+ * Return 0 if successful, -ENODEV if @pdev is not accessible, or -ETIMEDOUT
+ * if status has not changed within PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds.
*/
static int pcie_wait_for_link_status(struct pci_dev *pdev,
bool use_lt, bool active)
@@ -4602,6 +4602,9 @@ static int pcie_wait_for_link_status(struct pci_dev *pdev,
end_jiffies = jiffies + msecs_to_jiffies(PCIE_LINK_RETRAIN_TIMEOUT_MS);
do {
pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
+ /* All ones means @pdev is gone; it would look like an active link */
+ if (PCI_POSSIBLE_ERROR(lnksta))
+ return -ENODEV;
if ((lnksta & lnksta_mask) == lnksta_match)
return 0;
msleep(1);
@@ -4624,8 +4627,9 @@ static int pcie_wait_for_link_status(struct pci_dev *pdev,
* according to @use_lt. It is not verified whether the use of the DLLLA
* bit is valid.
*
- * Return 0 if successful, or -ETIMEDOUT if training has not completed
- * within PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds.
+ * Return 0 if successful, -ENODEV if @pdev is not accessible, or -ETIMEDOUT
+ * if training has not completed within PCIE_LINK_RETRAIN_TIMEOUT_MS
+ * milliseconds.
*/
int pcie_retrain_link(struct pci_dev *pdev, bool use_lt)
{
@@ -4858,8 +4862,10 @@ int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type)
if (!dev->link_active_reporting)
return -ENOTTY;
+ /* All ones means @dev is gone; it would look like an active link */
pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &status);
- if (!(status & PCI_EXP_LNKSTA_DLLLA))
+ if (PCI_POSSIBLE_ERROR(status) ||
+ !(status & PCI_EXP_LNKSTA_DLLLA))
return -ENOTTY;
return pci_dev_wait(child, reset_type,
When a bridge is no longer accessible, its Link Status register reads as 0xffff, which has both PCI_EXP_LNKSTA_DLLLA and PCI_EXP_LNKSTA_LT set. The code that waits for the link then takes a dead link for an active one: - pci_bridge_wait_for_secondary_bus(), for ports up to 5 GT/s, decides that the link is up and waits PCIE_RESET_READY_POLL_MS for the device below it; - pcie_wait_for_link_status(), used for faster ports and by pcie_retrain_link(), reports success at once when waiting for an active link, and times out after PCIE_LINK_RETRAIN_TIMEOUT_MS when waiting for LT to clear. Treat an all-ones read as the device being gone. All callers of pcie_wait_for_link_status() and pcie_retrain_link() treat any non-zero return as failure. On a MacBookPro14,3 whose Thunderbolt controller does not come back from S3, the downstream ports of the controller are 2.5 GT/s ports that no longer answer. Resume spent about 65 seconds waiting for the xHCI controller behind one of them ("not ready 65535ms after resume"); with the pci_bridge_wait_for_secondary_bus() change it gives up on that controller after about one second. That machine never reaches pcie_wait_for_link_status() in this situation, so that part has not been tested. Assisted-by: LLM Signed-off-by: Francisco Beltrán Millalén <fbeltranmillalen@gmail.com> --- v2: - Also check in pcie_wait_for_link_status() (faster ports and pcie_retrain_link()); not tested. - Say that it is the bridge that is gone. drivers/pci/pci.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)