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>
58 #include "scic_task_request.h"
59 #include "scic_io_request.h"
60 #include "remote_device.h"
61 #include "remote_node_context.h"
66 #include "core/scic_sds_request.h"
68 * isci_task_refuse() - complete the request to the upper layer driver in
69 * the case where an I/O needs to be completed back in the submit path.
70 * @ihost: host on which the the request was queued
71 * @task: request to complete
72 * @response: response code for the completed task.
73 * @status: status code for the completed task.
76 static void isci_task_refuse(struct isci_host
*ihost
, struct sas_task
*task
,
77 enum service_response response
,
78 enum exec_status status
)
81 enum isci_completion_selection disposition
;
83 disposition
= isci_perform_normal_io_completion
;
84 disposition
= isci_task_set_completion_status(task
, response
, status
,
87 /* Tasks aborted specifically by a call to the lldd_abort_task
88 * function should not be completed to the host in the regular path.
90 switch (disposition
) {
91 case isci_perform_normal_io_completion
:
92 /* Normal notification (task_done) */
93 dev_dbg(&ihost
->pdev
->dev
,
94 "%s: Normal - task = %p, response=%d, "
96 __func__
, task
, response
, status
);
98 task
->lldd_task
= NULL
;
100 isci_execpath_callback(ihost
, task
, task
->task_done
);
103 case isci_perform_aborted_io_completion
:
104 /* No notification because this request is already in the
107 dev_warn(&ihost
->pdev
->dev
,
108 "%s: Aborted - task = %p, response=%d, "
110 __func__
, task
, response
, status
);
113 case isci_perform_error_io_completion
:
114 /* Use sas_task_abort */
115 dev_warn(&ihost
->pdev
->dev
,
116 "%s: Error - task = %p, response=%d, "
118 __func__
, task
, response
, status
);
120 isci_execpath_callback(ihost
, task
, sas_task_abort
);
124 dev_warn(&ihost
->pdev
->dev
,
125 "%s: isci task notification default case!",
127 sas_task_abort(task
);
132 #define for_each_sas_task(num, task) \
133 for (; num > 0; num--,\
134 task = list_entry(task->list.next, struct sas_task, list))
137 * isci_task_execute_task() - This function is one of the SAS Domain Template
138 * functions. This function is called by libsas to send a task down to
140 * @task: This parameter specifies the SAS task to send.
141 * @num: This parameter specifies the number of tasks to queue.
142 * @gfp_flags: This parameter specifies the context of this call.
144 * status, zero indicates success.
146 int isci_task_execute_task(struct sas_task
*task
, int num
, gfp_t gfp_flags
)
148 struct isci_host
*ihost
= dev_to_ihost(task
->dev
);
149 struct isci_request
*request
= NULL
;
150 struct isci_remote_device
*device
;
153 enum sci_status status
;
154 enum isci_status device_status
;
156 dev_dbg(&ihost
->pdev
->dev
, "%s: num=%d\n", __func__
, num
);
158 /* Check if we have room for more tasks */
159 ret
= isci_host_can_queue(ihost
, num
);
162 dev_warn(&ihost
->pdev
->dev
, "%s: queue full\n", __func__
);
166 for_each_sas_task(num
, task
) {
167 dev_dbg(&ihost
->pdev
->dev
,
168 "task = %p, num = %d; dev = %p; cmd = %p\n",
169 task
, num
, task
->dev
, task
->uldd_task
);
171 device
= task
->dev
->lldd_dev
;
174 device_status
= device
->status
;
176 device_status
= isci_freed
;
178 /* From this point onward, any process that needs to guarantee
179 * that there is no kernel I/O being started will have to wait
180 * for the quiesce spinlock.
183 if (device_status
!= isci_ready_for_io
) {
185 /* Forces a retry from scsi mid layer. */
186 dev_dbg(&ihost
->pdev
->dev
,
187 "%s: task %p: isci_host->status = %d, "
188 "device = %p; device_status = 0x%x\n\n",
191 isci_host_get_state(ihost
),
195 if (device_status
== isci_ready
) {
196 /* Indicate QUEUE_FULL so that the scsi midlayer
199 isci_task_refuse(ihost
, task
,
203 /* Else, the device is going down. */
204 isci_task_refuse(ihost
, task
,
205 SAS_TASK_UNDELIVERED
,
208 isci_host_can_dequeue(ihost
, 1);
210 /* There is a device and it's ready for I/O. */
211 spin_lock_irqsave(&task
->task_state_lock
, flags
);
213 if (task
->task_state_flags
& SAS_TASK_STATE_ABORTED
) {
215 spin_unlock_irqrestore(&task
->task_state_lock
,
218 isci_task_refuse(ihost
, task
,
219 SAS_TASK_UNDELIVERED
,
220 SAM_STAT_TASK_ABORTED
);
222 /* The I/O was aborted. */
225 task
->task_state_flags
|= SAS_TASK_AT_INITIATOR
;
226 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
228 /* build and send the request. */
229 status
= isci_request_execute(ihost
, task
, &request
,
232 if (status
!= SCI_SUCCESS
) {
234 spin_lock_irqsave(&task
->task_state_lock
, flags
);
235 /* Did not really start this command. */
236 task
->task_state_flags
&= ~SAS_TASK_AT_INITIATOR
;
237 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
239 /* Indicate QUEUE_FULL so that the scsi
240 * midlayer retries. if the request
241 * failed for remote device reasons,
242 * it gets returned as
243 * SAS_TASK_UNDELIVERED next time
246 isci_task_refuse(ihost
, task
,
249 isci_host_can_dequeue(ihost
, 1);
260 * isci_task_request_build() - This function builds the task request object.
261 * @isci_host: This parameter specifies the ISCI host object
262 * @request: This parameter points to the isci_request object allocated in the
263 * request construct function.
264 * @tmf: This parameter is the task management struct to be built
266 * SCI_SUCCESS on successfull completion, or specific failure code.
268 static enum sci_status
isci_task_request_build(
269 struct isci_host
*isci_host
,
270 struct isci_request
**isci_request
,
271 struct isci_tmf
*isci_tmf
)
273 struct scic_sds_remote_device
*sci_device
;
274 enum sci_status status
= SCI_FAILURE
;
275 struct isci_request
*request
= NULL
;
276 struct isci_remote_device
*isci_device
;
277 struct domain_device
*dev
;
279 dev_dbg(&isci_host
->pdev
->dev
,
280 "%s: isci_tmf = %p\n", __func__
, isci_tmf
);
282 isci_device
= isci_tmf
->device
;
283 sci_device
= &isci_device
->sci
;
284 dev
= isci_device
->domain_dev
;
286 /* do common allocation and init of request object. */
287 status
= isci_request_alloc_tmf(
295 if (status
!= SCI_SUCCESS
)
298 /* let the core do it's construct. */
299 status
= scic_task_request_construct(
300 isci_host
->core_controller
,
302 SCI_CONTROLLER_INVALID_IO_TAG
,
304 request
->sci_request_mem_ptr
,
305 &request
->sci_request_handle
308 if (status
!= SCI_SUCCESS
) {
309 dev_warn(&isci_host
->pdev
->dev
,
310 "%s: scic_task_request_construct failed - "
317 request
->sci_request_handle
->ireq
= request
;
319 /* XXX convert to get this from task->tproto like other drivers */
320 if (dev
->dev_type
== SAS_END_DEV
) {
321 isci_tmf
->proto
= SAS_PROTOCOL_SSP
;
322 status
= scic_task_request_construct_ssp(
323 request
->sci_request_handle
325 if (status
!= SCI_SUCCESS
)
329 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
330 isci_tmf
->proto
= SAS_PROTOCOL_SATA
;
331 status
= isci_sata_management_task_request_build(request
);
333 if (status
!= SCI_SUCCESS
)
341 /* release the dma memory if we fail. */
342 isci_request_free(isci_host
, request
);
346 *isci_request
= request
;
351 * isci_tmf_timeout_cb() - This function is called as a kernel callback when
352 * the timeout period for the TMF has expired.
356 static void isci_tmf_timeout_cb(void *tmf_request_arg
)
358 struct isci_request
*request
= (struct isci_request
*)tmf_request_arg
;
359 struct isci_tmf
*tmf
= isci_request_access_tmf(request
);
360 enum sci_status status
;
362 /* This task management request has timed-out. Terminate the request
363 * so that the request eventually completes to the requestor in the
364 * request completion callback path.
366 /* Note - the timer callback function itself has provided spinlock
367 * exclusion from the start and completion paths. No need to take
368 * the request->isci_host->scic_lock here.
371 if (tmf
->timeout_timer
!= NULL
) {
372 /* Call the users callback, if any. */
373 if (tmf
->cb_state_func
!= NULL
)
374 tmf
->cb_state_func(isci_tmf_timed_out
, tmf
,
377 /* Terminate the TMF transmit request. */
378 status
= scic_controller_terminate_request(
379 request
->isci_host
->core_controller
,
380 &request
->isci_device
->sci
,
381 request
->sci_request_handle
384 dev_dbg(&request
->isci_host
->pdev
->dev
,
385 "%s: tmf_request = %p; tmf = %p; status = %d\n",
386 __func__
, request
, tmf
, status
);
388 dev_dbg(&request
->isci_host
->pdev
->dev
,
389 "%s: timer already canceled! "
390 "tmf_request = %p; tmf = %p\n",
391 __func__
, request
, tmf
);
393 /* No need to unlock since the caller to this callback is doing it for
395 * request->isci_host->scic_lock
400 * isci_task_execute_tmf() - This function builds and sends a task request,
401 * then waits for the completion.
402 * @isci_host: This parameter specifies the ISCI host object
403 * @tmf: This parameter is the pointer to the task management structure for
405 * @timeout_ms: This parameter specifies the timeout period for the task
406 * management request.
408 * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes
409 * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED.
411 int isci_task_execute_tmf(
412 struct isci_host
*isci_host
,
413 struct isci_tmf
*tmf
,
414 unsigned long timeout_ms
)
416 DECLARE_COMPLETION_ONSTACK(completion
);
417 enum sci_task_status status
= SCI_TASK_FAILURE
;
418 struct scic_sds_remote_device
*sci_device
;
419 struct isci_remote_device
*isci_device
= tmf
->device
;
420 struct isci_request
*request
;
421 int ret
= TMF_RESP_FUNC_FAILED
;
424 /* sanity check, return TMF_RESP_FUNC_FAILED
425 * if the device is not there and ready.
427 if (!isci_device
|| isci_device
->status
!= isci_ready_for_io
) {
428 dev_dbg(&isci_host
->pdev
->dev
,
429 "%s: isci_device = %p not ready (%d)\n",
431 isci_device
, isci_device
->status
);
432 return TMF_RESP_FUNC_FAILED
;
434 dev_dbg(&isci_host
->pdev
->dev
,
435 "%s: isci_device = %p\n",
436 __func__
, isci_device
);
438 sci_device
= &isci_device
->sci
;
440 /* Assign the pointer to the TMF's completion kernel wait structure. */
441 tmf
->complete
= &completion
;
443 isci_task_request_build(
450 dev_warn(&isci_host
->pdev
->dev
,
451 "%s: isci_task_request_build failed\n",
453 return TMF_RESP_FUNC_FAILED
;
456 /* Allocate the TMF timeout timer. */
457 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
458 tmf
->timeout_timer
= isci_timer_create(isci_host
, request
, isci_tmf_timeout_cb
);
460 /* Start the timer. */
461 if (tmf
->timeout_timer
)
462 isci_timer_start(tmf
->timeout_timer
, timeout_ms
);
464 dev_warn(&isci_host
->pdev
->dev
,
465 "%s: isci_timer_create failed!!!!\n",
468 /* start the TMF io. */
469 status
= scic_controller_start_task(
470 isci_host
->core_controller
,
472 request
->sci_request_handle
,
473 SCI_CONTROLLER_INVALID_IO_TAG
476 if (status
!= SCI_TASK_SUCCESS
) {
477 dev_warn(&isci_host
->pdev
->dev
,
478 "%s: start_io failed - status = 0x%x, request = %p\n",
482 goto cleanup_request
;
485 /* Call the users callback, if any. */
486 if (tmf
->cb_state_func
!= NULL
)
487 tmf
->cb_state_func(isci_tmf_started
, tmf
, tmf
->cb_data
);
489 /* Change the state of the TMF-bearing request to "started". */
490 isci_request_change_state(request
, started
);
492 /* add the request to the remote device request list. */
493 list_add(&request
->dev_node
, &isci_device
->reqs_in_process
);
495 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
497 /* Wait for the TMF to complete, or a timeout. */
498 wait_for_completion(&completion
);
502 if (tmf
->status
== SCI_SUCCESS
)
503 ret
= TMF_RESP_FUNC_COMPLETE
;
504 else if (tmf
->status
== SCI_FAILURE_IO_RESPONSE_VALID
) {
505 dev_dbg(&isci_host
->pdev
->dev
,
507 "SCI_FAILURE_IO_RESPONSE_VALID\n",
509 ret
= TMF_RESP_FUNC_COMPLETE
;
511 /* Else - leave the default "failed" status alone. */
513 dev_dbg(&isci_host
->pdev
->dev
,
514 "%s: completed request = %p\n",
518 if (request
->io_request_completion
!= NULL
) {
520 /* The fact that this is non-NULL for a TMF request
521 * means there is a thread waiting for this TMF to
524 complete(request
->io_request_completion
);
527 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
531 /* Clean up the timer if needed. */
532 if (tmf
->timeout_timer
) {
533 isci_del_timer(isci_host
, tmf
->timeout_timer
);
534 tmf
->timeout_timer
= NULL
;
537 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
539 isci_request_free(isci_host
, request
);
544 void isci_task_build_tmf(
545 struct isci_tmf
*tmf
,
546 struct isci_remote_device
*isci_device
,
547 enum isci_tmf_function_codes code
,
548 void (*tmf_sent_cb
)(enum isci_tmf_cb_state
,
553 dev_dbg(&isci_device
->isci_port
->isci_host
->pdev
->dev
,
554 "%s: isci_device = %p\n", __func__
, isci_device
);
556 memset(tmf
, 0, sizeof(*tmf
));
558 tmf
->device
= isci_device
;
559 tmf
->tmf_code
= code
;
560 tmf
->timeout_timer
= NULL
;
561 tmf
->cb_state_func
= tmf_sent_cb
;
562 tmf
->cb_data
= cb_data
;
565 static void isci_task_build_abort_task_tmf(
566 struct isci_tmf
*tmf
,
567 struct isci_remote_device
*isci_device
,
568 enum isci_tmf_function_codes code
,
569 void (*tmf_sent_cb
)(enum isci_tmf_cb_state
,
572 struct isci_request
*old_request
)
574 isci_task_build_tmf(tmf
, isci_device
, code
, tmf_sent_cb
,
575 (void *)old_request
);
576 tmf
->io_tag
= old_request
->io_tag
;
579 static struct isci_request
*isci_task_get_request_from_task(
580 struct sas_task
*task
,
581 struct isci_remote_device
**isci_device
)
584 struct isci_request
*request
= NULL
;
587 spin_lock_irqsave(&task
->task_state_lock
, flags
);
589 request
= task
->lldd_task
;
591 /* If task is already done, the request isn't valid */
592 if (!(task
->task_state_flags
& SAS_TASK_STATE_DONE
) &&
593 (task
->task_state_flags
& SAS_TASK_AT_INITIATOR
) &&
596 if (isci_device
!= NULL
)
597 *isci_device
= request
->isci_device
;
600 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
606 * isci_task_validate_request_to_abort() - This function checks the given I/O
607 * against the "started" state. If the request is still "started", it's
608 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
609 * BEFORE CALLING THIS FUNCTION.
610 * @isci_request: This parameter specifies the request object to control.
611 * @isci_host: This parameter specifies the ISCI host object
612 * @isci_device: This is the device to which the request is pending.
613 * @aborted_io_completion: This is a completion structure that will be added to
614 * the request in case it is changed to aborting; this completion is
615 * triggered when the request is fully completed.
617 * Either "started" on successful change of the task status to "aborted", or
618 * "unallocated" if the task cannot be controlled.
620 static enum isci_request_status
isci_task_validate_request_to_abort(
621 struct isci_request
*isci_request
,
622 struct isci_host
*isci_host
,
623 struct isci_remote_device
*isci_device
,
624 struct completion
*aborted_io_completion
)
626 enum isci_request_status old_state
= unallocated
;
628 /* Only abort the task if it's in the
629 * device's request_in_process list
631 if (isci_request
&& !list_empty(&isci_request
->dev_node
)) {
632 old_state
= isci_request_change_started_to_aborted(
633 isci_request
, aborted_io_completion
);
640 static void isci_request_cleanup_completed_loiterer(
641 struct isci_host
*isci_host
,
642 struct isci_remote_device
*isci_device
,
643 struct isci_request
*isci_request
)
645 struct sas_task
*task
;
648 task
= (isci_request
->ttype
== io_task
)
649 ? isci_request_access_task(isci_request
)
652 dev_dbg(&isci_host
->pdev
->dev
,
653 "%s: isci_device=%p, request=%p, task=%p\n",
654 __func__
, isci_device
, isci_request
, task
);
656 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
657 list_del_init(&isci_request
->dev_node
);
658 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
662 spin_lock_irqsave(&task
->task_state_lock
, flags
);
663 task
->lldd_task
= NULL
;
665 isci_set_task_doneflags(task
);
667 /* If this task is not in the abort path, call task_done. */
668 if (!(task
->task_state_flags
& SAS_TASK_STATE_ABORTED
)) {
670 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
671 task
->task_done(task
);
673 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
675 isci_request_free(isci_host
, isci_request
);
679 * @isci_termination_timed_out(): this function will deal with a request for
680 * which the wait for termination has timed-out.
682 * @isci_host This SCU.
683 * @isci_request The I/O request being terminated.
686 isci_termination_timed_out(
687 struct isci_host
* host
,
688 struct isci_request
* request
691 unsigned long state_flags
;
693 dev_warn(&host
->pdev
->dev
,
694 "%s: host = %p; request = %p\n",
695 __func__
, host
, request
);
697 /* At this point, the request to terminate
698 * has timed out. The best we can do is to
699 * have the request die a silent death
700 * if it ever completes.
702 spin_lock_irqsave(&request
->state_lock
, state_flags
);
704 if (request
->status
== started
) {
706 /* Set the request state to "dead",
707 * and clear the task pointer so that an actual
708 * completion event callback doesn't do
711 request
->status
= dead
;
713 /* Clear the timeout completion event pointer.*/
714 request
->io_request_completion
= NULL
;
716 if (request
->ttype
== io_task
) {
718 /* Break links with the sas_task. */
719 if (request
->ttype_ptr
.io_task_ptr
!= NULL
) {
721 request
->ttype_ptr
.io_task_ptr
->lldd_task
= NULL
;
722 request
->ttype_ptr
.io_task_ptr
= NULL
;
726 spin_unlock_irqrestore(&request
->state_lock
, state_flags
);
731 * isci_terminate_request_core() - This function will terminate the given
732 * request, and wait for it to complete. This function must only be called
733 * from a thread that can wait. Note that the request is terminated and
734 * completed (back to the host, if started there).
735 * @isci_host: This SCU.
736 * @isci_device: The target.
737 * @isci_request: The I/O request to be terminated.
741 static void isci_terminate_request_core(
742 struct isci_host
*isci_host
,
743 struct isci_remote_device
*isci_device
,
744 struct isci_request
*isci_request
)
746 enum sci_status status
= SCI_SUCCESS
;
747 bool was_terminated
= false;
748 bool needs_cleanup_handling
= false;
749 enum isci_request_status request_status
;
751 unsigned long timeout_remaining
;
754 dev_dbg(&isci_host
->pdev
->dev
,
755 "%s: device = %p; request = %p\n",
756 __func__
, isci_device
, isci_request
);
758 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
760 /* Note that we are not going to control
761 * the target to abort the request.
763 isci_request
->complete_in_target
= true;
765 /* Make sure the request wasn't just sitting around signalling
766 * device condition (if the request handle is NULL, then the
767 * request completed but needed additional handling here).
769 if (isci_request
->sci_request_handle
!= NULL
) {
770 was_terminated
= true;
771 needs_cleanup_handling
= true;
772 status
= scic_controller_terminate_request(
773 isci_host
->core_controller
,
775 isci_request
->sci_request_handle
);
777 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
780 * The only time the request to terminate will
781 * fail is when the io request is completed and
784 if (status
!= SCI_SUCCESS
) {
785 dev_err(&isci_host
->pdev
->dev
,
786 "%s: scic_controller_terminate_request"
787 " returned = 0x%x\n",
790 /* Clear the completion pointer from the request. */
791 isci_request
->io_request_completion
= NULL
;
794 if (was_terminated
) {
795 dev_dbg(&isci_host
->pdev
->dev
,
796 "%s: before completion wait (%p)\n",
798 isci_request
->io_request_completion
);
800 /* Wait here for the request to complete. */
801 #define TERMINATION_TIMEOUT_MSEC 50
803 = wait_for_completion_timeout(
804 isci_request
->io_request_completion
,
805 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC
));
807 if (!timeout_remaining
) {
809 isci_termination_timed_out(isci_host
,
812 dev_err(&isci_host
->pdev
->dev
,
813 "%s: *** Timeout waiting for "
814 "termination(%p/%p)\n",
816 isci_request
->io_request_completion
,
820 dev_dbg(&isci_host
->pdev
->dev
,
821 "%s: after completion wait (%p)\n",
823 isci_request
->io_request_completion
);
825 /* Clear the completion pointer from the request. */
826 isci_request
->io_request_completion
= NULL
;
828 /* Peek at the status of the request. This will tell
829 * us if there was special handling on the request such that it
830 * needs to be detached and freed here.
832 spin_lock_irqsave(&isci_request
->state_lock
, flags
);
833 request_status
= isci_request_get_state(isci_request
);
835 if ((isci_request
->ttype
== io_task
) /* TMFs are in their own thread */
836 && ((request_status
== aborted
)
837 || (request_status
== aborting
)
838 || (request_status
== terminating
)
839 || (request_status
== completed
)
840 || (request_status
== dead
)
844 /* The completion routine won't free a request in
845 * the aborted/aborting/etc. states, so we do
848 needs_cleanup_handling
= true;
850 spin_unlock_irqrestore(&isci_request
->state_lock
, flags
);
852 if (needs_cleanup_handling
)
853 isci_request_cleanup_completed_loiterer(
854 isci_host
, isci_device
, isci_request
859 static void isci_terminate_request(
860 struct isci_host
*isci_host
,
861 struct isci_remote_device
*isci_device
,
862 struct isci_request
*isci_request
,
863 enum isci_request_status new_request_state
)
865 enum isci_request_status old_state
;
866 DECLARE_COMPLETION_ONSTACK(request_completion
);
868 /* Change state to "new_request_state" if it is currently "started" */
869 old_state
= isci_request_change_started_to_newstate(
875 if ((old_state
== started
) ||
876 (old_state
== completed
) ||
877 (old_state
== aborting
)) {
879 /* If the old_state is started:
880 * This request was not already being aborted. If it had been,
881 * then the aborting I/O (ie. the TMF request) would not be in
882 * the aborting state, and thus would be terminated here. Note
883 * that since the TMF completion's call to the kernel function
884 * "complete()" does not happen until the pending I/O request
885 * terminate fully completes, we do not have to implement a
886 * special wait here for already aborting requests - the
887 * termination of the TMF request will force the request
888 * to finish it's already started terminate.
890 * If old_state == completed:
891 * This request completed from the SCU hardware perspective
892 * and now just needs cleaning up in terms of freeing the
893 * request and potentially calling up to libsas.
895 * If old_state == aborting:
896 * This request has already gone through a TMF timeout, but may
897 * not have been terminated; needs cleaning up at least.
899 isci_terminate_request_core(isci_host
, isci_device
,
905 * isci_terminate_pending_requests() - This function will change the all of the
906 * requests on the given device's state to "aborting", will terminate the
907 * requests, and wait for them to complete. This function must only be
908 * called from a thread that can wait. Note that the requests are all
909 * terminated and completed (back to the host, if started there).
910 * @isci_host: This parameter specifies SCU.
911 * @isci_device: This parameter specifies the target.
915 void isci_terminate_pending_requests(
916 struct isci_host
*isci_host
,
917 struct isci_remote_device
*isci_device
,
918 enum isci_request_status new_request_state
)
920 struct isci_request
*request
;
921 struct isci_request
*next_request
;
923 struct list_head aborted_request_list
;
925 INIT_LIST_HEAD(&aborted_request_list
);
927 dev_dbg(&isci_host
->pdev
->dev
,
928 "%s: isci_device = %p (new request state = %d)\n",
929 __func__
, isci_device
, new_request_state
);
931 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
933 /* Move all of the pending requests off of the device list. */
934 list_splice_init(&isci_device
->reqs_in_process
,
935 &aborted_request_list
);
937 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
939 /* Iterate through the now-local list. */
940 list_for_each_entry_safe(request
, next_request
,
941 &aborted_request_list
, dev_node
) {
943 dev_warn(&isci_host
->pdev
->dev
,
944 "%s: isci_device=%p request=%p; task=%p\n",
946 isci_device
, request
,
947 ((request
->ttype
== io_task
)
948 ? isci_request_access_task(request
)
951 /* Mark all still pending I/O with the selected next
952 * state, terminate and free it.
954 isci_terminate_request(isci_host
, isci_device
,
955 request
, new_request_state
961 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
962 * Template functions.
963 * @lun: This parameter specifies the lun to be reset.
965 * status, zero indicates success.
967 static int isci_task_send_lu_reset_sas(
968 struct isci_host
*isci_host
,
969 struct isci_remote_device
*isci_device
,
973 int ret
= TMF_RESP_FUNC_FAILED
;
975 dev_dbg(&isci_host
->pdev
->dev
,
976 "%s: isci_host = %p, isci_device = %p\n",
977 __func__
, isci_host
, isci_device
);
978 /* Send the LUN reset to the target. By the time the call returns,
979 * the TMF has fully exected in the target (in which case the return
980 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
981 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
983 isci_task_build_tmf(&tmf
, isci_device
, isci_tmf_ssp_lun_reset
, NULL
,
986 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
987 ret
= isci_task_execute_tmf(isci_host
, &tmf
, ISCI_LU_RESET_TIMEOUT_MS
);
989 if (ret
== TMF_RESP_FUNC_COMPLETE
)
990 dev_dbg(&isci_host
->pdev
->dev
,
991 "%s: %p: TMF_LU_RESET passed\n",
992 __func__
, isci_device
);
994 dev_dbg(&isci_host
->pdev
->dev
,
995 "%s: %p: TMF_LU_RESET failed (%x)\n",
996 __func__
, isci_device
, ret
);
1002 * isci_task_lu_reset() - This function is one of the SAS Domain Template
1003 * functions. This is one of the Task Management functoins called by libsas,
1004 * to reset the given lun. Note the assumption that while this call is
1005 * executing, no I/O will be sent by the host to the device.
1006 * @lun: This parameter specifies the lun to be reset.
1008 * status, zero indicates success.
1010 int isci_task_lu_reset(struct domain_device
*domain_device
, u8
*lun
)
1012 struct isci_host
*isci_host
= dev_to_ihost(domain_device
);
1013 struct isci_remote_device
*isci_device
= NULL
;
1015 bool device_stopping
= false;
1017 isci_device
= domain_device
->lldd_dev
;
1019 dev_dbg(&isci_host
->pdev
->dev
,
1020 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
1021 __func__
, domain_device
, isci_host
, isci_device
);
1023 if (isci_device
!= NULL
)
1024 device_stopping
= (isci_device
->status
== isci_stopping
)
1025 || (isci_device
->status
== isci_stopped
);
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 int isci_task_I_T_nexus_reset(struct domain_device
*dev
)
1072 return TMF_RESP_FUNC_FAILED
;
1076 /* Task Management Functions. Must be called from process context. */
1079 * isci_abort_task_process_cb() - This is a helper function for the abort task
1080 * TMF command. It manages the request state with respect to the successful
1081 * transmission / completion of the abort task request.
1082 * @cb_state: This parameter specifies when this function was called - after
1083 * the TMF request has been started and after it has timed-out.
1084 * @tmf: This parameter specifies the TMF in progress.
1088 static void isci_abort_task_process_cb(
1089 enum isci_tmf_cb_state cb_state
,
1090 struct isci_tmf
*tmf
,
1093 struct isci_request
*old_request
;
1095 old_request
= (struct isci_request
*)cb_data
;
1097 dev_dbg(&old_request
->isci_host
->pdev
->dev
,
1098 "%s: tmf=%p, old_request=%p\n",
1099 __func__
, tmf
, old_request
);
1103 case isci_tmf_started
:
1104 /* The TMF has been started. Nothing to do here, since the
1105 * request state was already set to "aborted" by the abort
1108 if ((old_request
->status
!= aborted
)
1109 && (old_request
->status
!= completed
))
1110 dev_err(&old_request
->isci_host
->pdev
->dev
,
1111 "%s: Bad request status (%d): tmf=%p, old_request=%p\n",
1112 __func__
, old_request
->status
, tmf
, old_request
);
1115 case isci_tmf_timed_out
:
1117 /* Set the task's state to "aborting", since the abort task
1118 * function thread set it to "aborted" (above) in anticipation
1119 * of the task management request working correctly. Since the
1120 * timeout has now fired, the TMF request failed. We set the
1121 * state such that the request completion will indicate the
1122 * device is no longer present.
1124 isci_request_change_state(old_request
, aborting
);
1128 dev_err(&old_request
->isci_host
->pdev
->dev
,
1129 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1130 __func__
, cb_state
, tmf
, old_request
);
1136 * isci_task_abort_task() - This function is one of the SAS Domain Template
1137 * functions. This function is called by libsas to abort a specified task.
1138 * @task: This parameter specifies the SAS task to abort.
1140 * status, zero indicates success.
1142 int isci_task_abort_task(struct sas_task
*task
)
1144 struct isci_host
*isci_host
= dev_to_ihost(task
->dev
);
1145 DECLARE_COMPLETION_ONSTACK(aborted_io_completion
);
1146 struct isci_request
*old_request
= NULL
;
1147 enum isci_request_status old_state
;
1148 struct isci_remote_device
*isci_device
= NULL
;
1149 struct isci_tmf tmf
;
1150 int ret
= TMF_RESP_FUNC_FAILED
;
1151 unsigned long flags
;
1152 bool any_dev_reset
= false;
1153 bool device_stopping
;
1155 /* Get the isci_request reference from the task. Note that
1156 * this check does not depend on the pending request list
1157 * in the device, because tasks driving resets may land here
1158 * after completion in the core.
1160 old_request
= isci_task_get_request_from_task(task
, &isci_device
);
1162 dev_dbg(&isci_host
->pdev
->dev
,
1163 "%s: task = %p\n", __func__
, task
);
1165 /* Check if the device has been / is currently being removed.
1166 * If so, no task management will be done, and the I/O will
1169 device_stopping
= (isci_device
->status
== isci_stopping
)
1170 || (isci_device
->status
== isci_stopped
);
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 * @isci_host: This parameter specifies the ISCI host object
1418 * @request: This parameter is the completed isci_request object.
1419 * @completion_status: This parameter specifies the completion status from the
1424 void isci_task_request_complete(
1425 struct isci_host
*isci_host
,
1426 struct isci_request
*request
,
1427 enum sci_task_status completion_status
)
1429 struct isci_remote_device
*isci_device
= request
->isci_device
;
1430 enum isci_request_status old_state
;
1431 struct isci_tmf
*tmf
= isci_request_access_tmf(request
);
1432 struct completion
*tmf_complete
;
1434 dev_dbg(&isci_host
->pdev
->dev
,
1435 "%s: request = %p, status=%d\n",
1436 __func__
, request
, completion_status
);
1438 old_state
= isci_request_change_state(request
, completed
);
1440 tmf
->status
= completion_status
;
1441 request
->complete_in_target
= true;
1443 if (SAS_PROTOCOL_SSP
== tmf
->proto
) {
1445 memcpy(&tmf
->resp
.resp_iu
,
1446 scic_io_request_get_response_iu_address(
1447 request
->sci_request_handle
1449 sizeof(struct sci_ssp_response_iu
));
1451 } else if (SAS_PROTOCOL_SATA
== tmf
->proto
) {
1453 memcpy(&tmf
->resp
.d2h_fis
,
1454 scic_stp_io_request_get_d2h_reg_address(
1455 request
->sci_request_handle
),
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(isci_host
, 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(
1469 isci_host
->core_controller
,
1471 request
->sci_request_handle
);
1472 /* NULL the request handle to make sure it cannot be terminated
1473 * or completed again.
1475 request
->sci_request_handle
= NULL
;
1477 isci_request_change_state(request
, unallocated
);
1478 list_del_init(&request
->dev_node
);
1480 /* The task management part completes last. */
1481 complete(tmf_complete
);
1486 * isci_task_ssp_request_get_lun() - This function is called by the sci core to
1487 * retrieve the lun for a given task request.
1488 * @request: This parameter is the isci_request object.
1490 * lun for specified task request.
1494 * isci_task_ssp_request_get_function() - This function is called by the sci
1495 * core to retrieve the function for a given task request.
1496 * @request: This parameter is the isci_request object.
1498 * function code for specified task request.
1500 u8
isci_task_ssp_request_get_function(struct isci_request
*request
)
1502 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(request
);
1504 dev_dbg(&request
->isci_host
->pdev
->dev
,
1505 "%s: func = %d\n", __func__
, isci_tmf
->tmf_code
);
1507 return isci_tmf
->tmf_code
;
1511 * isci_task_ssp_request_get_io_tag_to_manage() - This function is called by
1512 * the sci core to retrieve the io tag for a given task request.
1513 * @request: This parameter is the isci_request object.
1515 * io tag for specified task request.
1517 u16
isci_task_ssp_request_get_io_tag_to_manage(struct isci_request
*request
)
1519 u16 io_tag
= SCI_CONTROLLER_INVALID_IO_TAG
;
1521 if (tmf_task
== request
->ttype
) {
1522 struct isci_tmf
*tmf
= isci_request_access_tmf(request
);
1523 io_tag
= tmf
->io_tag
;
1526 dev_dbg(&request
->isci_host
->pdev
->dev
,
1527 "%s: request = %p, io_tag = %d\n",
1528 __func__
, request
, io_tag
);
1534 * isci_task_ssp_request_get_response_data_address() - This function is called
1535 * by the sci core to retrieve the response data address for a given task
1537 * @request: This parameter is the isci_request object.
1539 * response data address for specified task request.
1541 void *isci_task_ssp_request_get_response_data_address(
1542 struct isci_request
*request
)
1544 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(request
);
1546 return &isci_tmf
->resp
.resp_iu
;
1550 * isci_task_ssp_request_get_response_data_length() - This function is called
1551 * by the sci core to retrieve the response data length for a given task
1553 * @request: This parameter is the isci_request object.
1555 * response data length for specified task request.
1557 u32
isci_task_ssp_request_get_response_data_length(
1558 struct isci_request
*request
)
1560 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(request
);
1562 return sizeof(isci_tmf
->resp
.resp_iu
);
1566 * isci_bus_reset_handler() - This function performs a target reset of the
1567 * device referenced by "cmd'. This function is exported through the
1568 * "struct scsi_host_template" structure such that it is called when an I/O
1569 * recovery process has escalated to a target reset. Note that this function
1570 * is called from the scsi error handler event thread, so may block on calls.
1571 * @scsi_cmd: This parameter specifies the target to be reset.
1573 * SUCCESS if the reset process was successful, else FAILED.
1575 int isci_bus_reset_handler(struct scsi_cmnd
*cmd
)
1577 struct domain_device
*dev
= cmd_to_domain_dev(cmd
);
1578 struct isci_host
*isci_host
= dev_to_ihost(dev
);
1579 unsigned long flags
= 0;
1580 enum sci_status status
;
1582 struct isci_remote_device
*isci_dev
= dev
->lldd_dev
;
1584 dev_dbg(&isci_host
->pdev
->dev
,
1585 "%s: cmd %p, isci_dev %p\n",
1586 __func__
, cmd
, isci_dev
);
1589 dev_warn(&isci_host
->pdev
->dev
,
1590 "%s: isci_dev is GONE!\n",
1593 return TMF_RESP_FUNC_COMPLETE
; /* Nothing to reset. */
1596 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
1597 status
= scic_remote_device_reset(&isci_dev
->sci
);
1598 if (status
!= SCI_SUCCESS
) {
1599 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1601 scmd_printk(KERN_WARNING
, cmd
,
1602 "%s: scic_remote_device_reset(%p) returned %d!\n",
1603 __func__
, isci_dev
, status
);
1605 return TMF_RESP_FUNC_FAILED
;
1607 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1609 /* Make sure all pending requests are able to be fully terminated. */
1610 isci_device_clear_reset_pending(isci_host
, isci_dev
);
1612 /* Terminate in-progress I/O now. */
1613 isci_remote_device_nuke_requests(isci_host
, isci_dev
);
1615 /* Call into the libsas default handler (which calls sas_phy_reset). */
1616 base_status
= sas_eh_bus_reset_handler(cmd
);
1618 if (base_status
!= SUCCESS
) {
1620 /* There can be cases where the resets to individual devices
1621 * behind an expander will fail because of an unplug of the
1624 scmd_printk(KERN_WARNING
, cmd
,
1625 "%s: sas_eh_bus_reset_handler(%p) returned %d!\n",
1626 __func__
, cmd
, base_status
);
1629 /* WHAT TO DO HERE IF sas_phy_reset FAILS? */
1630 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
1631 status
= scic_remote_device_reset_complete(&isci_dev
->sci
);
1632 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1634 if (status
!= SCI_SUCCESS
) {
1635 scmd_printk(KERN_WARNING
, cmd
,
1636 "%s: scic_remote_device_reset_complete(%p) "
1638 __func__
, isci_dev
, status
);
1640 /* WHAT TO DO HERE IF scic_remote_device_reset_complete FAILS? */
1642 dev_dbg(&isci_host
->pdev
->dev
,
1643 "%s: cmd %p, isci_dev %p complete.\n",
1644 __func__
, cmd
, isci_dev
);
1646 return TMF_RESP_FUNC_COMPLETE
;