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
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
56 #include <dev/isci/scil/intel_sat.h>
57 #include <dev/isci/scil/intel_sata.h>
58 #include <dev/isci/scil/sci_types.h>
59 #include <dev/isci/scil/scic_remote_device.h>
60 #include <dev/isci/scil/scic_user_callback.h>
61 #include <dev/isci/scil/scic_sds_controller.h>
62 #include <dev/isci/scil/scic_sds_remote_device.h>
63 #include <dev/isci/scil/scic_sds_stp_request.h>
64 #include <dev/isci/scil/scic_sds_stp_pio_request.h>
65 #include <dev/isci/scil/scic_sds_logger.h>
66 #include <dev/isci/sci_environment.h>
67 #include <dev/isci/scil/sci_base_state_machine.h>
68 #include <dev/isci/scil/scu_task_context.h>
69 #include <dev/isci/scil/intel_ata.h>
70 #include <dev/isci/scil/sci_util.h>
71 #include <dev/isci/scil/scic_sds_logger.h>
72 #include <dev/isci/scil/scic_sds_request.h>
73 #include <dev/isci/scil/scic_sds_stp_request.h>
74 #include <dev/isci/scil/scu_completion_codes.h>
75 #include <dev/isci/scil/scu_event_codes.h>
76 #include <dev/isci/scil/sci_base_state.h>
77 #include <dev/isci/scil/scic_sds_unsolicited_frame_control.h>
78 #include <dev/isci/scil/scic_io_request.h>
80 #if !defined(DISABLE_ATAPI)
81 #include <dev/isci/scil/scic_sds_stp_packet_request.h>
85 * This macro returns the address of the stp h2d reg fis buffer in the io
88 #define scic_sds_stp_request_get_h2d_reg_buffer_unaligned(memory) \
89 ((SATA_FIS_REG_H2D_T *)( \
90 ((char *)(memory)) + sizeof(SCIC_SDS_STP_REQUEST_T) \
94 * This macro aligns the stp command buffer in DWORD alignment
96 #define scic_sds_stp_request_align_h2d_reg_buffer(address) \
97 ((SATA_FIS_REG_H2D_T *)( \
98 (((POINTER_UINT)(address)) + (sizeof(U32) - 1)) \
103 * This macro returns the DWORD-aligned stp command buffer
105 #define scic_sds_stp_request_get_h2d_reg_buffer(memory) \
106 ((SATA_FIS_REG_H2D_T *) \
107 ((char *)scic_sds_stp_request_align_h2d_reg_buffer( \
108 (char *) scic_sds_stp_request_get_h2d_reg_buffer_unaligned(memory) \
112 * This macro returns the address of the stp response buffer in the io
115 #define scic_sds_stp_request_get_response_buffer_unaligned(memory) \
116 ((SATA_FIS_REG_D2H_T *)( \
117 ((char *)(scic_sds_stp_request_get_h2d_reg_buffer(memory))) \
118 + sizeof(SATA_FIS_REG_H2D_T) \
123 * This macro aligns the stp response buffer in DWORD alignment
125 #define scic_sds_stp_request_align_response_buffer(address) \
126 ((SATA_FIS_REG_D2H_T *)( \
127 (((POINTER_UINT)(address)) + (sizeof(U32) - 1)) \
128 & ~(sizeof(U32)- 1) \
132 * This macro returns the DWORD-aligned stp response buffer
134 #define scic_sds_stp_request_get_response_buffer(memory) \
135 ((SATA_FIS_REG_D2H_T *) \
136 ((char *)scic_sds_stp_request_align_response_buffer( \
137 (char *)scic_sds_stp_request_get_response_buffer_unaligned(memory) \
142 * This macro returns the address of the task context buffer in the io
145 #define scic_sds_stp_request_get_task_context_buffer_unaligned(memory) \
146 ((SCU_TASK_CONTEXT_T *)( \
147 ((char *)(scic_sds_stp_request_get_response_buffer(memory))) \
148 + sizeof(SCI_SSP_RESPONSE_IU_T) \
152 * This macro returns the aligned task context buffer
154 #define scic_sds_stp_request_get_task_context_buffer(memory) \
155 ((SCU_TASK_CONTEXT_T *)( \
156 ((char *)scic_sds_request_align_task_context_buffer( \
157 (char *)scic_sds_stp_request_get_task_context_buffer_unaligned(memory)) \
161 * This macro returns the address of the sgl elment pairs in the io request
164 #define scic_sds_stp_request_get_sgl_element_buffer(memory) \
165 ((SCU_SGL_ELEMENT_PAIR_T *)( \
166 ((char *)(scic_sds_stp_request_get_task_context_buffer(memory))) \
167 + sizeof(SCU_TASK_CONTEXT_T) \
172 * This method return the memory space commonly required for STP IO and
178 U32 scic_sds_stp_common_request_get_object_size(void)
180 return sizeof(SCIC_SDS_STP_REQUEST_T)
181 + sizeof(SATA_FIS_REG_H2D_T)
183 + sizeof(SATA_FIS_REG_D2H_T)
185 + sizeof(SCU_TASK_CONTEXT_T)
191 * This method return the memory space required for STP PIO requests.
195 U32 scic_sds_stp_request_get_object_size(void)
197 return scic_sds_stp_common_request_get_object_size()
198 + sizeof(SCU_SGL_ELEMENT_PAIR_T) * SCU_MAX_SGL_ELEMENT_PAIRS;
203 * This method return the memory space required for STP task requests.
207 U32 scic_sds_stp_task_request_get_object_size(void)
209 return scic_sds_stp_common_request_get_object_size();
216 * @param[in] this_request
218 void scic_sds_stp_request_assign_buffers(
219 SCIC_SDS_REQUEST_T * request
222 SCIC_SDS_STP_REQUEST_T * this_request = (SCIC_SDS_STP_REQUEST_T *)request;
224 this_request->parent.command_buffer =
225 scic_sds_stp_request_get_h2d_reg_buffer(this_request);
226 this_request->parent.response_buffer =
227 scic_sds_stp_request_get_response_buffer(this_request);
228 this_request->parent.sgl_element_pair_buffer =
229 scic_sds_stp_request_get_sgl_element_buffer(this_request);
230 this_request->parent.sgl_element_pair_buffer =
231 scic_sds_request_align_sgl_element_buffer(this_request->parent.sgl_element_pair_buffer);
233 if (this_request->parent.was_tag_assigned_by_user == FALSE)
235 this_request->parent.task_context_buffer =
236 scic_sds_stp_request_get_task_context_buffer(this_request);
241 * @brief This method is will fill in the SCU Task Context for any type of
242 * SATA request. This is called from the various SATA constructors.
244 * @pre The general io request construction is complete.
245 * @pre The buffer assignment for the command buffer is complete.
247 * @param[in] this_request The general IO request object which is to be used
248 * in constructing the SCU task context.
249 * @param[in] task_context The buffer pointer for the SCU task context which
250 * is being constructed.
254 * @todo Revisit task context construction to determine what is common for
255 * SSP/SMP/STP task context structures.
257 void scu_sata_reqeust_construct_task_context(
258 SCIC_SDS_REQUEST_T * this_request,
259 SCU_TASK_CONTEXT_T * task_context
262 SCI_PHYSICAL_ADDRESS physical_address;
263 SCIC_SDS_CONTROLLER_T *owning_controller;
264 SCIC_SDS_REMOTE_DEVICE_T *target_device;
265 SCIC_SDS_PORT_T *target_port;
267 owning_controller = scic_sds_request_get_controller(this_request);
268 target_device = scic_sds_request_get_device(this_request);
269 target_port = scic_sds_request_get_port(this_request);
271 // Fill in the TC with the its required data
272 task_context->abort = 0;
273 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
274 task_context->initiator_request = 1;
275 task_context->connection_rate =
276 scic_remote_device_get_connection_rate(target_device);
277 task_context->protocol_engine_index =
278 scic_sds_controller_get_protocol_engine_group(owning_controller);
279 task_context->logical_port_index =
280 scic_sds_port_get_index(target_port);
281 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_STP;
282 task_context->valid = SCU_TASK_CONTEXT_VALID;
283 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
285 task_context->remote_node_index =
286 scic_sds_remote_device_get_index(this_request->target_device);
287 task_context->command_code = 0;
289 task_context->link_layer_control = 0;
290 task_context->do_not_dma_ssp_good_response = 1;
291 task_context->strict_ordering = 0;
292 task_context->control_frame = 0;
293 task_context->timeout_enable = 0;
294 task_context->block_guard_enable = 0;
296 task_context->address_modifier = 0;
297 task_context->task_phase = 0x01;
299 task_context->ssp_command_iu_length =
300 (sizeof(SATA_FIS_REG_H2D_T) - sizeof(U32)) / sizeof(U32);
302 // Set the first word of the H2D REG FIS
303 task_context->type.words[0] = *(U32 *)this_request->command_buffer;
305 if (this_request->was_tag_assigned_by_user)
307 // Build the task context now since we have already read the data
308 this_request->post_context = (
309 SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
311 scic_sds_controller_get_protocol_engine_group(owning_controller)
312 << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
315 scic_sds_port_get_index(target_port)
316 << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
318 | scic_sds_io_tag_get_index(this_request->io_tag)
323 // Build the task context now since we have already read the data
324 this_request->post_context = (
325 SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
327 scic_sds_controller_get_protocol_engine_group(owning_controller)
328 << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
331 scic_sds_port_get_index(target_port)
332 << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
334 // This is not assigned because we have to wait until we get a TCi
338 // Copy the physical address for the command buffer to the SCU Task Context
339 // We must offset the command buffer by 4 bytes because the first 4 bytes are
340 // transfered in the body of the TC
341 scic_cb_io_request_get_physical_address(
342 scic_sds_request_get_controller(this_request),
344 ((char *)this_request->command_buffer) + sizeof(U32),
348 task_context->command_iu_upper =
349 sci_cb_physical_address_upper(physical_address);
350 task_context->command_iu_lower =
351 sci_cb_physical_address_lower(physical_address);
353 // SATA Requests do not have a response buffer
354 task_context->response_iu_upper = 0;
355 task_context->response_iu_lower = 0;
359 * This method will perform any general sata request construction.
361 * @todo What part of SATA IO request construction is general?
363 * @param[in] this_request
367 void scic_sds_stp_non_ncq_request_construct(
368 SCIC_SDS_REQUEST_T * this_request
371 this_request->has_started_substate_machine = TRUE;
375 * This method will perform request construction common to all types of
376 * STP requests that are optimized by the silicon (i.e. UDMA, NCQ).
378 * @param[in,out] this_request This parameter specifies the request to be
379 * constructed as an optimized request.
380 * @param[in] optimized_task_type This parameter specifies whether the
381 * request is to be an UDMA request or a NCQ request.
382 * - A value of 0 indicates UDMA.
383 * - A value of 1 indicates NCQ.
385 * @return This method returns an indication as to whether the construction
389 void scic_sds_stp_optimized_request_construct(
390 SCIC_SDS_REQUEST_T * this_request,
391 U8 optimized_task_type,
393 SCI_IO_REQUEST_DATA_DIRECTION data_direction
396 SCU_TASK_CONTEXT_T * task_context = this_request->task_context_buffer;
398 // Build the STP task context structure
399 scu_sata_reqeust_construct_task_context(this_request, task_context);
401 // Copy over the number of bytes to be transfered
402 task_context->transfer_length_bytes = transfer_length;
404 if ( data_direction == SCI_IO_REQUEST_DATA_OUT )
406 // The difference between the DMA IN and DMA OUT request task type
407 // values are consistent with the difference between FPDMA READ
408 // and FPDMA WRITE values. Add the supplied task type parameter
409 // to this difference to set the task type properly for this
410 // DATA OUT (WRITE) case.
411 task_context->task_type = optimized_task_type + (SCU_TASK_TYPE_DMA_OUT
412 - SCU_TASK_TYPE_DMA_IN);
416 // For the DATA IN (READ) case, simply save the supplied
417 // optimized task type.
418 task_context->task_type = optimized_task_type;
423 * This method performs the operations common to all SATA/STP requests
424 * utilizing the raw frame method.
426 * @param[in] this_request This parameter specifies the STP request object
427 * for which to construct a RAW command frame task context.
428 * @param[in] task_context This parameter specifies the SCU specific
429 * task context buffer to construct.
433 void scu_stp_raw_request_construct_task_context(
434 SCIC_SDS_STP_REQUEST_T * this_request,
435 SCU_TASK_CONTEXT_T * task_context
438 scu_sata_reqeust_construct_task_context(&this_request->parent, task_context);
440 task_context->control_frame = 0;
441 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
442 task_context->task_type = SCU_TASK_TYPE_SATA_RAW_FRAME;
443 task_context->type.stp.fis_type = SATA_FIS_TYPE_REGH2D;
444 task_context->transfer_length_bytes = sizeof(SATA_FIS_REG_H2D_T) - sizeof(U32);
448 * This method will construct the STP Non-data request and its associated
449 * TC data. A non-data request essentially behaves like a 0 length read
450 * request in the SCU.
452 * @param[in] this_request This parameter specifies the core request
453 * object to construction into an STP/SATA non-data request.
455 * @return This method currently always returns SCI_SUCCESS
457 SCI_STATUS scic_sds_stp_non_data_request_construct(
458 SCIC_SDS_REQUEST_T * this_request
461 scic_sds_stp_non_ncq_request_construct(this_request);
463 // Build the STP task context structure
464 scu_stp_raw_request_construct_task_context(
465 (SCIC_SDS_STP_REQUEST_T*) this_request,
466 this_request->task_context_buffer
469 sci_base_state_machine_construct(
470 &this_request->started_substate_machine,
471 &this_request->parent.parent,
472 scic_sds_stp_request_started_non_data_substate_table,
473 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
480 SCI_STATUS scic_sds_stp_soft_reset_request_construct(
481 SCIC_SDS_REQUEST_T * this_request
484 scic_sds_stp_non_ncq_request_construct(this_request);
486 // Build the STP task context structure
487 scu_stp_raw_request_construct_task_context(
488 (SCIC_SDS_STP_REQUEST_T*) this_request,
489 this_request->task_context_buffer
492 sci_base_state_machine_construct(
493 &this_request->started_substate_machine,
494 &this_request->parent.parent,
495 scic_sds_stp_request_started_soft_reset_substate_table,
496 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
503 * @brief This method constructs the SATA request object.
505 * @param[in] this_request
506 * @param[in] sat_protocol
507 * @param[in] transfer_length
508 * @param[in] data_direction
509 * @param[in] copy_rx_frame
510 * @param[in] do_translate_sgl This parameter specifies whether SGL
511 * translation should be performed or if the user is handling
516 SCI_STATUS scic_sds_io_request_construct_sata(
517 SCIC_SDS_REQUEST_T * this_request,
520 SCI_IO_REQUEST_DATA_DIRECTION data_direction,
522 BOOL do_translate_sgl
525 SCI_STATUS status = SCI_SUCCESS;
527 this_request->protocol = SCIC_STP_PROTOCOL;
529 this_request->sat_protocol = sat_protocol;
531 switch (sat_protocol)
533 case SAT_PROTOCOL_FPDMA:
534 scic_sds_stp_optimized_request_construct(
536 SCU_TASK_TYPE_FPDMAQ_READ,
541 // Copy over the SGL elements
542 if (do_translate_sgl == TRUE)
543 scic_sds_request_build_sgl(this_request);
546 case SAT_PROTOCOL_UDMA_DATA_IN:
547 case SAT_PROTOCOL_UDMA_DATA_OUT:
548 scic_sds_stp_non_ncq_request_construct(this_request);
550 scic_sds_stp_optimized_request_construct(
551 this_request, SCU_TASK_TYPE_DMA_IN, transfer_length, data_direction
554 // Copy over the SGL elements
555 if (do_translate_sgl == TRUE)
556 scic_sds_request_build_sgl(this_request);
558 sci_base_state_machine_construct(
559 &this_request->started_substate_machine,
560 &this_request->parent.parent,
561 scic_sds_stp_request_started_udma_substate_table,
562 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
566 case SAT_PROTOCOL_PIO_DATA_IN:
567 case SAT_PROTOCOL_PIO_DATA_OUT:
568 status = scic_sds_stp_pio_request_construct(
569 this_request, sat_protocol, copy_rx_frame);
572 case SAT_PROTOCOL_ATA_HARD_RESET:
573 case SAT_PROTOCOL_SOFT_RESET:
574 status = scic_sds_stp_soft_reset_request_construct(this_request);
577 case SAT_PROTOCOL_NON_DATA:
578 status = scic_sds_stp_non_data_request_construct(this_request);
581 #if !defined(DISABLE_ATAPI)
582 case SAT_PROTOCOL_PACKET_NON_DATA:
583 case SAT_PROTOCOL_PACKET_DMA_DATA_IN:
584 case SAT_PROTOCOL_PACKET_DMA_DATA_OUT:
585 case SAT_PROTOCOL_PACKET_PIO_DATA_IN:
586 case SAT_PROTOCOL_PACKET_PIO_DATA_OUT:
587 status = scic_sds_stp_packet_request_construct(this_request);
588 if (do_translate_sgl == TRUE)
589 scic_sds_request_build_sgl(this_request);
593 case SAT_PROTOCOL_DMA_QUEUED:
594 case SAT_PROTOCOL_DMA:
595 case SAT_PROTOCOL_DEVICE_DIAGNOSTIC:
596 case SAT_PROTOCOL_DEVICE_RESET:
597 case SAT_PROTOCOL_RETURN_RESPONSE_INFO:
600 sci_base_object_get_logger(this_request),
601 SCIC_LOG_OBJECT_STP_IO_REQUEST,
602 "SCIC IO Request 0x%x received un-handled SAT Protocol %d.\n",
603 this_request, sat_protocol
606 status = SCI_FAILURE;
610 if (status == SCI_SUCCESS)
612 scic_sds_request_initialize_state_logging(this_request);
614 sci_base_state_machine_change_state(
615 &this_request->parent.state_machine,
616 SCI_BASE_REQUEST_STATE_CONSTRUCTED
623 //****************************************************************************
624 //* SCIC Interface Implementation
625 //****************************************************************************
627 void scic_stp_io_request_set_ncq_tag(
628 SCI_IO_REQUEST_HANDLE_T scic_io_request,
633 * @note This could be made to return an error to the user if the user
634 * attempts to set the NCQ tag in the wrong state.
636 SCIC_SDS_REQUEST_T * this_request = (SCIC_SDS_REQUEST_T *)scic_io_request;
637 this_request->task_context_buffer->type.stp.ncq_tag = ncq_tag;
640 // ---------------------------------------------------------------------------
642 void * scic_stp_io_request_get_h2d_reg_address(
643 SCI_IO_REQUEST_HANDLE_T scic_io_request
646 SCIC_SDS_REQUEST_T * this_request = (SCIC_SDS_REQUEST_T *)scic_io_request;
648 return this_request->command_buffer;
651 // ---------------------------------------------------------------------------
653 void * scic_stp_io_request_get_d2h_reg_address(
654 SCI_IO_REQUEST_HANDLE_T scic_io_request
657 SCIC_SDS_STP_REQUEST_T * this_request = (SCIC_SDS_STP_REQUEST_T *)scic_io_request;
659 return &this_request->d2h_reg_fis;
663 * Get the next SGL element from the request.
664 * - Check on which SGL element pair we are working
665 * - if working on SLG pair element A
666 * - advance to element B
668 * - check to see if there are more SGL element pairs
669 * for this IO request
670 * - if there are more SGL element pairs
671 * - advance to the next pair and return element A
673 * @param[in] this_request
675 * @return SCU_SGL_ELEMENT_T*
677 SCU_SGL_ELEMENT_T * scic_sds_stp_request_pio_get_next_sgl(
678 SCIC_SDS_STP_REQUEST_T * this_request
681 SCU_SGL_ELEMENT_T * current_sgl;
683 if (this_request->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A)
686 (this_request->type.pio.request_current.sgl_pair->B.address_lower == 0)
687 && (this_request->type.pio.request_current.sgl_pair->B.address_upper == 0)
694 this_request->type.pio.request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_B;
695 current_sgl = &(this_request->type.pio.request_current.sgl_pair->B);
701 (this_request->type.pio.request_current.sgl_pair->next_pair_lower == 0)
702 && (this_request->type.pio.request_current.sgl_pair->next_pair_upper == 0)
709 this_request->type.pio.request_current.sgl_pair =
710 scic_sds_request_get_sgl_element_pair(
711 &(this_request->parent),
712 ++this_request->type.pio.sgl_pair_index
715 this_request->type.pio.request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_A;
717 current_sgl = &(this_request->type.pio.request_current.sgl_pair->A);
725 * This method will construct the SATA PIO request.
727 * @param[in] scic_io_request The core request object which is cast to a SATA
728 * PIO request object.
730 * @return This method returns an indication as to whether the construction
732 * @retval SCI_SUCCESS Currently this method always returns this value.
734 SCI_STATUS scic_sds_stp_pio_request_construct(
735 SCIC_SDS_REQUEST_T * scic_io_request,
740 SCIC_SDS_STP_REQUEST_T * this_request;
742 this_request = (SCIC_SDS_STP_REQUEST_T *)scic_io_request;
744 scic_sds_stp_non_ncq_request_construct(&this_request->parent);
746 scu_stp_raw_request_construct_task_context(
747 this_request, this_request->parent.task_context_buffer
750 this_request->type.pio.current_transfer_bytes = 0;
751 this_request->type.pio.ending_error = 0;
752 this_request->type.pio.ending_status = 0;
754 this_request->type.pio.request_current.sgl_offset = 0;
755 this_request->type.pio.request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_A;
756 this_request->type.pio.sat_protocol = sat_protocol;
757 this_request->type.pio.sgl_pair_index = 0;
759 if ((copy_rx_frame) || (sat_protocol == SAT_PROTOCOL_PIO_DATA_OUT))
761 scic_sds_request_build_sgl(&this_request->parent);
762 // Since the IO request copy of the TC contains the same data as
763 // the actual TC this pointer is vaild for either.
764 this_request->type.pio.request_current.sgl_pair =
765 &this_request->parent.task_context_buffer->sgl_pair_ab;
769 // The user does not want the data copied to the SGL buffer location
770 this_request->type.pio.request_current.sgl_pair = NULL;
773 sci_base_state_machine_construct(
774 &this_request->parent.started_substate_machine,
775 &this_request->parent.parent.parent,
776 scic_sds_stp_request_started_pio_substate_table,
777 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
783 //******************************************************************************
784 //* STP NON-DATA STATE MACHINE
785 //******************************************************************************
788 * This method processes a TC completion. The expected TC completion is
789 * for the transmission of the H2D register FIS containing the SATA/STP
792 * @param[in] this_request
793 * @param[in] completion_code
795 * @return This method always successfully processes the TC completion.
796 * @retval SCI_SUCCESS This value is always returned.
799 SCI_STATUS scic_sds_stp_request_non_data_await_h2d_tc_completion_handler(
800 SCIC_SDS_REQUEST_T * this_request,
805 sci_base_object_get_logger(this_request),
806 SCIC_LOG_OBJECT_STP_IO_REQUEST,
807 "scic_sds_stp_request_non_data_await_h2d_tc_completion_handler(0x%x, 0x%x) enter\n",
808 this_request, completion_code
811 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code))
813 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
814 scic_sds_request_set_status(
815 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
818 sci_base_state_machine_change_state(
819 &this_request->started_substate_machine,
820 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
825 // All other completion status cause the IO to be complete. If a NAK
826 // was received, then it is up to the user to retry the request.
827 scic_sds_request_set_status(
829 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
830 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
833 sci_base_state_machine_change_state(
834 &this_request->parent.state_machine, SCI_BASE_REQUEST_STATE_COMPLETED
843 * This method processes frames received from the target while waiting
844 * for a device to host register FIS. If a non-register FIS is received
845 * during this time, it is treated as a protocol violation from an
848 * @param[in] request This parameter specifies the request for which a
849 * frame has been received.
850 * @param[in] frame_index This parameter specifies the index of the frame
851 * that has been received.
853 * @return Indicate if the received frame was processed successfully.
856 SCI_STATUS scic_sds_stp_request_non_data_await_d2h_frame_handler(
857 SCIC_SDS_REQUEST_T * request,
862 SATA_FIS_HEADER_T * frame_header;
864 SCIC_SDS_STP_REQUEST_T * this_request = (SCIC_SDS_STP_REQUEST_T *)request;
866 // Save off the controller, so that we do not touch the request after it
868 SCIC_SDS_CONTROLLER_T * owning_controller = this_request->parent.owning_controller;
871 sci_base_object_get_logger(this_request),
872 SCIC_LOG_OBJECT_STP_IO_REQUEST,
873 "scic_sds_stp_request_non_data_await_d2h_frame_handler(0x%x, 0x%x) enter\n",
874 this_request, frame_index
877 status = scic_sds_unsolicited_frame_control_get_header(
878 &(owning_controller->uf_control),
880 (void**) &frame_header
883 if (status == SCI_SUCCESS)
885 switch (frame_header->fis_type)
887 case SATA_FIS_TYPE_REGD2H:
888 scic_sds_unsolicited_frame_control_get_buffer(
889 &(owning_controller->uf_control),
891 (void**) &frame_buffer
894 scic_sds_controller_copy_sata_response(
895 &this_request->d2h_reg_fis, (U32 *)frame_header, frame_buffer
898 // The command has completed with error
899 scic_sds_request_set_status(
900 &this_request->parent,
901 SCU_TASK_DONE_CHECK_RESPONSE,
902 SCI_FAILURE_IO_RESPONSE_VALID
908 sci_base_object_get_logger(this_request),
909 SCIC_LOG_OBJECT_STP_IO_REQUEST,
910 "IO Request:0x%x Frame Id:%d protocol violation occurred\n",
911 this_request, frame_index
914 scic_sds_request_set_status(
915 &this_request->parent,
916 SCU_TASK_DONE_UNEXP_FIS,
917 SCI_FAILURE_PROTOCOL_VIOLATION
922 sci_base_state_machine_change_state(
923 &this_request->parent.parent.state_machine,
924 SCI_BASE_REQUEST_STATE_COMPLETED
927 // Frame has been decoded return it to the controller
928 scic_sds_controller_release_frame(
929 owning_controller, frame_index
935 sci_base_object_get_logger(this_request),
936 SCIC_LOG_OBJECT_STP_IO_REQUEST,
937 "SCIC IO Request 0x%x could not get frame header for frame index %d, status %x\n",
938 this_request, frame_index, status
945 // ---------------------------------------------------------------------------
947 SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
948 scic_sds_stp_request_started_non_data_substate_handler_table
949 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_MAX_SUBSTATES] =
951 // SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
954 scic_sds_request_default_start_handler,
955 scic_sds_request_started_state_abort_handler,
956 scic_sds_request_default_complete_handler,
957 scic_sds_request_default_destruct_handler
959 scic_sds_stp_request_non_data_await_h2d_tc_completion_handler,
960 scic_sds_request_default_event_handler,
961 scic_sds_request_default_frame_handler
963 // SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
966 scic_sds_request_default_start_handler,
967 scic_sds_request_started_state_abort_handler,
968 scic_sds_request_default_complete_handler,
969 scic_sds_request_default_destruct_handler
971 scic_sds_request_default_tc_completion_handler,
972 scic_sds_request_default_event_handler,
973 scic_sds_stp_request_non_data_await_d2h_frame_handler
978 void scic_sds_stp_request_started_non_data_await_h2d_completion_enter(
979 SCI_BASE_OBJECT_T *object
982 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
986 scic_sds_stp_request_started_non_data_substate_handler_table,
987 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
990 scic_sds_remote_device_set_working_request(
991 this_request->target_device, this_request
996 void scic_sds_stp_request_started_non_data_await_d2h_enter(
997 SCI_BASE_OBJECT_T *object
1000 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
1004 scic_sds_stp_request_started_non_data_substate_handler_table,
1005 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
1009 // ---------------------------------------------------------------------------
1011 SCI_BASE_STATE_T scic_sds_stp_request_started_non_data_substate_table
1012 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_MAX_SUBSTATES] =
1015 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE,
1016 scic_sds_stp_request_started_non_data_await_h2d_completion_enter,
1020 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE,
1021 scic_sds_stp_request_started_non_data_await_d2h_enter,
1026 //******************************************************************************
1027 //* STP PIO STATE MACHINE
1028 //******************************************************************************
1030 #define SCU_MAX_FRAME_BUFFER_SIZE 0x400 // 1K is the maximum SCU frame data payload
1033 * This function will transmit DATA_FIS from (current sgl + offset) for input parameter length.
1034 * current sgl and offset is alreay stored in the IO request
1036 * @param[in] this_request
1039 * @return SCI_STATUS
1042 SCI_STATUS scic_sds_stp_request_pio_data_out_trasmit_data_frame (
1043 SCIC_SDS_REQUEST_T * this_request,
1047 SCI_STATUS status = SCI_SUCCESS;
1048 SCU_SGL_ELEMENT_T * current_sgl;
1049 SCIC_SDS_STP_REQUEST_T * this_sds_stp_request = (SCIC_SDS_STP_REQUEST_T *)this_request;
1051 // Recycle the TC and reconstruct it for sending out DATA FIS containing
1052 // for the data from current_sgl+offset for the input length
1053 SCU_TASK_CONTEXT_T * task_context = scic_sds_controller_get_task_context_buffer(
1054 this_request->owning_controller,
1055 this_request->io_tag
1058 if (this_sds_stp_request->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A)
1060 current_sgl = &(this_sds_stp_request->type.pio.request_current.sgl_pair->A);
1064 current_sgl = &(this_sds_stp_request->type.pio.request_current.sgl_pair->B);
1068 task_context->command_iu_upper = current_sgl->address_upper;
1069 task_context->command_iu_lower = current_sgl->address_lower;
1070 task_context->transfer_length_bytes = length;
1071 task_context->type.stp.fis_type = SATA_FIS_TYPE_DATA;
1073 // send the new TC out.
1074 status = this_request->owning_controller->state_handlers->parent.continue_io_handler(
1075 &this_request->owning_controller->parent,
1076 &this_request->target_device->parent,
1077 &this_request->parent
1087 * @param[in] this_request
1089 * @return SCI_STATUS
1092 SCI_STATUS scic_sds_stp_request_pio_data_out_transmit_data(
1093 SCIC_SDS_REQUEST_T * this_sds_request
1097 SCU_SGL_ELEMENT_T * current_sgl;
1099 U32 remaining_bytes_in_current_sgl = 0;
1100 SCI_STATUS status = SCI_SUCCESS;
1102 SCIC_SDS_STP_REQUEST_T * this_sds_stp_request = (SCIC_SDS_STP_REQUEST_T *)this_sds_request;
1104 sgl_offset = this_sds_stp_request->type.pio.request_current.sgl_offset;
1106 if (this_sds_stp_request->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A)
1108 current_sgl = &(this_sds_stp_request->type.pio.request_current.sgl_pair->A);
1109 remaining_bytes_in_current_sgl = this_sds_stp_request->type.pio.request_current.sgl_pair->A.length - sgl_offset;
1113 current_sgl = &(this_sds_stp_request->type.pio.request_current.sgl_pair->B);
1114 remaining_bytes_in_current_sgl = this_sds_stp_request->type.pio.request_current.sgl_pair->B.length - sgl_offset;
1118 if (this_sds_stp_request->type.pio.pio_transfer_bytes > 0)
1120 if (this_sds_stp_request->type.pio.pio_transfer_bytes >= remaining_bytes_in_current_sgl )
1122 //recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = remaining_bytes_in_current_sgl
1123 status = scic_sds_stp_request_pio_data_out_trasmit_data_frame (this_sds_request, remaining_bytes_in_current_sgl);
1124 if (status == SCI_SUCCESS)
1126 this_sds_stp_request->type.pio.pio_transfer_bytes -= remaining_bytes_in_current_sgl;
1130 else if (this_sds_stp_request->type.pio.pio_transfer_bytes < remaining_bytes_in_current_sgl )
1132 //recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = type.pio.pio_transfer_bytes
1133 scic_sds_stp_request_pio_data_out_trasmit_data_frame (this_sds_request, this_sds_stp_request->type.pio.pio_transfer_bytes);
1135 if (status == SCI_SUCCESS)
1137 //Sgl offset will be adjusted and saved for future
1138 sgl_offset += this_sds_stp_request->type.pio.pio_transfer_bytes;
1139 current_sgl->address_lower += this_sds_stp_request->type.pio.pio_transfer_bytes;
1140 this_sds_stp_request->type.pio.pio_transfer_bytes = 0;
1145 if (status == SCI_SUCCESS)
1147 this_sds_stp_request->type.pio.request_current.sgl_offset = sgl_offset;
1154 * Copy the data from the buffer for the length specified to the IO reqeust
1155 * SGL specified data region.
1157 * @param[in] this_request The request that is used for the SGL processing.
1158 * @param[in] data_buffer The buffer of data to be copied.
1159 * @param[in] length The length of the data transfer.
1161 * @return SCI_STATUS
1164 SCI_STATUS scic_sds_stp_request_pio_data_in_copy_data_buffer(
1165 SCIC_SDS_STP_REQUEST_T * this_request,
1171 SCU_SGL_ELEMENT_T * current_sgl;
1174 U8 * source_address;
1176 // Initial setup to get the current working SGL and the offset within the buffer
1178 (this_request->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A) ?
1179 &(this_request->type.pio.request_current.sgl_pair->A) :
1180 &(this_request->type.pio.request_current.sgl_pair->B) ;
1182 sgl_offset = this_request->type.pio.request_current.sgl_offset;
1184 source_address = data_buffer;
1185 data_offset = this_request->type.pio.current_transfer_bytes;
1186 status = SCI_SUCCESS;
1188 // While we are still doing Ok and there is more data to transfer
1191 && (status == SCI_SUCCESS)
1194 if (current_sgl->length == sgl_offset)
1196 // This SGL has been exauhasted so we need to get the next SGL
1197 current_sgl = scic_sds_stp_request_pio_get_next_sgl(this_request);
1199 if (current_sgl == NULL)
1200 status = SCI_FAILURE;
1206 #ifdef ENABLE_OSSL_COPY_BUFFER
1207 scic_cb_io_request_copy_buffer(this_request, data_buffer, data_offset, length);
1210 U8 * destination_address;
1213 destination_address = (U8 *)scic_cb_io_request_get_virtual_address_from_sgl(
1218 copy_length = MIN(length, current_sgl->length - sgl_offset);
1220 memcpy(destination_address, source_address, copy_length);
1222 length -= copy_length;
1223 sgl_offset += copy_length;
1224 data_offset += copy_length;
1225 source_address += copy_length;
1230 this_request->type.pio.request_current.sgl_offset = sgl_offset;
1236 * Copy the data buffer to the io request data region.
1238 * @param[in] this_request The PIO DATA IN request that is to receive the
1240 * @param[in] data_buffer The buffer to copy from.
1242 * @return SCI_STATUS
1245 SCI_STATUS scic_sds_stp_request_pio_data_in_copy_data(
1246 SCIC_SDS_STP_REQUEST_T * this_request,
1252 // If there is less than 1K remaining in the transfer request
1253 // copy just the data for the transfer
1254 if (this_request->type.pio.pio_transfer_bytes < SCU_MAX_FRAME_BUFFER_SIZE)
1256 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
1257 this_request,data_buffer,this_request->type.pio.pio_transfer_bytes);
1259 if (status == SCI_SUCCESS)
1261 // All data for this PIO request has now been copied, so we don't
1262 // technically need to update current_transfer_bytes here - just
1263 // doing it for completeness.
1264 this_request->type.pio.current_transfer_bytes += this_request->type.pio.pio_transfer_bytes;
1265 this_request->type.pio.pio_transfer_bytes = 0;
1270 // We are transfering the whole frame so copy
1271 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
1272 this_request, data_buffer, SCU_MAX_FRAME_BUFFER_SIZE);
1274 if (status == SCI_SUCCESS)
1276 this_request->type.pio.pio_transfer_bytes -= SCU_MAX_FRAME_BUFFER_SIZE;
1277 this_request->type.pio.current_transfer_bytes += SCU_MAX_FRAME_BUFFER_SIZE;
1287 * @param[in] this_request
1288 * @param[in] completion_code
1290 * @return SCI_STATUS
1293 SCI_STATUS scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler(
1294 SCIC_SDS_REQUEST_T * this_request,
1298 SCI_STATUS status = SCI_SUCCESS;
1301 sci_base_object_get_logger(this_request),
1302 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1303 "scic_sds_stp_request_pio_data_in_await_h2d_completion_tc_completion_handler(0x%x, 0x%x) enter\n",
1304 this_request, completion_code
1307 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code))
1309 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1310 scic_sds_request_set_status(
1311 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1314 sci_base_state_machine_change_state(
1315 &this_request->started_substate_machine,
1316 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1321 // All other completion status cause the IO to be complete. If a NAK
1322 // was received, then it is up to the user to retry the request.
1323 scic_sds_request_set_status(
1325 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1326 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1329 sci_base_state_machine_change_state(
1330 &this_request->parent.state_machine,
1331 SCI_BASE_REQUEST_STATE_COMPLETED
1342 * @param[in] this_request
1343 * @param[in] frame_index
1345 * @return SCI_STATUS
1348 SCI_STATUS scic_sds_stp_request_pio_await_frame_frame_handler(
1349 SCIC_SDS_REQUEST_T * request,
1354 SATA_FIS_HEADER_T * frame_header;
1356 SCIC_SDS_STP_REQUEST_T * this_request;
1357 SCIC_SDS_CONTROLLER_T * owning_controller;
1359 this_request = (SCIC_SDS_STP_REQUEST_T *)request;
1361 // Save off the controller, so that we do not touch the request after it
1363 owning_controller = this_request->parent.owning_controller;
1366 sci_base_object_get_logger(this_request),
1367 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1368 "scic_sds_stp_request_pio_data_in_await_frame_frame_handler(0x%x, 0x%x) enter\n",
1369 this_request, frame_index
1372 status = scic_sds_unsolicited_frame_control_get_header(
1373 &(owning_controller->uf_control),
1375 (void**) &frame_header
1378 if (status == SCI_SUCCESS)
1380 switch (frame_header->fis_type)
1382 case SATA_FIS_TYPE_PIO_SETUP:
1383 // Get from the frame buffer the PIO Setup Data
1384 scic_sds_unsolicited_frame_control_get_buffer(
1385 &(owning_controller->uf_control),
1387 (void**) &frame_buffer
1390 // Get the data from the PIO Setup
1391 // The SCU Hardware returns first word in the frame_header and the rest
1392 // of the data is in the frame buffer so we need to back up one dword
1393 this_request->type.pio.pio_transfer_bytes =
1394 (U16)((SATA_FIS_PIO_SETUP_T *)(&frame_buffer[-1]))->transfter_count;
1395 this_request->type.pio.ending_status =
1396 (U8)((SATA_FIS_PIO_SETUP_T *)(&frame_buffer[-1]))->ending_status;
1398 scic_sds_controller_copy_sata_response(
1399 &this_request->d2h_reg_fis, (U32 *)frame_header, frame_buffer
1402 this_request->d2h_reg_fis.status =
1403 this_request->type.pio.ending_status;
1405 //The next state is dependent on whether the request was PIO Data-in or Data out
1406 if (this_request->type.pio.sat_protocol == SAT_PROTOCOL_PIO_DATA_IN)
1408 sci_base_state_machine_change_state(
1409 &this_request->parent.started_substate_machine,
1410 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
1413 else if (this_request->type.pio.sat_protocol == SAT_PROTOCOL_PIO_DATA_OUT)
1416 status = scic_sds_stp_request_pio_data_out_transmit_data ( request);
1417 if (status == SCI_SUCCESS)
1419 sci_base_state_machine_change_state(
1420 &this_request->parent.started_substate_machine,
1421 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
1427 case SATA_FIS_TYPE_SETDEVBITS:
1428 sci_base_state_machine_change_state(
1429 &this_request->parent.started_substate_machine,
1430 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1434 case SATA_FIS_TYPE_REGD2H:
1435 if ( (frame_header->status & ATA_STATUS_REG_BSY_BIT) == 0)
1437 scic_sds_unsolicited_frame_control_get_buffer(
1438 &(owning_controller->uf_control),
1440 (void**) &frame_buffer
1443 scic_sds_controller_copy_sata_response(
1444 &this_request->d2h_reg_fis, (U32 *)frame_header, frame_buffer);
1446 scic_sds_request_set_status(
1447 &this_request->parent,
1448 SCU_TASK_DONE_CHECK_RESPONSE,
1449 SCI_FAILURE_IO_RESPONSE_VALID
1452 sci_base_state_machine_change_state(
1453 &this_request->parent.parent.state_machine,
1454 SCI_BASE_REQUEST_STATE_COMPLETED
1459 // Now why is the drive sending a D2H Register FIS when it is still busy?
1460 // Do nothing since we are still in the right state.
1462 sci_base_object_get_logger(this_request),
1463 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1464 "SCIC PIO Request 0x%x received D2H Register FIS with BSY status 0x%x\n",
1465 this_request, frame_header->status
1474 // Frame is decoded return it to the controller
1475 scic_sds_controller_release_frame(
1483 sci_base_object_get_logger(this_request),
1484 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1485 "SCIC IO Request 0x%x could not get frame header for frame index %d, status %x\n",
1486 this_request, frame_index, status
1496 * @param[in] this_request
1497 * @param[in] frame_index
1499 * @return SCI_STATUS
1502 SCI_STATUS scic_sds_stp_request_pio_data_in_await_data_frame_handler(
1503 SCIC_SDS_REQUEST_T * request,
1508 SATA_FIS_HEADER_T * frame_header;
1509 SATA_FIS_DATA_T * frame_buffer;
1510 SCIC_SDS_STP_REQUEST_T * this_request;
1511 SCIC_SDS_CONTROLLER_T * owning_controller;
1513 this_request = (SCIC_SDS_STP_REQUEST_T *)request;
1515 // Save off the controller, so that we do not touch the request after it
1517 owning_controller = this_request->parent.owning_controller;
1520 sci_base_object_get_logger(this_request),
1521 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1522 "scic_sds_stp_request_pio_data_in_await_data_frame_handler(0x%x, 0x%x) enter\n",
1523 this_request, frame_index
1526 status = scic_sds_unsolicited_frame_control_get_header(
1527 &(owning_controller->uf_control),
1529 (void**) &frame_header
1532 if (status == SCI_SUCCESS)
1534 if (frame_header->fis_type == SATA_FIS_TYPE_DATA)
1536 if (this_request->type.pio.request_current.sgl_pair == NULL)
1538 this_request->parent.saved_rx_frame_index = frame_index;
1539 this_request->type.pio.pio_transfer_bytes = 0;
1543 status = scic_sds_unsolicited_frame_control_get_buffer(
1544 &(owning_controller->uf_control),
1546 (void**) &frame_buffer
1549 status = scic_sds_stp_request_pio_data_in_copy_data(this_request, (U8 *)frame_buffer);
1551 // Frame is decoded return it to the controller
1552 scic_sds_controller_release_frame(
1558 // Check for the end of the transfer, are there more bytes remaining
1559 // for this data transfer
1561 (status == SCI_SUCCESS)
1562 && (this_request->type.pio.pio_transfer_bytes == 0)
1565 if ((this_request->type.pio.ending_status & ATA_STATUS_REG_BSY_BIT) == 0)
1567 scic_sds_request_set_status(
1568 &this_request->parent,
1569 SCU_TASK_DONE_CHECK_RESPONSE,
1570 SCI_FAILURE_IO_RESPONSE_VALID
1573 sci_base_state_machine_change_state(
1574 &this_request->parent.parent.state_machine,
1575 SCI_BASE_REQUEST_STATE_COMPLETED
1580 sci_base_state_machine_change_state(
1581 &this_request->parent.started_substate_machine,
1582 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1590 sci_base_object_get_logger(this_request),
1591 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1592 "SCIC PIO Request 0x%x received frame %d with fis type 0x%02x when expecting a data fis.\n",
1593 this_request, frame_index, frame_header->fis_type
1596 scic_sds_request_set_status(
1597 &this_request->parent,
1599 SCI_FAILURE_IO_REQUIRES_SCSI_ABORT
1602 sci_base_state_machine_change_state(
1603 &this_request->parent.parent.state_machine,
1604 SCI_BASE_REQUEST_STATE_COMPLETED
1607 // Frame is decoded return it to the controller
1608 scic_sds_controller_release_frame(
1617 sci_base_object_get_logger(this_request),
1618 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1619 "SCIC IO Request 0x%x could not get frame header for frame index %d, status %x\n",
1620 this_request, frame_index, status
1631 * @param[in] this_request
1632 * @param[in] completion_code
1634 * @return SCI_STATUS
1637 SCI_STATUS scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler(
1639 SCIC_SDS_REQUEST_T * this_request,
1643 SCI_STATUS status = SCI_SUCCESS;
1644 BOOL all_frames_transferred = FALSE;
1646 SCIC_SDS_STP_REQUEST_T *this_scic_sds_stp_request = (SCIC_SDS_STP_REQUEST_T *) this_request;
1649 sci_base_object_get_logger(this_request),
1650 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1651 "scic_sds_stp_request_pio_data_in_await_h2d_completion_tc_completion_handler(0x%x, 0x%x) enter\n",
1652 this_request, completion_code
1655 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code))
1657 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1659 if (this_scic_sds_stp_request->type.pio.pio_transfer_bytes != 0)
1661 status = scic_sds_stp_request_pio_data_out_transmit_data ( this_request);
1662 if (status == SCI_SUCCESS)
1664 if (this_scic_sds_stp_request->type.pio.pio_transfer_bytes == 0)
1665 all_frames_transferred = TRUE;
1668 else if (this_scic_sds_stp_request->type.pio.pio_transfer_bytes == 0)
1670 //this will happen if the all data is written at the first time after the pio setup fis is recieved
1671 all_frames_transferred = TRUE;
1674 //all data transferred.
1675 if (all_frames_transferred)
1677 //Change the state to SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_FRAME_SUBSTATE
1678 //and wait for PIO_SETUP fis / or D2H REg fis.
1679 sci_base_state_machine_change_state(
1680 &this_request->started_substate_machine,
1681 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1687 // All other completion status cause the IO to be complete. If a NAK
1688 // was received, then it is up to the user to retry the request.
1689 scic_sds_request_set_status(
1691 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1692 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1695 sci_base_state_machine_change_state(
1696 &this_request->parent.state_machine,
1697 SCI_BASE_REQUEST_STATE_COMPLETED
1706 * This method will handle any link layer events while waiting for the data
1709 * @param[in] request This is the request which is receiving the event.
1710 * @param[in] event_code This is the event code that the request on which the
1711 * request is expected to take action.
1713 * @return SCI_STATUS
1714 * @retval SCI_SUCCESS
1715 * @retval SCI_FAILURE
1718 SCI_STATUS scic_sds_stp_request_pio_data_in_await_data_event_handler(
1719 SCIC_SDS_REQUEST_T * request,
1725 switch (scu_get_event_specifier(event_code))
1727 case SCU_TASK_DONE_CRC_ERR << SCU_EVENT_SPECIFIC_CODE_SHIFT:
1728 // We are waiting for data and the SCU has R_ERR the data frame.
1729 // Go back to waiting for the D2H Register FIS
1730 sci_base_state_machine_change_state(
1731 &request->started_substate_machine,
1732 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1735 status = SCI_SUCCESS;
1740 sci_base_object_get_logger(request),
1741 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1742 "SCIC PIO Request 0x%x received unexpected event 0x%08x\n",
1746 /// @todo Should we fail the PIO request when we get an unexpected event?
1747 status = SCI_FAILURE;
1754 // ---------------------------------------------------------------------------
1756 SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
1757 scic_sds_stp_request_started_pio_substate_handler_table
1758 [SCIC_SDS_STP_REQUEST_STARTED_PIO_MAX_SUBSTATES] =
1760 // SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
1763 scic_sds_request_default_start_handler,
1764 scic_sds_request_started_state_abort_handler,
1765 scic_sds_request_default_complete_handler,
1766 scic_sds_request_default_destruct_handler
1768 scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler,
1769 scic_sds_request_default_event_handler,
1770 scic_sds_request_default_frame_handler
1772 // SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1775 scic_sds_request_default_start_handler,
1776 //scic_sds_stp_pio_request_data_in_await_frame_abort_handler,
1777 scic_sds_request_started_state_abort_handler,
1778 scic_sds_request_default_complete_handler,
1779 scic_sds_request_default_destruct_handler
1781 scic_sds_request_default_tc_completion_handler,
1782 scic_sds_request_default_event_handler,
1783 scic_sds_stp_request_pio_await_frame_frame_handler
1785 // SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
1788 scic_sds_request_default_start_handler,
1789 //scic_sds_stp_pio_request_data_in_await_data_abort_handler,
1790 scic_sds_request_started_state_abort_handler,
1791 scic_sds_request_default_complete_handler,
1792 scic_sds_request_default_destruct_handler
1794 scic_sds_request_default_tc_completion_handler,
1795 scic_sds_stp_request_pio_data_in_await_data_event_handler,
1796 scic_sds_stp_request_pio_data_in_await_data_frame_handler
1798 //SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
1801 scic_sds_request_default_start_handler,
1802 scic_sds_request_started_state_abort_handler,
1803 scic_sds_request_default_complete_handler,
1804 scic_sds_request_default_destruct_handler
1806 scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler,
1807 scic_sds_request_default_event_handler,
1808 scic_sds_request_default_frame_handler
1813 void scic_sds_stp_request_started_pio_await_h2d_completion_enter(
1814 SCI_BASE_OBJECT_T *object
1817 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
1821 scic_sds_stp_request_started_pio_substate_handler_table,
1822 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
1825 scic_sds_remote_device_set_working_request(
1826 this_request->target_device, this_request);
1830 void scic_sds_stp_request_started_pio_await_frame_enter(
1831 SCI_BASE_OBJECT_T *object
1834 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
1838 scic_sds_stp_request_started_pio_substate_handler_table,
1839 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1844 void scic_sds_stp_request_started_pio_data_in_await_data_enter(
1845 SCI_BASE_OBJECT_T *object
1848 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
1852 scic_sds_stp_request_started_pio_substate_handler_table,
1853 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
1858 void scic_sds_stp_request_started_pio_data_out_transmit_data_enter(
1859 SCI_BASE_OBJECT_T *object
1862 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
1866 scic_sds_stp_request_started_pio_substate_handler_table,
1867 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
1871 // ---------------------------------------------------------------------------
1874 scic_sds_stp_request_started_pio_substate_table
1875 [SCIC_SDS_STP_REQUEST_STARTED_PIO_MAX_SUBSTATES] =
1878 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE,
1879 scic_sds_stp_request_started_pio_await_h2d_completion_enter,
1883 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE,
1884 scic_sds_stp_request_started_pio_await_frame_enter,
1888 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE,
1889 scic_sds_stp_request_started_pio_data_in_await_data_enter,
1893 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE,
1894 scic_sds_stp_request_started_pio_data_out_transmit_data_enter,
1899 //******************************************************************************
1900 //* UDMA REQUEST STATE MACHINE
1901 //******************************************************************************
1904 void scic_sds_stp_request_udma_complete_request(
1905 SCIC_SDS_REQUEST_T * this_request,
1907 SCI_STATUS sci_status
1910 scic_sds_request_set_status(
1911 this_request, scu_status, sci_status
1914 sci_base_state_machine_change_state(
1915 &this_request->parent.state_machine,
1916 SCI_BASE_REQUEST_STATE_COMPLETED
1923 * @param[in] this_request
1924 * @param[in] frame_index
1926 * @return SCI_STATUS
1929 SCI_STATUS scic_sds_stp_request_udma_general_frame_handler(
1930 SCIC_SDS_REQUEST_T * this_request,
1935 SATA_FIS_HEADER_T * frame_header;
1939 sci_base_object_get_logger(this_request),
1940 SCIC_LOG_OBJECT_STP_IO_REQUEST,
1941 "scic_sds_stp_pio_request_data_in_await_frame_frame_handler(0x%x, 0x%x) enter\n",
1942 this_request, frame_index
1945 status = scic_sds_unsolicited_frame_control_get_header(
1946 &this_request->owning_controller->uf_control,
1948 (void**) &frame_header
1952 (status == SCI_SUCCESS)
1953 && (frame_header->fis_type == SATA_FIS_TYPE_REGD2H)
1956 scic_sds_unsolicited_frame_control_get_buffer(
1957 &this_request->owning_controller->uf_control,
1959 (void**) &frame_buffer
1962 scic_sds_controller_copy_sata_response(
1963 &((SCIC_SDS_STP_REQUEST_T *)this_request)->d2h_reg_fis,
1964 (U32 *)frame_header,
1969 scic_sds_controller_release_frame(
1970 this_request->owning_controller, frame_index);
1976 * @brief This method process TC completions while in the state where
1977 * we are waiting for TC completions.
1979 * @param[in] this_request
1980 * @param[in] completion_code
1982 * @return SCI_STATUS
1985 SCI_STATUS scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler(
1986 SCIC_SDS_REQUEST_T * request,
1990 SCI_STATUS status = SCI_SUCCESS;
1991 SCIC_SDS_STP_REQUEST_T * this_request = (SCIC_SDS_STP_REQUEST_T *)request;
1993 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code))
1995 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1996 scic_sds_stp_request_udma_complete_request(
1997 &this_request->parent, SCU_TASK_DONE_GOOD, SCI_SUCCESS
2001 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS):
2002 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
2003 // We must check ther response buffer to see if the D2H Register FIS was
2004 // received before we got the TC completion.
2005 if (this_request->d2h_reg_fis.fis_type == SATA_FIS_TYPE_REGD2H)
2007 scic_sds_remote_device_suspend(
2008 this_request->parent.target_device,
2009 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code))
2012 scic_sds_stp_request_udma_complete_request(
2013 &this_request->parent,
2014 SCU_TASK_DONE_CHECK_RESPONSE,
2015 SCI_FAILURE_IO_RESPONSE_VALID
2020 // If we have an error completion status for the TC then we can expect a
2021 // D2H register FIS from the device so we must change state to wait for it
2022 sci_base_state_machine_change_state(
2023 &this_request->parent.started_substate_machine,
2024 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
2029 /// @todo Check to see if any of these completion status need to wait for
2030 /// the device to host register fis.
2031 /// @todo We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR - this comes only for B0
2032 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN):
2033 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
2034 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR):
2035 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR):
2036 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR):
2037 scic_sds_remote_device_suspend(
2038 this_request->parent.target_device,
2039 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code))
2041 // Fall through to the default case
2043 // All other completion status cause the IO to be complete.
2045 sci_base_object_get_logger(&this_request->parent),
2046 SCIC_LOG_OBJECT_STP_IO_REQUEST,
2047 "SCIC IO Request 0x%x returning CONTROLLER_SPECIFIC_IO_ERR for completion code 0x%x\n",
2048 &this_request->parent, completion_code
2050 scic_sds_stp_request_udma_complete_request(
2051 &this_request->parent,
2052 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
2053 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
2062 SCI_STATUS scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler(
2063 SCIC_SDS_REQUEST_T * this_request,
2069 // Use the general frame handler to copy the resposne data
2070 status = scic_sds_stp_request_udma_general_frame_handler(this_request, frame_index);
2072 if (status == SCI_SUCCESS)
2074 scic_sds_stp_request_udma_complete_request(
2076 SCU_TASK_DONE_CHECK_RESPONSE,
2077 SCI_FAILURE_IO_RESPONSE_VALID
2084 // ---------------------------------------------------------------------------
2086 SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
2087 scic_sds_stp_request_started_udma_substate_handler_table
2088 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_MAX_SUBSTATES] =
2090 // SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
2093 scic_sds_request_default_start_handler,
2094 scic_sds_request_started_state_abort_handler,
2095 scic_sds_request_default_complete_handler,
2096 scic_sds_request_default_destruct_handler
2098 scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler,
2099 scic_sds_request_default_event_handler,
2100 scic_sds_stp_request_udma_general_frame_handler
2102 // SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
2105 scic_sds_request_default_start_handler,
2106 scic_sds_request_started_state_abort_handler,
2107 scic_sds_request_default_complete_handler,
2108 scic_sds_request_default_destruct_handler
2110 scic_sds_request_default_tc_completion_handler,
2111 scic_sds_request_default_event_handler,
2112 scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler
2122 void scic_sds_stp_request_started_udma_await_tc_completion_enter(
2123 SCI_BASE_OBJECT_T *object
2126 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
2130 scic_sds_stp_request_started_udma_substate_handler_table,
2131 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
2136 * This state is entered when there is an TC completion failure. The hardware
2137 * received an unexpected condition while processing the IO request and now
2138 * will UF the D2H register FIS to complete the IO.
2143 void scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter(
2144 SCI_BASE_OBJECT_T *object
2147 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
2151 scic_sds_stp_request_started_udma_substate_handler_table,
2152 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
2156 // ---------------------------------------------------------------------------
2159 scic_sds_stp_request_started_udma_substate_table
2160 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_MAX_SUBSTATES] =
2163 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE,
2164 scic_sds_stp_request_started_udma_await_tc_completion_enter,
2168 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE,
2169 scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter,
2174 //******************************************************************************
2175 //* STP SOFT RESET STATE MACHINE
2176 //******************************************************************************
2179 * This method processes a TC completion. The expected TC completion is
2180 * for the transmission of the H2D register FIS containing the SATA/STP
2183 * @param[in] this_request
2184 * @param[in] completion_code
2186 * @return This method always successfully processes the TC completion.
2187 * @retval SCI_SUCCESS This value is always returned.
2190 SCI_STATUS scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler(
2191 SCIC_SDS_REQUEST_T * this_request,
2196 sci_base_object_get_logger(this_request),
2197 SCIC_LOG_OBJECT_STP_IO_REQUEST,
2198 "scic_sds_stp_request_soft_reset_await_h2d_tc_completion_handler(0x%x, 0x%x) enter\n",
2199 this_request, completion_code
2202 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code))
2204 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
2205 scic_sds_request_set_status(
2206 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
2209 sci_base_state_machine_change_state(
2210 &this_request->started_substate_machine,
2211 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
2216 // All other completion status cause the IO to be complete. If a NAK
2217 // was received, then it is up to the user to retry the request.
2218 scic_sds_request_set_status(
2220 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
2221 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
2224 sci_base_state_machine_change_state(
2225 &this_request->parent.state_machine, SCI_BASE_REQUEST_STATE_COMPLETED
2234 * This method processes a TC completion. The expected TC completion is
2235 * for the transmission of the H2D register FIS containing the SATA/STP
2238 * @param[in] this_request
2239 * @param[in] completion_code
2241 * @return This method always successfully processes the TC completion.
2242 * @retval SCI_SUCCESS This value is always returned.
2245 SCI_STATUS scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler(
2246 SCIC_SDS_REQUEST_T * this_request,
2251 sci_base_object_get_logger(this_request),
2252 SCIC_LOG_OBJECT_STP_IO_REQUEST,
2253 "scic_sds_stp_request_soft_reset_await_h2d_tc_completion_handler(0x%x, 0x%x) enter\n",
2254 this_request, completion_code
2257 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code))
2259 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
2260 scic_sds_request_set_status(
2261 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
2264 sci_base_state_machine_change_state(
2265 &this_request->started_substate_machine,
2266 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
2271 // All other completion status cause the IO to be complete. If a NAK
2272 // was received, then it is up to the user to retry the request.
2273 scic_sds_request_set_status(
2275 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
2276 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
2279 sci_base_state_machine_change_state(
2280 &this_request->parent.state_machine, SCI_BASE_REQUEST_STATE_COMPLETED
2289 * This method processes frames received from the target while waiting
2290 * for a device to host register FIS. If a non-register FIS is received
2291 * during this time, it is treated as a protocol violation from an
2294 * @param[in] request This parameter specifies the request for which a
2295 * frame has been received.
2296 * @param[in] frame_index This parameter specifies the index of the frame
2297 * that has been received.
2299 * @return Indicate if the received frame was processed successfully.
2302 SCI_STATUS scic_sds_stp_request_soft_reset_await_d2h_frame_handler(
2303 SCIC_SDS_REQUEST_T * request,
2308 SATA_FIS_HEADER_T * frame_header;
2310 SCIC_SDS_STP_REQUEST_T * this_request = (SCIC_SDS_STP_REQUEST_T *)request;
2312 // Save off the controller, so that we do not touch the request after it
2314 SCIC_SDS_CONTROLLER_T * owning_controller = this_request->parent.owning_controller;
2317 sci_base_object_get_logger(this_request),
2318 SCIC_LOG_OBJECT_STP_IO_REQUEST,
2319 "scic_sds_stp_request_soft_reset_await_d2h_frame_handler(0x%x, 0x%x) enter\n",
2320 this_request, frame_index
2323 status = scic_sds_unsolicited_frame_control_get_header(
2324 &(owning_controller->uf_control),
2326 (void**) &frame_header
2329 if (status == SCI_SUCCESS)
2331 switch (frame_header->fis_type)
2333 case SATA_FIS_TYPE_REGD2H:
2334 scic_sds_unsolicited_frame_control_get_buffer(
2335 &(owning_controller->uf_control),
2337 (void**) &frame_buffer
2340 scic_sds_controller_copy_sata_response(
2341 &this_request->d2h_reg_fis, (U32 *)frame_header, frame_buffer
2344 // The command has completed with error
2345 scic_sds_request_set_status(
2346 &this_request->parent,
2347 SCU_TASK_DONE_CHECK_RESPONSE,
2348 SCI_FAILURE_IO_RESPONSE_VALID
2354 sci_base_object_get_logger(this_request),
2355 SCIC_LOG_OBJECT_STP_IO_REQUEST,
2356 "IO Request:0x%x Frame Id:%d protocol violation occurred\n",
2357 this_request, frame_index
2360 scic_sds_request_set_status(
2361 &this_request->parent,
2362 SCU_TASK_DONE_UNEXP_FIS,
2363 SCI_FAILURE_PROTOCOL_VIOLATION
2368 sci_base_state_machine_change_state(
2369 &this_request->parent.parent.state_machine,
2370 SCI_BASE_REQUEST_STATE_COMPLETED
2373 // Frame has been decoded return it to the controller
2374 scic_sds_controller_release_frame(
2375 owning_controller, frame_index
2381 sci_base_object_get_logger(this_request),
2382 SCIC_LOG_OBJECT_STP_IO_REQUEST,
2383 "SCIC IO Request 0x%x could not get frame header for frame index %d, status %x\n",
2384 this_request, frame_index, status
2391 // ---------------------------------------------------------------------------
2393 SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
2394 scic_sds_stp_request_started_soft_reset_substate_handler_table
2395 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_MAX_SUBSTATES] =
2397 // SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
2400 scic_sds_request_default_start_handler,
2401 scic_sds_request_started_state_abort_handler,
2402 scic_sds_request_default_complete_handler,
2403 scic_sds_request_default_destruct_handler
2405 scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler,
2406 scic_sds_request_default_event_handler,
2407 scic_sds_request_default_frame_handler
2409 // SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
2412 scic_sds_request_default_start_handler,
2413 scic_sds_request_started_state_abort_handler,
2414 scic_sds_request_default_complete_handler,
2415 scic_sds_request_default_destruct_handler
2417 scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler,
2418 scic_sds_request_default_event_handler,
2419 scic_sds_request_default_frame_handler
2421 // SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
2424 scic_sds_request_default_start_handler,
2425 scic_sds_request_started_state_abort_handler,
2426 scic_sds_request_default_complete_handler,
2427 scic_sds_request_default_destruct_handler
2429 scic_sds_request_default_tc_completion_handler,
2430 scic_sds_request_default_event_handler,
2431 scic_sds_stp_request_soft_reset_await_d2h_frame_handler
2436 void scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter(
2437 SCI_BASE_OBJECT_T *object
2440 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
2444 scic_sds_stp_request_started_soft_reset_substate_handler_table,
2445 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
2448 scic_sds_remote_device_set_working_request(
2449 this_request->target_device, this_request
2454 void scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter(
2455 SCI_BASE_OBJECT_T *object
2459 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
2460 SATA_FIS_REG_H2D_T *h2d_fis;
2461 SCU_TASK_CONTEXT_T *task_context;
2463 // Clear the SRST bit
2464 h2d_fis = scic_stp_io_request_get_h2d_reg_address(this_request);
2465 h2d_fis->control = 0;
2467 // Clear the TC control bit
2468 task_context = scic_sds_controller_get_task_context_buffer(
2469 this_request->owning_controller, this_request->io_tag);
2470 task_context->control_frame = 0;
2472 status = this_request->owning_controller->state_handlers->parent.continue_io_handler(
2473 &this_request->owning_controller->parent,
2474 &this_request->target_device->parent,
2475 &this_request->parent
2478 if (status == SCI_SUCCESS)
2482 scic_sds_stp_request_started_soft_reset_substate_handler_table,
2483 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
2489 void scic_sds_stp_request_started_soft_reset_await_d2h_response_enter(
2490 SCI_BASE_OBJECT_T *object
2493 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
2497 scic_sds_stp_request_started_soft_reset_substate_handler_table,
2498 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
2502 // ---------------------------------------------------------------------------
2505 scic_sds_stp_request_started_soft_reset_substate_table
2506 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_MAX_SUBSTATES] =
2509 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE,
2510 scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter,
2514 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE,
2515 scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter,
2519 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE,
2520 scic_sds_stp_request_started_soft_reset_await_d2h_response_enter,
2525 // ---------------------------------------------------------------------------
2527 SCI_STATUS scic_io_request_construct_basic_sata(
2528 SCI_IO_REQUEST_HANDLE_T scic_io_request
2532 SCIC_SDS_REQUEST_T * request = (SCIC_SDS_REQUEST_T *)scic_io_request;
2535 sci_base_object_get_logger(scic_io_request),
2536 SCIC_LOG_OBJECT_STP_IO_REQUEST,
2537 "scic_io_request_construct_basic_sata(0x%x) enter\n",
2541 status = scic_sds_io_request_construct_sata(
2543 scic_cb_request_get_sat_protocol(request->user_request),
2544 scic_cb_io_request_get_transfer_length(request->user_request),
2545 scic_cb_io_request_get_data_direction(request->user_request),
2546 scic_cb_io_request_do_copy_rx_frames(request->user_request),
2553 // ---------------------------------------------------------------------------
2555 SCI_STATUS scic_io_request_construct_advanced_sata(
2556 SCI_IO_REQUEST_HANDLE_T scic_io_request,
2557 SCIC_IO_SATA_PARAMETERS_T * io_parameters
2561 SCIC_SDS_REQUEST_T * request = (SCIC_SDS_REQUEST_T *)scic_io_request;
2564 sci_base_object_get_logger(scic_io_request),
2565 SCIC_LOG_OBJECT_STP_IO_REQUEST,
2566 "scic_io_request_construct_basic_sata(0x%x) enter\n",
2570 status = scic_sds_io_request_construct_sata(
2572 scic_cb_request_get_sat_protocol(request->user_request),
2573 scic_sds_request_get_sgl_element_pair(request, 0)->A.length,
2574 scic_cb_io_request_get_data_direction(request->user_request),
2575 scic_cb_io_request_do_copy_rx_frames(request->user_request),
2576 io_parameters->do_translate_sgl