a5b9b22d3b3af316366fdc09fbd84f8800b16879
[deliverable/linux.git] / drivers / scsi / isci / request.c
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.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 *
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.
12 *
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.
17 *
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.
23 *
24 * BSD LICENSE
25 *
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
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.
42 *
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.
54 */
55
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 "scic_sds_request.h"
65 #include "sas.h"
66
67 static enum sci_status isci_request_ssp_request_construct(
68 struct isci_request *request)
69 {
70 enum sci_status status;
71
72 dev_dbg(&request->isci_host->pdev->dev,
73 "%s: request = %p\n",
74 __func__,
75 request);
76 status = scic_io_request_construct_basic_ssp(
77 request->sci_request_handle
78 );
79 return status;
80 }
81
82 static enum sci_status isci_request_stp_request_construct(
83 struct isci_request *request)
84 {
85 struct sas_task *task = isci_request_access_task(request);
86 enum sci_status status;
87 struct host_to_dev_fis *register_fis;
88
89 dev_dbg(&request->isci_host->pdev->dev,
90 "%s: request = %p\n",
91 __func__,
92 request);
93
94 /* Get the host_to_dev_fis from the core and copy
95 * the fis from the task into it.
96 */
97 register_fis = isci_sata_task_to_fis_copy(task);
98
99 status = scic_io_request_construct_basic_sata(
100 request->sci_request_handle
101 );
102
103 /* Set the ncq tag in the fis, from the queue
104 * command in the task.
105 */
106 if (isci_sata_is_task_ncq(task)) {
107
108 isci_sata_set_ncq_tag(
109 register_fis,
110 task
111 );
112 }
113
114 return status;
115 }
116
117 /*
118 * isci_smp_request_build() - This function builds the smp request.
119 * @ireq: This parameter points to the isci_request allocated in the
120 * request construct function.
121 *
122 * SCI_SUCCESS on successfull completion, or specific failure code.
123 */
124 static enum sci_status isci_smp_request_build(struct isci_request *ireq)
125 {
126 enum sci_status status = SCI_FAILURE;
127 struct sas_task *task = isci_request_access_task(ireq);
128 struct scic_sds_request *sci_req = ireq->sci_request_handle;
129
130 dev_dbg(&ireq->isci_host->pdev->dev,
131 "%s: request = %p\n", __func__, ireq);
132
133 dev_dbg(&ireq->isci_host->pdev->dev,
134 "%s: smp_req len = %d\n",
135 __func__,
136 task->smp_task.smp_req.length);
137
138 /* copy the smp_command to the address; */
139 sg_copy_to_buffer(&task->smp_task.smp_req, 1,
140 &sci_req->smp.cmd,
141 sizeof(struct smp_req));
142
143 status = scic_io_request_construct_smp(sci_req);
144 if (status != SCI_SUCCESS)
145 dev_warn(&ireq->isci_host->pdev->dev,
146 "%s: failed with status = %d\n",
147 __func__,
148 status);
149
150 return status;
151 }
152
153 /**
154 * isci_io_request_build() - This function builds the io request object.
155 * @isci_host: This parameter specifies the ISCI host object
156 * @request: This parameter points to the isci_request object allocated in the
157 * request construct function.
158 * @sci_device: This parameter is the handle for the sci core's remote device
159 * object that is the destination for this request.
160 *
161 * SCI_SUCCESS on successfull completion, or specific failure code.
162 */
163 static enum sci_status isci_io_request_build(
164 struct isci_host *isci_host,
165 struct isci_request *request,
166 struct isci_remote_device *isci_device)
167 {
168 enum sci_status status = SCI_SUCCESS;
169 struct sas_task *task = isci_request_access_task(request);
170 struct scic_sds_remote_device *sci_device = &isci_device->sci;
171
172 dev_dbg(&isci_host->pdev->dev,
173 "%s: isci_device = 0x%p; request = %p, "
174 "num_scatter = %d\n",
175 __func__,
176 isci_device,
177 request,
178 task->num_scatter);
179
180 /* map the sgl addresses, if present.
181 * libata does the mapping for sata devices
182 * before we get the request.
183 */
184 if (task->num_scatter &&
185 !sas_protocol_ata(task->task_proto) &&
186 !(SAS_PROTOCOL_SMP & task->task_proto)) {
187
188 request->num_sg_entries = dma_map_sg(
189 &isci_host->pdev->dev,
190 task->scatter,
191 task->num_scatter,
192 task->data_dir
193 );
194
195 if (request->num_sg_entries == 0)
196 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
197 }
198
199 /* build the common request object. For now,
200 * we will let the core allocate the IO tag.
201 */
202 status = scic_io_request_construct(&isci_host->sci, sci_device,
203 SCI_CONTROLLER_INVALID_IO_TAG,
204 request, request->sci_req,
205 &request->sci_request_handle);
206
207 if (status != SCI_SUCCESS) {
208 dev_warn(&isci_host->pdev->dev,
209 "%s: failed request construct\n",
210 __func__);
211 return SCI_FAILURE;
212 }
213
214 request->sci_request_handle->ireq = request;
215
216 switch (task->task_proto) {
217 case SAS_PROTOCOL_SMP:
218 status = isci_smp_request_build(request);
219 break;
220 case SAS_PROTOCOL_SSP:
221 status = isci_request_ssp_request_construct(request);
222 break;
223 case SAS_PROTOCOL_SATA:
224 case SAS_PROTOCOL_STP:
225 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
226 status = isci_request_stp_request_construct(request);
227 break;
228 default:
229 dev_warn(&isci_host->pdev->dev,
230 "%s: unknown protocol\n", __func__);
231 return SCI_FAILURE;
232 }
233
234 return SCI_SUCCESS;
235 }
236
237
238 /**
239 * isci_request_alloc_core() - This function gets the request object from the
240 * isci_host dma cache.
241 * @isci_host: This parameter specifies the ISCI host object
242 * @isci_request: This parameter will contain the pointer to the new
243 * isci_request object.
244 * @isci_device: This parameter is the pointer to the isci remote device object
245 * that is the destination for this request.
246 * @gfp_flags: This parameter specifies the os allocation flags.
247 *
248 * SCI_SUCCESS on successfull completion, or specific failure code.
249 */
250 static int isci_request_alloc_core(
251 struct isci_host *isci_host,
252 struct isci_request **isci_request,
253 struct isci_remote_device *isci_device,
254 gfp_t gfp_flags)
255 {
256 int ret = 0;
257 dma_addr_t handle;
258 struct isci_request *request;
259
260
261 /* get pointer to dma memory. This actually points
262 * to both the isci_remote_device object and the
263 * sci object. The isci object is at the beginning
264 * of the memory allocated here.
265 */
266 request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle);
267 if (!request) {
268 dev_warn(&isci_host->pdev->dev,
269 "%s: dma_pool_alloc returned NULL\n", __func__);
270 return -ENOMEM;
271 }
272
273 /* initialize the request object. */
274 spin_lock_init(&request->state_lock);
275 request->request_daddr = handle;
276 request->isci_host = isci_host;
277 request->isci_device = isci_device;
278 request->io_request_completion = NULL;
279
280 request->request_alloc_size = isci_host->dma_pool_alloc_size;
281 request->num_sg_entries = 0;
282
283 request->complete_in_target = false;
284
285 INIT_LIST_HEAD(&request->completed_node);
286 INIT_LIST_HEAD(&request->dev_node);
287
288 *isci_request = request;
289 isci_request_change_state(request, allocated);
290
291 return ret;
292 }
293
294 static int isci_request_alloc_io(
295 struct isci_host *isci_host,
296 struct sas_task *task,
297 struct isci_request **isci_request,
298 struct isci_remote_device *isci_device,
299 gfp_t gfp_flags)
300 {
301 int retval = isci_request_alloc_core(isci_host, isci_request,
302 isci_device, gfp_flags);
303
304 if (!retval) {
305 (*isci_request)->ttype_ptr.io_task_ptr = task;
306 (*isci_request)->ttype = io_task;
307
308 task->lldd_task = *isci_request;
309 }
310 return retval;
311 }
312
313 /**
314 * isci_request_alloc_tmf() - This function gets the request object from the
315 * isci_host dma cache and initializes the relevant fields as a sas_task.
316 * @isci_host: This parameter specifies the ISCI host object
317 * @sas_task: This parameter is the task struct from the upper layer driver.
318 * @isci_request: This parameter will contain the pointer to the new
319 * isci_request object.
320 * @isci_device: This parameter is the pointer to the isci remote device object
321 * that is the destination for this request.
322 * @gfp_flags: This parameter specifies the os allocation flags.
323 *
324 * SCI_SUCCESS on successfull completion, or specific failure code.
325 */
326 int isci_request_alloc_tmf(
327 struct isci_host *isci_host,
328 struct isci_tmf *isci_tmf,
329 struct isci_request **isci_request,
330 struct isci_remote_device *isci_device,
331 gfp_t gfp_flags)
332 {
333 int retval = isci_request_alloc_core(isci_host, isci_request,
334 isci_device, gfp_flags);
335
336 if (!retval) {
337
338 (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf;
339 (*isci_request)->ttype = tmf_task;
340 }
341 return retval;
342 }
343
344 /**
345 * isci_request_execute() - This function allocates the isci_request object,
346 * all fills in some common fields.
347 * @isci_host: This parameter specifies the ISCI host object
348 * @sas_task: This parameter is the task struct from the upper layer driver.
349 * @isci_request: This parameter will contain the pointer to the new
350 * isci_request object.
351 * @gfp_flags: This parameter specifies the os allocation flags.
352 *
353 * SCI_SUCCESS on successfull completion, or specific failure code.
354 */
355 int isci_request_execute(
356 struct isci_host *isci_host,
357 struct sas_task *task,
358 struct isci_request **isci_request,
359 gfp_t gfp_flags)
360 {
361 int ret = 0;
362 struct scic_sds_remote_device *sci_device;
363 enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
364 struct isci_remote_device *isci_device;
365 struct isci_request *request;
366 unsigned long flags;
367
368 isci_device = task->dev->lldd_dev;
369 sci_device = &isci_device->sci;
370
371 /* do common allocation and init of request object. */
372 ret = isci_request_alloc_io(
373 isci_host,
374 task,
375 &request,
376 isci_device,
377 gfp_flags
378 );
379
380 if (ret)
381 goto out;
382
383 status = isci_io_request_build(isci_host, request, isci_device);
384 if (status == SCI_SUCCESS) {
385
386 spin_lock_irqsave(&isci_host->scic_lock, flags);
387
388 /* send the request, let the core assign the IO TAG. */
389 status = scic_controller_start_io(
390 &isci_host->sci,
391 sci_device,
392 request->sci_request_handle,
393 SCI_CONTROLLER_INVALID_IO_TAG
394 );
395
396 if (status == SCI_SUCCESS ||
397 status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
398
399 /* Either I/O started OK, or the core has signaled that
400 * the device needs a target reset.
401 *
402 * In either case, hold onto the I/O for later.
403 *
404 * Update it's status and add it to the list in the
405 * remote device object.
406 */
407 isci_request_change_state(request, started);
408 list_add(&request->dev_node,
409 &isci_device->reqs_in_process);
410
411 if (status == SCI_SUCCESS) {
412 /* Save the tag for possible task mgmt later. */
413 request->io_tag = scic_io_request_get_io_tag(
414 request->sci_request_handle);
415 } else {
416 /* The request did not really start in the
417 * hardware, so clear the request handle
418 * here so no terminations will be done.
419 */
420 request->sci_request_handle = NULL;
421 }
422
423 } else
424 dev_warn(&isci_host->pdev->dev,
425 "%s: failed request start (0x%x)\n",
426 __func__, status);
427
428 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
429
430 if (status ==
431 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
432 /* Signal libsas that we need the SCSI error
433 * handler thread to work on this I/O and that
434 * we want a device reset.
435 */
436 spin_lock_irqsave(&task->task_state_lock, flags);
437 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
438 spin_unlock_irqrestore(&task->task_state_lock, flags);
439
440 /* Cause this task to be scheduled in the SCSI error
441 * handler thread.
442 */
443 isci_execpath_callback(isci_host, task,
444 sas_task_abort);
445
446 /* Change the status, since we are holding
447 * the I/O until it is managed by the SCSI
448 * error handler.
449 */
450 status = SCI_SUCCESS;
451 }
452
453 } else
454 dev_warn(&isci_host->pdev->dev,
455 "%s: request_construct failed - status = 0x%x\n",
456 __func__,
457 status);
458
459 out:
460 if (status != SCI_SUCCESS) {
461 /* release dma memory on failure. */
462 isci_request_free(isci_host, request);
463 request = NULL;
464 ret = SCI_FAILURE;
465 }
466
467 *isci_request = request;
468 return ret;
469 }
470
471
472 /**
473 * isci_request_process_response_iu() - This function sets the status and
474 * response iu, in the task struct, from the request object for the upper
475 * layer driver.
476 * @sas_task: This parameter is the task struct from the upper layer driver.
477 * @resp_iu: This parameter points to the response iu of the completed request.
478 * @dev: This parameter specifies the linux device struct.
479 *
480 * none.
481 */
482 static void isci_request_process_response_iu(
483 struct sas_task *task,
484 struct ssp_response_iu *resp_iu,
485 struct device *dev)
486 {
487 dev_dbg(dev,
488 "%s: resp_iu = %p "
489 "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
490 "resp_iu->response_data_len = %x, "
491 "resp_iu->sense_data_len = %x\nrepsonse data: ",
492 __func__,
493 resp_iu,
494 resp_iu->status,
495 resp_iu->datapres,
496 resp_iu->response_data_len,
497 resp_iu->sense_data_len);
498
499 task->task_status.stat = resp_iu->status;
500
501 /* libsas updates the task status fields based on the response iu. */
502 sas_ssp_task_response(dev, task, resp_iu);
503 }
504
505 /**
506 * isci_request_set_open_reject_status() - This function prepares the I/O
507 * completion for OPEN_REJECT conditions.
508 * @request: This parameter is the completed isci_request object.
509 * @response_ptr: This parameter specifies the service response for the I/O.
510 * @status_ptr: This parameter specifies the exec status for the I/O.
511 * @complete_to_host_ptr: This parameter specifies the action to be taken by
512 * the LLDD with respect to completing this request or forcing an abort
513 * condition on the I/O.
514 * @open_rej_reason: This parameter specifies the encoded reason for the
515 * abandon-class reject.
516 *
517 * none.
518 */
519 static void isci_request_set_open_reject_status(
520 struct isci_request *request,
521 struct sas_task *task,
522 enum service_response *response_ptr,
523 enum exec_status *status_ptr,
524 enum isci_completion_selection *complete_to_host_ptr,
525 enum sas_open_rej_reason open_rej_reason)
526 {
527 /* Task in the target is done. */
528 request->complete_in_target = true;
529 *response_ptr = SAS_TASK_UNDELIVERED;
530 *status_ptr = SAS_OPEN_REJECT;
531 *complete_to_host_ptr = isci_perform_normal_io_completion;
532 task->task_status.open_rej_reason = open_rej_reason;
533 }
534
535 /**
536 * isci_request_handle_controller_specific_errors() - This function decodes
537 * controller-specific I/O completion error conditions.
538 * @request: This parameter is the completed isci_request object.
539 * @response_ptr: This parameter specifies the service response for the I/O.
540 * @status_ptr: This parameter specifies the exec status for the I/O.
541 * @complete_to_host_ptr: This parameter specifies the action to be taken by
542 * the LLDD with respect to completing this request or forcing an abort
543 * condition on the I/O.
544 *
545 * none.
546 */
547 static void isci_request_handle_controller_specific_errors(
548 struct isci_remote_device *isci_device,
549 struct isci_request *request,
550 struct sas_task *task,
551 enum service_response *response_ptr,
552 enum exec_status *status_ptr,
553 enum isci_completion_selection *complete_to_host_ptr)
554 {
555 unsigned int cstatus;
556
557 cstatus = scic_request_get_controller_status(
558 request->sci_request_handle
559 );
560
561 dev_dbg(&request->isci_host->pdev->dev,
562 "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
563 "- controller status = 0x%x\n",
564 __func__, request, cstatus);
565
566 /* Decode the controller-specific errors; most
567 * important is to recognize those conditions in which
568 * the target may still have a task outstanding that
569 * must be aborted.
570 *
571 * Note that there are SCU completion codes being
572 * named in the decode below for which SCIC has already
573 * done work to handle them in a way other than as
574 * a controller-specific completion code; these are left
575 * in the decode below for completeness sake.
576 */
577 switch (cstatus) {
578 case SCU_TASK_DONE_DMASETUP_DIRERR:
579 /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
580 case SCU_TASK_DONE_XFERCNT_ERR:
581 /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
582 if (task->task_proto == SAS_PROTOCOL_SMP) {
583 /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
584 *response_ptr = SAS_TASK_COMPLETE;
585
586 /* See if the device has been/is being stopped. Note
587 * that we ignore the quiesce state, since we are
588 * concerned about the actual device state.
589 */
590 if ((isci_device->status == isci_stopping) ||
591 (isci_device->status == isci_stopped))
592 *status_ptr = SAS_DEVICE_UNKNOWN;
593 else
594 *status_ptr = SAS_ABORTED_TASK;
595
596 request->complete_in_target = true;
597
598 *complete_to_host_ptr =
599 isci_perform_normal_io_completion;
600 } else {
601 /* Task in the target is not done. */
602 *response_ptr = SAS_TASK_UNDELIVERED;
603
604 if ((isci_device->status == isci_stopping) ||
605 (isci_device->status == isci_stopped))
606 *status_ptr = SAS_DEVICE_UNKNOWN;
607 else
608 *status_ptr = SAM_STAT_TASK_ABORTED;
609
610 request->complete_in_target = false;
611
612 *complete_to_host_ptr =
613 isci_perform_error_io_completion;
614 }
615
616 break;
617
618 case SCU_TASK_DONE_CRC_ERR:
619 case SCU_TASK_DONE_NAK_CMD_ERR:
620 case SCU_TASK_DONE_EXCESS_DATA:
621 case SCU_TASK_DONE_UNEXP_FIS:
622 /* Also SCU_TASK_DONE_UNEXP_RESP: */
623 case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
624 case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
625 case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
626 /* These are conditions in which the target
627 * has completed the task, so that no cleanup
628 * is necessary.
629 */
630 *response_ptr = SAS_TASK_COMPLETE;
631
632 /* See if the device has been/is being stopped. Note
633 * that we ignore the quiesce state, since we are
634 * concerned about the actual device state.
635 */
636 if ((isci_device->status == isci_stopping) ||
637 (isci_device->status == isci_stopped))
638 *status_ptr = SAS_DEVICE_UNKNOWN;
639 else
640 *status_ptr = SAS_ABORTED_TASK;
641
642 request->complete_in_target = true;
643
644 *complete_to_host_ptr = isci_perform_normal_io_completion;
645 break;
646
647
648 /* Note that the only open reject completion codes seen here will be
649 * abandon-class codes; all others are automatically retried in the SCU.
650 */
651 case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
652
653 isci_request_set_open_reject_status(
654 request, task, response_ptr, status_ptr,
655 complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
656 break;
657
658 case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
659
660 /* Note - the return of AB0 will change when
661 * libsas implements detection of zone violations.
662 */
663 isci_request_set_open_reject_status(
664 request, task, response_ptr, status_ptr,
665 complete_to_host_ptr, SAS_OREJ_RESV_AB0);
666 break;
667
668 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
669
670 isci_request_set_open_reject_status(
671 request, task, response_ptr, status_ptr,
672 complete_to_host_ptr, SAS_OREJ_RESV_AB1);
673 break;
674
675 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
676
677 isci_request_set_open_reject_status(
678 request, task, response_ptr, status_ptr,
679 complete_to_host_ptr, SAS_OREJ_RESV_AB2);
680 break;
681
682 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
683
684 isci_request_set_open_reject_status(
685 request, task, response_ptr, status_ptr,
686 complete_to_host_ptr, SAS_OREJ_RESV_AB3);
687 break;
688
689 case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
690
691 isci_request_set_open_reject_status(
692 request, task, response_ptr, status_ptr,
693 complete_to_host_ptr, SAS_OREJ_BAD_DEST);
694 break;
695
696 case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
697
698 isci_request_set_open_reject_status(
699 request, task, response_ptr, status_ptr,
700 complete_to_host_ptr, SAS_OREJ_STP_NORES);
701 break;
702
703 case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
704
705 isci_request_set_open_reject_status(
706 request, task, response_ptr, status_ptr,
707 complete_to_host_ptr, SAS_OREJ_EPROTO);
708 break;
709
710 case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
711
712 isci_request_set_open_reject_status(
713 request, task, response_ptr, status_ptr,
714 complete_to_host_ptr, SAS_OREJ_CONN_RATE);
715 break;
716
717 case SCU_TASK_DONE_LL_R_ERR:
718 /* Also SCU_TASK_DONE_ACK_NAK_TO: */
719 case SCU_TASK_DONE_LL_PERR:
720 case SCU_TASK_DONE_LL_SY_TERM:
721 /* Also SCU_TASK_DONE_NAK_ERR:*/
722 case SCU_TASK_DONE_LL_LF_TERM:
723 /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
724 case SCU_TASK_DONE_LL_ABORT_ERR:
725 case SCU_TASK_DONE_SEQ_INV_TYPE:
726 /* Also SCU_TASK_DONE_UNEXP_XR: */
727 case SCU_TASK_DONE_XR_IU_LEN_ERR:
728 case SCU_TASK_DONE_INV_FIS_LEN:
729 /* Also SCU_TASK_DONE_XR_WD_LEN: */
730 case SCU_TASK_DONE_SDMA_ERR:
731 case SCU_TASK_DONE_OFFSET_ERR:
732 case SCU_TASK_DONE_MAX_PLD_ERR:
733 case SCU_TASK_DONE_LF_ERR:
734 case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
735 case SCU_TASK_DONE_SMP_LL_RX_ERR:
736 case SCU_TASK_DONE_UNEXP_DATA:
737 case SCU_TASK_DONE_UNEXP_SDBFIS:
738 case SCU_TASK_DONE_REG_ERR:
739 case SCU_TASK_DONE_SDB_ERR:
740 case SCU_TASK_DONE_TASK_ABORT:
741 default:
742 /* Task in the target is not done. */
743 *response_ptr = SAS_TASK_UNDELIVERED;
744 *status_ptr = SAM_STAT_TASK_ABORTED;
745 request->complete_in_target = false;
746
747 *complete_to_host_ptr = isci_perform_error_io_completion;
748 break;
749 }
750 }
751
752 /**
753 * isci_task_save_for_upper_layer_completion() - This function saves the
754 * request for later completion to the upper layer driver.
755 * @host: This parameter is a pointer to the host on which the the request
756 * should be queued (either as an error or success).
757 * @request: This parameter is the completed request.
758 * @response: This parameter is the response code for the completed task.
759 * @status: This parameter is the status code for the completed task.
760 *
761 * none.
762 */
763 static void isci_task_save_for_upper_layer_completion(
764 struct isci_host *host,
765 struct isci_request *request,
766 enum service_response response,
767 enum exec_status status,
768 enum isci_completion_selection task_notification_selection)
769 {
770 struct sas_task *task = isci_request_access_task(request);
771
772 task_notification_selection
773 = isci_task_set_completion_status(task, response, status,
774 task_notification_selection);
775
776 /* Tasks aborted specifically by a call to the lldd_abort_task
777 * function should not be completed to the host in the regular path.
778 */
779 switch (task_notification_selection) {
780
781 case isci_perform_normal_io_completion:
782
783 /* Normal notification (task_done) */
784 dev_dbg(&host->pdev->dev,
785 "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n",
786 __func__,
787 task,
788 task->task_status.resp, response,
789 task->task_status.stat, status);
790 /* Add to the completed list. */
791 list_add(&request->completed_node,
792 &host->requests_to_complete);
793
794 /* Take the request off the device's pending request list. */
795 list_del_init(&request->dev_node);
796 break;
797
798 case isci_perform_aborted_io_completion:
799 /* No notification to libsas because this request is
800 * already in the abort path.
801 */
802 dev_warn(&host->pdev->dev,
803 "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n",
804 __func__,
805 task,
806 task->task_status.resp, response,
807 task->task_status.stat, status);
808
809 /* Wake up whatever process was waiting for this
810 * request to complete.
811 */
812 WARN_ON(request->io_request_completion == NULL);
813
814 if (request->io_request_completion != NULL) {
815
816 /* Signal whoever is waiting that this
817 * request is complete.
818 */
819 complete(request->io_request_completion);
820 }
821 break;
822
823 case isci_perform_error_io_completion:
824 /* Use sas_task_abort */
825 dev_warn(&host->pdev->dev,
826 "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n",
827 __func__,
828 task,
829 task->task_status.resp, response,
830 task->task_status.stat, status);
831 /* Add to the aborted list. */
832 list_add(&request->completed_node,
833 &host->requests_to_errorback);
834 break;
835
836 default:
837 dev_warn(&host->pdev->dev,
838 "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n",
839 __func__,
840 task,
841 task->task_status.resp, response,
842 task->task_status.stat, status);
843
844 /* Add to the error to libsas list. */
845 list_add(&request->completed_node,
846 &host->requests_to_errorback);
847 break;
848 }
849 }
850
851 /**
852 * isci_request_io_request_complete() - This function is called by the sci core
853 * when an io request completes.
854 * @isci_host: This parameter specifies the ISCI host object
855 * @request: This parameter is the completed isci_request object.
856 * @completion_status: This parameter specifies the completion status from the
857 * sci core.
858 *
859 * none.
860 */
861 void isci_request_io_request_complete(
862 struct isci_host *isci_host,
863 struct isci_request *request,
864 enum sci_io_status completion_status)
865 {
866 struct sas_task *task = isci_request_access_task(request);
867 struct ssp_response_iu *resp_iu;
868 void *resp_buf;
869 unsigned long task_flags;
870 struct isci_remote_device *isci_device = request->isci_device;
871 enum service_response response = SAS_TASK_UNDELIVERED;
872 enum exec_status status = SAS_ABORTED_TASK;
873 enum isci_request_status request_status;
874 enum isci_completion_selection complete_to_host
875 = isci_perform_normal_io_completion;
876
877 dev_dbg(&isci_host->pdev->dev,
878 "%s: request = %p, task = %p,\n"
879 "task->data_dir = %d completion_status = 0x%x\n",
880 __func__,
881 request,
882 task,
883 task->data_dir,
884 completion_status);
885
886 spin_lock(&request->state_lock);
887 request_status = isci_request_get_state(request);
888
889 /* Decode the request status. Note that if the request has been
890 * aborted by a task management function, we don't care
891 * what the status is.
892 */
893 switch (request_status) {
894
895 case aborted:
896 /* "aborted" indicates that the request was aborted by a task
897 * management function, since once a task management request is
898 * perfomed by the device, the request only completes because
899 * of the subsequent driver terminate.
900 *
901 * Aborted also means an external thread is explicitly managing
902 * this request, so that we do not complete it up the stack.
903 *
904 * The target is still there (since the TMF was successful).
905 */
906 request->complete_in_target = true;
907 response = SAS_TASK_COMPLETE;
908
909 /* See if the device has been/is being stopped. Note
910 * that we ignore the quiesce state, since we are
911 * concerned about the actual device state.
912 */
913 if ((isci_device->status == isci_stopping)
914 || (isci_device->status == isci_stopped)
915 )
916 status = SAS_DEVICE_UNKNOWN;
917 else
918 status = SAS_ABORTED_TASK;
919
920 complete_to_host = isci_perform_aborted_io_completion;
921 /* This was an aborted request. */
922
923 spin_unlock(&request->state_lock);
924 break;
925
926 case aborting:
927 /* aborting means that the task management function tried and
928 * failed to abort the request. We need to note the request
929 * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
930 * target as down.
931 *
932 * Aborting also means an external thread is explicitly managing
933 * this request, so that we do not complete it up the stack.
934 */
935 request->complete_in_target = true;
936 response = SAS_TASK_UNDELIVERED;
937
938 if ((isci_device->status == isci_stopping) ||
939 (isci_device->status == isci_stopped))
940 /* The device has been /is being stopped. Note that
941 * we ignore the quiesce state, since we are
942 * concerned about the actual device state.
943 */
944 status = SAS_DEVICE_UNKNOWN;
945 else
946 status = SAS_PHY_DOWN;
947
948 complete_to_host = isci_perform_aborted_io_completion;
949
950 /* This was an aborted request. */
951
952 spin_unlock(&request->state_lock);
953 break;
954
955 case terminating:
956
957 /* This was an terminated request. This happens when
958 * the I/O is being terminated because of an action on
959 * the device (reset, tear down, etc.), and the I/O needs
960 * to be completed up the stack.
961 */
962 request->complete_in_target = true;
963 response = SAS_TASK_UNDELIVERED;
964
965 /* See if the device has been/is being stopped. Note
966 * that we ignore the quiesce state, since we are
967 * concerned about the actual device state.
968 */
969 if ((isci_device->status == isci_stopping) ||
970 (isci_device->status == isci_stopped))
971 status = SAS_DEVICE_UNKNOWN;
972 else
973 status = SAS_ABORTED_TASK;
974
975 complete_to_host = isci_perform_aborted_io_completion;
976
977 /* This was a terminated request. */
978
979 spin_unlock(&request->state_lock);
980 break;
981
982 default:
983
984 /* The request is done from an SCU HW perspective. */
985 request->status = completed;
986
987 spin_unlock(&request->state_lock);
988
989 /* This is an active request being completed from the core. */
990 switch (completion_status) {
991
992 case SCI_IO_FAILURE_RESPONSE_VALID:
993 dev_dbg(&isci_host->pdev->dev,
994 "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
995 __func__,
996 request,
997 task);
998
999 if (sas_protocol_ata(task->task_proto)) {
1000 resp_buf = &request->sci_request_handle->stp.rsp;
1001 isci_request_process_stp_response(task,
1002 resp_buf);
1003 } else if (SAS_PROTOCOL_SSP == task->task_proto) {
1004
1005 /* crack the iu response buffer. */
1006 resp_iu = &request->sci_request_handle->ssp.rsp;
1007 isci_request_process_response_iu(task, resp_iu,
1008 &isci_host->pdev->dev);
1009
1010 } else if (SAS_PROTOCOL_SMP == task->task_proto) {
1011
1012 dev_err(&isci_host->pdev->dev,
1013 "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
1014 "SAS_PROTOCOL_SMP protocol\n",
1015 __func__);
1016
1017 } else
1018 dev_err(&isci_host->pdev->dev,
1019 "%s: unknown protocol\n", __func__);
1020
1021 /* use the task status set in the task struct by the
1022 * isci_request_process_response_iu call.
1023 */
1024 request->complete_in_target = true;
1025 response = task->task_status.resp;
1026 status = task->task_status.stat;
1027 break;
1028
1029 case SCI_IO_SUCCESS:
1030 case SCI_IO_SUCCESS_IO_DONE_EARLY:
1031
1032 response = SAS_TASK_COMPLETE;
1033 status = SAM_STAT_GOOD;
1034 request->complete_in_target = true;
1035
1036 if (task->task_proto == SAS_PROTOCOL_SMP) {
1037 void *rsp = &request->sci_request_handle->smp.rsp;
1038
1039 dev_dbg(&isci_host->pdev->dev,
1040 "%s: SMP protocol completion\n",
1041 __func__);
1042
1043 sg_copy_from_buffer(
1044 &task->smp_task.smp_resp, 1,
1045 rsp, sizeof(struct smp_resp));
1046 } else if (completion_status
1047 == SCI_IO_SUCCESS_IO_DONE_EARLY) {
1048
1049 /* This was an SSP / STP / SATA transfer.
1050 * There is a possibility that less data than
1051 * the maximum was transferred.
1052 */
1053 u32 transferred_length
1054 = scic_io_request_get_number_of_bytes_transferred(
1055 request->sci_request_handle);
1056
1057 task->task_status.residual
1058 = task->total_xfer_len - transferred_length;
1059
1060 /* If there were residual bytes, call this an
1061 * underrun.
1062 */
1063 if (task->task_status.residual != 0)
1064 status = SAS_DATA_UNDERRUN;
1065
1066 dev_dbg(&isci_host->pdev->dev,
1067 "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
1068 __func__,
1069 status);
1070
1071 } else
1072 dev_dbg(&isci_host->pdev->dev,
1073 "%s: SCI_IO_SUCCESS\n",
1074 __func__);
1075
1076 break;
1077
1078 case SCI_IO_FAILURE_TERMINATED:
1079 dev_dbg(&isci_host->pdev->dev,
1080 "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
1081 __func__,
1082 request,
1083 task);
1084
1085 /* The request was terminated explicitly. No handling
1086 * is needed in the SCSI error handler path.
1087 */
1088 request->complete_in_target = true;
1089 response = SAS_TASK_UNDELIVERED;
1090
1091 /* See if the device has been/is being stopped. Note
1092 * that we ignore the quiesce state, since we are
1093 * concerned about the actual device state.
1094 */
1095 if ((isci_device->status == isci_stopping) ||
1096 (isci_device->status == isci_stopped))
1097 status = SAS_DEVICE_UNKNOWN;
1098 else
1099 status = SAS_ABORTED_TASK;
1100
1101 complete_to_host = isci_perform_normal_io_completion;
1102 break;
1103
1104 case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
1105
1106 isci_request_handle_controller_specific_errors(
1107 isci_device, request, task, &response, &status,
1108 &complete_to_host);
1109
1110 break;
1111
1112 case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
1113 /* This is a special case, in that the I/O completion
1114 * is telling us that the device needs a reset.
1115 * In order for the device reset condition to be
1116 * noticed, the I/O has to be handled in the error
1117 * handler. Set the reset flag and cause the
1118 * SCSI error thread to be scheduled.
1119 */
1120 spin_lock_irqsave(&task->task_state_lock, task_flags);
1121 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1122 spin_unlock_irqrestore(&task->task_state_lock, task_flags);
1123
1124 /* Fail the I/O. */
1125 response = SAS_TASK_UNDELIVERED;
1126 status = SAM_STAT_TASK_ABORTED;
1127
1128 complete_to_host = isci_perform_error_io_completion;
1129 request->complete_in_target = false;
1130 break;
1131
1132 default:
1133 /* Catch any otherwise unhandled error codes here. */
1134 dev_warn(&isci_host->pdev->dev,
1135 "%s: invalid completion code: 0x%x - "
1136 "isci_request = %p\n",
1137 __func__, completion_status, request);
1138
1139 response = SAS_TASK_UNDELIVERED;
1140
1141 /* See if the device has been/is being stopped. Note
1142 * that we ignore the quiesce state, since we are
1143 * concerned about the actual device state.
1144 */
1145 if ((isci_device->status == isci_stopping) ||
1146 (isci_device->status == isci_stopped))
1147 status = SAS_DEVICE_UNKNOWN;
1148 else
1149 status = SAS_ABORTED_TASK;
1150
1151 complete_to_host = isci_perform_error_io_completion;
1152 request->complete_in_target = false;
1153 break;
1154 }
1155 break;
1156 }
1157
1158 isci_request_unmap_sgl(request, isci_host->pdev);
1159
1160 /* Put the completed request on the correct list */
1161 isci_task_save_for_upper_layer_completion(isci_host, request, response,
1162 status, complete_to_host
1163 );
1164
1165 /* complete the io request to the core. */
1166 scic_controller_complete_io(&isci_host->sci,
1167 &isci_device->sci,
1168 request->sci_request_handle);
1169 /* NULL the request handle so it cannot be completed or
1170 * terminated again, and to cause any calls into abort
1171 * task to recognize the already completed case.
1172 */
1173 request->sci_request_handle = NULL;
1174
1175 isci_host_can_dequeue(isci_host, 1);
1176 }
This page took 0.054985 seconds and 4 git commands to generate.