xref: /titanic_41/usr/src/uts/common/sys/iscsi_protocol.h (revision 2e0fe3efe5f9d579d4e44b3532d8e342c68b40ca)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef _ISCSI_PROTOCOL_H
26 #define	_ISCSI_PROTOCOL_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /*
33  * iSCSI connection daemon
34  * Copyright (C) 2001 Cisco Systems, Inc.
35  * All rights reserved.
36  *
37  * This file sets up definitions of messages and constants used by the
38  * iSCSI protocol.
39  *
40  */
41 
42 #include <sys/types.h>
43 #include <sys/isa_defs.h>
44 
45 #define	ISCSI_MAX_NAME_LEN	224
46 #define	ISCSI_MAX_C_USER_LEN	512
47 
48 /* iSCSI listen port for incoming connections */
49 #define	ISCSI_LISTEN_PORT 3260
50 
51 /* assumes a pointer to a 3-byte array */
52 #define	ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
53 
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); \
59 }
60 
61 
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
67 
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 */
71 
72 /* Padding word length */
73 #define	ISCSI_PAD_WORD_LEN		4
74 
75 /* Max. number of Key=Value pairs in a text message */
76 #define	ISCSI_MAX_KEY_VALUE_PAIRS	8192
77 
78 /* text separtor between key value pairs exhanged in login */
79 #define	ISCSI_TEXT_SEPARATOR	'='
80 
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"
86 
87 /* Reserved value for initiator/target task tag */
88 #define	ISCSI_RSVD_TASK_TAG	0xffffffff
89 
90 /* maximum length for text keys/values */
91 #define	KEY_MAXLEN 64
92 #define	VALUE_MAXLEN 255
93 #define	TARGET_NAME_MAXLEN    VALUE_MAXLEN
94 
95 /* most PDU types have a final bit */
96 #define	ISCSI_FLAG_FINAL		0x80
97 
98 /*
99  * Strings used during SendTargets requests
100  */
101 #define	ISCSI_TEXT_SEPARATOR	'='
102 #define	TARGETNAME "TargetName="
103 #define	TARGETADDRESS "TargetAddress="
104 
105 /* iSCSI Template Message Header */
106 typedef struct _iscsi_hdr {
107 	uint8_t opcode;
108 	uint8_t flags;	/* Final bit */
109 	uint8_t rsvd2[2];
110 	uint8_t hlength;	/* AHSs total length */
111 	uint8_t dlength[3];	/* Data length */
112 	uint8_t lun[8];
113 	uint32_t itt;	/* Initiator Task Tag */
114 	uint8_t		rsvd3[8];
115 	uint32_t	expstatsn;
116 	uint8_t		other[16];
117 } iscsi_hdr_t;
118 
119 typedef struct _iscsi_rsp_hdr {
120 	uint8_t		opcode;
121 	uint8_t		flags;
122 	uint8_t		rsvd1[3];
123 	uint8_t		dlength[3];
124 	uint8_t		rsvd2[8];
125 	uint32_t	itt;
126 	uint8_t		rsvd3[4];
127 	uint32_t	statsn;
128 	uint32_t	expcmdsn;
129 	uint32_t	maxcmdsn;
130 	uint8_t		rsvd4[12];
131 } iscsi_rsp_hdr_t;
132 
133 /* Opcode encoding bits */
134 #define	ISCSI_OP_RETRY			0x80
135 #define	ISCSI_OP_IMMEDIATE		0x40
136 #define	ISCSI_OPCODE_MASK		0x3F
137 
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
147 
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
159 
160 
161 /* SCSI Command Header */
162 typedef struct _iscsi_scsi_cmd_hdr {
163 	uint8_t opcode;
164 	uint8_t flags;
165 	uint8_t rsvd[2];
166 	uint8_t hlength;
167 	uint8_t dlength[3];
168 	uint8_t lun[8];
169 	uint32_t itt;	/* Initiator Task Tag */
170 	uint32_t data_length;
171 	uint32_t cmdsn;
172 	uint32_t expstatsn;
173 	uint8_t scb[16];	/* SCSI Command Block */
174 	/*
175 	 * Additional Data (Command Dependent)
176 	 */
177 } iscsi_scsi_cmd_hdr_t;
178 
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 */
183 
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
190 
191 
192 /* SCSI Response Header */
193 typedef struct _iscsi_scsi_rsp_hdr {
194 	uint8_t opcode;
195 	uint8_t flags;
196 	uint8_t response;
197 	uint8_t cmd_status;
198 	uint8_t hlength;
199 	uint8_t dlength[3];
200 	uint8_t rsvd[8];
201 	uint32_t itt;	/* Initiator Task Tag */
202 	uint32_t rsvd1;
203 	uint32_t statsn;
204 	uint32_t expcmdsn;
205 	uint32_t maxcmdsn;
206 	uint32_t expdatasn;
207 	uint32_t bi_residual_count;
208 	uint32_t residual_count;
209 	/*
210 	 * Response or Sense Data (optional)
211 	 */
212 } iscsi_scsi_rsp_hdr_t;
213 
214 /* 10.2.2.3 - Extended CDB Additional Header Segment */
215 
216 typedef struct _iscsi_addl_hdr {
217 	iscsi_scsi_cmd_hdr_t ahs_isch;
218 	uint8_t ahs_hlen_hi;
219 	uint8_t ahs_hlen_lo;
220 	uint8_t ahs_key;
221 	uint8_t ahs_resv;
222 	uint8_t ahs_extscb[4];
223 } iscsi_addl_hdr_t;
224 
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
230 
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
235 
236 
237 /* Asynchronous Event Header */
238 typedef struct _iscsi_async_evt_hdr {
239 	uint8_t opcode;
240 	uint8_t flags;
241 	uint8_t rsvd2[2];
242 	uint8_t rsvd3;
243 	uint8_t dlength[3];
244 	uint8_t lun[8];
245 	uint8_t rsvd4[8];
246 	uint32_t statsn;
247 	uint32_t expcmdsn;
248 	uint32_t maxcmdsn;
249 	uint8_t async_event;
250 	uint8_t async_vcode;
251 	uint16_t param1;
252 	uint16_t param2;
253 	uint16_t param3;
254 	uint8_t rsvd5[4];
255 } iscsi_async_evt_hdr_t;
256 
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
264 
265 
266 /* NOP-Out Message */
267 typedef struct _iscsi_nop_out_hdr {
268 	uint8_t opcode;
269 	uint8_t flags;
270 	uint16_t rsvd2;
271 	uint8_t rsvd3;
272 	uint8_t dlength[3];
273 	uint8_t lun[8];
274 	uint32_t itt;	/* Initiator Task Tag */
275 	uint32_t ttt;	/* Target Transfer Tag */
276 	uint32_t cmdsn;
277 	uint32_t expstatsn;
278 	uint8_t rsvd4[16];
279 } iscsi_nop_out_hdr_t;
280 
281 
282 /* NOP-In Message */
283 typedef struct _iscsi_nop_in_hdr {
284 	uint8_t opcode;
285 	uint8_t flags;
286 	uint16_t rsvd2;
287 	uint8_t rsvd3;
288 	uint8_t dlength[3];
289 	uint8_t lun[8];
290 	uint32_t itt;	/* Initiator Task Tag */
291 	uint32_t ttt;	/* Target Transfer Tag */
292 	uint32_t statsn;
293 	uint32_t expcmdsn;
294 	uint32_t maxcmdsn;
295 	uint8_t rsvd4[12];
296 } iscsi_nop_in_hdr_t;
297 
298 /* SCSI Task Management Message Header */
299 typedef struct _iscsi_scsi_task_mgt_hdr {
300 	uint8_t opcode;
301 	uint8_t function;
302 	uint8_t rsvd1[2];
303 	uint8_t hlength;
304 	uint8_t dlength[3];
305 	uint8_t lun[8];
306 	uint32_t itt;	/* Initiator Task Tag */
307 	uint32_t rtt;	/* Reference Task Tag */
308 	uint32_t cmdsn;
309 	uint32_t expstatsn;
310 	uint32_t refcmdsn;
311 	uint32_t expdatasn;
312 	uint8_t rsvd2[8];
313 } iscsi_scsi_task_mgt_hdr_t;
314 
315 #define	ISCSI_FLAG_TASK_MGMT_FUNCTION_MASK  0x7F
316 
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
326 
327 
328 /* SCSI Task Management Response Header */
329 typedef struct _iscsi_scsi_task_mgt_rsp_hdr {
330 	uint8_t opcode;
331 	uint8_t flags;
332 	uint8_t response;	/* see Response values below */
333 	uint8_t qualifier;
334 	uint8_t hlength;
335 	uint8_t dlength[3];
336 	uint8_t rsvd2[8];
337 	uint32_t itt;	/* Initiator Task Tag */
338 	uint32_t rtt;	/* Reference Task Tag */
339 	uint32_t statsn;
340 	uint32_t expcmdsn;
341 	uint32_t maxcmdsn;
342 	uint8_t rsvd3[12];
343 } iscsi_scsi_task_mgt_rsp_hdr_t;
344 
345 
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
355 
356 /*
357  * Maintained for backward compatibility.
358  */
359 
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
362 
363 /* Ready To Transfer Header */
364 typedef struct _iscsi_rtt_hdr {
365 	uint8_t opcode;
366 	uint8_t flags;
367 	uint8_t rsvd2[2];
368 	uint8_t rsvd3[12];
369 	uint32_t itt;	/* Initiator Task Tag */
370 	uint32_t ttt;	/* Target Transfer Tag */
371 	uint32_t statsn;
372 	uint32_t expcmdsn;
373 	uint32_t maxcmdsn;
374 	uint32_t rttsn;
375 	uint32_t data_offset;
376 	uint32_t data_length;
377 } iscsi_rtt_hdr_t;
378 
379 
380 /* SCSI Data Hdr */
381 typedef struct _iscsi_data_hdr {
382 	uint8_t opcode;
383 	uint8_t flags;
384 	uint8_t rsvd2[2];
385 	uint8_t rsvd3;
386 	uint8_t dlength[3];
387 	uint8_t lun[8];
388 	uint32_t itt;
389 	uint32_t ttt;
390 	uint32_t rsvd4;
391 	uint32_t expstatsn;
392 	uint32_t rsvd5;
393 	uint32_t datasn;
394 	uint32_t offset;
395 	uint32_t rsvd6;
396 	/*
397 	 * Payload
398 	 */
399 } iscsi_data_hdr_t;
400 
401 /* SCSI Data Response Hdr */
402 typedef struct _iscsi_data_rsp_hdr {
403 	uint8_t opcode;
404 	uint8_t flags;
405 	uint8_t rsvd2;
406 	uint8_t cmd_status;
407 	uint8_t hlength;
408 	uint8_t dlength[3];
409 	uint8_t lun[8];
410 	uint32_t itt;
411 	uint32_t ttt;
412 	uint32_t statsn;
413 	uint32_t expcmdsn;
414 	uint32_t maxcmdsn;
415 	uint32_t datasn;
416 	uint32_t offset;
417 	uint32_t residual_count;
418 } iscsi_data_rsp_hdr_t;
419 
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
425 
426 
427 /* Text Header */
428 typedef struct _iscsi_text_hdr {
429 	uint8_t opcode;
430 	uint8_t flags;
431 	uint8_t rsvd2[2];
432 	uint8_t hlength;
433 	uint8_t dlength[3];
434 	uint8_t rsvd4[8];
435 	uint32_t itt;
436 	uint32_t ttt;
437 	uint32_t cmdsn;
438 	uint32_t expstatsn;
439 	uint8_t rsvd5[16];
440 	/*
441 	 * Text - key=value pairs
442 	 */
443 } iscsi_text_hdr_t;
444 
445 #define	ISCSI_FLAG_TEXT_CONTINUE	0x40
446 
447 /* Text Response Header */
448 typedef struct _iscsi_text_rsp_hdr {
449 	uint8_t opcode;
450 	uint8_t flags;
451 	uint8_t rsvd2[2];
452 	uint8_t hlength;
453 	uint8_t dlength[3];
454 	uint8_t rsvd4[8];
455 	uint32_t itt;
456 	uint32_t ttt;
457 	uint32_t statsn;
458 	uint32_t expcmdsn;
459 	uint32_t maxcmdsn;
460 	uint8_t rsvd5[12];
461 	/*
462 	 * Text Response - key:value pairs
463 	 */
464 } iscsi_text_rsp_hdr_t;
465 
466 #define	ISCSI_ISID_LEN	6
467 
468 /* Login Header */
469 typedef struct _iscsi_login_hdr {
470 	uint8_t opcode;
471 	uint8_t flags;
472 	uint8_t max_version;	/* Max. version supported */
473 	uint8_t min_version;	/* Min. version supported */
474 	uint8_t hlength;
475 	uint8_t dlength[3];
476 	uint8_t isid[ISCSI_ISID_LEN];	/* Initiator Session ID */
477 	uint16_t tsid;	/* Target Session ID */
478 	uint32_t itt;	/* Initiator Task Tag */
479 	uint16_t cid;
480 	uint16_t rsvd3;
481 	uint32_t cmdsn;
482 	uint32_t expstatsn;
483 	uint8_t rsvd5[16];
484 } iscsi_login_hdr_t;
485 
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 */
491 
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)
496 
497 
498 /* Login Response Header */
499 typedef struct _iscsi_login_rsp_hdr {
500 	uint8_t opcode;
501 	uint8_t flags;
502 	uint8_t max_version;	/* Max. version supported */
503 	uint8_t active_version;	/* Active version */
504 	uint8_t hlength;
505 	uint8_t dlength[3];
506 	uint8_t isid[ISCSI_ISID_LEN];	/* Initiator Session ID */
507 	uint16_t tsid;	/* Target Session ID */
508 	uint32_t itt;	/* Initiator Task Tag */
509 	uint32_t rsvd3;
510 	uint32_t statsn;
511 	uint32_t expcmdsn;
512 	uint32_t maxcmdsn;
513 	uint8_t status_class;	/* see Login RSP ststus classes below */
514 	uint8_t status_detail;	/* see Login RSP Status details below */
515 	uint8_t rsvd4[10];
516 } iscsi_login_rsp_hdr_t;
517 
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
522 
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
528 
529 /* Login Status response detail codes */
530 /* Class-0 (Success) */
531 #define	ISCSI_LOGIN_STATUS_ACCEPT		0x00
532 
533 /* Class-1 (Redirection) */
534 #define	ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP	0x01
535 #define	ISCSI_LOGIN_STATUS_TGT_MOVED_PERM	0x02
536 
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
550 
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
555 
556 /* Logout Header */
557 typedef struct _iscsi_logout_hdr {
558 	uint8_t opcode;
559 	uint8_t flags;
560 	uint8_t rsvd1[2];
561 	uint8_t hlength;
562 	uint8_t dlength[3];
563 	uint8_t rsvd2[8];
564 	uint32_t itt;	/* Initiator Task Tag */
565 	uint16_t cid;
566 	uint8_t rsvd3[2];
567 	uint32_t cmdsn;
568 	uint32_t expstatsn;
569 	uint8_t rsvd4[16];
570 } iscsi_logout_hdr_t;
571 
572 /* Logout PDU flags */
573 #define	ISCSI_FLAG_LOGOUT_REASON_MASK		0x7F
574 
575 /* logout reason_code values */
576 
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
581 
582 /* Logout Response Header */
583 typedef struct _iscsi_logout_rsp_hdr {
584 	uint8_t opcode;
585 	uint8_t flags;
586 	uint8_t response;	/* see Logout response values below */
587 	uint8_t rsvd2;
588 	uint8_t hlength;
589 	uint8_t dlength[3];
590 	uint8_t rsvd3[8];
591 	uint32_t itt;	/* Initiator Task Tag */
592 	uint32_t rsvd4;
593 	uint32_t statsn;
594 	uint32_t expcmdsn;
595 	uint32_t maxcmdsn;
596 	uint32_t rsvd5;
597 	uint16_t t2wait;
598 	uint16_t t2retain;
599 	uint32_t rsvd6;
600 } iscsi_logout_rsp_hdr_t;
601 
602 /* logout response status values */
603 
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
608 
609 
610 /* SNACK Header */
611 typedef struct _iscsi_snack_hdr {
612 	uint8_t opcode;
613 	uint8_t flags;
614 	uint8_t rsvd2[14];
615 	uint32_t itt;
616 	uint32_t begrun;
617 	uint32_t runlength;
618 	uint32_t expstatsn;
619 	uint32_t rsvd3;
620 	uint32_t expdatasn;
621 	uint8_t rsvd6[8];
622 } iscsi_snack_hdr_t;
623 
624 /* SNACK PDU flags */
625 #define	ISCSI_FLAG_SNACK_TYPE_MASK	0x0F	/* 4 bits */
626 
627 /* Reject Message Header */
628 typedef struct _iscsi_reject_rsp_hdr {
629 	uint8_t opcode;
630 	uint8_t flags;
631 	uint8_t reason;
632 	uint8_t rsvd2;
633 	uint8_t rsvd3;
634 	uint8_t dlength[3];
635 	uint8_t rsvd4[8];
636 	uint8_t	must_be_ff[4];
637 	uint8_t	rsvd4a[4];
638 	uint32_t statsn;
639 	uint32_t expcmdsn;
640 	uint32_t maxcmdsn;
641 	uint32_t datasn;
642 	uint8_t rsvd5[8];
643 	/*
644 	 * Text - Rejected hdr
645 	 */
646 } iscsi_reject_rsp_hdr_t;
647 
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
661 
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
680 
681 /*
682  * Minimum values from the iSCSI specification
683  */
684 
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
693 
694 /*
695  * Maximum values from the iSCSI specification
696  */
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 */
708 
709 /*
710  * iqn and eui name prefixes and related defines
711  */
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 */
715 
716 #ifdef __cplusplus
717 }
718 #endif
719 
720 #endif /* _ISCSI_PROTOCOL_H */
721