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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 #ifndef _ISCSIT_H_
26 #define	_ISCSIT_H_
27 
28 #include <sys/iscsit/iscsi_if.h>
29 #include <iscsit_authclient.h>
30 #include <sys/iscsit/iscsit_common.h>
31 
32 /*
33  * For some reason iscsi_protocol.h lists the max version as "0x02" and the
34  * min version as "0x00".  RFC3720 clearly states that the current version
35  * number is 0x00 so that is what we will use.
36  */
37 #define	ISCSIT_MIN_VERSION			0x00
38 #define	ISCSIT_MAX_VERSION			0x00
39 #define	ISCSIT_MAX_CONNECTIONS			1 /* No MC/S support */
40 #define	ISCSIT_MAX_RECV_DATA_SEGMENT_LENGTH	(32*1024)
41 #define	ISCSIT_MAX_BURST_LENGTH			(512*1024)
42 #define	ISCSIT_MAX_FIRST_BURST_LENGTH		ISCSI_DEFAULT_FIRST_BURST_LENGTH
43 #define	ISCSIT_MAX_TIME2WAIT			ISCSI_DEFAULT_TIME_TO_WAIT
44 #define	ISCSIT_MAX_TIME2RETAIN			ISCSI_DEFAULT_TIME_TO_RETAIN
45 #define	ISCSIT_MAX_OUTSTANDING_R2T		ISCSI_DEFAULT_MAX_OUT_R2T
46 #define	ISCSIT_MAX_ERROR_RECOVERY_LEVEL		0
47 
48 #define	ISCSIT_DEFAULT_TPG	"iscsit-default-tpg"
49 #define	ISCSIT_DEFAULT_TPGT	1
50 
51 #define	ISCSI_MAX_TSIH		0xffff
52 #define	ISCSI_UNSPEC_TSIH	0
53 
54 /* Max targets per system */
55 #define	ISCSIT_MAX_TARGETS	1024
56 
57 /* Time in seconds to wait between calls to stmf_deregister_local_port */
58 #define	TGT_DEREG_RETRY_SECONDS	1
59 
60 #define	ISCSIT_GLOBAL_LOCK(rw) rw_enter(&iscsit_global.global_rwlock, (rw))
61 #define	ISCSIT_GLOBAL_UNLOCK() rw_exit(&iscsit_global.global_rwlock)
62 
63 /*
64  * Used for serial number arithmetic (RFC 1982)
65  */
66 #define	ISCSIT_SNA32_CHECK	0x80000000
67 
68 typedef struct {
69 	char		tpg_name[MAX_TPG_NAMELEN];
70 	kmutex_t	tpg_mutex;
71 	idm_refcnt_t	tpg_refcnt;
72 	int		tpg_online;
73 	avl_tree_t	tpg_portal_list;
74 	avl_node_t	tpg_global_ln;
75 	list_node_t	tpg_delete_ln;
76 } iscsit_tpg_t;
77 
78 #define	IS_DEFAULT_TPGT(TPGT) \
79 	(((TPGT) != NULL) && \
80 	    ((TPGT)->tpgt_tpg == iscsit_global.global_default_tpg))
81 
82 typedef struct {
83 	iscsit_tpg_t	*tpgt_tpg;
84 	idm_refcnt_t	tpgt_refcnt;
85 	avl_node_t	tpgt_tgt_ln;
86 	list_node_t	tpgt_delete_ln;
87 	uint16_t	tpgt_tag;
88 	boolean_t	tpgt_needs_tpg_offline;
89 } iscsit_tpgt_t;
90 
91 typedef struct {
92 	struct sockaddr_storage portal_addr;
93 	int			portal_online;
94 	idm_refcnt_t		portal_refcnt;
95 	avl_node_t		portal_tpg_ln;
96 	iscsit_tpg_t		*portal_tpg;
97 	idm_svc_t		*portal_svc;
98 	boolean_t		portal_default;
99 	void			*portal_isns;
100 } iscsit_portal_t;
101 
102 
103 /* Target states and events, update iscsit_ts_name table whenever modified */
104 typedef enum {
105 	TS_UNDEFINED = 0,
106 	TS_CREATED,
107 	TS_ONLINING,
108 	TS_ONLINE,
109 	TS_STMF_ONLINE,
110 	TS_DELETING_NEED_OFFLINE,
111 	TS_OFFLINING,
112 	TS_OFFLINE,
113 	TS_STMF_OFFLINE,
114 	TS_DELETING_STMF_DEREG,
115 	TS_DELETING_STMF_DEREG_FAIL,
116 	TS_DELETING,
117 	TS_MAX_STATE
118 } iscsit_tgt_state_t;
119 
120 #ifdef ISCSIT_TGT_SM_STRINGS
121 static const char *iscsit_ts_name[TS_MAX_STATE+1] = {
122 	"TS_UNDEFINED",
123 	"TS_CREATED",
124 	"TS_ONLINING",
125 	"TS_ONLINE",
126 	"TS_STMF_ONLINE",
127 	"TS_DELETING_NEED_OFFLINE",
128 	"TS_OFFLINING",
129 	"TS_OFFLINE",
130 	"TS_STMF_OFFLINE",
131 	"TS_DELETING_STMF_DEREG",
132 	"TS_DELETING_STMF_DEREG_FAIL",
133 	"TS_DELETING",
134 	"TS_MAX_STATE"
135 };
136 #endif
137 
138 typedef enum {
139 	TE_UNDEFINED = 0,
140 	TE_STMF_ONLINE_REQ,
141 	TE_ONLINE_SUCCESS,
142 	TE_ONLINE_FAIL,
143 	TE_STMF_ONLINE_COMPLETE_ACK,
144 	TE_STMF_OFFLINE_REQ,
145 	TE_OFFLINE_COMPLETE,
146 	TE_STMF_OFFLINE_COMPLETE_ACK,
147 	TE_DELETE,
148 	TE_STMF_DEREG_SUCCESS,
149 	TE_STMF_DEREG_FAIL,
150 	TE_STMF_DEREG_RETRY,
151 	TE_WAIT_REF_COMPLETE,
152 	TE_MAX_EVENT
153 } iscsit_tgt_event_t;
154 
155 #ifdef ISCSIT_TGT_SM_STRINGS
156 static const char *iscsit_te_name[TE_MAX_EVENT+1] = {
157 	"TE_UNDEFINED",
158 	"TE_STMF_ONLINE_REQ",
159 	"TE_ONLINE_SUCCESS",
160 	"TE_ONLINE_FAIL",
161 	"TE_STMF_ONLINE_COMPLETE_ACK",
162 	"TE_STMF_OFFLINE_REQ",
163 	"TE_OFFLINE_COMPLETE",
164 	"TE_STMF_OFFLINE_COMPLETE_ACK",
165 	"TE_DELETE",
166 	"TE_STMF_DEREG_SUCCESS",
167 	"TE_STMF_DEREG_FAIL",
168 	"TE_STMF_DEREG_RETRY",
169 	"TE_WAIT_REF_COMPLETE",
170 	"TE_MAX_EVENT"
171 };
172 #endif
173 
174 typedef struct {
175 	char			*target_name;
176 	nvlist_t		*target_props;
177 	kmutex_t		target_mutex;
178 	idm_refcnt_t		target_refcnt;
179 	idm_refcnt_t		target_sess_refcnt;
180 	avl_tree_t		target_tpgt_list;
181 	avl_tree_t		target_sess_list;
182 	avl_node_t		target_global_ln;
183 	avl_node_t		target_global_deleted_ln;
184 	/* STMF lport == iSCSI target */
185 	scsi_devid_desc_t	*target_devid;
186 	stmf_local_port_t	*target_stmf_lport;
187 	uint8_t			target_stmf_lport_registered;
188 
189 	/* Target state */
190 	boolean_t		target_sm_busy;
191 	boolean_t		target_deleting;
192 	iscsit_tgt_state_t	target_state;
193 	iscsit_tgt_state_t	target_last_state;
194 	sm_audit_buf_t		target_state_audit;
195 	list_t			target_events;
196 	uint64_t		target_generation;
197 } iscsit_tgt_t;
198 
199 typedef struct {
200 	char			ini_name[MAX_ISCSI_NODENAMELEN];
201 	nvlist_t		*ini_props;
202 	avl_node_t		ini_global_ln;
203 } iscsit_ini_t;
204 
205 /*
206  * iSCSI Auth Information
207  */
208 typedef struct conn_auth {
209 	char			ca_tgt_chapuser[iscsitAuthStringMaxLength];
210 	uint8_t			ca_tgt_chapsecret[iscsitAuthStringMaxLength];
211 	int			ca_tgt_chapsecretlen;
212 
213 	char			ca_ini_chapuser[iscsitAuthStringMaxLength];
214 	uint8_t			ca_ini_chapsecret[iscsitAuthStringMaxLength];
215 	int			ca_ini_chapsecretlen;
216 
217 	/* RADIUS authentication information   	*/
218 	boolean_t		ca_use_radius;
219 	struct sockaddr_storage	ca_radius_server;
220 	uint8_t			ca_radius_secret[iscsitAuthStringMaxLength];
221 	int			ca_radius_secretlen;
222 
223 	/* authentication method list */
224 	iscsit_auth_method_t	ca_method_valid_list[iscsitAuthMethodMaxCount];
225 
226 	/* Target alias */
227 	char			ca_tgt_alias[MAX_ISCSI_NODENAMELEN];
228 } conn_auth_t;
229 
230 /*
231  * We have three state machines (so far) between the IDM connection state
232  * machine, the session state machine, and the login state machine.  All
233  * of these states have some concept of "full feature mode".  It's going
234  * to be obnoxious if we use a mixture of these "ffp" representations
235  * since it will be difficult to ensure the three state machines
236  * transition at exactly the same time.  We should drive decisions that
237  * depend on FFP from the IDM state machine which is actually snooping
238  * the iSCSI PDU's and will always transition at the correct time.
239  *
240  * A consequence of this approach is that there is a window just after
241  * login completes where we may get a SCSI request but the session
242  * or login state machine has not quite transitioned to "FFP".  Whether
243  * this is a problem depends on how we use those state machines.  This
244  * is what we should use them for:
245  *
246  * IDM Connection state machine - Decisions related to command processing
247  * including whether a connection is in FFP
248  *
249  * Session state machine - Summarize the state of all available connections
250  * for the purposes of ERL1, ERL2 and MC/S.  A session in LOGGED_IN state
251  * should always have at least one FFP connection but there may be a brief
252  * window where a session in ACTIVE might have one or more FFP connections
253  * even though ACTIVE is not strictly an FFP state according to the RFC.
254  *
255  * Login state machine -- drive the login process, collect negotiated
256  * parameters.  Another side effect of this approach is that we may get
257  * the "notify ffp" callback from the IDM connection state machine before
258  * the login state machine has actually transitioned to FFP state.
259  */
260 
261 struct iscsit_conn_s;
262 
263 /* Update iscsit_ss_name table whenever session states are modified */
264 typedef enum {
265 	SS_UNDEFINED = 0,
266 	SS_Q1_FREE,
267 	SS_Q2_ACTIVE,
268 	SS_Q3_LOGGED_IN,
269 	SS_Q4_FAILED,
270 	SS_Q5_CONTINUE,
271 	SS_Q6_DONE,
272 	SS_Q7_ERROR,
273 	/* Add new session states above SS_MAX_STATE */
274 	SS_MAX_STATE
275 } iscsit_session_state_t;
276 
277 #ifdef ISCSIT_SESS_SM_STRINGS
278 /* An array of state text values, for use in logging state transitions */
279 static const char *iscsit_ss_name[SS_MAX_STATE+1] = {
280 	"SS_UNDEFINED",
281 	"SS_Q1_FREE",
282 	"SS_Q2_ACTIVE",
283 	"SS_Q3_LOGGED_IN",
284 	"SS_Q4_FAILED",
285 	"SS_Q5_CONTINUE",
286 	"SS_Q6_DONE",
287 	"SS_Q7_ERROR",
288 	"SS_MAX_STATE"
289 };
290 #endif
291 
292 /* Update iscsit_se_name table whenever session events are modified */
293 typedef enum {
294 	SE_UNDEFINED = 0,
295 	SE_CONN_IN_LOGIN,	/* From login state machine */
296 	SE_CONN_LOGGED_IN,	/* FFP enabled client notification */
297 	SE_CONN_FFP_FAIL,	/* FFP disabled client notification */
298 	SE_CONN_FFP_DISABLE,	/* FFP disabled client notification */
299 	SE_CONN_FAIL,		/* Conn destroy client notification */
300 	SE_SESSION_CLOSE,	/* FFP disabled client notification */
301 	SE_SESSION_REINSTATE,	/* From login state machine */
302 	SE_SESSION_TIMEOUT,	/* Internal */
303 	SE_SESSION_CONTINUE,	/* From login state machine */
304 	SE_SESSION_CONTINUE_FAIL, /* From login state machine? */
305 	/* Add new events above SE_MAX_EVENT */
306 	SE_MAX_EVENT
307 } iscsit_session_event_t;
308 
309 #ifdef ISCSIT_SESS_SM_STRINGS
310 /* An array of event text values, for use in logging events */
311 static const char *iscsit_se_name[SE_MAX_EVENT+1] = {
312 	"SE_UNDEFINED",
313 	"SE_CONN_IN_LOGIN",
314 	"SE_CONN_LOGGED_IN",
315 	"SE_CONN_FFP_FAIL",
316 	"SE_CONN_FFP_DISABLE",
317 	"SE_CONN_FAIL",
318 	"SE_SESSION_CLOSE",
319 	"SE_SESSION_REINSTATE",
320 	"SE_SESSION_TIMEOUT",
321 	"SE_SESSION_CONTINUE",
322 	"SE_SESSION_CONTINUE_FAIL",
323 	"SE_MAX_EVENT"
324 };
325 #endif
326 
327 /*
328  * Set in ist_tgt after iscsit_tgt_unbind_sess to differentiate an unbound
329  * session from a discovery session.
330  */
331 #define	SESS_UNBOUND_FROM_TGT	-1
332 
333 typedef struct {
334 	stmf_scsi_session_t	*ist_stmf_sess;
335 	stmf_local_port_t	*ist_lport;
336 	iscsit_tgt_t		*ist_tgt;
337 	idm_refcnt_t		ist_refcnt;
338 	kmem_cache_t		*ist_task_cache;
339 	krwlock_t		ist_sn_rwlock;
340 	kmutex_t		ist_mutex;
341 	kcondvar_t		ist_cv;
342 	iscsit_session_state_t	ist_state;
343 	iscsit_session_state_t	ist_last_state;
344 	sm_audit_buf_t		ist_state_audit;
345 	boolean_t		ist_sm_busy;
346 	boolean_t		ist_sm_complete;
347 	boolean_t		ist_admin_close;
348 	list_t			ist_events;
349 	int			ist_conn_count;
350 	int			ist_ffp_conn_count;
351 	struct iscsit_conn_s	*ist_failed_conn;
352 	timeout_id_t		ist_state_timeout;
353 	list_t			ist_conn_list;
354 	avl_node_t		ist_tgt_ln;
355 	char			*ist_initiator_name;
356 	char			*ist_initiator_alias;
357 	char			*ist_target_name;
358 	char			*ist_target_alias;
359 	uint8_t			ist_isid[ISCSI_ISID_LEN];
360 	uint16_t		ist_tsih;
361 	uint16_t		ist_tpgt_tag;
362 	uint32_t		ist_expcmdsn;
363 	uint32_t		ist_maxcmdsn;
364 	avl_tree_t		ist_task_list;
365 } iscsit_sess_t;
366 
367 /* Update iscsit_ils_name table whenever login states are modified */
368 typedef enum {
369 	ILS_UNDEFINED = 0,
370 	ILS_LOGIN_INIT,
371 	ILS_LOGIN_WAITING,	/* Waiting for more login PDU's */
372 	ILS_LOGIN_PROCESSING,	/* Processing login request */
373 	ILS_LOGIN_RESPONDING,	/* Sending login response */
374 	ILS_LOGIN_RESPONDED,	/* Sent login response (no trans. to FFP) */
375 	ILS_LOGIN_FFP,		/* Sending last login PDU for final response */
376 	ILS_LOGIN_DONE,		/* Last login PDU sent (so we can free it) */
377 	ILS_LOGIN_ERROR,	/* Login error, login failed */
378 	/* Add new login states above ILS_MAX_STATE */
379 	ILS_MAX_STATE
380 } iscsit_login_state_t;
381 
382 #ifdef ISCSIT_LOGIN_SM_STRINGS
383 /* An array of login state text values, for use in logging login progress */
384 static const char *iscsit_ils_name[ILS_MAX_STATE+1] = {
385 	"ILS_UNDEFINED",
386 	"ILS_LOGIN_INIT",
387 	"ILS_LOGIN_WAITING",
388 	"ILS_LOGIN_PROCESSING",
389 	"ILS_LOGIN_RESPONDING",
390 	"ILS_LOGIN_RESPONDED",
391 	"ILS_LOGIN_FFP",
392 	"ILS_LOGIN_DONE",
393 	"ILS_LOGIN_ERROR",
394 	"ILS_MAX_STATE"
395 };
396 #endif
397 
398 /* Update iscsit_ile_name table whenever login events are modified */
399 typedef enum {
400 	ILE_UNDEFINED = 0,
401 	ILE_LOGIN_RCV,
402 	ILE_LOGIN_RESP_READY,
403 	ILE_LOGIN_FFP,
404 	ILE_LOGIN_RESP_COMPLETE,
405 	ILE_LOGIN_ERROR,
406 	ILE_LOGIN_CONN_ERROR,
407 	/* Add new login events above ILE_MAX_EVENT */
408 	ILE_MAX_EVENT
409 } iscsit_login_event_t;
410 
411 #ifdef ISCSIT_LOGIN_SM_STRINGS
412 /* An array of login event text values, for use in logging login events */
413 static const char *iscsit_ile_name[ILE_MAX_EVENT+1] = {
414 	"ILE_UNDEFINED",
415 	"ILE_LOGIN_RCV",
416 	"ILE_LOGIN_RESP_READY",
417 	"ILE_LOGIN_FFP",
418 	"ILE_LOGIN_RESP_COMPLETE",
419 	"ILE_LOGIN_ERROR",
420 	"ILE_LOGIN_CONN_ERROR",
421 	"ILE_MAX_EVENT"
422 };
423 #endif
424 
425 typedef struct {
426 	uint32_t		op_initial_params_set:1,
427 				op_discovery_session:1,
428 				op_initial_r2t:1,
429 				op_immed_data:1,
430 				op_data_pdu_in_order:1,
431 				op_data_sequence_in_order:1;
432 	uint64_t		op_max_connections;
433 	uint64_t		op_max_recv_data_segment_length;
434 	uint64_t		op_max_burst_length;
435 	uint64_t		op_first_burst_length;
436 	uint64_t		op_default_time_2_wait;
437 	uint64_t		op_default_time_2_retain;
438 	uint64_t		op_max_outstanding_r2t;
439 	uint64_t		op_error_recovery_level;
440 } iscsit_op_params_t;
441 
442 typedef struct {
443 	iscsit_login_state_t 	icl_login_state;
444 	iscsit_login_state_t 	icl_login_last_state;
445 	sm_audit_buf_t		icl_state_audit;
446 	boolean_t		icl_busy;
447 	boolean_t		icl_login_complete;
448 	kmutex_t		icl_mutex;
449 	uint32_t		icl_login_itt;
450 	uint8_t			icl_login_csg;
451 	uint8_t			icl_login_nsg;
452 	boolean_t		icl_login_transit;
453 	conn_auth_t		icl_auth;
454 	iscsit_auth_client_t	icl_auth_client;
455 	int			icl_auth_pass;
456 	list_t			icl_login_events;
457 	list_t			icl_pdu_list;
458 	uint16_t		icl_tsih;
459 	uint8_t			icl_isid[ISCSI_ISID_LEN];
460 	uint32_t		icl_cmdsn;
461 	uint16_t		icl_tpgt_tag;
462 	char			*icl_target_name;
463 	char			*icl_target_alias;
464 	char			*icl_initiator_name;
465 	char			*icl_login_resp_buf;
466 	void			*icl_login_resp_itb; /* mult-pdu idm buf */
467 	int			icl_login_resp_len; /* For kmem_free */
468 	int			icl_login_resp_valid_len;
469 	uint8_t			icl_login_resp_err_class;
470 	uint8_t			icl_login_resp_err_detail;
471 	iscsi_login_rsp_hdr_t	*icl_login_resp_tmpl;
472 	idm_pdu_t		*icl_login_resp;
473 	nvlist_t		*icl_request_nvlist;
474 	nvlist_t		*icl_response_nvlist;
475 	nvlist_t		*icl_negotiated_values;
476 } iscsit_conn_login_t;
477 
478 #define	SET_LOGIN_ERROR(SLE_ICT, SLE_CLASS, SLE_DETAIL) \
479 	(SLE_ICT)->ict_login_sm.icl_login_resp_err_class = (SLE_CLASS); \
480 	(SLE_ICT)->ict_login_sm.icl_login_resp_err_detail = (SLE_DETAIL);
481 
482 typedef struct iscsit_conn_s {
483 	idm_conn_t		*ict_ic;
484 	iscsit_sess_t		*ict_sess;
485 	kmutex_t		ict_mutex;
486 	idm_refcnt_t		ict_refcnt;
487 	idm_refcnt_t		ict_dispatch_refcnt;
488 	list_node_t		ict_sess_ln;
489 	iscsit_conn_login_t	ict_login_sm;
490 	iscsit_op_params_t	ict_op;
491 	uint16_t		ict_cid;
492 	uint32_t		ict_statsn;
493 	uint32_t		ict_keepalive_ttt;
494 	struct iscsit_conn_s	*ict_reinstate_conn;
495 	uint32_t		ict_reinstating:1,
496 				ict_lost:1,
497 				ict_destroyed:1;
498 } iscsit_conn_t;
499 
500 #define	ICT_FLAGS_DISCOVERY	0x00000001
501 
502 typedef struct {
503 	idm_buf_t		*ibuf_idm_buf;
504 	stmf_data_buf_t		*ibuf_stmf_buf;
505 	idm_pdu_t		*ibuf_immed_data_pdu;
506 	boolean_t		ibuf_is_immed;
507 } iscsit_buf_t;
508 
509 typedef struct {
510 	scsi_task_t		*it_stmf_task;
511 	idm_task_t		*it_idm_task;
512 	iscsit_buf_t		*it_immed_data;
513 	iscsit_conn_t		*it_ict;
514 	kmutex_t		it_mutex;
515 	idm_pdu_t		*it_tm_pdu;
516 	uint32_t		it_stmf_abort:1,
517 				it_aborted:1,
518 				it_active:1,
519 				it_tm_task:1,
520 				it_tm_responded:1;
521 	uint32_t		it_cmdsn;
522 	uint32_t		it_itt;
523 	uint32_t		it_ttt;
524 	avl_node_t		it_sess_ln;
525 } iscsit_task_t;
526 
527 typedef struct iscsit_isns_cfg {
528 	kmutex_t		isns_mutex;
529 	boolean_t		isns_state;
530 	list_t			isns_svrs;
531 } iscsit_isns_cfg_t;
532 
533 /*
534  * State values for the iscsit service
535  */
536 typedef enum {
537 	ISE_UNDEFINED = 0,
538 	ISE_DETACHED,
539 	ISE_DISABLED,
540 	ISE_ENABLING,
541 	ISE_ENABLED,
542 	ISE_BUSY,
543 	ISE_DISABLING
544 } iscsit_service_enabled_t;
545 
546 
547 typedef struct {
548 	iscsit_service_enabled_t	global_svc_state;
549 	dev_info_t			*global_dip;
550 	ldi_ident_t			global_li;
551 	nvlist_t			*global_props;
552 	stmf_port_provider_t		*global_pp;
553 	stmf_dbuf_store_t		*global_dbuf_store;
554 	taskq_t				*global_dispatch_taskq;
555 	idm_refcnt_t			global_refcnt;
556 	avl_tree_t			global_discovery_sessions;
557 	avl_tree_t			global_target_list;
558 	list_t				global_deleted_target_list;
559 	avl_tree_t			global_tpg_list;
560 	avl_tree_t			global_ini_list;
561 	iscsit_tpg_t			*global_default_tpg;
562 	vmem_t				*global_tsih_pool;
563 	iscsit_isns_cfg_t		global_isns_cfg;
564 	iscsi_radius_props_t		global_radius_server;
565 	krwlock_t			global_rwlock;
566 } iscsit_global_t;
567 
568 extern iscsit_global_t iscsit_global;
569 
570 void
571 iscsit_global_hold();
572 
573 void
574 iscsit_global_rele();
575 
576 void
577 iscsit_global_wait_ref();
578 
579 idm_status_t
580 iscsit_login_sm_init(iscsit_conn_t *ict);
581 
582 void
583 iscsit_login_sm_fini(iscsit_conn_t *ict);
584 
585 void
586 iscsit_login_sm_event(iscsit_conn_t *ic, iscsit_login_event_t event,
587     idm_pdu_t *pdu);
588 
589 void
590 iscsit_login_sm_event_locked(iscsit_conn_t *ic, iscsit_login_event_t event,
591     idm_pdu_t *pdu);
592 
593 void
594 iscsit_send_async_event(iscsit_conn_t *ict, uint8_t async_event);
595 
596 void
597 iscsit_pdu_tx(idm_pdu_t *pdu);
598 
599 /*
600  * IDM conn ops
601  */
602 
603 idm_rx_pdu_cb_t		iscsit_op_scsi_cmd;
604 idm_rx_pdu_cb_t		iscsit_rx_pdu;
605 idm_rx_pdu_error_cb_t	iscsit_rx_pdu_error;
606 idm_task_cb_t		iscsit_task_aborted;
607 idm_client_notify_cb_t	iscsit_client_notify;
608 idm_build_hdr_cb_t	iscsit_build_hdr;
609 idm_keepalive_cb_t	iscsit_keepalive;
610 
611 /*
612  * lport entry points
613  */
614 stmf_status_t
615 iscsit_xfer_scsi_data(scsi_task_t *task, stmf_data_buf_t *dbuf,
616     uint32_t ioflags);
617 
618 stmf_status_t
619 iscsit_send_scsi_status(scsi_task_t *task, uint32_t ioflags);
620 
621 void
622 iscsit_lport_task_free(scsi_task_t *task);
623 
624 stmf_status_t
625 iscsit_abort(stmf_local_port_t *lport, int abort_cmd, void *arg,
626     uint32_t flags);
627 
628 void
629 iscsit_ctl(stmf_local_port_t *lport, int cmd, void *arg);
630 
631 /*
632  * Connection functions
633  */
634 idm_status_t
635 iscsit_conn_reinstate(iscsit_conn_t *existing_ict, iscsit_conn_t *ict);
636 
637 void
638 iscsit_conn_destroy_done(iscsit_conn_t *ict);
639 
640 void
641 iscsit_conn_set_auth(iscsit_conn_t *ict);
642 
643 void
644 iscsit_conn_hold(iscsit_conn_t *ict);
645 
646 void
647 iscsit_conn_rele(iscsit_conn_t *ict);
648 
649 /*
650  * Session functions
651  */
652 int
653 iscsit_sess_avl_compare(const void *void_sess1, const void *void_sess2);
654 
655 iscsit_sess_t *
656 iscsit_sess_create(iscsit_tgt_t *tgt, iscsit_conn_t *ict,
657     uint32_t cmdsn, uint8_t *isid, uint16_t tag,
658     char *initiator_name, char *target_name,
659     uint8_t *error_class, uint8_t *error_detail);
660 
661 void
662 iscsit_sess_destroy(iscsit_sess_t *ist);
663 
664 void
665 iscsit_sess_hold(iscsit_sess_t *ist);
666 
667 void
668 iscsit_sess_rele(iscsit_sess_t *ist);
669 
670 iscsit_conn_t *
671 iscsit_sess_lookup_conn(iscsit_sess_t *ist, uint16_t cid);
672 
673 void
674 iscsit_sess_bind_conn(iscsit_sess_t *ist, iscsit_conn_t *ict);
675 
676 void
677 iscsit_sess_unbind_conn(iscsit_sess_t *ist, iscsit_conn_t *ict);
678 
679 void
680 iscsit_sess_close(iscsit_sess_t *ist);
681 
682 iscsit_sess_t *
683 iscsit_sess_reinstate(iscsit_tgt_t *tgt, iscsit_sess_t *ist, iscsit_conn_t *ict,
684     uint8_t *error_class, uint8_t *error_detail);
685 
686 void
687 iscsit_sess_sm_event(iscsit_sess_t *ist, iscsit_session_event_t event,
688     iscsit_conn_t *ict);
689 
690 /*
691  * Target, TPGT, TPGT and portal functions
692  */
693 
694 void
695 iscsit_tgt_sm_event(iscsit_tgt_t *tgt, iscsit_tgt_event_t event);
696 
697 void
698 tgt_sm_event_locked(iscsit_tgt_t *tgt, iscsit_tgt_event_t event);
699 
700 it_cfg_status_t
701 iscsit_config_merge_tgt(it_config_t *cfg);
702 
703 void
704 iscsit_config_destroy_tgts(list_t *tgt_del_list);
705 
706 void
707 iscsit_config_destroy_tpgts(list_t *tpgt_del_list);
708 
709 iscsit_tgt_t *
710 iscsit_tgt_lookup(char *target_name);
711 
712 iscsit_tgt_t *
713 iscsit_tgt_lookup_locked(char *target_name);
714 
715 int
716 iscsit_tgt_avl_compare(const void *void_tgt1, const void *void_tgt2);
717 
718 int
719 iscsit_tpgt_avl_compare(const void *void_tpgt1, const void *void_tpgt2);
720 
721 void
722 iscsit_tgt_hold(iscsit_tgt_t *tgt);
723 
724 void
725 iscsit_tgt_rele(iscsit_tgt_t *tgt);
726 
727 iscsit_tpgt_t *
728 iscsit_tgt_lookup_tpgt(iscsit_tgt_t *tgt, uint16_t tag);
729 
730 void
731 iscsit_tpgt_hold(iscsit_tpgt_t *tpgt);
732 
733 void
734 iscsit_tpgt_rele(iscsit_tpgt_t *tpgt);
735 
736 iscsit_portal_t *
737 iscsit_tgt_lookup_portal(iscsit_tgt_t *tgt, struct sockaddr_storage *sa,
738     iscsit_tpgt_t **output_tpgt);
739 
740 iscsit_sess_t *
741 iscsit_tgt_lookup_sess(iscsit_tgt_t *tgt, char *initiator_name,
742     uint8_t *isid, uint16_t tsih, uint16_t tag);
743 
744 void
745 iscsit_tgt_bind_sess(iscsit_tgt_t *tgt, iscsit_sess_t *sess);
746 
747 void
748 iscsit_tgt_unbind_sess(iscsit_tgt_t *tgt, iscsit_sess_t *sess);
749 
750 it_cfg_status_t
751 iscsit_config_merge_tpg(it_config_t *cfg, list_t *tpg_del_list);
752 
753 void
754 iscsit_config_destroy_tpgs(list_t *tpg_del_list);
755 
756 iscsit_tpg_t *
757 iscsit_tpg_lookup(char *tpg_name);
758 
759 int
760 iscsit_tpg_avl_compare(const void *void_tpg1, const void *void_tpg2);
761 
762 void
763 iscsit_tpg_hold(iscsit_tpg_t *tpg);
764 
765 void
766 iscsit_tpg_rele(iscsit_tpg_t *tpg);
767 
768 iscsit_tpg_t *
769 iscsit_tpg_createdefault();
770 
771 void
772 iscsit_tpg_destroydefault(iscsit_tpg_t *tpg);
773 
774 idm_status_t
775 iscsit_tpg_online(iscsit_tpg_t *tpg);
776 
777 void
778 iscsit_tpg_offline(iscsit_tpg_t *tpg);
779 
780 iscsit_portal_t *
781 iscsit_tpg_portal_lookup(iscsit_tpg_t *tpg, struct sockaddr_storage *sa);
782 
783 void
784 iscsit_portal_hold(iscsit_portal_t *portal);
785 
786 void
787 iscsit_portal_rele(iscsit_portal_t *portal);
788 
789 it_cfg_status_t
790 iscsit_config_merge_ini(it_config_t *cfg);
791 
792 int
793 iscsit_ini_avl_compare(const void *void_ini1, const void *void_ini2);
794 
795 iscsit_ini_t *
796 iscsit_ini_lookup_locked(char *ini_name);
797 
798 int
799 iscsit_portal_avl_compare(const void *void_portal1, const void *void_portal2);
800 
801 int
802 iscsit_verify_chap_resp(iscsit_conn_login_t *lsm,
803     unsigned int chap_i, uchar_t *chap_c, unsigned int challenge_len,
804     uchar_t *chap_r, unsigned int resp_len);
805 
806 #endif /* _ISCSIT_H_ */
807