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 "sci_base_state.h"
59 #include "sci_base_state_machine.h"
60 #include "scic_io_request.h"
61 #include "scic_sds_controller.h"
62 #include "remote_device.h"
63 #include "scic_sds_request.h"
64 #include "scic_sds_stp_pio_request.h"
65 #include "scic_sds_stp_request.h"
66 #include "scic_sds_unsolicited_frame_control.h"
67 #include "sci_environment.h"
69 #include "scu_completion_codes.h"
70 #include "scu_event_codes.h"
71 #include "scu_task_context.h"
74 void scic_sds_stp_request_assign_buffers(struct scic_sds_request *sci_req)
76 if (sci_req->was_tag_assigned_by_user == false)
77 sci_req->task_context_buffer = &sci_req->tc;
81 * This method is will fill in the SCU Task Context for any type of SATA
82 * request. This is called from the various SATA constructors.
83 * @sci_req: The general IO request object which is to be used in
84 * constructing the SCU task context.
85 * @task_context: The buffer pointer for the SCU task context which is being
88 * The general io request construction is complete. The buffer assignment for
89 * the command buffer is complete. none Revisit task context construction to
90 * determine what is common for SSP/SMP/STP task context structures.
92 static void scu_sata_reqeust_construct_task_context(
93 struct scic_sds_request *sci_req,
94 struct scu_task_context *task_context)
97 struct scic_sds_controller *controller;
98 struct scic_sds_remote_device *target_device;
99 struct scic_sds_port *target_port;
101 controller = scic_sds_request_get_controller(sci_req);
102 target_device = scic_sds_request_get_device(sci_req);
103 target_port = scic_sds_request_get_port(sci_req);
105 /* Fill in the TC with the its required data */
106 task_context->abort = 0;
107 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
108 task_context->initiator_request = 1;
109 task_context->connection_rate = target_device->connection_rate;
110 task_context->protocol_engine_index =
111 scic_sds_controller_get_protocol_engine_group(controller);
112 task_context->logical_port_index =
113 scic_sds_port_get_index(target_port);
114 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_STP;
115 task_context->valid = SCU_TASK_CONTEXT_VALID;
116 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
118 task_context->remote_node_index =
119 scic_sds_remote_device_get_index(sci_req->target_device);
120 task_context->command_code = 0;
122 task_context->link_layer_control = 0;
123 task_context->do_not_dma_ssp_good_response = 1;
124 task_context->strict_ordering = 0;
125 task_context->control_frame = 0;
126 task_context->timeout_enable = 0;
127 task_context->block_guard_enable = 0;
129 task_context->address_modifier = 0;
130 task_context->task_phase = 0x01;
132 task_context->ssp_command_iu_length =
133 (sizeof(struct host_to_dev_fis) - sizeof(u32)) / sizeof(u32);
135 /* Set the first word of the H2D REG FIS */
136 task_context->type.words[0] = *(u32 *)&sci_req->stp.cmd;
138 if (sci_req->was_tag_assigned_by_user) {
140 * Build the task context now since we have already read
143 sci_req->post_context =
144 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
145 (scic_sds_controller_get_protocol_engine_group(
147 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
148 (scic_sds_port_get_index(target_port) <<
149 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
150 scic_sds_io_tag_get_index(sci_req->io_tag));
153 * Build the task context now since we have already read
155 * I/O tag index is not assigned because we have to wait
156 * until we get a TCi.
158 sci_req->post_context =
159 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
160 (scic_sds_controller_get_protocol_engine_group(
162 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
163 (scic_sds_port_get_index(target_port) <<
164 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
168 * Copy the physical address for the command buffer to the SCU Task
169 * Context. We must offset the command buffer by 4 bytes because the
170 * first 4 bytes are transfered in the body of the TC.
172 dma_addr = scic_io_request_get_dma_addr(sci_req,
173 ((char *) &sci_req->stp.cmd) +
176 task_context->command_iu_upper = upper_32_bits(dma_addr);
177 task_context->command_iu_lower = lower_32_bits(dma_addr);
179 /* SATA Requests do not have a response buffer */
180 task_context->response_iu_upper = 0;
181 task_context->response_iu_lower = 0;
188 * This method will perform any general sata request construction. What part of
189 * SATA IO request construction is general? none
191 static void scic_sds_stp_non_ncq_request_construct(
192 struct scic_sds_request *sci_req)
194 sci_req->has_started_substate_machine = true;
199 * @sci_req: This parameter specifies the request to be constructed as an
201 * @optimized_task_type: This parameter specifies whether the request is to be
202 * an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A
203 * value of 1 indicates NCQ.
205 * This method will perform request construction common to all types of STP
206 * requests that are optimized by the silicon (i.e. UDMA, NCQ). This method
207 * returns an indication as to whether the construction was successful.
209 static void scic_sds_stp_optimized_request_construct(struct scic_sds_request *sci_req,
210 u8 optimized_task_type,
212 enum dma_data_direction dir)
214 struct scu_task_context *task_context = sci_req->task_context_buffer;
216 /* Build the STP task context structure */
217 scu_sata_reqeust_construct_task_context(sci_req, task_context);
219 /* Copy over the SGL elements */
220 scic_sds_request_build_sgl(sci_req);
222 /* Copy over the number of bytes to be transfered */
223 task_context->transfer_length_bytes = len;
225 if (dir == DMA_TO_DEVICE) {
227 * The difference between the DMA IN and DMA OUT request task type
228 * values are consistent with the difference between FPDMA READ
229 * and FPDMA WRITE values. Add the supplied task type parameter
230 * to this difference to set the task type properly for this
231 * DATA OUT (WRITE) case. */
232 task_context->task_type = optimized_task_type + (SCU_TASK_TYPE_DMA_OUT
233 - SCU_TASK_TYPE_DMA_IN);
236 * For the DATA IN (READ) case, simply save the supplied
237 * optimized task type. */
238 task_context->task_type = optimized_task_type;
244 * @sci_req: This parameter specifies the request to be constructed.
246 * This method will construct the STP UDMA request and its associated TC data.
247 * This method returns an indication as to whether the construction was
248 * successful. SCI_SUCCESS Currently this method always returns this value.
250 enum sci_status scic_sds_stp_ncq_request_construct(struct scic_sds_request *sci_req,
252 enum dma_data_direction dir)
254 scic_sds_stp_optimized_request_construct(sci_req,
255 SCU_TASK_TYPE_FPDMAQ_READ,
261 * scu_stp_raw_request_construct_task_context -
262 * @sci_req: This parameter specifies the STP request object for which to
263 * construct a RAW command frame task context.
264 * @task_context: This parameter specifies the SCU specific task context buffer
267 * This method performs the operations common to all SATA/STP requests
268 * utilizing the raw frame method. none
270 static void scu_stp_raw_request_construct_task_context(
271 struct scic_sds_stp_request *stp_req,
272 struct scu_task_context *task_context)
274 struct scic_sds_request *sci_req = to_sci_req(stp_req);
276 scu_sata_reqeust_construct_task_context(sci_req, task_context);
278 task_context->control_frame = 0;
279 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
280 task_context->task_type = SCU_TASK_TYPE_SATA_RAW_FRAME;
281 task_context->type.stp.fis_type = FIS_REGH2D;
282 task_context->transfer_length_bytes = sizeof(struct host_to_dev_fis) - sizeof(u32);
285 void scic_stp_io_request_set_ncq_tag(
286 struct scic_sds_request *req,
290 * @note This could be made to return an error to the user if the user
291 * attempts to set the NCQ tag in the wrong state.
293 req->task_context_buffer->type.stp.ncq_tag = ncq_tag;
300 * Get the next SGL element from the request. - Check on which SGL element pair
301 * we are working - if working on SLG pair element A - advance to element B -
302 * else - check to see if there are more SGL element pairs for this IO request
303 * - if there are more SGL element pairs - advance to the next pair and return
304 * element A struct scu_sgl_element*
306 static struct scu_sgl_element *scic_sds_stp_request_pio_get_next_sgl(struct scic_sds_stp_request *stp_req)
308 struct scu_sgl_element *current_sgl;
309 struct scic_sds_request *sci_req = to_sci_req(stp_req);
310 struct scic_sds_request_pio_sgl *pio_sgl = &stp_req->type.pio.request_current;
312 if (pio_sgl->sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
313 if (pio_sgl->sgl_pair->B.address_lower == 0 &&
314 pio_sgl->sgl_pair->B.address_upper == 0) {
317 pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_B;
318 current_sgl = &pio_sgl->sgl_pair->B;
321 if (pio_sgl->sgl_pair->next_pair_lower == 0 &&
322 pio_sgl->sgl_pair->next_pair_upper == 0) {
327 phys_addr = pio_sgl->sgl_pair->next_pair_upper;
329 phys_addr |= pio_sgl->sgl_pair->next_pair_lower;
331 pio_sgl->sgl_pair = scic_request_get_virt_addr(sci_req, phys_addr);
332 pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_A;
333 current_sgl = &pio_sgl->sgl_pair->A;
345 * This method processes a TC completion. The expected TC completion is for
346 * the transmission of the H2D register FIS containing the SATA/STP non-data
347 * request. This method always successfully processes the TC completion.
348 * SCI_SUCCESS This value is always returned.
350 static enum sci_status scic_sds_stp_request_non_data_await_h2d_tc_completion_handler(
351 struct scic_sds_request *sci_req,
354 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
355 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
356 scic_sds_request_set_status(
357 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
360 sci_base_state_machine_change_state(
361 &sci_req->started_substate_machine,
362 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
368 * All other completion status cause the IO to be complete. If a NAK
369 * was received, then it is up to the user to retry the request. */
370 scic_sds_request_set_status(
372 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
373 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
376 sci_base_state_machine_change_state(
377 &sci_req->state_machine, SCI_BASE_REQUEST_STATE_COMPLETED);
386 * @request: This parameter specifies the request for which a frame has been
388 * @frame_index: This parameter specifies the index of the frame that has been
391 * This method processes frames received from the target while waiting for a
392 * device to host register FIS. If a non-register FIS is received during this
393 * time, it is treated as a protocol violation from an IO perspective. Indicate
394 * if the received frame was processed successfully.
396 static enum sci_status scic_sds_stp_request_non_data_await_d2h_frame_handler(
397 struct scic_sds_request *sci_req,
400 enum sci_status status;
401 struct dev_to_host_fis *frame_header;
403 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
404 struct scic_sds_controller *scic = sci_req->owning_controller;
406 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
408 (void **)&frame_header);
410 if (status != SCI_SUCCESS) {
411 dev_err(scic_to_dev(sci_req->owning_controller),
412 "%s: SCIC IO Request 0x%p could not get frame header "
413 "for frame index %d, status %x\n",
414 __func__, stp_req, frame_index, status);
419 switch (frame_header->fis_type) {
421 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
423 (void **)&frame_buffer);
425 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
429 /* The command has completed with error */
430 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_CHECK_RESPONSE,
431 SCI_FAILURE_IO_RESPONSE_VALID);
435 dev_warn(scic_to_dev(scic),
436 "%s: IO Request:0x%p Frame Id:%d protocol "
437 "violation occurred\n", __func__, stp_req,
440 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_UNEXP_FIS,
441 SCI_FAILURE_PROTOCOL_VIOLATION);
445 sci_base_state_machine_change_state(&sci_req->state_machine,
446 SCI_BASE_REQUEST_STATE_COMPLETED);
448 /* Frame has been decoded return it to the controller */
449 scic_sds_controller_release_frame(scic, frame_index);
454 /* --------------------------------------------------------------------------- */
456 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_non_data_substate_handler_table[] = {
457 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE] = {
458 .abort_handler = scic_sds_request_started_state_abort_handler,
459 .tc_completion_handler = scic_sds_stp_request_non_data_await_h2d_tc_completion_handler,
461 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE] = {
462 .abort_handler = scic_sds_request_started_state_abort_handler,
463 .frame_handler = scic_sds_stp_request_non_data_await_d2h_frame_handler,
467 static void scic_sds_stp_request_started_non_data_await_h2d_completion_enter(
470 struct scic_sds_request *sci_req = object;
474 scic_sds_stp_request_started_non_data_substate_handler_table,
475 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
478 scic_sds_remote_device_set_working_request(
479 sci_req->target_device, sci_req
483 static void scic_sds_stp_request_started_non_data_await_d2h_enter(void *object)
485 struct scic_sds_request *sci_req = object;
489 scic_sds_stp_request_started_non_data_substate_handler_table,
490 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
494 /* --------------------------------------------------------------------------- */
496 static const struct sci_base_state scic_sds_stp_request_started_non_data_substate_table[] = {
497 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE] = {
498 .enter_state = scic_sds_stp_request_started_non_data_await_h2d_completion_enter,
500 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE] = {
501 .enter_state = scic_sds_stp_request_started_non_data_await_d2h_enter,
505 enum sci_status scic_sds_stp_non_data_request_construct(struct scic_sds_request *sci_req)
507 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
509 scic_sds_stp_non_ncq_request_construct(sci_req);
511 /* Build the STP task context structure */
512 scu_stp_raw_request_construct_task_context(stp_req, sci_req->task_context_buffer);
514 sci_base_state_machine_construct(&sci_req->started_substate_machine,
516 scic_sds_stp_request_started_non_data_substate_table,
517 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE);
522 #define SCU_MAX_FRAME_BUFFER_SIZE 0x400 /* 1K is the maximum SCU frame data payload */
524 /* transmit DATA_FIS from (current sgl + offset) for input
525 * parameter length. current sgl and offset is alreay stored in the IO request
527 static enum sci_status scic_sds_stp_request_pio_data_out_trasmit_data_frame(
528 struct scic_sds_request *sci_req,
531 struct scic_sds_controller *scic = sci_req->owning_controller;
532 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
533 struct scu_task_context *task_context;
534 struct scu_sgl_element *current_sgl;
536 /* Recycle the TC and reconstruct it for sending out DATA FIS containing
537 * for the data from current_sgl+offset for the input length
539 task_context = scic_sds_controller_get_task_context_buffer(scic,
542 if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A)
543 current_sgl = &stp_req->type.pio.request_current.sgl_pair->A;
545 current_sgl = &stp_req->type.pio.request_current.sgl_pair->B;
548 task_context->command_iu_upper = current_sgl->address_upper;
549 task_context->command_iu_lower = current_sgl->address_lower;
550 task_context->transfer_length_bytes = length;
551 task_context->type.stp.fis_type = FIS_DATA;
553 /* send the new TC out. */
554 return scic_controller_continue_io(sci_req);
557 static enum sci_status scic_sds_stp_request_pio_data_out_transmit_data(struct scic_sds_request *sci_req)
560 struct scu_sgl_element *current_sgl;
562 u32 remaining_bytes_in_current_sgl = 0;
563 enum sci_status status = SCI_SUCCESS;
564 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
566 sgl_offset = stp_req->type.pio.request_current.sgl_offset;
568 if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
569 current_sgl = &(stp_req->type.pio.request_current.sgl_pair->A);
570 remaining_bytes_in_current_sgl = stp_req->type.pio.request_current.sgl_pair->A.length - sgl_offset;
572 current_sgl = &(stp_req->type.pio.request_current.sgl_pair->B);
573 remaining_bytes_in_current_sgl = stp_req->type.pio.request_current.sgl_pair->B.length - sgl_offset;
577 if (stp_req->type.pio.pio_transfer_bytes > 0) {
578 if (stp_req->type.pio.pio_transfer_bytes >= remaining_bytes_in_current_sgl) {
579 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = remaining_bytes_in_current_sgl */
580 status = scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, remaining_bytes_in_current_sgl);
581 if (status == SCI_SUCCESS) {
582 stp_req->type.pio.pio_transfer_bytes -= remaining_bytes_in_current_sgl;
584 /* update the current sgl, sgl_offset and save for future */
585 current_sgl = scic_sds_stp_request_pio_get_next_sgl(stp_req);
588 } else if (stp_req->type.pio.pio_transfer_bytes < remaining_bytes_in_current_sgl) {
589 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = type.pio.pio_transfer_bytes */
590 scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, stp_req->type.pio.pio_transfer_bytes);
592 if (status == SCI_SUCCESS) {
593 /* Sgl offset will be adjusted and saved for future */
594 sgl_offset += stp_req->type.pio.pio_transfer_bytes;
595 current_sgl->address_lower += stp_req->type.pio.pio_transfer_bytes;
596 stp_req->type.pio.pio_transfer_bytes = 0;
601 if (status == SCI_SUCCESS) {
602 stp_req->type.pio.request_current.sgl_offset = sgl_offset;
610 * @stp_request: The request that is used for the SGL processing.
611 * @data_buffer: The buffer of data to be copied.
612 * @length: The length of the data transfer.
614 * Copy the data from the buffer for the length specified to the IO reqeust SGL
615 * specified data region. enum sci_status
617 static enum sci_status
618 scic_sds_stp_request_pio_data_in_copy_data_buffer(struct scic_sds_stp_request *stp_req,
619 u8 *data_buf, u32 len)
621 struct scic_sds_request *sci_req;
622 struct isci_request *ireq;
625 struct sas_task *task;
626 struct scatterlist *sg;
630 sci_req = to_sci_req(stp_req);
631 ireq = sci_req_to_ireq(sci_req);
632 task = isci_request_access_task(ireq);
635 if (task->num_scatter > 0) {
638 while (total_len > 0) {
639 struct page *page = sg_page(sg);
641 copy_len = min_t(int, total_len, sg_dma_len(sg));
642 kaddr = kmap_atomic(page, KM_IRQ0);
643 memcpy(kaddr + sg->offset, src_addr, copy_len);
644 kunmap_atomic(kaddr, KM_IRQ0);
645 total_len -= copy_len;
646 src_addr += copy_len;
650 BUG_ON(task->total_xfer_len < total_len);
651 memcpy(task->scatter, src_addr, total_len);
659 * @sci_req: The PIO DATA IN request that is to receive the data.
660 * @data_buffer: The buffer to copy from.
662 * Copy the data buffer to the io request data region. enum sci_status
664 static enum sci_status scic_sds_stp_request_pio_data_in_copy_data(
665 struct scic_sds_stp_request *sci_req,
668 enum sci_status status;
671 * If there is less than 1K remaining in the transfer request
672 * copy just the data for the transfer */
673 if (sci_req->type.pio.pio_transfer_bytes < SCU_MAX_FRAME_BUFFER_SIZE) {
674 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
675 sci_req, data_buffer, sci_req->type.pio.pio_transfer_bytes);
677 if (status == SCI_SUCCESS)
678 sci_req->type.pio.pio_transfer_bytes = 0;
680 /* We are transfering the whole frame so copy */
681 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
682 sci_req, data_buffer, SCU_MAX_FRAME_BUFFER_SIZE);
684 if (status == SCI_SUCCESS)
685 sci_req->type.pio.pio_transfer_bytes -= SCU_MAX_FRAME_BUFFER_SIZE;
698 static enum sci_status scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler(
699 struct scic_sds_request *sci_req,
702 enum sci_status status = SCI_SUCCESS;
704 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
705 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
706 scic_sds_request_set_status(
707 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
710 sci_base_state_machine_change_state(
711 &sci_req->started_substate_machine,
712 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
718 * All other completion status cause the IO to be complete. If a NAK
719 * was received, then it is up to the user to retry the request. */
720 scic_sds_request_set_status(
722 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
723 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
726 sci_base_state_machine_change_state(
727 &sci_req->state_machine,
728 SCI_BASE_REQUEST_STATE_COMPLETED
736 static enum sci_status scic_sds_stp_request_pio_await_frame_frame_handler(struct scic_sds_request *sci_req,
739 struct scic_sds_controller *scic = sci_req->owning_controller;
740 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
741 struct isci_request *ireq = sci_req_to_ireq(sci_req);
742 struct sas_task *task = isci_request_access_task(ireq);
743 struct dev_to_host_fis *frame_header;
744 enum sci_status status;
747 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
749 (void **)&frame_header);
751 if (status != SCI_SUCCESS) {
752 dev_err(scic_to_dev(scic),
753 "%s: SCIC IO Request 0x%p could not get frame header "
754 "for frame index %d, status %x\n",
755 __func__, stp_req, frame_index, status);
759 switch (frame_header->fis_type) {
761 /* Get from the frame buffer the PIO Setup Data */
762 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
764 (void **)&frame_buffer);
766 /* Get the data from the PIO Setup The SCU Hardware returns
767 * first word in the frame_header and the rest of the data is in
768 * the frame buffer so we need to back up one dword
771 /* transfer_count: first 16bits in the 4th dword */
772 stp_req->type.pio.pio_transfer_bytes = frame_buffer[3] & 0xffff;
774 /* ending_status: 4th byte in the 3rd dword */
775 stp_req->type.pio.ending_status = (frame_buffer[2] >> 24) & 0xff;
777 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
781 sci_req->stp.rsp.status = stp_req->type.pio.ending_status;
783 /* The next state is dependent on whether the
784 * request was PIO Data-in or Data out
786 if (task->data_dir == DMA_FROM_DEVICE) {
787 sci_base_state_machine_change_state(&sci_req->started_substate_machine,
788 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE);
789 } else if (task->data_dir == DMA_TO_DEVICE) {
791 status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
792 if (status != SCI_SUCCESS)
794 sci_base_state_machine_change_state(&sci_req->started_substate_machine,
795 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE);
799 sci_base_state_machine_change_state(&sci_req->started_substate_machine,
800 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
803 if (frame_header->status & ATA_BUSY) {
804 /* Now why is the drive sending a D2H Register FIS when
805 * it is still busy? Do nothing since we are still in
808 dev_dbg(scic_to_dev(scic),
809 "%s: SCIC PIO Request 0x%p received "
810 "D2H Register FIS with BSY status "
811 "0x%x\n", __func__, stp_req,
812 frame_header->status);
816 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
818 (void **)&frame_buffer);
820 scic_sds_controller_copy_sata_response(&sci_req->stp.req,
824 scic_sds_request_set_status(sci_req,
825 SCU_TASK_DONE_CHECK_RESPONSE,
826 SCI_FAILURE_IO_RESPONSE_VALID);
828 sci_base_state_machine_change_state(&sci_req->state_machine,
829 SCI_BASE_REQUEST_STATE_COMPLETED);
832 /* FIXME: what do we do here? */
836 /* Frame is decoded return it to the controller */
837 scic_sds_controller_release_frame(scic, frame_index);
842 static enum sci_status scic_sds_stp_request_pio_data_in_await_data_frame_handler(struct scic_sds_request *sci_req,
845 enum sci_status status;
846 struct dev_to_host_fis *frame_header;
847 struct sata_fis_data *frame_buffer;
848 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
849 struct scic_sds_controller *scic = sci_req->owning_controller;
851 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
853 (void **)&frame_header);
855 if (status != SCI_SUCCESS) {
856 dev_err(scic_to_dev(scic),
857 "%s: SCIC IO Request 0x%p could not get frame header "
858 "for frame index %d, status %x\n",
859 __func__, stp_req, frame_index, status);
863 if (frame_header->fis_type == FIS_DATA) {
864 if (stp_req->type.pio.request_current.sgl_pair == NULL) {
865 sci_req->saved_rx_frame_index = frame_index;
866 stp_req->type.pio.pio_transfer_bytes = 0;
868 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
870 (void **)&frame_buffer);
872 status = scic_sds_stp_request_pio_data_in_copy_data(stp_req,
875 /* Frame is decoded return it to the controller */
876 scic_sds_controller_release_frame(scic, frame_index);
879 /* Check for the end of the transfer, are there more
880 * bytes remaining for this data transfer
882 if (status != SCI_SUCCESS ||
883 stp_req->type.pio.pio_transfer_bytes != 0)
886 if ((stp_req->type.pio.ending_status & ATA_BUSY) == 0) {
887 scic_sds_request_set_status(sci_req,
888 SCU_TASK_DONE_CHECK_RESPONSE,
889 SCI_FAILURE_IO_RESPONSE_VALID);
891 sci_base_state_machine_change_state(&sci_req->state_machine,
892 SCI_BASE_REQUEST_STATE_COMPLETED);
894 sci_base_state_machine_change_state(&sci_req->started_substate_machine,
895 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
898 dev_err(scic_to_dev(scic),
899 "%s: SCIC PIO Request 0x%p received frame %d "
900 "with fis type 0x%02x when expecting a data "
901 "fis.\n", __func__, stp_req, frame_index,
902 frame_header->fis_type);
904 scic_sds_request_set_status(sci_req,
906 SCI_FAILURE_IO_REQUIRES_SCSI_ABORT);
908 sci_base_state_machine_change_state(&sci_req->state_machine,
909 SCI_BASE_REQUEST_STATE_COMPLETED);
911 /* Frame is decoded return it to the controller */
912 scic_sds_controller_release_frame(scic, frame_index);
926 static enum sci_status scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler(
928 struct scic_sds_request *sci_req,
931 enum sci_status status = SCI_SUCCESS;
932 bool all_frames_transferred = false;
933 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
935 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
936 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
938 if (stp_req->type.pio.pio_transfer_bytes != 0) {
939 status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
940 if (status == SCI_SUCCESS) {
941 if (stp_req->type.pio.pio_transfer_bytes == 0)
942 all_frames_transferred = true;
944 } else if (stp_req->type.pio.pio_transfer_bytes == 0) {
946 * this will happen if the all data is written at the
947 * first time after the pio setup fis is received
949 all_frames_transferred = true;
952 /* all data transferred. */
953 if (all_frames_transferred) {
955 * Change the state to SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_FRAME_SUBSTATE
956 * and wait for PIO_SETUP fis / or D2H REg fis. */
957 sci_base_state_machine_change_state(
958 &sci_req->started_substate_machine,
959 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
966 * All other completion status cause the IO to be complete. If a NAK
967 * was received, then it is up to the user to retry the request. */
968 scic_sds_request_set_status(
970 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
971 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
974 sci_base_state_machine_change_state(
975 &sci_req->state_machine,
976 SCI_BASE_REQUEST_STATE_COMPLETED
986 * @request: This is the request which is receiving the event.
987 * @event_code: This is the event code that the request on which the request is
988 * expected to take action.
990 * This method will handle any link layer events while waiting for the data
991 * frame. enum sci_status SCI_SUCCESS SCI_FAILURE
993 static enum sci_status scic_sds_stp_request_pio_data_in_await_data_event_handler(
994 struct scic_sds_request *request,
997 enum sci_status status;
999 switch (scu_get_event_specifier(event_code)) {
1000 case SCU_TASK_DONE_CRC_ERR << SCU_EVENT_SPECIFIC_CODE_SHIFT:
1002 * We are waiting for data and the SCU has R_ERR the data frame.
1003 * Go back to waiting for the D2H Register FIS */
1004 sci_base_state_machine_change_state(
1005 &request->started_substate_machine,
1006 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1009 status = SCI_SUCCESS;
1013 dev_err(scic_to_dev(request->owning_controller),
1014 "%s: SCIC PIO Request 0x%p received unexpected "
1016 __func__, request, event_code);
1018 /* / @todo Should we fail the PIO request when we get an unexpected event? */
1019 status = SCI_FAILURE;
1026 /* --------------------------------------------------------------------------- */
1028 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_pio_substate_handler_table[] = {
1029 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE] = {
1030 .abort_handler = scic_sds_request_started_state_abort_handler,
1031 .tc_completion_handler = scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler,
1033 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE] = {
1034 .abort_handler = scic_sds_request_started_state_abort_handler,
1035 .frame_handler = scic_sds_stp_request_pio_await_frame_frame_handler
1037 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE] = {
1038 .abort_handler = scic_sds_request_started_state_abort_handler,
1039 .event_handler = scic_sds_stp_request_pio_data_in_await_data_event_handler,
1040 .frame_handler = scic_sds_stp_request_pio_data_in_await_data_frame_handler
1042 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE] = {
1043 .abort_handler = scic_sds_request_started_state_abort_handler,
1044 .tc_completion_handler = scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler,
1048 static void scic_sds_stp_request_started_pio_await_h2d_completion_enter(
1051 struct scic_sds_request *sci_req = object;
1055 scic_sds_stp_request_started_pio_substate_handler_table,
1056 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
1059 scic_sds_remote_device_set_working_request(
1060 sci_req->target_device, sci_req);
1063 static void scic_sds_stp_request_started_pio_await_frame_enter(void *object)
1065 struct scic_sds_request *sci_req = object;
1069 scic_sds_stp_request_started_pio_substate_handler_table,
1070 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1074 static void scic_sds_stp_request_started_pio_data_in_await_data_enter(
1077 struct scic_sds_request *sci_req = object;
1081 scic_sds_stp_request_started_pio_substate_handler_table,
1082 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
1086 static void scic_sds_stp_request_started_pio_data_out_transmit_data_enter(
1089 struct scic_sds_request *sci_req = object;
1093 scic_sds_stp_request_started_pio_substate_handler_table,
1094 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
1098 /* --------------------------------------------------------------------------- */
1100 static const struct sci_base_state scic_sds_stp_request_started_pio_substate_table[] = {
1101 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE] = {
1102 .enter_state = scic_sds_stp_request_started_pio_await_h2d_completion_enter,
1104 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE] = {
1105 .enter_state = scic_sds_stp_request_started_pio_await_frame_enter,
1107 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE] = {
1108 .enter_state = scic_sds_stp_request_started_pio_data_in_await_data_enter,
1110 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE] = {
1111 .enter_state = scic_sds_stp_request_started_pio_data_out_transmit_data_enter,
1116 scic_sds_stp_pio_request_construct(struct scic_sds_request *sci_req,
1119 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
1120 struct scic_sds_stp_pio_request *pio = &stp_req->type.pio;
1122 scic_sds_stp_non_ncq_request_construct(sci_req);
1124 scu_stp_raw_request_construct_task_context(stp_req,
1125 sci_req->task_context_buffer);
1127 pio->current_transfer_bytes = 0;
1128 pio->ending_error = 0;
1129 pio->ending_status = 0;
1131 pio->request_current.sgl_offset = 0;
1132 pio->request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_A;
1134 if (copy_rx_frame) {
1135 scic_sds_request_build_sgl(sci_req);
1136 /* Since the IO request copy of the TC contains the same data as
1137 * the actual TC this pointer is vaild for either.
1139 pio->request_current.sgl_pair = &sci_req->task_context_buffer->sgl_pair_ab;
1141 /* The user does not want the data copied to the SGL buffer location */
1142 pio->request_current.sgl_pair = NULL;
1145 sci_base_state_machine_construct(&sci_req->started_substate_machine,
1147 scic_sds_stp_request_started_pio_substate_table,
1148 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE);
1153 static void scic_sds_stp_request_udma_complete_request(
1154 struct scic_sds_request *request,
1156 enum sci_status sci_status)
1158 scic_sds_request_set_status(request, scu_status, sci_status);
1159 sci_base_state_machine_change_state(&request->state_machine,
1160 SCI_BASE_REQUEST_STATE_COMPLETED);
1163 static enum sci_status scic_sds_stp_request_udma_general_frame_handler(struct scic_sds_request *sci_req,
1166 struct scic_sds_controller *scic = sci_req->owning_controller;
1167 struct dev_to_host_fis *frame_header;
1168 enum sci_status status;
1171 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1173 (void **)&frame_header);
1175 if ((status == SCI_SUCCESS) &&
1176 (frame_header->fis_type == FIS_REGD2H)) {
1177 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1179 (void **)&frame_buffer);
1181 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
1186 scic_sds_controller_release_frame(scic, frame_index);
1191 static enum sci_status scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler(
1192 struct scic_sds_request *sci_req,
1193 u32 completion_code)
1195 enum sci_status status = SCI_SUCCESS;
1197 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1198 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1199 scic_sds_stp_request_udma_complete_request(sci_req,
1203 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS):
1204 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
1206 * We must check ther response buffer to see if the D2H Register FIS was
1207 * received before we got the TC completion. */
1208 if (sci_req->stp.rsp.fis_type == FIS_REGD2H) {
1209 scic_sds_remote_device_suspend(sci_req->target_device,
1210 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
1212 scic_sds_stp_request_udma_complete_request(sci_req,
1213 SCU_TASK_DONE_CHECK_RESPONSE,
1214 SCI_FAILURE_IO_RESPONSE_VALID);
1217 * If we have an error completion status for the TC then we can expect a
1218 * D2H register FIS from the device so we must change state to wait for it */
1219 sci_base_state_machine_change_state(&sci_req->started_substate_machine,
1220 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE);
1225 * / @todo Check to see if any of these completion status need to wait for
1226 * / the device to host register fis. */
1227 /* / @todo We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR - this comes only for B0 */
1228 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN):
1229 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
1230 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR):
1231 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR):
1232 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR):
1233 scic_sds_remote_device_suspend(sci_req->target_device,
1234 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
1235 /* Fall through to the default case */
1237 /* All other completion status cause the IO to be complete. */
1238 scic_sds_stp_request_udma_complete_request(sci_req,
1239 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1240 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1247 static enum sci_status scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler(
1248 struct scic_sds_request *sci_req,
1251 enum sci_status status;
1253 /* Use the general frame handler to copy the resposne data */
1254 status = scic_sds_stp_request_udma_general_frame_handler(sci_req, frame_index);
1256 if (status != SCI_SUCCESS)
1259 scic_sds_stp_request_udma_complete_request(sci_req,
1260 SCU_TASK_DONE_CHECK_RESPONSE,
1261 SCI_FAILURE_IO_RESPONSE_VALID);
1266 /* --------------------------------------------------------------------------- */
1268 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_udma_substate_handler_table[] = {
1269 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE] = {
1270 .abort_handler = scic_sds_request_started_state_abort_handler,
1271 .tc_completion_handler = scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler,
1272 .frame_handler = scic_sds_stp_request_udma_general_frame_handler,
1274 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE] = {
1275 .abort_handler = scic_sds_request_started_state_abort_handler,
1276 .frame_handler = scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler,
1280 static void scic_sds_stp_request_started_udma_await_tc_completion_enter(
1283 struct scic_sds_request *sci_req = object;
1287 scic_sds_stp_request_started_udma_substate_handler_table,
1288 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
1295 * This state is entered when there is an TC completion failure. The hardware
1296 * received an unexpected condition while processing the IO request and now
1297 * will UF the D2H register FIS to complete the IO.
1299 static void scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter(
1302 struct scic_sds_request *sci_req = object;
1306 scic_sds_stp_request_started_udma_substate_handler_table,
1307 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
1311 /* --------------------------------------------------------------------------- */
1313 static const struct sci_base_state scic_sds_stp_request_started_udma_substate_table[] = {
1314 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE] = {
1315 .enter_state = scic_sds_stp_request_started_udma_await_tc_completion_enter,
1317 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE] = {
1318 .enter_state = scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter,
1322 enum sci_status scic_sds_stp_udma_request_construct(struct scic_sds_request *sci_req,
1324 enum dma_data_direction dir)
1326 scic_sds_stp_non_ncq_request_construct(sci_req);
1328 scic_sds_stp_optimized_request_construct(sci_req, SCU_TASK_TYPE_DMA_IN,
1331 sci_base_state_machine_construct(
1332 &sci_req->started_substate_machine,
1334 scic_sds_stp_request_started_udma_substate_table,
1335 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
1346 * This method processes a TC completion. The expected TC completion is for
1347 * the transmission of the H2D register FIS containing the SATA/STP non-data
1348 * request. This method always successfully processes the TC completion.
1349 * SCI_SUCCESS This value is always returned.
1351 static enum sci_status scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler(
1352 struct scic_sds_request *sci_req,
1353 u32 completion_code)
1355 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1356 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1357 scic_sds_request_set_status(
1358 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1361 sci_base_state_machine_change_state(
1362 &sci_req->started_substate_machine,
1363 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
1369 * All other completion status cause the IO to be complete. If a NAK
1370 * was received, then it is up to the user to retry the request. */
1371 scic_sds_request_set_status(
1373 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1374 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1377 sci_base_state_machine_change_state(
1378 &sci_req->state_machine, SCI_BASE_REQUEST_STATE_COMPLETED);
1390 * This method processes a TC completion. The expected TC completion is for
1391 * the transmission of the H2D register FIS containing the SATA/STP non-data
1392 * request. This method always successfully processes the TC completion.
1393 * SCI_SUCCESS This value is always returned.
1395 static enum sci_status scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler(
1396 struct scic_sds_request *sci_req,
1397 u32 completion_code)
1399 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1400 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1401 scic_sds_request_set_status(
1402 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1405 sci_base_state_machine_change_state(
1406 &sci_req->started_substate_machine,
1407 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
1413 * All other completion status cause the IO to be complete. If a NAK
1414 * was received, then it is up to the user to retry the request. */
1415 scic_sds_request_set_status(
1417 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1418 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1421 sci_base_state_machine_change_state(&sci_req->state_machine,
1422 SCI_BASE_REQUEST_STATE_COMPLETED);
1431 * @request: This parameter specifies the request for which a frame has been
1433 * @frame_index: This parameter specifies the index of the frame that has been
1436 * This method processes frames received from the target while waiting for a
1437 * device to host register FIS. If a non-register FIS is received during this
1438 * time, it is treated as a protocol violation from an IO perspective. Indicate
1439 * if the received frame was processed successfully.
1441 static enum sci_status scic_sds_stp_request_soft_reset_await_d2h_frame_handler(
1442 struct scic_sds_request *sci_req,
1445 enum sci_status status;
1446 struct dev_to_host_fis *frame_header;
1448 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
1449 struct scic_sds_controller *scic = sci_req->owning_controller;
1451 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1453 (void **)&frame_header);
1454 if (status != SCI_SUCCESS) {
1455 dev_err(scic_to_dev(scic),
1456 "%s: SCIC IO Request 0x%p could not get frame header "
1457 "for frame index %d, status %x\n",
1458 __func__, stp_req, frame_index, status);
1462 switch (frame_header->fis_type) {
1464 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1466 (void **)&frame_buffer);
1468 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
1472 /* The command has completed with error */
1473 scic_sds_request_set_status(sci_req,
1474 SCU_TASK_DONE_CHECK_RESPONSE,
1475 SCI_FAILURE_IO_RESPONSE_VALID);
1479 dev_warn(scic_to_dev(scic),
1480 "%s: IO Request:0x%p Frame Id:%d protocol "
1481 "violation occurred\n", __func__, stp_req,
1484 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_UNEXP_FIS,
1485 SCI_FAILURE_PROTOCOL_VIOLATION);
1489 sci_base_state_machine_change_state(&sci_req->state_machine,
1490 SCI_BASE_REQUEST_STATE_COMPLETED);
1492 /* Frame has been decoded return it to the controller */
1493 scic_sds_controller_release_frame(scic, frame_index);
1498 /* --------------------------------------------------------------------------- */
1500 static const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_soft_reset_substate_handler_table[] = {
1501 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE] = {
1502 .abort_handler = scic_sds_request_started_state_abort_handler,
1503 .tc_completion_handler = scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler,
1505 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE] = {
1506 .abort_handler = scic_sds_request_started_state_abort_handler,
1507 .tc_completion_handler = scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler,
1509 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE] = {
1510 .abort_handler = scic_sds_request_started_state_abort_handler,
1511 .frame_handler = scic_sds_stp_request_soft_reset_await_d2h_frame_handler,
1515 static void scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter(
1518 struct scic_sds_request *sci_req = object;
1522 scic_sds_stp_request_started_soft_reset_substate_handler_table,
1523 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
1526 scic_sds_remote_device_set_working_request(
1527 sci_req->target_device, sci_req
1531 static void scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter(
1534 struct scic_sds_request *sci_req = object;
1535 struct scu_task_context *task_context;
1536 struct host_to_dev_fis *h2d_fis;
1537 enum sci_status status;
1539 /* Clear the SRST bit */
1540 h2d_fis = &sci_req->stp.cmd;
1541 h2d_fis->control = 0;
1543 /* Clear the TC control bit */
1544 task_context = scic_sds_controller_get_task_context_buffer(
1545 sci_req->owning_controller, sci_req->io_tag);
1546 task_context->control_frame = 0;
1548 status = scic_controller_continue_io(sci_req);
1549 if (status == SCI_SUCCESS) {
1552 scic_sds_stp_request_started_soft_reset_substate_handler_table,
1553 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
1558 static void scic_sds_stp_request_started_soft_reset_await_d2h_response_enter(
1561 struct scic_sds_request *sci_req = object;
1565 scic_sds_stp_request_started_soft_reset_substate_handler_table,
1566 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
1570 static const struct sci_base_state scic_sds_stp_request_started_soft_reset_substate_table[] = {
1571 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE] = {
1572 .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter,
1574 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE] = {
1575 .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter,
1577 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE] = {
1578 .enter_state = scic_sds_stp_request_started_soft_reset_await_d2h_response_enter,
1582 enum sci_status scic_sds_stp_soft_reset_request_construct(struct scic_sds_request *sci_req)
1584 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
1586 scic_sds_stp_non_ncq_request_construct(sci_req);
1588 /* Build the STP task context structure */
1589 scu_stp_raw_request_construct_task_context(stp_req, sci_req->task_context_buffer);
1591 sci_base_state_machine_construct(&sci_req->started_substate_machine,
1593 scic_sds_stp_request_started_soft_reset_substate_table,
1594 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE);