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 #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 	uint64_t		op_max_connections;
434 	uint64_t		op_max_recv_data_segment_length;
435 	uint64_t		op_max_burst_length;
436 	uint64_t		op_first_burst_length;
437 	uint64_t		op_default_time_2_wait;
438 	uint64_t		op_default_time_2_retain;
439 	uint64_t		op_max_outstanding_r2t;
440 	uint64_t		op_error_recovery_level;
441 } iscsit_op_params_t;
442 
443 typedef struct {
444 	iscsit_login_state_t 	icl_login_state;
445 	iscsit_login_state_t 	icl_login_last_state;
446 	sm_audit_buf_t		icl_state_audit;
447 	boolean_t		icl_busy;
448 	boolean_t		icl_login_complete;
449 	kmutex_t		icl_mutex;
450 	uint32_t		icl_login_itt;
451 	uint8_t			icl_login_csg;
452 	uint8_t			icl_login_nsg;
453 	boolean_t		icl_login_transit;
454 	conn_auth_t		icl_auth;
455 	iscsit_auth_client_t	icl_auth_client;
456 	int			icl_auth_pass;
457 	list_t			icl_login_events;
458 	list_t			icl_pdu_list;
459 	uint16_t		icl_tsih;
460 	uint8_t			icl_isid[ISCSI_ISID_LEN];
461 	uint32_t		icl_cmdsn;
462 	uint16_t		icl_tpgt_tag;
463 	char			*icl_target_name;
464 	char			*icl_target_alias;
465 	char			*icl_initiator_name;
466 	char			*icl_login_resp_buf;
467 	void			*icl_login_resp_itb; /* mult-pdu idm buf */
468 	int			icl_login_resp_len; /* For kmem_free */
469 	int			icl_login_resp_valid_len;
470 	uint8_t			icl_login_resp_err_class;
471 	uint8_t			icl_login_resp_err_detail;
472 	iscsi_login_rsp_hdr_t	*icl_login_resp_tmpl;
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 	/*
499 	 * Parameters for processing text commands
500 	 */
501 	char			*ict_text_rsp_buf;
502 	uint32_t		ict_text_rsp_len;
503 	uint32_t		ict_text_rsp_valid_len;
504 	uint32_t		ict_text_rsp_off;
505 	uint32_t		ict_text_req_itt;	/* from initiator */
506 	uint32_t		ict_text_rsp_ttt;
507 } iscsit_conn_t;
508 
509 #define	ICT_FLAGS_DISCOVERY	0x00000001
510 
511 typedef struct {
512 	idm_buf_t		*ibuf_idm_buf;
513 	stmf_data_buf_t		*ibuf_stmf_buf;
514 	idm_pdu_t		*ibuf_immed_data_pdu;
515 	boolean_t		ibuf_is_immed;
516 } iscsit_buf_t;
517 
518 typedef struct {
519 	scsi_task_t		*it_stmf_task;
520 	idm_task_t		*it_idm_task;
521 	iscsit_buf_t		*it_immed_data;
522 	iscsit_conn_t		*it_ict;
523 	kmutex_t		it_mutex;
524 	idm_pdu_t		*it_tm_pdu;
525 	uint32_t		it_stmf_abort:1,
526 				it_aborted:1,
527 				it_active:1,
528 				it_tm_task:1,
529 				it_tm_responded:1;
530 	uint32_t		it_cmdsn;
531 	uint32_t		it_itt;
532 	uint32_t		it_ttt;
533 	avl_node_t		it_sess_ln;
534 } iscsit_task_t;
535 
536 typedef struct iscsit_isns_cfg {
537 	kmutex_t		isns_mutex;
538 	boolean_t		isns_state;
539 	list_t			isns_svrs;
540 } iscsit_isns_cfg_t;
541 
542 /*
543  * State values for the iscsit service
544  */
545 typedef enum {
546 	ISE_UNDEFINED = 0,
547 	ISE_DETACHED,
548 	ISE_DISABLED,
549 	ISE_ENABLING,
550 	ISE_ENABLED,
551 	ISE_BUSY,
552 	ISE_DISABLING
553 } iscsit_service_enabled_t;
554 
555 
556 typedef struct {
557 	iscsit_service_enabled_t	global_svc_state;
558 	dev_info_t			*global_dip;
559 	ldi_ident_t			global_li;
560 	nvlist_t			*global_props;
561 	stmf_port_provider_t		*global_pp;
562 	stmf_dbuf_store_t		*global_dbuf_store;
563 	taskq_t				*global_dispatch_taskq;
564 	idm_refcnt_t			global_refcnt;
565 	avl_tree_t			global_discovery_sessions;
566 	avl_tree_t			global_target_list;
567 	list_t				global_deleted_target_list;
568 	avl_tree_t			global_tpg_list;
569 	avl_tree_t			global_ini_list;
570 	iscsit_tpg_t			*global_default_tpg;
571 	vmem_t				*global_tsih_pool;
572 	iscsit_isns_cfg_t		global_isns_cfg;
573 	iscsi_radius_props_t		global_radius_server;
574 	krwlock_t			global_rwlock;
575 } iscsit_global_t;
576 
577 extern iscsit_global_t iscsit_global;
578 
579 void
580 iscsit_global_hold();
581 
582 void
583 iscsit_global_rele();
584 
585 void
586 iscsit_global_wait_ref();
587 
588 idm_status_t
589 iscsit_login_sm_init(iscsit_conn_t *ict);
590 
591 void
592 iscsit_login_sm_fini(iscsit_conn_t *ict);
593 
594 void
595 iscsit_login_sm_event(iscsit_conn_t *ic, iscsit_login_event_t event,
596     idm_pdu_t *pdu);
597 
598 void
599 iscsit_login_sm_event_locked(iscsit_conn_t *ic, iscsit_login_event_t event,
600     idm_pdu_t *pdu);
601 
602 void
603 iscsit_send_async_event(iscsit_conn_t *ict, uint8_t async_event);
604 
605 void
606 iscsit_pdu_tx(idm_pdu_t *pdu);
607 
608 void
609 iscsit_send_reject(iscsit_conn_t *ict, idm_pdu_t *rejected_pdu, uint8_t reason);
610 
611 void
612 iscsit_text_cmd_fini(iscsit_conn_t *ict);
613 
614 /*
615  * IDM conn ops
616  */
617 
618 idm_rx_pdu_cb_t		iscsit_op_scsi_cmd;
619 idm_rx_pdu_cb_t		iscsit_rx_pdu;
620 idm_rx_pdu_error_cb_t	iscsit_rx_pdu_error;
621 idm_task_cb_t		iscsit_task_aborted;
622 idm_client_notify_cb_t	iscsit_client_notify;
623 idm_build_hdr_cb_t	iscsit_build_hdr;
624 idm_keepalive_cb_t	iscsit_keepalive;
625 
626 /*
627  * lport entry points
628  */
629 stmf_status_t
630 iscsit_xfer_scsi_data(scsi_task_t *task, stmf_data_buf_t *dbuf,
631     uint32_t ioflags);
632 
633 stmf_status_t
634 iscsit_send_scsi_status(scsi_task_t *task, uint32_t ioflags);
635 
636 void
637 iscsit_lport_task_free(scsi_task_t *task);
638 
639 stmf_status_t
640 iscsit_abort(stmf_local_port_t *lport, int abort_cmd, void *arg,
641     uint32_t flags);
642 
643 void
644 iscsit_ctl(stmf_local_port_t *lport, int cmd, void *arg);
645 
646 /*
647  * Connection functions
648  */
649 idm_status_t
650 iscsit_conn_reinstate(iscsit_conn_t *existing_ict, iscsit_conn_t *ict);
651 
652 void
653 iscsit_conn_destroy_done(iscsit_conn_t *ict);
654 
655 void
656 iscsit_conn_set_auth(iscsit_conn_t *ict);
657 
658 void
659 iscsit_conn_hold(iscsit_conn_t *ict);
660 
661 void
662 iscsit_conn_rele(iscsit_conn_t *ict);
663 
664 /*
665  * Session functions
666  */
667 int
668 iscsit_sess_avl_compare(const void *void_sess1, const void *void_sess2);
669 
670 iscsit_sess_t *
671 iscsit_sess_create(iscsit_tgt_t *tgt, iscsit_conn_t *ict,
672     uint32_t cmdsn, uint8_t *isid, uint16_t tag,
673     char *initiator_name, char *target_name,
674     uint8_t *error_class, uint8_t *error_detail);
675 
676 void
677 iscsit_sess_destroy(iscsit_sess_t *ist);
678 
679 void
680 iscsit_sess_hold(iscsit_sess_t *ist);
681 
682 void
683 iscsit_sess_rele(iscsit_sess_t *ist);
684 
685 iscsit_conn_t *
686 iscsit_sess_lookup_conn(iscsit_sess_t *ist, uint16_t cid);
687 
688 void
689 iscsit_sess_bind_conn(iscsit_sess_t *ist, iscsit_conn_t *ict);
690 
691 void
692 iscsit_sess_unbind_conn(iscsit_sess_t *ist, iscsit_conn_t *ict);
693 
694 void
695 iscsit_sess_close(iscsit_sess_t *ist);
696 
697 iscsit_sess_t *
698 iscsit_sess_reinstate(iscsit_tgt_t *tgt, iscsit_sess_t *ist, iscsit_conn_t *ict,
699     uint8_t *error_class, uint8_t *error_detail);
700 
701 void
702 iscsit_sess_sm_event(iscsit_sess_t *ist, iscsit_session_event_t event,
703     iscsit_conn_t *ict);
704 
705 /*
706  * Target, TPGT, TPGT and portal functions
707  */
708 
709 void
710 iscsit_tgt_sm_event(iscsit_tgt_t *tgt, iscsit_tgt_event_t event);
711 
712 void
713 tgt_sm_event_locked(iscsit_tgt_t *tgt, iscsit_tgt_event_t event);
714 
715 it_cfg_status_t
716 iscsit_config_merge_tgt(it_config_t *cfg);
717 
718 void
719 iscsit_config_destroy_tgts(list_t *tgt_del_list);
720 
721 void
722 iscsit_config_destroy_tpgts(list_t *tpgt_del_list);
723 
724 iscsit_tgt_t *
725 iscsit_tgt_lookup(char *target_name);
726 
727 iscsit_tgt_t *
728 iscsit_tgt_lookup_locked(char *target_name);
729 
730 int
731 iscsit_tgt_avl_compare(const void *void_tgt1, const void *void_tgt2);
732 
733 int
734 iscsit_tpgt_avl_compare(const void *void_tpgt1, const void *void_tpgt2);
735 
736 void
737 iscsit_tgt_hold(iscsit_tgt_t *tgt);
738 
739 void
740 iscsit_tgt_rele(iscsit_tgt_t *tgt);
741 
742 iscsit_tpgt_t *
743 iscsit_tgt_lookup_tpgt(iscsit_tgt_t *tgt, uint16_t tag);
744 
745 void
746 iscsit_tpgt_hold(iscsit_tpgt_t *tpgt);
747 
748 void
749 iscsit_tpgt_rele(iscsit_tpgt_t *tpgt);
750 
751 iscsit_portal_t *
752 iscsit_tgt_lookup_portal(iscsit_tgt_t *tgt, struct sockaddr_storage *sa,
753     iscsit_tpgt_t **output_tpgt);
754 
755 iscsit_sess_t *
756 iscsit_tgt_lookup_sess(iscsit_tgt_t *tgt, char *initiator_name,
757     uint8_t *isid, uint16_t tsih, uint16_t tag);
758 
759 void
760 iscsit_tgt_bind_sess(iscsit_tgt_t *tgt, iscsit_sess_t *sess);
761 
762 void
763 iscsit_tgt_unbind_sess(iscsit_tgt_t *tgt, iscsit_sess_t *sess);
764 
765 it_cfg_status_t
766 iscsit_config_merge_tpg(it_config_t *cfg, list_t *tpg_del_list);
767 
768 void
769 iscsit_config_destroy_tpgs(list_t *tpg_del_list);
770 
771 iscsit_tpg_t *
772 iscsit_tpg_lookup(char *tpg_name);
773 
774 int
775 iscsit_tpg_avl_compare(const void *void_tpg1, const void *void_tpg2);
776 
777 void
778 iscsit_tpg_hold(iscsit_tpg_t *tpg);
779 
780 void
781 iscsit_tpg_rele(iscsit_tpg_t *tpg);
782 
783 iscsit_tpg_t *
784 iscsit_tpg_createdefault();
785 
786 void
787 iscsit_tpg_destroydefault(iscsit_tpg_t *tpg);
788 
789 idm_status_t
790 iscsit_tpg_online(iscsit_tpg_t *tpg);
791 
792 void
793 iscsit_tpg_offline(iscsit_tpg_t *tpg);
794 
795 iscsit_portal_t *
796 iscsit_tpg_portal_lookup(iscsit_tpg_t *tpg, struct sockaddr_storage *sa);
797 
798 void
799 iscsit_portal_hold(iscsit_portal_t *portal);
800 
801 void
802 iscsit_portal_rele(iscsit_portal_t *portal);
803 
804 it_cfg_status_t
805 iscsit_config_merge_ini(it_config_t *cfg);
806 
807 int
808 iscsit_ini_avl_compare(const void *void_ini1, const void *void_ini2);
809 
810 iscsit_ini_t *
811 iscsit_ini_lookup_locked(char *ini_name);
812 
813 int
814 iscsit_portal_avl_compare(const void *void_portal1, const void *void_portal2);
815 
816 int
817 iscsit_verify_chap_resp(iscsit_conn_login_t *lsm,
818     unsigned int chap_i, uchar_t *chap_c, unsigned int challenge_len,
819     uchar_t *chap_r, unsigned int resp_len);
820 
821 #endif /* _ISCSIT_H_ */
822