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 all of the method implementations pertaining
60 * to the framework remote device STARTING sub-state handler methods.
61 * The STARTING sub-state machine is responsible for ensuring that
62 * all initialization and configuration for a particular remote
63 * device is complete before transitioning to the READY state
64 * (i.e. before allowing normal host IO).
67 #include <dev/isci/scil/scic_remote_device.h>
69 #include <dev/isci/scil/scif_sas_logger.h>
70 #include <dev/isci/scil/scif_sas_remote_device.h>
71 #include <dev/isci/scil/scif_sas_domain.h>
72 #include <dev/isci/scil/scif_sas_task_request.h>
74 //******************************************************************************
75 //* G E N E R A L S T O P H A N D L E R S
76 //******************************************************************************
79 * @brief This method provides startig sub-state specific handling for
80 * when the remote device is requested to stop. This will occur
81 * when there is a link failure during the starting operation.
83 * @param[in] remote_device This parameter specifies the remote device
84 * object for which the failure condition occurred.
86 * @return This method returns an indication as to whether the failure
87 * operation completed successfully.
91 scif_sas_remote_device_starting_state_general_stop_handler(
92 SCI_BASE_REMOTE_DEVICE_T * remote_device
95 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)
99 sci_base_object_get_logger(fw_device),
100 SCIF_LOG_OBJECT_REMOTE_DEVICE,
101 "RemoteDevice:0x%x starting device requested to stop\n",
105 fw_device->domain->device_start_in_progress_count--;
107 sci_base_state_machine_change_state(
108 &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
114 //******************************************************************************
115 //* A W A I T C O M P L E T E H A N D L E R S
116 //******************************************************************************
119 * @brief This method provides AWAIT START COMPLETE sub-state specific
120 * handling for when the remote device undergoes a failure
123 * @param[in] remote_device This parameter specifies the remote device
124 * object for which the failure condition occurred.
126 * @return This method returns an indication as to whether the failure
127 * operation completed successfully.
130 SCI_STATUS scif_sas_remote_device_starting_await_complete_fail_handler(
131 SCI_BASE_REMOTE_DEVICE_T * remote_device
134 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)
138 sci_base_object_get_logger(fw_device),
139 SCIF_LOG_OBJECT_REMOTE_DEVICE,
140 "RemoteDevice:0x%x starting device failed, start complete not received\n",
144 sci_base_state_machine_change_state(
145 &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_FAILED
152 * @brief This method provides AWAIT COMPLETE state specific handling for
153 * when the core remote device object issues a device not ready
154 * notification. In the AWAIT COMPLETE state we do not inform
155 * the framework user of the state change of the device, since the
156 * user is unaware of the remote device start process.
158 * @param[in] remote_device This parameter specifies the remote device
159 * object for which the notification occurred.
164 void scif_sas_remote_device_starting_await_complete_not_ready_handler(
165 SCIF_SAS_REMOTE_DEVICE_T * fw_device,
172 * @brief This method provides AWAIT START COMPLETE sub-state specific
173 * handling for when the core provides a start complete notification
174 * for the remote device. If the start completion status indicates
175 * a successful start, then the device is transitioned into the
176 * READY state. All other status cause a transition to the
177 * FAILED state and a scif_cb_controller_error() notification
178 * message to the framework user.
180 * @param[in] fw_device This parameter specifies the remote device
181 * object for which the notification has occurred.
186 void scif_sas_remote_device_starting_await_complete_start_complete_handler(
187 SCIF_SAS_REMOTE_DEVICE_T * fw_device,
188 SCI_STATUS completion_status
191 if (completion_status == SCI_SUCCESS)
193 /** @todo need to add support for resetting the device first. This can
195 /** @todo Update to comprehend situations (i.e. SATA) where config is
198 sci_base_state_machine_change_state(
199 &fw_device->starting_substate_machine,
200 SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY
206 sci_base_object_get_logger(fw_device),
207 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_REMOTE_DEVICE_CONFIG,
208 "Device:0x%x Status:0x%x failed to start core device\n",
212 sci_base_state_machine_change_state(
213 &fw_device->parent.state_machine,
214 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
217 // Something is seriously wrong. Starting the core remote device
218 // shouldn't fail in anyway in this state.
219 scif_cb_controller_error(fw_device->domain->controller,
220 SCI_CONTROLLER_REMOTE_DEVICE_ERROR);
224 //******************************************************************************
225 //* C O M P L E T E H A N D L E R S
226 //******************************************************************************
229 * @brief This method provides STARTING AWAIT READY sub-state specific
230 * handling for when the core provides a device ready notification
231 * for the remote device. This essentially, causes a transition
232 * of the framework remote device into the READY state.
234 * @param[in] fw_device This parameter specifies the remote device
235 * object for which the notification has occurred.
240 void scif_sas_remote_device_starting_await_ready_ready_handler(
241 SCIF_SAS_REMOTE_DEVICE_T * fw_device
244 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
245 if (fw_device->destination_state ==
246 SCIF_SAS_REMOTE_DEVICE_DESTINATION_STATE_UPDATING_PORT_WIDTH)
249 sci_base_state_machine_change_state(
250 &fw_device->parent.state_machine,
251 SCI_BASE_REMOTE_DEVICE_STATE_UPDATING_PORT_WIDTH
258 sci_base_state_machine_change_state(
259 &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_READY
263 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
264 scif_sas_domain_remote_device_start_complete(fw_device->domain,fw_device);
269 SCIF_SAS_REMOTE_DEVICE_STATE_HANDLER_T
270 scif_sas_remote_device_starting_substate_handler_table[] =
272 // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_COMPLETE
275 scif_sas_remote_device_default_start_handler,
276 scif_sas_remote_device_starting_state_general_stop_handler,
277 scif_sas_remote_device_starting_await_complete_fail_handler,
278 scif_sas_remote_device_default_destruct_handler,
279 scif_sas_remote_device_default_reset_handler,
280 scif_sas_remote_device_default_reset_complete_handler,
281 scif_sas_remote_device_default_start_io_handler,
282 scif_sas_remote_device_default_complete_io_handler,
283 scif_sas_remote_device_default_continue_io_handler,
284 scif_sas_remote_device_default_start_task_handler,
285 scif_sas_remote_device_default_complete_task_handler
287 scif_sas_remote_device_starting_await_complete_start_complete_handler,
288 scif_sas_remote_device_default_stop_complete_handler,
289 scif_sas_remote_device_default_ready_handler,
290 scif_sas_remote_device_starting_await_complete_not_ready_handler,
291 scif_sas_remote_device_default_start_io_handler,
292 scif_sas_remote_device_default_complete_high_priority_io_handler
294 // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY
297 scif_sas_remote_device_default_start_handler,
298 scif_sas_remote_device_starting_state_general_stop_handler,
299 scif_sas_remote_device_starting_await_complete_fail_handler,
300 scif_sas_remote_device_default_destruct_handler,
301 scif_sas_remote_device_default_reset_handler,
302 scif_sas_remote_device_default_reset_complete_handler,
303 scif_sas_remote_device_default_start_io_handler,
304 scif_sas_remote_device_default_complete_io_handler,
305 scif_sas_remote_device_default_continue_io_handler,
306 scif_sas_remote_device_default_start_task_handler,
307 scif_sas_remote_device_default_complete_task_handler
309 scif_sas_remote_device_default_start_complete_handler,
310 scif_sas_remote_device_default_stop_complete_handler,
311 scif_sas_remote_device_starting_await_ready_ready_handler,
312 scif_sas_remote_device_default_not_ready_handler,
313 scif_sas_remote_device_default_start_io_handler,
314 scif_sas_remote_device_default_complete_high_priority_io_handler