Linux Audio

Check our new training course

Loading...
v3.1
 
  1/*
  2 * RFC 3720 (iSCSI) protocol data types
  3 *
  4 * Copyright (C) 2005 Dmitry Yusupov
  5 * Copyright (C) 2005 Alex Aizman
  6 * maintained by open-iscsi@googlegroups.com
  7 *
  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.
 12 *
 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.
 17 *
 18 * See the file COPYING included with this distribution for more details.
 19 */
 20
 21#ifndef ISCSI_PROTO_H
 22#define ISCSI_PROTO_H
 23
 24#include <linux/types.h>
 25#include <scsi/scsi.h>
 26
 27#define ISCSI_DRAFT20_VERSION	0x00
 28
 29/* default iSCSI listen port for incoming connections */
 30#define ISCSI_LISTEN_PORT	3260
 31
 32/* iSCSI header length */
 33#define ISCSI_HDR_LEN		48
 34
 35/* iSCSI CRC32C length */
 36#define ISCSI_CRC_LEN		4
 37
 38/* Padding word length */
 39#define ISCSI_PAD_LEN		4
 40
 41/*
 42 * Serial Number Arithmetic, 32 bits, RFC1982
 43 */
 44
 45static inline int iscsi_sna_lt(u32 n1, u32 n2)
 46{
 47	return (s32)(n1 - n2) < 0;
 48}
 49
 50static inline int iscsi_sna_lte(u32 n1, u32 n2)
 51{
 52	return (s32)(n1 - n2) <= 0;
 53}
 54
 55static inline int iscsi_sna_gt(u32 n1, u32 n2)
 56{
 57	return (s32)(n1 - n2) > 0;
 58}
 59
 60static inline int iscsi_sna_gte(u32 n1, u32 n2)
 61{
 62	return (s32)(n1 - n2) >= 0;
 63}
 64
 65/*
 66 * useful common(control and data pathes) macro
 67 */
 68#define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
 69#define hton24(p, v) { \
 70        p[0] = (((v) >> 16) & 0xFF); \
 71        p[1] = (((v) >> 8) & 0xFF); \
 72        p[2] = ((v) & 0xFF); \
 73}
 74#define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
 75
 76/* initiator tags; opaque for target */
 77typedef uint32_t __bitwise__ itt_t;
 78/* below makes sense only for initiator that created this tag */
 79#define build_itt(itt, age) ((__force itt_t)\
 80	((itt) | ((age) << ISCSI_AGE_SHIFT)))
 81#define get_itt(itt) ((__force uint32_t)(itt_t)(itt) & ISCSI_ITT_MASK)
 82#define RESERVED_ITT ((__force itt_t)0xffffffff)
 83
 84/*
 85 * iSCSI Template Message Header
 86 */
 87struct iscsi_hdr {
 88	uint8_t		opcode;
 89	uint8_t		flags;		/* Final bit */
 90	uint8_t		rsvd2[2];
 91	uint8_t		hlength;	/* AHSs total length */
 92	uint8_t		dlength[3];	/* Data length */
 93	struct scsi_lun	lun;
 94	itt_t		itt;		/* Initiator Task Tag, opaque for target */
 95	__be32		ttt;		/* Target Task Tag */
 96	__be32		statsn;
 97	__be32		exp_statsn;
 98	__be32		max_statsn;
 99	uint8_t		other[12];
100};
101
102/************************* RFC 3720 Begin *****************************/
103
104#define ISCSI_RESERVED_TAG		0xffffffff
105
106/* Opcode encoding bits */
107#define ISCSI_OP_RETRY			0x80
108#define ISCSI_OP_IMMEDIATE		0x40
109#define ISCSI_OPCODE_MASK		0x3F
110
111/* Initiator Opcode values */
112#define ISCSI_OP_NOOP_OUT		0x00
113#define ISCSI_OP_SCSI_CMD		0x01
114#define ISCSI_OP_SCSI_TMFUNC		0x02
115#define ISCSI_OP_LOGIN			0x03
116#define ISCSI_OP_TEXT			0x04
117#define ISCSI_OP_SCSI_DATA_OUT		0x05
118#define ISCSI_OP_LOGOUT			0x06
119#define ISCSI_OP_SNACK			0x10
120
121#define ISCSI_OP_VENDOR1_CMD		0x1c
122#define ISCSI_OP_VENDOR2_CMD		0x1d
123#define ISCSI_OP_VENDOR3_CMD		0x1e
124#define ISCSI_OP_VENDOR4_CMD		0x1f
125
126/* Target Opcode values */
127#define ISCSI_OP_NOOP_IN		0x20
128#define ISCSI_OP_SCSI_CMD_RSP		0x21
129#define ISCSI_OP_SCSI_TMFUNC_RSP	0x22
130#define ISCSI_OP_LOGIN_RSP		0x23
131#define ISCSI_OP_TEXT_RSP		0x24
132#define ISCSI_OP_SCSI_DATA_IN		0x25
133#define ISCSI_OP_LOGOUT_RSP		0x26
134#define ISCSI_OP_R2T			0x31
135#define ISCSI_OP_ASYNC_EVENT		0x32
136#define ISCSI_OP_REJECT			0x3f
137
138struct iscsi_ahs_hdr {
139	__be16 ahslength;
140	uint8_t ahstype;
141	uint8_t ahspec[5];
142};
143
144#define ISCSI_AHSTYPE_CDB		1
145#define ISCSI_AHSTYPE_RLENGTH		2
146#define ISCSI_CDB_SIZE			16
147
148/* iSCSI PDU Header */
149struct iscsi_scsi_req {
150	uint8_t opcode;
151	uint8_t flags;
152	__be16 rsvd2;
153	uint8_t hlength;
154	uint8_t dlength[3];
155	struct scsi_lun lun;
156	itt_t	 itt;	/* Initiator Task Tag */
157	__be32 data_length;
158	__be32 cmdsn;
159	__be32 exp_statsn;
160	uint8_t cdb[ISCSI_CDB_SIZE];	/* SCSI Command Block */
161	/* Additional Data (Command Dependent) */
162};
163
164/* Command PDU flags */
165#define ISCSI_FLAG_CMD_FINAL		0x80
166#define ISCSI_FLAG_CMD_READ		0x40
167#define ISCSI_FLAG_CMD_WRITE		0x20
168#define ISCSI_FLAG_CMD_ATTR_MASK	0x07	/* 3 bits */
169
170/* SCSI Command Attribute values */
171#define ISCSI_ATTR_UNTAGGED		0
172#define ISCSI_ATTR_SIMPLE		1
173#define ISCSI_ATTR_ORDERED		2
174#define ISCSI_ATTR_HEAD_OF_QUEUE	3
175#define ISCSI_ATTR_ACA			4
176
177struct iscsi_rlength_ahdr {
178	__be16 ahslength;
179	uint8_t ahstype;
180	uint8_t reserved;
181	__be32 read_length;
182};
183
184/* Extended CDB AHS */
185struct iscsi_ecdb_ahdr {
186	__be16 ahslength;	/* CDB length - 15, including reserved byte */
187	uint8_t ahstype;
188	uint8_t reserved;
189	/* 4-byte aligned extended CDB spillover */
190	uint8_t ecdb[SCSI_MAX_VARLEN_CDB_SIZE - ISCSI_CDB_SIZE];
191};
192
193/* SCSI Response Header */
194struct iscsi_scsi_rsp {
195	uint8_t opcode;
196	uint8_t flags;
197	uint8_t response;
198	uint8_t cmd_status;
199	uint8_t hlength;
200	uint8_t dlength[3];
201	uint8_t rsvd[8];
202	itt_t	 itt;	/* Initiator Task Tag */
203	__be32	rsvd1;
204	__be32	statsn;
205	__be32	exp_cmdsn;
206	__be32	max_cmdsn;
207	__be32	exp_datasn;
208	__be32	bi_residual_count;
209	__be32	residual_count;
210	/* Response or Sense Data (optional) */
211};
212
213/* Command Response PDU flags */
214#define ISCSI_FLAG_CMD_BIDI_OVERFLOW	0x10
215#define ISCSI_FLAG_CMD_BIDI_UNDERFLOW	0x08
216#define ISCSI_FLAG_CMD_OVERFLOW		0x04
217#define ISCSI_FLAG_CMD_UNDERFLOW	0x02
218
219/* iSCSI Status values. Valid if Rsp Selector bit is not set */
220#define ISCSI_STATUS_CMD_COMPLETED	0
221#define ISCSI_STATUS_TARGET_FAILURE	1
222#define ISCSI_STATUS_SUBSYS_FAILURE	2
223
224/* Asynchronous Event Header */
225struct iscsi_async {
226	uint8_t opcode;
227	uint8_t flags;
228	uint8_t rsvd2[2];
229	uint8_t rsvd3;
230	uint8_t dlength[3];
231	struct scsi_lun	lun;
232	uint8_t rsvd4[8];
233	__be32	statsn;
234	__be32	exp_cmdsn;
235	__be32	max_cmdsn;
236	uint8_t async_event;
237	uint8_t async_vcode;
238	__be16	param1;
239	__be16	param2;
240	__be16	param3;
241	uint8_t rsvd5[4];
242};
243
244/* iSCSI Event Codes */
245#define ISCSI_ASYNC_MSG_SCSI_EVENT			0
246#define ISCSI_ASYNC_MSG_REQUEST_LOGOUT			1
247#define ISCSI_ASYNC_MSG_DROPPING_CONNECTION		2
248#define ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS	3
249#define ISCSI_ASYNC_MSG_PARAM_NEGOTIATION		4
250#define ISCSI_ASYNC_MSG_VENDOR_SPECIFIC			255
251
252/* NOP-Out Message */
253struct iscsi_nopout {
254	uint8_t opcode;
255	uint8_t flags;
256	__be16	rsvd2;
257	uint8_t rsvd3;
258	uint8_t dlength[3];
259	struct scsi_lun	lun;
260	itt_t	 itt;	/* Initiator Task Tag */
261	__be32	ttt;	/* Target Transfer Tag */
262	__be32	cmdsn;
263	__be32	exp_statsn;
264	uint8_t rsvd4[16];
265};
266
267/* NOP-In Message */
268struct iscsi_nopin {
269	uint8_t opcode;
270	uint8_t flags;
271	__be16	rsvd2;
272	uint8_t rsvd3;
273	uint8_t dlength[3];
274	struct scsi_lun	lun;
275	itt_t	 itt;	/* Initiator Task Tag */
276	__be32	ttt;	/* Target Transfer Tag */
277	__be32	statsn;
278	__be32	exp_cmdsn;
279	__be32	max_cmdsn;
280	uint8_t rsvd4[12];
281};
282
283/* SCSI Task Management Message Header */
284struct iscsi_tm {
285	uint8_t opcode;
286	uint8_t flags;
287	uint8_t rsvd1[2];
288	uint8_t hlength;
289	uint8_t dlength[3];
290	struct scsi_lun lun;
291	itt_t	 itt;	/* Initiator Task Tag */
292	itt_t	 rtt;	/* Reference Task Tag */
293	__be32	cmdsn;
294	__be32	exp_statsn;
295	__be32	refcmdsn;
296	__be32	exp_datasn;
297	uint8_t rsvd2[8];
298};
299
300#define ISCSI_FLAG_TM_FUNC_MASK			0x7F
301
302/* Function values */
303#define ISCSI_TM_FUNC_ABORT_TASK		1
304#define ISCSI_TM_FUNC_ABORT_TASK_SET		2
305#define ISCSI_TM_FUNC_CLEAR_ACA			3
306#define ISCSI_TM_FUNC_CLEAR_TASK_SET		4
307#define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET	5
308#define ISCSI_TM_FUNC_TARGET_WARM_RESET		6
309#define ISCSI_TM_FUNC_TARGET_COLD_RESET		7
310#define ISCSI_TM_FUNC_TASK_REASSIGN		8
311
312#define ISCSI_TM_FUNC_VALUE(hdr) ((hdr)->flags & ISCSI_FLAG_TM_FUNC_MASK)
313
314/* SCSI Task Management Response Header */
315struct iscsi_tm_rsp {
316	uint8_t opcode;
317	uint8_t flags;
318	uint8_t response;	/* see Response values below */
319	uint8_t qualifier;
320	uint8_t hlength;
321	uint8_t dlength[3];
322	uint8_t rsvd2[8];
323	itt_t	 itt;	/* Initiator Task Tag */
324	itt_t	 rtt;	/* Reference Task Tag */
325	__be32	statsn;
326	__be32	exp_cmdsn;
327	__be32	max_cmdsn;
328	uint8_t rsvd3[12];
329};
330
331/* Response values */
332#define ISCSI_TMF_RSP_COMPLETE		0x00
333#define ISCSI_TMF_RSP_NO_TASK		0x01
334#define ISCSI_TMF_RSP_NO_LUN		0x02
335#define ISCSI_TMF_RSP_TASK_ALLEGIANT	0x03
336#define ISCSI_TMF_RSP_NO_FAILOVER	0x04
337#define ISCSI_TMF_RSP_NOT_SUPPORTED	0x05
338#define ISCSI_TMF_RSP_AUTH_FAILED	0x06
339#define ISCSI_TMF_RSP_REJECTED		0xff
340
341/* Ready To Transfer Header */
342struct iscsi_r2t_rsp {
343	uint8_t opcode;
344	uint8_t flags;
345	uint8_t rsvd2[2];
346	uint8_t	hlength;
347	uint8_t	dlength[3];
348	struct scsi_lun	lun;
349	itt_t	 itt;	/* Initiator Task Tag */
350	__be32	ttt;	/* Target Transfer Tag */
351	__be32	statsn;
352	__be32	exp_cmdsn;
353	__be32	max_cmdsn;
354	__be32	r2tsn;
355	__be32	data_offset;
356	__be32	data_length;
357};
358
359/* SCSI Data Hdr */
360struct iscsi_data {
361	uint8_t opcode;
362	uint8_t flags;
363	uint8_t rsvd2[2];
364	uint8_t rsvd3;
365	uint8_t dlength[3];
366	struct scsi_lun lun;
367	itt_t	 itt;
368	__be32	ttt;
369	__be32	rsvd4;
370	__be32	exp_statsn;
371	__be32	rsvd5;
372	__be32	datasn;
373	__be32	offset;
374	__be32	rsvd6;
375	/* Payload */
376};
377
378/* SCSI Data Response Hdr */
379struct iscsi_data_rsp {
380	uint8_t opcode;
381	uint8_t flags;
382	uint8_t rsvd2;
383	uint8_t cmd_status;
384	uint8_t hlength;
385	uint8_t dlength[3];
386	struct scsi_lun	lun;
387	itt_t	 itt;
388	__be32	ttt;
389	__be32	statsn;
390	__be32	exp_cmdsn;
391	__be32	max_cmdsn;
392	__be32	datasn;
393	__be32	offset;
394	__be32	residual_count;
395};
396
397/* Data Response PDU flags */
398#define ISCSI_FLAG_DATA_ACK		0x40
399#define ISCSI_FLAG_DATA_OVERFLOW	0x04
400#define ISCSI_FLAG_DATA_UNDERFLOW	0x02
401#define ISCSI_FLAG_DATA_STATUS		0x01
402
403/* Text Header */
404struct iscsi_text {
405	uint8_t opcode;
406	uint8_t flags;
407	uint8_t rsvd2[2];
408	uint8_t hlength;
409	uint8_t dlength[3];
410	uint8_t rsvd4[8];
411	itt_t	 itt;
412	__be32	ttt;
413	__be32	cmdsn;
414	__be32	exp_statsn;
415	uint8_t rsvd5[16];
416	/* Text - key=value pairs */
417};
418
419#define ISCSI_FLAG_TEXT_CONTINUE	0x40
420
421/* Text Response Header */
422struct iscsi_text_rsp {
423	uint8_t opcode;
424	uint8_t flags;
425	uint8_t rsvd2[2];
426	uint8_t hlength;
427	uint8_t dlength[3];
428	uint8_t rsvd4[8];
429	itt_t	 itt;
430	__be32	ttt;
431	__be32	statsn;
432	__be32	exp_cmdsn;
433	__be32	max_cmdsn;
434	uint8_t rsvd5[12];
435	/* Text Response - key:value pairs */
436};
437
438/* Login Header */
439struct iscsi_login_req {
440	uint8_t opcode;
441	uint8_t flags;
442	uint8_t max_version;	/* Max. version supported */
443	uint8_t min_version;	/* Min. version supported */
444	uint8_t hlength;
445	uint8_t dlength[3];
446	uint8_t isid[6];	/* Initiator Session ID */
447	__be16	tsih;	/* Target Session Handle */
448	itt_t	 itt;	/* Initiator Task Tag */
449	__be16	cid;
450	__be16	rsvd3;
451	__be32	cmdsn;
452	__be32	exp_statsn;
453	uint8_t rsvd5[16];
454};
455
456/* Login PDU flags */
457#define ISCSI_FLAG_LOGIN_TRANSIT		0x80
458#define ISCSI_FLAG_LOGIN_CONTINUE		0x40
459#define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK	0x0C	/* 2 bits */
460#define ISCSI_FLAG_LOGIN_CURRENT_STAGE1		0x04
461#define ISCSI_FLAG_LOGIN_CURRENT_STAGE2		0x08
462#define ISCSI_FLAG_LOGIN_CURRENT_STAGE3		0x0C
463#define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK	0x03	/* 2 bits */
464#define ISCSI_FLAG_LOGIN_NEXT_STAGE1		0x01
465#define ISCSI_FLAG_LOGIN_NEXT_STAGE2		0x02
466#define ISCSI_FLAG_LOGIN_NEXT_STAGE3		0x03
467
468#define ISCSI_LOGIN_CURRENT_STAGE(flags) \
469	((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
470#define ISCSI_LOGIN_NEXT_STAGE(flags) \
471	(flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
472
473/* Login Response Header */
474struct iscsi_login_rsp {
475	uint8_t opcode;
476	uint8_t flags;
477	uint8_t max_version;	/* Max. version supported */
478	uint8_t active_version;	/* Active version */
479	uint8_t hlength;
480	uint8_t dlength[3];
481	uint8_t isid[6];	/* Initiator Session ID */
482	__be16	tsih;	/* Target Session Handle */
483	itt_t	 itt;	/* Initiator Task Tag */
484	__be32	rsvd3;
485	__be32	statsn;
486	__be32	exp_cmdsn;
487	__be32	max_cmdsn;
488	uint8_t status_class;	/* see Login RSP ststus classes below */
489	uint8_t status_detail;	/* see Login RSP Status details below */
490	uint8_t rsvd4[10];
491};
492
493/* Login stage (phase) codes for CSG, NSG */
494#define ISCSI_INITIAL_LOGIN_STAGE		-1
495#define ISCSI_SECURITY_NEGOTIATION_STAGE	0
496#define ISCSI_OP_PARMS_NEGOTIATION_STAGE	1
497#define ISCSI_FULL_FEATURE_PHASE		3
498
499/* Login Status response classes */
500#define ISCSI_STATUS_CLS_SUCCESS		0x00
501#define ISCSI_STATUS_CLS_REDIRECT		0x01
502#define ISCSI_STATUS_CLS_INITIATOR_ERR		0x02
503#define ISCSI_STATUS_CLS_TARGET_ERR		0x03
504
505/* Login Status response detail codes */
506/* Class-0 (Success) */
507#define ISCSI_LOGIN_STATUS_ACCEPT		0x00
508
509/* Class-1 (Redirection) */
510#define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP	0x01
511#define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM	0x02
512
513/* Class-2 (Initiator Error) */
514#define ISCSI_LOGIN_STATUS_INIT_ERR		0x00
515#define ISCSI_LOGIN_STATUS_AUTH_FAILED		0x01
516#define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN	0x02
517#define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND	0x03
518#define ISCSI_LOGIN_STATUS_TGT_REMOVED		0x04
519#define ISCSI_LOGIN_STATUS_NO_VERSION		0x05
520#define ISCSI_LOGIN_STATUS_ISID_ERROR		0x06
521#define ISCSI_LOGIN_STATUS_MISSING_FIELDS	0x07
522#define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED	0x08
523#define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE	0x09
524#define ISCSI_LOGIN_STATUS_NO_SESSION		0x0a
525#define ISCSI_LOGIN_STATUS_INVALID_REQUEST	0x0b
526
527/* Class-3 (Target Error) */
528#define ISCSI_LOGIN_STATUS_TARGET_ERROR		0x00
529#define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE	0x01
530#define ISCSI_LOGIN_STATUS_NO_RESOURCES		0x02
531
532/* Logout Header */
533struct iscsi_logout {
534	uint8_t opcode;
535	uint8_t flags;
536	uint8_t rsvd1[2];
537	uint8_t hlength;
538	uint8_t dlength[3];
539	uint8_t rsvd2[8];
540	itt_t	 itt;	/* Initiator Task Tag */
541	__be16	cid;
542	uint8_t rsvd3[2];
543	__be32	cmdsn;
544	__be32	exp_statsn;
545	uint8_t rsvd4[16];
546};
547
548/* Logout PDU flags */
549#define ISCSI_FLAG_LOGOUT_REASON_MASK	0x7F
550
551/* logout reason_code values */
552
553#define ISCSI_LOGOUT_REASON_CLOSE_SESSION	0
554#define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION	1
555#define ISCSI_LOGOUT_REASON_RECOVERY		2
556#define ISCSI_LOGOUT_REASON_AEN_REQUEST		3
557
558/* Logout Response Header */
559struct iscsi_logout_rsp {
560	uint8_t opcode;
561	uint8_t flags;
562	uint8_t response;	/* see Logout response values below */
563	uint8_t rsvd2;
564	uint8_t hlength;
565	uint8_t dlength[3];
566	uint8_t rsvd3[8];
567	itt_t	 itt;	/* Initiator Task Tag */
568	__be32	rsvd4;
569	__be32	statsn;
570	__be32	exp_cmdsn;
571	__be32	max_cmdsn;
572	__be32	rsvd5;
573	__be16	t2wait;
574	__be16	t2retain;
575	__be32	rsvd6;
576};
577
578/* logout response status values */
579
580#define ISCSI_LOGOUT_SUCCESS			0
581#define ISCSI_LOGOUT_CID_NOT_FOUND		1
582#define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED	2
583#define ISCSI_LOGOUT_CLEANUP_FAILED		3
584
585/* SNACK Header */
586struct iscsi_snack {
587	uint8_t opcode;
588	uint8_t flags;
589	uint8_t rsvd2[2];
590	uint8_t hlength;
591	uint8_t dlength[3];
592	uint8_t lun[8];
593	itt_t	 itt;
594	__be32  ttt;
595	uint8_t rsvd3[4];
596	__be32  exp_statsn;
597	uint8_t rsvd4[8];
598	__be32	begrun;
599	__be32	runlength;
600};
601
602/* SNACK PDU flags */
603#define ISCSI_FLAG_SNACK_TYPE_DATA		0
604#define ISCSI_FLAG_SNACK_TYPE_R2T		0
605#define ISCSI_FLAG_SNACK_TYPE_STATUS		1
606#define ISCSI_FLAG_SNACK_TYPE_DATA_ACK		2
607#define ISCSI_FLAG_SNACK_TYPE_RDATA		3
608#define ISCSI_FLAG_SNACK_TYPE_MASK	0x0F	/* 4 bits */
609
610/* Reject Message Header */
611struct iscsi_reject {
612	uint8_t opcode;
613	uint8_t flags;
614	uint8_t reason;
615	uint8_t rsvd2;
616	uint8_t hlength;
617	uint8_t dlength[3];
618	uint8_t rsvd3[8];
619	__be32  ffffffff;
620	uint8_t rsvd4[4];
621	__be32	statsn;
622	__be32	exp_cmdsn;
623	__be32	max_cmdsn;
624	__be32	datasn;
625	uint8_t rsvd5[8];
626	/* Text - Rejected hdr */
627};
628
629/* Reason for Reject */
630#define ISCSI_REASON_CMD_BEFORE_LOGIN	1
631#define ISCSI_REASON_DATA_DIGEST_ERROR	2
632#define ISCSI_REASON_DATA_SNACK_REJECT	3
633#define ISCSI_REASON_PROTOCOL_ERROR	4
634#define ISCSI_REASON_CMD_NOT_SUPPORTED	5
635#define ISCSI_REASON_IMM_CMD_REJECT		6
636#define ISCSI_REASON_TASK_IN_PROGRESS	7
637#define ISCSI_REASON_INVALID_SNACK		8
638#define ISCSI_REASON_BOOKMARK_INVALID	9
639#define ISCSI_REASON_BOOKMARK_NO_RESOURCES	10
640#define ISCSI_REASON_NEGOTIATION_RESET	11
641
642/* Max. number of Key=Value pairs in a text message */
643#define MAX_KEY_VALUE_PAIRS	8192
644
645/* maximum length for text keys/values */
646#define KEY_MAXLEN		64
647#define VALUE_MAXLEN		255
648#define TARGET_NAME_MAXLEN	VALUE_MAXLEN
649
650#define ISCSI_DEF_MAX_RECV_SEG_LEN		8192
651#define ISCSI_MIN_MAX_RECV_SEG_LEN		512
652#define ISCSI_MAX_MAX_RECV_SEG_LEN		16777215
653
654#define ISCSI_DEF_FIRST_BURST_LEN		65536
655#define ISCSI_MIN_FIRST_BURST_LEN		512
656#define ISCSI_MAX_FIRST_BURST_LEN		16777215
657
658#define ISCSI_DEF_MAX_BURST_LEN			262144
659#define ISCSI_MIN_MAX_BURST_LEN			512
660#define ISCSI_MAX_MAX_BURST_LEN			16777215
661
662#define ISCSI_DEF_TIME2WAIT			2
 
 
663
664/************************* RFC 3720 End *****************************/
665
666#endif /* ISCSI_PROTO_H */
v6.2
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 * RFC 3720 (iSCSI) protocol data types
  4 *
  5 * Copyright (C) 2005 Dmitry Yusupov
  6 * Copyright (C) 2005 Alex Aizman
  7 * maintained by open-iscsi@googlegroups.com
 
 
 
 
 
 
 
 
 
 
 
 
  8 */
  9
 10#ifndef ISCSI_PROTO_H
 11#define ISCSI_PROTO_H
 12
 13#include <linux/types.h>
 14#include <scsi/scsi.h>
 15
 16#define ISCSI_DRAFT20_VERSION	0x00
 17
 18/* default iSCSI listen port for incoming connections */
 19#define ISCSI_LISTEN_PORT	3260
 20
 21/* iSCSI header length */
 22#define ISCSI_HDR_LEN		48
 23
 24/* iSCSI CRC32C length */
 25#define ISCSI_CRC_LEN		4
 26
 27/* Padding word length */
 28#define ISCSI_PAD_LEN		4
 29
 30/*
 31 * Serial Number Arithmetic, 32 bits, RFC1982
 32 */
 33
 34static inline int iscsi_sna_lt(u32 n1, u32 n2)
 35{
 36	return (s32)(n1 - n2) < 0;
 37}
 38
 39static inline int iscsi_sna_lte(u32 n1, u32 n2)
 40{
 41	return (s32)(n1 - n2) <= 0;
 42}
 43
 44static inline int iscsi_sna_gt(u32 n1, u32 n2)
 45{
 46	return (s32)(n1 - n2) > 0;
 47}
 48
 49static inline int iscsi_sna_gte(u32 n1, u32 n2)
 50{
 51	return (s32)(n1 - n2) >= 0;
 52}
 53
 54/*
 55 * useful common(control and data paths) macro
 56 */
 57#define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
 58#define hton24(p, v) { \
 59        p[0] = (((v) >> 16) & 0xFF); \
 60        p[1] = (((v) >> 8) & 0xFF); \
 61        p[2] = ((v) & 0xFF); \
 62}
 63#define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
 64
 65/* initiator tags; opaque for target */
 66typedef uint32_t __bitwise itt_t;
 67/* below makes sense only for initiator that created this tag */
 68#define build_itt(itt, age) ((__force itt_t)\
 69	((itt) | ((age) << ISCSI_AGE_SHIFT)))
 70#define get_itt(itt) ((__force uint32_t)(itt_t)(itt) & ISCSI_ITT_MASK)
 71#define RESERVED_ITT ((__force itt_t)0xffffffff)
 72
 73/*
 74 * iSCSI Template Message Header
 75 */
 76struct iscsi_hdr {
 77	uint8_t		opcode;
 78	uint8_t		flags;		/* Final bit */
 79	uint8_t		rsvd2[2];
 80	uint8_t		hlength;	/* AHSs total length */
 81	uint8_t		dlength[3];	/* Data length */
 82	struct scsi_lun	lun;
 83	itt_t		itt;		/* Initiator Task Tag, opaque for target */
 84	__be32		ttt;		/* Target Task Tag */
 85	__be32		statsn;
 86	__be32		exp_statsn;
 87	__be32		max_statsn;
 88	uint8_t		other[12];
 89};
 90
 91/************************* RFC 3720 Begin *****************************/
 92
 93#define ISCSI_RESERVED_TAG		0xffffffff
 94
 95/* Opcode encoding bits */
 96#define ISCSI_OP_RETRY			0x80
 97#define ISCSI_OP_IMMEDIATE		0x40
 98#define ISCSI_OPCODE_MASK		0x3F
 99
100/* Initiator Opcode values */
101#define ISCSI_OP_NOOP_OUT		0x00
102#define ISCSI_OP_SCSI_CMD		0x01
103#define ISCSI_OP_SCSI_TMFUNC		0x02
104#define ISCSI_OP_LOGIN			0x03
105#define ISCSI_OP_TEXT			0x04
106#define ISCSI_OP_SCSI_DATA_OUT		0x05
107#define ISCSI_OP_LOGOUT			0x06
108#define ISCSI_OP_SNACK			0x10
109
110#define ISCSI_OP_VENDOR1_CMD		0x1c
111#define ISCSI_OP_VENDOR2_CMD		0x1d
112#define ISCSI_OP_VENDOR3_CMD		0x1e
113#define ISCSI_OP_VENDOR4_CMD		0x1f
114
115/* Target Opcode values */
116#define ISCSI_OP_NOOP_IN		0x20
117#define ISCSI_OP_SCSI_CMD_RSP		0x21
118#define ISCSI_OP_SCSI_TMFUNC_RSP	0x22
119#define ISCSI_OP_LOGIN_RSP		0x23
120#define ISCSI_OP_TEXT_RSP		0x24
121#define ISCSI_OP_SCSI_DATA_IN		0x25
122#define ISCSI_OP_LOGOUT_RSP		0x26
123#define ISCSI_OP_R2T			0x31
124#define ISCSI_OP_ASYNC_EVENT		0x32
125#define ISCSI_OP_REJECT			0x3f
126
127struct iscsi_ahs_hdr {
128	__be16 ahslength;
129	uint8_t ahstype;
130	uint8_t ahspec[5];
131};
132
133#define ISCSI_AHSTYPE_CDB		1
134#define ISCSI_AHSTYPE_RLENGTH		2
135#define ISCSI_CDB_SIZE			16
136
137/* iSCSI PDU Header */
138struct iscsi_scsi_req {
139	uint8_t opcode;
140	uint8_t flags;
141	__be16 rsvd2;
142	uint8_t hlength;
143	uint8_t dlength[3];
144	struct scsi_lun lun;
145	itt_t	 itt;	/* Initiator Task Tag */
146	__be32 data_length;
147	__be32 cmdsn;
148	__be32 exp_statsn;
149	uint8_t cdb[ISCSI_CDB_SIZE];	/* SCSI Command Block */
150	/* Additional Data (Command Dependent) */
151};
152
153/* Command PDU flags */
154#define ISCSI_FLAG_CMD_FINAL		0x80
155#define ISCSI_FLAG_CMD_READ		0x40
156#define ISCSI_FLAG_CMD_WRITE		0x20
157#define ISCSI_FLAG_CMD_ATTR_MASK	0x07	/* 3 bits */
158
159/* SCSI Command Attribute values */
160#define ISCSI_ATTR_UNTAGGED		0
161#define ISCSI_ATTR_SIMPLE		1
162#define ISCSI_ATTR_ORDERED		2
163#define ISCSI_ATTR_HEAD_OF_QUEUE	3
164#define ISCSI_ATTR_ACA			4
165
166struct iscsi_rlength_ahdr {
167	__be16 ahslength;
168	uint8_t ahstype;
169	uint8_t reserved;
170	__be32 read_length;
171};
172
173/* Extended CDB AHS */
174struct iscsi_ecdb_ahdr {
175	__be16 ahslength;	/* CDB length - 15, including reserved byte */
176	uint8_t ahstype;
177	uint8_t reserved;
178	/* 4-byte aligned extended CDB spillover */
179	uint8_t ecdb[SCSI_MAX_VARLEN_CDB_SIZE - ISCSI_CDB_SIZE];
180};
181
182/* SCSI Response Header */
183struct iscsi_scsi_rsp {
184	uint8_t opcode;
185	uint8_t flags;
186	uint8_t response;
187	uint8_t cmd_status;
188	uint8_t hlength;
189	uint8_t dlength[3];
190	uint8_t rsvd[8];
191	itt_t	 itt;	/* Initiator Task Tag */
192	__be32	rsvd1;
193	__be32	statsn;
194	__be32	exp_cmdsn;
195	__be32	max_cmdsn;
196	__be32	exp_datasn;
197	__be32	bi_residual_count;
198	__be32	residual_count;
199	/* Response or Sense Data (optional) */
200};
201
202/* Command Response PDU flags */
203#define ISCSI_FLAG_CMD_BIDI_OVERFLOW	0x10
204#define ISCSI_FLAG_CMD_BIDI_UNDERFLOW	0x08
205#define ISCSI_FLAG_CMD_OVERFLOW		0x04
206#define ISCSI_FLAG_CMD_UNDERFLOW	0x02
207
208/* iSCSI Status values. Valid if Rsp Selector bit is not set */
209#define ISCSI_STATUS_CMD_COMPLETED	0
210#define ISCSI_STATUS_TARGET_FAILURE	1
211#define ISCSI_STATUS_SUBSYS_FAILURE	2
212
213/* Asynchronous Event Header */
214struct iscsi_async {
215	uint8_t opcode;
216	uint8_t flags;
217	uint8_t rsvd2[2];
218	uint8_t rsvd3;
219	uint8_t dlength[3];
220	struct scsi_lun	lun;
221	uint8_t rsvd4[8];
222	__be32	statsn;
223	__be32	exp_cmdsn;
224	__be32	max_cmdsn;
225	uint8_t async_event;
226	uint8_t async_vcode;
227	__be16	param1;
228	__be16	param2;
229	__be16	param3;
230	uint8_t rsvd5[4];
231};
232
233/* iSCSI Event Codes */
234#define ISCSI_ASYNC_MSG_SCSI_EVENT			0
235#define ISCSI_ASYNC_MSG_REQUEST_LOGOUT			1
236#define ISCSI_ASYNC_MSG_DROPPING_CONNECTION		2
237#define ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS	3
238#define ISCSI_ASYNC_MSG_PARAM_NEGOTIATION		4
239#define ISCSI_ASYNC_MSG_VENDOR_SPECIFIC			255
240
241/* NOP-Out Message */
242struct iscsi_nopout {
243	uint8_t opcode;
244	uint8_t flags;
245	__be16	rsvd2;
246	uint8_t rsvd3;
247	uint8_t dlength[3];
248	struct scsi_lun	lun;
249	itt_t	 itt;	/* Initiator Task Tag */
250	__be32	ttt;	/* Target Transfer Tag */
251	__be32	cmdsn;
252	__be32	exp_statsn;
253	uint8_t rsvd4[16];
254};
255
256/* NOP-In Message */
257struct iscsi_nopin {
258	uint8_t opcode;
259	uint8_t flags;
260	__be16	rsvd2;
261	uint8_t rsvd3;
262	uint8_t dlength[3];
263	struct scsi_lun	lun;
264	itt_t	 itt;	/* Initiator Task Tag */
265	__be32	ttt;	/* Target Transfer Tag */
266	__be32	statsn;
267	__be32	exp_cmdsn;
268	__be32	max_cmdsn;
269	uint8_t rsvd4[12];
270};
271
272/* SCSI Task Management Message Header */
273struct iscsi_tm {
274	uint8_t opcode;
275	uint8_t flags;
276	uint8_t rsvd1[2];
277	uint8_t hlength;
278	uint8_t dlength[3];
279	struct scsi_lun lun;
280	itt_t	 itt;	/* Initiator Task Tag */
281	itt_t	 rtt;	/* Reference Task Tag */
282	__be32	cmdsn;
283	__be32	exp_statsn;
284	__be32	refcmdsn;
285	__be32	exp_datasn;
286	uint8_t rsvd2[8];
287};
288
289#define ISCSI_FLAG_TM_FUNC_MASK			0x7F
290
291/* Function values */
292#define ISCSI_TM_FUNC_ABORT_TASK		1
293#define ISCSI_TM_FUNC_ABORT_TASK_SET		2
294#define ISCSI_TM_FUNC_CLEAR_ACA			3
295#define ISCSI_TM_FUNC_CLEAR_TASK_SET		4
296#define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET	5
297#define ISCSI_TM_FUNC_TARGET_WARM_RESET		6
298#define ISCSI_TM_FUNC_TARGET_COLD_RESET		7
299#define ISCSI_TM_FUNC_TASK_REASSIGN		8
300
301#define ISCSI_TM_FUNC_VALUE(hdr) ((hdr)->flags & ISCSI_FLAG_TM_FUNC_MASK)
302
303/* SCSI Task Management Response Header */
304struct iscsi_tm_rsp {
305	uint8_t opcode;
306	uint8_t flags;
307	uint8_t response;	/* see Response values below */
308	uint8_t qualifier;
309	uint8_t hlength;
310	uint8_t dlength[3];
311	uint8_t rsvd2[8];
312	itt_t	 itt;	/* Initiator Task Tag */
313	itt_t	 rtt;	/* Reference Task Tag */
314	__be32	statsn;
315	__be32	exp_cmdsn;
316	__be32	max_cmdsn;
317	uint8_t rsvd3[12];
318};
319
320/* Response values */
321#define ISCSI_TMF_RSP_COMPLETE		0x00
322#define ISCSI_TMF_RSP_NO_TASK		0x01
323#define ISCSI_TMF_RSP_NO_LUN		0x02
324#define ISCSI_TMF_RSP_TASK_ALLEGIANT	0x03
325#define ISCSI_TMF_RSP_NO_FAILOVER	0x04
326#define ISCSI_TMF_RSP_NOT_SUPPORTED	0x05
327#define ISCSI_TMF_RSP_AUTH_FAILED	0x06
328#define ISCSI_TMF_RSP_REJECTED		0xff
329
330/* Ready To Transfer Header */
331struct iscsi_r2t_rsp {
332	uint8_t opcode;
333	uint8_t flags;
334	uint8_t rsvd2[2];
335	uint8_t	hlength;
336	uint8_t	dlength[3];
337	struct scsi_lun	lun;
338	itt_t	 itt;	/* Initiator Task Tag */
339	__be32	ttt;	/* Target Transfer Tag */
340	__be32	statsn;
341	__be32	exp_cmdsn;
342	__be32	max_cmdsn;
343	__be32	r2tsn;
344	__be32	data_offset;
345	__be32	data_length;
346};
347
348/* SCSI Data Hdr */
349struct iscsi_data {
350	uint8_t opcode;
351	uint8_t flags;
352	uint8_t rsvd2[2];
353	uint8_t rsvd3;
354	uint8_t dlength[3];
355	struct scsi_lun lun;
356	itt_t	 itt;
357	__be32	ttt;
358	__be32	rsvd4;
359	__be32	exp_statsn;
360	__be32	rsvd5;
361	__be32	datasn;
362	__be32	offset;
363	__be32	rsvd6;
364	/* Payload */
365};
366
367/* SCSI Data Response Hdr */
368struct iscsi_data_rsp {
369	uint8_t opcode;
370	uint8_t flags;
371	uint8_t rsvd2;
372	uint8_t cmd_status;
373	uint8_t hlength;
374	uint8_t dlength[3];
375	struct scsi_lun	lun;
376	itt_t	 itt;
377	__be32	ttt;
378	__be32	statsn;
379	__be32	exp_cmdsn;
380	__be32	max_cmdsn;
381	__be32	datasn;
382	__be32	offset;
383	__be32	residual_count;
384};
385
386/* Data Response PDU flags */
387#define ISCSI_FLAG_DATA_ACK		0x40
388#define ISCSI_FLAG_DATA_OVERFLOW	0x04
389#define ISCSI_FLAG_DATA_UNDERFLOW	0x02
390#define ISCSI_FLAG_DATA_STATUS		0x01
391
392/* Text Header */
393struct iscsi_text {
394	uint8_t opcode;
395	uint8_t flags;
396	uint8_t rsvd2[2];
397	uint8_t hlength;
398	uint8_t dlength[3];
399	uint8_t rsvd4[8];
400	itt_t	 itt;
401	__be32	ttt;
402	__be32	cmdsn;
403	__be32	exp_statsn;
404	uint8_t rsvd5[16];
405	/* Text - key=value pairs */
406};
407
408#define ISCSI_FLAG_TEXT_CONTINUE	0x40
409
410/* Text Response Header */
411struct iscsi_text_rsp {
412	uint8_t opcode;
413	uint8_t flags;
414	uint8_t rsvd2[2];
415	uint8_t hlength;
416	uint8_t dlength[3];
417	uint8_t rsvd4[8];
418	itt_t	 itt;
419	__be32	ttt;
420	__be32	statsn;
421	__be32	exp_cmdsn;
422	__be32	max_cmdsn;
423	uint8_t rsvd5[12];
424	/* Text Response - key:value pairs */
425};
426
427/* Login Header */
428struct iscsi_login_req {
429	uint8_t opcode;
430	uint8_t flags;
431	uint8_t max_version;	/* Max. version supported */
432	uint8_t min_version;	/* Min. version supported */
433	uint8_t hlength;
434	uint8_t dlength[3];
435	uint8_t isid[6];	/* Initiator Session ID */
436	__be16	tsih;	/* Target Session Handle */
437	itt_t	 itt;	/* Initiator Task Tag */
438	__be16	cid;
439	__be16	rsvd3;
440	__be32	cmdsn;
441	__be32	exp_statsn;
442	uint8_t rsvd5[16];
443};
444
445/* Login PDU flags */
446#define ISCSI_FLAG_LOGIN_TRANSIT		0x80
447#define ISCSI_FLAG_LOGIN_CONTINUE		0x40
448#define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK	0x0C	/* 2 bits */
449#define ISCSI_FLAG_LOGIN_CURRENT_STAGE1		0x04
450#define ISCSI_FLAG_LOGIN_CURRENT_STAGE2		0x08
451#define ISCSI_FLAG_LOGIN_CURRENT_STAGE3		0x0C
452#define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK	0x03	/* 2 bits */
453#define ISCSI_FLAG_LOGIN_NEXT_STAGE1		0x01
454#define ISCSI_FLAG_LOGIN_NEXT_STAGE2		0x02
455#define ISCSI_FLAG_LOGIN_NEXT_STAGE3		0x03
456
457#define ISCSI_LOGIN_CURRENT_STAGE(flags) \
458	((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
459#define ISCSI_LOGIN_NEXT_STAGE(flags) \
460	(flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
461
462/* Login Response Header */
463struct iscsi_login_rsp {
464	uint8_t opcode;
465	uint8_t flags;
466	uint8_t max_version;	/* Max. version supported */
467	uint8_t active_version;	/* Active version */
468	uint8_t hlength;
469	uint8_t dlength[3];
470	uint8_t isid[6];	/* Initiator Session ID */
471	__be16	tsih;	/* Target Session Handle */
472	itt_t	 itt;	/* Initiator Task Tag */
473	__be32	rsvd3;
474	__be32	statsn;
475	__be32	exp_cmdsn;
476	__be32	max_cmdsn;
477	uint8_t status_class;	/* see Login RSP ststus classes below */
478	uint8_t status_detail;	/* see Login RSP Status details below */
479	uint8_t rsvd4[10];
480};
481
482/* Login stage (phase) codes for CSG, NSG */
483#define ISCSI_INITIAL_LOGIN_STAGE		-1
484#define ISCSI_SECURITY_NEGOTIATION_STAGE	0
485#define ISCSI_OP_PARMS_NEGOTIATION_STAGE	1
486#define ISCSI_FULL_FEATURE_PHASE		3
487
488/* Login Status response classes */
489#define ISCSI_STATUS_CLS_SUCCESS		0x00
490#define ISCSI_STATUS_CLS_REDIRECT		0x01
491#define ISCSI_STATUS_CLS_INITIATOR_ERR		0x02
492#define ISCSI_STATUS_CLS_TARGET_ERR		0x03
493
494/* Login Status response detail codes */
495/* Class-0 (Success) */
496#define ISCSI_LOGIN_STATUS_ACCEPT		0x00
497
498/* Class-1 (Redirection) */
499#define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP	0x01
500#define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM	0x02
501
502/* Class-2 (Initiator Error) */
503#define ISCSI_LOGIN_STATUS_INIT_ERR		0x00
504#define ISCSI_LOGIN_STATUS_AUTH_FAILED		0x01
505#define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN	0x02
506#define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND	0x03
507#define ISCSI_LOGIN_STATUS_TGT_REMOVED		0x04
508#define ISCSI_LOGIN_STATUS_NO_VERSION		0x05
509#define ISCSI_LOGIN_STATUS_ISID_ERROR		0x06
510#define ISCSI_LOGIN_STATUS_MISSING_FIELDS	0x07
511#define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED	0x08
512#define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE	0x09
513#define ISCSI_LOGIN_STATUS_NO_SESSION		0x0a
514#define ISCSI_LOGIN_STATUS_INVALID_REQUEST	0x0b
515
516/* Class-3 (Target Error) */
517#define ISCSI_LOGIN_STATUS_TARGET_ERROR		0x00
518#define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE	0x01
519#define ISCSI_LOGIN_STATUS_NO_RESOURCES		0x02
520
521/* Logout Header */
522struct iscsi_logout {
523	uint8_t opcode;
524	uint8_t flags;
525	uint8_t rsvd1[2];
526	uint8_t hlength;
527	uint8_t dlength[3];
528	uint8_t rsvd2[8];
529	itt_t	 itt;	/* Initiator Task Tag */
530	__be16	cid;
531	uint8_t rsvd3[2];
532	__be32	cmdsn;
533	__be32	exp_statsn;
534	uint8_t rsvd4[16];
535};
536
537/* Logout PDU flags */
538#define ISCSI_FLAG_LOGOUT_REASON_MASK	0x7F
539
540/* logout reason_code values */
541
542#define ISCSI_LOGOUT_REASON_CLOSE_SESSION	0
543#define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION	1
544#define ISCSI_LOGOUT_REASON_RECOVERY		2
545#define ISCSI_LOGOUT_REASON_AEN_REQUEST		3
546
547/* Logout Response Header */
548struct iscsi_logout_rsp {
549	uint8_t opcode;
550	uint8_t flags;
551	uint8_t response;	/* see Logout response values below */
552	uint8_t rsvd2;
553	uint8_t hlength;
554	uint8_t dlength[3];
555	uint8_t rsvd3[8];
556	itt_t	 itt;	/* Initiator Task Tag */
557	__be32	rsvd4;
558	__be32	statsn;
559	__be32	exp_cmdsn;
560	__be32	max_cmdsn;
561	__be32	rsvd5;
562	__be16	t2wait;
563	__be16	t2retain;
564	__be32	rsvd6;
565};
566
567/* logout response status values */
568
569#define ISCSI_LOGOUT_SUCCESS			0
570#define ISCSI_LOGOUT_CID_NOT_FOUND		1
571#define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED	2
572#define ISCSI_LOGOUT_CLEANUP_FAILED		3
573
574/* SNACK Header */
575struct iscsi_snack {
576	uint8_t opcode;
577	uint8_t flags;
578	uint8_t rsvd2[2];
579	uint8_t hlength;
580	uint8_t dlength[3];
581	uint8_t lun[8];
582	itt_t	 itt;
583	__be32  ttt;
584	uint8_t rsvd3[4];
585	__be32  exp_statsn;
586	uint8_t rsvd4[8];
587	__be32	begrun;
588	__be32	runlength;
589};
590
591/* SNACK PDU flags */
592#define ISCSI_FLAG_SNACK_TYPE_DATA		0
593#define ISCSI_FLAG_SNACK_TYPE_R2T		0
594#define ISCSI_FLAG_SNACK_TYPE_STATUS		1
595#define ISCSI_FLAG_SNACK_TYPE_DATA_ACK		2
596#define ISCSI_FLAG_SNACK_TYPE_RDATA		3
597#define ISCSI_FLAG_SNACK_TYPE_MASK	0x0F	/* 4 bits */
598
599/* Reject Message Header */
600struct iscsi_reject {
601	uint8_t opcode;
602	uint8_t flags;
603	uint8_t reason;
604	uint8_t rsvd2;
605	uint8_t hlength;
606	uint8_t dlength[3];
607	uint8_t rsvd3[8];
608	__be32  ffffffff;
609	uint8_t rsvd4[4];
610	__be32	statsn;
611	__be32	exp_cmdsn;
612	__be32	max_cmdsn;
613	__be32	datasn;
614	uint8_t rsvd5[8];
615	/* Text - Rejected hdr */
616};
617
618/* Reason for Reject */
619#define ISCSI_REASON_CMD_BEFORE_LOGIN	1
620#define ISCSI_REASON_DATA_DIGEST_ERROR	2
621#define ISCSI_REASON_DATA_SNACK_REJECT	3
622#define ISCSI_REASON_PROTOCOL_ERROR	4
623#define ISCSI_REASON_CMD_NOT_SUPPORTED	5
624#define ISCSI_REASON_IMM_CMD_REJECT		6
625#define ISCSI_REASON_TASK_IN_PROGRESS	7
626#define ISCSI_REASON_INVALID_SNACK		8
627#define ISCSI_REASON_BOOKMARK_INVALID	9
628#define ISCSI_REASON_BOOKMARK_NO_RESOURCES	10
629#define ISCSI_REASON_NEGOTIATION_RESET	11
630
631/* Max. number of Key=Value pairs in a text message */
632#define MAX_KEY_VALUE_PAIRS	8192
633
634/* maximum length for text keys/values */
635#define KEY_MAXLEN		64
636#define VALUE_MAXLEN		255
637#define TARGET_NAME_MAXLEN	VALUE_MAXLEN
638
639#define ISCSI_DEF_MAX_RECV_SEG_LEN		8192
640#define ISCSI_MIN_MAX_RECV_SEG_LEN		512
641#define ISCSI_MAX_MAX_RECV_SEG_LEN		16777215
642
643#define ISCSI_DEF_FIRST_BURST_LEN		65536
644#define ISCSI_MIN_FIRST_BURST_LEN		512
645#define ISCSI_MAX_FIRST_BURST_LEN		16777215
646
647#define ISCSI_DEF_MAX_BURST_LEN			262144
648#define ISCSI_MIN_MAX_BURST_LEN			512
649#define ISCSI_MAX_MAX_BURST_LEN			16777215
650
651#define ISCSI_DEF_TIME2WAIT			2
652
653#define ISCSI_NAME_LEN				224
654
655/************************* RFC 3720 End *****************************/
656
657#endif /* ISCSI_PROTO_H */