1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3 *
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.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
10 *
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.
14 *
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.
19 *
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.
25 *
26 * BSD LICENSE
27 *
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 *
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
40 * distribution.
41 *
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.
53 */
54
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
57
58 /**
59 * @file
60 *
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).
67 */
68
69 #include <dev/isci/scil/scic_remote_device.h>
70
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>
75
76 //******************************************************************************
77 //* G E N E R A L S T O P H A N D L E R S
78 //******************************************************************************
79
80 /**
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.
84 *
85 * @param[in] remote_device This parameter specifies the remote device
86 * object for which the failure condition occurred.
87 *
88 * @return This method returns an indication as to whether the failure
89 * operation completed successfully.
90 */
91 static
92 SCI_STATUS
93 scif_sas_remote_device_starting_state_general_stop_handler(
94 SCI_BASE_REMOTE_DEVICE_T * remote_device
95 )
96 {
97 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)
98 remote_device;
99
100 SCIF_LOG_INFO((
101 sci_base_object_get_logger(fw_device),
102 SCIF_LOG_OBJECT_REMOTE_DEVICE,
103 "RemoteDevice:0x%x starting device requested to stop\n",
104 fw_device
105 ));
106
107 fw_device->domain->device_start_in_progress_count--;
108
109 sci_base_state_machine_change_state(
110 &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
111 );
112
113 return SCI_SUCCESS;
114 }
115
116 //******************************************************************************
117 //* A W A I T C O M P L E T E H A N D L E R S
118 //******************************************************************************
119
120 /**
121 * @brief This method provides AWAIT START COMPLETE sub-state specific
122 * handling for when the remote device undergoes a failure
123 * condition.
124 *
125 * @param[in] remote_device This parameter specifies the remote device
126 * object for which the failure condition occurred.
127 *
128 * @return This method returns an indication as to whether the failure
129 * operation completed successfully.
130 */
131 static
132 SCI_STATUS scif_sas_remote_device_starting_await_complete_fail_handler(
133 SCI_BASE_REMOTE_DEVICE_T * remote_device
134 )
135 {
136 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)
137 remote_device;
138
139 SCIF_LOG_WARNING((
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",
143 fw_device
144 ));
145
146 sci_base_state_machine_change_state(
147 &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_FAILED
148 );
149
150 return SCI_SUCCESS;
151 }
152
153 /**
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.
159 *
160 * @param[in] remote_device This parameter specifies the remote device
161 * object for which the notification occurred.
162 *
163 * @return none.
164 */
165 static
166 void scif_sas_remote_device_starting_await_complete_not_ready_handler(
167 SCIF_SAS_REMOTE_DEVICE_T * fw_device,
168 U32 reason_code
169 )
170 {
171 }
172
173 /**
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.
181 *
182 * @param[in] fw_device This parameter specifies the remote device
183 * object for which the notification has occurred.
184 *
185 * @return none.
186 */
187 static
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
191 )
192 {
193 if (completion_status == SCI_SUCCESS)
194 {
195 /** @todo need to add support for resetting the device first. This can
196 wait until 1.3. */
197 /** @todo Update to comprehend situations (i.e. SATA) where config is
198 needed. */
199
200 sci_base_state_machine_change_state(
201 &fw_device->starting_substate_machine,
202 SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY
203 );
204 }
205 else
206 {
207 SCIF_LOG_WARNING((
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",
211 fw_device
212 ));
213
214 sci_base_state_machine_change_state(
215 &fw_device->parent.state_machine,
216 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
217 );
218
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);
223 }
224 }
225
226 //******************************************************************************
227 //* C O M P L E T E H A N D L E R S
228 //******************************************************************************
229
230 /**
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.
235 *
236 * @param[in] fw_device This parameter specifies the remote device
237 * object for which the notification has occurred.
238 *
239 * @return none.
240 */
241 static
242 void scif_sas_remote_device_starting_await_ready_ready_handler(
243 SCIF_SAS_REMOTE_DEVICE_T * fw_device
244 )
245 {
246 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
247 if (fw_device->destination_state ==
248 SCIF_SAS_REMOTE_DEVICE_DESTINATION_STATE_UPDATING_PORT_WIDTH)
249 {
250 {
251 sci_base_state_machine_change_state(
252 &fw_device->parent.state_machine,
253 SCI_BASE_REMOTE_DEVICE_STATE_UPDATING_PORT_WIDTH
254 );
255 }
256 }
257 else
258 #endif
259 {
260 sci_base_state_machine_change_state(
261 &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_READY
262 );
263 }
264
265 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
266 scif_sas_domain_remote_device_start_complete(fw_device->domain,fw_device);
267 #endif
268 }
269
270
271 SCIF_SAS_REMOTE_DEVICE_STATE_HANDLER_T
272 scif_sas_remote_device_starting_substate_handler_table[] =
273 {
274 // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_COMPLETE
275 {
276 {
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
288 },
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
295 },
296 // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY
297 {
298 {
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
310 },
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
317 }
318 };
319
Cache object: 1b3a98530456cc976979d6ccc5cb165e
|