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