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