[PATCH] ata: libata-sata: retry hardreset when device detected but PHY not established

From: Xingui Yang

Date: Sat Apr 25 2026 - 02:05:16 EST


When sata_link_hardreset() detects that the link is offline, it currently
returns immediately without distinguishing the reason. According to SATA
specification, the SStatus register's det filed (bits 0-3) indicates:
- 0x0: No device detected, PHY not communicating
- 0x1: Device detected but PHY communication not established
- 0x3: Device detected and PHY communication established

This patch helps improve device detection reliability and adds a check
when the link is offline but det filed shows 0x1, return -EAGAIN to
trigger retry, rather than giving up immediately.

Signed-off-by: Xingui Yang <yangxingui@xxxxxxxxxx>
---
drivers/ata/libata-sata.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
index b9d635088f5f..e5bb92c38e38 100644
--- a/drivers/ata/libata-sata.c
+++ b/drivers/ata/libata-sata.c
@@ -667,8 +667,18 @@ int sata_link_hardreset(struct ata_link *link, const unsigned int *timing,
if (rc)
goto out;
/* if link is offline nothing more to do */
- if (ata_phys_link_offline(link))
+ if (ata_phys_link_offline(link)) {
+ u32 sstatus;
+
+ if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 &&
+ (sstatus & 0xf) == 0x1) {
+ ata_link_warn(link, "device detected but PHY not ready (SStatus %X), retrying\n",
+ sstatus);
+ rc = -EAGAIN;
+ }
+
goto out;
+ }

/* Link is online. From this point, -ENODEV too is an error. */
if (online)
--
2.33.0