1009ea47eSEdward Tomasz Napierala /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4009ea47eSEdward Tomasz Napierala * Copyright (c) 2012 The FreeBSD Foundation 5009ea47eSEdward Tomasz Napierala * 6009ea47eSEdward Tomasz Napierala * This software was developed by Edward Tomasz Napierala under sponsorship 7009ea47eSEdward Tomasz Napierala * from the FreeBSD Foundation. 8009ea47eSEdward Tomasz Napierala * 9009ea47eSEdward Tomasz Napierala * Redistribution and use in source and binary forms, with or without 10009ea47eSEdward Tomasz Napierala * modification, are permitted provided that the following conditions 11009ea47eSEdward Tomasz Napierala * are met: 12009ea47eSEdward Tomasz Napierala * 1. Redistributions of source code must retain the above copyright 13009ea47eSEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer. 14009ea47eSEdward Tomasz Napierala * 2. Redistributions in binary form must reproduce the above copyright 15009ea47eSEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer in the 16009ea47eSEdward Tomasz Napierala * documentation and/or other materials provided with the distribution. 17009ea47eSEdward Tomasz Napierala * 18009ea47eSEdward Tomasz Napierala * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19009ea47eSEdward Tomasz Napierala * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20009ea47eSEdward Tomasz Napierala * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21009ea47eSEdward Tomasz Napierala * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22009ea47eSEdward Tomasz Napierala * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23009ea47eSEdward Tomasz Napierala * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24009ea47eSEdward Tomasz Napierala * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25009ea47eSEdward Tomasz Napierala * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26009ea47eSEdward Tomasz Napierala * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27009ea47eSEdward Tomasz Napierala * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28009ea47eSEdward Tomasz Napierala * SUCH DAMAGE. 29009ea47eSEdward Tomasz Napierala */ 30009ea47eSEdward Tomasz Napierala 31009ea47eSEdward Tomasz Napierala #ifndef ISCSI_PROTO_H 32009ea47eSEdward Tomasz Napierala #define ISCSI_PROTO_H 33009ea47eSEdward Tomasz Napierala 34009ea47eSEdward Tomasz Napierala #ifndef CTASSERT 35009ea47eSEdward Tomasz Napierala #define CTASSERT(x) _CTASSERT(x, __LINE__) 36009ea47eSEdward Tomasz Napierala #define _CTASSERT(x, y) __CTASSERT(x, y) 37009ea47eSEdward Tomasz Napierala #define __CTASSERT(x, y) typedef char __assert_ ## y [(x) ? 1 : -1] 38009ea47eSEdward Tomasz Napierala #endif 39009ea47eSEdward Tomasz Napierala 402124e3b0SAlexander Motin #define ISCSI_SNGT(x, y) ((int32_t)(x) - (int32_t)(y) > 0) 412124e3b0SAlexander Motin #define ISCSI_SNLT(x, y) ((int32_t)(x) - (int32_t)(y) < 0) 422124e3b0SAlexander Motin 43009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_SIZE 48 44009ea47eSEdward Tomasz Napierala #define ISCSI_HEADER_DIGEST_SIZE 4 45009ea47eSEdward Tomasz Napierala #define ISCSI_DATA_DIGEST_SIZE 4 46009ea47eSEdward Tomasz Napierala 47009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_IMMEDIATE 0x40 48009ea47eSEdward Tomasz Napierala 49009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_NOP_OUT 0x00 50009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_SCSI_COMMAND 0x01 51009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_TASK_REQUEST 0x02 52009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_LOGIN_REQUEST 0x03 53009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_TEXT_REQUEST 0x04 54009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_SCSI_DATA_OUT 0x05 55009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_LOGOUT_REQUEST 0x06 56009ea47eSEdward Tomasz Napierala 57009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_NOP_IN 0x20 58009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_SCSI_RESPONSE 0x21 59009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_TASK_RESPONSE 0x22 60009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_LOGIN_RESPONSE 0x23 61009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_TEXT_RESPONSE 0x24 62009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_SCSI_DATA_IN 0x25 63009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_LOGOUT_RESPONSE 0x26 64009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_R2T 0x31 65009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_ASYNC_MESSAGE 0x32 66009ea47eSEdward Tomasz Napierala #define ISCSI_BHS_OPCODE_REJECT 0x3f 67009ea47eSEdward Tomasz Napierala 68009ea47eSEdward Tomasz Napierala struct iscsi_bhs { 69009ea47eSEdward Tomasz Napierala uint8_t bhs_opcode; 70009ea47eSEdward Tomasz Napierala uint8_t bhs_opcode_specific1[3]; 71009ea47eSEdward Tomasz Napierala uint8_t bhs_total_ahs_len; 72009ea47eSEdward Tomasz Napierala uint8_t bhs_data_segment_len[3]; 73009ea47eSEdward Tomasz Napierala uint64_t bhs_lun; 74009ea47eSEdward Tomasz Napierala uint8_t bhs_inititator_task_tag[4]; 75009ea47eSEdward Tomasz Napierala uint8_t bhs_opcode_specific4[28]; 76009ea47eSEdward Tomasz Napierala }; 77009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs) == ISCSI_BHS_SIZE); 78009ea47eSEdward Tomasz Napierala 79009ea47eSEdward Tomasz Napierala #define BHSSC_FLAGS_F 0x80 80009ea47eSEdward Tomasz Napierala #define BHSSC_FLAGS_R 0x40 81009ea47eSEdward Tomasz Napierala #define BHSSC_FLAGS_W 0x20 82009ea47eSEdward Tomasz Napierala #define BHSSC_FLAGS_ATTR 0x07 83009ea47eSEdward Tomasz Napierala 84009ea47eSEdward Tomasz Napierala #define BHSSC_FLAGS_ATTR_UNTAGGED 0 85009ea47eSEdward Tomasz Napierala #define BHSSC_FLAGS_ATTR_SIMPLE 1 86009ea47eSEdward Tomasz Napierala #define BHSSC_FLAGS_ATTR_ORDERED 2 87009ea47eSEdward Tomasz Napierala #define BHSSC_FLAGS_ATTR_HOQ 3 88009ea47eSEdward Tomasz Napierala #define BHSSC_FLAGS_ATTR_ACA 4 89009ea47eSEdward Tomasz Napierala 907dbbd1aeSAlexander Motin #define BHSSC_PRI_MASK 0xf0 917dbbd1aeSAlexander Motin #define BHSSC_PRI_SHIFT 4 927dbbd1aeSAlexander Motin 93009ea47eSEdward Tomasz Napierala struct iscsi_bhs_scsi_command { 94009ea47eSEdward Tomasz Napierala uint8_t bhssc_opcode; 95009ea47eSEdward Tomasz Napierala uint8_t bhssc_flags; 967dbbd1aeSAlexander Motin uint8_t bhssc_pri; 977dbbd1aeSAlexander Motin uint8_t bhssc_reserved; 98009ea47eSEdward Tomasz Napierala uint8_t bhssc_total_ahs_len; 99009ea47eSEdward Tomasz Napierala uint8_t bhssc_data_segment_len[3]; 100009ea47eSEdward Tomasz Napierala uint64_t bhssc_lun; 101009ea47eSEdward Tomasz Napierala uint32_t bhssc_initiator_task_tag; 102009ea47eSEdward Tomasz Napierala uint32_t bhssc_expected_data_transfer_length; 103009ea47eSEdward Tomasz Napierala uint32_t bhssc_cmdsn; 104009ea47eSEdward Tomasz Napierala uint32_t bhssc_expstatsn; 105009ea47eSEdward Tomasz Napierala uint8_t bhssc_cdb[16]; 106009ea47eSEdward Tomasz Napierala }; 107009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_scsi_command) == ISCSI_BHS_SIZE); 108009ea47eSEdward Tomasz Napierala 109009ea47eSEdward Tomasz Napierala #define BHSSR_FLAGS_RESIDUAL_UNDERFLOW 0x02 110009ea47eSEdward Tomasz Napierala #define BHSSR_FLAGS_RESIDUAL_OVERFLOW 0x04 111009ea47eSEdward Tomasz Napierala 112009ea47eSEdward Tomasz Napierala #define BHSSR_RESPONSE_COMMAND_COMPLETED 0x00 113009ea47eSEdward Tomasz Napierala 114009ea47eSEdward Tomasz Napierala struct iscsi_bhs_scsi_response { 115009ea47eSEdward Tomasz Napierala uint8_t bhssr_opcode; 116009ea47eSEdward Tomasz Napierala uint8_t bhssr_flags; 117009ea47eSEdward Tomasz Napierala uint8_t bhssr_response; 118009ea47eSEdward Tomasz Napierala uint8_t bhssr_status; 119009ea47eSEdward Tomasz Napierala uint8_t bhssr_total_ahs_len; 120009ea47eSEdward Tomasz Napierala uint8_t bhssr_data_segment_len[3]; 121bebf6a85SAlexander Motin uint16_t bhssr_status_qualifier; 122bebf6a85SAlexander Motin uint16_t bhssr_reserved; 123bebf6a85SAlexander Motin uint32_t bhssr_reserved2; 124009ea47eSEdward Tomasz Napierala uint32_t bhssr_initiator_task_tag; 125009ea47eSEdward Tomasz Napierala uint32_t bhssr_snack_tag; 126009ea47eSEdward Tomasz Napierala uint32_t bhssr_statsn; 127009ea47eSEdward Tomasz Napierala uint32_t bhssr_expcmdsn; 128009ea47eSEdward Tomasz Napierala uint32_t bhssr_maxcmdsn; 129009ea47eSEdward Tomasz Napierala uint32_t bhssr_expdatasn; 130009ea47eSEdward Tomasz Napierala uint32_t bhssr_bidirectional_read_residual_count; 131009ea47eSEdward Tomasz Napierala uint32_t bhssr_residual_count; 132009ea47eSEdward Tomasz Napierala }; 133009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_scsi_response) == ISCSI_BHS_SIZE); 134009ea47eSEdward Tomasz Napierala 135009ea47eSEdward Tomasz Napierala #define BHSTMR_FUNCTION_ABORT_TASK 1 136009ea47eSEdward Tomasz Napierala #define BHSTMR_FUNCTION_ABORT_TASK_SET 2 137009ea47eSEdward Tomasz Napierala #define BHSTMR_FUNCTION_CLEAR_ACA 3 138009ea47eSEdward Tomasz Napierala #define BHSTMR_FUNCTION_CLEAR_TASK_SET 4 139009ea47eSEdward Tomasz Napierala #define BHSTMR_FUNCTION_LOGICAL_UNIT_RESET 5 140009ea47eSEdward Tomasz Napierala #define BHSTMR_FUNCTION_TARGET_WARM_RESET 6 141009ea47eSEdward Tomasz Napierala #define BHSTMR_FUNCTION_TARGET_COLD_RESET 7 142009ea47eSEdward Tomasz Napierala #define BHSTMR_FUNCTION_TASK_REASSIGN 8 143bebf6a85SAlexander Motin #define BHSTMR_FUNCTION_QUERY_TASK 9 144bebf6a85SAlexander Motin #define BHSTMR_FUNCTION_QUERY_TASK_SET 10 145bebf6a85SAlexander Motin #define BHSTMR_FUNCTION_I_T_NEXUS_RESET 11 146bebf6a85SAlexander Motin #define BHSTMR_FUNCTION_QUERY_ASYNC_EVENT 12 147009ea47eSEdward Tomasz Napierala 148009ea47eSEdward Tomasz Napierala struct iscsi_bhs_task_management_request { 149009ea47eSEdward Tomasz Napierala uint8_t bhstmr_opcode; 150009ea47eSEdward Tomasz Napierala uint8_t bhstmr_function; 151009ea47eSEdward Tomasz Napierala uint8_t bhstmr_reserved[2]; 152009ea47eSEdward Tomasz Napierala uint8_t bhstmr_total_ahs_len; 153009ea47eSEdward Tomasz Napierala uint8_t bhstmr_data_segment_len[3]; 154009ea47eSEdward Tomasz Napierala uint64_t bhstmr_lun; 155009ea47eSEdward Tomasz Napierala uint32_t bhstmr_initiator_task_tag; 156009ea47eSEdward Tomasz Napierala uint32_t bhstmr_referenced_task_tag; 157009ea47eSEdward Tomasz Napierala uint32_t bhstmr_cmdsn; 158009ea47eSEdward Tomasz Napierala uint32_t bhstmr_expstatsn; 159009ea47eSEdward Tomasz Napierala uint32_t bhstmr_refcmdsn; 160009ea47eSEdward Tomasz Napierala uint32_t bhstmr_expdatasn; 161009ea47eSEdward Tomasz Napierala uint64_t bhstmr_reserved2; 162009ea47eSEdward Tomasz Napierala }; 163009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_task_management_request) == ISCSI_BHS_SIZE); 164009ea47eSEdward Tomasz Napierala 165009ea47eSEdward Tomasz Napierala #define BHSTMR_RESPONSE_FUNCTION_COMPLETE 0 166bebf6a85SAlexander Motin #define BHSTMR_RESPONSE_TASK_DOES_NOT_EXIST 1 167bebf6a85SAlexander Motin #define BHSTMR_RESPONSE_LUN_DOES_NOT_EXIST 2 168bebf6a85SAlexander Motin #define BHSTMR_RESPONSE_TASK_STILL_ALLEGIANT 3 169bebf6a85SAlexander Motin #define BHSTMR_RESPONSE_TASK_ALL_REASS_NOT_SUPP 4 170009ea47eSEdward Tomasz Napierala #define BHSTMR_RESPONSE_FUNCTION_NOT_SUPPORTED 5 171bebf6a85SAlexander Motin #define BHSTMR_RESPONSE_FUNCTION_AUTH_FAIL 6 172bebf6a85SAlexander Motin #define BHSTMR_RESPONSE_FUNCTION_SUCCEEDED 7 173bebf6a85SAlexander Motin #define BHSTMR_RESPONSE_FUNCTION_REJECTED 255 174009ea47eSEdward Tomasz Napierala 175009ea47eSEdward Tomasz Napierala struct iscsi_bhs_task_management_response { 176009ea47eSEdward Tomasz Napierala uint8_t bhstmr_opcode; 177009ea47eSEdward Tomasz Napierala uint8_t bhstmr_flags; 178009ea47eSEdward Tomasz Napierala uint8_t bhstmr_response; 179009ea47eSEdward Tomasz Napierala uint8_t bhstmr_reserved; 180009ea47eSEdward Tomasz Napierala uint8_t bhstmr_total_ahs_len; 181009ea47eSEdward Tomasz Napierala uint8_t bhstmr_data_segment_len[3]; 1824b0e5c9eSAlexander Motin uint8_t bhstmr_additional_reponse_information[3]; 1834b0e5c9eSAlexander Motin uint8_t bhstmr_reserved2[5]; 184009ea47eSEdward Tomasz Napierala uint32_t bhstmr_initiator_task_tag; 185009ea47eSEdward Tomasz Napierala uint32_t bhstmr_reserved3; 186009ea47eSEdward Tomasz Napierala uint32_t bhstmr_statsn; 187009ea47eSEdward Tomasz Napierala uint32_t bhstmr_expcmdsn; 188009ea47eSEdward Tomasz Napierala uint32_t bhstmr_maxcmdsn; 189009ea47eSEdward Tomasz Napierala uint8_t bhstmr_reserved4[12]; 190009ea47eSEdward Tomasz Napierala }; 191009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_task_management_response) == ISCSI_BHS_SIZE); 192009ea47eSEdward Tomasz Napierala 193009ea47eSEdward Tomasz Napierala #define BHSLR_FLAGS_TRANSIT 0x80 194009ea47eSEdward Tomasz Napierala #define BHSLR_FLAGS_CONTINUE 0x40 195009ea47eSEdward Tomasz Napierala 196009ea47eSEdward Tomasz Napierala #define BHSLR_STAGE_SECURITY_NEGOTIATION 0 197009ea47eSEdward Tomasz Napierala #define BHSLR_STAGE_OPERATIONAL_NEGOTIATION 1 198009ea47eSEdward Tomasz Napierala #define BHSLR_STAGE_FULL_FEATURE_PHASE 3 /* Yes, 3. */ 199009ea47eSEdward Tomasz Napierala 200009ea47eSEdward Tomasz Napierala struct iscsi_bhs_login_request { 201009ea47eSEdward Tomasz Napierala uint8_t bhslr_opcode; 202009ea47eSEdward Tomasz Napierala uint8_t bhslr_flags; 203009ea47eSEdward Tomasz Napierala uint8_t bhslr_version_max; 204009ea47eSEdward Tomasz Napierala uint8_t bhslr_version_min; 205009ea47eSEdward Tomasz Napierala uint8_t bhslr_total_ahs_len; 206009ea47eSEdward Tomasz Napierala uint8_t bhslr_data_segment_len[3]; 207009ea47eSEdward Tomasz Napierala uint8_t bhslr_isid[6]; 208009ea47eSEdward Tomasz Napierala uint16_t bhslr_tsih; 209009ea47eSEdward Tomasz Napierala uint32_t bhslr_initiator_task_tag; 210009ea47eSEdward Tomasz Napierala uint16_t bhslr_cid; 211009ea47eSEdward Tomasz Napierala uint16_t bhslr_reserved; 212009ea47eSEdward Tomasz Napierala uint32_t bhslr_cmdsn; 213009ea47eSEdward Tomasz Napierala uint32_t bhslr_expstatsn; 214009ea47eSEdward Tomasz Napierala uint8_t bhslr_reserved2[16]; 215009ea47eSEdward Tomasz Napierala }; 216009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_login_request) == ISCSI_BHS_SIZE); 217009ea47eSEdward Tomasz Napierala 218009ea47eSEdward Tomasz Napierala struct iscsi_bhs_login_response { 219009ea47eSEdward Tomasz Napierala uint8_t bhslr_opcode; 220009ea47eSEdward Tomasz Napierala uint8_t bhslr_flags; 221009ea47eSEdward Tomasz Napierala uint8_t bhslr_version_max; 222009ea47eSEdward Tomasz Napierala uint8_t bhslr_version_active; 223009ea47eSEdward Tomasz Napierala uint8_t bhslr_total_ahs_len; 224009ea47eSEdward Tomasz Napierala uint8_t bhslr_data_segment_len[3]; 225009ea47eSEdward Tomasz Napierala uint8_t bhslr_isid[6]; 226009ea47eSEdward Tomasz Napierala uint16_t bhslr_tsih; 227009ea47eSEdward Tomasz Napierala uint32_t bhslr_initiator_task_tag; 228009ea47eSEdward Tomasz Napierala uint32_t bhslr_reserved; 229009ea47eSEdward Tomasz Napierala uint32_t bhslr_statsn; 230009ea47eSEdward Tomasz Napierala uint32_t bhslr_expcmdsn; 231009ea47eSEdward Tomasz Napierala uint32_t bhslr_maxcmdsn; 232009ea47eSEdward Tomasz Napierala uint8_t bhslr_status_class; 233009ea47eSEdward Tomasz Napierala uint8_t bhslr_status_detail; 234009ea47eSEdward Tomasz Napierala uint16_t bhslr_reserved2; 235009ea47eSEdward Tomasz Napierala uint8_t bhslr_reserved3[8]; 236009ea47eSEdward Tomasz Napierala }; 237009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_login_response) == ISCSI_BHS_SIZE); 238009ea47eSEdward Tomasz Napierala 239009ea47eSEdward Tomasz Napierala #define BHSTR_FLAGS_FINAL 0x80 240009ea47eSEdward Tomasz Napierala #define BHSTR_FLAGS_CONTINUE 0x40 241009ea47eSEdward Tomasz Napierala 242009ea47eSEdward Tomasz Napierala struct iscsi_bhs_text_request { 243009ea47eSEdward Tomasz Napierala uint8_t bhstr_opcode; 244009ea47eSEdward Tomasz Napierala uint8_t bhstr_flags; 245009ea47eSEdward Tomasz Napierala uint16_t bhstr_reserved; 246009ea47eSEdward Tomasz Napierala uint8_t bhstr_total_ahs_len; 247009ea47eSEdward Tomasz Napierala uint8_t bhstr_data_segment_len[3]; 248009ea47eSEdward Tomasz Napierala uint64_t bhstr_lun; 249009ea47eSEdward Tomasz Napierala uint32_t bhstr_initiator_task_tag; 250009ea47eSEdward Tomasz Napierala uint32_t bhstr_target_transfer_tag; 251009ea47eSEdward Tomasz Napierala uint32_t bhstr_cmdsn; 252009ea47eSEdward Tomasz Napierala uint32_t bhstr_expstatsn; 253009ea47eSEdward Tomasz Napierala uint8_t bhstr_reserved2[16]; 254009ea47eSEdward Tomasz Napierala }; 255009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_text_request) == ISCSI_BHS_SIZE); 256009ea47eSEdward Tomasz Napierala 257009ea47eSEdward Tomasz Napierala struct iscsi_bhs_text_response { 258009ea47eSEdward Tomasz Napierala uint8_t bhstr_opcode; 259009ea47eSEdward Tomasz Napierala uint8_t bhstr_flags; 260009ea47eSEdward Tomasz Napierala uint16_t bhstr_reserved; 261009ea47eSEdward Tomasz Napierala uint8_t bhstr_total_ahs_len; 262009ea47eSEdward Tomasz Napierala uint8_t bhstr_data_segment_len[3]; 263009ea47eSEdward Tomasz Napierala uint64_t bhstr_lun; 264009ea47eSEdward Tomasz Napierala uint32_t bhstr_initiator_task_tag; 265009ea47eSEdward Tomasz Napierala uint32_t bhstr_target_transfer_tag; 266009ea47eSEdward Tomasz Napierala uint32_t bhstr_statsn; 267009ea47eSEdward Tomasz Napierala uint32_t bhstr_expcmdsn; 268009ea47eSEdward Tomasz Napierala uint32_t bhstr_maxcmdsn; 269009ea47eSEdward Tomasz Napierala uint8_t bhstr_reserved2[12]; 270009ea47eSEdward Tomasz Napierala }; 271009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_text_response) == ISCSI_BHS_SIZE); 272009ea47eSEdward Tomasz Napierala 273009ea47eSEdward Tomasz Napierala #define BHSDO_FLAGS_F 0x80 274009ea47eSEdward Tomasz Napierala 275009ea47eSEdward Tomasz Napierala struct iscsi_bhs_data_out { 276009ea47eSEdward Tomasz Napierala uint8_t bhsdo_opcode; 277009ea47eSEdward Tomasz Napierala uint8_t bhsdo_flags; 278009ea47eSEdward Tomasz Napierala uint8_t bhsdo_reserved[2]; 279009ea47eSEdward Tomasz Napierala uint8_t bhsdo_total_ahs_len; 280009ea47eSEdward Tomasz Napierala uint8_t bhsdo_data_segment_len[3]; 281009ea47eSEdward Tomasz Napierala uint64_t bhsdo_lun; 282009ea47eSEdward Tomasz Napierala uint32_t bhsdo_initiator_task_tag; 283009ea47eSEdward Tomasz Napierala uint32_t bhsdo_target_transfer_tag; 284009ea47eSEdward Tomasz Napierala uint32_t bhsdo_reserved2; 285009ea47eSEdward Tomasz Napierala uint32_t bhsdo_expstatsn; 286009ea47eSEdward Tomasz Napierala uint32_t bhsdo_reserved3; 287009ea47eSEdward Tomasz Napierala uint32_t bhsdo_datasn; 288009ea47eSEdward Tomasz Napierala uint32_t bhsdo_buffer_offset; 289009ea47eSEdward Tomasz Napierala uint32_t bhsdo_reserved4; 290009ea47eSEdward Tomasz Napierala }; 291009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_data_out) == ISCSI_BHS_SIZE); 292009ea47eSEdward Tomasz Napierala 293009ea47eSEdward Tomasz Napierala #define BHSDI_FLAGS_F 0x80 294009ea47eSEdward Tomasz Napierala #define BHSDI_FLAGS_A 0x40 295009ea47eSEdward Tomasz Napierala #define BHSDI_FLAGS_O 0x04 296009ea47eSEdward Tomasz Napierala #define BHSDI_FLAGS_U 0x02 297009ea47eSEdward Tomasz Napierala #define BHSDI_FLAGS_S 0x01 298009ea47eSEdward Tomasz Napierala 299009ea47eSEdward Tomasz Napierala struct iscsi_bhs_data_in { 300009ea47eSEdward Tomasz Napierala uint8_t bhsdi_opcode; 301009ea47eSEdward Tomasz Napierala uint8_t bhsdi_flags; 302009ea47eSEdward Tomasz Napierala uint8_t bhsdi_reserved; 303009ea47eSEdward Tomasz Napierala uint8_t bhsdi_status; 304009ea47eSEdward Tomasz Napierala uint8_t bhsdi_total_ahs_len; 305009ea47eSEdward Tomasz Napierala uint8_t bhsdi_data_segment_len[3]; 306009ea47eSEdward Tomasz Napierala uint64_t bhsdi_lun; 307009ea47eSEdward Tomasz Napierala uint32_t bhsdi_initiator_task_tag; 308009ea47eSEdward Tomasz Napierala uint32_t bhsdi_target_transfer_tag; 309009ea47eSEdward Tomasz Napierala uint32_t bhsdi_statsn; 310009ea47eSEdward Tomasz Napierala uint32_t bhsdi_expcmdsn; 311009ea47eSEdward Tomasz Napierala uint32_t bhsdi_maxcmdsn; 312009ea47eSEdward Tomasz Napierala uint32_t bhsdi_datasn; 313009ea47eSEdward Tomasz Napierala uint32_t bhsdi_buffer_offset; 314009ea47eSEdward Tomasz Napierala uint32_t bhsdi_residual_count; 315009ea47eSEdward Tomasz Napierala }; 316009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_data_in) == ISCSI_BHS_SIZE); 317009ea47eSEdward Tomasz Napierala 318009ea47eSEdward Tomasz Napierala struct iscsi_bhs_r2t { 319009ea47eSEdward Tomasz Napierala uint8_t bhsr2t_opcode; 320009ea47eSEdward Tomasz Napierala uint8_t bhsr2t_flags; 321009ea47eSEdward Tomasz Napierala uint16_t bhsr2t_reserved; 322009ea47eSEdward Tomasz Napierala uint8_t bhsr2t_total_ahs_len; 323009ea47eSEdward Tomasz Napierala uint8_t bhsr2t_data_segment_len[3]; 324009ea47eSEdward Tomasz Napierala uint64_t bhsr2t_lun; 325009ea47eSEdward Tomasz Napierala uint32_t bhsr2t_initiator_task_tag; 326009ea47eSEdward Tomasz Napierala uint32_t bhsr2t_target_transfer_tag; 327009ea47eSEdward Tomasz Napierala uint32_t bhsr2t_statsn; 328009ea47eSEdward Tomasz Napierala uint32_t bhsr2t_expcmdsn; 329009ea47eSEdward Tomasz Napierala uint32_t bhsr2t_maxcmdsn; 330009ea47eSEdward Tomasz Napierala uint32_t bhsr2t_r2tsn; 331009ea47eSEdward Tomasz Napierala uint32_t bhsr2t_buffer_offset; 332009ea47eSEdward Tomasz Napierala uint32_t bhsr2t_desired_data_transfer_length; 333009ea47eSEdward Tomasz Napierala }; 334009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_r2t) == ISCSI_BHS_SIZE); 335009ea47eSEdward Tomasz Napierala 336009ea47eSEdward Tomasz Napierala struct iscsi_bhs_nop_out { 337009ea47eSEdward Tomasz Napierala uint8_t bhsno_opcode; 338009ea47eSEdward Tomasz Napierala uint8_t bhsno_flags; 339009ea47eSEdward Tomasz Napierala uint16_t bhsno_reserved; 340009ea47eSEdward Tomasz Napierala uint8_t bhsno_total_ahs_len; 341009ea47eSEdward Tomasz Napierala uint8_t bhsno_data_segment_len[3]; 342009ea47eSEdward Tomasz Napierala uint64_t bhsno_lun; 343009ea47eSEdward Tomasz Napierala uint32_t bhsno_initiator_task_tag; 344009ea47eSEdward Tomasz Napierala uint32_t bhsno_target_transfer_tag; 345009ea47eSEdward Tomasz Napierala uint32_t bhsno_cmdsn; 346009ea47eSEdward Tomasz Napierala uint32_t bhsno_expstatsn; 347009ea47eSEdward Tomasz Napierala uint8_t bhsno_reserved2[16]; 348009ea47eSEdward Tomasz Napierala }; 349009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_nop_out) == ISCSI_BHS_SIZE); 350009ea47eSEdward Tomasz Napierala 351009ea47eSEdward Tomasz Napierala struct iscsi_bhs_nop_in { 352009ea47eSEdward Tomasz Napierala uint8_t bhsni_opcode; 353009ea47eSEdward Tomasz Napierala uint8_t bhsni_flags; 354009ea47eSEdward Tomasz Napierala uint16_t bhsni_reserved; 355009ea47eSEdward Tomasz Napierala uint8_t bhsni_total_ahs_len; 356009ea47eSEdward Tomasz Napierala uint8_t bhsni_data_segment_len[3]; 357009ea47eSEdward Tomasz Napierala uint64_t bhsni_lun; 358009ea47eSEdward Tomasz Napierala uint32_t bhsni_initiator_task_tag; 359009ea47eSEdward Tomasz Napierala uint32_t bhsni_target_transfer_tag; 360009ea47eSEdward Tomasz Napierala uint32_t bhsni_statsn; 361009ea47eSEdward Tomasz Napierala uint32_t bhsni_expcmdsn; 362009ea47eSEdward Tomasz Napierala uint32_t bhsni_maxcmdsn; 363009ea47eSEdward Tomasz Napierala uint8_t bhsno_reserved2[12]; 364009ea47eSEdward Tomasz Napierala }; 365009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_nop_in) == ISCSI_BHS_SIZE); 366009ea47eSEdward Tomasz Napierala 367009ea47eSEdward Tomasz Napierala #define BHSLR_REASON_CLOSE_SESSION 0 368009ea47eSEdward Tomasz Napierala #define BHSLR_REASON_CLOSE_CONNECTION 1 369009ea47eSEdward Tomasz Napierala #define BHSLR_REASON_REMOVE_FOR_RECOVERY 2 370009ea47eSEdward Tomasz Napierala 371009ea47eSEdward Tomasz Napierala struct iscsi_bhs_logout_request { 372009ea47eSEdward Tomasz Napierala uint8_t bhslr_opcode; 373009ea47eSEdward Tomasz Napierala uint8_t bhslr_reason; 374009ea47eSEdward Tomasz Napierala uint16_t bhslr_reserved; 375009ea47eSEdward Tomasz Napierala uint8_t bhslr_total_ahs_len; 376009ea47eSEdward Tomasz Napierala uint8_t bhslr_data_segment_len[3]; 377009ea47eSEdward Tomasz Napierala uint64_t bhslr_reserved2; 378009ea47eSEdward Tomasz Napierala uint32_t bhslr_initiator_task_tag; 379009ea47eSEdward Tomasz Napierala uint16_t bhslr_cid; 380009ea47eSEdward Tomasz Napierala uint16_t bhslr_reserved3; 381009ea47eSEdward Tomasz Napierala uint32_t bhslr_cmdsn; 382009ea47eSEdward Tomasz Napierala uint32_t bhslr_expstatsn; 383009ea47eSEdward Tomasz Napierala uint8_t bhslr_reserved4[16]; 384009ea47eSEdward Tomasz Napierala }; 385009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_logout_request) == ISCSI_BHS_SIZE); 386009ea47eSEdward Tomasz Napierala 387009ea47eSEdward Tomasz Napierala #define BHSLR_RESPONSE_CLOSED_SUCCESSFULLY 0 388009ea47eSEdward Tomasz Napierala #define BHSLR_RESPONSE_RECOVERY_NOT_SUPPORTED 2 389009ea47eSEdward Tomasz Napierala 390009ea47eSEdward Tomasz Napierala struct iscsi_bhs_logout_response { 391009ea47eSEdward Tomasz Napierala uint8_t bhslr_opcode; 392009ea47eSEdward Tomasz Napierala uint8_t bhslr_flags; 393009ea47eSEdward Tomasz Napierala uint8_t bhslr_response; 394009ea47eSEdward Tomasz Napierala uint8_t bhslr_reserved; 395009ea47eSEdward Tomasz Napierala uint8_t bhslr_total_ahs_len; 396009ea47eSEdward Tomasz Napierala uint8_t bhslr_data_segment_len[3]; 397009ea47eSEdward Tomasz Napierala uint64_t bhslr_reserved2; 398009ea47eSEdward Tomasz Napierala uint32_t bhslr_initiator_task_tag; 399009ea47eSEdward Tomasz Napierala uint32_t bhslr_reserved3; 400009ea47eSEdward Tomasz Napierala uint32_t bhslr_statsn; 401009ea47eSEdward Tomasz Napierala uint32_t bhslr_expcmdsn; 402009ea47eSEdward Tomasz Napierala uint32_t bhslr_maxcmdsn; 403009ea47eSEdward Tomasz Napierala uint32_t bhslr_reserved4; 404009ea47eSEdward Tomasz Napierala uint16_t bhslr_time2wait; 405009ea47eSEdward Tomasz Napierala uint16_t bhslr_time2retain; 406009ea47eSEdward Tomasz Napierala uint32_t bhslr_reserved5; 407009ea47eSEdward Tomasz Napierala }; 408009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_logout_response) == ISCSI_BHS_SIZE); 409009ea47eSEdward Tomasz Napierala 410009ea47eSEdward Tomasz Napierala #define BHSAM_EVENT_TARGET_REQUESTS_LOGOUT 1 411009ea47eSEdward Tomasz Napierala #define BHSAM_EVENT_TARGET_TERMINATES_CONNECTION 2 412009ea47eSEdward Tomasz Napierala #define BHSAM_EVENT_TARGET_TERMINATES_SESSION 3 413009ea47eSEdward Tomasz Napierala 414009ea47eSEdward Tomasz Napierala struct iscsi_bhs_asynchronous_message { 415009ea47eSEdward Tomasz Napierala uint8_t bhsam_opcode; 416009ea47eSEdward Tomasz Napierala uint8_t bhsam_flags; 417009ea47eSEdward Tomasz Napierala uint16_t bhsam_reserved; 418009ea47eSEdward Tomasz Napierala uint8_t bhsam_total_ahs_len; 419009ea47eSEdward Tomasz Napierala uint8_t bhsam_data_segment_len[3]; 420009ea47eSEdward Tomasz Napierala uint64_t bhsam_lun; 421009ea47eSEdward Tomasz Napierala uint32_t bhsam_0xffffffff; 422009ea47eSEdward Tomasz Napierala uint32_t bhsam_reserved2; 423009ea47eSEdward Tomasz Napierala uint32_t bhsam_statsn; 424009ea47eSEdward Tomasz Napierala uint32_t bhsam_expcmdsn; 425009ea47eSEdward Tomasz Napierala uint32_t bhsam_maxcmdsn; 426009ea47eSEdward Tomasz Napierala uint8_t bhsam_async_event; 427009ea47eSEdward Tomasz Napierala uint8_t bhsam_async_vcode; 428009ea47eSEdward Tomasz Napierala uint16_t bhsam_parameter1; 429009ea47eSEdward Tomasz Napierala uint16_t bhsam_parameter2; 430009ea47eSEdward Tomasz Napierala uint16_t bhsam_parameter3; 431009ea47eSEdward Tomasz Napierala uint32_t bhsam_reserved3; 432009ea47eSEdward Tomasz Napierala }; 433009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_asynchronous_message) == ISCSI_BHS_SIZE); 434009ea47eSEdward Tomasz Napierala 435009ea47eSEdward Tomasz Napierala #define BHSSR_REASON_DATA_DIGEST_ERROR 0x02 436009ea47eSEdward Tomasz Napierala #define BHSSR_PROTOCOL_ERROR 0x04 437009ea47eSEdward Tomasz Napierala #define BHSSR_COMMAND_NOT_SUPPORTED 0x05 438009ea47eSEdward Tomasz Napierala #define BHSSR_INVALID_PDU_FIELD 0x09 439009ea47eSEdward Tomasz Napierala 440009ea47eSEdward Tomasz Napierala struct iscsi_bhs_reject { 441009ea47eSEdward Tomasz Napierala uint8_t bhsr_opcode; 442009ea47eSEdward Tomasz Napierala uint8_t bhsr_flags; 443009ea47eSEdward Tomasz Napierala uint8_t bhsr_reason; 444009ea47eSEdward Tomasz Napierala uint8_t bhsr_reserved; 445009ea47eSEdward Tomasz Napierala uint8_t bhsr_total_ahs_len; 446009ea47eSEdward Tomasz Napierala uint8_t bhsr_data_segment_len[3]; 447009ea47eSEdward Tomasz Napierala uint64_t bhsr_reserved2; 448009ea47eSEdward Tomasz Napierala uint32_t bhsr_0xffffffff; 449009ea47eSEdward Tomasz Napierala uint32_t bhsr_reserved3; 450009ea47eSEdward Tomasz Napierala uint32_t bhsr_statsn; 451009ea47eSEdward Tomasz Napierala uint32_t bhsr_expcmdsn; 452009ea47eSEdward Tomasz Napierala uint32_t bhsr_maxcmdsn; 453009ea47eSEdward Tomasz Napierala uint32_t bhsr_datasn_r2tsn; 454009ea47eSEdward Tomasz Napierala uint32_t bhsr_reserved4; 455009ea47eSEdward Tomasz Napierala uint32_t bhsr_reserved5; 456009ea47eSEdward Tomasz Napierala }; 457009ea47eSEdward Tomasz Napierala CTASSERT(sizeof(struct iscsi_bhs_reject) == ISCSI_BHS_SIZE); 458009ea47eSEdward Tomasz Napierala 459009ea47eSEdward Tomasz Napierala #endif /* !ISCSI_PROTO_H */ 460