1227745Slstewart/*-
2227745Slstewart * This file is provided under a dual BSD/GPLv2 license.  When using or
3227745Slstewart * redistributing this file, you may do so under either license.
4227745Slstewart *
5227745Slstewart * GPL LICENSE SUMMARY
6227745Slstewart *
7227745Slstewart * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8227745Slstewart *
9227745Slstewart * This program is free software; you can redistribute it and/or modify
10227745Slstewart * it under the terms of version 2 of the GNU General Public License as
11227745Slstewart * published by the Free Software Foundation.
12227745Slstewart *
13227745Slstewart * This program is distributed in the hope that it will be useful, but
14227745Slstewart * WITHOUT ANY WARRANTY; without even the implied warranty of
15227745Slstewart * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16227745Slstewart * General Public License for more details.
17227745Slstewart *
18227745Slstewart * You should have received a copy of the GNU General Public License
19227745Slstewart * along with this program; if not, write to the Free Software
20227745Slstewart * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21227745Slstewart * The full GNU General Public License is included in this distribution
22227745Slstewart * in the file called LICENSE.GPL.
23227745Slstewart *
24227745Slstewart * BSD LICENSE
25227745Slstewart *
26227745Slstewart * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27227745Slstewart * All rights reserved.
28227745Slstewart *
29227745Slstewart * Redistribution and use in source and binary forms, with or without
30227745Slstewart * modification, are permitted provided that the following conditions
31227745Slstewart * are met:
32227745Slstewart *
33227776Slstewart *   * Redistributions of source code must retain the above copyright
34227776Slstewart *     notice, this list of conditions and the following disclaimer.
35227745Slstewart *   * Redistributions in binary form must reproduce the above copyright
36227776Slstewart *     notice, this list of conditions and the following disclaimer in
37227776Slstewart *     the documentation and/or other materials provided with the
38227776Slstewart *     distribution.
39227776Slstewart *
40227776Slstewart * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41227776Slstewart * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42227776Slstewart * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43227747Slstewart * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44227776Slstewart * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45227776Slstewart * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46227747Slstewart * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47227745Slstewart * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48227745Slstewart * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49227745Slstewart * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50227776Slstewart * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51227776Slstewart */
52227986Slstewart
53227986Slstewart#include <sys/cdefs.h>
54227745Slstewart__FBSDID("$FreeBSD: releng/10.2/sys/dev/isci/scil/scif_sas_io_request_states.c 231136 2012-02-07 17:43:58Z jimharris $");
55227745Slstewart
56227776Slstewart/**
57227776Slstewart * @file
58227745Slstewart *
59227745Slstewart * @brief This file contains all of the SCIF_SAS_IO_REQUEST object
60227745Slstewart *        state entrance and exit method implementations.
61227745Slstewart */
62227745Slstewart
63227745Slstewart#include <dev/isci/scil/scic_controller.h>
64227745Slstewart
65227745Slstewart#include <dev/isci/scil/scif_sas_io_request.h>
66227745Slstewart#include <dev/isci/scil/scif_sas_domain.h>
67227745Slstewart#include <dev/isci/scil/scif_sas_controller.h>
68227745Slstewart#include <dev/isci/scil/scif_sas_logger.h>
69227745Slstewart
70227745Slstewart//******************************************************************************
71227745Slstewart//* P R O T E C T E D   M E T H O D S
72227745Slstewart//******************************************************************************
73227745Slstewart
74227745Slstewart/**
75227745Slstewart * @brief This method implements the actions taken when entering the
76227745Slstewart *        INITIAL state.
77227745Slstewart *
78227745Slstewart * @param[in]  object This parameter specifies the base object for which
79227745Slstewart *             the state transition is occurring.  This is cast into a
80227745Slstewart *             SCIF_SAS_IO_REQUEST object in the method implementation.
81227745Slstewart *
82227745Slstewart * @return none
83227745Slstewart */
84227745Slstewartstatic
85227745Slstewartvoid scif_sas_io_request_initial_state_enter(
86227745Slstewart   SCI_BASE_OBJECT_T *object
87227745Slstewart)
88227745Slstewart{
89227745Slstewart   SCIF_SAS_IO_REQUEST_T * fw_io = (SCIF_SAS_IO_REQUEST_T *)object;
90227745Slstewart
91227745Slstewart   SET_STATE_HANDLER(
92227745Slstewart      &fw_io->parent,
93227745Slstewart      scif_sas_io_request_state_handler_table,
94227745Slstewart      SCI_BASE_REQUEST_STATE_INITIAL
95227745Slstewart   );
96227745Slstewart
97227745Slstewart   // Initial state is a transitional state to the constructed state
98227745Slstewart   sci_base_state_machine_change_state(
99227745Slstewart      &fw_io->parent.parent.state_machine, SCI_BASE_REQUEST_STATE_CONSTRUCTED
100227745Slstewart   );
101227745Slstewart}
102227745Slstewart
103227745Slstewart/**
104227745Slstewart * @brief This method implements the actions taken when entering the
105227745Slstewart *        CONSTRUCTED state.
106227745Slstewart *
107227745Slstewart * @param[in]  object This parameter specifies the base object for which
108227745Slstewart *             the state transition is occurring.  This is cast into a
109227745Slstewart *             SCIF_SAS_IO_REQUEST object in the method implementation.
110227745Slstewart *
111227745Slstewart * @return none
112227745Slstewart */
113227745Slstewartstatic
114227745Slstewartvoid scif_sas_io_request_constructed_state_enter(
115227745Slstewart   SCI_BASE_OBJECT_T *object
116227745Slstewart)
117227745Slstewart{
118227745Slstewart   SCIF_SAS_IO_REQUEST_T * fw_io = (SCIF_SAS_IO_REQUEST_T *)object;
119227745Slstewart
120227745Slstewart   SET_STATE_HANDLER(
121227745Slstewart      &fw_io->parent,
122227745Slstewart      scif_sas_io_request_state_handler_table,
123227745Slstewart      SCI_BASE_REQUEST_STATE_CONSTRUCTED
124227745Slstewart   );
125227745Slstewart}
126227745Slstewart
127227745Slstewart/**
128227745Slstewart * @brief This method implements the actions taken when entering the
129227745Slstewart *        STARTED state.
130227745Slstewart *
131227745Slstewart * @param[in]  object This parameter specifies the base object for which
132227745Slstewart *             the state transition is occurring.  This is cast into a
133227745Slstewart *             SCIF_SAS_IO_REQUEST object in the method implementation.
134227745Slstewart *
135227745Slstewart * @return none
136227745Slstewart */
137227745Slstewartstatic
138227745Slstewartvoid scif_sas_io_request_started_state_enter(
139227745Slstewart   SCI_BASE_OBJECT_T *object
140227745Slstewart)
141227745Slstewart{
142227745Slstewart   SCIF_SAS_IO_REQUEST_T * fw_io = (SCIF_SAS_IO_REQUEST_T *)object;
143227745Slstewart
144227745Slstewart   SET_STATE_HANDLER(
145227745Slstewart      &fw_io->parent,
146227745Slstewart      scif_sas_io_request_state_handler_table,
147227745Slstewart      SCI_BASE_REQUEST_STATE_STARTED
148227745Slstewart   );
149227747Slstewart}
150227747Slstewart
151227747Slstewart/**
152227747Slstewart * @brief This method implements the actions taken when entering the
153227747Slstewart *        COMPLETED state.
154227747Slstewart *
155227747Slstewart * @param[in]  object This parameter specifies the base object for which
156227747Slstewart *             the state transition is occurring.  This is cast into a
157227747Slstewart *             SCIF_SAS_IO_REQUEST object in the method implementation.
158227747Slstewart *
159227747Slstewart * @return none
160227747Slstewart */
161227747Slstewartstatic
162227747Slstewartvoid scif_sas_io_request_completed_state_enter(
163227747Slstewart   SCI_BASE_OBJECT_T *object
164227747Slstewart)
165227747Slstewart{
166227747Slstewart   SCIF_SAS_IO_REQUEST_T * fw_io = (SCIF_SAS_IO_REQUEST_T *)object;
167227747Slstewart
168227747Slstewart   SET_STATE_HANDLER(
169227747Slstewart      &fw_io->parent,
170227747Slstewart      scif_sas_io_request_state_handler_table,
171227747Slstewart      SCI_BASE_REQUEST_STATE_COMPLETED
172227747Slstewart   );
173227747Slstewart}
174227747Slstewart
175227747Slstewart/**
176227747Slstewart * @brief This method implements the actions taken when entering the
177227747Slstewart *        ABORTING state.
178227747Slstewart *
179227747Slstewart * @param[in]  object This parameter specifies the base object for which
180227747Slstewart *             the state transition is occurring.  This is cast into a
181227747Slstewart *             SCIF_SAS_IO_REQUEST object in the method implementation.
182227747Slstewart *
183227747Slstewart * @return none
184227747Slstewart */
185227747Slstewartstatic
186227747Slstewartvoid scif_sas_io_request_aborting_state_enter(
187227747Slstewart   SCI_BASE_OBJECT_T *object
188227747Slstewart)
189227747Slstewart{
190227747Slstewart   SCIF_SAS_IO_REQUEST_T * fw_io = (SCIF_SAS_IO_REQUEST_T *)object;
191227747Slstewart
192227747Slstewart   SCIF_LOG_WARNING((
193227747Slstewart      sci_base_object_get_logger(fw_io),
194227747Slstewart      SCIF_LOG_OBJECT_IO_REQUEST | SCIF_LOG_OBJECT_TASK_MANAGEMENT,
195227747Slstewart      "Domain:0x%x Device:0x%x IORequest:0x%x terminating\n",
196227747Slstewart      fw_io->parent.device->domain, fw_io->parent.device, fw_io
197227747Slstewart   ));
198227747Slstewart
199227747Slstewart   SET_STATE_HANDLER(
200227747Slstewart      &fw_io->parent,
201227747Slstewart      scif_sas_io_request_state_handler_table,
202227747Slstewart      SCI_BASE_REQUEST_STATE_ABORTING
203227747Slstewart   );
204227747Slstewart
205227747Slstewart   fw_io->parent.status = scif_sas_request_terminate_start(
206227747Slstewart                             &fw_io->parent, fw_io->parent.core_object
207227747Slstewart                          );
208227747Slstewart}
209227747Slstewart
210227747Slstewart/**
211227747Slstewart * @brief This method implements the actions taken when exiting the
212227747Slstewart *        ABORTING state.
213227747Slstewart *
214227747Slstewart * @param[in]  object This parameter specifies the base object for which
215227747Slstewart *             the state transition is occurring.  This is cast into a
216227747Slstewart *             SCIF_SAS_IO_REQUEST object in the method implementation.
217227747Slstewart *
218227747Slstewart * @return none
219227747Slstewart */
220227747Slstewartstatic
221227747Slstewartvoid scif_sas_io_request_aborting_state_exit(
222227747Slstewart   SCI_BASE_OBJECT_T *object
223227747Slstewart)
224227747Slstewart{
225227747Slstewart   SCIF_SAS_REQUEST_T * fw_request = (SCIF_SAS_REQUEST_T *)object;
226227747Slstewart   scif_sas_request_terminate_complete(fw_request);
227227747Slstewart}
228227776Slstewart
229227776Slstewart/**
230227776Slstewart * @brief This method implements the actions taken when entering the
231227776Slstewart *        FINAL state.
232227776Slstewart *
233227776Slstewart * @param[in]  object This parameter specifies the base object for which
234227747Slstewart *             the state transition is occurring.  This is cast into a
235227747Slstewart *             SCIF_SAS_IO_REQUEST object in the method implementation.
236227747Slstewart *
237227747Slstewart * @return none
238227747Slstewart */
239227747Slstewartstatic
240227747Slstewartvoid scif_sas_io_request_final_state_enter(
241227747Slstewart   SCI_BASE_OBJECT_T *object
242227747Slstewart)
243227747Slstewart{
244227747Slstewart   SCIF_SAS_IO_REQUEST_T * fw_io = (SCIF_SAS_IO_REQUEST_T *)object;
245227747Slstewart
246227747Slstewart   SET_STATE_HANDLER(
247227747Slstewart      &fw_io->parent,
248227747Slstewart      scif_sas_io_request_state_handler_table,
249227747Slstewart      SCI_BASE_REQUEST_STATE_FINAL
250227747Slstewart   );
251227747Slstewart}
252227747Slstewart
253227747SlstewartSCI_BASE_STATE_T scif_sas_io_request_state_table[SCI_BASE_REQUEST_MAX_STATES] =
254227747Slstewart{
255227747Slstewart   {
256227747Slstewart      SCI_BASE_REQUEST_STATE_INITIAL,
257227747Slstewart      scif_sas_io_request_initial_state_enter,
258227747Slstewart      NULL
259227747Slstewart   },
260227747Slstewart   {
261227747Slstewart      SCI_BASE_REQUEST_STATE_CONSTRUCTED,
262227747Slstewart      scif_sas_io_request_constructed_state_enter,
263227747Slstewart      NULL
264227747Slstewart   },
265227747Slstewart   {
266227747Slstewart      SCI_BASE_REQUEST_STATE_STARTED,
267227747Slstewart      scif_sas_io_request_started_state_enter,
268227747Slstewart      NULL
269227747Slstewart   },
270227747Slstewart   {
271227747Slstewart      SCI_BASE_REQUEST_STATE_COMPLETED,
272227747Slstewart      scif_sas_io_request_completed_state_enter,
273227747Slstewart      NULL
274227747Slstewart   },
275227747Slstewart   {
276227747Slstewart      SCI_BASE_REQUEST_STATE_ABORTING,
277227747Slstewart      scif_sas_io_request_aborting_state_enter,
278227747Slstewart      scif_sas_io_request_aborting_state_exit
279227747Slstewart   },
280227747Slstewart   {
281227747Slstewart      SCI_BASE_REQUEST_STATE_FINAL,
282227747Slstewart      scif_sas_io_request_final_state_enter,
283227747Slstewart      NULL
284227747Slstewart   },
285227747Slstewart};
286227747Slstewart
287227747Slstewart