2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 #include <linux/completion.h>
57 #include <linux/irqflags.h>
59 #include "scic_task_request.h"
60 #include "scic_io_request.h"
61 #include "remote_device.h"
62 #include "remote_node_context.h"
67 #include "scic_sds_request.h"
70 * isci_task_refuse() - complete the request to the upper layer driver in
71 * the case where an I/O needs to be completed back in the submit path.
72 * @ihost: host on which the the request was queued
73 * @task: request to complete
74 * @response: response code for the completed task.
75 * @status: status code for the completed task.
78 static void isci_task_refuse(struct isci_host
*ihost
, struct sas_task
*task
,
79 enum service_response response
,
80 enum exec_status status
)
83 enum isci_completion_selection disposition
;
85 disposition
= isci_perform_normal_io_completion
;
86 disposition
= isci_task_set_completion_status(task
, response
, status
,
89 /* Tasks aborted specifically by a call to the lldd_abort_task
90 * function should not be completed to the host in the regular path.
92 switch (disposition
) {
93 case isci_perform_normal_io_completion
:
94 /* Normal notification (task_done) */
95 dev_dbg(&ihost
->pdev
->dev
,
96 "%s: Normal - task = %p, response=%d, "
98 __func__
, task
, response
, status
);
100 task
->lldd_task
= NULL
;
102 isci_execpath_callback(ihost
, task
, task
->task_done
);
105 case isci_perform_aborted_io_completion
:
106 /* No notification because this request is already in the
109 dev_warn(&ihost
->pdev
->dev
,
110 "%s: Aborted - task = %p, response=%d, "
112 __func__
, task
, response
, status
);
115 case isci_perform_error_io_completion
:
116 /* Use sas_task_abort */
117 dev_warn(&ihost
->pdev
->dev
,
118 "%s: Error - task = %p, response=%d, "
120 __func__
, task
, response
, status
);
122 isci_execpath_callback(ihost
, task
, sas_task_abort
);
126 dev_warn(&ihost
->pdev
->dev
,
127 "%s: isci task notification default case!",
129 sas_task_abort(task
);
134 #define for_each_sas_task(num, task) \
135 for (; num > 0; num--,\
136 task = list_entry(task->list.next, struct sas_task, list))
139 * isci_task_execute_task() - This function is one of the SAS Domain Template
140 * functions. This function is called by libsas to send a task down to
142 * @task: This parameter specifies the SAS task to send.
143 * @num: This parameter specifies the number of tasks to queue.
144 * @gfp_flags: This parameter specifies the context of this call.
146 * status, zero indicates success.
148 int isci_task_execute_task(struct sas_task
*task
, int num
, gfp_t gfp_flags
)
150 struct isci_host
*ihost
= dev_to_ihost(task
->dev
);
151 struct isci_request
*request
= NULL
;
152 struct isci_remote_device
*device
;
155 enum sci_status status
;
156 enum isci_status device_status
;
158 dev_dbg(&ihost
->pdev
->dev
, "%s: num=%d\n", __func__
, num
);
160 /* Check if we have room for more tasks */
161 ret
= isci_host_can_queue(ihost
, num
);
164 dev_warn(&ihost
->pdev
->dev
, "%s: queue full\n", __func__
);
168 for_each_sas_task(num
, task
) {
169 dev_dbg(&ihost
->pdev
->dev
,
170 "task = %p, num = %d; dev = %p; cmd = %p\n",
171 task
, num
, task
->dev
, task
->uldd_task
);
173 device
= task
->dev
->lldd_dev
;
176 device_status
= device
->status
;
178 device_status
= isci_freed
;
180 /* From this point onward, any process that needs to guarantee
181 * that there is no kernel I/O being started will have to wait
182 * for the quiesce spinlock.
185 if (device_status
!= isci_ready_for_io
) {
187 /* Forces a retry from scsi mid layer. */
188 dev_dbg(&ihost
->pdev
->dev
,
189 "%s: task %p: isci_host->status = %d, "
190 "device = %p; device_status = 0x%x\n\n",
193 isci_host_get_state(ihost
),
197 if (device_status
== isci_ready
) {
198 /* Indicate QUEUE_FULL so that the scsi midlayer
201 isci_task_refuse(ihost
, task
,
205 /* Else, the device is going down. */
206 isci_task_refuse(ihost
, task
,
207 SAS_TASK_UNDELIVERED
,
210 isci_host_can_dequeue(ihost
, 1);
212 /* There is a device and it's ready for I/O. */
213 spin_lock_irqsave(&task
->task_state_lock
, flags
);
215 if (task
->task_state_flags
& SAS_TASK_STATE_ABORTED
) {
217 spin_unlock_irqrestore(&task
->task_state_lock
,
220 isci_task_refuse(ihost
, task
,
221 SAS_TASK_UNDELIVERED
,
222 SAM_STAT_TASK_ABORTED
);
224 /* The I/O was aborted. */
227 task
->task_state_flags
|= SAS_TASK_AT_INITIATOR
;
228 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
230 /* build and send the request. */
231 status
= isci_request_execute(ihost
, task
, &request
,
234 if (status
!= SCI_SUCCESS
) {
236 spin_lock_irqsave(&task
->task_state_lock
, flags
);
237 /* Did not really start this command. */
238 task
->task_state_flags
&= ~SAS_TASK_AT_INITIATOR
;
239 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
241 /* Indicate QUEUE_FULL so that the scsi
242 * midlayer retries. if the request
243 * failed for remote device reasons,
244 * it gets returned as
245 * SAS_TASK_UNDELIVERED next time
248 isci_task_refuse(ihost
, task
,
251 isci_host_can_dequeue(ihost
, 1);
262 * isci_task_request_build() - This function builds the task request object.
263 * @isci_host: This parameter specifies the ISCI host object
264 * @request: This parameter points to the isci_request object allocated in the
265 * request construct function.
266 * @tmf: This parameter is the task management struct to be built
268 * SCI_SUCCESS on successfull completion, or specific failure code.
270 static enum sci_status
isci_task_request_build(
271 struct isci_host
*isci_host
,
272 struct isci_request
**isci_request
,
273 struct isci_tmf
*isci_tmf
)
275 struct scic_sds_remote_device
*sci_device
;
276 enum sci_status status
= SCI_FAILURE
;
277 struct isci_request
*request
= NULL
;
278 struct isci_remote_device
*isci_device
;
279 struct domain_device
*dev
;
281 dev_dbg(&isci_host
->pdev
->dev
,
282 "%s: isci_tmf = %p\n", __func__
, isci_tmf
);
284 isci_device
= isci_tmf
->device
;
285 sci_device
= &isci_device
->sci
;
286 dev
= isci_device
->domain_dev
;
288 /* do common allocation and init of request object. */
289 status
= isci_request_alloc_tmf(
297 if (status
!= SCI_SUCCESS
)
300 /* let the core do it's construct. */
301 status
= scic_task_request_construct(
304 SCI_CONTROLLER_INVALID_IO_TAG
,
306 request
->sci_request_mem_ptr
,
307 &request
->sci_request_handle
310 if (status
!= SCI_SUCCESS
) {
311 dev_warn(&isci_host
->pdev
->dev
,
312 "%s: scic_task_request_construct failed - "
319 request
->sci_request_handle
->ireq
= request
;
321 /* XXX convert to get this from task->tproto like other drivers */
322 if (dev
->dev_type
== SAS_END_DEV
) {
323 isci_tmf
->proto
= SAS_PROTOCOL_SSP
;
324 status
= scic_task_request_construct_ssp(
325 request
->sci_request_handle
327 if (status
!= SCI_SUCCESS
)
331 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
332 isci_tmf
->proto
= SAS_PROTOCOL_SATA
;
333 status
= isci_sata_management_task_request_build(request
);
335 if (status
!= SCI_SUCCESS
)
343 /* release the dma memory if we fail. */
344 isci_request_free(isci_host
, request
);
348 *isci_request
= request
;
353 * isci_tmf_timeout_cb() - This function is called as a kernel callback when
354 * the timeout period for the TMF has expired.
358 static void isci_tmf_timeout_cb(void *tmf_request_arg
)
360 struct isci_request
*request
= (struct isci_request
*)tmf_request_arg
;
361 struct isci_tmf
*tmf
= isci_request_access_tmf(request
);
362 enum sci_status status
;
364 /* This task management request has timed-out. Terminate the request
365 * so that the request eventually completes to the requestor in the
366 * request completion callback path.
368 /* Note - the timer callback function itself has provided spinlock
369 * exclusion from the start and completion paths. No need to take
370 * the request->isci_host->scic_lock here.
373 if (tmf
->timeout_timer
!= NULL
) {
374 /* Call the users callback, if any. */
375 if (tmf
->cb_state_func
!= NULL
)
376 tmf
->cb_state_func(isci_tmf_timed_out
, tmf
,
379 /* Terminate the TMF transmit request. */
380 status
= scic_controller_terminate_request(
381 &request
->isci_host
->sci
,
382 &request
->isci_device
->sci
,
383 request
->sci_request_handle
386 dev_dbg(&request
->isci_host
->pdev
->dev
,
387 "%s: tmf_request = %p; tmf = %p; status = %d\n",
388 __func__
, request
, tmf
, status
);
390 dev_dbg(&request
->isci_host
->pdev
->dev
,
391 "%s: timer already canceled! "
392 "tmf_request = %p; tmf = %p\n",
393 __func__
, request
, tmf
);
395 /* No need to unlock since the caller to this callback is doing it for
397 * request->isci_host->scic_lock
402 * isci_task_execute_tmf() - This function builds and sends a task request,
403 * then waits for the completion.
404 * @isci_host: This parameter specifies the ISCI host object
405 * @tmf: This parameter is the pointer to the task management structure for
407 * @timeout_ms: This parameter specifies the timeout period for the task
408 * management request.
410 * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes
411 * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED.
413 int isci_task_execute_tmf(
414 struct isci_host
*isci_host
,
415 struct isci_tmf
*tmf
,
416 unsigned long timeout_ms
)
418 DECLARE_COMPLETION_ONSTACK(completion
);
419 enum sci_task_status status
= SCI_TASK_FAILURE
;
420 struct scic_sds_remote_device
*sci_device
;
421 struct isci_remote_device
*isci_device
= tmf
->device
;
422 struct isci_request
*request
;
423 int ret
= TMF_RESP_FUNC_FAILED
;
426 /* sanity check, return TMF_RESP_FUNC_FAILED
427 * if the device is not there and ready.
429 if (!isci_device
|| isci_device
->status
!= isci_ready_for_io
) {
430 dev_dbg(&isci_host
->pdev
->dev
,
431 "%s: isci_device = %p not ready (%d)\n",
433 isci_device
, isci_device
->status
);
434 return TMF_RESP_FUNC_FAILED
;
436 dev_dbg(&isci_host
->pdev
->dev
,
437 "%s: isci_device = %p\n",
438 __func__
, isci_device
);
440 sci_device
= &isci_device
->sci
;
442 /* Assign the pointer to the TMF's completion kernel wait structure. */
443 tmf
->complete
= &completion
;
445 isci_task_request_build(
452 dev_warn(&isci_host
->pdev
->dev
,
453 "%s: isci_task_request_build failed\n",
455 return TMF_RESP_FUNC_FAILED
;
458 /* Allocate the TMF timeout timer. */
459 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
460 tmf
->timeout_timer
= isci_timer_create(isci_host
, request
, isci_tmf_timeout_cb
);
462 /* Start the timer. */
463 if (tmf
->timeout_timer
)
464 isci_timer_start(tmf
->timeout_timer
, timeout_ms
);
466 dev_warn(&isci_host
->pdev
->dev
,
467 "%s: isci_timer_create failed!!!!\n",
470 /* start the TMF io. */
471 status
= scic_controller_start_task(
474 request
->sci_request_handle
,
475 SCI_CONTROLLER_INVALID_IO_TAG
478 if (status
!= SCI_TASK_SUCCESS
) {
479 dev_warn(&isci_host
->pdev
->dev
,
480 "%s: start_io failed - status = 0x%x, request = %p\n",
484 goto cleanup_request
;
487 /* Call the users callback, if any. */
488 if (tmf
->cb_state_func
!= NULL
)
489 tmf
->cb_state_func(isci_tmf_started
, tmf
, tmf
->cb_data
);
491 /* Change the state of the TMF-bearing request to "started". */
492 isci_request_change_state(request
, started
);
494 /* add the request to the remote device request list. */
495 list_add(&request
->dev_node
, &isci_device
->reqs_in_process
);
497 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
499 /* Wait for the TMF to complete, or a timeout. */
500 wait_for_completion(&completion
);
504 if (tmf
->status
== SCI_SUCCESS
)
505 ret
= TMF_RESP_FUNC_COMPLETE
;
506 else if (tmf
->status
== SCI_FAILURE_IO_RESPONSE_VALID
) {
507 dev_dbg(&isci_host
->pdev
->dev
,
509 "SCI_FAILURE_IO_RESPONSE_VALID\n",
511 ret
= TMF_RESP_FUNC_COMPLETE
;
513 /* Else - leave the default "failed" status alone. */
515 dev_dbg(&isci_host
->pdev
->dev
,
516 "%s: completed request = %p\n",
520 if (request
->io_request_completion
!= NULL
) {
522 /* The fact that this is non-NULL for a TMF request
523 * means there is a thread waiting for this TMF to
526 complete(request
->io_request_completion
);
529 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
533 /* Clean up the timer if needed. */
534 if (tmf
->timeout_timer
) {
535 isci_del_timer(isci_host
, tmf
->timeout_timer
);
536 tmf
->timeout_timer
= NULL
;
539 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
541 isci_request_free(isci_host
, request
);
546 void isci_task_build_tmf(
547 struct isci_tmf
*tmf
,
548 struct isci_remote_device
*isci_device
,
549 enum isci_tmf_function_codes code
,
550 void (*tmf_sent_cb
)(enum isci_tmf_cb_state
,
555 dev_dbg(&isci_device
->isci_port
->isci_host
->pdev
->dev
,
556 "%s: isci_device = %p\n", __func__
, isci_device
);
558 memset(tmf
, 0, sizeof(*tmf
));
560 tmf
->device
= isci_device
;
561 tmf
->tmf_code
= code
;
562 tmf
->timeout_timer
= NULL
;
563 tmf
->cb_state_func
= tmf_sent_cb
;
564 tmf
->cb_data
= cb_data
;
567 static void isci_task_build_abort_task_tmf(
568 struct isci_tmf
*tmf
,
569 struct isci_remote_device
*isci_device
,
570 enum isci_tmf_function_codes code
,
571 void (*tmf_sent_cb
)(enum isci_tmf_cb_state
,
574 struct isci_request
*old_request
)
576 isci_task_build_tmf(tmf
, isci_device
, code
, tmf_sent_cb
,
577 (void *)old_request
);
578 tmf
->io_tag
= old_request
->io_tag
;
581 static struct isci_request
*isci_task_get_request_from_task(
582 struct sas_task
*task
,
583 struct isci_remote_device
**isci_device
)
586 struct isci_request
*request
= NULL
;
589 spin_lock_irqsave(&task
->task_state_lock
, flags
);
591 request
= task
->lldd_task
;
593 /* If task is already done, the request isn't valid */
594 if (!(task
->task_state_flags
& SAS_TASK_STATE_DONE
) &&
595 (task
->task_state_flags
& SAS_TASK_AT_INITIATOR
) &&
598 if (isci_device
!= NULL
)
599 *isci_device
= request
->isci_device
;
602 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
608 * isci_task_validate_request_to_abort() - This function checks the given I/O
609 * against the "started" state. If the request is still "started", it's
610 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
611 * BEFORE CALLING THIS FUNCTION.
612 * @isci_request: This parameter specifies the request object to control.
613 * @isci_host: This parameter specifies the ISCI host object
614 * @isci_device: This is the device to which the request is pending.
615 * @aborted_io_completion: This is a completion structure that will be added to
616 * the request in case it is changed to aborting; this completion is
617 * triggered when the request is fully completed.
619 * Either "started" on successful change of the task status to "aborted", or
620 * "unallocated" if the task cannot be controlled.
622 static enum isci_request_status
isci_task_validate_request_to_abort(
623 struct isci_request
*isci_request
,
624 struct isci_host
*isci_host
,
625 struct isci_remote_device
*isci_device
,
626 struct completion
*aborted_io_completion
)
628 enum isci_request_status old_state
= unallocated
;
630 /* Only abort the task if it's in the
631 * device's request_in_process list
633 if (isci_request
&& !list_empty(&isci_request
->dev_node
)) {
634 old_state
= isci_request_change_started_to_aborted(
635 isci_request
, aborted_io_completion
);
642 static void isci_request_cleanup_completed_loiterer(
643 struct isci_host
*isci_host
,
644 struct isci_remote_device
*isci_device
,
645 struct isci_request
*isci_request
)
647 struct sas_task
*task
;
650 task
= (isci_request
->ttype
== io_task
)
651 ? isci_request_access_task(isci_request
)
654 dev_dbg(&isci_host
->pdev
->dev
,
655 "%s: isci_device=%p, request=%p, task=%p\n",
656 __func__
, isci_device
, isci_request
, task
);
658 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
659 list_del_init(&isci_request
->dev_node
);
660 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
664 spin_lock_irqsave(&task
->task_state_lock
, flags
);
665 task
->lldd_task
= NULL
;
667 isci_set_task_doneflags(task
);
669 /* If this task is not in the abort path, call task_done. */
670 if (!(task
->task_state_flags
& SAS_TASK_STATE_ABORTED
)) {
672 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
673 task
->task_done(task
);
675 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
677 isci_request_free(isci_host
, isci_request
);
681 * @isci_termination_timed_out(): this function will deal with a request for
682 * which the wait for termination has timed-out.
684 * @isci_host This SCU.
685 * @isci_request The I/O request being terminated.
688 isci_termination_timed_out(
689 struct isci_host
* host
,
690 struct isci_request
* request
693 unsigned long state_flags
;
695 dev_warn(&host
->pdev
->dev
,
696 "%s: host = %p; request = %p\n",
697 __func__
, host
, request
);
699 /* At this point, the request to terminate
700 * has timed out. The best we can do is to
701 * have the request die a silent death
702 * if it ever completes.
704 spin_lock_irqsave(&request
->state_lock
, state_flags
);
706 if (request
->status
== started
) {
708 /* Set the request state to "dead",
709 * and clear the task pointer so that an actual
710 * completion event callback doesn't do
713 request
->status
= dead
;
715 /* Clear the timeout completion event pointer.*/
716 request
->io_request_completion
= NULL
;
718 if (request
->ttype
== io_task
) {
720 /* Break links with the sas_task. */
721 if (request
->ttype_ptr
.io_task_ptr
!= NULL
) {
723 request
->ttype_ptr
.io_task_ptr
->lldd_task
= NULL
;
724 request
->ttype_ptr
.io_task_ptr
= NULL
;
728 spin_unlock_irqrestore(&request
->state_lock
, state_flags
);
733 * isci_terminate_request_core() - This function will terminate the given
734 * request, and wait for it to complete. This function must only be called
735 * from a thread that can wait. Note that the request is terminated and
736 * completed (back to the host, if started there).
737 * @isci_host: This SCU.
738 * @isci_device: The target.
739 * @isci_request: The I/O request to be terminated.
743 static void isci_terminate_request_core(
744 struct isci_host
*isci_host
,
745 struct isci_remote_device
*isci_device
,
746 struct isci_request
*isci_request
)
748 enum sci_status status
= SCI_SUCCESS
;
749 bool was_terminated
= false;
750 bool needs_cleanup_handling
= false;
751 enum isci_request_status request_status
;
753 unsigned long timeout_remaining
;
756 dev_dbg(&isci_host
->pdev
->dev
,
757 "%s: device = %p; request = %p\n",
758 __func__
, isci_device
, isci_request
);
760 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
762 /* Note that we are not going to control
763 * the target to abort the request.
765 isci_request
->complete_in_target
= true;
767 /* Make sure the request wasn't just sitting around signalling
768 * device condition (if the request handle is NULL, then the
769 * request completed but needed additional handling here).
771 if (isci_request
->sci_request_handle
!= NULL
) {
772 was_terminated
= true;
773 needs_cleanup_handling
= true;
774 status
= scic_controller_terminate_request(
777 isci_request
->sci_request_handle
);
779 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
782 * The only time the request to terminate will
783 * fail is when the io request is completed and
786 if (status
!= SCI_SUCCESS
) {
787 dev_err(&isci_host
->pdev
->dev
,
788 "%s: scic_controller_terminate_request"
789 " returned = 0x%x\n",
792 /* Clear the completion pointer from the request. */
793 isci_request
->io_request_completion
= NULL
;
796 if (was_terminated
) {
797 dev_dbg(&isci_host
->pdev
->dev
,
798 "%s: before completion wait (%p)\n",
800 isci_request
->io_request_completion
);
802 /* Wait here for the request to complete. */
803 #define TERMINATION_TIMEOUT_MSEC 50
805 = wait_for_completion_timeout(
806 isci_request
->io_request_completion
,
807 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC
));
809 if (!timeout_remaining
) {
811 isci_termination_timed_out(isci_host
,
814 dev_err(&isci_host
->pdev
->dev
,
815 "%s: *** Timeout waiting for "
816 "termination(%p/%p)\n",
818 isci_request
->io_request_completion
,
822 dev_dbg(&isci_host
->pdev
->dev
,
823 "%s: after completion wait (%p)\n",
825 isci_request
->io_request_completion
);
827 /* Clear the completion pointer from the request. */
828 isci_request
->io_request_completion
= NULL
;
830 /* Peek at the status of the request. This will tell
831 * us if there was special handling on the request such that it
832 * needs to be detached and freed here.
834 spin_lock_irqsave(&isci_request
->state_lock
, flags
);
835 request_status
= isci_request_get_state(isci_request
);
837 if ((isci_request
->ttype
== io_task
) /* TMFs are in their own thread */
838 && ((request_status
== aborted
)
839 || (request_status
== aborting
)
840 || (request_status
== terminating
)
841 || (request_status
== completed
)
842 || (request_status
== dead
)
846 /* The completion routine won't free a request in
847 * the aborted/aborting/etc. states, so we do
850 needs_cleanup_handling
= true;
852 spin_unlock_irqrestore(&isci_request
->state_lock
, flags
);
854 if (needs_cleanup_handling
)
855 isci_request_cleanup_completed_loiterer(
856 isci_host
, isci_device
, isci_request
861 static void isci_terminate_request(
862 struct isci_host
*isci_host
,
863 struct isci_remote_device
*isci_device
,
864 struct isci_request
*isci_request
,
865 enum isci_request_status new_request_state
)
867 enum isci_request_status old_state
;
868 DECLARE_COMPLETION_ONSTACK(request_completion
);
870 /* Change state to "new_request_state" if it is currently "started" */
871 old_state
= isci_request_change_started_to_newstate(
877 if ((old_state
== started
) ||
878 (old_state
== completed
) ||
879 (old_state
== aborting
)) {
881 /* If the old_state is started:
882 * This request was not already being aborted. If it had been,
883 * then the aborting I/O (ie. the TMF request) would not be in
884 * the aborting state, and thus would be terminated here. Note
885 * that since the TMF completion's call to the kernel function
886 * "complete()" does not happen until the pending I/O request
887 * terminate fully completes, we do not have to implement a
888 * special wait here for already aborting requests - the
889 * termination of the TMF request will force the request
890 * to finish it's already started terminate.
892 * If old_state == completed:
893 * This request completed from the SCU hardware perspective
894 * and now just needs cleaning up in terms of freeing the
895 * request and potentially calling up to libsas.
897 * If old_state == aborting:
898 * This request has already gone through a TMF timeout, but may
899 * not have been terminated; needs cleaning up at least.
901 isci_terminate_request_core(isci_host
, isci_device
,
907 * isci_terminate_pending_requests() - This function will change the all of the
908 * requests on the given device's state to "aborting", will terminate the
909 * requests, and wait for them to complete. This function must only be
910 * called from a thread that can wait. Note that the requests are all
911 * terminated and completed (back to the host, if started there).
912 * @isci_host: This parameter specifies SCU.
913 * @isci_device: This parameter specifies the target.
917 void isci_terminate_pending_requests(
918 struct isci_host
*isci_host
,
919 struct isci_remote_device
*isci_device
,
920 enum isci_request_status new_request_state
)
922 struct isci_request
*request
;
923 struct isci_request
*next_request
;
925 struct list_head aborted_request_list
;
927 INIT_LIST_HEAD(&aborted_request_list
);
929 dev_dbg(&isci_host
->pdev
->dev
,
930 "%s: isci_device = %p (new request state = %d)\n",
931 __func__
, isci_device
, new_request_state
);
933 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
935 /* Move all of the pending requests off of the device list. */
936 list_splice_init(&isci_device
->reqs_in_process
,
937 &aborted_request_list
);
939 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
941 /* Iterate through the now-local list. */
942 list_for_each_entry_safe(request
, next_request
,
943 &aborted_request_list
, dev_node
) {
945 dev_warn(&isci_host
->pdev
->dev
,
946 "%s: isci_device=%p request=%p; task=%p\n",
948 isci_device
, request
,
949 ((request
->ttype
== io_task
)
950 ? isci_request_access_task(request
)
953 /* Mark all still pending I/O with the selected next
954 * state, terminate and free it.
956 isci_terminate_request(isci_host
, isci_device
,
957 request
, new_request_state
963 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
964 * Template functions.
965 * @lun: This parameter specifies the lun to be reset.
967 * status, zero indicates success.
969 static int isci_task_send_lu_reset_sas(
970 struct isci_host
*isci_host
,
971 struct isci_remote_device
*isci_device
,
975 int ret
= TMF_RESP_FUNC_FAILED
;
977 dev_dbg(&isci_host
->pdev
->dev
,
978 "%s: isci_host = %p, isci_device = %p\n",
979 __func__
, isci_host
, isci_device
);
980 /* Send the LUN reset to the target. By the time the call returns,
981 * the TMF has fully exected in the target (in which case the return
982 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
983 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
985 isci_task_build_tmf(&tmf
, isci_device
, isci_tmf_ssp_lun_reset
, NULL
,
988 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
989 ret
= isci_task_execute_tmf(isci_host
, &tmf
, ISCI_LU_RESET_TIMEOUT_MS
);
991 if (ret
== TMF_RESP_FUNC_COMPLETE
)
992 dev_dbg(&isci_host
->pdev
->dev
,
993 "%s: %p: TMF_LU_RESET passed\n",
994 __func__
, isci_device
);
996 dev_dbg(&isci_host
->pdev
->dev
,
997 "%s: %p: TMF_LU_RESET failed (%x)\n",
998 __func__
, isci_device
, ret
);
1004 * isci_task_lu_reset() - This function is one of the SAS Domain Template
1005 * functions. This is one of the Task Management functoins called by libsas,
1006 * to reset the given lun. Note the assumption that while this call is
1007 * executing, no I/O will be sent by the host to the device.
1008 * @lun: This parameter specifies the lun to be reset.
1010 * status, zero indicates success.
1012 int isci_task_lu_reset(struct domain_device
*domain_device
, u8
*lun
)
1014 struct isci_host
*isci_host
= dev_to_ihost(domain_device
);
1015 struct isci_remote_device
*isci_device
= NULL
;
1017 bool device_stopping
= false;
1019 isci_device
= domain_device
->lldd_dev
;
1021 dev_dbg(&isci_host
->pdev
->dev
,
1022 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
1023 __func__
, domain_device
, isci_host
, isci_device
);
1025 if (isci_device
!= NULL
) {
1026 device_stopping
= (isci_device
->status
== isci_stopping
)
1027 || (isci_device
->status
== isci_stopped
);
1028 set_bit(IDEV_EH
, &isci_device
->flags
);
1031 /* If there is a device reset pending on any request in the
1032 * device's list, fail this LUN reset request in order to
1033 * escalate to the device reset.
1035 if (!isci_device
|| device_stopping
||
1036 isci_device_is_reset_pending(isci_host
, isci_device
)) {
1037 dev_warn(&isci_host
->pdev
->dev
,
1038 "%s: No dev (%p), or "
1039 "RESET PENDING: domain_device=%p\n",
1040 __func__
, isci_device
, domain_device
);
1041 return TMF_RESP_FUNC_FAILED
;
1044 /* Send the task management part of the reset. */
1045 if (sas_protocol_ata(domain_device
->tproto
)) {
1046 ret
= isci_task_send_lu_reset_sata(isci_host
, isci_device
, lun
);
1048 ret
= isci_task_send_lu_reset_sas(isci_host
, isci_device
, lun
);
1050 /* If the LUN reset worked, all the I/O can now be terminated. */
1051 if (ret
== TMF_RESP_FUNC_COMPLETE
)
1052 /* Terminate all I/O now. */
1053 isci_terminate_pending_requests(isci_host
,
1061 /* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
1062 int isci_task_clear_nexus_port(struct asd_sas_port
*port
)
1064 return TMF_RESP_FUNC_FAILED
;
1069 int isci_task_clear_nexus_ha(struct sas_ha_struct
*ha
)
1071 return TMF_RESP_FUNC_FAILED
;
1074 /* Task Management Functions. Must be called from process context. */
1077 * isci_abort_task_process_cb() - This is a helper function for the abort task
1078 * TMF command. It manages the request state with respect to the successful
1079 * transmission / completion of the abort task request.
1080 * @cb_state: This parameter specifies when this function was called - after
1081 * the TMF request has been started and after it has timed-out.
1082 * @tmf: This parameter specifies the TMF in progress.
1086 static void isci_abort_task_process_cb(
1087 enum isci_tmf_cb_state cb_state
,
1088 struct isci_tmf
*tmf
,
1091 struct isci_request
*old_request
;
1093 old_request
= (struct isci_request
*)cb_data
;
1095 dev_dbg(&old_request
->isci_host
->pdev
->dev
,
1096 "%s: tmf=%p, old_request=%p\n",
1097 __func__
, tmf
, old_request
);
1101 case isci_tmf_started
:
1102 /* The TMF has been started. Nothing to do here, since the
1103 * request state was already set to "aborted" by the abort
1106 if ((old_request
->status
!= aborted
)
1107 && (old_request
->status
!= completed
))
1108 dev_err(&old_request
->isci_host
->pdev
->dev
,
1109 "%s: Bad request status (%d): tmf=%p, old_request=%p\n",
1110 __func__
, old_request
->status
, tmf
, old_request
);
1113 case isci_tmf_timed_out
:
1115 /* Set the task's state to "aborting", since the abort task
1116 * function thread set it to "aborted" (above) in anticipation
1117 * of the task management request working correctly. Since the
1118 * timeout has now fired, the TMF request failed. We set the
1119 * state such that the request completion will indicate the
1120 * device is no longer present.
1122 isci_request_change_state(old_request
, aborting
);
1126 dev_err(&old_request
->isci_host
->pdev
->dev
,
1127 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1128 __func__
, cb_state
, tmf
, old_request
);
1134 * isci_task_abort_task() - This function is one of the SAS Domain Template
1135 * functions. This function is called by libsas to abort a specified task.
1136 * @task: This parameter specifies the SAS task to abort.
1138 * status, zero indicates success.
1140 int isci_task_abort_task(struct sas_task
*task
)
1142 struct isci_host
*isci_host
= dev_to_ihost(task
->dev
);
1143 DECLARE_COMPLETION_ONSTACK(aborted_io_completion
);
1144 struct isci_request
*old_request
= NULL
;
1145 enum isci_request_status old_state
;
1146 struct isci_remote_device
*isci_device
= NULL
;
1147 struct isci_tmf tmf
;
1148 int ret
= TMF_RESP_FUNC_FAILED
;
1149 unsigned long flags
;
1150 bool any_dev_reset
= false;
1151 bool device_stopping
;
1153 /* Get the isci_request reference from the task. Note that
1154 * this check does not depend on the pending request list
1155 * in the device, because tasks driving resets may land here
1156 * after completion in the core.
1158 old_request
= isci_task_get_request_from_task(task
, &isci_device
);
1160 dev_dbg(&isci_host
->pdev
->dev
,
1161 "%s: task = %p\n", __func__
, task
);
1163 /* Check if the device has been / is currently being removed.
1164 * If so, no task management will be done, and the I/O will
1167 device_stopping
= (isci_device
->status
== isci_stopping
)
1168 || (isci_device
->status
== isci_stopped
);
1170 /* XXX need to fix device lookup lifetime (needs to be done
1171 * under scic_lock, among other things...), but for now assume
1172 * the device is available like the above code
1174 set_bit(IDEV_EH
, &isci_device
->flags
);
1176 /* This version of the driver will fail abort requests for
1177 * SATA/STP. Failing the abort request this way will cause the
1178 * SCSI error handler thread to escalate to LUN reset
1180 if (sas_protocol_ata(task
->task_proto
) && !device_stopping
) {
1181 dev_warn(&isci_host
->pdev
->dev
,
1182 " task %p is for a STP/SATA device;"
1183 " returning TMF_RESP_FUNC_FAILED\n"
1184 " to cause a LUN reset...\n", task
);
1185 return TMF_RESP_FUNC_FAILED
;
1188 dev_dbg(&isci_host
->pdev
->dev
,
1189 "%s: old_request == %p\n", __func__
, old_request
);
1191 if (!device_stopping
)
1192 any_dev_reset
= isci_device_is_reset_pending(isci_host
,isci_device
);
1194 spin_lock_irqsave(&task
->task_state_lock
, flags
);
1196 /* Don't do resets to stopping devices. */
1197 if (device_stopping
) {
1199 task
->task_state_flags
&= ~SAS_TASK_NEED_DEV_RESET
;
1200 any_dev_reset
= false;
1202 } else /* See if there is a pending device reset for this device. */
1203 any_dev_reset
= any_dev_reset
1204 || (task
->task_state_flags
& SAS_TASK_NEED_DEV_RESET
);
1206 /* If the extraction of the request reference from the task
1207 * failed, then the request has been completed (or if there is a
1208 * pending reset then this abort request function must be failed
1209 * in order to escalate to the target reset).
1211 if ((old_request
== NULL
) || any_dev_reset
) {
1213 /* If the device reset task flag is set, fail the task
1214 * management request. Otherwise, the original request
1217 if (any_dev_reset
) {
1219 /* Turn off the task's DONE to make sure this
1220 * task is escalated to a target reset.
1222 task
->task_state_flags
&= ~SAS_TASK_STATE_DONE
;
1224 /* Make the reset happen as soon as possible. */
1225 task
->task_state_flags
|= SAS_TASK_NEED_DEV_RESET
;
1227 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1229 /* Fail the task management request in order to
1230 * escalate to the target reset.
1232 ret
= TMF_RESP_FUNC_FAILED
;
1234 dev_dbg(&isci_host
->pdev
->dev
,
1235 "%s: Failing task abort in order to "
1236 "escalate to target reset because\n"
1237 "SAS_TASK_NEED_DEV_RESET is set for "
1238 "task %p on dev %p\n",
1239 __func__
, task
, isci_device
);
1243 /* The request has already completed and there
1244 * is nothing to do here other than to set the task
1245 * done bit, and indicate that the task abort function
1248 isci_set_task_doneflags(task
);
1250 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1252 ret
= TMF_RESP_FUNC_COMPLETE
;
1254 dev_dbg(&isci_host
->pdev
->dev
,
1255 "%s: abort task not needed for %p\n",
1262 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1264 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
1266 /* Check the request status and change to "aborted" if currently
1267 * "starting"; if true then set the I/O kernel completion
1268 * struct that will be triggered when the request completes.
1270 old_state
= isci_task_validate_request_to_abort(
1271 old_request
, isci_host
, isci_device
,
1272 &aborted_io_completion
);
1273 if ((old_state
!= started
) &&
1274 (old_state
!= completed
) &&
1275 (old_state
!= aborting
)) {
1277 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1279 /* The request was already being handled by someone else (because
1280 * they got to set the state away from started).
1282 dev_dbg(&isci_host
->pdev
->dev
,
1283 "%s: device = %p; old_request %p already being aborted\n",
1285 isci_device
, old_request
);
1287 return TMF_RESP_FUNC_COMPLETE
;
1289 if ((task
->task_proto
== SAS_PROTOCOL_SMP
)
1291 || old_request
->complete_in_target
1294 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1296 dev_dbg(&isci_host
->pdev
->dev
,
1297 "%s: SMP request (%d)"
1298 " or device is stopping (%d)"
1299 " or complete_in_target (%d), thus no TMF\n",
1300 __func__
, (task
->task_proto
== SAS_PROTOCOL_SMP
),
1301 device_stopping
, old_request
->complete_in_target
);
1303 /* Set the state on the task. */
1304 isci_task_all_done(task
);
1306 ret
= TMF_RESP_FUNC_COMPLETE
;
1308 /* Stopping and SMP devices are not sent a TMF, and are not
1309 * reset, but the outstanding I/O request is terminated below.
1312 /* Fill in the tmf stucture */
1313 isci_task_build_abort_task_tmf(&tmf
, isci_device
,
1314 isci_tmf_ssp_task_abort
,
1315 isci_abort_task_process_cb
,
1318 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1320 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */
1321 ret
= isci_task_execute_tmf(isci_host
, &tmf
,
1322 ISCI_ABORT_TASK_TIMEOUT_MS
);
1324 if (ret
!= TMF_RESP_FUNC_COMPLETE
)
1325 dev_err(&isci_host
->pdev
->dev
,
1326 "%s: isci_task_send_tmf failed\n",
1329 if (ret
== TMF_RESP_FUNC_COMPLETE
) {
1330 old_request
->complete_in_target
= true;
1332 /* Clean up the request on our side, and wait for the aborted I/O to
1335 isci_terminate_request_core(isci_host
, isci_device
, old_request
);
1338 /* Make sure we do not leave a reference to aborted_io_completion */
1339 old_request
->io_request_completion
= NULL
;
1344 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
1345 * functions. This is one of the Task Management functoins called by libsas,
1346 * to abort all task for the given lun.
1347 * @d_device: This parameter specifies the domain device associated with this
1349 * @lun: This parameter specifies the lun associated with this request.
1351 * status, zero indicates success.
1353 int isci_task_abort_task_set(
1354 struct domain_device
*d_device
,
1357 return TMF_RESP_FUNC_FAILED
;
1362 * isci_task_clear_aca() - This function is one of the SAS Domain Template
1363 * functions. This is one of the Task Management functoins called by libsas.
1364 * @d_device: This parameter specifies the domain device associated with this
1366 * @lun: This parameter specifies the lun associated with this request.
1368 * status, zero indicates success.
1370 int isci_task_clear_aca(
1371 struct domain_device
*d_device
,
1374 return TMF_RESP_FUNC_FAILED
;
1380 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
1381 * functions. This is one of the Task Management functoins called by libsas.
1382 * @d_device: This parameter specifies the domain device associated with this
1384 * @lun: This parameter specifies the lun associated with this request.
1386 * status, zero indicates success.
1388 int isci_task_clear_task_set(
1389 struct domain_device
*d_device
,
1392 return TMF_RESP_FUNC_FAILED
;
1397 * isci_task_query_task() - This function is implemented to cause libsas to
1398 * correctly escalate the failed abort to a LUN or target reset (this is
1399 * because sas_scsi_find_task libsas function does not correctly interpret
1400 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
1401 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
1402 * returned, libsas will turn this into a target reset
1403 * @task: This parameter specifies the sas task being queried.
1404 * @lun: This parameter specifies the lun associated with this request.
1406 * status, zero indicates success.
1408 int isci_task_query_task(
1409 struct sas_task
*task
)
1411 /* See if there is a pending device reset for this device. */
1412 if (task
->task_state_flags
& SAS_TASK_NEED_DEV_RESET
)
1413 return TMF_RESP_FUNC_FAILED
;
1415 return TMF_RESP_FUNC_SUCC
;
1419 * isci_task_request_complete() - This function is called by the sci core when
1420 * an task request completes.
1421 * @ihost: This parameter specifies the ISCI host object
1422 * @ireq: This parameter is the completed isci_request object.
1423 * @completion_status: This parameter specifies the completion status from the
1429 isci_task_request_complete(struct isci_host
*ihost
,
1430 struct isci_request
*ireq
,
1431 enum sci_task_status completion_status
)
1433 struct isci_remote_device
*idev
= ireq
->isci_device
;
1434 enum isci_request_status old_state
;
1435 struct isci_tmf
*tmf
= isci_request_access_tmf(ireq
);
1436 struct completion
*tmf_complete
;
1437 struct scic_sds_request
*sci_req
= ireq
->sci_request_handle
;
1438 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
1440 dev_dbg(&ihost
->pdev
->dev
,
1441 "%s: request = %p, status=%d\n",
1442 __func__
, ireq
, completion_status
);
1444 old_state
= isci_request_change_state(ireq
, completed
);
1446 tmf
->status
= completion_status
;
1447 ireq
->complete_in_target
= true;
1449 if (tmf
->proto
== SAS_PROTOCOL_SSP
) {
1450 memcpy(&tmf
->resp
.resp_iu
,
1451 sci_req
->response_buffer
,
1452 SSP_RESP_IU_MAX_SIZE
);
1453 } else if (tmf
->proto
== SAS_PROTOCOL_SATA
) {
1454 memcpy(&tmf
->resp
.d2h_fis
,
1455 &stp_req
->d2h_reg_fis
,
1456 sizeof(struct dev_to_host_fis
));
1459 /* Manage the timer if it is still running. */
1460 if (tmf
->timeout_timer
) {
1461 isci_del_timer(ihost
, tmf
->timeout_timer
);
1462 tmf
->timeout_timer
= NULL
;
1465 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1466 tmf_complete
= tmf
->complete
;
1468 scic_controller_complete_io(&ihost
->sci
, &idev
->sci
,
1469 ireq
->sci_request_handle
);
1470 /* NULL the request handle to make sure it cannot be terminated
1471 * or completed again.
1473 ireq
->sci_request_handle
= NULL
;
1475 isci_request_change_state(ireq
, unallocated
);
1476 list_del_init(&ireq
->dev_node
);
1478 /* The task management part completes last. */
1479 complete(tmf_complete
);
1482 static int isci_reset_device(struct domain_device
*dev
, int hard_reset
)
1484 struct isci_remote_device
*idev
= dev
->lldd_dev
;
1485 struct sas_phy
*phy
= sas_find_local_phy(dev
);
1486 struct isci_host
*ihost
= dev_to_ihost(dev
);
1487 enum sci_status status
;
1488 unsigned long flags
;
1491 dev_dbg(&ihost
->pdev
->dev
, "%s: idev %p\n", __func__
, idev
);
1494 dev_warn(&ihost
->pdev
->dev
,
1495 "%s: idev is GONE!\n",
1498 return TMF_RESP_FUNC_COMPLETE
; /* Nothing to reset. */
1501 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1502 status
= scic_remote_device_reset(&idev
->sci
);
1503 if (status
!= SCI_SUCCESS
) {
1504 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1506 dev_warn(&ihost
->pdev
->dev
,
1507 "%s: scic_remote_device_reset(%p) returned %d!\n",
1508 __func__
, idev
, status
);
1510 return TMF_RESP_FUNC_FAILED
;
1512 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1514 /* Make sure all pending requests are able to be fully terminated. */
1515 isci_device_clear_reset_pending(ihost
, idev
);
1517 rc
= sas_phy_reset(phy
, hard_reset
);
1518 msleep(2000); /* just like mvsas */
1520 /* Terminate in-progress I/O now. */
1521 isci_remote_device_nuke_requests(ihost
, idev
);
1523 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1524 status
= scic_remote_device_reset_complete(&idev
->sci
);
1525 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1527 if (status
!= SCI_SUCCESS
) {
1528 dev_warn(&ihost
->pdev
->dev
,
1529 "%s: scic_remote_device_reset_complete(%p) "
1530 "returned %d!\n", __func__
, idev
, status
);
1533 dev_dbg(&ihost
->pdev
->dev
, "%s: idev %p complete.\n", __func__
, idev
);
1538 int isci_task_I_T_nexus_reset(struct domain_device
*dev
)
1540 struct isci_host
*ihost
= dev_to_ihost(dev
);
1541 int ret
= TMF_RESP_FUNC_FAILED
, hard_reset
= 1;
1542 struct isci_remote_device
*idev
;
1543 unsigned long flags
;
1545 /* XXX mvsas is not protecting against ->lldd_dev_gone(), are we
1546 * being too paranoid, or is mvsas busted?!
1548 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1549 idev
= dev
->lldd_dev
;
1550 if (!idev
|| !test_bit(IDEV_EH
, &idev
->flags
))
1551 ret
= TMF_RESP_FUNC_COMPLETE
;
1552 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1554 if (ret
== TMF_RESP_FUNC_COMPLETE
)
1557 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))
1560 return isci_reset_device(dev
, hard_reset
);
1563 int isci_bus_reset_handler(struct scsi_cmnd
*cmd
)
1565 struct domain_device
*dev
= sdev_to_domain_dev(cmd
->device
);
1568 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))
1571 return isci_reset_device(dev
, hard_reset
);