iscsi_pdu.h revision 1.2 1 1.2 dholland /* $NetBSD: iscsi_pdu.h,v 1.2 2014/06/21 03:42:52 dholland Exp $ */
2 1.1 agc
3 1.1 agc /*-
4 1.1 agc * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
5 1.1 agc * All rights reserved.
6 1.1 agc *
7 1.1 agc * This code is derived from software contributed to The NetBSD Foundation
8 1.1 agc * by Wasabi Systems, Inc.
9 1.1 agc *
10 1.1 agc * Redistribution and use in source and binary forms, with or without
11 1.1 agc * modification, are permitted provided that the following conditions
12 1.1 agc * are met:
13 1.1 agc * 1. Redistributions of source code must retain the above copyright
14 1.1 agc * notice, this list of conditions and the following disclaimer.
15 1.1 agc * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 agc * notice, this list of conditions and the following disclaimer in the
17 1.1 agc * documentation and/or other materials provided with the distribution.
18 1.1 agc *
19 1.1 agc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 agc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 agc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 agc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 agc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 agc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 agc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 agc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 agc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 agc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 agc * POSSIBILITY OF SUCH DAMAGE.
30 1.1 agc */
31 1.1 agc #ifndef _ISCSI_PDU_H
32 1.1 agc #define _ISCSI_PDU_H
33 1.1 agc
34 1.1 agc #define BHS_SIZE 48 /* Basic Header Segment (without digest) */
35 1.1 agc #define PDU_HEADER_SIZE 52 /* PDU Header with Digest */
36 1.1 agc
37 1.1 agc #define OP_IMMEDIATE 0x40 /* Bit 1 in Opcode field: immediate delivery */
38 1.1 agc #define OPCODE_MASK 0x3f /* Mask for opcode */
39 1.1 agc
40 1.1 agc /* PDU Flags field */
41 1.1 agc
42 1.1 agc #define FLAG_FINAL 0x80 /* Bit 0: Final PDU in sequence */
43 1.1 agc #define FLAG_TRANSIT 0x80 /* Bit 0: Transit to next login phase */
44 1.1 agc #define FLAG_CONTINUE 0x40 /* Bit 1: Continue PDU */
45 1.1 agc #define FLAG_ACK 0x40 /* Bit 1: Acknowledge */
46 1.1 agc #define FLAG_READ 0x40 /* Bit 1: Read Data */
47 1.1 agc #define FLAG_WRITE 0x20 /* Bit 2: Write Data */
48 1.1 agc #define FLAG_BIDI_OFLO 0x10 /* Bit 3: Bidirectional Read Residual Oflow */
49 1.1 agc #define FLAG_BIDI_UFLOW 0x08 /* Bit 4: Bidirectional Read Residual Uflow */
50 1.1 agc #define FLAG_OVERFLOW 0x04 /* Bit 5: Residual Overflow */
51 1.1 agc #define FLAG_UNDERFLOW 0x02 /* Bit 6: Residual Underflow */
52 1.1 agc #define FLAG_STATUS 0x01 /* Bit 7: Command Status is valid */
53 1.1 agc
54 1.1 agc /* CSG/NSG flag field codes */
55 1.1 agc
56 1.1 agc #define SG_SECURITY_NEGOTIATION 0
57 1.1 agc #define SG_LOGIN_OPERATIONAL_NEGOTIATION 1
58 1.1 agc #define SG_FULL_FEATURE_PHASE 3
59 1.1 agc
60 1.1 agc #define CSG_SHIFT 2 /* shift factor for CSG field */
61 1.1 agc #define SG_MASK 3 /* mask for CSG (after shift) and NSG */
62 1.1 agc
63 1.1 agc #define NEXT_PHASE(ph) ((!ph) ? 1 : 3) /* no phase 2 */
64 1.1 agc
65 1.1 agc /* Task Management Function Codes (in Flags byte) */
66 1.1 agc
67 1.1 agc #define ABORT_TASK 1
68 1.1 agc #define ABORT_TASK_SET 2
69 1.1 agc #define CLEAR_ACA 3
70 1.1 agc #define CLEAR_TASK_SET 4
71 1.1 agc #define LOGICAL_UNIT_RESET 5
72 1.1 agc #define TARGET_WARM_RESET 6
73 1.1 agc #define TARGET_COLD_RESET 7
74 1.1 agc #define TASK_REASSIGN 8
75 1.1 agc
76 1.1 agc /* ISID T-Field (first byte) */
77 1.1 agc
78 1.1 agc #define T_FORMAT_OUI 0x00
79 1.1 agc #define T_FORMAT_EN 0x40
80 1.1 agc #define T_FORMAT_RANDOM 0x80
81 1.1 agc
82 1.1 agc
83 1.1 agc /* Task Attributes */
84 1.1 agc
85 1.1 agc #define ATTR_UNTAGGED 0
86 1.1 agc #define ATTR_SIMPLE 1
87 1.1 agc #define ATTR_ORDERED 2
88 1.1 agc #define ATTR_HEAD_OF_QUEUE 3
89 1.1 agc #define ATTR_ACA 4
90 1.1 agc
91 1.1 agc /* Initiator Opcodes */
92 1.1 agc
93 1.1 agc #define IOP_NOP_Out 0x00
94 1.1 agc #define IOP_SCSI_Command 0x01
95 1.1 agc #define IOP_SCSI_Task_Management 0x02
96 1.1 agc #define IOP_Login_Request 0x03
97 1.1 agc #define IOP_Text_Request 0x04
98 1.1 agc #define IOP_SCSI_Data_out 0x05
99 1.1 agc #define IOP_Logout_Request 0x06
100 1.1 agc #define IOP_SNACK_Request 0x10
101 1.1 agc
102 1.1 agc /* Target Opcodes */
103 1.1 agc
104 1.1 agc #define TOP_NOP_In 0x20
105 1.1 agc #define TOP_SCSI_Response 0x21
106 1.1 agc #define TOP_SCSI_Task_Management 0x22
107 1.1 agc #define TOP_Login_Response 0x23
108 1.1 agc #define TOP_Text_Response 0x24
109 1.1 agc #define TOP_SCSI_Data_in 0x25
110 1.1 agc #define TOP_Logout_Response 0x26
111 1.1 agc #define TOP_R2T 0x31
112 1.1 agc #define TOP_Asynchronous_Message 0x32
113 1.1 agc #define TOP_Reject 0x3f
114 1.1 agc
115 1.1 agc /*
116 1.1 agc * The Opcode-dependent fields of the BHS, defined per PDU
117 1.1 agc */
118 1.1 agc
119 1.1 agc /* Command + Response */
120 1.1 agc
121 1.1 agc struct scsi_command_pdu_s
122 1.1 agc {
123 1.1 agc uint32_t ExpectedDataTransferLength;
124 1.1 agc uint32_t CmdSN;
125 1.1 agc uint32_t ExpStatSN;
126 1.1 agc uint8_t SCSI_CDB[16];
127 1.2 dholland } __packed;
128 1.1 agc
129 1.1 agc typedef struct scsi_command_pdu_s scsi_command_pdu_t;
130 1.1 agc
131 1.1 agc struct scsi_response_pdu_s
132 1.1 agc {
133 1.1 agc uint32_t SNACKTag;
134 1.1 agc uint32_t StatSN;
135 1.1 agc uint32_t ExpCmdSN;
136 1.1 agc uint32_t MaxCmdSN;
137 1.1 agc uint32_t ExpStatSN;
138 1.1 agc uint32_t ReadResidualCount;
139 1.1 agc uint32_t ResidualCount;
140 1.2 dholland } __packed;
141 1.1 agc
142 1.1 agc typedef struct scsi_response_pdu_s scsi_response_pdu_t;
143 1.1 agc
144 1.1 agc
145 1.1 agc /* Task Management */
146 1.1 agc
147 1.1 agc struct task_management_req_pdu_s
148 1.1 agc {
149 1.1 agc uint32_t ReferencedTaskTag;
150 1.1 agc uint32_t CmdSN;
151 1.1 agc uint32_t ExpStatSN;
152 1.1 agc uint32_t RefCmdSN;
153 1.1 agc uint32_t ExpDataSN;
154 1.1 agc uint8_t reserved[8];
155 1.2 dholland } __packed;
156 1.1 agc
157 1.1 agc typedef struct task_management_req_pdu_s task_management_req_pdu_t;
158 1.1 agc
159 1.1 agc
160 1.1 agc struct task_management_rsp_pdu_s
161 1.1 agc {
162 1.1 agc uint32_t reserved1;
163 1.1 agc uint32_t StatSN;
164 1.1 agc uint32_t ExpCmdSN;
165 1.1 agc uint32_t MaxCmdSN;
166 1.1 agc uint8_t reserved2[12];
167 1.2 dholland } __packed;
168 1.1 agc
169 1.1 agc typedef struct task_management_rsp_pdu_s task_management_rsp_pdu_t;
170 1.1 agc
171 1.1 agc
172 1.1 agc /* Data Out & In, R2T */
173 1.1 agc
174 1.1 agc struct data_out_pdu_s
175 1.1 agc {
176 1.1 agc uint32_t TargetTransferTag;
177 1.1 agc uint32_t reserved1;
178 1.1 agc uint32_t ExpStatSN;
179 1.1 agc uint32_t reserved2;
180 1.1 agc uint32_t DataSN;
181 1.1 agc uint32_t BufferOffset;
182 1.1 agc uint32_t reserved3;
183 1.2 dholland } __packed;
184 1.1 agc
185 1.1 agc typedef struct data_out_pdu_s data_out_pdu_t;
186 1.1 agc
187 1.1 agc
188 1.1 agc struct data_in_pdu_s
189 1.1 agc {
190 1.1 agc uint32_t TargetTransferTag;
191 1.1 agc uint32_t StatSN;
192 1.1 agc uint32_t ExpCmdSN;
193 1.1 agc uint32_t MaxCmdSN;
194 1.1 agc uint32_t DataSN;
195 1.1 agc uint32_t BufferOffset;
196 1.1 agc uint32_t ResidualCount;
197 1.2 dholland } __packed;
198 1.1 agc
199 1.1 agc typedef struct data_in_pdu_s data_in_pdu_t;
200 1.1 agc
201 1.1 agc
202 1.1 agc struct r2t_pdu_s
203 1.1 agc {
204 1.1 agc uint32_t TargetTransferTag;
205 1.1 agc uint32_t StatSN;
206 1.1 agc uint32_t ExpCmdSN;
207 1.1 agc uint32_t MaxCmdSN;
208 1.1 agc uint32_t R2TSN;
209 1.1 agc uint32_t BufferOffset;
210 1.1 agc uint32_t DesiredDataTransferLength;
211 1.2 dholland } __packed;
212 1.1 agc
213 1.1 agc typedef struct r2t_pdu_s r2t_pdu_t;
214 1.1 agc
215 1.1 agc
216 1.1 agc /* Asynch message */
217 1.1 agc
218 1.1 agc struct asynch_pdu_s
219 1.1 agc {
220 1.1 agc uint32_t reserved1;
221 1.1 agc uint32_t StatSN;
222 1.1 agc uint32_t ExpCmdSN;
223 1.1 agc uint32_t MaxCmdSN;
224 1.1 agc uint8_t AsyncEvent;
225 1.1 agc uint8_t AsyncVCode;
226 1.1 agc uint16_t Parameter1;
227 1.1 agc uint16_t Parameter2;
228 1.1 agc uint16_t Parameter3;
229 1.1 agc uint32_t reserved2;
230 1.2 dholland } __packed;
231 1.1 agc
232 1.1 agc typedef struct asynch_pdu_s asynch_pdu_t;
233 1.1 agc
234 1.1 agc
235 1.1 agc /* Text request / response */
236 1.1 agc
237 1.1 agc struct text_req_pdu_s
238 1.1 agc {
239 1.1 agc uint32_t TargetTransferTag;
240 1.1 agc uint32_t CmdSN;
241 1.1 agc uint32_t ExpStatSN;
242 1.1 agc uint8_t reserved[16];
243 1.2 dholland } __packed;
244 1.1 agc
245 1.1 agc typedef struct text_req_pdu_s text_req_pdu_t;
246 1.1 agc
247 1.1 agc
248 1.1 agc struct text_rsp_pdu_s
249 1.1 agc {
250 1.1 agc uint32_t TargetTransferTag;
251 1.1 agc uint32_t StatSN;
252 1.1 agc uint32_t ExpCmdSN;
253 1.1 agc uint32_t MaxCmdSN;
254 1.1 agc uint8_t reserved[12];
255 1.2 dholland } __packed;
256 1.1 agc
257 1.1 agc typedef struct text_rsp_pdu_s text_rsp_pdu_t;
258 1.1 agc
259 1.1 agc
260 1.1 agc /* Login request / response */
261 1.1 agc
262 1.1 agc struct login_req_pdu_s
263 1.1 agc {
264 1.1 agc uint16_t CID;
265 1.1 agc uint16_t reserved1;
266 1.1 agc uint32_t CmdSN;
267 1.1 agc uint32_t ExpStatSN;
268 1.1 agc uint8_t reserved2[16];
269 1.2 dholland } __packed;
270 1.1 agc
271 1.1 agc typedef struct login_req_pdu_s login_req_pdu_t;
272 1.1 agc
273 1.1 agc /* Overlays LUN field in login request and response */
274 1.1 agc struct login_isid_s
275 1.1 agc {
276 1.1 agc uint8_t ISID_A;
277 1.1 agc uint16_t ISID_B;
278 1.1 agc uint8_t ISID_C;
279 1.1 agc uint16_t ISID_D;
280 1.1 agc uint16_t TSIH;
281 1.2 dholland } __packed;
282 1.1 agc
283 1.1 agc typedef struct login_isid_s login_isid_t;
284 1.1 agc
285 1.1 agc struct login_rsp_pdu_s
286 1.1 agc {
287 1.1 agc uint32_t reserved1;
288 1.1 agc uint32_t StatSN;
289 1.1 agc uint32_t ExpCmdSN;
290 1.1 agc uint32_t MaxCmdSN;
291 1.1 agc uint8_t StatusClass;
292 1.1 agc uint8_t StatusDetail;
293 1.1 agc uint8_t reserved2[10];
294 1.2 dholland } __packed;
295 1.1 agc
296 1.1 agc typedef struct login_rsp_pdu_s login_rsp_pdu_t;
297 1.1 agc
298 1.1 agc
299 1.1 agc /* Logout request / response */
300 1.1 agc
301 1.1 agc struct logout_req_pdu_s
302 1.1 agc {
303 1.1 agc uint16_t CID;
304 1.1 agc uint16_t reserved2;
305 1.1 agc uint32_t CmdSN;
306 1.1 agc uint32_t ExpStatSN;
307 1.1 agc uint8_t reserved3[16];
308 1.2 dholland } __packed;
309 1.1 agc
310 1.1 agc typedef struct logout_req_pdu_s logout_req_pdu_t;
311 1.1 agc
312 1.1 agc
313 1.1 agc struct logout_rsp_pdu_s
314 1.1 agc {
315 1.1 agc uint32_t reserved2;
316 1.1 agc uint32_t StatSN;
317 1.1 agc uint32_t ExpCmdSN;
318 1.1 agc uint32_t MaxCmdSN;
319 1.1 agc uint32_t reserved3;
320 1.1 agc uint16_t Time2Wait;
321 1.1 agc uint16_t Time2Retain;
322 1.1 agc uint32_t reserved4;
323 1.2 dholland } __packed;
324 1.1 agc
325 1.1 agc typedef struct logout_rsp_pdu_s logout_rsp_pdu_t;
326 1.1 agc
327 1.1 agc
328 1.1 agc /* SNACK request */
329 1.1 agc
330 1.1 agc /* SNACK Types (in Flags field) */
331 1.1 agc
332 1.1 agc #define SNACK_DATA_NAK 0
333 1.1 agc #define SNACK_STATUS_NAK 1
334 1.1 agc #define SNACK_DATA_ACK 2
335 1.1 agc #define SNACK_RDATA_NAK 3
336 1.1 agc
337 1.1 agc struct snack_req_pdu_s
338 1.1 agc {
339 1.1 agc uint32_t TargetTransferTag;
340 1.1 agc uint32_t reserved1;
341 1.1 agc uint32_t ExpStatSN;
342 1.1 agc uint8_t reserved2[8];
343 1.1 agc uint32_t BegRun;
344 1.1 agc uint32_t RunLength;
345 1.2 dholland } __packed;
346 1.1 agc
347 1.1 agc typedef struct snack_req_pdu_s snack_req_pdu_t;
348 1.1 agc
349 1.1 agc
350 1.1 agc /* Reject */
351 1.1 agc
352 1.1 agc #define REJECT_DIGEST_ERROR 2
353 1.1 agc #define REJECT_SNACK 3
354 1.1 agc #define REJECT_PROTOCOL_ERROR 4
355 1.1 agc #define REJECT_CMD_NOT_SUPPORTED 5
356 1.1 agc #define REJECT_IMMED_COMMAND 6
357 1.1 agc #define REJECT_TASK_IN_PROGRESS 7
358 1.1 agc #define REJECT_INVALID_DATA_ACK 8
359 1.1 agc #define REJECT_INVALID_PDU_FIELD 9
360 1.1 agc #define REJECT_LONG_OPERATION 10
361 1.1 agc #define REJECT_NEGOTIATION_RESET 11
362 1.1 agc #define REJECT_WAITING_FOR_LOGOUT 12
363 1.1 agc
364 1.1 agc
365 1.1 agc struct reject_pdu_s
366 1.1 agc {
367 1.1 agc uint32_t reserved2;
368 1.1 agc uint32_t StatSN;
369 1.1 agc uint32_t ExpCmdSN;
370 1.1 agc uint32_t MaxCmdSN;
371 1.1 agc uint8_t DataSN;
372 1.1 agc uint8_t reserved[8];
373 1.2 dholland } __packed;
374 1.1 agc
375 1.1 agc typedef struct reject_pdu_s reject_pdu_t;
376 1.1 agc
377 1.1 agc
378 1.1 agc /* NOP Out & In */
379 1.1 agc
380 1.1 agc struct nop_out_pdu_s
381 1.1 agc {
382 1.1 agc uint32_t TargetTransferTag;
383 1.1 agc uint32_t CmdSN;
384 1.1 agc uint32_t ExpStatSN;
385 1.1 agc uint8_t reserved[16];
386 1.2 dholland } __packed;
387 1.1 agc
388 1.1 agc typedef struct nop_out_pdu_s nop_out_pdu_t;
389 1.1 agc
390 1.1 agc
391 1.1 agc struct nop_in_pdu_s
392 1.1 agc {
393 1.1 agc uint32_t TargetTransferTag;
394 1.1 agc uint32_t StatSN;
395 1.1 agc uint32_t ExpCmdSN;
396 1.1 agc uint32_t MaxCmdSN;
397 1.1 agc uint8_t reserved3[12];
398 1.2 dholland } __packed;
399 1.1 agc
400 1.1 agc typedef struct nop_in_pdu_s nop_in_pdu_t;
401 1.1 agc
402 1.1 agc
403 1.1 agc /*
404 1.1 agc * The complete PDU Header.
405 1.1 agc */
406 1.1 agc
407 1.1 agc struct pdu_header_s
408 1.1 agc {
409 1.1 agc uint8_t Opcode;
410 1.1 agc uint8_t Flags;
411 1.1 agc uint8_t OpcodeSpecific[2];
412 1.1 agc uint8_t TotalAHSLength;
413 1.1 agc uint8_t DataSegmentLength[3];
414 1.1 agc uint64_t LUN;
415 1.1 agc uint32_t InitiatorTaskTag;
416 1.1 agc union
417 1.1 agc {
418 1.1 agc scsi_command_pdu_t command;
419 1.1 agc scsi_response_pdu_t response;
420 1.1 agc task_management_req_pdu_t task_req;
421 1.1 agc task_management_rsp_pdu_t task_rsp;
422 1.1 agc data_out_pdu_t data_out;
423 1.1 agc data_in_pdu_t data_in;
424 1.1 agc r2t_pdu_t r2t;
425 1.1 agc asynch_pdu_t asynch;
426 1.1 agc text_req_pdu_t text_req;
427 1.1 agc text_rsp_pdu_t text_rsp;
428 1.1 agc login_req_pdu_t login_req;
429 1.1 agc login_rsp_pdu_t login_rsp;
430 1.1 agc logout_req_pdu_t logout_req;
431 1.1 agc logout_rsp_pdu_t logout_rsp;
432 1.1 agc snack_req_pdu_t snack;
433 1.1 agc reject_pdu_t reject;
434 1.1 agc nop_out_pdu_t nop_out;
435 1.1 agc nop_in_pdu_t nop_in;
436 1.1 agc } p;
437 1.1 agc uint32_t HeaderDigest;
438 1.2 dholland } __packed;
439 1.1 agc
440 1.1 agc typedef struct pdu_header_s pdu_header_t;
441 1.1 agc
442 1.1 agc #endif /* !_ISCSI_PDU_H */
443