xref: /onnv-gate/usr/src/uts/common/sys/iscsi_protocol.h (revision 7978:4559e57ec313)
12314Smcneal /*
22314Smcneal  * CDDL HEADER START
32314Smcneal  *
42314Smcneal  * The contents of this file are subject to the terms of the
52314Smcneal  * Common Development and Distribution License (the "License").
62314Smcneal  * You may not use this file except in compliance with the License.
72314Smcneal  *
82314Smcneal  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92314Smcneal  * or http://www.opensolaris.org/os/licensing.
102314Smcneal  * See the License for the specific language governing permissions
112314Smcneal  * and limitations under the License.
122314Smcneal  *
132314Smcneal  * When distributing Covered Code, include this CDDL HEADER in each
142314Smcneal  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152314Smcneal  * If applicable, add the following below this CDDL HEADER, with the
162314Smcneal  * fields enclosed by brackets "[]" replaced with your own identifying
172314Smcneal  * information: Portions Copyright [yyyy] [name of copyright owner]
182314Smcneal  *
192314Smcneal  * CDDL HEADER END
202314Smcneal  */
212314Smcneal /*
22*7978SPeter.Dunlap@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
232314Smcneal  * Use is subject to license terms.
242314Smcneal  */
252314Smcneal 
262314Smcneal #ifndef _ISCSI_PROTOCOL_H
272314Smcneal #define	_ISCSI_PROTOCOL_H
282314Smcneal 
292314Smcneal #ifdef __cplusplus
302314Smcneal extern "C" {
312314Smcneal #endif
322314Smcneal 
332314Smcneal /*
342314Smcneal  * iSCSI connection daemon
352314Smcneal  * Copyright (C) 2001 Cisco Systems, Inc.
362314Smcneal  * All rights reserved.
372314Smcneal  *
382314Smcneal  * This file sets up definitions of messages and constants used by the
392314Smcneal  * iSCSI protocol.
402314Smcneal  *
412314Smcneal  */
422314Smcneal 
432314Smcneal #include <sys/types.h>
442314Smcneal #include <sys/isa_defs.h>
452314Smcneal 
462314Smcneal #define	ISCSI_MAX_NAME_LEN	224
472314Smcneal 
482314Smcneal /* prototypes for iscsi_crc.c */
492314Smcneal uint32_t iscsi_crc32c(void *address, unsigned long length);
502314Smcneal uint32_t iscsi_crc32c_continued(void *address, unsigned long length,
512314Smcneal     uint32_t crc);
522314Smcneal 
532314Smcneal /* iSCSI listen port for incoming connections */
542314Smcneal #define	ISCSI_LISTEN_PORT 3260
552314Smcneal 
562314Smcneal /* assumes a pointer to a 3-byte array */
572314Smcneal #define	ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
582314Smcneal 
592314Smcneal /* assumes a pointer to a 3 byte array, and an integer value */
602314Smcneal #define	hton24(p, v) {\
612314Smcneal 	p[0] = (((v) >> 16) & 0xFF); \
622314Smcneal 	p[1] = (((v) >> 8) & 0xFF); \
632314Smcneal 	p[2] = ((v) & 0xFF); \
642314Smcneal }
652314Smcneal 
662314Smcneal 
672314Smcneal /* for Login min, max, active version fields */
682314Smcneal #define	ISCSI_MIN_VERSION	0x00
692314Smcneal #define	ISCSI_DRAFT8_VERSION    0x02
702314Smcneal #define	ISCSI_DRAFT20_VERSION   0x00
712314Smcneal #define	ISCSI_MAX_VERSION	0x02
722314Smcneal 
732314Smcneal /* Min. and Max. length of a PDU we can support */
742314Smcneal #define	ISCSI_MIN_PDU_LENGTH	(8 << 9)	/* 4KB */
752314Smcneal #define	ISCSI_MAX_PDU_LENGTH	(0xffffffff)	/* Huge */
762314Smcneal 
772314Smcneal /* Padding word length */
782314Smcneal #define	ISCSI_PAD_WORD_LEN		4
792314Smcneal 
802314Smcneal /* Max. number of Key=Value pairs in a text message */
812314Smcneal #define	ISCSI_MAX_KEY_VALUE_PAIRS	8192
822314Smcneal 
832314Smcneal /* text separtor between key value pairs exhanged in login */
842314Smcneal #define	ISCSI_TEXT_SEPARATOR	'='
852314Smcneal 
86*7978SPeter.Dunlap@Sun.COM /* reserved text constants for Text Mode Negotiation */
87*7978SPeter.Dunlap@Sun.COM #define	ISCSI_TEXT_NONE			"None"
88*7978SPeter.Dunlap@Sun.COM #define	ISCSI_TEXT_REJECT		"Reject"
89*7978SPeter.Dunlap@Sun.COM #define	ISCSI_TEXT_IRRELEVANT		"Irrelevant"
90*7978SPeter.Dunlap@Sun.COM #define	ISCSI_TEXT_NOTUNDERSTOOD	"NotUnderstood"
91*7978SPeter.Dunlap@Sun.COM 
922314Smcneal /* Sun's initiator session ID */
932314Smcneal #define	ISCSI_SUN_ISID_0	0x40	/* ISID - EN format */
942314Smcneal #define	ISCSI_SUN_ISID_1	0x00	/* Sec B */
952314Smcneal #define	ISCSI_SUN_ISID_2	0x00	/* Sec B */
962314Smcneal #define	ISCSI_SUN_ISID_3	0x2A	/* Sec C - 42 = Sun's EN */
972314Smcneal 
982314Smcneal /* Reserved value for initiator/target task tag */
992314Smcneal #define	ISCSI_RSVD_TASK_TAG	0xffffffff
1002314Smcneal 
1012314Smcneal /* maximum length for text keys/values */
1022314Smcneal #define	KEY_MAXLEN 64
1032314Smcneal #define	VALUE_MAXLEN 255
1042314Smcneal #define	TARGET_NAME_MAXLEN    VALUE_MAXLEN
1052314Smcneal 
1062314Smcneal #define	ISCSI_DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH 8192
1072314Smcneal 
1082314Smcneal /* most PDU types have a final bit */
1092314Smcneal #define	ISCSI_FLAG_FINAL		0x80
1102314Smcneal 
1112314Smcneal /*
1122314Smcneal  * Strings used during SendTargets requests
1132314Smcneal  */
1142314Smcneal #define	ISCSI_TEXT_SEPARATOR	'='
1152314Smcneal #define	TARGETNAME "TargetName="
1162314Smcneal #define	TARGETADDRESS "TargetAddress="
1172314Smcneal 
1182314Smcneal /* iSCSI Template Message Header */
1192314Smcneal typedef struct _iscsi_hdr {
1202314Smcneal 	uint8_t opcode;
1212314Smcneal 	uint8_t flags;	/* Final bit */
1222314Smcneal 	uint8_t rsvd2[2];
1232314Smcneal 	uint8_t hlength;	/* AHSs total length */
1242314Smcneal 	uint8_t dlength[3];	/* Data length */
1252314Smcneal 	uint8_t lun[8];
1262314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
1272314Smcneal 	uint8_t		rsvd3[8];
1282314Smcneal 	uint32_t	expstatsn;
1292314Smcneal 	uint8_t		other[16];
1302314Smcneal } iscsi_hdr_t;
1312314Smcneal 
1322314Smcneal typedef struct _iscsi_rsp_hdr {
1332314Smcneal 	uint8_t		opcode;
1342314Smcneal 	uint8_t		flags;
1352314Smcneal 	uint8_t		rsvd1[3];
1362314Smcneal 	uint8_t		dlength[3];
1372314Smcneal 	uint8_t		rsvd2[8];
1382314Smcneal 	uint32_t	itt;
1392314Smcneal 	uint8_t		rsvd3[4];
1402314Smcneal 	uint32_t	statsn;
1412314Smcneal 	uint32_t	expcmdsn;
1422314Smcneal 	uint32_t	maxcmdsn;
1432314Smcneal 	uint8_t		rsvd4[12];
1442314Smcneal } iscsi_rsp_hdr_t;
1452314Smcneal 
1462314Smcneal /* Opcode encoding bits */
1472314Smcneal #define	ISCSI_OP_RETRY			0x80
1482314Smcneal #define	ISCSI_OP_IMMEDIATE		0x40
1492314Smcneal #define	ISCSI_OPCODE_MASK		0x3F
1502314Smcneal 
1512314Smcneal /* Client to Server Message Opcode values */
1522314Smcneal #define	ISCSI_OP_NOOP_OUT		0x00
1532314Smcneal #define	ISCSI_OP_SCSI_CMD		0x01
1542314Smcneal #define	ISCSI_OP_SCSI_TASK_MGT_MSG	0x02
1552314Smcneal #define	ISCSI_OP_LOGIN_CMD		0x03
1562314Smcneal #define	ISCSI_OP_TEXT_CMD		0x04
1572314Smcneal #define	ISCSI_OP_SCSI_DATA		0x05
1582314Smcneal #define	ISCSI_OP_LOGOUT_CMD		0x06
1592314Smcneal #define	ISCSI_OP_SNACK_CMD		0x10
1602314Smcneal 
1612314Smcneal /* Server to Client Message Opcode values */
1622314Smcneal #define	ISCSI_OP_NOOP_IN		0x20
1632314Smcneal #define	ISCSI_OP_SCSI_RSP		0x21
1642314Smcneal #define	ISCSI_OP_SCSI_TASK_MGT_RSP	0x22
1652314Smcneal #define	ISCSI_OP_LOGIN_RSP		0x23
1662314Smcneal #define	ISCSI_OP_TEXT_RSP		0x24
1672314Smcneal #define	ISCSI_OP_SCSI_DATA_RSP		0x25
1682314Smcneal #define	ISCSI_OP_LOGOUT_RSP		0x26
1692314Smcneal #define	ISCSI_OP_RTT_RSP		0x31
1702314Smcneal #define	ISCSI_OP_ASYNC_EVENT		0x32
1712314Smcneal #define	ISCSI_OP_REJECT_MSG		0x3f
1722314Smcneal 
1732314Smcneal 
1742314Smcneal /* SCSI Command Header */
1752314Smcneal typedef struct _iscsi_scsi_cmd_hdr {
1762314Smcneal 	uint8_t opcode;
1772314Smcneal 	uint8_t flags;
1782314Smcneal 	uint8_t rsvd[2];
1792314Smcneal 	uint8_t hlength;
1802314Smcneal 	uint8_t dlength[3];
1812314Smcneal 	uint8_t lun[8];
1822314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
1832314Smcneal 	uint32_t data_length;
1842314Smcneal 	uint32_t cmdsn;
1852314Smcneal 	uint32_t expstatsn;
1862314Smcneal 	uint8_t scb[16];	/* SCSI Command Block */
1872314Smcneal 	/*
1882314Smcneal 	 * Additional Data (Command Dependent)
1892314Smcneal 	 */
1902314Smcneal } iscsi_scsi_cmd_hdr_t;
1912314Smcneal 
1922314Smcneal /* Command PDU flags */
1932314Smcneal #define	ISCSI_FLAG_CMD_READ		0x40
1942314Smcneal #define	ISCSI_FLAG_CMD_WRITE		0x20
1952314Smcneal #define	ISCSI_FLAG_CMD_ATTR_MASK	0x07	/* 3 bits */
1962314Smcneal 
1972314Smcneal /* SCSI Command Attribute values */
1982314Smcneal #define	ISCSI_ATTR_UNTAGGED		0
1992314Smcneal #define	ISCSI_ATTR_SIMPLE		1
2002314Smcneal #define	ISCSI_ATTR_ORDERED		2
2012314Smcneal #define	ISCSI_ATTR_HEAD_OF_QUEUE	3
2022314Smcneal #define	ISCSI_ATTR_ACA			4
2032314Smcneal 
2042314Smcneal 
2052314Smcneal /* SCSI Response Header */
2062314Smcneal typedef struct _iscsi_scsi_rsp_hdr {
2072314Smcneal 	uint8_t opcode;
2082314Smcneal 	uint8_t flags;
2092314Smcneal 	uint8_t response;
2102314Smcneal 	uint8_t cmd_status;
2112314Smcneal 	uint8_t hlength;
2122314Smcneal 	uint8_t dlength[3];
2132314Smcneal 	uint8_t rsvd[8];
2142314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
2152314Smcneal 	uint32_t rsvd1;
2162314Smcneal 	uint32_t statsn;
2172314Smcneal 	uint32_t expcmdsn;
2182314Smcneal 	uint32_t maxcmdsn;
2192314Smcneal 	uint32_t expdatasn;
2202314Smcneal 	uint32_t bi_residual_count;
2212314Smcneal 	uint32_t residual_count;
2222314Smcneal 	/*
2232314Smcneal 	 * Response or Sense Data (optional)
2242314Smcneal 	 */
2252314Smcneal } iscsi_scsi_rsp_hdr_t;
2262314Smcneal 
2272314Smcneal /* 10.2.2.3 - Extended CDB Additional Header Segment */
2282314Smcneal 
2292314Smcneal typedef struct _iscsi_addl_hdr {
2302314Smcneal 	iscsi_scsi_cmd_hdr_t ahs_isch;
2312314Smcneal 	uint8_t ahs_hlen_hi;
2322314Smcneal 	uint8_t ahs_hlen_lo;
2332314Smcneal 	uint8_t ahs_key;
2342314Smcneal 	uint8_t ahs_resv;
2352314Smcneal 	uint8_t ahs_extscb[4];
2362314Smcneal } iscsi_addl_hdr_t;
2372314Smcneal 
2382314Smcneal /* Command Response PDU flags */
2392314Smcneal #define	ISCSI_FLAG_CMD_BIDI_OVERFLOW	0x10
2402314Smcneal #define	ISCSI_FLAG_CMD_BIDI_UNDERFLOW	0x08
2412314Smcneal #define	ISCSI_FLAG_CMD_OVERFLOW		0x04
2422314Smcneal #define	ISCSI_FLAG_CMD_UNDERFLOW	0x02
2432314Smcneal 
2442314Smcneal /* iSCSI Status values. Valid if Rsp Selector bit is not set */
2452314Smcneal #define	ISCSI_STATUS_CMD_COMPLETED	0
2462314Smcneal #define	ISCSI_STATUS_TARGET_FAILURE	1
2472314Smcneal #define	ISCSI_STATUS_SUBSYS_FAILURE	2
2482314Smcneal 
2492314Smcneal 
2502314Smcneal /* Asynchronous Event Header */
2512314Smcneal typedef struct _iscsi_async_evt_hdr {
2522314Smcneal 	uint8_t opcode;
2532314Smcneal 	uint8_t flags;
2542314Smcneal 	uint8_t rsvd2[2];
2552314Smcneal 	uint8_t rsvd3;
2562314Smcneal 	uint8_t dlength[3];
2572314Smcneal 	uint8_t lun[8];
2582314Smcneal 	uint8_t rsvd4[8];
2592314Smcneal 	uint32_t statsn;
2602314Smcneal 	uint32_t expcmdsn;
2612314Smcneal 	uint32_t maxcmdsn;
2622314Smcneal 	uint8_t async_event;
2632314Smcneal 	uint8_t async_vcode;
2642314Smcneal 	uint16_t param1;
2652314Smcneal 	uint16_t param2;
2662314Smcneal 	uint16_t param3;
2672314Smcneal 	uint8_t rsvd5[4];
2682314Smcneal } iscsi_async_evt_hdr_t;
2692314Smcneal 
2702314Smcneal /* iSCSI Event Indicator values */
2712314Smcneal #define	ISCSI_ASYNC_EVENT_SCSI_EVENT			0
2722314Smcneal #define	ISCSI_ASYNC_EVENT_REQUEST_LOGOUT		1
2732314Smcneal #define	ISCSI_ASYNC_EVENT_DROPPING_CONNECTION		2
2742314Smcneal #define	ISCSI_ASYNC_EVENT_DROPPING_ALL_CONNECTIONS	3
2752314Smcneal #define	ISCSI_ASYNC_EVENT_PARAM_NEGOTIATION		4
2762314Smcneal #define	ISCSI_ASYNC_EVENT_VENDOR_SPECIFIC		255
2772314Smcneal 
2782314Smcneal 
2792314Smcneal /* NOP-Out Message */
2802314Smcneal typedef struct _iscsi_nop_out_hdr {
2812314Smcneal 	uint8_t opcode;
2822314Smcneal 	uint8_t flags;
2832314Smcneal 	uint16_t rsvd2;
2842314Smcneal 	uint8_t rsvd3;
2852314Smcneal 	uint8_t dlength[3];
2862314Smcneal 	uint8_t lun[8];
2872314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
2882314Smcneal 	uint32_t ttt;	/* Target Transfer Tag */
2892314Smcneal 	uint32_t cmdsn;
2902314Smcneal 	uint32_t expstatsn;
2912314Smcneal 	uint8_t rsvd4[16];
2922314Smcneal } iscsi_nop_out_hdr_t;
2932314Smcneal 
2942314Smcneal 
2952314Smcneal /* NOP-In Message */
2962314Smcneal typedef struct _iscsi_nop_in_hdr {
2972314Smcneal 	uint8_t opcode;
2982314Smcneal 	uint8_t flags;
2992314Smcneal 	uint16_t rsvd2;
3002314Smcneal 	uint8_t rsvd3;
3012314Smcneal 	uint8_t dlength[3];
3022314Smcneal 	uint8_t lun[8];
3032314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
3042314Smcneal 	uint32_t ttt;	/* Target Transfer Tag */
3052314Smcneal 	uint32_t statsn;
3062314Smcneal 	uint32_t expcmdsn;
3072314Smcneal 	uint32_t maxcmdsn;
3082314Smcneal 	uint8_t rsvd4[12];
3092314Smcneal } iscsi_nop_in_hdr_t;
3102314Smcneal 
3112314Smcneal /* SCSI Task Management Message Header */
3122314Smcneal typedef struct _iscsi_scsi_task_mgt_hdr {
3132314Smcneal 	uint8_t opcode;
3142314Smcneal 	uint8_t function;
3152314Smcneal 	uint8_t rsvd1[2];
3162314Smcneal 	uint8_t hlength;
3172314Smcneal 	uint8_t dlength[3];
3182314Smcneal 	uint8_t lun[8];
3192314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
3202314Smcneal 	uint32_t rtt;	/* Reference Task Tag */
3212314Smcneal 	uint32_t cmdsn;
3222314Smcneal 	uint32_t expstatsn;
3232314Smcneal 	uint32_t refcmdsn;
3242314Smcneal 	uint32_t expdatasn;
3252314Smcneal 	uint8_t rsvd2[8];
3262314Smcneal } iscsi_scsi_task_mgt_hdr_t;
3272314Smcneal 
3282314Smcneal #define	ISCSI_FLAG_TASK_MGMT_FUNCTION_MASK  0x7F
3292314Smcneal 
3302314Smcneal /* Function values */
3312314Smcneal #define	ISCSI_TM_FUNC_ABORT_TASK		1
3322314Smcneal #define	ISCSI_TM_FUNC_ABORT_TASK_SET		2
3332314Smcneal #define	ISCSI_TM_FUNC_CLEAR_ACA			3
3342314Smcneal #define	ISCSI_TM_FUNC_CLEAR_TASK_SET		4
3352314Smcneal #define	ISCSI_TM_FUNC_LOGICAL_UNIT_RESET	5
3362314Smcneal #define	ISCSI_TM_FUNC_TARGET_WARM_RESET		6
3372314Smcneal #define	ISCSI_TM_FUNC_TARGET_COLD_RESET		7
3382314Smcneal #define	ISCSI_TM_FUNC_TASK_REASSIGN		8
3392314Smcneal 
3402314Smcneal 
3412314Smcneal /* SCSI Task Management Response Header */
3422314Smcneal typedef struct _iscsi_scsi_task_mgt_rsp_hdr {
3432314Smcneal 	uint8_t opcode;
3442314Smcneal 	uint8_t flags;
3452314Smcneal 	uint8_t response;	/* see Response values below */
3462314Smcneal 	uint8_t qualifier;
3472314Smcneal 	uint8_t hlength;
3482314Smcneal 	uint8_t dlength[3];
3492314Smcneal 	uint8_t rsvd2[8];
3502314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
3512314Smcneal 	uint32_t rtt;	/* Reference Task Tag */
3522314Smcneal 	uint32_t statsn;
3532314Smcneal 	uint32_t expcmdsn;
3542314Smcneal 	uint32_t maxcmdsn;
3552314Smcneal 	uint8_t rsvd3[12];
3562314Smcneal } iscsi_scsi_task_mgt_rsp_hdr_t;
3572314Smcneal 
3582314Smcneal 
3592314Smcneal /* Response values */
3602314Smcneal #define	SCSI_TCP_TM_RESP_COMPLETE	0x00
3612314Smcneal #define	SCSI_TCP_TM_RESP_NO_TASK	0x01
3622314Smcneal #define	SCSI_TCP_TM_RESP_NO_LUN		0x02
3632314Smcneal #define	SCSI_TCP_TM_RESP_TASK_ALLEGIANT	0x03
364*7978SPeter.Dunlap@Sun.COM #define	SCSI_TCP_TM_RESP_NO_ALLG_REASSN	0x04
365*7978SPeter.Dunlap@Sun.COM #define	SCSI_TCP_TM_RESP_FUNC_NOT_SUPP	0x05
366*7978SPeter.Dunlap@Sun.COM #define	SCSI_TCP_TM_RESP_FUNC_AUTH_FAIL	0x06
3672314Smcneal #define	SCSI_TCP_TM_RESP_REJECTED	0xff
3682314Smcneal 
369*7978SPeter.Dunlap@Sun.COM /*
370*7978SPeter.Dunlap@Sun.COM  * Maintained for backward compatibility.
371*7978SPeter.Dunlap@Sun.COM  */
372*7978SPeter.Dunlap@Sun.COM 
373*7978SPeter.Dunlap@Sun.COM #define	SCSI_TCP_TM_RESP_NO_FAILOVER	SCSI_TCP_TM_RESP_NO_ALLG_REASSN
374*7978SPeter.Dunlap@Sun.COM #define	SCSI_TCP_TM_RESP_IN_PRGRESS	SCSI_TCP_TM_RESP_FUNC_NOT_SUPP
375*7978SPeter.Dunlap@Sun.COM 
3762314Smcneal /* Ready To Transfer Header */
3772314Smcneal typedef struct _iscsi_rtt_hdr {
3782314Smcneal 	uint8_t opcode;
3792314Smcneal 	uint8_t flags;
3802314Smcneal 	uint8_t rsvd2[2];
3812314Smcneal 	uint8_t rsvd3[12];
3822314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
3832314Smcneal 	uint32_t ttt;	/* Target Transfer Tag */
3842314Smcneal 	uint32_t statsn;
3852314Smcneal 	uint32_t expcmdsn;
3862314Smcneal 	uint32_t maxcmdsn;
3872314Smcneal 	uint32_t rttsn;
3882314Smcneal 	uint32_t data_offset;
3892314Smcneal 	uint32_t data_length;
3902314Smcneal } iscsi_rtt_hdr_t;
3912314Smcneal 
3922314Smcneal 
3932314Smcneal /* SCSI Data Hdr */
3942314Smcneal typedef struct _iscsi_data_hdr {
3952314Smcneal 	uint8_t opcode;
3962314Smcneal 	uint8_t flags;
3972314Smcneal 	uint8_t rsvd2[2];
3982314Smcneal 	uint8_t rsvd3;
3992314Smcneal 	uint8_t dlength[3];
4002314Smcneal 	uint8_t lun[8];
4012314Smcneal 	uint32_t itt;
4022314Smcneal 	uint32_t ttt;
4032314Smcneal 	uint32_t rsvd4;
4042314Smcneal 	uint32_t expstatsn;
4052314Smcneal 	uint32_t rsvd5;
4062314Smcneal 	uint32_t datasn;
4072314Smcneal 	uint32_t offset;
4082314Smcneal 	uint32_t rsvd6;
4092314Smcneal 	/*
4102314Smcneal 	 * Payload
4112314Smcneal 	 */
4122314Smcneal } iscsi_data_hdr_t;
4132314Smcneal 
4142314Smcneal /* SCSI Data Response Hdr */
4152314Smcneal typedef struct _iscsi_data_rsp_hdr {
4162314Smcneal 	uint8_t opcode;
4172314Smcneal 	uint8_t flags;
4182314Smcneal 	uint8_t rsvd2;
4192314Smcneal 	uint8_t cmd_status;
4202314Smcneal 	uint8_t hlength;
4212314Smcneal 	uint8_t dlength[3];
4222314Smcneal 	uint8_t lun[8];
4232314Smcneal 	uint32_t itt;
4242314Smcneal 	uint32_t ttt;
4252314Smcneal 	uint32_t statsn;
4262314Smcneal 	uint32_t expcmdsn;
4272314Smcneal 	uint32_t maxcmdsn;
4282314Smcneal 	uint32_t datasn;
4292314Smcneal 	uint32_t offset;
4302314Smcneal 	uint32_t residual_count;
4312314Smcneal } iscsi_data_rsp_hdr_t;
4322314Smcneal 
4332314Smcneal /* Data Response PDU flags */
4342314Smcneal #define	ISCSI_FLAG_DATA_ACK		0x40
4352314Smcneal #define	ISCSI_FLAG_DATA_OVERFLOW	0x04
4362314Smcneal #define	ISCSI_FLAG_DATA_UNDERFLOW	0x02
4372314Smcneal #define	ISCSI_FLAG_DATA_STATUS		0x01
4382314Smcneal 
4392314Smcneal 
4402314Smcneal /* Text Header */
4412314Smcneal typedef struct _iscsi_text_hdr {
4422314Smcneal 	uint8_t opcode;
4432314Smcneal 	uint8_t flags;
4442314Smcneal 	uint8_t rsvd2[2];
4452314Smcneal 	uint8_t hlength;
4462314Smcneal 	uint8_t dlength[3];
4472314Smcneal 	uint8_t rsvd4[8];
4482314Smcneal 	uint32_t itt;
4492314Smcneal 	uint32_t ttt;
4502314Smcneal 	uint32_t cmdsn;
4512314Smcneal 	uint32_t expstatsn;
4522314Smcneal 	uint8_t rsvd5[16];
4532314Smcneal 	/*
4542314Smcneal 	 * Text - key=value pairs
4552314Smcneal 	 */
4562314Smcneal } iscsi_text_hdr_t;
4572314Smcneal 
4582314Smcneal #define	ISCSI_FLAG_TEXT_CONTINUE	0x40
4592314Smcneal 
4602314Smcneal /* Text Response Header */
4612314Smcneal typedef struct _iscsi_text_rsp_hdr {
4622314Smcneal 	uint8_t opcode;
4632314Smcneal 	uint8_t flags;
4642314Smcneal 	uint8_t rsvd2[2];
4652314Smcneal 	uint8_t hlength;
4662314Smcneal 	uint8_t dlength[3];
4672314Smcneal 	uint8_t rsvd4[8];
4682314Smcneal 	uint32_t itt;
4692314Smcneal 	uint32_t ttt;
4702314Smcneal 	uint32_t statsn;
4712314Smcneal 	uint32_t expcmdsn;
4722314Smcneal 	uint32_t maxcmdsn;
4732314Smcneal 	uint8_t rsvd5[12];
4742314Smcneal 	/*
4752314Smcneal 	 * Text Response - key:value pairs
4762314Smcneal 	 */
4772314Smcneal } iscsi_text_rsp_hdr_t;
4782314Smcneal 
479*7978SPeter.Dunlap@Sun.COM #define	ISCSI_ISID_LEN	6
480*7978SPeter.Dunlap@Sun.COM 
4812314Smcneal /* Login Header */
4822314Smcneal typedef struct _iscsi_login_hdr {
4832314Smcneal 	uint8_t opcode;
4842314Smcneal 	uint8_t flags;
4852314Smcneal 	uint8_t max_version;	/* Max. version supported */
4862314Smcneal 	uint8_t min_version;	/* Min. version supported */
4872314Smcneal 	uint8_t hlength;
4882314Smcneal 	uint8_t dlength[3];
489*7978SPeter.Dunlap@Sun.COM 	uint8_t isid[ISCSI_ISID_LEN];	/* Initiator Session ID */
4902314Smcneal 	uint16_t tsid;	/* Target Session ID */
4912314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
4922314Smcneal 	uint16_t cid;
4932314Smcneal 	uint16_t rsvd3;
4942314Smcneal 	uint32_t cmdsn;
4952314Smcneal 	uint32_t expstatsn;
4962314Smcneal 	uint8_t rsvd5[16];
4972314Smcneal } iscsi_login_hdr_t;
4982314Smcneal 
4992314Smcneal /* Login PDU flags */
5002314Smcneal #define	ISCSI_FLAG_LOGIN_TRANSIT		0x80
5012314Smcneal #define	ISCSI_FLAG_LOGIN_CONTINUE		0x40
5022314Smcneal #define	ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK	0x0C	/* 2 bits */
5032314Smcneal #define	ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK	0x03	/* 2 bits */
5042314Smcneal 
5052314Smcneal #define	ISCSI_LOGIN_CURRENT_STAGE(flags) \
5062314Smcneal 	((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
5072314Smcneal #define	ISCSI_LOGIN_NEXT_STAGE(flags) \
5082314Smcneal 	(flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
5092314Smcneal 
5102314Smcneal 
5112314Smcneal /* Login Response Header */
5122314Smcneal typedef struct _iscsi_login_rsp_hdr {
5132314Smcneal 	uint8_t opcode;
5142314Smcneal 	uint8_t flags;
5152314Smcneal 	uint8_t max_version;	/* Max. version supported */
5162314Smcneal 	uint8_t active_version;	/* Active version */
5172314Smcneal 	uint8_t hlength;
5182314Smcneal 	uint8_t dlength[3];
519*7978SPeter.Dunlap@Sun.COM 	uint8_t isid[ISCSI_ISID_LEN];	/* Initiator Session ID */
5202314Smcneal 	uint16_t tsid;	/* Target Session ID */
5212314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
5222314Smcneal 	uint32_t rsvd3;
5232314Smcneal 	uint32_t statsn;
5242314Smcneal 	uint32_t expcmdsn;
5252314Smcneal 	uint32_t maxcmdsn;
5262314Smcneal 	uint8_t status_class;	/* see Login RSP ststus classes below */
5272314Smcneal 	uint8_t status_detail;	/* see Login RSP Status details below */
5282314Smcneal 	uint8_t rsvd4[10];
5292314Smcneal } iscsi_login_rsp_hdr_t;
5302314Smcneal 
5312314Smcneal /* Login stage (phase) codes for CSG, NSG */
5322314Smcneal #define	ISCSI_SECURITY_NEGOTIATION_STAGE	0
5332314Smcneal #define	ISCSI_OP_PARMS_NEGOTIATION_STAGE	1
5342314Smcneal #define	ISCSI_FULL_FEATURE_PHASE		3
5352314Smcneal 
5362314Smcneal /* Login Status response classes */
5372314Smcneal #define	ISCSI_STATUS_CLASS_SUCCESS		0x00
5382314Smcneal #define	ISCSI_STATUS_CLASS_REDIRECT		0x01
5392314Smcneal #define	ISCSI_STATUS_CLASS_INITIATOR_ERR	0x02
5402314Smcneal #define	ISCSI_STATUS_CLASS_TARGET_ERR		0x03
5412314Smcneal 
5422314Smcneal /* Login Status response detail codes */
5432314Smcneal /* Class-0 (Success) */
5442314Smcneal #define	ISCSI_LOGIN_STATUS_ACCEPT		0x00
5452314Smcneal 
5462314Smcneal /* Class-1 (Redirection) */
5472314Smcneal #define	ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP	0x01
5482314Smcneal #define	ISCSI_LOGIN_STATUS_TGT_MOVED_PERM	0x02
5492314Smcneal 
5502314Smcneal /* Class-2 (Initiator Error) */
5512314Smcneal #define	ISCSI_LOGIN_STATUS_INIT_ERR		0x00
5522314Smcneal #define	ISCSI_LOGIN_STATUS_AUTH_FAILED		0x01
5532314Smcneal #define	ISCSI_LOGIN_STATUS_TGT_FORBIDDEN	0x02
5542314Smcneal #define	ISCSI_LOGIN_STATUS_TGT_NOT_FOUND	0x03
5552314Smcneal #define	ISCSI_LOGIN_STATUS_TGT_REMOVED		0x04
5562314Smcneal #define	ISCSI_LOGIN_STATUS_NO_VERSION		0x05
5572314Smcneal #define	ISCSI_LOGIN_STATUS_ISID_ERROR		0x06
5582314Smcneal #define	ISCSI_LOGIN_STATUS_MISSING_FIELDS	0x07
5592314Smcneal #define	ISCSI_LOGIN_STATUS_CONN_ADD_FAILED	0x08
5602314Smcneal #define	ISCSI_LOGIN_STATUS_NO_SESSION_TYPE	0x09
5612314Smcneal #define	ISCSI_LOGIN_STATUS_NO_SESSION		0x0a
5622314Smcneal #define	ISCSI_LOGIN_STATUS_INVALID_REQUEST	0x0b
5632314Smcneal 
5642314Smcneal /* Class-3 (Target Error) */
5652314Smcneal #define	ISCSI_LOGIN_STATUS_TARGET_ERROR		0x00
5662314Smcneal #define	ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE	0x01
5672314Smcneal #define	ISCSI_LOGIN_STATUS_NO_RESOURCES		0x02
5682314Smcneal 
5692314Smcneal /* Logout Header */
5702314Smcneal typedef struct _iscsi_logout_hdr {
5712314Smcneal 	uint8_t opcode;
5722314Smcneal 	uint8_t flags;
5732314Smcneal 	uint8_t rsvd1[2];
5742314Smcneal 	uint8_t hlength;
5752314Smcneal 	uint8_t dlength[3];
5762314Smcneal 	uint8_t rsvd2[8];
5772314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
5782314Smcneal 	uint16_t cid;
5792314Smcneal 	uint8_t rsvd3[2];
5802314Smcneal 	uint32_t cmdsn;
5812314Smcneal 	uint32_t expstatsn;
5822314Smcneal 	uint8_t rsvd4[16];
5832314Smcneal } iscsi_logout_hdr_t;
5842314Smcneal 
5852314Smcneal /* Logout PDU flags */
5862314Smcneal #define	ISCSI_FLAG_LOGOUT_REASON_MASK		0x7F
5872314Smcneal 
5882314Smcneal /* logout reason_code values */
5892314Smcneal 
5902314Smcneal #define	ISCSI_LOGOUT_REASON_CLOSE_SESSION	0
5912314Smcneal #define	ISCSI_LOGOUT_REASON_CLOSE_CONNECTION	1
5922314Smcneal #define	ISCSI_LOGOUT_REASON_RECOVERY		2
5932314Smcneal #define	ISCSI_LOGOUT_REASON_AEN_REQUEST		3
5942314Smcneal 
5952314Smcneal /* Logout Response Header */
5962314Smcneal typedef struct _iscsi_logout_rsp_hdr {
5972314Smcneal 	uint8_t opcode;
5982314Smcneal 	uint8_t flags;
5992314Smcneal 	uint8_t response;	/* see Logout response values below */
6002314Smcneal 	uint8_t rsvd2;
6012314Smcneal 	uint8_t hlength;
6022314Smcneal 	uint8_t dlength[3];
6032314Smcneal 	uint8_t rsvd3[8];
6042314Smcneal 	uint32_t itt;	/* Initiator Task Tag */
6052314Smcneal 	uint32_t rsvd4;
6062314Smcneal 	uint32_t statsn;
6072314Smcneal 	uint32_t expcmdsn;
6082314Smcneal 	uint32_t maxcmdsn;
6092314Smcneal 	uint32_t rsvd5;
6102314Smcneal 	uint16_t t2wait;
6112314Smcneal 	uint16_t t2retain;
6122314Smcneal 	uint32_t rsvd6;
6132314Smcneal } iscsi_logout_rsp_hdr_t;
6142314Smcneal 
6152314Smcneal /* logout response status values */
6162314Smcneal 
6172314Smcneal #define	ISCSI_LOGOUT_SUCCESS		  0
6182314Smcneal #define	ISCSI_LOGOUT_CID_NOT_FOUND	  1
6192314Smcneal #define	ISCSI_LOGOUT_RECOVERY_UNSUPPORTED 2
6202314Smcneal #define	ISCSI_LOGOUT_CLEANUP_FAILED	  3
6212314Smcneal 
6222314Smcneal 
6232314Smcneal /* SNACK Header */
6242314Smcneal typedef struct _iscsi_snack_hdr {
6252314Smcneal 	uint8_t opcode;
6262314Smcneal 	uint8_t flags;
6272314Smcneal 	uint8_t rsvd2[14];
6282314Smcneal 	uint32_t itt;
6292314Smcneal 	uint32_t begrun;
6302314Smcneal 	uint32_t runlength;
6312314Smcneal 	uint32_t expstatsn;
6322314Smcneal 	uint32_t rsvd3;
6332314Smcneal 	uint32_t expdatasn;
6342314Smcneal 	uint8_t rsvd6[8];
6352314Smcneal } iscsi_snack_hdr_t;
6362314Smcneal 
6372314Smcneal /* SNACK PDU flags */
6382314Smcneal #define	ISCSI_FLAG_SNACK_TYPE_MASK	0x0F	/* 4 bits */
6392314Smcneal 
6402314Smcneal /* Reject Message Header */
6412314Smcneal typedef struct _iscsi_reject_rsp_hdr {
6422314Smcneal 	uint8_t opcode;
6432314Smcneal 	uint8_t flags;
6442314Smcneal 	uint8_t reason;
6452314Smcneal 	uint8_t rsvd2;
6462314Smcneal 	uint8_t rsvd3;
6472314Smcneal 	uint8_t dlength[3];
648*7978SPeter.Dunlap@Sun.COM 	uint8_t rsvd4[8];
649*7978SPeter.Dunlap@Sun.COM 	uint8_t	must_be_ff[4];
650*7978SPeter.Dunlap@Sun.COM 	uint8_t	rsvd4a[4];
6512314Smcneal 	uint32_t statsn;
6522314Smcneal 	uint32_t expcmdsn;
6532314Smcneal 	uint32_t maxcmdsn;
6542314Smcneal 	uint32_t datasn;
6552314Smcneal 	uint8_t rsvd5[8];
6562314Smcneal 	/*
6572314Smcneal 	 * Text - Rejected hdr
6582314Smcneal 	 */
6592314Smcneal } iscsi_reject_rsp_hdr_t;
6602314Smcneal 
6612314Smcneal /* Reason for Reject */
6622314Smcneal #define	ISCSI_REJECT_CMD_BEFORE_LOGIN		1
6632314Smcneal #define	ISCSI_REJECT_DATA_DIGEST_ERROR		2
6642314Smcneal #define	ISCSI_REJECT_SNACK_REJECT		3
6652314Smcneal #define	ISCSI_REJECT_PROTOCOL_ERROR		4
6662314Smcneal #define	ISCSI_REJECT_CMD_NOT_SUPPORTED		5
6672314Smcneal #define	ISCSI_REJECT_IMM_CMD_REJECT		6
6682314Smcneal #define	ISCSI_REJECT_TASK_IN_PROGRESS		7
6692314Smcneal #define	ISCSI_REJECT_INVALID_DATA_ACK		8
6702314Smcneal #define	ISCSI_REJECT_INVALID_PDU_FIELD		9
6712314Smcneal #define	ISCSI_REJECT_LONG_OPERATION_REJECT	10
6722314Smcneal #define	ISCSI_REJECT_NEGOTIATION_RESET		11
6732314Smcneal #define	ISCSI_REJECT_WAITING_FOR_LOGOUT		12
6742314Smcneal 
6752314Smcneal /* Defaults as defined by the iSCSI specification */
6762314Smcneal #define	ISCSI_DEFAULT_IMMEDIATE_DATA		TRUE
6772314Smcneal #define	ISCSI_DEFAULT_INITIALR2T		TRUE
6782314Smcneal #define	ISCSI_DEFAULT_FIRST_BURST_LENGTH	(64 * 1024) /* 64kbytes */
6792314Smcneal #define	ISCSI_DEFAULT_MAX_BURST_LENGTH		(256 * 1024) /* 256kbytes */
6802314Smcneal #define	ISCSI_DEFAULT_DATA_PDU_IN_ORDER		TRUE
6812314Smcneal #define	ISCSI_DEFAULT_DATA_SEQUENCE_IN_ORDER	TRUE
6822314Smcneal #define	ISCSI_DEFAULT_TIME_TO_WAIT		2 /* 2 seconds */
6832314Smcneal #define	ISCSI_DEFAULT_TIME_TO_RETAIN		20 /* 20 seconds */
6842314Smcneal #define	ISCSI_DEFAULT_HEADER_DIGEST		ISCSI_DIGEST_NONE
6852314Smcneal #define	ISCSI_DEFAULT_DATA_DIGEST		ISCSI_DIGEST_NONE
6862314Smcneal #define	ISCSI_DEFAULT_MAX_RECV_SEG_LEN		(64 * 1024)
6872314Smcneal #define	ISCSI_DEFAULT_MAX_XMIT_SEG_LEN		(8 * 1024)
6882314Smcneal #define	ISCSI_DEFAULT_MAX_CONNECTIONS		1
6892314Smcneal #define	ISCSI_DEFAULT_MAX_OUT_R2T		1
6902314Smcneal #define	ISCSI_DEFAULT_ERROR_RECOVERY_LEVEL	0
6912314Smcneal #define	ISCSI_DEFAULT_IFMARKER			FALSE
6922314Smcneal #define	ISCSI_DEFAULT_OFMARKER			FALSE
6932314Smcneal 
6942314Smcneal /*
695*7978SPeter.Dunlap@Sun.COM  * Minimum values from the iSCSI specification
696*7978SPeter.Dunlap@Sun.COM  */
697*7978SPeter.Dunlap@Sun.COM 
698*7978SPeter.Dunlap@Sun.COM #define	ISCSI_MIN_TIME2RETAIN			0
699*7978SPeter.Dunlap@Sun.COM #define	ISCSI_MIN_TIME2WAIT			0
700*7978SPeter.Dunlap@Sun.COM #define	ISCSI_MIN_ERROR_RECOVERY_LEVEL		0
701*7978SPeter.Dunlap@Sun.COM #define	ISCSI_MIN_RECV_DATA_SEGMENT_LENGTH	0x200
702*7978SPeter.Dunlap@Sun.COM #define	ISCSI_MIN_FIRST_BURST_LENGTH		0x200
703*7978SPeter.Dunlap@Sun.COM #define	ISCSI_MIN_MAX_BURST_LENGTH		0x200
704*7978SPeter.Dunlap@Sun.COM #define	ISCSI_MIN_CONNECTIONS			1
705*7978SPeter.Dunlap@Sun.COM #define	ISCSI_MIN_MAX_OUTSTANDING_R2T		1
706*7978SPeter.Dunlap@Sun.COM 
707*7978SPeter.Dunlap@Sun.COM /*
7082314Smcneal  * Maximum values from the iSCSI specification
7092314Smcneal  */
7102314Smcneal #define	ISCSI_MAX_HEADER_DIGEST			3
7112314Smcneal #define	ISCSI_MAX_DATA_DIGEST			3
7122314Smcneal #define	ISCSI_MAX_TIME2RETAIN			3600
7132314Smcneal #define	ISCSI_MAX_TIME2WAIT			3600
7142314Smcneal #define	ISCSI_MAX_ERROR_RECOVERY_LEVEL		2
7152314Smcneal #define	ISCSI_MAX_FIRST_BURST_LENGTH		0xffffff
7162314Smcneal #define	ISCSI_MAX_BURST_LENGTH			0xffffff
7172314Smcneal #define	ISCSI_MAX_CONNECTIONS			65535
7182314Smcneal #define	ISCSI_MAX_OUTSTANDING_R2T		65535
7192314Smcneal #define	ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH	0xffffff
7202314Smcneal #define	ISCSI_MAX_TPGT_VALUE			65535 /* 16 bit numeric */
7212314Smcneal 
7222314Smcneal /*
7232314Smcneal  * iqn and eui name prefixes and related defines
7242314Smcneal  */
7252314Smcneal #define	ISCSI_IQN_NAME_PREFIX			"iqn"
7262314Smcneal #define	ISCSI_EUI_NAME_PREFIX			"eui"
7272314Smcneal #define	ISCSI_EUI_NAME_LEN			20 /* eui. plus 16 octets */
7282314Smcneal 
7292314Smcneal #ifdef __cplusplus
7302314Smcneal }
7312314Smcneal #endif
7322314Smcneal 
7332314Smcneal #endif /* _ISCSI_PROTOCOL_H */
734