isci: Removed sci_base_object from scic_sds_request.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / request.c
blobc45e78e41f27a16b34e54f8fed2bd82ebd96bfb4
1 /*
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.
5 * GPL LICENSE SUMMARY
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.
24 * BSD LICENSE
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
31 * are met:
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
38 * distribution.
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 "isci.h"
57 #include "scic_io_request.h"
58 #include "scic_task_request.h"
59 #include "scic_port.h"
60 #include "task.h"
61 #include "request.h"
62 #include "sata.h"
63 #include "scu_completion_codes.h"
64 #include "core/scic_sds_request.h"
66 static enum sci_status isci_request_ssp_request_construct(
67 struct isci_request *request)
69 enum sci_status status;
71 dev_dbg(&request->isci_host->pdev->dev,
72 "%s: request = %p\n",
73 __func__,
74 request);
75 status = scic_io_request_construct_basic_ssp(
76 request->sci_request_handle
78 return status;
81 static enum sci_status isci_request_stp_request_construct(
82 struct isci_request *request)
84 struct sas_task *task = isci_request_access_task(request);
85 enum sci_status status;
86 struct host_to_dev_fis *register_fis;
88 dev_dbg(&request->isci_host->pdev->dev,
89 "%s: request = %p\n",
90 __func__,
91 request);
93 /* Get the host_to_dev_fis from the core and copy
94 * the fis from the task into it.
96 register_fis = isci_sata_task_to_fis_copy(task);
98 status = scic_io_request_construct_basic_sata(
99 request->sci_request_handle
102 /* Set the ncq tag in the fis, from the queue
103 * command in the task.
105 if (isci_sata_is_task_ncq(task)) {
107 isci_sata_set_ncq_tag(
108 register_fis,
109 task
113 return status;
117 * isci_smp_request_build() - This function builds the smp request object.
118 * @isci_host: This parameter specifies the ISCI host object
119 * @request: This parameter points to the isci_request object allocated in the
120 * request construct function.
121 * @sci_device: This parameter is the handle for the sci core's remote device
122 * object that is the destination for this request.
124 * SCI_SUCCESS on successfull completion, or specific failure code.
126 static enum sci_status isci_smp_request_build(
127 struct isci_request *request)
129 enum sci_status status = SCI_FAILURE;
130 struct sas_task *task = isci_request_access_task(request);
132 void *command_iu_address =
133 scic_io_request_get_command_iu_address(
134 request->sci_request_handle
137 dev_dbg(&request->isci_host->pdev->dev,
138 "%s: request = %p\n",
139 __func__,
140 request);
141 dev_dbg(&request->isci_host->pdev->dev,
142 "%s: smp_req len = %d\n",
143 __func__,
144 task->smp_task.smp_req.length);
146 /* copy the smp_command to the address; */
147 sg_copy_to_buffer(&task->smp_task.smp_req, 1,
148 (char *)command_iu_address,
149 sizeof(struct smp_request)
152 status = scic_io_request_construct_smp(request->sci_request_handle);
153 if (status != SCI_SUCCESS)
154 dev_warn(&request->isci_host->pdev->dev,
155 "%s: scic_io_request_construct_smp failed with "
156 "status = %d\n",
157 __func__,
158 status);
160 return status;
164 * isci_io_request_build() - This function builds the io request object.
165 * @isci_host: This parameter specifies the ISCI host object
166 * @request: This parameter points to the isci_request object allocated in the
167 * request construct function.
168 * @sci_device: This parameter is the handle for the sci core's remote device
169 * object that is the destination for this request.
171 * SCI_SUCCESS on successfull completion, or specific failure code.
173 static enum sci_status isci_io_request_build(
174 struct isci_host *isci_host,
175 struct isci_request *request,
176 struct isci_remote_device *isci_device)
178 enum sci_status status = SCI_SUCCESS;
179 struct sas_task *task = isci_request_access_task(request);
180 struct scic_sds_remote_device *sci_device = &isci_device->sci;
182 dev_dbg(&isci_host->pdev->dev,
183 "%s: isci_device = 0x%p; request = %p, "
184 "num_scatter = %d\n",
185 __func__,
186 isci_device,
187 request,
188 task->num_scatter);
190 /* map the sgl addresses, if present.
191 * libata does the mapping for sata devices
192 * before we get the request.
194 if (task->num_scatter &&
195 !sas_protocol_ata(task->task_proto) &&
196 !(SAS_PROTOCOL_SMP & task->task_proto)) {
198 request->num_sg_entries = dma_map_sg(
199 &isci_host->pdev->dev,
200 task->scatter,
201 task->num_scatter,
202 task->data_dir
205 if (request->num_sg_entries == 0)
206 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
209 /* build the common request object. For now,
210 * we will let the core allocate the IO tag.
212 status = scic_io_request_construct(
213 isci_host->core_controller,
214 sci_device,
215 SCI_CONTROLLER_INVALID_IO_TAG,
216 request,
217 request->sci_request_mem_ptr,
218 (struct scic_sds_request **)&request->sci_request_handle
221 if (status != SCI_SUCCESS) {
222 dev_warn(&isci_host->pdev->dev,
223 "%s: failed request construct\n",
224 __func__);
225 return SCI_FAILURE;
228 request->sci_request_handle->ireq = request;
230 switch (task->task_proto) {
231 case SAS_PROTOCOL_SMP:
232 status = isci_smp_request_build(request);
233 break;
234 case SAS_PROTOCOL_SSP:
235 status = isci_request_ssp_request_construct(request);
236 break;
237 case SAS_PROTOCOL_SATA:
238 case SAS_PROTOCOL_STP:
239 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
240 status = isci_request_stp_request_construct(request);
241 break;
242 default:
243 dev_warn(&isci_host->pdev->dev,
244 "%s: unknown protocol\n", __func__);
245 return SCI_FAILURE;
248 return SCI_SUCCESS;
253 * isci_request_alloc_core() - This function gets the request object from the
254 * isci_host dma cache.
255 * @isci_host: This parameter specifies the ISCI host object
256 * @isci_request: This parameter will contain the pointer to the new
257 * isci_request object.
258 * @isci_device: This parameter is the pointer to the isci remote device object
259 * that is the destination for this request.
260 * @gfp_flags: This parameter specifies the os allocation flags.
262 * SCI_SUCCESS on successfull completion, or specific failure code.
264 static int isci_request_alloc_core(
265 struct isci_host *isci_host,
266 struct isci_request **isci_request,
267 struct isci_remote_device *isci_device,
268 gfp_t gfp_flags)
270 int ret = 0;
271 dma_addr_t handle;
272 struct isci_request *request;
275 /* get pointer to dma memory. This actually points
276 * to both the isci_remote_device object and the
277 * sci object. The isci object is at the beginning
278 * of the memory allocated here.
280 request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle);
281 if (!request) {
282 dev_warn(&isci_host->pdev->dev,
283 "%s: dma_pool_alloc returned NULL\n", __func__);
284 return -ENOMEM;
287 /* initialize the request object. */
288 spin_lock_init(&request->state_lock);
289 request->sci_request_mem_ptr = ((u8 *)request) +
290 sizeof(struct isci_request);
291 request->request_daddr = handle;
292 request->isci_host = isci_host;
293 request->isci_device = isci_device;
294 request->io_request_completion = NULL;
296 request->request_alloc_size = isci_host->dma_pool_alloc_size;
297 request->num_sg_entries = 0;
299 request->complete_in_target = false;
301 INIT_LIST_HEAD(&request->completed_node);
302 INIT_LIST_HEAD(&request->dev_node);
304 *isci_request = request;
305 isci_request_change_state(request, allocated);
307 return ret;
310 static int isci_request_alloc_io(
311 struct isci_host *isci_host,
312 struct sas_task *task,
313 struct isci_request **isci_request,
314 struct isci_remote_device *isci_device,
315 gfp_t gfp_flags)
317 int retval = isci_request_alloc_core(isci_host, isci_request,
318 isci_device, gfp_flags);
320 if (!retval) {
321 (*isci_request)->ttype_ptr.io_task_ptr = task;
322 (*isci_request)->ttype = io_task;
324 task->lldd_task = *isci_request;
326 return retval;
330 * isci_request_alloc_tmf() - This function gets the request object from the
331 * isci_host dma cache and initializes the relevant fields as a sas_task.
332 * @isci_host: This parameter specifies the ISCI host object
333 * @sas_task: This parameter is the task struct from the upper layer driver.
334 * @isci_request: This parameter will contain the pointer to the new
335 * isci_request object.
336 * @isci_device: This parameter is the pointer to the isci remote device object
337 * that is the destination for this request.
338 * @gfp_flags: This parameter specifies the os allocation flags.
340 * SCI_SUCCESS on successfull completion, or specific failure code.
342 int isci_request_alloc_tmf(
343 struct isci_host *isci_host,
344 struct isci_tmf *isci_tmf,
345 struct isci_request **isci_request,
346 struct isci_remote_device *isci_device,
347 gfp_t gfp_flags)
349 int retval = isci_request_alloc_core(isci_host, isci_request,
350 isci_device, gfp_flags);
352 if (!retval) {
354 (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf;
355 (*isci_request)->ttype = tmf_task;
357 return retval;
361 * isci_request_execute() - This function allocates the isci_request object,
362 * all fills in some common fields.
363 * @isci_host: This parameter specifies the ISCI host object
364 * @sas_task: This parameter is the task struct from the upper layer driver.
365 * @isci_request: This parameter will contain the pointer to the new
366 * isci_request object.
367 * @gfp_flags: This parameter specifies the os allocation flags.
369 * SCI_SUCCESS on successfull completion, or specific failure code.
371 int isci_request_execute(
372 struct isci_host *isci_host,
373 struct sas_task *task,
374 struct isci_request **isci_request,
375 gfp_t gfp_flags)
377 int ret = 0;
378 struct scic_sds_remote_device *sci_device;
379 enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
380 struct isci_remote_device *isci_device;
381 struct isci_request *request;
382 unsigned long flags;
384 isci_device = task->dev->lldd_dev;
385 sci_device = &isci_device->sci;
387 /* do common allocation and init of request object. */
388 ret = isci_request_alloc_io(
389 isci_host,
390 task,
391 &request,
392 isci_device,
393 gfp_flags
396 if (ret)
397 goto out;
399 status = isci_io_request_build(isci_host, request, isci_device);
400 if (status == SCI_SUCCESS) {
402 spin_lock_irqsave(&isci_host->scic_lock, flags);
404 /* send the request, let the core assign the IO TAG. */
405 status = scic_controller_start_io(
406 isci_host->core_controller,
407 sci_device,
408 request->sci_request_handle,
409 SCI_CONTROLLER_INVALID_IO_TAG
412 if (status == SCI_SUCCESS ||
413 status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
415 /* Either I/O started OK, or the core has signaled that
416 * the device needs a target reset.
418 * In either case, hold onto the I/O for later.
420 * Update it's status and add it to the list in the
421 * remote device object.
423 isci_request_change_state(request, started);
424 list_add(&request->dev_node,
425 &isci_device->reqs_in_process);
427 if (status == SCI_SUCCESS) {
428 /* Save the tag for possible task mgmt later. */
429 request->io_tag = scic_io_request_get_io_tag(
430 request->sci_request_handle);
431 } else {
432 /* The request did not really start in the
433 * hardware, so clear the request handle
434 * here so no terminations will be done.
436 request->sci_request_handle = NULL;
439 } else
440 dev_warn(&isci_host->pdev->dev,
441 "%s: failed request start (0x%x)\n",
442 __func__, status);
444 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
446 if (status ==
447 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
448 /* Signal libsas that we need the SCSI error
449 * handler thread to work on this I/O and that
450 * we want a device reset.
452 spin_lock_irqsave(&task->task_state_lock, flags);
453 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
454 spin_unlock_irqrestore(&task->task_state_lock, flags);
456 /* Cause this task to be scheduled in the SCSI error
457 * handler thread.
459 isci_execpath_callback(isci_host, task,
460 sas_task_abort);
462 /* Change the status, since we are holding
463 * the I/O until it is managed by the SCSI
464 * error handler.
466 status = SCI_SUCCESS;
469 } else
470 dev_warn(&isci_host->pdev->dev,
471 "%s: request_construct failed - status = 0x%x\n",
472 __func__,
473 status);
475 out:
476 if (status != SCI_SUCCESS) {
477 /* release dma memory on failure. */
478 isci_request_free(isci_host, request);
479 request = NULL;
480 ret = SCI_FAILURE;
483 *isci_request = request;
484 return ret;
489 * isci_request_process_response_iu() - This function sets the status and
490 * response iu, in the task struct, from the request object for the upper
491 * layer driver.
492 * @sas_task: This parameter is the task struct from the upper layer driver.
493 * @resp_iu: This parameter points to the response iu of the completed request.
494 * @dev: This parameter specifies the linux device struct.
496 * none.
498 static void isci_request_process_response_iu(
499 struct sas_task *task,
500 struct ssp_response_iu *resp_iu,
501 struct device *dev)
503 dev_dbg(dev,
504 "%s: resp_iu = %p "
505 "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
506 "resp_iu->response_data_len = %x, "
507 "resp_iu->sense_data_len = %x\nrepsonse data: ",
508 __func__,
509 resp_iu,
510 resp_iu->status,
511 resp_iu->datapres,
512 resp_iu->response_data_len,
513 resp_iu->sense_data_len);
515 task->task_status.stat = resp_iu->status;
517 /* libsas updates the task status fields based on the response iu. */
518 sas_ssp_task_response(dev, task, resp_iu);
522 * isci_request_set_open_reject_status() - This function prepares the I/O
523 * completion for OPEN_REJECT conditions.
524 * @request: This parameter is the completed isci_request object.
525 * @response_ptr: This parameter specifies the service response for the I/O.
526 * @status_ptr: This parameter specifies the exec status for the I/O.
527 * @complete_to_host_ptr: This parameter specifies the action to be taken by
528 * the LLDD with respect to completing this request or forcing an abort
529 * condition on the I/O.
530 * @open_rej_reason: This parameter specifies the encoded reason for the
531 * abandon-class reject.
533 * none.
535 static void isci_request_set_open_reject_status(
536 struct isci_request *request,
537 struct sas_task *task,
538 enum service_response *response_ptr,
539 enum exec_status *status_ptr,
540 enum isci_completion_selection *complete_to_host_ptr,
541 enum sas_open_rej_reason open_rej_reason)
543 /* Task in the target is done. */
544 request->complete_in_target = true;
545 *response_ptr = SAS_TASK_UNDELIVERED;
546 *status_ptr = SAS_OPEN_REJECT;
547 *complete_to_host_ptr = isci_perform_normal_io_completion;
548 task->task_status.open_rej_reason = open_rej_reason;
552 * isci_request_handle_controller_specific_errors() - This function decodes
553 * controller-specific I/O completion error conditions.
554 * @request: This parameter is the completed isci_request object.
555 * @response_ptr: This parameter specifies the service response for the I/O.
556 * @status_ptr: This parameter specifies the exec status for the I/O.
557 * @complete_to_host_ptr: This parameter specifies the action to be taken by
558 * the LLDD with respect to completing this request or forcing an abort
559 * condition on the I/O.
561 * none.
563 static void isci_request_handle_controller_specific_errors(
564 struct isci_remote_device *isci_device,
565 struct isci_request *request,
566 struct sas_task *task,
567 enum service_response *response_ptr,
568 enum exec_status *status_ptr,
569 enum isci_completion_selection *complete_to_host_ptr)
571 unsigned int cstatus;
573 cstatus = scic_request_get_controller_status(
574 request->sci_request_handle
577 dev_dbg(&request->isci_host->pdev->dev,
578 "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
579 "- controller status = 0x%x\n",
580 __func__, request, cstatus);
582 /* Decode the controller-specific errors; most
583 * important is to recognize those conditions in which
584 * the target may still have a task outstanding that
585 * must be aborted.
587 * Note that there are SCU completion codes being
588 * named in the decode below for which SCIC has already
589 * done work to handle them in a way other than as
590 * a controller-specific completion code; these are left
591 * in the decode below for completeness sake.
593 switch (cstatus) {
594 case SCU_TASK_DONE_DMASETUP_DIRERR:
595 /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
596 case SCU_TASK_DONE_XFERCNT_ERR:
597 /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
598 if (task->task_proto == SAS_PROTOCOL_SMP) {
599 /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
600 *response_ptr = SAS_TASK_COMPLETE;
602 /* See if the device has been/is being stopped. Note
603 * that we ignore the quiesce state, since we are
604 * concerned about the actual device state.
606 if ((isci_device->status == isci_stopping) ||
607 (isci_device->status == isci_stopped))
608 *status_ptr = SAS_DEVICE_UNKNOWN;
609 else
610 *status_ptr = SAS_ABORTED_TASK;
612 request->complete_in_target = true;
614 *complete_to_host_ptr =
615 isci_perform_normal_io_completion;
616 } else {
617 /* Task in the target is not done. */
618 *response_ptr = SAS_TASK_UNDELIVERED;
620 if ((isci_device->status == isci_stopping) ||
621 (isci_device->status == isci_stopped))
622 *status_ptr = SAS_DEVICE_UNKNOWN;
623 else
624 *status_ptr = SAM_STAT_TASK_ABORTED;
626 request->complete_in_target = false;
628 *complete_to_host_ptr =
629 isci_perform_error_io_completion;
632 break;
634 case SCU_TASK_DONE_CRC_ERR:
635 case SCU_TASK_DONE_NAK_CMD_ERR:
636 case SCU_TASK_DONE_EXCESS_DATA:
637 case SCU_TASK_DONE_UNEXP_FIS:
638 /* Also SCU_TASK_DONE_UNEXP_RESP: */
639 case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
640 case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
641 case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
642 /* These are conditions in which the target
643 * has completed the task, so that no cleanup
644 * is necessary.
646 *response_ptr = SAS_TASK_COMPLETE;
648 /* See if the device has been/is being stopped. Note
649 * that we ignore the quiesce state, since we are
650 * concerned about the actual device state.
652 if ((isci_device->status == isci_stopping) ||
653 (isci_device->status == isci_stopped))
654 *status_ptr = SAS_DEVICE_UNKNOWN;
655 else
656 *status_ptr = SAS_ABORTED_TASK;
658 request->complete_in_target = true;
660 *complete_to_host_ptr = isci_perform_normal_io_completion;
661 break;
664 /* Note that the only open reject completion codes seen here will be
665 * abandon-class codes; all others are automatically retried in the SCU.
667 case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
669 isci_request_set_open_reject_status(
670 request, task, response_ptr, status_ptr,
671 complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
672 break;
674 case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
676 /* Note - the return of AB0 will change when
677 * libsas implements detection of zone violations.
679 isci_request_set_open_reject_status(
680 request, task, response_ptr, status_ptr,
681 complete_to_host_ptr, SAS_OREJ_RESV_AB0);
682 break;
684 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
686 isci_request_set_open_reject_status(
687 request, task, response_ptr, status_ptr,
688 complete_to_host_ptr, SAS_OREJ_RESV_AB1);
689 break;
691 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
693 isci_request_set_open_reject_status(
694 request, task, response_ptr, status_ptr,
695 complete_to_host_ptr, SAS_OREJ_RESV_AB2);
696 break;
698 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
700 isci_request_set_open_reject_status(
701 request, task, response_ptr, status_ptr,
702 complete_to_host_ptr, SAS_OREJ_RESV_AB3);
703 break;
705 case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
707 isci_request_set_open_reject_status(
708 request, task, response_ptr, status_ptr,
709 complete_to_host_ptr, SAS_OREJ_BAD_DEST);
710 break;
712 case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
714 isci_request_set_open_reject_status(
715 request, task, response_ptr, status_ptr,
716 complete_to_host_ptr, SAS_OREJ_STP_NORES);
717 break;
719 case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
721 isci_request_set_open_reject_status(
722 request, task, response_ptr, status_ptr,
723 complete_to_host_ptr, SAS_OREJ_EPROTO);
724 break;
726 case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
728 isci_request_set_open_reject_status(
729 request, task, response_ptr, status_ptr,
730 complete_to_host_ptr, SAS_OREJ_CONN_RATE);
731 break;
733 case SCU_TASK_DONE_LL_R_ERR:
734 /* Also SCU_TASK_DONE_ACK_NAK_TO: */
735 case SCU_TASK_DONE_LL_PERR:
736 case SCU_TASK_DONE_LL_SY_TERM:
737 /* Also SCU_TASK_DONE_NAK_ERR:*/
738 case SCU_TASK_DONE_LL_LF_TERM:
739 /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
740 case SCU_TASK_DONE_LL_ABORT_ERR:
741 case SCU_TASK_DONE_SEQ_INV_TYPE:
742 /* Also SCU_TASK_DONE_UNEXP_XR: */
743 case SCU_TASK_DONE_XR_IU_LEN_ERR:
744 case SCU_TASK_DONE_INV_FIS_LEN:
745 /* Also SCU_TASK_DONE_XR_WD_LEN: */
746 case SCU_TASK_DONE_SDMA_ERR:
747 case SCU_TASK_DONE_OFFSET_ERR:
748 case SCU_TASK_DONE_MAX_PLD_ERR:
749 case SCU_TASK_DONE_LF_ERR:
750 case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
751 case SCU_TASK_DONE_SMP_LL_RX_ERR:
752 case SCU_TASK_DONE_UNEXP_DATA:
753 case SCU_TASK_DONE_UNEXP_SDBFIS:
754 case SCU_TASK_DONE_REG_ERR:
755 case SCU_TASK_DONE_SDB_ERR:
756 case SCU_TASK_DONE_TASK_ABORT:
757 default:
758 /* Task in the target is not done. */
759 *response_ptr = SAS_TASK_UNDELIVERED;
760 *status_ptr = SAM_STAT_TASK_ABORTED;
761 request->complete_in_target = false;
763 *complete_to_host_ptr = isci_perform_error_io_completion;
764 break;
769 * isci_task_save_for_upper_layer_completion() - This function saves the
770 * request for later completion to the upper layer driver.
771 * @host: This parameter is a pointer to the host on which the the request
772 * should be queued (either as an error or success).
773 * @request: This parameter is the completed request.
774 * @response: This parameter is the response code for the completed task.
775 * @status: This parameter is the status code for the completed task.
777 * none.
779 static void isci_task_save_for_upper_layer_completion(
780 struct isci_host *host,
781 struct isci_request *request,
782 enum service_response response,
783 enum exec_status status,
784 enum isci_completion_selection task_notification_selection)
786 struct sas_task *task = isci_request_access_task(request);
788 task_notification_selection
789 = isci_task_set_completion_status(task, response, status,
790 task_notification_selection);
792 /* Tasks aborted specifically by a call to the lldd_abort_task
793 * function should not be completed to the host in the regular path.
795 switch (task_notification_selection) {
797 case isci_perform_normal_io_completion:
799 /* Normal notification (task_done) */
800 dev_dbg(&host->pdev->dev,
801 "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n",
802 __func__,
803 task,
804 task->task_status.resp, response,
805 task->task_status.stat, status);
806 /* Add to the completed list. */
807 list_add(&request->completed_node,
808 &host->requests_to_complete);
810 /* Take the request off the device's pending request list. */
811 list_del_init(&request->dev_node);
812 break;
814 case isci_perform_aborted_io_completion:
815 /* No notification to libsas because this request is
816 * already in the abort path.
818 dev_warn(&host->pdev->dev,
819 "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n",
820 __func__,
821 task,
822 task->task_status.resp, response,
823 task->task_status.stat, status);
825 /* Wake up whatever process was waiting for this
826 * request to complete.
828 WARN_ON(request->io_request_completion == NULL);
830 if (request->io_request_completion != NULL) {
832 /* Signal whoever is waiting that this
833 * request is complete.
835 complete(request->io_request_completion);
837 break;
839 case isci_perform_error_io_completion:
840 /* Use sas_task_abort */
841 dev_warn(&host->pdev->dev,
842 "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n",
843 __func__,
844 task,
845 task->task_status.resp, response,
846 task->task_status.stat, status);
847 /* Add to the aborted list. */
848 list_add(&request->completed_node,
849 &host->requests_to_errorback);
850 break;
852 default:
853 dev_warn(&host->pdev->dev,
854 "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n",
855 __func__,
856 task,
857 task->task_status.resp, response,
858 task->task_status.stat, status);
860 /* Add to the error to libsas list. */
861 list_add(&request->completed_node,
862 &host->requests_to_errorback);
863 break;
868 * isci_request_io_request_complete() - This function is called by the sci core
869 * when an io request completes.
870 * @isci_host: This parameter specifies the ISCI host object
871 * @request: This parameter is the completed isci_request object.
872 * @completion_status: This parameter specifies the completion status from the
873 * sci core.
875 * none.
877 void isci_request_io_request_complete(
878 struct isci_host *isci_host,
879 struct isci_request *request,
880 enum sci_io_status completion_status)
882 struct sas_task *task = isci_request_access_task(request);
883 struct ssp_response_iu *resp_iu;
884 void *resp_buf;
885 unsigned long task_flags;
886 struct isci_remote_device *isci_device = request->isci_device;
887 enum service_response response = SAS_TASK_UNDELIVERED;
888 enum exec_status status = SAS_ABORTED_TASK;
889 enum isci_request_status request_status;
890 enum isci_completion_selection complete_to_host
891 = isci_perform_normal_io_completion;
893 dev_dbg(&isci_host->pdev->dev,
894 "%s: request = %p, task = %p,\n"
895 "task->data_dir = %d completion_status = 0x%x\n",
896 __func__,
897 request,
898 task,
899 task->data_dir,
900 completion_status);
902 spin_lock(&request->state_lock);
903 request_status = isci_request_get_state(request);
905 /* Decode the request status. Note that if the request has been
906 * aborted by a task management function, we don't care
907 * what the status is.
909 switch (request_status) {
911 case aborted:
912 /* "aborted" indicates that the request was aborted by a task
913 * management function, since once a task management request is
914 * perfomed by the device, the request only completes because
915 * of the subsequent driver terminate.
917 * Aborted also means an external thread is explicitly managing
918 * this request, so that we do not complete it up the stack.
920 * The target is still there (since the TMF was successful).
922 request->complete_in_target = true;
923 response = SAS_TASK_COMPLETE;
925 /* See if the device has been/is being stopped. Note
926 * that we ignore the quiesce state, since we are
927 * concerned about the actual device state.
929 if ((isci_device->status == isci_stopping)
930 || (isci_device->status == isci_stopped)
932 status = SAS_DEVICE_UNKNOWN;
933 else
934 status = SAS_ABORTED_TASK;
936 complete_to_host = isci_perform_aborted_io_completion;
937 /* This was an aborted request. */
939 spin_unlock(&request->state_lock);
940 break;
942 case aborting:
943 /* aborting means that the task management function tried and
944 * failed to abort the request. We need to note the request
945 * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
946 * target as down.
948 * Aborting also means an external thread is explicitly managing
949 * this request, so that we do not complete it up the stack.
951 request->complete_in_target = true;
952 response = SAS_TASK_UNDELIVERED;
954 if ((isci_device->status == isci_stopping) ||
955 (isci_device->status == isci_stopped))
956 /* The device has been /is being stopped. Note that
957 * we ignore the quiesce state, since we are
958 * concerned about the actual device state.
960 status = SAS_DEVICE_UNKNOWN;
961 else
962 status = SAS_PHY_DOWN;
964 complete_to_host = isci_perform_aborted_io_completion;
966 /* This was an aborted request. */
968 spin_unlock(&request->state_lock);
969 break;
971 case terminating:
973 /* This was an terminated request. This happens when
974 * the I/O is being terminated because of an action on
975 * the device (reset, tear down, etc.), and the I/O needs
976 * to be completed up the stack.
978 request->complete_in_target = true;
979 response = SAS_TASK_UNDELIVERED;
981 /* See if the device has been/is being stopped. Note
982 * that we ignore the quiesce state, since we are
983 * concerned about the actual device state.
985 if ((isci_device->status == isci_stopping) ||
986 (isci_device->status == isci_stopped))
987 status = SAS_DEVICE_UNKNOWN;
988 else
989 status = SAS_ABORTED_TASK;
991 complete_to_host = isci_perform_aborted_io_completion;
993 /* This was a terminated request. */
995 spin_unlock(&request->state_lock);
996 break;
998 default:
1000 /* The request is done from an SCU HW perspective. */
1001 request->status = completed;
1003 spin_unlock(&request->state_lock);
1005 /* This is an active request being completed from the core. */
1006 switch (completion_status) {
1008 case SCI_IO_FAILURE_RESPONSE_VALID:
1009 dev_dbg(&isci_host->pdev->dev,
1010 "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
1011 __func__,
1012 request,
1013 task);
1015 if (sas_protocol_ata(task->task_proto)) {
1016 resp_buf
1017 = scic_stp_io_request_get_d2h_reg_address(
1018 request->sci_request_handle
1020 isci_request_process_stp_response(task,
1021 resp_buf
1024 } else if (SAS_PROTOCOL_SSP == task->task_proto) {
1026 /* crack the iu response buffer. */
1027 resp_iu
1028 = scic_io_request_get_response_iu_address(
1029 request->sci_request_handle
1032 isci_request_process_response_iu(task, resp_iu,
1033 &isci_host->pdev->dev
1036 } else if (SAS_PROTOCOL_SMP == task->task_proto) {
1038 dev_err(&isci_host->pdev->dev,
1039 "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
1040 "SAS_PROTOCOL_SMP protocol\n",
1041 __func__);
1043 } else
1044 dev_err(&isci_host->pdev->dev,
1045 "%s: unknown protocol\n", __func__);
1047 /* use the task status set in the task struct by the
1048 * isci_request_process_response_iu call.
1050 request->complete_in_target = true;
1051 response = task->task_status.resp;
1052 status = task->task_status.stat;
1053 break;
1055 case SCI_IO_SUCCESS:
1056 case SCI_IO_SUCCESS_IO_DONE_EARLY:
1058 response = SAS_TASK_COMPLETE;
1059 status = SAM_STAT_GOOD;
1060 request->complete_in_target = true;
1062 if (task->task_proto == SAS_PROTOCOL_SMP) {
1064 u8 *command_iu_address
1065 = scic_io_request_get_command_iu_address(
1066 request->sci_request_handle
1069 dev_dbg(&isci_host->pdev->dev,
1070 "%s: SMP protocol completion\n",
1071 __func__);
1073 sg_copy_from_buffer(
1074 &task->smp_task.smp_resp, 1,
1075 command_iu_address
1076 + sizeof(struct smp_request),
1077 sizeof(struct smp_resp)
1079 } else if (completion_status
1080 == SCI_IO_SUCCESS_IO_DONE_EARLY) {
1082 /* This was an SSP / STP / SATA transfer.
1083 * There is a possibility that less data than
1084 * the maximum was transferred.
1086 u32 transferred_length
1087 = scic_io_request_get_number_of_bytes_transferred(
1088 request->sci_request_handle);
1090 task->task_status.residual
1091 = task->total_xfer_len - transferred_length;
1093 /* If there were residual bytes, call this an
1094 * underrun.
1096 if (task->task_status.residual != 0)
1097 status = SAS_DATA_UNDERRUN;
1099 dev_dbg(&isci_host->pdev->dev,
1100 "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
1101 __func__,
1102 status);
1104 } else
1105 dev_dbg(&isci_host->pdev->dev,
1106 "%s: SCI_IO_SUCCESS\n",
1107 __func__);
1109 break;
1111 case SCI_IO_FAILURE_TERMINATED:
1112 dev_dbg(&isci_host->pdev->dev,
1113 "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
1114 __func__,
1115 request,
1116 task);
1118 /* The request was terminated explicitly. No handling
1119 * is needed in the SCSI error handler path.
1121 request->complete_in_target = true;
1122 response = SAS_TASK_UNDELIVERED;
1124 /* See if the device has been/is being stopped. Note
1125 * that we ignore the quiesce state, since we are
1126 * concerned about the actual device state.
1128 if ((isci_device->status == isci_stopping) ||
1129 (isci_device->status == isci_stopped))
1130 status = SAS_DEVICE_UNKNOWN;
1131 else
1132 status = SAS_ABORTED_TASK;
1134 complete_to_host = isci_perform_normal_io_completion;
1135 break;
1137 case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
1139 isci_request_handle_controller_specific_errors(
1140 isci_device, request, task, &response, &status,
1141 &complete_to_host);
1143 break;
1145 case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
1146 /* This is a special case, in that the I/O completion
1147 * is telling us that the device needs a reset.
1148 * In order for the device reset condition to be
1149 * noticed, the I/O has to be handled in the error
1150 * handler. Set the reset flag and cause the
1151 * SCSI error thread to be scheduled.
1153 spin_lock_irqsave(&task->task_state_lock, task_flags);
1154 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1155 spin_unlock_irqrestore(&task->task_state_lock, task_flags);
1157 /* Fail the I/O. */
1158 response = SAS_TASK_UNDELIVERED;
1159 status = SAM_STAT_TASK_ABORTED;
1161 complete_to_host = isci_perform_error_io_completion;
1162 request->complete_in_target = false;
1163 break;
1165 default:
1166 /* Catch any otherwise unhandled error codes here. */
1167 dev_warn(&isci_host->pdev->dev,
1168 "%s: invalid completion code: 0x%x - "
1169 "isci_request = %p\n",
1170 __func__, completion_status, request);
1172 response = SAS_TASK_UNDELIVERED;
1174 /* See if the device has been/is being stopped. Note
1175 * that we ignore the quiesce state, since we are
1176 * concerned about the actual device state.
1178 if ((isci_device->status == isci_stopping) ||
1179 (isci_device->status == isci_stopped))
1180 status = SAS_DEVICE_UNKNOWN;
1181 else
1182 status = SAS_ABORTED_TASK;
1184 complete_to_host = isci_perform_error_io_completion;
1185 request->complete_in_target = false;
1186 break;
1188 break;
1191 isci_request_unmap_sgl(request, isci_host->pdev);
1193 /* Put the completed request on the correct list */
1194 isci_task_save_for_upper_layer_completion(isci_host, request, response,
1195 status, complete_to_host
1198 /* complete the io request to the core. */
1199 scic_controller_complete_io(isci_host->core_controller,
1200 &isci_device->sci,
1201 request->sci_request_handle);
1202 /* NULL the request handle so it cannot be completed or
1203 * terminated again, and to cause any calls into abort
1204 * task to recognize the already completed case.
1206 request->sci_request_handle = NULL;
1208 isci_host_can_dequeue(isci_host, 1);
1212 * isci_request_io_request_get_transfer_length() - This function is called by
1213 * the sci core to retrieve the transfer length for a given request.
1214 * @request: This parameter is the isci_request object.
1216 * length of transfer for specified request.
1218 u32 isci_request_io_request_get_transfer_length(struct isci_request *request)
1220 struct sas_task *task = isci_request_access_task(request);
1222 dev_dbg(&request->isci_host->pdev->dev,
1223 "%s: total_xfer_len: %d\n",
1224 __func__,
1225 task->total_xfer_len);
1226 return task->total_xfer_len;
1231 * isci_request_io_request_get_data_direction() - This function is called by
1232 * the sci core to retrieve the data direction for a given request.
1233 * @request: This parameter is the isci_request object.
1235 * data direction for specified request.
1237 enum dma_data_direction isci_request_io_request_get_data_direction(
1238 struct isci_request *request)
1240 struct sas_task *task = isci_request_access_task(request);
1242 return task->data_dir;
1246 * isci_request_sge_get_address_field() - This function is called by the sci
1247 * core to retrieve the address field contents for a given sge.
1248 * @request: This parameter is the isci_request object.
1249 * @sge_address: This parameter is the sge.
1251 * physical address in the specified sge.
1256 * isci_request_sge_get_length_field() - This function is called by the sci
1257 * core to retrieve the length field contents for a given sge.
1258 * @request: This parameter is the isci_request object.
1259 * @sge_address: This parameter is the sge.
1261 * length field value in the specified sge.
1266 * isci_request_ssp_io_request_get_cdb_address() - This function is called by
1267 * the sci core to retrieve the cdb address for a given request.
1268 * @request: This parameter is the isci_request object.
1270 * cdb address for specified request.
1272 void *isci_request_ssp_io_request_get_cdb_address(
1273 struct isci_request *request)
1275 struct sas_task *task = isci_request_access_task(request);
1277 dev_dbg(&request->isci_host->pdev->dev,
1278 "%s: request->task->ssp_task.cdb = %p\n",
1279 __func__,
1280 task->ssp_task.cdb);
1281 return task->ssp_task.cdb;
1286 * isci_request_ssp_io_request_get_cdb_length() - This function is called by
1287 * the sci core to retrieve the cdb length for a given request.
1288 * @request: This parameter is the isci_request object.
1290 * cdb length for specified request.
1292 u32 isci_request_ssp_io_request_get_cdb_length(
1293 struct isci_request *request)
1295 return 16;
1300 * isci_request_ssp_io_request_get_lun() - This function is called by the sci
1301 * core to retrieve the lun for a given request.
1302 * @request: This parameter is the isci_request object.
1304 * lun for specified request.
1306 u32 isci_request_ssp_io_request_get_lun(
1307 struct isci_request *request)
1309 struct sas_task *task = isci_request_access_task(request);
1311 #ifdef DEBUG
1312 int i;
1314 for (i = 0; i < 8; i++)
1315 dev_dbg(&request->isci_host->pdev->dev,
1316 "%s: task->ssp_task.LUN[%d] = %x\n",
1317 __func__, i, task->ssp_task.LUN[i]);
1319 #endif
1321 return task->ssp_task.LUN[0];
1326 * isci_request_ssp_io_request_get_task_attribute() - This function is called
1327 * by the sci core to retrieve the task attribute for a given request.
1328 * @request: This parameter is the isci_request object.
1330 * task attribute for specified request.
1332 u32 isci_request_ssp_io_request_get_task_attribute(
1333 struct isci_request *request)
1335 struct sas_task *task = isci_request_access_task(request);
1337 dev_dbg(&request->isci_host->pdev->dev,
1338 "%s: request->task->ssp_task.task_attr = %x\n",
1339 __func__,
1340 task->ssp_task.task_attr);
1342 return task->ssp_task.task_attr;
1347 * isci_request_ssp_io_request_get_command_priority() - This function is called
1348 * by the sci core to retrieve the command priority for a given request.
1349 * @request: This parameter is the isci_request object.
1351 * command priority for specified request.
1353 u32 isci_request_ssp_io_request_get_command_priority(
1354 struct isci_request *request)
1356 struct sas_task *task = isci_request_access_task(request);
1358 dev_dbg(&request->isci_host->pdev->dev,
1359 "%s: request->task->ssp_task.task_prio = %x\n",
1360 __func__,
1361 task->ssp_task.task_prio);
1363 return task->ssp_task.task_prio;