xref: /freebsd/sys/dev/isci/scil/sci_base_domain.h (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
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  * $FreeBSD$
55  */
56 #ifndef _SCI_BASE_DOMAIN_H_
57 #define _SCI_BASE_DOMAIN_H_
58 
59 /**
60  * @file
61  *
62  * @brief This file contains all of the structures, constants, and methods
63  *        common to all domain object definitions.
64  */
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif // __cplusplus
69 
70 #include <dev/isci/scil/sci_base_object.h>
71 #include <dev/isci/scil/sci_base_logger.h>
72 #include <dev/isci/scil/sci_base_state_machine.h>
73 #include <dev/isci/scil/sci_base_state_machine_logger.h>
74 
75 /**
76  * @enum SCI_BASE_DOMAIN_STATES
77  *
78  * @brief This enumeration depicts the standard states common to all domain
79  *        state machine implementations.
80  */
81 typedef enum _SCI_BASE_DOMAIN_STATES
82 {
83    /**
84     * Simply the initial state for the base domain state machine.
85     */
86    SCI_BASE_DOMAIN_STATE_INITIAL,
87 
88    /**
89     * This state indicates that the domain has successfully been stopped.
90     * In this state no new IO operations are permitted.
91     * This state is entered from the INITIAL state.
92     * This state is entered from the DISCOVERING state.
93     */
94    SCI_BASE_DOMAIN_STATE_STARTING,
95 
96    /**
97     * This state indicates the domain is now ready.  Thus, the user
98     * is able to perform IO operations to remote devices in this domain.
99     * This state is entered from the STOPPED state.
100     * This state is entered from the STOPPING state.
101     * This state is entered from the DISCOVERING state.
102     */
103    SCI_BASE_DOMAIN_STATE_READY,
104 
105    /**
106     * This state indicates that the domain is in the process of stopping.
107     * In this state no new IO operations are permitted, but existing IO
108     * operations in the domain are allowed to complete.
109     * This state is entered from the READY state.
110     * This state is entered from the DISCOVERING state.
111     */
112    SCI_BASE_DOMAIN_STATE_STOPPING,
113 
114    /**
115     * This state indicates that the domain has successfully been stopped.
116     * In this state no new IO operations are permitted.
117     * This state is entered from the INITIAL state.
118     * This state is entered from the STOPPING state.
119     */
120    SCI_BASE_DOMAIN_STATE_STOPPED,
121 
122    /**
123     * This state indicates that the domain is actively attempting to
124     * discover what remote devices are contained in it.  In this state no
125     * new user IO requests are permitted.
126     * This state is entered from the READY state.
127     */
128    SCI_BASE_DOMAIN_STATE_DISCOVERING,
129 
130    SCI_BASE_DOMAIN_MAX_STATES
131 
132 } SCI_BASE_DOMAIN_STATES;
133 
134 /**
135  * @struct SCI_BASE_DOMAIN
136  *
137  * @brief This structure defines all of the fields common to DOMAIN objects.
138  */
139 typedef struct SCI_BASE_DOMAIN
140 {
141    /**
142     * This field depicts the parent object (SCI_BASE_OBJECT) for the domain.
143     */
144    SCI_BASE_OBJECT_T parent;
145 
146    /**
147     * This field contains the information for the base domain state machine.
148     */
149    SCI_BASE_STATE_MACHINE_T state_machine;
150 
151    #ifdef SCI_LOGGING
152    SCI_BASE_STATE_MACHINE_LOGGER_T state_machine_logger;
153    #endif // SCI_LOGGING
154 
155 } SCI_BASE_DOMAIN_T;
156 
157 struct SCI_BASE_CONTROLLER;
158 struct SCI_BASE_REMOTE_DEVICE;
159 struct SCI_BASE_REQUEST;
160 struct SCI_BASE_REQUEST;
161 
162 typedef SCI_STATUS (*SCI_BASE_DOMAIN_TIMED_HANDLER_T)(
163    SCI_BASE_DOMAIN_T *,
164    U32,
165    U32
166 );
167 
168 typedef SCI_STATUS (*SCI_BASE_DOMAIN_HANDLER_T)(
169    SCI_BASE_DOMAIN_T *
170 );
171 
172 typedef SCI_STATUS (*SCI_BASE_DOMAIN_PORT_NOT_READY_HANDLER_T)(
173    SCI_BASE_DOMAIN_T *,
174    U32
175 );
176 
177 typedef SCI_STATUS (*SCI_BASE_DOMAIN_DEVICE_HANDLER_T)(
178    SCI_BASE_DOMAIN_T *,
179    struct SCI_BASE_REMOTE_DEVICE *
180 );
181 
182 typedef SCI_STATUS (*SCI_BASE_DOMAIN_REQUEST_HANDLER_T)(
183    SCI_BASE_DOMAIN_T *,
184    struct SCI_BASE_REMOTE_DEVICE *,
185    struct SCI_BASE_REQUEST *
186 );
187 
188 typedef SCI_STATUS (*SCI_BASE_DOMAIN_HIGH_PRIORITY_REQUEST_COMPLETE_HANDLER_T)(
189    SCI_BASE_DOMAIN_T *,
190    struct SCI_BASE_REMOTE_DEVICE *,
191    struct SCI_BASE_REQUEST *,
192    void *,
193    SCI_IO_STATUS
194 );
195 
196 
197 /**
198  * @struct SCI_BASE_DOMAIN_STATE_HANDLER
199  *
200  * @brief This structure contains all of the state handler methods common to
201  *        base domain state machines.  Handler methods provide the ability
202  *        to change the behavior for user requests or transitions depending
203  *        on the state the machine is in.
204  */
205 typedef struct SCI_BASE_DOMAIN_STATE_HANDLER
206 {
207    /**
208     * The discover_handler specifies the method invoked when a user attempts
209     * to discover a domain.
210     */
211    SCI_BASE_DOMAIN_TIMED_HANDLER_T discover_handler;
212 
213    /**
214     * The port_ready_handler specifies the method invoked an SCI Core
215     * informs the domain object that it's associated port is now ready
216     * for IO operation.
217     */
218    SCI_BASE_DOMAIN_HANDLER_T port_ready_handler;
219 
220    /**
221     * The port_not_ready_handler specifies the method invoked an SCI Core
222     * informs the domain object that it's associated port is no longer ready
223     * for IO operation.
224     */
225    SCI_BASE_DOMAIN_PORT_NOT_READY_HANDLER_T port_not_ready_handler;
226 
227    /**
228     * The device_start_complete_handler specifies the method invoked when a
229     * remote device start operation in the domain completes.
230     */
231    SCI_BASE_DOMAIN_DEVICE_HANDLER_T device_start_complete_handler;
232 
233    /**
234     * The device_stop_complete_handler specifies the method invoked when a
235     * remote device stop operation in the domain completes.
236     */
237    SCI_BASE_DOMAIN_DEVICE_HANDLER_T device_stop_complete_handler;
238 
239    /**
240     * The device_destruct_handler specifies the method invoked when sci user
241     * destruct a remote device of this domain.
242     */
243    SCI_BASE_DOMAIN_DEVICE_HANDLER_T device_destruct_handler;
244 
245    /**
246     * The start_io_handler specifies the method invoked when a user
247     * attempts to start an IO request for a domain.
248     */
249    SCI_BASE_DOMAIN_REQUEST_HANDLER_T start_io_handler;
250 
251    /**
252     * The start_high_priority_io_handler specifies the method invoked when a user
253     * attempts to start an high priority request for a domain.
254     */
255    SCI_BASE_DOMAIN_REQUEST_HANDLER_T start_high_priority_io_handler;
256 
257    /**
258     * The complete_io_handler specifies the method invoked when a user
259     * attempts to complete an IO request for a domain.
260     */
261    SCI_BASE_DOMAIN_REQUEST_HANDLER_T complete_io_handler;
262 
263    /**
264     * The complete_high_priority_io_handler specifies the method invoked when a
265     * user attempts to complete an high priority IO request for a domain.
266     */
267    SCI_BASE_DOMAIN_HIGH_PRIORITY_REQUEST_COMPLETE_HANDLER_T complete_high_priority_io_handler;
268 
269    /**
270     * The continue_io_handler specifies the method invoked when a user
271     * attempts to continue an IO request for a domain.
272     */
273    SCI_BASE_DOMAIN_REQUEST_HANDLER_T continue_io_handler;
274 
275    /**
276     * The start_task_handler specifies the method invoked when a user
277     * attempts to start a task management request for a domain.
278     */
279    SCI_BASE_DOMAIN_REQUEST_HANDLER_T start_task_handler;
280 
281    /**
282     * The complete_task_handler specifies the method invoked when a user
283     * attempts to complete a task management request for a domain.
284     */
285    SCI_BASE_DOMAIN_REQUEST_HANDLER_T complete_task_handler;
286 
287 } SCI_BASE_DOMAIN_STATE_HANDLER_T;
288 
289 /**
290  * @brief Construct the base domain
291  *
292  * @param[in] this_domain This parameter specifies the base domain to be
293  *            constructed.
294  * @param[in] logger This parameter specifies the logger associated with
295  *            this base domain object.
296  * @param[in] state_table This parameter specifies the table of state
297  *            definitions to be utilized for the domain state machine.
298  *
299  * @return none
300  */
301 void sci_base_domain_construct(
302    SCI_BASE_DOMAIN_T * this_domain,
303    SCI_BASE_LOGGER_T * logger,
304    SCI_BASE_STATE_T  * state_table
305 );
306 
307 #ifdef __cplusplus
308 }
309 #endif // __cplusplus
310 
311 #endif // _SCI_BASE_DOMAIN_H_
312