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(&isci_host
->sci
, sci_device
,
302 SCI_CONTROLLER_INVALID_IO_TAG
,
303 request
, &request
->sci_req
,
304 &request
->sci_request_handle
);
306 if (status
!= SCI_SUCCESS
) {
307 dev_warn(&isci_host
->pdev
->dev
,
308 "%s: scic_task_request_construct failed - "
315 request
->sci_request_handle
->ireq
= request
;
317 /* XXX convert to get this from task->tproto like other drivers */
318 if (dev
->dev_type
== SAS_END_DEV
) {
319 isci_tmf
->proto
= SAS_PROTOCOL_SSP
;
320 status
= scic_task_request_construct_ssp(
321 request
->sci_request_handle
323 if (status
!= SCI_SUCCESS
)
327 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
328 isci_tmf
->proto
= SAS_PROTOCOL_SATA
;
329 status
= isci_sata_management_task_request_build(request
);
331 if (status
!= SCI_SUCCESS
)
339 /* release the dma memory if we fail. */
340 isci_request_free(isci_host
, request
);
344 *isci_request
= request
;
349 * isci_tmf_timeout_cb() - This function is called as a kernel callback when
350 * the timeout period for the TMF has expired.
354 static void isci_tmf_timeout_cb(void *tmf_request_arg
)
356 struct isci_request
*request
= (struct isci_request
*)tmf_request_arg
;
357 struct isci_tmf
*tmf
= isci_request_access_tmf(request
);
358 enum sci_status status
;
360 /* This task management request has timed-out. Terminate the request
361 * so that the request eventually completes to the requestor in the
362 * request completion callback path.
364 /* Note - the timer callback function itself has provided spinlock
365 * exclusion from the start and completion paths. No need to take
366 * the request->isci_host->scic_lock here.
369 if (tmf
->timeout_timer
!= NULL
) {
370 /* Call the users callback, if any. */
371 if (tmf
->cb_state_func
!= NULL
)
372 tmf
->cb_state_func(isci_tmf_timed_out
, tmf
,
375 /* Terminate the TMF transmit request. */
376 status
= scic_controller_terminate_request(
377 &request
->isci_host
->sci
,
378 &request
->isci_device
->sci
,
379 request
->sci_request_handle
382 dev_dbg(&request
->isci_host
->pdev
->dev
,
383 "%s: tmf_request = %p; tmf = %p; status = %d\n",
384 __func__
, request
, tmf
, status
);
386 dev_dbg(&request
->isci_host
->pdev
->dev
,
387 "%s: timer already canceled! "
388 "tmf_request = %p; tmf = %p\n",
389 __func__
, request
, tmf
);
391 /* No need to unlock since the caller to this callback is doing it for
393 * request->isci_host->scic_lock
398 * isci_task_execute_tmf() - This function builds and sends a task request,
399 * then waits for the completion.
400 * @isci_host: This parameter specifies the ISCI host object
401 * @tmf: This parameter is the pointer to the task management structure for
403 * @timeout_ms: This parameter specifies the timeout period for the task
404 * management request.
406 * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes
407 * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED.
409 int isci_task_execute_tmf(
410 struct isci_host
*isci_host
,
411 struct isci_tmf
*tmf
,
412 unsigned long timeout_ms
)
414 DECLARE_COMPLETION_ONSTACK(completion
);
415 enum sci_task_status status
= SCI_TASK_FAILURE
;
416 struct scic_sds_remote_device
*sci_device
;
417 struct isci_remote_device
*isci_device
= tmf
->device
;
418 struct isci_request
*request
;
419 int ret
= TMF_RESP_FUNC_FAILED
;
422 /* sanity check, return TMF_RESP_FUNC_FAILED
423 * if the device is not there and ready.
425 if (!isci_device
|| isci_device
->status
!= isci_ready_for_io
) {
426 dev_dbg(&isci_host
->pdev
->dev
,
427 "%s: isci_device = %p not ready (%d)\n",
429 isci_device
, isci_device
->status
);
430 return TMF_RESP_FUNC_FAILED
;
432 dev_dbg(&isci_host
->pdev
->dev
,
433 "%s: isci_device = %p\n",
434 __func__
, isci_device
);
436 sci_device
= &isci_device
->sci
;
438 /* Assign the pointer to the TMF's completion kernel wait structure. */
439 tmf
->complete
= &completion
;
441 isci_task_request_build(
448 dev_warn(&isci_host
->pdev
->dev
,
449 "%s: isci_task_request_build failed\n",
451 return TMF_RESP_FUNC_FAILED
;
454 /* Allocate the TMF timeout timer. */
455 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
456 tmf
->timeout_timer
= isci_timer_create(isci_host
, request
, isci_tmf_timeout_cb
);
458 /* Start the timer. */
459 if (tmf
->timeout_timer
)
460 isci_timer_start(tmf
->timeout_timer
, timeout_ms
);
462 dev_warn(&isci_host
->pdev
->dev
,
463 "%s: isci_timer_create failed!!!!\n",
466 /* start the TMF io. */
467 status
= scic_controller_start_task(
470 request
->sci_request_handle
,
471 SCI_CONTROLLER_INVALID_IO_TAG
474 if (status
!= SCI_TASK_SUCCESS
) {
475 dev_warn(&isci_host
->pdev
->dev
,
476 "%s: start_io failed - status = 0x%x, request = %p\n",
480 goto cleanup_request
;
483 /* Call the users callback, if any. */
484 if (tmf
->cb_state_func
!= NULL
)
485 tmf
->cb_state_func(isci_tmf_started
, tmf
, tmf
->cb_data
);
487 /* Change the state of the TMF-bearing request to "started". */
488 isci_request_change_state(request
, started
);
490 /* add the request to the remote device request list. */
491 list_add(&request
->dev_node
, &isci_device
->reqs_in_process
);
493 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
495 /* Wait for the TMF to complete, or a timeout. */
496 wait_for_completion(&completion
);
500 if (tmf
->status
== SCI_SUCCESS
)
501 ret
= TMF_RESP_FUNC_COMPLETE
;
502 else if (tmf
->status
== SCI_FAILURE_IO_RESPONSE_VALID
) {
503 dev_dbg(&isci_host
->pdev
->dev
,
505 "SCI_FAILURE_IO_RESPONSE_VALID\n",
507 ret
= TMF_RESP_FUNC_COMPLETE
;
509 /* Else - leave the default "failed" status alone. */
511 dev_dbg(&isci_host
->pdev
->dev
,
512 "%s: completed request = %p\n",
516 if (request
->io_request_completion
!= NULL
) {
518 /* The fact that this is non-NULL for a TMF request
519 * means there is a thread waiting for this TMF to
522 complete(request
->io_request_completion
);
525 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
529 /* Clean up the timer if needed. */
530 if (tmf
->timeout_timer
) {
531 isci_del_timer(isci_host
, tmf
->timeout_timer
);
532 tmf
->timeout_timer
= NULL
;
535 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
537 isci_request_free(isci_host
, request
);
542 void isci_task_build_tmf(
543 struct isci_tmf
*tmf
,
544 struct isci_remote_device
*isci_device
,
545 enum isci_tmf_function_codes code
,
546 void (*tmf_sent_cb
)(enum isci_tmf_cb_state
,
551 dev_dbg(&isci_device
->isci_port
->isci_host
->pdev
->dev
,
552 "%s: isci_device = %p\n", __func__
, isci_device
);
554 memset(tmf
, 0, sizeof(*tmf
));
556 tmf
->device
= isci_device
;
557 tmf
->tmf_code
= code
;
558 tmf
->timeout_timer
= NULL
;
559 tmf
->cb_state_func
= tmf_sent_cb
;
560 tmf
->cb_data
= cb_data
;
563 static void isci_task_build_abort_task_tmf(
564 struct isci_tmf
*tmf
,
565 struct isci_remote_device
*isci_device
,
566 enum isci_tmf_function_codes code
,
567 void (*tmf_sent_cb
)(enum isci_tmf_cb_state
,
570 struct isci_request
*old_request
)
572 isci_task_build_tmf(tmf
, isci_device
, code
, tmf_sent_cb
,
573 (void *)old_request
);
574 tmf
->io_tag
= old_request
->io_tag
;
577 static struct isci_request
*isci_task_get_request_from_task(
578 struct sas_task
*task
,
579 struct isci_remote_device
**isci_device
)
582 struct isci_request
*request
= NULL
;
585 spin_lock_irqsave(&task
->task_state_lock
, flags
);
587 request
= task
->lldd_task
;
589 /* If task is already done, the request isn't valid */
590 if (!(task
->task_state_flags
& SAS_TASK_STATE_DONE
) &&
591 (task
->task_state_flags
& SAS_TASK_AT_INITIATOR
) &&
594 if (isci_device
!= NULL
)
595 *isci_device
= request
->isci_device
;
598 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
604 * isci_task_validate_request_to_abort() - This function checks the given I/O
605 * against the "started" state. If the request is still "started", it's
606 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
607 * BEFORE CALLING THIS FUNCTION.
608 * @isci_request: This parameter specifies the request object to control.
609 * @isci_host: This parameter specifies the ISCI host object
610 * @isci_device: This is the device to which the request is pending.
611 * @aborted_io_completion: This is a completion structure that will be added to
612 * the request in case it is changed to aborting; this completion is
613 * triggered when the request is fully completed.
615 * Either "started" on successful change of the task status to "aborted", or
616 * "unallocated" if the task cannot be controlled.
618 static enum isci_request_status
isci_task_validate_request_to_abort(
619 struct isci_request
*isci_request
,
620 struct isci_host
*isci_host
,
621 struct isci_remote_device
*isci_device
,
622 struct completion
*aborted_io_completion
)
624 enum isci_request_status old_state
= unallocated
;
626 /* Only abort the task if it's in the
627 * device's request_in_process list
629 if (isci_request
&& !list_empty(&isci_request
->dev_node
)) {
630 old_state
= isci_request_change_started_to_aborted(
631 isci_request
, aborted_io_completion
);
638 static void isci_request_cleanup_completed_loiterer(
639 struct isci_host
*isci_host
,
640 struct isci_remote_device
*isci_device
,
641 struct isci_request
*isci_request
)
643 struct sas_task
*task
;
646 task
= (isci_request
->ttype
== io_task
)
647 ? isci_request_access_task(isci_request
)
650 dev_dbg(&isci_host
->pdev
->dev
,
651 "%s: isci_device=%p, request=%p, task=%p\n",
652 __func__
, isci_device
, isci_request
, task
);
654 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
655 list_del_init(&isci_request
->dev_node
);
656 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
660 spin_lock_irqsave(&task
->task_state_lock
, flags
);
661 task
->lldd_task
= NULL
;
663 isci_set_task_doneflags(task
);
665 /* If this task is not in the abort path, call task_done. */
666 if (!(task
->task_state_flags
& SAS_TASK_STATE_ABORTED
)) {
668 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
669 task
->task_done(task
);
671 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
673 isci_request_free(isci_host
, isci_request
);
677 * @isci_termination_timed_out(): this function will deal with a request for
678 * which the wait for termination has timed-out.
680 * @isci_host This SCU.
681 * @isci_request The I/O request being terminated.
684 isci_termination_timed_out(
685 struct isci_host
* host
,
686 struct isci_request
* request
689 unsigned long state_flags
;
691 dev_warn(&host
->pdev
->dev
,
692 "%s: host = %p; request = %p\n",
693 __func__
, host
, request
);
695 /* At this point, the request to terminate
696 * has timed out. The best we can do is to
697 * have the request die a silent death
698 * if it ever completes.
700 spin_lock_irqsave(&request
->state_lock
, state_flags
);
702 if (request
->status
== started
) {
704 /* Set the request state to "dead",
705 * and clear the task pointer so that an actual
706 * completion event callback doesn't do
709 request
->status
= dead
;
711 /* Clear the timeout completion event pointer.*/
712 request
->io_request_completion
= NULL
;
714 if (request
->ttype
== io_task
) {
716 /* Break links with the sas_task. */
717 if (request
->ttype_ptr
.io_task_ptr
!= NULL
) {
719 request
->ttype_ptr
.io_task_ptr
->lldd_task
= NULL
;
720 request
->ttype_ptr
.io_task_ptr
= NULL
;
724 spin_unlock_irqrestore(&request
->state_lock
, state_flags
);
729 * isci_terminate_request_core() - This function will terminate the given
730 * request, and wait for it to complete. This function must only be called
731 * from a thread that can wait. Note that the request is terminated and
732 * completed (back to the host, if started there).
733 * @isci_host: This SCU.
734 * @isci_device: The target.
735 * @isci_request: The I/O request to be terminated.
739 static void isci_terminate_request_core(
740 struct isci_host
*isci_host
,
741 struct isci_remote_device
*isci_device
,
742 struct isci_request
*isci_request
)
744 enum sci_status status
= SCI_SUCCESS
;
745 bool was_terminated
= false;
746 bool needs_cleanup_handling
= false;
747 enum isci_request_status request_status
;
749 unsigned long timeout_remaining
;
752 dev_dbg(&isci_host
->pdev
->dev
,
753 "%s: device = %p; request = %p\n",
754 __func__
, isci_device
, isci_request
);
756 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
758 /* Note that we are not going to control
759 * the target to abort the request.
761 isci_request
->complete_in_target
= true;
763 /* Make sure the request wasn't just sitting around signalling
764 * device condition (if the request handle is NULL, then the
765 * request completed but needed additional handling here).
767 if (isci_request
->sci_request_handle
!= NULL
) {
768 was_terminated
= true;
769 needs_cleanup_handling
= true;
770 status
= scic_controller_terminate_request(
773 isci_request
->sci_request_handle
);
775 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
778 * The only time the request to terminate will
779 * fail is when the io request is completed and
782 if (status
!= SCI_SUCCESS
) {
783 dev_err(&isci_host
->pdev
->dev
,
784 "%s: scic_controller_terminate_request"
785 " returned = 0x%x\n",
788 /* Clear the completion pointer from the request. */
789 isci_request
->io_request_completion
= NULL
;
792 if (was_terminated
) {
793 dev_dbg(&isci_host
->pdev
->dev
,
794 "%s: before completion wait (%p)\n",
796 isci_request
->io_request_completion
);
798 /* Wait here for the request to complete. */
799 #define TERMINATION_TIMEOUT_MSEC 50
801 = wait_for_completion_timeout(
802 isci_request
->io_request_completion
,
803 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC
));
805 if (!timeout_remaining
) {
807 isci_termination_timed_out(isci_host
,
810 dev_err(&isci_host
->pdev
->dev
,
811 "%s: *** Timeout waiting for "
812 "termination(%p/%p)\n",
814 isci_request
->io_request_completion
,
818 dev_dbg(&isci_host
->pdev
->dev
,
819 "%s: after completion wait (%p)\n",
821 isci_request
->io_request_completion
);
823 /* Clear the completion pointer from the request. */
824 isci_request
->io_request_completion
= NULL
;
826 /* Peek at the status of the request. This will tell
827 * us if there was special handling on the request such that it
828 * needs to be detached and freed here.
830 spin_lock_irqsave(&isci_request
->state_lock
, flags
);
831 request_status
= isci_request_get_state(isci_request
);
833 if ((isci_request
->ttype
== io_task
) /* TMFs are in their own thread */
834 && ((request_status
== aborted
)
835 || (request_status
== aborting
)
836 || (request_status
== terminating
)
837 || (request_status
== completed
)
838 || (request_status
== dead
)
842 /* The completion routine won't free a request in
843 * the aborted/aborting/etc. states, so we do
846 needs_cleanup_handling
= true;
848 spin_unlock_irqrestore(&isci_request
->state_lock
, flags
);
850 if (needs_cleanup_handling
)
851 isci_request_cleanup_completed_loiterer(
852 isci_host
, isci_device
, isci_request
857 static void isci_terminate_request(
858 struct isci_host
*isci_host
,
859 struct isci_remote_device
*isci_device
,
860 struct isci_request
*isci_request
,
861 enum isci_request_status new_request_state
)
863 enum isci_request_status old_state
;
864 DECLARE_COMPLETION_ONSTACK(request_completion
);
866 /* Change state to "new_request_state" if it is currently "started" */
867 old_state
= isci_request_change_started_to_newstate(
873 if ((old_state
== started
) ||
874 (old_state
== completed
) ||
875 (old_state
== aborting
)) {
877 /* If the old_state is started:
878 * This request was not already being aborted. If it had been,
879 * then the aborting I/O (ie. the TMF request) would not be in
880 * the aborting state, and thus would be terminated here. Note
881 * that since the TMF completion's call to the kernel function
882 * "complete()" does not happen until the pending I/O request
883 * terminate fully completes, we do not have to implement a
884 * special wait here for already aborting requests - the
885 * termination of the TMF request will force the request
886 * to finish it's already started terminate.
888 * If old_state == completed:
889 * This request completed from the SCU hardware perspective
890 * and now just needs cleaning up in terms of freeing the
891 * request and potentially calling up to libsas.
893 * If old_state == aborting:
894 * This request has already gone through a TMF timeout, but may
895 * not have been terminated; needs cleaning up at least.
897 isci_terminate_request_core(isci_host
, isci_device
,
903 * isci_terminate_pending_requests() - This function will change the all of the
904 * requests on the given device's state to "aborting", will terminate the
905 * requests, and wait for them to complete. This function must only be
906 * called from a thread that can wait. Note that the requests are all
907 * terminated and completed (back to the host, if started there).
908 * @isci_host: This parameter specifies SCU.
909 * @isci_device: This parameter specifies the target.
913 void isci_terminate_pending_requests(
914 struct isci_host
*isci_host
,
915 struct isci_remote_device
*isci_device
,
916 enum isci_request_status new_request_state
)
918 struct isci_request
*request
;
919 struct isci_request
*next_request
;
921 struct list_head aborted_request_list
;
923 INIT_LIST_HEAD(&aborted_request_list
);
925 dev_dbg(&isci_host
->pdev
->dev
,
926 "%s: isci_device = %p (new request state = %d)\n",
927 __func__
, isci_device
, new_request_state
);
929 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
931 /* Move all of the pending requests off of the device list. */
932 list_splice_init(&isci_device
->reqs_in_process
,
933 &aborted_request_list
);
935 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
937 /* Iterate through the now-local list. */
938 list_for_each_entry_safe(request
, next_request
,
939 &aborted_request_list
, dev_node
) {
941 dev_warn(&isci_host
->pdev
->dev
,
942 "%s: isci_device=%p request=%p; task=%p\n",
944 isci_device
, request
,
945 ((request
->ttype
== io_task
)
946 ? isci_request_access_task(request
)
949 /* Mark all still pending I/O with the selected next
950 * state, terminate and free it.
952 isci_terminate_request(isci_host
, isci_device
,
953 request
, new_request_state
959 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
960 * Template functions.
961 * @lun: This parameter specifies the lun to be reset.
963 * status, zero indicates success.
965 static int isci_task_send_lu_reset_sas(
966 struct isci_host
*isci_host
,
967 struct isci_remote_device
*isci_device
,
971 int ret
= TMF_RESP_FUNC_FAILED
;
973 dev_dbg(&isci_host
->pdev
->dev
,
974 "%s: isci_host = %p, isci_device = %p\n",
975 __func__
, isci_host
, isci_device
);
976 /* Send the LUN reset to the target. By the time the call returns,
977 * the TMF has fully exected in the target (in which case the return
978 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
979 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
981 isci_task_build_tmf(&tmf
, isci_device
, isci_tmf_ssp_lun_reset
, NULL
,
984 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
985 ret
= isci_task_execute_tmf(isci_host
, &tmf
, ISCI_LU_RESET_TIMEOUT_MS
);
987 if (ret
== TMF_RESP_FUNC_COMPLETE
)
988 dev_dbg(&isci_host
->pdev
->dev
,
989 "%s: %p: TMF_LU_RESET passed\n",
990 __func__
, isci_device
);
992 dev_dbg(&isci_host
->pdev
->dev
,
993 "%s: %p: TMF_LU_RESET failed (%x)\n",
994 __func__
, isci_device
, ret
);
1000 * isci_task_lu_reset() - This function is one of the SAS Domain Template
1001 * functions. This is one of the Task Management functoins called by libsas,
1002 * to reset the given lun. Note the assumption that while this call is
1003 * executing, no I/O will be sent by the host to the device.
1004 * @lun: This parameter specifies the lun to be reset.
1006 * status, zero indicates success.
1008 int isci_task_lu_reset(struct domain_device
*domain_device
, u8
*lun
)
1010 struct isci_host
*isci_host
= dev_to_ihost(domain_device
);
1011 struct isci_remote_device
*isci_device
= NULL
;
1013 bool device_stopping
= false;
1015 isci_device
= domain_device
->lldd_dev
;
1017 dev_dbg(&isci_host
->pdev
->dev
,
1018 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
1019 __func__
, domain_device
, isci_host
, isci_device
);
1021 if (isci_device
!= NULL
) {
1022 device_stopping
= (isci_device
->status
== isci_stopping
)
1023 || (isci_device
->status
== isci_stopped
);
1024 set_bit(IDEV_EH
, &isci_device
->flags
);
1027 /* If there is a device reset pending on any request in the
1028 * device's list, fail this LUN reset request in order to
1029 * escalate to the device reset.
1031 if (!isci_device
|| device_stopping
||
1032 isci_device_is_reset_pending(isci_host
, isci_device
)) {
1033 dev_warn(&isci_host
->pdev
->dev
,
1034 "%s: No dev (%p), or "
1035 "RESET PENDING: domain_device=%p\n",
1036 __func__
, isci_device
, domain_device
);
1037 return TMF_RESP_FUNC_FAILED
;
1040 /* Send the task management part of the reset. */
1041 if (sas_protocol_ata(domain_device
->tproto
)) {
1042 ret
= isci_task_send_lu_reset_sata(isci_host
, isci_device
, lun
);
1044 ret
= isci_task_send_lu_reset_sas(isci_host
, isci_device
, lun
);
1046 /* If the LUN reset worked, all the I/O can now be terminated. */
1047 if (ret
== TMF_RESP_FUNC_COMPLETE
)
1048 /* Terminate all I/O now. */
1049 isci_terminate_pending_requests(isci_host
,
1057 /* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
1058 int isci_task_clear_nexus_port(struct asd_sas_port
*port
)
1060 return TMF_RESP_FUNC_FAILED
;
1065 int isci_task_clear_nexus_ha(struct sas_ha_struct
*ha
)
1067 return TMF_RESP_FUNC_FAILED
;
1070 /* Task Management Functions. Must be called from process context. */
1073 * isci_abort_task_process_cb() - This is a helper function for the abort task
1074 * TMF command. It manages the request state with respect to the successful
1075 * transmission / completion of the abort task request.
1076 * @cb_state: This parameter specifies when this function was called - after
1077 * the TMF request has been started and after it has timed-out.
1078 * @tmf: This parameter specifies the TMF in progress.
1082 static void isci_abort_task_process_cb(
1083 enum isci_tmf_cb_state cb_state
,
1084 struct isci_tmf
*tmf
,
1087 struct isci_request
*old_request
;
1089 old_request
= (struct isci_request
*)cb_data
;
1091 dev_dbg(&old_request
->isci_host
->pdev
->dev
,
1092 "%s: tmf=%p, old_request=%p\n",
1093 __func__
, tmf
, old_request
);
1097 case isci_tmf_started
:
1098 /* The TMF has been started. Nothing to do here, since the
1099 * request state was already set to "aborted" by the abort
1102 if ((old_request
->status
!= aborted
)
1103 && (old_request
->status
!= completed
))
1104 dev_err(&old_request
->isci_host
->pdev
->dev
,
1105 "%s: Bad request status (%d): tmf=%p, old_request=%p\n",
1106 __func__
, old_request
->status
, tmf
, old_request
);
1109 case isci_tmf_timed_out
:
1111 /* Set the task's state to "aborting", since the abort task
1112 * function thread set it to "aborted" (above) in anticipation
1113 * of the task management request working correctly. Since the
1114 * timeout has now fired, the TMF request failed. We set the
1115 * state such that the request completion will indicate the
1116 * device is no longer present.
1118 isci_request_change_state(old_request
, aborting
);
1122 dev_err(&old_request
->isci_host
->pdev
->dev
,
1123 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1124 __func__
, cb_state
, tmf
, old_request
);
1130 * isci_task_abort_task() - This function is one of the SAS Domain Template
1131 * functions. This function is called by libsas to abort a specified task.
1132 * @task: This parameter specifies the SAS task to abort.
1134 * status, zero indicates success.
1136 int isci_task_abort_task(struct sas_task
*task
)
1138 struct isci_host
*isci_host
= dev_to_ihost(task
->dev
);
1139 DECLARE_COMPLETION_ONSTACK(aborted_io_completion
);
1140 struct isci_request
*old_request
= NULL
;
1141 enum isci_request_status old_state
;
1142 struct isci_remote_device
*isci_device
= NULL
;
1143 struct isci_tmf tmf
;
1144 int ret
= TMF_RESP_FUNC_FAILED
;
1145 unsigned long flags
;
1146 bool any_dev_reset
= false;
1147 bool device_stopping
;
1149 /* Get the isci_request reference from the task. Note that
1150 * this check does not depend on the pending request list
1151 * in the device, because tasks driving resets may land here
1152 * after completion in the core.
1154 old_request
= isci_task_get_request_from_task(task
, &isci_device
);
1156 dev_dbg(&isci_host
->pdev
->dev
,
1157 "%s: task = %p\n", __func__
, task
);
1159 /* Check if the device has been / is currently being removed.
1160 * If so, no task management will be done, and the I/O will
1163 device_stopping
= (isci_device
->status
== isci_stopping
)
1164 || (isci_device
->status
== isci_stopped
);
1166 /* XXX need to fix device lookup lifetime (needs to be done
1167 * under scic_lock, among other things...), but for now assume
1168 * the device is available like the above code
1170 set_bit(IDEV_EH
, &isci_device
->flags
);
1172 /* This version of the driver will fail abort requests for
1173 * SATA/STP. Failing the abort request this way will cause the
1174 * SCSI error handler thread to escalate to LUN reset
1176 if (sas_protocol_ata(task
->task_proto
) && !device_stopping
) {
1177 dev_warn(&isci_host
->pdev
->dev
,
1178 " task %p is for a STP/SATA device;"
1179 " returning TMF_RESP_FUNC_FAILED\n"
1180 " to cause a LUN reset...\n", task
);
1181 return TMF_RESP_FUNC_FAILED
;
1184 dev_dbg(&isci_host
->pdev
->dev
,
1185 "%s: old_request == %p\n", __func__
, old_request
);
1187 if (!device_stopping
)
1188 any_dev_reset
= isci_device_is_reset_pending(isci_host
,isci_device
);
1190 spin_lock_irqsave(&task
->task_state_lock
, flags
);
1192 /* Don't do resets to stopping devices. */
1193 if (device_stopping
) {
1195 task
->task_state_flags
&= ~SAS_TASK_NEED_DEV_RESET
;
1196 any_dev_reset
= false;
1198 } else /* See if there is a pending device reset for this device. */
1199 any_dev_reset
= any_dev_reset
1200 || (task
->task_state_flags
& SAS_TASK_NEED_DEV_RESET
);
1202 /* If the extraction of the request reference from the task
1203 * failed, then the request has been completed (or if there is a
1204 * pending reset then this abort request function must be failed
1205 * in order to escalate to the target reset).
1207 if ((old_request
== NULL
) || any_dev_reset
) {
1209 /* If the device reset task flag is set, fail the task
1210 * management request. Otherwise, the original request
1213 if (any_dev_reset
) {
1215 /* Turn off the task's DONE to make sure this
1216 * task is escalated to a target reset.
1218 task
->task_state_flags
&= ~SAS_TASK_STATE_DONE
;
1220 /* Make the reset happen as soon as possible. */
1221 task
->task_state_flags
|= SAS_TASK_NEED_DEV_RESET
;
1223 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1225 /* Fail the task management request in order to
1226 * escalate to the target reset.
1228 ret
= TMF_RESP_FUNC_FAILED
;
1230 dev_dbg(&isci_host
->pdev
->dev
,
1231 "%s: Failing task abort in order to "
1232 "escalate to target reset because\n"
1233 "SAS_TASK_NEED_DEV_RESET is set for "
1234 "task %p on dev %p\n",
1235 __func__
, task
, isci_device
);
1239 /* The request has already completed and there
1240 * is nothing to do here other than to set the task
1241 * done bit, and indicate that the task abort function
1244 isci_set_task_doneflags(task
);
1246 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1248 ret
= TMF_RESP_FUNC_COMPLETE
;
1250 dev_dbg(&isci_host
->pdev
->dev
,
1251 "%s: abort task not needed for %p\n",
1258 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1260 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
1262 /* Check the request status and change to "aborted" if currently
1263 * "starting"; if true then set the I/O kernel completion
1264 * struct that will be triggered when the request completes.
1266 old_state
= isci_task_validate_request_to_abort(
1267 old_request
, isci_host
, isci_device
,
1268 &aborted_io_completion
);
1269 if ((old_state
!= started
) &&
1270 (old_state
!= completed
) &&
1271 (old_state
!= aborting
)) {
1273 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1275 /* The request was already being handled by someone else (because
1276 * they got to set the state away from started).
1278 dev_dbg(&isci_host
->pdev
->dev
,
1279 "%s: device = %p; old_request %p already being aborted\n",
1281 isci_device
, old_request
);
1283 return TMF_RESP_FUNC_COMPLETE
;
1285 if ((task
->task_proto
== SAS_PROTOCOL_SMP
)
1287 || old_request
->complete_in_target
1290 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1292 dev_dbg(&isci_host
->pdev
->dev
,
1293 "%s: SMP request (%d)"
1294 " or device is stopping (%d)"
1295 " or complete_in_target (%d), thus no TMF\n",
1296 __func__
, (task
->task_proto
== SAS_PROTOCOL_SMP
),
1297 device_stopping
, old_request
->complete_in_target
);
1299 /* Set the state on the task. */
1300 isci_task_all_done(task
);
1302 ret
= TMF_RESP_FUNC_COMPLETE
;
1304 /* Stopping and SMP devices are not sent a TMF, and are not
1305 * reset, but the outstanding I/O request is terminated below.
1308 /* Fill in the tmf stucture */
1309 isci_task_build_abort_task_tmf(&tmf
, isci_device
,
1310 isci_tmf_ssp_task_abort
,
1311 isci_abort_task_process_cb
,
1314 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1316 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */
1317 ret
= isci_task_execute_tmf(isci_host
, &tmf
,
1318 ISCI_ABORT_TASK_TIMEOUT_MS
);
1320 if (ret
!= TMF_RESP_FUNC_COMPLETE
)
1321 dev_err(&isci_host
->pdev
->dev
,
1322 "%s: isci_task_send_tmf failed\n",
1325 if (ret
== TMF_RESP_FUNC_COMPLETE
) {
1326 old_request
->complete_in_target
= true;
1328 /* Clean up the request on our side, and wait for the aborted I/O to
1331 isci_terminate_request_core(isci_host
, isci_device
, old_request
);
1334 /* Make sure we do not leave a reference to aborted_io_completion */
1335 old_request
->io_request_completion
= NULL
;
1340 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
1341 * functions. This is one of the Task Management functoins called by libsas,
1342 * to abort all task for the given lun.
1343 * @d_device: This parameter specifies the domain device associated with this
1345 * @lun: This parameter specifies the lun associated with this request.
1347 * status, zero indicates success.
1349 int isci_task_abort_task_set(
1350 struct domain_device
*d_device
,
1353 return TMF_RESP_FUNC_FAILED
;
1358 * isci_task_clear_aca() - This function is one of the SAS Domain Template
1359 * functions. This is one of the Task Management functoins called by libsas.
1360 * @d_device: This parameter specifies the domain device associated with this
1362 * @lun: This parameter specifies the lun associated with this request.
1364 * status, zero indicates success.
1366 int isci_task_clear_aca(
1367 struct domain_device
*d_device
,
1370 return TMF_RESP_FUNC_FAILED
;
1376 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
1377 * functions. This is one of the Task Management functoins called by libsas.
1378 * @d_device: This parameter specifies the domain device associated with this
1380 * @lun: This parameter specifies the lun associated with this request.
1382 * status, zero indicates success.
1384 int isci_task_clear_task_set(
1385 struct domain_device
*d_device
,
1388 return TMF_RESP_FUNC_FAILED
;
1393 * isci_task_query_task() - This function is implemented to cause libsas to
1394 * correctly escalate the failed abort to a LUN or target reset (this is
1395 * because sas_scsi_find_task libsas function does not correctly interpret
1396 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
1397 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
1398 * returned, libsas will turn this into a target reset
1399 * @task: This parameter specifies the sas task being queried.
1400 * @lun: This parameter specifies the lun associated with this request.
1402 * status, zero indicates success.
1404 int isci_task_query_task(
1405 struct sas_task
*task
)
1407 /* See if there is a pending device reset for this device. */
1408 if (task
->task_state_flags
& SAS_TASK_NEED_DEV_RESET
)
1409 return TMF_RESP_FUNC_FAILED
;
1411 return TMF_RESP_FUNC_SUCC
;
1415 * isci_task_request_complete() - This function is called by the sci core when
1416 * an task request completes.
1417 * @ihost: This parameter specifies the ISCI host object
1418 * @ireq: This parameter is the completed isci_request object.
1419 * @completion_status: This parameter specifies the completion status from the
1425 isci_task_request_complete(struct isci_host
*ihost
,
1426 struct isci_request
*ireq
,
1427 enum sci_task_status completion_status
)
1429 struct isci_remote_device
*idev
= ireq
->isci_device
;
1430 enum isci_request_status old_state
;
1431 struct isci_tmf
*tmf
= isci_request_access_tmf(ireq
);
1432 struct completion
*tmf_complete
;
1433 struct scic_sds_request
*sci_req
= ireq
->sci_request_handle
;
1435 dev_dbg(&ihost
->pdev
->dev
,
1436 "%s: request = %p, status=%d\n",
1437 __func__
, ireq
, completion_status
);
1439 old_state
= isci_request_change_state(ireq
, completed
);
1441 tmf
->status
= completion_status
;
1442 ireq
->complete_in_target
= true;
1444 if (tmf
->proto
== SAS_PROTOCOL_SSP
) {
1445 memcpy(&tmf
->resp
.resp_iu
,
1447 SSP_RESP_IU_MAX_SIZE
);
1448 } else if (tmf
->proto
== SAS_PROTOCOL_SATA
) {
1449 memcpy(&tmf
->resp
.d2h_fis
,
1451 sizeof(struct dev_to_host_fis
));
1454 /* Manage the timer if it is still running. */
1455 if (tmf
->timeout_timer
) {
1456 isci_del_timer(ihost
, tmf
->timeout_timer
);
1457 tmf
->timeout_timer
= NULL
;
1460 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1461 tmf_complete
= tmf
->complete
;
1463 scic_controller_complete_io(&ihost
->sci
, &idev
->sci
,
1464 ireq
->sci_request_handle
);
1465 /* NULL the request handle to make sure it cannot be terminated
1466 * or completed again.
1468 ireq
->sci_request_handle
= NULL
;
1470 isci_request_change_state(ireq
, unallocated
);
1471 list_del_init(&ireq
->dev_node
);
1473 /* The task management part completes last. */
1474 complete(tmf_complete
);
1477 static int isci_reset_device(struct domain_device
*dev
, int hard_reset
)
1479 struct isci_remote_device
*idev
= dev
->lldd_dev
;
1480 struct sas_phy
*phy
= sas_find_local_phy(dev
);
1481 struct isci_host
*ihost
= dev_to_ihost(dev
);
1482 enum sci_status status
;
1483 unsigned long flags
;
1486 dev_dbg(&ihost
->pdev
->dev
, "%s: idev %p\n", __func__
, idev
);
1489 dev_warn(&ihost
->pdev
->dev
,
1490 "%s: idev is GONE!\n",
1493 return TMF_RESP_FUNC_COMPLETE
; /* Nothing to reset. */
1496 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1497 status
= scic_remote_device_reset(&idev
->sci
);
1498 if (status
!= SCI_SUCCESS
) {
1499 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1501 dev_warn(&ihost
->pdev
->dev
,
1502 "%s: scic_remote_device_reset(%p) returned %d!\n",
1503 __func__
, idev
, status
);
1505 return TMF_RESP_FUNC_FAILED
;
1507 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1509 /* Make sure all pending requests are able to be fully terminated. */
1510 isci_device_clear_reset_pending(ihost
, idev
);
1512 rc
= sas_phy_reset(phy
, hard_reset
);
1513 msleep(2000); /* just like mvsas */
1515 /* Terminate in-progress I/O now. */
1516 isci_remote_device_nuke_requests(ihost
, idev
);
1518 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1519 status
= scic_remote_device_reset_complete(&idev
->sci
);
1520 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1522 if (status
!= SCI_SUCCESS
) {
1523 dev_warn(&ihost
->pdev
->dev
,
1524 "%s: scic_remote_device_reset_complete(%p) "
1525 "returned %d!\n", __func__
, idev
, status
);
1528 dev_dbg(&ihost
->pdev
->dev
, "%s: idev %p complete.\n", __func__
, idev
);
1533 int isci_task_I_T_nexus_reset(struct domain_device
*dev
)
1535 struct isci_host
*ihost
= dev_to_ihost(dev
);
1536 int ret
= TMF_RESP_FUNC_FAILED
, hard_reset
= 1;
1537 struct isci_remote_device
*idev
;
1538 unsigned long flags
;
1540 /* XXX mvsas is not protecting against ->lldd_dev_gone(), are we
1541 * being too paranoid, or is mvsas busted?!
1543 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
1544 idev
= dev
->lldd_dev
;
1545 if (!idev
|| !test_bit(IDEV_EH
, &idev
->flags
))
1546 ret
= TMF_RESP_FUNC_COMPLETE
;
1547 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
1549 if (ret
== TMF_RESP_FUNC_COMPLETE
)
1552 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))
1555 return isci_reset_device(dev
, hard_reset
);
1558 int isci_bus_reset_handler(struct scsi_cmnd
*cmd
)
1560 struct domain_device
*dev
= sdev_to_domain_dev(cmd
->device
);
1563 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))
1566 return isci_reset_device(dev
, hard_reset
);