isci: Intel(R) C600 Series Chipset Storage Control Unit Driver
[firefly-linux-kernel-4.4.55.git] / drivers / scsi / isci / core / sci_base_phy.h
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  *   * Neither the name of Intel Corporation nor the names of its
40  *     contributors may be used to endorse or promote products derived
41  *     from this software without specific prior written permission.
42  *
43  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54  */
55
56 #ifndef _SCI_BASE_PHY_H_
57 #define _SCI_BASE_PHY_H_
58
59 /**
60  * This file contains all of the structures, constants, and methods common to
61  *    all phy object definitions.
62  *
63  *
64  */
65
66 #include "sci_base_state_machine.h"
67
68 /**
69  * enum sci_base_phy_states - This enumeration depicts the standard states
70  *    common to all phy state machine implementations.
71  *
72  *
73  */
74 enum sci_base_phy_states {
75         /**
76          * Simply the initial state for the base domain state machine.
77          */
78         SCI_BASE_PHY_STATE_INITIAL,
79
80         /**
81          * This state indicates that the phy has successfully been stopped.
82          * In this state no new IO operations are permitted on this phy.
83          * This state is entered from the INITIAL state.
84          * This state is entered from the STARTING state.
85          * This state is entered from the READY state.
86          * This state is entered from the RESETTING state.
87          */
88         SCI_BASE_PHY_STATE_STOPPED,
89
90         /**
91          * This state indicates that the phy is in the process of becomming
92          * ready.  In this state no new IO operations are permitted on this phy.
93          * This state is entered from the STOPPED state.
94          * This state is entered from the READY state.
95          * This state is entered from the RESETTING state.
96          */
97         SCI_BASE_PHY_STATE_STARTING,
98
99         /**
100          * This state indicates the the phy is now ready.  Thus, the user
101          * is able to perform IO operations utilizing this phy as long as it
102          * is currently part of a valid port.
103          * This state is entered from the STARTING state.
104          */
105         SCI_BASE_PHY_STATE_READY,
106
107         /**
108          * This state indicates that the phy is in the process of being reset.
109          * In this state no new IO operations are permitted on this phy.
110          * This state is entered from the READY state.
111          */
112         SCI_BASE_PHY_STATE_RESETTING,
113
114         /**
115          * Simply the final state for the base phy state machine.
116          */
117         SCI_BASE_PHY_STATE_FINAL,
118
119         SCI_BASE_PHY_MAX_STATES
120
121 };
122
123 /**
124  * struct sci_base_phy - This structure defines all of the fields common to PHY
125  *    objects.
126  *
127  *
128  */
129 struct sci_base_phy {
130         /**
131          * This field depicts the parent object (struct sci_base_object) for the phy.
132          */
133         struct sci_base_object parent;
134
135         /**
136          * This field contains the information for the base phy state machine.
137          */
138         struct sci_base_state_machine state_machine;
139 };
140
141 typedef enum sci_status (*SCI_BASE_PHY_HANDLER_T)(
142         struct sci_base_phy *
143         );
144
145 /**
146  * struct sci_base_phy_state_handler - This structure contains all of the state
147  *    handler methods common to base phy state machines.  Handler methods
148  *    provide the ability to change the behavior for user requests or
149  *    transitions depending on the state the machine is in.
150  *
151  *
152  */
153 struct sci_base_phy_state_handler {
154         /**
155          * The start_handler specifies the method invoked when there is an
156          * attempt to start a phy.
157          */
158         SCI_BASE_PHY_HANDLER_T start_handler;
159
160         /**
161          * The stop_handler specifies the method invoked when there is an
162          * attempt to stop a phy.
163          */
164         SCI_BASE_PHY_HANDLER_T stop_handler;
165
166         /**
167          * The reset_handler specifies the method invoked when there is an
168          * attempt to reset a phy.
169          */
170         SCI_BASE_PHY_HANDLER_T reset_handler;
171
172         /**
173          * The destruct_handler specifies the method invoked when attempting to
174          * destruct a phy.
175          */
176         SCI_BASE_PHY_HANDLER_T destruct_handler;
177
178 };
179
180 /**
181  * sci_base_phy_construct() - Construct the base phy
182  * @this_phy: This parameter specifies the base phy to be constructed.
183  * @state_table: This parameter specifies the table of state definitions to be
184  *    utilized for the phy state machine.
185  *
186  */
187 static inline void sci_base_phy_construct(
188         struct sci_base_phy *base_phy,
189         const struct sci_base_state *state_table)
190 {
191         base_phy->parent.private = NULL;
192         sci_base_state_machine_construct(
193                 &base_phy->state_machine,
194                 &base_phy->parent,
195                 state_table,
196                 SCI_BASE_PHY_STATE_INITIAL
197                 );
198
199         sci_base_state_machine_start(
200                 &base_phy->state_machine
201                 );
202 }
203
204
205 #endif /* _SCI_BASE_PHY_H_ */