xref: /freebsd/sys/dev/isci/scil/scif_sas_task_request_states.c (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
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 SCIF_SAS_TASK_REQUEST object
62  *        state entrance and exit method implementations.
63  */
64 
65 #include <dev/isci/scil/scif_sas_task_request.h>
66 
67 //******************************************************************************
68 //* P R O T E C T E D   M E T H O D S
69 //******************************************************************************
70 
71 /**
72  * @brief This method implements the actions taken when entering the
73  *        INITIAL state.
74  *
75  * @param[in]  object This parameter specifies the base object for which
76  *             the state transition is occurring.  This is cast into a
77  *             SCIF_SAS_TASK_REQUEST object in the method implementation.
78  *
79  * @return none
80  */
81 static
82 void scif_sas_task_request_initial_state_enter(
83    SCI_BASE_OBJECT_T *object
84 )
85 {
86    SCIF_SAS_TASK_REQUEST_T * fw_task = (SCIF_SAS_TASK_REQUEST_T *)object;
87 
88    SET_STATE_HANDLER(
89       &fw_task->parent,
90       scif_sas_task_request_state_handler_table,
91       SCI_BASE_REQUEST_STATE_INITIAL
92    );
93 
94    // Initial state is a transitional state to the constructed state
95    sci_base_state_machine_change_state(
96       &fw_task->parent.parent.state_machine, SCI_BASE_REQUEST_STATE_CONSTRUCTED
97    );
98 }
99 
100 /**
101  * @brief This method implements the actions taken when entering the
102  *        CONSTRUCTED state.
103  *
104  * @param[in]  object This parameter specifies the base object for which
105  *             the state transition is occurring.  This is cast into a
106  *             SCIF_SAS_TASK_REQUEST object in the method implementation.
107  *
108  * @return none
109  */
110 static
111 void scif_sas_task_request_constructed_state_enter(
112    SCI_BASE_OBJECT_T *object
113 )
114 {
115    SCIF_SAS_TASK_REQUEST_T * fw_task = (SCIF_SAS_TASK_REQUEST_T *)object;
116 
117    SET_STATE_HANDLER(
118       &fw_task->parent,
119       scif_sas_task_request_state_handler_table,
120       SCI_BASE_REQUEST_STATE_CONSTRUCTED
121    );
122 }
123 
124 /**
125  * @brief This method implements the actions taken when entering the
126  *        STARTED state.
127  *
128  * @param[in]  object This parameter specifies the base object for which
129  *             the state transition is occurring.  This is cast into a
130  *             SCIF_SAS_TASK_REQUEST object in the method implementation.
131  *
132  * @return none
133  */
134 static
135 void scif_sas_task_request_started_state_enter(
136    SCI_BASE_OBJECT_T *object
137 )
138 {
139    SCIF_SAS_TASK_REQUEST_T * fw_task = (SCIF_SAS_TASK_REQUEST_T *)object;
140 
141    SET_STATE_HANDLER(
142       &fw_task->parent,
143       scif_sas_task_request_state_handler_table,
144       SCI_BASE_REQUEST_STATE_STARTED
145    );
146 
147    // Increment the affected request count to include the task performing
148    // the task management to ensure we don't complete the task request until
149    // all terminations and the task itself have completed.
150    fw_task->affected_request_count++;
151 }
152 
153 /**
154  * @brief This method implements the actions taken when entering the
155  *        COMPLETED state.
156  *
157  * @param[in]  object This parameter specifies the base object for which
158  *             the state transition is occurring.  This is cast into a
159  *             SCIF_SAS_TASK_REQUEST object in the method implementation.
160  *
161  * @return none
162  */
163 static
164 void scif_sas_task_request_completed_state_enter(
165    SCI_BASE_OBJECT_T *object
166 )
167 {
168    SCIF_SAS_TASK_REQUEST_T * fw_task = (SCIF_SAS_TASK_REQUEST_T *)object;
169 
170    SET_STATE_HANDLER(
171       &fw_task->parent,
172       scif_sas_task_request_state_handler_table,
173       SCI_BASE_REQUEST_STATE_COMPLETED
174    );
175 
176    // Check to see if the task management operation is now finished (i.e.
177    // all of the task terminations and the task management request are
178    // complete).
179    scif_sas_task_request_operation_complete(fw_task);
180 }
181 
182 /**
183  * @brief This method implements the actions taken when entering the
184  *        ABORTING state.
185  *
186  * @param[in]  object This parameter specifies the base object for which
187  *             the state transition is occurring.  This is cast into a
188  *             SCIF_SAS_TASK_REQUEST object in the method implementation.
189  *
190  * @return none
191  */
192 static
193 void scif_sas_task_request_aborting_state_enter(
194    SCI_BASE_OBJECT_T *object
195 )
196 {
197    SCIF_SAS_TASK_REQUEST_T * fw_task = (SCIF_SAS_TASK_REQUEST_T *)object;
198 
199    SET_STATE_HANDLER(
200       &fw_task->parent,
201       scif_sas_task_request_state_handler_table,
202       SCI_BASE_REQUEST_STATE_ABORTING
203    );
204 
205    /// @todo Is terminating a previously outstanding task request right?
206    fw_task->parent.status = scif_sas_request_terminate_start(
207                                &fw_task->parent, fw_task->parent.core_object
208                             );
209 }
210 
211 /**
212  * @brief This method implements the actions taken when exiting the
213  *        ABORTING state.
214  *
215  * @param[in]  object This parameter specifies the base object for which
216  *             the state transition is occurring.  This is cast into a
217  *             SCIF_SAS_TASK_REQUEST object in the method implementation.
218  *
219  * @return none
220  */
221 static
222 void scif_sas_task_request_aborting_state_exit(
223    SCI_BASE_OBJECT_T *object
224 )
225 {
226    SCIF_SAS_REQUEST_T * fw_request = (SCIF_SAS_REQUEST_T *)object;
227    scif_sas_request_terminate_complete(fw_request);
228 }
229 
230 /**
231  * @brief This method implements the actions taken when entering the
232  *        FINAL state.
233  *
234  * @param[in]  object This parameter specifies the base object for which
235  *             the state transition is occurring.  This is cast into a
236  *             SCIF_SAS_TASK_REQUEST object in the method implementation.
237  *
238  * @return none
239  */
240 static
241 void scif_sas_task_request_final_state_enter(
242    SCI_BASE_OBJECT_T *object
243 )
244 {
245    SCIF_SAS_TASK_REQUEST_T * fw_task = (SCIF_SAS_TASK_REQUEST_T *)object;
246 
247    SET_STATE_HANDLER(
248       &fw_task->parent,
249       scif_sas_task_request_state_handler_table,
250       SCI_BASE_REQUEST_STATE_FINAL
251    );
252 }
253 
254 
255 SCI_BASE_STATE_T
256    scif_sas_task_request_state_table[SCI_BASE_REQUEST_MAX_STATES] =
257 {
258    {
259       SCI_BASE_REQUEST_STATE_INITIAL,
260       scif_sas_task_request_initial_state_enter,
261       NULL
262    },
263    {
264       SCI_BASE_REQUEST_STATE_CONSTRUCTED,
265       scif_sas_task_request_constructed_state_enter,
266       NULL
267    },
268    {
269       SCI_BASE_REQUEST_STATE_STARTED,
270       scif_sas_task_request_started_state_enter,
271       NULL
272    },
273    {
274       SCI_BASE_REQUEST_STATE_COMPLETED,
275       scif_sas_task_request_completed_state_enter,
276       NULL
277    },
278    {
279       SCI_BASE_REQUEST_STATE_ABORTING,
280       scif_sas_task_request_aborting_state_enter,
281       scif_sas_task_request_aborting_state_exit
282    },
283    {
284       SCI_BASE_REQUEST_STATE_FINAL,
285       scif_sas_task_request_final_state_enter,
286       NULL
287    },
288 };
289 
290