xref: /netbsd-src/sys/dev/iscsi/iscsi_ioctl.h (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1 /*	$NetBSD: iscsi_ioctl.h,v 1.2 2011/10/29 16:04:39 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Wasabi Systems, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 #ifndef _ISCSI_IOCTL_H
32 #define _ISCSI_IOCTL_H
33 
34 #include <dev/iscsi/iscsi.h>
35 
36 /* ==================  Interface Structures ======================== */
37 
38 /* ===== Login, add_connection, and restore_connection ===== */
39 
40 typedef struct {
41 	uint32_t status;
42 	int socket;
43 	struct {
44 		unsigned int HeaderDigest:1;
45 		unsigned int DataDigest:1;
46 		unsigned int MaxConnections:1;
47 		unsigned int DefaultTime2Wait:1;
48 		unsigned int DefaultTime2Retain:1;
49 		unsigned int MaxRecvDataSegmentLength:1;
50 		unsigned int auth_info:1;
51 		unsigned int user_name:1;
52 		unsigned int password:1;
53 		unsigned int target_password:1;
54 		unsigned int TargetName:1;
55 		unsigned int TargetAlias:1;
56 		unsigned int ErrorRecoveryLevel:1;
57 	} is_present;
58 	iscsi_auth_info_t auth_info;
59 	iscsi_login_session_type_t login_type;
60 	iscsi_digest_t HeaderDigest;
61 	iscsi_digest_t DataDigest;
62 	uint32_t session_id;
63 	uint32_t connection_id;
64 	uint32_t MaxRecvDataSegmentLength;
65 	uint16_t MaxConnections;
66 	uint16_t DefaultTime2Wait;
67 	uint16_t DefaultTime2Retain;
68 	uint16_t ErrorRecoveryLevel;
69 	void *user_name;
70 	void *password;
71 	void *target_password;
72 	void *TargetName;
73 	void *TargetAlias;
74 } iscsi_login_parameters_t;
75 
76 /*
77    status
78       Contains, on return, the result of the command.
79    socket
80       A handle to the open TCP connection to the target portal.
81    is_present
82       Contains a bitfield that indicates which members of the
83       iscsi_login_parameters structure contain valid data.
84    auth_info
85       Is a bitfield of parameters for authorization.
86       The members are
87          mutual_auth Indicates that authentication should be mutual, i.e.
88             the initiator should authenticate the target, and the target
89             should authenticate the initiator. If not specified, the target
90             will authenticate the initiator only.
91          is_secure   Indicates that the connection is secure.
92          auth_number Indicates the number of elements in auth_type.
93             When 0, no authentication will be used.
94    auth_type
95       Contains up to ISCSI_AUTH_OPTIONS enumerator values of type
96       iscsi_auth_types that indicates the authentication method that should
97       be used to establish a login connection (none, CHAP, KRB5, etc.), in
98       order of priority.  The first element is the most preferred method, the
99       last element the least preferred.
100    login_type
101       Contains an enumerator value of type login_session_type that indicates
102       the type of logon session (discovery, informational, or full featured).
103    HeaderDigest
104       Indicates which digest (if any) to use for the PDU header.
105    DataDigest
106       Indicates which digest (if any) to use for the PDU data.
107    session_id
108       Login: OUT: Receives an integer that identifies the session.
109       Add_connection, Restore_connection: IN: Session ID.
110    connection_id
111       Login, Add_connection: OUT: Receives an integer that identifies the
112       connection.
113       Restore_connection: IN: Connection ID.
114    MaxRecvDataSegmentLength
115       Allows limiting or extending the maximum receive data segment length.
116       Must contain a value between 512 and 2**24-1 if specified.
117    MaxConnections
118       Contains a value between 1 and 65535 that specifies the maximum number
119       of connections to target devices that can be associated with a single
120       logon session. A value of 0 indicates that there no limit to the
121       number of connections.
122    DefaultTime2Wait
123       Specifies the minimum time to wait, in seconds, before attempting to
124       reconnect or reassign a connection that has been dropped.
125 	  The default is 2.
126    DefaultTime2Retain
127       Specifies the maximum time, in seconds, allowed to reassign a
128       connection after the initial wait indicated in DefaultTime2Retain has
129       elapsed. The default is 20.
130    ErrorRecoveryLevel
131       Specifies the desired error recovery level for the session.
132 	  The default and maximum is 2.
133    user_name
134       Sets the user (or CHAP) name to use during login authentication of the
135       initiator (zero terminated UTF-8 string). Default is initiator name.
136    password
137       Contains the password to use during login authentication of the
138       initiator (zero terminated UTF-8 string). Required if authentication
139       is requested.
140    target_password
141       Contains the password to use during login authentication of the target
142       (zero terminated UTF-8 string). Required if mutual authentication is
143       requested.
144    TargetName
145       Indicates the name of the target with which to establish the logon
146       session (zero terminated UTF-8 string).
147    TargetAlias
148       Receives the target alias as a zero terminated UTF-8 string. When
149       present, the buffer must be of size ISCSI_STRING_LENGTH.
150 */
151 
152 
153 /* ===== Logout ===== */
154 
155 typedef struct {
156 	uint32_t status;
157 	uint32_t session_id;
158 } iscsi_logout_parameters_t;
159 
160 /*
161    status
162       Contains, on return, the result of the command.
163    session_id
164       Contains an integer that identifies the session.
165 */
166 
167 /* ===== remove_connection ===== */
168 
169 typedef struct {
170 	uint32_t status;
171 	uint32_t session_id;
172 	uint32_t connection_id;
173 } iscsi_remove_parameters_t;
174 
175 /*
176    status
177       Contains, on return, the result of the command.
178    session_id
179       Contains an integer that identifies the session.
180    connection_id
181       Contains an integer that identifies the connection.
182 */
183 
184 /* ===== connection status ===== */
185 
186 typedef struct {
187 	uint32_t status;
188 	uint32_t session_id;
189 	uint32_t connection_id;
190 } iscsi_conn_status_parameters_t;
191 
192 /*
193    status
194       Contains, on return, the result of the command.
195    session_id
196       Contains an integer that identifies the session.
197    connection_id
198       Contains an integer that identifies the connection.
199 */
200 
201 /* ===== io_command ===== */
202 
203 typedef struct {
204 	uint32_t status;
205 	uint32_t session_id;
206 	uint32_t connection_id;
207 	struct {
208 		unsigned int immediate:1;
209 	} options;
210 	uint64_t lun;
211 	scsireq_t req;
212 } iscsi_iocommand_parameters_t;
213 
214 /*
215    status
216       Contains, on return, the result of the command (an ISCSI_STATUS code).
217    lun
218       Indicates which of the target's logical units should provide the data.
219    session_id
220       Contains an integer that identifies the session.
221    connection_id
222       Contains an integer that identifies the connection.
223       This parameter is optional and should only be used for test purposes.
224    options
225       A bitfield indicating options for the command.
226       The members are
227          immediate   Indicates that the command should be sent
228                      immediately, ahead of any queued requests.
229 
230    req
231       Contains the parameters for the request as defined in sys/scsiio.h
232       typedef struct scsireq {
233          u_long   flags;
234          u_long   timeout;
235          uint8_t   cmd[16];
236          uint8_t   cmdlen;
237          void * databuf;
238          u_long   datalen;
239          u_long   datalen_used;
240          uint8_t   sense[SENSEBUFLEN];
241          uint8_t   senselen;
242          uint8_t   senselen_used;
243          uint8_t   status;
244          uint8_t   retsts;
245          int      error;
246       } scsireq_t;
247 
248       flags
249          Indicates request status and type.
250       timeout
251          Indicates a timeout value (reserved).
252       cmd
253          SCSI command buffer.
254       cmdlen
255          Length of SCSI command in cmd.
256       databuf
257          Pointer to user-space buffer that holds the data
258          read or written by the SCSI command.
259       datalen
260          Indicates the size in bytes of the buffer at databuf.
261       datalen_used
262          Returns the number of bytes actually read or written.
263       sense
264          Sense data buffer.
265       senselen
266          Indicates the requested size of sense data. Must not exceed
267          SENSEBUFLEN (48).
268       senselen_used
269          Contains, on return, the number of bytes written to sense.
270       status
271          Contains, on return, the original SCSI status (reserved).
272       retsts
273          Contains, on return, the status of the command as defined in scsiio.h.
274       error
275          Contains, on return, the original SCSI error bits (reserved).
276 */
277 
278 
279 /* ===== send_targets ===== */
280 
281 typedef struct {
282 	uint32_t status;
283 	uint32_t session_id;
284 	void *response_buffer;
285 	uint32_t response_size;
286 	uint32_t response_used;
287 	uint32_t response_total;
288 	uint8_t key[ISCSI_STRING_LENGTH];
289 } iscsi_send_targets_parameters_t;
290 
291 /*
292    status
293       Contains, on return, the result of the command.
294    session_id
295       Contains an integer that identifies the session.
296    response_buffer
297       User mode address of buffer to hold the response data retrieved by
298       the iSCSI send targets command.
299    response_size
300       Contains, on input, the size in bytes of the buffer at
301       response_buffer. If this is 0, the command will execute the
302       SendTargets request, and return (in response_total) the number of
303       bytes required.
304    response_used
305       Contains, on return, the number of bytes actually retrieved to
306       response_buffer.
307    response_total
308       Contains, on return, the total number of bytes required to hold the
309       complete list of targets. This may be larger than response_size.
310    key
311       Specifies the SendTargets key value ("All", <target name>, or empty).
312 */
313 
314 /* ===== set_node_name ===== */
315 
316 typedef struct {
317 	uint32_t status;
318 	uint8_t InitiatorName[ISCSI_STRING_LENGTH];
319 	uint8_t InitiatorAlias[ISCSI_STRING_LENGTH];
320 	uint8_t ISID[6];
321 } iscsi_set_node_name_parameters_t;
322 
323 /*
324    status
325       Contains, on return, the result of the command.
326    InitiatorName
327       Specifies the InitiatorName used during login. Required.
328    InitiatorAlias
329       Specifies the InitiatorAlias for use during login. May be empty.
330    ISID
331       Specifies the ISID (a 6 byte binary value) for use during login.
332       May be zero (all bytes) for the initiator to use a default value.
333 */
334 
335 /* ===== register_event and deregister_event ===== */
336 
337 typedef struct {
338 	uint32_t status;
339 	uint32_t event_id;
340 } iscsi_register_event_parameters_t;
341 
342 /*
343    status
344       Contains, on return, the result of the command.
345    event_id
346       Returns driver-assigned event ID to be used in
347       subsequent calls to wait_event and deregister_event.
348 */
349 
350 /* ===== wait_event ===== */
351 
352 typedef enum {
353 	ISCSI_SESSION_TERMINATED = 1,
354 	ISCSI_CONNECTION_TERMINATED,
355 	ISCSI_RECOVER_CONNECTION,
356 	ISCSI_DRIVER_TERMINATING
357 } iscsi_event_t;
358 
359 /*
360    Driver Events
361 
362    ISCSI_SESSION_TERMINATED
363       The specified session (including all of its associated connections)
364       has been terminated.
365    ISCSI_CONNECTION_TERMINATED
366       The specified connection has been terminated.
367    ISCSI_RECOVER_CONNECTION
368       The application should attempt to recover the given connection.
369    ISCSI_DRIVER_TERMINATING
370       The driver is unloading.
371       The application MUST call ISCSI_DEREGISTER_EVENT as soon as possible
372       after receiving this event. After performing the deregister IOCTL,
373       the application must no longer attempt to access the driver.
374 */
375 
376 
377 typedef struct {
378 	uint32_t status;
379 	uint32_t event_id;
380 	iscsi_event_t event_kind;
381 	uint32_t session_id;
382 	uint32_t connection_id;
383 	uint32_t reason;
384 } iscsi_wait_event_parameters_t;
385 
386 /*
387    status
388       Contains, on return, the result of the command.
389    event_id
390       Driver assigned event ID.
391    event_kind
392       Identifies the event.
393    session_id
394       Identifies the affected session (0 for DRIVER_TERMINATING).
395    connection_id
396       Identifies the affected connection (0 for DRIVER_TERMINATING).
397    reason
398       Identifies the termination reason (ISCSI status code).
399 */
400 
401 typedef struct {
402 	uint32_t status;
403 	uint16_t interface_version;
404 	uint16_t major;
405 	uint16_t minor;
406 	uint8_t version_string[ISCSI_STRING_LENGTH];
407 } iscsi_get_version_parameters_t;
408 
409 /*
410    status
411       Contains, on return, the result of the command.
412    interface_version
413       Updated when interface changes. Current Version is 2.
414    major
415       Major version number.
416    minor
417       Minor version number.
418    version_string
419       Displayable version string (zero terminated).
420 */
421 
422 /* =========================  IOCTL Codes =========================== */
423 
424 #define ISCSI_GET_VERSION        _IOWR(0,  1, iscsi_get_version_parameters_t)
425 #define ISCSI_LOGIN              _IOWR(0,  2, iscsi_login_parameters_t)
426 #define ISCSI_LOGOUT             _IOWR(0,  3, iscsi_logout_parameters_t)
427 #define ISCSI_ADD_CONNECTION     _IOWR(0,  4, iscsi_login_parameters_t)
428 #define ISCSI_RESTORE_CONNECTION _IOWR(0,  5, iscsi_login_parameters_t)
429 #define ISCSI_REMOVE_CONNECTION  _IOWR(0,  6, iscsi_remove_parameters_t)
430 #define ISCSI_CONNECTION_STATUS  _IOWR(0,  7, iscsi_conn_status_parameters_t)
431 #define ISCSI_SEND_TARGETS       _IOWR(0,  8, iscsi_send_targets_parameters_t)
432 #define ISCSI_SET_NODE_NAME      _IOWR(0,  9, iscsi_set_node_name_parameters_t)
433 #define ISCSI_IO_COMMAND         _IOWR(0, 10, iscsi_iocommand_parameters_t)
434 #define ISCSI_REGISTER_EVENT     _IOWR(0, 11, iscsi_register_event_parameters_t)
435 #define ISCSI_DEREGISTER_EVENT   _IOWR(0, 12, iscsi_register_event_parameters_t)
436 #define ISCSI_WAIT_EVENT         _IOWR(0, 13, iscsi_wait_event_parameters_t)
437 #define ISCSI_POLL_EVENT         _IOWR(0, 14, iscsi_wait_event_parameters_t)
438 
439 #endif /* !_ISCSI_IOCTL_H */
440