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