1 /* $OpenBSD: iscsi.h,v 1.9 2019/09/27 23:07:42 krw Exp $ */ 2 3 /* 4 * Copyright (c) 2008 David Gwynne <dlg@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _SCSI_ISCSI_H 20 #define _SCSI_ISCSI_H 21 22 struct iscsi_pdu { 23 u_int8_t opcode; 24 u_int8_t flags; 25 u_int8_t _reserved1[2]; 26 27 u_int8_t ahslen; 28 u_int8_t datalen[3]; 29 30 u_int8_t lun[8]; 31 32 u_int32_t itt; 33 34 u_int8_t _reserved2[4]; 35 36 u_int32_t cmdsn; 37 38 u_int32_t expstatsn; 39 40 u_int8_t _reserved3[16]; 41 } __packed; 42 43 /* 44 * Initiator opcodes 45 */ 46 47 #define ISCSI_OP_I_NOP 0x00 48 #define ISCSI_OP_SCSI_REQUEST 0x01 49 #define ISCSI_OP_TASK_REQUEST 0x02 50 #define ISCSI_OP_LOGIN_REQUEST 0x03 51 #define ISCSI_OP_TEXT_REQUEST 0x04 52 #define ISCSI_OP_DATA_OUT 0x05 53 #define ISCSI_OP_LOGOUT_REQUEST 0x06 54 #define ISCSI_OP_SNACK_REQUEST 0x10 55 56 /* 57 * Target opcodes 58 */ 59 60 #define ISCSI_OP_T_NOP 0x20 61 #define ISCSI_OP_SCSI_RESPONSE 0x21 62 #define ISCSI_OP_TASK_RESPONSE 0x22 63 #define ISCSI_OP_LOGIN_RESPONSE 0x23 64 #define ISCSI_OP_TEXT_RESPONSE 0x24 65 #define ISCSI_OP_DATA_IN 0x25 66 #define ISCSI_OP_LOGOUT_RESPONSE 0x26 67 #define ISCSI_OP_R2T 0x31 68 #define ISCSI_OP_ASYNC 0x32 69 #define ISCSI_OP_REJECT 0x3f 70 71 #define ISCSI_PDU_OPCODE(_o) ((_o) & 0x3f) 72 #define ISCSI_PDU_I(_h) ((_h)->opcode & 0x40) 73 #define ISCSI_PDU_F(_h) ((_h)->flags & 0x80) 74 75 #define ISCSI_OP_F_IMMEDIATE 0x40 76 77 /* 78 * various other flags and values 79 */ 80 #define ISCSI_ISID_OUI 0x00000000 81 #define ISCSI_ISID_EN 0x40000000 82 #define ISCSI_ISID_RAND 0x80000000 83 84 struct iscsi_pdu_scsi_request { 85 u_int8_t opcode; 86 u_int8_t flags; 87 u_int8_t _reserved[2]; 88 89 u_int8_t ahslen; 90 u_int8_t datalen[3]; 91 92 u_int8_t lun[8]; 93 94 u_int32_t itt; 95 96 u_int32_t bytes; 97 98 u_int32_t cmdsn; 99 100 u_int32_t expstatsn; 101 102 u_int8_t cdb[16]; 103 } __packed; 104 105 struct iscsi_pdu_scsi_response { 106 u_int8_t opcode; 107 u_int8_t flags; 108 u_int8_t response; 109 u_int8_t status; 110 111 u_int8_t ahslen; 112 u_int8_t datalen[3]; 113 114 u_int8_t _reserved[8]; 115 116 u_int32_t itt; 117 118 u_int32_t snack; 119 120 u_int32_t statsn; 121 122 u_int32_t expcmdsn; 123 124 u_int32_t maxcmdsn; 125 126 u_int32_t expdatasn; 127 128 u_int32_t birescount; 129 130 u_int32_t rescount; 131 } __packed; 132 133 #define ISCSI_SCSI_F_F 0x80 134 #define ISCSI_SCSI_F_R 0x40 135 #define ISCSI_SCSI_F_W 0x20 136 137 #define ISCSI_SCSI_ATTR_UNTAGGED 0 138 #define ISCSI_SCSI_ATTR_SIMPLE 1 139 #define ISCSI_SCSI_ATTR_ORDERED 2 140 #define ISCSI_SCSI_ATTR_HEAD_OF_Q 3 141 #define ISCSI_SCSI_ATTR_ACA 4 142 143 #define ISCSI_SCSI_STAT_GOOD 0x00 144 #define ISCSI_SCSI_STAT_CHCK_COND 0x02 145 /* we don't care about the type of the other error conditions */ 146 147 struct iscsi_pdu_task_request { 148 u_int8_t opcode; 149 u_int8_t flags; 150 u_int8_t reserved[2]; 151 152 u_int8_t ahslen; 153 u_int8_t datalen[3]; 154 155 u_int8_t lun[8]; 156 157 u_int32_t itt; 158 159 u_int32_t tag; 160 161 u_int32_t cmdsn; 162 163 u_int32_t expstatsn; 164 165 u_int32_t refcmdsn; 166 167 u_int32_t expdatasn; 168 169 u_int8_t _reserved[8]; 170 } __packed; 171 172 struct iscsi_pdu_task_response { 173 u_int8_t opcode; 174 u_int8_t flags; 175 u_int8_t response; 176 u_int8_t _reserved1; 177 178 u_int8_t ahslen; 179 u_int8_t datalen[3]; 180 181 u_int8_t _reserved[8]; 182 183 u_int32_t itt; 184 185 u_int8_t _reserved2[4]; 186 187 u_int32_t statsn; 188 189 u_int32_t expcmdsn; 190 191 u_int32_t maxcmdsn; 192 193 u_int8_t _reserved3[12]; 194 } __packed; 195 196 struct iscsi_pdu_data_out { 197 u_int8_t opcode; 198 u_int8_t flags; 199 u_int8_t _reserved1[2]; 200 201 u_int8_t ahslen; 202 u_int8_t datalen[3]; 203 204 u_int8_t lun[8]; 205 206 u_int32_t itt; 207 208 u_int32_t ttt; 209 210 u_int8_t _reserved2[4]; 211 212 u_int32_t expstatsn; 213 214 u_int8_t _reserved3[4]; 215 216 u_int32_t datasn; 217 218 u_int32_t buffer_offs; 219 220 u_int8_t _reserved4[4]; 221 } __packed; 222 223 struct iscsi_pdu_data_in { 224 u_int8_t opcode; 225 u_int8_t flags; 226 u_int8_t _reserved; 227 u_int8_t status; 228 229 u_int8_t ahslen; 230 u_int8_t datalen[3]; 231 232 u_int8_t lun[8]; 233 234 u_int32_t itt; 235 236 u_int32_t ttt; 237 238 u_int32_t statsn; 239 240 u_int32_t expcmdsn; 241 242 u_int32_t maxcmdsn; 243 244 u_int32_t datasn; 245 246 u_int32_t buffer_offs; 247 248 u_int32_t residual; 249 } __packed; 250 251 struct iscsi_pdu_rt2 { 252 u_int8_t opcode; 253 u_int8_t flags; 254 u_int8_t _reserved1[2]; 255 256 u_int8_t ahslen; 257 u_int8_t datalen[3]; 258 259 u_int8_t lun[8]; 260 261 u_int32_t itt; 262 263 u_int32_t ttt; 264 265 u_int32_t statsn; 266 267 u_int32_t expcmdsn; 268 269 u_int32_t maxcmdsn; 270 271 u_int32_t r2tsn; 272 273 u_int32_t buffer_offs; 274 275 u_int32_t desired_datalen; 276 } __packed; 277 278 struct iscsi_pdu_async { 279 u_int8_t opcode; 280 u_int8_t flags; 281 u_int8_t _reserved1[2]; 282 283 u_int8_t ahslen; 284 u_int8_t datalen[3]; 285 286 u_int8_t lun[8]; 287 288 u_int32_t ffffffff; 289 290 u_int8_t _reserved2[4]; 291 292 u_int32_t statsn; 293 294 u_int32_t expcmdsn; 295 296 u_int32_t maxcmdsn; 297 298 u_int8_t event; 299 u_int8_t vcode; 300 u_int16_t param[3]; 301 302 u_int8_t _reserved3[4]; 303 } __packed; 304 305 struct iscsi_pdu_text_request { 306 u_int8_t opcode; 307 u_int8_t flags; 308 u_int8_t _reserved1[2]; 309 310 u_int8_t ahslen; 311 u_int8_t datalen[3]; 312 313 u_int8_t lun[8]; 314 315 u_int32_t itt; 316 317 u_int32_t ttt; 318 319 u_int32_t cmdsn; 320 321 u_int32_t expstatsn; 322 323 u_int8_t _reserved2[16]; 324 } __packed; 325 326 struct iscsi_pdu_text_response { 327 u_int8_t opcode; 328 u_int8_t flags; 329 u_int8_t _reserved1[2]; 330 331 u_int8_t ahslen; 332 u_int8_t datalen[3]; 333 334 u_int8_t lun[8]; 335 336 u_int32_t itt; 337 338 u_int32_t ttt; 339 340 u_int32_t cmdsn; 341 342 u_int32_t expcmdsn; 343 344 u_int32_t maxcmdsn; 345 346 u_int8_t _reserved2[12]; 347 } __packed; 348 349 #define ISCSI_TEXT_F_F 0x80 350 #define ISCSI_TEXT_F_C 0x40 351 352 struct iscsi_pdu_login_request { 353 u_int8_t opcode; 354 u_int8_t flags; 355 u_int8_t version_max; 356 u_int8_t version_min; 357 358 u_int8_t ahslen; 359 u_int8_t datalen[3]; 360 361 u_int32_t isid_base; 362 u_int16_t isid_qual; 363 u_int16_t tsih; 364 365 u_int32_t itt; 366 367 u_int16_t cid; 368 u_int8_t _reserved1[2]; 369 370 u_int32_t cmdsn; 371 372 u_int32_t expstatsn; 373 374 u_int8_t _reserved2[16]; 375 } __packed; 376 377 #define ISCSI_LOGIN_F_T 0x80 378 #define ISCSI_LOGIN_F_C 0x40 379 #define ISCSI_LOGIN_F_CSG(x) (((x) & 0x3) << 2) 380 #define ISCSI_LOGIN_F_NSG(x) ((x) & 0x3) 381 #define ISCSI_LOGIN_STG_SECNEG 0 382 #define ISCSI_LOGIN_STG_OPNEG 1 383 #define ISCSI_LOGIN_STG_FULL 3 384 385 struct iscsi_pdu_login_response { 386 u_int8_t opcode; 387 u_int8_t flags; 388 u_int8_t version_max; 389 u_int8_t version_active; 390 391 u_int8_t ahslen; 392 u_int8_t datalen[3]; 393 394 u_int32_t isid_base; 395 u_int16_t isid_qual; 396 u_int16_t tsih; 397 398 u_int32_t itt; 399 400 u_int8_t _reserved1[4]; 401 402 u_int32_t statsn; 403 404 u_int32_t expcmdsn; 405 406 u_int32_t maxcmdsn; 407 408 u_int8_t status_class; 409 u_int8_t status_detail; 410 411 u_int8_t _reserved2[10]; 412 } __packed; 413 414 struct iscsi_pdu_logout_request { 415 u_int8_t opcode; 416 u_int8_t flags; 417 u_int8_t _reserved1[2]; 418 419 u_int8_t ahslen; 420 u_int8_t datalen[3]; 421 422 u_int8_t _reserved2[8]; 423 424 u_int32_t itt; 425 426 u_int16_t cid; 427 u_int8_t _reserved3[2]; 428 429 u_int32_t cmdsn; 430 431 u_int32_t expstatsn; 432 433 u_int8_t _reserved4[16]; 434 } __packed; 435 436 #define ISCSI_LOGOUT_F 0x80 437 #define ISCSI_LOGOUT_CLOSE_SESS 0 438 #define ISCSI_LOGOUT_CLOSE_CONN 1 439 #define ISCSI_LOGOUT_RCVRY_CONN 2 440 441 #define ISCSI_LOGOUT_RESP_SUCCESS 0 442 #define ISCSI_LOGOUT_RESP_UNKN_CID 1 443 #define ISCSI_LOGOUT_RESP_NO_SUPPORT 2 444 #define ISCSI_LOGOUT_RESP_ERROR 3 445 446 struct iscsi_pdu_logout_response { 447 u_int8_t opcode; 448 u_int8_t flags; 449 u_int8_t response; 450 u_int8_t _reserved1; 451 452 u_int8_t ahslen; 453 u_int8_t datalen[3]; 454 455 u_int8_t _reserved2[8]; 456 457 u_int32_t itt; 458 459 u_int8_t _reserved3[4]; 460 461 u_int32_t statsn; 462 463 u_int32_t expcmdsn; 464 465 u_int32_t maxcmdsn; 466 467 u_int8_t _reserved4[4]; 468 469 u_int16_t time2wait; 470 u_int16_t time2retain; 471 472 u_int8_t _reserved5[4]; 473 } __packed; 474 475 struct iscsi_pdu_snack_request { 476 u_int8_t opcode; 477 u_int8_t flags; 478 u_int8_t _reserved1[2]; 479 480 u_int8_t ahslen; 481 u_int8_t datalen[3]; 482 483 u_int8_t lun[8]; 484 485 u_int32_t itt; 486 487 u_int32_t ttt; 488 489 u_int8_t _reserved2[4]; 490 491 u_int32_t expstatsn; 492 493 u_int8_t _reserved3[8]; 494 495 u_int32_t begrun; 496 497 u_int32_t runlength; 498 } __packed; 499 500 struct iscsi_pdu_reject { 501 u_int8_t opcode; 502 u_int8_t flags; 503 u_int8_t reason; 504 u_int8_t _reserved1; 505 506 u_int8_t ahslen; 507 u_int8_t datalen[3]; 508 509 u_int8_t _reserved2[8]; 510 511 u_int32_t ffffffff; 512 513 u_int8_t _reserved3[4]; 514 515 u_int32_t statsn; 516 517 u_int32_t expcmdsn; 518 519 u_int32_t maxcmdsn; 520 521 u_int32_t datasn_r2tsn; 522 523 u_int8_t _reserved4[8]; 524 } __packed; 525 526 struct iscsi_pdu_nop_out { 527 u_int8_t opcode; 528 u_int8_t flags; 529 u_int8_t _reserved1[2]; 530 531 u_int8_t ahslen; 532 u_int8_t datalen[3]; 533 534 u_int8_t lun[8]; 535 536 u_int32_t itt; 537 538 u_int32_t ttt; 539 540 u_int32_t cmdsn; 541 542 u_int32_t expstatsn; 543 544 u_int8_t _reserved2[16]; 545 } __packed; 546 547 struct iscsi_pdu_nop_in { 548 u_int8_t opcode; 549 u_int8_t flags; 550 u_int8_t _reserved1[2]; 551 552 u_int8_t ahslen; 553 u_int8_t datalen[3]; 554 555 u_int8_t lun[8]; 556 557 u_int32_t itt; 558 559 u_int32_t ttt; 560 561 u_int32_t statsn; 562 563 u_int32_t expcmdsn; 564 565 u_int32_t maxcmdsn; 566 567 u_int8_t _reserved2[12]; 568 } __packed; 569 570 #endif /* _SCSI_ISCSI_H */ 571