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 
26 #ifndef _ISCSI_IF_H
27 #define	_ISCSI_IF_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #ifdef _KERNEL
34 #include <sys/types.h>
35 #include <sys/strsubr.h>	/* for prototype of kstrgetmsg */
36 #include <sys/socket.h>
37 #include <sys/socketvar.h>	/* for struct sonode */
38 #endif
39 #include <netinet/in.h>
40 #include <sys/scsi/impl/uscsi.h>
41 #include <sys/iscsi_protocol.h>
42 
43 /*
44  * Each of the top level structures have a version field as
45  * the first member. That version value will be set by the
46  * caller. The consumer of the structure will check to see
47  * if the version is correct.
48  */
49 #define	ISCSI_INTERFACE_VERSION			3
50 
51 /*
52  * Login parameter values are used instead of ascii text
53  * between the IMA plug-in and kernel.
54  */
55 #define	ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER	0x0000  /* bool */
56 #define	ISCSI_LOGIN_PARAM_IMMEDIATE_DATA		0x0001  /* bool */
57 #define	ISCSI_LOGIN_PARAM_INITIAL_R2T			0x0002  /* bool */
58 #define	ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER		0x0003  /* bool */
59 #define	ISCSI_LOGIN_PARAM_HEADER_DIGEST			0x0004	/* int */
60 #define	ISCSI_LOGIN_PARAM_DATA_DIGEST			0x0005	/* int */
61 #define	ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN		0x0006  /* int */
62 #define	ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT		0x0007  /* int */
63 #define	ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH	0x0008  /* int */
64 #define	ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH		0x0009  /* int */
65 #define	ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH		0x000A  /* int */
66 #define	ISCSI_LOGIN_PARAM_MAX_CONNECTIONS		0x000B  /* int */
67 #define	ISCSI_LOGIN_PARAM_OUTSTANDING_R2T		0x000C  /* int */
68 #define	ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL		0x000D  /* int */
69 /*
70  * number of login parameters - needs to be updated when new parameter added
71  */
72 #define	ISCSI_NUM_LOGIN_PARAM				0x000E
73 
74 /*
75  * Used internally by the persistent store code. Currently a bitmap is kept of
76  * which params are currently set. This allows for quick a look up instead of
77  * cycling through the possible entries. Using an unsigned int as the bitmap we
78  * can have parameter numbers up through 31. Since the current only has 22
79  * we're okay.
80  */
81 #define	ISCSI_LOGIN_PARAM_DB_ENTRY			0x0020
82 /*
83  * Special case. When this parameter value is set in iscsi_param_set_t
84  * the member s_value (type iscsi_param_set_t) is not used.
85  * The name field contains the InitiatorName for the system which
86  * should be used for all future sessions.
87  */
88 #define	ISCSI_LOGIN_PARAM_INITIATOR_NAME		0x0021
89 #define	ISCSI_LOGIN_PARAM_INITIATOR_ALIAS		0x0022
90 
91 #define	ISCSI_DEVCTL		"devctl"
92 #define	ISCSI_DRIVER_DEVCTL	"/devices/iscsi:" ISCSI_DEVCTL
93 
94 /*
95  * ioctls supported by the driver.
96  */
97 #define	ISCSI_IOCTL		(('i' << 24) | ('S' << 16) | ('C' << 8))
98 #define	ISCSI_CREATE_OID		(ISCSI_IOCTL | 2)
99 #define	ISCSI_LOGIN			(ISCSI_IOCTL | 3)
100 #define	ISCSI_LOGOUT			(ISCSI_IOCTL | 4)
101 #define	ISCSI_PARAM_GET			(ISCSI_IOCTL | 5)
102 #define	ISCSI_PARAM_SET			(ISCSI_IOCTL | 6)
103 #define	ISCSI_TARGET_PARAM_CLEAR	(ISCSI_IOCTL | 8)
104 #define	ISCSI_TARGET_OID_LIST_GET	(ISCSI_IOCTL | 9)
105 #define	ISCSI_TARGET_PROPS_GET		(ISCSI_IOCTL | 10)
106 #define	ISCSI_TARGET_PROPS_SET		(ISCSI_IOCTL | 11)
107 #define	ISCSI_TARGET_ADDRESS_GET	(ISCSI_IOCTL | 12)
108 #define	ISCSI_CHAP_SET			(ISCSI_IOCTL | 13)
109 #define	ISCSI_CHAP_GET			(ISCSI_IOCTL | 14)
110 #define	ISCSI_CHAP_CLEAR		(ISCSI_IOCTL | 15)
111 #define	ISCSI_STATIC_GET		(ISCSI_IOCTL | 16)
112 #define	ISCSI_STATIC_SET		(ISCSI_IOCTL | 17)
113 #define	ISCSI_STATIC_CLEAR		(ISCSI_IOCTL | 18)
114 #define	ISCSI_DISCOVERY_SET		(ISCSI_IOCTL | 19)
115 #define	ISCSI_DISCOVERY_GET		(ISCSI_IOCTL | 20)
116 #define	ISCSI_DISCOVERY_CLEAR		(ISCSI_IOCTL | 21)
117 #define	ISCSI_DISCOVERY_PROPS		(ISCSI_IOCTL | 22)
118 #define	ISCSI_DISCOVERY_ADDR_SET	(ISCSI_IOCTL | 23)
119 #define	ISCSI_DISCOVERY_ADDR_LIST_GET	(ISCSI_IOCTL | 24)
120 #define	ISCSI_DISCOVERY_ADDR_CLEAR	(ISCSI_IOCTL | 25)
121 #define	ISCSI_RADIUS_SET		(ISCSI_IOCTL | 26)
122 #define	ISCSI_RADIUS_GET		(ISCSI_IOCTL | 27)
123 #define	ISCSI_DB_RELOAD			(ISCSI_IOCTL | 28)
124 #define	ISCSI_LUN_OID_LIST_GET		(ISCSI_IOCTL | 29)
125 #define	ISCSI_LUN_PROPS_GET		(ISCSI_IOCTL | 30)
126 #define	ISCSI_CONN_OID_LIST_GET		(ISCSI_IOCTL | 31)
127 #define	ISCSI_CONN_PROPS_GET		(ISCSI_IOCTL | 32)
128 #define	ISCSI_USCSI			(ISCSI_IOCTL | 33)
129 #define	ISCSI_DOOR_HANDLE_SET		(ISCSI_IOCTL | 34)
130 #define	ISCSI_DISCOVERY_EVENTS		(ISCSI_IOCTL | 35)
131 #define	ISCSI_AUTH_SET			(ISCSI_IOCTL | 36)
132 #define	ISCSI_AUTH_GET			(ISCSI_IOCTL | 37)
133 #define	ISCSI_AUTH_CLEAR		(ISCSI_IOCTL | 38)
134 #define	ISCSI_SENDTGTS_GET		(ISCSI_IOCTL | 39)
135 #define	ISCSI_ISNS_SERVER_ADDR_SET	(ISCSI_IOCTL | 40)
136 #define	ISCSI_ISNS_SERVER_ADDR_LIST_GET	(ISCSI_IOCTL | 41)
137 #define	ISCSI_ISNS_SERVER_ADDR_CLEAR	(ISCSI_IOCTL | 42)
138 #define	ISCSI_ISNS_SERVER_GET		(ISCSI_IOCTL | 43)
139 #define	ISCSI_GET_CONFIG_SESSIONS	(ISCSI_IOCTL | 44)
140 #define	ISCSI_SET_CONFIG_SESSIONS	(ISCSI_IOCTL | 45)
141 #define	ISCSI_INIT_NODE_NAME_SET	(ISCSI_IOCTL | 46)
142 #define	ISCSI_IS_ACTIVE			(ISCSI_IOCTL | 47)
143 #define	ISCSI_BOOTPROP_GET		(ISCSI_IOCTL | 48)
144 #define	ISCSI_DB_DUMP			(ISCSI_IOCTL | 100) /* DBG */
145 
146 /*
147  * Misc. defines
148  */
149 #define	ISCSI_CHAP_NAME_LEN			512
150 #define	ISCSI_CHAP_SECRET_LEN			16
151 #define	ISCSI_TGT_OID_LIST			0x0001
152 #define	ISCSI_STATIC_TGT_OID_LIST		0x0002
153 #define	ISCSI_TGT_PARAM_OID_LIST		0x0004
154 #define	ISCSI_SESS_PARAM			0x0001
155 #define	ISCSI_CONN_PARAM			0x0002
156 
157 /* digest level defines */
158 #define	ISCSI_DIGEST_NONE		0
159 #define	ISCSI_DIGEST_CRC32C		1
160 #define	ISCSI_DIGEST_CRC32C_NONE	2 /* offer both, prefer CRC32C */
161 #define	ISCSI_DIGEST_NONE_CRC32C	3 /* offer both, prefer None */
162 
163 /*
164  * A last error associated with each target session is returned in the
165  * iscsi_target_t structure.
166  */
167 typedef enum iscsi_error {
168 	NoError, AuthenticationError, LoginParamError, ConnectionReset
169 } iscsi_error_t;
170 
171 /*
172  * The values associated with each enum is based on the IMA specification.
173  */
174 typedef enum	iSCSIDiscoveryMethod {
175 	iSCSIDiscoveryMethodUnknown	= 0,
176 	iSCSIDiscoveryMethodStatic	= 1,
177 	iSCSIDiscoveryMethodSLP		= 2,
178 	iSCSIDiscoveryMethodISNS	= 4,
179 	iSCSIDiscoveryMethodSendTargets	= 8,
180 	/*
181 	 * Since there is no specification about boot discovery method,
182 	 * we should leave a value gap in case of other discovery
183 	 * methods added.
184 	 */
185 	iSCSIDiscoveryMethodBoot	= 128
186 } iSCSIDiscoveryMethod_t;
187 #define	ISCSI_ALL_DISCOVERY_METHODS	(iSCSIDiscoveryMethodStatic |	\
188 					iSCSIDiscoveryMethodSLP |	\
189 					iSCSIDiscoveryMethodISNS |	\
190 					iSCSIDiscoveryMethodSendTargets)
191 
192 /*
193  * Before anything can be done to a target it must have an OID.
194  */
195 typedef struct iscsi_oid {
196 	uint32_t		o_vers;				/* In */
197 	uchar_t			o_name[ISCSI_MAX_NAME_LEN];	/* In */
198 	/*
199 	 * tpgt is only 16 bits per spec.  use 32 in ioctl to reduce
200 	 * packing issue.  Also -1 tpgt denotes default value.  iSCSI
201 	 * stack will detemermine tpgt during login.
202 	 */
203 	int			o_tpgt;				/* In */
204 	uint32_t		o_oid;				/* Out */
205 } iscsi_oid_t;
206 #define	ISCSI_OID_NOTSET	0
207 #define	ISCSI_INITIATOR_OID	1	/* Other OIDs follow > 1 */
208 #define	ISCSI_DEFAULT_TPGT	-1
209 
210 /*
211  * iSCSI Login Parameters - Reference iscsi draft for
212  * definitions of the below login params.
213  */
214 typedef struct iscsi_login_params {
215 	boolean_t	immediate_data;
216 	boolean_t	initial_r2t;
217 	int		first_burst_length;	/* range: 512 - 2**24-1 */
218 	int		max_burst_length;	/* range: 512 - 2**24-1 */
219 	boolean_t	data_pdu_in_order;
220 	boolean_t	data_sequence_in_order;
221 	int		default_time_to_wait;
222 	int		default_time_to_retain;
223 	int		header_digest;
224 	int		data_digest;
225 	int		max_recv_data_seg_len;	/* range: 512 - 2**24-1 */
226 	int		max_xmit_data_seg_len;	/* range: 512 - 2**24-1 */
227 	int		max_connections;
228 	int		max_outstanding_r2t;
229 	int		error_recovery_level;
230 	boolean_t	ifmarker;
231 	boolean_t	ofmarker;
232 } iscsi_login_params_t;
233 
234 /*
235  * Once parameters have been set via ISCSI_SET_PARAM the login is initiated
236  * by sending an ISCSI_LOGIN ioctl with the following structure filled in.
237  */
238 typedef struct entry {
239 	int			e_vers;
240 	uint32_t		e_oid;
241 	union {
242 		struct in_addr		u_in4;
243 		struct in6_addr		u_in6;
244 	} e_u;
245 	/*
246 	 * e_insize indicates which of the previous structs is valid.
247 	 */
248 	int			e_insize;
249 	int			e_port;
250 	int			e_tpgt;
251 	/* e_boot should be true if a boot session is created. */
252 	boolean_t		e_boot;
253 } entry_t;
254 
255 /*
256  * Used when setting or gettnig the Initiator Name or Alias.
257  */
258 typedef struct node_name {
259 	unsigned char		n_name[ISCSI_MAX_NAME_LEN];
260 	int			n_len;
261 } node_name_t;
262 
263 typedef struct	_iSCSIMinMaxValue {
264 	uint32_t		i_current,
265 				i_default,
266 				i_min,
267 				i_max,
268 				i_incr;
269 } iscsi_int_info_t;
270 
271 typedef struct	_iSCSIBoolValue {
272 	boolean_t		b_current,
273 				b_default;
274 } iscsi_bool_info_t;
275 
276 typedef struct	_iSCSIParamValueGet {
277 	boolean_t		v_valid,
278 				v_settable;
279 	iscsi_int_info_t	v_integer;
280 	iscsi_bool_info_t	v_bool;
281 	uchar_t			v_name[ISCSI_MAX_NAME_LEN];
282 } iscsi_get_value_t;
283 
284 typedef struct	_iSCSILoginParamGet {
285 	uint32_t		g_vers;				/* In */
286 	uint32_t		g_oid;				/* In */
287 	uint32_t		g_param;			/* Out */
288 	iscsi_get_value_t	g_value;			/* Out */
289 	uint32_t		g_conn_cid;			/* In */
290 
291 	/*
292 	 * To indicate whether session or connection related param is
293 	 * being requested.
294 	 */
295 	uint32_t		g_param_type;			/* In */
296 } iscsi_param_get_t;
297 
298 typedef struct	iscsi_set_value {
299 	uint32_t		v_integer;
300 	boolean_t		v_bool;
301 	uchar_t			v_name[ISCSI_MAX_NAME_LEN];
302 } iscsi_set_value_t;
303 
304 /*
305  * All of the members of this structure are set by the user agent and
306  * consumed by the driver.
307  */
308 typedef struct	iSCSILoginParamSet {
309 	uint32_t		s_vers,
310 				s_oid;
311 	uint32_t		s_param;
312 	iscsi_set_value_t	s_value;
313 } iscsi_param_set_t;
314 
315 /*
316  * Data in this structure is set by the user agent and consumed by
317  * the driver.
318  */
319 typedef struct chap_props {
320 	uint32_t		c_vers,
321 				c_retries,
322 				c_oid;
323 	unsigned char		c_user[128];
324 	uint32_t		c_user_len;
325 	unsigned char		c_secret[16];
326 	uint32_t		c_secret_len;
327 } iscsi_chap_props_t;
328 
329 typedef enum	authMethod {
330 	authMethodNone  = 0x00,
331 	authMethodCHAP  = 0x01,
332 	authMethodSRP   = 0x02,
333 	authMethodKRB5  = 0x04,
334 	authMethodSPKM1 = 0x08,
335 	authMethodSPKM2 = 0x10
336 } authMethod_t;
337 
338 /*
339  * Data in this structure is set by the user agent and consumed by
340  * the driver.
341  */
342 typedef struct auth_props {
343 	uint32_t a_vers;
344 	uint32_t a_oid;
345 	boolean_t a_bi_auth;
346 	authMethod_t a_auth_method;
347 } iscsi_auth_props_t;
348 
349 /*
350  * Data in this structure is set by the user agent and consumed by
351  * the driver.
352  */
353 #define	MAX_RAD_SHARED_SECRET_LEN 128
354 typedef struct radius_props {
355 	uint32_t		r_vers;
356 	uint32_t		r_oid;
357 	union {
358 		struct in_addr		u_in4;
359 		struct in6_addr		u_in6;
360 	} r_addr;
361 	/*
362 	 * r_insize indicates which of the previous structs is valid.
363 	 */
364 	int			r_insize;
365 
366 	uint32_t		r_port;
367 	uint8_t			r_shared_secret[MAX_RAD_SHARED_SECRET_LEN];
368 	boolean_t		r_radius_access;
369 	boolean_t		r_radius_config_valid;
370 	uint32_t		r_shared_secret_len;
371 } iscsi_radius_props_t;
372 
373 typedef struct	_IPAddress {
374 	union {
375 		struct in_addr	in4;
376 		struct in6_addr	in6;
377 	} i_addr;
378 	/* i_insize determines which is valid in the union above */
379 	int			i_insize;
380 } iscsi_ipaddr_t;
381 
382 typedef struct	_iSCSITargetAddressKey {
383 	iscsi_ipaddr_t		a_addr;
384 	uint32_t		a_port,
385 				a_oid;
386 } iscsi_addr_t;
387 
388 typedef struct	_iSCSITargetAddressKeyProperties {
389 	uint32_t		al_vers,			/* In */
390 				al_oid;				/* In */
391 	uint32_t		al_in_cnt;			/* In */
392 	uint32_t		al_out_cnt;			/* Out */
393 	uint32_t		al_tpgt;			/* Out */
394 	iscsi_addr_t		al_addrs[1];			/* Out */
395 } iscsi_addr_list_t;
396 
397 typedef struct	_iSCSITargetProperties {
398 	uint32_t		p_vers,				/* In */
399 				p_oid;				/* In */
400 	uchar_t			p_name[ISCSI_MAX_NAME_LEN];	/* Out */
401 	uint_t			p_name_len;			/* Out */
402 	uchar_t			p_alias[ISCSI_MAX_NAME_LEN];	/* Out */
403 	uint_t			p_alias_len;			/* Out */
404 	iSCSIDiscoveryMethod_t	p_discovery;			/* Out */
405 	boolean_t		p_connected;			/* Out */
406 	uint32_t		p_num_of_connections;		/* Out */
407 	/* ---- If connected == B_TRUE then lastErr has no meaning. ---- */
408 	iscsi_error_t		p_last_err;			/* Out */
409 	/*
410 	 * Target portal group tag = -1 value means default.
411 	 */
412 	int			p_tpgt_conf;			/* Out */
413 	int			p_tpgt_nego;			/* Out */
414 	uchar_t			p_isid[ISCSI_ISID_LEN];		/* Out */
415 	uchar_t			p_reserved[128];
416 } iscsi_property_t;
417 
418 typedef struct	_iSCSITargetDeviceList {
419 	uint32_t		tl_vers,			/* In */
420 				tl_in_cnt,			/* In */
421 				tl_tgt_list_type,		/* In */
422 				tl_out_cnt,			/* Out */
423 				tl_oid_list[1];			/* Out */
424 } iscsi_target_list_t;
425 
426 typedef struct	_iSCSIStaticTargetProperties {
427 	uint32_t		p_vers,				/* In */
428 				p_oid;				/* In */
429 	uchar_t			p_name[ISCSI_MAX_NAME_LEN];	/* Out */
430 	uint_t			p_name_len;			/* Out */
431 	iscsi_addr_list_t	p_addr_list;			/* Out */
432 } iscsi_static_property_t;
433 
434 typedef enum iscsi_lun_status {
435 	LunValid, LunDoesNotExist
436 } iscsi_lun_status_t;
437 
438 /*
439  * SCSI inquiry vendor and product identifier buffer length - these values are
440  * defined by the identifier length plus 1 byte for the
441  * null termination.
442  */
443 #define	ISCSI_INQ_VID_BUF_LEN		9	/* 8 byte ID */
444 #define	ISCSI_INQ_PID_BUF_LEN		17	/* 16 byte ID */
445 
446 typedef struct iscsi_lun_props {
447 	uint32_t		lp_vers,			/* In */
448 				lp_tgt_oid,			/* In */
449 				lp_oid,				/* In */
450 				lp_num,				/* Out */
451 				lp_status;			/* Out */
452 	char			lp_pathname[MAXPATHLEN],	/* Out */
453 				lp_vid[ISCSI_INQ_VID_BUF_LEN],	/* Out */
454 				lp_pid[ISCSI_INQ_PID_BUF_LEN];	/* Out */
455 	time_t			lp_time_online;			/* Out */
456 } iscsi_lun_props_t;
457 
458 typedef struct iscsi_if_lun {
459 	uint32_t		l_tgt_oid,
460 				l_oid,
461 				l_num;
462 } iscsi_if_lun_t;
463 
464 typedef struct iscsi_lun_list {
465 	uint32_t		ll_vers;			/* In */
466 	boolean_t		ll_all_tgts;			/* In */
467 	uint32_t		ll_tgt_oid,			/* In */
468 				ll_in_cnt,			/* In */
469 				ll_out_cnt;			/* Out */
470 	iscsi_if_lun_t		ll_luns[1];			/* Out */
471 } iscsi_lun_list_t;
472 
473 typedef struct iscsi_conn_props {
474 	uint32_t		cp_vers,			/* In */
475 				cp_oid,				/* In */
476 				cp_cid,				/* In */
477 				cp_sess_oid;			/* In */
478 	union {
479 		struct	sockaddr_in	soa4;
480 		struct	sockaddr_in6	soa6;
481 	} cp_local;						/* Out */
482 	union {
483 		struct	sockaddr_in	soa4;
484 		struct	sockaddr_in6	soa6;
485 	} cp_peer;						/* Out */
486 
487 
488 	iscsi_login_params_t 	cp_params;
489 	boolean_t 		cp_params_valid;
490 
491 } iscsi_conn_props_t;
492 
493 typedef struct iscsi_if_conn {
494 	uint32_t		c_sess_oid,
495 				c_oid,
496 				c_cid;
497 } iscsi_if_conn_t;
498 
499 typedef struct iscsi_conn_list {
500 	uint32_t		cl_vers;			/* In */
501 	boolean_t		cl_all_sess;			/* In */
502 	uint32_t		cl_sess_oid,			/* In */
503 				cl_in_cnt,			/* In */
504 				cl_out_cnt;			/* Out */
505 	iscsi_if_conn_t		cl_list[1];			/* Out */
506 } iscsi_conn_list_t;
507 
508 typedef enum iSNSDiscoveryMethod {
509 	iSNSDiscoveryMethodStatic	= 0,
510 	iSNSDiscoveryMethodDHCP		= 1,
511 	iSNSDiscoveryMethodSLP		= 2
512 } isns_method_t;
513 
514 typedef struct iSCSIDiscoveryProperties {
515 	uint32_t		vers;
516 	boolean_t		iSNSDiscoverySettable;
517 	boolean_t		iSNSDiscoveryEnabled;
518 	isns_method_t		iSNSDiscoveryMethod;
519 	unsigned char		iSNSDomainName[256];
520 	boolean_t		SLPDiscoverySettable;
521 	boolean_t		SLPDiscoveryEnabled;
522 	boolean_t		StaticDiscoverySettable;
523 	boolean_t		StaticDiscoveryEnabled;
524 	boolean_t		SendTargetsDiscoverySettable;
525 	boolean_t		SendTargetsDiscoveryEnabled;
526 } iSCSIDiscoveryProperties_t;
527 
528 typedef struct iscsi_uscsi {
529 	uint32_t		iu_vers;
530 	uint32_t		iu_oid;
531 	int			iu_tpgt;
532 	uint32_t		iu_len;
533 	uint32_t		iu_lun;
534 	struct uscsi_cmd	iu_ucmd;
535 } iscsi_uscsi_t;
536 
537 #if defined(_SYSCALL32)
538 typedef struct iscsi_uscsi32 {
539 	uint32_t		iu_vers;
540 	uint32_t		iu_oid;
541 	int			iu_tpgt;
542 	uint32_t		iu_len;
543 	uint32_t		iu_lun;
544 	struct uscsi_cmd32	iu_ucmd;
545 } iscsi_uscsi32_t;
546 #endif /* _SYSCALL32 */
547 
548 typedef struct iscsi_sendtgts_entry {
549 	/* ---- Node name, NULL terminated UTF-8 string ---- */
550 	uchar_t			ste_name[ISCSI_MAX_NAME_LEN];
551 
552 	iscsi_addr_t		ste_ipaddr;
553 	int			ste_tpgt;
554 } iscsi_sendtgts_entry_t;
555 
556 typedef struct iscsi_sendtgts_list {
557 	entry_t			stl_entry;			/* In */
558 	uint32_t		stl_in_cnt,			/* In */
559 				stl_out_cnt;			/* Out */
560 	iscsi_sendtgts_entry_t	stl_list[1];			/* Out */
561 } iscsi_sendtgts_list_t;
562 
563 typedef struct iscsi_statictgt_entry {
564 	entry_t			te_entry;			/* In */
565 	uchar_t			te_name[ISCSI_MAX_NAME_LEN];	/* In */
566 } iscsi_target_entry_t;
567 
568 /* iSNS Draft - section 4.1.1. */
569 typedef struct isns_portal_group {
570 	uint8_t pg_iscsi_name[ISCSI_MAX_NAME_LEN];
571 	union {
572 		in_addr_t	u_ip4;
573 		in6_addr_t	u_ip6;
574 	} pg_ip_addr;
575 	int	insize;
576 
577 	in_port_t pg_port;
578 	uint16_t pg_tag;
579 
580 	iscsi_ipaddr_t	isns_server_ip;
581 	uint32_t	isns_server_port;
582 } isns_portal_group_t;
583 
584 typedef struct isns_portal_group_list {
585 	uint32_t		pg_in_cnt,
586 				pg_out_cnt;
587 	isns_portal_group_t	pg_list[1];
588 } isns_portal_group_list_t;
589 
590 typedef struct isns_server_portal_group_list {
591 	iscsi_addr_t		    addr;
592 	isns_portal_group_list_t    addr_port_list;
593 } isns_server_portal_group_list_t;
594 
595 #define	ISCSI_MIN_CONFIG_SESSIONS	1
596 /* lowered max config sessions due to ct_power_cnt >= 0 assert */
597 #define	ISCSI_MAX_CONFIG_SESSIONS	4
598 
599 typedef struct iscsi_config_sess {
600 	uint32_t	ics_ver;
601 	uint32_t	ics_oid;
602 	boolean_t	ics_bound;
603 	uint_t		ics_in;
604 	uint_t		ics_out;
605 	iscsi_ipaddr_t	ics_bindings[1];
606 } iscsi_config_sess_t;
607 
608 /* iscsi booting prop */
609 typedef struct _iSCSIBootProperties {
610 	node_name_t	ini_name;
611 	node_name_t	tgt_name;
612 	iscsi_auth_props_t	auth;
613 	iscsi_chap_props_t	ini_chap;
614 	iscsi_chap_props_t	tgt_chap;
615 	int iscsiboot;
616 	boolean_t hba_mpxio_enabled;
617 } iscsi_boot_property_t;
618 
619 #define	ISCSI_SESSION_CONFIG_SIZE(SIZE)		\
620 	(sizeof (iscsi_config_sess_t) +		\
621 	((SIZE - 1) * sizeof (iscsi_ipaddr_t)))
622 
623 /*
624  * Event class and subclass information
625  */
626 #define	EC_ISCSI			"EC_iSCSI"
627 #define	ESC_ISCSI_STATIC_START		"ESC_static_start"
628 #define	ESC_ISCSI_STATIC_END		"ESC_static_end"
629 #define	ESC_ISCSI_SEND_TARGETS_START	"ESC_send_targets_start"
630 #define	ESC_ISCSI_SEND_TARGETS_END	"ESC_send_targets_end"
631 #define	ESC_ISCSI_SLP_START		"ESC_slp_start"
632 #define	ESC_ISCSI_SLP_END		"ESC_slp_end"
633 #define	ESC_ISCSI_ISNS_START		"ESC_isns_start"
634 #define	ESC_ISCSI_ISNS_END		"ESC_isns_end"
635 #define	ESC_ISCSI_PROP_CHANGE		"ESC_prop_change"
636 
637 #ifdef _KERNEL
638 /* ---- iscsi_utils.c ---- */
639 extern int		iscsid_open(char *, int, int);
640 extern int		iscsid_close(int);
641 extern int		iscsid_remove(char *filename);
642 extern int		iscsid_rename(char *oldname, char *newname);
643 extern ssize_t		iscsid_write(int, void *, ssize_t);
644 extern ssize_t		iscsid_read(int, void *, ssize_t);
645 extern ssize_t		iscsid_sendto(struct sonode *, void *, size_t,
646     struct sockaddr *, socklen_t);
647 extern ssize_t		iscsid_recvfrom(struct sonode *, void *buffer,
648     size_t len);
649 extern int		iscsid_errno;
650 #endif
651 
652 /*
653  * Function prototypes for those routines found in the common code
654  */
655 /* ---- utils.c ---- */
656 extern boolean_t	utils_iqn_create(char *, int);
657 extern char		*prt_bitmap(int, char *, char *, int);
658 extern char		*utils_map_param(int);
659 extern boolean_t	parse_addr_port_tpgt(char *in, char **addr,
660 			    int *type, char **port, char **tpgt);
661 
662 #ifdef __cplusplus
663 }
664 #endif
665 
666 #endif /* _ISCSI_IF_H */
667