2 * RFC 3720 (iSCSI) protocol data types
4 * Copyright (C) 2005 Dmitry Yusupov
5 * Copyright (C) 2005 Alex Aizman
6 * maintained by open-iscsi@googlegroups.com
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * See the file COPYING included with this distribution for more details.
24 #define ISCSI_VERSION_STR "0.3"
25 #define ISCSI_DATE_STR "22-Apr-2005"
26 #define ISCSI_DRAFT20_VERSION 0x00
28 /* default iSCSI listen port for incoming connections */
29 #define ISCSI_LISTEN_PORT 3260
31 /* Padding word length */
32 #define PAD_WORD_LEN 4
35 * useful common(control and data pathes) macro
37 #define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
38 #define hton24(p, v) { \
39 p[0] = (((v) >> 16) & 0xFF); \
40 p[1] = (((v) >> 8) & 0xFF); \
41 p[2] = ((v) & 0xFF); \
43 #define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
46 * iSCSI Template Message Header
50 uint8_t flags; /* Final bit */
52 uint8_t hlength; /* AHSs total length */
53 uint8_t dlength[3]; /* Data length */
55 __be32 itt; /* Initiator Task Tag */
56 __be32 ttt; /* Target Task Tag */
62 /************************* RFC 3720 Begin *****************************/
64 #define ISCSI_RESERVED_TAG 0xffffffff
66 /* Opcode encoding bits */
67 #define ISCSI_OP_RETRY 0x80
68 #define ISCSI_OP_IMMEDIATE 0x40
69 #define ISCSI_OPCODE_MASK 0x3F
71 /* Initiator Opcode values */
72 #define ISCSI_OP_NOOP_OUT 0x00
73 #define ISCSI_OP_SCSI_CMD 0x01
74 #define ISCSI_OP_SCSI_TMFUNC 0x02
75 #define ISCSI_OP_LOGIN 0x03
76 #define ISCSI_OP_TEXT 0x04
77 #define ISCSI_OP_SCSI_DATA_OUT 0x05
78 #define ISCSI_OP_LOGOUT 0x06
79 #define ISCSI_OP_SNACK 0x10
81 /* Target Opcode values */
82 #define ISCSI_OP_NOOP_IN 0x20
83 #define ISCSI_OP_SCSI_CMD_RSP 0x21
84 #define ISCSI_OP_SCSI_TMFUNC_RSP 0x22
85 #define ISCSI_OP_LOGIN_RSP 0x23
86 #define ISCSI_OP_TEXT_RSP 0x24
87 #define ISCSI_OP_SCSI_DATA_IN 0x25
88 #define ISCSI_OP_LOGOUT_RSP 0x26
89 #define ISCSI_OP_R2T 0x31
90 #define ISCSI_OP_ASYNC_EVENT 0x32
91 #define ISCSI_OP_REJECT 0x3f
93 /* iSCSI PDU Header */
102 __be32 itt; /* Initiator Task Tag */
106 uint8_t cdb[16]; /* SCSI Command Block */
107 /* Additional Data (Command Dependent) */
110 /* Command PDU flags */
111 #define ISCSI_FLAG_CMD_FINAL 0x80
112 #define ISCSI_FLAG_CMD_READ 0x40
113 #define ISCSI_FLAG_CMD_WRITE 0x20
114 #define ISCSI_FLAG_CMD_ATTR_MASK 0x07 /* 3 bits */
116 /* SCSI Command Attribute values */
117 #define ISCSI_ATTR_UNTAGGED 0
118 #define ISCSI_ATTR_SIMPLE 1
119 #define ISCSI_ATTR_ORDERED 2
120 #define ISCSI_ATTR_HEAD_OF_QUEUE 3
121 #define ISCSI_ATTR_ACA 4
123 /* SCSI Response Header */
124 struct iscsi_cmd_rsp {
132 __be32 itt; /* Initiator Task Tag */
138 __be32 bi_residual_count;
139 __be32 residual_count;
140 /* Response or Sense Data (optional) */
143 /* Command Response PDU flags */
144 #define ISCSI_FLAG_CMD_BIDI_OVERFLOW 0x10
145 #define ISCSI_FLAG_CMD_BIDI_UNDERFLOW 0x08
146 #define ISCSI_FLAG_CMD_OVERFLOW 0x04
147 #define ISCSI_FLAG_CMD_UNDERFLOW 0x02
149 /* iSCSI Status values. Valid if Rsp Selector bit is not set */
150 #define ISCSI_STATUS_CMD_COMPLETED 0
151 #define ISCSI_STATUS_TARGET_FAILURE 1
152 #define ISCSI_STATUS_SUBSYS_FAILURE 2
154 /* Asynchronous Event Header */
174 /* iSCSI Event Codes */
175 #define ISCSI_ASYNC_MSG_SCSI_EVENT 0
176 #define ISCSI_ASYNC_MSG_REQUEST_LOGOUT 1
177 #define ISCSI_ASYNC_MSG_DROPPING_CONNECTION 2
178 #define ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS 3
179 #define ISCSI_ASYNC_MSG_PARAM_NEGOTIATION 4
180 #define ISCSI_ASYNC_MSG_VENDOR_SPECIFIC 255
182 /* NOP-Out Message */
183 struct iscsi_nopout {
190 __be32 itt; /* Initiator Task Tag */
191 __be32 ttt; /* Target Transfer Tag */
205 __be32 itt; /* Initiator Task Tag */
206 __be32 ttt; /* Target Transfer Tag */
213 /* SCSI Task Management Message Header */
221 __be32 itt; /* Initiator Task Tag */
222 __be32 rtt; /* Reference Task Tag */
230 #define ISCSI_FLAG_TASK_MGMT_FUNCTION_MASK 0x7F
232 /* Function values */
233 #define ISCSI_TM_FUNC_ABORT_TASK 1
234 #define ISCSI_TM_FUNC_ABORT_TASK_SET 2
235 #define ISCSI_TM_FUNC_CLEAR_ACA 3
236 #define ISCSI_TM_FUNC_CLEAR_TASK_SET 4
237 #define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET 5
238 #define ISCSI_TM_FUNC_TARGET_WARM_RESET 6
239 #define ISCSI_TM_FUNC_TARGET_COLD_RESET 7
240 #define ISCSI_TM_FUNC_TASK_REASSIGN 8
242 /* SCSI Task Management Response Header */
243 struct iscsi_tm_rsp {
246 uint8_t response; /* see Response values below */
251 __be32 itt; /* Initiator Task Tag */
252 __be32 rtt; /* Reference Task Tag */
259 /* Response values */
260 #define SCSI_TCP_TM_RESP_COMPLETE 0x00
261 #define SCSI_TCP_TM_RESP_NO_TASK 0x01
262 #define SCSI_TCP_TM_RESP_NO_LUN 0x02
263 #define SCSI_TCP_TM_RESP_TASK_ALLEGIANT 0x03
264 #define SCSI_TCP_TM_RESP_NO_FAILOVER 0x04
265 #define SCSI_TCP_TM_RESP_NOT_SUPPORTED 0x05
266 #define SCSI_TCP_TM_RESP_AUTH_FAILED 0x06
267 #define SCSI_TCP_TM_RESP_REJECTED 0xff
269 /* Ready To Transfer Header */
270 struct iscsi_r2t_rsp {
277 __be32 itt; /* Initiator Task Tag */
278 __be32 ttt; /* Target Transfer Tag */
306 /* SCSI Data Response Hdr */
307 struct iscsi_data_rsp {
322 __be32 residual_count;
325 /* Data Response PDU flags */
326 #define ISCSI_FLAG_DATA_ACK 0x40
327 #define ISCSI_FLAG_DATA_OVERFLOW 0x04
328 #define ISCSI_FLAG_DATA_UNDERFLOW 0x02
329 #define ISCSI_FLAG_DATA_STATUS 0x01
344 /* Text - key=value pairs */
347 #define ISCSI_FLAG_TEXT_CONTINUE 0x40
349 /* Text Response Header */
350 struct iscsi_text_rsp {
363 /* Text Response - key:value pairs */
370 uint8_t max_version; /* Max. version supported */
371 uint8_t min_version; /* Min. version supported */
374 uint8_t isid[6]; /* Initiator Session ID */
375 __be16 tsih; /* Target Session Handle */
376 __be32 itt; /* Initiator Task Tag */
384 /* Login PDU flags */
385 #define ISCSI_FLAG_LOGIN_TRANSIT 0x80
386 #define ISCSI_FLAG_LOGIN_CONTINUE 0x40
387 #define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK 0x0C /* 2 bits */
388 #define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK 0x03 /* 2 bits */
390 #define ISCSI_LOGIN_CURRENT_STAGE(flags) \
391 ((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
392 #define ISCSI_LOGIN_NEXT_STAGE(flags) \
393 (flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
395 /* Login Response Header */
396 struct iscsi_login_rsp {
399 uint8_t max_version; /* Max. version supported */
400 uint8_t active_version; /* Active version */
403 uint8_t isid[6]; /* Initiator Session ID */
404 __be16 tsih; /* Target Session Handle */
405 __be32 itt; /* Initiator Task Tag */
410 uint8_t status_class; /* see Login RSP ststus classes below */
411 uint8_t status_detail; /* see Login RSP Status details below */
415 /* Login stage (phase) codes for CSG, NSG */
416 #define ISCSI_INITIAL_LOGIN_STAGE -1
417 #define ISCSI_SECURITY_NEGOTIATION_STAGE 0
418 #define ISCSI_OP_PARMS_NEGOTIATION_STAGE 1
419 #define ISCSI_FULL_FEATURE_PHASE 3
421 /* Login Status response classes */
422 #define ISCSI_STATUS_CLS_SUCCESS 0x00
423 #define ISCSI_STATUS_CLS_REDIRECT 0x01
424 #define ISCSI_STATUS_CLS_INITIATOR_ERR 0x02
425 #define ISCSI_STATUS_CLS_TARGET_ERR 0x03
427 /* Login Status response detail codes */
428 /* Class-0 (Success) */
429 #define ISCSI_LOGIN_STATUS_ACCEPT 0x00
431 /* Class-1 (Redirection) */
432 #define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP 0x01
433 #define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM 0x02
435 /* Class-2 (Initiator Error) */
436 #define ISCSI_LOGIN_STATUS_INIT_ERR 0x00
437 #define ISCSI_LOGIN_STATUS_AUTH_FAILED 0x01
438 #define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN 0x02
439 #define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND 0x03
440 #define ISCSI_LOGIN_STATUS_TGT_REMOVED 0x04
441 #define ISCSI_LOGIN_STATUS_NO_VERSION 0x05
442 #define ISCSI_LOGIN_STATUS_ISID_ERROR 0x06
443 #define ISCSI_LOGIN_STATUS_MISSING_FIELDS 0x07
444 #define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED 0x08
445 #define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE 0x09
446 #define ISCSI_LOGIN_STATUS_NO_SESSION 0x0a
447 #define ISCSI_LOGIN_STATUS_INVALID_REQUEST 0x0b
449 /* Class-3 (Target Error) */
450 #define ISCSI_LOGIN_STATUS_TARGET_ERROR 0x00
451 #define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE 0x01
452 #define ISCSI_LOGIN_STATUS_NO_RESOURCES 0x02
455 struct iscsi_logout {
462 __be32 itt; /* Initiator Task Tag */
470 /* Logout PDU flags */
471 #define ISCSI_FLAG_LOGOUT_REASON_MASK 0x7F
473 /* logout reason_code values */
475 #define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
476 #define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
477 #define ISCSI_LOGOUT_REASON_RECOVERY 2
478 #define ISCSI_LOGOUT_REASON_AEN_REQUEST 3
480 /* Logout Response Header */
481 struct iscsi_logout_rsp {
484 uint8_t response; /* see Logout response values below */
489 __be32 itt; /* Initiator Task Tag */
500 /* logout response status values */
502 #define ISCSI_LOGOUT_SUCCESS 0
503 #define ISCSI_LOGOUT_CID_NOT_FOUND 1
504 #define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED 2
505 #define ISCSI_LOGOUT_CLEANUP_FAILED 3
521 /* SNACK PDU flags */
522 #define ISCSI_FLAG_SNACK_TYPE_MASK 0x0F /* 4 bits */
524 /* Reject Message Header */
525 struct iscsi_reject {
538 /* Text - Rejected hdr */
541 /* Reason for Reject */
542 #define CMD_BEFORE_LOGIN 1
543 #define DATA_DIGEST_ERROR 2
544 #define DATA_SNACK_REJECT 3
545 #define ISCSI_PROTOCOL_ERROR 4
546 #define CMD_NOT_SUPPORTED 5
547 #define IMM_CMD_REJECT 6
548 #define TASK_IN_PROGRESS 7
549 #define INVALID_SNACK 8
550 #define BOOKMARK_REJECTED 9
551 #define BOOKMARK_NO_RESOURCES 10
552 #define NEGOTIATION_RESET 11
554 /* Max. number of Key=Value pairs in a text message */
555 #define MAX_KEY_VALUE_PAIRS 8192
557 /* maximum length for text keys/values */
558 #define KEY_MAXLEN 64
559 #define VALUE_MAXLEN 255
560 #define TARGET_NAME_MAXLEN VALUE_MAXLEN
562 #define DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH 8192
564 /************************* RFC 3720 End *****************************/
566 #endif /* ISCSI_PROTO_H */