static int isci_task_execute_tmf(struct isci_host *ihost, struct isci_remote_device *idev, struct isci_tmf *tmf, unsigned long timeout_ms) { DECLARE_COMPLETION_ONSTACK(completion); enum sci_task_status status = SCI_TASK_FAILURE; struct isci_request *ireq; int ret = TMF_RESP_FUNC_FAILED; unsigned long flags; unsigned long timeleft; u16 tag; spin_lock_irqsave(&ihost->scic_lock, flags); tag = isci_alloc_tag(ihost); spin_unlock_irqrestore(&ihost->scic_lock, flags); if (tag == SCI_CONTROLLER_INVALID_IO_TAG) return ret; /* sanity check, return TMF_RESP_FUNC_FAILED * if the device is not there and ready. */ if (!idev || (!test_bit(IDEV_IO_READY, &idev->flags) && !test_bit(IDEV_IO_NCQERROR, &idev->flags))) { dev_dbg(&ihost->pdev->dev, "%s: idev = %p not ready (%#lx)\n", __func__, idev, idev ? idev->flags : 0); goto err_tci; } else dev_dbg(&ihost->pdev->dev, "%s: idev = %p\n", __func__, idev); /* Assign the pointer to the TMF's completion kernel wait structure. */ tmf->complete = &completion; tmf->status = SCI_FAILURE_TIMEOUT; ireq = isci_task_request_build(ihost, idev, tag, tmf); if (!ireq) goto err_tci; spin_lock_irqsave(&ihost->scic_lock, flags); /* start the TMF io. */ status = sci_controller_start_task(ihost, idev, ireq); if (status != SCI_TASK_SUCCESS) { dev_dbg(&ihost->pdev->dev, "%s: start_io failed - status = 0x%x, request = %p\n", __func__, status, ireq); spin_unlock_irqrestore(&ihost->scic_lock, flags); goto err_tci; } if (tmf->cb_state_func != NULL) tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data); isci_request_change_state(ireq, started); /* add the request to the remote device request list. */ list_add(&ireq->dev_node, &idev->reqs_in_process); spin_unlock_irqrestore(&ihost->scic_lock, flags); /* Wait for the TMF to complete, or a timeout. */ timeleft = wait_for_completion_timeout(&completion, msecs_to_jiffies(timeout_ms)); if (timeleft == 0) { /* The TMF did not complete - this could be because * of an unplug. Terminate the TMF request now. */ spin_lock_irqsave(&ihost->scic_lock, flags); if (tmf->cb_state_func != NULL) tmf->cb_state_func(isci_tmf_timed_out, tmf, tmf->cb_data); sci_controller_terminate_request(ihost, idev, ireq); spin_unlock_irqrestore(&ihost->scic_lock, flags); timeleft = wait_for_completion_timeout( &completion, msecs_to_jiffies(ISCI_TERMINATION_TIMEOUT_MSEC)); if (!timeleft) { /* Strange condition - the termination of the TMF * request timed-out. */ spin_lock_irqsave(&ihost->scic_lock, flags); /* If the TMF status has not changed, kill it. */ if (tmf->status == SCI_FAILURE_TIMEOUT) isci_request_mark_zombie(ihost, ireq); spin_unlock_irqrestore(&ihost->scic_lock, flags); } } isci_print_tmf(ihost, tmf); if (tmf->status == SCI_SUCCESS) ret = TMF_RESP_FUNC_COMPLETE; else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) { dev_dbg(&ihost->pdev->dev, "%s: tmf.status == " "SCI_FAILURE_IO_RESPONSE_VALID\n", __func__); ret = TMF_RESP_FUNC_COMPLETE; } /* Else - leave the default "failed" status alone. */ dev_dbg(&ihost->pdev->dev, "%s: completed request = %p\n", __func__, ireq); return ret; err_tci: spin_lock_irqsave(&ihost->scic_lock, flags); isci_tci_free(ihost, ISCI_TAG_TCI(tag)); spin_unlock_irqrestore(&ihost->scic_lock, flags); return ret; }
static int isci_task_execute_tmf(struct isci_host *ihost, struct isci_remote_device *idev, struct isci_tmf *tmf, unsigned long timeout_ms) { DECLARE_COMPLETION_ONSTACK(completion); enum sci_task_status status = SCI_TASK_FAILURE; struct isci_request *ireq; int ret = TMF_RESP_FUNC_FAILED; unsigned long flags; unsigned long timeleft; u16 tag; spin_lock_irqsave(&ihost->scic_lock, flags); tag = isci_alloc_tag(ihost); spin_unlock_irqrestore(&ihost->scic_lock, flags); if (tag == SCI_CONTROLLER_INVALID_IO_TAG) return ret; /* sanity check, return TMF_RESP_FUNC_FAILED * if the device is not there and ready. */ if (!idev || (!test_bit(IDEV_IO_READY, &idev->flags) && !test_bit(IDEV_IO_NCQERROR, &idev->flags))) { dev_dbg(&ihost->pdev->dev, "%s: idev = %p not ready (%#lx)\n", __func__, idev, idev ? idev->flags : 0); goto err_tci; } else dev_dbg(&ihost->pdev->dev, "%s: idev = %p\n", __func__, idev); /* Assign the pointer to the TMF's completion kernel wait structure. */ tmf->complete = &completion; tmf->status = SCI_FAILURE_TIMEOUT; ireq = isci_task_request_build(ihost, idev, tag, tmf); if (!ireq) goto err_tci; spin_lock_irqsave(&ihost->scic_lock, flags); /* start the TMF io. */ status = sci_controller_start_task(ihost, idev, ireq); if (status != SCI_TASK_SUCCESS) { dev_dbg(&ihost->pdev->dev, "%s: start_io failed - status = 0x%x, request = %p\n", __func__, status, ireq); spin_unlock_irqrestore(&ihost->scic_lock, flags); goto err_tci; } spin_unlock_irqrestore(&ihost->scic_lock, flags); /* The RNC must be unsuspended before the TMF can get a response. */ isci_remote_device_resume_from_abort(ihost, idev); /* Wait for the TMF to complete, or a timeout. */ timeleft = wait_for_completion_timeout(&completion, msecs_to_jiffies(timeout_ms)); if (timeleft == 0) { /* The TMF did not complete - this could be because * of an unplug. Terminate the TMF request now. */ isci_remote_device_suspend_terminate(ihost, idev, ireq); } isci_print_tmf(ihost, tmf); if (tmf->status == SCI_SUCCESS) ret = TMF_RESP_FUNC_COMPLETE; else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) { dev_dbg(&ihost->pdev->dev, "%s: tmf.status == " "SCI_FAILURE_IO_RESPONSE_VALID\n", __func__); ret = TMF_RESP_FUNC_COMPLETE; } /* Else - leave the default "failed" status alone. */ dev_dbg(&ihost->pdev->dev, "%s: completed request = %p\n", __func__, ireq); return ret; err_tci: spin_lock_irqsave(&ihost->scic_lock, flags); isci_tci_free(ihost, ISCI_TAG_TCI(tag)); spin_unlock_irqrestore(&ihost->scic_lock, flags); return ret; }
static int isci_task_execute_tmf(struct isci_host *ihost, struct isci_remote_device *idev, struct isci_tmf *tmf, unsigned long timeout_ms) { DECLARE_COMPLETION_ONSTACK(completion); enum sci_task_status status = SCI_TASK_FAILURE; struct isci_request *ireq; int ret = TMF_RESP_FUNC_FAILED; unsigned long flags; unsigned long timeleft; u16 tag; spin_lock_irqsave(&ihost->scic_lock, flags); tag = isci_alloc_tag(ihost); spin_unlock_irqrestore(&ihost->scic_lock, flags); if (tag == SCI_CONTROLLER_INVALID_IO_TAG) return ret; if (!idev || (!test_bit(IDEV_IO_READY, &idev->flags) && !test_bit(IDEV_IO_NCQERROR, &idev->flags))) { dev_dbg(&ihost->pdev->dev, "%s: idev = %p not ready (%#lx)\n", __func__, idev, idev ? idev->flags : 0); goto err_tci; } else dev_dbg(&ihost->pdev->dev, "%s: idev = %p\n", __func__, idev); tmf->complete = &completion; tmf->status = SCI_FAILURE_TIMEOUT; ireq = isci_task_request_build(ihost, idev, tag, tmf); if (!ireq) goto err_tci; spin_lock_irqsave(&ihost->scic_lock, flags); status = sci_controller_start_task(ihost, idev, ireq); if (status != SCI_TASK_SUCCESS) { dev_dbg(&ihost->pdev->dev, "%s: start_io failed - status = 0x%x, request = %p\n", __func__, status, ireq); spin_unlock_irqrestore(&ihost->scic_lock, flags); goto err_tci; } if (tmf->cb_state_func != NULL) tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data); isci_request_change_state(ireq, started); list_add(&ireq->dev_node, &idev->reqs_in_process); spin_unlock_irqrestore(&ihost->scic_lock, flags); timeleft = wait_for_completion_timeout(&completion, msecs_to_jiffies(timeout_ms)); if (timeleft == 0) { spin_lock_irqsave(&ihost->scic_lock, flags); if (tmf->cb_state_func != NULL) tmf->cb_state_func(isci_tmf_timed_out, tmf, tmf->cb_data); sci_controller_terminate_request(ihost, idev, ireq); spin_unlock_irqrestore(&ihost->scic_lock, flags); timeleft = wait_for_completion_timeout( &completion, msecs_to_jiffies(ISCI_TERMINATION_TIMEOUT_MSEC)); if (!timeleft) { spin_lock_irqsave(&ihost->scic_lock, flags); if (tmf->status == SCI_FAILURE_TIMEOUT) isci_request_mark_zombie(ihost, ireq); spin_unlock_irqrestore(&ihost->scic_lock, flags); } } isci_print_tmf(ihost, tmf); if (tmf->status == SCI_SUCCESS) ret = TMF_RESP_FUNC_COMPLETE; else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) { dev_dbg(&ihost->pdev->dev, "%s: tmf.status == " "SCI_FAILURE_IO_RESPONSE_VALID\n", __func__); ret = TMF_RESP_FUNC_COMPLETE; } dev_dbg(&ihost->pdev->dev, "%s: completed request = %p\n", __func__, ireq); return ret; err_tci: spin_lock_irqsave(&ihost->scic_lock, flags); isci_tci_free(ihost, ISCI_TAG_TCI(tag)); spin_unlock_irqrestore(&ihost->scic_lock, flags); return ret; }