2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 #include "intel_sas.h"
59 #include "scic_controller.h"
60 #include "scic_io_request.h"
61 #include "scic_sds_controller.h"
62 #include "scu_registers.h"
63 #include "scic_sds_port.h"
64 #include "remote_device.h"
65 #include "scic_sds_request.h"
66 #include "scic_sds_smp_request.h"
67 #include "scic_sds_stp_request.h"
68 #include "scic_sds_unsolicited_frame_control.h"
69 #include "sci_environment.h"
71 #include "scu_completion_codes.h"
72 #include "scu_constants.h"
73 #include "scu_task_context.h"
76 * ****************************************************************************
77 * * SCIC SDS IO REQUEST CONSTANTS
78 * **************************************************************************** */
83 * We have no timer requirements for IO requests right now
85 #define SCIC_SDS_IO_REQUEST_MINIMUM_TIMER_COUNT (0)
86 #define SCIC_SDS_IO_REQUEST_MAXIMUM_TIMER_COUNT (0)
89 * ****************************************************************************
90 * * SCIC SDS IO REQUEST MACROS
91 * **************************************************************************** */
94 * scic_ssp_io_request_get_object_size() -
96 * This macro returns the sizeof memory required to store the an SSP IO
97 * request. This does not include the size of the SGL or SCU Task Context
100 #define scic_ssp_io_request_get_object_size() \
102 sizeof(struct ssp_cmd_iu) \
103 + SSP_RESP_IU_MAX_SIZE \
107 * scic_sds_ssp_request_get_command_buffer() -
109 * This macro returns the address of the ssp command buffer in the io request
112 #define scic_sds_ssp_request_get_command_buffer(memory) \
113 ((struct ssp_cmd_iu *)(\
114 ((char *)(memory)) + sizeof(struct scic_sds_request) \
118 * scic_sds_ssp_request_get_response_buffer() -
120 * This macro returns the address of the ssp response buffer in the io request
123 #define scic_sds_ssp_request_get_response_buffer(memory) \
124 ((struct ssp_response_iu *)(\
125 ((char *)(scic_sds_ssp_request_get_command_buffer(memory))) \
126 + sizeof(struct ssp_cmd_iu) \
130 * scic_sds_ssp_request_get_task_context_buffer() -
132 * This macro returns the address of the task context buffer in the io request
135 #define scic_sds_ssp_request_get_task_context_buffer(memory) \
136 ((struct scu_task_context *)(\
137 ((char *)(scic_sds_ssp_request_get_response_buffer(memory))) \
138 + SSP_RESP_IU_MAX_SIZE \
142 * scic_sds_ssp_request_get_sgl_element_buffer() -
144 * This macro returns the address of the sgl elment pairs in the io request
147 #define scic_sds_ssp_request_get_sgl_element_buffer(memory) \
148 ((struct scu_sgl_element_pair *)(\
149 ((char *)(scic_sds_ssp_request_get_task_context_buffer(memory))) \
150 + sizeof(struct scu_task_context) \
155 * scic_ssp_task_request_get_object_size() -
157 * This macro returns the sizeof of memory required to store an SSP Task
158 * request. This does not include the size of the SCU Task Context memory.
160 #define scic_ssp_task_request_get_object_size() \
162 sizeof(struct ssp_task_iu) \
163 + SSP_RESP_IU_MAX_SIZE \
167 * scic_sds_ssp_task_request_get_command_buffer() -
169 * This macro returns the address of the ssp command buffer in the task request
170 * memory. Yes its the same as the above macro except for the name.
172 #define scic_sds_ssp_task_request_get_command_buffer(memory) \
173 ((struct ssp_task_iu *)(\
174 ((char *)(memory)) + sizeof(struct scic_sds_request) \
178 * scic_sds_ssp_task_request_get_response_buffer() -
180 * This macro returns the address of the ssp response buffer in the task
183 #define scic_sds_ssp_task_request_get_response_buffer(memory) \
184 ((struct ssp_response_iu *)(\
185 ((char *)(scic_sds_ssp_task_request_get_command_buffer(memory))) \
186 + sizeof(struct ssp_task_iu) \
190 * scic_sds_ssp_task_request_get_task_context_buffer() -
192 * This macro returs the task context buffer for the SSP task request.
194 #define scic_sds_ssp_task_request_get_task_context_buffer(memory) \
195 ((struct scu_task_context *)(\
196 ((char *)(scic_sds_ssp_task_request_get_response_buffer(memory))) \
197 + SSP_RESP_IU_MAX_SIZE \
203 * ****************************************************************************
204 * * SCIC SDS IO REQUEST PRIVATE METHODS
205 * **************************************************************************** */
210 * This method returns the size required to store an SSP IO request object. u32
212 static u32
scic_sds_ssp_request_get_object_size(void)
214 return sizeof(struct scic_sds_request
)
215 + scic_ssp_io_request_get_object_size()
216 + sizeof(struct scu_task_context
)
218 + sizeof(struct scu_sgl_element_pair
) * SCU_MAX_SGL_ELEMENT_PAIRS
;
222 * This method returns the sgl element pair for the specificed sgl_pair index.
223 * @sci_req: This parameter specifies the IO request for which to retrieve
224 * the Scatter-Gather List element pair.
225 * @sgl_pair_index: This parameter specifies the index into the SGL element
226 * pair to be retrieved.
228 * This method returns a pointer to an struct scu_sgl_element_pair.
230 static struct scu_sgl_element_pair
*scic_sds_request_get_sgl_element_pair(
231 struct scic_sds_request
*sci_req
,
234 struct scu_task_context
*task_context
;
236 task_context
= (struct scu_task_context
*)sci_req
->task_context_buffer
;
238 if (sgl_pair_index
== 0) {
239 return &task_context
->sgl_pair_ab
;
240 } else if (sgl_pair_index
== 1) {
241 return &task_context
->sgl_pair_cd
;
244 return &sci_req
->sgl_element_pair_buffer
[sgl_pair_index
- 2];
248 * This function will build the SGL list for an IO request.
249 * @sci_req: This parameter specifies the IO request for which to build
250 * the Scatter-Gather List.
253 void scic_sds_request_build_sgl(struct scic_sds_request
*sds_request
)
255 struct isci_request
*isci_request
= sds_request
->ireq
;
256 struct isci_host
*isci_host
= isci_request
->isci_host
;
257 struct sas_task
*task
= isci_request_access_task(isci_request
);
258 struct scatterlist
*sg
= NULL
;
261 struct scu_sgl_element_pair
*scu_sg
= NULL
;
262 struct scu_sgl_element_pair
*prev_sg
= NULL
;
264 if (task
->num_scatter
> 0) {
268 scu_sg
= scic_sds_request_get_sgl_element_pair(
272 SCU_SGL_COPY(scu_sg
->A
, sg
);
277 SCU_SGL_COPY(scu_sg
->B
, sg
);
280 SCU_SGL_ZERO(scu_sg
->B
);
284 scic_io_request_get_dma_addr(
288 prev_sg
->next_pair_upper
=
289 upper_32_bits(dma_addr
);
290 prev_sg
->next_pair_lower
=
291 lower_32_bits(dma_addr
);
297 } else { /* handle when no sg */
298 scu_sg
= scic_sds_request_get_sgl_element_pair(sds_request
,
301 dma_addr
= dma_map_single(&isci_host
->pdev
->dev
,
303 task
->total_xfer_len
,
306 isci_request
->zero_scatter_daddr
= dma_addr
;
308 scu_sg
->A
.length
= task
->total_xfer_len
;
309 scu_sg
->A
.address_upper
= upper_32_bits(dma_addr
);
310 scu_sg
->A
.address_lower
= lower_32_bits(dma_addr
);
314 scu_sg
->next_pair_upper
= 0;
315 scu_sg
->next_pair_lower
= 0;
320 * This method build the remainder of the IO request object.
321 * @sci_req: This parameter specifies the request object being constructed.
323 * The scic_sds_general_request_construct() must be called before this call is
326 static void scic_sds_ssp_io_request_assign_buffers(
327 struct scic_sds_request
*sci_req
)
329 sci_req
->command_buffer
=
330 scic_sds_ssp_request_get_command_buffer(sci_req
);
331 sci_req
->response_buffer
=
332 scic_sds_ssp_request_get_response_buffer(sci_req
);
333 sci_req
->sgl_element_pair_buffer
=
334 scic_sds_ssp_request_get_sgl_element_buffer(sci_req
);
335 sci_req
->sgl_element_pair_buffer
=
336 PTR_ALIGN(sci_req
->sgl_element_pair_buffer
,
337 sizeof(struct scu_sgl_element_pair
));
339 if (sci_req
->was_tag_assigned_by_user
== false) {
340 sci_req
->task_context_buffer
=
341 scic_sds_ssp_request_get_task_context_buffer(sci_req
);
342 sci_req
->task_context_buffer
=
343 PTR_ALIGN(sci_req
->task_context_buffer
,
348 static void scic_sds_io_request_build_ssp_command_iu(struct scic_sds_request
*sci_req
)
350 struct ssp_cmd_iu
*cmd_iu
;
351 struct isci_request
*ireq
= sci_req
->ireq
;
352 struct sas_task
*task
= isci_request_access_task(ireq
);
354 cmd_iu
= sci_req
->command_buffer
;
356 memcpy(cmd_iu
->LUN
, task
->ssp_task
.LUN
, 8);
357 cmd_iu
->add_cdb_len
= 0;
360 cmd_iu
->en_fburst
= 0; /* unsupported */
361 cmd_iu
->task_prio
= task
->ssp_task
.task_prio
;
362 cmd_iu
->task_attr
= task
->ssp_task
.task_attr
;
365 sci_swab32_cpy(&cmd_iu
->cdb
, task
->ssp_task
.cdb
,
366 sizeof(task
->ssp_task
.cdb
) / sizeof(u32
));
369 static void scic_sds_task_request_build_ssp_task_iu(struct scic_sds_request
*sci_req
)
371 struct ssp_task_iu
*task_iu
;
372 struct isci_request
*ireq
= sci_req
->ireq
;
373 struct sas_task
*task
= isci_request_access_task(ireq
);
374 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(ireq
);
376 task_iu
= sci_req
->command_buffer
;
378 memset(task_iu
, 0, sizeof(struct ssp_task_iu
));
380 memcpy(task_iu
->LUN
, task
->ssp_task
.LUN
, 8);
382 task_iu
->task_func
= isci_tmf
->tmf_code
;
384 (ireq
->ttype
== tmf_task
) ?
386 SCI_CONTROLLER_INVALID_IO_TAG
;
390 * This method is will fill in the SCU Task Context for any type of SSP request.
395 static void scu_ssp_reqeust_construct_task_context(
396 struct scic_sds_request
*sds_request
,
397 struct scu_task_context
*task_context
)
400 struct scic_sds_controller
*controller
;
401 struct scic_sds_remote_device
*target_device
;
402 struct scic_sds_port
*target_port
;
404 controller
= scic_sds_request_get_controller(sds_request
);
405 target_device
= scic_sds_request_get_device(sds_request
);
406 target_port
= scic_sds_request_get_port(sds_request
);
408 /* Fill in the TC with the its required data */
409 task_context
->abort
= 0;
410 task_context
->priority
= 0;
411 task_context
->initiator_request
= 1;
412 task_context
->connection_rate
= target_device
->connection_rate
;
413 task_context
->protocol_engine_index
=
414 scic_sds_controller_get_protocol_engine_group(controller
);
415 task_context
->logical_port_index
=
416 scic_sds_port_get_index(target_port
);
417 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
418 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
419 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
421 task_context
->remote_node_index
=
422 scic_sds_remote_device_get_index(sds_request
->target_device
);
423 task_context
->command_code
= 0;
425 task_context
->link_layer_control
= 0;
426 task_context
->do_not_dma_ssp_good_response
= 1;
427 task_context
->strict_ordering
= 0;
428 task_context
->control_frame
= 0;
429 task_context
->timeout_enable
= 0;
430 task_context
->block_guard_enable
= 0;
432 task_context
->address_modifier
= 0;
434 /* task_context->type.ssp.tag = sci_req->io_tag; */
435 task_context
->task_phase
= 0x01;
437 if (sds_request
->was_tag_assigned_by_user
) {
439 * Build the task context now since we have already read
442 sds_request
->post_context
=
443 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
444 (scic_sds_controller_get_protocol_engine_group(
446 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
447 (scic_sds_port_get_index(target_port
) <<
448 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
) |
449 scic_sds_io_tag_get_index(sds_request
->io_tag
));
452 * Build the task context now since we have already read
455 * I/O tag index is not assigned because we have to wait
458 sds_request
->post_context
=
459 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
460 (scic_sds_controller_get_protocol_engine_group(
461 owning_controller
) <<
462 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
463 (scic_sds_port_get_index(target_port
) <<
464 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
));
468 * Copy the physical address for the command buffer to the
471 dma_addr
= scic_io_request_get_dma_addr(sds_request
,
472 sds_request
->command_buffer
);
474 task_context
->command_iu_upper
= upper_32_bits(dma_addr
);
475 task_context
->command_iu_lower
= lower_32_bits(dma_addr
);
478 * Copy the physical address for the response buffer to the
481 dma_addr
= scic_io_request_get_dma_addr(sds_request
,
482 sds_request
->response_buffer
);
484 task_context
->response_iu_upper
= upper_32_bits(dma_addr
);
485 task_context
->response_iu_lower
= lower_32_bits(dma_addr
);
489 * This method is will fill in the SCU Task Context for a SSP IO request.
493 static void scu_ssp_io_request_construct_task_context(
494 struct scic_sds_request
*sci_req
,
495 enum dma_data_direction dir
,
498 struct scu_task_context
*task_context
;
500 task_context
= scic_sds_request_get_task_context(sci_req
);
502 scu_ssp_reqeust_construct_task_context(sci_req
, task_context
);
504 task_context
->ssp_command_iu_length
=
505 sizeof(struct ssp_cmd_iu
) / sizeof(u32
);
506 task_context
->type
.ssp
.frame_type
= SCI_SAS_COMMAND_FRAME
;
509 case DMA_FROM_DEVICE
:
512 task_context
->task_type
= SCU_TASK_TYPE_IOREAD
;
515 task_context
->task_type
= SCU_TASK_TYPE_IOWRITE
;
519 task_context
->transfer_length_bytes
= len
;
521 if (task_context
->transfer_length_bytes
> 0)
522 scic_sds_request_build_sgl(sci_req
);
527 * This method will fill in the remainder of the io request object for SSP Task
532 static void scic_sds_ssp_task_request_assign_buffers(
533 struct scic_sds_request
*sci_req
)
535 /* Assign all of the buffer pointers */
536 sci_req
->command_buffer
=
537 scic_sds_ssp_task_request_get_command_buffer(sci_req
);
538 sci_req
->response_buffer
=
539 scic_sds_ssp_task_request_get_response_buffer(sci_req
);
540 sci_req
->sgl_element_pair_buffer
= NULL
;
542 if (sci_req
->was_tag_assigned_by_user
== false) {
543 sci_req
->task_context_buffer
=
544 scic_sds_ssp_task_request_get_task_context_buffer(sci_req
);
545 sci_req
->task_context_buffer
=
546 PTR_ALIGN(sci_req
->task_context_buffer
, SMP_CACHE_BYTES
);
551 * This method will fill in the SCU Task Context for a SSP Task request. The
552 * following important settings are utilized: -# priority ==
553 * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued
554 * ahead of other task destined for the same Remote Node. -# task_type ==
555 * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type
556 * (i.e. non-raw frame) is being utilized to perform task management. -#
557 * control_frame == 1. This ensures that the proper endianess is set so
558 * that the bytes are transmitted in the right order for a task frame.
559 * @sci_req: This parameter specifies the task request object being
563 static void scu_ssp_task_request_construct_task_context(
564 struct scic_sds_request
*sci_req
)
566 struct scu_task_context
*task_context
;
568 task_context
= scic_sds_request_get_task_context(sci_req
);
570 scu_ssp_reqeust_construct_task_context(sci_req
, task_context
);
572 task_context
->control_frame
= 1;
573 task_context
->priority
= SCU_TASK_PRIORITY_HIGH
;
574 task_context
->task_type
= SCU_TASK_TYPE_RAW_FRAME
;
575 task_context
->transfer_length_bytes
= 0;
576 task_context
->type
.ssp
.frame_type
= SCI_SAS_TASK_FRAME
;
577 task_context
->ssp_command_iu_length
=
578 sizeof(struct ssp_task_iu
) / sizeof(u32
);
583 * This method constructs the SSP Command IU data for this ssp passthrough
584 * comand request object.
585 * @sci_req: This parameter specifies the request object for which the SSP
586 * command information unit is being built.
588 * enum sci_status, returns invalid parameter is cdb > 16
593 * This method constructs the SATA request object.
602 static enum sci_status
603 scic_io_request_construct_sata(struct scic_sds_request
*sci_req
,
605 enum dma_data_direction dir
,
608 enum sci_status status
= SCI_SUCCESS
;
609 struct isci_request
*ireq
= sci_req
->ireq
;
610 struct sas_task
*task
= isci_request_access_task(ireq
);
612 /* check for management protocols */
613 if (ireq
->ttype
== tmf_task
) {
614 struct isci_tmf
*tmf
= isci_request_access_tmf(ireq
);
616 if (tmf
->tmf_code
== isci_tmf_sata_srst_high
||
617 tmf
->tmf_code
== isci_tmf_sata_srst_low
)
618 return scic_sds_stp_soft_reset_request_construct(sci_req
);
620 dev_err(scic_to_dev(sci_req
->owning_controller
),
621 "%s: Request 0x%p received un-handled SAT "
622 "management protocol 0x%x.\n",
623 __func__
, sci_req
, tmf
->tmf_code
);
629 if (!sas_protocol_ata(task
->task_proto
)) {
630 dev_err(scic_to_dev(sci_req
->owning_controller
),
631 "%s: Non-ATA protocol in SATA path: 0x%x\n",
639 if (task
->data_dir
== DMA_NONE
)
640 return scic_sds_stp_non_data_request_construct(sci_req
);
643 if (task
->ata_task
.use_ncq
)
644 return scic_sds_stp_ncq_request_construct(sci_req
, len
, dir
);
647 if (task
->ata_task
.dma_xfer
)
648 return scic_sds_stp_udma_request_construct(sci_req
, len
, dir
);
650 return scic_sds_stp_pio_request_construct(sci_req
, copy
);
655 u32
scic_io_request_get_object_size(void)
657 u32 ssp_request_size
;
658 u32 stp_request_size
;
659 u32 smp_request_size
;
661 ssp_request_size
= scic_sds_ssp_request_get_object_size();
662 stp_request_size
= scic_sds_stp_request_get_object_size();
663 smp_request_size
= scic_sds_smp_request_get_object_size();
665 return max(ssp_request_size
, max(stp_request_size
, smp_request_size
));
668 enum sci_status
scic_io_request_construct_basic_ssp(
669 struct scic_sds_request
*sci_req
)
671 struct isci_request
*isci_request
= sci_req
->ireq
;
673 sci_req
->protocol
= SCIC_SSP_PROTOCOL
;
675 scu_ssp_io_request_construct_task_context(
677 isci_request_io_request_get_data_direction(isci_request
),
678 isci_request_io_request_get_transfer_length(isci_request
));
680 scic_sds_io_request_build_ssp_command_iu(sci_req
);
682 sci_base_state_machine_change_state(&sci_req
->state_machine
,
683 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
689 enum sci_status
scic_task_request_construct_ssp(
690 struct scic_sds_request
*sci_req
)
692 /* Construct the SSP Task SCU Task Context */
693 scu_ssp_task_request_construct_task_context(sci_req
);
695 /* Fill in the SSP Task IU */
696 scic_sds_task_request_build_ssp_task_iu(sci_req
);
698 sci_base_state_machine_change_state(&sci_req
->state_machine
,
699 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
705 enum sci_status
scic_io_request_construct_basic_sata(
706 struct scic_sds_request
*sci_req
)
708 enum sci_status status
;
709 struct scic_sds_stp_request
*stp_req
;
711 enum dma_data_direction dir
;
713 struct isci_request
*isci_request
= sci_req
->ireq
;
714 struct sas_task
*task
= isci_request_access_task(isci_request
);
716 stp_req
= container_of(sci_req
, typeof(*stp_req
), parent
);
718 sci_req
->protocol
= SCIC_STP_PROTOCOL
;
720 len
= isci_request_io_request_get_transfer_length(isci_request
);
721 dir
= isci_request_io_request_get_data_direction(isci_request
);
722 copy
= (task
->data_dir
== DMA_NONE
) ? false : true;
724 status
= scic_io_request_construct_sata(sci_req
, len
, dir
, copy
);
726 if (status
== SCI_SUCCESS
)
727 sci_base_state_machine_change_state(&sci_req
->state_machine
,
728 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
734 enum sci_status
scic_task_request_construct_sata(
735 struct scic_sds_request
*sci_req
)
737 enum sci_status status
= SCI_SUCCESS
;
738 struct isci_request
*ireq
= sci_req
->ireq
;
740 /* check for management protocols */
741 if (ireq
->ttype
== tmf_task
) {
742 struct isci_tmf
*tmf
= isci_request_access_tmf(ireq
);
744 if (tmf
->tmf_code
== isci_tmf_sata_srst_high
||
745 tmf
->tmf_code
== isci_tmf_sata_srst_low
) {
746 status
= scic_sds_stp_soft_reset_request_construct(sci_req
);
748 dev_err(scic_to_dev(sci_req
->owning_controller
),
749 "%s: Request 0x%p received un-handled SAT "
751 __func__
, sci_req
, tmf
->tmf_code
);
757 if (status
== SCI_SUCCESS
)
758 sci_base_state_machine_change_state(
759 &sci_req
->state_machine
,
760 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
766 u16
scic_io_request_get_io_tag(
767 struct scic_sds_request
*sci_req
)
769 return sci_req
->io_tag
;
773 u32
scic_request_get_controller_status(
774 struct scic_sds_request
*sci_req
)
776 return sci_req
->scu_status
;
780 void *scic_io_request_get_command_iu_address(
781 struct scic_sds_request
*sci_req
)
783 return sci_req
->command_buffer
;
787 void *scic_io_request_get_response_iu_address(
788 struct scic_sds_request
*sci_req
)
790 return sci_req
->response_buffer
;
794 #define SCU_TASK_CONTEXT_SRAM 0x200000
795 u32
scic_io_request_get_number_of_bytes_transferred(
796 struct scic_sds_request
*scic_sds_request
)
798 struct scic_sds_controller
*scic
= scic_sds_request
->owning_controller
;
801 if (readl(&scic
->smu_registers
->address_modifier
) == 0) {
802 void __iomem
*scu_reg_base
= scic
->scu_registers
;
804 * get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
805 * BAR1 is the scu_registers
806 * 0x20002C = 0x200000 + 0x2c
807 * = start of task context SRAM + offset of (type.ssp.data_offset)
808 * TCi is the io_tag of struct scic_sds_request */
809 ret_val
= readl(scu_reg_base
+
810 (SCU_TASK_CONTEXT_SRAM
+ offsetof(struct scu_task_context
, type
.ssp
.data_offset
)) +
811 ((sizeof(struct scu_task_context
)) * scic_sds_io_tag_get_index(scic_sds_request
->io_tag
)));
819 * ****************************************************************************
820 * * SCIC SDS Interface Implementation
821 * **************************************************************************** */
824 scic_sds_request_start(struct scic_sds_request
*request
)
826 if (request
->device_sequence
!=
827 scic_sds_remote_device_get_sequence(request
->target_device
))
830 if (request
->state_handlers
->start_handler
)
831 return request
->state_handlers
->start_handler(request
);
833 dev_warn(scic_to_dev(request
->owning_controller
),
834 "%s: SCIC IO Request requested to start while in wrong "
837 sci_base_state_machine_get_state(&request
->state_machine
));
839 return SCI_FAILURE_INVALID_STATE
;
843 scic_sds_io_request_terminate(struct scic_sds_request
*request
)
845 if (request
->state_handlers
->abort_handler
)
846 return request
->state_handlers
->abort_handler(request
);
848 dev_warn(scic_to_dev(request
->owning_controller
),
849 "%s: SCIC IO Request requested to abort while in wrong "
852 sci_base_state_machine_get_state(&request
->state_machine
));
854 return SCI_FAILURE_INVALID_STATE
;
858 scic_sds_io_request_complete(struct scic_sds_request
*request
)
860 if (request
->state_handlers
->complete_handler
)
861 return request
->state_handlers
->complete_handler(request
);
863 dev_warn(scic_to_dev(request
->owning_controller
),
864 "%s: SCIC IO Request requested to complete while in wrong "
867 sci_base_state_machine_get_state(&request
->state_machine
));
869 return SCI_FAILURE_INVALID_STATE
;
872 enum sci_status
scic_sds_io_request_event_handler(
873 struct scic_sds_request
*request
,
876 if (request
->state_handlers
->event_handler
)
877 return request
->state_handlers
->event_handler(request
, event_code
);
879 dev_warn(scic_to_dev(request
->owning_controller
),
880 "%s: SCIC IO Request given event code notification %x while "
881 "in wrong state %d\n",
884 sci_base_state_machine_get_state(&request
->state_machine
));
886 return SCI_FAILURE_INVALID_STATE
;
890 scic_sds_io_request_tc_completion(struct scic_sds_request
*request
, u32 completion_code
)
892 if (request
->state_machine
.current_state_id
== SCI_BASE_REQUEST_STATE_STARTED
&&
893 request
->has_started_substate_machine
== false)
894 return scic_sds_request_started_state_tc_completion_handler(request
, completion_code
);
895 else if (request
->state_handlers
->tc_completion_handler
)
896 return request
->state_handlers
->tc_completion_handler(request
, completion_code
);
898 dev_warn(scic_to_dev(request
->owning_controller
),
899 "%s: SCIC IO Request given task completion notification %x "
900 "while in wrong state %d\n",
903 sci_base_state_machine_get_state(&request
->state_machine
));
905 return SCI_FAILURE_INVALID_STATE
;
912 * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the start
913 * operation is to be executed.
914 * @frame_index: The frame index returned by the hardware for the reqeust
917 * This method invokes the core state frame handler for the
918 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
920 enum sci_status
scic_sds_io_request_frame_handler(
921 struct scic_sds_request
*request
,
924 if (request
->state_handlers
->frame_handler
)
925 return request
->state_handlers
->frame_handler(request
, frame_index
);
927 dev_warn(scic_to_dev(request
->owning_controller
),
928 "%s: SCIC IO Request given unexpected frame %x while in "
932 sci_base_state_machine_get_state(&request
->state_machine
));
934 scic_sds_controller_release_frame(request
->owning_controller
, frame_index
);
935 return SCI_FAILURE_INVALID_STATE
;
939 * This function copies response data for requests returning response data
940 * instead of sense data.
941 * @sci_req: This parameter specifies the request object for which to copy
944 void scic_sds_io_request_copy_response(struct scic_sds_request
*sci_req
)
948 struct ssp_response_iu
*ssp_response
;
949 struct isci_request
*ireq
= sci_req
->ireq
;
950 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(ireq
);
952 ssp_response
= sci_req
->response_buffer
;
954 resp_buf
= &isci_tmf
->resp
.resp_iu
;
957 SSP_RESP_IU_MAX_SIZE
,
958 be32_to_cpu(ssp_response
->response_data_len
));
960 memcpy(resp_buf
, ssp_response
->resp_data
, len
);
964 * *****************************************************************************
965 * * CONSTRUCTED STATE HANDLERS
966 * ***************************************************************************** */
969 * This method implements the action taken when a constructed
970 * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request.
971 * This method will, if necessary, allocate a TCi for the io request object and
972 * then will, if necessary, copy the constructed TC data into the actual TC
973 * buffer. If everything is successful the post context field is updated with
974 * the TCi so the controller can post the request to the hardware. enum sci_status
975 * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES
977 static enum sci_status
scic_sds_request_constructed_state_start_handler(
978 struct scic_sds_request
*request
)
980 struct scu_task_context
*task_context
;
982 if (request
->io_tag
== SCI_CONTROLLER_INVALID_IO_TAG
) {
984 scic_controller_allocate_io_tag(request
->owning_controller
);
987 /* Record the IO Tag in the request */
988 if (request
->io_tag
!= SCI_CONTROLLER_INVALID_IO_TAG
) {
989 task_context
= request
->task_context_buffer
;
991 task_context
->task_index
= scic_sds_io_tag_get_index(request
->io_tag
);
993 switch (task_context
->protocol_type
) {
994 case SCU_TASK_CONTEXT_PROTOCOL_SMP
:
995 case SCU_TASK_CONTEXT_PROTOCOL_SSP
:
997 task_context
->type
.ssp
.tag
= request
->io_tag
;
998 task_context
->type
.ssp
.target_port_transfer_tag
= 0xFFFF;
1001 case SCU_TASK_CONTEXT_PROTOCOL_STP
:
1004 * task_context->type.stp.ncq_tag = request->ncq_tag; */
1007 case SCU_TASK_CONTEXT_PROTOCOL_NONE
:
1008 /* / @todo When do we set no protocol type? */
1012 /* This should never happen since we build the IO requests */
1017 * Check to see if we need to copy the task context buffer
1018 * or have been building into the task context buffer */
1019 if (request
->was_tag_assigned_by_user
== false) {
1020 scic_sds_controller_copy_task_context(
1021 request
->owning_controller
, request
);
1024 /* Add to the post_context the io tag value */
1025 request
->post_context
|= scic_sds_io_tag_get_index(request
->io_tag
);
1027 /* Everything is good go ahead and change state */
1028 sci_base_state_machine_change_state(&request
->state_machine
,
1029 SCI_BASE_REQUEST_STATE_STARTED
);
1034 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1038 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1039 * object receives a scic_sds_request_terminate() request. Since the request
1040 * has not yet been posted to the hardware the request transitions to the
1041 * completed state. enum sci_status SCI_SUCCESS
1043 static enum sci_status
scic_sds_request_constructed_state_abort_handler(
1044 struct scic_sds_request
*request
)
1047 * This request has been terminated by the user make sure that the correct
1048 * status code is returned */
1049 scic_sds_request_set_status(request
,
1050 SCU_TASK_DONE_TASK_ABORT
,
1051 SCI_FAILURE_IO_TERMINATED
);
1053 sci_base_state_machine_change_state(&request
->state_machine
,
1054 SCI_BASE_REQUEST_STATE_COMPLETED
);
1059 * *****************************************************************************
1060 * * STARTED STATE HANDLERS
1061 * ***************************************************************************** */
1064 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1065 * object receives a scic_sds_request_terminate() request. Since the request
1066 * has been posted to the hardware the io request state is changed to the
1067 * aborting state. enum sci_status SCI_SUCCESS
1069 enum sci_status
scic_sds_request_started_state_abort_handler(
1070 struct scic_sds_request
*request
)
1072 if (request
->has_started_substate_machine
)
1073 sci_base_state_machine_stop(&request
->started_substate_machine
);
1075 sci_base_state_machine_change_state(&request
->state_machine
,
1076 SCI_BASE_REQUEST_STATE_ABORTING
);
1081 * scic_sds_request_started_state_tc_completion_handler() - This method process
1082 * TC (task context) completions for normal IO request (i.e. Task/Abort
1083 * Completions of type 0). This method will update the
1084 * SCIC_SDS_IO_REQUEST_T::status field.
1085 * @sci_req: This parameter specifies the request for which a completion
1087 * @completion_code: This parameter specifies the completion code received from
1092 scic_sds_request_started_state_tc_completion_handler(
1093 struct scic_sds_request
*sci_req
,
1094 u32 completion_code
)
1097 struct ssp_response_iu
*resp_iu
;
1100 * TODO: Any SDMA return code of other than 0 is bad
1101 * decode 0x003C0000 to determine SDMA status
1103 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1104 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
1105 scic_sds_request_set_status(sci_req
,
1110 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP
):
1113 * There are times when the SCU hardware will return an early
1114 * response because the io request specified more data than is
1115 * returned by the target device (mode pages, inquiry data,
1116 * etc.). We must check the response stats to see if this is
1117 * truly a failed request or a good request that just got
1120 struct ssp_response_iu
*resp
= sci_req
->response_buffer
;
1121 ssize_t word_cnt
= SSP_RESP_IU_MAX_SIZE
/ sizeof(u32
);
1123 sci_swab32_cpy(sci_req
->response_buffer
,
1124 sci_req
->response_buffer
,
1127 if (resp
->status
== 0) {
1128 scic_sds_request_set_status(
1131 SCI_SUCCESS_IO_DONE_EARLY
);
1133 scic_sds_request_set_status(
1135 SCU_TASK_DONE_CHECK_RESPONSE
,
1136 SCI_FAILURE_IO_RESPONSE_VALID
);
1141 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE
):
1143 ssize_t word_cnt
= SSP_RESP_IU_MAX_SIZE
/ sizeof(u32
);
1145 sci_swab32_cpy(sci_req
->response_buffer
,
1146 sci_req
->response_buffer
,
1149 scic_sds_request_set_status(sci_req
,
1150 SCU_TASK_DONE_CHECK_RESPONSE
,
1151 SCI_FAILURE_IO_RESPONSE_VALID
);
1155 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR
):
1157 * / @todo With TASK_DONE_RESP_LEN_ERR is the response frame
1158 * guaranteed to be received before this completion status is
1161 resp_iu
= sci_req
->response_buffer
;
1162 datapres
= resp_iu
->datapres
;
1164 if ((datapres
== 0x01) || (datapres
== 0x02)) {
1165 scic_sds_request_set_status(
1167 SCU_TASK_DONE_CHECK_RESPONSE
,
1168 SCI_FAILURE_IO_RESPONSE_VALID
);
1170 scic_sds_request_set_status(
1171 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
);
1174 /* only stp device gets suspended. */
1175 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO
):
1176 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR
):
1177 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR
):
1178 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR
):
1179 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR
):
1180 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN
):
1181 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR
):
1182 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP
):
1183 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS
):
1184 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR
):
1185 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR
):
1186 if (sci_req
->protocol
== SCIC_STP_PROTOCOL
) {
1187 scic_sds_request_set_status(
1189 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >>
1190 SCU_COMPLETION_TL_STATUS_SHIFT
,
1191 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
);
1193 scic_sds_request_set_status(
1195 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >>
1196 SCU_COMPLETION_TL_STATUS_SHIFT
,
1197 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
);
1201 /* both stp/ssp device gets suspended */
1202 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR
):
1203 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION
):
1204 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1
):
1205 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2
):
1206 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3
):
1207 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION
):
1208 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION
):
1209 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY
):
1210 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED
):
1211 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED
):
1212 scic_sds_request_set_status(
1214 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >>
1215 SCU_COMPLETION_TL_STATUS_SHIFT
,
1216 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
);
1219 /* neither ssp nor stp gets suspended. */
1220 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR
):
1221 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR
):
1222 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR
):
1223 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR
):
1224 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR
):
1225 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA
):
1226 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR
):
1227 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR
):
1228 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR
):
1229 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR
):
1230 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA
):
1231 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL
):
1232 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV
):
1233 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV
):
1234 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND
):
1236 scic_sds_request_set_status(
1238 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >>
1239 SCU_COMPLETION_TL_STATUS_SHIFT
,
1240 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
);
1245 * TODO: This is probably wrong for ACK/NAK timeout conditions
1248 /* In all cases we will treat this as the completion of the IO req. */
1249 sci_base_state_machine_change_state(
1250 &sci_req
->state_machine
,
1251 SCI_BASE_REQUEST_STATE_COMPLETED
);
1256 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1257 * object receives a scic_sds_request_frame_handler() request. This method
1258 * first determines the frame type received. If this is a response frame then
1259 * the response data is copied to the io request response buffer for processing
1260 * at completion time. If the frame type is not a response buffer an error is
1261 * logged. enum sci_status SCI_SUCCESS SCI_FAILURE_INVALID_PARAMETER_VALUE
1263 static enum sci_status
1264 scic_sds_request_started_state_frame_handler(struct scic_sds_request
*sci_req
,
1267 enum sci_status status
;
1269 struct ssp_frame_hdr ssp_hdr
;
1272 status
= scic_sds_unsolicited_frame_control_get_header(
1273 &(scic_sds_request_get_controller(sci_req
)->uf_control
),
1275 (void **)&frame_header
);
1277 word_cnt
= sizeof(struct ssp_frame_hdr
) / sizeof(u32
);
1278 sci_swab32_cpy(&ssp_hdr
, frame_header
, word_cnt
);
1280 if (ssp_hdr
.frame_type
== SSP_RESPONSE
) {
1281 struct ssp_response_iu
*resp_iu
;
1282 ssize_t word_cnt
= SSP_RESP_IU_MAX_SIZE
/ sizeof(u32
);
1284 status
= scic_sds_unsolicited_frame_control_get_buffer(
1285 &(scic_sds_request_get_controller(sci_req
)->uf_control
),
1289 sci_swab32_cpy(sci_req
->response_buffer
,
1292 resp_iu
= sci_req
->response_buffer
;
1294 if ((resp_iu
->datapres
== 0x01) ||
1295 (resp_iu
->datapres
== 0x02)) {
1296 scic_sds_request_set_status(
1298 SCU_TASK_DONE_CHECK_RESPONSE
,
1299 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
);
1301 scic_sds_request_set_status(
1302 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
);
1304 /* This was not a response frame why did it get forwarded? */
1305 dev_err(scic_to_dev(sci_req
->owning_controller
),
1306 "%s: SCIC IO Request 0x%p received unexpected "
1307 "frame %d type 0x%02x\n",
1311 ssp_hdr
.frame_type
);
1315 * In any case we are done with this frame buffer return it to the
1318 scic_sds_controller_release_frame(
1319 sci_req
->owning_controller
, frame_index
);
1325 * *****************************************************************************
1326 * * COMPLETED STATE HANDLERS
1327 * ***************************************************************************** */
1331 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1332 * object receives a scic_sds_request_complete() request. This method frees up
1333 * any io request resources that have been allocated and transitions the
1334 * request to its final state. Consider stopping the state machine instead of
1335 * transitioning to the final state? enum sci_status SCI_SUCCESS
1337 static enum sci_status
scic_sds_request_completed_state_complete_handler(
1338 struct scic_sds_request
*request
)
1340 if (request
->was_tag_assigned_by_user
!= true) {
1341 scic_controller_free_io_tag(
1342 request
->owning_controller
, request
->io_tag
);
1345 if (request
->saved_rx_frame_index
!= SCU_INVALID_FRAME_INDEX
) {
1346 scic_sds_controller_release_frame(
1347 request
->owning_controller
, request
->saved_rx_frame_index
);
1350 sci_base_state_machine_change_state(&request
->state_machine
,
1351 SCI_BASE_REQUEST_STATE_FINAL
);
1356 * *****************************************************************************
1357 * * ABORTING STATE HANDLERS
1358 * ***************************************************************************** */
1361 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1362 * object receives a scic_sds_request_terminate() request. This method is the
1363 * io request aborting state abort handlers. On receipt of a multiple
1364 * terminate requests the io request will transition to the completed state.
1365 * This should not happen in normal operation. enum sci_status SCI_SUCCESS
1367 static enum sci_status
scic_sds_request_aborting_state_abort_handler(
1368 struct scic_sds_request
*request
)
1370 sci_base_state_machine_change_state(&request
->state_machine
,
1371 SCI_BASE_REQUEST_STATE_COMPLETED
);
1376 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1377 * object receives a scic_sds_request_task_completion() request. This method
1378 * decodes the completion type waiting for the abort task complete
1379 * notification. When the abort task complete is received the io request
1380 * transitions to the completed state. enum sci_status SCI_SUCCESS
1382 static enum sci_status
scic_sds_request_aborting_state_tc_completion_handler(
1383 struct scic_sds_request
*sci_req
,
1384 u32 completion_code
)
1386 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1387 case (SCU_TASK_DONE_GOOD
<< SCU_COMPLETION_TL_STATUS_SHIFT
):
1388 case (SCU_TASK_DONE_TASK_ABORT
<< SCU_COMPLETION_TL_STATUS_SHIFT
):
1389 scic_sds_request_set_status(
1390 sci_req
, SCU_TASK_DONE_TASK_ABORT
, SCI_FAILURE_IO_TERMINATED
1393 sci_base_state_machine_change_state(&sci_req
->state_machine
,
1394 SCI_BASE_REQUEST_STATE_COMPLETED
);
1399 * Unless we get some strange error wait for the task abort to complete
1400 * TODO: Should there be a state change for this completion? */
1408 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1409 * object receives a scic_sds_request_frame_handler() request. This method
1410 * discards the unsolicited frame since we are waiting for the abort task
1411 * completion. enum sci_status SCI_SUCCESS
1413 static enum sci_status
scic_sds_request_aborting_state_frame_handler(
1414 struct scic_sds_request
*sci_req
,
1417 /* TODO: Is it even possible to get an unsolicited frame in the aborting state? */
1419 scic_sds_controller_release_frame(
1420 sci_req
->owning_controller
, frame_index
);
1425 static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table
[] = {
1426 [SCI_BASE_REQUEST_STATE_INITIAL
] = {
1428 [SCI_BASE_REQUEST_STATE_CONSTRUCTED
] = {
1429 .start_handler
= scic_sds_request_constructed_state_start_handler
,
1430 .abort_handler
= scic_sds_request_constructed_state_abort_handler
,
1432 [SCI_BASE_REQUEST_STATE_STARTED
] = {
1433 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1434 .tc_completion_handler
= scic_sds_request_started_state_tc_completion_handler
,
1435 .frame_handler
= scic_sds_request_started_state_frame_handler
,
1437 [SCI_BASE_REQUEST_STATE_COMPLETED
] = {
1438 .complete_handler
= scic_sds_request_completed_state_complete_handler
,
1440 [SCI_BASE_REQUEST_STATE_ABORTING
] = {
1441 .abort_handler
= scic_sds_request_aborting_state_abort_handler
,
1442 .tc_completion_handler
= scic_sds_request_aborting_state_tc_completion_handler
,
1443 .frame_handler
= scic_sds_request_aborting_state_frame_handler
,
1445 [SCI_BASE_REQUEST_STATE_FINAL
] = {
1450 * scic_sds_request_initial_state_enter() -
1451 * @object: This parameter specifies the base object for which the state
1452 * transition is occurring.
1454 * This method implements the actions taken when entering the
1455 * SCI_BASE_REQUEST_STATE_INITIAL state. This state is entered when the initial
1456 * base request is constructed. Entry into the initial state sets all handlers
1457 * for the io request object to their default handlers. none
1459 static void scic_sds_request_initial_state_enter(void *object
)
1461 struct scic_sds_request
*sci_req
= object
;
1465 scic_sds_request_state_handler_table
,
1466 SCI_BASE_REQUEST_STATE_INITIAL
1471 * scic_sds_request_constructed_state_enter() -
1472 * @object: The io request object that is to enter the constructed state.
1474 * This method implements the actions taken when entering the
1475 * SCI_BASE_REQUEST_STATE_CONSTRUCTED state. The method sets the state handlers
1476 * for the the constructed state. none
1478 static void scic_sds_request_constructed_state_enter(void *object
)
1480 struct scic_sds_request
*sci_req
= object
;
1484 scic_sds_request_state_handler_table
,
1485 SCI_BASE_REQUEST_STATE_CONSTRUCTED
1490 * scic_sds_request_started_state_enter() -
1491 * @object: This parameter specifies the base object for which the state
1492 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1494 * This method implements the actions taken when entering the
1495 * SCI_BASE_REQUEST_STATE_STARTED state. If the io request object type is a
1496 * SCSI Task request we must enter the started substate machine. none
1498 static void scic_sds_request_started_state_enter(void *object
)
1500 struct scic_sds_request
*sci_req
= object
;
1504 scic_sds_request_state_handler_table
,
1505 SCI_BASE_REQUEST_STATE_STARTED
1509 * Most of the request state machines have a started substate machine so
1510 * start its execution on the entry to the started state. */
1511 if (sci_req
->has_started_substate_machine
== true)
1512 sci_base_state_machine_start(&sci_req
->started_substate_machine
);
1516 * scic_sds_request_started_state_exit() -
1517 * @object: This parameter specifies the base object for which the state
1518 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1521 * This method implements the actions taken when exiting the
1522 * SCI_BASE_REQUEST_STATE_STARTED state. For task requests the action will be
1523 * to stop the started substate machine. none
1525 static void scic_sds_request_started_state_exit(void *object
)
1527 struct scic_sds_request
*sci_req
= object
;
1529 if (sci_req
->has_started_substate_machine
== true)
1530 sci_base_state_machine_stop(&sci_req
->started_substate_machine
);
1534 * scic_sds_request_completed_state_enter() -
1535 * @object: This parameter specifies the base object for which the state
1536 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1539 * This method implements the actions taken when entering the
1540 * SCI_BASE_REQUEST_STATE_COMPLETED state. This state is entered when the
1541 * SCIC_SDS_IO_REQUEST has completed. The method will decode the request
1542 * completion status and convert it to an enum sci_status to return in the
1543 * completion callback function. none
1545 static void scic_sds_request_completed_state_enter(void *object
)
1547 struct scic_sds_request
*sci_req
= object
;
1548 struct scic_sds_controller
*scic
=
1549 scic_sds_request_get_controller(sci_req
);
1550 struct isci_host
*ihost
= scic
->ihost
;
1551 struct isci_request
*ireq
= sci_req
->ireq
;
1553 SET_STATE_HANDLER(sci_req
,
1554 scic_sds_request_state_handler_table
,
1555 SCI_BASE_REQUEST_STATE_COMPLETED
);
1557 /* Tell the SCI_USER that the IO request is complete */
1558 if (sci_req
->is_task_management_request
== false)
1559 isci_request_io_request_complete(ihost
,
1561 sci_req
->sci_status
);
1563 isci_task_request_complete(ihost
, ireq
, sci_req
->sci_status
);
1567 * scic_sds_request_aborting_state_enter() -
1568 * @object: This parameter specifies the base object for which the state
1569 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1572 * This method implements the actions taken when entering the
1573 * SCI_BASE_REQUEST_STATE_ABORTING state. none
1575 static void scic_sds_request_aborting_state_enter(void *object
)
1577 struct scic_sds_request
*sci_req
= object
;
1579 /* Setting the abort bit in the Task Context is required by the silicon. */
1580 sci_req
->task_context_buffer
->abort
= 1;
1584 scic_sds_request_state_handler_table
,
1585 SCI_BASE_REQUEST_STATE_ABORTING
1590 * scic_sds_request_final_state_enter() -
1591 * @object: This parameter specifies the base object for which the state
1592 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1594 * This method implements the actions taken when entering the
1595 * SCI_BASE_REQUEST_STATE_FINAL state. The only action required is to put the
1596 * state handlers in place. none
1598 static void scic_sds_request_final_state_enter(void *object
)
1600 struct scic_sds_request
*sci_req
= object
;
1604 scic_sds_request_state_handler_table
,
1605 SCI_BASE_REQUEST_STATE_FINAL
1609 static const struct sci_base_state scic_sds_request_state_table
[] = {
1610 [SCI_BASE_REQUEST_STATE_INITIAL
] = {
1611 .enter_state
= scic_sds_request_initial_state_enter
,
1613 [SCI_BASE_REQUEST_STATE_CONSTRUCTED
] = {
1614 .enter_state
= scic_sds_request_constructed_state_enter
,
1616 [SCI_BASE_REQUEST_STATE_STARTED
] = {
1617 .enter_state
= scic_sds_request_started_state_enter
,
1618 .exit_state
= scic_sds_request_started_state_exit
1620 [SCI_BASE_REQUEST_STATE_COMPLETED
] = {
1621 .enter_state
= scic_sds_request_completed_state_enter
,
1623 [SCI_BASE_REQUEST_STATE_ABORTING
] = {
1624 .enter_state
= scic_sds_request_aborting_state_enter
,
1626 [SCI_BASE_REQUEST_STATE_FINAL
] = {
1627 .enter_state
= scic_sds_request_final_state_enter
,
1631 static void scic_sds_general_request_construct(struct scic_sds_controller
*scic
,
1632 struct scic_sds_remote_device
*sci_dev
,
1634 void *user_io_request_object
,
1635 struct scic_sds_request
*sci_req
)
1637 sci_base_state_machine_construct(&sci_req
->state_machine
, sci_req
,
1638 scic_sds_request_state_table
, SCI_BASE_REQUEST_STATE_INITIAL
);
1639 sci_base_state_machine_start(&sci_req
->state_machine
);
1641 sci_req
->io_tag
= io_tag
;
1642 sci_req
->user_request
= user_io_request_object
;
1643 sci_req
->owning_controller
= scic
;
1644 sci_req
->target_device
= sci_dev
;
1645 sci_req
->has_started_substate_machine
= false;
1646 sci_req
->protocol
= SCIC_NO_PROTOCOL
;
1647 sci_req
->saved_rx_frame_index
= SCU_INVALID_FRAME_INDEX
;
1648 sci_req
->device_sequence
= scic_sds_remote_device_get_sequence(sci_dev
);
1650 sci_req
->sci_status
= SCI_SUCCESS
;
1651 sci_req
->scu_status
= 0;
1652 sci_req
->post_context
= 0xFFFFFFFF;
1654 sci_req
->is_task_management_request
= false;
1656 if (io_tag
== SCI_CONTROLLER_INVALID_IO_TAG
) {
1657 sci_req
->was_tag_assigned_by_user
= false;
1658 sci_req
->task_context_buffer
= NULL
;
1660 sci_req
->was_tag_assigned_by_user
= true;
1662 sci_req
->task_context_buffer
=
1663 scic_sds_controller_get_task_context_buffer(scic
, io_tag
);
1668 scic_io_request_construct(struct scic_sds_controller
*scic
,
1669 struct scic_sds_remote_device
*sci_dev
,
1672 struct scic_sds_request
*sci_req
,
1673 struct scic_sds_request
**new_sci_req
)
1675 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1676 enum sci_status status
= SCI_SUCCESS
;
1678 /* Build the common part of the request */
1679 scic_sds_general_request_construct(scic
,
1685 if (sci_dev
->rnc
.remote_node_index
==
1686 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
)
1687 return SCI_FAILURE_INVALID_REMOTE_DEVICE
;
1689 if (dev
->dev_type
== SAS_END_DEV
)
1690 scic_sds_ssp_io_request_assign_buffers(sci_req
);
1691 else if ((dev
->dev_type
== SATA_DEV
) ||
1692 (dev
->tproto
& SAS_PROTOCOL_STP
)) {
1693 scic_sds_stp_request_assign_buffers(sci_req
);
1694 memset(sci_req
->command_buffer
,
1696 sizeof(struct host_to_dev_fis
));
1697 } else if (dev_is_expander(dev
)) {
1698 scic_sds_smp_request_assign_buffers(sci_req
);
1699 memset(sci_req
->command_buffer
, 0, sizeof(struct smp_req
));
1701 status
= SCI_FAILURE_UNSUPPORTED_PROTOCOL
;
1703 if (status
== SCI_SUCCESS
) {
1704 memset(sci_req
->task_context_buffer
,
1706 SCI_FIELD_OFFSET(struct scu_task_context
, sgl_pair_ab
));
1707 *new_sci_req
= sci_req
;
1713 enum sci_status
scic_task_request_construct(struct scic_sds_controller
*scic
,
1714 struct scic_sds_remote_device
*sci_dev
,
1716 void *user_io_request_object
,
1717 struct scic_sds_request
*sci_req
,
1718 struct scic_sds_request
**new_sci_req
)
1720 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1721 enum sci_status status
= SCI_SUCCESS
;
1723 /* Build the common part of the request */
1724 scic_sds_general_request_construct(scic
, sci_dev
, io_tag
,
1725 user_io_request_object
,
1728 if (dev
->dev_type
== SAS_END_DEV
) {
1729 scic_sds_ssp_task_request_assign_buffers(sci_req
);
1731 sci_req
->has_started_substate_machine
= true;
1733 /* Construct the started sub-state machine. */
1734 sci_base_state_machine_construct(
1735 &sci_req
->started_substate_machine
,
1737 scic_sds_io_request_started_task_mgmt_substate_table
,
1738 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
1740 } else if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))
1741 scic_sds_stp_request_assign_buffers(sci_req
);
1743 status
= SCI_FAILURE_UNSUPPORTED_PROTOCOL
;
1745 if (status
== SCI_SUCCESS
) {
1746 sci_req
->is_task_management_request
= true;
1747 memset(sci_req
->task_context_buffer
, 0, sizeof(struct scu_task_context
));
1748 *new_sci_req
= sci_req
;