[PATCH] libata-eh-fw: implement ata_port_schedule_eh() and ata_port_abort()
[deliverable/linux.git] / drivers / scsi / libata-core.c
index 9a97ebd5920996d5b4c4ec8f1f6535be32e4d5b1..9c97783462d650b473355d1baf20b38bebea2d6d 100644 (file)
@@ -980,15 +980,39 @@ unsigned ata_exec_internal(struct ata_device *dev,
        struct ata_port *ap = dev->ap;
        u8 command = tf->command;
        struct ata_queued_cmd *qc;
+       unsigned int tag, preempted_tag;
        DECLARE_COMPLETION(wait);
        unsigned long flags;
        unsigned int err_mask;
 
        spin_lock_irqsave(&ap->host_set->lock, flags);
 
-       qc = ata_qc_new_init(dev);
-       BUG_ON(qc == NULL);
+       /* initialize internal qc */
 
+       /* XXX: Tag 0 is used for drivers with legacy EH as some
+        * drivers choke if any other tag is given.  This breaks
+        * ata_tag_internal() test for those drivers.  Don't use new
+        * EH stuff without converting to it.
+        */
+       if (ap->ops->error_handler)
+               tag = ATA_TAG_INTERNAL;
+       else
+               tag = 0;
+
+       if (test_and_set_bit(tag, &ap->qactive))
+               BUG();
+       qc = __ata_qc_from_tag(ap, tag);
+
+       qc->tag = tag;
+       qc->scsicmd = NULL;
+       qc->ap = ap;
+       qc->dev = dev;
+       ata_qc_reinit(qc);
+
+       preempted_tag = ap->active_tag;
+       ap->active_tag = ATA_TAG_POISON;
+
+       /* prepare & issue qc */
        qc->tf = *tf;
        if (cdb)
                memcpy(qc->cdb, cdb, ATAPI_CDB_LEN);
@@ -1035,6 +1059,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
        err_mask = qc->err_mask;
 
        ata_qc_free(qc);
+       ap->active_tag = preempted_tag;
 
        /* XXX - Some LLDDs (sata_mv) disable port on command failure.
         * Until those drivers are fixed, we detect the condition
@@ -2528,11 +2553,17 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
  */
 void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
 {
+       u32 serror;
+
        DPRINTK("ENTER\n");
 
        /* print link status */
        sata_print_link_status(ap);
 
+       /* clear SError */
+       if (sata_scr_read(ap, SCR_ERROR, &serror) == 0)
+               sata_scr_write(ap, SCR_ERROR, serror);
+
        /* re-enable interrupts */
        if (ap->ioaddr.ctl_addr)        /* FIXME: hack. create a hook instead */
                ata_irq_on(ap);
@@ -4008,9 +4039,10 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
        struct ata_queued_cmd *qc = NULL;
        unsigned int i;
 
-       for (i = 0; i < ATA_MAX_QUEUE; i++)
+       /* the last tag is reserved for internal command. */
+       for (i = 0; i < ATA_MAX_QUEUE - 1; i++)
                if (!test_and_set_bit(i, &ap->qactive)) {
-                       qc = ata_qc_from_tag(ap, i);
+                       qc = __ata_qc_from_tag(ap, i);
                        break;
                }
 
@@ -4091,6 +4123,66 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
        qc->complete_fn(qc);
 }
 
+/**
+ *     ata_qc_complete - Complete an active ATA command
+ *     @qc: Command to complete
+ *     @err_mask: ATA Status register contents
+ *
+ *     Indicate to the mid and upper layers that an ATA
+ *     command has completed, with either an ok or not-ok status.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host_set lock)
+ */
+void ata_qc_complete(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+
+       /* XXX: New EH and old EH use different mechanisms to
+        * synchronize EH with regular execution path.
+        *
+        * In new EH, a failed qc is marked with ATA_QCFLAG_FAILED.
+        * Normal execution path is responsible for not accessing a
+        * failed qc.  libata core enforces the rule by returning NULL
+        * from ata_qc_from_tag() for failed qcs.
+        *
+        * Old EH depends on ata_qc_complete() nullifying completion
+        * requests if ATA_QCFLAG_EH_SCHEDULED is set.  Old EH does
+        * not synchronize with interrupt handler.  Only PIO task is
+        * taken care of.
+        */
+       if (ap->ops->error_handler) {
+               WARN_ON(ap->flags & ATA_FLAG_FROZEN);
+
+               if (unlikely(qc->err_mask))
+                       qc->flags |= ATA_QCFLAG_FAILED;
+
+               if (unlikely(qc->flags & ATA_QCFLAG_FAILED)) {
+                       if (!ata_tag_internal(qc->tag)) {
+                               /* always fill result TF for failed qc */
+                               ap->ops->tf_read(ap, &qc->result_tf);
+                               ata_qc_schedule_eh(qc);
+                               return;
+                       }
+               }
+
+               /* read result TF if requested */
+               if (qc->flags & ATA_QCFLAG_RESULT_TF)
+                       ap->ops->tf_read(ap, &qc->result_tf);
+
+               __ata_qc_complete(qc);
+       } else {
+               if (qc->flags & ATA_QCFLAG_EH_SCHEDULED)
+                       return;
+
+               /* read result TF if failed or requested */
+               if (qc->err_mask || qc->flags & ATA_QCFLAG_RESULT_TF)
+                       ap->ops->tf_read(ap, &qc->result_tf);
+
+               __ata_qc_complete(qc);
+       }
+}
+
 static inline int ata_should_dma_map(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
@@ -5213,7 +5305,7 @@ EXPORT_SYMBOL_GPL(ata_device_add);
 EXPORT_SYMBOL_GPL(ata_host_set_remove);
 EXPORT_SYMBOL_GPL(ata_sg_init);
 EXPORT_SYMBOL_GPL(ata_sg_init_one);
-EXPORT_SYMBOL_GPL(__ata_qc_complete);
+EXPORT_SYMBOL_GPL(ata_qc_complete);
 EXPORT_SYMBOL_GPL(ata_qc_issue_prot);
 EXPORT_SYMBOL_GPL(ata_tf_load);
 EXPORT_SYMBOL_GPL(ata_tf_read);
@@ -5291,5 +5383,7 @@ EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
 EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
 
 EXPORT_SYMBOL_GPL(ata_eng_timeout);
+EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
+EXPORT_SYMBOL_GPL(ata_port_abort);
 EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
 EXPORT_SYMBOL_GPL(ata_eh_qc_retry);
This page took 0.025895 seconds and 5 git commands to generate.