libata: IDENTIFY backwards for drive side cable detection
[powerpc.git] / drivers / ata / libata-eh.c
index cad0d6d..c89664a 100644 (file)
@@ -52,8 +52,33 @@ enum {
 
 static void __ata_port_freeze(struct ata_port *ap);
 static void ata_eh_finish(struct ata_port *ap);
+#ifdef CONFIG_PM
 static void ata_eh_handle_port_suspend(struct ata_port *ap);
 static void ata_eh_handle_port_resume(struct ata_port *ap);
+static int ata_eh_suspend(struct ata_port *ap,
+                         struct ata_device **r_failed_dev);
+static void ata_eh_prep_resume(struct ata_port *ap);
+static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev);
+#else /* CONFIG_PM */
+static void ata_eh_handle_port_suspend(struct ata_port *ap)
+{ }
+
+static void ata_eh_handle_port_resume(struct ata_port *ap)
+{ }
+
+static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
+{
+       return 0;
+}
+
+static void ata_eh_prep_resume(struct ata_port *ap)
+{ }
+
+static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
+{
+       return 0;
+}
+#endif /* CONFIG_PM */
 
 static void ata_ering_record(struct ata_ering *ering, int is_io,
                             unsigned int err_mask)
@@ -1600,8 +1625,14 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
                rc = prereset(ap);
                if (rc) {
                        if (rc == -ENOENT) {
-                               ata_port_printk(ap, KERN_DEBUG, "port disabled. ignoring.\n");
+                               ata_port_printk(ap, KERN_DEBUG,
+                                               "port disabled. ignoring.\n");
                                ap->eh_context.i.action &= ~ATA_EH_RESET_MASK;
+
+                               for (i = 0; i < ATA_MAX_DEVICES; i++)
+                                       classes[i] = ATA_DEV_NONE;
+
+                               rc = 0;
                        } else
                                ata_port_printk(ap, KERN_ERR,
                                        "prereset failed (errno=%d)\n", rc);
@@ -1712,12 +1743,17 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
 {
        struct ata_eh_context *ehc = &ap->eh_context;
        struct ata_device *dev;
+       unsigned int new_mask = 0;
        unsigned long flags;
        int i, rc = 0;
 
        DPRINTK("ENTER\n");
 
-       for (i = 0; i < ATA_MAX_DEVICES; i++) {
+       /* For PATA drive side cable detection to work, IDENTIFY must
+        * be done backwards such that PDIAG- is released by the slave
+        * device before the master device is identified.
+        */
+       for (i = ATA_MAX_DEVICES - 1; i >= 0; i--) {
                unsigned int action, readid_flags = 0;
 
                dev = &ap->device[i];
@@ -1729,13 +1765,13 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
                if (action & ATA_EH_REVALIDATE && ata_dev_ready(dev)) {
                        if (ata_port_offline(ap)) {
                                rc = -EIO;
-                               break;
+                               goto err;
                        }
 
                        ata_eh_about_to_do(ap, dev, ATA_EH_REVALIDATE);
                        rc = ata_dev_revalidate(dev, readid_flags);
                        if (rc)
-                               break;
+                               goto err;
 
                        ata_eh_done(ap, dev, ATA_EH_REVALIDATE);
 
@@ -1753,43 +1789,57 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
 
                        rc = ata_dev_read_id(dev, &dev->class, readid_flags,
                                             dev->id);
-                       if (rc == 0) {
-                               ehc->i.flags |= ATA_EHI_PRINTINFO;
-                               rc = ata_dev_configure(dev);
-                               ehc->i.flags &= ~ATA_EHI_PRINTINFO;
-                       } else if (rc == -ENOENT) {
+                       switch (rc) {
+                       case 0:
+                               new_mask |= 1 << i;
+                               break;
+                       case -ENOENT:
                                /* IDENTIFY was issued to non-existent
                                 * device.  No need to reset.  Just
                                 * thaw and kill the device.
                                 */
                                ata_eh_thaw_port(ap);
-                               dev->class = ATA_DEV_UNKNOWN;
-                               rc = 0;
-                       }
-
-                       if (rc) {
                                dev->class = ATA_DEV_UNKNOWN;
                                break;
+                       default:
+                               dev->class = ATA_DEV_UNKNOWN;
+                               goto err;
                        }
+               }
+       }
 
-                       if (ata_dev_enabled(dev)) {
-                               spin_lock_irqsave(ap->lock, flags);
-                               ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
-                               spin_unlock_irqrestore(ap->lock, flags);
+       /* Configure new devices forward such that user doesn't see
+        * device detection messages backwards.
+        */
+       for (i = 0; i < ATA_MAX_DEVICES; i++) {
+               dev = &ap->device[i];
 
-                               /* new device discovered, configure xfermode */
-                               ehc->i.flags |= ATA_EHI_SETMODE;
-                       }
-               }
+               if (!(new_mask & (1 << i)))
+                       continue;
+
+               ehc->i.flags |= ATA_EHI_PRINTINFO;
+               rc = ata_dev_configure(dev);
+               ehc->i.flags &= ~ATA_EHI_PRINTINFO;
+               if (rc)
+                       goto err;
+
+               spin_lock_irqsave(ap->lock, flags);
+               ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
+               spin_unlock_irqrestore(ap->lock, flags);
+
+               /* new device discovered, configure xfermode */
+               ehc->i.flags |= ATA_EHI_SETMODE;
        }
 
-       if (rc)
-               *r_failed_dev = dev;
+       return 0;
 
-       DPRINTK("EXIT\n");
+ err:
+       *r_failed_dev = dev;
+       DPRINTK("EXIT rc=%d\n", rc);
        return rc;
 }
 
+#ifdef CONFIG_PM
 /**
  *     ata_eh_suspend - handle suspend EH action
  *     @ap: target host port
@@ -1947,6 +1997,7 @@ static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
        DPRINTK("EXIT\n");
        return 0;
 }
+#endif /* CONFIG_PM */
 
 static int ata_port_nr_enabled(struct ata_port *ap)
 {
@@ -2249,6 +2300,7 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
        ata_eh_finish(ap);
 }
 
+#ifdef CONFIG_PM
 /**
  *     ata_eh_handle_port_suspend - perform port suspend operation
  *     @ap: port to suspend
@@ -2364,3 +2416,4 @@ static void ata_eh_handle_port_resume(struct ata_port *ap)
        }
        spin_unlock_irqrestore(ap->lock, flags);
 }
+#endif /* CONFIG_PM */