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