xref: /illumos-gate/usr/src/uts/common/sys/idm/idm_conn_sm.h (revision ef2504f26d1ea5859db9838255bb63f488f1b050)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #ifndef	_IDM_CONN_SM_H_
27 #define	_IDM_CONN_SM_H_
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 
34 /*
35  * IDM connection state machine events.  Most events get generated internally
36  * either by the state machine or by the IDM TX/RX code.  For example when IDM
37  * receives a login request for a target connectionit will generate a
38  * CE_LOGIN_RCV event.  Similarly when the target sends a successful login
39  * response IDM generate a "CE_LOGIN_SUCCESS_SND" event.  The following
40  * events are not detected on the TX/RX path and must be generated explicitly
41  * by the client when appropriate:
42  *
43  * CE_LOGOUT_OTHER_CONN_RCV
44  * CE_ASYNC_DROP_CONN_RCV   (Only because the message may be received on
45  * a different connection from the connection being dropped)
46  * CE_ASYNC_DROP_ALL_CONN_RCV
47  * CE_LOGOUT_OTHER_CONN_SND
48  * CE_ASYNC_DROP_ALL_CONN_SND
49  *
50  * The following events might occur in any state since they are driven
51  * by the PDU's that IDM receives:
52  *
53  * CE_LOGIN_RCV
54  * CE_LOGIN_SUCCESS_RCV
55  * CE_LOGIN_FAIL_RCV
56  * CE_LOGOUT_SUCCESS_RCV
57  * CE_LOGOUT_FAIL_RCV
58  * CE_ASYNC_LOGOUT_RCV
59  * CE_MISC_RCV
60  * CE_RX_PROTOCOL_ERROR
61  */
62 
63 #define	IDM_LOGIN_SECONDS	20
64 #define	IDM_LOGOUT_SECONDS	20
65 #define	IDM_CLEANUP_SECONDS	0
66 
67 /* Update idm_ce_name table whenever connection events are modified */
68 typedef enum {
69 	CE_UNDEFINED = 0,
70 
71 	/* Initiator events */
72 	CE_CONNECT_REQ,
73 	CE_CONNECT_FAIL,
74 	CE_CONNECT_SUCCESS,
75 	CE_LOGIN_SND,
76 	CE_LOGIN_SUCCESS_RCV,
77 	CE_LOGIN_FAIL_RCV,
78 	CE_LOGOUT_THIS_CONN_SND,
79 	CE_LOGOUT_OTHER_CONN_SND,
80 	CE_LOGOUT_SESSION_SND,
81 	CE_LOGOUT_SUCCESS_RCV,
82 	CE_LOGOUT_FAIL_RCV,
83 	CE_ASYNC_LOGOUT_RCV,
84 	CE_ASYNC_DROP_CONN_RCV,
85 	CE_ASYNC_DROP_ALL_CONN_RCV,
86 
87 	/* Target events */
88 	CE_CONNECT_ACCEPT,
89 	CE_CONNECT_REJECT,
90 	CE_LOGIN_RCV,
91 	CE_LOGIN_TIMEOUT,
92 	CE_LOGIN_SUCCESS_SND,
93 	CE_LOGIN_FAIL_SND,
94 	CE_LOGIN_FAIL_SND_DONE,
95 	CE_LOGOUT_THIS_CONN_RCV,
96 	CE_LOGOUT_OTHER_CONN_RCV,
97 	CE_LOGOUT_SESSION_RCV,
98 	CE_LOGOUT_SUCCESS_SND,
99 	CE_LOGOUT_SUCCESS_SND_DONE,
100 	CE_LOGOUT_FAIL_SND,
101 	CE_LOGOUT_FAIL_SND_DONE,
102 	CE_CLEANUP_TIMEOUT,
103 	CE_ASYNC_LOGOUT_SND,
104 	CE_ASYNC_DROP_CONN_SND,
105 	CE_ASYNC_DROP_ALL_CONN_SND,
106 	CE_LOGOUT_TIMEOUT,
107 
108 	/* Common events */
109 	CE_TRANSPORT_FAIL,
110 	CE_MISC_TX,
111 	CE_TX_PROTOCOL_ERROR,
112 	CE_MISC_RX,
113 	CE_RX_PROTOCOL_ERROR,
114 	CE_LOGOUT_SESSION_SUCCESS,
115 	CE_CONN_REINSTATE,
116 	CE_CONN_REINSTATE_SUCCESS,
117 	CE_CONN_REINSTATE_FAIL,
118 	CE_ENABLE_DM_SUCCESS,
119 	CE_ENABLE_DM_FAIL,
120 
121 	/* Add new events above CE_MAX_EVENT */
122 	CE_MAX_EVENT
123 } idm_conn_event_t;
124 
125 #ifdef IDM_CONN_SM_STRINGS
126 /* An array of event text values, for use in logging events */
127 static const char *idm_ce_name[CE_MAX_EVENT+1] = {
128 	"CE_UNDEFINED",
129 	"CE_CONNECT_REQ",
130 	"CE_CONNECT_FAIL",
131 	"CE_CONNECT_SUCCESS",
132 	"CE_LOGIN_SND",
133 	"CE_LOGIN_SUCCESS_RCV",
134 	"CE_LOGIN_FAIL_RCV",
135 	"CE_LOGOUT_THIS_CONN_SND",
136 	"CE_LOGOUT_OTHER_CONN_SND",
137 	"CE_LOGOUT_SESSION_SND",
138 	"CE_LOGOUT_SUCCESS_RCV",
139 	"CE_LOGOUT_FAIL_RCV",
140 	"CE_ASYNC_LOGOUT_RCV",
141 	"CE_ASYNC_DROP_CONN_RCV",
142 	"CE_ASYNC_DROP_ALL_CONN_RCV",
143 	"CE_CONNECT_ACCEPT",
144 	"CE_CONNECT_REJECT",
145 	"CE_LOGIN_RCV",
146 	"CE_LOGIN_TIMEOUT",
147 	"CE_LOGIN_SUCCESS_SND",
148 	"CE_LOGIN_FAIL_SND",
149 	"CE_LOGIN_FAIL_SND_DONE",
150 	"CE_LOGOUT_THIS_CONN_RCV",
151 	"CE_LOGOUT_OTHER_CONN_RCV",
152 	"CE_LOGOUT_SESSION_RCV",
153 	"CE_LOGOUT_SUCCESS_SND",
154 	"CE_LOGOUT_SUCCESS_SND_DONE",
155 	"CE_LOGOUT_FAIL_SND",
156 	"CE_LOGOUT_FAIL_SND_DONE",
157 	"CE_CLEANUP_TIMEOUT",
158 	"CE_ASYNC_LOGOUT_SND",
159 	"CE_ASYNC_DROP_CONN_SND",
160 	"CE_ASYNC_DROP_ALL_CONN_SND",
161 	"CE_LOGOUT_TIMEOUT",
162 	"CE_TRANSPORT_FAIL",
163 	"CE_MISC_TX",
164 	"CE_TX_PROTOCOL_ERROR",
165 	"CE_MISC_RX",
166 	"CE_RX_PROTOCOL_ERROR",
167 	"CE_LOGOUT_SESSION_SUCCESS",
168 	"CE_CONN_REINSTATE",
169 	"CE_CONN_REINSTATE_SUCCESS",
170 	"CE_CONN_REINSTATE_FAIL",
171 	"CE_ENABLE_DM_SUCCESS",
172 	"CE_ENABLE_DM_FAIL",
173 	"CE_MAX_EVENT"
174 };
175 #endif
176 
177 /* Update idm_cs_name table whenever connection states are modified */
178 typedef enum {
179 	CS_S0_UNDEFINED = 0,
180 
181 	CS_S1_FREE,
182 	CS_S2_XPT_WAIT,
183 	CS_S3_XPT_UP,
184 	CS_S4_IN_LOGIN,
185 	CS_S5_LOGGED_IN,
186 	CS_S6_IN_LOGOUT,
187 	CS_S7_LOGOUT_REQ,
188 	CS_S8_CLEANUP,
189 	CS_S9_INIT_ERROR,
190 	CS_S9A_REJECTED,
191 	CS_S10_IN_CLEANUP,
192 	CS_S11_COMPLETE,
193 	CS_S12_ENABLE_DM,
194 
195 	/* Add new connection states above CS_MAX_STATE */
196 	CS_MAX_STATE
197 } idm_conn_state_t;
198 
199 #ifdef IDM_CONN_SM_STRINGS
200 /* An array of state text values, for use in logging state transitions */
201 static const char *idm_cs_name[CS_MAX_STATE+1] = {
202 	"CS_S0_UNDEFINED",
203 	"CS_S1_FREE",
204 	"CS_S2_XPT_WAIT",
205 	"CS_S3_XPT_UP",
206 	"CS_S4_IN_LOGIN",
207 	"CS_S5_LOGGED_IN",
208 	"CS_S6_IN_LOGOUT",
209 	"CS_S7_LOGOUT_REQ",
210 	"CS_S8_CLEANUP",
211 	"CS_S9_INIT_ERROR",
212 	"CS_S9A_REJECTED",
213 	"CS_S10_IN_CLEANUP",
214 	"CS_S11_COMPLETE",
215 	"CS_S12_ENABLE_DM",
216 	"CS_MAX_STATE"
217 };
218 #endif
219 
220 typedef enum {
221 	CT_NONE = 0,
222 	CT_RX_PDU,
223 	CT_TX_PDU
224 } idm_pdu_event_type_t;
225 
226 typedef enum {
227 	CA_TX_PROTOCOL_ERROR,	/* Send "protocol error" to state machine */
228 	CA_RX_PROTOCOL_ERROR,	/* Send "protocol error" to state machine */
229 	CA_FORWARD,		/* State machine event and forward to client */
230 	CA_DROP			/* Drop PDU */
231 } idm_pdu_event_action_t;
232 
233 typedef struct {
234 	struct idm_conn_s	*iec_ic;
235 	idm_conn_event_t	iec_event;
236 	uintptr_t		iec_info;
237 	idm_pdu_event_type_t	iec_pdu_event_type;
238 	boolean_t		iec_pdu_forwarded;
239 } idm_conn_event_ctx_t;
240 
241 idm_status_t
242 idm_conn_sm_init(struct idm_conn_s *ic);
243 
244 void
245 idm_conn_sm_fini(struct idm_conn_s *ic);
246 
247 idm_status_t
248 idm_notify_client(struct idm_conn_s *ic, idm_client_notify_t cn,
249     uintptr_t data);
250 
251 void
252 idm_conn_event(struct idm_conn_s *ic, idm_conn_event_t event, uintptr_t data);
253 
254 void
255 idm_conn_event(struct idm_conn_s *ic, idm_conn_event_t event, uintptr_t data);
256 
257 void
258 idm_conn_event_locked(struct idm_conn_s *ic, idm_conn_event_t event,
259     uintptr_t event_info, idm_pdu_event_type_t pdu_event_type);
260 
261 idm_status_t
262 idm_conn_reinstate_event(struct idm_conn_s *old_ic, struct idm_conn_s *new_ic);
263 
264 void
265 idm_conn_tx_pdu_event(struct idm_conn_s *ic, idm_conn_event_t event,
266     uintptr_t data);
267 
268 void
269 idm_conn_rx_pdu_event(struct idm_conn_s *ic, idm_conn_event_t event,
270     uintptr_t data);
271 
272 char *
273 idm_conn_state_str(struct idm_conn_s *ic);
274 
275 #ifdef	__cplusplus
276 }
277 #endif
278 
279 #endif /* _IDM_CONN_SM_H_ */
280