Skip to content

Commit 7b3ba09

Browse files
westeribjorn-helgaas
authored andcommitted
PCI/PM: Shorten pci_bridge_wait_for_secondary_bus() wait time for slow links
With slow links (<= 5GT/s) active link reporting is not mandatory, so if a device is disconnected during system sleep we might end up waiting for it to respond for ~60s, which slows down resume time. PCIe r6.0, sec 6.6.1, mandates that software must wait for at least 1s before it can assume a device is broken, so use that minimum requirement for slow links and bail out if the device doesn't respond within 1s. However, if the port supports active link reporting we can wait longer as we do with the fast links. This should make system resume time faster for slow links as well while still following the PCIe spec. While there move the PCI_RESET_WAIT constant into pci.c because it is not used outside of that file anymore. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mika Westerberg <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Lukas Wunner <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]>
1 parent ac9a786 commit 7b3ba09

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

drivers/pci/pci.c

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ struct pci_pme_device {
6464

6565
#define PME_TIMEOUT 1000 /* How long between PME checks */
6666

67+
/*
68+
* Following exit from Conventional Reset, devices must be ready within 1 sec
69+
* (PCIe r6.0 sec 6.6.1). A D3cold to D0 transition implies a Conventional
70+
* Reset (PCIe r6.0 sec 5.8).
71+
*/
72+
#define PCI_RESET_WAIT 1000 /* msec */
73+
6774
/*
6875
* Devices may extend the 1 sec period through Request Retry Status
6976
* completions (PCIe r6.0 sec 2.3.1). The spec does not provide an upper
@@ -5011,11 +5018,9 @@ int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type)
50115018
*
50125019
* However, 100 ms is the minimum and the PCIe spec says the
50135020
* software must allow at least 1s before it can determine that the
5014-
* device that did not respond is a broken device. There is
5015-
* evidence that 100 ms is not always enough, for example certain
5016-
* Titan Ridge xHCI controller does not always respond to
5017-
* configuration requests if we only wait for 100 ms (see
5018-
* https://bugzilla.kernel.org/show_bug.cgi?id=203885).
5021+
* device that did not respond is a broken device. Also device can
5022+
* take longer than that to respond if it indicates so through Request
5023+
* Retry Status completions.
50195024
*
50205025
* Therefore we wait for 100 ms and check for the device presence
50215026
* until the timeout expires.
@@ -5024,16 +5029,36 @@ int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type)
50245029
return 0;
50255030

50265031
if (pcie_get_speed_cap(dev) <= PCIE_SPEED_5_0GT) {
5032+
u16 status;
5033+
50275034
pci_dbg(dev, "waiting %d ms for downstream link\n", delay);
50285035
msleep(delay);
5029-
} else {
5030-
pci_dbg(dev, "waiting %d ms for downstream link, after activation\n",
5031-
delay);
5032-
if (!pcie_wait_for_link_delay(dev, true, delay)) {
5033-
/* Did not train, no need to wait any further */
5034-
pci_info(dev, "Data Link Layer Link Active not set in 1000 msec\n");
5036+
5037+
if (!pci_dev_wait(child, reset_type, PCI_RESET_WAIT - delay))
5038+
return 0;
5039+
5040+
/*
5041+
* If the port supports active link reporting we now check
5042+
* whether the link is active and if not bail out early with
5043+
* the assumption that the device is not present anymore.
5044+
*/
5045+
if (!dev->link_active_reporting)
50355046
return -ENOTTY;
5036-
}
5047+
5048+
pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &status);
5049+
if (!(status & PCI_EXP_LNKSTA_DLLLA))
5050+
return -ENOTTY;
5051+
5052+
return pci_dev_wait(child, reset_type,
5053+
PCIE_RESET_READY_POLL_MS - PCI_RESET_WAIT);
5054+
}
5055+
5056+
pci_dbg(dev, "waiting %d ms for downstream link, after activation\n",
5057+
delay);
5058+
if (!pcie_wait_for_link_delay(dev, true, delay)) {
5059+
/* Did not train, no need to wait any further */
5060+
pci_info(dev, "Data Link Layer Link Active not set in 1000 msec\n");
5061+
return -ENOTTY;
50375062
}
50385063

50395064
return pci_dev_wait(child, reset_type,

drivers/pci/pci.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,
6464
#define PCI_PM_D3HOT_WAIT 10 /* msec */
6565
#define PCI_PM_D3COLD_WAIT 100 /* msec */
6666

67-
/*
68-
* Following exit from Conventional Reset, devices must be ready within 1 sec
69-
* (PCIe r6.0 sec 6.6.1). A D3cold to D0 transition implies a Conventional
70-
* Reset (PCIe r6.0 sec 5.8).
71-
*/
72-
#define PCI_RESET_WAIT 1000 /* msec */
73-
7467
void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
7568
void pci_refresh_power_state(struct pci_dev *dev);
7669
int pci_power_up(struct pci_dev *dev);

0 commit comments

Comments
 (0)