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