[PATCH] libata: implement ATA_EHI_NO_AUTOPSY and QUIET
[pandora-kernel.git] / drivers / scsi / libata-eh.c
index 8233859..1e9e73d 100644 (file)
@@ -93,6 +93,38 @@ static int ata_ering_map(struct ata_ering *ering,
        return rc;
 }
 
+static unsigned int ata_eh_dev_action(struct ata_device *dev)
+{
+       struct ata_eh_context *ehc = &dev->ap->eh_context;
+
+       return ehc->i.action | ehc->i.dev_action[dev->devno];
+}
+
+static void ata_eh_clear_action(struct ata_device *dev,
+                               struct ata_eh_info *ehi, unsigned int action)
+{
+       int i;
+
+       if (!dev) {
+               ehi->action &= ~action;
+               for (i = 0; i < ATA_MAX_DEVICES; i++)
+                       ehi->dev_action[i] &= ~action;
+       } else {
+               /* doesn't make sense for port-wide EH actions */
+               WARN_ON(!(action & ATA_EH_PERDEV_MASK));
+
+               /* break ehi->action into ehi->dev_action */
+               if (ehi->action & action) {
+                       for (i = 0; i < ATA_MAX_DEVICES; i++)
+                               ehi->dev_action[i] |= ehi->action & action;
+                       ehi->action &= ~action;
+               }
+
+               /* turn off the specified per-dev action */
+               ehi->dev_action[dev->devno] &= ~action;
+       }
+}
+
 /**
  *     ata_scsi_timed_out - SCSI layer time out callback
  *     @cmd: timed out SCSI command
@@ -158,7 +190,6 @@ enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
 void ata_scsi_error(struct Scsi_Host *host)
 {
        struct ata_port *ap = ata_shost_to_port(host);
-       spinlock_t *ap_lock = ap->lock;
        int i, repeat_cnt = ATA_EH_MAX_REPEAT;
        unsigned long flags;
 
@@ -185,7 +216,7 @@ void ata_scsi_error(struct Scsi_Host *host)
                struct scsi_cmnd *scmd, *tmp;
                int nr_timedout = 0;
 
-               spin_lock_irqsave(ap_lock, flags);
+               spin_lock_irqsave(ap->lock, flags);
 
                list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
                        struct ata_queued_cmd *qc;
@@ -224,27 +255,27 @@ void ata_scsi_error(struct Scsi_Host *host)
                if (nr_timedout)
                        __ata_port_freeze(ap);
 
-               spin_unlock_irqrestore(ap_lock, flags);
+               spin_unlock_irqrestore(ap->lock, flags);
        } else
-               spin_unlock_wait(ap_lock);
+               spin_unlock_wait(ap->lock);
 
  repeat:
        /* invoke error handler */
        if (ap->ops->error_handler) {
                /* fetch & clear EH info */
-               spin_lock_irqsave(ap_lock, flags);
+               spin_lock_irqsave(ap->lock, flags);
 
                memset(&ap->eh_context, 0, sizeof(ap->eh_context));
                ap->eh_context.i = ap->eh_info;
                memset(&ap->eh_info, 0, sizeof(ap->eh_info));
 
-               ap->flags |= ATA_FLAG_EH_IN_PROGRESS;
-               ap->flags &= ~ATA_FLAG_EH_PENDING;
+               ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS;
+               ap->pflags &= ~ATA_PFLAG_EH_PENDING;
 
-               spin_unlock_irqrestore(ap_lock, flags);
+               spin_unlock_irqrestore(ap->lock, flags);
 
                /* invoke EH.  if unloading, just finish failed qcs */
-               if (!(ap->flags & ATA_FLAG_UNLOADING))
+               if (!(ap->pflags & ATA_PFLAG_UNLOADING))
                        ap->ops->error_handler(ap);
                else
                        ata_eh_finish(ap);
@@ -253,14 +284,14 @@ void ata_scsi_error(struct Scsi_Host *host)
                 * recovered the port but before this point.  Repeat
                 * EH in such case.
                 */
-               spin_lock_irqsave(ap_lock, flags);
+               spin_lock_irqsave(ap->lock, flags);
 
-               if (ap->flags & ATA_FLAG_EH_PENDING) {
+               if (ap->pflags & ATA_PFLAG_EH_PENDING) {
                        if (--repeat_cnt) {
                                ata_port_printk(ap, KERN_INFO,
                                        "EH pending after completion, "
                                        "repeating EH (cnt=%d)\n", repeat_cnt);
-                               spin_unlock_irqrestore(ap_lock, flags);
+                               spin_unlock_irqrestore(ap->lock, flags);
                                goto repeat;
                        }
                        ata_port_printk(ap, KERN_ERR, "EH pending after %d "
@@ -270,14 +301,14 @@ void ata_scsi_error(struct Scsi_Host *host)
                /* this run is complete, make sure EH info is clear */
                memset(&ap->eh_info, 0, sizeof(ap->eh_info));
 
-               /* Clear host_eh_scheduled while holding ap_lock such
+               /* Clear host_eh_scheduled while holding ap->lock such
                 * that if exception occurs after this point but
                 * before EH completion, SCSI midlayer will
                 * re-initiate EH.
                 */
                host->host_eh_scheduled = 0;
 
-               spin_unlock_irqrestore(ap_lock, flags);
+               spin_unlock_irqrestore(ap->lock, flags);
        } else {
                WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
                ap->ops->eng_timeout(ap);
@@ -289,24 +320,23 @@ void ata_scsi_error(struct Scsi_Host *host)
        scsi_eh_flush_done_q(&ap->eh_done_q);
 
        /* clean up */
-       spin_lock_irqsave(ap_lock, flags);
+       spin_lock_irqsave(ap->lock, flags);
 
-       if (ap->flags & ATA_FLAG_LOADING) {
-               ap->flags &= ~ATA_FLAG_LOADING;
-       } else {
-               if (ap->flags & ATA_FLAG_SCSI_HOTPLUG)
-                       queue_work(ata_aux_wq, &ap->hotplug_task);
-               if (ap->flags & ATA_FLAG_RECOVERED)
-                       ata_port_printk(ap, KERN_INFO, "EH complete\n");
-       }
+       if (ap->pflags & ATA_PFLAG_LOADING)
+               ap->pflags &= ~ATA_PFLAG_LOADING;
+       else if (ap->pflags & ATA_PFLAG_SCSI_HOTPLUG)
+               queue_work(ata_aux_wq, &ap->hotplug_task);
+
+       if (ap->pflags & ATA_PFLAG_RECOVERED)
+               ata_port_printk(ap, KERN_INFO, "EH complete\n");
 
-       ap->flags &= ~(ATA_FLAG_SCSI_HOTPLUG | ATA_FLAG_RECOVERED);
+       ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED);
 
        /* tell wait_eh that we're done */
-       ap->flags &= ~ATA_FLAG_EH_IN_PROGRESS;
+       ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS;
        wake_up_all(&ap->eh_wait_q);
 
-       spin_unlock_irqrestore(ap_lock, flags);
+       spin_unlock_irqrestore(ap->lock, flags);
 
        DPRINTK("EXIT\n");
 }
@@ -328,7 +358,7 @@ void ata_port_wait_eh(struct ata_port *ap)
  retry:
        spin_lock_irqsave(ap->lock, flags);
 
-       while (ap->flags & (ATA_FLAG_EH_PENDING | ATA_FLAG_EH_IN_PROGRESS)) {
+       while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) {
                prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
                spin_unlock_irqrestore(ap->lock, flags);
                schedule();
@@ -457,7 +487,7 @@ void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
        WARN_ON(!ap->ops->error_handler);
 
        qc->flags |= ATA_QCFLAG_FAILED;
-       qc->ap->flags |= ATA_FLAG_EH_PENDING;
+       qc->ap->pflags |= ATA_PFLAG_EH_PENDING;
 
        /* The following will fail if timeout has already expired.
         * ata_scsi_error() takes care of such scmds on EH entry.
@@ -481,7 +511,7 @@ void ata_port_schedule_eh(struct ata_port *ap)
 {
        WARN_ON(!ap->ops->error_handler);
 
-       ap->flags |= ATA_FLAG_EH_PENDING;
+       ap->pflags |= ATA_PFLAG_EH_PENDING;
        scsi_schedule_eh(ap->host);
 
        DPRINTK("port EH scheduled\n");
@@ -546,7 +576,7 @@ static void __ata_port_freeze(struct ata_port *ap)
        if (ap->ops->freeze)
                ap->ops->freeze(ap);
 
-       ap->flags |= ATA_FLAG_FROZEN;
+       ap->pflags |= ATA_PFLAG_FROZEN;
 
        DPRINTK("ata%u port frozen\n", ap->id);
 }
@@ -614,7 +644,7 @@ void ata_eh_thaw_port(struct ata_port *ap)
 
        spin_lock_irqsave(ap->lock, flags);
 
-       ap->flags &= ~ATA_FLAG_FROZEN;
+       ap->pflags &= ~ATA_PFLAG_FROZEN;
 
        if (ap->ops->thaw)
                ap->ops->thaw(ap);
@@ -699,35 +729,14 @@ static void ata_eh_detach_dev(struct ata_device *dev)
 
        if (ata_scsi_offline_dev(dev)) {
                dev->flags |= ATA_DFLAG_DETACHED;
-               ap->flags |= ATA_FLAG_SCSI_HOTPLUG;
+               ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
        }
 
-       spin_unlock_irqrestore(ap->lock, flags);
-}
-
-static void ata_eh_clear_action(struct ata_device *dev,
-                               struct ata_eh_info *ehi, unsigned int action)
-{
-       int i;
+       /* clear per-dev EH actions */
+       ata_eh_clear_action(dev, &ap->eh_info, ATA_EH_PERDEV_MASK);
+       ata_eh_clear_action(dev, &ap->eh_context.i, ATA_EH_PERDEV_MASK);
 
-       if (!dev) {
-               ehi->action &= ~action;
-               for (i = 0; i < ATA_MAX_DEVICES; i++)
-                       ehi->dev_action[i] &= ~action;
-       } else {
-               /* doesn't make sense for port-wide EH actions */
-               WARN_ON(!(action & ATA_EH_PERDEV_MASK));
-
-               /* break ehi->action into ehi->dev_action */
-               if (ehi->action & action) {
-                       for (i = 0; i < ATA_MAX_DEVICES; i++)
-                               ehi->dev_action[i] |= ehi->action & action;
-                       ehi->action &= ~action;
-               }
-
-               /* turn off the specified per-dev action */
-               ehi->dev_action[dev->devno] &= ~action;
-       }
+       spin_unlock_irqrestore(ap->lock, flags);
 }
 
 /**
@@ -749,8 +758,12 @@ static void ata_eh_about_to_do(struct ata_port *ap, struct ata_device *dev,
        unsigned long flags;
 
        spin_lock_irqsave(ap->lock, flags);
+
        ata_eh_clear_action(dev, &ap->eh_info, action);
-       ap->flags |= ATA_FLAG_RECOVERED;
+
+       if (!(ap->eh_context.i.flags & ATA_EHI_QUIET))
+               ap->pflags |= ATA_PFLAG_RECOVERED;
+
        spin_unlock_irqrestore(ap->lock, flags);
 }
 
@@ -1016,7 +1029,7 @@ static void ata_eh_analyze_ncq_error(struct ata_port *ap)
        int tag, rc;
 
        /* if frozen, we can't do much */
-       if (ap->flags & ATA_FLAG_FROZEN)
+       if (ap->pflags & ATA_PFLAG_FROZEN)
                return;
 
        /* is it NCQ device error? */
@@ -1264,6 +1277,9 @@ static void ata_eh_autopsy(struct ata_port *ap)
 
        DPRINTK("ENTER\n");
 
+       if (ehc->i.flags & ATA_EHI_NO_AUTOPSY)
+               return;
+
        /* obtain and analyze SError */
        rc = sata_scr_read(ap, SCR_ERROR, &serror);
        if (rc == 0) {
@@ -1316,7 +1332,7 @@ static void ata_eh_autopsy(struct ata_port *ap)
        }
 
        /* enforce default EH actions */
-       if (ap->flags & ATA_FLAG_FROZEN ||
+       if (ap->pflags & ATA_PFLAG_FROZEN ||
            all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
                action |= ATA_EH_SOFTRESET;
        else if (all_err_mask)
@@ -1335,7 +1351,7 @@ static void ata_eh_autopsy(struct ata_port *ap)
 
        /* record autopsy result */
        ehc->i.dev = failed_dev;
-       ehc->i.action = action;
+       ehc->i.action |= action;
 
        DPRINTK("EXIT\n");
 }
@@ -1374,7 +1390,7 @@ static void ata_eh_report(struct ata_port *ap)
                return;
 
        frozen = "";
-       if (ap->flags & ATA_FLAG_FROZEN)
+       if (ap->pflags & ATA_PFLAG_FROZEN)
                frozen = " frozen";
 
        if (ehc->i.dev) {
@@ -1454,7 +1470,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
        struct ata_eh_context *ehc = &ap->eh_context;
        unsigned int *classes = ehc->classes;
        int tries = ATA_EH_RESET_TRIES;
-       int verbose = !(ap->flags & ATA_FLAG_LOADING);
+       int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
        unsigned int action;
        ata_reset_fn_t reset;
        int i, did_followup_srst, rc;
@@ -1592,7 +1608,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
                unsigned int action;
 
                dev = &ap->device[i];
-               action = ehc->i.action | ehc->i.dev_action[dev->devno];
+               action = ata_eh_dev_action(dev);
 
                if (action & ATA_EH_REVALIDATE && ata_dev_enabled(dev)) {
                        if (ata_port_offline(ap)) {
@@ -1625,7 +1641,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
                        }
 
                        spin_lock_irqsave(ap->lock, flags);
-                       ap->flags |= ATA_FLAG_SCSI_HOTPLUG;
+                       ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
                        spin_unlock_irqrestore(ap->lock, flags);
                }
        }
@@ -1662,7 +1678,7 @@ static int ata_eh_skip_recovery(struct ata_port *ap)
        struct ata_eh_context *ehc = &ap->eh_context;
        int i;
 
-       if (ap->flags & ATA_FLAG_FROZEN || ata_port_nr_enabled(ap))
+       if (ap->pflags & ATA_PFLAG_FROZEN || ata_port_nr_enabled(ap))
                return 0;
 
        /* skip if class codes for all vacant slots are ATA_DEV_NONE */
@@ -1733,7 +1749,7 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
        rc = 0;
 
        /* if UNLOADING, finish immediately */
-       if (ap->flags & ATA_FLAG_UNLOADING)
+       if (ap->pflags & ATA_PFLAG_UNLOADING)
                goto out;
 
        /* skip EH if possible. */
@@ -1897,11 +1913,8 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
               ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
               ata_postreset_fn_t postreset)
 {
-       if (!(ap->flags & ATA_FLAG_LOADING)) {
-               ata_eh_autopsy(ap);
-               ata_eh_report(ap);
-       }
-
+       ata_eh_autopsy(ap);
+       ata_eh_report(ap);
        ata_eh_recover(ap, prereset, softreset, hardreset, postreset);
        ata_eh_finish(ap);
 }