4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 #ifndef _ISCSI_PROTOCOL_H
26 #define _ISCSI_PROTOCOL_H
33 * iSCSI connection daemon
34 * Copyright (C) 2001 Cisco Systems, Inc.
35 * All rights reserved.
37 * This file sets up definitions of messages and constants used by the
42 #include <sys/types.h>
43 #include <sys/isa_defs.h>
45 #define ISCSI_MAX_NAME_LEN 224
46 #define ISCSI_MAX_C_USER_LEN 512
48 /* iSCSI listen port for incoming connections */
49 #define ISCSI_LISTEN_PORT 3260
51 /* assumes a pointer to a 3-byte array */
52 #define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
54 /* assumes a pointer to a 3 byte array, and an integer value */
55 #define hton24(p, v) {\
56 p[0] = (((v) >> 16) & 0xFF); \
57 p[1] = (((v) >> 8) & 0xFF); \
58 p[2] = ((v) & 0xFF); \
62 /* for Login min, max, active version fields */
63 #define ISCSI_MIN_VERSION 0x00
64 #define ISCSI_DRAFT8_VERSION 0x02
65 #define ISCSI_DRAFT20_VERSION 0x00
66 #define ISCSI_MAX_VERSION 0x02
68 /* Min. and Max. length of a PDU we can support */
69 #define ISCSI_MIN_PDU_LENGTH (8 << 9) /* 4KB */
70 #define ISCSI_MAX_PDU_LENGTH (0xffffffff) /* Huge */
72 /* Padding word length */
73 #define ISCSI_PAD_WORD_LEN 4
75 /* Max. number of Key=Value pairs in a text message */
76 #define ISCSI_MAX_KEY_VALUE_PAIRS 8192
78 /* text separtor between key value pairs exhanged in login */
79 #define ISCSI_TEXT_SEPARATOR '='
81 /* reserved text constants for Text Mode Negotiation */
82 #define ISCSI_TEXT_NONE "None"
83 #define ISCSI_TEXT_REJECT "Reject"
84 #define ISCSI_TEXT_IRRELEVANT "Irrelevant"
85 #define ISCSI_TEXT_NOTUNDERSTOOD "NotUnderstood"
87 /* Reserved value for initiator/target task tag */
88 #define ISCSI_RSVD_TASK_TAG 0xffffffff
90 /* maximum length for text keys/values */
92 #define VALUE_MAXLEN 255
93 #define TARGET_NAME_MAXLEN VALUE_MAXLEN
95 /* most PDU types have a final bit */
96 #define ISCSI_FLAG_FINAL 0x80
99 * Strings used during SendTargets requests
101 #define ISCSI_TEXT_SEPARATOR '='
102 #define TARGETNAME "TargetName="
103 #define TARGETADDRESS "TargetAddress="
105 /* iSCSI Template Message Header */
106 typedef struct _iscsi_hdr
{
108 uint8_t flags
; /* Final bit */
110 uint8_t hlength
; /* AHSs total length */
111 uint8_t dlength
[3]; /* Data length */
113 uint32_t itt
; /* Initiator Task Tag */
119 typedef struct _iscsi_rsp_hdr
{
133 /* Opcode encoding bits */
134 #define ISCSI_OP_RETRY 0x80
135 #define ISCSI_OP_IMMEDIATE 0x40
136 #define ISCSI_OPCODE_MASK 0x3F
138 /* Client to Server Message Opcode values */
139 #define ISCSI_OP_NOOP_OUT 0x00
140 #define ISCSI_OP_SCSI_CMD 0x01
141 #define ISCSI_OP_SCSI_TASK_MGT_MSG 0x02
142 #define ISCSI_OP_LOGIN_CMD 0x03
143 #define ISCSI_OP_TEXT_CMD 0x04
144 #define ISCSI_OP_SCSI_DATA 0x05
145 #define ISCSI_OP_LOGOUT_CMD 0x06
146 #define ISCSI_OP_SNACK_CMD 0x10
148 /* Server to Client Message Opcode values */
149 #define ISCSI_OP_NOOP_IN 0x20
150 #define ISCSI_OP_SCSI_RSP 0x21
151 #define ISCSI_OP_SCSI_TASK_MGT_RSP 0x22
152 #define ISCSI_OP_LOGIN_RSP 0x23
153 #define ISCSI_OP_TEXT_RSP 0x24
154 #define ISCSI_OP_SCSI_DATA_RSP 0x25
155 #define ISCSI_OP_LOGOUT_RSP 0x26
156 #define ISCSI_OP_RTT_RSP 0x31
157 #define ISCSI_OP_ASYNC_EVENT 0x32
158 #define ISCSI_OP_REJECT_MSG 0x3f
161 /* SCSI Command Header */
162 typedef struct _iscsi_scsi_cmd_hdr
{
169 uint32_t itt
; /* Initiator Task Tag */
170 uint32_t data_length
;
173 uint8_t scb
[16]; /* SCSI Command Block */
175 * Additional Data (Command Dependent)
177 } iscsi_scsi_cmd_hdr_t
;
179 /* Command PDU flags */
180 #define ISCSI_FLAG_CMD_READ 0x40
181 #define ISCSI_FLAG_CMD_WRITE 0x20
182 #define ISCSI_FLAG_CMD_ATTR_MASK 0x07 /* 3 bits */
184 /* SCSI Command Attribute values */
185 #define ISCSI_ATTR_UNTAGGED 0
186 #define ISCSI_ATTR_SIMPLE 1
187 #define ISCSI_ATTR_ORDERED 2
188 #define ISCSI_ATTR_HEAD_OF_QUEUE 3
189 #define ISCSI_ATTR_ACA 4
192 /* SCSI Response Header */
193 typedef struct _iscsi_scsi_rsp_hdr
{
201 uint32_t itt
; /* Initiator Task Tag */
207 uint32_t bi_residual_count
;
208 uint32_t residual_count
;
210 * Response or Sense Data (optional)
212 } iscsi_scsi_rsp_hdr_t
;
214 /* 10.2.2.3 - Extended CDB Additional Header Segment */
216 typedef struct _iscsi_addl_hdr
{
217 iscsi_scsi_cmd_hdr_t ahs_isch
;
222 uint8_t ahs_extscb
[4];
225 /* Command Response PDU flags */
226 #define ISCSI_FLAG_CMD_BIDI_OVERFLOW 0x10
227 #define ISCSI_FLAG_CMD_BIDI_UNDERFLOW 0x08
228 #define ISCSI_FLAG_CMD_OVERFLOW 0x04
229 #define ISCSI_FLAG_CMD_UNDERFLOW 0x02
231 /* iSCSI Status values. Valid if Rsp Selector bit is not set */
232 #define ISCSI_STATUS_CMD_COMPLETED 0
233 #define ISCSI_STATUS_TARGET_FAILURE 1
234 #define ISCSI_STATUS_SUBSYS_FAILURE 2
237 /* Asynchronous Event Header */
238 typedef struct _iscsi_async_evt_hdr
{
255 } iscsi_async_evt_hdr_t
;
257 /* iSCSI Event Indicator values */
258 #define ISCSI_ASYNC_EVENT_SCSI_EVENT 0
259 #define ISCSI_ASYNC_EVENT_REQUEST_LOGOUT 1
260 #define ISCSI_ASYNC_EVENT_DROPPING_CONNECTION 2
261 #define ISCSI_ASYNC_EVENT_DROPPING_ALL_CONNECTIONS 3
262 #define ISCSI_ASYNC_EVENT_PARAM_NEGOTIATION 4
263 #define ISCSI_ASYNC_EVENT_VENDOR_SPECIFIC 255
266 /* NOP-Out Message */
267 typedef struct _iscsi_nop_out_hdr
{
274 uint32_t itt
; /* Initiator Task Tag */
275 uint32_t ttt
; /* Target Transfer Tag */
279 } iscsi_nop_out_hdr_t
;
283 typedef struct _iscsi_nop_in_hdr
{
290 uint32_t itt
; /* Initiator Task Tag */
291 uint32_t ttt
; /* Target Transfer Tag */
296 } iscsi_nop_in_hdr_t
;
298 /* SCSI Task Management Message Header */
299 typedef struct _iscsi_scsi_task_mgt_hdr
{
306 uint32_t itt
; /* Initiator Task Tag */
307 uint32_t rtt
; /* Reference Task Tag */
313 } iscsi_scsi_task_mgt_hdr_t
;
315 #define ISCSI_FLAG_TASK_MGMT_FUNCTION_MASK 0x7F
317 /* Function values */
318 #define ISCSI_TM_FUNC_ABORT_TASK 1
319 #define ISCSI_TM_FUNC_ABORT_TASK_SET 2
320 #define ISCSI_TM_FUNC_CLEAR_ACA 3
321 #define ISCSI_TM_FUNC_CLEAR_TASK_SET 4
322 #define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET 5
323 #define ISCSI_TM_FUNC_TARGET_WARM_RESET 6
324 #define ISCSI_TM_FUNC_TARGET_COLD_RESET 7
325 #define ISCSI_TM_FUNC_TASK_REASSIGN 8
328 /* SCSI Task Management Response Header */
329 typedef struct _iscsi_scsi_task_mgt_rsp_hdr
{
332 uint8_t response
; /* see Response values below */
337 uint32_t itt
; /* Initiator Task Tag */
338 uint32_t rtt
; /* Reference Task Tag */
343 } iscsi_scsi_task_mgt_rsp_hdr_t
;
346 /* Response values */
347 #define SCSI_TCP_TM_RESP_COMPLETE 0x00
348 #define SCSI_TCP_TM_RESP_NO_TASK 0x01
349 #define SCSI_TCP_TM_RESP_NO_LUN 0x02
350 #define SCSI_TCP_TM_RESP_TASK_ALLEGIANT 0x03
351 #define SCSI_TCP_TM_RESP_NO_ALLG_REASSN 0x04
352 #define SCSI_TCP_TM_RESP_FUNC_NOT_SUPP 0x05
353 #define SCSI_TCP_TM_RESP_FUNC_AUTH_FAIL 0x06
354 #define SCSI_TCP_TM_RESP_REJECTED 0xff
357 * Maintained for backward compatibility.
360 #define SCSI_TCP_TM_RESP_NO_FAILOVER SCSI_TCP_TM_RESP_NO_ALLG_REASSN
361 #define SCSI_TCP_TM_RESP_IN_PRGRESS SCSI_TCP_TM_RESP_FUNC_NOT_SUPP
363 /* Ready To Transfer Header */
364 typedef struct _iscsi_rtt_hdr
{
369 uint32_t itt
; /* Initiator Task Tag */
370 uint32_t ttt
; /* Target Transfer Tag */
375 uint32_t data_offset
;
376 uint32_t data_length
;
381 typedef struct _iscsi_data_hdr
{
401 /* SCSI Data Response Hdr */
402 typedef struct _iscsi_data_rsp_hdr
{
417 uint32_t residual_count
;
418 } iscsi_data_rsp_hdr_t
;
420 /* Data Response PDU flags */
421 #define ISCSI_FLAG_DATA_ACK 0x40
422 #define ISCSI_FLAG_DATA_OVERFLOW 0x04
423 #define ISCSI_FLAG_DATA_UNDERFLOW 0x02
424 #define ISCSI_FLAG_DATA_STATUS 0x01
428 typedef struct _iscsi_text_hdr
{
441 * Text - key=value pairs
445 #define ISCSI_FLAG_TEXT_CONTINUE 0x40
447 /* Text Response Header */
448 typedef struct _iscsi_text_rsp_hdr
{
462 * Text Response - key:value pairs
464 } iscsi_text_rsp_hdr_t
;
466 #define ISCSI_ISID_LEN 6
469 typedef struct _iscsi_login_hdr
{
472 uint8_t max_version
; /* Max. version supported */
473 uint8_t min_version
; /* Min. version supported */
476 uint8_t isid
[ISCSI_ISID_LEN
]; /* Initiator Session ID */
477 uint16_t tsid
; /* Target Session ID */
478 uint32_t itt
; /* Initiator Task Tag */
486 /* Login PDU flags */
487 #define ISCSI_FLAG_LOGIN_TRANSIT 0x80
488 #define ISCSI_FLAG_LOGIN_CONTINUE 0x40
489 #define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK 0x0C /* 2 bits */
490 #define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK 0x03 /* 2 bits */
492 #define ISCSI_LOGIN_CURRENT_STAGE(flags) \
493 ((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
494 #define ISCSI_LOGIN_NEXT_STAGE(flags) \
495 (flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
498 /* Login Response Header */
499 typedef struct _iscsi_login_rsp_hdr
{
502 uint8_t max_version
; /* Max. version supported */
503 uint8_t active_version
; /* Active version */
506 uint8_t isid
[ISCSI_ISID_LEN
]; /* Initiator Session ID */
507 uint16_t tsid
; /* Target Session ID */
508 uint32_t itt
; /* Initiator Task Tag */
513 uint8_t status_class
; /* see Login RSP ststus classes below */
514 uint8_t status_detail
; /* see Login RSP Status details below */
516 } iscsi_login_rsp_hdr_t
;
518 /* Login stage (phase) codes for CSG, NSG */
519 #define ISCSI_SECURITY_NEGOTIATION_STAGE 0
520 #define ISCSI_OP_PARMS_NEGOTIATION_STAGE 1
521 #define ISCSI_FULL_FEATURE_PHASE 3
523 /* Login Status response classes */
524 #define ISCSI_STATUS_CLASS_SUCCESS 0x00
525 #define ISCSI_STATUS_CLASS_REDIRECT 0x01
526 #define ISCSI_STATUS_CLASS_INITIATOR_ERR 0x02
527 #define ISCSI_STATUS_CLASS_TARGET_ERR 0x03
529 /* Login Status response detail codes */
530 /* Class-0 (Success) */
531 #define ISCSI_LOGIN_STATUS_ACCEPT 0x00
533 /* Class-1 (Redirection) */
534 #define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP 0x01
535 #define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM 0x02
537 /* Class-2 (Initiator Error) */
538 #define ISCSI_LOGIN_STATUS_INIT_ERR 0x00
539 #define ISCSI_LOGIN_STATUS_AUTH_FAILED 0x01
540 #define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN 0x02
541 #define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND 0x03
542 #define ISCSI_LOGIN_STATUS_TGT_REMOVED 0x04
543 #define ISCSI_LOGIN_STATUS_NO_VERSION 0x05
544 #define ISCSI_LOGIN_STATUS_ISID_ERROR 0x06
545 #define ISCSI_LOGIN_STATUS_MISSING_FIELDS 0x07
546 #define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED 0x08
547 #define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE 0x09
548 #define ISCSI_LOGIN_STATUS_NO_SESSION 0x0a
549 #define ISCSI_LOGIN_STATUS_INVALID_REQUEST 0x0b
551 /* Class-3 (Target Error) */
552 #define ISCSI_LOGIN_STATUS_TARGET_ERROR 0x00
553 #define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE 0x01
554 #define ISCSI_LOGIN_STATUS_NO_RESOURCES 0x02
557 typedef struct _iscsi_logout_hdr
{
564 uint32_t itt
; /* Initiator Task Tag */
570 } iscsi_logout_hdr_t
;
572 /* Logout PDU flags */
573 #define ISCSI_FLAG_LOGOUT_REASON_MASK 0x7F
575 /* logout reason_code values */
577 #define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
578 #define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
579 #define ISCSI_LOGOUT_REASON_RECOVERY 2
580 #define ISCSI_LOGOUT_REASON_AEN_REQUEST 3
582 /* Logout Response Header */
583 typedef struct _iscsi_logout_rsp_hdr
{
586 uint8_t response
; /* see Logout response values below */
591 uint32_t itt
; /* Initiator Task Tag */
600 } iscsi_logout_rsp_hdr_t
;
602 /* logout response status values */
604 #define ISCSI_LOGOUT_SUCCESS 0
605 #define ISCSI_LOGOUT_CID_NOT_FOUND 1
606 #define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED 2
607 #define ISCSI_LOGOUT_CLEANUP_FAILED 3
611 typedef struct _iscsi_snack_hdr
{
624 /* SNACK PDU flags */
625 #define ISCSI_FLAG_SNACK_TYPE_MASK 0x0F /* 4 bits */
627 /* Reject Message Header */
628 typedef struct _iscsi_reject_rsp_hdr
{
636 uint8_t must_be_ff
[4];
644 * Text - Rejected hdr
646 } iscsi_reject_rsp_hdr_t
;
648 /* Reason for Reject */
649 #define ISCSI_REJECT_CMD_BEFORE_LOGIN 1
650 #define ISCSI_REJECT_DATA_DIGEST_ERROR 2
651 #define ISCSI_REJECT_SNACK_REJECT 3
652 #define ISCSI_REJECT_PROTOCOL_ERROR 4
653 #define ISCSI_REJECT_CMD_NOT_SUPPORTED 5
654 #define ISCSI_REJECT_IMM_CMD_REJECT 6
655 #define ISCSI_REJECT_TASK_IN_PROGRESS 7
656 #define ISCSI_REJECT_INVALID_DATA_ACK 8
657 #define ISCSI_REJECT_INVALID_PDU_FIELD 9
658 #define ISCSI_REJECT_LONG_OPERATION_REJECT 10
659 #define ISCSI_REJECT_NEGOTIATION_RESET 11
660 #define ISCSI_REJECT_WAITING_FOR_LOGOUT 12
662 /* Defaults as defined by the iSCSI specification */
663 #define ISCSI_DEFAULT_IMMEDIATE_DATA TRUE
664 #define ISCSI_DEFAULT_INITIALR2T TRUE
665 #define ISCSI_DEFAULT_FIRST_BURST_LENGTH (64 * 1024) /* 64kbytes */
666 #define ISCSI_DEFAULT_MAX_BURST_LENGTH (256 * 1024) /* 256kbytes */
667 #define ISCSI_DEFAULT_DATA_PDU_IN_ORDER TRUE
668 #define ISCSI_DEFAULT_DATA_SEQUENCE_IN_ORDER TRUE
669 #define ISCSI_DEFAULT_TIME_TO_WAIT 2 /* 2 seconds */
670 #define ISCSI_DEFAULT_TIME_TO_RETAIN 20 /* 20 seconds */
671 #define ISCSI_DEFAULT_HEADER_DIGEST ISCSI_DIGEST_NONE
672 #define ISCSI_DEFAULT_DATA_DIGEST ISCSI_DIGEST_NONE
673 #define ISCSI_DEFAULT_MAX_RECV_SEG_LEN (8 * 1024)
674 #define ISCSI_DEFAULT_MAX_XMIT_SEG_LEN (8 * 1024)
675 #define ISCSI_DEFAULT_MAX_CONNECTIONS 1
676 #define ISCSI_DEFAULT_MAX_OUT_R2T 1
677 #define ISCSI_DEFAULT_ERROR_RECOVERY_LEVEL 0
678 #define ISCSI_DEFAULT_IFMARKER FALSE
679 #define ISCSI_DEFAULT_OFMARKER FALSE
682 * Minimum values from the iSCSI specification
685 #define ISCSI_MIN_TIME2RETAIN 0
686 #define ISCSI_MIN_TIME2WAIT 0
687 #define ISCSI_MIN_ERROR_RECOVERY_LEVEL 0
688 #define ISCSI_MIN_RECV_DATA_SEGMENT_LENGTH 0x200
689 #define ISCSI_MIN_FIRST_BURST_LENGTH 0x200
690 #define ISCSI_MIN_MAX_BURST_LENGTH 0x200
691 #define ISCSI_MIN_CONNECTIONS 1
692 #define ISCSI_MIN_MAX_OUTSTANDING_R2T 1
695 * Maximum values from the iSCSI specification
697 #define ISCSI_MAX_HEADER_DIGEST 3
698 #define ISCSI_MAX_DATA_DIGEST 3
699 #define ISCSI_MAX_TIME2RETAIN 3600
700 #define ISCSI_MAX_TIME2WAIT 3600
701 #define ISCSI_MAX_ERROR_RECOVERY_LEVEL 2
702 #define ISCSI_MAX_FIRST_BURST_LENGTH 0xffffff
703 #define ISCSI_MAX_BURST_LENGTH 0xffffff
704 #define ISCSI_MAX_CONNECTIONS 65535
705 #define ISCSI_MAX_OUTSTANDING_R2T 65535
706 #define ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH 0xffffff
707 #define ISCSI_MAX_TPGT_VALUE 65535 /* 16 bit numeric */
710 * iqn and eui name prefixes and related defines
712 #define ISCSI_IQN_NAME_PREFIX "iqn"
713 #define ISCSI_EUI_NAME_PREFIX "eui"
714 #define ISCSI_EUI_NAME_LEN 20 /* eui. plus 16 octets */
720 #endif /* _ISCSI_PROTOCOL_H */