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/sati.h>
57 #include <dev/isci/scil/scif_sas_logger.h>
58 #include <dev/isci/scil/scif_sas_task_request.h>
59 #include <dev/isci/scil/scif_sas_controller.h>
60 #include <dev/isci/scil/scif_sas_remote_device.h>
61 #include <dev/isci/scil/scif_sas_stp_task_request.h>
62 #include <dev/isci/scil/scic_task_request.h>
63 #include <dev/isci/scil/scic_controller.h>
66 * @brief This method provides SATA/STP STARTED state specific handling for
67 * when the user attempts to complete the supplied IO request.
68 * It will perform data/response translation and free NCQ tags
71 * @param[in] io_request This parameter specifies the IO request object
74 * @return This method returns a value indicating if the IO request was
75 * successfully completed or not.
78 SCI_STATUS scif_sas_stp_core_cb_task_request_complete_handler(
79 SCIF_SAS_CONTROLLER_T * fw_controller,
80 SCIF_SAS_REMOTE_DEVICE_T * fw_device,
81 SCIF_SAS_REQUEST_T * fw_request,
82 SCI_STATUS * completion_status
85 #if !defined(DISABLE_SATI_TASK_MANAGEMENT)
86 SCIF_SAS_TASK_REQUEST_T * fw_task = (SCIF_SAS_TASK_REQUEST_T *) fw_request;
89 sci_base_object_get_logger(fw_controller),
90 SCIF_LOG_OBJECT_TASK_MANAGEMENT,
91 "scif_sas_stp_core_cb_task_request_complete_handler(0x%x, 0x%x, 0x%x, 0x%x) enter\n",
92 fw_controller, fw_device, fw_request, *completion_status
95 // Translating the response is only necessary if some sort of error
96 // occurred resulting in having the error bit set in the ATA status
97 // register and values to decode in the ATA error register.
98 if ( (*completion_status == SCI_SUCCESS)
99 || (*completion_status == SCI_FAILURE_IO_RESPONSE_VALID) )
101 SATI_STATUS sati_status = sati_translate_task_response(
102 &fw_task->parent.stp.sequence,
107 if (sati_status == SATI_COMPLETE)
108 *completion_status = SCI_SUCCESS;
109 else if (sati_status == SATI_FAILURE_CHECK_RESPONSE_DATA)
110 *completion_status = SCI_FAILURE_IO_RESPONSE_VALID;
111 else if (sati_status == SATI_SEQUENCE_INCOMPLETE)
113 // The translation indicates that additional SATA requests are
114 // necessary to finish the original SCSI request. As a result,
115 // do not complete the IO and begin the next stage of the
117 /// @todo multiple ATA commands are required, but not supported yet.
122 // Something unexpected occurred during translation. Fail the
123 // IO request to the user.
124 *completion_status = SCI_FAILURE;
127 else //A stp task request sometimes fails.
129 if (scif_sas_task_request_get_function(fw_task) == SCI_SAS_ABORT_TASK_SET)
131 scif_sas_stp_task_request_abort_task_set_failure_handler(
137 #else // !defined(DISABLE_SATI_TASK_MANAGEMENT)
139 #endif // !defined(DISABLE_SATI_TASK_MANAGEMENT)
145 * @brief This file contains the method implementations for the
146 * SCIF_SAS_STP_TASK_REQUEST object. The contents will implement
147 * SATA/STP specific functionality.
149 SCI_STATUS scif_sas_stp_task_request_construct(
150 SCIF_SAS_TASK_REQUEST_T * fw_task
153 SCI_STATUS sci_status = SCI_FAILURE;
155 #if !defined(DISABLE_SATI_TASK_MANAGEMENT)
156 SATI_STATUS sati_status;
157 SCIF_SAS_REMOTE_DEVICE_T * fw_device = fw_task->parent.device;
160 sci_base_object_get_logger(fw_task),
161 SCIF_LOG_OBJECT_TASK_MANAGEMENT,
162 "scif_sas_stp_task_request_construct(0x%x) enter\n",
166 // The translator will indirectly invoke core methods to set the fields
167 // of the ATA register FIS inside of this method.
168 sati_status = sati_translate_task_management(
169 &fw_task->parent.stp.sequence,
170 &fw_device->protocol_device.stp_device.sati_device,
175 if (sati_status == SATI_SUCCESS)
177 sci_status = scic_task_request_construct_sata(fw_task->parent.core_object);
178 //fw_task->parent.state_handlers = &stp_io_request_constructed_handlers;
179 fw_task->parent.protocol_complete_handler =
180 scif_sas_stp_core_cb_task_request_complete_handler;
185 sci_base_object_get_logger(fw_task),
186 SCIF_LOG_OBJECT_TASK_MANAGEMENT,
187 "Task 0x%x received unexpected SAT translation failure 0x%x\n",
191 #endif // !defined(DISABLE_SATI_TASK_MANAGEMENT)
198 * @brief This method provides handling for failed stp TASK MANAGEMENT
201 * @param[in] fw_device This parameter specifies the target device the
202 * task management request towards to.
203 * @param[in] fw_request This parameter specifies the failed task management
205 * @param[in] completion_status This parameter sprecifies the completion
206 * status of the task management request's core status.
210 void scif_sas_stp_task_request_abort_task_set_failure_handler(
211 SCIF_SAS_REMOTE_DEVICE_T * fw_device,
212 SCIF_SAS_TASK_REQUEST_T * fw_task
215 #if !defined(DISABLE_SATI_TASK_MANAGEMENT)
216 SCIF_SAS_DOMAIN_T * fw_domain = fw_device->domain;
217 SCI_FAST_LIST_ELEMENT_T * pending_request_element;
218 SCIF_SAS_REQUEST_T * pending_request = NULL;
220 pending_request_element = fw_domain->request_list.list_head;
222 // Cycle through the list of IO requests. search all the
223 // outstanding IOs with "waiting for abort task set" flag,
224 // completes them now.
225 while (pending_request_element != NULL)
228 (SCIF_SAS_REQUEST_T*) sci_fast_list_get_object(pending_request_element);
230 // The current element may be deleted from the list becasue of
231 // IO completion so advance to the next element early
232 pending_request_element = sci_fast_list_get_next(pending_request_element);
234 if ( pending_request->device == fw_device
235 && pending_request->is_waiting_for_abort_task_set == TRUE )
237 //In case the pending_request is still in the middle of aborting.
238 //abort it again to the core.
239 SCI_STATUS abort_status;
241 //Reset the flag now since we are process the read log ext command now.
242 pending_request->is_waiting_for_abort_task_set = FALSE;
244 abort_status = scic_controller_terminate_request(
245 fw_domain->controller->core_object,
246 fw_device->core_object,
247 pending_request->core_object
250 if (abort_status == SCI_FAILURE_INVALID_STATE)
252 //the request must have not be in aborting state anymore, complete it now.
253 scif_cb_io_request_complete(
254 fw_domain->controller,
257 SCI_IO_FAILURE_TERMINATED
260 //otherwise, the abort succeeded. Since the waiting flag is cleared,
261 //the pending request will be completed later.
264 #endif //#if !defined(DISABLE_SATI_TASK_MANAGEMENT)