]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/dev/isci/scil/scif_sas_remote_device_starting_substate_handlers.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / dev / isci / scil / scif_sas_remote_device_starting_substate_handlers.c
1 /*-
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.
4  *
5  * GPL LICENSE SUMMARY
6  *
7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8  *
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.
12  *
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.
17  *
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.
23  *
24  * BSD LICENSE
25  *
26  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
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
38  *     distribution.
39  *
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.
51  */
52
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
55
56 /**
57  * @file
58  *
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).
65  */
66
67 #include <dev/isci/scil/scic_remote_device.h>
68
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>
73
74 //******************************************************************************
75 //* G E N E R A L   S T O P   H A N D L E R S
76 //******************************************************************************
77
78 /**
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.
82  *
83  * @param[in]  remote_device This parameter specifies the remote device
84  *             object for which the failure condition occurred.
85  *
86  * @return This method returns an indication as to whether the failure
87  *         operation completed successfully.
88  */
89 static
90 SCI_STATUS
91 scif_sas_remote_device_starting_state_general_stop_handler(
92    SCI_BASE_REMOTE_DEVICE_T * remote_device
93 )
94 {
95    SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)
96                                           remote_device;
97
98    SCIF_LOG_INFO((
99       sci_base_object_get_logger(fw_device),
100       SCIF_LOG_OBJECT_REMOTE_DEVICE,
101       "RemoteDevice:0x%x starting device requested to stop\n",
102       fw_device
103    ));
104
105    fw_device->domain->device_start_in_progress_count--;
106
107    sci_base_state_machine_change_state(
108       &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
109    );
110
111    return SCI_SUCCESS;
112 }
113
114 //******************************************************************************
115 //* A W A I T   C O M P L E T E   H A N D L E R S
116 //******************************************************************************
117
118 /**
119  * @brief This method provides AWAIT START COMPLETE sub-state specific
120  *        handling for when the remote device undergoes a failure
121  *        condition.
122  *
123  * @param[in]  remote_device This parameter specifies the remote device
124  *             object for which the failure condition occurred.
125  *
126  * @return This method returns an indication as to whether the failure
127  *         operation completed successfully.
128  */
129 static
130 SCI_STATUS scif_sas_remote_device_starting_await_complete_fail_handler(
131    SCI_BASE_REMOTE_DEVICE_T * remote_device
132 )
133 {
134    SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *)
135                                           remote_device;
136
137    SCIF_LOG_WARNING((
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",
141       fw_device
142    ));
143
144    sci_base_state_machine_change_state(
145       &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_FAILED
146    );
147
148    return SCI_SUCCESS;
149 }
150
151 /**
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.
157  *
158  * @param[in]  remote_device This parameter specifies the remote device
159  *             object for which the notification occurred.
160  *
161  * @return none.
162  */
163 static
164 void scif_sas_remote_device_starting_await_complete_not_ready_handler(
165    SCIF_SAS_REMOTE_DEVICE_T * fw_device,
166    U32                        reason_code
167 )
168 {
169 }
170
171 /**
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.
179  *
180  * @param[in]  fw_device This parameter specifies the remote device
181  *             object for which the notification has occurred.
182  *
183  * @return none.
184  */
185 static
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
189 )
190 {
191    if (completion_status == SCI_SUCCESS)
192    {
193       /** @todo need to add support for resetting the device first.  This can
194                 wait until 1.3. */
195       /** @todo Update to comprehend situations (i.e. SATA) where config is
196                 needed. */
197
198       sci_base_state_machine_change_state(
199          &fw_device->starting_substate_machine,
200          SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY
201       );
202    }
203    else
204    {
205       SCIF_LOG_WARNING((
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",
209          fw_device
210       ));
211
212       sci_base_state_machine_change_state(
213          &fw_device->parent.state_machine,
214          SCI_BASE_REMOTE_DEVICE_STATE_FAILED
215       );
216
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);
221    }
222 }
223
224 //******************************************************************************
225 //* C O M P L E T E   H A N D L E R S
226 //******************************************************************************
227
228 /**
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.
233  *
234  * @param[in]  fw_device This parameter specifies the remote device
235  *             object for which the notification has occurred.
236  *
237  * @return none.
238  */
239 static
240 void scif_sas_remote_device_starting_await_ready_ready_handler(
241    SCIF_SAS_REMOTE_DEVICE_T * fw_device
242 )
243 {
244 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
245    if (fw_device->destination_state ==
246           SCIF_SAS_REMOTE_DEVICE_DESTINATION_STATE_UPDATING_PORT_WIDTH)
247    {
248       {
249          sci_base_state_machine_change_state(
250             &fw_device->parent.state_machine,
251             SCI_BASE_REMOTE_DEVICE_STATE_UPDATING_PORT_WIDTH
252          );
253       }
254    }
255    else
256 #endif
257    {
258       sci_base_state_machine_change_state(
259          &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_READY
260       );
261    }
262
263 #if !defined(DISABLE_WIDE_PORTED_TARGETS)
264    scif_sas_domain_remote_device_start_complete(fw_device->domain,fw_device);
265 #endif
266 }
267
268
269 SCIF_SAS_REMOTE_DEVICE_STATE_HANDLER_T
270 scif_sas_remote_device_starting_substate_handler_table[] =
271 {
272    // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_COMPLETE
273    {
274       {
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
286       },
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
293    },
294    // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY
295    {
296       {
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
308       },
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
315    }
316 };
317