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