libata: track SLEEP state and issue SRST to wake it up
authorTejun Heo <htejun@gmail.com>
Thu, 25 Oct 2007 09:30:36 +0000 (18:30 +0900)
committerJeff Garzik <jeff@garzik.org>
Mon, 29 Oct 2007 10:15:25 +0000 (06:15 -0400)
ATA devices in SLEEP mode don't respond to any commands.  SRST is
necessary to wake it up.  Till now, when a command is issued to a
device in SLEEP mode, the command times out, which makes EH reset the
device and retry the command after that, causing a long delay.

This patch makes libata track SLEEP state and issue SRST automatically
if a command is about to be issued to a device in SLEEP.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Cc: Bruce Allen <ballen@gravity.phys.uwm.edu>
Cc: Andrew Paprocki <andrew@ishiboo.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
drivers/ata/libata-core.c
drivers/ata/libata-eh.c
include/linux/ata.h
include/linux/libata.h

index 5aedd1af06e6e7fa0d8a8ac5fbc0c36ceea4dd1e..50ae20101d10f555615165154bd5428e6fbec1b4 100644 (file)
@@ -5630,6 +5630,10 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
                        ehi->dev_action[dev->devno] |= ATA_EH_REVALIDATE;
                        ata_port_schedule_eh(ap);
                        break;
+
+               case ATA_CMD_SLEEP:
+                       dev->flags |= ATA_DFLAG_SLEEPING;
+                       break;
                }
 
                __ata_qc_complete(qc);
@@ -5769,6 +5773,14 @@ void ata_qc_issue(struct ata_queued_cmd *qc)
                qc->flags &= ~ATA_QCFLAG_DMAMAP;
        }
 
+       /* if device is sleeping, schedule softreset and abort the link */
+       if (unlikely(qc->dev->flags & ATA_DFLAG_SLEEPING)) {
+               link->eh_info.action |= ATA_EH_SOFTRESET;
+               ata_ehi_push_desc(&link->eh_info, "waking up from sleep");
+               ata_link_abort(link);
+               return;
+       }
+
        ap->ops->qc_prep(qc);
 
        qc->err_mask |= ap->ops->qc_issue(qc);
index 8cb35bb8760575c2c5b1b20bcd6b80febbb74096..496edaff119a2ec7d5681dbace21606b01d6577e 100644 (file)
@@ -2208,9 +2208,11 @@ int ata_eh_reset(struct ata_link *link, int classify,
                ata_link_for_each_dev(dev, link) {
                        /* After the reset, the device state is PIO 0
                         * and the controller state is undefined.
-                        * Record the mode.
+                        * Reset also wakes up drives from sleeping
+                        * mode.
                         */
                        dev->pio_mode = XFER_PIO_0;
+                       dev->flags &= ~ATA_DFLAG_SLEEPING;
 
                        if (ata_link_offline(link))
                                continue;
index 8263a7b74d34c63bdb88851518638ad2b65c5c54..e21c002c3a4a4f2dded103f76d44d612e642f0bd 100644 (file)
@@ -180,6 +180,7 @@ enum {
        ATA_CMD_VERIFY_EXT      = 0x42,
        ATA_CMD_STANDBYNOW1     = 0xE0,
        ATA_CMD_IDLEIMMEDIATE   = 0xE1,
+       ATA_CMD_SLEEP           = 0xE6,
        ATA_CMD_INIT_DEV_PARAMS = 0x91,
        ATA_CMD_READ_NATIVE_MAX = 0xF8,
        ATA_CMD_READ_NATIVE_MAX_EXT = 0x27,
index 6fd24e03622ecd915a6a4160cfb400e1445c1d15..2f0fc636b4b6c66e6c2c23cad8132ea60e595b22 100644 (file)
@@ -138,6 +138,7 @@ enum {
        ATA_DFLAG_PIO           = (1 << 12), /* device limited to PIO mode */
        ATA_DFLAG_NCQ_OFF       = (1 << 13), /* device limited to non-NCQ mode */
        ATA_DFLAG_SPUNDOWN      = (1 << 14), /* XXX: for spindown_compat */
+       ATA_DFLAG_SLEEPING      = (1 << 15), /* device is sleeping */
        ATA_DFLAG_INIT_MASK     = (1 << 16) - 1,
 
        ATA_DFLAG_DETACH        = (1 << 16),