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 entrance and exit methods for each
62 * of the controller states defined by the SCI_BASE_CONTROLLER state
66 #include <dev/isci/scil/scic_controller.h>
68 #include <dev/isci/scil/scif_sas_logger.h>
69 #include <dev/isci/scil/scif_sas_controller.h>
71 //******************************************************************************
72 //* P R O T E C T E D M E T H O D S
73 //******************************************************************************
76 * @brief This method implements the actions taken when entering the
79 * @param[in] object This parameter specifies the base object for which
80 * the state transition is occurring. This is cast into a
81 * SCIF_SAS_CONTROLLER object in the method implementation.
86 void scif_sas_controller_initial_state_enter(
87 SCI_BASE_OBJECT_T * object
90 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
94 scif_sas_controller_state_handler_table,
95 SCI_BASE_CONTROLLER_STATE_INITIAL
100 * @brief This method implements the actions taken when entering the
103 * @param[in] object This parameter specifies the base object for which
104 * the state transition is occurring. This is cast into a
105 * SCIF_SAS_CONTROLLER object in the method implementation.
110 void scif_sas_controller_reset_state_enter(
111 SCI_BASE_OBJECT_T * object
114 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
120 scif_sas_controller_state_handler_table,
121 SCI_BASE_CONTROLLER_STATE_RESET
124 scif_sas_high_priority_request_queue_construct(
125 &fw_controller->hprq, sci_base_object_get_logger(fw_controller)
128 // Construct the abstract element pool. This pool will store the
129 // references to the framework's remote devices objects.
130 sci_abstract_element_pool_construct(
131 &fw_controller->free_remote_device_pool,
132 fw_controller->remote_device_pool_elements,
133 SCI_MAX_REMOTE_DEVICES
136 // Construct the domain objects.
137 for (index = 0; index < SCI_MAX_DOMAINS; index++)
139 scif_sas_domain_construct(
140 &fw_controller->domains[index], index, fw_controller
144 //Initialize SMP PHY MEMORY LIST.
145 sci_fast_list_init(&fw_controller->smp_phy_memory_list);
147 for (smp_phy_index = 0;
148 smp_phy_index < SCIF_SAS_SMP_PHY_COUNT;
151 sci_fast_list_element_init(
152 &fw_controller->smp_phy_array[smp_phy_index],
153 &(fw_controller->smp_phy_array[smp_phy_index].list_element)
156 //insert to owning device's smp phy list.
157 sci_fast_list_insert_tail(
158 (&(fw_controller->smp_phy_memory_list)),
159 (&(fw_controller->smp_phy_array[smp_phy_index].list_element))
163 scif_sas_controller_set_default_config_parameters(fw_controller);
165 fw_controller->internal_request_entries =
166 SCIF_SAS_MAX_INTERNAL_REQUEST_COUNT;
168 //@Todo: may need to verify all timers are released. Including domain's
169 //operation timer and all the Internal IO's timer.
171 //take care of the lock.
172 scif_cb_lock_disassociate(fw_controller, &fw_controller->hprq.lock);
176 * @brief This method implements the actions taken when entering the
177 * INITIALIZING state.
179 * @param[in] object This parameter specifies the base object for which
180 * the state transition is occurring. This is cast into a
181 * SCIF_SAS_CONTROLLER object in the method implementation.
186 void scif_sas_controller_initializing_state_enter(
187 SCI_BASE_OBJECT_T * object
190 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
194 scif_sas_controller_state_handler_table,
195 SCI_BASE_CONTROLLER_STATE_INITIALIZING
200 * @brief This method implements the actions taken when entering the
203 * @param[in] object This parameter specifies the base object for which
204 * the state transition is occurring. This is cast into a
205 * SCIF_SAS_CONTROLLER object in the method implementation.
210 void scif_sas_controller_initialized_state_enter(
211 SCI_BASE_OBJECT_T * object
214 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
218 scif_sas_controller_state_handler_table,
219 SCI_BASE_CONTROLLER_STATE_INITIALIZED
224 * @brief This method implements the actions taken when entering the
227 * @param[in] object This parameter specifies the base object for which
228 * the state transition is occurring. This is cast into a
229 * SCIF_SAS_CONTROLLER object in the method implementation.
234 void scif_sas_controller_starting_state_enter(
235 SCI_BASE_OBJECT_T * object
238 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
242 scif_sas_controller_state_handler_table,
243 SCI_BASE_CONTROLLER_STATE_STARTING
248 * @brief This method implements the actions taken when entering the
251 * @param[in] object This parameter specifies the base object for which
252 * the state transition is occurring. This is cast into a
253 * SCIF_SAS_CONTROLLER object in the method implementation.
258 void scif_sas_controller_ready_state_enter(
259 SCI_BASE_OBJECT_T * object
262 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
266 scif_sas_controller_state_handler_table,
267 SCI_BASE_CONTROLLER_STATE_READY
272 * @brief This method implements the actions taken when entering the
275 * @param[in] object This parameter specifies the base object for which
276 * the state transition is occurring. This is cast into a
277 * SCIF_SAS_CONTROLLER object in the method implementation.
282 void scif_sas_controller_stopping_state_enter(
283 SCI_BASE_OBJECT_T * object
286 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
290 scif_sas_controller_state_handler_table,
291 SCI_BASE_CONTROLLER_STATE_STOPPING
296 * @brief This method implements the actions taken when entering the
299 * @param[in] object This parameter specifies the base object for which
300 * the state transition is occurring. This is cast into a
301 * SCIF_SAS_CONTROLLER object in the method implementation.
306 void scif_sas_controller_stopped_state_enter(
307 SCI_BASE_OBJECT_T * object
310 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
314 scif_sas_controller_state_handler_table,
315 SCI_BASE_CONTROLLER_STATE_STOPPED
320 * @brief This method implements the actions taken when entering the
323 * @param[in] object This parameter specifies the base object for which
324 * the state transition is occurring. This is cast into a
325 * SCIF_SAS_CONTROLLER object in the method implementation.
330 void scif_sas_controller_resetting_state_enter(
331 SCI_BASE_OBJECT_T * object
334 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
338 scif_sas_controller_state_handler_table,
339 SCI_BASE_CONTROLLER_STATE_RESETTING
342 // Attempt to reset the core controller.
343 fw_controller->operation_status = scic_controller_reset(
344 fw_controller->core_object
346 if (fw_controller->operation_status == SCI_SUCCESS)
348 // Reset the framework controller.
349 sci_base_state_machine_change_state(
350 &fw_controller->parent.state_machine,
351 SCI_BASE_CONTROLLER_STATE_RESET
357 sci_base_object_get_logger(fw_controller),
358 SCIF_LOG_OBJECT_CONTROLLER,
359 "Controller: unable to successfully reset controller.\n"
362 sci_base_state_machine_change_state(
363 &fw_controller->parent.state_machine,
364 SCI_BASE_CONTROLLER_STATE_FAILED
370 * @brief This method implements the actions taken when entering the
373 * @param[in] object This parameter specifies the base object for which
374 * the state transition is occurring. This is cast into a
375 * SCIF_SAS_CONTROLLER object in the method implementation.
380 void scif_sas_controller_failed_state_enter(
381 SCI_BASE_OBJECT_T * object
384 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T *)object;
387 sci_base_object_get_logger(fw_controller),
388 SCIF_LOG_OBJECT_CONTROLLER,
389 "Controller: entered FAILED state.\n"
394 scif_sas_controller_state_handler_table,
395 SCI_BASE_CONTROLLER_STATE_FAILED
398 if (fw_controller->parent.error != SCI_CONTROLLER_FATAL_MEMORY_ERROR)
400 //clean timers to avoid timer leak.
401 scif_sas_controller_release_resource(fw_controller);
404 scif_cb_controller_error(fw_controller, fw_controller->parent.error);
409 scif_sas_controller_state_table[SCI_BASE_CONTROLLER_MAX_STATES] =
412 SCI_BASE_CONTROLLER_STATE_INITIAL,
413 scif_sas_controller_initial_state_enter,
417 SCI_BASE_CONTROLLER_STATE_RESET,
418 scif_sas_controller_reset_state_enter,
422 SCI_BASE_CONTROLLER_STATE_INITIALIZING,
423 scif_sas_controller_initializing_state_enter,
427 SCI_BASE_CONTROLLER_STATE_INITIALIZED,
428 scif_sas_controller_initialized_state_enter,
432 SCI_BASE_CONTROLLER_STATE_STARTING,
433 scif_sas_controller_starting_state_enter,
437 SCI_BASE_CONTROLLER_STATE_READY,
438 scif_sas_controller_ready_state_enter,
442 SCI_BASE_CONTROLLER_STATE_RESETTING,
443 scif_sas_controller_resetting_state_enter,
447 SCI_BASE_CONTROLLER_STATE_STOPPING,
448 scif_sas_controller_stopping_state_enter,
452 SCI_BASE_CONTROLLER_STATE_STOPPED,
453 scif_sas_controller_stopped_state_enter,
457 SCI_BASE_CONTROLLER_STATE_FAILED,
458 scif_sas_controller_failed_state_enter,