blob: ff5c05a19543d4aa38205a73f38345cea8f1cf0e [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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"
Dan Williams6f231dd2011-07-02 22:56:22 -070057#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
65
66static enum sci_status isci_request_ssp_request_construct(
67 struct isci_request *request)
68{
69 enum sci_status status;
70
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
77 );
78 return status;
79}
80
81static enum sci_status isci_request_stp_request_construct(
82 struct isci_request *request)
83{
84 struct sas_task *task = isci_request_access_task(request);
85 enum sci_status status;
86 struct host_to_dev_fis *register_fis;
87
88 dev_dbg(&request->isci_host->pdev->dev,
89 "%s: request = %p\n",
90 __func__,
91 request);
92
93 /* Get the host_to_dev_fis from the core and copy
94 * the fis from the task into it.
95 */
96 register_fis = isci_sata_task_to_fis_copy(task);
97
98 status = scic_io_request_construct_basic_sata(
99 request->sci_request_handle
100 );
101
102 /* Set the ncq tag in the fis, from the queue
103 * command in the task.
104 */
105 if (isci_sata_is_task_ncq(task)) {
106
107 isci_sata_set_ncq_tag(
108 register_fis,
109 task
110 );
111 }
112
113 return status;
114}
115
116/**
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.
123 *
124 * SCI_SUCCESS on successfull completion, or specific failure code.
125 */
126static enum sci_status isci_smp_request_build(
127 struct isci_request *request)
128{
129 enum sci_status status = SCI_FAILURE;
130 struct sas_task *task = isci_request_access_task(request);
131
132 void *command_iu_address =
133 scic_io_request_get_command_iu_address(
134 request->sci_request_handle
135 );
136
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);
145
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)
150 );
151
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);
159
160 return status;
161}
162
163/**
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.
170 *
171 * SCI_SUCCESS on successfull completion, or specific failure code.
172 */
173static 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)
177{
178 struct smp_discover_response_protocols dev_protocols;
179 enum sci_status status = SCI_SUCCESS;
180 struct sas_task *task = isci_request_access_task(request);
Dan Williams57f20f42011-04-21 18:14:45 -0700181 struct scic_sds_remote_device *sci_device = &isci_device->sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700182
183 dev_dbg(&isci_host->pdev->dev,
184 "%s: isci_device = 0x%p; request = %p, "
185 "num_scatter = %d\n",
186 __func__,
187 isci_device,
188 request,
189 task->num_scatter);
190
191 /* map the sgl addresses, if present.
192 * libata does the mapping for sata devices
193 * before we get the request.
194 */
195 if (task->num_scatter &&
196 !sas_protocol_ata(task->task_proto) &&
197 !(SAS_PROTOCOL_SMP & task->task_proto)) {
198
199 request->num_sg_entries = dma_map_sg(
200 &isci_host->pdev->dev,
201 task->scatter,
202 task->num_scatter,
203 task->data_dir
204 );
205
206 if (request->num_sg_entries == 0)
207 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
208 }
209
210 /* build the common request object. For now,
211 * we will let the core allocate the IO tag.
212 */
213 status = scic_io_request_construct(
214 isci_host->core_controller,
215 sci_device,
216 SCI_CONTROLLER_INVALID_IO_TAG,
217 request,
218 request->sci_request_mem_ptr,
219 (struct scic_sds_request **)&request->sci_request_handle
220 );
221
222 if (status != SCI_SUCCESS) {
223 dev_warn(&isci_host->pdev->dev,
224 "%s: failed request construct\n",
225 __func__);
226 return SCI_FAILURE;
227 }
228
229 sci_object_set_association(request->sci_request_handle, request);
230
231 /* Determine protocol and call the appropriate basic constructor */
232 scic_remote_device_get_protocols(sci_device, &dev_protocols);
233 if (dev_protocols.u.bits.attached_ssp_target)
234 status = isci_request_ssp_request_construct(request);
235 else if (dev_protocols.u.bits.attached_stp_target)
236 status = isci_request_stp_request_construct(request);
237 else if (dev_protocols.u.bits.attached_smp_target)
238 status = isci_smp_request_build(request);
239 else {
240 dev_warn(&isci_host->pdev->dev,
241 "%s: unknown protocol\n", __func__);
242 return SCI_FAILURE;
243 }
244
245 return SCI_SUCCESS;
246}
247
248
249/**
250 * isci_request_alloc_core() - This function gets the request object from the
251 * isci_host dma cache.
252 * @isci_host: This parameter specifies the ISCI host object
253 * @isci_request: This parameter will contain the pointer to the new
254 * isci_request object.
255 * @isci_device: This parameter is the pointer to the isci remote device object
256 * that is the destination for this request.
257 * @gfp_flags: This parameter specifies the os allocation flags.
258 *
259 * SCI_SUCCESS on successfull completion, or specific failure code.
260 */
261static int isci_request_alloc_core(
262 struct isci_host *isci_host,
263 struct isci_request **isci_request,
264 struct isci_remote_device *isci_device,
265 gfp_t gfp_flags)
266{
267 int ret = 0;
268 dma_addr_t handle;
269 struct isci_request *request;
270
271
272 /* get pointer to dma memory. This actually points
273 * to both the isci_remote_device object and the
274 * sci object. The isci object is at the beginning
275 * of the memory allocated here.
276 */
277 request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle);
278 if (!request) {
279 dev_warn(&isci_host->pdev->dev,
280 "%s: dma_pool_alloc returned NULL\n", __func__);
281 return -ENOMEM;
282 }
283
284 /* initialize the request object. */
285 spin_lock_init(&request->state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700286 request->sci_request_mem_ptr = ((u8 *)request) +
287 sizeof(struct isci_request);
288 request->request_daddr = handle;
289 request->isci_host = isci_host;
290 request->isci_device = isci_device;
291 request->io_request_completion = NULL;
292
293 request->request_alloc_size = isci_host->dma_pool_alloc_size;
294 request->num_sg_entries = 0;
295
296 request->complete_in_target = false;
297
298 INIT_LIST_HEAD(&request->completed_node);
299 INIT_LIST_HEAD(&request->dev_node);
300
301 *isci_request = request;
Dan Williams83f5eee2011-02-18 09:25:15 -0800302 isci_request_change_state(request, allocated);
Dan Williams6f231dd2011-07-02 22:56:22 -0700303
304 return ret;
305}
306
307static int isci_request_alloc_io(
308 struct isci_host *isci_host,
309 struct sas_task *task,
310 struct isci_request **isci_request,
311 struct isci_remote_device *isci_device,
312 gfp_t gfp_flags)
313{
314 int retval = isci_request_alloc_core(isci_host, isci_request,
315 isci_device, gfp_flags);
316
317 if (!retval) {
318 (*isci_request)->ttype_ptr.io_task_ptr = task;
319 (*isci_request)->ttype = io_task;
320
321 task->lldd_task = *isci_request;
322 }
323 return retval;
324}
325
326/**
327 * isci_request_alloc_tmf() - This function gets the request object from the
328 * isci_host dma cache and initializes the relevant fields as a sas_task.
329 * @isci_host: This parameter specifies the ISCI host object
330 * @sas_task: This parameter is the task struct from the upper layer driver.
331 * @isci_request: This parameter will contain the pointer to the new
332 * isci_request object.
333 * @isci_device: This parameter is the pointer to the isci remote device object
334 * that is the destination for this request.
335 * @gfp_flags: This parameter specifies the os allocation flags.
336 *
337 * SCI_SUCCESS on successfull completion, or specific failure code.
338 */
339int isci_request_alloc_tmf(
340 struct isci_host *isci_host,
341 struct isci_tmf *isci_tmf,
342 struct isci_request **isci_request,
343 struct isci_remote_device *isci_device,
344 gfp_t gfp_flags)
345{
346 int retval = isci_request_alloc_core(isci_host, isci_request,
347 isci_device, gfp_flags);
348
349 if (!retval) {
350
351 (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf;
352 (*isci_request)->ttype = tmf_task;
353 }
354 return retval;
355}
356
357/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700358 * isci_request_execute() - This function allocates the isci_request object,
359 * all fills in some common fields.
360 * @isci_host: This parameter specifies the ISCI host object
361 * @sas_task: This parameter is the task struct from the upper layer driver.
362 * @isci_request: This parameter will contain the pointer to the new
363 * isci_request object.
364 * @gfp_flags: This parameter specifies the os allocation flags.
365 *
366 * SCI_SUCCESS on successfull completion, or specific failure code.
367 */
368int isci_request_execute(
369 struct isci_host *isci_host,
370 struct sas_task *task,
371 struct isci_request **isci_request,
372 gfp_t gfp_flags)
373{
374 int ret = 0;
375 struct scic_sds_remote_device *sci_device;
376 enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
377 struct isci_remote_device *isci_device;
378 struct isci_request *request;
379 unsigned long flags;
380
Dan Williams4393aa42011-03-31 13:10:44 -0700381 isci_device = task->dev->lldd_dev;
Dan Williams57f20f42011-04-21 18:14:45 -0700382 sci_device = &isci_device->sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700383
384 /* do common allocation and init of request object. */
385 ret = isci_request_alloc_io(
386 isci_host,
387 task,
388 &request,
389 isci_device,
390 gfp_flags
391 );
392
393 if (ret)
394 goto out;
395
396 status = isci_io_request_build(isci_host, request, isci_device);
397 if (status == SCI_SUCCESS) {
398
399 spin_lock_irqsave(&isci_host->scic_lock, flags);
400
401 /* send the request, let the core assign the IO TAG. */
402 status = scic_controller_start_io(
403 isci_host->core_controller,
404 sci_device,
405 request->sci_request_handle,
406 SCI_CONTROLLER_INVALID_IO_TAG
407 );
408
409 if (status == SCI_SUCCESS ||
410 status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
411
412 /* Either I/O started OK, or the core has signaled that
413 * the device needs a target reset.
414 *
415 * In either case, hold onto the I/O for later.
416 *
417 * Update it's status and add it to the list in the
418 * remote device object.
419 */
420 isci_request_change_state(request, started);
421 list_add(&request->dev_node,
422 &isci_device->reqs_in_process);
423
Jeff Skirvinc4b9e242011-03-16 09:41:59 -0700424 if (status == SCI_SUCCESS) {
Jeff Skirvin1fad9e92011-03-04 14:06:46 -0800425 /* Save the tag for possible task mgmt later. */
426 request->io_tag = scic_io_request_get_io_tag(
427 request->sci_request_handle);
Jeff Skirvince4f75d2011-03-31 13:10:36 -0700428 } else {
429 /* The request did not really start in the
430 * hardware, so clear the request handle
431 * here so no terminations will be done.
432 */
433 request->sci_request_handle = NULL;
Jeff Skirvinc4b9e242011-03-16 09:41:59 -0700434 }
Jeff Skirvince4f75d2011-03-31 13:10:36 -0700435
Dan Williams6f231dd2011-07-02 22:56:22 -0700436 } else
437 dev_warn(&isci_host->pdev->dev,
Jeff Skirvince4f75d2011-03-31 13:10:36 -0700438 "%s: failed request start (0x%x)\n",
439 __func__, status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700440
441 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
442
Jeff Skirvinc4b9e242011-03-16 09:41:59 -0700443 if (status ==
444 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
445 /* Signal libsas that we need the SCSI error
446 * handler thread to work on this I/O and that
447 * we want a device reset.
448 */
Jeff Skirvince4f75d2011-03-31 13:10:36 -0700449 spin_lock_irqsave(&task->task_state_lock, flags);
450 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
451 spin_unlock_irqrestore(&task->task_state_lock, flags);
452
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700453 /* Cause this task to be scheduled in the SCSI error
454 * handler thread.
Jeff Skirvince4f75d2011-03-31 13:10:36 -0700455 */
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700456 isci_execpath_callback(isci_host, task,
457 sas_task_abort);
Jeff Skirvinc4b9e242011-03-16 09:41:59 -0700458
459 /* Change the status, since we are holding
460 * the I/O until it is managed by the SCSI
461 * error handler.
462 */
463 status = SCI_SUCCESS;
464 }
465
Dan Williams6f231dd2011-07-02 22:56:22 -0700466 } else
467 dev_warn(&isci_host->pdev->dev,
468 "%s: request_construct failed - status = 0x%x\n",
469 __func__,
470 status);
471
472 out:
473 if (status != SCI_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700474 /* release dma memory on failure. */
475 isci_request_free(isci_host, request);
476 request = NULL;
477 ret = SCI_FAILURE;
478 }
479
480 *isci_request = request;
481 return ret;
482}
483
484
485/**
486 * isci_request_process_response_iu() - This function sets the status and
487 * response iu, in the task struct, from the request object for the upper
488 * layer driver.
489 * @sas_task: This parameter is the task struct from the upper layer driver.
490 * @resp_iu: This parameter points to the response iu of the completed request.
491 * @dev: This parameter specifies the linux device struct.
492 *
493 * none.
494 */
495static void isci_request_process_response_iu(
496 struct sas_task *task,
497 struct ssp_response_iu *resp_iu,
498 struct device *dev)
499{
500 dev_dbg(dev,
501 "%s: resp_iu = %p "
502 "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
503 "resp_iu->response_data_len = %x, "
504 "resp_iu->sense_data_len = %x\nrepsonse data: ",
505 __func__,
506 resp_iu,
507 resp_iu->status,
508 resp_iu->datapres,
509 resp_iu->response_data_len,
510 resp_iu->sense_data_len);
511
512 task->task_status.stat = resp_iu->status;
513
514 /* libsas updates the task status fields based on the response iu. */
515 sas_ssp_task_response(dev, task, resp_iu);
516}
517
518/**
519 * isci_request_set_open_reject_status() - This function prepares the I/O
520 * completion for OPEN_REJECT conditions.
521 * @request: This parameter is the completed isci_request object.
522 * @response_ptr: This parameter specifies the service response for the I/O.
523 * @status_ptr: This parameter specifies the exec status for the I/O.
524 * @complete_to_host_ptr: This parameter specifies the action to be taken by
525 * the LLDD with respect to completing this request or forcing an abort
526 * condition on the I/O.
527 * @open_rej_reason: This parameter specifies the encoded reason for the
528 * abandon-class reject.
529 *
530 * none.
531 */
532static void isci_request_set_open_reject_status(
533 struct isci_request *request,
534 struct sas_task *task,
535 enum service_response *response_ptr,
536 enum exec_status *status_ptr,
537 enum isci_completion_selection *complete_to_host_ptr,
538 enum sas_open_rej_reason open_rej_reason)
539{
540 /* Task in the target is done. */
541 request->complete_in_target = true;
542 *response_ptr = SAS_TASK_UNDELIVERED;
543 *status_ptr = SAS_OPEN_REJECT;
544 *complete_to_host_ptr = isci_perform_normal_io_completion;
545 task->task_status.open_rej_reason = open_rej_reason;
546}
547
548/**
549 * isci_request_handle_controller_specific_errors() - This function decodes
550 * controller-specific I/O completion error conditions.
551 * @request: This parameter is the completed isci_request object.
552 * @response_ptr: This parameter specifies the service response for the I/O.
553 * @status_ptr: This parameter specifies the exec status for the I/O.
554 * @complete_to_host_ptr: This parameter specifies the action to be taken by
555 * the LLDD with respect to completing this request or forcing an abort
556 * condition on the I/O.
557 *
558 * none.
559 */
560static void isci_request_handle_controller_specific_errors(
561 struct isci_remote_device *isci_device,
562 struct isci_request *request,
563 struct sas_task *task,
564 enum service_response *response_ptr,
565 enum exec_status *status_ptr,
566 enum isci_completion_selection *complete_to_host_ptr)
567{
568 unsigned int cstatus;
569
570 cstatus = scic_request_get_controller_status(
571 request->sci_request_handle
572 );
573
574 dev_dbg(&request->isci_host->pdev->dev,
575 "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
576 "- controller status = 0x%x\n",
577 __func__, request, cstatus);
578
579 /* Decode the controller-specific errors; most
580 * important is to recognize those conditions in which
581 * the target may still have a task outstanding that
582 * must be aborted.
583 *
584 * Note that there are SCU completion codes being
585 * named in the decode below for which SCIC has already
586 * done work to handle them in a way other than as
587 * a controller-specific completion code; these are left
588 * in the decode below for completeness sake.
589 */
590 switch (cstatus) {
591 case SCU_TASK_DONE_DMASETUP_DIRERR:
592 /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
593 case SCU_TASK_DONE_XFERCNT_ERR:
594 /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
595 if (task->task_proto == SAS_PROTOCOL_SMP) {
596 /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
597 *response_ptr = SAS_TASK_COMPLETE;
598
599 /* See if the device has been/is being stopped. Note
600 * that we ignore the quiesce state, since we are
601 * concerned about the actual device state.
602 */
603 if ((isci_device->status == isci_stopping) ||
604 (isci_device->status == isci_stopped))
605 *status_ptr = SAS_DEVICE_UNKNOWN;
606 else
607 *status_ptr = SAS_ABORTED_TASK;
608
609 request->complete_in_target = true;
610
611 *complete_to_host_ptr =
612 isci_perform_normal_io_completion;
613 } else {
614 /* Task in the target is not done. */
615 *response_ptr = SAS_TASK_UNDELIVERED;
616
617 if ((isci_device->status == isci_stopping) ||
618 (isci_device->status == isci_stopped))
619 *status_ptr = SAS_DEVICE_UNKNOWN;
620 else
621 *status_ptr = SAM_STAT_TASK_ABORTED;
622
623 request->complete_in_target = false;
624
625 *complete_to_host_ptr =
626 isci_perform_error_io_completion;
627 }
628
629 break;
630
631 case SCU_TASK_DONE_CRC_ERR:
632 case SCU_TASK_DONE_NAK_CMD_ERR:
633 case SCU_TASK_DONE_EXCESS_DATA:
634 case SCU_TASK_DONE_UNEXP_FIS:
635 /* Also SCU_TASK_DONE_UNEXP_RESP: */
636 case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
637 case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
638 case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
639 /* These are conditions in which the target
640 * has completed the task, so that no cleanup
641 * is necessary.
642 */
643 *response_ptr = SAS_TASK_COMPLETE;
644
645 /* See if the device has been/is being stopped. Note
646 * that we ignore the quiesce state, since we are
647 * concerned about the actual device state.
648 */
649 if ((isci_device->status == isci_stopping) ||
650 (isci_device->status == isci_stopped))
651 *status_ptr = SAS_DEVICE_UNKNOWN;
652 else
653 *status_ptr = SAS_ABORTED_TASK;
654
655 request->complete_in_target = true;
656
657 *complete_to_host_ptr = isci_perform_normal_io_completion;
658 break;
659
660
661 /* Note that the only open reject completion codes seen here will be
662 * abandon-class codes; all others are automatically retried in the SCU.
663 */
664 case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
665
666 isci_request_set_open_reject_status(
667 request, task, response_ptr, status_ptr,
668 complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
669 break;
670
671 case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
672
673 /* Note - the return of AB0 will change when
674 * libsas implements detection of zone violations.
675 */
676 isci_request_set_open_reject_status(
677 request, task, response_ptr, status_ptr,
678 complete_to_host_ptr, SAS_OREJ_RESV_AB0);
679 break;
680
681 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
682
683 isci_request_set_open_reject_status(
684 request, task, response_ptr, status_ptr,
685 complete_to_host_ptr, SAS_OREJ_RESV_AB1);
686 break;
687
688 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
689
690 isci_request_set_open_reject_status(
691 request, task, response_ptr, status_ptr,
692 complete_to_host_ptr, SAS_OREJ_RESV_AB2);
693 break;
694
695 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
696
697 isci_request_set_open_reject_status(
698 request, task, response_ptr, status_ptr,
699 complete_to_host_ptr, SAS_OREJ_RESV_AB3);
700 break;
701
702 case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
703
704 isci_request_set_open_reject_status(
705 request, task, response_ptr, status_ptr,
706 complete_to_host_ptr, SAS_OREJ_BAD_DEST);
707 break;
708
709 case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
710
711 isci_request_set_open_reject_status(
712 request, task, response_ptr, status_ptr,
713 complete_to_host_ptr, SAS_OREJ_STP_NORES);
714 break;
715
716 case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
717
718 isci_request_set_open_reject_status(
719 request, task, response_ptr, status_ptr,
720 complete_to_host_ptr, SAS_OREJ_EPROTO);
721 break;
722
723 case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
724
725 isci_request_set_open_reject_status(
726 request, task, response_ptr, status_ptr,
727 complete_to_host_ptr, SAS_OREJ_CONN_RATE);
728 break;
729
730 case SCU_TASK_DONE_LL_R_ERR:
731 /* Also SCU_TASK_DONE_ACK_NAK_TO: */
732 case SCU_TASK_DONE_LL_PERR:
733 case SCU_TASK_DONE_LL_SY_TERM:
734 /* Also SCU_TASK_DONE_NAK_ERR:*/
735 case SCU_TASK_DONE_LL_LF_TERM:
736 /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
737 case SCU_TASK_DONE_LL_ABORT_ERR:
738 case SCU_TASK_DONE_SEQ_INV_TYPE:
739 /* Also SCU_TASK_DONE_UNEXP_XR: */
740 case SCU_TASK_DONE_XR_IU_LEN_ERR:
741 case SCU_TASK_DONE_INV_FIS_LEN:
742 /* Also SCU_TASK_DONE_XR_WD_LEN: */
743 case SCU_TASK_DONE_SDMA_ERR:
744 case SCU_TASK_DONE_OFFSET_ERR:
745 case SCU_TASK_DONE_MAX_PLD_ERR:
746 case SCU_TASK_DONE_LF_ERR:
747 case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
748 case SCU_TASK_DONE_SMP_LL_RX_ERR:
749 case SCU_TASK_DONE_UNEXP_DATA:
750 case SCU_TASK_DONE_UNEXP_SDBFIS:
751 case SCU_TASK_DONE_REG_ERR:
752 case SCU_TASK_DONE_SDB_ERR:
753 case SCU_TASK_DONE_TASK_ABORT:
754 default:
755 /* Task in the target is not done. */
756 *response_ptr = SAS_TASK_UNDELIVERED;
757 *status_ptr = SAM_STAT_TASK_ABORTED;
758 request->complete_in_target = false;
759
760 *complete_to_host_ptr = isci_perform_error_io_completion;
761 break;
762 }
763}
764
765/**
766 * isci_task_save_for_upper_layer_completion() - This function saves the
767 * request for later completion to the upper layer driver.
768 * @host: This parameter is a pointer to the host on which the the request
769 * should be queued (either as an error or success).
770 * @request: This parameter is the completed request.
771 * @response: This parameter is the response code for the completed task.
772 * @status: This parameter is the status code for the completed task.
773 *
774 * none.
775 */
776static void isci_task_save_for_upper_layer_completion(
777 struct isci_host *host,
778 struct isci_request *request,
779 enum service_response response,
780 enum exec_status status,
781 enum isci_completion_selection task_notification_selection)
782{
783 struct sas_task *task = isci_request_access_task(request);
784
Jeff Skirvinec6c9632011-03-04 14:06:44 -0800785 task_notification_selection
786 = isci_task_set_completion_status(task, response, status,
787 task_notification_selection);
Dan Williams6f231dd2011-07-02 22:56:22 -0700788
789 /* Tasks aborted specifically by a call to the lldd_abort_task
790 * function should not be completed to the host in the regular path.
791 */
792 switch (task_notification_selection) {
793
794 case isci_perform_normal_io_completion:
795
796 /* Normal notification (task_done) */
797 dev_dbg(&host->pdev->dev,
Jeff Skirvinaa145102011-03-07 16:40:47 -0700798 "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700799 __func__,
800 task,
Jeff Skirvinaa145102011-03-07 16:40:47 -0700801 task->task_status.resp, response,
802 task->task_status.stat, status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700803 /* Add to the completed list. */
804 list_add(&request->completed_node,
805 &host->requests_to_complete);
Jeff Skirvinec6c9632011-03-04 14:06:44 -0800806
807 /* Take the request off the device's pending request list. */
808 list_del_init(&request->dev_node);
Dan Williams6f231dd2011-07-02 22:56:22 -0700809 break;
810
811 case isci_perform_aborted_io_completion:
Jeff Skirvina5fde222011-03-04 14:06:42 -0800812 /* No notification to libsas because this request is
813 * already in the abort path.
Dan Williams6f231dd2011-07-02 22:56:22 -0700814 */
815 dev_warn(&host->pdev->dev,
Jeff Skirvinaa145102011-03-07 16:40:47 -0700816 "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700817 __func__,
818 task,
Jeff Skirvinaa145102011-03-07 16:40:47 -0700819 task->task_status.resp, response,
820 task->task_status.stat, status);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800821
822 /* Wake up whatever process was waiting for this
823 * request to complete.
824 */
825 WARN_ON(request->io_request_completion == NULL);
826
827 if (request->io_request_completion != NULL) {
828
829 /* Signal whoever is waiting that this
830 * request is complete.
831 */
832 complete(request->io_request_completion);
833 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700834 break;
835
836 case isci_perform_error_io_completion:
837 /* Use sas_task_abort */
838 dev_warn(&host->pdev->dev,
Jeff Skirvinaa145102011-03-07 16:40:47 -0700839 "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700840 __func__,
841 task,
Jeff Skirvinaa145102011-03-07 16:40:47 -0700842 task->task_status.resp, response,
843 task->task_status.stat, status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700844 /* Add to the aborted list. */
845 list_add(&request->completed_node,
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800846 &host->requests_to_errorback);
Dan Williams6f231dd2011-07-02 22:56:22 -0700847 break;
848
849 default:
850 dev_warn(&host->pdev->dev,
Jeff Skirvinaa145102011-03-07 16:40:47 -0700851 "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700852 __func__,
853 task,
Jeff Skirvinaa145102011-03-07 16:40:47 -0700854 task->task_status.resp, response,
855 task->task_status.stat, status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700856
Jeff Skirvina5fde222011-03-04 14:06:42 -0800857 /* Add to the error to libsas list. */
Dan Williams6f231dd2011-07-02 22:56:22 -0700858 list_add(&request->completed_node,
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800859 &host->requests_to_errorback);
Dan Williams6f231dd2011-07-02 22:56:22 -0700860 break;
861 }
862}
863
864/**
865 * isci_request_io_request_complete() - This function is called by the sci core
866 * when an io request completes.
867 * @isci_host: This parameter specifies the ISCI host object
868 * @request: This parameter is the completed isci_request object.
869 * @completion_status: This parameter specifies the completion status from the
870 * sci core.
871 *
872 * none.
873 */
874void isci_request_io_request_complete(
875 struct isci_host *isci_host,
876 struct isci_request *request,
877 enum sci_io_status completion_status)
878{
879 struct sas_task *task = isci_request_access_task(request);
880 struct ssp_response_iu *resp_iu;
881 void *resp_buf;
882 unsigned long task_flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700883 struct isci_remote_device *isci_device = request->isci_device;
884 enum service_response response = SAS_TASK_UNDELIVERED;
885 enum exec_status status = SAS_ABORTED_TASK;
886 enum isci_request_status request_status;
887 enum isci_completion_selection complete_to_host
888 = isci_perform_normal_io_completion;
889
890 dev_dbg(&isci_host->pdev->dev,
891 "%s: request = %p, task = %p,\n"
892 "task->data_dir = %d completion_status = 0x%x\n",
893 __func__,
894 request,
895 task,
896 task->data_dir,
897 completion_status);
898
Jeff Skirvina5fde222011-03-04 14:06:42 -0800899 spin_lock(&request->state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700900 request_status = isci_request_get_state(request);
Dan Williams6f231dd2011-07-02 22:56:22 -0700901
902 /* Decode the request status. Note that if the request has been
903 * aborted by a task management function, we don't care
904 * what the status is.
905 */
906 switch (request_status) {
907
908 case aborted:
909 /* "aborted" indicates that the request was aborted by a task
910 * management function, since once a task management request is
911 * perfomed by the device, the request only completes because
912 * of the subsequent driver terminate.
913 *
914 * Aborted also means an external thread is explicitly managing
915 * this request, so that we do not complete it up the stack.
916 *
917 * The target is still there (since the TMF was successful).
918 */
919 request->complete_in_target = true;
920 response = SAS_TASK_COMPLETE;
921
922 /* See if the device has been/is being stopped. Note
923 * that we ignore the quiesce state, since we are
924 * concerned about the actual device state.
925 */
926 if ((isci_device->status == isci_stopping)
927 || (isci_device->status == isci_stopped)
928 )
929 status = SAS_DEVICE_UNKNOWN;
930 else
931 status = SAS_ABORTED_TASK;
932
933 complete_to_host = isci_perform_aborted_io_completion;
934 /* This was an aborted request. */
Jeff Skirvina5fde222011-03-04 14:06:42 -0800935
936 spin_unlock(&request->state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700937 break;
938
939 case aborting:
940 /* aborting means that the task management function tried and
941 * failed to abort the request. We need to note the request
942 * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
943 * target as down.
944 *
945 * Aborting also means an external thread is explicitly managing
946 * this request, so that we do not complete it up the stack.
947 */
948 request->complete_in_target = true;
949 response = SAS_TASK_UNDELIVERED;
950
951 if ((isci_device->status == isci_stopping) ||
952 (isci_device->status == isci_stopped))
953 /* The device has been /is being stopped. Note that
954 * we ignore the quiesce state, since we are
955 * concerned about the actual device state.
956 */
957 status = SAS_DEVICE_UNKNOWN;
958 else
959 status = SAS_PHY_DOWN;
960
961 complete_to_host = isci_perform_aborted_io_completion;
962
963 /* This was an aborted request. */
Jeff Skirvina5fde222011-03-04 14:06:42 -0800964
965 spin_unlock(&request->state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700966 break;
967
968 case terminating:
969
970 /* This was an terminated request. This happens when
971 * the I/O is being terminated because of an action on
972 * the device (reset, tear down, etc.), and the I/O needs
973 * to be completed up the stack.
974 */
975 request->complete_in_target = true;
976 response = SAS_TASK_UNDELIVERED;
977
978 /* See if the device has been/is being stopped. Note
979 * that we ignore the quiesce state, since we are
980 * concerned about the actual device state.
981 */
982 if ((isci_device->status == isci_stopping) ||
983 (isci_device->status == isci_stopped))
984 status = SAS_DEVICE_UNKNOWN;
985 else
986 status = SAS_ABORTED_TASK;
987
Jeff Skirvina5fde222011-03-04 14:06:42 -0800988 complete_to_host = isci_perform_aborted_io_completion;
Dan Williams6f231dd2011-07-02 22:56:22 -0700989
990 /* This was a terminated request. */
Jeff Skirvina5fde222011-03-04 14:06:42 -0800991
992 spin_unlock(&request->state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700993 break;
994
995 default:
996
Jeff Skirvina5fde222011-03-04 14:06:42 -0800997 /* The request is done from an SCU HW perspective. */
998 request->status = completed;
999
1000 spin_unlock(&request->state_lock);
1001
Dan Williams6f231dd2011-07-02 22:56:22 -07001002 /* This is an active request being completed from the core. */
1003 switch (completion_status) {
1004
1005 case SCI_IO_FAILURE_RESPONSE_VALID:
1006 dev_dbg(&isci_host->pdev->dev,
1007 "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
1008 __func__,
1009 request,
1010 task);
1011
1012 if (sas_protocol_ata(task->task_proto)) {
1013 resp_buf
1014 = scic_stp_io_request_get_d2h_reg_address(
1015 request->sci_request_handle
1016 );
1017 isci_request_process_stp_response(task,
1018 resp_buf
1019 );
1020
1021 } else if (SAS_PROTOCOL_SSP == task->task_proto) {
1022
1023 /* crack the iu response buffer. */
1024 resp_iu
1025 = scic_io_request_get_response_iu_address(
1026 request->sci_request_handle
1027 );
1028
1029 isci_request_process_response_iu(task, resp_iu,
1030 &isci_host->pdev->dev
1031 );
1032
1033 } else if (SAS_PROTOCOL_SMP == task->task_proto) {
1034
1035 dev_err(&isci_host->pdev->dev,
1036 "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
1037 "SAS_PROTOCOL_SMP protocol\n",
1038 __func__);
1039
1040 } else
1041 dev_err(&isci_host->pdev->dev,
1042 "%s: unknown protocol\n", __func__);
1043
1044 /* use the task status set in the task struct by the
1045 * isci_request_process_response_iu call.
1046 */
1047 request->complete_in_target = true;
1048 response = task->task_status.resp;
1049 status = task->task_status.stat;
1050 break;
1051
1052 case SCI_IO_SUCCESS:
1053 case SCI_IO_SUCCESS_IO_DONE_EARLY:
1054
1055 response = SAS_TASK_COMPLETE;
1056 status = SAM_STAT_GOOD;
1057 request->complete_in_target = true;
1058
1059 if (task->task_proto == SAS_PROTOCOL_SMP) {
1060
1061 u8 *command_iu_address
1062 = scic_io_request_get_command_iu_address(
1063 request->sci_request_handle
1064 );
1065
1066 dev_dbg(&isci_host->pdev->dev,
1067 "%s: SMP protocol completion\n",
1068 __func__);
1069
1070 sg_copy_from_buffer(
1071 &task->smp_task.smp_resp, 1,
1072 command_iu_address
1073 + sizeof(struct smp_request),
1074 sizeof(struct smp_resp)
1075 );
1076 } else if (completion_status
1077 == SCI_IO_SUCCESS_IO_DONE_EARLY) {
1078
1079 /* This was an SSP / STP / SATA transfer.
1080 * There is a possibility that less data than
1081 * the maximum was transferred.
1082 */
1083 u32 transferred_length
1084 = scic_io_request_get_number_of_bytes_transferred(
1085 request->sci_request_handle);
1086
1087 task->task_status.residual
1088 = task->total_xfer_len - transferred_length;
1089
1090 /* If there were residual bytes, call this an
1091 * underrun.
1092 */
1093 if (task->task_status.residual != 0)
1094 status = SAS_DATA_UNDERRUN;
1095
1096 dev_dbg(&isci_host->pdev->dev,
1097 "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
1098 __func__,
1099 status);
1100
1101 } else
1102 dev_dbg(&isci_host->pdev->dev,
1103 "%s: SCI_IO_SUCCESS\n",
1104 __func__);
1105
1106 break;
1107
1108 case SCI_IO_FAILURE_TERMINATED:
1109 dev_dbg(&isci_host->pdev->dev,
1110 "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
1111 __func__,
1112 request,
1113 task);
1114
1115 /* The request was terminated explicitly. No handling
1116 * is needed in the SCSI error handler path.
1117 */
1118 request->complete_in_target = true;
1119 response = SAS_TASK_UNDELIVERED;
1120
1121 /* See if the device has been/is being stopped. Note
1122 * that we ignore the quiesce state, since we are
1123 * concerned about the actual device state.
1124 */
1125 if ((isci_device->status == isci_stopping) ||
1126 (isci_device->status == isci_stopped))
1127 status = SAS_DEVICE_UNKNOWN;
1128 else
1129 status = SAS_ABORTED_TASK;
1130
1131 complete_to_host = isci_perform_normal_io_completion;
1132 break;
1133
1134 case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
1135
1136 isci_request_handle_controller_specific_errors(
1137 isci_device, request, task, &response, &status,
1138 &complete_to_host);
1139
1140 break;
1141
1142 case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
1143 /* This is a special case, in that the I/O completion
1144 * is telling us that the device needs a reset.
1145 * In order for the device reset condition to be
1146 * noticed, the I/O has to be handled in the error
1147 * handler. Set the reset flag and cause the
1148 * SCSI error thread to be scheduled.
1149 */
1150 spin_lock_irqsave(&task->task_state_lock, task_flags);
1151 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1152 spin_unlock_irqrestore(&task->task_state_lock, task_flags);
1153
Jeff Skirvinaa145102011-03-07 16:40:47 -07001154 /* Fail the I/O. */
1155 response = SAS_TASK_UNDELIVERED;
1156 status = SAM_STAT_TASK_ABORTED;
1157
Dan Williams6f231dd2011-07-02 22:56:22 -07001158 complete_to_host = isci_perform_error_io_completion;
1159 request->complete_in_target = false;
1160 break;
1161
1162 default:
1163 /* Catch any otherwise unhandled error codes here. */
1164 dev_warn(&isci_host->pdev->dev,
1165 "%s: invalid completion code: 0x%x - "
1166 "isci_request = %p\n",
1167 __func__, completion_status, request);
1168
1169 response = SAS_TASK_UNDELIVERED;
1170
1171 /* See if the device has been/is being stopped. Note
1172 * that we ignore the quiesce state, since we are
1173 * concerned about the actual device state.
1174 */
1175 if ((isci_device->status == isci_stopping) ||
1176 (isci_device->status == isci_stopped))
1177 status = SAS_DEVICE_UNKNOWN;
1178 else
1179 status = SAS_ABORTED_TASK;
1180
1181 complete_to_host = isci_perform_error_io_completion;
1182 request->complete_in_target = false;
1183 break;
1184 }
1185 break;
1186 }
1187
1188 isci_request_unmap_sgl(request, isci_host->pdev);
1189
1190 /* Put the completed request on the correct list */
1191 isci_task_save_for_upper_layer_completion(isci_host, request, response,
1192 status, complete_to_host
1193 );
1194
1195 /* complete the io request to the core. */
Dan Williams57f20f42011-04-21 18:14:45 -07001196 scic_controller_complete_io(isci_host->core_controller,
1197 &isci_device->sci,
1198 request->sci_request_handle);
Dan Williams6f231dd2011-07-02 22:56:22 -07001199 /* NULL the request handle so it cannot be completed or
1200 * terminated again, and to cause any calls into abort
1201 * task to recognize the already completed case.
1202 */
1203 request->sci_request_handle = NULL;
1204
Dan Williams6f231dd2011-07-02 22:56:22 -07001205 isci_host_can_dequeue(isci_host, 1);
1206}
1207
1208/**
1209 * isci_request_io_request_get_transfer_length() - This function is called by
1210 * the sci core to retrieve the transfer length for a given request.
1211 * @request: This parameter is the isci_request object.
1212 *
1213 * length of transfer for specified request.
1214 */
1215u32 isci_request_io_request_get_transfer_length(struct isci_request *request)
1216{
1217 struct sas_task *task = isci_request_access_task(request);
1218
1219 dev_dbg(&request->isci_host->pdev->dev,
1220 "%s: total_xfer_len: %d\n",
1221 __func__,
1222 task->total_xfer_len);
1223 return task->total_xfer_len;
1224}
1225
1226
1227/**
1228 * isci_request_io_request_get_data_direction() - This function is called by
1229 * the sci core to retrieve the data direction for a given request.
1230 * @request: This parameter is the isci_request object.
1231 *
1232 * data direction for specified request.
1233 */
Dan Williams82d29922011-02-08 17:53:10 -08001234enum dma_data_direction isci_request_io_request_get_data_direction(
Dan Williams6f231dd2011-07-02 22:56:22 -07001235 struct isci_request *request)
1236{
1237 struct sas_task *task = isci_request_access_task(request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001238
Dan Williams82d29922011-02-08 17:53:10 -08001239 return task->data_dir;
Dan Williams6f231dd2011-07-02 22:56:22 -07001240}
1241
1242/**
1243 * isci_request_sge_get_address_field() - This function is called by the sci
1244 * core to retrieve the address field contents for a given sge.
1245 * @request: This parameter is the isci_request object.
1246 * @sge_address: This parameter is the sge.
1247 *
1248 * physical address in the specified sge.
1249 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001250
1251
1252/**
1253 * isci_request_sge_get_length_field() - This function is called by the sci
1254 * core to retrieve the length field contents for a given sge.
1255 * @request: This parameter is the isci_request object.
1256 * @sge_address: This parameter is the sge.
1257 *
1258 * length field value in the specified sge.
1259 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001260
1261
1262/**
1263 * isci_request_ssp_io_request_get_cdb_address() - This function is called by
1264 * the sci core to retrieve the cdb address for a given request.
1265 * @request: This parameter is the isci_request object.
1266 *
1267 * cdb address for specified request.
1268 */
1269void *isci_request_ssp_io_request_get_cdb_address(
1270 struct isci_request *request)
1271{
1272 struct sas_task *task = isci_request_access_task(request);
1273
1274 dev_dbg(&request->isci_host->pdev->dev,
1275 "%s: request->task->ssp_task.cdb = %p\n",
1276 __func__,
1277 task->ssp_task.cdb);
1278 return task->ssp_task.cdb;
1279}
1280
1281
1282/**
1283 * isci_request_ssp_io_request_get_cdb_length() - This function is called by
1284 * the sci core to retrieve the cdb length for a given request.
1285 * @request: This parameter is the isci_request object.
1286 *
1287 * cdb length for specified request.
1288 */
1289u32 isci_request_ssp_io_request_get_cdb_length(
1290 struct isci_request *request)
1291{
1292 return 16;
1293}
1294
1295
1296/**
1297 * isci_request_ssp_io_request_get_lun() - This function is called by the sci
1298 * core to retrieve the lun for a given request.
1299 * @request: This parameter is the isci_request object.
1300 *
1301 * lun for specified request.
1302 */
1303u32 isci_request_ssp_io_request_get_lun(
1304 struct isci_request *request)
1305{
1306 struct sas_task *task = isci_request_access_task(request);
1307
1308#ifdef DEBUG
1309 int i;
1310
1311 for (i = 0; i < 8; i++)
1312 dev_dbg(&request->isci_host->pdev->dev,
Dan Williams83f5eee2011-02-18 09:25:15 -08001313 "%s: task->ssp_task.LUN[%d] = %x\n",
1314 __func__, i, task->ssp_task.LUN[i]);
Dan Williams6f231dd2011-07-02 22:56:22 -07001315
1316#endif
1317
1318 return task->ssp_task.LUN[0];
1319}
1320
1321
1322/**
1323 * isci_request_ssp_io_request_get_task_attribute() - This function is called
1324 * by the sci core to retrieve the task attribute for a given request.
1325 * @request: This parameter is the isci_request object.
1326 *
1327 * task attribute for specified request.
1328 */
1329u32 isci_request_ssp_io_request_get_task_attribute(
1330 struct isci_request *request)
1331{
1332 struct sas_task *task = isci_request_access_task(request);
1333
1334 dev_dbg(&request->isci_host->pdev->dev,
1335 "%s: request->task->ssp_task.task_attr = %x\n",
1336 __func__,
1337 task->ssp_task.task_attr);
1338
1339 return task->ssp_task.task_attr;
1340}
1341
1342
1343/**
1344 * isci_request_ssp_io_request_get_command_priority() - This function is called
1345 * by the sci core to retrieve the command priority for a given request.
1346 * @request: This parameter is the isci_request object.
1347 *
1348 * command priority for specified request.
1349 */
1350u32 isci_request_ssp_io_request_get_command_priority(
1351 struct isci_request *request)
1352{
1353 struct sas_task *task = isci_request_access_task(request);
1354
1355 dev_dbg(&request->isci_host->pdev->dev,
1356 "%s: request->task->ssp_task.task_prio = %x\n",
1357 __func__,
1358 task->ssp_task.task_prio);
1359
1360 return task->ssp_task.task_prio;
1361}