2 * Copyright (c) 2003 Silicon Graphics International Corp.
3 * Copyright (c) 2011 Spectra Logic Corporation
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13 * substantially similar to the "NO WARRANTY" disclaimer below
14 * ("Disclaimer") and any redistribution must be conditioned upon
15 * including a substantially similar Disclaimer requirement for further
16 * binary redistribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGES.
31 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ioctl.h#4 $
35 * CAM Target Layer ioctl interface.
37 * Author: Ken Merry <ken@FreeBSD.org>
43 #ifdef ICL_KERNEL_PROXY
44 #include <sys/socket.h>
47 #include <sys/ioccom.h>
49 #define CTL_DEFAULT_DEV "/dev/cam/ctl"
51 * Maximum number of targets we support.
53 #define CTL_MAX_TARGETS 1
56 * Maximum target ID we support.
58 #define CTL_MAX_TARGID 15
61 * Maximum number of LUNs we support at the moment. MUST be a power of 2.
63 #define CTL_MAX_LUNS 1024
66 * Maximum number of initiators per port.
68 #define CTL_MAX_INIT_PER_PORT 2048
71 * Maximum number of ports registered at one time.
73 #define CTL_MAX_PORTS 256
76 * Maximum number of initiators we support.
78 #define CTL_MAX_INITIATORS (CTL_MAX_INIT_PER_PORT * CTL_MAX_PORTS)
80 /* Hopefully this won't conflict with new misc devices that pop up */
86 CTL_DELAY_TYPE_ONESHOT
91 CTL_DELAY_LOC_DATAMOVE,
96 CTL_DELAY_STATUS_NONE,
98 CTL_DELAY_STATUS_INVALID_LUN,
99 CTL_DELAY_STATUS_INVALID_TYPE,
100 CTL_DELAY_STATUS_INVALID_LOC,
101 CTL_DELAY_STATUS_NOT_IMPLEMENTED
104 struct ctl_io_delay_info {
106 ctl_delay_type delay_type;
107 ctl_delay_location delay_loc;
109 ctl_delay_status status;
117 #define CTL_STATS_NUM_TYPES 3
120 CTL_LUN_STATS_NO_BLOCKSIZE = 0x01
121 } ctl_lun_stats_flags;
123 struct ctl_lun_io_port_stats {
125 uint64_t bytes[CTL_STATS_NUM_TYPES];
126 uint64_t operations[CTL_STATS_NUM_TYPES];
127 struct bintime time[CTL_STATS_NUM_TYPES];
128 uint64_t num_dmas[CTL_STATS_NUM_TYPES];
129 struct bintime dma_time[CTL_STATS_NUM_TYPES];
132 struct ctl_lun_io_stats {
136 ctl_lun_stats_flags flags;
137 struct ctl_lun_io_port_stats ports[CTL_MAX_PORTS];
142 CTL_SS_NEED_MORE_SPACE,
147 CTL_STATS_FLAG_NONE = 0x00,
148 CTL_STATS_FLAG_TIME_VALID = 0x01
152 int alloc_len; /* passed to kernel */
153 struct ctl_lun_io_stats *lun_stats; /* passed to/from kernel */
154 int fill_len; /* passed to userland */
155 int num_luns; /* passed to userland */
156 ctl_stats_status status; /* passed to userland */
157 ctl_stats_flags flags; /* passed to userland */
158 struct timespec timestamp; /* passed to userland */
162 * The types of errors that can be injected:
164 * NONE: No error specified.
165 * ABORTED: SSD_KEY_ABORTED_COMMAND, 0x45, 0x00
166 * MEDIUM_ERR: Medium error, different asc/ascq depending on read/write.
167 * UA: Unit attention.
168 * CUSTOM: User specifies the sense data.
169 * TYPE: Mask to use with error types.
171 * Flags that affect injection behavior:
172 * CONTINUOUS: This error will stay around until explicitly cleared.
173 * DESCRIPTOR: Use descriptor sense instead of fixed sense.
176 CTL_LUN_INJ_NONE = 0x000,
177 CTL_LUN_INJ_ABORTED = 0x001,
178 CTL_LUN_INJ_MEDIUM_ERR = 0x002,
179 CTL_LUN_INJ_UA = 0x003,
180 CTL_LUN_INJ_CUSTOM = 0x004,
181 CTL_LUN_INJ_TYPE = 0x0ff,
182 CTL_LUN_INJ_CONTINUOUS = 0x100,
183 CTL_LUN_INJ_DESCRIPTOR = 0x200
187 * Flags to specify what type of command the given error pattern will
188 * execute on. The first group of types can be ORed together.
190 * READ: Any read command.
191 * WRITE: Any write command.
192 * READWRITE: Any read or write command.
193 * READCAP: Any read capacity command.
194 * TUR: Test Unit Ready.
196 * MASK: Mask for basic command patterns.
200 * CMD: The CDB to act on is specified in struct ctl_error_desc_cmd.
201 * RANGE: For read/write commands, act when the LBA is in the
205 CTL_LUN_PAT_NONE = 0x000,
206 CTL_LUN_PAT_READ = 0x001,
207 CTL_LUN_PAT_WRITE = 0x002,
208 CTL_LUN_PAT_READWRITE = CTL_LUN_PAT_READ | CTL_LUN_PAT_WRITE,
209 CTL_LUN_PAT_READCAP = 0x004,
210 CTL_LUN_PAT_TUR = 0x008,
211 CTL_LUN_PAT_ANY = 0x0ff,
212 CTL_LUN_PAT_MASK = 0x0ff,
213 CTL_LUN_PAT_CMD = 0x100,
214 CTL_LUN_PAT_RANGE = 0x200
215 } ctl_lun_error_pattern;
218 * This structure allows the user to specify a particular CDB pattern to
221 * cdb_pattern: Fill in the relevant bytes to look for in the CDB.
222 * cdb_valid_bytes: Bitmask specifying valid bytes in the cdb_pattern.
223 * flags: Specify any command flags (see ctl_io_flags) that
226 struct ctl_error_desc_cmd {
227 uint8_t cdb_pattern[CTL_MAX_CDBLEN];
228 uint32_t cdb_valid_bytes;
233 * Error injection descriptor.
235 * lun_id LUN to act on.
236 * lun_error: The type of error to inject. See above for descriptions.
237 * error_pattern: What kind of command to act on. See above.
238 * cmd_desc: For CTL_LUN_PAT_CMD only.
239 * lba_range: For CTL_LUN_PAT_RANGE only.
240 * custom_sense: Specify sense. For CTL_LUN_INJ_CUSTOM only.
241 * serial: Serial number returned by the kernel. Use for deletion.
242 * links: Kernel use only.
244 struct ctl_error_desc {
245 uint32_t lun_id; /* To kernel */
246 ctl_lun_error lun_error; /* To kernel */
247 ctl_lun_error_pattern error_pattern; /* To kernel */
248 struct ctl_error_desc_cmd cmd_desc; /* To kernel */
249 struct ctl_lba_len lba_range; /* To kernel */
250 struct scsi_sense_data custom_sense; /* To kernel */
251 uint64_t serial; /* From kernel */
252 STAILQ_ENTRY(ctl_error_desc) links; /* Kernel use only */
256 CTL_OOA_FLAG_NONE = 0x00,
257 CTL_OOA_FLAG_ALL_LUNS = 0x01
262 CTL_OOA_NEED_MORE_SPACE,
264 } ctl_get_ooa_status;
267 CTL_OOACMD_FLAG_NONE = 0x00,
268 CTL_OOACMD_FLAG_DMA = 0x01,
269 CTL_OOACMD_FLAG_BLOCKED = 0x02,
270 CTL_OOACMD_FLAG_ABORT = 0x04,
271 CTL_OOACMD_FLAG_RTR = 0x08,
272 CTL_OOACMD_FLAG_DMA_QUEUED = 0x10
275 struct ctl_ooa_entry {
276 ctl_ooa_cmd_flags cmd_flags;
277 uint8_t cdb[CTL_MAX_CDBLEN];
281 struct bintime start_bt;
285 ctl_ooa_flags flags; /* passed to kernel */
286 uint64_t lun_num; /* passed to kernel */
287 uint32_t alloc_len; /* passed to kernel */
288 uint32_t alloc_num; /* passed to kernel */
289 struct ctl_ooa_entry *entries; /* filled in kernel */
290 uint32_t fill_len; /* passed to userland */
291 uint32_t fill_num; /* passed to userland */
292 uint32_t dropped_num; /* passed to userland */
293 struct bintime cur_bt; /* passed to userland */
294 ctl_get_ooa_status status; /* passed to userland */
304 #define CTL_ERROR_STR_LEN 160
306 #define CTL_BEARG_RD 0x01
307 #define CTL_BEARG_WR 0x02
308 #define CTL_BEARG_RW (CTL_BEARG_RD|CTL_BEARG_WR)
309 #define CTL_BEARG_ASCII 0x04
314 * namelen: Length of the name field, including the terminating NUL.
316 * name: Name of the paramter. This must be NUL-terminated.
318 * flags: Flags for the parameter, see above for values.
320 * vallen: Length of the value in bytes.
322 * value: Value to be set/fetched.
324 * kname: For kernel use only.
326 * kvalue: For kernel use only.
347 * LUN creation parameters:
349 * flags: Various LUN flags, see ctl_backend.h for a
350 * description of the flag values and meanings.
352 * device_type: The SCSI device type. e.g. 0 for Direct Access,
353 * 3 for Processor, etc. Only certain backends may
354 * support setting this field. The CTL_LUN_FLAG_DEV_TYPE
355 * flag should be set in the flags field if the device
358 * lun_size_bytes: The size of the LUN in bytes. For some backends
359 * this is relevant (e.g. ramdisk), for others, it may
360 * be ignored in favor of using the properties of the
361 * backing store. If specified, this should be a
362 * multiple of the blocksize.
364 * The actual size of the LUN is returned in this
367 * blocksize_bytes: The LUN blocksize in bytes. For some backends this
368 * is relevant, for others it may be ignored in
369 * favor of using the properties of the backing store.
371 * The actual blocksize of the LUN is returned in this
374 * req_lun_id: The requested LUN ID. The CTL_LUN_FLAG_ID_REQ flag
375 * should be set if this is set. The request will be
376 * granted if the LUN number is available, otherwise
377 * the LUN addition request will fail.
379 * The allocated LUN number is returned in this field.
381 * serial_num: This is the value returned in SCSI INQUIRY VPD page
382 * 0x80. If it is specified, the CTL_LUN_FLAG_SERIAL_NUM
383 * flag should be set.
385 * The serial number value used is returned in this
388 * device_id: This is the value returned in the T10 vendor ID
389 * based DESIGNATOR field in the SCSI INQUIRY VPD page
390 * 0x83 data. If it is specified, the CTL_LUN_FLAG_DEVID
391 * flag should be set.
393 * The device id value used is returned in this field.
395 struct ctl_lun_create_params {
396 ctl_backend_lun_flags flags;
398 uint64_t lun_size_bytes;
399 uint32_t blocksize_bytes;
401 uint8_t serial_num[CTL_SN_LEN];
402 uint8_t device_id[CTL_DEVID_LEN];
406 * LUN removal parameters:
408 * lun_id: The number of the LUN to delete. This must be set.
409 * The LUN must be backed by the given backend.
411 struct ctl_lun_rm_params {
416 * LUN modification parameters:
418 * lun_id: The number of the LUN to modify. This must be set.
419 * The LUN must be backed by the given backend.
421 * lun_size_bytes: The size of the LUN in bytes. If zero, update
422 * the size using the backing file size, if possible.
424 struct ctl_lun_modify_params {
426 uint64_t lun_size_bytes;
430 * Union of request type data. Fill in the appropriate union member for
433 union ctl_lunreq_data {
434 struct ctl_lun_create_params create;
435 struct ctl_lun_rm_params rm;
436 struct ctl_lun_modify_params modify;
440 * LUN request interface:
442 * backend: This is required, and is NUL-terminated a string
443 * that is the name of the backend, like "ramdisk" or
446 * reqtype: The type of request, CTL_LUNREQ_CREATE to create a
447 * LUN, CTL_LUNREQ_RM to delete a LUN.
449 * reqdata: Request type-specific information. See the
450 * description of individual the union members above
451 * for more information.
453 * num_be_args: This is the number of backend-specific arguments
454 * in the be_args array.
456 * be_args: This is an array of backend-specific arguments.
457 * See above for a description of the fields in this
460 * status: Status of the LUN request.
462 * error_str: If the status is CTL_LUN_ERROR, this will
463 * contain a string describing the error.
465 * kern_be_args: For kernel use only.
468 char backend[CTL_BE_NAME_LEN];
469 ctl_lunreq_type reqtype;
470 union ctl_lunreq_data reqdata;
472 struct ctl_be_arg *be_args;
473 ctl_lun_status status;
474 char error_str[CTL_ERROR_STR_LEN];
475 struct ctl_be_arg *kern_be_args;
483 * OK: Request completed successfully.
485 * NEED_MORE_SPACE: The allocated length of the entries field is too
486 * small for the available data.
488 * ERROR: An error occured, look at the error string for a
489 * description of the error.
494 CTL_LUN_LIST_NEED_MORE_SPACE,
496 } ctl_lun_list_status;
501 * backend_name: This is a NUL-terminated string. If the string
502 * length is 0, then all LUNs on all backends will
503 * be enumerated. Otherwise this is the name of the
504 * backend to be enumerated, like "ramdisk" or "block".
506 * alloc_len: The length of the data buffer allocated for entries.
507 * In order to properly size the buffer, make one call
508 * with alloc_len set to 0, and then use the returned
509 * dropped_len as the buffer length to allocate and
510 * pass in on a subsequent call.
512 * lun_xml: XML-formatted information on the requested LUNs.
514 * fill_len: The amount of data filled in the storage for entries.
516 * status: The status of the request. See above for the
517 * description of the values of this field.
519 * error_str: If the status indicates an error, this string will
520 * be filled in to describe the error.
522 struct ctl_lun_list {
523 char backend[CTL_BE_NAME_LEN]; /* passed to kernel*/
524 uint32_t alloc_len; /* passed to kernel */
525 char *lun_xml; /* filled in kernel */
526 uint32_t fill_len; /* passed to userland */
527 ctl_lun_list_status status; /* passed to userland */
528 char error_str[CTL_ERROR_STR_LEN];
529 /* passed to userland */
533 * Port request interface:
535 * driver: This is required, and is NUL-terminated a string
536 * that is the name of the frontend, like "iscsi" .
538 * reqtype: The type of request, CTL_REQ_CREATE to create a
539 * port, CTL_REQ_REMOVE to delete a port.
541 * num_be_args: This is the number of frontend-specific arguments
542 * in the be_args array.
544 * be_args: This is an array of frontend-specific arguments.
545 * See above for a description of the fields in this
548 * status: Status of the request.
550 * error_str: If the status is CTL_LUN_ERROR, this will
551 * contain a string describing the error.
553 * kern_be_args: For kernel use only.
562 char driver[CTL_DRIVER_NAME_LEN];
563 ctl_req_type reqtype;
565 struct ctl_be_arg *args;
566 ctl_lun_status status;
567 char error_str[CTL_ERROR_STR_LEN];
568 struct ctl_be_arg *kern_args;
574 * OK: Request completed successfully.
576 * ERROR: An error occured, look at the error string for a
577 * description of the error.
579 * CTL_ISCSI_LIST_NEED_MORE_SPACE:
580 * User has to pass larger buffer for CTL_ISCSI_LIST ioctl.
585 CTL_ISCSI_LIST_NEED_MORE_SPACE,
586 CTL_ISCSI_SESSION_NOT_FOUND
594 #if defined(ICL_KERNEL_PROXY) || 1
596 * We actually need those in all cases, but leave the ICL_KERNEL_PROXY,
597 * to remember to remove them along with rest of proxy code, eventually.
607 CTL_ISCSI_DIGEST_NONE,
608 CTL_ISCSI_DIGEST_CRC32C
611 #define CTL_ISCSI_NAME_LEN 224 /* 223 bytes, by RFC 3720, + '\0' */
612 #define CTL_ISCSI_ADDR_LEN 47 /* INET6_ADDRSTRLEN + '\0' */
613 #define CTL_ISCSI_ALIAS_LEN 128 /* Arbitrary. */
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];
622 int portal_group_tag;
625 * Connection parameters negotiated by ctld(8).
627 ctl_iscsi_digest header_digest;
628 ctl_iscsi_digest data_digest;
631 uint32_t max_recv_data_segment_length;
632 uint32_t max_burst_length;
633 uint32_t first_burst_length;
634 uint32_t immediate_data;
635 #ifdef ICL_KERNEL_PROXY
643 struct ctl_iscsi_list_params {
644 uint32_t alloc_len; /* passed to kernel */
645 char *conn_xml; /* filled in kernel */
646 uint32_t fill_len; /* passed to userland */
650 struct ctl_iscsi_logout_params {
651 int connection_id; /* passed to kernel */
652 char initiator_name[CTL_ISCSI_NAME_LEN];
653 /* passed to kernel */
654 char initiator_addr[CTL_ISCSI_ADDR_LEN];
655 /* passed to kernel */
656 int all; /* passed to kernel */
660 struct ctl_iscsi_terminate_params {
661 int connection_id; /* passed to kernel */
662 char initiator_name[CTL_ISCSI_NAME_LEN];
663 /* passed to kernel */
664 char initiator_addr[CTL_ISCSI_NAME_LEN];
665 /* passed to kernel */
666 int all; /* passed to kernel */
670 #ifdef ICL_KERNEL_PROXY
671 struct ctl_iscsi_listen_params {
676 struct sockaddr *addr;
682 struct ctl_iscsi_accept_params {
685 struct sockaddr *initiator_addr;
686 socklen_t initiator_addrlen;
690 struct ctl_iscsi_send_params {
695 size_t data_segment_len;
700 struct ctl_iscsi_receive_params {
705 size_t data_segment_len;
710 #endif /* ICL_KERNEL_PROXY */
712 union ctl_iscsi_data {
713 struct ctl_iscsi_handoff_params handoff;
714 struct ctl_iscsi_list_params list;
715 struct ctl_iscsi_logout_params logout;
716 struct ctl_iscsi_terminate_params terminate;
717 #ifdef ICL_KERNEL_PROXY
718 struct ctl_iscsi_listen_params listen;
719 struct ctl_iscsi_accept_params accept;
720 struct ctl_iscsi_send_params send;
721 struct ctl_iscsi_receive_params receive;
728 * status: The status of the request. See above for the
729 * description of the values of this field.
731 * error_str: If the status indicates an error, this string will
732 * be filled in to describe the error.
735 ctl_iscsi_type type; /* passed to kernel */
736 union ctl_iscsi_data data; /* passed to kernel */
737 ctl_iscsi_status status; /* passed to userland */
738 char error_str[CTL_ERROR_STR_LEN];
739 /* passed to userland */
748 #define CTL_IO _IOWR(CTL_MINOR, 0x00, union ctl_io)
749 #define CTL_ENABLE_PORT _IOW(CTL_MINOR, 0x04, struct ctl_port_entry)
750 #define CTL_DISABLE_PORT _IOW(CTL_MINOR, 0x05, struct ctl_port_entry)
751 #define CTL_DELAY_IO _IOWR(CTL_MINOR, 0x10, struct ctl_io_delay_info)
752 #define CTL_GETSTATS _IOWR(CTL_MINOR, 0x15, struct ctl_stats)
753 #define CTL_ERROR_INJECT _IOWR(CTL_MINOR, 0x16, struct ctl_error_desc)
754 #define CTL_GET_OOA _IOWR(CTL_MINOR, 0x18, struct ctl_ooa)
755 #define CTL_DUMP_STRUCTS _IO(CTL_MINOR, 0x19)
756 #define CTL_LUN_REQ _IOWR(CTL_MINOR, 0x21, struct ctl_lun_req)
757 #define CTL_LUN_LIST _IOWR(CTL_MINOR, 0x22, struct ctl_lun_list)
758 #define CTL_ERROR_INJECT_DELETE _IOW(CTL_MINOR, 0x23, struct ctl_error_desc)
759 #define CTL_SET_PORT_WWNS _IOW(CTL_MINOR, 0x24, struct ctl_port_entry)
760 #define CTL_ISCSI _IOWR(CTL_MINOR, 0x25, struct ctl_iscsi)
761 #define CTL_PORT_REQ _IOWR(CTL_MINOR, 0x26, struct ctl_req)
762 #define CTL_PORT_LIST _IOWR(CTL_MINOR, 0x27, struct ctl_lun_list)
763 #define CTL_LUN_MAP _IOW(CTL_MINOR, 0x28, struct ctl_lun_map)
765 #endif /* _CTL_IOCTL_H_ */