1229997Sken/*- 2229997Sken * Copyright (c) 2003 Silicon Graphics International Corp. 3229997Sken * Copyright (c) 2011 Spectra Logic Corporation 4312841Smav * Copyright (c) 2014-2017 Alexander Motin <mav@FreeBSD.org> 5229997Sken * All rights reserved. 6229997Sken * 7229997Sken * Redistribution and use in source and binary forms, with or without 8229997Sken * modification, are permitted provided that the following conditions 9229997Sken * are met: 10229997Sken * 1. Redistributions of source code must retain the above copyright 11229997Sken * notice, this list of conditions, and the following disclaimer, 12229997Sken * without modification. 13229997Sken * 2. Redistributions in binary form must reproduce at minimum a disclaimer 14229997Sken * substantially similar to the "NO WARRANTY" disclaimer below 15229997Sken * ("Disclaimer") and any redistribution must be conditioned upon 16229997Sken * including a substantially similar Disclaimer requirement for further 17229997Sken * binary redistribution. 18229997Sken * 19229997Sken * NO WARRANTY 20229997Sken * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21229997Sken * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22229997Sken * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 23229997Sken * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24229997Sken * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25229997Sken * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26229997Sken * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27229997Sken * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28229997Sken * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29229997Sken * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30229997Sken * POSSIBILITY OF SUCH DAMAGES. 31229997Sken * 32229997Sken * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ioctl.h#4 $ 33229997Sken * $FreeBSD: stable/10/sys/cam/ctl/ctl_ioctl.h 312841 2017-01-26 21:00:49Z mav $ 34229997Sken */ 35229997Sken/* 36229997Sken * CAM Target Layer ioctl interface. 37229997Sken * 38229997Sken * Author: Ken Merry <ken@FreeBSD.org> 39229997Sken */ 40229997Sken 41229997Sken#ifndef _CTL_IOCTL_H_ 42229997Sken#define _CTL_IOCTL_H_ 43229997Sken 44255570Strasz#ifdef ICL_KERNEL_PROXY 45255570Strasz#include <sys/socket.h> 46255570Strasz#endif 47255570Strasz 48255570Strasz#include <sys/ioccom.h> 49255570Strasz 50229997Sken#define CTL_DEFAULT_DEV "/dev/cam/ctl" 51229997Sken/* 52229997Sken * Maximum number of targets we support. 53229997Sken */ 54229997Sken#define CTL_MAX_TARGETS 1 55229997Sken 56229997Sken/* 57229997Sken * Maximum target ID we support. 58229997Sken */ 59229997Sken#define CTL_MAX_TARGID 15 60229997Sken 61229997Sken/* 62229997Sken * Maximum number of LUNs we support at the moment. MUST be a power of 2. 63229997Sken */ 64275891Smav#define CTL_MAX_LUNS 1024 65229997Sken 66229997Sken/* 67229997Sken * Maximum number of initiators per port. 68229997Sken */ 69275891Smav#define CTL_MAX_INIT_PER_PORT 2048 70229997Sken 71229997Sken/* 72229997Sken * Maximum number of ports registered at one time. 73229997Sken */ 74275891Smav#define CTL_MAX_PORTS 256 75229997Sken 76229997Sken/* 77229997Sken * Maximum number of initiators we support. 78229997Sken */ 79229997Sken#define CTL_MAX_INITIATORS (CTL_MAX_INIT_PER_PORT * CTL_MAX_PORTS) 80229997Sken 81229997Sken/* Hopefully this won't conflict with new misc devices that pop up */ 82229997Sken#define CTL_MINOR 225 83229997Sken 84312841Smav/* Legacy statistics accumulated for every port for every LU. */ 85312841Smav#define CTL_LEGACY_STATS 1 86312841Smav 87229997Skentypedef enum { 88229997Sken CTL_DELAY_TYPE_NONE, 89229997Sken CTL_DELAY_TYPE_CONT, 90229997Sken CTL_DELAY_TYPE_ONESHOT 91229997Sken} ctl_delay_type; 92229997Sken 93229997Skentypedef enum { 94229997Sken CTL_DELAY_LOC_NONE, 95229997Sken CTL_DELAY_LOC_DATAMOVE, 96229997Sken CTL_DELAY_LOC_DONE, 97229997Sken} ctl_delay_location; 98229997Sken 99229997Skentypedef enum { 100229997Sken CTL_DELAY_STATUS_NONE, 101229997Sken CTL_DELAY_STATUS_OK, 102229997Sken CTL_DELAY_STATUS_INVALID_LUN, 103229997Sken CTL_DELAY_STATUS_INVALID_TYPE, 104229997Sken CTL_DELAY_STATUS_INVALID_LOC, 105229997Sken CTL_DELAY_STATUS_NOT_IMPLEMENTED 106229997Sken} ctl_delay_status; 107229997Sken 108229997Skenstruct ctl_io_delay_info { 109229997Sken uint32_t lun_id; 110229997Sken ctl_delay_type delay_type; 111229997Sken ctl_delay_location delay_loc; 112229997Sken uint32_t delay_secs; 113229997Sken ctl_delay_status status; 114229997Sken}; 115229997Sken 116229997Skentypedef enum { 117229997Sken CTL_STATS_NO_IO, 118229997Sken CTL_STATS_READ, 119229997Sken CTL_STATS_WRITE 120229997Sken} ctl_stat_types; 121229997Sken#define CTL_STATS_NUM_TYPES 3 122229997Sken 123229997Skentypedef enum { 124312841Smav CTL_SS_OK, 125312841Smav CTL_SS_NEED_MORE_SPACE, 126312841Smav CTL_SS_ERROR 127312841Smav} ctl_stats_status; 128312841Smav 129312841Smavtypedef enum { 130312841Smav CTL_STATS_FLAG_NONE = 0x00, 131312841Smav CTL_STATS_FLAG_TIME_VALID = 0x01 132312841Smav} ctl_stats_flags; 133312841Smav 134312841Smav#ifdef CTL_LEGACY_STATS 135312841Smavtypedef enum { 136229997Sken CTL_LUN_STATS_NO_BLOCKSIZE = 0x01 137229997Sken} ctl_lun_stats_flags; 138229997Sken 139229997Skenstruct ctl_lun_io_port_stats { 140229997Sken uint32_t targ_port; 141229997Sken uint64_t bytes[CTL_STATS_NUM_TYPES]; 142229997Sken uint64_t operations[CTL_STATS_NUM_TYPES]; 143229997Sken struct bintime time[CTL_STATS_NUM_TYPES]; 144229997Sken uint64_t num_dmas[CTL_STATS_NUM_TYPES]; 145229997Sken struct bintime dma_time[CTL_STATS_NUM_TYPES]; 146229997Sken}; 147229997Sken 148229997Skenstruct ctl_lun_io_stats { 149229997Sken uint8_t device_type; 150229997Sken uint64_t lun_number; 151229997Sken uint32_t blocksize; 152229997Sken ctl_lun_stats_flags flags; 153229997Sken struct ctl_lun_io_port_stats ports[CTL_MAX_PORTS]; 154229997Sken}; 155229997Sken 156229997Skenstruct ctl_stats { 157229997Sken int alloc_len; /* passed to kernel */ 158229997Sken struct ctl_lun_io_stats *lun_stats; /* passed to/from kernel */ 159229997Sken int fill_len; /* passed to userland */ 160229997Sken int num_luns; /* passed to userland */ 161229997Sken ctl_stats_status status; /* passed to userland */ 162229997Sken ctl_stats_flags flags; /* passed to userland */ 163229997Sken struct timespec timestamp; /* passed to userland */ 164229997Sken}; 165312841Smav#endif /* CTL_LEGACY_STATS */ 166229997Sken 167312841Smavstruct ctl_io_stats { 168312841Smav uint32_t item; 169312841Smav uint64_t bytes[CTL_STATS_NUM_TYPES]; 170312841Smav uint64_t operations[CTL_STATS_NUM_TYPES]; 171312841Smav uint64_t dmas[CTL_STATS_NUM_TYPES]; 172312841Smav struct bintime time[CTL_STATS_NUM_TYPES]; 173312841Smav struct bintime dma_time[CTL_STATS_NUM_TYPES]; 174312841Smav}; 175312841Smav 176312841Smavstruct ctl_get_io_stats { 177312841Smav struct ctl_io_stats *stats; /* passed to/from kernel */ 178312841Smav size_t alloc_len; /* passed to kernel */ 179312841Smav size_t fill_len; /* passed to userland */ 180312841Smav int first_item; /* passed to kernel */ 181312841Smav int num_items; /* passed to userland */ 182312841Smav ctl_stats_status status; /* passed to userland */ 183312841Smav ctl_stats_flags flags; /* passed to userland */ 184312841Smav struct timespec timestamp; /* passed to userland */ 185312841Smav}; 186312841Smav 187229997Sken/* 188229997Sken * The types of errors that can be injected: 189229997Sken * 190229997Sken * NONE: No error specified. 191229997Sken * ABORTED: SSD_KEY_ABORTED_COMMAND, 0x45, 0x00 192229997Sken * MEDIUM_ERR: Medium error, different asc/ascq depending on read/write. 193229997Sken * UA: Unit attention. 194229997Sken * CUSTOM: User specifies the sense data. 195229997Sken * TYPE: Mask to use with error types. 196229997Sken * 197229997Sken * Flags that affect injection behavior: 198229997Sken * CONTINUOUS: This error will stay around until explicitly cleared. 199229997Sken * DESCRIPTOR: Use descriptor sense instead of fixed sense. 200229997Sken */ 201229997Skentypedef enum { 202229997Sken CTL_LUN_INJ_NONE = 0x000, 203229997Sken CTL_LUN_INJ_ABORTED = 0x001, 204229997Sken CTL_LUN_INJ_MEDIUM_ERR = 0x002, 205229997Sken CTL_LUN_INJ_UA = 0x003, 206229997Sken CTL_LUN_INJ_CUSTOM = 0x004, 207229997Sken CTL_LUN_INJ_TYPE = 0x0ff, 208229997Sken CTL_LUN_INJ_CONTINUOUS = 0x100, 209229997Sken CTL_LUN_INJ_DESCRIPTOR = 0x200 210229997Sken} ctl_lun_error; 211229997Sken 212229997Sken/* 213229997Sken * Flags to specify what type of command the given error pattern will 214229997Sken * execute on. The first group of types can be ORed together. 215229997Sken * 216229997Sken * READ: Any read command. 217229997Sken * WRITE: Any write command. 218229997Sken * READWRITE: Any read or write command. 219229997Sken * READCAP: Any read capacity command. 220229997Sken * TUR: Test Unit Ready. 221229997Sken * ANY: Any command. 222229997Sken * MASK: Mask for basic command patterns. 223229997Sken * 224229997Sken * Special types: 225229997Sken * 226229997Sken * CMD: The CDB to act on is specified in struct ctl_error_desc_cmd. 227229997Sken * RANGE: For read/write commands, act when the LBA is in the 228229997Sken * specified range. 229229997Sken */ 230229997Skentypedef enum { 231229997Sken CTL_LUN_PAT_NONE = 0x000, 232229997Sken CTL_LUN_PAT_READ = 0x001, 233229997Sken CTL_LUN_PAT_WRITE = 0x002, 234229997Sken CTL_LUN_PAT_READWRITE = CTL_LUN_PAT_READ | CTL_LUN_PAT_WRITE, 235229997Sken CTL_LUN_PAT_READCAP = 0x004, 236229997Sken CTL_LUN_PAT_TUR = 0x008, 237229997Sken CTL_LUN_PAT_ANY = 0x0ff, 238229997Sken CTL_LUN_PAT_MASK = 0x0ff, 239229997Sken CTL_LUN_PAT_CMD = 0x100, 240229997Sken CTL_LUN_PAT_RANGE = 0x200 241229997Sken} ctl_lun_error_pattern; 242229997Sken 243229997Sken/* 244229997Sken * This structure allows the user to specify a particular CDB pattern to 245229997Sken * look for. 246229997Sken * 247229997Sken * cdb_pattern: Fill in the relevant bytes to look for in the CDB. 248229997Sken * cdb_valid_bytes: Bitmask specifying valid bytes in the cdb_pattern. 249229997Sken * flags: Specify any command flags (see ctl_io_flags) that 250229997Sken * should be set. 251229997Sken */ 252229997Skenstruct ctl_error_desc_cmd { 253229997Sken uint8_t cdb_pattern[CTL_MAX_CDBLEN]; 254229997Sken uint32_t cdb_valid_bytes; 255229997Sken uint32_t flags; 256229997Sken}; 257229997Sken 258229997Sken/* 259229997Sken * Error injection descriptor. 260229997Sken * 261229997Sken * lun_id LUN to act on. 262229997Sken * lun_error: The type of error to inject. See above for descriptions. 263229997Sken * error_pattern: What kind of command to act on. See above. 264229997Sken * cmd_desc: For CTL_LUN_PAT_CMD only. 265229997Sken * lba_range: For CTL_LUN_PAT_RANGE only. 266229997Sken * custom_sense: Specify sense. For CTL_LUN_INJ_CUSTOM only. 267229997Sken * serial: Serial number returned by the kernel. Use for deletion. 268229997Sken * links: Kernel use only. 269229997Sken */ 270229997Skenstruct ctl_error_desc { 271229997Sken uint32_t lun_id; /* To kernel */ 272229997Sken ctl_lun_error lun_error; /* To kernel */ 273229997Sken ctl_lun_error_pattern error_pattern; /* To kernel */ 274229997Sken struct ctl_error_desc_cmd cmd_desc; /* To kernel */ 275229997Sken struct ctl_lba_len lba_range; /* To kernel */ 276229997Sken struct scsi_sense_data custom_sense; /* To kernel */ 277229997Sken uint64_t serial; /* From kernel */ 278229997Sken STAILQ_ENTRY(ctl_error_desc) links; /* Kernel use only */ 279229997Sken}; 280229997Sken 281229997Skentypedef enum { 282229997Sken CTL_OOA_FLAG_NONE = 0x00, 283229997Sken CTL_OOA_FLAG_ALL_LUNS = 0x01 284229997Sken} ctl_ooa_flags; 285229997Sken 286229997Skentypedef enum { 287229997Sken CTL_OOA_OK, 288229997Sken CTL_OOA_NEED_MORE_SPACE, 289229997Sken CTL_OOA_ERROR 290229997Sken} ctl_get_ooa_status; 291229997Sken 292229997Skentypedef enum { 293229997Sken CTL_OOACMD_FLAG_NONE = 0x00, 294229997Sken CTL_OOACMD_FLAG_DMA = 0x01, 295229997Sken CTL_OOACMD_FLAG_BLOCKED = 0x02, 296229997Sken CTL_OOACMD_FLAG_ABORT = 0x04, 297229997Sken CTL_OOACMD_FLAG_RTR = 0x08, 298229997Sken CTL_OOACMD_FLAG_DMA_QUEUED = 0x10 299229997Sken} ctl_ooa_cmd_flags; 300229997Sken 301229997Skenstruct ctl_ooa_entry { 302229997Sken ctl_ooa_cmd_flags cmd_flags; 303229997Sken uint8_t cdb[CTL_MAX_CDBLEN]; 304229997Sken uint8_t cdb_len; 305229997Sken uint32_t tag_num; 306229997Sken uint32_t lun_num; 307229997Sken struct bintime start_bt; 308229997Sken}; 309229997Sken 310229997Skenstruct ctl_ooa { 311229997Sken ctl_ooa_flags flags; /* passed to kernel */ 312229997Sken uint64_t lun_num; /* passed to kernel */ 313229997Sken uint32_t alloc_len; /* passed to kernel */ 314229997Sken uint32_t alloc_num; /* passed to kernel */ 315229997Sken struct ctl_ooa_entry *entries; /* filled in kernel */ 316229997Sken uint32_t fill_len; /* passed to userland */ 317229997Sken uint32_t fill_num; /* passed to userland */ 318229997Sken uint32_t dropped_num; /* passed to userland */ 319229997Sken struct bintime cur_bt; /* passed to userland */ 320229997Sken ctl_get_ooa_status status; /* passed to userland */ 321229997Sken}; 322229997Sken 323229997Skentypedef enum { 324229997Sken CTL_LUN_NOSTATUS, 325229997Sken CTL_LUN_OK, 326273315Smav CTL_LUN_ERROR, 327273315Smav CTL_LUN_WARNING 328229997Sken} ctl_lun_status; 329229997Sken 330229997Sken#define CTL_ERROR_STR_LEN 160 331229997Sken 332229997Sken#define CTL_BEARG_RD 0x01 333229997Sken#define CTL_BEARG_WR 0x02 334229997Sken#define CTL_BEARG_RW (CTL_BEARG_RD|CTL_BEARG_WR) 335229997Sken#define CTL_BEARG_ASCII 0x04 336229997Sken 337229997Sken/* 338229997Sken * Backend Argument: 339229997Sken * 340229997Sken * namelen: Length of the name field, including the terminating NUL. 341229997Sken * 342311402Smav * name: Name of the parameter. This must be NUL-terminated. 343229997Sken * 344229997Sken * flags: Flags for the parameter, see above for values. 345229997Sken * 346229997Sken * vallen: Length of the value in bytes. 347229997Sken * 348229997Sken * value: Value to be set/fetched. 349229997Sken * 350229997Sken * kname: For kernel use only. 351229997Sken * 352229997Sken * kvalue: For kernel use only. 353229997Sken */ 354229997Skenstruct ctl_be_arg { 355229997Sken int namelen; 356229997Sken char *name; 357229997Sken int flags; 358229997Sken int vallen; 359229997Sken void *value; 360229997Sken 361229997Sken char *kname; 362229997Sken void *kvalue; 363229997Sken}; 364229997Sken 365229997Skentypedef enum { 366229997Sken CTL_LUNREQ_CREATE, 367232604Strasz CTL_LUNREQ_RM, 368232604Strasz CTL_LUNREQ_MODIFY, 369229997Sken} ctl_lunreq_type; 370229997Sken 371312841Smav/* 372312841Smav * The ID_REQ flag is used to say that the caller has requested a 373312841Smav * particular LUN ID in the req_lun_id field. If we cannot allocate that 374312841Smav * LUN ID, the ctl_add_lun() call will fail. 375312841Smav * 376312841Smav * The STOPPED flag tells us that the LUN should default to the powered 377312841Smav * off state. It will return 0x04,0x02 until it is powered up. ("Logical 378312841Smav * unit not ready, initializing command required.") 379312841Smav * 380312841Smav * The NO_MEDIA flag tells us that the LUN has no media inserted. 381312841Smav * 382312841Smav * The PRIMARY flag tells us that this LUN is registered as a Primary LUN 383312841Smav * which is accessible via the Master shelf controller in an HA. This flag 384312841Smav * being set indicates a Primary LUN. This flag being reset represents a 385312841Smav * Secondary LUN controlled by the Secondary controller in an HA 386312841Smav * configuration. Flag is applicable at this time to T_DIRECT types. 387312841Smav * 388312841Smav * The SERIAL_NUM flag tells us that the serial_num field is filled in and 389312841Smav * valid for use in SCSI INQUIRY VPD page 0x80. 390312841Smav * 391312841Smav * The DEVID flag tells us that the device_id field is filled in and 392312841Smav * valid for use in SCSI INQUIRY VPD page 0x83. 393312841Smav * 394312841Smav * The DEV_TYPE flag tells us that the device_type field is filled in. 395312841Smav * 396312841Smav * The EJECTED flag tells us that the removable LUN has tray open. 397312841Smav * 398312841Smav * The UNMAP flag tells us that this LUN supports UNMAP. 399312841Smav * 400312841Smav * The OFFLINE flag tells us that this LUN can not access backing store. 401312841Smav */ 402312841Smavtypedef enum { 403312841Smav CTL_LUN_FLAG_ID_REQ = 0x01, 404312841Smav CTL_LUN_FLAG_STOPPED = 0x02, 405312841Smav CTL_LUN_FLAG_NO_MEDIA = 0x04, 406312841Smav CTL_LUN_FLAG_PRIMARY = 0x08, 407312841Smav CTL_LUN_FLAG_SERIAL_NUM = 0x10, 408312841Smav CTL_LUN_FLAG_DEVID = 0x20, 409312841Smav CTL_LUN_FLAG_DEV_TYPE = 0x40, 410312841Smav CTL_LUN_FLAG_UNMAP = 0x80, 411312841Smav CTL_LUN_FLAG_EJECTED = 0x100, 412312841Smav CTL_LUN_FLAG_READONLY = 0x200 413312841Smav} ctl_backend_lun_flags; 414229997Sken 415229997Sken/* 416229997Sken * LUN creation parameters: 417229997Sken * 418312841Smav * flags: Various LUN flags, see above. 419229997Sken * 420229997Sken * device_type: The SCSI device type. e.g. 0 for Direct Access, 421229997Sken * 3 for Processor, etc. Only certain backends may 422229997Sken * support setting this field. The CTL_LUN_FLAG_DEV_TYPE 423229997Sken * flag should be set in the flags field if the device 424229997Sken * type is set. 425229997Sken * 426229997Sken * lun_size_bytes: The size of the LUN in bytes. For some backends 427229997Sken * this is relevant (e.g. ramdisk), for others, it may 428229997Sken * be ignored in favor of using the properties of the 429229997Sken * backing store. If specified, this should be a 430229997Sken * multiple of the blocksize. 431229997Sken * 432229997Sken * The actual size of the LUN is returned in this 433229997Sken * field. 434229997Sken * 435229997Sken * blocksize_bytes: The LUN blocksize in bytes. For some backends this 436229997Sken * is relevant, for others it may be ignored in 437229997Sken * favor of using the properties of the backing store. 438229997Sken * 439229997Sken * The actual blocksize of the LUN is returned in this 440229997Sken * field. 441229997Sken * 442229997Sken * req_lun_id: The requested LUN ID. The CTL_LUN_FLAG_ID_REQ flag 443229997Sken * should be set if this is set. The request will be 444229997Sken * granted if the LUN number is available, otherwise 445229997Sken * the LUN addition request will fail. 446229997Sken * 447229997Sken * The allocated LUN number is returned in this field. 448229997Sken * 449229997Sken * serial_num: This is the value returned in SCSI INQUIRY VPD page 450229997Sken * 0x80. If it is specified, the CTL_LUN_FLAG_SERIAL_NUM 451229997Sken * flag should be set. 452229997Sken * 453229997Sken * The serial number value used is returned in this 454229997Sken * field. 455229997Sken * 456229997Sken * device_id: This is the value returned in the T10 vendor ID 457229997Sken * based DESIGNATOR field in the SCSI INQUIRY VPD page 458229997Sken * 0x83 data. If it is specified, the CTL_LUN_FLAG_DEVID 459229997Sken * flag should be set. 460229997Sken * 461229997Sken * The device id value used is returned in this field. 462229997Sken */ 463229997Skenstruct ctl_lun_create_params { 464229997Sken ctl_backend_lun_flags flags; 465229997Sken uint8_t device_type; 466229997Sken uint64_t lun_size_bytes; 467229997Sken uint32_t blocksize_bytes; 468229997Sken uint32_t req_lun_id; 469229997Sken uint8_t serial_num[CTL_SN_LEN]; 470229997Sken uint8_t device_id[CTL_DEVID_LEN]; 471229997Sken}; 472229997Sken 473229997Sken/* 474229997Sken * LUN removal parameters: 475229997Sken * 476229997Sken * lun_id: The number of the LUN to delete. This must be set. 477229997Sken * The LUN must be backed by the given backend. 478229997Sken */ 479229997Skenstruct ctl_lun_rm_params { 480229997Sken uint32_t lun_id; 481229997Sken}; 482229997Sken 483229997Sken/* 484232604Strasz * LUN modification parameters: 485232604Strasz * 486232604Strasz * lun_id: The number of the LUN to modify. This must be set. 487232604Strasz * The LUN must be backed by the given backend. 488232604Strasz * 489232604Strasz * lun_size_bytes: The size of the LUN in bytes. If zero, update 490232604Strasz * the size using the backing file size, if possible. 491232604Strasz */ 492232604Straszstruct ctl_lun_modify_params { 493232604Strasz uint32_t lun_id; 494232604Strasz uint64_t lun_size_bytes; 495232604Strasz}; 496232604Strasz 497232604Strasz/* 498229997Sken * Union of request type data. Fill in the appropriate union member for 499229997Sken * the request type. 500229997Sken */ 501229997Skenunion ctl_lunreq_data { 502229997Sken struct ctl_lun_create_params create; 503229997Sken struct ctl_lun_rm_params rm; 504232604Strasz struct ctl_lun_modify_params modify; 505229997Sken}; 506229997Sken 507229997Sken/* 508229997Sken * LUN request interface: 509229997Sken * 510229997Sken * backend: This is required, and is NUL-terminated a string 511229997Sken * that is the name of the backend, like "ramdisk" or 512229997Sken * "block". 513229997Sken * 514229997Sken * reqtype: The type of request, CTL_LUNREQ_CREATE to create a 515229997Sken * LUN, CTL_LUNREQ_RM to delete a LUN. 516229997Sken * 517229997Sken * reqdata: Request type-specific information. See the 518229997Sken * description of individual the union members above 519229997Sken * for more information. 520229997Sken * 521229997Sken * num_be_args: This is the number of backend-specific arguments 522229997Sken * in the be_args array. 523229997Sken * 524229997Sken * be_args: This is an array of backend-specific arguments. 525229997Sken * See above for a description of the fields in this 526229997Sken * structure. 527229997Sken * 528229997Sken * status: Status of the LUN request. 529229997Sken * 530229997Sken * error_str: If the status is CTL_LUN_ERROR, this will 531229997Sken * contain a string describing the error. 532229997Sken * 533229997Sken * kern_be_args: For kernel use only. 534229997Sken */ 535229997Skenstruct ctl_lun_req { 536312841Smav#define CTL_BE_NAME_LEN 32 537229997Sken char backend[CTL_BE_NAME_LEN]; 538229997Sken ctl_lunreq_type reqtype; 539229997Sken union ctl_lunreq_data reqdata; 540229997Sken int num_be_args; 541229997Sken struct ctl_be_arg *be_args; 542229997Sken ctl_lun_status status; 543229997Sken char error_str[CTL_ERROR_STR_LEN]; 544229997Sken struct ctl_be_arg *kern_be_args; 545229997Sken}; 546229997Sken 547229997Sken/* 548229997Sken * LUN list status: 549229997Sken * 550229997Sken * NONE: No status. 551229997Sken * 552229997Sken * OK: Request completed successfully. 553229997Sken * 554229997Sken * NEED_MORE_SPACE: The allocated length of the entries field is too 555229997Sken * small for the available data. 556229997Sken * 557311402Smav * ERROR: An error occurred, look at the error string for a 558229997Sken * description of the error. 559229997Sken */ 560229997Skentypedef enum { 561229997Sken CTL_LUN_LIST_NONE, 562229997Sken CTL_LUN_LIST_OK, 563229997Sken CTL_LUN_LIST_NEED_MORE_SPACE, 564229997Sken CTL_LUN_LIST_ERROR 565229997Sken} ctl_lun_list_status; 566229997Sken 567229997Sken/* 568229997Sken * LUN list interface 569229997Sken * 570229997Sken * backend_name: This is a NUL-terminated string. If the string 571229997Sken * length is 0, then all LUNs on all backends will 572229997Sken * be enumerated. Otherwise this is the name of the 573229997Sken * backend to be enumerated, like "ramdisk" or "block". 574229997Sken * 575229997Sken * alloc_len: The length of the data buffer allocated for entries. 576229997Sken * In order to properly size the buffer, make one call 577229997Sken * with alloc_len set to 0, and then use the returned 578229997Sken * dropped_len as the buffer length to allocate and 579229997Sken * pass in on a subsequent call. 580229997Sken * 581229997Sken * lun_xml: XML-formatted information on the requested LUNs. 582229997Sken * 583229997Sken * fill_len: The amount of data filled in the storage for entries. 584229997Sken * 585229997Sken * status: The status of the request. See above for the 586229997Sken * description of the values of this field. 587229997Sken * 588229997Sken * error_str: If the status indicates an error, this string will 589229997Sken * be filled in to describe the error. 590229997Sken */ 591229997Skenstruct ctl_lun_list { 592229997Sken char backend[CTL_BE_NAME_LEN]; /* passed to kernel*/ 593229997Sken uint32_t alloc_len; /* passed to kernel */ 594229997Sken char *lun_xml; /* filled in kernel */ 595229997Sken uint32_t fill_len; /* passed to userland */ 596229997Sken ctl_lun_list_status status; /* passed to userland */ 597229997Sken char error_str[CTL_ERROR_STR_LEN]; 598229997Sken /* passed to userland */ 599229997Sken}; 600229997Sken 601255570Strasz/* 602268682Smav * Port request interface: 603268682Smav * 604268682Smav * driver: This is required, and is NUL-terminated a string 605268682Smav * that is the name of the frontend, like "iscsi" . 606268682Smav * 607268682Smav * reqtype: The type of request, CTL_REQ_CREATE to create a 608268682Smav * port, CTL_REQ_REMOVE to delete a port. 609268682Smav * 610268682Smav * num_be_args: This is the number of frontend-specific arguments 611268682Smav * in the be_args array. 612268682Smav * 613268682Smav * be_args: This is an array of frontend-specific arguments. 614268682Smav * See above for a description of the fields in this 615268682Smav * structure. 616268682Smav * 617268682Smav * status: Status of the request. 618268682Smav * 619268682Smav * error_str: If the status is CTL_LUN_ERROR, this will 620268682Smav * contain a string describing the error. 621268682Smav * 622268682Smav * kern_be_args: For kernel use only. 623268682Smav */ 624268682Smavtypedef enum { 625268682Smav CTL_REQ_CREATE, 626268682Smav CTL_REQ_REMOVE, 627268682Smav CTL_REQ_MODIFY, 628268682Smav} ctl_req_type; 629268682Smav 630268682Smavstruct ctl_req { 631268682Smav char driver[CTL_DRIVER_NAME_LEN]; 632268682Smav ctl_req_type reqtype; 633268682Smav int num_args; 634268682Smav struct ctl_be_arg *args; 635268682Smav ctl_lun_status status; 636268682Smav char error_str[CTL_ERROR_STR_LEN]; 637268682Smav struct ctl_be_arg *kern_args; 638268682Smav}; 639268682Smav 640268682Smav/* 641255570Strasz * iSCSI status 642255570Strasz * 643255570Strasz * OK: Request completed successfully. 644255570Strasz * 645311402Smav * ERROR: An error occurred, look at the error string for a 646255570Strasz * description of the error. 647255570Strasz * 648255570Strasz * CTL_ISCSI_LIST_NEED_MORE_SPACE: 649255570Strasz * User has to pass larger buffer for CTL_ISCSI_LIST ioctl. 650255570Strasz */ 651255570Strasztypedef enum { 652255570Strasz CTL_ISCSI_OK, 653255570Strasz CTL_ISCSI_ERROR, 654255570Strasz CTL_ISCSI_LIST_NEED_MORE_SPACE, 655255570Strasz CTL_ISCSI_SESSION_NOT_FOUND 656255570Strasz} ctl_iscsi_status; 657255570Strasz 658255570Strasztypedef enum { 659255570Strasz CTL_ISCSI_HANDOFF, 660255570Strasz CTL_ISCSI_LIST, 661255570Strasz CTL_ISCSI_LOGOUT, 662255570Strasz CTL_ISCSI_TERMINATE, 663265508Strasz#if defined(ICL_KERNEL_PROXY) || 1 664265508Strasz /* 665265508Strasz * We actually need those in all cases, but leave the ICL_KERNEL_PROXY, 666265508Strasz * to remember to remove them along with rest of proxy code, eventually. 667265508Strasz */ 668255570Strasz CTL_ISCSI_LISTEN, 669255570Strasz CTL_ISCSI_ACCEPT, 670255570Strasz CTL_ISCSI_SEND, 671255570Strasz CTL_ISCSI_RECEIVE, 672255570Strasz#endif 673255570Strasz} ctl_iscsi_type; 674255570Strasz 675255570Strasztypedef enum { 676255570Strasz CTL_ISCSI_DIGEST_NONE, 677255570Strasz CTL_ISCSI_DIGEST_CRC32C 678255570Strasz} ctl_iscsi_digest; 679255570Strasz 680255570Strasz#define CTL_ISCSI_NAME_LEN 224 /* 223 bytes, by RFC 3720, + '\0' */ 681255570Strasz#define CTL_ISCSI_ADDR_LEN 47 /* INET6_ADDRSTRLEN + '\0' */ 682255570Strasz#define CTL_ISCSI_ALIAS_LEN 128 /* Arbitrary. */ 683255570Strasz 684255570Straszstruct ctl_iscsi_handoff_params { 685255570Strasz char initiator_name[CTL_ISCSI_NAME_LEN]; 686255570Strasz char initiator_addr[CTL_ISCSI_ADDR_LEN]; 687255570Strasz char initiator_alias[CTL_ISCSI_ALIAS_LEN]; 688268684Smav uint8_t initiator_isid[6]; 689255570Strasz char target_name[CTL_ISCSI_NAME_LEN]; 690255570Strasz int socket; 691255570Strasz int portal_group_tag; 692255570Strasz 693255570Strasz /* 694255570Strasz * Connection parameters negotiated by ctld(8). 695255570Strasz */ 696255570Strasz ctl_iscsi_digest header_digest; 697255570Strasz ctl_iscsi_digest data_digest; 698255570Strasz uint32_t cmdsn; 699255570Strasz uint32_t statsn; 700255570Strasz uint32_t max_recv_data_segment_length; 701255570Strasz uint32_t max_burst_length; 702255570Strasz uint32_t first_burst_length; 703255570Strasz uint32_t immediate_data; 704265507Strasz#ifdef ICL_KERNEL_PROXY 705265507Strasz int connection_id; 706265507Strasz int spare[3]; 707265507Strasz#else 708255739Strasz int spare[4]; 709265507Strasz#endif 710255570Strasz}; 711255570Strasz 712255570Straszstruct ctl_iscsi_list_params { 713255570Strasz uint32_t alloc_len; /* passed to kernel */ 714255570Strasz char *conn_xml; /* filled in kernel */ 715255570Strasz uint32_t fill_len; /* passed to userland */ 716255739Strasz int spare[4]; 717255570Strasz}; 718255570Strasz 719255570Straszstruct ctl_iscsi_logout_params { 720255570Strasz int connection_id; /* passed to kernel */ 721255570Strasz char initiator_name[CTL_ISCSI_NAME_LEN]; 722255570Strasz /* passed to kernel */ 723255570Strasz char initiator_addr[CTL_ISCSI_ADDR_LEN]; 724255570Strasz /* passed to kernel */ 725255570Strasz int all; /* passed to kernel */ 726255739Strasz int spare[4]; 727255570Strasz}; 728255570Strasz 729255570Straszstruct ctl_iscsi_terminate_params { 730255570Strasz int connection_id; /* passed to kernel */ 731255570Strasz char initiator_name[CTL_ISCSI_NAME_LEN]; 732255570Strasz /* passed to kernel */ 733255570Strasz char initiator_addr[CTL_ISCSI_NAME_LEN]; 734255570Strasz /* passed to kernel */ 735255570Strasz int all; /* passed to kernel */ 736255739Strasz int spare[4]; 737255570Strasz}; 738255570Strasz 739255570Strasz#ifdef ICL_KERNEL_PROXY 740255570Straszstruct ctl_iscsi_listen_params { 741255570Strasz int iser; 742255570Strasz int domain; 743255570Strasz int socktype; 744255570Strasz int protocol; 745255570Strasz struct sockaddr *addr; 746255570Strasz socklen_t addrlen; 747265509Strasz int portal_id; 748255739Strasz int spare[4]; 749255570Strasz}; 750255570Strasz 751255570Straszstruct ctl_iscsi_accept_params { 752255570Strasz int connection_id; 753265513Strasz int portal_id; 754265509Strasz struct sockaddr *initiator_addr; 755265513Strasz socklen_t initiator_addrlen; 756255739Strasz int spare[4]; 757255570Strasz}; 758255570Strasz 759255570Straszstruct ctl_iscsi_send_params { 760255570Strasz int connection_id; 761255570Strasz void *bhs; 762255570Strasz size_t spare; 763255570Strasz void *spare2; 764255570Strasz size_t data_segment_len; 765255570Strasz void *data_segment; 766265507Strasz int spare3[4]; 767255570Strasz}; 768255570Strasz 769255570Straszstruct ctl_iscsi_receive_params { 770255570Strasz int connection_id; 771255570Strasz void *bhs; 772255570Strasz size_t spare; 773255570Strasz void *spare2; 774255570Strasz size_t data_segment_len; 775255570Strasz void *data_segment; 776265507Strasz int spare3[4]; 777255570Strasz}; 778255570Strasz 779255570Strasz#endif /* ICL_KERNEL_PROXY */ 780255570Strasz 781255570Straszunion ctl_iscsi_data { 782255570Strasz struct ctl_iscsi_handoff_params handoff; 783255570Strasz struct ctl_iscsi_list_params list; 784255570Strasz struct ctl_iscsi_logout_params logout; 785255570Strasz struct ctl_iscsi_terminate_params terminate; 786255570Strasz#ifdef ICL_KERNEL_PROXY 787255570Strasz struct ctl_iscsi_listen_params listen; 788255570Strasz struct ctl_iscsi_accept_params accept; 789255570Strasz struct ctl_iscsi_send_params send; 790255570Strasz struct ctl_iscsi_receive_params receive; 791255570Strasz#endif 792255570Strasz}; 793255570Strasz 794255570Strasz/* 795255570Strasz * iSCSI interface 796255570Strasz * 797255570Strasz * status: The status of the request. See above for the 798255570Strasz * description of the values of this field. 799255570Strasz * 800255570Strasz * error_str: If the status indicates an error, this string will 801255570Strasz * be filled in to describe the error. 802255570Strasz */ 803255570Straszstruct ctl_iscsi { 804255570Strasz ctl_iscsi_type type; /* passed to kernel */ 805255570Strasz union ctl_iscsi_data data; /* passed to kernel */ 806255570Strasz ctl_iscsi_status status; /* passed to userland */ 807255570Strasz char error_str[CTL_ERROR_STR_LEN]; 808255570Strasz /* passed to userland */ 809255570Strasz}; 810255570Strasz 811279002Smavstruct ctl_lun_map { 812279002Smav uint32_t port; 813279002Smav uint32_t plun; 814279002Smav uint32_t lun; 815279002Smav}; 816279002Smav 817229997Sken#define CTL_IO _IOWR(CTL_MINOR, 0x00, union ctl_io) 818229997Sken#define CTL_ENABLE_PORT _IOW(CTL_MINOR, 0x04, struct ctl_port_entry) 819229997Sken#define CTL_DISABLE_PORT _IOW(CTL_MINOR, 0x05, struct ctl_port_entry) 820229997Sken#define CTL_DELAY_IO _IOWR(CTL_MINOR, 0x10, struct ctl_io_delay_info) 821229997Sken#define CTL_GETSTATS _IOWR(CTL_MINOR, 0x15, struct ctl_stats) 822229997Sken#define CTL_ERROR_INJECT _IOWR(CTL_MINOR, 0x16, struct ctl_error_desc) 823229997Sken#define CTL_GET_OOA _IOWR(CTL_MINOR, 0x18, struct ctl_ooa) 824229997Sken#define CTL_DUMP_STRUCTS _IO(CTL_MINOR, 0x19) 825229997Sken#define CTL_LUN_REQ _IOWR(CTL_MINOR, 0x21, struct ctl_lun_req) 826229997Sken#define CTL_LUN_LIST _IOWR(CTL_MINOR, 0x22, struct ctl_lun_list) 827229997Sken#define CTL_ERROR_INJECT_DELETE _IOW(CTL_MINOR, 0x23, struct ctl_error_desc) 828229997Sken#define CTL_SET_PORT_WWNS _IOW(CTL_MINOR, 0x24, struct ctl_port_entry) 829255570Strasz#define CTL_ISCSI _IOWR(CTL_MINOR, 0x25, struct ctl_iscsi) 830268682Smav#define CTL_PORT_REQ _IOWR(CTL_MINOR, 0x26, struct ctl_req) 831268682Smav#define CTL_PORT_LIST _IOWR(CTL_MINOR, 0x27, struct ctl_lun_list) 832279002Smav#define CTL_LUN_MAP _IOW(CTL_MINOR, 0x28, struct ctl_lun_map) 833312841Smav#define CTL_GET_LUN_STATS _IOWR(CTL_MINOR, 0x29, struct ctl_get_io_stats) 834312841Smav#define CTL_GET_PORT_STATS _IOWR(CTL_MINOR, 0x2a, struct ctl_get_io_stats) 835229997Sken 836229997Sken#endif /* _CTL_IOCTL_H_ */ 837229997Sken 838229997Sken/* 839229997Sken * vim: ts=8 840229997Sken */ 841