]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/IScsiDxe/IScsiProto.h
e11565e3015dd6b6cdd517d06218a55f99274178
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiProto.h
1 /** @file
2 The header file of iSCSI Protocol that defines many specific data structures.
3
4 Copyright (c) 2004 - 2010, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _ISCSI_PROTO_H_
16 #define _ISCSI_PROTO_H_
17
18 #include <Protocol/ScsiPassThruExt.h>
19
20 //
21 // RFC 1982 Serial Number Arithmetic, SERIAL_BITS = 32
22 //
23 #define ISCSI_SEQ_EQ(s1, s2) ((s1) == (s2))
24 #define ISCSI_SEQ_LT(s1, s2) \
25 ( \
26 (((INT32) (s1) < (INT32) (s2)) && (s2 - s1) < ((UINT32) 1 << 31)) || \
27 (((INT32) (s1) > (INT32) (s2)) && (s1 - s2) > ((UINT32) 1 << 31)) \
28 )
29 #define ISCSI_SEQ_GT(s1, s2) \
30 ( \
31 (((INT32) (s1) < (INT32) (s2)) && (s2 - s1) > ((UINT32) 1 << 31)) || \
32 (((INT32) (s1) > (INT32) (s2)) && (s1 - s2) < ((UINT32) 1 << 31)) \
33 )
34
35 #define ISCSI_WELL_KNOWN_PORT 3260
36 #define ISCSI_MAX_CONNS_PER_SESSION 1
37
38 #define DEFAULT_MAX_RECV_DATA_SEG_LEN 8192
39 #define MAX_RECV_DATA_SEG_LEN_IN_FFP 65536
40 #define DEFAULT_MAX_OUTSTANDING_R2T 1
41
42 #define ISCSI_VERSION_MAX 0x00
43 #define ISCSI_VERSION_MIN 0x00
44
45 #define ISID_BYTE_0 0 // OUI format
46 #define ISID_BYTE_1 0
47 #define ISID_BYTE_2 0xaa
48 #define ISID_BYTE_3 0x1
49
50 #define ISCSI_KEY_AUTH_METHOD "AuthMethod"
51 #define ISCSI_KEY_HEADER_DIGEST "HeaderDigest"
52 #define ISCSI_KEY_DATA_DIGEST "DataDigest"
53 #define ISCSI_KEY_MAX_CONNECTIONS "MaxConnections"
54 #define ISCSI_KEY_TARGET_NAME "TargetName"
55 #define ISCSI_KEY_INITIATOR_NAME "InitiatorName"
56 #define ISCSI_KEY_TARGET_ALIAS "TargetAlias"
57 #define ISCSI_KEY_INITIATOR_ALIAS "InitiatorAlias"
58 #define ISCSI_KEY_TARGET_ADDRESS "TargetAddress"
59 #define ISCSI_KEY_INITIAL_R2T "InitialR2T"
60 #define ISCSI_KEY_IMMEDIATE_DATA "ImmediateData"
61 #define ISCSI_KEY_TARGET_PORTAL_GROUP_TAG "TargetPortalGroupTag"
62 #define ISCSI_KEY_MAX_BURST_LENGTH "MaxBurstLength"
63 #define ISCSI_KEY_FIRST_BURST_LENGTH "FirstBurstLength"
64 #define ISCSI_KEY_DEFAULT_TIME2WAIT "DefaultTime2Wait"
65 #define ISCSI_KEY_DEFAULT_TIME2RETAIN "DefaultTime2Retain"
66 #define ISCSI_KEY_MAX_OUTSTANDING_R2T "MaxOutstandingR2T"
67 #define ISCSI_KEY_DATA_PDU_IN_ORDER "DataPDUInOrder"
68 #define ISCSI_KEY_DATA_SEQUENCE_IN_ORDER "DataSequenceInOrder"
69 #define ISCSI_KEY_ERROR_RECOVERY_LEVEL "ErrorRecoveryLevel"
70 #define ISCSI_KEY_SESSION_TYPE "SessionType"
71 #define ISCSI_KEY_MAX_RECV_DATA_SEGMENT_LENGTH "MaxRecvDataSegmentLength"
72
73 #define ISCSI_KEY_VALUE_NONE "None"
74
75 ///
76 /// connection state for initiator
77 ///
78
79 #define CONN_STATE_FREE 0
80 #define CONN_STATE_XPT_WAIT 1
81 #define CONN_STATE_IN_LOGIN 2
82 #define CONN_STATE_LOGGED_IN 3
83 #define CONN_STATE_IN_LOGOUT 4
84 #define CONN_STATE_LOGOUT_REQUESTED 5
85 #define CONN_STATE_CLEANUP_WAIT 6
86 #define CONN_STATE_IN_CLEANUP 7
87
88 ///
89 /// session state for initiator
90 ///
91 #define SESSION_STATE_FREE 0
92 #define SESSION_STATE_LOGGED_IN 1
93 #define SESSION_STATE_FAILED 2
94
95 typedef enum {
96 DataIn = 0,
97 DataOut = 1,
98 DataBi = 2
99 } DATA_DIRECTION;
100
101 #define ISCSI_RESERVED_TAG 0xffffffff
102
103 #define ISCSI_REQ_IMMEDIATE 0x40
104 #define ISCSI_OPCODE_MASK 0x3F
105
106 #define ISCSI_SET_OPCODE(PduHdr, Op, Flgs) ((((ISCSI_BASIC_HEADER *) (PduHdr))->OpCode) = ((Op) | (Flgs)))
107 #define ISCSI_GET_OPCODE(PduHdr) ((((ISCSI_BASIC_HEADER *) (PduHdr))->OpCode) & ISCSI_OPCODE_MASK)
108 #define ISCSI_CHECK_OPCODE(PduHdr, Op) ((((PduHdr)->OpCode) & ISCSI_OPCODE_MASK) == (Op))
109 #define ISCSI_IMMEDIATE_ON(PduHdr) ((PduHdr)->OpCode & ISCSI_REQ_IMMEDIATE)
110 #define ISCSI_SET_FLAG(PduHdr, Flag) (((ISCSI_BASIC_HEADER *) (PduHdr))->Flags |= (BOOLEAN)(Flag))
111 #define ISCSI_CLEAR_FLAG(PduHdr, Flag) (((ISCSI_BASIC_HEADER *) (PduHdr))->Flags &= ~(Flag))
112 #define ISCSI_FLAG_ON(PduHdr, Flag) ((((ISCSI_BASIC_HEADER *) (PduHdr))->Flags & (Flag)) == (Flag))
113 #define ISCSI_SET_STAGES(PduHdr, Cur, Nxt) ((PduHdr)->Flags = (UINT8) ((PduHdr)->Flags | ((Cur) << 2 | (Nxt))))
114 #define ISCSI_GET_CURRENT_STAGE(PduHdr) (((PduHdr)->Flags >> 2) & 0x3)
115 #define ISCSI_GET_NEXT_STAGE(PduHdr) (((PduHdr)->Flags) & 0x3)
116
117 #define ISCSI_GET_PAD_LEN(DataLen) ((~(DataLen) + 1) & 0x3)
118 #define ISCSI_ROUNDUP(DataLen) (((DataLen) + 3) &~(0x3))
119
120 #define HTON24(Dst, Src) \
121 do { \
122 (Dst)[0] = (UINT8) (((Src) >> 16) & 0xFF); \
123 (Dst)[1] = (UINT8) (((Src) >> 8) & 0xFF); \
124 (Dst)[2] = (UINT8) ((Src) & 0xFF); \
125 } while (0);
126
127 #define NTOH24(src) (((src)[0] << 16) | ((src)[1] << 8) | ((src)[2]))
128
129 #define ISCSI_GET_DATASEG_LEN(PduHdr) NTOH24 (((ISCSI_BASIC_HEADER *) (PduHdr))->DataSegmentLength)
130 #define ISCSI_SET_DATASEG_LEN(PduHdr, Len) HTON24 (((ISCSI_BASIC_HEADER *) (PduHdr))->DataSegmentLength, (Len))
131
132 //
133 // initiator opcodes
134 //
135 #define ISCSI_OPCODE_NOP_OUT 0x00
136 #define ISCSI_OPCODE_SCSI_CMD 0x01
137 #define ISCSI_OPCODE_SCSI_TMF_REQ 0x02
138 #define ISCSI_OPCODE_LOGIN_REQ 0x03
139 #define ISCSI_OPCODE_TEXT_REQ 0x04
140 #define ISCSI_OPCODE_SCSI_DATA_OUT 0x05
141 #define ISCSI_OPCODE_LOGOUT_REQ 0x06
142 #define ISCSI_OPCODE_SNACK_REQ 0x10
143 #define ISCSI_OPCODE_VENDOR_I0 0x1c
144 #define ISCSI_OPCODE_VENDOR_I1 0x1d
145 #define ISCSI_OPCODE_VENDOR_I2 0x1e
146
147 //
148 // target opcodes
149 //
150 #define ISCSI_OPCODE_NOP_IN 0x20
151 #define ISCSI_OPCODE_SCSI_RSP 0x21
152 #define ISCSI_OPCODE_SCSI_TMF_RSP 0x22
153 #define ISCSI_OPCODE_LOGIN_RSP 0x23
154 #define ISCSI_OPCODE_TEXT_RSP 0x24
155 #define ISCSI_OPCODE_SCSI_DATA_IN 0x25
156 #define ISCSI_OPCODE_LOGOUT_RSP 0x26
157 #define ISCSI_OPCODE_R2T 0x31
158 #define ISCSI_OPCODE_ASYNC_MSG 0x32
159 #define ISCSI_OPCODE_VENDOR_T0 0x3c
160 #define ISCSI_OPCODE_VENDOR_T1 0x3d
161 #define ISCSI_OPCODE_VENDOR_T2 0x3e
162 #define ISCSI_OPCODE_REJECT 0x3f
163
164 #define ISCSI_BHS_FLAG_FINAL 0x80
165
166 ///
167 /// iSCSI Basic Header Segment
168 ///
169 typedef struct _ISCSI_BASIC_HEADER {
170 UINT8 OpCode;
171 UINT8 Flags;
172 UINT16 OpCodeSpecific1;
173 UINT8 TotalAHSLength;
174 UINT8 DataSegmentLength[3];
175 UINT8 Lun[8];
176 UINT32 InitiatorTaskTag;
177 UINT32 OpCodeSpecific2[7];
178 } ISCSI_BASIC_HEADER;
179
180 //
181 // Defined AHS types, others are reserved.
182 //
183 #define ISCSI_AHS_TYPE_EXT_CDB 0x1
184 #define ISCSI_AHS_TYPE_BI_EXP_READ_DATA_LEN 0x2
185
186 typedef struct _ISCSI_ADDTIONAL_HEADER {
187 UINT16 Length;
188 UINT8 Type;
189 UINT8 TypeSpecific[1];
190 } ISCSI_ADDITIONAL_HEADER;
191
192 typedef struct _ISCSI_BI_EXP_READ_DATA_LEN_AHS {
193 UINT16 Length;
194 UINT8 Type;
195 UINT8 Reserved;
196 UINT32 ExpReadDataLength;
197 } ISCSI_BI_EXP_READ_DATA_LEN_AHS;
198
199 #define SCSI_CMD_PDU_FLAG_READ 0x40
200 #define SCSI_CMD_PDU_FLAG_WRITE 0x20
201
202 #define ISCSI_CMD_PDU_TASK_ATTR_MASK 0x07
203
204 //
205 // task attributes
206 //
207 #define ISCSI_TASK_ATTR_UNTAGGED 0x00
208 #define ISCSI_TASK_ATTR_SIMPLE 0x01
209 #define ISCSI_TASK_ATTR_ORDERD 0x02
210 #define ISCSI_TASK_ATTR_HOQ 0x03
211 #define ISCSI_TASK_ATTR_ACA 0x04
212
213 ///
214 /// SCSI Command
215 ///
216 typedef struct _SCSI_COMMAND {
217 UINT8 OpCode;
218 UINT8 Flags;
219 UINT16 Reserved;
220 UINT8 TotalAHSLength;
221 UINT8 DataSegmentLength[3];
222 UINT8 Lun[8];
223 UINT32 InitiatorTaskTag;
224 UINT32 ExpDataXferLength;
225 UINT32 CmdSN;
226 UINT32 ExpStatSN;
227 UINT8 Cdb[16];
228 } SCSI_COMMAND;
229
230 //
231 // flag bit definitions in SCSI response
232 //
233 #define SCSI_RSP_PDU_FLAG_BI_READ_OVERFLOW 0x10
234 #define SCSI_RSP_PDU_FLAG_BI_READ_UNDERFLOW 0x08
235 #define SCSI_RSP_PDU_FLAG_OVERFLOW 0x04
236 #define SCSI_RSP_PDU_FLAG_UNDERFLOW 0x02
237
238 //
239 // iSCSI service response codes
240 //
241 #define ISCSI_SERVICE_RSP_COMMAND_COMPLETE_AT_TARGET 0x00
242 #define ISCSI_SERVICE_RSP_TARGET_FAILURE 0x01
243
244 ///
245 /// SCSI Response
246 ///
247 typedef struct _SCSI_RESPONSE {
248 UINT8 OpCode;
249 UINT8 Flags;
250 UINT8 Response;
251 UINT8 Status;
252 UINT8 TotalAHSLength;
253 UINT8 DataSegmentLength[3];
254 UINT8 Reserved[8];
255 UINT32 InitiatorTaskTag;
256 UINT32 SNACKTag;
257 UINT32 StatSN;
258 UINT32 ExpCmdSN;
259 UINT32 MaxCmdSN;
260 UINT32 ExpDataSN;
261 UINT32 BiReadResidualCount;
262 UINT32 ResidualCount;
263 } SCSI_RESPONSE;
264
265 typedef struct _ISCSI_SENSE_DATA {
266 UINT16 Length;
267 UINT8 Data[2];
268 } ISCSI_SENSE_DATA;
269
270 ///
271 /// iSCSI Task Managment Function Request
272 ///
273 typedef struct _ISCSI_TMF_REQUEST {
274 UINT8 OpCode;
275 UINT8 Fuction;
276 UINT16 Reserved1;
277 UINT8 TotalAHSLength;
278 UINT8 DataSegmentLength[3];
279 UINT8 Lun[8];
280 UINT32 InitiatorTaskTag;
281 UINT32 ReferencedTaskTag;
282 UINT32 CmdSN;
283 UINT32 ExpStatSN;
284 UINT32 RefCmdSN;
285 UINT32 ExpDataSN;
286 UINT32 Reserved2[2];
287 } ISCSI_TMF_REQUEST;
288
289 #define ISCSI_TMF_RSP_PDU_RSP_FUNCTION_COMPLETE 0
290 #define ISCSI_TMF_RSP_PDU_RSP_TASK_NOT_EXIST 1
291 #define ISCSI_TMF_RSP_PDU_RSP_LUN_NOT_EXIST 2
292 #define ISCSI_TMF_RSP_PDU_RSP_TASK_STILL_ALLEGIANT 3
293 #define ISCSI_TMF_RSP_PDU_RSP_TASK_REASSGIN_NOT_SUPPORTED 4
294 #define ISCSI_TMF_RSP_PDU_RSP_NOT_SUPPORTED 5
295 #define ISCSI_TMF_RSP_PDU_RSP_FUNCTION_AHTH_FAILED 6
296 #define ISCSI_TMF_RSP_PDU_RSP_FUNCTION_REJECTED 255
297
298 ///
299 /// iSCSI Task Management Function Response
300 ///
301 typedef struct _ISCSI_TMF_RESPONSE {
302 UINT8 OpCode;
303 UINT8 Reserved1;
304 UINT8 Response;
305 UINT8 Reserved2;
306 UINT8 TotalAHSLength;
307 UINT8 DataSegmentLength[3];
308 UINT32 Reserver3[2];
309 UINT32 InitiatorTaskTag;
310 UINT32 Reserved4;
311 UINT32 StatSN;
312 UINT32 ExpCmdSN;
313 UINT32 MaxCmdSN;
314 UINT32 Reserved[3];
315 } ISCSI_TMF_RESPONSE;
316
317 ///
318 /// SCSI Data-Out
319 ///
320 typedef struct _ISCSI_SCSI_DATA_OUT {
321 UINT8 OpCode;
322 UINT8 Reserved1[3];
323 UINT8 TotalAHSLength;
324 UINT8 DataSegmentLength[3];
325 UINT8 Lun[8];
326 UINT32 InitiatorTaskTag;
327 UINT32 TargetTransferTag;
328 UINT32 Reserved2;
329 UINT32 ExpStatSN;
330 UINT32 Reserved3;
331 UINT32 DataSN;
332 UINT32 BufferOffset;
333 UINT32 Reserved4;
334 } ISCSI_SCSI_DATA_OUT;
335
336 #define SCSI_DATA_IN_PDU_FLAG_ACKKNOWLEDGE 0x40
337 #define SCSI_DATA_IN_PDU_FLAG_OVERFLOW SCSI_RSP_PDU_FLAG_OVERFLOW
338 #define SCSI_DATA_IN_PDU_FLAG_UNDERFLOW SCSI_RSP_PDU_FLAG_UNDERFLOW
339 #define SCSI_DATA_IN_PDU_FLAG_STATUS_VALID 0x01
340
341 ///
342 /// SCSI Data-In
343 ///
344 typedef struct _ISCSI_SCSI_DATA_IN {
345 UINT8 OpCode;
346 UINT8 Flags;
347 UINT8 Reserved1;
348 UINT8 Status;
349 UINT8 TotalAHSLength;
350 UINT8 DataSegmentLength[3];
351 UINT8 Lun[8];
352 UINT32 InitiatorTaskTag;
353 UINT32 TargetTransferTag;
354 UINT32 StatSN;
355 UINT32 ExpCmdSN;
356 UINT32 MaxCmdSN;
357 UINT32 DataSN;
358 UINT32 BufferOffset;
359 UINT32 ResidualCount;
360 } ISCSI_SCSI_DATA_IN;
361
362 #define ISCSI_GET_BUFFER_OFFSET(PduHdr) NTOHL (((ISCSI_SCSI_DATA_IN *) (PduHdr))->BufferOffset)
363
364 ///
365 /// Ready To Transfer
366 ///
367 typedef struct _ISCSI_READY_TO_TRANSFER {
368 UINT8 OpCode;
369 UINT8 Reserved1[3];
370 UINT8 TotalAHSLength;
371 UINT8 DataSegmentLength[3];
372 UINT8 Lun[8];
373 UINT32 InitiatorTaskTag;
374 UINT32 TargetTransferTag;
375 UINT32 StatSN;
376 UINT32 ExpCmdSN;
377 UINT32 MaxCmdSN;
378 UINT32 R2TSeqNum;
379 UINT32 BufferOffset;
380 UINT32 DesiredDataTransferLength;
381 } ISCSI_READY_TO_TRANSFER;
382
383 typedef struct _ISCSI_ASYNC_MESSAGE {
384 UINT8 OpCode;
385 UINT8 Reserved1[8];
386 UINT8 TotalAHSLength;
387 UINT8 DataSegmentLength[3];
388 UINT8 Lun[8];
389 UINT32 InitiatorTaskTag;
390 UINT32 Reserved2;
391 UINT32 StatSN;
392 UINT32 ExpCmdSN;
393 UINT32 MaxCmdSN;
394 UINT8 AsyncEvent;
395 UINT8 AsyncVCode;
396 UINT16 Parameter1;
397 UINT16 Parameter2;
398 UINT16 Parameter3;
399 UINT32 Reserved3;
400 } ISCSI_ASYNC_MESSAGE;
401
402 #define ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT 0x80
403 #define ISCSI_LOGIN_REQ_PDU_FLAG_CONTINUE 0x40
404
405 ///
406 /// Login Request
407 ///
408 typedef struct _ISCSI_LOGIN_REQUEST {
409 UINT8 OpCode;
410 UINT8 Flags;
411 UINT8 VersionMax;
412 UINT8 VersionMin;
413 UINT8 TotalAHSLength;
414 UINT8 DataSegmentLength[3];
415 UINT8 Isid[6];
416 UINT16 Tsih;
417 UINT32 InitiatorTaskTag;
418 UINT16 Cid;
419 UINT16 Reserved1;
420 UINT32 CmdSN;
421 UINT32 ExpStatSN;
422 UINT32 Reserved2[4];
423 } ISCSI_LOGIN_REQUEST;
424
425 #define ISCSI_LOGIN_RSP_PDU_FLAG_TRANSIT ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT
426 #define ISCSI_LOGIN_RSP_PDU_FLAG_CONTINUE ISCSI_LOGIN_REQ_PDU_FLAG_CONTINUE
427
428 #define ISCSI_LOGIN_STATUS_SUCCESS 0
429 #define ISCSI_LOGIN_STATUS_REDIRECTION 1
430 #define ISCSI_LOGIN_STATUS_INITIATOR_ERROR 2
431 #define ISCSI_LOGIN_STATUS_TARGET_ERROR 3
432
433 ///
434 /// Login Response
435 ///
436 typedef struct _ISCSI_LOGIN_RESPONSE {
437 UINT8 OpCode;
438 UINT8 Flags;
439 UINT8 VersionMax;
440 UINT8 VersionActive;
441 UINT8 TotalAHSLength;
442 UINT8 DataSegmentLength[3];
443 UINT8 Isid[6];
444 UINT16 Tsih;
445 UINT32 InitiatorTaskTag;
446 UINT32 Reserved1;
447 UINT32 StatSN;
448 UINT32 ExpCmdSN;
449 UINT32 MaxCmdSN;
450 UINT8 StatusClass;
451 UINT8 StatusDetail;
452 UINT8 Reserved2[10];
453 } ISCSI_LOGIN_RESPONSE;
454
455 #define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
456 #define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
457 #define ISCSI_LOGOUT_REASON_REMOVE_CONNECTION_FOR_RECOVERY 2
458
459 ///
460 /// Logout Request
461 ///
462 typedef struct _ISCSI_LOGOUT_REQUEST {
463 UINT8 OpCode;
464 UINT8 ReasonCode;
465 UINT16 Reserved1;
466 UINT8 TotalAHSLength;
467 UINT8 DataSegmentLength[3];
468 UINT32 Reserved2[2];
469 UINT32 InitiatorTaskTag;
470 UINT16 Cid;
471 UINT16 Reserved3;
472 UINT32 CmdSN;
473 UINT32 ExpStatSN;
474 UINT32 Reserved4[4];
475 } ISCSI_LOGOUT_REQUEST;
476
477 #define ISCSI_LOGOUT_RESPONSE_SESSION_CLOSED_SUCCESS 0
478 #define ISCSI_LOGOUT_RESPONSE_CID_NOT_FOUND 1
479 #define ISCSI_LOGOUT_RESPONSE_RECOVERY_NOT_SUPPORTED 2
480 #define ISCSI_LOGOUT_RESPONSE_CLEANUP_FAILED 3
481
482 ///
483 /// Logout Response
484 ///
485 typedef struct _ISCSI_LOGOUT_RESPONSE {
486 UINT8 OpCode;
487 UINT8 Reserved1;
488 UINT8 Response;
489 UINT8 Reserved2;
490 UINT8 TotalAHSLength;
491 UINT8 DataSegmentLength[3];
492 UINT32 Reserved3[2];
493 UINT32 InitiatorTaskTag;
494 UINT32 Reserved4;
495 UINT32 StatSN;
496 UINT32 ExpCmdSN;
497 UINT32 MaxCmdSN;
498 UINT32 Reserved5;
499 UINT16 Time2Wait;
500 UINT16 Time2Retain;
501 UINT32 Reserved6;
502 } ISCSI_LOGOUT_RESPONSE;
503
504 #define ISCSI_SNACK_REQUEST_TYPE_DATA_OR_R2T 0
505 #define ISCSI_SNACK_REQUEST_TYPE_STATUS 1
506 #define ISCSI_SNACK_REQUEST_TYPE_DATA_ACK 2
507 #define ISCSI_SNACK_REQUEST_TYPE_RDATA 3
508
509 ///
510 /// SNACK Request
511 ///
512 typedef struct _ISCSI_SNACK_REQUEST {
513 UINT8 OpCode;
514 UINT8 Type;
515 UINT16 Reserved1;
516 UINT8 TotalAHSLength;
517 UINT8 DataSegmentLength[3];
518 UINT8 Lun[8];
519 UINT32 InitiatorTaskTag;
520 UINT32 TargetTransferTag;
521 UINT32 Reserved2;
522 UINT32 ExpStatSN;
523 UINT32 Reserved[2];
524 UINT32 BegRun;
525 UINT32 RunLength;
526 } ISCSI_SNACK_REQUEST;
527
528 ///
529 /// Reject
530 ///
531 typedef struct _ISCSI_REJECT {
532 UINT8 OpCode;
533 UINT8 Reserved1;
534 UINT8 Reason;
535 UINT8 Reserved2;
536 UINT8 TotalAHSLength;
537 UINT8 DataSegmentLength[3];
538 UINT32 Reserved3[2];
539 UINT32 InitiatorTaskTag;
540 UINT32 Reserved4;
541 UINT32 StatSN;
542 UINT32 ExpCmdSN;
543 UINT32 MaxCmdSN;
544 UINT32 DataSN;
545 UINT32 Reserved5[2];
546 } ISCSI_REJECT;
547
548 ///
549 /// NOP-Out
550 ///
551 typedef struct _ISCSI_NOP_OUT {
552 UINT8 OpCode;
553 UINT8 Reserved1[3];
554 UINT8 TotalAHSLength;
555 UINT8 DataSegmentLength[3];
556 UINT8 Lun[8];
557 UINT32 InitiatorTaskTag;
558 UINT32 TargetTransferTag;
559 UINT32 CmdSN;
560 UINT32 ExpStatSN;
561 UINT32 Reserved2[4];
562 } ISCSI_NOP_OUT;
563
564 ///
565 /// NOP-In
566 ///
567 typedef struct _ISCSI_NOP_IN {
568 UINT8 OpCode;
569 UINT8 Reserved1[3];
570 UINT8 TotalAHSLength;
571 UINT8 DataSegmentLength[3];
572 UINT8 Lun[8];
573 UINT32 InitiatorTaskTag;
574 UINT32 TargetTransferTag;
575 UINT32 StatSN;
576 UINT32 ExpCmdSN;
577 UINT32 MaxCmdSN;
578 UINT32 Reserved2[3];
579 } ISCSI_NOP_IN;
580
581 #define ISCSI_SECURITY_NEGOTIATION 0
582 #define ISCSI_LOGIN_OPERATIONAL_NEGOTIATION 1
583 #define ISCSI_FULL_FEATURE_PHASE 3
584
585 typedef enum {
586 IScsiDigestNone,
587 IScsiDigestCRC32
588 } ISCSI_DIGEST_TYPE;
589
590 typedef struct _ISCSI_XFER_CONTEXT {
591 UINT32 TargetTransferTag;
592 UINT32 Offset;
593 UINT32 DesiredLength;
594 UINT32 ExpDataSN;
595 } ISCSI_XFER_CONTEXT;
596
597 typedef struct _ISCSI_IN_BUFFER_CONTEXT {
598 UINT8 *InData;
599 UINT32 InDataLen;
600 } ISCSI_IN_BUFFER_CONTEXT;
601
602 typedef struct _ISCSI_TCB {
603 LIST_ENTRY Link;
604
605 BOOLEAN SoFarInOrder;
606 UINT32 ExpDataSN;
607 BOOLEAN FbitReceived;
608 BOOLEAN StatusXferd;
609 UINT32 ActiveR2Ts;
610 UINT32 Response;
611 CHAR8 *Reason;
612 UINT32 InitiatorTaskTag;
613 UINT32 CmdSN;
614 UINT32 SNACKTag;
615
616 ISCSI_XFER_CONTEXT XferContext;
617
618 ISCSI_CONNECTION *Conn;
619 } ISCSI_TCB;
620
621 typedef struct _ISCSI_KEY_VALUE_PAIR {
622 LIST_ENTRY List;
623
624 CHAR8 *Key;
625 CHAR8 *Value;
626 } ISCSI_KEY_VALUE_PAIR;
627
628 /**
629 Attach the iSCSI connection to the iSCSI session.
630
631 @param[in, out] Session The iSCSI session.
632 @param[in, out] Conn The iSCSI connection.
633 **/
634 VOID
635 IScsiAttatchConnection (
636 IN OUT ISCSI_SESSION *Session,
637 IN OUT ISCSI_CONNECTION *Conn
638 );
639
640 /**
641 Detach the iSCSI connection from the session it belongs to.
642
643 @param[in, out] Conn The iSCSI connection.
644 **/
645 VOID
646 IScsiDetatchConnection (
647 IN OUT ISCSI_CONNECTION *Conn
648 );
649
650 /**
651 This function does the iSCSI connection login.
652
653 @param[in, out] Conn The iSCSI connection to login.
654
655 @retval EFI_SUCCESS The iSCSI connection is logged into the iSCSI target.
656 @retval EFI_TIMEOUT Timeout happened during the login procedure.
657 @retval Others Other errors as indicated.
658 **/
659 EFI_STATUS
660 IScsiConnLogin (
661 IN OUT ISCSI_CONNECTION *Conn
662 );
663
664 /**
665 Create a TCP connection for the iSCSI session.
666
667 @param[in] Private The iSCSI driver data.
668 @param[in] Session Maximum CmdSN from the target.
669
670 @return The newly created iSCSI connection.
671 **/
672 ISCSI_CONNECTION *
673 IScsiCreateConnection (
674 IN ISCSI_DRIVER_DATA *Private,
675 IN ISCSI_SESSION *Session
676 );
677
678 /**
679 Destroy an iSCSI connection.
680
681 @param[in] Conn The connection to destroy.
682 **/
683 VOID
684 IScsiDestroyConnection (
685 IN ISCSI_CONNECTION *Conn
686 );
687
688 /**
689 Login the iSCSI session.
690
691 @param[in] Private The iSCSI driver data.
692
693 @retval EFI_SUCCESS The iSCSI session login procedure finished.
694 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
695 @retval EFI_NO_MEDIA There was a media error.
696 @retval Others Other errors as indicated.
697
698 **/
699 EFI_STATUS
700 IScsiSessionLogin (
701 IN ISCSI_DRIVER_DATA *Private
702 );
703
704 /**
705 Build and send the iSCSI login request to the iSCSI target according to
706 the current login stage.
707
708 @param[in] Conn The connection in the iSCSI login phase.
709
710 @retval EFI_SUCCESS The iSCSI login request PDU is built and sent on this
711 connection.
712 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
713 @retval EFI_DEVICE_ERROR Some kind of device error happened.
714 **/
715 EFI_STATUS
716 IScsiSendLoginReq (
717 IN ISCSI_CONNECTION *Conn
718 );
719
720 /**
721 Receive and process the iSCSI login response.
722
723 @param[in] Conn The connection in the iSCSI login phase.
724
725 @retval EFI_SUCCESS The iSCSI login response PDU is received and processed.
726 @retval Others Other errors as indicated.
727 **/
728 EFI_STATUS
729 IScsiReceiveLoginRsp (
730 IN ISCSI_CONNECTION *Conn
731 );
732
733 /**
734 Add an iSCSI key-value pair as a string into the data segment of the Login Request PDU.
735 The DataSegmentLength and the actual size of the net buffer containing this PDU will be
736 updated.
737
738 @param[in, out] Pdu The iSCSI PDU whose data segment the key-value pair will
739 be added to.
740 @param[in] Key The key name string.
741 @param[in] Value The value string.
742
743 @retval EFI_SUCCESS The key-valu pair is added to the PDU's datasegment and
744 the correspondence length fields are updated.
745 @retval EFI_OUT_OF_RESOURCES There is not enough space in the PDU to add the key-value
746 pair.
747 **/
748 EFI_STATUS
749 IScsiAddKeyValuePair (
750 IN OUT NET_BUF *Pdu,
751 IN CHAR8 *Key,
752 IN CHAR8 *Value
753 );
754
755 /**
756 Prepare the iSCSI login request to be sent according to the current login status.
757
758 @param[in, out] Conn The connection in the iSCSI login phase.
759
760 @return The pointer to the net buffer containing the iSCSI login request built.
761 @retval Others Other errors as indicated.
762 **/
763 NET_BUF *
764 IScsiPrepareLoginReq (
765 IN OUT ISCSI_CONNECTION *Conn
766 );
767
768 /**
769 Process the iSCSI Login Response.
770
771 @param[in, out] Conn The connection on which the iSCSI login response is received.
772 @param[in, out] Pdu The iSCSI login response PDU.
773
774 @retval EFI_SUCCESS The iSCSI login response PDU is processed and all check are passed.
775 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened.
776 @retval EFI_MEDIA_CHANGED Target is redirected.
777 @retval Others Other errors as indicated.
778 **/
779 EFI_STATUS
780 IScsiProcessLoginRsp (
781 IN OUT ISCSI_CONNECTION *Conn,
782 IN OUT NET_BUF *Pdu
783 );
784
785 /**
786 Updated the target information according the data received in the iSCSI
787 login response with an target redirection status.
788
789 @param[in, out] Session The iSCSI session.
790 @param[in] Data The data segment which should contain the
791 TargetAddress key-value list.
792 @param[in] Len Length of the data.
793
794 @retval EFI_SUCCESS The target address is updated.
795 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
796 @retval EFI_NOT_FOUND The TargetAddress key is not found.
797 @retval Others Other errors as indicated.
798 **/
799 EFI_STATUS
800 IScsiUpdateTargetAddress (
801 IN OUT ISCSI_SESSION *Session,
802 IN CHAR8 *Data,
803 IN UINT32 Len
804 );
805
806 /**
807 The callback function to free the net buffer list.
808
809 @param[in] Arg The opaque parameter.
810 **/
811 VOID
812 IScsiFreeNbufList (
813 VOID *Arg
814 );
815
816 /**
817 Receive an iSCSI response PDU. An iSCSI response PDU contains an iSCSI PDU header and
818 an optional data segment. The two parts will be put into two blocks of buffers in the
819 net buffer. The digest check will be conducted in this function if needed and the digests
820 will be trimmed from the PDU buffer.
821
822 @param[in] Conn The iSCSI connection to receive data from.
823 @param[out] Pdu The received iSCSI pdu.
824 @param[in] Context The context used to describe information on the caller provided
825 buffer to receive data segment of the iSCSI pdu, it's optional.
826 @param[in] HeaderDigest Whether there will be header digest received.
827 @param[in] DataDigest Whether there will be data digest.
828 @param[in] TimeoutEvent The timeout event, it's optional.
829
830 @retval EFI_SUCCESS An iSCSI pdu is received.
831 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
832 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened.
833 @retval Others Other errors as indicated.
834 **/
835 EFI_STATUS
836 IScsiReceivePdu (
837 IN ISCSI_CONNECTION *Conn,
838 OUT NET_BUF **Pdu,
839 IN ISCSI_IN_BUFFER_CONTEXT *Context, OPTIONAL
840 IN BOOLEAN HeaderDigest,
841 IN BOOLEAN DataDigest,
842 IN EFI_EVENT TimeoutEvent OPTIONAL
843 );
844
845 /**
846 Check and get the result of the prameter negotiation.
847
848 @param[in, out] Conn The connection in iSCSI login.
849
850 @retval EFI_SUCCESS The parmeter check is passed and negotiation is finished.
851 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error happened.
852 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
853 **/
854 EFI_STATUS
855 IScsiCheckOpParams (
856 IN OUT ISCSI_CONNECTION *Conn
857 );
858
859 /**
860 Fill the oprational prameters.
861
862 @param[in] Conn The connection in iSCSI login.
863 @param[in, out] Pdu The iSCSI login request PDU to fill the parameters.
864
865 @retval EFI_SUCCESS The parmeters are filled into the iSCSI login request PDU.
866 **/
867 EFI_STATUS
868 IScsiFillOpParams (
869 IN ISCSI_CONNECTION *Conn,
870 IN OUT NET_BUF *Pdu
871 );
872
873 /**
874 Pad the iSCSI AHS or data segment to an integer number of 4 byte words.
875
876 @param[in, out] Pdu The iSCSI pdu which contains segments to pad.
877 @param[in] Len The length of the last semgnet in the PDU.
878
879 @retval EFI_SUCCESS The segment is padded or no need to pad it.
880 @retval EFI_OUT_OF_RESOURCES There is not enough remaining free space to add the
881 padding bytes.
882 **/
883 EFI_STATUS
884 IScsiPadSegment (
885 IN OUT NET_BUF *Pdu,
886 IN UINT32 Len
887 );
888
889 /**
890 Build a key-value list from the data segment.
891
892 @param[in] Data The data segment containing the key-value pairs.
893 @param[in] Len Length of the data segment.
894
895 @return The key-value list.
896 @retval NULL Other errors as indicated.
897 **/
898 LIST_ENTRY *
899 IScsiBuildKeyValueList (
900 IN CHAR8 *Data,
901 IN UINT32 Len
902 );
903
904 /**
905 Get the value string by the key name from the key-value list. If found,
906 the key-value entry will be removed from the list.
907
908 @param[in, out] KeyValueList The key-value list.
909 @param[in] Key The key name to find.
910
911 @return The value string.
912 **/
913 CHAR8 *
914 IScsiGetValueByKeyFromList (
915 IN OUT LIST_ENTRY *KeyValueList,
916 IN CHAR8 *Key
917 );
918
919 /**
920 Free the key-value list.
921
922 @param[in] KeyValueList The key-value list.
923 **/
924 VOID
925 IScsiFreeKeyValueList (
926 IN LIST_ENTRY *KeyValueList
927 );
928
929 /**
930 Normalize the iSCSI name according to RFC.
931
932 @param[in, out] Name The iSCSI name.
933 @param[in] Len length of the iSCSI name.
934
935 @retval EFI_SUCCESS The iSCSI name is valid and normalized.
936 @retval EFI_PROTOCOL_ERROR The iSCSI name is mal-formatted or not in the IQN format.
937 **/
938 EFI_STATUS
939 IScsiNormalizeName (
940 IN OUT CHAR8 *Name,
941 IN UINTN Len
942 );
943
944 /**
945 Execute the SCSI command issued through the EXT SCSI PASS THRU protocol.
946
947 @param[in] PassThru The EXT SCSI PASS THRU protocol.
948 @param[in] Target The target ID.
949 @param[in] Lun The LUN.
950 @param[in, out] Packet The request packet containing IO request, SCSI command
951 buffer and buffers to read/write.
952
953 @retval EFI_SUCCES The SCSI command is executed and the result is updated to
954 the Packet.
955 @retval EFI_DEVICE_ERROR Session state was not as required.
956 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
957 @retval Others Other errors as indicated.
958 **/
959 EFI_STATUS
960 IScsiExecuteScsiCommand (
961 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru,
962 IN UINT8 *Target,
963 IN UINT64 Lun,
964 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
965 );
966
967 /**
968 Reinstate the session on some error.
969
970 @param[in, out] Private The iSCSI driver data.
971
972 @retval EFI_SUCCES The session is reinstated from some error.
973 @retval Other Reinstatement failed.
974 **/
975 EFI_STATUS
976 IScsiSessionReinstatement (
977 IN OUT ISCSI_DRIVER_DATA *Private
978 );
979
980 /**
981 Initialize some session parameters before login.
982
983 @param[in, out] Session The iSCSI session.
984 @param[in] Recovery Whether the request is from a fresh new start or recovery.
985 **/
986 VOID
987 IScsiSessionInit (
988 IN OUT ISCSI_SESSION *Session,
989 IN BOOLEAN Recovery
990 );
991
992 /**
993 Abort the iSCSI session, that is, reset all the connection and free the
994 resources.
995
996 @param[in, out] Session The iSCSI session.
997
998 @retval EFI_SUCCES The session is aborted.
999 **/
1000 EFI_STATUS
1001 IScsiSessionAbort (
1002 IN OUT ISCSI_SESSION *Session
1003 );
1004
1005 #endif