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 "state_machine.h"
59 #include "remote_device.h"
60 #include "stp_request.h"
61 #include "unsolicited_frame_control.h"
62 #include "scu_completion_codes.h"
63 #include "scu_event_codes.h"
64 #include "scu_task_context.h"
67 void scic_sds_stp_request_assign_buffers(struct scic_sds_request
*sci_req
)
69 if (sci_req
->was_tag_assigned_by_user
== false)
70 sci_req
->task_context_buffer
= &sci_req
->tc
;
74 * This method is will fill in the SCU Task Context for any type of SATA
75 * request. This is called from the various SATA constructors.
76 * @sci_req: The general IO request object which is to be used in
77 * constructing the SCU task context.
78 * @task_context: The buffer pointer for the SCU task context which is being
81 * The general io request construction is complete. The buffer assignment for
82 * the command buffer is complete. none Revisit task context construction to
83 * determine what is common for SSP/SMP/STP task context structures.
85 static void scu_sata_reqeust_construct_task_context(
86 struct scic_sds_request
*sci_req
,
87 struct scu_task_context
*task_context
)
90 struct scic_sds_controller
*controller
;
91 struct scic_sds_remote_device
*target_device
;
92 struct scic_sds_port
*target_port
;
94 controller
= scic_sds_request_get_controller(sci_req
);
95 target_device
= scic_sds_request_get_device(sci_req
);
96 target_port
= scic_sds_request_get_port(sci_req
);
98 /* Fill in the TC with the its required data */
99 task_context
->abort
= 0;
100 task_context
->priority
= SCU_TASK_PRIORITY_NORMAL
;
101 task_context
->initiator_request
= 1;
102 task_context
->connection_rate
= target_device
->connection_rate
;
103 task_context
->protocol_engine_index
=
104 scic_sds_controller_get_protocol_engine_group(controller
);
105 task_context
->logical_port_index
=
106 scic_sds_port_get_index(target_port
);
107 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_STP
;
108 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
109 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
111 task_context
->remote_node_index
=
112 scic_sds_remote_device_get_index(sci_req
->target_device
);
113 task_context
->command_code
= 0;
115 task_context
->link_layer_control
= 0;
116 task_context
->do_not_dma_ssp_good_response
= 1;
117 task_context
->strict_ordering
= 0;
118 task_context
->control_frame
= 0;
119 task_context
->timeout_enable
= 0;
120 task_context
->block_guard_enable
= 0;
122 task_context
->address_modifier
= 0;
123 task_context
->task_phase
= 0x01;
125 task_context
->ssp_command_iu_length
=
126 (sizeof(struct host_to_dev_fis
) - sizeof(u32
)) / sizeof(u32
);
128 /* Set the first word of the H2D REG FIS */
129 task_context
->type
.words
[0] = *(u32
*)&sci_req
->stp
.cmd
;
131 if (sci_req
->was_tag_assigned_by_user
) {
133 * Build the task context now since we have already read
136 sci_req
->post_context
=
137 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
138 (scic_sds_controller_get_protocol_engine_group(
140 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
141 (scic_sds_port_get_index(target_port
) <<
142 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
) |
143 scic_sds_io_tag_get_index(sci_req
->io_tag
));
146 * Build the task context now since we have already read
148 * I/O tag index is not assigned because we have to wait
149 * until we get a TCi.
151 sci_req
->post_context
=
152 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
153 (scic_sds_controller_get_protocol_engine_group(
155 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
156 (scic_sds_port_get_index(target_port
) <<
157 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
));
161 * Copy the physical address for the command buffer to the SCU Task
162 * Context. We must offset the command buffer by 4 bytes because the
163 * first 4 bytes are transfered in the body of the TC.
165 dma_addr
= scic_io_request_get_dma_addr(sci_req
,
166 ((char *) &sci_req
->stp
.cmd
) +
169 task_context
->command_iu_upper
= upper_32_bits(dma_addr
);
170 task_context
->command_iu_lower
= lower_32_bits(dma_addr
);
172 /* SATA Requests do not have a response buffer */
173 task_context
->response_iu_upper
= 0;
174 task_context
->response_iu_lower
= 0;
181 * This method will perform any general sata request construction. What part of
182 * SATA IO request construction is general? none
184 static void scic_sds_stp_non_ncq_request_construct(
185 struct scic_sds_request
*sci_req
)
187 sci_req
->has_started_substate_machine
= true;
192 * @sci_req: This parameter specifies the request to be constructed as an
194 * @optimized_task_type: This parameter specifies whether the request is to be
195 * an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A
196 * value of 1 indicates NCQ.
198 * This method will perform request construction common to all types of STP
199 * requests that are optimized by the silicon (i.e. UDMA, NCQ). This method
200 * returns an indication as to whether the construction was successful.
202 static void scic_sds_stp_optimized_request_construct(struct scic_sds_request
*sci_req
,
203 u8 optimized_task_type
,
205 enum dma_data_direction dir
)
207 struct scu_task_context
*task_context
= sci_req
->task_context_buffer
;
209 /* Build the STP task context structure */
210 scu_sata_reqeust_construct_task_context(sci_req
, task_context
);
212 /* Copy over the SGL elements */
213 scic_sds_request_build_sgl(sci_req
);
215 /* Copy over the number of bytes to be transfered */
216 task_context
->transfer_length_bytes
= len
;
218 if (dir
== DMA_TO_DEVICE
) {
220 * The difference between the DMA IN and DMA OUT request task type
221 * values are consistent with the difference between FPDMA READ
222 * and FPDMA WRITE values. Add the supplied task type parameter
223 * to this difference to set the task type properly for this
224 * DATA OUT (WRITE) case. */
225 task_context
->task_type
= optimized_task_type
+ (SCU_TASK_TYPE_DMA_OUT
226 - SCU_TASK_TYPE_DMA_IN
);
229 * For the DATA IN (READ) case, simply save the supplied
230 * optimized task type. */
231 task_context
->task_type
= optimized_task_type
;
237 * @sci_req: This parameter specifies the request to be constructed.
239 * This method will construct the STP UDMA request and its associated TC data.
240 * This method returns an indication as to whether the construction was
241 * successful. SCI_SUCCESS Currently this method always returns this value.
243 enum sci_status
scic_sds_stp_ncq_request_construct(struct scic_sds_request
*sci_req
,
245 enum dma_data_direction dir
)
247 scic_sds_stp_optimized_request_construct(sci_req
,
248 SCU_TASK_TYPE_FPDMAQ_READ
,
254 * scu_stp_raw_request_construct_task_context -
255 * @sci_req: This parameter specifies the STP request object for which to
256 * construct a RAW command frame task context.
257 * @task_context: This parameter specifies the SCU specific task context buffer
260 * This method performs the operations common to all SATA/STP requests
261 * utilizing the raw frame method. none
263 static void scu_stp_raw_request_construct_task_context(
264 struct scic_sds_stp_request
*stp_req
,
265 struct scu_task_context
*task_context
)
267 struct scic_sds_request
*sci_req
= to_sci_req(stp_req
);
269 scu_sata_reqeust_construct_task_context(sci_req
, task_context
);
271 task_context
->control_frame
= 0;
272 task_context
->priority
= SCU_TASK_PRIORITY_NORMAL
;
273 task_context
->task_type
= SCU_TASK_TYPE_SATA_RAW_FRAME
;
274 task_context
->type
.stp
.fis_type
= FIS_REGH2D
;
275 task_context
->transfer_length_bytes
= sizeof(struct host_to_dev_fis
) - sizeof(u32
);
278 void scic_stp_io_request_set_ncq_tag(
279 struct scic_sds_request
*req
,
283 * @note This could be made to return an error to the user if the user
284 * attempts to set the NCQ tag in the wrong state.
286 req
->task_context_buffer
->type
.stp
.ncq_tag
= ncq_tag
;
293 * Get the next SGL element from the request. - Check on which SGL element pair
294 * we are working - if working on SLG pair element A - advance to element B -
295 * else - check to see if there are more SGL element pairs for this IO request
296 * - if there are more SGL element pairs - advance to the next pair and return
297 * element A struct scu_sgl_element*
299 static struct scu_sgl_element
*scic_sds_stp_request_pio_get_next_sgl(struct scic_sds_stp_request
*stp_req
)
301 struct scu_sgl_element
*current_sgl
;
302 struct scic_sds_request
*sci_req
= to_sci_req(stp_req
);
303 struct scic_sds_request_pio_sgl
*pio_sgl
= &stp_req
->type
.pio
.request_current
;
305 if (pio_sgl
->sgl_set
== SCU_SGL_ELEMENT_PAIR_A
) {
306 if (pio_sgl
->sgl_pair
->B
.address_lower
== 0 &&
307 pio_sgl
->sgl_pair
->B
.address_upper
== 0) {
310 pio_sgl
->sgl_set
= SCU_SGL_ELEMENT_PAIR_B
;
311 current_sgl
= &pio_sgl
->sgl_pair
->B
;
314 if (pio_sgl
->sgl_pair
->next_pair_lower
== 0 &&
315 pio_sgl
->sgl_pair
->next_pair_upper
== 0) {
320 phys_addr
= pio_sgl
->sgl_pair
->next_pair_upper
;
322 phys_addr
|= pio_sgl
->sgl_pair
->next_pair_lower
;
324 pio_sgl
->sgl_pair
= scic_request_get_virt_addr(sci_req
, phys_addr
);
325 pio_sgl
->sgl_set
= SCU_SGL_ELEMENT_PAIR_A
;
326 current_sgl
= &pio_sgl
->sgl_pair
->A
;
338 * This method processes a TC completion. The expected TC completion is for
339 * the transmission of the H2D register FIS containing the SATA/STP non-data
340 * request. This method always successfully processes the TC completion.
341 * SCI_SUCCESS This value is always returned.
343 static enum sci_status
scic_sds_stp_request_non_data_await_h2d_tc_completion_handler(
344 struct scic_sds_request
*sci_req
,
347 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
348 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
349 scic_sds_request_set_status(
350 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
353 sci_base_state_machine_change_state(
354 &sci_req
->started_substate_machine
,
355 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
361 * All other completion status cause the IO to be complete. If a NAK
362 * was received, then it is up to the user to retry the request. */
363 scic_sds_request_set_status(
365 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
366 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
369 sci_base_state_machine_change_state(
370 &sci_req
->state_machine
, SCI_BASE_REQUEST_STATE_COMPLETED
);
379 * @request: This parameter specifies the request for which a frame has been
381 * @frame_index: This parameter specifies the index of the frame that has been
384 * This method processes frames received from the target while waiting for a
385 * device to host register FIS. If a non-register FIS is received during this
386 * time, it is treated as a protocol violation from an IO perspective. Indicate
387 * if the received frame was processed successfully.
389 static enum sci_status
scic_sds_stp_request_non_data_await_d2h_frame_handler(
390 struct scic_sds_request
*sci_req
,
393 enum sci_status status
;
394 struct dev_to_host_fis
*frame_header
;
396 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
397 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
399 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
401 (void **)&frame_header
);
403 if (status
!= SCI_SUCCESS
) {
404 dev_err(scic_to_dev(sci_req
->owning_controller
),
405 "%s: SCIC IO Request 0x%p could not get frame header "
406 "for frame index %d, status %x\n",
407 __func__
, stp_req
, frame_index
, status
);
412 switch (frame_header
->fis_type
) {
414 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
416 (void **)&frame_buffer
);
418 scic_sds_controller_copy_sata_response(&sci_req
->stp
.rsp
,
422 /* The command has completed with error */
423 scic_sds_request_set_status(sci_req
, SCU_TASK_DONE_CHECK_RESPONSE
,
424 SCI_FAILURE_IO_RESPONSE_VALID
);
428 dev_warn(scic_to_dev(scic
),
429 "%s: IO Request:0x%p Frame Id:%d protocol "
430 "violation occurred\n", __func__
, stp_req
,
433 scic_sds_request_set_status(sci_req
, SCU_TASK_DONE_UNEXP_FIS
,
434 SCI_FAILURE_PROTOCOL_VIOLATION
);
438 sci_base_state_machine_change_state(&sci_req
->state_machine
,
439 SCI_BASE_REQUEST_STATE_COMPLETED
);
441 /* Frame has been decoded return it to the controller */
442 scic_sds_controller_release_frame(scic
, frame_index
);
447 /* --------------------------------------------------------------------------- */
449 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_non_data_substate_handler_table
[] = {
450 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
] = {
451 .abort_handler
= scic_sds_request_started_state_abort_handler
,
452 .tc_completion_handler
= scic_sds_stp_request_non_data_await_h2d_tc_completion_handler
,
454 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
] = {
455 .abort_handler
= scic_sds_request_started_state_abort_handler
,
456 .frame_handler
= scic_sds_stp_request_non_data_await_d2h_frame_handler
,
460 static void scic_sds_stp_request_started_non_data_await_h2d_completion_enter(
463 struct scic_sds_request
*sci_req
= object
;
467 scic_sds_stp_request_started_non_data_substate_handler_table
,
468 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
471 scic_sds_remote_device_set_working_request(
472 sci_req
->target_device
, sci_req
476 static void scic_sds_stp_request_started_non_data_await_d2h_enter(void *object
)
478 struct scic_sds_request
*sci_req
= object
;
482 scic_sds_stp_request_started_non_data_substate_handler_table
,
483 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
487 /* --------------------------------------------------------------------------- */
489 static const struct sci_base_state scic_sds_stp_request_started_non_data_substate_table
[] = {
490 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
] = {
491 .enter_state
= scic_sds_stp_request_started_non_data_await_h2d_completion_enter
,
493 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
] = {
494 .enter_state
= scic_sds_stp_request_started_non_data_await_d2h_enter
,
498 enum sci_status
scic_sds_stp_non_data_request_construct(struct scic_sds_request
*sci_req
)
500 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
502 scic_sds_stp_non_ncq_request_construct(sci_req
);
504 /* Build the STP task context structure */
505 scu_stp_raw_request_construct_task_context(stp_req
, sci_req
->task_context_buffer
);
507 sci_base_state_machine_construct(&sci_req
->started_substate_machine
,
509 scic_sds_stp_request_started_non_data_substate_table
,
510 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
);
515 #define SCU_MAX_FRAME_BUFFER_SIZE 0x400 /* 1K is the maximum SCU frame data payload */
517 /* transmit DATA_FIS from (current sgl + offset) for input
518 * parameter length. current sgl and offset is alreay stored in the IO request
520 static enum sci_status
scic_sds_stp_request_pio_data_out_trasmit_data_frame(
521 struct scic_sds_request
*sci_req
,
524 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
525 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
526 struct scu_task_context
*task_context
;
527 struct scu_sgl_element
*current_sgl
;
529 /* Recycle the TC and reconstruct it for sending out DATA FIS containing
530 * for the data from current_sgl+offset for the input length
532 task_context
= scic_sds_controller_get_task_context_buffer(scic
,
535 if (stp_req
->type
.pio
.request_current
.sgl_set
== SCU_SGL_ELEMENT_PAIR_A
)
536 current_sgl
= &stp_req
->type
.pio
.request_current
.sgl_pair
->A
;
538 current_sgl
= &stp_req
->type
.pio
.request_current
.sgl_pair
->B
;
541 task_context
->command_iu_upper
= current_sgl
->address_upper
;
542 task_context
->command_iu_lower
= current_sgl
->address_lower
;
543 task_context
->transfer_length_bytes
= length
;
544 task_context
->type
.stp
.fis_type
= FIS_DATA
;
546 /* send the new TC out. */
547 return scic_controller_continue_io(sci_req
);
550 static enum sci_status
scic_sds_stp_request_pio_data_out_transmit_data(struct scic_sds_request
*sci_req
)
553 struct scu_sgl_element
*current_sgl
;
555 u32 remaining_bytes_in_current_sgl
= 0;
556 enum sci_status status
= SCI_SUCCESS
;
557 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
559 sgl_offset
= stp_req
->type
.pio
.request_current
.sgl_offset
;
561 if (stp_req
->type
.pio
.request_current
.sgl_set
== SCU_SGL_ELEMENT_PAIR_A
) {
562 current_sgl
= &(stp_req
->type
.pio
.request_current
.sgl_pair
->A
);
563 remaining_bytes_in_current_sgl
= stp_req
->type
.pio
.request_current
.sgl_pair
->A
.length
- sgl_offset
;
565 current_sgl
= &(stp_req
->type
.pio
.request_current
.sgl_pair
->B
);
566 remaining_bytes_in_current_sgl
= stp_req
->type
.pio
.request_current
.sgl_pair
->B
.length
- sgl_offset
;
570 if (stp_req
->type
.pio
.pio_transfer_bytes
> 0) {
571 if (stp_req
->type
.pio
.pio_transfer_bytes
>= remaining_bytes_in_current_sgl
) {
572 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = remaining_bytes_in_current_sgl */
573 status
= scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req
, remaining_bytes_in_current_sgl
);
574 if (status
== SCI_SUCCESS
) {
575 stp_req
->type
.pio
.pio_transfer_bytes
-= remaining_bytes_in_current_sgl
;
577 /* update the current sgl, sgl_offset and save for future */
578 current_sgl
= scic_sds_stp_request_pio_get_next_sgl(stp_req
);
581 } else if (stp_req
->type
.pio
.pio_transfer_bytes
< remaining_bytes_in_current_sgl
) {
582 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = type.pio.pio_transfer_bytes */
583 scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req
, stp_req
->type
.pio
.pio_transfer_bytes
);
585 if (status
== SCI_SUCCESS
) {
586 /* Sgl offset will be adjusted and saved for future */
587 sgl_offset
+= stp_req
->type
.pio
.pio_transfer_bytes
;
588 current_sgl
->address_lower
+= stp_req
->type
.pio
.pio_transfer_bytes
;
589 stp_req
->type
.pio
.pio_transfer_bytes
= 0;
594 if (status
== SCI_SUCCESS
) {
595 stp_req
->type
.pio
.request_current
.sgl_offset
= sgl_offset
;
603 * @stp_request: The request that is used for the SGL processing.
604 * @data_buffer: The buffer of data to be copied.
605 * @length: The length of the data transfer.
607 * Copy the data from the buffer for the length specified to the IO reqeust SGL
608 * specified data region. enum sci_status
610 static enum sci_status
611 scic_sds_stp_request_pio_data_in_copy_data_buffer(struct scic_sds_stp_request
*stp_req
,
612 u8
*data_buf
, u32 len
)
614 struct scic_sds_request
*sci_req
;
615 struct isci_request
*ireq
;
618 struct sas_task
*task
;
619 struct scatterlist
*sg
;
623 sci_req
= to_sci_req(stp_req
);
624 ireq
= sci_req_to_ireq(sci_req
);
625 task
= isci_request_access_task(ireq
);
628 if (task
->num_scatter
> 0) {
631 while (total_len
> 0) {
632 struct page
*page
= sg_page(sg
);
634 copy_len
= min_t(int, total_len
, sg_dma_len(sg
));
635 kaddr
= kmap_atomic(page
, KM_IRQ0
);
636 memcpy(kaddr
+ sg
->offset
, src_addr
, copy_len
);
637 kunmap_atomic(kaddr
, KM_IRQ0
);
638 total_len
-= copy_len
;
639 src_addr
+= copy_len
;
643 BUG_ON(task
->total_xfer_len
< total_len
);
644 memcpy(task
->scatter
, src_addr
, total_len
);
652 * @sci_req: The PIO DATA IN request that is to receive the data.
653 * @data_buffer: The buffer to copy from.
655 * Copy the data buffer to the io request data region. enum sci_status
657 static enum sci_status
scic_sds_stp_request_pio_data_in_copy_data(
658 struct scic_sds_stp_request
*sci_req
,
661 enum sci_status status
;
664 * If there is less than 1K remaining in the transfer request
665 * copy just the data for the transfer */
666 if (sci_req
->type
.pio
.pio_transfer_bytes
< SCU_MAX_FRAME_BUFFER_SIZE
) {
667 status
= scic_sds_stp_request_pio_data_in_copy_data_buffer(
668 sci_req
, data_buffer
, sci_req
->type
.pio
.pio_transfer_bytes
);
670 if (status
== SCI_SUCCESS
)
671 sci_req
->type
.pio
.pio_transfer_bytes
= 0;
673 /* We are transfering the whole frame so copy */
674 status
= scic_sds_stp_request_pio_data_in_copy_data_buffer(
675 sci_req
, data_buffer
, SCU_MAX_FRAME_BUFFER_SIZE
);
677 if (status
== SCI_SUCCESS
)
678 sci_req
->type
.pio
.pio_transfer_bytes
-= SCU_MAX_FRAME_BUFFER_SIZE
;
691 static enum sci_status
scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler(
692 struct scic_sds_request
*sci_req
,
695 enum sci_status status
= SCI_SUCCESS
;
697 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
698 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
699 scic_sds_request_set_status(
700 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
703 sci_base_state_machine_change_state(
704 &sci_req
->started_substate_machine
,
705 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
711 * All other completion status cause the IO to be complete. If a NAK
712 * was received, then it is up to the user to retry the request. */
713 scic_sds_request_set_status(
715 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
716 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
719 sci_base_state_machine_change_state(
720 &sci_req
->state_machine
,
721 SCI_BASE_REQUEST_STATE_COMPLETED
729 static enum sci_status
scic_sds_stp_request_pio_await_frame_frame_handler(struct scic_sds_request
*sci_req
,
732 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
733 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
734 struct isci_request
*ireq
= sci_req_to_ireq(sci_req
);
735 struct sas_task
*task
= isci_request_access_task(ireq
);
736 struct dev_to_host_fis
*frame_header
;
737 enum sci_status status
;
740 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
742 (void **)&frame_header
);
744 if (status
!= SCI_SUCCESS
) {
745 dev_err(scic_to_dev(scic
),
746 "%s: SCIC IO Request 0x%p could not get frame header "
747 "for frame index %d, status %x\n",
748 __func__
, stp_req
, frame_index
, status
);
752 switch (frame_header
->fis_type
) {
754 /* Get from the frame buffer the PIO Setup Data */
755 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
757 (void **)&frame_buffer
);
759 /* Get the data from the PIO Setup The SCU Hardware returns
760 * first word in the frame_header and the rest of the data is in
761 * the frame buffer so we need to back up one dword
764 /* transfer_count: first 16bits in the 4th dword */
765 stp_req
->type
.pio
.pio_transfer_bytes
= frame_buffer
[3] & 0xffff;
767 /* ending_status: 4th byte in the 3rd dword */
768 stp_req
->type
.pio
.ending_status
= (frame_buffer
[2] >> 24) & 0xff;
770 scic_sds_controller_copy_sata_response(&sci_req
->stp
.rsp
,
774 sci_req
->stp
.rsp
.status
= stp_req
->type
.pio
.ending_status
;
776 /* The next state is dependent on whether the
777 * request was PIO Data-in or Data out
779 if (task
->data_dir
== DMA_FROM_DEVICE
) {
780 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
781 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
);
782 } else if (task
->data_dir
== DMA_TO_DEVICE
) {
784 status
= scic_sds_stp_request_pio_data_out_transmit_data(sci_req
);
785 if (status
!= SCI_SUCCESS
)
787 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
788 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
);
792 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
793 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
);
796 if (frame_header
->status
& ATA_BUSY
) {
797 /* Now why is the drive sending a D2H Register FIS when
798 * it is still busy? Do nothing since we are still in
801 dev_dbg(scic_to_dev(scic
),
802 "%s: SCIC PIO Request 0x%p received "
803 "D2H Register FIS with BSY status "
804 "0x%x\n", __func__
, stp_req
,
805 frame_header
->status
);
809 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
811 (void **)&frame_buffer
);
813 scic_sds_controller_copy_sata_response(&sci_req
->stp
.req
,
817 scic_sds_request_set_status(sci_req
,
818 SCU_TASK_DONE_CHECK_RESPONSE
,
819 SCI_FAILURE_IO_RESPONSE_VALID
);
821 sci_base_state_machine_change_state(&sci_req
->state_machine
,
822 SCI_BASE_REQUEST_STATE_COMPLETED
);
825 /* FIXME: what do we do here? */
829 /* Frame is decoded return it to the controller */
830 scic_sds_controller_release_frame(scic
, frame_index
);
835 static enum sci_status
scic_sds_stp_request_pio_data_in_await_data_frame_handler(struct scic_sds_request
*sci_req
,
838 enum sci_status status
;
839 struct dev_to_host_fis
*frame_header
;
840 struct sata_fis_data
*frame_buffer
;
841 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
842 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
844 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
846 (void **)&frame_header
);
848 if (status
!= SCI_SUCCESS
) {
849 dev_err(scic_to_dev(scic
),
850 "%s: SCIC IO Request 0x%p could not get frame header "
851 "for frame index %d, status %x\n",
852 __func__
, stp_req
, frame_index
, status
);
856 if (frame_header
->fis_type
== FIS_DATA
) {
857 if (stp_req
->type
.pio
.request_current
.sgl_pair
== NULL
) {
858 sci_req
->saved_rx_frame_index
= frame_index
;
859 stp_req
->type
.pio
.pio_transfer_bytes
= 0;
861 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
863 (void **)&frame_buffer
);
865 status
= scic_sds_stp_request_pio_data_in_copy_data(stp_req
,
868 /* Frame is decoded return it to the controller */
869 scic_sds_controller_release_frame(scic
, frame_index
);
872 /* Check for the end of the transfer, are there more
873 * bytes remaining for this data transfer
875 if (status
!= SCI_SUCCESS
||
876 stp_req
->type
.pio
.pio_transfer_bytes
!= 0)
879 if ((stp_req
->type
.pio
.ending_status
& ATA_BUSY
) == 0) {
880 scic_sds_request_set_status(sci_req
,
881 SCU_TASK_DONE_CHECK_RESPONSE
,
882 SCI_FAILURE_IO_RESPONSE_VALID
);
884 sci_base_state_machine_change_state(&sci_req
->state_machine
,
885 SCI_BASE_REQUEST_STATE_COMPLETED
);
887 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
888 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
);
891 dev_err(scic_to_dev(scic
),
892 "%s: SCIC PIO Request 0x%p received frame %d "
893 "with fis type 0x%02x when expecting a data "
894 "fis.\n", __func__
, stp_req
, frame_index
,
895 frame_header
->fis_type
);
897 scic_sds_request_set_status(sci_req
,
899 SCI_FAILURE_IO_REQUIRES_SCSI_ABORT
);
901 sci_base_state_machine_change_state(&sci_req
->state_machine
,
902 SCI_BASE_REQUEST_STATE_COMPLETED
);
904 /* Frame is decoded return it to the controller */
905 scic_sds_controller_release_frame(scic
, frame_index
);
919 static enum sci_status
scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler(
921 struct scic_sds_request
*sci_req
,
924 enum sci_status status
= SCI_SUCCESS
;
925 bool all_frames_transferred
= false;
926 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
928 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
929 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
931 if (stp_req
->type
.pio
.pio_transfer_bytes
!= 0) {
932 status
= scic_sds_stp_request_pio_data_out_transmit_data(sci_req
);
933 if (status
== SCI_SUCCESS
) {
934 if (stp_req
->type
.pio
.pio_transfer_bytes
== 0)
935 all_frames_transferred
= true;
937 } else if (stp_req
->type
.pio
.pio_transfer_bytes
== 0) {
939 * this will happen if the all data is written at the
940 * first time after the pio setup fis is received
942 all_frames_transferred
= true;
945 /* all data transferred. */
946 if (all_frames_transferred
) {
948 * Change the state to SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_FRAME_SUBSTATE
949 * and wait for PIO_SETUP fis / or D2H REg fis. */
950 sci_base_state_machine_change_state(
951 &sci_req
->started_substate_machine
,
952 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
959 * All other completion status cause the IO to be complete. If a NAK
960 * was received, then it is up to the user to retry the request. */
961 scic_sds_request_set_status(
963 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
964 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
967 sci_base_state_machine_change_state(
968 &sci_req
->state_machine
,
969 SCI_BASE_REQUEST_STATE_COMPLETED
979 * @request: This is the request which is receiving the event.
980 * @event_code: This is the event code that the request on which the request is
981 * expected to take action.
983 * This method will handle any link layer events while waiting for the data
984 * frame. enum sci_status SCI_SUCCESS SCI_FAILURE
986 static enum sci_status
scic_sds_stp_request_pio_data_in_await_data_event_handler(
987 struct scic_sds_request
*request
,
990 enum sci_status status
;
992 switch (scu_get_event_specifier(event_code
)) {
993 case SCU_TASK_DONE_CRC_ERR
<< SCU_EVENT_SPECIFIC_CODE_SHIFT
:
995 * We are waiting for data and the SCU has R_ERR the data frame.
996 * Go back to waiting for the D2H Register FIS */
997 sci_base_state_machine_change_state(
998 &request
->started_substate_machine
,
999 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1002 status
= SCI_SUCCESS
;
1006 dev_err(scic_to_dev(request
->owning_controller
),
1007 "%s: SCIC PIO Request 0x%p received unexpected "
1009 __func__
, request
, event_code
);
1011 /* / @todo Should we fail the PIO request when we get an unexpected event? */
1012 status
= SCI_FAILURE
;
1019 /* --------------------------------------------------------------------------- */
1021 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_pio_substate_handler_table
[] = {
1022 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
] = {
1023 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1024 .tc_completion_handler
= scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler
,
1026 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
] = {
1027 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1028 .frame_handler
= scic_sds_stp_request_pio_await_frame_frame_handler
1030 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
] = {
1031 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1032 .event_handler
= scic_sds_stp_request_pio_data_in_await_data_event_handler
,
1033 .frame_handler
= scic_sds_stp_request_pio_data_in_await_data_frame_handler
1035 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
] = {
1036 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1037 .tc_completion_handler
= scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler
,
1041 static void scic_sds_stp_request_started_pio_await_h2d_completion_enter(
1044 struct scic_sds_request
*sci_req
= object
;
1048 scic_sds_stp_request_started_pio_substate_handler_table
,
1049 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
1052 scic_sds_remote_device_set_working_request(
1053 sci_req
->target_device
, sci_req
);
1056 static void scic_sds_stp_request_started_pio_await_frame_enter(void *object
)
1058 struct scic_sds_request
*sci_req
= object
;
1062 scic_sds_stp_request_started_pio_substate_handler_table
,
1063 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1067 static void scic_sds_stp_request_started_pio_data_in_await_data_enter(
1070 struct scic_sds_request
*sci_req
= object
;
1074 scic_sds_stp_request_started_pio_substate_handler_table
,
1075 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
1079 static void scic_sds_stp_request_started_pio_data_out_transmit_data_enter(
1082 struct scic_sds_request
*sci_req
= object
;
1086 scic_sds_stp_request_started_pio_substate_handler_table
,
1087 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
1091 /* --------------------------------------------------------------------------- */
1093 static const struct sci_base_state scic_sds_stp_request_started_pio_substate_table
[] = {
1094 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
] = {
1095 .enter_state
= scic_sds_stp_request_started_pio_await_h2d_completion_enter
,
1097 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
] = {
1098 .enter_state
= scic_sds_stp_request_started_pio_await_frame_enter
,
1100 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
] = {
1101 .enter_state
= scic_sds_stp_request_started_pio_data_in_await_data_enter
,
1103 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
] = {
1104 .enter_state
= scic_sds_stp_request_started_pio_data_out_transmit_data_enter
,
1109 scic_sds_stp_pio_request_construct(struct scic_sds_request
*sci_req
,
1112 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
1113 struct scic_sds_stp_pio_request
*pio
= &stp_req
->type
.pio
;
1115 scic_sds_stp_non_ncq_request_construct(sci_req
);
1117 scu_stp_raw_request_construct_task_context(stp_req
,
1118 sci_req
->task_context_buffer
);
1120 pio
->current_transfer_bytes
= 0;
1121 pio
->ending_error
= 0;
1122 pio
->ending_status
= 0;
1124 pio
->request_current
.sgl_offset
= 0;
1125 pio
->request_current
.sgl_set
= SCU_SGL_ELEMENT_PAIR_A
;
1127 if (copy_rx_frame
) {
1128 scic_sds_request_build_sgl(sci_req
);
1129 /* Since the IO request copy of the TC contains the same data as
1130 * the actual TC this pointer is vaild for either.
1132 pio
->request_current
.sgl_pair
= &sci_req
->task_context_buffer
->sgl_pair_ab
;
1134 /* The user does not want the data copied to the SGL buffer location */
1135 pio
->request_current
.sgl_pair
= NULL
;
1138 sci_base_state_machine_construct(&sci_req
->started_substate_machine
,
1140 scic_sds_stp_request_started_pio_substate_table
,
1141 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
);
1146 static void scic_sds_stp_request_udma_complete_request(
1147 struct scic_sds_request
*request
,
1149 enum sci_status sci_status
)
1151 scic_sds_request_set_status(request
, scu_status
, sci_status
);
1152 sci_base_state_machine_change_state(&request
->state_machine
,
1153 SCI_BASE_REQUEST_STATE_COMPLETED
);
1156 static enum sci_status
scic_sds_stp_request_udma_general_frame_handler(struct scic_sds_request
*sci_req
,
1159 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
1160 struct dev_to_host_fis
*frame_header
;
1161 enum sci_status status
;
1164 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
1166 (void **)&frame_header
);
1168 if ((status
== SCI_SUCCESS
) &&
1169 (frame_header
->fis_type
== FIS_REGD2H
)) {
1170 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
1172 (void **)&frame_buffer
);
1174 scic_sds_controller_copy_sata_response(&sci_req
->stp
.rsp
,
1179 scic_sds_controller_release_frame(scic
, frame_index
);
1184 static enum sci_status
scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler(
1185 struct scic_sds_request
*sci_req
,
1186 u32 completion_code
)
1188 enum sci_status status
= SCI_SUCCESS
;
1190 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1191 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
1192 scic_sds_stp_request_udma_complete_request(sci_req
,
1196 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS
):
1197 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR
):
1199 * We must check ther response buffer to see if the D2H Register FIS was
1200 * received before we got the TC completion. */
1201 if (sci_req
->stp
.rsp
.fis_type
== FIS_REGD2H
) {
1202 scic_sds_remote_device_suspend(sci_req
->target_device
,
1203 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code
)));
1205 scic_sds_stp_request_udma_complete_request(sci_req
,
1206 SCU_TASK_DONE_CHECK_RESPONSE
,
1207 SCI_FAILURE_IO_RESPONSE_VALID
);
1210 * If we have an error completion status for the TC then we can expect a
1211 * D2H register FIS from the device so we must change state to wait for it */
1212 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
1213 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
);
1218 * / @todo Check to see if any of these completion status need to wait for
1219 * / the device to host register fis. */
1220 /* / @todo We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR - this comes only for B0 */
1221 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN
):
1222 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR
):
1223 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR
):
1224 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR
):
1225 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR
):
1226 scic_sds_remote_device_suspend(sci_req
->target_device
,
1227 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code
)));
1228 /* Fall through to the default case */
1230 /* All other completion status cause the IO to be complete. */
1231 scic_sds_stp_request_udma_complete_request(sci_req
,
1232 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
1233 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
);
1240 static enum sci_status
scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler(
1241 struct scic_sds_request
*sci_req
,
1244 enum sci_status status
;
1246 /* Use the general frame handler to copy the resposne data */
1247 status
= scic_sds_stp_request_udma_general_frame_handler(sci_req
, frame_index
);
1249 if (status
!= SCI_SUCCESS
)
1252 scic_sds_stp_request_udma_complete_request(sci_req
,
1253 SCU_TASK_DONE_CHECK_RESPONSE
,
1254 SCI_FAILURE_IO_RESPONSE_VALID
);
1259 /* --------------------------------------------------------------------------- */
1261 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_udma_substate_handler_table
[] = {
1262 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
] = {
1263 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1264 .tc_completion_handler
= scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler
,
1265 .frame_handler
= scic_sds_stp_request_udma_general_frame_handler
,
1267 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
] = {
1268 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1269 .frame_handler
= scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler
,
1273 static void scic_sds_stp_request_started_udma_await_tc_completion_enter(
1276 struct scic_sds_request
*sci_req
= object
;
1280 scic_sds_stp_request_started_udma_substate_handler_table
,
1281 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
1288 * This state is entered when there is an TC completion failure. The hardware
1289 * received an unexpected condition while processing the IO request and now
1290 * will UF the D2H register FIS to complete the IO.
1292 static void scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter(
1295 struct scic_sds_request
*sci_req
= object
;
1299 scic_sds_stp_request_started_udma_substate_handler_table
,
1300 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
1304 /* --------------------------------------------------------------------------- */
1306 static const struct sci_base_state scic_sds_stp_request_started_udma_substate_table
[] = {
1307 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
] = {
1308 .enter_state
= scic_sds_stp_request_started_udma_await_tc_completion_enter
,
1310 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
] = {
1311 .enter_state
= scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter
,
1315 enum sci_status
scic_sds_stp_udma_request_construct(struct scic_sds_request
*sci_req
,
1317 enum dma_data_direction dir
)
1319 scic_sds_stp_non_ncq_request_construct(sci_req
);
1321 scic_sds_stp_optimized_request_construct(sci_req
, SCU_TASK_TYPE_DMA_IN
,
1324 sci_base_state_machine_construct(
1325 &sci_req
->started_substate_machine
,
1327 scic_sds_stp_request_started_udma_substate_table
,
1328 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
1339 * This method processes a TC completion. The expected TC completion is for
1340 * the transmission of the H2D register FIS containing the SATA/STP non-data
1341 * request. This method always successfully processes the TC completion.
1342 * SCI_SUCCESS This value is always returned.
1344 static enum sci_status
scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler(
1345 struct scic_sds_request
*sci_req
,
1346 u32 completion_code
)
1348 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1349 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
1350 scic_sds_request_set_status(
1351 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
1354 sci_base_state_machine_change_state(
1355 &sci_req
->started_substate_machine
,
1356 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
1362 * All other completion status cause the IO to be complete. If a NAK
1363 * was received, then it is up to the user to retry the request. */
1364 scic_sds_request_set_status(
1366 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
1367 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1370 sci_base_state_machine_change_state(
1371 &sci_req
->state_machine
, SCI_BASE_REQUEST_STATE_COMPLETED
);
1383 * This method processes a TC completion. The expected TC completion is for
1384 * the transmission of the H2D register FIS containing the SATA/STP non-data
1385 * request. This method always successfully processes the TC completion.
1386 * SCI_SUCCESS This value is always returned.
1388 static enum sci_status
scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler(
1389 struct scic_sds_request
*sci_req
,
1390 u32 completion_code
)
1392 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1393 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
1394 scic_sds_request_set_status(
1395 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
1398 sci_base_state_machine_change_state(
1399 &sci_req
->started_substate_machine
,
1400 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
1406 * All other completion status cause the IO to be complete. If a NAK
1407 * was received, then it is up to the user to retry the request. */
1408 scic_sds_request_set_status(
1410 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
1411 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1414 sci_base_state_machine_change_state(&sci_req
->state_machine
,
1415 SCI_BASE_REQUEST_STATE_COMPLETED
);
1424 * @request: This parameter specifies the request for which a frame has been
1426 * @frame_index: This parameter specifies the index of the frame that has been
1429 * This method processes frames received from the target while waiting for a
1430 * device to host register FIS. If a non-register FIS is received during this
1431 * time, it is treated as a protocol violation from an IO perspective. Indicate
1432 * if the received frame was processed successfully.
1434 static enum sci_status
scic_sds_stp_request_soft_reset_await_d2h_frame_handler(
1435 struct scic_sds_request
*sci_req
,
1438 enum sci_status status
;
1439 struct dev_to_host_fis
*frame_header
;
1441 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
1442 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
1444 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
1446 (void **)&frame_header
);
1447 if (status
!= SCI_SUCCESS
) {
1448 dev_err(scic_to_dev(scic
),
1449 "%s: SCIC IO Request 0x%p could not get frame header "
1450 "for frame index %d, status %x\n",
1451 __func__
, stp_req
, frame_index
, status
);
1455 switch (frame_header
->fis_type
) {
1457 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
1459 (void **)&frame_buffer
);
1461 scic_sds_controller_copy_sata_response(&sci_req
->stp
.rsp
,
1465 /* The command has completed with error */
1466 scic_sds_request_set_status(sci_req
,
1467 SCU_TASK_DONE_CHECK_RESPONSE
,
1468 SCI_FAILURE_IO_RESPONSE_VALID
);
1472 dev_warn(scic_to_dev(scic
),
1473 "%s: IO Request:0x%p Frame Id:%d protocol "
1474 "violation occurred\n", __func__
, stp_req
,
1477 scic_sds_request_set_status(sci_req
, SCU_TASK_DONE_UNEXP_FIS
,
1478 SCI_FAILURE_PROTOCOL_VIOLATION
);
1482 sci_base_state_machine_change_state(&sci_req
->state_machine
,
1483 SCI_BASE_REQUEST_STATE_COMPLETED
);
1485 /* Frame has been decoded return it to the controller */
1486 scic_sds_controller_release_frame(scic
, frame_index
);
1491 /* --------------------------------------------------------------------------- */
1493 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_soft_reset_substate_handler_table
[] = {
1494 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
] = {
1495 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1496 .tc_completion_handler
= scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler
,
1498 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
] = {
1499 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1500 .tc_completion_handler
= scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler
,
1502 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
] = {
1503 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1504 .frame_handler
= scic_sds_stp_request_soft_reset_await_d2h_frame_handler
,
1508 static void scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter(
1511 struct scic_sds_request
*sci_req
= object
;
1515 scic_sds_stp_request_started_soft_reset_substate_handler_table
,
1516 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
1519 scic_sds_remote_device_set_working_request(
1520 sci_req
->target_device
, sci_req
1524 static void scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter(
1527 struct scic_sds_request
*sci_req
= object
;
1528 struct scu_task_context
*task_context
;
1529 struct host_to_dev_fis
*h2d_fis
;
1530 enum sci_status status
;
1532 /* Clear the SRST bit */
1533 h2d_fis
= &sci_req
->stp
.cmd
;
1534 h2d_fis
->control
= 0;
1536 /* Clear the TC control bit */
1537 task_context
= scic_sds_controller_get_task_context_buffer(
1538 sci_req
->owning_controller
, sci_req
->io_tag
);
1539 task_context
->control_frame
= 0;
1541 status
= scic_controller_continue_io(sci_req
);
1542 if (status
== SCI_SUCCESS
) {
1545 scic_sds_stp_request_started_soft_reset_substate_handler_table
,
1546 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
1551 static void scic_sds_stp_request_started_soft_reset_await_d2h_response_enter(
1554 struct scic_sds_request
*sci_req
= object
;
1558 scic_sds_stp_request_started_soft_reset_substate_handler_table
,
1559 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
1563 static const struct sci_base_state scic_sds_stp_request_started_soft_reset_substate_table
[] = {
1564 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
] = {
1565 .enter_state
= scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter
,
1567 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
] = {
1568 .enter_state
= scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter
,
1570 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
] = {
1571 .enter_state
= scic_sds_stp_request_started_soft_reset_await_d2h_response_enter
,
1575 enum sci_status
scic_sds_stp_soft_reset_request_construct(struct scic_sds_request
*sci_req
)
1577 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
1579 scic_sds_stp_non_ncq_request_construct(sci_req
);
1581 /* Build the STP task context structure */
1582 scu_stp_raw_request_construct_task_context(stp_req
, sci_req
->task_context_buffer
);
1584 sci_base_state_machine_construct(&sci_req
->started_substate_machine
,
1586 scic_sds_stp_request_started_soft_reset_substate_table
,
1587 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
);