Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / iscsi / dist / include / iscsiprotocol.h
blobe31b2bbddaa7292cd48de96f42bd08cf027b51a1
1 /*
2 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
3 * By downloading, copying, installing or using the software you agree
4 * to this license. If you do not agree to this license, do not
5 * download, install, copy or use the software.
7 * Intel License Agreement
9 * Copyright (c) 2000, Intel Corporation
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
16 * -Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
19 * -Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the
22 * distribution.
24 * -The name of Intel Corporation may not be used to endorse or
25 * promote products derived from this software without specific prior
26 * written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
35 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
41 #ifndef ISCSI_H
42 #define ISCSI_H
44 #include "iscsiutil.h"
47 * iSCSI Version 18
50 #define ISCSI_VENDOR "NetBSD"
51 #define ISCSI_PRODUCT "NetBSD iSCSI"
52 #define ISCSI_VERSION 0
55 * Parameters
58 #define ISCSI_IMMEDIATE_DATA_DFLT 1
59 #define ISCSI_INITIAL_R2T_DFLT 1
60 #define ISCSI_USE_PHASE_COLLAPSED_READ_DFLT 0
61 #define ISCSI_HEADER_LEN 48
62 #define ISCSI_PORT 3260 /* Default port */
63 #define ISCSI_OPCODE(HEADER) (HEADER[0] & 0x3f)
65 #define ISCSI_FIRST_BURST (ISCSI_FIRST_BURST_DFLT)
66 #define ISCSI_DATA_PDU_LENGTH (ISCSI_DATA_PDU_LENGTH_DFLT)
69 * Opcodes
71 enum {
72 ISCSI_NOP_OUT = 0x00,
73 ISCSI_SCSI_CMD = 0x01,
74 ISCSI_TASK_CMD = 0x02,
75 ISCSI_LOGIN_CMD = 0x03,
76 ISCSI_TEXT_CMD = 0x04,
77 ISCSI_WRITE_DATA = 0x05,
78 ISCSI_LOGOUT_CMD = 0x06,
79 ISCSI_SNACK = 0x10, /* not implemented */
80 ISCSI_NOP_IN = 0x20,
81 ISCSI_SCSI_RSP = 0x21,
82 ISCSI_TASK_RSP = 0x22,
83 ISCSI_LOGIN_RSP = 0x23,
84 ISCSI_TEXT_RSP = 0x24,
85 ISCSI_READ_DATA = 0x25,
86 ISCSI_LOGOUT_RSP = 0x26,
87 ISCSI_R2T = 0x31,
88 ISCSI_ASYNC = 0x32,
89 ISCSI_REJECT = 0x3f
92 enum {
93 ISCSI_AHS_EXTENDED_CDB = 0x01,
94 ISCSI_AHS_BIDI_READ = 0x02
98 * Login Phase
100 enum {
101 ISCSI_LOGIN_STATUS_SUCCESS = 0,
102 ISCSI_LOGIN_STATUS_REDIRECTION = 1,
103 ISCSI_LOGIN_STATUS_INITIATOR_ERROR = 2,
104 ISCSI_LOGIN_STATUS_TARGET_ERROR = 3,
106 ISCSI_LOGIN_STAGE_SECURITY = 0,
107 ISCSI_LOGIN_STAGE_NEGOTIATE = 1,
108 ISCSI_LOGIN_STAGE_FULL_FEATURE = 3
111 /* detailed return codes for login phase */
112 enum {
113 ISCSI_LOGIN_DETAIL_SUCCESS = 0x0,
114 ISCSI_LOGIN_DETAIL_INIT_AUTH_FAILURE = 0x01,
115 ISCSI_LOGIN_DETAIL_VERSION_NOT_SUPPORTED = 0x05,
116 ISCSI_LOGIN_DETAIL_NOT_LOGGED_IN = 0x0b
121 * Logout Phase
123 enum {
124 ISCSI_LOGOUT_CLOSE_SESSION = 0,
125 ISCSI_LOGOUT_CLOSE_CONNECTION = 1,
126 ISCSI_LOGOUT_CLOSE_RECOVERY = 2,
128 ISCSI_LOGOUT_STATUS_SUCCESS = 0,
129 ISCSI_LOGOUT_STATUS_NO_CID = 1,
130 ISCSI_LOGOUT_STATUS_NO_RECOVERY = 2,
131 ISCSI_LOGOUT_STATUS_FAILURE = 3
136 * Task Command
138 enum {
139 ISCSI_TASK_CMD_ABORT_TASK = 1,
140 ISCSI_TASK_CMD_ABORT_TASK_SET = 2,
141 ISCSI_TASK_CMD_CLEAR_ACA = 3,
142 ISCSI_TASK_CMD_CLEAR_TASK_SET = 4,
143 ISCSI_TASK_CMD_LOGICAL_UNIT_RESET = 5,
144 ISCSI_TASK_CMD_TARGET_WARM_RESET = 6,
145 ISCSI_TASK_CMD_TARGET_COLD_RESET = 7,
146 ISCSI_TASK_CMD_TARGET_REASSIGN = 8
149 typedef struct iscsi_task_cmd_t {
150 int32_t immediate;
151 uint8_t function;
152 uint64_t lun;
153 uint32_t tag;
154 uint32_t ref_tag;
155 uint32_t CmdSN;
156 uint32_t ExpStatSN;
157 uint32_t RefCmdSN;
158 uint32_t ExpDataSN;
159 } iscsi_task_cmd_t;
161 int iscsi_task_cmd_encap(uint8_t *header, iscsi_task_cmd_t * cmd);
162 int iscsi_task_cmd_decap(uint8_t *header, iscsi_task_cmd_t * cmd);
166 * Task Response
168 enum {
169 ISCSI_TASK_RSP_FUNCTION_COMPLETE = 0,
170 ISCSI_TASK_RSP_NO_SUCH_TASK = 1,
171 ISCSI_TASK_RSP_NO_SUCH_LUN = 2,
172 ISCSI_TASK_RSP_STILL_ALLEGIANT = 3,
173 ISCSI_TASK_RSP_NO_FAILOVER = 4,
174 ISCSI_TASK_RSP_NO_SUPPORT = 5,
175 ISCSI_TASK_RSP_AUTHORIZED_FAILED = 6,
177 ISCSI_TASK_RSP_REJECTED = 255,
179 ISCSI_TASK_QUAL_FUNCTION_EXECUTED = 0,
180 ISCSI_TASK_QUAL_NOT_AUTHORIZED = 1
183 typedef struct iscsi_task_rsp_t {
184 uint8_t response;
185 uint32_t length;
186 uint32_t tag;
187 uint32_t StatSN;
188 uint32_t ExpCmdSN;
189 uint32_t MaxCmdSN;
190 } iscsi_task_rsp_t;
192 int iscsi_task_rsp_encap(uint8_t *header, iscsi_task_rsp_t * rsp);
193 int iscsi_task_rsp_decap(uint8_t *header, iscsi_task_rsp_t * rsp);
197 * NOP-Out
201 typedef struct iscsi_nop_out_args_t {
202 int32_t immediate;
203 uint32_t length;
204 uint64_t lun;
205 uint32_t tag;
206 uint32_t transfer_tag;
207 uint32_t CmdSN;
208 uint32_t ExpStatSN;
209 const uint8_t *data;
210 } iscsi_nop_out_args_t;
212 int iscsi_nop_out_encap(uint8_t *header, iscsi_nop_out_args_t * cmd);
213 int iscsi_nop_out_decap(uint8_t *header, iscsi_nop_out_args_t * cmd);
217 * NOP-In
221 typedef struct iscsi_nop_in_args_t {
222 uint32_t length;
223 uint64_t lun;
224 uint32_t tag;
225 uint32_t transfer_tag;
226 uint32_t StatSN;
227 uint32_t ExpCmdSN;
228 uint32_t MaxCmdSN;
229 } iscsi_nop_in_args_t;
231 int iscsi_nop_in_encap(uint8_t *header, iscsi_nop_in_args_t * cmd);
232 int iscsi_nop_in_decap(uint8_t *header, iscsi_nop_in_args_t * cmd);
236 * Text Command
240 typedef struct iscsi_text_cmd_args_t {
241 int32_t immediate;
242 int32_t final;
243 int32_t cont;
244 uint32_t length;
245 uint64_t lun;
246 uint32_t tag;
247 uint32_t transfer_tag;
248 uint32_t CmdSN;
249 uint32_t ExpStatSN;
250 char *text;
251 } iscsi_text_cmd_args_t;
253 int iscsi_text_cmd_encap(uint8_t *header, iscsi_text_cmd_args_t * cmd);
254 int iscsi_text_cmd_decap(uint8_t *header, iscsi_text_cmd_args_t * cmd);
258 * Text Response
262 typedef struct iscsi_text_rsp_args_t {
263 int32_t final;
264 int32_t cont;
265 uint32_t length;
266 uint64_t lun;
267 uint32_t tag;
268 uint32_t transfer_tag;
269 uint32_t StatSN;
270 uint32_t ExpCmdSN;
271 uint32_t MaxCmdSN;
272 } iscsi_text_rsp_args_t;
274 int iscsi_text_rsp_encap(uint8_t *header, iscsi_text_rsp_args_t * rsp);
275 int iscsi_text_rsp_decap(uint8_t *header, iscsi_text_rsp_args_t * rsp);
279 * Login Command
283 typedef struct iscsi_login_cmd_args_t {
284 int32_t transit;
285 int32_t cont;
286 uint8_t csg;
287 uint8_t nsg;
288 int8_t version_max;
289 int8_t version_min;
290 uint8_t AHSlength;
291 uint32_t length;
292 uint64_t isid;
293 uint16_t tsih;
294 uint32_t tag;
295 uint16_t cid;
296 uint32_t CmdSN;
297 uint32_t ExpStatSN;
298 char *text;
299 } iscsi_login_cmd_args_t;
301 int iscsi_login_cmd_encap(uint8_t *header, iscsi_login_cmd_args_t * cmd);
302 int iscsi_login_cmd_decap(uint8_t *header, iscsi_login_cmd_args_t * cmd);
306 * Login Response
310 typedef struct iscsi_login_rsp_args_t {
311 int32_t transit;
312 int32_t cont;
313 uint8_t csg;
314 uint8_t nsg;
315 int8_t version_max;
316 int8_t version_active;
317 uint8_t AHSlength;
318 uint32_t length;
319 uint64_t isid;
320 uint16_t tsih;
321 uint32_t tag;
322 uint32_t StatSN;
323 uint32_t ExpCmdSN;
324 uint32_t MaxCmdSN;
325 uint8_t status_class;
326 uint8_t status_detail;
327 } iscsi_login_rsp_args_t;
329 int iscsi_login_rsp_encap(uint8_t *header, iscsi_login_rsp_args_t * rsp);
330 int iscsi_login_rsp_decap(uint8_t *header, iscsi_login_rsp_args_t * rsp);
334 * Logout Command
338 typedef struct iscsi_logout_cmd_args_t {
339 int32_t immediate;
340 uint8_t reason;
341 uint32_t tag;
342 uint16_t cid;
343 uint32_t CmdSN;
344 uint32_t ExpStatSN;
345 } iscsi_logout_cmd_args_t;
347 int iscsi_logout_cmd_encap(uint8_t *header, iscsi_logout_cmd_args_t * cmd);
348 int iscsi_logout_cmd_decap(uint8_t *header, iscsi_logout_cmd_args_t * cmd);
352 * Logout Response
356 typedef struct iscsi_logout_rsp_args_t {
357 uint8_t response;
358 uint32_t length;
359 uint32_t tag;
360 uint32_t StatSN;
361 uint32_t ExpCmdSN;
362 uint32_t MaxCmdSN;
363 uint16_t Time2Wait;
364 uint16_t Time2Retain;
365 } iscsi_logout_rsp_args_t;
367 int iscsi_logout_rsp_encap(uint8_t *header, iscsi_logout_rsp_args_t * rsp);
368 int iscsi_logout_rsp_decap(uint8_t *header, iscsi_logout_rsp_args_t * rsp);
372 * SCSI Command
376 typedef struct iscsi_scsi_cmd_args_t {
377 int32_t immediate;
378 int32_t final;
379 int32_t input;
380 int32_t output;
381 uint8_t attr;
382 uint32_t length;
383 uint64_t lun;
384 uint32_t tag;
385 uint32_t trans_len;
386 uint32_t bidi_trans_len;
387 uint32_t CmdSN;
388 uint32_t ExpStatSN;
389 uint8_t *cdb;
390 uint8_t *ext_cdb;
391 uint8_t *ahs;
392 uint8_t ahs_len;
393 uint8_t *send_data;
394 int32_t send_sg_len;
395 uint8_t *recv_data;
396 int32_t recv_sg_len;
397 uint8_t status;
398 uint32_t bytes_sent;
399 uint32_t bytes_recv;
400 } iscsi_scsi_cmd_args_t;
402 int iscsi_scsi_cmd_encap(uint8_t *header, iscsi_scsi_cmd_args_t * cmd);
403 int iscsi_scsi_cmd_decap(uint8_t *header, iscsi_scsi_cmd_args_t * cmd);
407 * SCSI Response
411 typedef struct iscsi_scsi_rsp_args_t {
412 int32_t bidi_overflow;
413 int32_t bidi_underflow;
414 int32_t overflow;
415 int32_t underflow;
418 uint8_t response;
419 uint8_t status;
420 uint32_t ahs_len;
421 uint32_t length;
422 uint32_t tag;
423 uint32_t StatSN;
424 uint32_t ExpCmdSN;
425 uint32_t MaxCmdSN;
426 uint32_t ExpDataSN;
427 uint32_t bidi_res_cnt;
428 uint32_t basic_res_cnt;
429 } iscsi_scsi_rsp_t;
431 int iscsi_scsi_rsp_encap(uint8_t *header, iscsi_scsi_rsp_t * rsp);
432 int iscsi_scsi_rsp_decap(uint8_t *header, iscsi_scsi_rsp_t * rsp);
436 * Ready To Transfer (R2T)
440 typedef struct iscsi_r2t_args_t {
441 uint32_t AHSlength;
442 uint64_t lun;
443 uint32_t tag;
444 uint32_t transfer_tag;
445 uint32_t StatSN;
446 uint32_t ExpCmdSN;
447 uint32_t MaxCmdSN;
448 uint32_t R2TSN;
449 uint32_t offset;
450 uint32_t length;
451 } iscsi_r2t_t;
453 int iscsi_r2t_encap(uint8_t *header, iscsi_r2t_t * cmd);
454 int iscsi_r2t_decap(uint8_t *header, iscsi_r2t_t * cmd);
458 * SCSI Write Data
462 typedef struct iscsi_write_data_args_t {
463 int32_t final;
464 uint32_t length;
465 uint64_t lun;
466 uint32_t tag;
467 uint32_t transfer_tag;
468 uint32_t ExpStatSN;
469 uint32_t DataSN;
470 uint32_t offset;
471 } iscsi_write_data_t;
473 int iscsi_write_data_encap(uint8_t *header, iscsi_write_data_t * cmd);
474 int iscsi_write_data_decap(uint8_t *header, iscsi_write_data_t * cmd);
478 * SCSI Read Data
482 typedef struct iscsi_read_data_args_t {
483 int32_t final;
484 int32_t ack;
485 int32_t overflow;
486 int32_t underflow;
487 int32_t S_bit;
488 uint8_t status;
489 uint32_t length;
490 uint64_t lun;
491 uint32_t task_tag;
492 uint32_t transfer_tag;
493 uint32_t StatSN;
494 uint32_t ExpCmdSN;
495 uint32_t MaxCmdSN;
496 uint32_t DataSN;
497 uint32_t offset;
498 uint32_t res_count;
499 } iscsi_read_data_t;
501 int iscsi_read_data_encap(uint8_t *header, iscsi_read_data_t * cmd);
502 int iscsi_read_data_decap(uint8_t *header, iscsi_read_data_t * cmd);
506 * Reject
509 typedef struct iscsi_reject_args_t {
510 uint8_t reason;
511 uint32_t length;
512 uint32_t StatSN;
513 uint32_t ExpCmdSN;
514 uint32_t MaxCmdSN;
515 uint32_t DataSN;
516 char *header;
518 } iscsi_reject_t;
520 int iscsi_reject_encap(uint8_t *header, iscsi_reject_t * cmd);
521 int iscsi_reject_decap(uint8_t *header, iscsi_reject_t * cmd);
524 * Async Message
527 typedef struct iscsi_async_msg_args_t {
528 uint8_t AHSlength;
529 uint64_t lun;
530 uint32_t StatSN;
531 uint32_t ExpCmdSN;
532 uint32_t MaxCmdSN;
533 uint32_t length;
534 uint8_t AsyncEvent;
535 uint8_t AsyncVCode;
536 } iscsi_async_msg_t;
538 int iscsi_amsg_decap(uint8_t *header, iscsi_async_msg_t * msg);
540 #ifndef SOL_TCP
541 #define SOL_TCP IPPROTO_TCP
542 #endif
544 #endif /* ISCSI_H */