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 #include <linux/types.h>
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 ISCSI_PAD_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;}
45 /* initiator tags; opaque for target */
46 typedef uint32_t __bitwise__ itt_t
;
47 /* below makes sense only for initiator that created this tag */
48 #define build_itt(itt, id, age) ((__force itt_t)\
49 ((itt) | ((id) << ISCSI_CID_SHIFT) | ((age) << ISCSI_AGE_SHIFT)))
50 #define get_itt(itt) ((__force uint32_t)(itt_t)(itt) & ISCSI_ITT_MASK)
51 #define RESERVED_ITT ((__force itt_t)0xffffffff)
54 * iSCSI Template Message Header
58 uint8_t flags
; /* Final bit */
60 uint8_t hlength
; /* AHSs total length */
61 uint8_t dlength
[3]; /* Data length */
63 itt_t itt
; /* Initiator Task Tag, opaque for target */
64 __be32 ttt
; /* Target Task Tag */
71 /************************* RFC 3720 Begin *****************************/
73 #define ISCSI_RESERVED_TAG 0xffffffff
75 /* Opcode encoding bits */
76 #define ISCSI_OP_RETRY 0x80
77 #define ISCSI_OP_IMMEDIATE 0x40
78 #define ISCSI_OPCODE_MASK 0x3F
80 /* Initiator Opcode values */
81 #define ISCSI_OP_NOOP_OUT 0x00
82 #define ISCSI_OP_SCSI_CMD 0x01
83 #define ISCSI_OP_SCSI_TMFUNC 0x02
84 #define ISCSI_OP_LOGIN 0x03
85 #define ISCSI_OP_TEXT 0x04
86 #define ISCSI_OP_SCSI_DATA_OUT 0x05
87 #define ISCSI_OP_LOGOUT 0x06
88 #define ISCSI_OP_SNACK 0x10
90 #define ISCSI_OP_VENDOR1_CMD 0x1c
91 #define ISCSI_OP_VENDOR2_CMD 0x1d
92 #define ISCSI_OP_VENDOR3_CMD 0x1e
93 #define ISCSI_OP_VENDOR4_CMD 0x1f
95 /* Target Opcode values */
96 #define ISCSI_OP_NOOP_IN 0x20
97 #define ISCSI_OP_SCSI_CMD_RSP 0x21
98 #define ISCSI_OP_SCSI_TMFUNC_RSP 0x22
99 #define ISCSI_OP_LOGIN_RSP 0x23
100 #define ISCSI_OP_TEXT_RSP 0x24
101 #define ISCSI_OP_SCSI_DATA_IN 0x25
102 #define ISCSI_OP_LOGOUT_RSP 0x26
103 #define ISCSI_OP_R2T 0x31
104 #define ISCSI_OP_ASYNC_EVENT 0x32
105 #define ISCSI_OP_REJECT 0x3f
107 struct iscsi_ahs_hdr
{
113 #define ISCSI_AHSTYPE_CDB 1
114 #define ISCSI_AHSTYPE_RLENGTH 2
116 /* iSCSI PDU Header */
124 itt_t itt
; /* Initiator Task Tag */
128 uint8_t cdb
[16]; /* SCSI Command Block */
129 /* Additional Data (Command Dependent) */
132 /* Command PDU flags */
133 #define ISCSI_FLAG_CMD_FINAL 0x80
134 #define ISCSI_FLAG_CMD_READ 0x40
135 #define ISCSI_FLAG_CMD_WRITE 0x20
136 #define ISCSI_FLAG_CMD_ATTR_MASK 0x07 /* 3 bits */
138 /* SCSI Command Attribute values */
139 #define ISCSI_ATTR_UNTAGGED 0
140 #define ISCSI_ATTR_SIMPLE 1
141 #define ISCSI_ATTR_ORDERED 2
142 #define ISCSI_ATTR_HEAD_OF_QUEUE 3
143 #define ISCSI_ATTR_ACA 4
145 struct iscsi_rlength_ahdr
{
152 /* Extended CDB AHS */
153 struct iscsi_ecdb_ahdr
{
154 __be16 ahslength
; /* CDB length - 15, including reserved byte */
157 uint8_t ecdb
[260 - 16]; /* 4-byte aligned extended CDB spillover */
160 /* SCSI Response Header */
161 struct iscsi_cmd_rsp
{
169 itt_t itt
; /* Initiator Task Tag */
175 __be32 bi_residual_count
;
176 __be32 residual_count
;
177 /* Response or Sense Data (optional) */
180 /* Command Response PDU flags */
181 #define ISCSI_FLAG_CMD_BIDI_OVERFLOW 0x10
182 #define ISCSI_FLAG_CMD_BIDI_UNDERFLOW 0x08
183 #define ISCSI_FLAG_CMD_OVERFLOW 0x04
184 #define ISCSI_FLAG_CMD_UNDERFLOW 0x02
186 /* iSCSI Status values. Valid if Rsp Selector bit is not set */
187 #define ISCSI_STATUS_CMD_COMPLETED 0
188 #define ISCSI_STATUS_TARGET_FAILURE 1
189 #define ISCSI_STATUS_SUBSYS_FAILURE 2
191 /* Asynchronous Event Header */
211 /* iSCSI Event Codes */
212 #define ISCSI_ASYNC_MSG_SCSI_EVENT 0
213 #define ISCSI_ASYNC_MSG_REQUEST_LOGOUT 1
214 #define ISCSI_ASYNC_MSG_DROPPING_CONNECTION 2
215 #define ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS 3
216 #define ISCSI_ASYNC_MSG_PARAM_NEGOTIATION 4
217 #define ISCSI_ASYNC_MSG_VENDOR_SPECIFIC 255
219 /* NOP-Out Message */
220 struct iscsi_nopout
{
227 itt_t itt
; /* Initiator Task Tag */
228 __be32 ttt
; /* Target Transfer Tag */
242 itt_t itt
; /* Initiator Task Tag */
243 __be32 ttt
; /* Target Transfer Tag */
250 /* SCSI Task Management Message Header */
258 itt_t itt
; /* Initiator Task Tag */
259 itt_t rtt
; /* Reference Task Tag */
267 #define ISCSI_FLAG_TM_FUNC_MASK 0x7F
269 /* Function values */
270 #define ISCSI_TM_FUNC_ABORT_TASK 1
271 #define ISCSI_TM_FUNC_ABORT_TASK_SET 2
272 #define ISCSI_TM_FUNC_CLEAR_ACA 3
273 #define ISCSI_TM_FUNC_CLEAR_TASK_SET 4
274 #define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET 5
275 #define ISCSI_TM_FUNC_TARGET_WARM_RESET 6
276 #define ISCSI_TM_FUNC_TARGET_COLD_RESET 7
277 #define ISCSI_TM_FUNC_TASK_REASSIGN 8
279 /* SCSI Task Management Response Header */
280 struct iscsi_tm_rsp
{
283 uint8_t response
; /* see Response values below */
288 itt_t itt
; /* Initiator Task Tag */
289 itt_t rtt
; /* Reference Task Tag */
296 /* Response values */
297 #define ISCSI_TMF_RSP_COMPLETE 0x00
298 #define ISCSI_TMF_RSP_NO_TASK 0x01
299 #define ISCSI_TMF_RSP_NO_LUN 0x02
300 #define ISCSI_TMF_RSP_TASK_ALLEGIANT 0x03
301 #define ISCSI_TMF_RSP_NO_FAILOVER 0x04
302 #define ISCSI_TMF_RSP_NOT_SUPPORTED 0x05
303 #define ISCSI_TMF_RSP_AUTH_FAILED 0x06
304 #define ISCSI_TMF_RSP_REJECTED 0xff
306 /* Ready To Transfer Header */
307 struct iscsi_r2t_rsp
{
314 itt_t itt
; /* Initiator Task Tag */
315 __be32 ttt
; /* Target Transfer Tag */
343 /* SCSI Data Response Hdr */
344 struct iscsi_data_rsp
{
359 __be32 residual_count
;
362 /* Data Response PDU flags */
363 #define ISCSI_FLAG_DATA_ACK 0x40
364 #define ISCSI_FLAG_DATA_OVERFLOW 0x04
365 #define ISCSI_FLAG_DATA_UNDERFLOW 0x02
366 #define ISCSI_FLAG_DATA_STATUS 0x01
381 /* Text - key=value pairs */
384 #define ISCSI_FLAG_TEXT_CONTINUE 0x40
386 /* Text Response Header */
387 struct iscsi_text_rsp
{
400 /* Text Response - key:value pairs */
407 uint8_t max_version
; /* Max. version supported */
408 uint8_t min_version
; /* Min. version supported */
411 uint8_t isid
[6]; /* Initiator Session ID */
412 __be16 tsih
; /* Target Session Handle */
413 itt_t itt
; /* Initiator Task Tag */
421 /* Login PDU flags */
422 #define ISCSI_FLAG_LOGIN_TRANSIT 0x80
423 #define ISCSI_FLAG_LOGIN_CONTINUE 0x40
424 #define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK 0x0C /* 2 bits */
425 #define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK 0x03 /* 2 bits */
427 #define ISCSI_LOGIN_CURRENT_STAGE(flags) \
428 ((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
429 #define ISCSI_LOGIN_NEXT_STAGE(flags) \
430 (flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
432 /* Login Response Header */
433 struct iscsi_login_rsp
{
436 uint8_t max_version
; /* Max. version supported */
437 uint8_t active_version
; /* Active version */
440 uint8_t isid
[6]; /* Initiator Session ID */
441 __be16 tsih
; /* Target Session Handle */
442 itt_t itt
; /* Initiator Task Tag */
447 uint8_t status_class
; /* see Login RSP ststus classes below */
448 uint8_t status_detail
; /* see Login RSP Status details below */
452 /* Login stage (phase) codes for CSG, NSG */
453 #define ISCSI_INITIAL_LOGIN_STAGE -1
454 #define ISCSI_SECURITY_NEGOTIATION_STAGE 0
455 #define ISCSI_OP_PARMS_NEGOTIATION_STAGE 1
456 #define ISCSI_FULL_FEATURE_PHASE 3
458 /* Login Status response classes */
459 #define ISCSI_STATUS_CLS_SUCCESS 0x00
460 #define ISCSI_STATUS_CLS_REDIRECT 0x01
461 #define ISCSI_STATUS_CLS_INITIATOR_ERR 0x02
462 #define ISCSI_STATUS_CLS_TARGET_ERR 0x03
464 /* Login Status response detail codes */
465 /* Class-0 (Success) */
466 #define ISCSI_LOGIN_STATUS_ACCEPT 0x00
468 /* Class-1 (Redirection) */
469 #define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP 0x01
470 #define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM 0x02
472 /* Class-2 (Initiator Error) */
473 #define ISCSI_LOGIN_STATUS_INIT_ERR 0x00
474 #define ISCSI_LOGIN_STATUS_AUTH_FAILED 0x01
475 #define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN 0x02
476 #define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND 0x03
477 #define ISCSI_LOGIN_STATUS_TGT_REMOVED 0x04
478 #define ISCSI_LOGIN_STATUS_NO_VERSION 0x05
479 #define ISCSI_LOGIN_STATUS_ISID_ERROR 0x06
480 #define ISCSI_LOGIN_STATUS_MISSING_FIELDS 0x07
481 #define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED 0x08
482 #define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE 0x09
483 #define ISCSI_LOGIN_STATUS_NO_SESSION 0x0a
484 #define ISCSI_LOGIN_STATUS_INVALID_REQUEST 0x0b
486 /* Class-3 (Target Error) */
487 #define ISCSI_LOGIN_STATUS_TARGET_ERROR 0x00
488 #define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE 0x01
489 #define ISCSI_LOGIN_STATUS_NO_RESOURCES 0x02
492 struct iscsi_logout
{
499 itt_t itt
; /* Initiator Task Tag */
507 /* Logout PDU flags */
508 #define ISCSI_FLAG_LOGOUT_REASON_MASK 0x7F
510 /* logout reason_code values */
512 #define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
513 #define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
514 #define ISCSI_LOGOUT_REASON_RECOVERY 2
515 #define ISCSI_LOGOUT_REASON_AEN_REQUEST 3
517 /* Logout Response Header */
518 struct iscsi_logout_rsp
{
521 uint8_t response
; /* see Logout response values below */
526 itt_t itt
; /* Initiator Task Tag */
537 /* logout response status values */
539 #define ISCSI_LOGOUT_SUCCESS 0
540 #define ISCSI_LOGOUT_CID_NOT_FOUND 1
541 #define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED 2
542 #define ISCSI_LOGOUT_CLEANUP_FAILED 3
558 /* SNACK PDU flags */
559 #define ISCSI_FLAG_SNACK_TYPE_MASK 0x0F /* 4 bits */
561 /* Reject Message Header */
562 struct iscsi_reject
{
577 /* Text - Rejected hdr */
580 /* Reason for Reject */
581 #define ISCSI_REASON_CMD_BEFORE_LOGIN 1
582 #define ISCSI_REASON_DATA_DIGEST_ERROR 2
583 #define ISCSI_REASON_DATA_SNACK_REJECT 3
584 #define ISCSI_REASON_PROTOCOL_ERROR 4
585 #define ISCSI_REASON_CMD_NOT_SUPPORTED 5
586 #define ISCSI_REASON_IMM_CMD_REJECT 6
587 #define ISCSI_REASON_TASK_IN_PROGRESS 7
588 #define ISCSI_REASON_INVALID_SNACK 8
589 #define ISCSI_REASON_BOOKMARK_INVALID 9
590 #define ISCSI_REASON_BOOKMARK_NO_RESOURCES 10
591 #define ISCSI_REASON_NEGOTIATION_RESET 11
593 /* Max. number of Key=Value pairs in a text message */
594 #define MAX_KEY_VALUE_PAIRS 8192
596 /* maximum length for text keys/values */
597 #define KEY_MAXLEN 64
598 #define VALUE_MAXLEN 255
599 #define TARGET_NAME_MAXLEN VALUE_MAXLEN
601 #define ISCSI_DEF_MAX_RECV_SEG_LEN 8192
602 #define ISCSI_MIN_MAX_RECV_SEG_LEN 512
603 #define ISCSI_MAX_MAX_RECV_SEG_LEN 16777215
605 #define ISCSI_DEF_FIRST_BURST_LEN 65536
606 #define ISCSI_MIN_FIRST_BURST_LEN 512
607 #define ISCSI_MAX_FIRST_BURST_LEN 16777215
609 #define ISCSI_DEF_MAX_BURST_LEN 262144
610 #define ISCSI_MIN_MAX_BURST_LEN 512
611 #define ISCSI_MAX_MAX_BURST_LEN 16777215
613 #define ISCSI_DEF_TIME2WAIT 2
615 /************************* RFC 3720 End *****************************/
617 #endif /* ISCSI_PROTO_H */