All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: linux-ide@vger.kernel.org
Cc: Paul Menzel <pmenzel@molgen.mpg.de>
Subject: [PATCH 4/4] ata: libata-sata: Improve sata_link_debounce()
Date: Wed, 23 Mar 2022 17:17:40 +0900	[thread overview]
Message-ID: <20220323081740.540006-5-damien.lemoal@opensource.wdc.com> (raw)
In-Reply-To: <20220323081740.540006-1-damien.lemoal@opensource.wdc.com>

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@opensource.wdc.com>
---
 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


  parent reply	other threads:[~2022-03-23  8:19 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23  8:17 [PATCH 0/4] Remove link debounce delays by default Damien Le Moal
2022-03-23  8:17 ` [PATCH 1/4] ata: libata-sata: Simplify sata_link_resume() interface Damien Le Moal
2022-03-23  8:17 ` [PATCH 2/4] ata: libata-sata: Introduce struct sata_deb_timing Damien Le Moal
2022-03-23 14:09   ` Paul Menzel
2022-03-23 23:51     ` Damien Le Moal
2022-03-23  8:17 ` [PATCH 3/4] ata: libata-sata: Remove debounce delay by default Damien Le Moal
2022-03-23 14:25   ` Paul Menzel
2022-03-23  8:17 ` Damien Le Moal [this message]
2022-03-25  9:10   ` [PATCH 4/4] ata: libata-sata: Improve sata_link_debounce() Paul Menzel
2022-03-28  7:19     ` Damien Le Moal
2022-03-28  7:41       ` Paul Menzel
2022-03-28  9:13         ` Damien Le Moal
2022-03-28  9:43         ` Damien Le Moal
2022-03-23  8:43 ` [PATCH 0/4] Remove link debounce delays by default Paul Menzel
2022-03-23  8:45   ` Paul Menzel
2022-03-23  9:34   ` Damien Le Moal
2022-03-23  9:39   ` Damien Le Moal
2022-03-23 10:59     ` Paul Menzel
2022-03-23 23:58       ` Damien Le Moal
2022-03-24  5:30         ` Paul Menzel
2022-03-24  6:15           ` Damien Le Moal
2022-03-24  6:35             ` Paul Menzel
2022-03-24  6:51               ` Damien Le Moal

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=20220323081740.540006-5-damien.lemoal@opensource.wdc.com \
    --to=damien.lemoal@opensource.wdc.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=pmenzel@molgen.mpg.de \
    /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.