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