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