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