2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
34 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ioctl.h#4 $
38 * CAM Target Layer ioctl interface.
40 * Author: Ken Merry <ken@FreeBSD.org>
46 #ifdef ICL_KERNEL_PROXY
47 #include <sys/socket.h>
50 #include <sys/ioccom.h>
53 #define CTL_DEFAULT_DEV "/dev/cam/ctl"
55 * Maximum number of targets we support.
57 #define CTL_MAX_TARGETS 1
60 * Maximum target ID we support.
62 #define CTL_MAX_TARGID 15
65 * Maximum number of initiators per port.
67 #define CTL_MAX_INIT_PER_PORT 2048
69 /* Hopefully this won't conflict with new misc devices that pop up */
75 CTL_DELAY_TYPE_ONESHOT
80 CTL_DELAY_LOC_DATAMOVE,
85 CTL_DELAY_STATUS_NONE,
87 CTL_DELAY_STATUS_INVALID_LUN,
88 CTL_DELAY_STATUS_INVALID_TYPE,
89 CTL_DELAY_STATUS_INVALID_LOC,
90 CTL_DELAY_STATUS_NOT_IMPLEMENTED
93 struct ctl_io_delay_info {
95 ctl_delay_type delay_type;
96 ctl_delay_location delay_loc;
98 ctl_delay_status status;
106 #define CTL_STATS_NUM_TYPES 3
110 CTL_SS_NEED_MORE_SPACE,
115 CTL_STATS_FLAG_NONE = 0x00,
116 CTL_STATS_FLAG_TIME_VALID = 0x01
119 struct ctl_io_stats {
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];
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 */
140 * The types of errors that can be injected:
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.
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.
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
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.
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.
174 * MASK: Mask for basic command patterns.
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
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;
196 * This structure allows the user to specify a particular CDB pattern to
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
204 struct ctl_error_desc_cmd {
205 uint8_t cdb_pattern[CTL_MAX_CDBLEN];
206 uint32_t cdb_valid_bytes;
211 * Error injection descriptor.
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.
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 */
234 CTL_OOA_FLAG_NONE = 0x00,
235 CTL_OOA_FLAG_ALL_LUNS = 0x01
240 CTL_OOA_NEED_MORE_SPACE,
242 } ctl_get_ooa_status;
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
253 struct ctl_ooa_entry {
254 ctl_ooa_cmd_flags cmd_flags;
255 uint8_t cdb[CTL_MAX_CDBLEN];
259 struct bintime start_bt;
263 ctl_ooa_flags flags; /* passed to kernel */
264 uint64_t lun_num; /* passed to kernel */
265 uint32_t alloc_len; /* passed to kernel */
266 uint32_t alloc_num; /* passed to kernel */
267 struct ctl_ooa_entry *entries; /* filled in kernel */
268 uint32_t fill_len; /* passed to userland */
269 uint32_t fill_num; /* passed to userland */
270 uint32_t dropped_num; /* passed to userland */
271 struct bintime cur_bt; /* passed to userland */
272 ctl_get_ooa_status status; /* passed to userland */
282 #define CTL_ERROR_STR_LEN 160
291 * The ID_REQ flag is used to say that the caller has requested a
292 * particular LUN ID in the req_lun_id field. If we cannot allocate that
293 * LUN ID, the ctl_add_lun() call will fail.
295 * The STOPPED flag tells us that the LUN should default to the powered
296 * off state. It will return 0x04,0x02 until it is powered up. ("Logical
297 * unit not ready, initializing command required.")
299 * The NO_MEDIA flag tells us that the LUN has no media inserted.
301 * The PRIMARY flag tells us that this LUN is registered as a Primary LUN
302 * which is accessible via the Master shelf controller in an HA. This flag
303 * being set indicates a Primary LUN. This flag being reset represents a
304 * Secondary LUN controlled by the Secondary controller in an HA
305 * configuration. Flag is applicable at this time to T_DIRECT types.
307 * The SERIAL_NUM flag tells us that the serial_num field is filled in and
308 * valid for use in SCSI INQUIRY VPD page 0x80.
310 * The DEVID flag tells us that the device_id field is filled in and
311 * valid for use in SCSI INQUIRY VPD page 0x83.
313 * The DEV_TYPE flag tells us that the device_type field is filled in.
315 * The EJECTED flag tells us that the removable LUN has tray open.
317 * The UNMAP flag tells us that this LUN supports UNMAP.
319 * The OFFLINE flag tells us that this LUN can not access backing store.
322 CTL_LUN_FLAG_ID_REQ = 0x01,
323 CTL_LUN_FLAG_STOPPED = 0x02,
324 CTL_LUN_FLAG_NO_MEDIA = 0x04,
325 CTL_LUN_FLAG_PRIMARY = 0x08,
326 CTL_LUN_FLAG_SERIAL_NUM = 0x10,
327 CTL_LUN_FLAG_DEVID = 0x20,
328 CTL_LUN_FLAG_DEV_TYPE = 0x40,
329 CTL_LUN_FLAG_UNMAP = 0x80,
330 CTL_LUN_FLAG_EJECTED = 0x100,
331 CTL_LUN_FLAG_READONLY = 0x200
332 } ctl_backend_lun_flags;
335 * LUN creation parameters:
337 * flags: Various LUN flags, see above.
339 * device_type: The SCSI device type. e.g. 0 for Direct Access,
340 * 3 for Processor, etc. Only certain backends may
341 * support setting this field. The CTL_LUN_FLAG_DEV_TYPE
342 * flag should be set in the flags field if the device
345 * lun_size_bytes: The size of the LUN in bytes. For some backends
346 * this is relevant (e.g. ramdisk), for others, it may
347 * be ignored in favor of using the properties of the
348 * backing store. If specified, this should be a
349 * multiple of the blocksize.
351 * The actual size of the LUN is returned in this
354 * blocksize_bytes: The LUN blocksize in bytes. For some backends this
355 * is relevant, for others it may be ignored in
356 * favor of using the properties of the backing store.
358 * The actual blocksize of the LUN is returned in this
361 * req_lun_id: The requested LUN ID. The CTL_LUN_FLAG_ID_REQ flag
362 * should be set if this is set. The request will be
363 * granted if the LUN number is available, otherwise
364 * the LUN addition request will fail.
366 * The allocated LUN number is returned in this field.
368 * serial_num: This is the value returned in SCSI INQUIRY VPD page
369 * 0x80. If it is specified, the CTL_LUN_FLAG_SERIAL_NUM
370 * flag should be set.
372 * The serial number value used is returned in this
375 * device_id: This is the value returned in the T10 vendor ID
376 * based DESIGNATOR field in the SCSI INQUIRY VPD page
377 * 0x83 data. If it is specified, the CTL_LUN_FLAG_DEVID
378 * flag should be set.
380 * The device id value used is returned in this field.
382 struct ctl_lun_create_params {
383 ctl_backend_lun_flags flags;
385 uint64_t lun_size_bytes;
386 uint32_t blocksize_bytes;
388 uint8_t serial_num[CTL_SN_LEN];
389 uint8_t device_id[CTL_DEVID_LEN];
393 * LUN removal parameters:
395 * lun_id: The number of the LUN to delete. This must be set.
396 * The LUN must be backed by the given backend.
398 struct ctl_lun_rm_params {
403 * LUN modification parameters:
405 * lun_id: The number of the LUN to modify. This must be set.
406 * The LUN must be backed by the given backend.
408 * lun_size_bytes: The size of the LUN in bytes. If zero, update
409 * the size using the backing file size, if possible.
411 struct ctl_lun_modify_params {
413 uint64_t lun_size_bytes;
417 * Union of request type data. Fill in the appropriate union member for
420 union ctl_lunreq_data {
421 struct ctl_lun_create_params create;
422 struct ctl_lun_rm_params rm;
423 struct ctl_lun_modify_params modify;
427 * LUN request interface:
429 * backend: This is required, and is NUL-terminated a string
430 * that is the name of the backend, like "ramdisk" or
433 * reqtype: The type of request, CTL_LUNREQ_CREATE to create a
434 * LUN, CTL_LUNREQ_RM to delete a LUN.
436 * reqdata: Request type-specific information. See the
437 * description of individual the union members above
438 * for more information.
440 * num_be_args: This is the number of backend-specific arguments
441 * in the be_args array.
443 * be_args: This is an array of backend-specific arguments.
444 * See above for a description of the fields in this
447 * status: Status of the LUN request.
449 * error_str: If the status is CTL_LUN_ERROR, this will
450 * contain a string describing the error.
452 * kern_be_args: For kernel use only.
455 #define CTL_BE_NAME_LEN 32
456 char backend[CTL_BE_NAME_LEN];
457 ctl_lunreq_type reqtype;
458 union ctl_lunreq_data reqdata;
463 nvlist_t * result_nvl;
465 ctl_lun_status status;
466 char error_str[CTL_ERROR_STR_LEN];
474 * OK: Request completed successfully.
476 * NEED_MORE_SPACE: The allocated length of the entries field is too
477 * small for the available data.
479 * ERROR: An error occurred, look at the error string for a
480 * description of the error.
485 CTL_LUN_LIST_NEED_MORE_SPACE,
487 } ctl_lun_list_status;
492 * backend_name: This is a NUL-terminated string. If the string
493 * length is 0, then all LUNs on all backends will
494 * be enumerated. Otherwise this is the name of the
495 * backend to be enumerated, like "ramdisk" or "block".
497 * alloc_len: The length of the data buffer allocated for entries.
498 * In order to properly size the buffer, make one call
499 * with alloc_len set to 0, and then use the returned
500 * dropped_len as the buffer length to allocate and
501 * pass in on a subsequent call.
503 * lun_xml: XML-formatted information on the requested LUNs.
505 * fill_len: The amount of data filled in the storage for entries.
507 * status: The status of the request. See above for the
508 * description of the values of this field.
510 * error_str: If the status indicates an error, this string will
511 * be filled in to describe the error.
513 struct ctl_lun_list {
514 char backend[CTL_BE_NAME_LEN]; /* passed to kernel*/
515 uint32_t alloc_len; /* passed to kernel */
516 char *lun_xml; /* filled in kernel */
517 uint32_t fill_len; /* passed to userland */
518 ctl_lun_list_status status; /* passed to userland */
519 char error_str[CTL_ERROR_STR_LEN];
520 /* passed to userland */
524 * Port request interface:
526 * driver: This is required, and is NUL-terminated a string
527 * that is the name of the frontend, like "iscsi" .
529 * reqtype: The type of request, CTL_REQ_CREATE to create a
530 * port, CTL_REQ_REMOVE to delete a port.
532 * num_be_args: This is the number of frontend-specific arguments
533 * in the be_args array.
535 * be_args: This is an array of frontend-specific arguments.
536 * See above for a description of the fields in this
539 * status: Status of the request.
541 * error_str: If the status is CTL_LUN_ERROR, this will
542 * contain a string describing the error.
544 * kern_be_args: For kernel use only.
553 char driver[CTL_DRIVER_NAME_LEN];
554 ctl_req_type reqtype;
559 nvlist_t * result_nvl;
561 ctl_lun_status status;
562 char error_str[CTL_ERROR_STR_LEN];
568 * OK: Request completed successfully.
570 * ERROR: An error occurred, look at the error string for a
571 * description of the error.
573 * CTL_ISCSI_LIST_NEED_MORE_SPACE:
574 * User has to pass larger buffer for CTL_ISCSI_LIST ioctl.
579 CTL_ISCSI_LIST_NEED_MORE_SPACE,
580 CTL_ISCSI_SESSION_NOT_FOUND
589 #if defined(ICL_KERNEL_PROXY) || 1
591 * We actually need those in all cases, but leave the ICL_KERNEL_PROXY,
592 * to remember to remove them along with rest of proxy code, eventually.
602 CTL_ISCSI_DIGEST_NONE,
603 CTL_ISCSI_DIGEST_CRC32C
606 #define CTL_ISCSI_NAME_LEN 224 /* 223 bytes, by RFC 3720, + '\0' */
607 #define CTL_ISCSI_ADDR_LEN 47 /* INET6_ADDRSTRLEN + '\0' */
608 #define CTL_ISCSI_ALIAS_LEN 128 /* Arbitrary. */
609 #define CTL_ISCSI_OFFLOAD_LEN 8 /* Arbitrary. */
611 struct ctl_iscsi_handoff_params {
612 char initiator_name[CTL_ISCSI_NAME_LEN];
613 char initiator_addr[CTL_ISCSI_ADDR_LEN];
614 char initiator_alias[CTL_ISCSI_ALIAS_LEN];
615 uint8_t initiator_isid[6];
616 char target_name[CTL_ISCSI_NAME_LEN];
618 int portal_group_tag;
621 * Connection parameters negotiated by ctld(8).
623 ctl_iscsi_digest header_digest;
624 ctl_iscsi_digest data_digest;
627 int max_recv_data_segment_length;
628 int max_burst_length;
629 int first_burst_length;
630 uint32_t immediate_data;
631 char offload[CTL_ISCSI_OFFLOAD_LEN];
632 #ifdef ICL_KERNEL_PROXY
637 int max_send_data_segment_length;
640 struct ctl_iscsi_list_params {
641 uint32_t alloc_len; /* passed to kernel */
642 char *conn_xml; /* filled in kernel */
643 uint32_t fill_len; /* passed to userland */
647 struct ctl_iscsi_logout_params {
648 int connection_id; /* passed to kernel */
649 char initiator_name[CTL_ISCSI_NAME_LEN];
650 /* passed to kernel */
651 char initiator_addr[CTL_ISCSI_ADDR_LEN];
652 /* passed to kernel */
653 int all; /* passed to kernel */
657 struct ctl_iscsi_terminate_params {
658 int connection_id; /* passed to kernel */
659 char initiator_name[CTL_ISCSI_NAME_LEN];
660 /* passed to kernel */
661 char initiator_addr[CTL_ISCSI_NAME_LEN];
662 /* passed to kernel */
663 int all; /* passed to kernel */
667 struct ctl_iscsi_limits_params {
668 /* passed to kernel */
669 char offload[CTL_ISCSI_OFFLOAD_LEN];
671 /* passed to userland */
673 int max_recv_data_segment_length;
674 int max_send_data_segment_length;
675 int max_burst_length;
676 int first_burst_length;
679 #ifdef ICL_KERNEL_PROXY
680 struct ctl_iscsi_listen_params {
685 struct sockaddr *addr;
691 struct ctl_iscsi_accept_params {
694 struct sockaddr *initiator_addr;
695 socklen_t initiator_addrlen;
699 struct ctl_iscsi_send_params {
704 size_t data_segment_len;
709 struct ctl_iscsi_receive_params {
714 size_t data_segment_len;
719 #endif /* ICL_KERNEL_PROXY */
721 union ctl_iscsi_data {
722 struct ctl_iscsi_handoff_params handoff;
723 struct ctl_iscsi_list_params list;
724 struct ctl_iscsi_logout_params logout;
725 struct ctl_iscsi_terminate_params terminate;
726 struct ctl_iscsi_limits_params limits;
727 #ifdef ICL_KERNEL_PROXY
728 struct ctl_iscsi_listen_params listen;
729 struct ctl_iscsi_accept_params accept;
730 struct ctl_iscsi_send_params send;
731 struct ctl_iscsi_receive_params receive;
738 * status: The status of the request. See above for the
739 * description of the values of this field.
741 * error_str: If the status indicates an error, this string will
742 * be filled in to describe the error.
745 ctl_iscsi_type type; /* passed to kernel */
746 union ctl_iscsi_data data; /* passed to kernel */
747 ctl_iscsi_status status; /* passed to userland */
748 char error_str[CTL_ERROR_STR_LEN];
749 /* passed to userland */
758 #define CTL_IO _IOWR(CTL_MINOR, 0x00, union ctl_io)
759 #define CTL_ENABLE_PORT _IOW(CTL_MINOR, 0x04, struct ctl_port_entry)
760 #define CTL_DISABLE_PORT _IOW(CTL_MINOR, 0x05, struct ctl_port_entry)
761 #define CTL_DELAY_IO _IOWR(CTL_MINOR, 0x10, struct ctl_io_delay_info)
762 #define CTL_ERROR_INJECT _IOWR(CTL_MINOR, 0x16, struct ctl_error_desc)
763 #define CTL_GET_OOA _IOWR(CTL_MINOR, 0x18, struct ctl_ooa)
764 #define CTL_DUMP_STRUCTS _IO(CTL_MINOR, 0x19)
765 #define CTL_LUN_REQ _IOWR(CTL_MINOR, 0x21, struct ctl_lun_req)
766 #define CTL_LUN_LIST _IOWR(CTL_MINOR, 0x22, struct ctl_lun_list)
767 #define CTL_ERROR_INJECT_DELETE _IOW(CTL_MINOR, 0x23, struct ctl_error_desc)
768 #define CTL_SET_PORT_WWNS _IOW(CTL_MINOR, 0x24, struct ctl_port_entry)
769 #define CTL_ISCSI _IOWR(CTL_MINOR, 0x25, struct ctl_iscsi)
770 #define CTL_PORT_REQ _IOWR(CTL_MINOR, 0x26, struct ctl_req)
771 #define CTL_PORT_LIST _IOWR(CTL_MINOR, 0x27, struct ctl_lun_list)
772 #define CTL_LUN_MAP _IOW(CTL_MINOR, 0x28, struct ctl_lun_map)
773 #define CTL_GET_LUN_STATS _IOWR(CTL_MINOR, 0x29, struct ctl_get_io_stats)
774 #define CTL_GET_PORT_STATS _IOWR(CTL_MINOR, 0x2a, struct ctl_get_io_stats)
776 #endif /* _CTL_IOCTL_H_ */