xref: /freebsd/sys/dev/isci/scil/sci_base_phy.h (revision 8ef24a0d4b28fe230e20637f56869cc4148cd2ca)
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license.  When using or
3  * redistributing this file, you may do so under either license.
4  *
5  * GPL LICENSE SUMMARY
6  *
7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of version 2 of the GNU General Public License as
11  * published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21  * The full GNU General Public License is included in this distribution
22  * in the file called LICENSE.GPL.
23  *
24  * BSD LICENSE
25  *
26  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
33  *   * Redistributions of source code must retain the above copyright
34  *     notice, this list of conditions and the following disclaimer.
35  *   * Redistributions in binary form must reproduce the above copyright
36  *     notice, this list of conditions and the following disclaimer in
37  *     the documentation and/or other materials provided with the
38  *     distribution.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51  *
52  * $FreeBSD$
53  */
54 #ifndef _SCI_BASE_PHY_H_
55 #define _SCI_BASE_PHY_H_
56 
57 /**
58  * @file
59  *
60  * @brief This file contains all of the structures, constants, and methods
61  *        common to all phy object definitions.
62  */
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif // __cplusplus
67 
68 #include <dev/isci/scil/sci_base_logger.h>
69 #include <dev/isci/scil/sci_base_state_machine.h>
70 #include <dev/isci/scil/sci_base_state_machine_logger.h>
71 
72 /**
73  * @enum SCI_BASE_PHY_STATES
74  *
75  * @brief This enumeration depicts the standard states common to all phy
76  *        state machine implementations.
77  */
78 typedef enum _SCI_BASE_PHY_STATES
79 {
80    /**
81     * Simply the initial state for the base domain state machine.
82     */
83    SCI_BASE_PHY_STATE_INITIAL,
84 
85    /**
86     * This state indicates that the phy has successfully been stopped.
87     * In this state no new IO operations are permitted on this phy.
88     * This state is entered from the INITIAL state.
89     * This state is entered from the STARTING state.
90     * This state is entered from the READY state.
91     * This state is entered from the RESETTING state.
92     */
93    SCI_BASE_PHY_STATE_STOPPED,
94 
95    /**
96     * This state indicates that the phy is in the process of becoming
97     * ready.  In this state no new IO operations are permitted on this phy.
98     * This state is entered from the STOPPED state.
99     * This state is entered from the READY state.
100     * This state is entered from the RESETTING state.
101     */
102    SCI_BASE_PHY_STATE_STARTING,
103 
104    /**
105     * This state indicates the phy is now ready.  Thus, the user
106     * is able to perform IO operations utilizing this phy as long as it
107     * is currently part of a valid port.
108     * This state is entered from the STARTING state.
109     */
110    SCI_BASE_PHY_STATE_READY,
111 
112    /**
113     * This state indicates that the phy is in the process of being reset.
114     * In this state no new IO operations are permitted on this phy.
115     * This state is entered from the READY state.
116     */
117    SCI_BASE_PHY_STATE_RESETTING,
118 
119    /**
120     * Simply the final state for the base phy state machine.
121     */
122    SCI_BASE_PHY_STATE_FINAL,
123 
124    SCI_BASE_PHY_MAX_STATES
125 
126 } SCI_BASE_PHY_STATES;
127 
128 /**
129  * @struct SCI_BASE_PHY
130  *
131  * @brief This structure defines all of the fields common to PHY objects.
132  */
133 typedef struct SCI_BASE_PHY
134 {
135    /**
136     * This field depicts the parent object (SCI_BASE_OBJECT) for the phy.
137     */
138    SCI_BASE_OBJECT_T parent;
139 
140    /**
141     * This field contains the information for the base phy state machine.
142     */
143    SCI_BASE_STATE_MACHINE_T state_machine;
144 
145    #ifdef SCI_LOGGING
146    SCI_BASE_STATE_MACHINE_LOGGER_T state_machine_logger;
147    #endif // SCI_LOGGING
148 
149 } SCI_BASE_PHY_T;
150 
151 typedef SCI_STATUS (*SCI_BASE_PHY_HANDLER_T)(
152    SCI_BASE_PHY_T *
153 );
154 
155 /**
156  * @struct SCI_BASE_PHY_STATE_HANDLER
157  *
158  * @brief This structure contains all of the state handler methods common to
159  *        base phy state machines.  Handler methods provide the ability
160  *        to change the behavior for user requests or transitions depending
161  *        on the state the machine is in.
162  */
163 typedef struct SCI_BASE_PHY_STATE_HANDLER
164 {
165    /**
166     * The start_handler specifies the method invoked when there is an
167     * attempt to start a phy.
168     */
169    SCI_BASE_PHY_HANDLER_T start_handler;
170 
171    /**
172     * The stop_handler specifies the method invoked when there is an
173     * attempt to stop a phy.
174     */
175    SCI_BASE_PHY_HANDLER_T stop_handler;
176 
177    /**
178     * The reset_handler specifies the method invoked when there is an
179     * attempt to reset a phy.
180     */
181    SCI_BASE_PHY_HANDLER_T reset_handler;
182 
183    /**
184     * The destruct_handler specifies the method invoked when attempting to
185     * destruct a phy.
186     */
187    SCI_BASE_PHY_HANDLER_T destruct_handler;
188 
189 } SCI_BASE_PHY_STATE_HANDLER_T;
190 
191 /**
192  * @brief Construct the base phy
193  *
194  * @param[in] this_phy This parameter specifies the base phy to be
195  *            constructed.
196  * @param[in] logger This parameter specifies the logger associated with
197  *            this base phy object.
198  * @param[in] state_table This parameter specifies the table of state
199  *            definitions to be utilized for the phy state machine.
200  *
201  * @return none
202  */
203 void sci_base_phy_construct(
204    SCI_BASE_PHY_T    * this_phy,
205    SCI_BASE_LOGGER_T * logger,
206    SCI_BASE_STATE_T  * state_table
207 );
208 
209 #ifdef __cplusplus
210 }
211 #endif // __cplusplus
212 
213 #endif // _SCI_BASE_PHY_H_
214