[SCSI] iscsi: add newline to sysfs output
[deliverable/linux.git] / include / scsi / iscsi_proto.h
CommitLineData
39e84790
AA
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#define ISCSI_VERSION_STR "0.3"
25#define ISCSI_DATE_STR "22-Apr-2005"
26#define ISCSI_DRAFT20_VERSION 0x00
27
28/* default iSCSI listen port for incoming connections */
29#define ISCSI_LISTEN_PORT 3260
30
31/* Padding word length */
32#define PAD_WORD_LEN 4
33
34/*
35 * useful common(control and data pathes) macro
36 */
37#define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
38#define hton24(p, v) { \
39 p[0] = (((v) >> 16) & 0xFF); \
40 p[1] = (((v) >> 8) & 0xFF); \
41 p[2] = ((v) & 0xFF); \
42}
43#define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
44
45/*
46 * iSCSI Template Message Header
47 */
48struct iscsi_hdr {
49 uint8_t opcode;
50 uint8_t flags; /* Final bit */
51 uint8_t rsvd2[2];
52 uint8_t hlength; /* AHSs total length */
53 uint8_t dlength[3]; /* Data length */
54 uint8_t lun[8];
55 __be32 itt; /* Initiator Task Tag */
56 __be32 ttt; /* Target Task Tag */
57 __be32 statsn;
58 __be32 exp_statsn;
baebc497
MC
59 __be32 max_statsn;
60 uint8_t other[12];
39e84790
AA
61};
62
63/************************* RFC 3720 Begin *****************************/
64
65#define ISCSI_RESERVED_TAG 0xffffffff
66
67/* Opcode encoding bits */
68#define ISCSI_OP_RETRY 0x80
69#define ISCSI_OP_IMMEDIATE 0x40
70#define ISCSI_OPCODE_MASK 0x3F
71
72/* Initiator Opcode values */
73#define ISCSI_OP_NOOP_OUT 0x00
74#define ISCSI_OP_SCSI_CMD 0x01
75#define ISCSI_OP_SCSI_TMFUNC 0x02
76#define ISCSI_OP_LOGIN 0x03
77#define ISCSI_OP_TEXT 0x04
78#define ISCSI_OP_SCSI_DATA_OUT 0x05
79#define ISCSI_OP_LOGOUT 0x06
80#define ISCSI_OP_SNACK 0x10
81
baebc497
MC
82#define ISCSI_OP_VENDOR1_CMD 0x1c
83#define ISCSI_OP_VENDOR2_CMD 0x1d
84#define ISCSI_OP_VENDOR3_CMD 0x1e
85#define ISCSI_OP_VENDOR4_CMD 0x1f
86
39e84790
AA
87/* Target Opcode values */
88#define ISCSI_OP_NOOP_IN 0x20
89#define ISCSI_OP_SCSI_CMD_RSP 0x21
90#define ISCSI_OP_SCSI_TMFUNC_RSP 0x22
91#define ISCSI_OP_LOGIN_RSP 0x23
92#define ISCSI_OP_TEXT_RSP 0x24
93#define ISCSI_OP_SCSI_DATA_IN 0x25
94#define ISCSI_OP_LOGOUT_RSP 0x26
95#define ISCSI_OP_R2T 0x31
96#define ISCSI_OP_ASYNC_EVENT 0x32
97#define ISCSI_OP_REJECT 0x3f
98
baebc497
MC
99struct iscsi_ahs_hdr {
100 __be16 ahslength;
101 uint8_t ahstype;
102 uint8_t ahspec[5];
103};
104
105#define ISCSI_AHSTYPE_CDB 1
106#define ISCSI_AHSTYPE_RLENGTH 2
107
39e84790
AA
108/* iSCSI PDU Header */
109struct iscsi_cmd {
110 uint8_t opcode;
111 uint8_t flags;
baebc497 112 __be16 rsvd2;
39e84790
AA
113 uint8_t hlength;
114 uint8_t dlength[3];
115 uint8_t lun[8];
116 __be32 itt; /* Initiator Task Tag */
117 __be32 data_length;
118 __be32 cmdsn;
119 __be32 exp_statsn;
120 uint8_t cdb[16]; /* SCSI Command Block */
121 /* Additional Data (Command Dependent) */
122};
123
124/* Command PDU flags */
125#define ISCSI_FLAG_CMD_FINAL 0x80
126#define ISCSI_FLAG_CMD_READ 0x40
127#define ISCSI_FLAG_CMD_WRITE 0x20
128#define ISCSI_FLAG_CMD_ATTR_MASK 0x07 /* 3 bits */
129
130/* SCSI Command Attribute values */
131#define ISCSI_ATTR_UNTAGGED 0
132#define ISCSI_ATTR_SIMPLE 1
133#define ISCSI_ATTR_ORDERED 2
134#define ISCSI_ATTR_HEAD_OF_QUEUE 3
135#define ISCSI_ATTR_ACA 4
136
baebc497
MC
137struct iscsi_rlength_ahdr {
138 __be16 ahslength;
139 uint8_t ahstype;
140 uint8_t reserved;
141 __be32 read_length;
142};
143
39e84790
AA
144/* SCSI Response Header */
145struct iscsi_cmd_rsp {
146 uint8_t opcode;
147 uint8_t flags;
148 uint8_t response;
149 uint8_t cmd_status;
150 uint8_t hlength;
151 uint8_t dlength[3];
152 uint8_t rsvd[8];
153 __be32 itt; /* Initiator Task Tag */
154 __be32 rsvd1;
155 __be32 statsn;
156 __be32 exp_cmdsn;
157 __be32 max_cmdsn;
158 __be32 exp_datasn;
159 __be32 bi_residual_count;
160 __be32 residual_count;
161 /* Response or Sense Data (optional) */
162};
163
164/* Command Response PDU flags */
165#define ISCSI_FLAG_CMD_BIDI_OVERFLOW 0x10
166#define ISCSI_FLAG_CMD_BIDI_UNDERFLOW 0x08
167#define ISCSI_FLAG_CMD_OVERFLOW 0x04
168#define ISCSI_FLAG_CMD_UNDERFLOW 0x02
169
170/* iSCSI Status values. Valid if Rsp Selector bit is not set */
171#define ISCSI_STATUS_CMD_COMPLETED 0
172#define ISCSI_STATUS_TARGET_FAILURE 1
173#define ISCSI_STATUS_SUBSYS_FAILURE 2
174
175/* Asynchronous Event Header */
176struct iscsi_async {
177 uint8_t opcode;
178 uint8_t flags;
179 uint8_t rsvd2[2];
180 uint8_t rsvd3;
181 uint8_t dlength[3];
182 uint8_t lun[8];
183 uint8_t rsvd4[8];
184 __be32 statsn;
185 __be32 exp_cmdsn;
186 __be32 max_cmdsn;
187 uint8_t async_event;
188 uint8_t async_vcode;
189 __be16 param1;
190 __be16 param2;
191 __be16 param3;
192 uint8_t rsvd5[4];
193};
194
195/* iSCSI Event Codes */
196#define ISCSI_ASYNC_MSG_SCSI_EVENT 0
197#define ISCSI_ASYNC_MSG_REQUEST_LOGOUT 1
198#define ISCSI_ASYNC_MSG_DROPPING_CONNECTION 2
199#define ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS 3
200#define ISCSI_ASYNC_MSG_PARAM_NEGOTIATION 4
201#define ISCSI_ASYNC_MSG_VENDOR_SPECIFIC 255
202
203/* NOP-Out Message */
204struct iscsi_nopout {
205 uint8_t opcode;
206 uint8_t flags;
207 __be16 rsvd2;
208 uint8_t rsvd3;
209 uint8_t dlength[3];
210 uint8_t lun[8];
211 __be32 itt; /* Initiator Task Tag */
212 __be32 ttt; /* Target Transfer Tag */
213 __be32 cmdsn;
214 __be32 exp_statsn;
215 uint8_t rsvd4[16];
216};
217
218/* NOP-In Message */
219struct iscsi_nopin {
220 uint8_t opcode;
221 uint8_t flags;
222 __be16 rsvd2;
223 uint8_t rsvd3;
224 uint8_t dlength[3];
225 uint8_t lun[8];
226 __be32 itt; /* Initiator Task Tag */
227 __be32 ttt; /* Target Transfer Tag */
228 __be32 statsn;
229 __be32 exp_cmdsn;
230 __be32 max_cmdsn;
231 uint8_t rsvd4[12];
232};
233
234/* SCSI Task Management Message Header */
235struct iscsi_tm {
236 uint8_t opcode;
237 uint8_t flags;
238 uint8_t rsvd1[2];
239 uint8_t hlength;
240 uint8_t dlength[3];
241 uint8_t lun[8];
242 __be32 itt; /* Initiator Task Tag */
243 __be32 rtt; /* Reference Task Tag */
244 __be32 cmdsn;
245 __be32 exp_statsn;
246 __be32 refcmdsn;
247 __be32 exp_datasn;
248 uint8_t rsvd2[8];
249};
250
baebc497 251#define ISCSI_FLAG_TM_FUNC_MASK 0x7F
39e84790
AA
252
253/* Function values */
254#define ISCSI_TM_FUNC_ABORT_TASK 1
255#define ISCSI_TM_FUNC_ABORT_TASK_SET 2
256#define ISCSI_TM_FUNC_CLEAR_ACA 3
257#define ISCSI_TM_FUNC_CLEAR_TASK_SET 4
258#define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET 5
259#define ISCSI_TM_FUNC_TARGET_WARM_RESET 6
260#define ISCSI_TM_FUNC_TARGET_COLD_RESET 7
261#define ISCSI_TM_FUNC_TASK_REASSIGN 8
262
263/* SCSI Task Management Response Header */
264struct iscsi_tm_rsp {
265 uint8_t opcode;
266 uint8_t flags;
267 uint8_t response; /* see Response values below */
268 uint8_t qualifier;
269 uint8_t hlength;
270 uint8_t dlength[3];
271 uint8_t rsvd2[8];
272 __be32 itt; /* Initiator Task Tag */
273 __be32 rtt; /* Reference Task Tag */
274 __be32 statsn;
275 __be32 exp_cmdsn;
276 __be32 max_cmdsn;
277 uint8_t rsvd3[12];
278};
279
280/* Response values */
baebc497
MC
281#define ISCSI_TMF_RSP_COMPLETE 0x00
282#define ISCSI_TMF_RSP_NO_TASK 0x01
283#define ISCSI_TMF_RSP_NO_LUN 0x02
284#define ISCSI_TMF_RSP_TASK_ALLEGIANT 0x03
285#define ISCSI_TMF_RSP_NO_FAILOVER 0x04
286#define ISCSI_TMF_RSP_NOT_SUPPORTED 0x05
287#define ISCSI_TMF_RSP_AUTH_FAILED 0x06
288#define ISCSI_TMF_RSP_REJECTED 0xff
39e84790
AA
289
290/* Ready To Transfer Header */
291struct iscsi_r2t_rsp {
292 uint8_t opcode;
293 uint8_t flags;
294 uint8_t rsvd2[2];
295 uint8_t hlength;
296 uint8_t dlength[3];
297 uint8_t lun[8];
298 __be32 itt; /* Initiator Task Tag */
299 __be32 ttt; /* Target Transfer Tag */
300 __be32 statsn;
301 __be32 exp_cmdsn;
302 __be32 max_cmdsn;
303 __be32 r2tsn;
304 __be32 data_offset;
305 __be32 data_length;
306};
307
308/* SCSI Data Hdr */
309struct iscsi_data {
310 uint8_t opcode;
311 uint8_t flags;
312 uint8_t rsvd2[2];
313 uint8_t rsvd3;
314 uint8_t dlength[3];
315 uint8_t lun[8];
316 __be32 itt;
317 __be32 ttt;
318 __be32 rsvd4;
319 __be32 exp_statsn;
320 __be32 rsvd5;
321 __be32 datasn;
322 __be32 offset;
323 __be32 rsvd6;
324 /* Payload */
325};
326
327/* SCSI Data Response Hdr */
328struct iscsi_data_rsp {
329 uint8_t opcode;
330 uint8_t flags;
331 uint8_t rsvd2;
332 uint8_t cmd_status;
333 uint8_t hlength;
334 uint8_t dlength[3];
335 uint8_t lun[8];
336 __be32 itt;
337 __be32 ttt;
338 __be32 statsn;
339 __be32 exp_cmdsn;
340 __be32 max_cmdsn;
341 __be32 datasn;
342 __be32 offset;
343 __be32 residual_count;
344};
345
346/* Data Response PDU flags */
347#define ISCSI_FLAG_DATA_ACK 0x40
348#define ISCSI_FLAG_DATA_OVERFLOW 0x04
349#define ISCSI_FLAG_DATA_UNDERFLOW 0x02
350#define ISCSI_FLAG_DATA_STATUS 0x01
351
352/* Text Header */
353struct iscsi_text {
354 uint8_t opcode;
355 uint8_t flags;
356 uint8_t rsvd2[2];
357 uint8_t hlength;
358 uint8_t dlength[3];
359 uint8_t rsvd4[8];
360 __be32 itt;
361 __be32 ttt;
362 __be32 cmdsn;
363 __be32 exp_statsn;
364 uint8_t rsvd5[16];
365 /* Text - key=value pairs */
366};
367
368#define ISCSI_FLAG_TEXT_CONTINUE 0x40
369
370/* Text Response Header */
371struct iscsi_text_rsp {
372 uint8_t opcode;
373 uint8_t flags;
374 uint8_t rsvd2[2];
375 uint8_t hlength;
376 uint8_t dlength[3];
377 uint8_t rsvd4[8];
378 __be32 itt;
379 __be32 ttt;
380 __be32 statsn;
381 __be32 exp_cmdsn;
382 __be32 max_cmdsn;
383 uint8_t rsvd5[12];
384 /* Text Response - key:value pairs */
385};
386
387/* Login Header */
388struct iscsi_login {
389 uint8_t opcode;
390 uint8_t flags;
391 uint8_t max_version; /* Max. version supported */
392 uint8_t min_version; /* Min. version supported */
393 uint8_t hlength;
394 uint8_t dlength[3];
395 uint8_t isid[6]; /* Initiator Session ID */
396 __be16 tsih; /* Target Session Handle */
397 __be32 itt; /* Initiator Task Tag */
398 __be16 cid;
399 __be16 rsvd3;
400 __be32 cmdsn;
401 __be32 exp_statsn;
402 uint8_t rsvd5[16];
403};
404
405/* Login PDU flags */
406#define ISCSI_FLAG_LOGIN_TRANSIT 0x80
407#define ISCSI_FLAG_LOGIN_CONTINUE 0x40
408#define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK 0x0C /* 2 bits */
409#define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK 0x03 /* 2 bits */
410
411#define ISCSI_LOGIN_CURRENT_STAGE(flags) \
412 ((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
413#define ISCSI_LOGIN_NEXT_STAGE(flags) \
414 (flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
415
416/* Login Response Header */
417struct iscsi_login_rsp {
418 uint8_t opcode;
419 uint8_t flags;
420 uint8_t max_version; /* Max. version supported */
421 uint8_t active_version; /* Active version */
422 uint8_t hlength;
423 uint8_t dlength[3];
424 uint8_t isid[6]; /* Initiator Session ID */
425 __be16 tsih; /* Target Session Handle */
426 __be32 itt; /* Initiator Task Tag */
427 __be32 rsvd3;
428 __be32 statsn;
429 __be32 exp_cmdsn;
430 __be32 max_cmdsn;
431 uint8_t status_class; /* see Login RSP ststus classes below */
432 uint8_t status_detail; /* see Login RSP Status details below */
433 uint8_t rsvd4[10];
434};
435
436/* Login stage (phase) codes for CSG, NSG */
437#define ISCSI_INITIAL_LOGIN_STAGE -1
438#define ISCSI_SECURITY_NEGOTIATION_STAGE 0
439#define ISCSI_OP_PARMS_NEGOTIATION_STAGE 1
440#define ISCSI_FULL_FEATURE_PHASE 3
441
442/* Login Status response classes */
443#define ISCSI_STATUS_CLS_SUCCESS 0x00
444#define ISCSI_STATUS_CLS_REDIRECT 0x01
445#define ISCSI_STATUS_CLS_INITIATOR_ERR 0x02
446#define ISCSI_STATUS_CLS_TARGET_ERR 0x03
447
448/* Login Status response detail codes */
449/* Class-0 (Success) */
450#define ISCSI_LOGIN_STATUS_ACCEPT 0x00
451
452/* Class-1 (Redirection) */
453#define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP 0x01
454#define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM 0x02
455
456/* Class-2 (Initiator Error) */
457#define ISCSI_LOGIN_STATUS_INIT_ERR 0x00
458#define ISCSI_LOGIN_STATUS_AUTH_FAILED 0x01
459#define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN 0x02
460#define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND 0x03
461#define ISCSI_LOGIN_STATUS_TGT_REMOVED 0x04
462#define ISCSI_LOGIN_STATUS_NO_VERSION 0x05
463#define ISCSI_LOGIN_STATUS_ISID_ERROR 0x06
464#define ISCSI_LOGIN_STATUS_MISSING_FIELDS 0x07
465#define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED 0x08
466#define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE 0x09
467#define ISCSI_LOGIN_STATUS_NO_SESSION 0x0a
468#define ISCSI_LOGIN_STATUS_INVALID_REQUEST 0x0b
469
470/* Class-3 (Target Error) */
471#define ISCSI_LOGIN_STATUS_TARGET_ERROR 0x00
472#define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE 0x01
473#define ISCSI_LOGIN_STATUS_NO_RESOURCES 0x02
474
475/* Logout Header */
476struct iscsi_logout {
477 uint8_t opcode;
478 uint8_t flags;
479 uint8_t rsvd1[2];
480 uint8_t hlength;
481 uint8_t dlength[3];
482 uint8_t rsvd2[8];
483 __be32 itt; /* Initiator Task Tag */
484 __be16 cid;
485 uint8_t rsvd3[2];
486 __be32 cmdsn;
487 __be32 exp_statsn;
488 uint8_t rsvd4[16];
489};
490
491/* Logout PDU flags */
492#define ISCSI_FLAG_LOGOUT_REASON_MASK 0x7F
493
494/* logout reason_code values */
495
496#define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
497#define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
498#define ISCSI_LOGOUT_REASON_RECOVERY 2
499#define ISCSI_LOGOUT_REASON_AEN_REQUEST 3
500
501/* Logout Response Header */
502struct iscsi_logout_rsp {
503 uint8_t opcode;
504 uint8_t flags;
505 uint8_t response; /* see Logout response values below */
506 uint8_t rsvd2;
507 uint8_t hlength;
508 uint8_t dlength[3];
509 uint8_t rsvd3[8];
510 __be32 itt; /* Initiator Task Tag */
511 __be32 rsvd4;
512 __be32 statsn;
513 __be32 exp_cmdsn;
514 __be32 max_cmdsn;
515 __be32 rsvd5;
516 __be16 t2wait;
517 __be16 t2retain;
518 __be32 rsvd6;
519};
520
521/* logout response status values */
522
523#define ISCSI_LOGOUT_SUCCESS 0
524#define ISCSI_LOGOUT_CID_NOT_FOUND 1
525#define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED 2
526#define ISCSI_LOGOUT_CLEANUP_FAILED 3
527
528/* SNACK Header */
529struct iscsi_snack {
530 uint8_t opcode;
531 uint8_t flags;
532 uint8_t rsvd2[14];
533 __be32 itt;
534 __be32 begrun;
535 __be32 runlength;
536 __be32 exp_statsn;
537 __be32 rsvd3;
538 __be32 exp_datasn;
539 uint8_t rsvd6[8];
540};
541
542/* SNACK PDU flags */
543#define ISCSI_FLAG_SNACK_TYPE_MASK 0x0F /* 4 bits */
544
545/* Reject Message Header */
546struct iscsi_reject {
547 uint8_t opcode;
548 uint8_t flags;
549 uint8_t reason;
550 uint8_t rsvd2;
551 uint8_t rsvd3;
552 uint8_t dlength[3];
553 uint8_t rsvd4[16];
554 __be32 statsn;
555 __be32 exp_cmdsn;
556 __be32 max_cmdsn;
557 __be32 datasn;
558 uint8_t rsvd5[8];
559 /* Text - Rejected hdr */
560};
561
562/* Reason for Reject */
563#define CMD_BEFORE_LOGIN 1
564#define DATA_DIGEST_ERROR 2
565#define DATA_SNACK_REJECT 3
566#define ISCSI_PROTOCOL_ERROR 4
567#define CMD_NOT_SUPPORTED 5
568#define IMM_CMD_REJECT 6
569#define TASK_IN_PROGRESS 7
570#define INVALID_SNACK 8
571#define BOOKMARK_REJECTED 9
572#define BOOKMARK_NO_RESOURCES 10
573#define NEGOTIATION_RESET 11
574
575/* Max. number of Key=Value pairs in a text message */
576#define MAX_KEY_VALUE_PAIRS 8192
577
578/* maximum length for text keys/values */
579#define KEY_MAXLEN 64
580#define VALUE_MAXLEN 255
581#define TARGET_NAME_MAXLEN VALUE_MAXLEN
582
583#define DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH 8192
584
585/************************* RFC 3720 End *****************************/
586
587#endif /* ISCSI_PROTO_H */
This page took 0.058586 seconds and 5 git commands to generate.