* @isci_host: This parameter specifies the isci host object.
  * @isci_device: This parameter specifies the remote device
  *
+ * scic_lock is held on entrance to this function.
  */
 static void isci_remote_device_not_ready(struct isci_host *ihost,
                                  struct isci_remote_device *idev, u32 reason)
 {
+       struct isci_request * ireq;
+
        dev_dbg(&ihost->pdev->dev,
                "%s: isci_device = %p\n", __func__, idev);
 
-       if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED)
+       switch (reason) {
+       case SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED:
                set_bit(IDEV_GONE, &idev->flags);
-       else
+               break;
+       case SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED:
+               set_bit(IDEV_IO_NCQERROR, &idev->flags);
+
+               /* Kill all outstanding requests for the device. */
+               list_for_each_entry(ireq, &idev->reqs_in_process, dev_node) {
+
+                       dev_dbg(&ihost->pdev->dev,
+                               "%s: isci_device = %p request = %p\n",
+                               __func__, idev, ireq);
+
+                       scic_controller_terminate_request(&ihost->sci,
+                                                         &idev->sci,
+                                                         &ireq->sci);
+               }
+               /* Fall through into the default case... */
+       default:
                clear_bit(IDEV_IO_READY, &idev->flags);
+               break;
+       }
 }
 
 /**
        dev_dbg(&ihost->pdev->dev,
                "%s: idev = %p\n", __func__, idev);
 
+       clear_bit(IDEV_IO_NCQERROR, &idev->flags);
        set_bit(IDEV_IO_READY, &idev->flags);
        if (test_and_clear_bit(IDEV_START_PENDING, &idev->flags))
                wake_up(&ihost->eventq);
 
        #define IDEV_EH 3
        #define IDEV_GONE 4
        #define IDEV_IO_READY 5
+       #define IDEV_IO_NCQERROR 6
        unsigned long flags;
        struct kref kref;
        struct isci_port *isci_port;
 
 
        spin_lock_irqsave(&ihost->scic_lock, flags);
 
-       /* send the request, let the core assign the IO TAG.    */
-       status = scic_controller_start_io(&ihost->sci, &idev->sci, &ireq->sci,
-                                         SCI_CONTROLLER_INVALID_IO_TAG);
+       if (test_bit(IDEV_IO_NCQERROR, &idev->flags)) {
+
+               if (isci_task_is_ncq_recovery(task)) {
+
+                       /* The device is in an NCQ recovery state.  Issue the
+                        * request on the task side.  Note that it will
+                        * complete on the I/O request side because the
+                        * request was built that way (ie.
+                        * ireq->is_task_management_request is false).
+                        */
+                       status = scic_controller_start_task(&ihost->sci,
+                                                           &idev->sci,
+                                                           &ireq->sci,
+                                                           SCI_CONTROLLER_INVALID_IO_TAG);
+               } else {
+                       status = SCI_FAILURE;
+               }
+       } else {
+
+               /* send the request, let the core assign the IO TAG.    */
+               status = scic_controller_start_io(&ihost->sci, &idev->sci,
+                                                 &ireq->sci,
+                                                 SCI_CONTROLLER_INVALID_IO_TAG);
+       }
        if (status != SCI_SUCCESS &&
            status != SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
                dev_warn(&ihost->pdev->dev,
 
 void
 scic_stp_io_request_set_ncq_tag(struct scic_sds_request *sci_req, u16 ncq_tag);
 void scic_sds_smp_request_copy_response(struct scic_sds_request *sci_req);
+
+static inline int isci_task_is_ncq_recovery(struct sas_task *task)
+{
+       return (sas_protocol_ata(task->task_proto) &&
+               task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT &&
+               task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ);
+
+}
+
 #endif /* !defined(_ISCI_REQUEST_H_) */
 
        for (; num > 0; num--,\
             task = list_entry(task->list.next, struct sas_task, list))
 
+
+static inline int isci_device_io_ready(struct isci_remote_device *idev,
+                                      struct sas_task *task)
+{
+       return idev ? test_bit(IDEV_IO_READY, &idev->flags) ||
+                     (test_bit(IDEV_IO_NCQERROR, &idev->flags) &&
+                      isci_task_is_ncq_recovery(task))
+                   : 0;
+}
 /**
  * isci_task_execute_task() - This function is one of the SAS Domain Template
  *    functions. This function is called by libsas to send a task down to
        for_each_sas_task(num, task) {
                spin_lock_irqsave(&ihost->scic_lock, flags);
                idev = isci_lookup_device(task->dev);
-               io_ready = idev ? test_bit(IDEV_IO_READY, &idev->flags) : 0;
+               io_ready = isci_device_io_ready(idev, task);
                spin_unlock_irqrestore(&ihost->scic_lock, flags);
 
                dev_dbg(&ihost->pdev->dev,
                                         SAS_DEVICE_UNKNOWN);
                        isci_host_can_dequeue(ihost, 1);
                } else if (!io_ready) {
+
                        /* Indicate QUEUE_FULL so that the scsi midlayer
                         * retries.
                          */
        /* sanity check, return TMF_RESP_FUNC_FAILED
         * if the device is not there and ready.
         */
-       if (!isci_device || !test_bit(IDEV_IO_READY, &isci_device->flags)) {
+       if (!isci_device ||
+           (!test_bit(IDEV_IO_READY, &isci_device->flags) &&
+            !test_bit(IDEV_IO_NCQERROR, &isci_device->flags))) {
                dev_dbg(&ihost->pdev->dev,
                        "%s: isci_device = %p not ready (%#lx)\n",
                        __func__,