Merge branch 'fixes' of git://git.linux-nfs.org/pub/linux/nfs-2.6
[pandora-kernel.git] / drivers / scsi / libata-core.c
index 4a44e75..73dd6c8 100644 (file)
@@ -32,7 +32,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -62,9 +61,9 @@
 #include "libata.h"
 
 /* debounce timing parameters in msecs { interval, duration, timeout } */
-const unsigned long sata_deb_timing_boot[]             = {   5,  100, 2000 };
-const unsigned long sata_deb_timing_eh[]               = {  25,  500, 2000 };
-const unsigned long sata_deb_timing_before_fsrst[]     = { 100, 2000, 5000 };
+const unsigned long sata_deb_timing_normal[]           = {   5,  100, 2000 };
+const unsigned long sata_deb_timing_hotplug[]          = {  25,  500, 2000 };
+const unsigned long sata_deb_timing_long[]             = { 100, 2000, 5000 };
 
 static unsigned int ata_dev_init_params(struct ata_device *dev,
                                        u16 heads, u16 sectors);
@@ -88,6 +87,10 @@ int libata_fua = 0;
 module_param_named(fua, libata_fua, int, 0444);
 MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)");
 
+static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ;
+module_param(ata_probe_timeout, int, 0444);
+MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)");
+
 MODULE_AUTHOR("Jeff Garzik");
 MODULE_DESCRIPTION("Library module for ATA devices");
 MODULE_LICENSE("GPL");
@@ -777,11 +780,9 @@ void ata_std_dev_select (struct ata_port *ap, unsigned int device)
 void ata_dev_select(struct ata_port *ap, unsigned int device,
                           unsigned int wait, unsigned int can_sleep)
 {
-       if (ata_msg_probe(ap)) {
+       if (ata_msg_probe(ap))
                ata_port_printk(ap, KERN_INFO, "ata_dev_select: ENTER, ata%u: "
-                               "device %u, wait %u\n",
-                               ap->id, device, wait);
-       }
+                               "device %u, wait %u\n", ap->id, device, wait);
 
        if (wait)
                ata_wait_idle(ap);
@@ -906,7 +907,7 @@ void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data,
 {
        int rc;
 
-       if (ap->flags & ATA_FLAG_FLUSH_PORT_TASK)
+       if (ap->pflags & ATA_PFLAG_FLUSH_PORT_TASK)
                return;
 
        PREPARE_WORK(&ap->port_task, fn, data);
@@ -937,7 +938,7 @@ void ata_port_flush_task(struct ata_port *ap)
        DPRINTK("ENTER\n");
 
        spin_lock_irqsave(ap->lock, flags);
-       ap->flags |= ATA_FLAG_FLUSH_PORT_TASK;
+       ap->pflags |= ATA_PFLAG_FLUSH_PORT_TASK;
        spin_unlock_irqrestore(ap->lock, flags);
 
        DPRINTK("flush #1\n");
@@ -950,12 +951,13 @@ void ata_port_flush_task(struct ata_port *ap)
         */
        if (!cancel_delayed_work(&ap->port_task)) {
                if (ata_msg_ctl(ap))
-                       ata_port_printk(ap, KERN_DEBUG, "%s: flush #2\n", __FUNCTION__);
+                       ata_port_printk(ap, KERN_DEBUG, "%s: flush #2\n",
+                                       __FUNCTION__);
                flush_workqueue(ata_wq);
        }
 
        spin_lock_irqsave(ap->lock, flags);
-       ap->flags &= ~ATA_FLAG_FLUSH_PORT_TASK;
+       ap->pflags &= ~ATA_PFLAG_FLUSH_PORT_TASK;
        spin_unlock_irqrestore(ap->lock, flags);
 
        if (ata_msg_ctl(ap))
@@ -999,7 +1001,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
        struct ata_queued_cmd *qc;
        unsigned int tag, preempted_tag;
        u32 preempted_sactive, preempted_qc_active;
-       DECLARE_COMPLETION(wait);
+       DECLARE_COMPLETION_ONSTACK(wait);
        unsigned long flags;
        unsigned int err_mask;
        int rc;
@@ -1007,7 +1009,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
        spin_lock_irqsave(ap->lock, flags);
 
        /* no internal command while frozen */
-       if (ap->flags & ATA_FLAG_FROZEN) {
+       if (ap->pflags & ATA_PFLAG_FROZEN) {
                spin_unlock_irqrestore(ap->lock, flags);
                return AC_ERR_SYSTEM;
        }
@@ -1059,7 +1061,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
 
        spin_unlock_irqrestore(ap->lock, flags);
 
-       rc = wait_for_completion_timeout(&wait, ATA_TMOUT_INTERNAL);
+       rc = wait_for_completion_timeout(&wait, ata_probe_timeout);
 
        ata_port_flush_task(ap);
 
@@ -1081,7 +1083,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
 
                        if (ata_msg_warn(ap))
                                ata_dev_printk(dev, KERN_WARNING,
-                                      "qc timeout (cmd 0x%x)\n", command);
+                                       "qc timeout (cmd 0x%x)\n", command);
                }
 
                spin_unlock_irqrestore(ap->lock, flags);
@@ -1093,9 +1095,9 @@ unsigned ata_exec_internal(struct ata_device *dev,
 
        if (qc->flags & ATA_QCFLAG_FAILED && !qc->err_mask) {
                if (ata_msg_warn(ap))
-                       ata_dev_printk(dev, KERN_WARNING, 
+                       ata_dev_printk(dev, KERN_WARNING,
                                "zero err_mask for failed "
-                              "internal command, assuming AC_ERR_OTHER\n");
+                               "internal command, assuming AC_ERR_OTHER\n");
                qc->err_mask |= AC_ERR_OTHER;
        }
 
@@ -1145,7 +1147,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
  *     RETURNS:
  *     Zero on success, AC_ERR_* mask on failure
  */
-static unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd)
+unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd)
 {
        struct ata_taskfile tf;
 
@@ -1220,8 +1222,8 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
        int rc;
 
        if (ata_msg_ctl(ap))
-               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n", 
-                               __FUNCTION__, ap->id, dev->devno);
+               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n",
+                              __FUNCTION__, ap->id, dev->devno);
 
        ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */
 
@@ -1290,9 +1292,9 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
        return 0;
 
  err_out:
-       if (ata_msg_warn(ap)) 
+       if (ata_msg_warn(ap))
                ata_dev_printk(dev, KERN_WARNING, "failed to IDENTIFY "
-                      "(%s, err_mask=0x%x)\n", reason, err_mask);
+                              "(%s, err_mask=0x%x)\n", reason, err_mask);
        return rc;
 }
 
@@ -1323,6 +1325,19 @@ static void ata_dev_config_ncq(struct ata_device *dev,
                snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth);
 }
 
+static void ata_set_port_max_cmd_len(struct ata_port *ap)
+{
+       int i;
+
+       if (ap->host) {
+               ap->host->max_cmd_len = 0;
+               for (i = 0; i < ATA_MAX_DEVICES; i++)
+                       ap->host->max_cmd_len = max_t(unsigned int,
+                                                     ap->host->max_cmd_len,
+                                                     ap->device[i].cdb_len);
+       }
+}
+
 /**
  *     ata_dev_configure - Configure the specified ATA/ATAPI device
  *     @dev: Target device to configure
@@ -1342,22 +1357,24 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
        struct ata_port *ap = dev->ap;
        const u16 *id = dev->id;
        unsigned int xfer_mask;
-       int i, rc;
+       int rc;
 
        if (!ata_dev_enabled(dev) && ata_msg_info(ap)) {
-               ata_dev_printk(dev, KERN_INFO, "%s: ENTER/EXIT (host %u, dev %u) -- nodev\n",
-                       __FUNCTION__, ap->id, dev->devno);
+               ata_dev_printk(dev, KERN_INFO,
+                              "%s: ENTER/EXIT (host %u, dev %u) -- nodev\n",
+                              __FUNCTION__, ap->id, dev->devno);
                return 0;
        }
 
        if (ata_msg_probe(ap))
-               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n", 
-                       __FUNCTION__, ap->id, dev->devno);
+               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n",
+                              __FUNCTION__, ap->id, dev->devno);
 
        /* print device capabilities */
        if (ata_msg_probe(ap))
-               ata_dev_printk(dev, KERN_DEBUG, "%s: cfg 49:%04x 82:%04x 83:%04x "
-                              "84:%04x 85:%04x 86:%04x 87:%04x 88:%04x\n",
+               ata_dev_printk(dev, KERN_DEBUG,
+                              "%s: cfg 49:%04x 82:%04x 83:%04x 84:%04x "
+                              "85:%04x 86:%04x 87:%04x 88:%04x\n",
                               __FUNCTION__,
                               id[49], id[82], id[83], id[84],
                               id[85], id[86], id[87], id[88]);
@@ -1400,7 +1417,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
                        ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
 
                        /* print device info to dmesg */
-                       if (ata_msg_info(ap))
+                       if (ata_msg_drv(ap) && print_info)
                                ata_dev_printk(dev, KERN_INFO, "ATA-%d, "
                                        "max %s, %Lu sectors: %s %s\n",
                                        ata_id_major_version(id),
@@ -1423,20 +1440,22 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
                        }
 
                        /* print device info to dmesg */
-                       if (ata_msg_info(ap))
+                       if (ata_msg_drv(ap) && print_info)
                                ata_dev_printk(dev, KERN_INFO, "ATA-%d, "
                                        "max %s, %Lu sectors: CHS %u/%u/%u\n",
                                        ata_id_major_version(id),
                                        ata_mode_string(xfer_mask),
                                        (unsigned long long)dev->n_sectors,
-                                       dev->cylinders, dev->heads, dev->sectors);
+                                       dev->cylinders, dev->heads,
+                                       dev->sectors);
                }
 
                if (dev->id[59] & 0x100) {
                        dev->multi_count = dev->id[59] & 0xff;
-                       if (ata_msg_info(ap))
-                               ata_dev_printk(dev, KERN_INFO, "ata%u: dev %u multi count %u\n",
-                               ap->id, dev->devno, dev->multi_count);
+                       if (ata_msg_drv(ap) && print_info)
+                               ata_dev_printk(dev, KERN_INFO,
+                                       "ata%u: dev %u multi count %u\n",
+                                       ap->id, dev->devno, dev->multi_count);
                }
 
                dev->cdb_len = 16;
@@ -1449,8 +1468,8 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
                rc = atapi_cdb_len(id);
                if ((rc < 12) || (rc > ATAPI_CDB_LEN)) {
                        if (ata_msg_warn(ap))
-                               ata_dev_printk(dev, KERN_WARNING, 
-                                       "unsupported CDB len\n");
+                               ata_dev_printk(dev, KERN_WARNING,
+                                              "unsupported CDB len\n");
                        rc = -EINVAL;
                        goto err_out_nosup;
                }
@@ -1462,21 +1481,17 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
                }
 
                /* print device info to dmesg */
-               if (ata_msg_info(ap))
+               if (ata_msg_drv(ap) && print_info)
                        ata_dev_printk(dev, KERN_INFO, "ATAPI, max %s%s\n",
                                       ata_mode_string(xfer_mask),
                                       cdb_intr_string);
        }
 
-       ap->host->max_cmd_len = 0;
-       for (i = 0; i < ATA_MAX_DEVICES; i++)
-               ap->host->max_cmd_len = max_t(unsigned int,
-                                             ap->host->max_cmd_len,
-                                             ap->device[i].cdb_len);
+       ata_set_port_max_cmd_len(ap);
 
        /* limit bridge transfers to udma5, 200 sectors */
        if (ata_dev_knobble(dev)) {
-               if (ata_msg_info(ap))
+               if (ata_msg_drv(ap) && print_info)
                        ata_dev_printk(dev, KERN_INFO,
                                       "applying bridge limits\n");
                dev->udma_mask &= ATA_UDMA5;
@@ -1493,8 +1508,8 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
 
 err_out_nosup:
        if (ata_msg_probe(ap))
-               ata_dev_printk(dev, KERN_DEBUG, 
-                               "%s: EXIT, err\n", __FUNCTION__);
+               ata_dev_printk(dev, KERN_DEBUG,
+                              "%s: EXIT, err\n", __FUNCTION__);
        return rc;
 }
 
@@ -2131,7 +2146,7 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
                 * return error code and failing device on failure.
                 */
                for (i = 0; i < ATA_MAX_DEVICES; i++) {
-                       if (ata_dev_enabled(&ap->device[i])) {
+                       if (ata_dev_ready(&ap->device[i])) {
                                ap->ops->set_mode(ap);
                                break;
                        }
@@ -2197,7 +2212,8 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
        for (i = 0; i < ATA_MAX_DEVICES; i++) {
                dev = &ap->device[i];
 
-               if (!ata_dev_enabled(dev))
+               /* don't udpate suspended devices' xfer mode */
+               if (!ata_dev_ready(dev))
                        continue;
 
                rc = ata_dev_set_mode(dev);
@@ -2573,7 +2589,7 @@ static void ata_wait_spinup(struct ata_port *ap)
 
        /* first, debounce phy if SATA */
        if (ap->cbl == ATA_CBL_SATA) {
-               rc = sata_phy_debounce(ap, sata_deb_timing_eh);
+               rc = sata_phy_debounce(ap, sata_deb_timing_hotplug);
 
                /* if debounced successfully and offline, no need to wait */
                if ((rc == 0 || rc == -EOPNOTSUPP) && ata_port_offline(ap))
@@ -2609,16 +2625,17 @@ static void ata_wait_spinup(struct ata_port *ap)
 int ata_std_prereset(struct ata_port *ap)
 {
        struct ata_eh_context *ehc = &ap->eh_context;
-       const unsigned long *timing;
+       const unsigned long *timing = sata_ehc_deb_timing(ehc);
        int rc;
 
-       /* hotplug? */
-       if (ehc->i.flags & ATA_EHI_HOTPLUGGED) {
-               if (ap->flags & ATA_FLAG_HRST_TO_RESUME)
-                       ehc->i.action |= ATA_EH_HARDRESET;
-               if (ap->flags & ATA_FLAG_SKIP_D2H_BSY)
-                       ata_wait_spinup(ap);
-       }
+       /* handle link resume & hotplug spinup */
+       if ((ehc->i.flags & ATA_EHI_RESUME_LINK) &&
+           (ap->flags & ATA_FLAG_HRST_TO_RESUME))
+               ehc->i.action |= ATA_EH_HARDRESET;
+
+       if ((ehc->i.flags & ATA_EHI_HOTPLUGGED) &&
+           (ap->flags & ATA_FLAG_SKIP_D2H_BSY))
+               ata_wait_spinup(ap);
 
        /* if we're about to do hardreset, nothing more to do */
        if (ehc->i.action & ATA_EH_HARDRESET)
@@ -2626,11 +2643,6 @@ int ata_std_prereset(struct ata_port *ap)
 
        /* if SATA, resume phy */
        if (ap->cbl == ATA_CBL_SATA) {
-               if (ap->flags & ATA_FLAG_LOADING)
-                       timing = sata_deb_timing_boot;
-               else
-                       timing = sata_deb_timing_eh;
-
                rc = sata_phy_resume(ap, timing);
                if (rc && rc != -EOPNOTSUPP) {
                        /* phy resume failed */
@@ -2718,6 +2730,8 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
  */
 int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
 {
+       struct ata_eh_context *ehc = &ap->eh_context;
+       const unsigned long *timing = sata_ehc_deb_timing(ehc);
        u32 scontrol;
        int rc;
 
@@ -2732,7 +2746,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
                if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol)))
                        return rc;
 
-               scontrol = (scontrol & 0x0f0) | 0x302;
+               scontrol = (scontrol & 0x0f0) | 0x304;
 
                if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol)))
                        return rc;
@@ -2755,7 +2769,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
        msleep(1);
 
        /* bring phy back */
-       sata_phy_resume(ap, sata_deb_timing_eh);
+       sata_phy_resume(ap, timing);
 
        /* TODO: phy layer with polling, timeouts, etc. */
        if (ata_port_offline(ap)) {
@@ -3554,7 +3568,7 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
  *     Inherited from caller.
  */
 
-void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf, 
+void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
                        unsigned int buflen, int write_data)
 {
        struct ata_port *ap = adev->ap;
@@ -3600,7 +3614,7 @@ void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
  *     Inherited from caller.
  */
 
-void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf, 
+void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf,
                       unsigned int buflen, int write_data)
 {
        struct ata_port *ap = adev->ap;
@@ -3634,7 +3648,7 @@ void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf,
  *     @buflen: buffer length
  *     @write_data: read/write
  *
- *     Transfer data from/to the device data register by PIO. Do the 
+ *     Transfer data from/to the device data register by PIO. Do the
  *     transfer with interrupts disabled.
  *
  *     LOCKING:
@@ -4279,7 +4293,7 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
        unsigned int i;
 
        /* no command while frozen */
-       if (unlikely(ap->flags & ATA_FLAG_FROZEN))
+       if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
                return NULL;
 
        /* the last tag is reserved for internal command. */
@@ -4401,7 +4415,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
         * taken care of.
         */
        if (ap->ops->error_handler) {
-               WARN_ON(ap->flags & ATA_FLAG_FROZEN);
+               WARN_ON(ap->pflags & ATA_PFLAG_FROZEN);
 
                if (unlikely(qc->err_mask))
                        qc->flags |= ATA_QCFLAG_FAILED;
@@ -4973,7 +4987,7 @@ int ata_port_offline(struct ata_port *ap)
        return 0;
 }
 
-static int ata_flush_cache(struct ata_device *dev)
+int ata_flush_cache(struct ata_device *dev)
 {
        unsigned int err_mask;
        u8 cmd;
@@ -4995,86 +5009,120 @@ static int ata_flush_cache(struct ata_device *dev)
        return 0;
 }
 
-static int ata_standby_drive(struct ata_device *dev)
+static int ata_host_set_request_pm(struct ata_host_set *host_set,
+                                  pm_message_t mesg, unsigned int action,
+                                  unsigned int ehi_flags, int wait)
 {
-       unsigned int err_mask;
+       unsigned long flags;
+       int i, rc;
 
-       err_mask = ata_do_simple_cmd(dev, ATA_CMD_STANDBYNOW1);
-       if (err_mask) {
-               ata_dev_printk(dev, KERN_ERR, "failed to standby drive "
-                              "(err_mask=0x%x)\n", err_mask);
-               return -EIO;
-       }
+       for (i = 0; i < host_set->n_ports; i++) {
+               struct ata_port *ap = host_set->ports[i];
 
-       return 0;
-}
+               /* Previous resume operation might still be in
+                * progress.  Wait for PM_PENDING to clear.
+                */
+               if (ap->pflags & ATA_PFLAG_PM_PENDING) {
+                       ata_port_wait_eh(ap);
+                       WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
+               }
 
-static int ata_start_drive(struct ata_device *dev)
-{
-       unsigned int err_mask;
+               /* request PM ops to EH */
+               spin_lock_irqsave(ap->lock, flags);
 
-       err_mask = ata_do_simple_cmd(dev, ATA_CMD_IDLEIMMEDIATE);
-       if (err_mask) {
-               ata_dev_printk(dev, KERN_ERR, "failed to start drive "
-                              "(err_mask=0x%x)\n", err_mask);
-               return -EIO;
+               ap->pm_mesg = mesg;
+               if (wait) {
+                       rc = 0;
+                       ap->pm_result = &rc;
+               }
+
+               ap->pflags |= ATA_PFLAG_PM_PENDING;
+               ap->eh_info.action |= action;
+               ap->eh_info.flags |= ehi_flags;
+
+               ata_port_schedule_eh(ap);
+
+               spin_unlock_irqrestore(ap->lock, flags);
+
+               /* wait and check result */
+               if (wait) {
+                       ata_port_wait_eh(ap);
+                       WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
+                       if (rc)
+                               return rc;
+               }
        }
 
        return 0;
 }
 
 /**
- *     ata_device_resume - wakeup a previously suspended devices
- *     @dev: the device to resume
+ *     ata_host_set_suspend - suspend host_set
+ *     @host_set: host_set to suspend
+ *     @mesg: PM message
  *
- *     Kick the drive back into action, by sending it an idle immediate
- *     command and making sure its transfer mode matches between drive
- *     and host.
+ *     Suspend @host_set.  Actual operation is performed by EH.  This
+ *     function requests EH to perform PM operations and waits for EH
+ *     to finish.
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep).
  *
+ *     RETURNS:
+ *     0 on success, -errno on failure.
  */
-int ata_device_resume(struct ata_device *dev)
+int ata_host_set_suspend(struct ata_host_set *host_set, pm_message_t mesg)
 {
-       struct ata_port *ap = dev->ap;
+       int i, j, rc;
 
-       if (ap->flags & ATA_FLAG_SUSPENDED) {
-               struct ata_device *failed_dev;
+       rc = ata_host_set_request_pm(host_set, mesg, 0, ATA_EHI_QUIET, 1);
+       if (rc)
+               goto fail;
 
-               ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
-               ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 200000);
+       /* EH is quiescent now.  Fail if we have any ready device.
+        * This happens if hotplug occurs between completion of device
+        * suspension and here.
+        */
+       for (i = 0; i < host_set->n_ports; i++) {
+               struct ata_port *ap = host_set->ports[i];
+
+               for (j = 0; j < ATA_MAX_DEVICES; j++) {
+                       struct ata_device *dev = &ap->device[j];
 
-               ap->flags &= ~ATA_FLAG_SUSPENDED;
-               while (ata_set_mode(ap, &failed_dev))
-                       ata_dev_disable(failed_dev);
+                       if (ata_dev_ready(dev)) {
+                               ata_port_printk(ap, KERN_WARNING,
+                                               "suspend failed, device %d "
+                                               "still active\n", dev->devno);
+                               rc = -EBUSY;
+                               goto fail;
+                       }
+               }
        }
-       if (!ata_dev_enabled(dev))
-               return 0;
-       if (dev->class == ATA_DEV_ATA)
-               ata_start_drive(dev);
 
+       host_set->dev->power.power_state = mesg;
        return 0;
+
+ fail:
+       ata_host_set_resume(host_set);
+       return rc;
 }
 
 /**
- *     ata_device_suspend - prepare a device for suspend
- *     @dev: the device to suspend
- *     @state: target power management state
+ *     ata_host_set_resume - resume host_set
+ *     @host_set: host_set to resume
  *
- *     Flush the cache on the drive, if appropriate, then issue a
- *     standbynow command.
+ *     Resume @host_set.  Actual operation is performed by EH.  This
+ *     function requests EH to perform PM operations and returns.
+ *     Note that all resume operations are performed parallely.
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep).
  */
-int ata_device_suspend(struct ata_device *dev, pm_message_t state)
+void ata_host_set_resume(struct ata_host_set *host_set)
 {
-       struct ata_port *ap = dev->ap;
-
-       if (!ata_dev_enabled(dev))
-               return 0;
-       if (dev->class == ATA_DEV_ATA)
-               ata_flush_cache(dev);
-
-       if (state.event != PM_EVENT_FREEZE)
-               ata_standby_drive(dev);
-       ap->flags |= ATA_FLAG_SUSPENDED;
-       return 0;
+       ata_host_set_request_pm(host_set, PMSG_ON, ATA_EH_SOFTRESET,
+                               ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0);
+       host_set->dev->power.power_state = PMSG_ON;
 }
 
 /**
@@ -5137,28 +5185,6 @@ void ata_host_stop (struct ata_host_set *host_set)
                iounmap(host_set->mmio_base);
 }
 
-
-/**
- *     ata_host_remove - Unregister SCSI host structure with upper layers
- *     @ap: Port to unregister
- *     @do_unregister: 1 if we fully unregister, 0 to just stop the port
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-
-static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister)
-{
-       struct Scsi_Host *sh = ap->host;
-
-       DPRINTK("ENTER\n");
-
-       if (do_unregister)
-               scsi_remove_host(sh);
-
-       ap->ops->port_stop(ap);
-}
-
 /**
  *     ata_dev_init - Initialize an ata_device structure
  *     @dev: Device structure to initialize
@@ -5241,7 +5267,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
        ap->msg_enable = 0x00FF;
 #elif defined(ATA_DEBUG)
        ap->msg_enable = ATA_MSG_DRV | ATA_MSG_INFO | ATA_MSG_CTL | ATA_MSG_WARN | ATA_MSG_ERR;
-#else 
+#else
        ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN;
 #endif
 
@@ -5434,6 +5460,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
                }
 
                if (ap->ops->error_handler) {
+                       struct ata_eh_info *ehi = &ap->eh_info;
                        unsigned long flags;
 
                        ata_port_probe(ap);
@@ -5441,10 +5468,11 @@ int ata_device_add(const struct ata_probe_ent *ent)
                        /* kick EH for boot probing */
                        spin_lock_irqsave(ap->lock, flags);
 
-                       ap->eh_info.probe_mask = (1 << ATA_MAX_DEVICES) - 1;
-                       ap->eh_info.action |= ATA_EH_SOFTRESET;
+                       ehi->probe_mask = (1 << ATA_MAX_DEVICES) - 1;
+                       ehi->action |= ATA_EH_SOFTRESET;
+                       ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
 
-                       ap->flags |= ATA_FLAG_LOADING;
+                       ap->pflags |= ATA_PFLAG_LOADING;
                        ata_port_schedule_eh(ap);
 
                        spin_unlock_irqrestore(ap->lock, flags);
@@ -5482,8 +5510,11 @@ int ata_device_add(const struct ata_probe_ent *ent)
 
 err_out:
        for (i = 0; i < count; i++) {
-               ata_host_remove(host_set->ports[i], 1);
-               scsi_host_put(host_set->ports[i]->host);
+               struct ata_port *ap = host_set->ports[i];
+               if (ap) {
+                       ap->ops->port_stop(ap);
+                       scsi_host_put(ap->host);
+               }
        }
 err_free_ret:
        kfree(host_set);
@@ -5508,11 +5539,11 @@ void ata_port_detach(struct ata_port *ap)
        int i;
 
        if (!ap->ops->error_handler)
-               return;
+               goto skip_eh;
 
        /* tell EH we're leaving & flush EH */
        spin_lock_irqsave(ap->lock, flags);
-       ap->flags |= ATA_FLAG_UNLOADING;
+       ap->pflags |= ATA_PFLAG_UNLOADING;
        spin_unlock_irqrestore(ap->lock, flags);
 
        ata_port_wait_eh(ap);
@@ -5544,6 +5575,7 @@ void ata_port_detach(struct ata_port *ap)
        cancel_delayed_work(&ap->hotplug_task);
        flush_workqueue(ata_aux_wq);
 
+ skip_eh:
        /* remove the associated SCSI host */
        scsi_remove_host(ap->host);
 }
@@ -5612,7 +5644,7 @@ int ata_scsi_release(struct Scsi_Host *host)
        DPRINTK("ENTER\n");
 
        ap->ops->port_disable(ap);
-       ata_host_remove(ap, 0);
+       ap->ops->port_stop(ap);
 
        DPRINTK("EXIT\n");
        return 1;
@@ -5717,20 +5749,55 @@ int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
        return (tmp == bits->val) ? 1 : 0;
 }
 
-int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state)
+void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        pci_save_state(pdev);
-       pci_disable_device(pdev);
-       pci_set_power_state(pdev, PCI_D3hot);
-       return 0;
+
+       if (state.event == PM_EVENT_SUSPEND) {
+               pci_disable_device(pdev);
+               pci_set_power_state(pdev, PCI_D3hot);
+       }
 }
 
-int ata_pci_device_resume(struct pci_dev *pdev)
+void ata_pci_device_do_resume(struct pci_dev *pdev)
 {
        pci_set_power_state(pdev, PCI_D0);
        pci_restore_state(pdev);
        pci_enable_device(pdev);
        pci_set_master(pdev);
+}
+
+int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+       struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
+       int rc = 0;
+
+       rc = ata_host_set_suspend(host_set, state);
+       if (rc)
+               return rc;
+
+       if (host_set->next) {
+               rc = ata_host_set_suspend(host_set->next, state);
+               if (rc) {
+                       ata_host_set_resume(host_set);
+                       return rc;
+               }
+       }
+
+       ata_pci_device_do_suspend(pdev, state);
+
+       return 0;
+}
+
+int ata_pci_device_resume(struct pci_dev *pdev)
+{
+       struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
+
+       ata_pci_device_do_resume(pdev);
+       ata_host_set_resume(host_set);
+       if (host_set->next)
+               ata_host_set_resume(host_set->next);
+
        return 0;
 }
 #endif /* CONFIG_PCI */
@@ -5738,6 +5805,7 @@ int ata_pci_device_resume(struct pci_dev *pdev)
 
 static int __init ata_init(void)
 {
+       ata_probe_timeout *= HZ;
        ata_wq = create_workqueue("ata");
        if (!ata_wq)
                return -ENOMEM;
@@ -5762,7 +5830,7 @@ module_init(ata_init);
 module_exit(ata_exit);
 
 static unsigned long ratelimit_time;
-static spinlock_t ata_ratelimit_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(ata_ratelimit_lock);
 
 int ata_ratelimit(void)
 {
@@ -5835,9 +5903,9 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
  * Do not depend on ABI/API stability.
  */
 
-EXPORT_SYMBOL_GPL(sata_deb_timing_boot);
-EXPORT_SYMBOL_GPL(sata_deb_timing_eh);
-EXPORT_SYMBOL_GPL(sata_deb_timing_before_fsrst);
+EXPORT_SYMBOL_GPL(sata_deb_timing_normal);
+EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug);
+EXPORT_SYMBOL_GPL(sata_deb_timing_long);
 EXPORT_SYMBOL_GPL(ata_std_bios_param);
 EXPORT_SYMBOL_GPL(ata_std_ports);
 EXPORT_SYMBOL_GPL(ata_device_add);
@@ -5909,6 +5977,8 @@ EXPORT_SYMBOL_GPL(sata_scr_write);
 EXPORT_SYMBOL_GPL(sata_scr_write_flush);
 EXPORT_SYMBOL_GPL(ata_port_online);
 EXPORT_SYMBOL_GPL(ata_port_offline);
+EXPORT_SYMBOL_GPL(ata_host_set_suspend);
+EXPORT_SYMBOL_GPL(ata_host_set_resume);
 EXPORT_SYMBOL_GPL(ata_id_string);
 EXPORT_SYMBOL_GPL(ata_id_c_string);
 EXPORT_SYMBOL_GPL(ata_scsi_simulate);
@@ -5923,14 +5993,14 @@ EXPORT_SYMBOL_GPL(ata_pci_host_stop);
 EXPORT_SYMBOL_GPL(ata_pci_init_native_mode);
 EXPORT_SYMBOL_GPL(ata_pci_init_one);
 EXPORT_SYMBOL_GPL(ata_pci_remove_one);
+EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend);
+EXPORT_SYMBOL_GPL(ata_pci_device_do_resume);
 EXPORT_SYMBOL_GPL(ata_pci_device_suspend);
 EXPORT_SYMBOL_GPL(ata_pci_device_resume);
 EXPORT_SYMBOL_GPL(ata_pci_default_filter);
 EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
 #endif /* CONFIG_PCI */
 
-EXPORT_SYMBOL_GPL(ata_device_suspend);
-EXPORT_SYMBOL_GPL(ata_device_resume);
 EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
 EXPORT_SYMBOL_GPL(ata_scsi_device_resume);