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 <scsi/sas_ata.h>
59 #include "scic_task_request.h"
60 #include "scic_remote_device.h"
61 #include "scic_io_request.h"
62 #include "scic_sds_remote_device.h"
63 #include "scic_sds_remote_node_context.h"
70 * isci_task_complete_for_upper_layer() - This function completes the request
71 * to the upper layer driver in the case where an I/O needs to be completed
72 * back in the submit path.
73 * @host: This parameter is a pointer to the host on which the the request
74 * should be queued (either as an error or success).
75 * @task: This parameter is the completed request.
76 * @response: This parameter is the response code for the completed task.
77 * @status: This parameter is the status code for the completed task.
81 static void isci_task_complete_for_upper_layer(struct sas_task
*task
,
82 enum service_response response
,
83 enum exec_status status
,
84 enum isci_completion_selection task_notification_selection
)
86 unsigned long flags
= 0;
87 struct Scsi_Host
*host
= NULL
;
89 task_notification_selection
90 = isci_task_set_completion_status(task
, response
, status
,
91 task_notification_selection
);
93 /* Tasks aborted specifically by a call to the lldd_abort_task
94 * function should not be completed to the host in the regular path.
96 switch (task_notification_selection
) {
97 case isci_perform_normal_io_completion
:
98 /* Normal notification (task_done) */
99 dev_dbg(task
->dev
->port
->ha
->dev
,
100 "%s: Normal - task = %p, response=%d, status=%d\n",
101 __func__
, task
, response
, status
);
103 if (dev_is_sata(task
->dev
)) {
104 /* Since we are still in the submit path, and since
105 * libsas takes the host lock on behalf of SATA
106 * devices before I/O starts, we need to unlock
107 * before we can call back and report the I/O
112 && task
->dev
->port
->ha
) {
114 host
= task
->dev
->port
->ha
->core
.shost
;
115 raw_local_irq_save(flags
);
116 spin_unlock(host
->host_lock
);
118 task
->task_done(task
);
120 spin_lock(host
->host_lock
);
121 raw_local_irq_restore(flags
);
124 task
->task_done(task
);
126 task
->lldd_task
= NULL
;
129 case isci_perform_aborted_io_completion
:
130 /* No notification because this request is already in the
133 dev_warn(task
->dev
->port
->ha
->dev
,
134 "%s: Aborted - task = %p, response=%d, status=%d\n",
135 __func__
, task
, response
, status
);
138 case isci_perform_error_io_completion
:
139 /* Use sas_task_abort */
140 dev_warn(task
->dev
->port
->ha
->dev
,
141 "%s: Error - task = %p, response=%d, status=%d\n",
142 __func__
, task
, response
, status
);
143 sas_task_abort(task
);
147 dev_warn(task
->dev
->port
->ha
->dev
,
148 "%s: isci task notification default case!",
150 sas_task_abort(task
);
156 * isci_task_execute_task() - This function is one of the SAS Domain Template
157 * functions. This function is called by libsas to send a task down to
159 * @task: This parameter specifies the SAS task to send.
160 * @num: This parameter specifies the number of tasks to queue.
161 * @gfp_flags: This parameter specifies the context of this call.
163 * status, zero indicates success.
165 int isci_task_execute_task(struct sas_task
*task
, int num
, gfp_t gfp_flags
)
167 struct isci_host
*isci_host
;
168 struct isci_request
*request
= NULL
;
169 struct isci_remote_device
*device
;
172 enum sci_status status
;
173 enum isci_status device_status
;
175 dev_dbg(task
->dev
->port
->ha
->dev
, "%s: num=%d\n", __func__
, num
);
177 if ((task
->dev
== NULL
) || (task
->dev
->port
== NULL
)) {
179 /* Indicate SAS_TASK_UNDELIVERED, so that the scsi midlayer
180 * removes the target.
182 isci_task_complete_for_upper_layer(
184 SAS_TASK_UNDELIVERED
,
186 isci_perform_normal_io_completion
188 return 0; /* The I/O was accepted (and failed). */
190 isci_host
= isci_host_from_sas_ha(task
->dev
->port
->ha
);
192 /* Check if we have room for more tasks */
193 ret
= isci_host_can_queue(isci_host
, num
);
196 dev_warn(task
->dev
->port
->ha
->dev
, "%s: queue full\n", __func__
);
201 dev_dbg(task
->dev
->port
->ha
->dev
,
202 "task = %p, num = %d; dev = %p; cmd = %p\n",
203 task
, num
, task
->dev
, task
->uldd_task
);
205 if ((task
->dev
== NULL
) || (task
->dev
->port
== NULL
)) {
206 dev_warn(task
->dev
->port
->ha
->dev
,
207 "%s: task %p's port or dev == NULL!\n",
210 /* Indicate SAS_TASK_UNDELIVERED, so that the scsi
211 * midlayer removes the target.
213 isci_task_complete_for_upper_layer(
215 SAS_TASK_UNDELIVERED
,
217 isci_perform_normal_io_completion
219 /* We don't have a valid host reference, so we
220 * can't control the host queueing condition.
225 device
= isci_dev_from_domain_dev(task
->dev
);
227 isci_host
= isci_host_from_sas_ha(task
->dev
->port
->ha
);
230 device_status
= device
->status
;
232 device_status
= isci_freed
;
234 /* From this point onward, any process that needs to guarantee
235 * that there is no kernel I/O being started will have to wait
236 * for the quiesce spinlock.
239 if (device_status
!= isci_ready_for_io
) {
241 /* Forces a retry from scsi mid layer. */
242 dev_warn(task
->dev
->port
->ha
->dev
,
243 "%s: task %p: isci_host->status = %d, "
244 "device = %p; device_status = 0x%x\n\n",
247 isci_host_get_state(isci_host
),
248 device
, device_status
);
250 if (device_status
== isci_ready
) {
251 /* Indicate QUEUE_FULL so that the scsi midlayer
254 isci_task_complete_for_upper_layer(
258 isci_perform_normal_io_completion
261 /* Else, the device is going down. */
262 isci_task_complete_for_upper_layer(
264 SAS_TASK_UNDELIVERED
,
266 isci_perform_normal_io_completion
269 isci_host_can_dequeue(isci_host
, 1);
271 /* There is a device and it's ready for I/O. */
272 spin_lock_irqsave(&task
->task_state_lock
, flags
);
274 if (task
->task_state_flags
& SAS_TASK_STATE_ABORTED
) {
276 spin_unlock_irqrestore(&task
->task_state_lock
,
279 isci_task_complete_for_upper_layer(
281 SAS_TASK_UNDELIVERED
,
282 SAM_STAT_TASK_ABORTED
,
283 isci_perform_normal_io_completion
286 /* The I/O was aborted. */
289 task
->task_state_flags
|= SAS_TASK_AT_INITIATOR
;
290 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
292 /* build and send the request. */
293 status
= isci_request_execute(isci_host
, task
, &request
,
296 if (status
!= SCI_SUCCESS
) {
298 spin_lock_irqsave(&task
->task_state_lock
, flags
);
299 /* Did not really start this command. */
300 task
->task_state_flags
&= ~SAS_TASK_AT_INITIATOR
;
301 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
303 /* Indicate QUEUE_FULL so that the scsi
304 * midlayer retries. if the request
305 * failed for remote device reasons,
306 * it gets returned as
307 * SAS_TASK_UNDELIVERED next time
310 isci_task_complete_for_upper_layer(
314 isci_perform_normal_io_completion
316 isci_host_can_dequeue(isci_host
, 1);
321 task
= list_entry(task
->list
.next
, struct sas_task
, list
);
329 * isci_task_request_build() - This function builds the task request object.
330 * @isci_host: This parameter specifies the ISCI host object
331 * @request: This parameter points to the isci_request object allocated in the
332 * request construct function.
333 * @tmf: This parameter is the task management struct to be built
335 * SCI_SUCCESS on successfull completion, or specific failure code.
337 static enum sci_status
isci_task_request_build(
338 struct isci_host
*isci_host
,
339 struct isci_request
**isci_request
,
340 struct isci_tmf
*isci_tmf
)
342 struct scic_sds_remote_device
*sci_device
;
343 enum sci_status status
= SCI_FAILURE
;
344 struct isci_request
*request
;
345 struct isci_remote_device
*isci_device
;
346 /* struct sci_sas_identify_address_frame_protocols dev_protocols; */
347 struct smp_discover_response_protocols dev_protocols
;
350 dev_dbg(&isci_host
->pdev
->dev
,
351 "%s: isci_tmf = %p\n", __func__
, isci_tmf
);
353 isci_device
= isci_tmf
->device
;
354 sci_device
= to_sci_dev(isci_device
);
356 /* do common allocation and init of request object. */
357 status
= isci_request_alloc_tmf(
365 if (status
!= SCI_SUCCESS
)
368 /* let the core do it's construct. */
369 status
= scic_task_request_construct(
370 isci_host
->core_controller
,
372 SCI_CONTROLLER_INVALID_IO_TAG
,
374 request
->sci_request_mem_ptr
,
375 &request
->sci_request_handle
378 if (status
!= SCI_SUCCESS
) {
379 dev_warn(&isci_host
->pdev
->dev
,
380 "%s: scic_task_request_construct failed - "
387 sci_object_set_association(
388 request
->sci_request_handle
,
392 scic_remote_device_get_protocols(
397 /* let the core do it's protocol
398 * specific construction.
400 if (dev_protocols
.u
.bits
.attached_ssp_target
) {
402 isci_tmf
->proto
= SAS_PROTOCOL_SSP
;
403 status
= scic_task_request_construct_ssp(
404 request
->sci_request_handle
406 if (status
!= SCI_SUCCESS
)
410 if (dev_protocols
.u
.bits
.attached_stp_target
) {
412 isci_tmf
->proto
= SAS_PROTOCOL_SATA
;
413 status
= isci_sata_management_task_request_build(request
);
415 if (status
!= SCI_SUCCESS
)
423 /* release the dma memory if we fail. */
424 isci_request_free(isci_host
, request
);
428 *isci_request
= request
;
433 * isci_tmf_timeout_cb() - This function is called as a kernel callback when
434 * the timeout period for the TMF has expired.
438 static void isci_tmf_timeout_cb(void *tmf_request_arg
)
440 struct isci_request
*request
= (struct isci_request
*)tmf_request_arg
;
441 struct isci_tmf
*tmf
= isci_request_access_tmf(request
);
442 enum sci_status status
;
444 BUG_ON(request
->ttype
!= tmf_task
);
446 /* This task management request has timed-out. Terminate the request
447 * so that the request eventually completes to the requestor in the
448 * request completion callback path.
450 /* Note - the timer callback function itself has provided spinlock
451 * exclusion from the start and completion paths. No need to take
452 * the request->isci_host->scic_lock here.
455 if (tmf
->timeout_timer
!= NULL
) {
456 /* Call the users callback, if any. */
457 if (tmf
->cb_state_func
!= NULL
)
458 tmf
->cb_state_func(isci_tmf_timed_out
, tmf
,
461 /* Terminate the TMF transmit request. */
462 status
= scic_controller_terminate_request(
463 request
->isci_host
->core_controller
,
464 to_sci_dev(request
->isci_device
),
465 request
->sci_request_handle
468 dev_dbg(&request
->isci_host
->pdev
->dev
,
469 "%s: tmf_request = %p; tmf = %p; status = %d\n",
470 __func__
, request
, tmf
, status
);
472 dev_dbg(&request
->isci_host
->pdev
->dev
,
473 "%s: timer already canceled! "
474 "tmf_request = %p; tmf = %p\n",
475 __func__
, request
, tmf
);
477 /* No need to unlock since the caller to this callback is doing it for
479 * request->isci_host->scic_lock
484 * isci_task_execute_tmf() - This function builds and sends a task request,
485 * then waits for the completion.
486 * @isci_host: This parameter specifies the ISCI host object
487 * @tmf: This parameter is the pointer to the task management structure for
489 * @timeout_ms: This parameter specifies the timeout period for the task
490 * management request.
492 * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes
493 * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED.
495 int isci_task_execute_tmf(
496 struct isci_host
*isci_host
,
497 struct isci_tmf
*tmf
,
498 unsigned long timeout_ms
)
500 DECLARE_COMPLETION_ONSTACK(completion
);
501 enum sci_status status
= SCI_FAILURE
;
502 struct scic_sds_remote_device
*sci_device
;
503 struct isci_remote_device
*isci_device
= tmf
->device
;
504 struct isci_request
*request
;
505 int ret
= TMF_RESP_FUNC_FAILED
;
508 /* sanity check, return TMF_RESP_FUNC_FAILED
509 * if the device is not there and ready.
511 if (!isci_device
|| isci_device
->status
!= isci_ready_for_io
) {
512 dev_dbg(&isci_host
->pdev
->dev
,
513 "%s: isci_device = %p not ready (%d)\n",
515 isci_device
, isci_device
->status
);
516 return TMF_RESP_FUNC_FAILED
;
518 dev_dbg(&isci_host
->pdev
->dev
,
519 "%s: isci_device = %p\n",
520 __func__
, isci_device
);
522 sci_device
= to_sci_dev(isci_device
);
524 /* Assign the pointer to the TMF's completion kernel wait structure. */
525 tmf
->complete
= &completion
;
527 isci_task_request_build(
534 dev_warn(&isci_host
->pdev
->dev
,
535 "%s: isci_task_request_build failed\n",
537 return TMF_RESP_FUNC_FAILED
;
540 /* Allocate the TMF timeout timer. */
541 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
542 tmf
->timeout_timer
= isci_timer_create(isci_host
, request
, isci_tmf_timeout_cb
);
544 /* Start the timer. */
545 if (tmf
->timeout_timer
)
546 isci_timer_start(tmf
->timeout_timer
, timeout_ms
);
548 dev_warn(&isci_host
->pdev
->dev
,
549 "%s: isci_timer_create failed!!!!\n",
552 /* start the TMF io. */
553 status
= scic_controller_start_task(
554 isci_host
->core_controller
,
556 request
->sci_request_handle
,
557 SCI_CONTROLLER_INVALID_IO_TAG
560 if (status
!= SCI_SUCCESS
) {
561 dev_warn(&isci_host
->pdev
->dev
,
562 "%s: start_io failed - status = 0x%x, request = %p\n",
566 goto cleanup_request
;
569 /* Call the users callback, if any. */
570 if (tmf
->cb_state_func
!= NULL
)
571 tmf
->cb_state_func(isci_tmf_started
, tmf
, tmf
->cb_data
);
573 /* Change the state of the TMF-bearing request to "started". */
574 isci_request_change_state(request
, started
);
576 /* add the request to the remote device request list. */
577 list_add(&request
->dev_node
, &isci_device
->reqs_in_process
);
579 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
581 /* Wait for the TMF to complete, or a timeout. */
582 wait_for_completion(&completion
);
586 if (tmf
->status
== SCI_SUCCESS
)
587 ret
= TMF_RESP_FUNC_COMPLETE
;
588 else if (tmf
->status
== SCI_FAILURE_IO_RESPONSE_VALID
) {
589 dev_dbg(&isci_host
->pdev
->dev
,
591 "SCI_FAILURE_IO_RESPONSE_VALID\n",
593 ret
= TMF_RESP_FUNC_COMPLETE
;
595 /* Else - leave the default "failed" status alone. */
597 dev_dbg(&isci_host
->pdev
->dev
,
598 "%s: completed request = %p\n",
602 if (request
->io_request_completion
!= NULL
) {
604 /* The fact that this is non-NULL for a TMF request
605 * means there is a thread waiting for this TMF to
608 complete(request
->io_request_completion
);
611 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
615 /* Clean up the timer if needed. */
616 if (tmf
->timeout_timer
) {
617 isci_del_timer(isci_host
, tmf
->timeout_timer
);
618 tmf
->timeout_timer
= NULL
;
621 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
623 isci_request_free(isci_host
, request
);
628 void isci_task_build_tmf(
629 struct isci_tmf
*tmf
,
630 struct isci_remote_device
*isci_device
,
631 enum isci_tmf_function_codes code
,
632 void (*tmf_sent_cb
)(enum isci_tmf_cb_state
,
637 dev_dbg(&isci_device
->isci_port
->isci_host
->pdev
->dev
,
638 "%s: isci_device = %p\n", __func__
, isci_device
);
640 memset(tmf
, 0, sizeof(*tmf
));
642 tmf
->device
= isci_device
;
643 tmf
->tmf_code
= code
;
644 tmf
->timeout_timer
= NULL
;
645 tmf
->cb_state_func
= tmf_sent_cb
;
646 tmf
->cb_data
= cb_data
;
649 void isci_task_build_abort_task_tmf(
650 struct isci_tmf
*tmf
,
651 struct isci_remote_device
*isci_device
,
652 enum isci_tmf_function_codes code
,
653 void (*tmf_sent_cb
)(enum isci_tmf_cb_state
,
656 struct isci_request
*old_request
)
658 isci_task_build_tmf(tmf
, isci_device
, code
, tmf_sent_cb
,
659 (void *)old_request
);
660 tmf
->io_tag
= old_request
->io_tag
;
663 static struct isci_request
*isci_task_get_request_from_task(
664 struct sas_task
*task
,
665 struct isci_host
**isci_host
,
666 struct isci_remote_device
**isci_device
)
669 struct isci_request
*request
= NULL
;
672 spin_lock_irqsave(&task
->task_state_lock
, flags
);
674 request
= task
->lldd_task
;
676 /* If task is already done, the request isn't valid */
677 if (!(task
->task_state_flags
& SAS_TASK_STATE_DONE
) &&
678 (task
->task_state_flags
& SAS_TASK_AT_INITIATOR
) &&
681 if (isci_host
!= NULL
)
682 *isci_host
= request
->isci_host
;
684 if (isci_device
!= NULL
)
685 *isci_device
= request
->isci_device
;
688 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
694 * isci_task_validate_request_to_abort() - This function checks the given I/O
695 * against the "started" state. If the request is still "started", it's
696 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
697 * BEFORE CALLING THIS FUNCTION.
698 * @isci_request: This parameter specifies the request object to control.
699 * @isci_host: This parameter specifies the ISCI host object
700 * @isci_device: This is the device to which the request is pending.
701 * @aborted_io_completion: This is a completion structure that will be added to
702 * the request in case it is changed to aborting; this completion is
703 * triggered when the request is fully completed.
705 * Either "started" on successful change of the task status to "aborted", or
706 * "unallocated" if the task cannot be controlled.
708 static enum isci_request_status
isci_task_validate_request_to_abort(
709 struct isci_request
*isci_request
,
710 struct isci_host
*isci_host
,
711 struct isci_remote_device
*isci_device
,
712 struct completion
*aborted_io_completion
)
714 enum isci_request_status old_state
= unallocated
;
716 /* Only abort the task if it's in the
717 * device's request_in_process list
719 if (isci_request
&& !list_empty(&isci_request
->dev_node
)) {
720 old_state
= isci_request_change_started_to_aborted(
721 isci_request
, aborted_io_completion
);
728 static void isci_request_cleanup_completed_loiterer(
729 struct isci_host
*isci_host
,
730 struct isci_remote_device
*isci_device
,
731 struct isci_request
*isci_request
)
733 struct sas_task
*task
;
736 task
= (isci_request
->ttype
== io_task
)
737 ? isci_request_access_task(isci_request
)
740 dev_dbg(&isci_host
->pdev
->dev
,
741 "%s: isci_device=%p, request=%p, task=%p\n",
742 __func__
, isci_device
, isci_request
, task
);
744 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
745 list_del_init(&isci_request
->dev_node
);
746 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
750 spin_lock_irqsave(&task
->task_state_lock
, flags
);
751 task
->lldd_task
= NULL
;
753 isci_set_task_doneflags(task
);
755 /* If this task is not in the abort path, call task_done. */
756 if (!(task
->task_state_flags
& SAS_TASK_STATE_ABORTED
)) {
758 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
759 task
->task_done(task
);
761 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
763 isci_request_free(isci_host
, isci_request
);
767 * @isci_termination_timed_out(): this function will deal with a request for
768 * which the wait for termination has timed-out.
770 * @isci_host This SCU.
771 * @isci_request The I/O request being terminated.
774 isci_termination_timed_out(
775 struct isci_host
* host
,
776 struct isci_request
* request
779 unsigned long state_flags
;
781 dev_warn(&host
->pdev
->dev
,
782 "%s: host = %p; request = %p\n",
783 __func__
, host
, request
);
785 /* At this point, the request to terminate
786 * has timed out. The best we can do is to
787 * have the request die a silent death
788 * if it ever completes.
790 spin_lock_irqsave(&request
->state_lock
, state_flags
);
792 if (request
->status
== started
) {
794 /* Set the request state to "dead",
795 * and clear the task pointer so that an actual
796 * completion event callback doesn't do
799 request
->status
= dead
;
801 /* Clear the timeout completion event pointer.*/
802 request
->io_request_completion
= NULL
;
804 if (request
->ttype
== io_task
) {
806 /* Break links with the sas_task. */
807 if (request
->ttype_ptr
.io_task_ptr
!= NULL
) {
809 request
->ttype_ptr
.io_task_ptr
->lldd_task
= NULL
;
810 request
->ttype_ptr
.io_task_ptr
= NULL
;
814 spin_unlock_irqrestore(&request
->state_lock
, state_flags
);
819 * isci_terminate_request_core() - This function will terminate the given
820 * request, and wait for it to complete. This function must only be called
821 * from a thread that can wait. Note that the request is terminated and
822 * completed (back to the host, if started there).
823 * @isci_host: This SCU.
824 * @isci_device: The target.
825 * @isci_request: The I/O request to be terminated.
829 static void isci_terminate_request_core(
830 struct isci_host
*isci_host
,
831 struct isci_remote_device
*isci_device
,
832 struct isci_request
*isci_request
)
834 enum sci_status status
= SCI_SUCCESS
;
835 bool was_terminated
= false;
836 bool needs_cleanup_handling
= false;
837 enum isci_request_status request_status
;
839 unsigned long timeout_remaining
;
842 dev_dbg(&isci_host
->pdev
->dev
,
843 "%s: device = %p; request = %p\n",
844 __func__
, isci_device
, isci_request
);
846 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
848 /* Note that we are not going to control
849 * the target to abort the request.
851 isci_request
->complete_in_target
= true;
853 /* Make sure the request wasn't just sitting around signalling
854 * device condition (if the request handle is NULL, then the
855 * request completed but needed additional handling here).
857 if (isci_request
->sci_request_handle
!= NULL
) {
858 was_terminated
= true;
859 needs_cleanup_handling
= true;
860 status
= scic_controller_terminate_request(
861 isci_host
->core_controller
,
862 to_sci_dev(isci_device
),
863 isci_request
->sci_request_handle
866 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
869 * The only time the request to terminate will
870 * fail is when the io request is completed and
873 if (status
!= SCI_SUCCESS
) {
874 dev_err(&isci_host
->pdev
->dev
,
875 "%s: scic_controller_terminate_request"
876 " returned = 0x%x\n",
879 /* Clear the completion pointer from the request. */
880 isci_request
->io_request_completion
= NULL
;
883 if (was_terminated
) {
884 dev_dbg(&isci_host
->pdev
->dev
,
885 "%s: before completion wait (%p)\n",
887 isci_request
->io_request_completion
);
889 /* Wait here for the request to complete. */
890 #define TERMINATION_TIMEOUT_MSEC 50
892 = wait_for_completion_timeout(
893 isci_request
->io_request_completion
,
894 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC
));
896 if (!timeout_remaining
) {
898 isci_termination_timed_out(isci_host
,
901 dev_err(&isci_host
->pdev
->dev
,
902 "%s: *** Timeout waiting for "
903 "termination(%p/%p)\n",
905 isci_request
->io_request_completion
,
909 dev_dbg(&isci_host
->pdev
->dev
,
910 "%s: after completion wait (%p)\n",
912 isci_request
->io_request_completion
);
914 /* Clear the completion pointer from the request. */
915 isci_request
->io_request_completion
= NULL
;
917 /* Peek at the status of the request. This will tell
918 * us if there was special handling on the request such that it
919 * needs to be detached and freed here.
921 spin_lock_irqsave(&isci_request
->state_lock
, flags
);
922 request_status
= isci_request_get_state(isci_request
);
924 if ((isci_request
->ttype
== io_task
) /* TMFs are in their own thread */
925 && ((request_status
== aborted
)
926 || (request_status
== aborting
)
927 || (request_status
== terminating
)
928 || (request_status
== completed
)
929 || (request_status
== dead
)
933 /* The completion routine won't free a request in
934 * the aborted/aborting/etc. states, so we do
937 needs_cleanup_handling
= true;
939 spin_unlock_irqrestore(&isci_request
->state_lock
, flags
);
941 if (needs_cleanup_handling
)
942 isci_request_cleanup_completed_loiterer(
943 isci_host
, isci_device
, isci_request
948 static void isci_terminate_request(
949 struct isci_host
*isci_host
,
950 struct isci_remote_device
*isci_device
,
951 struct isci_request
*isci_request
,
952 enum isci_request_status new_request_state
)
954 enum isci_request_status old_state
;
955 DECLARE_COMPLETION_ONSTACK(request_completion
);
957 /* Change state to "new_request_state" if it is currently "started" */
958 old_state
= isci_request_change_started_to_newstate(
964 if ((old_state
== started
) || (old_state
== completed
)) {
966 /* If the old_state is started:
967 * This request was not already being aborted. If it had been,
968 * then the aborting I/O (ie. the TMF request) would not be in
969 * the aborting state, and thus would be terminated here. Note
970 * that since the TMF completion's call to the kernel function
971 * "complete()" does not happen until the pending I/O request
972 * terminate fully completes, we do not have to implement a
973 * special wait here for already aborting requests - the
974 * termination of the TMF request will force the request
975 * to finish it's already started terminate.
977 * If old_state == completed:
978 * This request completed from the SCU hardware perspective
979 * and now just needs cleaning up in terms of freeing the
980 * request and potentially calling up to libsas.
982 isci_terminate_request_core(isci_host
, isci_device
,
988 * isci_terminate_pending_requests() - This function will change the all of the
989 * requests on the given device's state to "aborting", will terminate the
990 * requests, and wait for them to complete. This function must only be
991 * called from a thread that can wait. Note that the requests are all
992 * terminated and completed (back to the host, if started there).
993 * @isci_host: This parameter specifies SCU.
994 * @isci_device: This parameter specifies the target.
998 void isci_terminate_pending_requests(
999 struct isci_host
*isci_host
,
1000 struct isci_remote_device
*isci_device
,
1001 enum isci_request_status new_request_state
)
1003 struct isci_request
*request
;
1004 struct isci_request
*next_request
;
1005 unsigned long flags
;
1006 struct list_head aborted_request_list
;
1008 INIT_LIST_HEAD(&aborted_request_list
);
1010 dev_dbg(&isci_host
->pdev
->dev
,
1011 "%s: isci_device = %p (new request state = %d)\n",
1012 __func__
, isci_device
, new_request_state
);
1014 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
1016 /* Move all of the pending requests off of the device list. */
1017 list_splice_init(&isci_device
->reqs_in_process
,
1018 &aborted_request_list
);
1020 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1022 /* Iterate through the now-local list. */
1023 list_for_each_entry_safe(request
, next_request
,
1024 &aborted_request_list
, dev_node
) {
1026 dev_warn(&isci_host
->pdev
->dev
,
1027 "%s: isci_device=%p request=%p; task=%p\n",
1029 isci_device
, request
,
1030 ((request
->ttype
== io_task
)
1031 ? isci_request_access_task(request
)
1034 /* Mark all still pending I/O with the selected next
1035 * state, terminate and free it.
1037 isci_terminate_request(isci_host
, isci_device
,
1038 request
, new_request_state
1044 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
1045 * Template functions.
1046 * @lun: This parameter specifies the lun to be reset.
1048 * status, zero indicates success.
1050 static int isci_task_send_lu_reset_sas(
1051 struct isci_host
*isci_host
,
1052 struct isci_remote_device
*isci_device
,
1055 struct isci_tmf tmf
;
1056 int ret
= TMF_RESP_FUNC_FAILED
;
1058 dev_dbg(&isci_host
->pdev
->dev
,
1059 "%s: isci_host = %p, isci_device = %p\n",
1060 __func__
, isci_host
, isci_device
);
1061 /* Send the LUN reset to the target. By the time the call returns,
1062 * the TMF has fully exected in the target (in which case the return
1063 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
1064 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
1066 isci_task_build_tmf(&tmf
, isci_device
, isci_tmf_ssp_lun_reset
, NULL
,
1069 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
1070 ret
= isci_task_execute_tmf(isci_host
, &tmf
, ISCI_LU_RESET_TIMEOUT_MS
);
1072 if (ret
== TMF_RESP_FUNC_COMPLETE
)
1073 dev_dbg(&isci_host
->pdev
->dev
,
1074 "%s: %p: TMF_LU_RESET passed\n",
1075 __func__
, isci_device
);
1077 dev_dbg(&isci_host
->pdev
->dev
,
1078 "%s: %p: TMF_LU_RESET failed (%x)\n",
1079 __func__
, isci_device
, ret
);
1085 * isci_task_lu_reset() - This function is one of the SAS Domain Template
1086 * functions. This is one of the Task Management functoins called by libsas,
1087 * to reset the given lun. Note the assumption that while this call is
1088 * executing, no I/O will be sent by the host to the device.
1089 * @lun: This parameter specifies the lun to be reset.
1091 * status, zero indicates success.
1093 int isci_task_lu_reset(
1094 struct domain_device
*domain_device
,
1097 struct isci_host
*isci_host
= NULL
;
1098 struct isci_remote_device
*isci_device
= NULL
;
1100 bool device_stopping
= false;
1102 if (domain_device
== NULL
) {
1103 pr_warn("%s: domain_device == NULL\n", __func__
);
1104 return TMF_RESP_FUNC_FAILED
;
1107 isci_device
= isci_dev_from_domain_dev(domain_device
);
1109 if (domain_device
->port
!= NULL
)
1110 isci_host
= isci_host_from_sas_ha(domain_device
->port
->ha
);
1112 pr_debug("%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
1113 __func__
, domain_device
, isci_host
, isci_device
);
1115 if (isci_device
!= NULL
)
1116 device_stopping
= (isci_device
->status
== isci_stopping
)
1117 || (isci_device
->status
== isci_stopped
);
1119 /* If there is a device reset pending on any request in the
1120 * device's list, fail this LUN reset request in order to
1121 * escalate to the device reset.
1123 if ((isci_device
== NULL
) ||
1124 (isci_host
== NULL
) ||
1125 ((isci_host
!= NULL
) &&
1126 (isci_device
!= NULL
) &&
1128 (isci_device_is_reset_pending(isci_host
, isci_device
))))) {
1129 dev_warn(&isci_host
->pdev
->dev
,
1130 "%s: No dev (%p), no host (%p), or "
1131 "RESET PENDING: domain_device=%p\n",
1132 __func__
, isci_device
, isci_host
, domain_device
);
1133 return TMF_RESP_FUNC_FAILED
;
1136 /* Send the task management part of the reset. */
1137 if (sas_protocol_ata(domain_device
->tproto
)) {
1138 ret
= isci_task_send_lu_reset_sata(
1139 isci_host
, isci_device
, lun
1142 ret
= isci_task_send_lu_reset_sas(isci_host
, isci_device
, lun
);
1144 /* If the LUN reset worked, all the I/O can now be terminated. */
1145 if (ret
== TMF_RESP_FUNC_COMPLETE
)
1146 /* Terminate all I/O now. */
1147 isci_terminate_pending_requests(isci_host
,
1155 /* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
1156 int isci_task_clear_nexus_port(struct asd_sas_port
*port
)
1158 return TMF_RESP_FUNC_FAILED
;
1163 int isci_task_clear_nexus_ha(struct sas_ha_struct
*ha
)
1165 return TMF_RESP_FUNC_FAILED
;
1168 int isci_task_I_T_nexus_reset(struct domain_device
*dev
)
1170 return TMF_RESP_FUNC_FAILED
;
1174 /* Task Management Functions. Must be called from process context. */
1177 * isci_abort_task_process_cb() - This is a helper function for the abort task
1178 * TMF command. It manages the request state with respect to the successful
1179 * transmission / completion of the abort task request.
1180 * @cb_state: This parameter specifies when this function was called - after
1181 * the TMF request has been started and after it has timed-out.
1182 * @tmf: This parameter specifies the TMF in progress.
1186 static void isci_abort_task_process_cb(
1187 enum isci_tmf_cb_state cb_state
,
1188 struct isci_tmf
*tmf
,
1191 struct isci_request
*old_request
;
1193 old_request
= (struct isci_request
*)cb_data
;
1195 dev_dbg(&old_request
->isci_host
->pdev
->dev
,
1196 "%s: tmf=%p, old_request=%p\n",
1197 __func__
, tmf
, old_request
);
1201 case isci_tmf_started
:
1202 /* The TMF has been started. Nothing to do here, since the
1203 * request state was already set to "aborted" by the abort
1206 BUG_ON((old_request
->status
!= aborted
)
1207 && (old_request
->status
!= completed
));
1210 case isci_tmf_timed_out
:
1212 /* Set the task's state to "aborting", since the abort task
1213 * function thread set it to "aborted" (above) in anticipation
1214 * of the task management request working correctly. Since the
1215 * timeout has now fired, the TMF request failed. We set the
1216 * state such that the request completion will indicate the
1217 * device is no longer present.
1219 isci_request_change_state(old_request
, aborting
);
1223 dev_err(&old_request
->isci_host
->pdev
->dev
,
1224 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1225 __func__
, cb_state
, tmf
, old_request
);
1231 * isci_task_abort_task() - This function is one of the SAS Domain Template
1232 * functions. This function is called by libsas to abort a specified task.
1233 * @task: This parameter specifies the SAS task to abort.
1235 * status, zero indicates success.
1237 int isci_task_abort_task(struct sas_task
*task
)
1239 DECLARE_COMPLETION_ONSTACK(aborted_io_completion
);
1240 struct isci_request
*old_request
= NULL
;
1241 enum isci_request_status old_state
;
1242 struct isci_remote_device
*isci_device
= NULL
;
1243 struct isci_host
*isci_host
= NULL
;
1244 struct isci_tmf tmf
;
1245 int ret
= TMF_RESP_FUNC_FAILED
;
1246 unsigned long flags
;
1247 bool any_dev_reset
= false;
1248 bool device_stopping
;
1250 /* Get the isci_request reference from the task. Note that
1251 * this check does not depend on the pending request list
1252 * in the device, because tasks driving resets may land here
1253 * after completion in the core.
1255 old_request
= isci_task_get_request_from_task(task
, &isci_host
,
1258 dev_dbg(&isci_host
->pdev
->dev
,
1259 "%s: task = %p\n", __func__
, task
);
1261 /* Check if the device has been / is currently being removed.
1262 * If so, no task management will be done, and the I/O will
1265 device_stopping
= (isci_device
->status
== isci_stopping
)
1266 || (isci_device
->status
== isci_stopped
);
1268 /* This version of the driver will fail abort requests for
1269 * SATA/STP. Failing the abort request this way will cause the
1270 * SCSI error handler thread to escalate to LUN reset
1272 if (sas_protocol_ata(task
->task_proto
) && !device_stopping
) {
1273 dev_warn(&isci_host
->pdev
->dev
,
1274 " task %p is for a STP/SATA device;"
1275 " returning TMF_RESP_FUNC_FAILED\n"
1276 " to cause a LUN reset...\n", task
);
1277 return TMF_RESP_FUNC_FAILED
;
1280 dev_dbg(&isci_host
->pdev
->dev
,
1281 "%s: old_request == %p\n", __func__
, old_request
);
1283 if (!device_stopping
)
1284 any_dev_reset
= isci_device_is_reset_pending(isci_host
,isci_device
);
1286 spin_lock_irqsave(&task
->task_state_lock
, flags
);
1288 /* Don't do resets to stopping devices. */
1289 if (device_stopping
) {
1291 task
->task_state_flags
&= ~SAS_TASK_NEED_DEV_RESET
;
1292 any_dev_reset
= false;
1294 } else /* See if there is a pending device reset for this device. */
1295 any_dev_reset
= any_dev_reset
1296 || (task
->task_state_flags
& SAS_TASK_NEED_DEV_RESET
);
1298 /* If the extraction of the request reference from the task
1299 * failed, then the request has been completed (or if there is a
1300 * pending reset then this abort request function must be failed
1301 * in order to escalate to the target reset).
1303 if ((old_request
== NULL
) || any_dev_reset
) {
1305 /* If the device reset task flag is set, fail the task
1306 * management request. Otherwise, the original request
1309 if (any_dev_reset
) {
1311 /* Turn off the task's DONE to make sure this
1312 * task is escalated to a target reset.
1314 task
->task_state_flags
&= ~SAS_TASK_STATE_DONE
;
1316 /* Make the reset happen as soon as possible. */
1317 task
->task_state_flags
|= SAS_TASK_NEED_DEV_RESET
;
1319 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1321 /* Fail the task management request in order to
1322 * escalate to the target reset.
1324 ret
= TMF_RESP_FUNC_FAILED
;
1326 dev_dbg(&isci_host
->pdev
->dev
,
1327 "%s: Failing task abort in order to "
1328 "escalate to target reset because\n"
1329 "SAS_TASK_NEED_DEV_RESET is set for "
1330 "task %p on dev %p\n",
1331 __func__
, task
, isci_device
);
1335 /* The request has already completed and there
1336 * is nothing to do here other than to set the task
1337 * done bit, and indicate that the task abort function
1340 isci_set_task_doneflags(task
);
1342 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1344 ret
= TMF_RESP_FUNC_COMPLETE
;
1346 dev_dbg(&isci_host
->pdev
->dev
,
1347 "%s: abort task not needed for %p\n",
1354 spin_unlock_irqrestore(&task
->task_state_lock
, flags
);
1356 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
1358 /* Check the request status and change to "aborting" if currently
1359 * "starting"; if true then set the I/O kernel completion
1360 * struct that will be triggered when the request completes.
1362 old_state
= isci_task_validate_request_to_abort(
1363 old_request
, isci_host
, isci_device
,
1364 &aborted_io_completion
);
1365 if ((old_state
!= started
) && (old_state
!= completed
)) {
1367 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1369 /* The request was already being handled by someone else (because
1370 * they got to set the state away from started).
1372 dev_dbg(&isci_host
->pdev
->dev
,
1373 "%s: device = %p; old_request %p already being aborted\n",
1375 isci_device
, old_request
);
1377 return TMF_RESP_FUNC_COMPLETE
;
1379 if ((task
->task_proto
== SAS_PROTOCOL_SMP
)
1381 || old_request
->complete_in_target
1384 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1386 dev_dbg(&isci_host
->pdev
->dev
,
1387 "%s: SMP request (%d)"
1388 " or device is stopping (%d)"
1389 " or complete_in_target (%d), thus no TMF\n",
1390 __func__
, (task
->task_proto
== SAS_PROTOCOL_SMP
),
1391 device_stopping
, old_request
->complete_in_target
);
1393 /* Set the state on the task. */
1394 isci_task_all_done(task
);
1396 ret
= TMF_RESP_FUNC_COMPLETE
;
1398 /* Stopping and SMP devices are not sent a TMF, and are not
1399 * reset, but the outstanding I/O request is terminated below.
1402 /* Fill in the tmf stucture */
1403 isci_task_build_abort_task_tmf(&tmf
, isci_device
,
1404 isci_tmf_ssp_task_abort
,
1405 isci_abort_task_process_cb
,
1408 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1410 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */
1411 ret
= isci_task_execute_tmf(isci_host
, &tmf
,
1412 ISCI_ABORT_TASK_TIMEOUT_MS
);
1414 if (ret
!= TMF_RESP_FUNC_COMPLETE
)
1415 dev_err(&isci_host
->pdev
->dev
,
1416 "%s: isci_task_send_tmf failed\n",
1419 if (ret
== TMF_RESP_FUNC_COMPLETE
) {
1420 old_request
->complete_in_target
= true;
1422 /* Clean up the request on our side, and wait for the aborted I/O to
1425 isci_terminate_request_core(isci_host
, isci_device
, old_request
);
1428 /* Make sure we do not leave a reference to aborted_io_completion */
1429 old_request
->io_request_completion
= NULL
;
1434 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
1435 * functions. This is one of the Task Management functoins called by libsas,
1436 * to abort all task for the given lun.
1437 * @d_device: This parameter specifies the domain device associated with this
1439 * @lun: This parameter specifies the lun associated with this request.
1441 * status, zero indicates success.
1443 int isci_task_abort_task_set(
1444 struct domain_device
*d_device
,
1447 return TMF_RESP_FUNC_FAILED
;
1452 * isci_task_clear_aca() - This function is one of the SAS Domain Template
1453 * functions. This is one of the Task Management functoins called by libsas.
1454 * @d_device: This parameter specifies the domain device associated with this
1456 * @lun: This parameter specifies the lun associated with this request.
1458 * status, zero indicates success.
1460 int isci_task_clear_aca(
1461 struct domain_device
*d_device
,
1464 return TMF_RESP_FUNC_FAILED
;
1470 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
1471 * functions. This is one of the Task Management functoins called by libsas.
1472 * @d_device: This parameter specifies the domain device associated with this
1474 * @lun: This parameter specifies the lun associated with this request.
1476 * status, zero indicates success.
1478 int isci_task_clear_task_set(
1479 struct domain_device
*d_device
,
1482 return TMF_RESP_FUNC_FAILED
;
1487 * isci_task_query_task() - This function is implemented to cause libsas to
1488 * correctly escalate the failed abort to a LUN or target reset (this is
1489 * because sas_scsi_find_task libsas function does not correctly interpret
1490 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
1491 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
1492 * returned, libsas will turn this into a target reset
1493 * @task: This parameter specifies the sas task being queried.
1494 * @lun: This parameter specifies the lun associated with this request.
1496 * status, zero indicates success.
1498 int isci_task_query_task(
1499 struct sas_task
*task
)
1501 /* See if there is a pending device reset for this device. */
1502 if (task
->task_state_flags
& SAS_TASK_NEED_DEV_RESET
)
1503 return TMF_RESP_FUNC_FAILED
;
1505 return TMF_RESP_FUNC_SUCC
;
1509 * isci_task_request_complete() - This function is called by the sci core when
1510 * an task request completes.
1511 * @isci_host: This parameter specifies the ISCI host object
1512 * @request: This parameter is the completed isci_request object.
1513 * @completion_status: This parameter specifies the completion status from the
1518 void isci_task_request_complete(
1519 struct isci_host
*isci_host
,
1520 struct isci_request
*request
,
1521 enum sci_task_status completion_status
)
1523 struct isci_remote_device
*isci_device
= request
->isci_device
;
1524 enum isci_request_status old_state
;
1525 struct isci_tmf
*tmf
= isci_request_access_tmf(request
);
1526 struct completion
*tmf_complete
;
1528 dev_dbg(&isci_host
->pdev
->dev
,
1529 "%s: request = %p, status=%d\n",
1530 __func__
, request
, completion_status
);
1532 old_state
= isci_request_change_state(request
, completed
);
1534 tmf
->status
= completion_status
;
1535 request
->complete_in_target
= true;
1537 if (SAS_PROTOCOL_SSP
== tmf
->proto
) {
1539 memcpy(&tmf
->resp
.resp_iu
,
1540 scic_io_request_get_response_iu_address(
1541 request
->sci_request_handle
1543 sizeof(struct sci_ssp_response_iu
));
1545 } else if (SAS_PROTOCOL_SATA
== tmf
->proto
) {
1547 memcpy(&tmf
->resp
.d2h_fis
,
1548 scic_stp_io_request_get_d2h_reg_address(
1549 request
->sci_request_handle
1551 sizeof(struct sata_fis_reg_d2h
)
1555 /* Manage the timer if it is still running. */
1556 if (tmf
->timeout_timer
) {
1557 isci_del_timer(isci_host
, tmf
->timeout_timer
);
1558 tmf
->timeout_timer
= NULL
;
1561 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1562 tmf_complete
= tmf
->complete
;
1564 scic_controller_complete_task(
1565 isci_host
->core_controller
,
1566 to_sci_dev(isci_device
),
1567 request
->sci_request_handle
1569 /* NULL the request handle to make sure it cannot be terminated
1570 * or completed again.
1572 request
->sci_request_handle
= NULL
;
1574 isci_request_change_state(request
, unallocated
);
1575 list_del_init(&request
->dev_node
);
1577 /* The task management part completes last. */
1578 complete(tmf_complete
);
1583 * isci_task_ssp_request_get_lun() - This function is called by the sci core to
1584 * retrieve the lun for a given task request.
1585 * @request: This parameter is the isci_request object.
1587 * lun for specified task request.
1589 u32
isci_task_ssp_request_get_lun(struct isci_request
*request
)
1591 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(request
);
1593 dev_dbg(&request
->isci_host
->pdev
->dev
,
1594 "%s: lun = %d\n", __func__
, isci_tmf
->lun
[0]);
1595 /* @todo: build lun from array of bytes to 32 bit */
1596 return isci_tmf
->lun
[0];
1600 * isci_task_ssp_request_get_function() - This function is called by the sci
1601 * core to retrieve the function for a given task request.
1602 * @request: This parameter is the isci_request object.
1604 * function code for specified task request.
1606 u8
isci_task_ssp_request_get_function(struct isci_request
*request
)
1608 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(request
);
1610 dev_dbg(&request
->isci_host
->pdev
->dev
,
1611 "%s: func = %d\n", __func__
, isci_tmf
->tmf_code
);
1613 return isci_tmf
->tmf_code
;
1617 * isci_task_ssp_request_get_io_tag_to_manage() - This function is called by
1618 * the sci core to retrieve the io tag for a given task request.
1619 * @request: This parameter is the isci_request object.
1621 * io tag for specified task request.
1623 u16
isci_task_ssp_request_get_io_tag_to_manage(struct isci_request
*request
)
1625 u16 io_tag
= SCI_CONTROLLER_INVALID_IO_TAG
;
1627 if (tmf_task
== request
->ttype
) {
1628 struct isci_tmf
*tmf
= isci_request_access_tmf(request
);
1629 io_tag
= tmf
->io_tag
;
1632 dev_dbg(&request
->isci_host
->pdev
->dev
,
1633 "%s: request = %p, io_tag = %d\n",
1634 __func__
, request
, io_tag
);
1640 * isci_task_ssp_request_get_response_data_address() - This function is called
1641 * by the sci core to retrieve the response data address for a given task
1643 * @request: This parameter is the isci_request object.
1645 * response data address for specified task request.
1647 void *isci_task_ssp_request_get_response_data_address(
1648 struct isci_request
*request
)
1650 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(request
);
1652 return &isci_tmf
->resp
.resp_iu
;
1656 * isci_task_ssp_request_get_response_data_length() - This function is called
1657 * by the sci core to retrieve the response data length for a given task
1659 * @request: This parameter is the isci_request object.
1661 * response data length for specified task request.
1663 u32
isci_task_ssp_request_get_response_data_length(
1664 struct isci_request
*request
)
1666 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(request
);
1668 return sizeof(isci_tmf
->resp
.resp_iu
);
1672 * isci_bus_reset_handler() - This function performs a target reset of the
1673 * device referenced by "cmd'. This function is exported through the
1674 * "struct scsi_host_template" structure such that it is called when an I/O
1675 * recovery process has escalated to a target reset. Note that this function
1676 * is called from the scsi error handler event thread, so may block on calls.
1677 * @scsi_cmd: This parameter specifies the target to be reset.
1679 * SUCCESS if the reset process was successful, else FAILED.
1681 int isci_bus_reset_handler(struct scsi_cmnd
*cmd
)
1683 unsigned long flags
= 0;
1684 struct isci_host
*isci_host
= NULL
;
1685 enum sci_status status
;
1687 struct isci_remote_device
*isci_dev
1688 = isci_dev_from_domain_dev(
1689 sdev_to_domain_dev(cmd
->device
));
1691 dev_dbg(&cmd
->device
->sdev_gendev
,
1692 "%s: cmd %p, isci_dev %p\n",
1693 __func__
, cmd
, isci_dev
);
1696 dev_warn(&cmd
->device
->sdev_gendev
,
1697 "%s: isci_dev is GONE!\n",
1700 return TMF_RESP_FUNC_COMPLETE
; /* Nothing to reset. */
1703 if (isci_dev
->isci_port
!= NULL
)
1704 isci_host
= isci_dev
->isci_port
->isci_host
;
1706 if (isci_host
!= NULL
)
1707 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
1709 status
= scic_remote_device_reset(to_sci_dev(isci_dev
));
1710 if (status
!= SCI_SUCCESS
) {
1712 if (isci_host
!= NULL
)
1713 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1715 scmd_printk(KERN_WARNING
, cmd
,
1716 "%s: scic_remote_device_reset(%p) returned %d!\n",
1717 __func__
, isci_dev
, status
);
1719 return TMF_RESP_FUNC_FAILED
;
1721 if (isci_host
!= NULL
)
1722 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1724 /* Make sure all pending requests are able to be fully terminated. */
1725 isci_device_clear_reset_pending(isci_dev
);
1727 /* Terminate in-progress I/O now. */
1728 isci_remote_device_nuke_requests(isci_dev
);
1730 /* Call into the libsas default handler (which calls sas_phy_reset). */
1731 base_status
= sas_eh_bus_reset_handler(cmd
);
1733 if (base_status
!= SUCCESS
) {
1735 /* There can be cases where the resets to individual devices
1736 * behind an expander will fail because of an unplug of the
1739 scmd_printk(KERN_WARNING
, cmd
,
1740 "%s: sas_eh_bus_reset_handler(%p) returned %d!\n",
1741 __func__
, cmd
, base_status
);
1744 /* WHAT TO DO HERE IF sas_phy_reset FAILS? */
1746 if (isci_host
!= NULL
)
1747 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
1748 status
= scic_remote_device_reset_complete(to_sci_dev(isci_dev
));
1750 if (isci_host
!= NULL
)
1751 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
1753 if (status
!= SCI_SUCCESS
) {
1754 scmd_printk(KERN_WARNING
, cmd
,
1755 "%s: scic_remote_device_reset_complete(%p) "
1757 __func__
, isci_dev
, status
);
1759 /* WHAT TO DO HERE IF scic_remote_device_reset_complete FAILS? */
1761 dev_dbg(&cmd
->device
->sdev_gendev
,
1762 "%s: cmd %p, isci_dev %p complete.\n",
1763 __func__
, cmd
, isci_dev
);
1765 return TMF_RESP_FUNC_COMPLETE
;