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