Blame view

include/scsi/iscsi_proto.h 16 KB
39e84790d   Alex Aizman   [SCSI] open-iscsi...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  /*
   * RFC 3720 (iSCSI) protocol data types
   *
   * Copyright (C) 2005 Dmitry Yusupov
   * Copyright (C) 2005 Alex Aizman
   * maintained by open-iscsi@googlegroups.com
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published
   * by the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful, but
   * WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * General Public License for more details.
   *
   * See the file COPYING included with this distribution for more details.
   */
  
  #ifndef ISCSI_PROTO_H
  #define ISCSI_PROTO_H
269747890   Mike Christie   [SCSI] libiscsi: ...
23
  #include <linux/types.h>
30e9ba9f2   Boaz Harrosh   [SCSI] iscsi_tcp:...
24
  #include <scsi/scsi.h>
269747890   Mike Christie   [SCSI] libiscsi: ...
25

39e84790d   Alex Aizman   [SCSI] open-iscsi...
26
27
28
29
  #define ISCSI_DRAFT20_VERSION	0x00
  
  /* default iSCSI listen port for incoming connections */
  #define ISCSI_LISTEN_PORT	3260
8304bbcee   Nicholas Bellinger   iscsi: Add Serial...
30
31
32
33
34
  /* iSCSI header length */
  #define ISCSI_HDR_LEN		48
  
  /* iSCSI CRC32C length */
  #define ISCSI_CRC_LEN		4
39e84790d   Alex Aizman   [SCSI] open-iscsi...
35
  /* Padding word length */
004d6530f   Boaz Harrosh   [SCSI] iscsi_tcp,...
36
  #define ISCSI_PAD_LEN		4
39e84790d   Alex Aizman   [SCSI] open-iscsi...
37
38
  
  /*
8304bbcee   Nicholas Bellinger   iscsi: Add Serial...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
   * Serial Number Arithmetic, 32 bits, RFC1982
   */
  
  static inline int iscsi_sna_lt(u32 n1, u32 n2)
  {
  	return (s32)(n1 - n2) < 0;
  }
  
  static inline int iscsi_sna_lte(u32 n1, u32 n2)
  {
  	return (s32)(n1 - n2) <= 0;
  }
  
  static inline int iscsi_sna_gt(u32 n1, u32 n2)
  {
  	return (s32)(n1 - n2) > 0;
  }
  
  static inline int iscsi_sna_gte(u32 n1, u32 n2)
  {
  	return (s32)(n1 - n2) >= 0;
  }
  
  /*
39e84790d   Alex Aizman   [SCSI] open-iscsi...
63
64
65
66
67
68
69
70
71
   * useful common(control and data pathes) macro
   */
  #define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
  #define hton24(p, v) { \
          p[0] = (((v) >> 16) & 0xFF); \
          p[1] = (((v) >> 8) & 0xFF); \
          p[2] = ((v) & 0xFF); \
  }
  #define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
b43773564   Al Viro   [PATCH] iscsi end...
72
73
74
  /* initiator tags; opaque for target */
  typedef uint32_t __bitwise__ itt_t;
  /* below makes sense only for initiator that created this tag */
8b1d03434   Mike Christie   [SCSI] libiscsi: ...
75
76
  #define build_itt(itt, age) ((__force itt_t)\
  	((itt) | ((age) << ISCSI_AGE_SHIFT)))
b43773564   Al Viro   [PATCH] iscsi end...
77
78
  #define get_itt(itt) ((__force uint32_t)(itt_t)(itt) & ISCSI_ITT_MASK)
  #define RESERVED_ITT ((__force itt_t)0xffffffff)
39e84790d   Alex Aizman   [SCSI] open-iscsi...
79
80
81
82
83
84
85
86
87
  /*
   * iSCSI Template Message Header
   */
  struct iscsi_hdr {
  	uint8_t		opcode;
  	uint8_t		flags;		/* Final bit */
  	uint8_t		rsvd2[2];
  	uint8_t		hlength;	/* AHSs total length */
  	uint8_t		dlength[3];	/* Data length */
55bdabdf4   Andy Grover   iscsi: Use struct...
88
  	struct scsi_lun	lun;
b43773564   Al Viro   [PATCH] iscsi end...
89
  	itt_t		itt;		/* Initiator Task Tag, opaque for target */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
90
91
92
  	__be32		ttt;		/* Target Task Tag */
  	__be32		statsn;
  	__be32		exp_statsn;
baebc497b   Mike Christie   [SCSI] iscsi: upd...
93
94
  	__be32		max_statsn;
  	uint8_t		other[12];
39e84790d   Alex Aizman   [SCSI] open-iscsi...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  };
  
  /************************* RFC 3720 Begin *****************************/
  
  #define ISCSI_RESERVED_TAG		0xffffffff
  
  /* Opcode encoding bits */
  #define ISCSI_OP_RETRY			0x80
  #define ISCSI_OP_IMMEDIATE		0x40
  #define ISCSI_OPCODE_MASK		0x3F
  
  /* Initiator Opcode values */
  #define ISCSI_OP_NOOP_OUT		0x00
  #define ISCSI_OP_SCSI_CMD		0x01
  #define ISCSI_OP_SCSI_TMFUNC		0x02
  #define ISCSI_OP_LOGIN			0x03
  #define ISCSI_OP_TEXT			0x04
  #define ISCSI_OP_SCSI_DATA_OUT		0x05
  #define ISCSI_OP_LOGOUT			0x06
  #define ISCSI_OP_SNACK			0x10
baebc497b   Mike Christie   [SCSI] iscsi: upd...
115
116
117
118
  #define ISCSI_OP_VENDOR1_CMD		0x1c
  #define ISCSI_OP_VENDOR2_CMD		0x1d
  #define ISCSI_OP_VENDOR3_CMD		0x1e
  #define ISCSI_OP_VENDOR4_CMD		0x1f
39e84790d   Alex Aizman   [SCSI] open-iscsi...
119
120
121
122
123
124
125
126
127
128
129
  /* Target Opcode values */
  #define ISCSI_OP_NOOP_IN		0x20
  #define ISCSI_OP_SCSI_CMD_RSP		0x21
  #define ISCSI_OP_SCSI_TMFUNC_RSP	0x22
  #define ISCSI_OP_LOGIN_RSP		0x23
  #define ISCSI_OP_TEXT_RSP		0x24
  #define ISCSI_OP_SCSI_DATA_IN		0x25
  #define ISCSI_OP_LOGOUT_RSP		0x26
  #define ISCSI_OP_R2T			0x31
  #define ISCSI_OP_ASYNC_EVENT		0x32
  #define ISCSI_OP_REJECT			0x3f
baebc497b   Mike Christie   [SCSI] iscsi: upd...
130
131
132
133
134
135
136
137
  struct iscsi_ahs_hdr {
  	__be16 ahslength;
  	uint8_t ahstype;
  	uint8_t ahspec[5];
  };
  
  #define ISCSI_AHSTYPE_CDB		1
  #define ISCSI_AHSTYPE_RLENGTH		2
38d1c069d   Boaz Harrosh   [SCSI] iscsi: ext...
138
  #define ISCSI_CDB_SIZE			16
baebc497b   Mike Christie   [SCSI] iscsi: upd...
139

39e84790d   Alex Aizman   [SCSI] open-iscsi...
140
  /* iSCSI PDU Header */
123521830   Nicholas Bellinger   iscsi: Resolve is...
141
  struct iscsi_scsi_req {
39e84790d   Alex Aizman   [SCSI] open-iscsi...
142
143
  	uint8_t opcode;
  	uint8_t flags;
baebc497b   Mike Christie   [SCSI] iscsi: upd...
144
  	__be16 rsvd2;
39e84790d   Alex Aizman   [SCSI] open-iscsi...
145
146
  	uint8_t hlength;
  	uint8_t dlength[3];
55bdabdf4   Andy Grover   iscsi: Use struct...
147
  	struct scsi_lun lun;
b43773564   Al Viro   [PATCH] iscsi end...
148
  	itt_t	 itt;	/* Initiator Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
149
150
151
  	__be32 data_length;
  	__be32 cmdsn;
  	__be32 exp_statsn;
38d1c069d   Boaz Harrosh   [SCSI] iscsi: ext...
152
  	uint8_t cdb[ISCSI_CDB_SIZE];	/* SCSI Command Block */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
  	/* Additional Data (Command Dependent) */
  };
  
  /* Command PDU flags */
  #define ISCSI_FLAG_CMD_FINAL		0x80
  #define ISCSI_FLAG_CMD_READ		0x40
  #define ISCSI_FLAG_CMD_WRITE		0x20
  #define ISCSI_FLAG_CMD_ATTR_MASK	0x07	/* 3 bits */
  
  /* SCSI Command Attribute values */
  #define ISCSI_ATTR_UNTAGGED		0
  #define ISCSI_ATTR_SIMPLE		1
  #define ISCSI_ATTR_ORDERED		2
  #define ISCSI_ATTR_HEAD_OF_QUEUE	3
  #define ISCSI_ATTR_ACA			4
baebc497b   Mike Christie   [SCSI] iscsi: upd...
168
169
170
171
172
173
  struct iscsi_rlength_ahdr {
  	__be16 ahslength;
  	uint8_t ahstype;
  	uint8_t reserved;
  	__be32 read_length;
  };
004d6530f   Boaz Harrosh   [SCSI] iscsi_tcp,...
174
175
176
177
178
  /* Extended CDB AHS */
  struct iscsi_ecdb_ahdr {
  	__be16 ahslength;	/* CDB length - 15, including reserved byte */
  	uint8_t ahstype;
  	uint8_t reserved;
38d1c069d   Boaz Harrosh   [SCSI] iscsi: ext...
179
  	/* 4-byte aligned extended CDB spillover */
30e9ba9f2   Boaz Harrosh   [SCSI] iscsi_tcp:...
180
  	uint8_t ecdb[SCSI_MAX_VARLEN_CDB_SIZE - ISCSI_CDB_SIZE];
004d6530f   Boaz Harrosh   [SCSI] iscsi_tcp,...
181
  };
39e84790d   Alex Aizman   [SCSI] open-iscsi...
182
  /* SCSI Response Header */
123521830   Nicholas Bellinger   iscsi: Resolve is...
183
  struct iscsi_scsi_rsp {
39e84790d   Alex Aizman   [SCSI] open-iscsi...
184
185
186
187
188
189
190
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t response;
  	uint8_t cmd_status;
  	uint8_t hlength;
  	uint8_t dlength[3];
  	uint8_t rsvd[8];
b43773564   Al Viro   [PATCH] iscsi end...
191
  	itt_t	 itt;	/* Initiator Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  	__be32	rsvd1;
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	__be32	exp_datasn;
  	__be32	bi_residual_count;
  	__be32	residual_count;
  	/* Response or Sense Data (optional) */
  };
  
  /* Command Response PDU flags */
  #define ISCSI_FLAG_CMD_BIDI_OVERFLOW	0x10
  #define ISCSI_FLAG_CMD_BIDI_UNDERFLOW	0x08
  #define ISCSI_FLAG_CMD_OVERFLOW		0x04
  #define ISCSI_FLAG_CMD_UNDERFLOW	0x02
  
  /* iSCSI Status values. Valid if Rsp Selector bit is not set */
  #define ISCSI_STATUS_CMD_COMPLETED	0
  #define ISCSI_STATUS_TARGET_FAILURE	1
  #define ISCSI_STATUS_SUBSYS_FAILURE	2
  
  /* Asynchronous Event Header */
  struct iscsi_async {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t rsvd2[2];
  	uint8_t rsvd3;
  	uint8_t dlength[3];
55bdabdf4   Andy Grover   iscsi: Use struct...
220
  	struct scsi_lun	lun;
39e84790d   Alex Aizman   [SCSI] open-iscsi...
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
  	uint8_t rsvd4[8];
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	uint8_t async_event;
  	uint8_t async_vcode;
  	__be16	param1;
  	__be16	param2;
  	__be16	param3;
  	uint8_t rsvd5[4];
  };
  
  /* iSCSI Event Codes */
  #define ISCSI_ASYNC_MSG_SCSI_EVENT			0
  #define ISCSI_ASYNC_MSG_REQUEST_LOGOUT			1
  #define ISCSI_ASYNC_MSG_DROPPING_CONNECTION		2
  #define ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS	3
  #define ISCSI_ASYNC_MSG_PARAM_NEGOTIATION		4
  #define ISCSI_ASYNC_MSG_VENDOR_SPECIFIC			255
  
  /* NOP-Out Message */
  struct iscsi_nopout {
  	uint8_t opcode;
  	uint8_t flags;
  	__be16	rsvd2;
  	uint8_t rsvd3;
  	uint8_t dlength[3];
55bdabdf4   Andy Grover   iscsi: Use struct...
248
  	struct scsi_lun	lun;
b43773564   Al Viro   [PATCH] iscsi end...
249
  	itt_t	 itt;	/* Initiator Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
250
251
252
253
254
255
256
257
258
259
260
261
262
  	__be32	ttt;	/* Target Transfer Tag */
  	__be32	cmdsn;
  	__be32	exp_statsn;
  	uint8_t rsvd4[16];
  };
  
  /* NOP-In Message */
  struct iscsi_nopin {
  	uint8_t opcode;
  	uint8_t flags;
  	__be16	rsvd2;
  	uint8_t rsvd3;
  	uint8_t dlength[3];
55bdabdf4   Andy Grover   iscsi: Use struct...
263
  	struct scsi_lun	lun;
b43773564   Al Viro   [PATCH] iscsi end...
264
  	itt_t	 itt;	/* Initiator Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
  	__be32	ttt;	/* Target Transfer Tag */
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	uint8_t rsvd4[12];
  };
  
  /* SCSI Task Management Message Header */
  struct iscsi_tm {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t rsvd1[2];
  	uint8_t hlength;
  	uint8_t dlength[3];
55bdabdf4   Andy Grover   iscsi: Use struct...
279
  	struct scsi_lun lun;
b43773564   Al Viro   [PATCH] iscsi end...
280
281
  	itt_t	 itt;	/* Initiator Task Tag */
  	itt_t	 rtt;	/* Reference Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
282
283
284
285
286
287
  	__be32	cmdsn;
  	__be32	exp_statsn;
  	__be32	refcmdsn;
  	__be32	exp_datasn;
  	uint8_t rsvd2[8];
  };
baebc497b   Mike Christie   [SCSI] iscsi: upd...
288
  #define ISCSI_FLAG_TM_FUNC_MASK			0x7F
39e84790d   Alex Aizman   [SCSI] open-iscsi...
289
290
291
292
293
294
295
296
297
298
  
  /* Function values */
  #define ISCSI_TM_FUNC_ABORT_TASK		1
  #define ISCSI_TM_FUNC_ABORT_TASK_SET		2
  #define ISCSI_TM_FUNC_CLEAR_ACA			3
  #define ISCSI_TM_FUNC_CLEAR_TASK_SET		4
  #define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET	5
  #define ISCSI_TM_FUNC_TARGET_WARM_RESET		6
  #define ISCSI_TM_FUNC_TARGET_COLD_RESET		7
  #define ISCSI_TM_FUNC_TASK_REASSIGN		8
5d12c05e2   Mike Christie   [SCSI] libiscsi: ...
299
  #define ISCSI_TM_FUNC_VALUE(hdr) ((hdr)->flags & ISCSI_FLAG_TM_FUNC_MASK)
39e84790d   Alex Aizman   [SCSI] open-iscsi...
300
301
302
303
304
305
306
307
308
  /* SCSI Task Management Response Header */
  struct iscsi_tm_rsp {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t response;	/* see Response values below */
  	uint8_t qualifier;
  	uint8_t hlength;
  	uint8_t dlength[3];
  	uint8_t rsvd2[8];
b43773564   Al Viro   [PATCH] iscsi end...
309
310
  	itt_t	 itt;	/* Initiator Task Tag */
  	itt_t	 rtt;	/* Reference Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
311
312
313
314
315
316
317
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	uint8_t rsvd3[12];
  };
  
  /* Response values */
baebc497b   Mike Christie   [SCSI] iscsi: upd...
318
319
320
321
322
323
324
325
  #define ISCSI_TMF_RSP_COMPLETE		0x00
  #define ISCSI_TMF_RSP_NO_TASK		0x01
  #define ISCSI_TMF_RSP_NO_LUN		0x02
  #define ISCSI_TMF_RSP_TASK_ALLEGIANT	0x03
  #define ISCSI_TMF_RSP_NO_FAILOVER	0x04
  #define ISCSI_TMF_RSP_NOT_SUPPORTED	0x05
  #define ISCSI_TMF_RSP_AUTH_FAILED	0x06
  #define ISCSI_TMF_RSP_REJECTED		0xff
39e84790d   Alex Aizman   [SCSI] open-iscsi...
326
327
328
329
330
331
332
333
  
  /* Ready To Transfer Header */
  struct iscsi_r2t_rsp {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t rsvd2[2];
  	uint8_t	hlength;
  	uint8_t	dlength[3];
55bdabdf4   Andy Grover   iscsi: Use struct...
334
  	struct scsi_lun	lun;
b43773564   Al Viro   [PATCH] iscsi end...
335
  	itt_t	 itt;	/* Initiator Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
  	__be32	ttt;	/* Target Transfer Tag */
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	__be32	r2tsn;
  	__be32	data_offset;
  	__be32	data_length;
  };
  
  /* SCSI Data Hdr */
  struct iscsi_data {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t rsvd2[2];
  	uint8_t rsvd3;
  	uint8_t dlength[3];
55bdabdf4   Andy Grover   iscsi: Use struct...
352
  	struct scsi_lun lun;
b43773564   Al Viro   [PATCH] iscsi end...
353
  	itt_t	 itt;
39e84790d   Alex Aizman   [SCSI] open-iscsi...
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
  	__be32	ttt;
  	__be32	rsvd4;
  	__be32	exp_statsn;
  	__be32	rsvd5;
  	__be32	datasn;
  	__be32	offset;
  	__be32	rsvd6;
  	/* Payload */
  };
  
  /* SCSI Data Response Hdr */
  struct iscsi_data_rsp {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t rsvd2;
  	uint8_t cmd_status;
  	uint8_t hlength;
  	uint8_t dlength[3];
55bdabdf4   Andy Grover   iscsi: Use struct...
372
  	struct scsi_lun	lun;
b43773564   Al Viro   [PATCH] iscsi end...
373
  	itt_t	 itt;
39e84790d   Alex Aizman   [SCSI] open-iscsi...
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
  	__be32	ttt;
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	__be32	datasn;
  	__be32	offset;
  	__be32	residual_count;
  };
  
  /* Data Response PDU flags */
  #define ISCSI_FLAG_DATA_ACK		0x40
  #define ISCSI_FLAG_DATA_OVERFLOW	0x04
  #define ISCSI_FLAG_DATA_UNDERFLOW	0x02
  #define ISCSI_FLAG_DATA_STATUS		0x01
  
  /* Text Header */
  struct iscsi_text {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t rsvd2[2];
  	uint8_t hlength;
  	uint8_t dlength[3];
  	uint8_t rsvd4[8];
b43773564   Al Viro   [PATCH] iscsi end...
397
  	itt_t	 itt;
39e84790d   Alex Aizman   [SCSI] open-iscsi...
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
  	__be32	ttt;
  	__be32	cmdsn;
  	__be32	exp_statsn;
  	uint8_t rsvd5[16];
  	/* Text - key=value pairs */
  };
  
  #define ISCSI_FLAG_TEXT_CONTINUE	0x40
  
  /* Text Response Header */
  struct iscsi_text_rsp {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t rsvd2[2];
  	uint8_t hlength;
  	uint8_t dlength[3];
  	uint8_t rsvd4[8];
b43773564   Al Viro   [PATCH] iscsi end...
415
  	itt_t	 itt;
39e84790d   Alex Aizman   [SCSI] open-iscsi...
416
417
418
419
420
421
422
423
424
  	__be32	ttt;
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	uint8_t rsvd5[12];
  	/* Text Response - key:value pairs */
  };
  
  /* Login Header */
123521830   Nicholas Bellinger   iscsi: Resolve is...
425
  struct iscsi_login_req {
39e84790d   Alex Aizman   [SCSI] open-iscsi...
426
427
428
429
430
431
432
433
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t max_version;	/* Max. version supported */
  	uint8_t min_version;	/* Min. version supported */
  	uint8_t hlength;
  	uint8_t dlength[3];
  	uint8_t isid[6];	/* Initiator Session ID */
  	__be16	tsih;	/* Target Session Handle */
b43773564   Al Viro   [PATCH] iscsi end...
434
  	itt_t	 itt;	/* Initiator Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
435
436
437
438
439
440
441
442
443
444
445
  	__be16	cid;
  	__be16	rsvd3;
  	__be32	cmdsn;
  	__be32	exp_statsn;
  	uint8_t rsvd5[16];
  };
  
  /* Login PDU flags */
  #define ISCSI_FLAG_LOGIN_TRANSIT		0x80
  #define ISCSI_FLAG_LOGIN_CONTINUE		0x40
  #define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK	0x0C	/* 2 bits */
123521830   Nicholas Bellinger   iscsi: Resolve is...
446
447
448
  #define ISCSI_FLAG_LOGIN_CURRENT_STAGE1		0x04
  #define ISCSI_FLAG_LOGIN_CURRENT_STAGE2		0x08
  #define ISCSI_FLAG_LOGIN_CURRENT_STAGE3		0x0C
39e84790d   Alex Aizman   [SCSI] open-iscsi...
449
  #define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK	0x03	/* 2 bits */
123521830   Nicholas Bellinger   iscsi: Resolve is...
450
451
452
  #define ISCSI_FLAG_LOGIN_NEXT_STAGE1		0x01
  #define ISCSI_FLAG_LOGIN_NEXT_STAGE2		0x02
  #define ISCSI_FLAG_LOGIN_NEXT_STAGE3		0x03
39e84790d   Alex Aizman   [SCSI] open-iscsi...
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
  
  #define ISCSI_LOGIN_CURRENT_STAGE(flags) \
  	((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
  #define ISCSI_LOGIN_NEXT_STAGE(flags) \
  	(flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
  
  /* Login Response Header */
  struct iscsi_login_rsp {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t max_version;	/* Max. version supported */
  	uint8_t active_version;	/* Active version */
  	uint8_t hlength;
  	uint8_t dlength[3];
  	uint8_t isid[6];	/* Initiator Session ID */
  	__be16	tsih;	/* Target Session Handle */
b43773564   Al Viro   [PATCH] iscsi end...
469
  	itt_t	 itt;	/* Initiator Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
  	__be32	rsvd3;
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	uint8_t status_class;	/* see Login RSP ststus classes below */
  	uint8_t status_detail;	/* see Login RSP Status details below */
  	uint8_t rsvd4[10];
  };
  
  /* Login stage (phase) codes for CSG, NSG */
  #define ISCSI_INITIAL_LOGIN_STAGE		-1
  #define ISCSI_SECURITY_NEGOTIATION_STAGE	0
  #define ISCSI_OP_PARMS_NEGOTIATION_STAGE	1
  #define ISCSI_FULL_FEATURE_PHASE		3
  
  /* Login Status response classes */
  #define ISCSI_STATUS_CLS_SUCCESS		0x00
  #define ISCSI_STATUS_CLS_REDIRECT		0x01
  #define ISCSI_STATUS_CLS_INITIATOR_ERR		0x02
  #define ISCSI_STATUS_CLS_TARGET_ERR		0x03
  
  /* Login Status response detail codes */
  /* Class-0 (Success) */
  #define ISCSI_LOGIN_STATUS_ACCEPT		0x00
  
  /* Class-1 (Redirection) */
  #define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP	0x01
  #define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM	0x02
  
  /* Class-2 (Initiator Error) */
  #define ISCSI_LOGIN_STATUS_INIT_ERR		0x00
  #define ISCSI_LOGIN_STATUS_AUTH_FAILED		0x01
  #define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN	0x02
  #define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND	0x03
  #define ISCSI_LOGIN_STATUS_TGT_REMOVED		0x04
  #define ISCSI_LOGIN_STATUS_NO_VERSION		0x05
  #define ISCSI_LOGIN_STATUS_ISID_ERROR		0x06
  #define ISCSI_LOGIN_STATUS_MISSING_FIELDS	0x07
  #define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED	0x08
  #define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE	0x09
  #define ISCSI_LOGIN_STATUS_NO_SESSION		0x0a
  #define ISCSI_LOGIN_STATUS_INVALID_REQUEST	0x0b
  
  /* Class-3 (Target Error) */
  #define ISCSI_LOGIN_STATUS_TARGET_ERROR		0x00
  #define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE	0x01
  #define ISCSI_LOGIN_STATUS_NO_RESOURCES		0x02
  
  /* Logout Header */
  struct iscsi_logout {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t rsvd1[2];
  	uint8_t hlength;
  	uint8_t dlength[3];
  	uint8_t rsvd2[8];
b43773564   Al Viro   [PATCH] iscsi end...
526
  	itt_t	 itt;	/* Initiator Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
  	__be16	cid;
  	uint8_t rsvd3[2];
  	__be32	cmdsn;
  	__be32	exp_statsn;
  	uint8_t rsvd4[16];
  };
  
  /* Logout PDU flags */
  #define ISCSI_FLAG_LOGOUT_REASON_MASK	0x7F
  
  /* logout reason_code values */
  
  #define ISCSI_LOGOUT_REASON_CLOSE_SESSION	0
  #define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION	1
  #define ISCSI_LOGOUT_REASON_RECOVERY		2
  #define ISCSI_LOGOUT_REASON_AEN_REQUEST		3
  
  /* Logout Response Header */
  struct iscsi_logout_rsp {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t response;	/* see Logout response values below */
  	uint8_t rsvd2;
  	uint8_t hlength;
  	uint8_t dlength[3];
  	uint8_t rsvd3[8];
b43773564   Al Viro   [PATCH] iscsi end...
553
  	itt_t	 itt;	/* Initiator Task Tag */
39e84790d   Alex Aizman   [SCSI] open-iscsi...
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
  	__be32	rsvd4;
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	__be32	rsvd5;
  	__be16	t2wait;
  	__be16	t2retain;
  	__be32	rsvd6;
  };
  
  /* logout response status values */
  
  #define ISCSI_LOGOUT_SUCCESS			0
  #define ISCSI_LOGOUT_CID_NOT_FOUND		1
  #define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED	2
  #define ISCSI_LOGOUT_CLEANUP_FAILED		3
  
  /* SNACK Header */
  struct iscsi_snack {
  	uint8_t opcode;
  	uint8_t flags;
123521830   Nicholas Bellinger   iscsi: Resolve is...
575
576
577
578
  	uint8_t rsvd2[2];
  	uint8_t hlength;
  	uint8_t dlength[3];
  	uint8_t lun[8];
b43773564   Al Viro   [PATCH] iscsi end...
579
  	itt_t	 itt;
123521830   Nicholas Bellinger   iscsi: Resolve is...
580
581
582
583
  	__be32  ttt;
  	uint8_t rsvd3[4];
  	__be32  exp_statsn;
  	uint8_t rsvd4[8];
39e84790d   Alex Aizman   [SCSI] open-iscsi...
584
585
  	__be32	begrun;
  	__be32	runlength;
39e84790d   Alex Aizman   [SCSI] open-iscsi...
586
587
588
  };
  
  /* SNACK PDU flags */
123521830   Nicholas Bellinger   iscsi: Resolve is...
589
590
591
592
593
  #define ISCSI_FLAG_SNACK_TYPE_DATA		0
  #define ISCSI_FLAG_SNACK_TYPE_R2T		0
  #define ISCSI_FLAG_SNACK_TYPE_STATUS		1
  #define ISCSI_FLAG_SNACK_TYPE_DATA_ACK		2
  #define ISCSI_FLAG_SNACK_TYPE_RDATA		3
39e84790d   Alex Aizman   [SCSI] open-iscsi...
594
595
596
597
598
599
600
601
  #define ISCSI_FLAG_SNACK_TYPE_MASK	0x0F	/* 4 bits */
  
  /* Reject Message Header */
  struct iscsi_reject {
  	uint8_t opcode;
  	uint8_t flags;
  	uint8_t reason;
  	uint8_t rsvd2;
fa0a6957a   Mike Christie   [SCSI] iscsi: ren...
602
  	uint8_t hlength;
39e84790d   Alex Aizman   [SCSI] open-iscsi...
603
  	uint8_t dlength[3];
fa0a6957a   Mike Christie   [SCSI] iscsi: ren...
604
605
606
  	uint8_t rsvd3[8];
  	__be32  ffffffff;
  	uint8_t rsvd4[4];
39e84790d   Alex Aizman   [SCSI] open-iscsi...
607
608
609
610
611
612
613
614
615
  	__be32	statsn;
  	__be32	exp_cmdsn;
  	__be32	max_cmdsn;
  	__be32	datasn;
  	uint8_t rsvd5[8];
  	/* Text - Rejected hdr */
  };
  
  /* Reason for Reject */
fa0a6957a   Mike Christie   [SCSI] iscsi: ren...
616
617
618
619
620
621
622
623
624
625
626
  #define ISCSI_REASON_CMD_BEFORE_LOGIN	1
  #define ISCSI_REASON_DATA_DIGEST_ERROR	2
  #define ISCSI_REASON_DATA_SNACK_REJECT	3
  #define ISCSI_REASON_PROTOCOL_ERROR	4
  #define ISCSI_REASON_CMD_NOT_SUPPORTED	5
  #define ISCSI_REASON_IMM_CMD_REJECT		6
  #define ISCSI_REASON_TASK_IN_PROGRESS	7
  #define ISCSI_REASON_INVALID_SNACK		8
  #define ISCSI_REASON_BOOKMARK_INVALID	9
  #define ISCSI_REASON_BOOKMARK_NO_RESOURCES	10
  #define ISCSI_REASON_NEGOTIATION_RESET	11
39e84790d   Alex Aizman   [SCSI] open-iscsi...
627
628
629
630
631
632
633
634
  
  /* Max. number of Key=Value pairs in a text message */
  #define MAX_KEY_VALUE_PAIRS	8192
  
  /* maximum length for text keys/values */
  #define KEY_MAXLEN		64
  #define VALUE_MAXLEN		255
  #define TARGET_NAME_MAXLEN	VALUE_MAXLEN
bf32ed33e   Mike Christie   [SCSI] iscsi: ren...
635
636
637
638
639
640
641
642
643
644
645
  #define ISCSI_DEF_MAX_RECV_SEG_LEN		8192
  #define ISCSI_MIN_MAX_RECV_SEG_LEN		512
  #define ISCSI_MAX_MAX_RECV_SEG_LEN		16777215
  
  #define ISCSI_DEF_FIRST_BURST_LEN		65536
  #define ISCSI_MIN_FIRST_BURST_LEN		512
  #define ISCSI_MAX_FIRST_BURST_LEN		16777215
  
  #define ISCSI_DEF_MAX_BURST_LEN			262144
  #define ISCSI_MIN_MAX_BURST_LEN			512
  #define ISCSI_MAX_MAX_BURST_LEN			16777215
39e84790d   Alex Aizman   [SCSI] open-iscsi...
646

843c0a8a7   Mike Christie   [SCSI] libiscsi, ...
647
  #define ISCSI_DEF_TIME2WAIT			2
39e84790d   Alex Aizman   [SCSI] open-iscsi...
648
649
650
  /************************* RFC 3720 End *****************************/
  
  #endif /* ISCSI_PROTO_H */