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.
57 #include "intel_ata.h"
58 #include "intel_sata.h"
59 #include "intel_sat.h"
60 #include "sci_base_state.h"
61 #include "sci_base_state_machine.h"
62 #include "scic_io_request.h"
63 #include "scic_remote_device.h"
64 #include "scic_sds_controller.h"
65 #include "scic_sds_remote_device.h"
66 #include "scic_sds_request.h"
67 #include "scic_sds_stp_pio_request.h"
68 #include "scic_sds_stp_request.h"
69 #include "scic_sds_unsolicited_frame_control.h"
70 #include "scic_user_callback.h"
71 #include "sci_environment.h"
72 #include "sci_types.h"
74 #include "scu_completion_codes.h"
75 #include "scu_event_codes.h"
76 #include "scu_task_context.h"
79 * scic_sds_stp_request_get_h2d_reg_buffer() -
81 * This macro returns the address of the stp h2d reg fis buffer in the io
84 #define scic_sds_stp_request_get_h2d_reg_buffer(memory) \
85 ((struct sata_fis_reg_h2d *)(\
86 ((char *)(memory)) + sizeof(struct scic_sds_stp_request) \
90 * scic_sds_stp_request_get_response_buffer() -
92 * This macro returns the address of the ssp response iu buffer in the io
95 #define scic_sds_stp_request_get_response_buffer(memory) \
96 ((struct sata_fis_reg_d2h *)(\
97 ((char *)(scic_sds_stp_request_get_h2d_reg_buffer(memory))) \
98 + sizeof(struct sata_fis_reg_h2d) \
102 * scic_sds_stp_request_get_task_context_buffer() -
104 * This macro returns the address of the task context buffer in the io request
107 #define scic_sds_stp_request_get_task_context_buffer(memory) \
108 ((struct scu_task_context *)(\
109 ((char *)(scic_sds_stp_request_get_response_buffer(memory))) \
110 + sizeof(struct sci_ssp_response_iu) \
114 * scic_sds_stp_request_get_sgl_element_buffer() -
116 * This macro returns the address of the sgl elment pairs in the io request
119 #define scic_sds_stp_request_get_sgl_element_buffer(memory) \
120 ((struct scu_sgl_element_pair *)(\
121 ((char *)(scic_sds_stp_request_get_task_context_buffer(memory))) \
122 + sizeof(struct scu_task_context) \
128 * This method return the memory space required for STP PIO requests. u32
130 u32 scic_sds_stp_request_get_object_size(void)
132 return sizeof(struct scic_sds_stp_request)
133 + sizeof(struct sata_fis_reg_h2d)
134 + sizeof(struct sata_fis_reg_d2h)
135 + sizeof(struct scu_task_context)
136 + sizeof(struct scu_sgl_element_pair) * SCU_MAX_SGL_ELEMENT_PAIRS;
144 void scic_sds_stp_request_assign_buffers(
145 struct scic_sds_request *request)
147 struct scic_sds_stp_request *this_request = (struct scic_sds_stp_request *)request;
149 this_request->parent.command_buffer =
150 scic_sds_stp_request_get_h2d_reg_buffer(this_request);
151 this_request->parent.response_buffer =
152 scic_sds_stp_request_get_response_buffer(this_request);
153 this_request->parent.sgl_element_pair_buffer =
154 scic_sds_stp_request_get_sgl_element_buffer(this_request);
155 this_request->parent.sgl_element_pair_buffer =
156 scic_sds_request_align_sgl_element_buffer(this_request->parent.sgl_element_pair_buffer);
158 if (this_request->parent.was_tag_assigned_by_user == false) {
159 this_request->parent.task_context_buffer =
160 scic_sds_stp_request_get_task_context_buffer(this_request);
161 this_request->parent.task_context_buffer =
162 scic_sds_request_align_task_context_buffer(this_request->parent.task_context_buffer);
167 * This method is will fill in the SCU Task Context for any type of SATA
168 * request. This is called from the various SATA constructors.
169 * @this_request: The general IO request object which is to be used in
170 * constructing the SCU task context.
171 * @task_context: The buffer pointer for the SCU task context which is being
174 * The general io request construction is complete. The buffer assignment for
175 * the command buffer is complete. none Revisit task context construction to
176 * determine what is common for SSP/SMP/STP task context structures.
178 static void scu_sata_reqeust_construct_task_context(
179 struct scic_sds_request *this_request,
180 struct scu_task_context *task_context)
182 dma_addr_t physical_address;
183 struct scic_sds_controller *owning_controller;
184 struct scic_sds_remote_device *target_device;
185 struct scic_sds_port *target_port;
187 owning_controller = scic_sds_request_get_controller(this_request);
188 target_device = scic_sds_request_get_device(this_request);
189 target_port = scic_sds_request_get_port(this_request);
191 /* Fill in the TC with the its required data */
192 task_context->abort = 0;
193 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
194 task_context->initiator_request = 1;
195 task_context->connection_rate =
196 scic_remote_device_get_connection_rate(target_device);
197 task_context->protocol_engine_index =
198 scic_sds_controller_get_protocol_engine_group(owning_controller);
199 task_context->logical_port_index =
200 scic_sds_port_get_index(target_port);
201 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_STP;
202 task_context->valid = SCU_TASK_CONTEXT_VALID;
203 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
205 task_context->remote_node_index =
206 scic_sds_remote_device_get_index(this_request->target_device);
207 task_context->command_code = 0;
209 task_context->link_layer_control = 0;
210 task_context->do_not_dma_ssp_good_response = 1;
211 task_context->strict_ordering = 0;
212 task_context->control_frame = 0;
213 task_context->timeout_enable = 0;
214 task_context->block_guard_enable = 0;
216 task_context->address_modifier = 0;
217 task_context->task_phase = 0x01;
219 task_context->ssp_command_iu_length =
220 (sizeof(struct sata_fis_reg_h2d) - sizeof(u32)) / sizeof(u32);
222 /* Set the first word of the H2D REG FIS */
223 task_context->type.words[0] = *(u32 *)this_request->command_buffer;
225 if (this_request->was_tag_assigned_by_user) {
226 /* Build the task context now since we have already read the data */
227 this_request->post_context = (
228 SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
230 scic_sds_controller_get_protocol_engine_group(owning_controller)
231 << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
234 scic_sds_port_get_index(target_port)
235 << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
237 | scic_sds_io_tag_get_index(this_request->io_tag)
240 /* Build the task context now since we have already read the data */
241 this_request->post_context = (
242 SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
244 scic_sds_controller_get_protocol_engine_group(owning_controller)
245 << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
248 scic_sds_port_get_index(target_port)
249 << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
251 /* This is not assigned because we have to wait until we get a TCi */
256 * Copy the physical address for the command buffer to the SCU Task Context
257 * We must offset the command buffer by 4 bytes because the first 4 bytes are
258 * transfered in the body of the TC */
259 scic_cb_io_request_get_physical_address(
260 scic_sds_request_get_controller(this_request),
262 ((char *)this_request->command_buffer) + sizeof(u32),
266 task_context->command_iu_upper =
267 upper_32_bits(physical_address);
268 task_context->command_iu_lower =
269 lower_32_bits(physical_address);
271 /* SATA Requests do not have a response buffer */
272 task_context->response_iu_upper = 0;
273 task_context->response_iu_lower = 0;
280 * This method will perform any general sata request construction. What part of
281 * SATA IO request construction is general? none
283 void scic_sds_stp_non_ncq_request_construct(
284 struct scic_sds_request *this_request)
286 this_request->has_started_substate_machine = true;
291 * @this_request: This parameter specifies the request to be constructed as an
293 * @optimized_task_type: This parameter specifies whether the request is to be
294 * an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A
295 * value of 1 indicates NCQ.
297 * This method will perform request construction common to all types of STP
298 * requests that are optimized by the silicon (i.e. UDMA, NCQ). This method
299 * returns an indication as to whether the construction was successful.
301 static void scic_sds_stp_optimized_request_construct(
302 struct scic_sds_request *this_request,
303 u8 optimized_task_type,
305 SCI_IO_REQUEST_DATA_DIRECTION data_direction)
307 struct scu_task_context *task_context = this_request->task_context_buffer;
309 /* Build the STP task context structure */
310 scu_sata_reqeust_construct_task_context(this_request, task_context);
312 /* Copy over the SGL elements */
313 scic_sds_request_build_sgl(this_request);
315 /* Copy over the number of bytes to be transfered */
316 task_context->transfer_length_bytes = transfer_length;
318 if (data_direction == SCI_IO_REQUEST_DATA_OUT) {
320 * The difference between the DMA IN and DMA OUT request task type
321 * values are consistent with the difference between FPDMA READ
322 * and FPDMA WRITE values. Add the supplied task type parameter
323 * to this difference to set the task type properly for this
324 * DATA OUT (WRITE) case. */
325 task_context->task_type = optimized_task_type + (SCU_TASK_TYPE_DMA_OUT
326 - SCU_TASK_TYPE_DMA_IN);
329 * For the DATA IN (READ) case, simply save the supplied
330 * optimized task type. */
331 task_context->task_type = optimized_task_type;
337 * @this_request: This parameter specifies the request to be constructed.
339 * This method will construct the STP UDMA request and its associated TC data.
340 * This method returns an indication as to whether the construction was
341 * successful. SCI_SUCCESS Currently this method always returns this value.
343 enum sci_status scic_sds_stp_udma_request_construct(
344 struct scic_sds_request *this_request,
346 SCI_IO_REQUEST_DATA_DIRECTION data_direction)
348 scic_sds_stp_non_ncq_request_construct(this_request);
350 scic_sds_stp_optimized_request_construct(
352 SCU_TASK_TYPE_DMA_IN,
357 sci_base_state_machine_construct(
358 &this_request->started_substate_machine,
359 &this_request->parent.parent,
360 scic_sds_stp_request_started_udma_substate_table,
361 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
369 * @this_request: This parameter specifies the request to be constructed.
371 * This method will construct the STP UDMA request and its associated TC data.
372 * This method returns an indication as to whether the construction was
373 * successful. SCI_SUCCESS Currently this method always returns this value.
375 enum sci_status scic_sds_stp_ncq_request_construct(
376 struct scic_sds_request *this_request,
378 SCI_IO_REQUEST_DATA_DIRECTION data_direction)
380 scic_sds_stp_optimized_request_construct(
382 SCU_TASK_TYPE_FPDMAQ_READ,
391 * @this_request: This parameter specifies the STP request object for which to
392 * construct a RAW command frame task context.
393 * @task_context: This parameter specifies the SCU specific task context buffer
396 * This method performs the operations common to all SATA/STP requests
397 * utilizing the raw frame method. none
399 void scu_stp_raw_request_construct_task_context(
400 struct scic_sds_stp_request *this_request,
401 struct scu_task_context *task_context)
403 scu_sata_reqeust_construct_task_context(&this_request->parent, task_context);
405 task_context->control_frame = 0;
406 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
407 task_context->task_type = SCU_TASK_TYPE_SATA_RAW_FRAME;
408 task_context->type.stp.fis_type = SATA_FIS_TYPE_REGH2D;
409 task_context->transfer_length_bytes = sizeof(struct sata_fis_reg_h2d) - sizeof(u32);
414 * @this_request: This parameter specifies the core request object to
415 * construction into an STP/SATA non-data request.
417 * This method will construct the STP Non-data request and its associated TC
418 * data. A non-data request essentially behaves like a 0 length read request
419 * in the SCU. This method currently always returns SCI_SUCCESS
421 enum sci_status scic_sds_stp_non_data_request_construct(
422 struct scic_sds_request *this_request)
424 scic_sds_stp_non_ncq_request_construct(this_request);
426 /* Build the STP task context structure */
427 scu_stp_raw_request_construct_task_context(
428 (struct scic_sds_stp_request *)this_request,
429 this_request->task_context_buffer
432 sci_base_state_machine_construct(
433 &this_request->started_substate_machine,
434 &this_request->parent.parent,
435 scic_sds_stp_request_started_non_data_substate_table,
436 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
443 enum sci_status scic_sds_stp_soft_reset_request_construct(
444 struct scic_sds_request *this_request)
446 scic_sds_stp_non_ncq_request_construct(this_request);
448 /* Build the STP task context structure */
449 scu_stp_raw_request_construct_task_context(
450 (struct scic_sds_stp_request *)this_request,
451 this_request->task_context_buffer
454 sci_base_state_machine_construct(
455 &this_request->started_substate_machine,
456 &this_request->parent.parent,
457 scic_sds_stp_request_started_soft_reset_substate_table,
458 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
465 void scic_stp_io_request_set_ncq_tag(
466 struct scic_sds_request *req,
470 * @note This could be made to return an error to the user if the user
471 * attempts to set the NCQ tag in the wrong state.
473 req->task_context_buffer->type.stp.ncq_tag = ncq_tag;
477 void *scic_stp_io_request_get_h2d_reg_address(
478 struct scic_sds_request *req)
480 return req->command_buffer;
484 void *scic_stp_io_request_get_d2h_reg_address(
485 struct scic_sds_request *req)
487 return &((struct scic_sds_stp_request *)req)->d2h_reg_fis;
494 * Get the next SGL element from the request. - Check on which SGL element pair
495 * we are working - if working on SLG pair element A - advance to element B -
496 * else - check to see if there are more SGL element pairs for this IO request
497 * - if there are more SGL element pairs - advance to the next pair and return
498 * element A struct scu_sgl_element*
500 struct scu_sgl_element *scic_sds_stp_request_pio_get_next_sgl(
501 struct scic_sds_stp_request *this_request
503 struct scu_sgl_element *current_sgl;
505 if (this_request->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
507 (this_request->type.pio.request_current.sgl_pair->B.address_lower == 0)
508 && (this_request->type.pio.request_current.sgl_pair->B.address_upper == 0)
512 this_request->type.pio.request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_B;
513 current_sgl = &(this_request->type.pio.request_current.sgl_pair->B);
517 (this_request->type.pio.request_current.sgl_pair->next_pair_lower == 0)
518 && (this_request->type.pio.request_current.sgl_pair->next_pair_upper == 0)
522 dma_addr_t physical_address;
524 sci_cb_make_physical_address(
526 this_request->type.pio.request_current.sgl_pair->next_pair_upper,
527 this_request->type.pio.request_current.sgl_pair->next_pair_lower
530 this_request->type.pio.request_current.sgl_pair =
531 (struct scu_sgl_element_pair *)scic_cb_get_virtual_address(
532 this_request->parent.owning_controller,
536 this_request->type.pio.request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_A;
538 current_sgl = &(this_request->type.pio.request_current.sgl_pair->A);
547 * @scic_io_request: The core request object which is cast to a SATA PIO
550 * This method will construct the SATA PIO request. This method returns an
551 * indication as to whether the construction was successful. SCI_SUCCESS
552 * Currently this method always returns this value.
554 enum sci_status scic_sds_stp_pio_request_construct(
555 struct scic_sds_request *scic_io_request,
559 struct scic_sds_stp_request *this_request;
561 this_request = (struct scic_sds_stp_request *)scic_io_request;
563 scic_sds_stp_non_ncq_request_construct(&this_request->parent);
565 scu_stp_raw_request_construct_task_context(
566 this_request, this_request->parent.task_context_buffer
569 this_request->type.pio.current_transfer_bytes = 0;
570 this_request->type.pio.ending_error = 0;
571 this_request->type.pio.ending_status = 0;
573 this_request->type.pio.request_current.sgl_offset = 0;
574 this_request->type.pio.request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_A;
575 this_request->type.pio.sat_protocol = sat_protocol;
578 scic_sds_request_build_sgl(&this_request->parent);
580 * Since the IO request copy of the TC contains the same data as
581 * the actual TC this pointer is vaild for either. */
582 this_request->type.pio.request_current.sgl_pair =
583 &this_request->parent.task_context_buffer->sgl_pair_ab;
585 /* The user does not want the data copied to the SGL buffer location */
586 this_request->type.pio.request_current.sgl_pair = NULL;
589 sci_base_state_machine_construct(
590 &this_request->parent.started_substate_machine,
591 &this_request->parent.parent.parent,
592 scic_sds_stp_request_started_pio_substate_table,
593 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
604 * This method processes a TC completion. The expected TC completion is for
605 * the transmission of the H2D register FIS containing the SATA/STP non-data
606 * request. This method always successfully processes the TC completion.
607 * SCI_SUCCESS This value is always returned.
609 static enum sci_status scic_sds_stp_request_non_data_await_h2d_tc_completion_handler(
610 struct scic_sds_request *this_request,
613 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
614 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
615 scic_sds_request_set_status(
616 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
619 sci_base_state_machine_change_state(
620 &this_request->started_substate_machine,
621 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
627 * All other completion status cause the IO to be complete. If a NAK
628 * was received, then it is up to the user to retry the request. */
629 scic_sds_request_set_status(
631 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
632 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
635 sci_base_state_machine_change_state(
636 &this_request->parent.state_machine, SCI_BASE_REQUEST_STATE_COMPLETED
646 * @request: This parameter specifies the request for which a frame has been
648 * @frame_index: This parameter specifies the index of the frame that has been
651 * This method processes frames received from the target while waiting for a
652 * device to host register FIS. If a non-register FIS is received during this
653 * time, it is treated as a protocol violation from an IO perspective. Indicate
654 * if the received frame was processed successfully.
656 static enum sci_status scic_sds_stp_request_non_data_await_d2h_frame_handler(
657 struct scic_sds_request *request,
660 enum sci_status status;
661 struct sata_fis_header *frame_header;
663 struct scic_sds_stp_request *this_request = (struct scic_sds_stp_request *)request;
665 status = scic_sds_unsolicited_frame_control_get_header(
666 &(this_request->parent.owning_controller->uf_control),
668 (void **)&frame_header
671 if (status == SCI_SUCCESS) {
672 switch (frame_header->fis_type) {
673 case SATA_FIS_TYPE_REGD2H:
674 scic_sds_unsolicited_frame_control_get_buffer(
675 &(this_request->parent.owning_controller->uf_control),
677 (void **)&frame_buffer
680 scic_sds_controller_copy_sata_response(
681 &this_request->d2h_reg_fis, (u32 *)frame_header, frame_buffer
684 /* The command has completed with error */
685 scic_sds_request_set_status(
686 &this_request->parent,
687 SCU_TASK_DONE_CHECK_RESPONSE,
688 SCI_FAILURE_IO_RESPONSE_VALID
693 dev_warn(scic_to_dev(request->owning_controller),
694 "%s: IO Request:0x%p Frame Id:%d protocol "
695 "violation occurred\n",
696 __func__, this_request, frame_index);
698 scic_sds_request_set_status(
699 &this_request->parent,
700 SCU_TASK_DONE_UNEXP_FIS,
701 SCI_FAILURE_PROTOCOL_VIOLATION
706 sci_base_state_machine_change_state(
707 &this_request->parent.parent.state_machine,
708 SCI_BASE_REQUEST_STATE_COMPLETED
711 /* Frame has been decoded return it to the controller */
712 scic_sds_controller_release_frame(
713 this_request->parent.owning_controller, frame_index
716 dev_err(scic_to_dev(request->owning_controller),
717 "%s: SCIC IO Request 0x%p could not get frame header "
718 "for frame index %d, status %x\n",
719 __func__, this_request, frame_index, status);
724 /* --------------------------------------------------------------------------- */
726 const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_non_data_substate_handler_table[] = {
727 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE] = {
728 .parent.start_handler = scic_sds_request_default_start_handler,
729 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
730 .parent.complete_handler = scic_sds_request_default_complete_handler,
731 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
732 .tc_completion_handler = scic_sds_stp_request_non_data_await_h2d_tc_completion_handler,
733 .event_handler = scic_sds_request_default_event_handler,
734 .frame_handler = scic_sds_request_default_frame_handler,
736 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE] = {
737 .parent.start_handler = scic_sds_request_default_start_handler,
738 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
739 .parent.complete_handler = scic_sds_request_default_complete_handler,
740 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
741 .tc_completion_handler = scic_sds_request_default_tc_completion_handler,
742 .event_handler = scic_sds_request_default_event_handler,
743 .frame_handler = scic_sds_stp_request_non_data_await_d2h_frame_handler,
747 static void scic_sds_stp_request_started_non_data_await_h2d_completion_enter(
748 struct sci_base_object *object)
750 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
754 scic_sds_stp_request_started_non_data_substate_handler_table,
755 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
758 scic_sds_remote_device_set_working_request(
759 this_request->target_device, this_request
763 static void scic_sds_stp_request_started_non_data_await_d2h_enter(
764 struct sci_base_object *object)
766 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
770 scic_sds_stp_request_started_non_data_substate_handler_table,
771 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
775 /* --------------------------------------------------------------------------- */
777 const struct sci_base_state scic_sds_stp_request_started_non_data_substate_table[] = {
778 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE] = {
779 .enter_state = scic_sds_stp_request_started_non_data_await_h2d_completion_enter,
781 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE] = {
782 .enter_state = scic_sds_stp_request_started_non_data_await_d2h_enter,
786 #define SCU_MAX_FRAME_BUFFER_SIZE 0x400 /* 1K is the maximum SCU frame data payload */
793 * This function will transmit DATA_FIS from (current sgl + offset) for input
794 * parameter length. current sgl and offset is alreay stored in the IO request
798 static enum sci_status scic_sds_stp_request_pio_data_out_trasmit_data_frame(
799 struct scic_sds_request *this_request,
802 struct scic_sds_stp_request *this_sds_stp_request = (struct scic_sds_stp_request *)this_request;
803 sci_base_controller_request_handler_t continue_io;
804 struct scu_sgl_element *current_sgl;
805 struct scic_sds_controller *scic;
809 * Recycle the TC and reconstruct it for sending out DATA FIS containing
810 * for the data from current_sgl+offset for the input length */
811 struct scu_task_context *task_context = scic_sds_controller_get_task_context_buffer(
812 this_request->owning_controller,
816 if (this_sds_stp_request->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A)
817 current_sgl = &(this_sds_stp_request->type.pio.request_current.sgl_pair->A);
819 current_sgl = &(this_sds_stp_request->type.pio.request_current.sgl_pair->B);
822 task_context->command_iu_upper = current_sgl->address_upper;
823 task_context->command_iu_lower = current_sgl->address_lower;
824 task_context->transfer_length_bytes = length;
825 task_context->type.stp.fis_type = SATA_FIS_TYPE_DATA;
827 /* send the new TC out. */
828 scic = this_request->owning_controller;
829 state = scic->parent.state_machine.current_state_id;
830 continue_io = scic_sds_controller_state_handler_table[state].base.continue_io;
831 return continue_io(&scic->parent, &this_request->target_device->parent,
832 &this_request->parent);
841 static enum sci_status scic_sds_stp_request_pio_data_out_transmit_data(
842 struct scic_sds_request *this_sds_request)
845 struct scu_sgl_element *current_sgl;
847 u32 remaining_bytes_in_current_sgl = 0;
848 enum sci_status status = SCI_SUCCESS;
850 struct scic_sds_stp_request *this_sds_stp_request = (struct scic_sds_stp_request *)this_sds_request;
852 sgl_offset = this_sds_stp_request->type.pio.request_current.sgl_offset;
854 if (this_sds_stp_request->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
855 current_sgl = &(this_sds_stp_request->type.pio.request_current.sgl_pair->A);
856 remaining_bytes_in_current_sgl = this_sds_stp_request->type.pio.request_current.sgl_pair->A.length - sgl_offset;
858 current_sgl = &(this_sds_stp_request->type.pio.request_current.sgl_pair->B);
859 remaining_bytes_in_current_sgl = this_sds_stp_request->type.pio.request_current.sgl_pair->B.length - sgl_offset;
863 if (this_sds_stp_request->type.pio.pio_transfer_bytes > 0) {
864 if (this_sds_stp_request->type.pio.pio_transfer_bytes >= remaining_bytes_in_current_sgl) {
865 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = remaining_bytes_in_current_sgl */
866 status = scic_sds_stp_request_pio_data_out_trasmit_data_frame(this_sds_request, remaining_bytes_in_current_sgl);
867 if (status == SCI_SUCCESS) {
868 this_sds_stp_request->type.pio.pio_transfer_bytes -= remaining_bytes_in_current_sgl;
870 /* update the current sgl, sgl_offset and save for future */
871 current_sgl = scic_sds_stp_request_pio_get_next_sgl(this_sds_stp_request);
874 } else if (this_sds_stp_request->type.pio.pio_transfer_bytes < remaining_bytes_in_current_sgl) {
875 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = type.pio.pio_transfer_bytes */
876 scic_sds_stp_request_pio_data_out_trasmit_data_frame(this_sds_request, this_sds_stp_request->type.pio.pio_transfer_bytes);
878 if (status == SCI_SUCCESS) {
879 /* Sgl offset will be adjusted and saved for future */
880 sgl_offset += this_sds_stp_request->type.pio.pio_transfer_bytes;
881 current_sgl->address_lower += this_sds_stp_request->type.pio.pio_transfer_bytes;
882 this_sds_stp_request->type.pio.pio_transfer_bytes = 0;
887 if (status == SCI_SUCCESS) {
888 this_sds_stp_request->type.pio.request_current.sgl_offset = sgl_offset;
896 * @this_request: The request that is used for the SGL processing.
897 * @data_buffer: The buffer of data to be copied.
898 * @length: The length of the data transfer.
900 * Copy the data from the buffer for the length specified to the IO reqeust SGL
901 * specified data region. enum sci_status
903 static enum sci_status scic_sds_stp_request_pio_data_in_copy_data_buffer(
904 struct scic_sds_stp_request *this_request,
908 enum sci_status status;
909 struct scu_sgl_element *current_sgl;
913 u8 *destination_address;
916 /* Initial setup to get the current working SGL and the offset within the buffer */
918 (this_request->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A) ?
919 &(this_request->type.pio.request_current.sgl_pair->A) :
920 &(this_request->type.pio.request_current.sgl_pair->B);
922 sgl_offset = this_request->type.pio.request_current.sgl_offset;
924 source_address = data_buffer;
927 status = SCI_SUCCESS;
929 /* While we are still doing Ok and there is more data to transfer */
932 && (status == SCI_SUCCESS)
934 if (current_sgl->length == sgl_offset) {
935 /* This SGL has been exauhasted so we need to get the next SGL */
936 current_sgl = scic_sds_stp_request_pio_get_next_sgl(this_request);
938 if (current_sgl == NULL)
939 status = SCI_FAILURE;
943 dma_addr_t physical_address;
945 sci_cb_make_physical_address(
947 current_sgl->address_upper,
948 current_sgl->address_lower
951 destination_address = (u8 *)scic_cb_get_virtual_address(
952 this_request->parent.owning_controller,
956 source_address += data_offset;
957 destination_address += sgl_offset;
959 copy_length = min(length, current_sgl->length - sgl_offset);
961 memcpy(destination_address, source_address, copy_length);
963 length -= copy_length;
964 sgl_offset += copy_length;
965 data_offset += copy_length;
969 this_request->type.pio.request_current.sgl_offset = sgl_offset;
976 * @this_request: The PIO DATA IN request that is to receive the data.
977 * @data_buffer: The buffer to copy from.
979 * Copy the data buffer to the io request data region. enum sci_status
981 static enum sci_status scic_sds_stp_request_pio_data_in_copy_data(
982 struct scic_sds_stp_request *this_request,
985 enum sci_status status;
988 * If there is less than 1K remaining in the transfer request
989 * copy just the data for the transfer */
990 if (this_request->type.pio.pio_transfer_bytes < SCU_MAX_FRAME_BUFFER_SIZE) {
991 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
992 this_request, data_buffer, this_request->type.pio.pio_transfer_bytes);
994 if (status == SCI_SUCCESS)
995 this_request->type.pio.pio_transfer_bytes = 0;
997 /* We are transfering the whole frame so copy */
998 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
999 this_request, data_buffer, SCU_MAX_FRAME_BUFFER_SIZE);
1001 if (status == SCI_SUCCESS)
1002 this_request->type.pio.pio_transfer_bytes -= SCU_MAX_FRAME_BUFFER_SIZE;
1015 static enum sci_status scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler(
1016 struct scic_sds_request *this_request,
1017 u32 completion_code)
1019 enum sci_status status = SCI_SUCCESS;
1021 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1022 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1023 scic_sds_request_set_status(
1024 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1027 sci_base_state_machine_change_state(
1028 &this_request->started_substate_machine,
1029 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1035 * All other completion status cause the IO to be complete. If a NAK
1036 * was received, then it is up to the user to retry the request. */
1037 scic_sds_request_set_status(
1039 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1040 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1043 sci_base_state_machine_change_state(
1044 &this_request->parent.state_machine,
1045 SCI_BASE_REQUEST_STATE_COMPLETED
1060 static enum sci_status scic_sds_stp_request_pio_await_frame_frame_handler(
1061 struct scic_sds_request *request,
1064 enum sci_status status;
1065 struct sata_fis_header *frame_header;
1067 struct scic_sds_stp_request *this_request;
1069 this_request = (struct scic_sds_stp_request *)request;
1071 status = scic_sds_unsolicited_frame_control_get_header(
1072 &(this_request->parent.owning_controller->uf_control),
1074 (void **)&frame_header
1077 if (status == SCI_SUCCESS) {
1078 switch (frame_header->fis_type) {
1079 case SATA_FIS_TYPE_PIO_SETUP:
1080 /* Get from the frame buffer the PIO Setup Data */
1081 scic_sds_unsolicited_frame_control_get_buffer(
1082 &(this_request->parent.owning_controller->uf_control),
1084 (void **)&frame_buffer
1088 * Get the data from the PIO Setup
1089 * The SCU Hardware returns first word in the frame_header and the rest
1090 * of the data is in the frame buffer so we need to back up one dword */
1091 this_request->type.pio.pio_transfer_bytes =
1092 (u16)((struct sata_fis_pio_setup *)(&frame_buffer[-1]))->transfter_count;
1093 this_request->type.pio.ending_status =
1094 (u8)((struct sata_fis_pio_setup *)(&frame_buffer[-1]))->ending_status;
1096 scic_sds_controller_copy_sata_response(
1097 &this_request->d2h_reg_fis, (u32 *)frame_header, frame_buffer
1100 this_request->d2h_reg_fis.status =
1101 this_request->type.pio.ending_status;
1103 /* The next state is dependent on whether the request was PIO Data-in or Data out */
1104 if (this_request->type.pio.sat_protocol == SAT_PROTOCOL_PIO_DATA_IN) {
1105 sci_base_state_machine_change_state(
1106 &this_request->parent.started_substate_machine,
1107 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
1109 } else if (this_request->type.pio.sat_protocol == SAT_PROTOCOL_PIO_DATA_OUT) {
1111 status = scic_sds_stp_request_pio_data_out_transmit_data(request);
1112 if (status == SCI_SUCCESS) {
1113 sci_base_state_machine_change_state(
1114 &this_request->parent.started_substate_machine,
1115 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
1121 case SATA_FIS_TYPE_SETDEVBITS:
1122 sci_base_state_machine_change_state(
1123 &this_request->parent.started_substate_machine,
1124 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1128 case SATA_FIS_TYPE_REGD2H:
1129 if ((frame_header->status & ATA_STATUS_REG_BSY_BIT) == 0) {
1130 scic_sds_unsolicited_frame_control_get_buffer(
1131 &(this_request->parent.owning_controller->uf_control),
1133 (void **)&frame_buffer
1136 scic_sds_controller_copy_sata_response(
1137 &this_request->d2h_reg_fis, (u32 *)frame_header, frame_buffer);
1139 scic_sds_request_set_status(
1140 &this_request->parent,
1141 SCU_TASK_DONE_CHECK_RESPONSE,
1142 SCI_FAILURE_IO_RESPONSE_VALID
1145 sci_base_state_machine_change_state(
1146 &this_request->parent.parent.state_machine,
1147 SCI_BASE_REQUEST_STATE_COMPLETED
1151 * Now why is the drive sending a D2H Register FIS when it is still busy?
1152 * Do nothing since we are still in the right state. */
1153 dev_dbg(scic_to_dev(request->owning_controller),
1154 "%s: SCIC PIO Request 0x%p received "
1155 "D2H Register FIS with BSY status "
1159 frame_header->status);
1167 /* Frame is decoded return it to the controller */
1168 scic_sds_controller_release_frame(
1169 this_request->parent.owning_controller,
1173 dev_err(scic_to_dev(request->owning_controller),
1174 "%s: SCIC IO Request 0x%p could not get frame header "
1175 "for frame index %d, status %x\n",
1176 __func__, this_request, frame_index, status);
1188 static enum sci_status scic_sds_stp_request_pio_data_in_await_data_frame_handler(
1189 struct scic_sds_request *request,
1192 enum sci_status status;
1193 struct sata_fis_header *frame_header;
1194 struct sata_fis_data *frame_buffer;
1195 struct scic_sds_stp_request *this_request;
1197 this_request = (struct scic_sds_stp_request *)request;
1199 status = scic_sds_unsolicited_frame_control_get_header(
1200 &(this_request->parent.owning_controller->uf_control),
1202 (void **)&frame_header
1205 if (status == SCI_SUCCESS) {
1206 if (frame_header->fis_type == SATA_FIS_TYPE_DATA) {
1207 if (this_request->type.pio.request_current.sgl_pair == NULL) {
1208 this_request->parent.saved_rx_frame_index = frame_index;
1209 this_request->type.pio.pio_transfer_bytes = 0;
1211 status = scic_sds_unsolicited_frame_control_get_buffer(
1212 &(this_request->parent.owning_controller->uf_control),
1214 (void **)&frame_buffer
1217 status = scic_sds_stp_request_pio_data_in_copy_data(this_request, (u8 *)frame_buffer);
1219 /* Frame is decoded return it to the controller */
1220 scic_sds_controller_release_frame(
1221 this_request->parent.owning_controller,
1227 * Check for the end of the transfer, are there more bytes remaining
1228 * for this data transfer */
1230 (status == SCI_SUCCESS)
1231 && (this_request->type.pio.pio_transfer_bytes == 0)
1233 if ((this_request->type.pio.ending_status & ATA_STATUS_REG_BSY_BIT) == 0) {
1234 scic_sds_request_set_status(
1235 &this_request->parent,
1236 SCU_TASK_DONE_CHECK_RESPONSE,
1237 SCI_FAILURE_IO_RESPONSE_VALID
1240 sci_base_state_machine_change_state(
1241 &this_request->parent.parent.state_machine,
1242 SCI_BASE_REQUEST_STATE_COMPLETED
1245 sci_base_state_machine_change_state(
1246 &this_request->parent.started_substate_machine,
1247 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1252 dev_err(scic_to_dev(request->owning_controller),
1253 "%s: SCIC PIO Request 0x%p received frame %d "
1254 "with fis type 0x%02x when expecting a data "
1259 frame_header->fis_type);
1261 scic_sds_request_set_status(
1262 &this_request->parent,
1264 SCI_FAILURE_IO_REQUIRES_SCSI_ABORT
1267 sci_base_state_machine_change_state(
1268 &this_request->parent.parent.state_machine,
1269 SCI_BASE_REQUEST_STATE_COMPLETED
1272 /* Frame is decoded return it to the controller */
1273 scic_sds_controller_release_frame(
1274 this_request->parent.owning_controller,
1279 dev_err(scic_to_dev(request->owning_controller),
1280 "%s: SCIC IO Request 0x%p could not get frame header "
1281 "for frame index %d, status %x\n",
1282 __func__, this_request, frame_index, status);
1295 static enum sci_status scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler(
1297 struct scic_sds_request *this_request,
1298 u32 completion_code)
1300 enum sci_status status = SCI_SUCCESS;
1301 bool all_frames_transferred = false;
1303 struct scic_sds_stp_request *this_scic_sds_stp_request = (struct scic_sds_stp_request *)this_request;
1305 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1306 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1308 if (this_scic_sds_stp_request->type.pio.pio_transfer_bytes != 0) {
1309 status = scic_sds_stp_request_pio_data_out_transmit_data(this_request);
1310 if (status == SCI_SUCCESS) {
1311 if (this_scic_sds_stp_request->type.pio.pio_transfer_bytes == 0)
1312 all_frames_transferred = true;
1314 } else if (this_scic_sds_stp_request->type.pio.pio_transfer_bytes == 0) {
1316 * this will happen if the all data is written at the
1317 * first time after the pio setup fis is received
1319 all_frames_transferred = true;
1322 /* all data transferred. */
1323 if (all_frames_transferred) {
1325 * Change the state to SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_FRAME_SUBSTATE
1326 * and wait for PIO_SETUP fis / or D2H REg fis. */
1327 sci_base_state_machine_change_state(
1328 &this_request->started_substate_machine,
1329 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1336 * All other completion status cause the IO to be complete. If a NAK
1337 * was received, then it is up to the user to retry the request. */
1338 scic_sds_request_set_status(
1340 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1341 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1344 sci_base_state_machine_change_state(
1345 &this_request->parent.state_machine,
1346 SCI_BASE_REQUEST_STATE_COMPLETED
1356 * @request: This is the request which is receiving the event.
1357 * @event_code: This is the event code that the request on which the request is
1358 * expected to take action.
1360 * This method will handle any link layer events while waiting for the data
1361 * frame. enum sci_status SCI_SUCCESS SCI_FAILURE
1363 static enum sci_status scic_sds_stp_request_pio_data_in_await_data_event_handler(
1364 struct scic_sds_request *request,
1367 enum sci_status status;
1369 switch (scu_get_event_specifier(event_code)) {
1370 case SCU_TASK_DONE_CRC_ERR << SCU_EVENT_SPECIFIC_CODE_SHIFT:
1372 * We are waiting for data and the SCU has R_ERR the data frame.
1373 * Go back to waiting for the D2H Register FIS */
1374 sci_base_state_machine_change_state(
1375 &request->started_substate_machine,
1376 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1379 status = SCI_SUCCESS;
1383 dev_err(scic_to_dev(request->owning_controller),
1384 "%s: SCIC PIO Request 0x%p received unexpected "
1386 __func__, request, event_code);
1388 /* / @todo Should we fail the PIO request when we get an unexpected event? */
1389 status = SCI_FAILURE;
1396 /* --------------------------------------------------------------------------- */
1398 const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_pio_substate_handler_table[] = {
1399 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE] = {
1400 .parent.start_handler = scic_sds_request_default_start_handler,
1401 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1402 .parent.complete_handler = scic_sds_request_default_complete_handler,
1403 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1404 .tc_completion_handler = scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler,
1405 .event_handler = scic_sds_request_default_event_handler,
1406 .frame_handler = scic_sds_request_default_frame_handler
1408 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE] = {
1409 .parent.start_handler = scic_sds_request_default_start_handler,
1410 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1411 .parent.complete_handler = scic_sds_request_default_complete_handler,
1412 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1413 .tc_completion_handler = scic_sds_request_default_tc_completion_handler,
1414 .event_handler = scic_sds_request_default_event_handler,
1415 .frame_handler = scic_sds_stp_request_pio_await_frame_frame_handler
1417 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE] = {
1418 .parent.start_handler = scic_sds_request_default_start_handler,
1419 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1420 .parent.complete_handler = scic_sds_request_default_complete_handler,
1421 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1422 .tc_completion_handler = scic_sds_request_default_tc_completion_handler,
1423 .event_handler = scic_sds_stp_request_pio_data_in_await_data_event_handler,
1424 .frame_handler = scic_sds_stp_request_pio_data_in_await_data_frame_handler
1426 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE] = {
1427 .parent.start_handler = scic_sds_request_default_start_handler,
1428 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1429 .parent.complete_handler = scic_sds_request_default_complete_handler,
1430 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1431 .tc_completion_handler = scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler,
1432 .event_handler = scic_sds_request_default_event_handler,
1433 .frame_handler = scic_sds_request_default_frame_handler,
1437 static void scic_sds_stp_request_started_pio_await_h2d_completion_enter(
1438 struct sci_base_object *object)
1440 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1444 scic_sds_stp_request_started_pio_substate_handler_table,
1445 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
1448 scic_sds_remote_device_set_working_request(
1449 this_request->target_device, this_request);
1452 static void scic_sds_stp_request_started_pio_await_frame_enter(
1453 struct sci_base_object *object)
1455 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1459 scic_sds_stp_request_started_pio_substate_handler_table,
1460 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1464 static void scic_sds_stp_request_started_pio_data_in_await_data_enter(
1465 struct sci_base_object *object)
1467 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1471 scic_sds_stp_request_started_pio_substate_handler_table,
1472 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
1476 static void scic_sds_stp_request_started_pio_data_out_transmit_data_enter(
1477 struct sci_base_object *object)
1479 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1483 scic_sds_stp_request_started_pio_substate_handler_table,
1484 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
1488 /* --------------------------------------------------------------------------- */
1490 const struct sci_base_state scic_sds_stp_request_started_pio_substate_table[] = {
1491 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE] = {
1492 .enter_state = scic_sds_stp_request_started_pio_await_h2d_completion_enter,
1494 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE] = {
1495 .enter_state = scic_sds_stp_request_started_pio_await_frame_enter,
1497 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE] = {
1498 .enter_state = scic_sds_stp_request_started_pio_data_in_await_data_enter,
1500 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE] = {
1501 .enter_state = scic_sds_stp_request_started_pio_data_out_transmit_data_enter,
1505 static void scic_sds_stp_request_udma_complete_request(
1506 struct scic_sds_request *this_request,
1508 enum sci_status sci_status)
1510 scic_sds_request_set_status(
1511 this_request, scu_status, sci_status
1514 sci_base_state_machine_change_state(
1515 &this_request->parent.state_machine,
1516 SCI_BASE_REQUEST_STATE_COMPLETED
1527 static enum sci_status scic_sds_stp_request_udma_general_frame_handler(
1528 struct scic_sds_request *this_request,
1531 enum sci_status status;
1532 struct sata_fis_header *frame_header;
1535 status = scic_sds_unsolicited_frame_control_get_header(
1536 &this_request->owning_controller->uf_control,
1538 (void **)&frame_header
1542 (status == SCI_SUCCESS)
1543 && (frame_header->fis_type == SATA_FIS_TYPE_REGD2H)
1545 scic_sds_unsolicited_frame_control_get_buffer(
1546 &this_request->owning_controller->uf_control,
1548 (void **)&frame_buffer
1551 scic_sds_controller_copy_sata_response(
1552 &((struct scic_sds_stp_request *)this_request)->d2h_reg_fis,
1553 (u32 *)frame_header,
1558 scic_sds_controller_release_frame(
1559 this_request->owning_controller, frame_index);
1565 * This method process TC completions while in the state where we are waiting
1566 * for TC completions.
1572 static enum sci_status scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler(
1573 struct scic_sds_request *request,
1574 u32 completion_code)
1576 enum sci_status status = SCI_SUCCESS;
1577 struct scic_sds_stp_request *this_request = (struct scic_sds_stp_request *)request;
1579 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1580 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1581 scic_sds_stp_request_udma_complete_request(
1582 &this_request->parent, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1586 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS):
1587 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
1589 * We must check ther response buffer to see if the D2H Register FIS was
1590 * received before we got the TC completion. */
1591 if (this_request->d2h_reg_fis.fis_type == SATA_FIS_TYPE_REGD2H) {
1592 scic_sds_remote_device_suspend(
1593 this_request->parent.target_device,
1594 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code))
1597 scic_sds_stp_request_udma_complete_request(
1598 &this_request->parent,
1599 SCU_TASK_DONE_CHECK_RESPONSE,
1600 SCI_FAILURE_IO_RESPONSE_VALID
1604 * If we have an error completion status for the TC then we can expect a
1605 * D2H register FIS from the device so we must change state to wait for it */
1606 sci_base_state_machine_change_state(
1607 &this_request->parent.started_substate_machine,
1608 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
1614 * / @todo Check to see if any of these completion status need to wait for
1615 * / the device to host register fis. */
1616 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN):
1617 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
1618 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR):
1619 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR):
1620 scic_sds_remote_device_suspend(
1621 this_request->parent.target_device,
1622 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code))
1624 /* Fall through to the default case */
1626 /* All other completion status cause the IO to be complete. */
1627 scic_sds_stp_request_udma_complete_request(
1628 &this_request->parent,
1629 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1630 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1638 static enum sci_status scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler(
1639 struct scic_sds_request *this_request,
1642 enum sci_status status;
1644 /* Use the general frame handler to copy the resposne data */
1645 status = scic_sds_stp_request_udma_general_frame_handler(this_request, frame_index);
1647 if (status == SCI_SUCCESS) {
1648 scic_sds_stp_request_udma_complete_request(
1650 SCU_TASK_DONE_CHECK_RESPONSE,
1651 SCI_FAILURE_IO_RESPONSE_VALID
1658 /* --------------------------------------------------------------------------- */
1660 const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_udma_substate_handler_table[] = {
1661 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE] = {
1662 .parent.start_handler = scic_sds_request_default_start_handler,
1663 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1664 .parent.complete_handler = scic_sds_request_default_complete_handler,
1665 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1666 .tc_completion_handler = scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler,
1667 .event_handler = scic_sds_request_default_event_handler,
1668 .frame_handler = scic_sds_stp_request_udma_general_frame_handler,
1670 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE] = {
1671 .parent.start_handler = scic_sds_request_default_start_handler,
1672 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1673 .parent.complete_handler = scic_sds_request_default_complete_handler,
1674 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1675 .tc_completion_handler = scic_sds_request_default_tc_completion_handler,
1676 .event_handler = scic_sds_request_default_event_handler,
1677 .frame_handler = scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler,
1681 static void scic_sds_stp_request_started_udma_await_tc_completion_enter(
1682 struct sci_base_object *object)
1684 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1688 scic_sds_stp_request_started_udma_substate_handler_table,
1689 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
1696 * This state is entered when there is an TC completion failure. The hardware
1697 * received an unexpected condition while processing the IO request and now
1698 * will UF the D2H register FIS to complete the IO.
1700 static void scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter(
1701 struct sci_base_object *object)
1703 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1707 scic_sds_stp_request_started_udma_substate_handler_table,
1708 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
1712 /* --------------------------------------------------------------------------- */
1714 const struct sci_base_state scic_sds_stp_request_started_udma_substate_table[] = {
1715 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE] = {
1716 .enter_state = scic_sds_stp_request_started_udma_await_tc_completion_enter,
1718 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE] = {
1719 .enter_state = scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter,
1728 * This method processes a TC completion. The expected TC completion is for
1729 * the transmission of the H2D register FIS containing the SATA/STP non-data
1730 * request. This method always successfully processes the TC completion.
1731 * SCI_SUCCESS This value is always returned.
1733 static enum sci_status scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler(
1734 struct scic_sds_request *this_request,
1735 u32 completion_code)
1737 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1738 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1739 scic_sds_request_set_status(
1740 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1743 sci_base_state_machine_change_state(
1744 &this_request->started_substate_machine,
1745 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
1751 * All other completion status cause the IO to be complete. If a NAK
1752 * was received, then it is up to the user to retry the request. */
1753 scic_sds_request_set_status(
1755 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1756 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1759 sci_base_state_machine_change_state(
1760 &this_request->parent.state_machine, SCI_BASE_REQUEST_STATE_COMPLETED
1773 * This method processes a TC completion. The expected TC completion is for
1774 * the transmission of the H2D register FIS containing the SATA/STP non-data
1775 * request. This method always successfully processes the TC completion.
1776 * SCI_SUCCESS This value is always returned.
1778 static enum sci_status scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler(
1779 struct scic_sds_request *this_request,
1780 u32 completion_code)
1782 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1783 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1784 scic_sds_request_set_status(
1785 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1788 sci_base_state_machine_change_state(
1789 &this_request->started_substate_machine,
1790 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
1796 * All other completion status cause the IO to be complete. If a NAK
1797 * was received, then it is up to the user to retry the request. */
1798 scic_sds_request_set_status(
1800 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1801 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1804 sci_base_state_machine_change_state(
1805 &this_request->parent.state_machine, SCI_BASE_REQUEST_STATE_COMPLETED
1815 * @request: This parameter specifies the request for which a frame has been
1817 * @frame_index: This parameter specifies the index of the frame that has been
1820 * This method processes frames received from the target while waiting for a
1821 * device to host register FIS. If a non-register FIS is received during this
1822 * time, it is treated as a protocol violation from an IO perspective. Indicate
1823 * if the received frame was processed successfully.
1825 static enum sci_status scic_sds_stp_request_soft_reset_await_d2h_frame_handler(
1826 struct scic_sds_request *request,
1829 enum sci_status status;
1830 struct sata_fis_header *frame_header;
1832 struct scic_sds_stp_request *this_request = (struct scic_sds_stp_request *)request;
1834 status = scic_sds_unsolicited_frame_control_get_header(
1835 &(this_request->parent.owning_controller->uf_control),
1837 (void **)&frame_header
1840 if (status == SCI_SUCCESS) {
1841 switch (frame_header->fis_type) {
1842 case SATA_FIS_TYPE_REGD2H:
1843 scic_sds_unsolicited_frame_control_get_buffer(
1844 &(this_request->parent.owning_controller->uf_control),
1846 (void **)&frame_buffer
1849 scic_sds_controller_copy_sata_response(
1850 &this_request->d2h_reg_fis, (u32 *)frame_header, frame_buffer
1853 /* The command has completed with error */
1854 scic_sds_request_set_status(
1855 &this_request->parent,
1856 SCU_TASK_DONE_CHECK_RESPONSE,
1857 SCI_FAILURE_IO_RESPONSE_VALID
1862 dev_warn(scic_to_dev(request->owning_controller),
1863 "%s: IO Request:0x%p Frame Id:%d protocol "
1864 "violation occurred\n",
1869 scic_sds_request_set_status(
1870 &this_request->parent,
1871 SCU_TASK_DONE_UNEXP_FIS,
1872 SCI_FAILURE_PROTOCOL_VIOLATION
1877 sci_base_state_machine_change_state(
1878 &this_request->parent.parent.state_machine,
1879 SCI_BASE_REQUEST_STATE_COMPLETED
1882 /* Frame has been decoded return it to the controller */
1883 scic_sds_controller_release_frame(
1884 this_request->parent.owning_controller, frame_index
1887 dev_err(scic_to_dev(request->owning_controller),
1888 "%s: SCIC IO Request 0x%p could not get frame header "
1889 "for frame index %d, status %x\n",
1890 __func__, this_request, frame_index, status);
1895 /* --------------------------------------------------------------------------- */
1897 const struct scic_sds_io_request_state_handler scic_sds_stp_request_started_soft_reset_substate_handler_table[] = {
1898 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE] = {
1899 .parent.start_handler = scic_sds_request_default_start_handler,
1900 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1901 .parent.complete_handler = scic_sds_request_default_complete_handler,
1902 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1903 .tc_completion_handler = scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler,
1904 .event_handler = scic_sds_request_default_event_handler,
1905 .frame_handler = scic_sds_request_default_frame_handler,
1907 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE] = {
1908 .parent.start_handler = scic_sds_request_default_start_handler,
1909 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1910 .parent.complete_handler = scic_sds_request_default_complete_handler,
1911 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1912 .tc_completion_handler = scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler,
1913 .event_handler = scic_sds_request_default_event_handler,
1914 .frame_handler = scic_sds_request_default_frame_handler,
1916 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE] = {
1917 .parent.start_handler = scic_sds_request_default_start_handler,
1918 .parent.abort_handler = scic_sds_request_started_state_abort_handler,
1919 .parent.complete_handler = scic_sds_request_default_complete_handler,
1920 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
1921 .tc_completion_handler = scic_sds_request_default_tc_completion_handler,
1922 .event_handler = scic_sds_request_default_event_handler,
1923 .frame_handler = scic_sds_stp_request_soft_reset_await_d2h_frame_handler,
1927 static void scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter(
1928 struct sci_base_object *object)
1930 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1934 scic_sds_stp_request_started_soft_reset_substate_handler_table,
1935 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
1938 scic_sds_remote_device_set_working_request(
1939 this_request->target_device, this_request
1943 static void scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter(
1944 struct sci_base_object *object)
1946 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1947 sci_base_controller_request_handler_t continue_io;
1948 struct scu_task_context *task_context;
1949 struct sata_fis_reg_h2d *h2d_fis;
1950 struct scic_sds_controller *scic;
1951 enum sci_status status;
1954 /* Clear the SRST bit */
1955 h2d_fis = scic_stp_io_request_get_h2d_reg_address(this_request);
1956 h2d_fis->control = 0;
1958 /* Clear the TC control bit */
1959 task_context = scic_sds_controller_get_task_context_buffer(
1960 this_request->owning_controller, this_request->io_tag);
1961 task_context->control_frame = 0;
1963 scic = this_request->owning_controller;
1964 state = scic->parent.state_machine.current_state_id;
1965 continue_io = scic_sds_controller_state_handler_table[state].base.continue_io;
1967 status = continue_io(&scic->parent, &this_request->target_device->parent,
1968 &this_request->parent);
1970 if (status == SCI_SUCCESS) {
1973 scic_sds_stp_request_started_soft_reset_substate_handler_table,
1974 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
1979 static void scic_sds_stp_request_started_soft_reset_await_d2h_response_enter(
1980 struct sci_base_object *object)
1982 struct scic_sds_request *this_request = (struct scic_sds_request *)object;
1986 scic_sds_stp_request_started_soft_reset_substate_handler_table,
1987 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
1991 /* --------------------------------------------------------------------------- */
1993 const struct sci_base_state scic_sds_stp_request_started_soft_reset_substate_table[] = {
1994 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE] = {
1995 .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter,
1997 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE] = {
1998 .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter,
2000 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE] = {
2001 .enter_state = scic_sds_stp_request_started_soft_reset_await_d2h_response_enter,