2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23 * The full GNU General Public License is included in this distribution
24 * in the file called LICENSE.GPL.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
35 * * Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * * Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in
39 * the documentation and/or other materials provided with the
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
61 * @brief This file contains all of the method implementations pertaining
62 * to the framework remote device STARTING sub-state handler methods.
63 * The STARTING sub-state machine is responsible for ensuring that
64 * all initialization and configuration for a particular remote
65 * device is complete before transitioning to the READY state
66 * (i.e. before allowing normal host IO).
69 #include <dev/isci/scil/scic_remote_device.h>
71 #include <dev/isci/scil/scif_sas_logger.h>
72 #include <dev/isci/scil/scif_sas_remote_device.h>
73 #include <dev/isci/scil/scif_sas_domain.h>
74 #include <dev/isci/scil/scif_sas_task_request.h>
76 //******************************************************************************
77 //* G E N E R A L S T O P H A N D L E R S
78 //******************************************************************************
81 * @brief This method provides startig sub-state specific handling for
82 * when the remote device is requested to stop. This will occur
83 * when there is a link failure during the starting operation.
85 * @param[in] remote_device This parameter specifies the remote device
86 * object for which the failure condition occurred.
88 * @return This method returns an indication as to whether the failure
89 * operation completed successfully.
93 scif_sas_remote_device_starting_state_general_stop_handler(
94 SCI_BASE_REMOTE_DEVICE_T * remote_device
97 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)
101 sci_base_object_get_logger(fw_device),
102 SCIF_LOG_OBJECT_REMOTE_DEVICE,
103 "RemoteDevice:0x%x starting device requested to stop\n",
107 fw_device->domain->device_start_in_progress_count--;
109 sci_base_state_machine_change_state(
110 &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
116 //******************************************************************************
117 //* A W A I T C O M P L E T E H A N D L E R S
118 //******************************************************************************
121 * @brief This method provides AWAIT START COMPLETE sub-state specific
122 * handling for when the remote device undergoes a failure
125 * @param[in] remote_device This parameter specifies the remote device
126 * object for which the failure condition occurred.
128 * @return This method returns an indication as to whether the failure
129 * operation completed successfully.
132 SCI_STATUS scif_sas_remote_device_starting_await_complete_fail_handler(
133 SCI_BASE_REMOTE_DEVICE_T * remote_device
136 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)
140 sci_base_object_get_logger(fw_device),
141 SCIF_LOG_OBJECT_REMOTE_DEVICE,
142 "RemoteDevice:0x%x starting device failed, start complete not received\n",
146 sci_base_state_machine_change_state(
147 &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_FAILED
154 * @brief This method provides AWAIT COMPLETE state specific handling for
155 * when the core remote device object issues a device not ready
156 * notification. In the AWAIT COMPLETE state we do not inform
157 * the framework user of the state change of the device, since the
158 * user is unaware of the remote device start process.
160 * @param[in] remote_device This parameter specifies the remote device
161 * object for which the notification occurred.
166 void scif_sas_remote_device_starting_await_complete_not_ready_handler(
167 SCIF_SAS_REMOTE_DEVICE_T * fw_device,
174 * @brief This method provides AWAIT START COMPLETE sub-state specific
175 * handling for when the core provides a start complete notification
176 * for the remote device. If the start completion status indicates
177 * a successful start, then the device is transitioned into the
178 * READY state. All other status cause a transition to the
179 * FAILED state and a scif_cb_controller_error() notification
180 * message to the framework user.
182 * @param[in] fw_device This parameter specifies the remote device
183 * object for which the notification has occurred.
188 void scif_sas_remote_device_starting_await_complete_start_complete_handler(
189 SCIF_SAS_REMOTE_DEVICE_T * fw_device,
190 SCI_STATUS completion_status
193 if (completion_status == SCI_SUCCESS)
195 /** @todo need to add support for resetting the device first. This can
197 /** @todo Update to comprehend situations (i.e. SATA) where config is
200 sci_base_state_machine_change_state(
201 &fw_device->starting_substate_machine,
202 SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY
208 sci_base_object_get_logger(fw_device),
209 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_REMOTE_DEVICE_CONFIG,
210 "Device:0x%x Status:0x%x failed to start core device\n",
214 sci_base_state_machine_change_state(
215 &fw_device->parent.state_machine,
216 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
219 // Something is seriously wrong. Starting the core remote device
220 // shouldn't fail in anyway in this state.
221 scif_cb_controller_error(fw_device->domain->controller,
222 SCI_CONTROLLER_REMOTE_DEVICE_ERROR);
226 //******************************************************************************
227 //* C O M P L E T E H A N D L E R S
228 //******************************************************************************
231 * @brief This method provides STARTING AWAIT READY sub-state specific
232 * handling for when the core provides a device ready notification
233 * for the remote device. This essentially, causes a transition
234 * of the framework remote device into the READY state.
236 * @param[in] fw_device This parameter specifies the remote device
237 * object for which the notification has occurred.
242 void scif_sas_remote_device_starting_await_ready_ready_handler(
243 SCIF_SAS_REMOTE_DEVICE_T * fw_device
246 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
247 if (fw_device->destination_state ==
248 SCIF_SAS_REMOTE_DEVICE_DESTINATION_STATE_UPDATING_PORT_WIDTH)
251 sci_base_state_machine_change_state(
252 &fw_device->parent.state_machine,
253 SCI_BASE_REMOTE_DEVICE_STATE_UPDATING_PORT_WIDTH
260 sci_base_state_machine_change_state(
261 &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_READY
265 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
266 scif_sas_domain_remote_device_start_complete(fw_device->domain,fw_device);
271 SCIF_SAS_REMOTE_DEVICE_STATE_HANDLER_T
272 scif_sas_remote_device_starting_substate_handler_table[] =
274 // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_COMPLETE
277 scif_sas_remote_device_default_start_handler,
278 scif_sas_remote_device_starting_state_general_stop_handler,
279 scif_sas_remote_device_starting_await_complete_fail_handler,
280 scif_sas_remote_device_default_destruct_handler,
281 scif_sas_remote_device_default_reset_handler,
282 scif_sas_remote_device_default_reset_complete_handler,
283 scif_sas_remote_device_default_start_io_handler,
284 scif_sas_remote_device_default_complete_io_handler,
285 scif_sas_remote_device_default_continue_io_handler,
286 scif_sas_remote_device_default_start_task_handler,
287 scif_sas_remote_device_default_complete_task_handler
289 scif_sas_remote_device_starting_await_complete_start_complete_handler,
290 scif_sas_remote_device_default_stop_complete_handler,
291 scif_sas_remote_device_default_ready_handler,
292 scif_sas_remote_device_starting_await_complete_not_ready_handler,
293 scif_sas_remote_device_default_start_io_handler,
294 scif_sas_remote_device_default_complete_high_priority_io_handler
296 // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY
299 scif_sas_remote_device_default_start_handler,
300 scif_sas_remote_device_starting_state_general_stop_handler,
301 scif_sas_remote_device_starting_await_complete_fail_handler,
302 scif_sas_remote_device_default_destruct_handler,
303 scif_sas_remote_device_default_reset_handler,
304 scif_sas_remote_device_default_reset_complete_handler,
305 scif_sas_remote_device_default_start_io_handler,
306 scif_sas_remote_device_default_complete_io_handler,
307 scif_sas_remote_device_default_continue_io_handler,
308 scif_sas_remote_device_default_start_task_handler,
309 scif_sas_remote_device_default_complete_task_handler
311 scif_sas_remote_device_default_start_complete_handler,
312 scif_sas_remote_device_default_stop_complete_handler,
313 scif_sas_remote_device_starting_await_ready_ready_handler,
314 scif_sas_remote_device_default_not_ready_handler,
315 scif_sas_remote_device_default_start_io_handler,
316 scif_sas_remote_device_default_complete_high_priority_io_handler