xref: /freebsd/sys/dev/isci/scil/sci_base_port.h (revision c697fb7f)
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_PORT_H_
57 #define _SCI_BASE_PORT_H_
58 
59 /**
60  * @file
61  *
62  * @brief This file contains all of the structures, constants, and methods
63  *        common to all port 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_PORT_STATES
77  *
78  * @brief This enumeration depicts all the states for the common port
79  *        state machine.
80  */
81 typedef enum _SCI_BASE_PORT_STATES
82 {
83    /**
84     * This state indicates that the port has successfully been stopped.
85     * In this state no new IO operations are permitted.
86     * This state is entered from the STOPPING state.
87     */
88    SCI_BASE_PORT_STATE_STOPPED,
89 
90    /**
91     * This state indicates that the port is in the process of stopping.
92     * In this state no new IO operations are permitted, but existing IO
93     * operations are allowed to complete.
94     * This state is entered from the READY state.
95     */
96    SCI_BASE_PORT_STATE_STOPPING,
97 
98    /**
99     * This state indicates the port is now ready.  Thus, the user is
100     * able to perform IO operations on this port.
101     * This state is entered from the STARTING state.
102     */
103    SCI_BASE_PORT_STATE_READY,
104 
105    /**
106     * This state indicates the port is in the process of performing a hard
107     * reset.  Thus, the user is unable to perform IO operations on this
108     * port.
109     * This state is entered from the READY state.
110     */
111    SCI_BASE_PORT_STATE_RESETTING,
112 
113    /**
114     * This state indicates the port has failed a reset request.  This state
115     * is entered when a port reset request times out.
116     * This state is entered from the RESETTING state.
117     */
118    SCI_BASE_PORT_STATE_FAILED,
119 
120    SCI_BASE_PORT_MAX_STATES
121 
122 } SCI_BASE_PORT_STATES;
123 
124 /**
125  * @struct SCI_BASE_PORT
126  *
127  * @brief The base port object abstracts the fields common to all SCI
128  *        port objects.
129  */
130 typedef struct SCI_BASE_PORT
131 {
132    /**
133     * The field specifies that the parent object for the base controller
134     * is the base object itself.
135     */
136    SCI_BASE_OBJECT_T parent;
137 
138    /**
139     * This field contains the information for the base port state machine.
140     */
141    SCI_BASE_STATE_MACHINE_T state_machine;
142 
143    #ifdef SCI_LOGGING
144    SCI_BASE_STATE_MACHINE_LOGGER_T state_machine_logger;
145    #endif // SCI_LOGGING
146 
147 } SCI_BASE_PORT_T;
148 
149 struct SCI_BASE_PHY;
150 
151 typedef SCI_STATUS (*SCI_BASE_PORT_HANDLER_T)(
152    SCI_BASE_PORT_T *
153 );
154 
155 typedef SCI_STATUS (*SCI_BASE_PORT_PHY_HANDLER_T)(
156    SCI_BASE_PORT_T *,
157    struct SCI_BASE_PHY *
158 );
159 
160 typedef SCI_STATUS (*SCI_BASE_PORT_RESET_HANDLER_T)(
161    SCI_BASE_PORT_T *,
162    U32 timeout
163 );
164 
165 /**
166  * @struct SCI_BASE_PORT_STATE_HANDLER
167  *
168  * @brief This structure contains all of the state handler methods common to
169  *        base port state machines.  Handler methods provide the ability
170  *        to change the behavior for user requests or transitions depending
171  *        on the state the machine is in.
172  */
173 typedef struct SCI_BASE_PORT_STATE_HANDLER
174 {
175    /**
176     * The start_handler specifies the method invoked when a user attempts to
177     * start a port.
178     */
179    SCI_BASE_PORT_HANDLER_T start_handler;
180 
181    /**
182     * The stop_handler specifies the method invoked when a user attempts to
183     * stop a port.
184     */
185    SCI_BASE_PORT_HANDLER_T stop_handler;
186 
187    /**
188     * The destruct_handler specifies the method invoked when attempting to
189     * destruct a port.
190     */
191    SCI_BASE_PORT_HANDLER_T destruct_handler;
192 
193    /**
194     * The reset_handler specifies the method invoked when a user attempts to
195     * hard reset a port.
196     */
197    SCI_BASE_PORT_RESET_HANDLER_T reset_handler;
198 
199    /**
200     * The add_phy_handler specifies the method invoked when a user attempts to
201     * add another phy into the port.
202     */
203    SCI_BASE_PORT_PHY_HANDLER_T add_phy_handler;
204 
205    /**
206     * The remove_phy_handler specifies the method invoked when a user
207     * attempts to remove a phy from the port.
208     */
209    SCI_BASE_PORT_PHY_HANDLER_T remove_phy_handler;
210 
211 } SCI_BASE_PORT_STATE_HANDLER_T;
212 
213 /**
214  * @brief Construct the base port object
215  *
216  * @param[in] this_port This parameter specifies the base port to be
217  *            constructed.
218  * @param[in] logger This parameter specifies the logger to be associated
219  *            with this base port object.
220  * @param[in] state_table This parameter specifies the table of state
221  *            definitions to be utilized for the domain state machine.
222  *
223  * @return none
224  */
225 void sci_base_port_construct(
226    SCI_BASE_PORT_T   * this_port,
227    SCI_BASE_LOGGER_T * logger,
228    SCI_BASE_STATE_T  * state_table
229 );
230 
231 #ifdef __cplusplus
232 }
233 #endif // __cplusplus
234 
235 #endif // _SCI_BASE_PORT_H_
236