Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
iscsi_proto.h
Go to the documentation of this file.
1 /*
2  * RFC 3720 (iSCSI) protocol data types
3  *
4  * Copyright (C) 2005 Dmitry Yusupov
5  * Copyright (C) 2005 Alex Aizman
6  * maintained by [email protected]
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 
45 static inline int iscsi_sna_lt(u32 n1, u32 n2)
46 {
47  return (s32)(n1 - n2) < 0;
48 }
49 
50 static inline int iscsi_sna_lte(u32 n1, u32 n2)
51 {
52  return (s32)(n1 - n2) <= 0;
53 }
54 
55 static inline int iscsi_sna_gt(u32 n1, u32 n2)
56 {
57  return (s32)(n1 - n2) > 0;
58 }
59 
60 static 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 */
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  */
87 struct iscsi_hdr {
89  uint8_t flags; /* Final bit */
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 */
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 
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 */
155  struct scsi_lun lun;
156  itt_t itt; /* Initiator Task Tag */
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 
182 };
183 
184 /* Extended CDB AHS */
186  __be16 ahslength; /* CDB length - 15, including reserved byte */
189  /* 4-byte aligned extended CDB spillover */
191 };
192 
193 /* SCSI Response Header */
202  itt_t itt; /* Initiator Task Tag */
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 */
225 struct iscsi_async {
231  struct scsi_lun lun;
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 */
253 struct iscsi_nopout {
259  struct scsi_lun lun;
260  itt_t itt; /* Initiator Task Tag */
261  __be32 ttt; /* Target Transfer Tag */
265 };
266 
267 /* NOP-In Message */
268 struct iscsi_nopin {
274  struct scsi_lun lun;
275  itt_t itt; /* Initiator Task Tag */
276  __be32 ttt; /* Target Transfer Tag */
281 };
282 
283 /* SCSI Task Management Message Header */
284 struct iscsi_tm {
290  struct scsi_lun lun;
291  itt_t itt; /* Initiator Task Tag */
292  itt_t rtt; /* Reference Task Tag */
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 */
315 struct iscsi_tm_rsp {
318  uint8_t response; /* see Response values below */
323  itt_t itt; /* Initiator Task Tag */
324  itt_t rtt; /* Reference Task Tag */
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 */
348  struct scsi_lun lun;
349  itt_t itt; /* Initiator Task Tag */
350  __be32 ttt; /* Target Transfer Tag */
357 };
358 
359 /* SCSI Data Hdr */
360 struct iscsi_data {
366  struct scsi_lun lun;
367  itt_t itt;
375  /* Payload */
376 };
377 
378 /* SCSI Data Response Hdr */
386  struct scsi_lun lun;
387  itt_t itt;
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 */
404 struct iscsi_text {
411  itt_t itt;
416  /* Text - key=value pairs */
417 };
418 
419 #define ISCSI_FLAG_TEXT_CONTINUE 0x40
420 
421 /* Text Response Header */
429  itt_t itt;
435  /* Text Response - key:value pairs */
436 };
437 
438 /* Login Header */
442  uint8_t max_version; /* Max. version supported */
443  uint8_t min_version; /* Min. version supported */
446  uint8_t isid[6]; /* Initiator Session ID */
447  __be16 tsih; /* Target Session Handle */
448  itt_t itt; /* Initiator Task Tag */
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 */
477  uint8_t max_version; /* Max. version supported */
478  uint8_t active_version; /* Active version */
481  uint8_t isid[6]; /* Initiator Session ID */
482  __be16 tsih; /* Target Session Handle */
483  itt_t itt; /* Initiator Task Tag */
488  uint8_t status_class; /* see Login RSP ststus classes below */
489  uint8_t status_detail; /* see Login RSP Status details below */
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 */
533 struct iscsi_logout {
540  itt_t itt; /* Initiator Task Tag */
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 */
562  uint8_t response; /* see Logout response values below */
567  itt_t itt; /* Initiator Task Tag */
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 */
586 struct iscsi_snack {
593  itt_t itt;
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 */
611 struct iscsi_reject {
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 #define ISCSI_NAME_LEN 224
665 
666 /************************* RFC 3720 End *****************************/
667 
668 #endif /* ISCSI_PROTO_H */