/** * isci_task_abort_task() - This function is one of the SAS Domain Template * functions. This function is called by libsas to abort a specified task. * @task: This parameter specifies the SAS task to abort. * * status, zero indicates success. */ int isci_task_abort_task(struct sas_task *task) { struct isci_host *isci_host = dev_to_ihost(task->dev); DECLARE_COMPLETION_ONSTACK(aborted_io_completion); struct isci_request *old_request = NULL; enum isci_request_status old_state; struct isci_remote_device *isci_device = NULL; struct isci_tmf tmf; int ret = TMF_RESP_FUNC_FAILED; unsigned long flags; int perform_termination = 0; /* Get the isci_request reference from the task. Note that * this check does not depend on the pending request list * in the device, because tasks driving resets may land here * after completion in the core. */ spin_lock_irqsave(&isci_host->scic_lock, flags); spin_lock(&task->task_state_lock); old_request = task->lldd_task; /* If task is already done, the request isn't valid */ if (!(task->task_state_flags & SAS_TASK_STATE_DONE) && (task->task_state_flags & SAS_TASK_AT_INITIATOR) && old_request) isci_device = isci_lookup_device(task->dev); spin_unlock(&task->task_state_lock); spin_unlock_irqrestore(&isci_host->scic_lock, flags); dev_dbg(&isci_host->pdev->dev, "%s: dev = %p, task = %p, old_request == %p\n", __func__, isci_device, task, old_request); /* Device reset conditions signalled in task_state_flags are the * responsbility of libsas to observe at the start of the error * handler thread. */ if (!isci_device || !old_request) { /* The request has already completed and there * is nothing to do here other than to set the task * done bit, and indicate that the task abort function * was successful. */ spin_lock_irqsave(&task->task_state_lock, flags); task->task_state_flags |= SAS_TASK_STATE_DONE; task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | SAS_TASK_STATE_PENDING); spin_unlock_irqrestore(&task->task_state_lock, flags); ret = TMF_RESP_FUNC_COMPLETE; dev_dbg(&isci_host->pdev->dev, "%s: abort task not needed for %p\n", __func__, task); goto out; } spin_lock_irqsave(&isci_host->scic_lock, flags); /* Check the request status and change to "aborted" if currently * "starting"; if true then set the I/O kernel completion * struct that will be triggered when the request completes. */ old_state = isci_task_validate_request_to_abort( old_request, isci_host, isci_device, &aborted_io_completion); if ((old_state != started) && (old_state != completed) && (old_state != aborting)) { spin_unlock_irqrestore(&isci_host->scic_lock, flags); /* The request was already being handled by someone else (because * they got to set the state away from started). */ dev_dbg(&isci_host->pdev->dev, "%s: device = %p; old_request %p already being aborted\n", __func__, isci_device, old_request); ret = TMF_RESP_FUNC_COMPLETE; goto out; } if (task->task_proto == SAS_PROTOCOL_SMP || sas_protocol_ata(task->task_proto) || test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) { spin_unlock_irqrestore(&isci_host->scic_lock, flags); dev_dbg(&isci_host->pdev->dev, "%s: %s request" " or complete_in_target (%d), thus no TMF\n", __func__, ((task->task_proto == SAS_PROTOCOL_SMP) ? "SMP" : (sas_protocol_ata(task->task_proto) ? "SATA/STP" : "<other>") ), test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)); if (test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) { spin_lock_irqsave(&task->task_state_lock, flags); task->task_state_flags |= SAS_TASK_STATE_DONE; task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | SAS_TASK_STATE_PENDING); spin_unlock_irqrestore(&task->task_state_lock, flags); ret = TMF_RESP_FUNC_COMPLETE; } else { spin_lock_irqsave(&task->task_state_lock, flags); task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | SAS_TASK_STATE_PENDING); spin_unlock_irqrestore(&task->task_state_lock, flags); } /* STP and SMP devices are not sent a TMF, but the * outstanding I/O request is terminated below. This is * because SATA/STP and SMP discovery path timeouts directly * call the abort task interface for cleanup. */ perform_termination = 1; } else { /* Fill in the tmf stucture */ isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort, isci_abort_task_process_cb, old_request); spin_unlock_irqrestore(&isci_host->scic_lock, flags); #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* 1/2 second timeout */ ret = isci_task_execute_tmf(isci_host, isci_device, &tmf, ISCI_ABORT_TASK_TIMEOUT_MS); if (ret == TMF_RESP_FUNC_COMPLETE) perform_termination = 1; else dev_dbg(&isci_host->pdev->dev, "%s: isci_task_send_tmf failed\n", __func__); } if (perform_termination) { set_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags); /* Clean up the request on our side, and wait for the aborted * I/O to complete. */ isci_terminate_request_core(isci_host, isci_device, old_request); } /* Make sure we do not leave a reference to aborted_io_completion */ old_request->io_request_completion = NULL; out: isci_put_device(isci_device); return ret; }
/** * isci_task_abort_task() - This function is one of the SAS Domain Template * functions. This function is called by libsas to abort a specified task. * @task: This parameter specifies the SAS task to abort. * * status, zero indicates success. */ int isci_task_abort_task(struct sas_task *task) { struct isci_host *ihost = dev_to_ihost(task->dev); DECLARE_COMPLETION_ONSTACK(aborted_io_completion); struct isci_request *old_request = NULL; struct isci_remote_device *idev = NULL; struct isci_tmf tmf; int ret = TMF_RESP_FUNC_FAILED; unsigned long flags; int target_done_already = 0; /* Get the isci_request reference from the task. Note that * this check does not depend on the pending request list * in the device, because tasks driving resets may land here * after completion in the core. */ spin_lock_irqsave(&ihost->scic_lock, flags); spin_lock(&task->task_state_lock); old_request = task->lldd_task; /* If task is already done, the request isn't valid */ if (!(task->task_state_flags & SAS_TASK_STATE_DONE) && (task->task_state_flags & SAS_TASK_AT_INITIATOR) && old_request) { idev = isci_get_device(task->dev->lldd_dev); target_done_already = test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags); } spin_unlock(&task->task_state_lock); spin_unlock_irqrestore(&ihost->scic_lock, flags); dev_warn(&ihost->pdev->dev, "%s: dev = %p (%s%s), task = %p, old_request == %p\n", __func__, idev, (dev_is_sata(task->dev) ? "STP/SATA" : ((dev_is_expander(task->dev)) ? "SMP" : "SSP")), ((idev) ? ((test_bit(IDEV_GONE, &idev->flags)) ? " IDEV_GONE" : "") : " <NULL>"), task, old_request); /* Device reset conditions signalled in task_state_flags are the * responsbility of libsas to observe at the start of the error * handler thread. */ if (!idev || !old_request) { /* The request has already completed and there * is nothing to do here other than to set the task * done bit, and indicate that the task abort function * was successful. */ spin_lock_irqsave(&task->task_state_lock, flags); task->task_state_flags |= SAS_TASK_STATE_DONE; task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | SAS_TASK_STATE_PENDING); spin_unlock_irqrestore(&task->task_state_lock, flags); ret = TMF_RESP_FUNC_COMPLETE; dev_warn(&ihost->pdev->dev, "%s: abort task not needed for %p\n", __func__, task); goto out; } /* Suspend the RNC, kill the TC */ if (isci_remote_device_suspend_terminate(ihost, idev, old_request) != SCI_SUCCESS) { dev_warn(&ihost->pdev->dev, "%s: isci_remote_device_reset_terminate(dev=%p, " "req=%p, task=%p) failed\n", __func__, idev, old_request, task); ret = TMF_RESP_FUNC_FAILED; goto out; } spin_lock_irqsave(&ihost->scic_lock, flags); if (task->task_proto == SAS_PROTOCOL_SMP || sas_protocol_ata(task->task_proto) || target_done_already || test_bit(IDEV_GONE, &idev->flags)) { spin_unlock_irqrestore(&ihost->scic_lock, flags); /* No task to send, so explicitly resume the device here */ isci_remote_device_resume_from_abort(ihost, idev); dev_warn(&ihost->pdev->dev, "%s: %s request" " or complete_in_target (%d), " "or IDEV_GONE (%d), thus no TMF\n", __func__, ((task->task_proto == SAS_PROTOCOL_SMP) ? "SMP" : (sas_protocol_ata(task->task_proto) ? "SATA/STP" : "<other>") ), test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags), test_bit(IDEV_GONE, &idev->flags)); spin_lock_irqsave(&task->task_state_lock, flags); task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | SAS_TASK_STATE_PENDING); task->task_state_flags |= SAS_TASK_STATE_DONE; spin_unlock_irqrestore(&task->task_state_lock, flags); ret = TMF_RESP_FUNC_COMPLETE; } else { /* Fill in the tmf stucture */ isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort, old_request); spin_unlock_irqrestore(&ihost->scic_lock, flags); /* Send the task management request. */ #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* 1/2 second timeout */ ret = isci_task_execute_tmf(ihost, idev, &tmf, ISCI_ABORT_TASK_TIMEOUT_MS); } out: dev_warn(&ihost->pdev->dev, "%s: Done; dev = %p, task = %p , old_request == %p\n", __func__, idev, task, old_request); isci_put_device(idev); return ret; }
int isci_task_abort_task(struct sas_task *task) { struct isci_host *isci_host = dev_to_ihost(task->dev); DECLARE_COMPLETION_ONSTACK(aborted_io_completion); struct isci_request *old_request = NULL; enum isci_request_status old_state; struct isci_remote_device *isci_device = NULL; struct isci_tmf tmf; int ret = TMF_RESP_FUNC_FAILED; unsigned long flags; int perform_termination = 0; spin_lock_irqsave(&isci_host->scic_lock, flags); spin_lock(&task->task_state_lock); old_request = task->lldd_task; if (!(task->task_state_flags & SAS_TASK_STATE_DONE) && (task->task_state_flags & SAS_TASK_AT_INITIATOR) && old_request) isci_device = isci_lookup_device(task->dev); spin_unlock(&task->task_state_lock); spin_unlock_irqrestore(&isci_host->scic_lock, flags); dev_dbg(&isci_host->pdev->dev, "%s: dev = %p, task = %p, old_request == %p\n", __func__, isci_device, task, old_request); if (!isci_device || !old_request) { spin_lock_irqsave(&task->task_state_lock, flags); task->task_state_flags |= SAS_TASK_STATE_DONE; task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | SAS_TASK_STATE_PENDING); spin_unlock_irqrestore(&task->task_state_lock, flags); ret = TMF_RESP_FUNC_COMPLETE; dev_dbg(&isci_host->pdev->dev, "%s: abort task not needed for %p\n", __func__, task); goto out; } spin_lock_irqsave(&isci_host->scic_lock, flags); old_state = isci_task_validate_request_to_abort( old_request, isci_host, isci_device, &aborted_io_completion); if ((old_state != started) && (old_state != completed) && (old_state != aborting)) { spin_unlock_irqrestore(&isci_host->scic_lock, flags); dev_dbg(&isci_host->pdev->dev, "%s: device = %p; old_request %p already being aborted\n", __func__, isci_device, old_request); ret = TMF_RESP_FUNC_COMPLETE; goto out; } if (task->task_proto == SAS_PROTOCOL_SMP || sas_protocol_ata(task->task_proto) || test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) { spin_unlock_irqrestore(&isci_host->scic_lock, flags); dev_dbg(&isci_host->pdev->dev, "%s: %s request" " or complete_in_target (%d), thus no TMF\n", __func__, ((task->task_proto == SAS_PROTOCOL_SMP) ? "SMP" : (sas_protocol_ata(task->task_proto) ? "SATA/STP" : "<other>") ), test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)); if (test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) { spin_lock_irqsave(&task->task_state_lock, flags); task->task_state_flags |= SAS_TASK_STATE_DONE; task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | SAS_TASK_STATE_PENDING); spin_unlock_irqrestore(&task->task_state_lock, flags); ret = TMF_RESP_FUNC_COMPLETE; } else { spin_lock_irqsave(&task->task_state_lock, flags); task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | SAS_TASK_STATE_PENDING); spin_unlock_irqrestore(&task->task_state_lock, flags); } perform_termination = 1; } else { isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort, isci_abort_task_process_cb, old_request); spin_unlock_irqrestore(&isci_host->scic_lock, flags); #define ISCI_ABORT_TASK_TIMEOUT_MS 500 ret = isci_task_execute_tmf(isci_host, isci_device, &tmf, ISCI_ABORT_TASK_TIMEOUT_MS); if (ret == TMF_RESP_FUNC_COMPLETE) perform_termination = 1; else dev_dbg(&isci_host->pdev->dev, "%s: isci_task_send_tmf failed\n", __func__); } if (perform_termination) { set_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags); isci_terminate_request_core(isci_host, isci_device, old_request); } old_request->io_request_completion = NULL; out: isci_put_device(isci_device); return ret; }