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