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$");
64 #include <dev/isci/scil/scic_remote_device.h>
66 #include <dev/isci/scil/scif_sas_remote_device.h>
67 #include <dev/isci/scil/scif_sas_domain.h>
68 #include <dev/isci/scil/scif_sas_logger.h>
72 * This constant indicates the number of milliseconds to wait for the core
73 * to start/stop it's remote device object.
75 //#define SCIF_SAS_REMOTE_DEVICE_CORE_OP_TIMEOUT 1000
77 //******************************************************************************
78 //* P R O T E C T E D M E T H O D S
79 //******************************************************************************
82 * @brief This method implements the actions taken when entering the
83 * INITIAL state. This basically, causes an immediate transition
84 * into the STOPPED state.
86 * @param[in] object This parameter specifies the base object for which
87 * the state transition is occurring. This is cast into a
88 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
93 void scif_sas_remote_device_initial_state_enter(
94 SCI_BASE_OBJECT_T *object
97 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
101 scif_sas_remote_device_state_handler_table,
102 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
105 // Initial state is a transitional state to the stopped state
106 sci_base_state_machine_change_state(
107 &fw_device->parent.state_machine,
108 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
113 * @brief This method implements the actions taken when entering the
114 * STOPPED state. This method updates the domains count of started
115 * devices and will invoke the destruct method if this entrance into
116 * the STOPPED state was due to a scif_remote_device_destruct()
119 * @param[in] object This parameter specifies the base object for which
120 * the state transition is occurring. This is cast into a
121 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
126 void scif_sas_remote_device_stopped_state_enter(
127 SCI_BASE_OBJECT_T *object
130 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
134 scif_sas_remote_device_state_handler_table,
135 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
138 // There should be no outstanding requests for this device in the
140 ASSERT(fw_device->request_count == 0);
142 // If we are entering the stopped state as a result of a destruct
143 // request, then let's perform the actual destruct operation now.
144 if (fw_device->destruct_when_stopped == TRUE)
145 fw_device->operation_status
146 = fw_device->state_handlers->parent.destruct_handler(
150 /// @todo What should we do if this call fails?
151 fw_device->domain->state_handlers->device_stop_complete_handler(
152 &fw_device->domain->parent, &fw_device->parent
157 * @brief This method implements the actions taken when entering the
158 * STARTING state. This method will attempt to start the core
159 * remote device and will kick-start the starting sub-state machine
160 * if no errors are encountered.
162 * @param[in] object This parameter specifies the base object for which
163 * the state transition is occurring. This is cast into a
164 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
169 void scif_sas_remote_device_starting_state_enter(
170 SCI_BASE_OBJECT_T *object
173 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
177 scif_sas_remote_device_state_handler_table,
178 SCI_BASE_REMOTE_DEVICE_STATE_STARTING
182 sci_base_object_get_logger(fw_device),
183 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_REMOTE_DEVICE_CONFIG,
184 "RemoteDevice:0x%x starting/configuring\n",
188 fw_device->destination_state =
189 SCIF_SAS_REMOTE_DEVICE_DESTINATION_STATE_READY;
191 sci_base_state_machine_start(&fw_device->starting_substate_machine);
193 fw_device->operation_status = scic_remote_device_start(
194 fw_device->core_object,
195 SCIF_SAS_REMOTE_DEVICE_CORE_OP_TIMEOUT
198 if (fw_device->operation_status != SCI_SUCCESS)
200 fw_device->state_handlers->parent.fail_handler(&fw_device->parent);
202 // Something is seriously wrong. Starting the core remote device
203 // shouldn't fail in anyway in this state.
204 scif_cb_controller_error(fw_device->domain->controller,
205 SCI_CONTROLLER_REMOTE_DEVICE_ERROR);
210 * @brief This method implements the actions taken when exiting the
211 * STARTING state. Currently this method simply stops the
214 * @param[in] object This parameter specifies the base object for which
215 * the state transition is occurring. This is cast into a
216 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
221 void scif_sas_remote_device_starting_state_exit(
222 SCI_BASE_OBJECT_T *object
225 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
227 fw_device->destination_state =
228 SCIF_SAS_REMOTE_DEVICE_DESTINATION_STATE_UNSPECIFIED;
230 // Transition immediately into the operational sub-state.
231 sci_base_state_machine_stop(&fw_device->starting_substate_machine);
235 * @brief This method implements the actions taken when entering the
236 * READY state. Currently this method simply starts the
239 * @param[in] object This parameter specifies the base object for which
240 * the state transition is occurring. This is cast into a
241 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
246 void scif_sas_remote_device_ready_state_enter(
247 SCI_BASE_OBJECT_T *object
250 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
252 // Transition immediately into the operational sub-state.
253 sci_base_state_machine_start(&fw_device->ready_substate_machine);
255 #if defined(DISABLE_WIDE_PORTED_TARGETS)
256 scif_sas_domain_remote_device_start_complete(fw_device->domain,fw_device);
261 * @brief This method implements the actions taken when exiting the
262 * READY state. Currently this method simply stops the
265 * @param[in] object This parameter specifies the base object for which
266 * the state transition is occurring. This is cast into a
267 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
272 void scif_sas_remote_device_ready_state_exit(
273 SCI_BASE_OBJECT_T *object
276 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
278 // Transition immediately into the operational sub-state.
279 sci_base_state_machine_stop(&fw_device->ready_substate_machine);
283 * @brief This method implements the actions taken when entering the
284 * STOPPING state. This includes: stopping the core remote device
285 * and handling any errors that may occur.
287 * @param[in] object This parameter specifies the base object for which
288 * the state transition is occurring. This is cast into a
289 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
294 void scif_sas_remote_device_stopping_state_enter(
295 SCI_BASE_OBJECT_T *object
298 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
302 scif_sas_remote_device_state_handler_table,
303 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
306 fw_device->operation_status = scic_remote_device_stop(
307 fw_device->core_object,
308 SCIF_SAS_REMOTE_DEVICE_CORE_OP_TIMEOUT
311 // If there was a failure, then transition directly to the stopped state.
312 if (fw_device->operation_status != SCI_SUCCESS)
315 * @todo We may want to consider adding handling to reset the
316 * structure data for the framework and core devices here
317 * in order to help aid recovery.
320 fw_device->state_handlers->stop_complete_handler(
321 fw_device, fw_device->operation_status
327 * @brief This method implements the actions taken when exiting the
330 * @param[in] object This parameter specifies the base object for which
331 * the state transition is occurring. This is cast into a
332 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
337 void scif_sas_remote_device_stopping_state_exit(
338 SCI_BASE_OBJECT_T *object
341 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
343 // Let the domain know that the device has stopped
344 fw_device->domain->device_start_count--;
348 * @brief This method implements the actions taken when entering the
349 * FAILED state. This includes setting the state handler methods
350 * and issuing a scif_cb_remote_device_failed() notification to
353 * @param[in] object This parameter specifies the base object for which
354 * the state transition is occurring. This is cast into a
355 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
360 void scif_sas_remote_device_failed_state_enter(
361 SCI_BASE_OBJECT_T *object
364 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
368 scif_sas_remote_device_state_handler_table,
369 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
373 sci_base_object_get_logger(fw_device),
374 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_REMOTE_DEVICE_CONFIG,
375 "Domain:0x%x Device:0x%x Status:0x%x device failed\n",
376 fw_device->domain, fw_device, fw_device->operation_status
379 // Notify the user that the device has failed.
380 scif_cb_remote_device_failed(
381 fw_device->domain->controller,
384 fw_device->operation_status
387 // Only call start_complete for the remote device if the device failed
388 // from the STARTING state.
389 if (fw_device->parent.state_machine.previous_state_id
390 == SCI_BASE_REMOTE_DEVICE_STATE_STARTING)
391 scif_sas_domain_remote_device_start_complete(fw_device->domain,fw_device);
395 * @brief This method implements the actions taken when entering the RESETTING
398 * @param[in] object This parameter specifies the base object for which
399 * the state transition is occurring. This is cast into a
400 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
405 void scif_sas_remote_device_resetting_state_enter(
406 SCI_BASE_OBJECT_T *object
411 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
413 * @brief This method implements the actions taken when entering the UPDATING
416 * @param[in] object This parameter specifies the base object for which
417 * the state transition is occurring. This is cast into a
418 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
423 void scif_sas_remote_device_updating_port_width_state_enter(
424 SCI_BASE_OBJECT_T *object
427 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
431 scif_sas_remote_device_state_handler_table,
432 SCI_BASE_REMOTE_DEVICE_STATE_UPDATING_PORT_WIDTH
435 fw_device->destination_state = SCIF_SAS_REMOTE_DEVICE_DESTINATION_STATE_READY;
437 //If the request count is zero, go ahead to update the RNC.
438 //If not, don't do anything for now. The IO complete handler of this state
439 //will update the RNC whenever the request count goes down to zero.
440 if (fw_device->request_count == 0)
442 //stop the device, upon the stop complete callback, start the device again
443 //with the updated port width.
444 scic_remote_device_stop(
445 fw_device->core_object, SCIF_SAS_REMOTE_DEVICE_CORE_OP_TIMEOUT);
451 * @brief This method implements the actions taken when exiting the
454 * @param[in] object This parameter specifies the base object for which
455 * the state transition is occurring. This is cast into a
456 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
461 void scif_sas_remote_device_updating_port_width_state_exit(
462 SCI_BASE_OBJECT_T *object
465 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
467 fw_device->destination_state =
468 SCIF_SAS_REMOTE_DEVICE_DESTINATION_STATE_UNSPECIFIED;
472 #endif //#if !defined(DISABLE_WIDE_PORTED_TARGETS)
475 * @brief This method implements the actions taken when entering the
476 * FINAL state. This includes setting the FINAL state handler
479 * @param[in] object This parameter specifies the base object for which
480 * the state transition is occurring. This is cast into a
481 * SCIF_SAS_REMOTE_DEVICE object in the method implementation.
486 void scif_sas_remote_device_final_state_enter(
487 SCI_BASE_OBJECT_T *object
490 SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)object;
494 scif_sas_remote_device_state_handler_table,
495 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
501 scif_sas_remote_device_state_table[SCI_BASE_REMOTE_DEVICE_MAX_STATES] =
504 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL,
505 scif_sas_remote_device_initial_state_enter,
509 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED,
510 scif_sas_remote_device_stopped_state_enter,
514 SCI_BASE_REMOTE_DEVICE_STATE_STARTING,
515 scif_sas_remote_device_starting_state_enter,
516 scif_sas_remote_device_starting_state_exit
519 SCI_BASE_REMOTE_DEVICE_STATE_READY,
520 scif_sas_remote_device_ready_state_enter,
521 scif_sas_remote_device_ready_state_exit
524 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING,
525 scif_sas_remote_device_stopping_state_enter,
526 scif_sas_remote_device_stopping_state_exit
529 SCI_BASE_REMOTE_DEVICE_STATE_FAILED,
530 scif_sas_remote_device_failed_state_enter,
534 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING,
535 scif_sas_remote_device_resetting_state_enter,
538 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
540 SCI_BASE_REMOTE_DEVICE_STATE_UPDATING_PORT_WIDTH,
541 scif_sas_remote_device_updating_port_width_state_enter,
542 scif_sas_remote_device_updating_port_width_state_exit
544 #endif //#if !defined(DISABLE_WIDE_PORTED_TARGETS)
546 SCI_BASE_REMOTE_DEVICE_STATE_FINAL,
547 scif_sas_remote_device_final_state_enter,