1a6d42e7dSPeter Dunlap /*
2a6d42e7dSPeter Dunlap  * CDDL HEADER START
3a6d42e7dSPeter Dunlap  *
4a6d42e7dSPeter Dunlap  * The contents of this file are subject to the terms of the
5a6d42e7dSPeter Dunlap  * Common Development and Distribution License (the "License").
6a6d42e7dSPeter Dunlap  * You may not use this file except in compliance with the License.
7a6d42e7dSPeter Dunlap  *
8a6d42e7dSPeter Dunlap  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9a6d42e7dSPeter Dunlap  * or http://www.opensolaris.org/os/licensing.
10a6d42e7dSPeter Dunlap  * See the License for the specific language governing permissions
11a6d42e7dSPeter Dunlap  * and limitations under the License.
12a6d42e7dSPeter Dunlap  *
13a6d42e7dSPeter Dunlap  * When distributing Covered Code, include this CDDL HEADER in each
14a6d42e7dSPeter Dunlap  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15a6d42e7dSPeter Dunlap  * If applicable, add the following below this CDDL HEADER, with the
16a6d42e7dSPeter Dunlap  * fields enclosed by brackets "[]" replaced with your own identifying
17a6d42e7dSPeter Dunlap  * information: Portions Copyright [yyyy] [name of copyright owner]
18a6d42e7dSPeter Dunlap  *
19a6d42e7dSPeter Dunlap  * CDDL HEADER END
20a6d42e7dSPeter Dunlap  */
21483b029bSYuri Pankov 
22a6d42e7dSPeter Dunlap /*
23d618d68dSPriya Krishnan  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24483b029bSYuri Pankov  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
252727bb05STim Kordas  * Copyright (c) 2017, Joyent, Inc.  All rights reserved.
26a6d42e7dSPeter Dunlap  */
27483b029bSYuri Pankov 
28a6d42e7dSPeter Dunlap #ifndef _ISCSIT_H_
29a6d42e7dSPeter Dunlap #define	_ISCSIT_H_
30a6d42e7dSPeter Dunlap 
31a6d42e7dSPeter Dunlap #include <sys/iscsit/iscsi_if.h>
32a6d42e7dSPeter Dunlap #include <sys/iscsit/iscsit_common.h>
33a6d42e7dSPeter Dunlap 
344558d122SViswanathan Kannappan #include "iscsit_authclient.h"
354558d122SViswanathan Kannappan 
36a6d42e7dSPeter Dunlap /*
37a6d42e7dSPeter Dunlap  * For some reason iscsi_protocol.h lists the max version as "0x02" and the
38a6d42e7dSPeter Dunlap  * min version as "0x00".  RFC3720 clearly states that the current version
39a6d42e7dSPeter Dunlap  * number is 0x00 so that is what we will use.
40a6d42e7dSPeter Dunlap  */
41a6d42e7dSPeter Dunlap #define	ISCSIT_MIN_VERSION			0x00
42a6d42e7dSPeter Dunlap #define	ISCSIT_MAX_VERSION			0x00
43d618d68dSPriya Krishnan #define	ISCSIT_MAX_CONNECTIONS			32 /* MC/S support  */
44a6d42e7dSPeter Dunlap #define	ISCSIT_MAX_RECV_DATA_SEGMENT_LENGTH	(32*1024)
45c050a449SPeter Gill #define	ISCSIT_MAX_BURST_LENGTH			(1024*1024)
47c050a449SPeter Gill #define	ISCSIT_MAX_TIME2WAIT			ISCSI_MAX_TIME2WAIT
50a6d42e7dSPeter Dunlap #define	ISCSIT_MAX_ERROR_RECOVERY_LEVEL		0
52a6d42e7dSPeter Dunlap 
53a6d42e7dSPeter Dunlap #define	ISCSIT_DEFAULT_TPG	"iscsit-default-tpg"
54a6d42e7dSPeter Dunlap #define	ISCSIT_DEFAULT_TPGT	1
55a6d42e7dSPeter Dunlap 
56a6d42e7dSPeter Dunlap #define	ISCSI_MAX_TSIH		0xffff
57a6d42e7dSPeter Dunlap #define	ISCSI_UNSPEC_TSIH	0
58a6d42e7dSPeter Dunlap 
59d618d68dSPriya Krishnan #define	ISCSIT_MAX_WINDOW	1024
60d618d68dSPriya Krishnan #define	ISCSIT_RXPDU_QUEUE_LEN	2048
61d618d68dSPriya Krishnan 
62d618d68dSPriya Krishnan /*
63d618d68dSPriya Krishnan  * MC/S: A timeout is maintained to recover from lost CmdSN (holes in the
64d618d68dSPriya Krishnan  * CmdSN ordering). When the timeout is reached, the ExpCmdSN is advanced
65d618d68dSPriya Krishnan  * past the hole to continue processing the queued commands. This value is
66d618d68dSPriya Krishnan  * system-tunable (volatile rxpdu_queue_threshold) and should be in the
67d618d68dSPriya Krishnan  * range from 5 to 30 seconds.
68d618d68dSPriya Krishnan  */
69d618d68dSPriya Krishnan #define	ISCSIT_RXPDU_QUEUE_THRESHOLD		5	/* 5 seconds */
70d618d68dSPriya Krishnan #define	ISCSIT_RXPDU_QUEUE_MONITOR_INTERVAL	5	/* 5 seconds */
71d618d68dSPriya Krishnan 
72a6d42e7dSPeter Dunlap /* Time in seconds to wait between calls to stmf_deregister_local_port */
73a6d42e7dSPeter Dunlap #define	TGT_DEREG_RETRY_SECONDS	1
74a6d42e7dSPeter Dunlap 
75a6d42e7dSPeter Dunlap #define	ISCSIT_GLOBAL_LOCK(rw) rw_enter(&iscsit_global.global_rwlock, (rw))
76a6d42e7dSPeter Dunlap #define	ISCSIT_GLOBAL_UNLOCK() rw_exit(&iscsit_global.global_rwlock)
77a6d42e7dSPeter Dunlap 
78d618d68dSPriya Krishnan /* Circular buffer to hold the out-of-order PDUs in MC/S */
79d618d68dSPriya Krishnan typedef struct {
80d618d68dSPriya Krishnan 	idm_pdu_t	*cb_buffer[ISCSIT_RXPDU_QUEUE_LEN];
81d618d68dSPriya Krishnan 	int		cb_num_elems;
82d618d68dSPriya Krishnan } iscsit_cbuf_t;
83d618d68dSPriya Krishnan 
84a6d42e7dSPeter Dunlap /*
85a6d42e7dSPeter Dunlap  * Used for serial number arithmetic (RFC 1982)
86a6d42e7dSPeter Dunlap  */
87a6d42e7dSPeter Dunlap #define	ISCSIT_SNA32_CHECK	0x80000000
88a6d42e7dSPeter Dunlap 
89a6d42e7dSPeter Dunlap typedef struct {
90a6d42e7dSPeter Dunlap 	char		tpg_name[MAX_TPG_NAMELEN];
91a6d42e7dSPeter Dunlap 	kmutex_t	tpg_mutex;
92a6d42e7dSPeter Dunlap 	idm_refcnt_t	tpg_refcnt;
93a6d42e7dSPeter Dunlap 	int		tpg_online;
94a6d42e7dSPeter Dunlap 	avl_tree_t	tpg_portal_list;
95a6d42e7dSPeter Dunlap 	avl_node_t	tpg_global_ln;
96a6d42e7dSPeter Dunlap 	list_node_t	tpg_delete_ln;
97a6d42e7dSPeter Dunlap } iscsit_tpg_t;
98a6d42e7dSPeter Dunlap 
99a6d42e7dSPeter Dunlap #define	IS_DEFAULT_TPGT(TPGT) \
100a6d42e7dSPeter Dunlap 	(((TPGT) != NULL) && \
101a6d42e7dSPeter Dunlap 	    ((TPGT)->tpgt_tpg == iscsit_global.global_default_tpg))
102a6d42e7dSPeter Dunlap 
103a6d42e7dSPeter Dunlap typedef struct {
104a6d42e7dSPeter Dunlap 	iscsit_tpg_t	*tpgt_tpg;
105a6d42e7dSPeter Dunlap 	idm_refcnt_t	tpgt_refcnt;
106a6d42e7dSPeter Dunlap 	avl_node_t	tpgt_tgt_ln;
107a6d42e7dSPeter Dunlap 	list_node_t	tpgt_delete_ln;
108a6d42e7dSPeter Dunlap 	uint16_t	tpgt_tag;
109a6d42e7dSPeter Dunlap 	boolean_t	tpgt_needs_tpg_offline;
110a6d42e7dSPeter Dunlap } iscsit_tpgt_t;
111a6d42e7dSPeter Dunlap 
112a6d42e7dSPeter Dunlap typedef struct {
113a6d42e7dSPeter Dunlap 	struct sockaddr_storage portal_addr;
114a6d42e7dSPeter Dunlap 	int			portal_online;
115a6d42e7dSPeter Dunlap 	idm_refcnt_t		portal_refcnt;
116a6d42e7dSPeter Dunlap 	avl_node_t		portal_tpg_ln;
117a6d42e7dSPeter Dunlap 	iscsit_tpg_t		*portal_tpg;
118a6d42e7dSPeter Dunlap 	idm_svc_t		*portal_svc;
119e42a0851Speter dunlap 	boolean_t		portal_default;
120e42a0851Speter dunlap 	void			*portal_isns;
121a6d42e7dSPeter Dunlap } iscsit_portal_t;
122a6d42e7dSPeter Dunlap 
123a6d42e7dSPeter Dunlap 
124*61dfa509SRick McNeal #define	TGT_STATE_LIST() \
125*61dfa509SRick McNeal 	item(TS_UNDEFINED) \
126*61dfa509SRick McNeal 	item(TS_CREATED) \
127*61dfa509SRick McNeal 	item(TS_ONLINING) \
128*61dfa509SRick McNeal 	item(TS_ONLINE) \
129*61dfa509SRick McNeal 	item(TS_STMF_ONLINE) \
130*61dfa509SRick McNeal 	item(TS_DELETING_NEED_OFFLINE) \
131*61dfa509SRick McNeal 	item(TS_OFFLINING) \
132*61dfa509SRick McNeal 	item(TS_OFFLINE) \
133*61dfa509SRick McNeal 	item(TS_STMF_OFFLINE) \
134*61dfa509SRick McNeal 	item(TS_DELETING_STMF_DEREG) \
135*61dfa509SRick McNeal 	item(TS_DELETING_STMF_DEREG_FAIL) \
136*61dfa509SRick McNeal 	item(TS_DELETING) \
137*61dfa509SRick McNeal 	item(TS_MAX_STATE)
138*61dfa509SRick McNeal 
139a6d42e7dSPeter Dunlap /* Target states and events, update iscsit_ts_name table whenever modified */
140a6d42e7dSPeter Dunlap typedef enum {
141*61dfa509SRick McNeal #define	item(a)	a,
142*61dfa509SRick McNeal 	TGT_STATE_LIST()
143*61dfa509SRick McNeal #undef	item
144a6d42e7dSPeter Dunlap } iscsit_tgt_state_t;
145a6d42e7dSPeter Dunlap 
146a6d42e7dSPeter Dunlap #ifdef ISCSIT_TGT_SM_STRINGS
147*61dfa509SRick McNeal static const char *iscsit_ts_name[TS_MAX_STATE + 1] = {
148*61dfa509SRick McNeal #define	item(a) #a,
149*61dfa509SRick McNeal 	TGT_STATE_LIST()
150*61dfa509SRick McNeal #undef	item
151a6d42e7dSPeter Dunlap };
152a6d42e7dSPeter Dunlap #endif
153a6d42e7dSPeter Dunlap 
154*61dfa509SRick McNeal #define	TGT_EVENT_LIST() \
155*61dfa509SRick McNeal 	item(TE_UNDEFINED) \
156*61dfa509SRick McNeal 	item(TE_STMF_ONLINE_REQ) \
157*61dfa509SRick McNeal 	item(TE_ONLINE_SUCCESS) \
158*61dfa509SRick McNeal 	item(TE_ONLINE_FAIL) \
159*61dfa509SRick McNeal 	item(TE_STMF_ONLINE_COMPLETE_ACK) \
160*61dfa509SRick McNeal 	item(TE_STMF_OFFLINE_REQ) \
161*61dfa509SRick McNeal 	item(TE_OFFLINE_COMPLETE) \
162*61dfa509SRick McNeal 	item(TE_STMF_OFFLINE_COMPLETE_ACK) \
163*61dfa509SRick McNeal 	item(TE_DELETE) \
164*61dfa509SRick McNeal 	item(TE_STMF_DEREG_SUCCESS) \
165*61dfa509SRick McNeal 	item(TE_STMF_DEREG_FAIL) \
166*61dfa509SRick McNeal 	item(TE_STMF_DEREG_RETRY) \
167*61dfa509SRick McNeal 	item(TE_WAIT_REF_COMPLETE) \
168*61dfa509SRick McNeal 	item(TE_MAX_EVENT)
169*61dfa509SRick McNeal 
170a6d42e7dSPeter Dunlap typedef enum {
171*61dfa509SRick McNeal #define	item(a) a,
172*61dfa509SRick McNeal 	TGT_EVENT_LIST()
173*61dfa509SRick McNeal #undef	item
174a6d42e7dSPeter Dunlap } iscsit_tgt_event_t;
175a6d42e7dSPeter Dunlap 
176a6d42e7dSPeter Dunlap #ifdef ISCSIT_TGT_SM_STRINGS
177*61dfa509SRick McNeal static const char *iscsit_te_name[TE_MAX_EVENT + 1] = {
178*61dfa509SRick McNeal #define	item(a) #a,
179*61dfa509SRick McNeal 	TGT_EVENT_LIST()
180*61dfa509SRick McNeal #undef	item
181a6d42e7dSPeter Dunlap };
182a6d42e7dSPeter Dunlap #endif
183a6d42e7dSPeter Dunlap 
184a6d42e7dSPeter Dunlap typedef struct {
185a6d42e7dSPeter Dunlap 	char			*target_name;
186a6d42e7dSPeter Dunlap 	nvlist_t		*target_props;
187a6d42e7dSPeter Dunlap 	kmutex_t		target_mutex;
188a6d42e7dSPeter Dunlap 	idm_refcnt_t		target_refcnt;
189a6d42e7dSPeter Dunlap 	idm_refcnt_t		target_sess_refcnt;
190a6d42e7dSPeter Dunlap 	avl_tree_t		target_tpgt_list;
191a6d42e7dSPeter Dunlap 	avl_tree_t		target_sess_list;
192a6d42e7dSPeter Dunlap 	avl_node_t		target_global_ln;
193a6d42e7dSPeter Dunlap 	avl_node_t		target_global_deleted_ln;
194a6d42e7dSPeter Dunlap 	/* STMF lport == iSCSI target */
195a6d42e7dSPeter Dunlap 	scsi_devid_desc_t	*target_devid;
196a6d42e7dSPeter Dunlap 	stmf_local_port_t	*target_stmf_lport;
197a6d42e7dSPeter Dunlap 	uint8_t			target_stmf_lport_registered;
198a6d42e7dSPeter Dunlap 
199a6d42e7dSPeter Dunlap 	/* Target state */
200a6d42e7dSPeter Dunlap 	boolean_t		target_sm_busy;
201a6d42e7dSPeter Dunlap 	boolean_t		target_deleting;
202a6d42e7dSPeter Dunlap 	iscsit_tgt_state_t	target_state;
203a6d42e7dSPeter Dunlap 	iscsit_tgt_state_t	target_last_state;
204a6d42e7dSPeter Dunlap 	sm_audit_buf_t		target_state_audit;
205a6d42e7dSPeter Dunlap 	list_t			target_events;
206a6d42e7dSPeter Dunlap 	uint64_t		target_generation;
207a6d42e7dSPeter Dunlap } iscsit_tgt_t;
208a6d42e7dSPeter Dunlap 
209a6d42e7dSPeter Dunlap typedef struct {
210a6d42e7dSPeter Dunlap 	char			ini_name[MAX_ISCSI_NODENAMELEN];
211a6d42e7dSPeter Dunlap 	nvlist_t		*ini_props;
212a6d42e7dSPeter Dunlap 	avl_node_t		ini_global_ln;
213a6d42e7dSPeter Dunlap } iscsit_ini_t;
214a6d42e7dSPeter Dunlap 
215a6d42e7dSPeter Dunlap /*
216a6d42e7dSPeter Dunlap  * iSCSI Auth Information
217a6d42e7dSPeter Dunlap  */
218a6d42e7dSPeter Dunlap typedef struct conn_auth {
21930e7468fSPeter Dunlap 	char			ca_tgt_chapuser[iscsitAuthStringMaxLength];
22030e7468fSPeter Dunlap 	uint8_t			ca_tgt_chapsecret[iscsitAuthStringMaxLength];
221a6d42e7dSPeter Dunlap 	int			ca_tgt_chapsecretlen;
222a6d42e7dSPeter Dunlap 
22330e7468fSPeter Dunlap 	char			ca_ini_chapuser[iscsitAuthStringMaxLength];
22430e7468fSPeter Dunlap 	uint8_t			ca_ini_chapsecret[iscsitAuthStringMaxLength];
225a6d42e7dSPeter Dunlap 	int			ca_ini_chapsecretlen;
226a6d42e7dSPeter Dunlap 
227*61dfa509SRick McNeal 	/* RADIUS authentication information	*/
228a6d42e7dSPeter Dunlap 	boolean_t		ca_use_radius;
229a6d42e7dSPeter Dunlap 	struct sockaddr_storage	ca_radius_server;
23030e7468fSPeter Dunlap 	uint8_t			ca_radius_secret[iscsitAuthStringMaxLength];
231a6d42e7dSPeter Dunlap 	int			ca_radius_secretlen;
232a6d42e7dSPeter Dunlap 
233a6d42e7dSPeter Dunlap 	/* authentication method list */
23430e7468fSPeter Dunlap 	iscsit_auth_method_t	ca_method_valid_list[iscsitAuthMethodMaxCount];
235a6d42e7dSPeter Dunlap 
236a6d42e7dSPeter Dunlap 	/* Target alias */
237a6d42e7dSPeter Dunlap 	char			ca_tgt_alias[MAX_ISCSI_NODENAMELEN];
238a6d42e7dSPeter Dunlap } conn_auth_t;
239a6d42e7dSPeter Dunlap 
240a6d42e7dSPeter Dunlap /*
241a6d42e7dSPeter Dunlap  * We have three state machines (so far) between the IDM connection state
242a6d42e7dSPeter Dunlap  * machine, the session state machine, and the login state machine.  All
243a6d42e7dSPeter Dunlap  * of these states have some concept of "full feature mode".  It's going
244a6d42e7dSPeter Dunlap  * to be obnoxious if we use a mixture of these "ffp" representations
245a6d42e7dSPeter Dunlap  * since it will be difficult to ensure the three state machines
246a6d42e7dSPeter Dunlap  * transition at exactly the same time.  We should drive decisions that
247a6d42e7dSPeter Dunlap  * depend on FFP from the IDM state machine which is actually snooping
248a6d42e7dSPeter Dunlap  * the iSCSI PDU's and will always transition at the correct time.
249a6d42e7dSPeter Dunlap  *
250a6d42e7dSPeter Dunlap  * A consequence of this approach is that there is a window just after
251a6d42e7dSPeter Dunlap  * login completes where we may get a SCSI request but the session
252a6d42e7dSPeter Dunlap  * or login state machine has not quite transitioned to "FFP".  Whether
253a6d42e7dSPeter Dunlap  * this is a problem depends on how we use those state machines.  This
254a6d42e7dSPeter Dunlap  * is what we should use them for:
255a6d42e7dSPeter Dunlap  *
256a6d42e7dSPeter Dunlap  * IDM Connection state machine - Decisions related to command processing
257a6d42e7dSPeter Dunlap  * including whether a connection is in FFP
258a6d42e7dSPeter Dunlap  *
259a6d42e7dSPeter Dunlap  * Session state machine - Summarize the state of all available connections
260a6d42e7dSPeter Dunlap  * for the purposes of ERL1, ERL2 and MC/S.  A session in LOGGED_IN state
261a6d42e7dSPeter Dunlap  * should always have at least one FFP connection but there may be a brief
262a6d42e7dSPeter Dunlap  * window where a session in ACTIVE might have one or more FFP connections
263a6d42e7dSPeter Dunlap  * even though ACTIVE is not strictly an FFP state according to the RFC.
264a6d42e7dSPeter Dunlap  *
265a6d42e7dSPeter Dunlap  * Login state machine -- drive the login process, collect negotiated
266a6d42e7dSPeter Dunlap  * parameters.  Another side effect of this approach is that we may get
267a6d42e7dSPeter Dunlap  * the "notify ffp" callback from the IDM connection state machine before
268a6d42e7dSPeter Dunlap  * the login state machine has actually transitioned to FFP state.
269a6d42e7dSPeter Dunlap  */
270a6d42e7dSPeter Dunlap 
271a6d42e7dSPeter Dunlap struct iscsit_conn_s;
272a6d42e7dSPeter Dunlap 
273*61dfa509SRick McNeal /* Add new session states above SS_MAX_STATE */
274*61dfa509SRick McNeal #define	SESSION_STATE_LIST() \
275*61dfa509SRick McNeal 	item(SS_UNDEFINED) \
276*61dfa509SRick McNeal 	item(SS_Q1_FREE) \
277*61dfa509SRick McNeal 	item(SS_Q2_ACTIVE) \
278*61dfa509SRick McNeal 	item(SS_Q3_LOGGED_IN) \
279*61dfa509SRick McNeal 	item(SS_Q4_FAILED) \
280*61dfa509SRick McNeal 	item(SS_Q5_CONTINUE) \
281*61dfa509SRick McNeal 	item(SS_Q6_DONE) \
282*61dfa509SRick McNeal 	item(SS_Q7_ERROR) \
283*61dfa509SRick McNeal 	item(SS_MAX_STATE)
284*61dfa509SRick McNeal 
285a6d42e7dSPeter Dunlap /* Update iscsit_ss_name table whenever session states are modified */
286a6d42e7dSPeter Dunlap typedef enum {
287*61dfa509SRick McNeal #define	item(a) a,
288*61dfa509SRick McNeal 	SESSION_STATE_LIST()
289*61dfa509SRick McNeal #undef	item
290a6d42e7dSPeter Dunlap } iscsit_session_state_t;
291a6d42e7dSPeter Dunlap 
292a6d42e7dSPeter Dunlap #ifdef ISCSIT_SESS_SM_STRINGS
293a6d42e7dSPeter Dunlap /* An array of state text values, for use in logging state transitions */
294*61dfa509SRick McNeal static const char *iscsit_ss_name[SS_MAX_STATE + 1] = {
295*61dfa509SRick McNeal #define	item(a) #a,
296*61dfa509SRick McNeal 	SESSION_STATE_LIST()
297*61dfa509SRick McNeal #undef	item
298a6d42e7dSPeter Dunlap };
299a6d42e7dSPeter Dunlap #endif
300a6d42e7dSPeter Dunlap 
301*61dfa509SRick McNeal /* Add new events above SE_MAX_EVENT */
302*61dfa509SRick McNeal #define	SESSION_EVENT_LIST() \
303*61dfa509SRick McNeal 	item(SE_UNDEFINED) \
304*61dfa509SRick McNeal 	item(SE_CONN_IN_LOGIN)	/* From login state machine */ \
305*61dfa509SRick McNeal 	item(SE_CONN_LOGGED_IN)	/* FFP enabled client notification */ \
306*61dfa509SRick McNeal 	item(SE_CONN_FFP_FAIL)	/* FFP disabled client notification */ \
307*61dfa509SRick McNeal 	item(SE_CONN_FFP_DISABLE) /* FFP disabled client notification */ \
308*61dfa509SRick McNeal 	item(SE_CONN_FAIL) /* Conn destroy client notification */ \
309*61dfa509SRick McNeal 	item(SE_SESSION_CLOSE)	/* FFP disabled client notification */ \
310*61dfa509SRick McNeal 	item(SE_SESSION_REINSTATE) /* From login state machine */ \
311*61dfa509SRick McNeal 	item(SE_SESSION_TIMEOUT) /* Internal */ \
312*61dfa509SRick McNeal 	item(SE_SESSION_CONTINUE) /* From login state machine */ \
313*61dfa509SRick McNeal 	item(SE_SESSION_CONTINUE_FAIL) /* From login state machine? */ \
314*61dfa509SRick McNeal 	item(SE_MAX_EVENT)
315*61dfa509SRick McNeal 
316a6d42e7dSPeter Dunlap /* Update iscsit_se_name table whenever session events are modified */
317a6d42e7dSPeter Dunlap typedef enum {
318*61dfa509SRick McNeal #define	item(a) a,
319*61dfa509SRick McNeal 	SESSION_EVENT_LIST()
320*61dfa509SRick McNeal #undef	item
321a6d42e7dSPeter Dunlap } iscsit_session_event_t;
322a6d42e7dSPeter Dunlap 
323a6d42e7dSPeter Dunlap #ifdef ISCSIT_SESS_SM_STRINGS
324a6d42e7dSPeter Dunlap /* An array of event text values, for use in logging events */
325*61dfa509SRick McNeal static const char *iscsit_se_name[SE_MAX_EVENT + 1] = {
326*61dfa509SRick McNeal #define	item(a) #a,
327*61dfa509SRick McNeal 	SESSION_EVENT_LIST()
328*61dfa509SRick McNeal #undef	item
329a6d42e7dSPeter Dunlap };
330a6d42e7dSPeter Dunlap #endif
331a6d42e7dSPeter Dunlap 
332a6d42e7dSPeter Dunlap /*
333a6d42e7dSPeter Dunlap  * Set in ist_tgt after iscsit_tgt_unbind_sess to differentiate an unbound
334a6d42e7dSPeter Dunlap  * session from a discovery session.
335a6d42e7dSPeter Dunlap  */
336a6d42e7dSPeter Dunlap #define	SESS_UNBOUND_FROM_TGT	-1
337a6d42e7dSPeter Dunlap 
338a6d42e7dSPeter Dunlap typedef struct {
339a6d42e7dSPeter Dunlap 	stmf_scsi_session_t	*ist_stmf_sess;
340a6d42e7dSPeter Dunlap 	stmf_local_port_t	*ist_lport;
341a6d42e7dSPeter Dunlap 	iscsit_tgt_t		*ist_tgt;
342a6d42e7dSPeter Dunlap 	idm_refcnt_t		ist_refcnt;
343a6d42e7dSPeter Dunlap 	kmem_cache_t		*ist_task_cache;
344d618d68dSPriya Krishnan 	kmutex_t		ist_sn_mutex;
345a6d42e7dSPeter Dunlap 	kmutex_t		ist_mutex;
346a6d42e7dSPeter Dunlap 	kcondvar_t		ist_cv;
347a6d42e7dSPeter Dunlap 	iscsit_session_state_t	ist_state;
348a6d42e7dSPeter Dunlap 	iscsit_session_state_t	ist_last_state;
349a6d42e7dSPeter Dunlap 	sm_audit_buf_t		ist_state_audit;
350a6d42e7dSPeter Dunlap 	boolean_t		ist_sm_busy;
351a6d42e7dSPeter Dunlap 	boolean_t		ist_sm_complete;
352a6d42e7dSPeter Dunlap 	boolean_t		ist_admin_close;
353a6d42e7dSPeter Dunlap 	list_t			ist_events;
354a6d42e7dSPeter Dunlap 	int			ist_conn_count;
355a6d42e7dSPeter Dunlap 	int			ist_ffp_conn_count;
356a6d42e7dSPeter Dunlap 	struct iscsit_conn_s	*ist_failed_conn;
357a6d42e7dSPeter Dunlap 	timeout_id_t		ist_state_timeout;
358a6d42e7dSPeter Dunlap 	list_t			ist_conn_list;
359a6d42e7dSPeter Dunlap 	avl_node_t		ist_tgt_ln;
360a6d42e7dSPeter Dunlap 	char			*ist_initiator_name;
361a6d42e7dSPeter Dunlap 	char			*ist_initiator_alias;
362a6d42e7dSPeter Dunlap 	char			*ist_target_name;
363a6d42e7dSPeter Dunlap 	char			*ist_target_alias;
364a6d42e7dSPeter Dunlap 	uint8_t			ist_isid[ISCSI_ISID_LEN];
365a6d42e7dSPeter Dunlap 	uint16_t		ist_tsih;
366a6d42e7dSPeter Dunlap 	uint16_t		ist_tpgt_tag;
367a6d42e7dSPeter Dunlap 	uint32_t		ist_expcmdsn;
368a6d42e7dSPeter Dunlap 	uint32_t		ist_maxcmdsn;
36972cf3143Speter dunlap 	avl_tree_t		ist_task_list;
370d618d68dSPriya Krishnan 	iscsit_cbuf_t		*ist_rxpdu_queue;
371a6d42e7dSPeter Dunlap } iscsit_sess_t;
372a6d42e7dSPeter Dunlap 
373*61dfa509SRick McNeal /* Add new login states above ILS_MAX_STATE */
374*61dfa509SRick McNeal #define	LOGIN_STATE_LIST() \
375*61dfa509SRick McNeal 	item(ILS_UNDEFINED) \
376*61dfa509SRick McNeal 	item(ILS_LOGIN_INIT) \
377*61dfa509SRick McNeal 	item(ILS_LOGIN_WAITING)	/* Waiting for more login PDU's */ \
378*61dfa509SRick McNeal 	item(ILS_LOGIN_PROCESSING) /* Processing login request */ \
379*61dfa509SRick McNeal 	item(ILS_LOGIN_RESPONDING) /* Sending login response */ \
380*61dfa509SRick McNeal 	item(ILS_LOGIN_RESPONDED) /* Sent login response (no trans. to FFP) */ \
381*61dfa509SRick McNeal 	item(ILS_LOGIN_FFP) /* Sending last login PDU for final response */ \
382*61dfa509SRick McNeal 	item(ILS_LOGIN_DONE) /* Last login PDU sent (so we can free it) */ \
383*61dfa509SRick McNeal 	item(ILS_LOGIN_ERROR) /* Login error, login failed */ \
384*61dfa509SRick McNeal 	item(ILS_MAX_STATE)
385*61dfa509SRick McNeal 
386a6d42e7dSPeter Dunlap /* Update iscsit_ils_name table whenever login states are modified */
387a6d42e7dSPeter Dunlap typedef enum {
388*61dfa509SRick McNeal #define	item(a) a,
389*61dfa509SRick McNeal 	LOGIN_STATE_LIST()
390*61dfa509SRick McNeal #undef	item
391a6d42e7dSPeter Dunlap } iscsit_login_state_t;
392a6d42e7dSPeter Dunlap 
393a6d42e7dSPeter Dunlap #ifdef ISCSIT_LOGIN_SM_STRINGS
394*61dfa509SRick McNeal /* An array of login state text values, for use in logging login progess */
395*61dfa509SRick McNeal static const char *iscsit_ils_name[ILS_MAX_STATE + 1] = {
396*61dfa509SRick McNeal #define	item(a) #a,
397*61dfa509SRick McNeal 	LOGIN_STATE_LIST()
398*61dfa509SRick McNeal #undef	item
399a6d42e7dSPeter Dunlap };
400a6d42e7dSPeter Dunlap #endif
401a6d42e7dSPeter Dunlap 
402*61dfa509SRick McNeal /* Add new login events above ILE_MAX_EVENT */
403*61dfa509SRick McNeal #define	LOGIN_EVENT_LIST() \
404*61dfa509SRick McNeal 	item(ILE_UNDEFINED) \
405*61dfa509SRick McNeal 	item(ILE_LOGIN_RCV) \
406*61dfa509SRick McNeal 	item(ILE_LOGIN_RESP_READY) \
407*61dfa509SRick McNeal 	item(ILE_LOGIN_FFP) \
408*61dfa509SRick McNeal 	item(ILE_LOGIN_RESP_COMPLETE) \
409*61dfa509SRick McNeal 	item(ILE_LOGIN_ERROR) \
410*61dfa509SRick McNeal 	item(ILE_LOGIN_CONN_ERROR) \
411*61dfa509SRick McNeal 	item(ILE_MAX_EVENT)
412*61dfa509SRick McNeal 
413a6d42e7dSPeter Dunlap /* Update iscsit_ile_name table whenever login events are modified */
414a6d42e7dSPeter Dunlap typedef enum {
415*61dfa509SRick McNeal #define	item(a) a,
416*61dfa509SRick McNeal 	LOGIN_EVENT_LIST()
417*61dfa509SRick McNeal #undef	item
418a6d42e7dSPeter Dunlap } iscsit_login_event_t;
419a6d42e7dSPeter Dunlap 
420a6d42e7dSPeter Dunlap #ifdef ISCSIT_LOGIN_SM_STRINGS
421*61dfa509SRick McNeal /* An array of login event text values, for use in loggin login events */
422*61dfa509SRick McNeal static const char *iscsit_ile_name[ILE_MAX_EVENT + 1] = {
423*61dfa509SRick McNeal #define	item(a) #a,