Patchwork [v2,2/4] scsi: sd: enter stop power condition on runtime suspend

login
register
mail settings
Submitter Aaron Lu
Date Sept. 18, 2012, 7 a.m.
Message ID <1347951631-1592-3-git-send-email-aaron.lu@intel.com>
Download mbox | patch
Permalink /patch/184630/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Aaron Lu - Sept. 18, 2012, 7 a.m.
On runtime suspend, put device into stop power condition.

For standard scsi device, no need to synchronize cache.
For ata devices, issue synchronize cache before enter standby state
as reflected by the sync_before_stop flag.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
 drivers/ata/libata-scsi.c |  1 +
 drivers/scsi/sd.c         | 10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

Patch

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 8ec81ca..9307f52 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1117,6 +1117,7 @@  static int ata_scsi_dev_config(struct scsi_device *sdev,
 	} else {
 		sdev->sector_size = ata_id_logical_sector_size(dev->id);
 		sdev->manage_start_stop = 1;
+		sdev->sync_before_stop = 1;
 	}
 
 	/*
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 4df73e5..7b0f07a 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2866,18 +2866,24 @@  static int sd_suspend(struct device *dev, pm_message_t mesg)
 {
 	struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
 	int ret = 0;
+	bool sync;
 
 	if (!sdkp)
 		return 0;	/* this can happen */
 
-	if (sdkp->WCE) {
+	if (!sdkp->device->manage_start_stop)
+		sync = !!sdkp->WCE;
+	else
+		sync = sdkp->device->sync_before_stop && !!sdkp->WCE;
+
+	if (sync) {
 		sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
 		ret = sd_sync_cache(sdkp);
 		if (ret)
 			goto done;
 	}
 
-	if ((mesg.event & PM_EVENT_SLEEP) && sdkp->device->manage_start_stop) {
+	if (sdkp->device->manage_start_stop) {
 		sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
 		ret = sd_start_stop_device(sdkp, 0);
 	}