1230557Sjimharris/*-
2230557Sjimharris * This file is provided under a dual BSD/GPLv2 license.  When using or
3230557Sjimharris * redistributing this file, you may do so under either license.
4230557Sjimharris *
5230557Sjimharris * GPL LICENSE SUMMARY
6230557Sjimharris *
7230557Sjimharris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8230557Sjimharris *
9230557Sjimharris * This program is free software; you can redistribute it and/or modify
10230557Sjimharris * it under the terms of version 2 of the GNU General Public License as
11230557Sjimharris * published by the Free Software Foundation.
12230557Sjimharris *
13230557Sjimharris * This program is distributed in the hope that it will be useful, but
14230557Sjimharris * WITHOUT ANY WARRANTY; without even the implied warranty of
15230557Sjimharris * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16230557Sjimharris * General Public License for more details.
17230557Sjimharris *
18230557Sjimharris * You should have received a copy of the GNU General Public License
19230557Sjimharris * along with this program; if not, write to the Free Software
20230557Sjimharris * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21230557Sjimharris * The full GNU General Public License is included in this distribution
22230557Sjimharris * in the file called LICENSE.GPL.
23230557Sjimharris *
24230557Sjimharris * BSD LICENSE
25230557Sjimharris *
26230557Sjimharris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27230557Sjimharris * All rights reserved.
28230557Sjimharris *
29230557Sjimharris * Redistribution and use in source and binary forms, with or without
30230557Sjimharris * modification, are permitted provided that the following conditions
31230557Sjimharris * are met:
32230557Sjimharris *
33230557Sjimharris *   * Redistributions of source code must retain the above copyright
34230557Sjimharris *     notice, this list of conditions and the following disclaimer.
35230557Sjimharris *   * Redistributions in binary form must reproduce the above copyright
36230557Sjimharris *     notice, this list of conditions and the following disclaimer in
37230557Sjimharris *     the documentation and/or other materials provided with the
38230557Sjimharris *     distribution.
39230557Sjimharris *
40230557Sjimharris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41230557Sjimharris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42230557Sjimharris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43230557Sjimharris * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44230557Sjimharris * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45230557Sjimharris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46230557Sjimharris * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47230557Sjimharris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48230557Sjimharris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49230557Sjimharris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50230557Sjimharris * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51230557Sjimharris *
52230557Sjimharris * $FreeBSD$
53230557Sjimharris */
54230557Sjimharris#ifndef _SCI_BASE_REMOTE_DEVICE_H_
55230557Sjimharris#define _SCI_BASE_REMOTE_DEVICE_H_
56230557Sjimharris
57230557Sjimharris/**
58230557Sjimharris * @file
59230557Sjimharris *
60230557Sjimharris * @brief This file contains all of the structures, constants, and methods
61230557Sjimharris *        common to all remote device object definitions.
62230557Sjimharris */
63230557Sjimharris
64230557Sjimharris#ifdef __cplusplus
65230557Sjimharrisextern "C" {
66230557Sjimharris#endif // __cplusplus
67230557Sjimharris
68230557Sjimharris#include <dev/isci/scil/sci_base_state_machine.h>
69230557Sjimharris#include <dev/isci/scil/sci_base_logger.h>
70230557Sjimharris#include <dev/isci/scil/sci_base_state_machine_logger.h>
71230557Sjimharris
72230557Sjimharrisstruct SCI_BASE_REQUEST;
73230557Sjimharris
74230557Sjimharris/**
75230557Sjimharris * @enum SCI_BASE_REMOTE_DEVICE_STATES
76230557Sjimharris *
77230557Sjimharris * @brief This enumeration depicts all the states for the common remote device
78230557Sjimharris *        state machine.
79230557Sjimharris */
80230557Sjimharristypedef enum _SCI_BASE_REMOTE_DEVICE_STATES
81230557Sjimharris{
82230557Sjimharris   /**
83230557Sjimharris    * Simply the initial state for the base remote device state machine.
84230557Sjimharris    */
85230557Sjimharris   SCI_BASE_REMOTE_DEVICE_STATE_INITIAL,
86230557Sjimharris
87230557Sjimharris   /**
88230557Sjimharris    * This state indicates that the remote device has successfully been
89230557Sjimharris    * stopped.  In this state no new IO operations are permitted.
90230557Sjimharris    * This state is entered from the INITIAL state.
91230557Sjimharris    * This state is entered from the STOPPING state.
92230557Sjimharris    */
93230557Sjimharris   SCI_BASE_REMOTE_DEVICE_STATE_STOPPED,
94230557Sjimharris
95230557Sjimharris   /**
96240518Seadler    * This state indicates the remote device is in the process of
97230557Sjimharris    * becoming ready (i.e. starting).  In this state no new IO operations
98230557Sjimharris    * are permitted.
99230557Sjimharris    * This state is entered from the STOPPED state.
100230557Sjimharris    */
101230557Sjimharris   SCI_BASE_REMOTE_DEVICE_STATE_STARTING,
102230557Sjimharris
103230557Sjimharris   /**
104230557Sjimharris    * This state indicates the remote device is now ready.  Thus, the user
105230557Sjimharris    * is able to perform IO operations on the remote device.
106230557Sjimharris    * This state is entered from the STARTING state.
107230557Sjimharris    */
108230557Sjimharris   SCI_BASE_REMOTE_DEVICE_STATE_READY,
109230557Sjimharris
110230557Sjimharris   /**
111230557Sjimharris    * This state indicates that the remote device is in the process of
112230557Sjimharris    * stopping.  In this state no new IO operations are permitted, but
113230557Sjimharris    * existing IO operations are allowed to complete.
114230557Sjimharris    * This state is entered from the READY state.
115230557Sjimharris    * This state is entered from the FAILED state.
116230557Sjimharris    */
117230557Sjimharris   SCI_BASE_REMOTE_DEVICE_STATE_STOPPING,
118230557Sjimharris
119230557Sjimharris   /**
120230557Sjimharris    * This state indicates that the remote device has failed.
121230557Sjimharris    * In this state no new IO operations are permitted.
122230557Sjimharris    * This state is entered from the INITIALIZING state.
123230557Sjimharris    * This state is entered from the READY state.
124230557Sjimharris    */
125230557Sjimharris   SCI_BASE_REMOTE_DEVICE_STATE_FAILED,
126230557Sjimharris
127230557Sjimharris   /**
128230557Sjimharris    * This state indicates the device is being reset.
129230557Sjimharris    * In this state no new IO operations are permitted.
130230557Sjimharris    * This state is entered from the READY state.
131230557Sjimharris    */
132230557Sjimharris   SCI_BASE_REMOTE_DEVICE_STATE_RESETTING,
133230557Sjimharris
134230557Sjimharris#if !defined(DISABLE_WIDE_PORTED_TARGETS)
135230557Sjimharris   /**
136230557Sjimharris    * This state indicates the device is in the middle of updating
137230557Sjimharris    * its port width. All the IOs sent to this device will be Quiesced.
138230557Sjimharris    */
139230557Sjimharris   SCI_BASE_REMOTE_DEVICE_STATE_UPDATING_PORT_WIDTH,
140230557Sjimharris#endif
141230557Sjimharris
142230557Sjimharris   /**
143230557Sjimharris    * Simply the final state for the base remote device state machine.
144230557Sjimharris    */
145230557Sjimharris   SCI_BASE_REMOTE_DEVICE_STATE_FINAL,
146230557Sjimharris
147230557Sjimharris   SCI_BASE_REMOTE_DEVICE_MAX_STATES
148230557Sjimharris
149230557Sjimharris} SCI_BASE_REMOTE_DEVICE_STATES;
150230557Sjimharris
151230557Sjimharris/**
152230557Sjimharris * @struct SCI_BASE_REMOTE_DEVICE
153230557Sjimharris *
154230557Sjimharris * @brief The base remote device object abstracts the fields common to all
155230557Sjimharris *        SCI remote device objects.
156230557Sjimharris */
157230557Sjimharristypedef struct SCI_BASE_REMOTE_DEVICE
158230557Sjimharris{
159230557Sjimharris   /**
160230557Sjimharris    * The field specifies that the parent object for the base remote
161230557Sjimharris    * device is the base object itself.
162230557Sjimharris    */
163230557Sjimharris   SCI_BASE_OBJECT_T parent;
164230557Sjimharris
165230557Sjimharris   /**
166230557Sjimharris    * This field contains the information for the base remote device state
167230557Sjimharris    * machine.
168230557Sjimharris    */
169230557Sjimharris   SCI_BASE_STATE_MACHINE_T state_machine;
170230557Sjimharris
171230557Sjimharris   #ifdef SCI_LOGGING
172230557Sjimharris   /**
173230557Sjimharris    * This field contains the state machine observer for the state machine.
174230557Sjimharris    */
175230557Sjimharris   SCI_BASE_STATE_MACHINE_LOGGER_T state_machine_logger;
176230557Sjimharris   #endif // SCI_LOGGING
177230557Sjimharris
178230557Sjimharris} SCI_BASE_REMOTE_DEVICE_T;
179230557Sjimharris
180230557Sjimharris
181230557Sjimharristypedef SCI_STATUS (*SCI_BASE_REMOTE_DEVICE_HANDLER_T)(
182230557Sjimharris   SCI_BASE_REMOTE_DEVICE_T *
183230557Sjimharris);
184230557Sjimharris
185230557Sjimharristypedef SCI_STATUS (*SCI_BASE_REMOTE_DEVICE_REQUEST_HANDLER_T)(
186230557Sjimharris   SCI_BASE_REMOTE_DEVICE_T *,
187230557Sjimharris   struct SCI_BASE_REQUEST *
188230557Sjimharris);
189230557Sjimharris
190230557Sjimharristypedef SCI_STATUS (*SCI_BASE_REMOTE_DEVICE_HIGH_PRIORITY_REQUEST_COMPLETE_HANDLER_T)(
191230557Sjimharris   SCI_BASE_REMOTE_DEVICE_T *,
192230557Sjimharris   struct SCI_BASE_REQUEST *,
193230557Sjimharris   void *,
194230557Sjimharris   SCI_IO_STATUS
195230557Sjimharris);
196230557Sjimharris
197230557Sjimharris/**
198230557Sjimharris * @struct SCI_BASE_CONTROLLER_STATE_HANDLER
199230557Sjimharris *
200230557Sjimharris * @brief This structure contains all of the state handler methods common to
201230557Sjimharris *        base remote device state machines.  Handler methods provide the ability
202230557Sjimharris *        to change the behavior for user requests or transitions depending
203230557Sjimharris *        on the state the machine is in.
204230557Sjimharris */
205230557Sjimharristypedef struct SCI_BASE_REMOTE_DEVICE_STATE_HANDLER
206230557Sjimharris{
207230557Sjimharris   /**
208230557Sjimharris    * The start_handler specifies the method invoked when a user attempts to
209230557Sjimharris    * start a remote device.
210230557Sjimharris    */
211230557Sjimharris   SCI_BASE_REMOTE_DEVICE_HANDLER_T start_handler;
212230557Sjimharris
213230557Sjimharris   /**
214230557Sjimharris    * The stop_handler specifies the method invoked when a user attempts to
215230557Sjimharris    * stop a remote device.
216230557Sjimharris    */
217230557Sjimharris   SCI_BASE_REMOTE_DEVICE_HANDLER_T stop_handler;
218230557Sjimharris
219230557Sjimharris   /**
220230557Sjimharris    * The fail_handler specifies the method invoked when a remote device
221230557Sjimharris    * failure has occurred.  A failure may be due to an inability to
222230557Sjimharris    * initialize/configure the device.
223230557Sjimharris    */
224230557Sjimharris   SCI_BASE_REMOTE_DEVICE_HANDLER_T fail_handler;
225230557Sjimharris
226230557Sjimharris   /**
227230557Sjimharris    * The destruct_handler specifies the method invoked when attempting to
228230557Sjimharris    * destruct a remote device.
229230557Sjimharris    */
230230557Sjimharris   SCI_BASE_REMOTE_DEVICE_HANDLER_T destruct_handler;
231230557Sjimharris
232230557Sjimharris   /**
233230557Sjimharris    * The reset handler specifies the method invloked when requesting to reset a
234230557Sjimharris    * remote device.
235230557Sjimharris    */
236230557Sjimharris   SCI_BASE_REMOTE_DEVICE_HANDLER_T reset_handler;
237230557Sjimharris
238230557Sjimharris   /**
239230557Sjimharris    * The reset complete handler specifies the method invloked when reporting
240230557Sjimharris    * that a reset has completed to the remote device.
241230557Sjimharris    */
242230557Sjimharris   SCI_BASE_REMOTE_DEVICE_HANDLER_T reset_complete_handler;
243230557Sjimharris
244230557Sjimharris   /**
245230557Sjimharris    * The start_io_handler specifies the method invoked when a user
246230557Sjimharris    * attempts to start an IO request for a remote device.
247230557Sjimharris    */
248230557Sjimharris   SCI_BASE_REMOTE_DEVICE_REQUEST_HANDLER_T start_io_handler;
249230557Sjimharris
250230557Sjimharris   /**
251230557Sjimharris    * The complete_io_handler specifies the method invoked when a user
252230557Sjimharris    * attempts to complete an IO request for a remote device.
253230557Sjimharris    */
254230557Sjimharris   SCI_BASE_REMOTE_DEVICE_REQUEST_HANDLER_T complete_io_handler;
255230557Sjimharris
256230557Sjimharris   /**
257230557Sjimharris    * The continue_io_handler specifies the method invoked when a user
258230557Sjimharris    * attempts to continue an IO request for a remote device.
259230557Sjimharris    */
260230557Sjimharris   SCI_BASE_REMOTE_DEVICE_REQUEST_HANDLER_T continue_io_handler;
261230557Sjimharris
262230557Sjimharris   /**
263230557Sjimharris    * The start_task_handler specifies the method invoked when a user
264230557Sjimharris    * attempts to start a task management request for a remote device.
265230557Sjimharris    */
266230557Sjimharris   SCI_BASE_REMOTE_DEVICE_REQUEST_HANDLER_T start_task_handler;
267230557Sjimharris
268230557Sjimharris   /**
269230557Sjimharris    * The complete_task_handler specifies the method invoked when a user
270230557Sjimharris    * attempts to complete a task management request for a remote device.
271230557Sjimharris    */
272230557Sjimharris   SCI_BASE_REMOTE_DEVICE_REQUEST_HANDLER_T complete_task_handler;
273230557Sjimharris
274230557Sjimharris} SCI_BASE_REMOTE_DEVICE_STATE_HANDLER_T;
275230557Sjimharris
276230557Sjimharris/**
277230557Sjimharris * @brief Construct the base remote device
278230557Sjimharris *
279230557Sjimharris * @param[in] this_remote_device This parameter specifies the base remote
280230557Sjimharris *            device to be constructed.
281230557Sjimharris * @param[in] logger This parameter specifies the logger associated with
282230557Sjimharris *            this base remote device object.
283230557Sjimharris * @param[in] state_table This parameter specifies the table of state
284230557Sjimharris *            definitions to be utilized for the remote device state machine.
285230557Sjimharris *
286230557Sjimharris * @return none
287230557Sjimharris */
288230557Sjimharrisvoid sci_base_remote_device_construct(
289230557Sjimharris   SCI_BASE_REMOTE_DEVICE_T * this_device,
290230557Sjimharris   SCI_BASE_LOGGER_T        * logger,
291230557Sjimharris   SCI_BASE_STATE_T         * state_table
292230557Sjimharris);
293230557Sjimharris
294230557Sjimharris#ifdef __cplusplus
295230557Sjimharris}
296230557Sjimharris#endif // __cplusplus
297230557Sjimharris
298230557Sjimharris#endif // _SCI_BASE_REMOTE_DEVICE_H_
299