xref: /freebsd/sys/cam/ctl/ctl_ioctl.h (revision c9dbb1cc52b063bbd9ab078a7afc89a8696da659)
1 /*-
2  * Copyright (c) 2003 Silicon Graphics International Corp.
3  * Copyright (c) 2011 Spectra Logic Corporation
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions, and the following disclaimer,
11  *    without modification.
12  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13  *    substantially similar to the "NO WARRANTY" disclaimer below
14  *    ("Disclaimer") and any redistribution must be conditioned upon
15  *    including a substantially similar Disclaimer requirement for further
16  *    binary redistribution.
17  *
18  * NO WARRANTY
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGES.
30  *
31  * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ioctl.h#4 $
32  * $FreeBSD$
33  */
34 /*
35  * CAM Target Layer ioctl interface.
36  *
37  * Author: Ken Merry <ken@FreeBSD.org>
38  */
39 
40 #ifndef	_CTL_IOCTL_H_
41 #define	_CTL_IOCTL_H_
42 
43 #ifdef ICL_KERNEL_PROXY
44 #include <sys/socket.h>
45 #endif
46 
47 #include <sys/ioccom.h>
48 
49 #define	CTL_DEFAULT_DEV		"/dev/cam/ctl"
50 /*
51  * Maximum number of targets we support.
52  */
53 #define	CTL_MAX_TARGETS		1
54 
55 /*
56  * Maximum target ID we support.
57  */
58 #define	CTL_MAX_TARGID		15
59 
60 /*
61  * Maximum number of LUNs we support at the moment.  MUST be a power of 2.
62  */
63 #define	CTL_MAX_LUNS		1024
64 
65 /*
66  * Maximum number of initiators per port.
67  */
68 #define	CTL_MAX_INIT_PER_PORT	2048
69 
70 /*
71  * Maximum number of ports registered at one time.
72  */
73 #define	CTL_MAX_PORTS		256
74 
75 /*
76  * Maximum number of initiators we support.
77  */
78 #define	CTL_MAX_INITIATORS	(CTL_MAX_INIT_PER_PORT * CTL_MAX_PORTS)
79 
80 /* Hopefully this won't conflict with new misc devices that pop up */
81 #define	CTL_MINOR	225
82 
83 typedef enum {
84 	CTL_OOA_INVALID_LUN,
85 	CTL_OOA_SUCCESS
86 } ctl_ooa_status;
87 
88 struct ctl_ooa_info {
89 	uint32_t lun_id;	/* Passed in to CTL */
90 	uint32_t num_entries;	/* Returned from CTL */
91 	ctl_ooa_status status;	/* Returned from CTL */
92 };
93 
94 typedef enum {
95 	CTL_DELAY_TYPE_NONE,
96 	CTL_DELAY_TYPE_CONT,
97 	CTL_DELAY_TYPE_ONESHOT
98 } ctl_delay_type;
99 
100 typedef enum {
101 	CTL_DELAY_LOC_NONE,
102 	CTL_DELAY_LOC_DATAMOVE,
103 	CTL_DELAY_LOC_DONE,
104 } ctl_delay_location;
105 
106 typedef enum {
107 	CTL_DELAY_STATUS_NONE,
108 	CTL_DELAY_STATUS_OK,
109 	CTL_DELAY_STATUS_INVALID_LUN,
110 	CTL_DELAY_STATUS_INVALID_TYPE,
111 	CTL_DELAY_STATUS_INVALID_LOC,
112 	CTL_DELAY_STATUS_NOT_IMPLEMENTED
113 } ctl_delay_status;
114 
115 struct ctl_io_delay_info {
116 	uint32_t		lun_id;
117 	ctl_delay_type		delay_type;
118 	ctl_delay_location	delay_loc;
119 	uint32_t		delay_secs;
120 	ctl_delay_status	status;
121 };
122 
123 typedef enum {
124 	CTL_GS_SYNC_NONE,
125 	CTL_GS_SYNC_OK,
126 	CTL_GS_SYNC_NO_LUN
127 } ctl_gs_sync_status;
128 
129 /*
130  * The target and LUN id specify which device to modify.  The sync interval
131  * means that we will let through every N SYNCHRONIZE CACHE commands.
132  */
133 struct ctl_sync_info {
134 	uint32_t		lun_id;		/* passed to kernel */
135 	int			sync_interval;	/* depends on whether get/set */
136 	ctl_gs_sync_status	status;		/* passed from kernel */
137 };
138 
139 typedef enum {
140 	CTL_STATS_NO_IO,
141 	CTL_STATS_READ,
142 	CTL_STATS_WRITE
143 } ctl_stat_types;
144 #define	CTL_STATS_NUM_TYPES	3
145 
146 typedef enum {
147 	CTL_LUN_STATS_NO_BLOCKSIZE	= 0x01
148 } ctl_lun_stats_flags;
149 
150 struct ctl_lun_io_port_stats {
151 	uint32_t			targ_port;
152 	uint64_t			bytes[CTL_STATS_NUM_TYPES];
153 	uint64_t			operations[CTL_STATS_NUM_TYPES];
154 	struct bintime			time[CTL_STATS_NUM_TYPES];
155 	uint64_t			num_dmas[CTL_STATS_NUM_TYPES];
156 	struct bintime			dma_time[CTL_STATS_NUM_TYPES];
157 };
158 
159 struct ctl_lun_io_stats {
160 	uint8_t				device_type;
161 	uint64_t			lun_number;
162 	uint32_t			blocksize;
163 	ctl_lun_stats_flags		flags;
164 	struct ctl_lun_io_port_stats	ports[CTL_MAX_PORTS];
165 };
166 
167 typedef enum {
168 	CTL_SS_OK,
169 	CTL_SS_NEED_MORE_SPACE,
170 	CTL_SS_ERROR
171 } ctl_stats_status;
172 
173 typedef enum {
174 	CTL_STATS_FLAG_NONE		= 0x00,
175 	CTL_STATS_FLAG_TIME_VALID	= 0x01
176 } ctl_stats_flags;
177 
178 struct ctl_stats {
179 	int			alloc_len;	/* passed to kernel */
180 	struct ctl_lun_io_stats	*lun_stats;	/* passed to/from kernel */
181 	int			fill_len;	/* passed to userland */
182 	int			num_luns;	/* passed to userland */
183 	ctl_stats_status	status;		/* passed to userland */
184 	ctl_stats_flags		flags;		/* passed to userland */
185 	struct timespec		timestamp;	/* passed to userland */
186 };
187 
188 /*
189  * The types of errors that can be injected:
190  *
191  * NONE:	No error specified.
192  * ABORTED:	SSD_KEY_ABORTED_COMMAND, 0x45, 0x00
193  * MEDIUM_ERR:	Medium error, different asc/ascq depending on read/write.
194  * UA:		Unit attention.
195  * CUSTOM:	User specifies the sense data.
196  * TYPE:	Mask to use with error types.
197  *
198  * Flags that affect injection behavior:
199  * CONTINUOUS:	This error will stay around until explicitly cleared.
200  * DESCRIPTOR:	Use descriptor sense instead of fixed sense.
201  */
202 typedef enum {
203 	CTL_LUN_INJ_NONE		= 0x000,
204 	CTL_LUN_INJ_ABORTED		= 0x001,
205 	CTL_LUN_INJ_MEDIUM_ERR		= 0x002,
206 	CTL_LUN_INJ_UA			= 0x003,
207 	CTL_LUN_INJ_CUSTOM		= 0x004,
208 	CTL_LUN_INJ_TYPE		= 0x0ff,
209 	CTL_LUN_INJ_CONTINUOUS		= 0x100,
210 	CTL_LUN_INJ_DESCRIPTOR		= 0x200
211 } ctl_lun_error;
212 
213 /*
214  * Flags to specify what type of command the given error pattern will
215  * execute on.  The first group of types can be ORed together.
216  *
217  * READ:	Any read command.
218  * WRITE:	Any write command.
219  * READWRITE:	Any read or write command.
220  * READCAP:	Any read capacity command.
221  * TUR:		Test Unit Ready.
222  * ANY:		Any command.
223  * MASK:	Mask for basic command patterns.
224  *
225  * Special types:
226  *
227  * CMD:		The CDB to act on is specified in struct ctl_error_desc_cmd.
228  * RANGE:	For read/write commands, act when the LBA is in the
229  *		specified range.
230  */
231 typedef enum {
232 	CTL_LUN_PAT_NONE	= 0x000,
233 	CTL_LUN_PAT_READ	= 0x001,
234 	CTL_LUN_PAT_WRITE	= 0x002,
235 	CTL_LUN_PAT_READWRITE	= CTL_LUN_PAT_READ | CTL_LUN_PAT_WRITE,
236 	CTL_LUN_PAT_READCAP	= 0x004,
237 	CTL_LUN_PAT_TUR		= 0x008,
238 	CTL_LUN_PAT_ANY		= 0x0ff,
239 	CTL_LUN_PAT_MASK	= 0x0ff,
240 	CTL_LUN_PAT_CMD		= 0x100,
241 	CTL_LUN_PAT_RANGE	= 0x200
242 } ctl_lun_error_pattern;
243 
244 /*
245  * This structure allows the user to specify a particular CDB pattern to
246  * look for.
247  *
248  * cdb_pattern:		Fill in the relevant bytes to look for in the CDB.
249  * cdb_valid_bytes:	Bitmask specifying valid bytes in the cdb_pattern.
250  * flags:		Specify any command flags (see ctl_io_flags) that
251  *			should be set.
252  */
253 struct ctl_error_desc_cmd {
254 	uint8_t		cdb_pattern[CTL_MAX_CDBLEN];
255 	uint32_t	cdb_valid_bytes;
256 	uint32_t	flags;
257 };
258 
259 /*
260  * Error injection descriptor.
261  *
262  * lun_id	   LUN to act on.
263  * lun_error:	   The type of error to inject.  See above for descriptions.
264  * error_pattern:  What kind of command to act on.  See above.
265  * cmd_desc:	   For CTL_LUN_PAT_CMD only.
266  * lba_range:	   For CTL_LUN_PAT_RANGE only.
267  * custom_sense:   Specify sense.  For CTL_LUN_INJ_CUSTOM only.
268  * serial:	   Serial number returned by the kernel.  Use for deletion.
269  * links:	   Kernel use only.
270  */
271 struct ctl_error_desc {
272 	uint32_t			lun_id;		/* To kernel */
273 	ctl_lun_error			lun_error;	/* To kernel */
274 	ctl_lun_error_pattern		error_pattern;	/* To kernel */
275 	struct ctl_error_desc_cmd	cmd_desc;	/* To kernel */
276 	struct ctl_lba_len		lba_range;	/* To kernel */
277 	struct scsi_sense_data		custom_sense;	/* To kernel */
278 	uint64_t			serial;		/* From kernel */
279 	STAILQ_ENTRY(ctl_error_desc)	links;		/* Kernel use only */
280 };
281 
282 typedef enum {
283 	CTL_OOA_FLAG_NONE	= 0x00,
284 	CTL_OOA_FLAG_ALL_LUNS	= 0x01
285 } ctl_ooa_flags;
286 
287 typedef enum {
288 	CTL_OOA_OK,
289 	CTL_OOA_NEED_MORE_SPACE,
290 	CTL_OOA_ERROR
291 } ctl_get_ooa_status;
292 
293 typedef enum {
294 	CTL_OOACMD_FLAG_NONE		= 0x00,
295 	CTL_OOACMD_FLAG_DMA		= 0x01,
296 	CTL_OOACMD_FLAG_BLOCKED		= 0x02,
297 	CTL_OOACMD_FLAG_ABORT		= 0x04,
298 	CTL_OOACMD_FLAG_RTR		= 0x08,
299 	CTL_OOACMD_FLAG_DMA_QUEUED	= 0x10
300 } ctl_ooa_cmd_flags;
301 
302 struct ctl_ooa_entry {
303 	ctl_ooa_cmd_flags	cmd_flags;
304 	uint8_t			cdb[CTL_MAX_CDBLEN];
305 	uint8_t			cdb_len;
306 	uint32_t		tag_num;
307 	uint32_t		lun_num;
308 	struct bintime		start_bt;
309 };
310 
311 struct ctl_ooa {
312 	ctl_ooa_flags		flags;		/* passed to kernel */
313 	uint64_t		lun_num;	/* passed to kernel */
314 	uint32_t		alloc_len;	/* passed to kernel */
315 	uint32_t		alloc_num;	/* passed to kernel */
316 	struct ctl_ooa_entry	*entries;	/* filled in kernel */
317 	uint32_t		fill_len;	/* passed to userland */
318 	uint32_t		fill_num;	/* passed to userland */
319 	uint32_t		dropped_num;	/* passed to userland */
320 	struct bintime		cur_bt;		/* passed to userland */
321 	ctl_get_ooa_status	status;		/* passed to userland */
322 };
323 
324 typedef enum {
325 	CTL_PORT_LIST_NONE,
326 	CTL_PORT_LIST_OK,
327 	CTL_PORT_LIST_NEED_MORE_SPACE,
328 	CTL_PORT_LIST_ERROR
329 } ctl_port_list_status;
330 
331 struct ctl_port_list {
332 	uint32_t		alloc_len;	/* passed to kernel */
333 	uint32_t		alloc_num;	/* passed to kernel */
334 	struct ctl_port_entry   *entries;	/* filled in kernel */
335 	uint32_t		fill_len;	/* passed to userland */
336 	uint32_t		fill_num;	/* passed to userland */
337 	uint32_t		dropped_num;	/* passed to userland */
338 	ctl_port_list_status	status;		/* passed to userland */
339 };
340 
341 typedef enum {
342 	CTL_LUN_NOSTATUS,
343 	CTL_LUN_OK,
344 	CTL_LUN_ERROR,
345 	CTL_LUN_WARNING
346 } ctl_lun_status;
347 
348 #define	CTL_ERROR_STR_LEN	160
349 
350 #define	CTL_BEARG_RD		0x01
351 #define	CTL_BEARG_WR		0x02
352 #define	CTL_BEARG_RW		(CTL_BEARG_RD|CTL_BEARG_WR)
353 #define	CTL_BEARG_ASCII		0x04
354 
355 /*
356  * Backend Argument:
357  *
358  * namelen:	Length of the name field, including the terminating NUL.
359  *
360  * name:	Name of the paramter.  This must be NUL-terminated.
361  *
362  * flags:	Flags for the parameter, see above for values.
363  *
364  * vallen:	Length of the value in bytes.
365  *
366  * value:	Value to be set/fetched.
367  *
368  * kname:	For kernel use only.
369  *
370  * kvalue:	For kernel use only.
371  */
372 struct ctl_be_arg {
373 	int	namelen;
374 	char	*name;
375 	int	flags;
376 	int	vallen;
377 	void	*value;
378 
379 	char	*kname;
380 	void	*kvalue;
381 };
382 
383 typedef enum {
384 	CTL_LUNREQ_CREATE,
385 	CTL_LUNREQ_RM,
386 	CTL_LUNREQ_MODIFY,
387 } ctl_lunreq_type;
388 
389 
390 /*
391  * LUN creation parameters:
392  *
393  * flags:		Various LUN flags, see ctl_backend.h for a
394  *			description of the flag values and meanings.
395  *
396  * device_type:		The SCSI device type.  e.g. 0 for Direct Access,
397  *			3 for Processor, etc.  Only certain backends may
398  *			support setting this field.  The CTL_LUN_FLAG_DEV_TYPE
399  *			flag should be set in the flags field if the device
400  *			type is set.
401  *
402  * lun_size_bytes:	The size of the LUN in bytes.  For some backends
403  *			this is relevant (e.g. ramdisk), for others, it may
404  *			be ignored in favor of using the properties of the
405  *			backing store.  If specified, this should be a
406  *			multiple of the blocksize.
407  *
408  *			The actual size of the LUN is returned in this
409  *			field.
410  *
411  * blocksize_bytes:	The LUN blocksize in bytes.  For some backends this
412  *			is relevant, for others it may be ignored in
413  *			favor of using the properties of the backing store.
414  *
415  *			The actual blocksize of the LUN is returned in this
416  *			field.
417  *
418  * req_lun_id:		The requested LUN ID.  The CTL_LUN_FLAG_ID_REQ flag
419  *			should be set if this is set.  The request will be
420  *			granted if the LUN number is available, otherwise
421  * 			the LUN addition request will fail.
422  *
423  *			The allocated LUN number is returned in this field.
424  *
425  * serial_num:		This is the value returned in SCSI INQUIRY VPD page
426  *			0x80.  If it is specified, the CTL_LUN_FLAG_SERIAL_NUM
427  *			flag should be set.
428  *
429  *			The serial number value used is returned in this
430  *			field.
431  *
432  * device_id:		This is the value returned in the T10 vendor ID
433  *			based DESIGNATOR field in the SCSI INQUIRY VPD page
434  *			0x83 data.  If it is specified, the CTL_LUN_FLAG_DEVID
435  *			flag should be set.
436  *
437  *			The device id value used is returned in this field.
438  */
439 struct ctl_lun_create_params {
440 	ctl_backend_lun_flags	flags;
441 	uint8_t			device_type;
442 	uint64_t		lun_size_bytes;
443 	uint32_t		blocksize_bytes;
444 	uint32_t		req_lun_id;
445 	uint8_t			serial_num[CTL_SN_LEN];
446 	uint8_t			device_id[CTL_DEVID_LEN];
447 };
448 
449 /*
450  * LUN removal parameters:
451  *
452  * lun_id:		The number of the LUN to delete.  This must be set.
453  *			The LUN must be backed by the given backend.
454  */
455 struct ctl_lun_rm_params {
456 	uint32_t		lun_id;
457 };
458 
459 /*
460  * LUN modification parameters:
461  *
462  * lun_id:		The number of the LUN to modify.  This must be set.
463  *			The LUN must be backed by the given backend.
464  *
465  * lun_size_bytes:	The size of the LUN in bytes.  If zero, update
466  * 			the size using the backing file size, if possible.
467  */
468 struct ctl_lun_modify_params {
469 	uint32_t		lun_id;
470 	uint64_t		lun_size_bytes;
471 };
472 
473 /*
474  * Union of request type data.  Fill in the appropriate union member for
475  * the request type.
476  */
477 union ctl_lunreq_data {
478 	struct ctl_lun_create_params	create;
479 	struct ctl_lun_rm_params	rm;
480 	struct ctl_lun_modify_params	modify;
481 };
482 
483 /*
484  * LUN request interface:
485  *
486  * backend:		This is required, and is NUL-terminated a string
487  *			that is the name of the backend, like "ramdisk" or
488  *			"block".
489  *
490  * reqtype:		The type of request, CTL_LUNREQ_CREATE to create a
491  *			LUN, CTL_LUNREQ_RM to delete a LUN.
492  *
493  * reqdata:		Request type-specific information.  See the
494  *			description of individual the union members above
495  *			for more information.
496  *
497  * num_be_args:		This is the number of backend-specific arguments
498  *			in the be_args array.
499  *
500  * be_args:		This is an array of backend-specific arguments.
501  *			See above for a description of the fields in this
502  *			structure.
503  *
504  * status:		Status of the LUN request.
505  *
506  * error_str:		If the status is CTL_LUN_ERROR, this will
507  *			contain a string describing the error.
508  *
509  * kern_be_args:	For kernel use only.
510  */
511 struct ctl_lun_req {
512 	char			backend[CTL_BE_NAME_LEN];
513 	ctl_lunreq_type		reqtype;
514 	union ctl_lunreq_data	reqdata;
515 	int			num_be_args;
516 	struct ctl_be_arg	*be_args;
517 	ctl_lun_status		status;
518 	char			error_str[CTL_ERROR_STR_LEN];
519 	struct ctl_be_arg	*kern_be_args;
520 };
521 
522 /*
523  * LUN list status:
524  *
525  * NONE:		No status.
526  *
527  * OK:			Request completed successfully.
528  *
529  * NEED_MORE_SPACE:	The allocated length of the entries field is too
530  * 			small for the available data.
531  *
532  * ERROR:		An error occured, look at the error string for a
533  *			description of the error.
534  */
535 typedef enum {
536 	CTL_LUN_LIST_NONE,
537 	CTL_LUN_LIST_OK,
538 	CTL_LUN_LIST_NEED_MORE_SPACE,
539 	CTL_LUN_LIST_ERROR
540 } ctl_lun_list_status;
541 
542 /*
543  * LUN list interface
544  *
545  * backend_name:	This is a NUL-terminated string.  If the string
546  *			length is 0, then all LUNs on all backends will
547  *			be enumerated.  Otherwise this is the name of the
548  *			backend to be enumerated, like "ramdisk" or "block".
549  *
550  * alloc_len:		The length of the data buffer allocated for entries.
551  *			In order to properly size the buffer, make one call
552  *			with alloc_len set to 0, and then use the returned
553  *			dropped_len as the buffer length to allocate and
554  *			pass in on a subsequent call.
555  *
556  * lun_xml:		XML-formatted information on the requested LUNs.
557  *
558  * fill_len:		The amount of data filled in the storage for entries.
559  *
560  * status:		The status of the request.  See above for the
561  *			description of the values of this field.
562  *
563  * error_str:		If the status indicates an error, this string will
564  *			be filled in to describe the error.
565  */
566 struct ctl_lun_list {
567 	char			backend[CTL_BE_NAME_LEN]; /* passed to kernel*/
568 	uint32_t		alloc_len;	/* passed to kernel */
569 	char                   *lun_xml;	/* filled in kernel */
570 	uint32_t		fill_len;	/* passed to userland */
571 	ctl_lun_list_status	status;		/* passed to userland */
572 	char			error_str[CTL_ERROR_STR_LEN];
573 						/* passed to userland */
574 };
575 
576 /*
577  * Port request interface:
578  *
579  * driver:		This is required, and is NUL-terminated a string
580  *			that is the name of the frontend, like "iscsi" .
581  *
582  * reqtype:		The type of request, CTL_REQ_CREATE to create a
583  *			port, CTL_REQ_REMOVE to delete a port.
584  *
585  * num_be_args:		This is the number of frontend-specific arguments
586  *			in the be_args array.
587  *
588  * be_args:		This is an array of frontend-specific arguments.
589  *			See above for a description of the fields in this
590  *			structure.
591  *
592  * status:		Status of the request.
593  *
594  * error_str:		If the status is CTL_LUN_ERROR, this will
595  *			contain a string describing the error.
596  *
597  * kern_be_args:	For kernel use only.
598  */
599 typedef enum {
600 	CTL_REQ_CREATE,
601 	CTL_REQ_REMOVE,
602 	CTL_REQ_MODIFY,
603 } ctl_req_type;
604 
605 struct ctl_req {
606 	char			driver[CTL_DRIVER_NAME_LEN];
607 	ctl_req_type		reqtype;
608 	int			num_args;
609 	struct ctl_be_arg	*args;
610 	ctl_lun_status		status;
611 	char			error_str[CTL_ERROR_STR_LEN];
612 	struct ctl_be_arg	*kern_args;
613 };
614 
615 /*
616  * iSCSI status
617  *
618  * OK:			Request completed successfully.
619  *
620  * ERROR:		An error occured, look at the error string for a
621  *			description of the error.
622  *
623  * CTL_ISCSI_LIST_NEED_MORE_SPACE:
624  * 			User has to pass larger buffer for CTL_ISCSI_LIST ioctl.
625  */
626 typedef enum {
627 	CTL_ISCSI_OK,
628 	CTL_ISCSI_ERROR,
629 	CTL_ISCSI_LIST_NEED_MORE_SPACE,
630 	CTL_ISCSI_SESSION_NOT_FOUND
631 } ctl_iscsi_status;
632 
633 typedef enum {
634 	CTL_ISCSI_HANDOFF,
635 	CTL_ISCSI_LIST,
636 	CTL_ISCSI_LOGOUT,
637 	CTL_ISCSI_TERMINATE,
638 	CTL_ISCSI_LIMITS,
639 #if defined(ICL_KERNEL_PROXY) || 1
640 	/*
641 	 * We actually need those in all cases, but leave the ICL_KERNEL_PROXY,
642 	 * to remember to remove them along with rest of proxy code, eventually.
643 	 */
644 	CTL_ISCSI_LISTEN,
645 	CTL_ISCSI_ACCEPT,
646 	CTL_ISCSI_SEND,
647 	CTL_ISCSI_RECEIVE,
648 #endif
649 } ctl_iscsi_type;
650 
651 typedef enum {
652 	CTL_ISCSI_DIGEST_NONE,
653 	CTL_ISCSI_DIGEST_CRC32C
654 } ctl_iscsi_digest;
655 
656 #define	CTL_ISCSI_NAME_LEN	224	/* 223 bytes, by RFC 3720, + '\0' */
657 #define	CTL_ISCSI_ADDR_LEN	47	/* INET6_ADDRSTRLEN + '\0' */
658 #define	CTL_ISCSI_ALIAS_LEN	128	/* Arbitrary. */
659 #define	CTL_ISCSI_OFFLOAD_LEN	8	/* Arbitrary. */
660 
661 struct ctl_iscsi_handoff_params {
662 	char			initiator_name[CTL_ISCSI_NAME_LEN];
663 	char			initiator_addr[CTL_ISCSI_ADDR_LEN];
664 	char			initiator_alias[CTL_ISCSI_ALIAS_LEN];
665 	uint8_t			initiator_isid[6];
666 	char			target_name[CTL_ISCSI_NAME_LEN];
667 	int			socket;
668 	int			portal_group_tag;
669 
670 	/*
671 	 * Connection parameters negotiated by ctld(8).
672 	 */
673 	ctl_iscsi_digest	header_digest;
674 	ctl_iscsi_digest	data_digest;
675 	uint32_t		cmdsn;
676 	uint32_t		statsn;
677 	uint32_t		max_recv_data_segment_length;
678 	uint32_t		max_burst_length;
679 	uint32_t		first_burst_length;
680 	uint32_t		immediate_data;
681 	char			offload[CTL_ISCSI_OFFLOAD_LEN];
682 #ifdef ICL_KERNEL_PROXY
683 	int			connection_id;
684 	int			spare[1];
685 #else
686 	int			spare[2];
687 #endif
688 };
689 
690 struct ctl_iscsi_list_params {
691 	uint32_t		alloc_len;	/* passed to kernel */
692 	char                   *conn_xml;	/* filled in kernel */
693 	uint32_t		fill_len;	/* passed to userland */
694 	int			spare[4];
695 };
696 
697 struct ctl_iscsi_logout_params {
698 	int			connection_id;	/* passed to kernel */
699 	char			initiator_name[CTL_ISCSI_NAME_LEN];
700 						/* passed to kernel */
701 	char			initiator_addr[CTL_ISCSI_ADDR_LEN];
702 						/* passed to kernel */
703 	int			all;		/* passed to kernel */
704 	int			spare[4];
705 };
706 
707 struct ctl_iscsi_terminate_params {
708 	int			connection_id;	/* passed to kernel */
709 	char			initiator_name[CTL_ISCSI_NAME_LEN];
710 						/* passed to kernel */
711 	char			initiator_addr[CTL_ISCSI_NAME_LEN];
712 						/* passed to kernel */
713 	int			all;		/* passed to kernel */
714 	int			spare[4];
715 };
716 
717 struct ctl_iscsi_limits_params {
718 	char			offload[CTL_ISCSI_OFFLOAD_LEN];
719 						/* passed to kernel */
720 	size_t			data_segment_limit;
721 						/* passed to userland */
722 	int			spare[4];
723 };
724 
725 #ifdef ICL_KERNEL_PROXY
726 struct ctl_iscsi_listen_params {
727 	int				iser;
728 	int				domain;
729 	int				socktype;
730 	int				protocol;
731 	struct sockaddr			*addr;
732 	socklen_t			addrlen;
733 	int				portal_id;
734 	int				spare[4];
735 };
736 
737 struct ctl_iscsi_accept_params {
738 	int				connection_id;
739 	int				portal_id;
740 	struct sockaddr			*initiator_addr;
741 	socklen_t			initiator_addrlen;
742 	int				spare[4];
743 };
744 
745 struct ctl_iscsi_send_params {
746 	int				connection_id;
747 	void				*bhs;
748 	size_t				spare;
749 	void				*spare2;
750 	size_t				data_segment_len;
751 	void				*data_segment;
752 	int				spare3[4];
753 };
754 
755 struct ctl_iscsi_receive_params {
756 	int				connection_id;
757 	void				*bhs;
758 	size_t				spare;
759 	void				*spare2;
760 	size_t				data_segment_len;
761 	void				*data_segment;
762 	int				spare3[4];
763 };
764 
765 #endif /* ICL_KERNEL_PROXY */
766 
767 union ctl_iscsi_data {
768 	struct ctl_iscsi_handoff_params		handoff;
769 	struct ctl_iscsi_list_params		list;
770 	struct ctl_iscsi_logout_params		logout;
771 	struct ctl_iscsi_terminate_params	terminate;
772 	struct ctl_iscsi_limits_params		limits;
773 #ifdef ICL_KERNEL_PROXY
774 	struct ctl_iscsi_listen_params		listen;
775 	struct ctl_iscsi_accept_params		accept;
776 	struct ctl_iscsi_send_params		send;
777 	struct ctl_iscsi_receive_params		receive;
778 #endif
779 };
780 
781 /*
782  * iSCSI interface
783  *
784  * status:		The status of the request.  See above for the
785  *			description of the values of this field.
786  *
787  * error_str:		If the status indicates an error, this string will
788  *			be filled in to describe the error.
789  */
790 struct ctl_iscsi {
791 	ctl_iscsi_type		type;		/* passed to kernel */
792 	union ctl_iscsi_data	data;		/* passed to kernel */
793 	ctl_iscsi_status	status;		/* passed to userland */
794 	char			error_str[CTL_ERROR_STR_LEN];
795 						/* passed to userland */
796 };
797 
798 struct ctl_lun_map {
799 	uint32_t		port;
800 	uint32_t		plun;
801 	uint32_t		lun;
802 };
803 
804 #define	CTL_IO			_IOWR(CTL_MINOR, 0x00, union ctl_io)
805 #define	CTL_ENABLE_PORT		_IOW(CTL_MINOR, 0x04, struct ctl_port_entry)
806 #define	CTL_DISABLE_PORT	_IOW(CTL_MINOR, 0x05, struct ctl_port_entry)
807 #define	CTL_DUMP_OOA		_IO(CTL_MINOR, 0x06)
808 #define	CTL_CHECK_OOA		_IOWR(CTL_MINOR, 0x07, struct ctl_ooa_info)
809 #define	CTL_DELAY_IO		_IOWR(CTL_MINOR, 0x10, struct ctl_io_delay_info)
810 #define	CTL_REALSYNC_GET	_IOR(CTL_MINOR, 0x11, int)
811 #define	CTL_REALSYNC_SET	_IOW(CTL_MINOR, 0x12, int)
812 #define	CTL_SETSYNC		_IOWR(CTL_MINOR, 0x13, struct ctl_sync_info)
813 #define	CTL_GETSYNC		_IOWR(CTL_MINOR, 0x14, struct ctl_sync_info)
814 #define	CTL_GETSTATS		_IOWR(CTL_MINOR, 0x15, struct ctl_stats)
815 #define	CTL_ERROR_INJECT	_IOWR(CTL_MINOR, 0x16, struct ctl_error_desc)
816 #define	CTL_GET_OOA		_IOWR(CTL_MINOR, 0x18, struct ctl_ooa)
817 #define	CTL_DUMP_STRUCTS	_IO(CTL_MINOR, 0x19)
818 #define	CTL_GET_PORT_LIST	_IOWR(CTL_MINOR, 0x20, struct ctl_port_list)
819 #define	CTL_LUN_REQ		_IOWR(CTL_MINOR, 0x21, struct ctl_lun_req)
820 #define	CTL_LUN_LIST		_IOWR(CTL_MINOR, 0x22, struct ctl_lun_list)
821 #define	CTL_ERROR_INJECT_DELETE	_IOW(CTL_MINOR, 0x23, struct ctl_error_desc)
822 #define	CTL_SET_PORT_WWNS	_IOW(CTL_MINOR, 0x24, struct ctl_port_entry)
823 #define	CTL_ISCSI		_IOWR(CTL_MINOR, 0x25, struct ctl_iscsi)
824 #define	CTL_PORT_REQ		_IOWR(CTL_MINOR, 0x26, struct ctl_req)
825 #define	CTL_PORT_LIST		_IOWR(CTL_MINOR, 0x27, struct ctl_lun_list)
826 #define	CTL_LUN_MAP		_IOW(CTL_MINOR, 0x28, struct ctl_lun_map)
827 
828 #endif /* _CTL_IOCTL_H_ */
829 
830 /*
831  * vim: ts=8
832  */
833