Linux-ide Archive mirror
 help / color / mirror / Atom feed
From: Phillip Susi <phill@thesusis.net>
To: Damien Le Moal <dlemoal@kernel.org>
Cc: linux-ide@vger.kernel.org, Phillip Susi <phill@thesusis.net>
Subject: [PATCH 4/4] libata: don't start PuiS disks on resume
Date: Thu,  4 Jan 2024 17:39:40 -0500	[thread overview]
Message-ID: <20240104223940.339290-4-phill@thesusis.net> (raw)
In-Reply-To: <20240104223940.339290-1-phill@thesusis.net>

Disks with Power Up In Standby enabled that required the
SET FEATURES command to start up were being issued the
command during resume.  Suppress this until the disk
is actually accessed.
---
 drivers/ata/libata-core.c | 24 ++++++++++++++++++++++--
 drivers/ata/libata-eh.c   | 12 +++++++++++-
 drivers/ata/libata.h      |  1 +
 include/linux/libata.h    |  1 +
 4 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index d9e889fa2881..3f6187c75b16 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -1912,7 +1912,25 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
 			goto err_out;
 	}
 
-	if (!tried_spinup && (id[2] == 0x37c8 || id[2] == 0x738c)) {
+	if (flags & ATA_READID_NOSTART && id[2] == 0x37c8)
+	{
+		/*
+		 * the drive has powered up in standby, and returned incomplete IDENTIFY info
+		 * so we can't revalidate it yet.  We have also been asked to avoid starting the
+		 * drive, so stop  here and leave the drive asleep and the EH pending, to be
+		 * restarted on later IO request
+		 */
+		ata_tf_init(dev, &tf);
+		tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
+		tf.protocol = ATA_PROT_NODATA;
+		tf.command = ATA_CMD_SLEEP;
+		err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0);
+		ata_dev_info(dev, "PuiS detected, putting drive to sleep");
+		return -EAGAIN;
+	}
+
+	if (!(flags & ATA_READID_NOSTART) &&
+	    !tried_spinup && (id[2] == 0x37c8 || id[2] == 0x738c)) {
 		tried_spinup = 1;
 		/*
 		 * Drive powered-up in standby mode, and requires a specific
@@ -3973,6 +3991,8 @@ int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
 
 	/* re-read ID */
 	rc = ata_dev_reread_id(dev, readid_flags);
+	if (rc == -EAGAIN)
+		return rc;
 	if (rc)
 		goto fail;
 
@@ -5241,7 +5261,7 @@ static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg,
 	 * http://thread.gmane.org/gmane.linux.ide/46764
 	 */
 	ata_port_request_pm(ap, mesg, 0,
-			    ATA_EHI_QUIET | ATA_EHI_NO_AUTOPSY |
+			    ATA_EHI_QUIET | ATA_EHI_NO_AUTOPSY | ATA_EHI_NOSTART
 			    ATA_EHI_NO_RECOVERY,
 			    async);
 }
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 799a1b8bc384..74e0d54a204e 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -22,6 +22,7 @@
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_dbg.h>
 #include "../scsi/scsi_transport_api.h"
+#include <linux/pm_runtime.h>
 
 #include <linux/libata.h>
 
@@ -3046,6 +3047,8 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
 
 		if (ehc->i.flags & ATA_EHI_DID_RESET)
 			readid_flags |= ATA_READID_POSTRESET;
+		if (ehc->i.flags & ATA_EHI_NOSTART)
+			readid_flags |= ATA_READID_NOSTART;
 
 		if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
 			WARN_ON(dev->class == ATA_DEV_PMP);
@@ -3075,9 +3078,16 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
 			ata_eh_about_to_do(link, dev, ATA_EH_REVALIDATE);
 			rc = ata_dev_revalidate(dev, ehc->classes[dev->devno],
 						readid_flags);
-			if (rc)
+			if (rc == -EAGAIN) {
+				rc = 0; /* start required but suppressed, handle later */
+				ehc->i.dev_action[dev->devno] &= ~ATA_EH_SET_ACTIVE;
+				ata_dev_warn(dev, "Leaving PuiS disk asleep for now");
+				continue;
+			}
+			else if (rc)
 				goto err;
 
+			pm_runtime_resume(&dev->sdev->sdev_gendev);
 			ata_eh_done(link, dev, ATA_EH_REVALIDATE);
 
 			/* Configuration may have changed, reconfigure
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 43ad1ef9b63a..cff3facad055 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -19,6 +19,7 @@
 enum {
 	/* flags for ata_dev_read_id() */
 	ATA_READID_POSTRESET	= (1 << 0), /* reading ID after reset */
+	ATA_READID_NOSTART	= (1 << 1), /* do not start drive */
 
 	/* selector for ata_down_xfermask_limit() */
 	ATA_DNXFER_PIO		= 0,	/* speed down PIO */
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 1dbb14daccfa..50d6fa933946 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -328,6 +328,7 @@ enum {
 
 	/* ata_eh_info->flags */
 	ATA_EHI_HOTPLUGGED	= (1 << 0),  /* could have been hotplugged */
+	ATA_EHI_NOSTART		= (1 << 1),  /* don't start the disk */
 	ATA_EHI_NO_AUTOPSY	= (1 << 2),  /* no autopsy */
 	ATA_EHI_QUIET		= (1 << 3),  /* be quiet */
 	ATA_EHI_NO_RECOVERY	= (1 << 4),  /* no recovery */
-- 
2.30.2


  parent reply	other threads:[~2024-01-04 22:40 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-25 15:19 [PATCH 0/1] Only activate drive once during system resume Phillip Susi
2023-12-25 15:19 ` [PATCH 1/1] libata: only wake a drive once on " Phillip Susi
2023-12-30 18:21 ` [PATCH 0/1 v2] Only activate drive once during " Phillip Susi
2023-12-30 18:21   ` [PATCH 1/1] libata: only wake a drive once on " Phillip Susi
2023-12-30 19:42     ` Sergey Shtylyov
2024-01-02 23:17     ` Damien Le Moal
2024-01-03 21:00       ` Phillip Susi
2024-01-04  1:21         ` Damien Le Moal
2024-01-04 14:05           ` Phillip Susi
2024-01-04 22:39             ` [PATCH 1/4] " Phillip Susi
2024-01-04 22:39               ` [PATCH 2/4] libata: don't wake sleeping disk during system suspend Phillip Susi
2024-01-05 12:25                 ` Damien Le Moal
2024-01-05 16:18                   ` Phillip Susi
2024-01-04 22:39               ` [PATCH 3/4] libata: avoid waking disk for several commands Phillip Susi
2024-01-05  8:46                 ` Sergei Shtylyov
2024-01-05 16:24                   ` Phillip Susi
2024-01-05 18:33                     ` Sergei Shtylyov
2024-01-06 19:49                       ` Phillip Susi
2024-01-06 20:29                   ` Phillip Susi
2024-01-08  8:57                     ` Sergei Shtylyov
2024-01-05 12:29                 ` Damien Le Moal
2024-01-05 16:30                   ` Phillip Susi
2024-01-06 23:14                     ` Damien Le Moal
2024-01-07 17:57                       ` Phillip Susi
2024-01-07 18:02                         ` [PATCH 0/3] Let sleeping disks lie Phillip Susi
2024-01-07 18:02                           ` [PATCH 1/3] libata: avoid waking disk for several commands Phillip Susi
2024-01-08  6:25                             ` Damien Le Moal
2024-01-08 13:27                               ` Phillip Susi
2024-01-10  2:39                                 ` Damien Le Moal
2024-01-16 17:06                                   ` Phillip Susi
2024-01-19 20:43                                     ` Phillip Susi
2024-01-20 18:08                                       ` Phillip Susi
2024-01-21  0:37                                         ` Damien Le Moal
2024-01-21  0:37                                       ` Damien Le Moal
2024-01-24 16:04                                         ` Phillip Susi
2024-01-24 21:51                                           ` Damien Le Moal
2024-02-01 20:01                                             ` Phillip Susi
2024-02-02  1:08                                               ` Damien Le Moal
2024-02-02 19:53                                                 ` Phillip Susi
2024-02-02 23:17                                                   ` Damien Le Moal
2024-02-05 19:52                                                     ` Phillip Susi
2024-01-08  8:48                             ` Sergey Shtylyov
2024-01-08 13:30                               ` Phillip Susi
2024-01-07 18:02                           ` [PATCH 2/3] libata: only wake a drive once on system resume Phillip Susi
2024-01-08  6:04                             ` Damien Le Moal
2024-01-07 18:02                           ` [PATCH 3/3] libata: don't start PuiS disks on resume Phillip Susi
2024-01-08  6:03                             ` Damien Le Moal
2024-01-08 13:39                               ` Phillip Susi
2024-01-10  2:19                                 ` Damien Le Moal
2024-01-16 17:13                                   ` Phillip Susi
2024-01-04 22:39               ` Phillip Susi [this message]
2024-01-05  8:57                 ` [PATCH 4/4] " Sergei Shtylyov
2024-01-05 12:42                 ` Damien Le Moal
2024-01-05 16:44                   ` Phillip Susi
2024-01-05 12:13               ` [PATCH 1/4] libata: only wake a drive once on system resume Damien Le Moal
2024-01-05 17:03                 ` Phillip Susi
2024-01-06 23:06                   ` Damien Le Moal
2024-01-05 12:44               ` Damien Le Moal
2024-01-09 15:20   ` [PATCH 0/1 v2] Only activate drive once during " Niklas Cassel
2024-01-16 17:23     ` Phillip Susi
2024-01-02 22:46 ` [PATCH 0/1] " 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=20240104223940.339290-4-phill@thesusis.net \
    --to=phill@thesusis.net \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).