1*84333434Sdsl /* $NetBSD: iscsi_ioctl.h,v 1.3 2013/04/04 22:17:13 dsl Exp $ */ 204b70f55Sagc 304b70f55Sagc /*- 404b70f55Sagc * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc. 504b70f55Sagc * All rights reserved. 604b70f55Sagc * 704b70f55Sagc * This code is derived from software contributed to The NetBSD Foundation 804b70f55Sagc * by Wasabi Systems, Inc. 904b70f55Sagc * 1004b70f55Sagc * Redistribution and use in source and binary forms, with or without 1104b70f55Sagc * modification, are permitted provided that the following conditions 1204b70f55Sagc * are met: 1304b70f55Sagc * 1. Redistributions of source code must retain the above copyright 1404b70f55Sagc * notice, this list of conditions and the following disclaimer. 1504b70f55Sagc * 2. Redistributions in binary form must reproduce the above copyright 1604b70f55Sagc * notice, this list of conditions and the following disclaimer in the 1704b70f55Sagc * documentation and/or other materials provided with the distribution. 1804b70f55Sagc * 1904b70f55Sagc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2004b70f55Sagc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2104b70f55Sagc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2204b70f55Sagc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2304b70f55Sagc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2404b70f55Sagc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2504b70f55Sagc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2604b70f55Sagc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2704b70f55Sagc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2804b70f55Sagc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2904b70f55Sagc * POSSIBILITY OF SUCH DAMAGE. 3004b70f55Sagc */ 3104b70f55Sagc #ifndef _ISCSI_IOCTL_H 3204b70f55Sagc #define _ISCSI_IOCTL_H 3304b70f55Sagc 3404b70f55Sagc #include <dev/iscsi/iscsi.h> 35*84333434Sdsl #include <sys/scsiio.h> 3604b70f55Sagc 3704b70f55Sagc /* ================== Interface Structures ======================== */ 3804b70f55Sagc 3904b70f55Sagc /* ===== Login, add_connection, and restore_connection ===== */ 4004b70f55Sagc 4104b70f55Sagc typedef struct { 4204b70f55Sagc uint32_t status; 4304b70f55Sagc int socket; 4404b70f55Sagc struct { 45eb8aeefaSchristos unsigned int HeaderDigest:1; 46eb8aeefaSchristos unsigned int DataDigest:1; 47eb8aeefaSchristos unsigned int MaxConnections:1; 48eb8aeefaSchristos unsigned int DefaultTime2Wait:1; 49eb8aeefaSchristos unsigned int DefaultTime2Retain:1; 50eb8aeefaSchristos unsigned int MaxRecvDataSegmentLength:1; 51eb8aeefaSchristos unsigned int auth_info:1; 52eb8aeefaSchristos unsigned int user_name:1; 53eb8aeefaSchristos unsigned int password:1; 54eb8aeefaSchristos unsigned int target_password:1; 55eb8aeefaSchristos unsigned int TargetName:1; 56eb8aeefaSchristos unsigned int TargetAlias:1; 57eb8aeefaSchristos unsigned int ErrorRecoveryLevel:1; 5804b70f55Sagc } is_present; 5904b70f55Sagc iscsi_auth_info_t auth_info; 6004b70f55Sagc iscsi_login_session_type_t login_type; 6104b70f55Sagc iscsi_digest_t HeaderDigest; 6204b70f55Sagc iscsi_digest_t DataDigest; 6304b70f55Sagc uint32_t session_id; 6404b70f55Sagc uint32_t connection_id; 6504b70f55Sagc uint32_t MaxRecvDataSegmentLength; 6604b70f55Sagc uint16_t MaxConnections; 6704b70f55Sagc uint16_t DefaultTime2Wait; 6804b70f55Sagc uint16_t DefaultTime2Retain; 6904b70f55Sagc uint16_t ErrorRecoveryLevel; 7004b70f55Sagc void *user_name; 7104b70f55Sagc void *password; 7204b70f55Sagc void *target_password; 7304b70f55Sagc void *TargetName; 7404b70f55Sagc void *TargetAlias; 7504b70f55Sagc } iscsi_login_parameters_t; 7604b70f55Sagc 7704b70f55Sagc /* 7804b70f55Sagc status 7904b70f55Sagc Contains, on return, the result of the command. 8004b70f55Sagc socket 8104b70f55Sagc A handle to the open TCP connection to the target portal. 8204b70f55Sagc is_present 8304b70f55Sagc Contains a bitfield that indicates which members of the 8404b70f55Sagc iscsi_login_parameters structure contain valid data. 8504b70f55Sagc auth_info 8604b70f55Sagc Is a bitfield of parameters for authorization. 8704b70f55Sagc The members are 8804b70f55Sagc mutual_auth Indicates that authentication should be mutual, i.e. 8904b70f55Sagc the initiator should authenticate the target, and the target 9004b70f55Sagc should authenticate the initiator. If not specified, the target 9104b70f55Sagc will authenticate the initiator only. 9204b70f55Sagc is_secure Indicates that the connection is secure. 9304b70f55Sagc auth_number Indicates the number of elements in auth_type. 9404b70f55Sagc When 0, no authentication will be used. 9504b70f55Sagc auth_type 9604b70f55Sagc Contains up to ISCSI_AUTH_OPTIONS enumerator values of type 9704b70f55Sagc iscsi_auth_types that indicates the authentication method that should 9804b70f55Sagc be used to establish a login connection (none, CHAP, KRB5, etc.), in 9904b70f55Sagc order of priority. The first element is the most preferred method, the 10004b70f55Sagc last element the least preferred. 10104b70f55Sagc login_type 10204b70f55Sagc Contains an enumerator value of type login_session_type that indicates 10304b70f55Sagc the type of logon session (discovery, informational, or full featured). 10404b70f55Sagc HeaderDigest 10504b70f55Sagc Indicates which digest (if any) to use for the PDU header. 10604b70f55Sagc DataDigest 10704b70f55Sagc Indicates which digest (if any) to use for the PDU data. 10804b70f55Sagc session_id 10904b70f55Sagc Login: OUT: Receives an integer that identifies the session. 11004b70f55Sagc Add_connection, Restore_connection: IN: Session ID. 11104b70f55Sagc connection_id 11204b70f55Sagc Login, Add_connection: OUT: Receives an integer that identifies the 11304b70f55Sagc connection. 11404b70f55Sagc Restore_connection: IN: Connection ID. 11504b70f55Sagc MaxRecvDataSegmentLength 11604b70f55Sagc Allows limiting or extending the maximum receive data segment length. 11704b70f55Sagc Must contain a value between 512 and 2**24-1 if specified. 11804b70f55Sagc MaxConnections 11904b70f55Sagc Contains a value between 1 and 65535 that specifies the maximum number 12004b70f55Sagc of connections to target devices that can be associated with a single 12104b70f55Sagc logon session. A value of 0 indicates that there no limit to the 12204b70f55Sagc number of connections. 12304b70f55Sagc DefaultTime2Wait 12404b70f55Sagc Specifies the minimum time to wait, in seconds, before attempting to 12504b70f55Sagc reconnect or reassign a connection that has been dropped. 12604b70f55Sagc The default is 2. 12704b70f55Sagc DefaultTime2Retain 12804b70f55Sagc Specifies the maximum time, in seconds, allowed to reassign a 12904b70f55Sagc connection after the initial wait indicated in DefaultTime2Retain has 13004b70f55Sagc elapsed. The default is 20. 13104b70f55Sagc ErrorRecoveryLevel 13204b70f55Sagc Specifies the desired error recovery level for the session. 13304b70f55Sagc The default and maximum is 2. 13404b70f55Sagc user_name 13504b70f55Sagc Sets the user (or CHAP) name to use during login authentication of the 13604b70f55Sagc initiator (zero terminated UTF-8 string). Default is initiator name. 13704b70f55Sagc password 13804b70f55Sagc Contains the password to use during login authentication of the 13904b70f55Sagc initiator (zero terminated UTF-8 string). Required if authentication 14004b70f55Sagc is requested. 14104b70f55Sagc target_password 14204b70f55Sagc Contains the password to use during login authentication of the target 14304b70f55Sagc (zero terminated UTF-8 string). Required if mutual authentication is 14404b70f55Sagc requested. 14504b70f55Sagc TargetName 14604b70f55Sagc Indicates the name of the target with which to establish the logon 14704b70f55Sagc session (zero terminated UTF-8 string). 14804b70f55Sagc TargetAlias 14904b70f55Sagc Receives the target alias as a zero terminated UTF-8 string. When 15004b70f55Sagc present, the buffer must be of size ISCSI_STRING_LENGTH. 15104b70f55Sagc */ 15204b70f55Sagc 15304b70f55Sagc 15404b70f55Sagc /* ===== Logout ===== */ 15504b70f55Sagc 15604b70f55Sagc typedef struct { 15704b70f55Sagc uint32_t status; 15804b70f55Sagc uint32_t session_id; 15904b70f55Sagc } iscsi_logout_parameters_t; 16004b70f55Sagc 16104b70f55Sagc /* 16204b70f55Sagc status 16304b70f55Sagc Contains, on return, the result of the command. 16404b70f55Sagc session_id 16504b70f55Sagc Contains an integer that identifies the session. 16604b70f55Sagc */ 16704b70f55Sagc 16804b70f55Sagc /* ===== remove_connection ===== */ 16904b70f55Sagc 17004b70f55Sagc typedef struct { 17104b70f55Sagc uint32_t status; 17204b70f55Sagc uint32_t session_id; 17304b70f55Sagc uint32_t connection_id; 17404b70f55Sagc } iscsi_remove_parameters_t; 17504b70f55Sagc 17604b70f55Sagc /* 17704b70f55Sagc status 17804b70f55Sagc Contains, on return, the result of the command. 17904b70f55Sagc session_id 18004b70f55Sagc Contains an integer that identifies the session. 18104b70f55Sagc connection_id 18204b70f55Sagc Contains an integer that identifies the connection. 18304b70f55Sagc */ 18404b70f55Sagc 18504b70f55Sagc /* ===== connection status ===== */ 18604b70f55Sagc 18704b70f55Sagc typedef struct { 18804b70f55Sagc uint32_t status; 18904b70f55Sagc uint32_t session_id; 19004b70f55Sagc uint32_t connection_id; 19104b70f55Sagc } iscsi_conn_status_parameters_t; 19204b70f55Sagc 19304b70f55Sagc /* 19404b70f55Sagc status 19504b70f55Sagc Contains, on return, the result of the command. 19604b70f55Sagc session_id 19704b70f55Sagc Contains an integer that identifies the session. 19804b70f55Sagc connection_id 19904b70f55Sagc Contains an integer that identifies the connection. 20004b70f55Sagc */ 20104b70f55Sagc 20204b70f55Sagc /* ===== io_command ===== */ 20304b70f55Sagc 20404b70f55Sagc typedef struct { 20504b70f55Sagc uint32_t status; 20604b70f55Sagc uint32_t session_id; 20704b70f55Sagc uint32_t connection_id; 20804b70f55Sagc struct { 209eb8aeefaSchristos unsigned int immediate:1; 21004b70f55Sagc } options; 21104b70f55Sagc uint64_t lun; 21204b70f55Sagc scsireq_t req; 21304b70f55Sagc } iscsi_iocommand_parameters_t; 21404b70f55Sagc 21504b70f55Sagc /* 21604b70f55Sagc status 21704b70f55Sagc Contains, on return, the result of the command (an ISCSI_STATUS code). 21804b70f55Sagc lun 21904b70f55Sagc Indicates which of the target's logical units should provide the data. 22004b70f55Sagc session_id 22104b70f55Sagc Contains an integer that identifies the session. 22204b70f55Sagc connection_id 22304b70f55Sagc Contains an integer that identifies the connection. 22404b70f55Sagc This parameter is optional and should only be used for test purposes. 22504b70f55Sagc options 22604b70f55Sagc A bitfield indicating options for the command. 22704b70f55Sagc The members are 22804b70f55Sagc immediate Indicates that the command should be sent 22904b70f55Sagc immediately, ahead of any queued requests. 23004b70f55Sagc 23104b70f55Sagc req 23204b70f55Sagc Contains the parameters for the request as defined in sys/scsiio.h 23304b70f55Sagc typedef struct scsireq { 23404b70f55Sagc u_long flags; 23504b70f55Sagc u_long timeout; 23604b70f55Sagc uint8_t cmd[16]; 23704b70f55Sagc uint8_t cmdlen; 23804b70f55Sagc void * databuf; 23904b70f55Sagc u_long datalen; 24004b70f55Sagc u_long datalen_used; 24104b70f55Sagc uint8_t sense[SENSEBUFLEN]; 24204b70f55Sagc uint8_t senselen; 24304b70f55Sagc uint8_t senselen_used; 24404b70f55Sagc uint8_t status; 24504b70f55Sagc uint8_t retsts; 24604b70f55Sagc int error; 24704b70f55Sagc } scsireq_t; 24804b70f55Sagc 24904b70f55Sagc flags 25004b70f55Sagc Indicates request status and type. 25104b70f55Sagc timeout 25204b70f55Sagc Indicates a timeout value (reserved). 25304b70f55Sagc cmd 25404b70f55Sagc SCSI command buffer. 25504b70f55Sagc cmdlen 25604b70f55Sagc Length of SCSI command in cmd. 25704b70f55Sagc databuf 25804b70f55Sagc Pointer to user-space buffer that holds the data 25904b70f55Sagc read or written by the SCSI command. 26004b70f55Sagc datalen 26104b70f55Sagc Indicates the size in bytes of the buffer at databuf. 26204b70f55Sagc datalen_used 26304b70f55Sagc Returns the number of bytes actually read or written. 26404b70f55Sagc sense 26504b70f55Sagc Sense data buffer. 26604b70f55Sagc senselen 26704b70f55Sagc Indicates the requested size of sense data. Must not exceed 26804b70f55Sagc SENSEBUFLEN (48). 26904b70f55Sagc senselen_used 27004b70f55Sagc Contains, on return, the number of bytes written to sense. 27104b70f55Sagc status 27204b70f55Sagc Contains, on return, the original SCSI status (reserved). 27304b70f55Sagc retsts 27404b70f55Sagc Contains, on return, the status of the command as defined in scsiio.h. 27504b70f55Sagc error 27604b70f55Sagc Contains, on return, the original SCSI error bits (reserved). 27704b70f55Sagc */ 27804b70f55Sagc 27904b70f55Sagc 28004b70f55Sagc /* ===== send_targets ===== */ 28104b70f55Sagc 28204b70f55Sagc typedef struct { 28304b70f55Sagc uint32_t status; 28404b70f55Sagc uint32_t session_id; 28504b70f55Sagc void *response_buffer; 28604b70f55Sagc uint32_t response_size; 28704b70f55Sagc uint32_t response_used; 28804b70f55Sagc uint32_t response_total; 28904b70f55Sagc uint8_t key[ISCSI_STRING_LENGTH]; 29004b70f55Sagc } iscsi_send_targets_parameters_t; 29104b70f55Sagc 29204b70f55Sagc /* 29304b70f55Sagc status 29404b70f55Sagc Contains, on return, the result of the command. 29504b70f55Sagc session_id 29604b70f55Sagc Contains an integer that identifies the session. 29704b70f55Sagc response_buffer 29804b70f55Sagc User mode address of buffer to hold the response data retrieved by 29904b70f55Sagc the iSCSI send targets command. 30004b70f55Sagc response_size 30104b70f55Sagc Contains, on input, the size in bytes of the buffer at 30204b70f55Sagc response_buffer. If this is 0, the command will execute the 30304b70f55Sagc SendTargets request, and return (in response_total) the number of 30404b70f55Sagc bytes required. 30504b70f55Sagc response_used 30604b70f55Sagc Contains, on return, the number of bytes actually retrieved to 30704b70f55Sagc response_buffer. 30804b70f55Sagc response_total 30904b70f55Sagc Contains, on return, the total number of bytes required to hold the 31004b70f55Sagc complete list of targets. This may be larger than response_size. 31104b70f55Sagc key 31204b70f55Sagc Specifies the SendTargets key value ("All", <target name>, or empty). 31304b70f55Sagc */ 31404b70f55Sagc 31504b70f55Sagc /* ===== set_node_name ===== */ 31604b70f55Sagc 31704b70f55Sagc typedef struct { 31804b70f55Sagc uint32_t status; 31904b70f55Sagc uint8_t InitiatorName[ISCSI_STRING_LENGTH]; 32004b70f55Sagc uint8_t InitiatorAlias[ISCSI_STRING_LENGTH]; 32104b70f55Sagc uint8_t ISID[6]; 32204b70f55Sagc } iscsi_set_node_name_parameters_t; 32304b70f55Sagc 32404b70f55Sagc /* 32504b70f55Sagc status 32604b70f55Sagc Contains, on return, the result of the command. 32704b70f55Sagc InitiatorName 32804b70f55Sagc Specifies the InitiatorName used during login. Required. 32904b70f55Sagc InitiatorAlias 33004b70f55Sagc Specifies the InitiatorAlias for use during login. May be empty. 33104b70f55Sagc ISID 33204b70f55Sagc Specifies the ISID (a 6 byte binary value) for use during login. 33304b70f55Sagc May be zero (all bytes) for the initiator to use a default value. 33404b70f55Sagc */ 33504b70f55Sagc 33604b70f55Sagc /* ===== register_event and deregister_event ===== */ 33704b70f55Sagc 33804b70f55Sagc typedef struct { 33904b70f55Sagc uint32_t status; 34004b70f55Sagc uint32_t event_id; 34104b70f55Sagc } iscsi_register_event_parameters_t; 34204b70f55Sagc 34304b70f55Sagc /* 34404b70f55Sagc status 34504b70f55Sagc Contains, on return, the result of the command. 34604b70f55Sagc event_id 34704b70f55Sagc Returns driver-assigned event ID to be used in 34804b70f55Sagc subsequent calls to wait_event and deregister_event. 34904b70f55Sagc */ 35004b70f55Sagc 35104b70f55Sagc /* ===== wait_event ===== */ 35204b70f55Sagc 35304b70f55Sagc typedef enum { 35404b70f55Sagc ISCSI_SESSION_TERMINATED = 1, 35504b70f55Sagc ISCSI_CONNECTION_TERMINATED, 35604b70f55Sagc ISCSI_RECOVER_CONNECTION, 35704b70f55Sagc ISCSI_DRIVER_TERMINATING 35804b70f55Sagc } iscsi_event_t; 35904b70f55Sagc 36004b70f55Sagc /* 36104b70f55Sagc Driver Events 36204b70f55Sagc 36304b70f55Sagc ISCSI_SESSION_TERMINATED 36404b70f55Sagc The specified session (including all of its associated connections) 36504b70f55Sagc has been terminated. 36604b70f55Sagc ISCSI_CONNECTION_TERMINATED 36704b70f55Sagc The specified connection has been terminated. 36804b70f55Sagc ISCSI_RECOVER_CONNECTION 36904b70f55Sagc The application should attempt to recover the given connection. 37004b70f55Sagc ISCSI_DRIVER_TERMINATING 37104b70f55Sagc The driver is unloading. 37204b70f55Sagc The application MUST call ISCSI_DEREGISTER_EVENT as soon as possible 37304b70f55Sagc after receiving this event. After performing the deregister IOCTL, 37404b70f55Sagc the application must no longer attempt to access the driver. 37504b70f55Sagc */ 37604b70f55Sagc 37704b70f55Sagc 37804b70f55Sagc typedef struct { 37904b70f55Sagc uint32_t status; 38004b70f55Sagc uint32_t event_id; 38104b70f55Sagc iscsi_event_t event_kind; 38204b70f55Sagc uint32_t session_id; 38304b70f55Sagc uint32_t connection_id; 38404b70f55Sagc uint32_t reason; 38504b70f55Sagc } iscsi_wait_event_parameters_t; 38604b70f55Sagc 38704b70f55Sagc /* 38804b70f55Sagc status 38904b70f55Sagc Contains, on return, the result of the command. 39004b70f55Sagc event_id 39104b70f55Sagc Driver assigned event ID. 39204b70f55Sagc event_kind 39304b70f55Sagc Identifies the event. 39404b70f55Sagc session_id 39504b70f55Sagc Identifies the affected session (0 for DRIVER_TERMINATING). 39604b70f55Sagc connection_id 39704b70f55Sagc Identifies the affected connection (0 for DRIVER_TERMINATING). 39804b70f55Sagc reason 39904b70f55Sagc Identifies the termination reason (ISCSI status code). 40004b70f55Sagc */ 40104b70f55Sagc 40204b70f55Sagc typedef struct { 40304b70f55Sagc uint32_t status; 40404b70f55Sagc uint16_t interface_version; 40504b70f55Sagc uint16_t major; 40604b70f55Sagc uint16_t minor; 40704b70f55Sagc uint8_t version_string[ISCSI_STRING_LENGTH]; 40804b70f55Sagc } iscsi_get_version_parameters_t; 40904b70f55Sagc 41004b70f55Sagc /* 41104b70f55Sagc status 41204b70f55Sagc Contains, on return, the result of the command. 41304b70f55Sagc interface_version 41404b70f55Sagc Updated when interface changes. Current Version is 2. 41504b70f55Sagc major 41604b70f55Sagc Major version number. 41704b70f55Sagc minor 41804b70f55Sagc Minor version number. 41904b70f55Sagc version_string 42004b70f55Sagc Displayable version string (zero terminated). 42104b70f55Sagc */ 42204b70f55Sagc 42304b70f55Sagc /* ========================= IOCTL Codes =========================== */ 42404b70f55Sagc 42504b70f55Sagc #define ISCSI_GET_VERSION _IOWR(0, 1, iscsi_get_version_parameters_t) 42604b70f55Sagc #define ISCSI_LOGIN _IOWR(0, 2, iscsi_login_parameters_t) 42704b70f55Sagc #define ISCSI_LOGOUT _IOWR(0, 3, iscsi_logout_parameters_t) 42804b70f55Sagc #define ISCSI_ADD_CONNECTION _IOWR(0, 4, iscsi_login_parameters_t) 42904b70f55Sagc #define ISCSI_RESTORE_CONNECTION _IOWR(0, 5, iscsi_login_parameters_t) 43004b70f55Sagc #define ISCSI_REMOVE_CONNECTION _IOWR(0, 6, iscsi_remove_parameters_t) 43104b70f55Sagc #define ISCSI_CONNECTION_STATUS _IOWR(0, 7, iscsi_conn_status_parameters_t) 43204b70f55Sagc #define ISCSI_SEND_TARGETS _IOWR(0, 8, iscsi_send_targets_parameters_t) 43304b70f55Sagc #define ISCSI_SET_NODE_NAME _IOWR(0, 9, iscsi_set_node_name_parameters_t) 43404b70f55Sagc #define ISCSI_IO_COMMAND _IOWR(0, 10, iscsi_iocommand_parameters_t) 43504b70f55Sagc #define ISCSI_REGISTER_EVENT _IOWR(0, 11, iscsi_register_event_parameters_t) 43604b70f55Sagc #define ISCSI_DEREGISTER_EVENT _IOWR(0, 12, iscsi_register_event_parameters_t) 43704b70f55Sagc #define ISCSI_WAIT_EVENT _IOWR(0, 13, iscsi_wait_event_parameters_t) 43804b70f55Sagc #define ISCSI_POLL_EVENT _IOWR(0, 14, iscsi_wait_event_parameters_t) 43904b70f55Sagc 44004b70f55Sagc #endif /* !_ISCSI_IOCTL_H */ 441