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 #if !defined(DISABLE_ATAPI)
58 #include <dev/isci/scil/scic_sds_stp_packet_request.h>
59 #include <dev/isci/scil/scic_sds_logger.h>
60 #include <dev/isci/scil/scic_sds_controller.h>
61 #include <dev/isci/scil/scic_sds_remote_device.h>
62 #include <dev/isci/scil/scic_remote_device.h>
63 #include <dev/isci/scil/sci_util.h>
64 #include <dev/isci/scil/intel_sas.h>
65 #include <dev/isci/scil/intel_ata.h>
66 #include <dev/isci/scil/intel_sata.h>
67 #include <dev/isci/scil/scic_user_callback.h>
68 #include <dev/isci/sci_environment.h>
69 #include <dev/isci/scil/intel_sat.h>
70 #include <dev/isci/scil/scic_sds_request.h>
71 #include <dev/isci/scil/scic_controller.h>
72 #include <dev/isci/scil/scu_completion_codes.h>
73 #include <dev/isci/scil/scu_task_context.h>
74 #include <dev/isci/scil/scic_sds_stp_packet_request.h>
75 #include <dev/isci/scil/sci_base_state.h>
78 * @brief This method will fill in the SCU Task Context for a PACKET fis. And
79 * construct the request STARTED sub-state machine for Packet Protocol
82 * @param[in] this_request This parameter specifies the stp packet request object
87 SCI_STATUS scic_sds_stp_packet_request_construct(
88 SCIC_SDS_REQUEST_T *this_request
91 SATA_FIS_REG_H2D_T * h2d_fis =
92 scic_stp_io_request_get_h2d_reg_address(
96 // Work around, we currently only support PACKET DMA protocol, so we
97 // need to make change to Packet Fis features field.
98 h2d_fis->features = h2d_fis->features | ATA_PACKET_FEATURE_DMA;
100 scic_sds_stp_non_ncq_request_construct(this_request);
102 // Build the Packet Fis task context structure
103 scu_stp_raw_request_construct_task_context(
104 (SCIC_SDS_STP_REQUEST_T*) this_request,
105 this_request->task_context_buffer
108 sci_base_state_machine_construct(
109 &this_request->started_substate_machine,
110 &this_request->parent.parent,
111 scic_sds_stp_packet_request_started_substate_table,
112 SCIC_SDS_STP_PACKET_REQUEST_STARTED_PACKET_PHASE_AWAIT_TC_COMPLETION_SUBSTATE
120 * @brief This method will fill in the SCU Task Context for a Packet request
121 * command phase in PACKET DMA DATA (IN/OUT) type. The following
122 * important settings are utilized:
124 * -# task_type == SCU_TASK_TYPE_PACKET_DMA. This simply indicates
125 * that a normal request type (i.e. non-raw frame) is being
126 * utilized to perform task management.
127 * -# control_frame == 1. This ensures that the proper endianess
128 * is set so that the bytes are transmitted in the right order
129 * for a smp request frame.
131 * @param[in] this_request This parameter specifies the smp request object
133 * @param[in] task_context The task_context to be reconstruct for packet
134 * request command phase.
137 void scu_stp_packet_request_command_phase_construct_task_context(
138 SCIC_SDS_REQUEST_T * this_request,
139 SCU_TASK_CONTEXT_T * task_context
143 U32 atapi_cdb_length;
144 SCIC_SDS_STP_REQUEST_T * stp_request = (SCIC_SDS_STP_REQUEST_T *)this_request;
146 // reference: SSTL 1.13.4.2
147 // task_type, sata_direction
148 if ( scic_cb_io_request_get_data_direction(this_request->user_request)
149 == SCI_IO_REQUEST_DATA_OUT )
151 task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_OUT;
152 task_context->sata_direction = 0;
154 else // todo: for NO_DATA command, we need to send out raw frame.
156 task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_IN;
157 task_context->sata_direction = 1;
161 memset(&(task_context->type.stp), 0, sizeof(struct STP_TASK_CONTEXT));
162 task_context->type.stp.fis_type = SATA_FIS_TYPE_DATA;
164 // Copy in the command IU with CDB so that the commandIU address doesn't
166 memset(this_request->command_buffer, 0, sizeof(SATA_FIS_REG_H2D_T));
169 scic_cb_stp_packet_io_request_get_cdb_address(this_request->user_request);
172 scic_cb_stp_packet_io_request_get_cdb_length(this_request->user_request);
174 memcpy(((U8 *)this_request->command_buffer+sizeof(U32)), atapi_cdb, atapi_cdb_length);
177 MAX(atapi_cdb_length, stp_request->type.packet.device_preferred_cdb_length);
179 task_context->ssp_command_iu_length =
180 ((atapi_cdb_length % 4) == 0) ?
181 (atapi_cdb_length / 4) : ((atapi_cdb_length / 4) + 1);
183 // task phase is set to TX_CMD
184 task_context->task_phase = 0x1;
187 task_context->stp_retry_count = 0;
189 if (scic_cb_request_is_initial_construction(this_request->user_request))
191 // data transfer size.
192 task_context->transfer_length_bytes =
193 scic_cb_io_request_get_transfer_length(this_request->user_request);
195 // sgls were already built when request was constructed, so don't need to
200 // data transfer size, need to be 4 bytes aligned.
201 task_context->transfer_length_bytes = (SCSI_FIXED_SENSE_DATA_BASE_LENGTH + 2);
203 scic_sds_stp_packet_internal_request_sense_build_sgl(this_request);
208 * @brief This method will fill in the SCU Task Context for a DATA fis
209 * containing CDB in Raw Frame type. The TC for previous Packet
210 * fis was already there, we only need to change the H2D fis content.
212 * @param[in] this_request This parameter specifies the smp request object
214 * @param[in] task_context The task_context to be reconstruct for packet
215 * request command phase.
218 void scu_stp_packet_request_command_phase_reconstruct_raw_frame_task_context(
219 SCIC_SDS_REQUEST_T * this_request,
220 SCU_TASK_CONTEXT_T * task_context
224 scic_cb_stp_packet_io_request_get_cdb_address(this_request->user_request);
226 U32 atapi_cdb_length =
227 scic_cb_stp_packet_io_request_get_cdb_length(this_request->user_request);
229 memset(this_request->command_buffer, 0, sizeof(SATA_FIS_REG_H2D_T));
230 memcpy( ((U8 *)this_request->command_buffer+sizeof(U32)), atapi_cdb, atapi_cdb_length);
232 memset(&(task_context->type.stp), 0, sizeof(struct STP_TASK_CONTEXT));
233 task_context->type.stp.fis_type = SATA_FIS_TYPE_DATA;
235 //Note the data send out has to be 4 bytes aligned. Or else out hardware will
236 //patch non-zero bytes and cause the target device unhappy.
237 task_context->transfer_length_bytes = 12;
242 *@brief This methods decode the D2H status FIS and retrieve the sense data,
243 * then pass the sense data to user request.
245 *@param[in] this_request The request receive D2H status FIS.
246 *@param[in] status_fis The D2H status fis to be processed.
249 SCI_STATUS scic_sds_stp_packet_request_process_status_fis(
250 SCIC_SDS_REQUEST_T * this_request,
251 SATA_FIS_REG_D2H_T * status_fis
254 SCI_STATUS status = SCI_SUCCESS;
256 //TODO: Process the error status fis, retrieve sense data.
257 if (status_fis->status & ATA_STATUS_REG_ERROR_BIT)
258 status = SCI_FAILURE_IO_RESPONSE_VALID;
264 *@brief This methods builds sgl for internal REQUEST SENSE stp packet
265 * command using this request response buffer, only one sge is
268 *@param[in] this_request The request receive request sense data.
271 void scic_sds_stp_packet_internal_request_sense_build_sgl(
272 SCIC_SDS_REQUEST_T * this_request
276 SCU_SGL_ELEMENT_PAIR_T *scu_sgl_list = NULL;
277 SCU_TASK_CONTEXT_T *task_context;
278 SCI_PHYSICAL_ADDRESS physical_address;
280 SCI_SSP_RESPONSE_IU_T * rsp_iu =
281 (SCI_SSP_RESPONSE_IU_T *)this_request->response_buffer;
282 sge = (void*)&rsp_iu->data[0];
284 task_context = (SCU_TASK_CONTEXT_T *)this_request->task_context_buffer;
285 scu_sgl_list = &task_context->sgl_pair_ab;
287 scic_cb_io_request_get_physical_address(
288 scic_sds_request_get_controller(this_request),
294 scu_sgl_list->A.address_upper = sci_cb_physical_address_upper(physical_address);
295 scu_sgl_list->A.address_lower = sci_cb_physical_address_lower(physical_address);
296 scu_sgl_list->A.length = task_context->transfer_length_bytes;
297 scu_sgl_list->A.address_modifier = 0;
299 SCU_SGL_ZERO(scu_sgl_list->B);
302 //******************************************************************************
303 //* STP PACKET REQUEST STATE MACHINES
304 //******************************************************************************
307 * @brief This method processes the completions transport layer (TL) status
308 * to determine if the Packet FIS was sent successfully. If the Packet
309 * FIS was sent successfully, then the state for the Packet request
310 * transits to waiting for a PIO SETUP frame.
312 * @param[in] this_request This parameter specifies the request for which
313 * the TC completion was received.
314 * @param[in] completion_code This parameter indicates the completion status
315 * information for the TC.
317 * @return Indicate if the tc completion handler was successful.
318 * @retval SCI_SUCCESS currently this method always returns success.
321 SCI_STATUS scic_sds_stp_packet_request_packet_phase_await_tc_completion_tc_completion_handler(
322 SCIC_SDS_REQUEST_T * this_request,
326 SCI_STATUS status = SCI_SUCCESS;
329 sci_base_object_get_logger(this_request),
330 SCIC_LOG_OBJECT_STP_IO_REQUEST,
331 "scic_sds_stp_packet_request_packet_phase_await_tc_completion_tc_completion_handler(0x%x, 0x%x) enter\n",
332 this_request, completion_code
335 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code))
337 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
338 scic_sds_request_set_status(
339 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
342 sci_base_state_machine_change_state(
343 &this_request->started_substate_machine,
344 SCIC_SDS_STP_PACKET_REQUEST_STARTED_PACKET_PHASE_AWAIT_PIO_SETUP_SUBSTATE
349 // All other completion status cause the IO to be complete. If a NAK
350 // was received, then it is up to the user to retry the request.
351 scic_sds_request_set_status(
353 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
354 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
357 sci_base_state_machine_change_state(
358 &this_request->parent.state_machine,
359 SCI_BASE_REQUEST_STATE_COMPLETED
369 * @brief This method processes an unsolicited frame while the Packet request
370 * is waiting for a PIO SETUP FIS. It will release
371 * the unsolicited frame, and transition the request to the
372 * COMMAND_PHASE_AWAIT_TC_COMPLETION_SUBSTATE state.
374 * @param[in] this_request This parameter specifies the request for which
375 * the unsolicited frame was received.
376 * @param[in] frame_index This parameter indicates the unsolicited frame
377 * index that should contain the response.
379 * @return This method returns an indication of whether the pio setup
380 * frame was handled successfully or not.
381 * @retval SCI_SUCCESS Currently this value is always returned and indicates
382 * successful processing of the TC response.
386 SCI_STATUS scic_sds_stp_packet_request_packet_phase_await_pio_setup_frame_handler(
387 SCIC_SDS_REQUEST_T * request,
392 SATA_FIS_HEADER_T * frame_header;
394 SCIC_SDS_STP_REQUEST_T * this_request;
396 this_request = (SCIC_SDS_STP_REQUEST_T *)request;
399 sci_base_object_get_logger(this_request),
400 SCIC_LOG_OBJECT_STP_IO_REQUEST,
401 "scic_sds_stp_packet_request_packet_phase_await_pio_setup_frame_handler(0x%x, 0x%x) enter\n",
402 this_request, frame_index
405 status = scic_sds_unsolicited_frame_control_get_header(
406 &(this_request->parent.owning_controller->uf_control),
408 (void**) &frame_header
411 if (status == SCI_SUCCESS)
413 ASSERT(frame_header->fis_type == SATA_FIS_TYPE_PIO_SETUP);
415 // Get from the frame buffer the PIO Setup Data, although we don't need
416 // any info from this pio setup fis.
417 scic_sds_unsolicited_frame_control_get_buffer(
418 &(this_request->parent.owning_controller->uf_control),
420 (void**) &frame_buffer
423 // Get the data from the PIO Setup
424 // The SCU Hardware returns first word in the frame_header and the rest
425 // of the data is in the frame buffer so we need to back up one dword
426 this_request->type.packet.device_preferred_cdb_length =
427 (U16)((SATA_FIS_PIO_SETUP_T *)(&frame_buffer[-1]))->transfter_count;
429 // Frame has been decoded return it to the controller
430 scic_sds_controller_release_frame(
431 this_request->parent.owning_controller, frame_index
434 sci_base_state_machine_change_state(
435 &this_request->parent.started_substate_machine,
436 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMMAND_PHASE_AWAIT_TC_COMPLETION_SUBSTATE
442 sci_base_object_get_logger(this_request),
443 SCIC_LOG_OBJECT_STP_IO_REQUEST,
444 "SCIC IO Request 0x%x could not get frame header for frame index %d, status %x\n",
445 this_request, frame_index, status
454 * @brief This method processes the completions transport layer (TL) status
455 * to determine if the PACKET command data FIS was sent successfully.
456 * If successfully, then the state for the packet request
457 * transits to COMPLETE state. If not successfuly, the request transits
458 * to COMMAND_PHASE_AWAIT_D2H_FIS_SUBSTATE.
460 * @param[in] this_request This parameter specifies the request for which
461 * the TC completion was received.
462 * @param[in] completion_code This parameter indicates the completion status
463 * information for the TC.
465 * @return Indicate if the tc completion handler was successful.
466 * @retval SCI_SUCCESS currently this method always returns success.
469 SCI_STATUS scic_sds_stp_packet_request_command_phase_await_tc_completion_tc_completion_handler(
470 SCIC_SDS_REQUEST_T * this_request,
474 SCI_STATUS status = SCI_SUCCESS;
475 U8 sat_packet_protocol = this_request->sat_protocol;
478 sci_base_object_get_logger(this_request),
479 SCIC_LOG_OBJECT_STP_IO_REQUEST,
480 "scic_sds_stp_packet_request_command_phase_await_tc_completion_tc_completion_handler(0x%x, 0x%x) enter\n",
481 this_request, completion_code
484 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code))
486 case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
487 scic_sds_request_set_status(
488 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
491 if ( sat_packet_protocol == SAT_PROTOCOL_PACKET_DMA_DATA_IN
492 || sat_packet_protocol == SAT_PROTOCOL_PACKET_DMA_DATA_OUT
494 sci_base_state_machine_change_state(
495 &this_request->parent.state_machine,
496 SCI_BASE_REQUEST_STATE_COMPLETED
499 sci_base_state_machine_change_state(
500 &this_request->started_substate_machine,
501 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMMAND_PHASE_AWAIT_D2H_FIS_SUBSTATE
505 case (SCU_TASK_DONE_UNEXP_FIS << SCU_COMPLETION_TL_STATUS_SHIFT):
506 if (scic_io_request_get_number_of_bytes_transferred(this_request) <
507 scic_cb_io_request_get_transfer_length(this_request->user_request))
509 scic_sds_request_set_status(
510 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS_IO_DONE_EARLY
513 sci_base_state_machine_change_state(
514 &this_request->started_substate_machine,
515 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMPLETION_DELAY_SUBSTATE
518 //change the device state to ATAPI_ERROR.
519 sci_base_state_machine_change_state(
520 &this_request->target_device->ready_substate_machine,
521 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_ATAPI_ERROR
524 status = this_request->sci_status;
528 case (SCU_TASK_DONE_EXCESS_DATA << SCU_COMPLETION_TL_STATUS_SHIFT):
529 //In this case, there is no UF coming after. compelte the IO now.
530 scic_sds_request_set_status(
531 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
534 sci_base_state_machine_change_state(
535 &this_request->parent.state_machine,
536 SCI_BASE_REQUEST_STATE_COMPLETED
542 if (this_request->sci_status != SCI_SUCCESS)
543 { //The io status was set already. This means an UF for the status
544 //fis was received already.
546 //A device suspension event is expected, we need to have the device
547 //coming out of suspension, then complete the IO.
548 sci_base_state_machine_change_state(
549 &this_request->started_substate_machine,
550 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMPLETION_DELAY_SUBSTATE
553 //change the device state to ATAPI_ERROR.
554 sci_base_state_machine_change_state(
555 &this_request->target_device->ready_substate_machine,
556 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_ATAPI_ERROR
559 status = this_request->sci_status;
562 { //If receiving any non-sucess TC status, no UF received yet, then an UF for
563 //the status fis is coming after.
564 scic_sds_request_set_status(
566 SCU_TASK_DONE_CHECK_RESPONSE,
567 SCI_FAILURE_IO_RESPONSE_VALID
570 sci_base_state_machine_change_state(
571 &this_request->started_substate_machine,
572 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMMAND_PHASE_AWAIT_D2H_FIS_SUBSTATE
583 * @brief This method processes an unsolicited frame.
585 * @param[in] this_request This parameter specifies the request for which
586 * the unsolicited frame was received.
587 * @param[in] frame_index This parameter indicates the unsolicited frame
588 * index that should contain the response.
590 * @return This method returns an indication of whether the UF
591 * frame was handled successfully or not.
592 * @retval SCI_SUCCESS Currently this value is always returned and indicates
593 * successful processing of the TC response.
597 SCI_STATUS scic_sds_stp_packet_request_command_phase_common_frame_handler(
598 SCIC_SDS_REQUEST_T * request,
603 SATA_FIS_HEADER_T * frame_header;
605 SCIC_SDS_STP_REQUEST_T * this_request;
607 this_request = (SCIC_SDS_STP_REQUEST_T *)request;
610 sci_base_object_get_logger(this_request),
611 SCIC_LOG_OBJECT_STP_IO_REQUEST,
612 "scic_sds_stp_packet_request_command_phase_await_d2h_frame_handler(0x%x, 0x%x) enter\n",
613 this_request, frame_index
616 status = scic_sds_unsolicited_frame_control_get_header(
617 &(this_request->parent.owning_controller->uf_control),
619 (void**) &frame_header
622 if (status == SCI_SUCCESS)
624 ASSERT(frame_header->fis_type == SATA_FIS_TYPE_REGD2H);
626 // Get from the frame buffer the PIO Setup Data, although we don't need
627 // any info from this pio setup fis.
628 scic_sds_unsolicited_frame_control_get_buffer(
629 &(this_request->parent.owning_controller->uf_control),
631 (void**) &frame_buffer
634 scic_sds_controller_copy_sata_response(
635 &this_request->d2h_reg_fis, (U32 *)frame_header, frame_buffer
638 // Frame has been decoded return it to the controller
639 scic_sds_controller_release_frame(
640 this_request->parent.owning_controller, frame_index
648 * @brief This method processes an unsolicited frame while the packet request is
649 * expecting TC completion. It will process the FIS and construct sense
652 * @param[in] this_request This parameter specifies the request for which
653 * the unsolicited frame was received.
654 * @param[in] frame_index This parameter indicates the unsolicited frame
655 * index that should contain the response.
657 * @return This method returns an indication of whether the UF
658 * frame was handled successfully or not.
659 * @retval SCI_SUCCESS Currently this value is always returned and indicates
660 * successful processing of the TC response.
664 SCI_STATUS scic_sds_stp_packet_request_command_phase_await_tc_completion_frame_handler(
665 SCIC_SDS_REQUEST_T * request,
669 SCIC_SDS_STP_REQUEST_T * this_request = (SCIC_SDS_STP_REQUEST_T *)request;
672 scic_sds_stp_packet_request_command_phase_common_frame_handler(
673 request, frame_index);
675 if (status == SCI_SUCCESS)
677 // The command has completed with error status from target device.
678 status = scic_sds_stp_packet_request_process_status_fis(
679 request, &this_request->d2h_reg_fis);
681 if (status != SCI_SUCCESS)
683 scic_sds_request_set_status(
684 &this_request->parent,
685 SCU_TASK_DONE_CHECK_RESPONSE,
690 scic_sds_request_set_status(
691 &this_request->parent, SCU_TASK_DONE_GOOD, SCI_SUCCESS
700 * @brief This method processes an unsolicited frame while the packet request is
701 * expecting TC completion. It will process the FIS and construct sense
704 * @param[in] this_request This parameter specifies the request for which
705 * the unsolicited frame was received.
706 * @param[in] frame_index This parameter indicates the unsolicited frame
707 * index that should contain the response.
709 * @return This method returns an indication of whether the UF
710 * frame was handled successfully or not.
711 * @retval SCI_SUCCESS Currently this value is always returned and indicates
712 * successful processing of the TC response.
716 SCI_STATUS scic_sds_stp_packet_request_command_phase_await_d2h_fis_frame_handler(
717 SCIC_SDS_REQUEST_T * request,
722 scic_sds_stp_packet_request_command_phase_common_frame_handler(
723 request, frame_index);
725 SCIC_SDS_STP_REQUEST_T * this_request = (SCIC_SDS_STP_REQUEST_T *)request;
727 if (status == SCI_SUCCESS)
729 // The command has completed with error status from target device.
730 status = scic_sds_stp_packet_request_process_status_fis(
731 request, &this_request->d2h_reg_fis);
733 if (status != SCI_SUCCESS)
735 scic_sds_request_set_status(
737 SCU_TASK_DONE_CHECK_RESPONSE,
742 scic_sds_request_set_status(
743 request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
746 //Always complete the NON_DATA command right away, no need to delay completion
747 //even an error status fis came from target device.
748 sci_base_state_machine_change_state(
749 &request->parent.state_machine,
750 SCI_BASE_REQUEST_STATE_COMPLETED
758 SCI_STATUS scic_sds_stp_packet_request_started_completion_delay_complete_handler(
759 SCI_BASE_REQUEST_T *request
762 SCIC_SDS_REQUEST_T * this_request = (SCIC_SDS_REQUEST_T *)request;
764 sci_base_state_machine_change_state(
765 &this_request->parent.state_machine,
766 SCI_BASE_REQUEST_STATE_COMPLETED
769 return this_request->sci_status;
772 // ---------------------------------------------------------------------------
774 SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
775 scic_sds_stp_packet_request_started_substate_handler_table
776 [SCIC_SDS_STP_PACKET_REQUEST_STARTED_MAX_SUBSTATES] =
778 // SCIC_SDS_STP_PACKET_REQUEST_STARTED_PACKET_PHASE_AWAIT_TC_COMPLETION_SUBSTATE
781 scic_sds_request_default_start_handler,
782 scic_sds_request_started_state_abort_handler,
783 scic_sds_request_default_complete_handler,
784 scic_sds_request_default_destruct_handler
786 scic_sds_stp_packet_request_packet_phase_await_tc_completion_tc_completion_handler,
787 scic_sds_request_default_event_handler,
788 scic_sds_request_default_frame_handler
790 // SCIC_SDS_STP_PACKET_REQUEST_STARTED_PACKET_PHASE_AWAIT_PIO_SETUP_SUBSTATE
793 scic_sds_request_default_start_handler,
794 scic_sds_request_started_state_abort_handler,
795 scic_sds_request_default_complete_handler,
796 scic_sds_request_default_destruct_handler
798 scic_sds_request_default_tc_completion_handler,
799 scic_sds_request_default_event_handler,
800 scic_sds_stp_packet_request_packet_phase_await_pio_setup_frame_handler
802 // SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMMAND_PHASE_AWAIT_TC_COMPLETION_SUBSTATE
805 scic_sds_request_default_start_handler,
806 scic_sds_request_started_state_abort_handler,
807 scic_sds_request_default_complete_handler,
808 scic_sds_request_default_destruct_handler
810 scic_sds_stp_packet_request_command_phase_await_tc_completion_tc_completion_handler,
811 scic_sds_request_default_event_handler,
812 scic_sds_stp_packet_request_command_phase_await_tc_completion_frame_handler
814 // SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMMAND_PHASE_AWAIT_D2H_FIS_SUBSTATE
817 scic_sds_request_default_start_handler,
818 scic_sds_request_started_state_abort_handler,
819 scic_sds_request_default_complete_handler,
820 scic_sds_request_default_destruct_handler
822 scic_sds_request_default_tc_completion_handler,
823 scic_sds_request_default_event_handler,
824 scic_sds_stp_packet_request_command_phase_await_d2h_fis_frame_handler
826 // SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMPLETION_DELAY_SUBSTATE
829 scic_sds_request_default_start_handler,
830 scic_sds_request_started_state_abort_handler,
831 scic_sds_stp_packet_request_started_completion_delay_complete_handler,
832 scic_sds_request_default_destruct_handler
834 scic_sds_request_default_tc_completion_handler,
835 scic_sds_request_default_event_handler,
836 scic_sds_request_default_frame_handler
843 * @brief This file contains the Packet IO started substate machine
844 * for the SCIC_SDS_IO_REQUEST object.
847 void scic_sds_stp_packet_request_started_packet_phase_await_tc_completion_enter(
848 SCI_BASE_OBJECT_T *object
851 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
855 scic_sds_stp_packet_request_started_substate_handler_table,
856 SCIC_SDS_STP_PACKET_REQUEST_STARTED_PACKET_PHASE_AWAIT_TC_COMPLETION_SUBSTATE
859 scic_sds_remote_device_set_working_request(
860 this_request->target_device, this_request
865 void scic_sds_stp_packet_request_started_packet_phase_await_pio_setup_enter(
866 SCI_BASE_OBJECT_T *object
869 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
873 scic_sds_stp_packet_request_started_substate_handler_table,
874 SCIC_SDS_STP_PACKET_REQUEST_STARTED_PACKET_PHASE_AWAIT_PIO_SETUP_SUBSTATE
879 void scic_sds_stp_packet_request_started_command_phase_await_tc_completion_enter(
880 SCI_BASE_OBJECT_T *object
883 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
884 U8 sat_packet_protocol = this_request->sat_protocol;
886 SCU_TASK_CONTEXT_T *task_context;
889 // Recycle the TC and reconstruct it for sending out data fis containing
891 task_context = scic_sds_controller_get_task_context_buffer(
892 this_request->owning_controller, this_request->io_tag);
894 if (sat_packet_protocol == SAT_PROTOCOL_PACKET_NON_DATA)
895 scu_stp_packet_request_command_phase_reconstruct_raw_frame_task_context(
896 this_request, task_context);
898 scu_stp_packet_request_command_phase_construct_task_context(
899 this_request, task_context);
901 // send the new TC out.
902 status = this_request->owning_controller->state_handlers->parent.continue_io_handler(
903 &this_request->owning_controller->parent,
904 &this_request->target_device->parent,
905 &this_request->parent
908 if (status == SCI_SUCCESS)
911 scic_sds_stp_packet_request_started_substate_handler_table,
912 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMMAND_PHASE_AWAIT_TC_COMPLETION_SUBSTATE
917 void scic_sds_stp_packet_request_started_command_phase_await_d2h_fis_enter(
918 SCI_BASE_OBJECT_T *object
921 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
925 scic_sds_stp_packet_request_started_substate_handler_table,
926 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMMAND_PHASE_AWAIT_D2H_FIS_SUBSTATE
931 void scic_sds_stp_packet_request_started_completion_delay_enter(
932 SCI_BASE_OBJECT_T *object
935 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
939 scic_sds_stp_packet_request_started_substate_handler_table,
940 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMPLETION_DELAY_SUBSTATE
945 // ---------------------------------------------------------------------------
947 scic_sds_stp_packet_request_started_substate_table
948 [SCIC_SDS_STP_PACKET_REQUEST_STARTED_MAX_SUBSTATES] =
951 SCIC_SDS_STP_PACKET_REQUEST_STARTED_PACKET_PHASE_AWAIT_TC_COMPLETION_SUBSTATE,
952 scic_sds_stp_packet_request_started_packet_phase_await_tc_completion_enter,
956 SCIC_SDS_STP_PACKET_REQUEST_STARTED_PACKET_PHASE_AWAIT_PIO_SETUP_SUBSTATE,
957 scic_sds_stp_packet_request_started_packet_phase_await_pio_setup_enter,
961 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMMAND_PHASE_AWAIT_TC_COMPLETION_SUBSTATE,
962 scic_sds_stp_packet_request_started_command_phase_await_tc_completion_enter,
966 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMMAND_PHASE_AWAIT_D2H_FIS_SUBSTATE,
967 scic_sds_stp_packet_request_started_command_phase_await_d2h_fis_enter,
971 SCIC_SDS_STP_PACKET_REQUEST_STARTED_COMPLETION_DELAY_SUBSTATE,
972 scic_sds_stp_packet_request_started_completion_delay_enter,
977 #endif //#if !defined(DISABLE_ATAPI)