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 "scic_io_request.h"
60 #include "remote_device.h"
61 #include "scic_sds_request.h"
62 #include "scic_sds_stp_pio_request.h"
63 #include "scic_sds_stp_request.h"
64 #include "unsolicited_frame_control.h"
66 #include "scu_completion_codes.h"
67 #include "scu_event_codes.h"
68 #include "scu_task_context.h"
71 void scic_sds_stp_request_assign_buffers(struct scic_sds_request
*sci_req
)
73 if (sci_req
->was_tag_assigned_by_user
== false)
74 sci_req
->task_context_buffer
= &sci_req
->tc
;
78 * This method is will fill in the SCU Task Context for any type of SATA
79 * request. This is called from the various SATA constructors.
80 * @sci_req: The general IO request object which is to be used in
81 * constructing the SCU task context.
82 * @task_context: The buffer pointer for the SCU task context which is being
85 * The general io request construction is complete. The buffer assignment for
86 * the command buffer is complete. none Revisit task context construction to
87 * determine what is common for SSP/SMP/STP task context structures.
89 static void scu_sata_reqeust_construct_task_context(
90 struct scic_sds_request
*sci_req
,
91 struct scu_task_context
*task_context
)
94 struct scic_sds_controller
*controller
;
95 struct scic_sds_remote_device
*target_device
;
96 struct scic_sds_port
*target_port
;
98 controller
= scic_sds_request_get_controller(sci_req
);
99 target_device
= scic_sds_request_get_device(sci_req
);
100 target_port
= scic_sds_request_get_port(sci_req
);
102 /* Fill in the TC with the its required data */
103 task_context
->abort
= 0;
104 task_context
->priority
= SCU_TASK_PRIORITY_NORMAL
;
105 task_context
->initiator_request
= 1;
106 task_context
->connection_rate
= target_device
->connection_rate
;
107 task_context
->protocol_engine_index
=
108 scic_sds_controller_get_protocol_engine_group(controller
);
109 task_context
->logical_port_index
=
110 scic_sds_port_get_index(target_port
);
111 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_STP
;
112 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
113 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
115 task_context
->remote_node_index
=
116 scic_sds_remote_device_get_index(sci_req
->target_device
);
117 task_context
->command_code
= 0;
119 task_context
->link_layer_control
= 0;
120 task_context
->do_not_dma_ssp_good_response
= 1;
121 task_context
->strict_ordering
= 0;
122 task_context
->control_frame
= 0;
123 task_context
->timeout_enable
= 0;
124 task_context
->block_guard_enable
= 0;
126 task_context
->address_modifier
= 0;
127 task_context
->task_phase
= 0x01;
129 task_context
->ssp_command_iu_length
=
130 (sizeof(struct host_to_dev_fis
) - sizeof(u32
)) / sizeof(u32
);
132 /* Set the first word of the H2D REG FIS */
133 task_context
->type
.words
[0] = *(u32
*)&sci_req
->stp
.cmd
;
135 if (sci_req
->was_tag_assigned_by_user
) {
137 * Build the task context now since we have already read
140 sci_req
->post_context
=
141 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
142 (scic_sds_controller_get_protocol_engine_group(
144 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
145 (scic_sds_port_get_index(target_port
) <<
146 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
) |
147 scic_sds_io_tag_get_index(sci_req
->io_tag
));
150 * Build the task context now since we have already read
152 * I/O tag index is not assigned because we have to wait
153 * until we get a TCi.
155 sci_req
->post_context
=
156 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
157 (scic_sds_controller_get_protocol_engine_group(
159 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
160 (scic_sds_port_get_index(target_port
) <<
161 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
));
165 * Copy the physical address for the command buffer to the SCU Task
166 * Context. We must offset the command buffer by 4 bytes because the
167 * first 4 bytes are transfered in the body of the TC.
169 dma_addr
= scic_io_request_get_dma_addr(sci_req
,
170 ((char *) &sci_req
->stp
.cmd
) +
173 task_context
->command_iu_upper
= upper_32_bits(dma_addr
);
174 task_context
->command_iu_lower
= lower_32_bits(dma_addr
);
176 /* SATA Requests do not have a response buffer */
177 task_context
->response_iu_upper
= 0;
178 task_context
->response_iu_lower
= 0;
185 * This method will perform any general sata request construction. What part of
186 * SATA IO request construction is general? none
188 static void scic_sds_stp_non_ncq_request_construct(
189 struct scic_sds_request
*sci_req
)
191 sci_req
->has_started_substate_machine
= true;
196 * @sci_req: This parameter specifies the request to be constructed as an
198 * @optimized_task_type: This parameter specifies whether the request is to be
199 * an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A
200 * value of 1 indicates NCQ.
202 * This method will perform request construction common to all types of STP
203 * requests that are optimized by the silicon (i.e. UDMA, NCQ). This method
204 * returns an indication as to whether the construction was successful.
206 static void scic_sds_stp_optimized_request_construct(struct scic_sds_request
*sci_req
,
207 u8 optimized_task_type
,
209 enum dma_data_direction dir
)
211 struct scu_task_context
*task_context
= sci_req
->task_context_buffer
;
213 /* Build the STP task context structure */
214 scu_sata_reqeust_construct_task_context(sci_req
, task_context
);
216 /* Copy over the SGL elements */
217 scic_sds_request_build_sgl(sci_req
);
219 /* Copy over the number of bytes to be transfered */
220 task_context
->transfer_length_bytes
= len
;
222 if (dir
== DMA_TO_DEVICE
) {
224 * The difference between the DMA IN and DMA OUT request task type
225 * values are consistent with the difference between FPDMA READ
226 * and FPDMA WRITE values. Add the supplied task type parameter
227 * to this difference to set the task type properly for this
228 * DATA OUT (WRITE) case. */
229 task_context
->task_type
= optimized_task_type
+ (SCU_TASK_TYPE_DMA_OUT
230 - SCU_TASK_TYPE_DMA_IN
);
233 * For the DATA IN (READ) case, simply save the supplied
234 * optimized task type. */
235 task_context
->task_type
= optimized_task_type
;
241 * @sci_req: This parameter specifies the request to be constructed.
243 * This method will construct the STP UDMA request and its associated TC data.
244 * This method returns an indication as to whether the construction was
245 * successful. SCI_SUCCESS Currently this method always returns this value.
247 enum sci_status
scic_sds_stp_ncq_request_construct(struct scic_sds_request
*sci_req
,
249 enum dma_data_direction dir
)
251 scic_sds_stp_optimized_request_construct(sci_req
,
252 SCU_TASK_TYPE_FPDMAQ_READ
,
258 * scu_stp_raw_request_construct_task_context -
259 * @sci_req: This parameter specifies the STP request object for which to
260 * construct a RAW command frame task context.
261 * @task_context: This parameter specifies the SCU specific task context buffer
264 * This method performs the operations common to all SATA/STP requests
265 * utilizing the raw frame method. none
267 static void scu_stp_raw_request_construct_task_context(
268 struct scic_sds_stp_request
*stp_req
,
269 struct scu_task_context
*task_context
)
271 struct scic_sds_request
*sci_req
= to_sci_req(stp_req
);
273 scu_sata_reqeust_construct_task_context(sci_req
, task_context
);
275 task_context
->control_frame
= 0;
276 task_context
->priority
= SCU_TASK_PRIORITY_NORMAL
;
277 task_context
->task_type
= SCU_TASK_TYPE_SATA_RAW_FRAME
;
278 task_context
->type
.stp
.fis_type
= FIS_REGH2D
;
279 task_context
->transfer_length_bytes
= sizeof(struct host_to_dev_fis
) - sizeof(u32
);
282 void scic_stp_io_request_set_ncq_tag(
283 struct scic_sds_request
*req
,
287 * @note This could be made to return an error to the user if the user
288 * attempts to set the NCQ tag in the wrong state.
290 req
->task_context_buffer
->type
.stp
.ncq_tag
= ncq_tag
;
297 * Get the next SGL element from the request. - Check on which SGL element pair
298 * we are working - if working on SLG pair element A - advance to element B -
299 * else - check to see if there are more SGL element pairs for this IO request
300 * - if there are more SGL element pairs - advance to the next pair and return
301 * element A struct scu_sgl_element*
303 static struct scu_sgl_element
*scic_sds_stp_request_pio_get_next_sgl(struct scic_sds_stp_request
*stp_req
)
305 struct scu_sgl_element
*current_sgl
;
306 struct scic_sds_request
*sci_req
= to_sci_req(stp_req
);
307 struct scic_sds_request_pio_sgl
*pio_sgl
= &stp_req
->type
.pio
.request_current
;
309 if (pio_sgl
->sgl_set
== SCU_SGL_ELEMENT_PAIR_A
) {
310 if (pio_sgl
->sgl_pair
->B
.address_lower
== 0 &&
311 pio_sgl
->sgl_pair
->B
.address_upper
== 0) {
314 pio_sgl
->sgl_set
= SCU_SGL_ELEMENT_PAIR_B
;
315 current_sgl
= &pio_sgl
->sgl_pair
->B
;
318 if (pio_sgl
->sgl_pair
->next_pair_lower
== 0 &&
319 pio_sgl
->sgl_pair
->next_pair_upper
== 0) {
324 phys_addr
= pio_sgl
->sgl_pair
->next_pair_upper
;
326 phys_addr
|= pio_sgl
->sgl_pair
->next_pair_lower
;
328 pio_sgl
->sgl_pair
= scic_request_get_virt_addr(sci_req
, phys_addr
);
329 pio_sgl
->sgl_set
= SCU_SGL_ELEMENT_PAIR_A
;
330 current_sgl
= &pio_sgl
->sgl_pair
->A
;
342 * This method processes a TC completion. The expected TC completion is for
343 * the transmission of the H2D register FIS containing the SATA/STP non-data
344 * request. This method always successfully processes the TC completion.
345 * SCI_SUCCESS This value is always returned.
347 static enum sci_status
scic_sds_stp_request_non_data_await_h2d_tc_completion_handler(
348 struct scic_sds_request
*sci_req
,
351 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
352 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
353 scic_sds_request_set_status(
354 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
357 sci_base_state_machine_change_state(
358 &sci_req
->started_substate_machine
,
359 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
365 * All other completion status cause the IO to be complete. If a NAK
366 * was received, then it is up to the user to retry the request. */
367 scic_sds_request_set_status(
369 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
370 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
373 sci_base_state_machine_change_state(
374 &sci_req
->state_machine
, SCI_BASE_REQUEST_STATE_COMPLETED
);
383 * @request: This parameter specifies the request for which a frame has been
385 * @frame_index: This parameter specifies the index of the frame that has been
388 * This method processes frames received from the target while waiting for a
389 * device to host register FIS. If a non-register FIS is received during this
390 * time, it is treated as a protocol violation from an IO perspective. Indicate
391 * if the received frame was processed successfully.
393 static enum sci_status
scic_sds_stp_request_non_data_await_d2h_frame_handler(
394 struct scic_sds_request
*sci_req
,
397 enum sci_status status
;
398 struct dev_to_host_fis
*frame_header
;
400 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
401 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
403 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
405 (void **)&frame_header
);
407 if (status
!= SCI_SUCCESS
) {
408 dev_err(scic_to_dev(sci_req
->owning_controller
),
409 "%s: SCIC IO Request 0x%p could not get frame header "
410 "for frame index %d, status %x\n",
411 __func__
, stp_req
, frame_index
, status
);
416 switch (frame_header
->fis_type
) {
418 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
420 (void **)&frame_buffer
);
422 scic_sds_controller_copy_sata_response(&sci_req
->stp
.rsp
,
426 /* The command has completed with error */
427 scic_sds_request_set_status(sci_req
, SCU_TASK_DONE_CHECK_RESPONSE
,
428 SCI_FAILURE_IO_RESPONSE_VALID
);
432 dev_warn(scic_to_dev(scic
),
433 "%s: IO Request:0x%p Frame Id:%d protocol "
434 "violation occurred\n", __func__
, stp_req
,
437 scic_sds_request_set_status(sci_req
, SCU_TASK_DONE_UNEXP_FIS
,
438 SCI_FAILURE_PROTOCOL_VIOLATION
);
442 sci_base_state_machine_change_state(&sci_req
->state_machine
,
443 SCI_BASE_REQUEST_STATE_COMPLETED
);
445 /* Frame has been decoded return it to the controller */
446 scic_sds_controller_release_frame(scic
, frame_index
);
451 /* --------------------------------------------------------------------------- */
453 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_non_data_substate_handler_table
[] = {
454 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
] = {
455 .abort_handler
= scic_sds_request_started_state_abort_handler
,
456 .tc_completion_handler
= scic_sds_stp_request_non_data_await_h2d_tc_completion_handler
,
458 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
] = {
459 .abort_handler
= scic_sds_request_started_state_abort_handler
,
460 .frame_handler
= scic_sds_stp_request_non_data_await_d2h_frame_handler
,
464 static void scic_sds_stp_request_started_non_data_await_h2d_completion_enter(
467 struct scic_sds_request
*sci_req
= object
;
471 scic_sds_stp_request_started_non_data_substate_handler_table
,
472 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
475 scic_sds_remote_device_set_working_request(
476 sci_req
->target_device
, sci_req
480 static void scic_sds_stp_request_started_non_data_await_d2h_enter(void *object
)
482 struct scic_sds_request
*sci_req
= object
;
486 scic_sds_stp_request_started_non_data_substate_handler_table
,
487 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
491 /* --------------------------------------------------------------------------- */
493 static const struct sci_base_state scic_sds_stp_request_started_non_data_substate_table
[] = {
494 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
] = {
495 .enter_state
= scic_sds_stp_request_started_non_data_await_h2d_completion_enter
,
497 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
] = {
498 .enter_state
= scic_sds_stp_request_started_non_data_await_d2h_enter
,
502 enum sci_status
scic_sds_stp_non_data_request_construct(struct scic_sds_request
*sci_req
)
504 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
506 scic_sds_stp_non_ncq_request_construct(sci_req
);
508 /* Build the STP task context structure */
509 scu_stp_raw_request_construct_task_context(stp_req
, sci_req
->task_context_buffer
);
511 sci_base_state_machine_construct(&sci_req
->started_substate_machine
,
513 scic_sds_stp_request_started_non_data_substate_table
,
514 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
);
519 #define SCU_MAX_FRAME_BUFFER_SIZE 0x400 /* 1K is the maximum SCU frame data payload */
521 /* transmit DATA_FIS from (current sgl + offset) for input
522 * parameter length. current sgl and offset is alreay stored in the IO request
524 static enum sci_status
scic_sds_stp_request_pio_data_out_trasmit_data_frame(
525 struct scic_sds_request
*sci_req
,
528 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
529 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
530 struct scu_task_context
*task_context
;
531 struct scu_sgl_element
*current_sgl
;
533 /* Recycle the TC and reconstruct it for sending out DATA FIS containing
534 * for the data from current_sgl+offset for the input length
536 task_context
= scic_sds_controller_get_task_context_buffer(scic
,
539 if (stp_req
->type
.pio
.request_current
.sgl_set
== SCU_SGL_ELEMENT_PAIR_A
)
540 current_sgl
= &stp_req
->type
.pio
.request_current
.sgl_pair
->A
;
542 current_sgl
= &stp_req
->type
.pio
.request_current
.sgl_pair
->B
;
545 task_context
->command_iu_upper
= current_sgl
->address_upper
;
546 task_context
->command_iu_lower
= current_sgl
->address_lower
;
547 task_context
->transfer_length_bytes
= length
;
548 task_context
->type
.stp
.fis_type
= FIS_DATA
;
550 /* send the new TC out. */
551 return scic_controller_continue_io(sci_req
);
554 static enum sci_status
scic_sds_stp_request_pio_data_out_transmit_data(struct scic_sds_request
*sci_req
)
557 struct scu_sgl_element
*current_sgl
;
559 u32 remaining_bytes_in_current_sgl
= 0;
560 enum sci_status status
= SCI_SUCCESS
;
561 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
563 sgl_offset
= stp_req
->type
.pio
.request_current
.sgl_offset
;
565 if (stp_req
->type
.pio
.request_current
.sgl_set
== SCU_SGL_ELEMENT_PAIR_A
) {
566 current_sgl
= &(stp_req
->type
.pio
.request_current
.sgl_pair
->A
);
567 remaining_bytes_in_current_sgl
= stp_req
->type
.pio
.request_current
.sgl_pair
->A
.length
- sgl_offset
;
569 current_sgl
= &(stp_req
->type
.pio
.request_current
.sgl_pair
->B
);
570 remaining_bytes_in_current_sgl
= stp_req
->type
.pio
.request_current
.sgl_pair
->B
.length
- sgl_offset
;
574 if (stp_req
->type
.pio
.pio_transfer_bytes
> 0) {
575 if (stp_req
->type
.pio
.pio_transfer_bytes
>= remaining_bytes_in_current_sgl
) {
576 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = remaining_bytes_in_current_sgl */
577 status
= scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req
, remaining_bytes_in_current_sgl
);
578 if (status
== SCI_SUCCESS
) {
579 stp_req
->type
.pio
.pio_transfer_bytes
-= remaining_bytes_in_current_sgl
;
581 /* update the current sgl, sgl_offset and save for future */
582 current_sgl
= scic_sds_stp_request_pio_get_next_sgl(stp_req
);
585 } else if (stp_req
->type
.pio
.pio_transfer_bytes
< remaining_bytes_in_current_sgl
) {
586 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = type.pio.pio_transfer_bytes */
587 scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req
, stp_req
->type
.pio
.pio_transfer_bytes
);
589 if (status
== SCI_SUCCESS
) {
590 /* Sgl offset will be adjusted and saved for future */
591 sgl_offset
+= stp_req
->type
.pio
.pio_transfer_bytes
;
592 current_sgl
->address_lower
+= stp_req
->type
.pio
.pio_transfer_bytes
;
593 stp_req
->type
.pio
.pio_transfer_bytes
= 0;
598 if (status
== SCI_SUCCESS
) {
599 stp_req
->type
.pio
.request_current
.sgl_offset
= sgl_offset
;
607 * @stp_request: The request that is used for the SGL processing.
608 * @data_buffer: The buffer of data to be copied.
609 * @length: The length of the data transfer.
611 * Copy the data from the buffer for the length specified to the IO reqeust SGL
612 * specified data region. enum sci_status
614 static enum sci_status
615 scic_sds_stp_request_pio_data_in_copy_data_buffer(struct scic_sds_stp_request
*stp_req
,
616 u8
*data_buf
, u32 len
)
618 struct scic_sds_request
*sci_req
;
619 struct isci_request
*ireq
;
622 struct sas_task
*task
;
623 struct scatterlist
*sg
;
627 sci_req
= to_sci_req(stp_req
);
628 ireq
= sci_req_to_ireq(sci_req
);
629 task
= isci_request_access_task(ireq
);
632 if (task
->num_scatter
> 0) {
635 while (total_len
> 0) {
636 struct page
*page
= sg_page(sg
);
638 copy_len
= min_t(int, total_len
, sg_dma_len(sg
));
639 kaddr
= kmap_atomic(page
, KM_IRQ0
);
640 memcpy(kaddr
+ sg
->offset
, src_addr
, copy_len
);
641 kunmap_atomic(kaddr
, KM_IRQ0
);
642 total_len
-= copy_len
;
643 src_addr
+= copy_len
;
647 BUG_ON(task
->total_xfer_len
< total_len
);
648 memcpy(task
->scatter
, src_addr
, total_len
);
656 * @sci_req: The PIO DATA IN request that is to receive the data.
657 * @data_buffer: The buffer to copy from.
659 * Copy the data buffer to the io request data region. enum sci_status
661 static enum sci_status
scic_sds_stp_request_pio_data_in_copy_data(
662 struct scic_sds_stp_request
*sci_req
,
665 enum sci_status status
;
668 * If there is less than 1K remaining in the transfer request
669 * copy just the data for the transfer */
670 if (sci_req
->type
.pio
.pio_transfer_bytes
< SCU_MAX_FRAME_BUFFER_SIZE
) {
671 status
= scic_sds_stp_request_pio_data_in_copy_data_buffer(
672 sci_req
, data_buffer
, sci_req
->type
.pio
.pio_transfer_bytes
);
674 if (status
== SCI_SUCCESS
)
675 sci_req
->type
.pio
.pio_transfer_bytes
= 0;
677 /* We are transfering the whole frame so copy */
678 status
= scic_sds_stp_request_pio_data_in_copy_data_buffer(
679 sci_req
, data_buffer
, SCU_MAX_FRAME_BUFFER_SIZE
);
681 if (status
== SCI_SUCCESS
)
682 sci_req
->type
.pio
.pio_transfer_bytes
-= SCU_MAX_FRAME_BUFFER_SIZE
;
695 static enum sci_status
scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler(
696 struct scic_sds_request
*sci_req
,
699 enum sci_status status
= SCI_SUCCESS
;
701 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
702 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
703 scic_sds_request_set_status(
704 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
707 sci_base_state_machine_change_state(
708 &sci_req
->started_substate_machine
,
709 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
715 * All other completion status cause the IO to be complete. If a NAK
716 * was received, then it is up to the user to retry the request. */
717 scic_sds_request_set_status(
719 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
720 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
723 sci_base_state_machine_change_state(
724 &sci_req
->state_machine
,
725 SCI_BASE_REQUEST_STATE_COMPLETED
733 static enum sci_status
scic_sds_stp_request_pio_await_frame_frame_handler(struct scic_sds_request
*sci_req
,
736 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
737 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
738 struct isci_request
*ireq
= sci_req_to_ireq(sci_req
);
739 struct sas_task
*task
= isci_request_access_task(ireq
);
740 struct dev_to_host_fis
*frame_header
;
741 enum sci_status status
;
744 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
746 (void **)&frame_header
);
748 if (status
!= SCI_SUCCESS
) {
749 dev_err(scic_to_dev(scic
),
750 "%s: SCIC IO Request 0x%p could not get frame header "
751 "for frame index %d, status %x\n",
752 __func__
, stp_req
, frame_index
, status
);
756 switch (frame_header
->fis_type
) {
758 /* Get from the frame buffer the PIO Setup Data */
759 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
761 (void **)&frame_buffer
);
763 /* Get the data from the PIO Setup The SCU Hardware returns
764 * first word in the frame_header and the rest of the data is in
765 * the frame buffer so we need to back up one dword
768 /* transfer_count: first 16bits in the 4th dword */
769 stp_req
->type
.pio
.pio_transfer_bytes
= frame_buffer
[3] & 0xffff;
771 /* ending_status: 4th byte in the 3rd dword */
772 stp_req
->type
.pio
.ending_status
= (frame_buffer
[2] >> 24) & 0xff;
774 scic_sds_controller_copy_sata_response(&sci_req
->stp
.rsp
,
778 sci_req
->stp
.rsp
.status
= stp_req
->type
.pio
.ending_status
;
780 /* The next state is dependent on whether the
781 * request was PIO Data-in or Data out
783 if (task
->data_dir
== DMA_FROM_DEVICE
) {
784 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
785 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
);
786 } else if (task
->data_dir
== DMA_TO_DEVICE
) {
788 status
= scic_sds_stp_request_pio_data_out_transmit_data(sci_req
);
789 if (status
!= SCI_SUCCESS
)
791 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
792 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
);
796 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
797 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
);
800 if (frame_header
->status
& ATA_BUSY
) {
801 /* Now why is the drive sending a D2H Register FIS when
802 * it is still busy? Do nothing since we are still in
805 dev_dbg(scic_to_dev(scic
),
806 "%s: SCIC PIO Request 0x%p received "
807 "D2H Register FIS with BSY status "
808 "0x%x\n", __func__
, stp_req
,
809 frame_header
->status
);
813 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
815 (void **)&frame_buffer
);
817 scic_sds_controller_copy_sata_response(&sci_req
->stp
.req
,
821 scic_sds_request_set_status(sci_req
,
822 SCU_TASK_DONE_CHECK_RESPONSE
,
823 SCI_FAILURE_IO_RESPONSE_VALID
);
825 sci_base_state_machine_change_state(&sci_req
->state_machine
,
826 SCI_BASE_REQUEST_STATE_COMPLETED
);
829 /* FIXME: what do we do here? */
833 /* Frame is decoded return it to the controller */
834 scic_sds_controller_release_frame(scic
, frame_index
);
839 static enum sci_status
scic_sds_stp_request_pio_data_in_await_data_frame_handler(struct scic_sds_request
*sci_req
,
842 enum sci_status status
;
843 struct dev_to_host_fis
*frame_header
;
844 struct sata_fis_data
*frame_buffer
;
845 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
846 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
848 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
850 (void **)&frame_header
);
852 if (status
!= SCI_SUCCESS
) {
853 dev_err(scic_to_dev(scic
),
854 "%s: SCIC IO Request 0x%p could not get frame header "
855 "for frame index %d, status %x\n",
856 __func__
, stp_req
, frame_index
, status
);
860 if (frame_header
->fis_type
== FIS_DATA
) {
861 if (stp_req
->type
.pio
.request_current
.sgl_pair
== NULL
) {
862 sci_req
->saved_rx_frame_index
= frame_index
;
863 stp_req
->type
.pio
.pio_transfer_bytes
= 0;
865 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
867 (void **)&frame_buffer
);
869 status
= scic_sds_stp_request_pio_data_in_copy_data(stp_req
,
872 /* Frame is decoded return it to the controller */
873 scic_sds_controller_release_frame(scic
, frame_index
);
876 /* Check for the end of the transfer, are there more
877 * bytes remaining for this data transfer
879 if (status
!= SCI_SUCCESS
||
880 stp_req
->type
.pio
.pio_transfer_bytes
!= 0)
883 if ((stp_req
->type
.pio
.ending_status
& ATA_BUSY
) == 0) {
884 scic_sds_request_set_status(sci_req
,
885 SCU_TASK_DONE_CHECK_RESPONSE
,
886 SCI_FAILURE_IO_RESPONSE_VALID
);
888 sci_base_state_machine_change_state(&sci_req
->state_machine
,
889 SCI_BASE_REQUEST_STATE_COMPLETED
);
891 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
892 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
);
895 dev_err(scic_to_dev(scic
),
896 "%s: SCIC PIO Request 0x%p received frame %d "
897 "with fis type 0x%02x when expecting a data "
898 "fis.\n", __func__
, stp_req
, frame_index
,
899 frame_header
->fis_type
);
901 scic_sds_request_set_status(sci_req
,
903 SCI_FAILURE_IO_REQUIRES_SCSI_ABORT
);
905 sci_base_state_machine_change_state(&sci_req
->state_machine
,
906 SCI_BASE_REQUEST_STATE_COMPLETED
);
908 /* Frame is decoded return it to the controller */
909 scic_sds_controller_release_frame(scic
, frame_index
);
923 static enum sci_status
scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler(
925 struct scic_sds_request
*sci_req
,
928 enum sci_status status
= SCI_SUCCESS
;
929 bool all_frames_transferred
= false;
930 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
932 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
933 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
935 if (stp_req
->type
.pio
.pio_transfer_bytes
!= 0) {
936 status
= scic_sds_stp_request_pio_data_out_transmit_data(sci_req
);
937 if (status
== SCI_SUCCESS
) {
938 if (stp_req
->type
.pio
.pio_transfer_bytes
== 0)
939 all_frames_transferred
= true;
941 } else if (stp_req
->type
.pio
.pio_transfer_bytes
== 0) {
943 * this will happen if the all data is written at the
944 * first time after the pio setup fis is received
946 all_frames_transferred
= true;
949 /* all data transferred. */
950 if (all_frames_transferred
) {
952 * Change the state to SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_FRAME_SUBSTATE
953 * and wait for PIO_SETUP fis / or D2H REg fis. */
954 sci_base_state_machine_change_state(
955 &sci_req
->started_substate_machine
,
956 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
963 * All other completion status cause the IO to be complete. If a NAK
964 * was received, then it is up to the user to retry the request. */
965 scic_sds_request_set_status(
967 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
968 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
971 sci_base_state_machine_change_state(
972 &sci_req
->state_machine
,
973 SCI_BASE_REQUEST_STATE_COMPLETED
983 * @request: This is the request which is receiving the event.
984 * @event_code: This is the event code that the request on which the request is
985 * expected to take action.
987 * This method will handle any link layer events while waiting for the data
988 * frame. enum sci_status SCI_SUCCESS SCI_FAILURE
990 static enum sci_status
scic_sds_stp_request_pio_data_in_await_data_event_handler(
991 struct scic_sds_request
*request
,
994 enum sci_status status
;
996 switch (scu_get_event_specifier(event_code
)) {
997 case SCU_TASK_DONE_CRC_ERR
<< SCU_EVENT_SPECIFIC_CODE_SHIFT
:
999 * We are waiting for data and the SCU has R_ERR the data frame.
1000 * Go back to waiting for the D2H Register FIS */
1001 sci_base_state_machine_change_state(
1002 &request
->started_substate_machine
,
1003 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1006 status
= SCI_SUCCESS
;
1010 dev_err(scic_to_dev(request
->owning_controller
),
1011 "%s: SCIC PIO Request 0x%p received unexpected "
1013 __func__
, request
, event_code
);
1015 /* / @todo Should we fail the PIO request when we get an unexpected event? */
1016 status
= SCI_FAILURE
;
1023 /* --------------------------------------------------------------------------- */
1025 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_pio_substate_handler_table
[] = {
1026 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
] = {
1027 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1028 .tc_completion_handler
= scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler
,
1030 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
] = {
1031 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1032 .frame_handler
= scic_sds_stp_request_pio_await_frame_frame_handler
1034 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
] = {
1035 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1036 .event_handler
= scic_sds_stp_request_pio_data_in_await_data_event_handler
,
1037 .frame_handler
= scic_sds_stp_request_pio_data_in_await_data_frame_handler
1039 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
] = {
1040 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1041 .tc_completion_handler
= scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler
,
1045 static void scic_sds_stp_request_started_pio_await_h2d_completion_enter(
1048 struct scic_sds_request
*sci_req
= object
;
1052 scic_sds_stp_request_started_pio_substate_handler_table
,
1053 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
1056 scic_sds_remote_device_set_working_request(
1057 sci_req
->target_device
, sci_req
);
1060 static void scic_sds_stp_request_started_pio_await_frame_enter(void *object
)
1062 struct scic_sds_request
*sci_req
= object
;
1066 scic_sds_stp_request_started_pio_substate_handler_table
,
1067 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1071 static void scic_sds_stp_request_started_pio_data_in_await_data_enter(
1074 struct scic_sds_request
*sci_req
= object
;
1078 scic_sds_stp_request_started_pio_substate_handler_table
,
1079 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
1083 static void scic_sds_stp_request_started_pio_data_out_transmit_data_enter(
1086 struct scic_sds_request
*sci_req
= object
;
1090 scic_sds_stp_request_started_pio_substate_handler_table
,
1091 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
1095 /* --------------------------------------------------------------------------- */
1097 static const struct sci_base_state scic_sds_stp_request_started_pio_substate_table
[] = {
1098 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
] = {
1099 .enter_state
= scic_sds_stp_request_started_pio_await_h2d_completion_enter
,
1101 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
] = {
1102 .enter_state
= scic_sds_stp_request_started_pio_await_frame_enter
,
1104 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
] = {
1105 .enter_state
= scic_sds_stp_request_started_pio_data_in_await_data_enter
,
1107 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
] = {
1108 .enter_state
= scic_sds_stp_request_started_pio_data_out_transmit_data_enter
,
1113 scic_sds_stp_pio_request_construct(struct scic_sds_request
*sci_req
,
1116 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
1117 struct scic_sds_stp_pio_request
*pio
= &stp_req
->type
.pio
;
1119 scic_sds_stp_non_ncq_request_construct(sci_req
);
1121 scu_stp_raw_request_construct_task_context(stp_req
,
1122 sci_req
->task_context_buffer
);
1124 pio
->current_transfer_bytes
= 0;
1125 pio
->ending_error
= 0;
1126 pio
->ending_status
= 0;
1128 pio
->request_current
.sgl_offset
= 0;
1129 pio
->request_current
.sgl_set
= SCU_SGL_ELEMENT_PAIR_A
;
1131 if (copy_rx_frame
) {
1132 scic_sds_request_build_sgl(sci_req
);
1133 /* Since the IO request copy of the TC contains the same data as
1134 * the actual TC this pointer is vaild for either.
1136 pio
->request_current
.sgl_pair
= &sci_req
->task_context_buffer
->sgl_pair_ab
;
1138 /* The user does not want the data copied to the SGL buffer location */
1139 pio
->request_current
.sgl_pair
= NULL
;
1142 sci_base_state_machine_construct(&sci_req
->started_substate_machine
,
1144 scic_sds_stp_request_started_pio_substate_table
,
1145 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
);
1150 static void scic_sds_stp_request_udma_complete_request(
1151 struct scic_sds_request
*request
,
1153 enum sci_status sci_status
)
1155 scic_sds_request_set_status(request
, scu_status
, sci_status
);
1156 sci_base_state_machine_change_state(&request
->state_machine
,
1157 SCI_BASE_REQUEST_STATE_COMPLETED
);
1160 static enum sci_status
scic_sds_stp_request_udma_general_frame_handler(struct scic_sds_request
*sci_req
,
1163 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
1164 struct dev_to_host_fis
*frame_header
;
1165 enum sci_status status
;
1168 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
1170 (void **)&frame_header
);
1172 if ((status
== SCI_SUCCESS
) &&
1173 (frame_header
->fis_type
== FIS_REGD2H
)) {
1174 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
1176 (void **)&frame_buffer
);
1178 scic_sds_controller_copy_sata_response(&sci_req
->stp
.rsp
,
1183 scic_sds_controller_release_frame(scic
, frame_index
);
1188 static enum sci_status
scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler(
1189 struct scic_sds_request
*sci_req
,
1190 u32 completion_code
)
1192 enum sci_status status
= SCI_SUCCESS
;
1194 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1195 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
1196 scic_sds_stp_request_udma_complete_request(sci_req
,
1200 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS
):
1201 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR
):
1203 * We must check ther response buffer to see if the D2H Register FIS was
1204 * received before we got the TC completion. */
1205 if (sci_req
->stp
.rsp
.fis_type
== FIS_REGD2H
) {
1206 scic_sds_remote_device_suspend(sci_req
->target_device
,
1207 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code
)));
1209 scic_sds_stp_request_udma_complete_request(sci_req
,
1210 SCU_TASK_DONE_CHECK_RESPONSE
,
1211 SCI_FAILURE_IO_RESPONSE_VALID
);
1214 * If we have an error completion status for the TC then we can expect a
1215 * D2H register FIS from the device so we must change state to wait for it */
1216 sci_base_state_machine_change_state(&sci_req
->started_substate_machine
,
1217 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
);
1222 * / @todo Check to see if any of these completion status need to wait for
1223 * / the device to host register fis. */
1224 /* / @todo We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR - this comes only for B0 */
1225 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN
):
1226 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR
):
1227 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR
):
1228 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR
):
1229 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR
):
1230 scic_sds_remote_device_suspend(sci_req
->target_device
,
1231 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code
)));
1232 /* Fall through to the default case */
1234 /* All other completion status cause the IO to be complete. */
1235 scic_sds_stp_request_udma_complete_request(sci_req
,
1236 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
1237 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
);
1244 static enum sci_status
scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler(
1245 struct scic_sds_request
*sci_req
,
1248 enum sci_status status
;
1250 /* Use the general frame handler to copy the resposne data */
1251 status
= scic_sds_stp_request_udma_general_frame_handler(sci_req
, frame_index
);
1253 if (status
!= SCI_SUCCESS
)
1256 scic_sds_stp_request_udma_complete_request(sci_req
,
1257 SCU_TASK_DONE_CHECK_RESPONSE
,
1258 SCI_FAILURE_IO_RESPONSE_VALID
);
1263 /* --------------------------------------------------------------------------- */
1265 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_udma_substate_handler_table
[] = {
1266 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
] = {
1267 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1268 .tc_completion_handler
= scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler
,
1269 .frame_handler
= scic_sds_stp_request_udma_general_frame_handler
,
1271 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
] = {
1272 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1273 .frame_handler
= scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler
,
1277 static void scic_sds_stp_request_started_udma_await_tc_completion_enter(
1280 struct scic_sds_request
*sci_req
= object
;
1284 scic_sds_stp_request_started_udma_substate_handler_table
,
1285 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
1292 * This state is entered when there is an TC completion failure. The hardware
1293 * received an unexpected condition while processing the IO request and now
1294 * will UF the D2H register FIS to complete the IO.
1296 static void scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter(
1299 struct scic_sds_request
*sci_req
= object
;
1303 scic_sds_stp_request_started_udma_substate_handler_table
,
1304 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
1308 /* --------------------------------------------------------------------------- */
1310 static const struct sci_base_state scic_sds_stp_request_started_udma_substate_table
[] = {
1311 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
] = {
1312 .enter_state
= scic_sds_stp_request_started_udma_await_tc_completion_enter
,
1314 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
] = {
1315 .enter_state
= scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter
,
1319 enum sci_status
scic_sds_stp_udma_request_construct(struct scic_sds_request
*sci_req
,
1321 enum dma_data_direction dir
)
1323 scic_sds_stp_non_ncq_request_construct(sci_req
);
1325 scic_sds_stp_optimized_request_construct(sci_req
, SCU_TASK_TYPE_DMA_IN
,
1328 sci_base_state_machine_construct(
1329 &sci_req
->started_substate_machine
,
1331 scic_sds_stp_request_started_udma_substate_table
,
1332 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
1343 * This method processes a TC completion. The expected TC completion is for
1344 * the transmission of the H2D register FIS containing the SATA/STP non-data
1345 * request. This method always successfully processes the TC completion.
1346 * SCI_SUCCESS This value is always returned.
1348 static enum sci_status
scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler(
1349 struct scic_sds_request
*sci_req
,
1350 u32 completion_code
)
1352 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1353 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
1354 scic_sds_request_set_status(
1355 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
1358 sci_base_state_machine_change_state(
1359 &sci_req
->started_substate_machine
,
1360 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
1366 * All other completion status cause the IO to be complete. If a NAK
1367 * was received, then it is up to the user to retry the request. */
1368 scic_sds_request_set_status(
1370 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
1371 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1374 sci_base_state_machine_change_state(
1375 &sci_req
->state_machine
, SCI_BASE_REQUEST_STATE_COMPLETED
);
1387 * This method processes a TC completion. The expected TC completion is for
1388 * the transmission of the H2D register FIS containing the SATA/STP non-data
1389 * request. This method always successfully processes the TC completion.
1390 * SCI_SUCCESS This value is always returned.
1392 static enum sci_status
scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler(
1393 struct scic_sds_request
*sci_req
,
1394 u32 completion_code
)
1396 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1397 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
1398 scic_sds_request_set_status(
1399 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
1402 sci_base_state_machine_change_state(
1403 &sci_req
->started_substate_machine
,
1404 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
1410 * All other completion status cause the IO to be complete. If a NAK
1411 * was received, then it is up to the user to retry the request. */
1412 scic_sds_request_set_status(
1414 SCU_NORMALIZE_COMPLETION_STATUS(completion_code
),
1415 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1418 sci_base_state_machine_change_state(&sci_req
->state_machine
,
1419 SCI_BASE_REQUEST_STATE_COMPLETED
);
1428 * @request: This parameter specifies the request for which a frame has been
1430 * @frame_index: This parameter specifies the index of the frame that has been
1433 * This method processes frames received from the target while waiting for a
1434 * device to host register FIS. If a non-register FIS is received during this
1435 * time, it is treated as a protocol violation from an IO perspective. Indicate
1436 * if the received frame was processed successfully.
1438 static enum sci_status
scic_sds_stp_request_soft_reset_await_d2h_frame_handler(
1439 struct scic_sds_request
*sci_req
,
1442 enum sci_status status
;
1443 struct dev_to_host_fis
*frame_header
;
1445 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
1446 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
1448 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
1450 (void **)&frame_header
);
1451 if (status
!= SCI_SUCCESS
) {
1452 dev_err(scic_to_dev(scic
),
1453 "%s: SCIC IO Request 0x%p could not get frame header "
1454 "for frame index %d, status %x\n",
1455 __func__
, stp_req
, frame_index
, status
);
1459 switch (frame_header
->fis_type
) {
1461 scic_sds_unsolicited_frame_control_get_buffer(&scic
->uf_control
,
1463 (void **)&frame_buffer
);
1465 scic_sds_controller_copy_sata_response(&sci_req
->stp
.rsp
,
1469 /* The command has completed with error */
1470 scic_sds_request_set_status(sci_req
,
1471 SCU_TASK_DONE_CHECK_RESPONSE
,
1472 SCI_FAILURE_IO_RESPONSE_VALID
);
1476 dev_warn(scic_to_dev(scic
),
1477 "%s: IO Request:0x%p Frame Id:%d protocol "
1478 "violation occurred\n", __func__
, stp_req
,
1481 scic_sds_request_set_status(sci_req
, SCU_TASK_DONE_UNEXP_FIS
,
1482 SCI_FAILURE_PROTOCOL_VIOLATION
);
1486 sci_base_state_machine_change_state(&sci_req
->state_machine
,
1487 SCI_BASE_REQUEST_STATE_COMPLETED
);
1489 /* Frame has been decoded return it to the controller */
1490 scic_sds_controller_release_frame(scic
, frame_index
);
1495 /* --------------------------------------------------------------------------- */
1497 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_soft_reset_substate_handler_table
[] = {
1498 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
] = {
1499 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1500 .tc_completion_handler
= scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler
,
1502 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
] = {
1503 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1504 .tc_completion_handler
= scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler
,
1506 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
] = {
1507 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1508 .frame_handler
= scic_sds_stp_request_soft_reset_await_d2h_frame_handler
,
1512 static void scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter(
1515 struct scic_sds_request
*sci_req
= object
;
1519 scic_sds_stp_request_started_soft_reset_substate_handler_table
,
1520 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
1523 scic_sds_remote_device_set_working_request(
1524 sci_req
->target_device
, sci_req
1528 static void scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter(
1531 struct scic_sds_request
*sci_req
= object
;
1532 struct scu_task_context
*task_context
;
1533 struct host_to_dev_fis
*h2d_fis
;
1534 enum sci_status status
;
1536 /* Clear the SRST bit */
1537 h2d_fis
= &sci_req
->stp
.cmd
;
1538 h2d_fis
->control
= 0;
1540 /* Clear the TC control bit */
1541 task_context
= scic_sds_controller_get_task_context_buffer(
1542 sci_req
->owning_controller
, sci_req
->io_tag
);
1543 task_context
->control_frame
= 0;
1545 status
= scic_controller_continue_io(sci_req
);
1546 if (status
== SCI_SUCCESS
) {
1549 scic_sds_stp_request_started_soft_reset_substate_handler_table
,
1550 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
1555 static void scic_sds_stp_request_started_soft_reset_await_d2h_response_enter(
1558 struct scic_sds_request
*sci_req
= object
;
1562 scic_sds_stp_request_started_soft_reset_substate_handler_table
,
1563 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
1567 static const struct sci_base_state scic_sds_stp_request_started_soft_reset_substate_table
[] = {
1568 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
] = {
1569 .enter_state
= scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter
,
1571 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
] = {
1572 .enter_state
= scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter
,
1574 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
] = {
1575 .enter_state
= scic_sds_stp_request_started_soft_reset_await_d2h_response_enter
,
1579 enum sci_status
scic_sds_stp_soft_reset_request_construct(struct scic_sds_request
*sci_req
)
1581 struct scic_sds_stp_request
*stp_req
= &sci_req
->stp
.req
;
1583 scic_sds_stp_non_ncq_request_construct(sci_req
);
1585 /* Build the STP task context structure */
1586 scu_stp_raw_request_construct_task_context(stp_req
, sci_req
->task_context_buffer
);
1588 sci_base_state_machine_construct(&sci_req
->started_substate_machine
,
1590 scic_sds_stp_request_started_soft_reset_substate_table
,
1591 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
);