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_PORT_H_
55230557Sjimharris#define _SCI_BASE_PORT_H_
56230557Sjimharris
57230557Sjimharris/**
58230557Sjimharris * @file
59230557Sjimharris *
60230557Sjimharris * @brief This file contains all of the structures, constants, and methods
61230557Sjimharris *        common to all port object definitions.
62230557Sjimharris */
63230557Sjimharris
64230557Sjimharris#ifdef __cplusplus
65230557Sjimharrisextern "C" {
66230557Sjimharris#endif // __cplusplus
67230557Sjimharris
68230557Sjimharris#include <dev/isci/scil/sci_base_object.h>
69230557Sjimharris#include <dev/isci/scil/sci_base_logger.h>
70230557Sjimharris#include <dev/isci/scil/sci_base_state_machine.h>
71230557Sjimharris#include <dev/isci/scil/sci_base_state_machine_logger.h>
72230557Sjimharris
73230557Sjimharris/**
74230557Sjimharris * @enum SCI_BASE_PORT_STATES
75230557Sjimharris *
76230557Sjimharris * @brief This enumeration depicts all the states for the common port
77230557Sjimharris *        state machine.
78230557Sjimharris */
79230557Sjimharristypedef enum _SCI_BASE_PORT_STATES
80230557Sjimharris{
81230557Sjimharris   /**
82230557Sjimharris    * This state indicates that the port has successfully been stopped.
83230557Sjimharris    * In this state no new IO operations are permitted.
84230557Sjimharris    * This state is entered from the STOPPING state.
85230557Sjimharris    */
86230557Sjimharris   SCI_BASE_PORT_STATE_STOPPED,
87230557Sjimharris
88230557Sjimharris   /**
89230557Sjimharris    * This state indicates that the port is in the process of stopping.
90230557Sjimharris    * In this state no new IO operations are permitted, but existing IO
91230557Sjimharris    * operations are allowed to complete.
92230557Sjimharris    * This state is entered from the READY state.
93230557Sjimharris    */
94230557Sjimharris   SCI_BASE_PORT_STATE_STOPPING,
95230557Sjimharris
96230557Sjimharris   /**
97230557Sjimharris    * This state indicates the port is now ready.  Thus, the user is
98230557Sjimharris    * able to perform IO operations on this port.
99230557Sjimharris    * This state is entered from the STARTING state.
100230557Sjimharris    */
101230557Sjimharris   SCI_BASE_PORT_STATE_READY,
102230557Sjimharris
103230557Sjimharris   /**
104230557Sjimharris    * This state indicates the port is in the process of performing a hard
105230557Sjimharris    * reset.  Thus, the user is unable to perform IO operations on this
106230557Sjimharris    * port.
107230557Sjimharris    * This state is entered from the READY state.
108230557Sjimharris    */
109230557Sjimharris   SCI_BASE_PORT_STATE_RESETTING,
110230557Sjimharris
111230557Sjimharris   /**
112230557Sjimharris    * This state indicates the port has failed a reset request.  This state
113230557Sjimharris    * is entered when a port reset request times out.
114230557Sjimharris    * This state is entered from the RESETTING state.
115230557Sjimharris    */
116230557Sjimharris   SCI_BASE_PORT_STATE_FAILED,
117230557Sjimharris
118230557Sjimharris   SCI_BASE_PORT_MAX_STATES
119230557Sjimharris
120230557Sjimharris} SCI_BASE_PORT_STATES;
121230557Sjimharris
122230557Sjimharris/**
123230557Sjimharris * @struct SCI_BASE_PORT
124230557Sjimharris *
125230557Sjimharris * @brief The base port object abstracts the fields common to all SCI
126230557Sjimharris *        port objects.
127230557Sjimharris */
128230557Sjimharristypedef struct SCI_BASE_PORT
129230557Sjimharris{
130230557Sjimharris   /**
131230557Sjimharris    * The field specifies that the parent object for the base controller
132230557Sjimharris    * is the base object itself.
133230557Sjimharris    */
134230557Sjimharris   SCI_BASE_OBJECT_T parent;
135230557Sjimharris
136230557Sjimharris   /**
137230557Sjimharris    * This field contains the information for the base port state machine.
138230557Sjimharris    */
139230557Sjimharris   SCI_BASE_STATE_MACHINE_T state_machine;
140230557Sjimharris
141230557Sjimharris   #ifdef SCI_LOGGING
142230557Sjimharris   SCI_BASE_STATE_MACHINE_LOGGER_T state_machine_logger;
143230557Sjimharris   #endif // SCI_LOGGING
144230557Sjimharris
145230557Sjimharris} SCI_BASE_PORT_T;
146230557Sjimharris
147230557Sjimharrisstruct SCI_BASE_PHY;
148230557Sjimharris
149230557Sjimharristypedef SCI_STATUS (*SCI_BASE_PORT_HANDLER_T)(
150230557Sjimharris   SCI_BASE_PORT_T *
151230557Sjimharris);
152230557Sjimharris
153230557Sjimharristypedef SCI_STATUS (*SCI_BASE_PORT_PHY_HANDLER_T)(
154230557Sjimharris   SCI_BASE_PORT_T *,
155230557Sjimharris   struct SCI_BASE_PHY *
156230557Sjimharris);
157230557Sjimharris
158230557Sjimharristypedef SCI_STATUS (*SCI_BASE_PORT_RESET_HANDLER_T)(
159230557Sjimharris   SCI_BASE_PORT_T *,
160230557Sjimharris   U32 timeout
161230557Sjimharris);
162230557Sjimharris
163230557Sjimharris/**
164230557Sjimharris * @struct SCI_BASE_PORT_STATE_HANDLER
165230557Sjimharris *
166230557Sjimharris * @brief This structure contains all of the state handler methods common to
167230557Sjimharris *        base port state machines.  Handler methods provide the ability
168230557Sjimharris *        to change the behavior for user requests or transitions depending
169230557Sjimharris *        on the state the machine is in.
170230557Sjimharris */
171230557Sjimharristypedef struct SCI_BASE_PORT_STATE_HANDLER
172230557Sjimharris{
173230557Sjimharris   /**
174230557Sjimharris    * The start_handler specifies the method invoked when a user attempts to
175230557Sjimharris    * start a port.
176230557Sjimharris    */
177230557Sjimharris   SCI_BASE_PORT_HANDLER_T start_handler;
178230557Sjimharris
179230557Sjimharris   /**
180230557Sjimharris    * The stop_handler specifies the method invoked when a user attempts to
181230557Sjimharris    * stop a port.
182230557Sjimharris    */
183230557Sjimharris   SCI_BASE_PORT_HANDLER_T stop_handler;
184230557Sjimharris
185230557Sjimharris   /**
186230557Sjimharris    * The destruct_handler specifies the method invoked when attempting to
187230557Sjimharris    * destruct a port.
188230557Sjimharris    */
189230557Sjimharris   SCI_BASE_PORT_HANDLER_T destruct_handler;
190230557Sjimharris
191230557Sjimharris   /**
192230557Sjimharris    * The reset_handler specifies the method invoked when a user attempts to
193230557Sjimharris    * hard reset a port.
194230557Sjimharris    */
195230557Sjimharris   SCI_BASE_PORT_RESET_HANDLER_T reset_handler;
196230557Sjimharris
197230557Sjimharris   /**
198230557Sjimharris    * The add_phy_handler specifies the method invoked when a user attempts to
199230557Sjimharris    * add another phy into the port.
200230557Sjimharris    */
201230557Sjimharris   SCI_BASE_PORT_PHY_HANDLER_T add_phy_handler;
202230557Sjimharris
203230557Sjimharris   /**
204230557Sjimharris    * The remove_phy_handler specifies the method invoked when a user
205230557Sjimharris    * attempts to remove a phy from the port.
206230557Sjimharris    */
207230557Sjimharris   SCI_BASE_PORT_PHY_HANDLER_T remove_phy_handler;
208230557Sjimharris
209230557Sjimharris} SCI_BASE_PORT_STATE_HANDLER_T;
210230557Sjimharris
211230557Sjimharris/**
212230557Sjimharris * @brief Construct the base port object
213230557Sjimharris *
214230557Sjimharris * @param[in] this_port This parameter specifies the base port to be
215230557Sjimharris *            constructed.
216230557Sjimharris * @param[in] logger This parameter specifies the logger to be associated
217230557Sjimharris *            with this base port object.
218230557Sjimharris * @param[in] state_table This parameter specifies the table of state
219230557Sjimharris *            definitions to be utilized for the domain state machine.
220230557Sjimharris *
221230557Sjimharris * @return none
222230557Sjimharris */
223230557Sjimharrisvoid sci_base_port_construct(
224230557Sjimharris   SCI_BASE_PORT_T   * this_port,
225230557Sjimharris   SCI_BASE_LOGGER_T * logger,
226230557Sjimharris   SCI_BASE_STATE_T  * state_table
227230557Sjimharris);
228230557Sjimharris
229230557Sjimharris#ifdef __cplusplus
230230557Sjimharris}
231230557Sjimharris#endif // __cplusplus
232230557Sjimharris
233230557Sjimharris#endif // _SCI_BASE_PORT_H_
234