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 256
66 * Maximum number of initiators per port.
68 #define CTL_MAX_INIT_PER_PORT 2048 // Was 16
71 * Maximum number of ports registered at one time.
73 #define CTL_MAX_PORTS 32
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 */
89 uint32_t target_id; /* Passed in to CTL */
90 uint32_t lun_id; /* Passed in to CTL */
91 uint32_t num_entries; /* Returned from CTL */
92 ctl_ooa_status status; /* Returned from CTL */
95 struct ctl_hard_startstop_info {
102 struct ctl_bbrread_info {
103 int lun_num; /* Passed in to CTL */
104 uint64_t lba; /* Passed in to CTL */
105 int len; /* Passed in to CTL */
106 cfi_mt_status status; /* Returned from CTL */
107 cfi_bbrread_status bbr_status; /* Returned from CTL */
108 uint8_t scsi_status; /* Returned from CTL */
109 struct scsi_sense_data sense_data; /* Returned from CTL */
115 CTL_DELAY_TYPE_ONESHOT
120 CTL_DELAY_LOC_DATAMOVE,
122 } ctl_delay_location;
125 CTL_DELAY_STATUS_NONE,
127 CTL_DELAY_STATUS_INVALID_LUN,
128 CTL_DELAY_STATUS_INVALID_TYPE,
129 CTL_DELAY_STATUS_INVALID_LOC,
130 CTL_DELAY_STATUS_NOT_IMPLEMENTED
133 struct ctl_io_delay_info {
136 ctl_delay_type delay_type;
137 ctl_delay_location delay_loc;
139 ctl_delay_status status;
146 } ctl_gs_sync_status;
149 * The target and LUN id specify which device to modify. The sync interval
150 * means that we will let through every N SYNCHRONIZE CACHE commands.
152 struct ctl_sync_info {
153 uint32_t target_id; /* passed to kernel */
154 uint32_t lun_id; /* passed to kernel */
155 int sync_interval; /* depends on whether get/set */
156 ctl_gs_sync_status status; /* passed from kernel */
164 #define CTL_STATS_NUM_TYPES 3
167 CTL_LUN_STATS_NO_BLOCKSIZE = 0x01
168 } ctl_lun_stats_flags;
170 struct ctl_lun_io_port_stats {
172 uint64_t bytes[CTL_STATS_NUM_TYPES];
173 uint64_t operations[CTL_STATS_NUM_TYPES];
174 struct bintime time[CTL_STATS_NUM_TYPES];
175 uint64_t num_dmas[CTL_STATS_NUM_TYPES];
176 struct bintime dma_time[CTL_STATS_NUM_TYPES];
179 struct ctl_lun_io_stats {
183 ctl_lun_stats_flags flags;
184 struct ctl_lun_io_port_stats ports[CTL_MAX_PORTS];
189 CTL_SS_NEED_MORE_SPACE,
194 CTL_STATS_FLAG_NONE = 0x00,
195 CTL_STATS_FLAG_TIME_VALID = 0x01
199 int alloc_len; /* passed to kernel */
200 struct ctl_lun_io_stats *lun_stats; /* passed to/from kernel */
201 int fill_len; /* passed to userland */
202 int num_luns; /* passed to userland */
203 ctl_stats_status status; /* passed to userland */
204 ctl_stats_flags flags; /* passed to userland */
205 struct timespec timestamp; /* passed to userland */
209 * The types of errors that can be injected:
211 * NONE: No error specified.
212 * ABORTED: SSD_KEY_ABORTED_COMMAND, 0x45, 0x00
213 * MEDIUM_ERR: Medium error, different asc/ascq depending on read/write.
214 * UA: Unit attention.
215 * CUSTOM: User specifies the sense data.
216 * TYPE: Mask to use with error types.
218 * Flags that affect injection behavior:
219 * CONTINUOUS: This error will stay around until explicitly cleared.
220 * DESCRIPTOR: Use descriptor sense instead of fixed sense.
223 CTL_LUN_INJ_NONE = 0x000,
224 CTL_LUN_INJ_ABORTED = 0x001,
225 CTL_LUN_INJ_MEDIUM_ERR = 0x002,
226 CTL_LUN_INJ_UA = 0x003,
227 CTL_LUN_INJ_CUSTOM = 0x004,
228 CTL_LUN_INJ_TYPE = 0x0ff,
229 CTL_LUN_INJ_CONTINUOUS = 0x100,
230 CTL_LUN_INJ_DESCRIPTOR = 0x200
234 * Flags to specify what type of command the given error pattern will
235 * execute on. The first group of types can be ORed together.
237 * READ: Any read command.
238 * WRITE: Any write command.
239 * READWRITE: Any read or write command.
240 * READCAP: Any read capacity command.
241 * TUR: Test Unit Ready.
243 * MASK: Mask for basic command patterns.
247 * CMD: The CDB to act on is specified in struct ctl_error_desc_cmd.
248 * RANGE: For read/write commands, act when the LBA is in the
252 CTL_LUN_PAT_NONE = 0x000,
253 CTL_LUN_PAT_READ = 0x001,
254 CTL_LUN_PAT_WRITE = 0x002,
255 CTL_LUN_PAT_READWRITE = CTL_LUN_PAT_READ | CTL_LUN_PAT_WRITE,
256 CTL_LUN_PAT_READCAP = 0x004,
257 CTL_LUN_PAT_TUR = 0x008,
258 CTL_LUN_PAT_ANY = 0x0ff,
259 CTL_LUN_PAT_MASK = 0x0ff,
260 CTL_LUN_PAT_CMD = 0x100,
261 CTL_LUN_PAT_RANGE = 0x200
262 } ctl_lun_error_pattern;
265 * This structure allows the user to specify a particular CDB pattern to
268 * cdb_pattern: Fill in the relevant bytes to look for in the CDB.
269 * cdb_valid_bytes: Bitmask specifying valid bytes in the cdb_pattern.
270 * flags: Specify any command flags (see ctl_io_flags) that
273 struct ctl_error_desc_cmd {
274 uint8_t cdb_pattern[CTL_MAX_CDBLEN];
275 uint32_t cdb_valid_bytes;
280 * Error injection descriptor.
282 * target_id: Target ID to act on.
283 * lun_id LUN to act on.
284 * lun_error: The type of error to inject. See above for descriptions.
285 * error_pattern: What kind of command to act on. See above.
286 * cmd_desc: For CTL_LUN_PAT_CMD only.
287 * lba_range: For CTL_LUN_PAT_RANGE only.
288 * custom_sense: Specify sense. For CTL_LUN_INJ_CUSTOM only.
289 * serial: Serial number returned by the kernel. Use for deletion.
290 * links: Kernel use only.
292 struct ctl_error_desc {
293 uint32_t target_id; /* To kernel */
294 uint32_t lun_id; /* To kernel */
295 ctl_lun_error lun_error; /* To kernel */
296 ctl_lun_error_pattern error_pattern; /* To kernel */
297 struct ctl_error_desc_cmd cmd_desc; /* To kernel */
298 struct ctl_lba_len lba_range; /* To kernel */
299 struct scsi_sense_data custom_sense; /* To kernel */
300 uint64_t serial; /* From kernel */
301 STAILQ_ENTRY(ctl_error_desc) links; /* Kernel use only */
305 CTL_OOA_FLAG_NONE = 0x00,
306 CTL_OOA_FLAG_ALL_LUNS = 0x01
311 CTL_OOA_NEED_MORE_SPACE,
313 } ctl_get_ooa_status;
316 CTL_OOACMD_FLAG_NONE = 0x00,
317 CTL_OOACMD_FLAG_DMA = 0x01,
318 CTL_OOACMD_FLAG_BLOCKED = 0x02,
319 CTL_OOACMD_FLAG_ABORT = 0x04,
320 CTL_OOACMD_FLAG_RTR = 0x08,
321 CTL_OOACMD_FLAG_DMA_QUEUED = 0x10
324 struct ctl_ooa_entry {
325 ctl_ooa_cmd_flags cmd_flags;
326 uint8_t cdb[CTL_MAX_CDBLEN];
330 struct bintime start_bt;
334 ctl_ooa_flags flags; /* passed to kernel */
335 uint64_t lun_num; /* passed to kernel */
336 uint32_t alloc_len; /* passed to kernel */
337 uint32_t alloc_num; /* passed to kernel */
338 struct ctl_ooa_entry *entries; /* filled in kernel */
339 uint32_t fill_len; /* passed to userland */
340 uint32_t fill_num; /* passed to userland */
341 uint32_t dropped_num; /* passed to userland */
342 struct bintime cur_bt; /* passed to userland */
343 ctl_get_ooa_status status; /* passed to userland */
349 CTL_PORT_LIST_NEED_MORE_SPACE,
351 } ctl_port_list_status;
353 struct ctl_port_list {
354 uint32_t alloc_len; /* passed to kernel */
355 uint32_t alloc_num; /* passed to kernel */
356 struct ctl_port_entry *entries; /* filled in kernel */
357 uint32_t fill_len; /* passed to userland */
358 uint32_t fill_num; /* passed to userland */
359 uint32_t dropped_num; /* passed to userland */
360 ctl_port_list_status status; /* passed to userland */
369 #define CTL_ERROR_STR_LEN 160
371 #define CTL_BEARG_RD 0x01
372 #define CTL_BEARG_WR 0x02
373 #define CTL_BEARG_RW (CTL_BEARG_RD|CTL_BEARG_WR)
374 #define CTL_BEARG_ASCII 0x04
379 * namelen: Length of the name field, including the terminating NUL.
381 * name: Name of the paramter. This must be NUL-terminated.
383 * flags: Flags for the parameter, see above for values.
385 * vallen: Length of the value in bytes.
387 * value: Value to be set/fetched.
389 * kname: For kernel use only.
391 * kvalue: For kernel use only.
412 * LUN creation parameters:
414 * flags: Various LUN flags, see ctl_backend.h for a
415 * description of the flag values and meanings.
417 * device_type: The SCSI device type. e.g. 0 for Direct Access,
418 * 3 for Processor, etc. Only certain backends may
419 * support setting this field. The CTL_LUN_FLAG_DEV_TYPE
420 * flag should be set in the flags field if the device
423 * lun_size_bytes: The size of the LUN in bytes. For some backends
424 * this is relevant (e.g. ramdisk), for others, it may
425 * be ignored in favor of using the properties of the
426 * backing store. If specified, this should be a
427 * multiple of the blocksize.
429 * The actual size of the LUN is returned in this
432 * blocksize_bytes: The LUN blocksize in bytes. For some backends this
433 * is relevant, for others it may be ignored in
434 * favor of using the properties of the backing store.
436 * The actual blocksize of the LUN is returned in this
439 * req_lun_id: The requested LUN ID. The CTL_LUN_FLAG_ID_REQ flag
440 * should be set if this is set. The request will be
441 * granted if the LUN number is available, otherwise
442 * the LUN addition request will fail.
444 * The allocated LUN number is returned in this field.
446 * serial_num: This is the value returned in SCSI INQUIRY VPD page
447 * 0x80. If it is specified, the CTL_LUN_FLAG_SERIAL_NUM
448 * flag should be set.
450 * The serial number value used is returned in this
453 * device_id: This is the value returned in the T10 vendor ID
454 * based DESIGNATOR field in the SCSI INQUIRY VPD page
455 * 0x83 data. If it is specified, the CTL_LUN_FLAG_DEVID
456 * flag should be set.
458 * The device id value used is returned in this field.
460 struct ctl_lun_create_params {
461 ctl_backend_lun_flags flags;
463 uint64_t lun_size_bytes;
464 uint32_t blocksize_bytes;
466 uint8_t serial_num[CTL_SN_LEN];
467 uint8_t device_id[CTL_DEVID_LEN];
471 * LUN removal parameters:
473 * lun_id: The number of the LUN to delete. This must be set.
474 * The LUN must be backed by the given backend.
476 struct ctl_lun_rm_params {
481 * LUN modification parameters:
483 * lun_id: The number of the LUN to modify. This must be set.
484 * The LUN must be backed by the given backend.
486 * lun_size_bytes: The size of the LUN in bytes. If zero, update
487 * the size using the backing file size, if possible.
489 struct ctl_lun_modify_params {
491 uint64_t lun_size_bytes;
495 * Union of request type data. Fill in the appropriate union member for
498 union ctl_lunreq_data {
499 struct ctl_lun_create_params create;
500 struct ctl_lun_rm_params rm;
501 struct ctl_lun_modify_params modify;
505 * LUN request interface:
507 * backend: This is required, and is NUL-terminated a string
508 * that is the name of the backend, like "ramdisk" or
511 * reqtype: The type of request, CTL_LUNREQ_CREATE to create a
512 * LUN, CTL_LUNREQ_RM to delete a LUN.
514 * reqdata: Request type-specific information. See the
515 * description of individual the union members above
516 * for more information.
518 * num_be_args: This is the number of backend-specific arguments
519 * in the be_args array.
521 * be_args: This is an array of backend-specific arguments.
522 * See above for a description of the fields in this
525 * status: Status of the LUN request.
527 * error_str: If the status is CTL_LUN_ERROR, this will
528 * contain a string describing the error.
530 * kern_be_args: For kernel use only.
533 char backend[CTL_BE_NAME_LEN];
534 ctl_lunreq_type reqtype;
535 union ctl_lunreq_data reqdata;
537 struct ctl_be_arg *be_args;
538 ctl_lun_status status;
539 char error_str[CTL_ERROR_STR_LEN];
540 struct ctl_be_arg *kern_be_args;
548 * OK: Request completed successfully.
550 * NEED_MORE_SPACE: The allocated length of the entries field is too
551 * small for the available data.
553 * ERROR: An error occured, look at the error string for a
554 * description of the error.
559 CTL_LUN_LIST_NEED_MORE_SPACE,
561 } ctl_lun_list_status;
566 * backend_name: This is a NUL-terminated string. If the string
567 * length is 0, then all LUNs on all backends will
568 * be enumerated. Otherwise this is the name of the
569 * backend to be enumerated, like "ramdisk" or "block".
571 * alloc_len: The length of the data buffer allocated for entries.
572 * In order to properly size the buffer, make one call
573 * with alloc_len set to 0, and then use the returned
574 * dropped_len as the buffer length to allocate and
575 * pass in on a subsequent call.
577 * lun_xml: XML-formatted information on the requested LUNs.
579 * fill_len: The amount of data filled in the storage for entries.
581 * status: The status of the request. See above for the
582 * description of the values of this field.
584 * error_str: If the status indicates an error, this string will
585 * be filled in to describe the error.
587 struct ctl_lun_list {
588 char backend[CTL_BE_NAME_LEN]; /* passed to kernel*/
589 uint32_t alloc_len; /* passed to kernel */
590 char *lun_xml; /* filled in kernel */
591 uint32_t fill_len; /* passed to userland */
592 ctl_lun_list_status status; /* passed to userland */
593 char error_str[CTL_ERROR_STR_LEN];
594 /* passed to userland */
600 * OK: Request completed successfully.
602 * ERROR: An error occured, look at the error string for a
603 * description of the error.
605 * CTL_ISCSI_LIST_NEED_MORE_SPACE:
606 * User has to pass larger buffer for CTL_ISCSI_LIST ioctl.
611 CTL_ISCSI_LIST_NEED_MORE_SPACE,
612 CTL_ISCSI_SESSION_NOT_FOUND
620 #ifdef ICL_KERNEL_PROXY
630 CTL_ISCSI_DIGEST_NONE,
631 CTL_ISCSI_DIGEST_CRC32C
634 #define CTL_ISCSI_NAME_LEN 224 /* 223 bytes, by RFC 3720, + '\0' */
635 #define CTL_ISCSI_ADDR_LEN 47 /* INET6_ADDRSTRLEN + '\0' */
636 #define CTL_ISCSI_ALIAS_LEN 128 /* Arbitrary. */
638 struct ctl_iscsi_handoff_params {
639 char initiator_name[CTL_ISCSI_NAME_LEN];
640 char initiator_addr[CTL_ISCSI_ADDR_LEN];
641 char initiator_alias[CTL_ISCSI_ALIAS_LEN];
642 char target_name[CTL_ISCSI_NAME_LEN];
643 #ifdef ICL_KERNEL_PROXY
652 int portal_group_tag;
655 * Connection parameters negotiated by ctld(8).
657 ctl_iscsi_digest header_digest;
658 ctl_iscsi_digest data_digest;
661 uint32_t max_recv_data_segment_length;
662 uint32_t max_burst_length;
663 uint32_t first_burst_length;
664 uint32_t immediate_data;
668 struct ctl_iscsi_list_params {
669 uint32_t alloc_len; /* passed to kernel */
670 char *conn_xml; /* filled in kernel */
671 uint32_t fill_len; /* passed to userland */
675 struct ctl_iscsi_logout_params {
676 int connection_id; /* passed to kernel */
677 char initiator_name[CTL_ISCSI_NAME_LEN];
678 /* passed to kernel */
679 char initiator_addr[CTL_ISCSI_ADDR_LEN];
680 /* passed to kernel */
681 int all; /* passed to kernel */
685 struct ctl_iscsi_terminate_params {
686 int connection_id; /* passed to kernel */
687 char initiator_name[CTL_ISCSI_NAME_LEN];
688 /* passed to kernel */
689 char initiator_addr[CTL_ISCSI_NAME_LEN];
690 /* passed to kernel */
691 int all; /* passed to kernel */
695 #ifdef ICL_KERNEL_PROXY
696 struct ctl_iscsi_listen_params {
701 struct sockaddr *addr;
706 struct ctl_iscsi_accept_params {
711 struct ctl_iscsi_send_params {
716 size_t data_segment_len;
721 struct ctl_iscsi_receive_params {
726 size_t data_segment_len;
731 struct ctl_iscsi_close_params {
735 #endif /* ICL_KERNEL_PROXY */
737 union ctl_iscsi_data {
738 struct ctl_iscsi_handoff_params handoff;
739 struct ctl_iscsi_list_params list;
740 struct ctl_iscsi_logout_params logout;
741 struct ctl_iscsi_terminate_params terminate;
742 #ifdef ICL_KERNEL_PROXY
743 struct ctl_iscsi_listen_params listen;
744 struct ctl_iscsi_accept_params accept;
745 struct ctl_iscsi_send_params send;
746 struct ctl_iscsi_receive_params receive;
747 struct ctl_iscsi_close_params close;
754 * status: The status of the request. See above for the
755 * description of the values of this field.
757 * error_str: If the status indicates an error, this string will
758 * be filled in to describe the error.
761 ctl_iscsi_type type; /* passed to kernel */
762 union ctl_iscsi_data data; /* passed to kernel */
763 ctl_iscsi_status status; /* passed to userland */
764 char error_str[CTL_ERROR_STR_LEN];
765 /* passed to userland */
768 #define CTL_IO _IOWR(CTL_MINOR, 0x00, union ctl_io)
769 #define CTL_ENABLE_PORT _IOW(CTL_MINOR, 0x04, struct ctl_port_entry)
770 #define CTL_DISABLE_PORT _IOW(CTL_MINOR, 0x05, struct ctl_port_entry)
771 #define CTL_DUMP_OOA _IO(CTL_MINOR, 0x06)
772 #define CTL_CHECK_OOA _IOWR(CTL_MINOR, 0x07, struct ctl_ooa_info)
773 #define CTL_HARD_STOP _IOR(CTL_MINOR, 0x08, \
774 struct ctl_hard_startstop_info)
775 #define CTL_HARD_START _IOR(CTL_MINOR, 0x09, \
776 struct ctl_hard_startstop_info)
777 #define CTL_DELAY_IO _IOWR(CTL_MINOR, 0x10, struct ctl_io_delay_info)
778 #define CTL_REALSYNC_GET _IOR(CTL_MINOR, 0x11, int)
779 #define CTL_REALSYNC_SET _IOW(CTL_MINOR, 0x12, int)
780 #define CTL_SETSYNC _IOWR(CTL_MINOR, 0x13, struct ctl_sync_info)
781 #define CTL_GETSYNC _IOWR(CTL_MINOR, 0x14, struct ctl_sync_info)
782 #define CTL_GETSTATS _IOWR(CTL_MINOR, 0x15, struct ctl_stats)
783 #define CTL_ERROR_INJECT _IOWR(CTL_MINOR, 0x16, struct ctl_error_desc)
784 #define CTL_BBRREAD _IOWR(CTL_MINOR, 0x17, struct ctl_bbrread_info)
785 #define CTL_GET_OOA _IOWR(CTL_MINOR, 0x18, struct ctl_ooa)
786 #define CTL_DUMP_STRUCTS _IO(CTL_MINOR, 0x19)
787 #define CTL_GET_PORT_LIST _IOWR(CTL_MINOR, 0x20, struct ctl_port_list)
788 #define CTL_LUN_REQ _IOWR(CTL_MINOR, 0x21, struct ctl_lun_req)
789 #define CTL_LUN_LIST _IOWR(CTL_MINOR, 0x22, struct ctl_lun_list)
790 #define CTL_ERROR_INJECT_DELETE _IOW(CTL_MINOR, 0x23, struct ctl_error_desc)
791 #define CTL_SET_PORT_WWNS _IOW(CTL_MINOR, 0x24, struct ctl_port_entry)
792 #define CTL_ISCSI _IOWR(CTL_MINOR, 0x25, struct ctl_iscsi)
794 #endif /* _CTL_IOCTL_H_ */