ctl_ioctl.h revision 311402
1255570Strasz/*-
2255570Strasz * Copyright (c) 2003 Silicon Graphics International Corp.
3255570Strasz * Copyright (c) 2011 Spectra Logic Corporation
4255570Strasz * All rights reserved.
5255570Strasz *
6255570Strasz * Redistribution and use in source and binary forms, with or without
7255570Strasz * modification, are permitted provided that the following conditions
8255570Strasz * are met:
9255570Strasz * 1. Redistributions of source code must retain the above copyright
10255570Strasz *    notice, this list of conditions, and the following disclaimer,
11255570Strasz *    without modification.
12255570Strasz * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13255570Strasz *    substantially similar to the "NO WARRANTY" disclaimer below
14255570Strasz *    ("Disclaimer") and any redistribution must be conditioned upon
15255570Strasz *    including a substantially similar Disclaimer requirement for further
16255570Strasz *    binary redistribution.
17255570Strasz *
18255570Strasz * NO WARRANTY
19255570Strasz * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20255570Strasz * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21255570Strasz * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
22255570Strasz * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23255570Strasz * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24255570Strasz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25255570Strasz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26255570Strasz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27255570Strasz * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28255570Strasz * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29255570Strasz * POSSIBILITY OF SUCH DAMAGES.
30255570Strasz *
31270888Strasz * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ioctl.h#4 $
32270888Strasz * $FreeBSD: stable/10/sys/cam/ctl/ctl_ioctl.h 311402 2017-01-05 11:20:31Z mav $
33270888Strasz */
34255570Strasz/*
35269065Smav * CAM Target Layer ioctl interface.
36255570Strasz *
37255570Strasz * Author: Ken Merry <ken@FreeBSD.org>
38255570Strasz */
39255570Strasz
40255570Strasz#ifndef	_CTL_IOCTL_H_
41255570Strasz#define	_CTL_IOCTL_H_
42255570Strasz
43255570Strasz#ifdef ICL_KERNEL_PROXY
44255570Strasz#include <sys/socket.h>
45255570Strasz#endif
46255570Strasz
47255570Strasz#include <sys/ioccom.h>
48255570Strasz
49255570Strasz#define	CTL_DEFAULT_DEV		"/dev/cam/ctl"
50255570Strasz/*
51255570Strasz * Maximum number of targets we support.
52255570Strasz */
53255570Strasz#define	CTL_MAX_TARGETS		1
54255570Strasz
55255570Strasz/*
56255570Strasz * Maximum target ID we support.
57255570Strasz */
58255570Strasz#define	CTL_MAX_TARGID		15
59255570Strasz
60255570Strasz/*
61255570Strasz * Maximum number of LUNs we support at the moment.  MUST be a power of 2.
62255570Strasz */
63255570Strasz#define	CTL_MAX_LUNS		1024
64255570Strasz
65255570Strasz/*
66255570Strasz * Maximum number of initiators per port.
67255570Strasz */
68255570Strasz#define	CTL_MAX_INIT_PER_PORT	2048
69255570Strasz
70255570Strasz/*
71255570Strasz * Maximum number of ports registered at one time.
72255570Strasz */
73255570Strasz#define	CTL_MAX_PORTS		256
74255570Strasz
75255570Strasz/*
76255570Strasz * Maximum number of initiators we support.
77255570Strasz */
78255570Strasz#define	CTL_MAX_INITIATORS	(CTL_MAX_INIT_PER_PORT * CTL_MAX_PORTS)
79255570Strasz
80255570Strasz/* Hopefully this won't conflict with new misc devices that pop up */
81255570Strasz#define	CTL_MINOR	225
82255570Strasz
83255570Strasztypedef enum {
84255570Strasz	CTL_DELAY_TYPE_NONE,
85255570Strasz	CTL_DELAY_TYPE_CONT,
86255570Strasz	CTL_DELAY_TYPE_ONESHOT
87255570Strasz} ctl_delay_type;
88255570Strasz
89255570Strasztypedef enum {
90255570Strasz	CTL_DELAY_LOC_NONE,
91255570Strasz	CTL_DELAY_LOC_DATAMOVE,
92255570Strasz	CTL_DELAY_LOC_DONE,
93255570Strasz} ctl_delay_location;
94255570Strasz
95255570Strasztypedef enum {
96255570Strasz	CTL_DELAY_STATUS_NONE,
97255570Strasz	CTL_DELAY_STATUS_OK,
98255570Strasz	CTL_DELAY_STATUS_INVALID_LUN,
99255570Strasz	CTL_DELAY_STATUS_INVALID_TYPE,
100255570Strasz	CTL_DELAY_STATUS_INVALID_LOC,
101255570Strasz	CTL_DELAY_STATUS_NOT_IMPLEMENTED
102255570Strasz} ctl_delay_status;
103255570Strasz
104255570Straszstruct ctl_io_delay_info {
105255570Strasz	uint32_t		lun_id;
106255570Strasz	ctl_delay_type		delay_type;
107255570Strasz	ctl_delay_location	delay_loc;
108255570Strasz	uint32_t		delay_secs;
109255570Strasz	ctl_delay_status	status;
110255570Strasz};
111255570Strasz
112255570Strasztypedef enum {
113255570Strasz	CTL_STATS_NO_IO,
114255570Strasz	CTL_STATS_READ,
115255570Strasz	CTL_STATS_WRITE
116255570Strasz} ctl_stat_types;
117255570Strasz#define	CTL_STATS_NUM_TYPES	3
118255570Strasz
119255570Strasztypedef enum {
120255570Strasz	CTL_LUN_STATS_NO_BLOCKSIZE	= 0x01
121255570Strasz} ctl_lun_stats_flags;
122255570Strasz
123255570Straszstruct ctl_lun_io_port_stats {
124255570Strasz	uint32_t			targ_port;
125255570Strasz	uint64_t			bytes[CTL_STATS_NUM_TYPES];
126255570Strasz	uint64_t			operations[CTL_STATS_NUM_TYPES];
127255570Strasz	struct bintime			time[CTL_STATS_NUM_TYPES];
128255570Strasz	uint64_t			num_dmas[CTL_STATS_NUM_TYPES];
129255570Strasz	struct bintime			dma_time[CTL_STATS_NUM_TYPES];
130255570Strasz};
131255570Strasz
132255570Straszstruct ctl_lun_io_stats {
133255570Strasz	uint8_t				device_type;
134255570Strasz	uint64_t			lun_number;
135255570Strasz	uint32_t			blocksize;
136255570Strasz	ctl_lun_stats_flags		flags;
137255570Strasz	struct ctl_lun_io_port_stats	ports[CTL_MAX_PORTS];
138255570Strasz};
139255570Strasz
140255570Strasztypedef enum {
141255570Strasz	CTL_SS_OK,
142255570Strasz	CTL_SS_NEED_MORE_SPACE,
143255570Strasz	CTL_SS_ERROR
144255570Strasz} ctl_stats_status;
145255570Strasz
146255570Strasztypedef enum {
147255570Strasz	CTL_STATS_FLAG_NONE		= 0x00,
148255570Strasz	CTL_STATS_FLAG_TIME_VALID	= 0x01
149255570Strasz} ctl_stats_flags;
150255570Strasz
151255570Straszstruct ctl_stats {
152255570Strasz	int			alloc_len;	/* passed to kernel */
153255570Strasz	struct ctl_lun_io_stats	*lun_stats;	/* passed to/from kernel */
154255570Strasz	int			fill_len;	/* passed to userland */
155255570Strasz	int			num_luns;	/* passed to userland */
156255570Strasz	ctl_stats_status	status;		/* passed to userland */
157255570Strasz	ctl_stats_flags		flags;		/* passed to userland */
158255570Strasz	struct timespec		timestamp;	/* passed to userland */
159255570Strasz};
160255570Strasz
161269065Smav/*
162269065Smav * The types of errors that can be injected:
163269065Smav *
164269065Smav * NONE:	No error specified.
165269065Smav * ABORTED:	SSD_KEY_ABORTED_COMMAND, 0x45, 0x00
166269065Smav * MEDIUM_ERR:	Medium error, different asc/ascq depending on read/write.
167269065Smav * UA:		Unit attention.
168269065Smav * CUSTOM:	User specifies the sense data.
169269065Smav * TYPE:	Mask to use with error types.
170269065Smav *
171269065Smav * Flags that affect injection behavior:
172269065Smav * CONTINUOUS:	This error will stay around until explicitly cleared.
173269065Smav * DESCRIPTOR:	Use descriptor sense instead of fixed sense.
174269065Smav */
175269065Smavtypedef enum {
176269065Smav	CTL_LUN_INJ_NONE		= 0x000,
177269065Smav	CTL_LUN_INJ_ABORTED		= 0x001,
178269065Smav	CTL_LUN_INJ_MEDIUM_ERR		= 0x002,
179269065Smav	CTL_LUN_INJ_UA			= 0x003,
180269065Smav	CTL_LUN_INJ_CUSTOM		= 0x004,
181269065Smav	CTL_LUN_INJ_TYPE		= 0x0ff,
182269065Smav	CTL_LUN_INJ_CONTINUOUS		= 0x100,
183269065Smav	CTL_LUN_INJ_DESCRIPTOR		= 0x200
184269065Smav} ctl_lun_error;
185274870Strasz
186269065Smav/*
187269065Smav * Flags to specify what type of command the given error pattern will
188269065Smav * execute on.  The first group of types can be ORed together.
189269065Smav *
190269065Smav * READ:	Any read command.
191269065Smav * WRITE:	Any write command.
192269065Smav * READWRITE:	Any read or write command.
193269065Smav * READCAP:	Any read capacity command.
194269065Smav * TUR:		Test Unit Ready.
195269065Smav * ANY:		Any command.
196269065Smav * MASK:	Mask for basic command patterns.
197269065Smav *
198269065Smav * Special types:
199269065Smav *
200269065Smav * CMD:		The CDB to act on is specified in struct ctl_error_desc_cmd.
201269065Smav * RANGE:	For read/write commands, act when the LBA is in the
202269065Smav *		specified range.
203269065Smav */
204269065Smavtypedef enum {
205269065Smav	CTL_LUN_PAT_NONE	= 0x000,
206269065Smav	CTL_LUN_PAT_READ	= 0x001,
207269065Smav	CTL_LUN_PAT_WRITE	= 0x002,
208269065Smav	CTL_LUN_PAT_READWRITE	= CTL_LUN_PAT_READ | CTL_LUN_PAT_WRITE,
209269065Smav	CTL_LUN_PAT_READCAP	= 0x004,
210269065Smav	CTL_LUN_PAT_TUR		= 0x008,
211269065Smav	CTL_LUN_PAT_ANY		= 0x0ff,
212269065Smav	CTL_LUN_PAT_MASK	= 0x0ff,
213275259Strasz	CTL_LUN_PAT_CMD		= 0x100,
214269065Smav	CTL_LUN_PAT_RANGE	= 0x200
215269065Smav} ctl_lun_error_pattern;
216255570Strasz
217269069Smav/*
218255570Strasz * This structure allows the user to specify a particular CDB pattern to
219255570Strasz * look for.
220255570Strasz *
221255570Strasz * cdb_pattern:		Fill in the relevant bytes to look for in the CDB.
222269069Smav * cdb_valid_bytes:	Bitmask specifying valid bytes in the cdb_pattern.
223255570Strasz * flags:		Specify any command flags (see ctl_io_flags) that
224255570Strasz *			should be set.
225255570Strasz */
226255570Straszstruct ctl_error_desc_cmd {
227255570Strasz	uint8_t		cdb_pattern[CTL_MAX_CDBLEN];
228255570Strasz	uint32_t	cdb_valid_bytes;
229255570Strasz	uint32_t	flags;
230255570Strasz};
231255570Strasz
232255570Strasz/*
233255570Strasz * Error injection descriptor.
234255570Strasz *
235255570Strasz * lun_id	   LUN to act on.
236255570Strasz * lun_error:	   The type of error to inject.  See above for descriptions.
237255570Strasz * error_pattern:  What kind of command to act on.  See above.
238255570Strasz * cmd_desc:	   For CTL_LUN_PAT_CMD only.
239255570Strasz * lba_range:	   For CTL_LUN_PAT_RANGE only.
240255570Strasz * custom_sense:   Specify sense.  For CTL_LUN_INJ_CUSTOM only.
241255570Strasz * serial:	   Serial number returned by the kernel.  Use for deletion.
242269065Smav * links:	   Kernel use only.
243269065Smav */
244269065Smavstruct ctl_error_desc {
245269065Smav	uint32_t			lun_id;		/* To kernel */
246269065Smav	ctl_lun_error			lun_error;	/* To kernel */
247255570Strasz	ctl_lun_error_pattern		error_pattern;	/* To kernel */
248255570Strasz	struct ctl_error_desc_cmd	cmd_desc;	/* To kernel */
249255570Strasz	struct ctl_lba_len		lba_range;	/* To kernel */
250255570Strasz	struct scsi_sense_data		custom_sense;	/* To kernel */
251255570Strasz	uint64_t			serial;		/* From kernel */
252255570Strasz	STAILQ_ENTRY(ctl_error_desc)	links;		/* Kernel use only */
253255570Strasz};
254255570Strasz
255255570Strasztypedef enum {
256255570Strasz	CTL_OOA_FLAG_NONE	= 0x00,
257255570Strasz	CTL_OOA_FLAG_ALL_LUNS	= 0x01
258255570Strasz} ctl_ooa_flags;
259255570Strasz
260276613Smavtypedef enum {
261255570Strasz	CTL_OOA_OK,
262255570Strasz	CTL_OOA_NEED_MORE_SPACE,
263268703Smav	CTL_OOA_ERROR
264255570Strasz} ctl_get_ooa_status;
265255570Strasz
266269069Smavtypedef enum {
267269069Smav	CTL_OOACMD_FLAG_NONE		= 0x00,
268255570Strasz	CTL_OOACMD_FLAG_DMA		= 0x01,
269255570Strasz	CTL_OOACMD_FLAG_BLOCKED		= 0x02,
270255570Strasz	CTL_OOACMD_FLAG_ABORT		= 0x04,
271255570Strasz	CTL_OOACMD_FLAG_RTR		= 0x08,
272269068Smav	CTL_OOACMD_FLAG_DMA_QUEUED	= 0x10
273255570Strasz} ctl_ooa_cmd_flags;
274255570Strasz
275255570Straszstruct ctl_ooa_entry {
276269068Smav	ctl_ooa_cmd_flags	cmd_flags;
277255570Strasz	uint8_t			cdb[CTL_MAX_CDBLEN];
278255570Strasz	uint8_t			cdb_len;
279255570Strasz	uint32_t		tag_num;
280255570Strasz	uint32_t		lun_num;
281255570Strasz	struct bintime		start_bt;
282269068Smav};
283255570Strasz
284269068Smavstruct ctl_ooa {
285269068Smav	ctl_ooa_flags		flags;		/* passed to kernel */
286269068Smav	uint64_t		lun_num;	/* passed to kernel */
287269068Smav	uint32_t		alloc_len;	/* passed to kernel */
288269068Smav	uint32_t		alloc_num;	/* passed to kernel */
289269068Smav	struct ctl_ooa_entry	*entries;	/* filled in kernel */
290269068Smav	uint32_t		fill_len;	/* passed to userland */
291269068Smav	uint32_t		fill_num;	/* passed to userland */
292269068Smav	uint32_t		dropped_num;	/* passed to userland */
293269068Smav	struct bintime		cur_bt;		/* passed to userland */
294269068Smav	ctl_get_ooa_status	status;		/* passed to userland */
295269068Smav};
296269068Smav
297269068Smavtypedef enum {
298255570Strasz	CTL_LUN_NOSTATUS,
299268703Smav	CTL_LUN_OK,
300255570Strasz	CTL_LUN_ERROR,
301255570Strasz	CTL_LUN_WARNING
302255570Strasz} ctl_lun_status;
303255570Strasz
304255570Strasz#define	CTL_ERROR_STR_LEN	160
305255570Strasz
306255570Strasz#define	CTL_BEARG_RD		0x01
307255570Strasz#define	CTL_BEARG_WR		0x02
308255570Strasz#define	CTL_BEARG_RW		(CTL_BEARG_RD|CTL_BEARG_WR)
309255570Strasz#define	CTL_BEARG_ASCII		0x04
310255570Strasz
311255570Strasz/*
312255570Strasz * Backend Argument:
313255570Strasz *
314255570Strasz * namelen:	Length of the name field, including the terminating NUL.
315255570Strasz *
316255570Strasz * name:	Name of the parameter.  This must be NUL-terminated.
317255570Strasz *
318255570Strasz * flags:	Flags for the parameter, see above for values.
319255570Strasz *
320255570Strasz * vallen:	Length of the value in bytes.
321255570Strasz *
322255570Strasz * value:	Value to be set/fetched.
323255570Strasz *
324255570Strasz * kname:	For kernel use only.
325255570Strasz *
326255570Strasz * kvalue:	For kernel use only.
327255570Strasz */
328255570Straszstruct ctl_be_arg {
329255570Strasz	int	namelen;
330255570Strasz	char	*name;
331255570Strasz	int	flags;
332255570Strasz	int	vallen;
333255570Strasz	void	*value;
334255570Strasz
335255570Strasz	char	*kname;
336255570Strasz	void	*kvalue;
337255570Strasz};
338255570Strasz
339255570Strasztypedef enum {
340255570Strasz	CTL_LUNREQ_CREATE,
341255570Strasz	CTL_LUNREQ_RM,
342255570Strasz	CTL_LUNREQ_MODIFY,
343255570Strasz} ctl_lunreq_type;
344255570Strasz
345255570Strasz
346255570Strasz/*
347255570Strasz * LUN creation parameters:
348255570Strasz *
349255570Strasz * flags:		Various LUN flags, see ctl_backend.h for a
350255570Strasz *			description of the flag values and meanings.
351255570Strasz *
352255570Strasz * device_type:		The SCSI device type.  e.g. 0 for Direct Access,
353255570Strasz *			3 for Processor, etc.  Only certain backends may
354255570Strasz *			support setting this field.  The CTL_LUN_FLAG_DEV_TYPE
355255570Strasz *			flag should be set in the flags field if the device
356255570Strasz *			type is set.
357255570Strasz *
358255570Strasz * lun_size_bytes:	The size of the LUN in bytes.  For some backends
359255570Strasz *			this is relevant (e.g. ramdisk), for others, it may
360255570Strasz *			be ignored in favor of using the properties of the
361255570Strasz *			backing store.  If specified, this should be a
362255570Strasz *			multiple of the blocksize.
363255570Strasz *
364255570Strasz *			The actual size of the LUN is returned in this
365255570Strasz *			field.
366255570Strasz *
367255570Strasz * blocksize_bytes:	The LUN blocksize in bytes.  For some backends this
368255570Strasz *			is relevant, for others it may be ignored in
369255570Strasz *			favor of using the properties of the backing store.
370255570Strasz *
371255570Strasz *			The actual blocksize of the LUN is returned in this
372255570Strasz *			field.
373255570Strasz *
374255570Strasz * req_lun_id:		The requested LUN ID.  The CTL_LUN_FLAG_ID_REQ flag
375255570Strasz *			should be set if this is set.  The request will be
376255570Strasz *			granted if the LUN number is available, otherwise
377255570Strasz * 			the LUN addition request will fail.
378255570Strasz *
379255570Strasz *			The allocated LUN number is returned in this field.
380255570Strasz *
381255570Strasz * serial_num:		This is the value returned in SCSI INQUIRY VPD page
382255570Strasz *			0x80.  If it is specified, the CTL_LUN_FLAG_SERIAL_NUM
383255570Strasz *			flag should be set.
384255570Strasz *
385255570Strasz *			The serial number value used is returned in this
386255570Strasz *			field.
387255570Strasz *
388255570Strasz * device_id:		This is the value returned in the T10 vendor ID
389255570Strasz *			based DESIGNATOR field in the SCSI INQUIRY VPD page
390255570Strasz *			0x83 data.  If it is specified, the CTL_LUN_FLAG_DEVID
391276234Smav *			flag should be set.
392276234Smav *
393276234Smav *			The device id value used is returned in this field.
394276234Smav */
395276234Smavstruct ctl_lun_create_params {
396255570Strasz	ctl_backend_lun_flags	flags;
397255570Strasz	uint8_t			device_type;
398255570Strasz	uint64_t		lun_size_bytes;
399255570Strasz	uint32_t		blocksize_bytes;
400255570Strasz	uint32_t		req_lun_id;
401255570Strasz	uint8_t			serial_num[CTL_SN_LEN];
402255570Strasz	uint8_t			device_id[CTL_DEVID_LEN];
403255570Strasz};
404255570Strasz
405255570Strasz/*
406255570Strasz * LUN removal parameters:
407255570Strasz *
408255570Strasz * lun_id:		The number of the LUN to delete.  This must be set.
409255570Strasz *			The LUN must be backed by the given backend.
410255570Strasz */
411255570Straszstruct ctl_lun_rm_params {
412255570Strasz	uint32_t		lun_id;
413255570Strasz};
414255570Strasz
415255570Strasz/*
416255570Strasz * LUN modification parameters:
417255570Strasz *
418255570Strasz * lun_id:		The number of the LUN to modify.  This must be set.
419255570Strasz *			The LUN must be backed by the given backend.
420255570Strasz *
421255570Strasz * lun_size_bytes:	The size of the LUN in bytes.  If zero, update
422255570Strasz * 			the size using the backing file size, if possible.
423255570Strasz */
424255570Straszstruct ctl_lun_modify_params {
425255570Strasz	uint32_t		lun_id;
426255570Strasz	uint64_t		lun_size_bytes;
427255570Strasz};
428255570Strasz
429255570Strasz/*
430255570Strasz * Union of request type data.  Fill in the appropriate union member for
431255570Strasz * the request type.
432255570Strasz */
433255570Straszunion ctl_lunreq_data {
434255570Strasz	struct ctl_lun_create_params	create;
435255570Strasz	struct ctl_lun_rm_params	rm;
436255570Strasz	struct ctl_lun_modify_params	modify;
437255570Strasz};
438271706Strasz
439255570Strasz/*
440269067Smav * LUN request interface:
441269068Smav *
442255570Strasz * backend:		This is required, and is NUL-terminated a string
443255678Strasz *			that is the name of the backend, like "ramdisk" or
444255678Strasz *			"block".
445255678Strasz *
446255678Strasz * reqtype:		The type of request, CTL_LUNREQ_CREATE to create a
447255570Strasz *			LUN, CTL_LUNREQ_RM to delete a LUN.
448255570Strasz *
449255570Strasz * reqdata:		Request type-specific information.  See the
450255678Strasz *			description of individual the union members above
451255678Strasz *			for more information.
452255570Strasz *
453255570Strasz * num_be_args:		This is the number of backend-specific arguments
454255678Strasz *			in the be_args array.
455255678Strasz *
456255570Strasz * be_args:		This is an array of backend-specific arguments.
457255570Strasz *			See above for a description of the fields in this
458255570Strasz *			structure.
459276234Smav *
460255570Strasz * status:		Status of the LUN request.
461255570Strasz *
462255678Strasz * error_str:		If the status is CTL_LUN_ERROR, this will
463276234Smav *			contain a string describing the error.
464255678Strasz *
465255678Strasz * kern_be_args:	For kernel use only.
466255678Strasz */
467255570Straszstruct ctl_lun_req {
468255678Strasz	char			backend[CTL_BE_NAME_LEN];
469255570Strasz	ctl_lunreq_type		reqtype;
470255570Strasz	union ctl_lunreq_data	reqdata;
471255570Strasz	int			num_be_args;
472255570Strasz	struct ctl_be_arg	*be_args;
473255678Strasz	ctl_lun_status		status;
474255570Strasz	char			error_str[CTL_ERROR_STR_LEN];
475255570Strasz	struct ctl_be_arg	*kern_be_args;
476255570Strasz};
477255570Strasz
478255570Strasz/*
479255570Strasz * LUN list status:
480255570Strasz *
481269069Smav * NONE:		No status.
482255570Strasz *
483255570Strasz * OK:			Request completed successfully.
484255570Strasz *
485255570Strasz * NEED_MORE_SPACE:	The allocated length of the entries field is too
486255570Strasz * 			small for the available data.
487255570Strasz *
488255570Strasz * ERROR:		An error occurred, look at the error string for a
489255570Strasz *			description of the error.
490255570Strasz */
491255570Strasztypedef enum {
492271706Strasz	CTL_LUN_LIST_NONE,
493271706Strasz	CTL_LUN_LIST_OK,
494271706Strasz	CTL_LUN_LIST_NEED_MORE_SPACE,
495271706Strasz	CTL_LUN_LIST_ERROR
496271706Strasz} ctl_lun_list_status;
497271706Strasz
498271706Strasz/*
499271706Strasz * LUN list interface
500271706Strasz *
501271706Strasz * backend_name:	This is a NUL-terminated string.  If the string
502271706Strasz *			length is 0, then all LUNs on all backends will
503271706Strasz *			be enumerated.  Otherwise this is the name of the
504271706Strasz *			backend to be enumerated, like "ramdisk" or "block".
505271706Strasz *
506271706Strasz * alloc_len:		The length of the data buffer allocated for entries.
507271706Strasz *			In order to properly size the buffer, make one call
508271706Strasz *			with alloc_len set to 0, and then use the returned
509271706Strasz *			dropped_len as the buffer length to allocate and
510271706Strasz *			pass in on a subsequent call.
511271706Strasz *
512271706Strasz * lun_xml:		XML-formatted information on the requested LUNs.
513271706Strasz *
514271706Strasz * fill_len:		The amount of data filled in the storage for entries.
515271706Strasz *
516271706Strasz * status:		The status of the request.  See above for the
517271706Strasz *			description of the values of this field.
518271706Strasz *
519271706Strasz * error_str:		If the status indicates an error, this string will
520271706Strasz *			be filled in to describe the error.
521255570Strasz */
522255570Straszstruct ctl_lun_list {
523271706Strasz	char			backend[CTL_BE_NAME_LEN]; /* passed to kernel*/
524255570Strasz	uint32_t		alloc_len;	/* passed to kernel */
525269067Smav	char                   *lun_xml;	/* filled in kernel */
526255570Strasz	uint32_t		fill_len;	/* passed to userland */
527255570Strasz	ctl_lun_list_status	status;		/* passed to userland */
528255570Strasz	char			error_str[CTL_ERROR_STR_LEN];
529255570Strasz						/* passed to userland */
530255570Strasz};
531255570Strasz
532255570Strasz/*
533255570Strasz * Port request interface:
534255570Strasz *
535269068Smav * driver:		This is required, and is NUL-terminated a string
536255570Strasz *			that is the name of the frontend, like "iscsi" .
537255570Strasz *
538255570Strasz * reqtype:		The type of request, CTL_REQ_CREATE to create a
539255570Strasz *			port, CTL_REQ_REMOVE to delete a port.
540255570Strasz *
541255570Strasz * num_be_args:		This is the number of frontend-specific arguments
542255570Strasz *			in the be_args array.
543255570Strasz *
544255570Strasz * be_args:		This is an array of frontend-specific arguments.
545255570Strasz *			See above for a description of the fields in this
546255570Strasz *			structure.
547255570Strasz *
548255570Strasz * status:		Status of the request.
549255570Strasz *
550274866Strasz * error_str:		If the status is CTL_LUN_ERROR, this will
551255570Strasz *			contain a string describing the error.
552274866Strasz *
553274866Strasz * kern_be_args:	For kernel use only.
554274866Strasz */
555255570Strasztypedef enum {
556255570Strasz	CTL_REQ_CREATE,
557255570Strasz	CTL_REQ_REMOVE,
558255570Strasz	CTL_REQ_MODIFY,
559255570Strasz} ctl_req_type;
560255570Strasz
561255570Straszstruct ctl_req {
562255570Strasz	char			driver[CTL_DRIVER_NAME_LEN];
563255570Strasz	ctl_req_type		reqtype;
564255570Strasz	int			num_args;
565255570Strasz	struct ctl_be_arg	*args;
566255570Strasz	ctl_lun_status		status;
567255570Strasz	char			error_str[CTL_ERROR_STR_LEN];
568255570Strasz	struct ctl_be_arg	*kern_args;
569255570Strasz};
570255570Strasz
571255570Strasz/*
572255570Strasz * iSCSI status
573255570Strasz *
574255570Strasz * OK:			Request completed successfully.
575255570Strasz *
576255570Strasz * ERROR:		An error occurred, look at the error string for a
577255570Strasz *			description of the error.
578255570Strasz *
579255570Strasz * CTL_ISCSI_LIST_NEED_MORE_SPACE:
580255570Strasz * 			User has to pass larger buffer for CTL_ISCSI_LIST ioctl.
581255570Strasz */
582274866Strasztypedef enum {
583255570Strasz	CTL_ISCSI_OK,
584255570Strasz	CTL_ISCSI_ERROR,
585274866Strasz	CTL_ISCSI_LIST_NEED_MORE_SPACE,
586255570Strasz	CTL_ISCSI_SESSION_NOT_FOUND
587274866Strasz} ctl_iscsi_status;
588274866Strasz
589274866Strasztypedef enum {
590274866Strasz	CTL_ISCSI_HANDOFF,
591274866Strasz	CTL_ISCSI_LIST,
592274866Strasz	CTL_ISCSI_LOGOUT,
593274866Strasz	CTL_ISCSI_TERMINATE,
594274866Strasz#if defined(ICL_KERNEL_PROXY) || 1
595274866Strasz	/*
596255570Strasz	 * We actually need those in all cases, but leave the ICL_KERNEL_PROXY,
597255570Strasz	 * to remember to remove them along with rest of proxy code, eventually.
598269068Smav	 */
599255570Strasz	CTL_ISCSI_LISTEN,
600255570Strasz	CTL_ISCSI_ACCEPT,
601255570Strasz	CTL_ISCSI_SEND,
602255570Strasz	CTL_ISCSI_RECEIVE,
603255570Strasz#endif
604255570Strasz} ctl_iscsi_type;
605255570Strasz
606255570Strasztypedef enum {
607255570Strasz	CTL_ISCSI_DIGEST_NONE,
608255570Strasz	CTL_ISCSI_DIGEST_CRC32C
609255570Strasz} ctl_iscsi_digest;
610255570Strasz
611274866Strasz#define	CTL_ISCSI_NAME_LEN	224	/* 223 bytes, by RFC 3720, + '\0' */
612255570Strasz#define	CTL_ISCSI_ADDR_LEN	47	/* INET6_ADDRSTRLEN + '\0' */
613274866Strasz#define	CTL_ISCSI_ALIAS_LEN	128	/* Arbitrary. */
614274866Strasz
615274866Straszstruct ctl_iscsi_handoff_params {
616274866Strasz	char			initiator_name[CTL_ISCSI_NAME_LEN];
617255570Strasz	char			initiator_addr[CTL_ISCSI_ADDR_LEN];
618255570Strasz	char			initiator_alias[CTL_ISCSI_ALIAS_LEN];
619274866Strasz	uint8_t			initiator_isid[6];
620255570Strasz	char			target_name[CTL_ISCSI_NAME_LEN];
621255570Strasz	int			socket;
622255570Strasz	int			portal_group_tag;
623255570Strasz
624255570Strasz	/*
625255570Strasz	 * Connection parameters negotiated by ctld(8).
626255570Strasz	 */
627255570Strasz	ctl_iscsi_digest	header_digest;
628255570Strasz	ctl_iscsi_digest	data_digest;
629255570Strasz	uint32_t		cmdsn;
630255570Strasz	uint32_t		statsn;
631255570Strasz	uint32_t		max_recv_data_segment_length;
632255570Strasz	uint32_t		max_burst_length;
633255570Strasz	uint32_t		first_burst_length;
634255570Strasz	uint32_t		immediate_data;
635255570Strasz#ifdef ICL_KERNEL_PROXY
636255570Strasz	int			connection_id;
637255570Strasz	int			spare[3];
638255570Strasz#else
639255570Strasz	int			spare[4];
640255570Strasz#endif
641255570Strasz};
642255570Strasz
643255570Straszstruct ctl_iscsi_list_params {
644255570Strasz	uint32_t		alloc_len;	/* passed to kernel */
645255570Strasz	char                   *conn_xml;	/* filled in kernel */
646255570Strasz	uint32_t		fill_len;	/* passed to userland */
647255570Strasz	int			spare[4];
648255570Strasz};
649274866Strasz
650274866Straszstruct ctl_iscsi_logout_params {
651274866Strasz	int			connection_id;	/* passed to kernel */
652274866Strasz	char			initiator_name[CTL_ISCSI_NAME_LEN];
653255570Strasz						/* passed to kernel */
654255570Strasz	char			initiator_addr[CTL_ISCSI_ADDR_LEN];
655255570Strasz						/* passed to kernel */
656255570Strasz	int			all;		/* passed to kernel */
657255570Strasz	int			spare[4];
658274866Strasz};
659274866Strasz
660274866Straszstruct ctl_iscsi_terminate_params {
661255570Strasz	int			connection_id;	/* passed to kernel */
662255570Strasz	char			initiator_name[CTL_ISCSI_NAME_LEN];
663255570Strasz						/* passed to kernel */
664255570Strasz	char			initiator_addr[CTL_ISCSI_NAME_LEN];
665274866Strasz						/* passed to kernel */
666274866Strasz	int			all;		/* passed to kernel */
667274866Strasz	int			spare[4];
668255570Strasz};
669255570Strasz
670255570Strasz#ifdef ICL_KERNEL_PROXY
671255570Straszstruct ctl_iscsi_listen_params {
672255570Strasz	int				iser;
673255570Strasz	int				domain;
674255570Strasz	int				socktype;
675255570Strasz	int				protocol;
676255570Strasz	struct sockaddr			*addr;
677255570Strasz	socklen_t			addrlen;
678255570Strasz	int				portal_id;
679255570Strasz	int				spare[4];
680255570Strasz};
681269069Smav
682255570Straszstruct ctl_iscsi_accept_params {
683255570Strasz	int				connection_id;
684255570Strasz	int				portal_id;
685255570Strasz	struct sockaddr			*initiator_addr;
686255570Strasz	socklen_t			initiator_addrlen;
687255570Strasz	int				spare[4];
688255570Strasz};
689255570Strasz
690255570Straszstruct ctl_iscsi_send_params {
691255570Strasz	int				connection_id;
692269069Smav	void				*bhs;
693255570Strasz	size_t				spare;
694255570Strasz	void				*spare2;
695255570Strasz	size_t				data_segment_len;
696255570Strasz	void				*data_segment;
697255570Strasz	int				spare3[4];
698255570Strasz};
699255570Strasz
700255570Straszstruct ctl_iscsi_receive_params {
701255570Strasz	int				connection_id;
702255570Strasz	void				*bhs;
703255570Strasz	size_t				spare;
704255570Strasz	void				*spare2;
705255570Strasz	size_t				data_segment_len;
706255570Strasz	void				*data_segment;
707255570Strasz	int				spare3[4];
708255570Strasz};
709255570Strasz
710269068Smav#endif /* ICL_KERNEL_PROXY */
711255570Strasz
712255678Straszunion ctl_iscsi_data {
713255678Strasz	struct ctl_iscsi_handoff_params		handoff;
714255678Strasz	struct ctl_iscsi_list_params		list;
715255678Strasz	struct ctl_iscsi_logout_params		logout;
716255678Strasz	struct ctl_iscsi_terminate_params	terminate;
717255678Strasz#ifdef ICL_KERNEL_PROXY
718255678Strasz	struct ctl_iscsi_listen_params		listen;
719255678Strasz	struct ctl_iscsi_accept_params		accept;
720255678Strasz	struct ctl_iscsi_send_params		send;
721255678Strasz	struct ctl_iscsi_receive_params		receive;
722255678Strasz#endif
723255678Strasz};
724255678Strasz
725255678Strasz/*
726255678Strasz * iSCSI interface
727255678Strasz *
728255678Strasz * status:		The status of the request.  See above for the
729255678Strasz *			description of the values of this field.
730255570Strasz *
731255678Strasz * error_str:		If the status indicates an error, this string will
732255570Strasz *			be filled in to describe the error.
733255570Strasz */
734255570Straszstruct ctl_iscsi {
735255570Strasz	ctl_iscsi_type		type;		/* passed to kernel */
736255570Strasz	union ctl_iscsi_data	data;		/* passed to kernel */
737255570Strasz	ctl_iscsi_status	status;		/* passed to userland */
738255570Strasz	char			error_str[CTL_ERROR_STR_LEN];
739255570Strasz						/* passed to userland */
740255570Strasz};
741255570Strasz
742255570Straszstruct ctl_lun_map {
743255570Strasz	uint32_t		port;
744255570Strasz	uint32_t		plun;
745255570Strasz	uint32_t		lun;
746255570Strasz};
747255570Strasz
748255570Strasz#define	CTL_IO			_IOWR(CTL_MINOR, 0x00, union ctl_io)
749255570Strasz#define	CTL_ENABLE_PORT		_IOW(CTL_MINOR, 0x04, struct ctl_port_entry)
750269069Smav#define	CTL_DISABLE_PORT	_IOW(CTL_MINOR, 0x05, struct ctl_port_entry)
751255570Strasz#define	CTL_DELAY_IO		_IOWR(CTL_MINOR, 0x10, struct ctl_io_delay_info)
752255570Strasz#define	CTL_GETSTATS		_IOWR(CTL_MINOR, 0x15, struct ctl_stats)
753255570Strasz#define	CTL_ERROR_INJECT	_IOWR(CTL_MINOR, 0x16, struct ctl_error_desc)
754255570Strasz#define	CTL_GET_OOA		_IOWR(CTL_MINOR, 0x18, struct ctl_ooa)
755255570Strasz#define	CTL_DUMP_STRUCTS	_IO(CTL_MINOR, 0x19)
756255570Strasz#define	CTL_LUN_REQ		_IOWR(CTL_MINOR, 0x21, struct ctl_lun_req)
757255570Strasz#define	CTL_LUN_LIST		_IOWR(CTL_MINOR, 0x22, struct ctl_lun_list)
758255570Strasz#define	CTL_ERROR_INJECT_DELETE	_IOW(CTL_MINOR, 0x23, struct ctl_error_desc)
759255570Strasz#define	CTL_SET_PORT_WWNS	_IOW(CTL_MINOR, 0x24, struct ctl_port_entry)
760255570Strasz#define	CTL_ISCSI		_IOWR(CTL_MINOR, 0x25, struct ctl_iscsi)
761255570Strasz#define	CTL_PORT_REQ		_IOWR(CTL_MINOR, 0x26, struct ctl_req)
762255570Strasz#define	CTL_PORT_LIST		_IOWR(CTL_MINOR, 0x27, struct ctl_lun_list)
763255570Strasz#define	CTL_LUN_MAP		_IOW(CTL_MINOR, 0x28, struct ctl_lun_map)
764274870Strasz
765274870Strasz#endif /* _CTL_IOCTL_H_ */
766255570Strasz
767255570Strasz/*
768255570Strasz * vim: ts=8
769255570Strasz */
770255570Strasz