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$");
59 * @brief This file contains the task management substate handlers for the
60 * SCIC_SDS_IO_REQUEST object.
61 * This file contains the enter/exit methods associated with each of
62 * the task management raw request states. For more information on the
63 * task management request state machine please refer to
64 * scic_sds_io_request.h
67 #include <dev/isci/scil/intel_sas.h>
68 #include <dev/isci/scil/scic_sds_request.h>
69 #include <dev/isci/scil/scic_controller.h>
70 #include <dev/isci/scil/scic_sds_logger.h>
71 #include <dev/isci/scil/scic_sds_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/sci_base_state_machine.h>
77 * @brief This method processes the completions transport layer (TL) status
78 * to determine if the RAW task management frame was sent successfully.
79 * If the raw frame was sent successfully, then the state for the
80 * task request transitions to waiting for a response frame.
82 * @param[in] this_request This parameter specifies the request for which
83 * the TC completion was received.
84 * @param[in] completion_code This parameter indicates the completion status
85 * information for the TC.
87 * @return Indicate if the tc completion handler was successful.
88 * @retval SCI_SUCCESS currently this method always returns success.
91 SCI_STATUS scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler(
92 SCIC_SDS_REQUEST_T * this_request,
97 sci_base_object_get_logger(this_request),
98 SCIC_LOG_OBJECT_TASK_MANAGEMENT,
99 "scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler(0x%x, 0x%x) enter\n",
100 this_request, completion_code
103 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code))
105 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
106 scic_sds_request_set_status(
107 this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
110 sci_base_state_machine_change_state(
111 &this_request->started_substate_machine,
112 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
116 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
117 // Currently, the decision is to simply allow the task request to
118 // timeout if the task IU wasn't received successfully.
119 // There is a potential for receiving multiple task responses if we
120 // decide to send the task IU again.
122 sci_base_object_get_logger(this_request),
123 SCIC_LOG_OBJECT_TASK_MANAGEMENT,
124 "TaskRequest:0x%x CompletionCode:%x - ACK/NAK timeout\n",
125 this_request, completion_code
128 sci_base_state_machine_change_state(
129 &this_request->started_substate_machine,
130 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
135 // All other completion status cause the IO to be complete. If a NAK
136 // was received, then it is up to the user to retry the request.
137 scic_sds_request_set_status(
139 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
140 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
143 sci_base_state_machine_change_state(
144 &this_request->parent.state_machine,
145 SCI_BASE_REQUEST_STATE_COMPLETED
154 * @brief This method is responsible for processing a terminate/abort
155 * request for this TC while the request is waiting for the task
156 * management response unsolicited frame.
158 * @param[in] this_request This parameter specifies the request for which
159 * the termination was requested.
161 * @return This method returns an indication as to whether the abort
162 * request was successfully handled.
164 * @todo need to update to ensure the received UF doesn't cause damage
165 * to subsequent requests (i.e. put the extended tag in a holding
166 * pattern for this particular device).
169 SCI_STATUS scic_sds_ssp_task_request_await_tc_response_abort_handler(
170 SCI_BASE_REQUEST_T * request
173 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)request;
176 sci_base_object_get_logger(this_request),
177 SCIC_LOG_OBJECT_TASK_MANAGEMENT,
178 "scic_sds_ssp_task_request_await_tc_response_abort_handler(0x%x) enter\n",
182 sci_base_state_machine_change_state(
183 &this_request->parent.state_machine,
184 SCI_BASE_REQUEST_STATE_ABORTING
187 sci_base_state_machine_change_state(
188 &this_request->parent.state_machine,
189 SCI_BASE_REQUEST_STATE_COMPLETED
196 * @brief This method processes an unsolicited frame while the task mgmt
197 * request is waiting for a response frame. It will copy the
198 * response data, release the unsolicited frame, and transition
199 * the request to the SCI_BASE_REQUEST_STATE_COMPLETED state.
201 * @param[in] this_request This parameter specifies the request for which
202 * the unsolicited frame was received.
203 * @param[in] frame_index This parameter indicates the unsolicited frame
204 * index that should contain the response.
206 * @return This method returns an indication of whether the TC response
207 * frame was handled successfully or not.
208 * @retval SCI_SUCCESS Currently this value is always returned and indicates
209 * successful processing of the TC response.
211 * @todo Should probably update to check frame type and make sure it is
215 SCI_STATUS scic_sds_ssp_task_request_await_tc_response_frame_handler(
216 SCIC_SDS_REQUEST_T * this_request,
220 // Save off the controller, so that we do not touch the request after it
222 SCIC_SDS_CONTROLLER_T * owning_controller = this_request->owning_controller;
225 sci_base_object_get_logger(this_request),
226 SCIC_LOG_OBJECT_TASK_MANAGEMENT,
227 "scic_sds_ssp_task_request_await_tc_response_frame_handler(0x%x, 0x%x) enter\n",
228 this_request, frame_index
231 scic_sds_io_request_copy_response(this_request);
233 sci_base_state_machine_change_state(
234 &this_request->parent.state_machine,
235 SCI_BASE_REQUEST_STATE_COMPLETED
238 scic_sds_controller_release_frame(
239 owning_controller, frame_index
245 SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
246 scic_sds_ssp_task_request_started_substate_handler_table
247 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_MAX_SUBSTATES] =
249 // SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
252 scic_sds_request_default_start_handler,
253 scic_sds_request_started_state_abort_handler,
254 scic_sds_request_default_complete_handler,
255 scic_sds_request_default_destruct_handler
257 scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler,
258 scic_sds_request_default_event_handler,
259 scic_sds_request_default_frame_handler
261 // SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
264 scic_sds_request_default_start_handler,
265 scic_sds_ssp_task_request_await_tc_response_abort_handler,
266 scic_sds_request_default_complete_handler,
267 scic_sds_request_default_destruct_handler
269 scic_sds_request_default_tc_completion_handler,
270 scic_sds_request_default_event_handler,
271 scic_sds_ssp_task_request_await_tc_response_frame_handler
276 * @brief This method performs the actions required when entering the
277 * SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
278 * sub-state. This includes setting the IO request state handlers
279 * for this sub-state.
281 * @param[in] object This parameter specifies the request object for which
282 * the sub-state change is occuring.
287 void scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter(
288 SCI_BASE_OBJECT_T *object
291 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
295 scic_sds_ssp_task_request_started_substate_handler_table,
296 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
301 * @brief This method performs the actions required when entering the
302 * SCIC_SDS_IO_REQUEST_STARTED_SUBSTATE_AWAIT_TC_RESPONSE sub-state.
303 * This includes setting the IO request state handlers for this
306 * @param[in] object This parameter specifies the request object for which
307 * the sub-state change is occuring.
312 void scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter(
313 SCI_BASE_OBJECT_T *object
316 SCIC_SDS_REQUEST_T *this_request = (SCIC_SDS_REQUEST_T *)object;
320 scic_sds_ssp_task_request_started_substate_handler_table,
321 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
325 SCI_BASE_STATE_T scic_sds_io_request_started_task_mgmt_substate_table
326 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_MAX_SUBSTATES] =
329 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION,
330 scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter,
334 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE,
335 scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter,