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