sata_link_debounce() polls the SStatus register DET field to ensure that a stable value is provided, to reliably detect device presence and PHY readiness. Polling is done for at least timing->duration if there is no device detected. For the device detected case, polling last up to deadline to ensure that the PHY becomes ready. However, the PHY ready state is actually never checked, leading to the poll loop duration always reaching the maximum duration. For adapters that do not require a debounce delay (link flag ATA_LFLAG_DEBOUNCE_DELAY no set), add a check to test if DET indicates device present *and* PHY ready and bail out of the polling loop if it does. While at it, add comments to clarify the various checks in sata_link_debounce() polling loop. Signed-off-by: Damien Le Moal <damien.lemoal@xxxxxxxxxxxxxxxxxx> --- drivers/ata/libata-sata.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 87ad03c2e49f..15423723c9dd 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -276,8 +276,27 @@ int sata_link_debounce(struct ata_link *link, /* DET stable? */ if (cur == last) { + /* + * If the device presence was detected but PHY + * communication is not yet established, wait until + * deadline. + */ if (cur == 1 && time_before(jiffies, deadline)) continue; + + /* + * If PHY is ready and the device is present, and the + * driver did not request debounce delay, bail out early + * assuming that the link is stable. + */ + if (cur == 3 && + !(link->flags & ATA_LFLAG_DEBOUNCE_DELAY)) + return 0; + + /* + * If DET value has remained stable for + * timing->duration, bail out. + */ if (time_after(jiffies, ata_deadline(last_jiffies, timing->duration))) return 0; @@ -288,8 +307,9 @@ int sata_link_debounce(struct ata_link *link, last = cur; last_jiffies = jiffies; - /* Check deadline. If debouncing failed, return - * -EPIPE to tell upper layer to lower link speed. + /* + * If debouncing has not succeeded before dealine, return + * -EPIPE to tell the upper layer to lower the link speed. */ if (time_after(jiffies, deadline)) return -EPIPE; -- 2.35.1