10#define _ISCSI_PROTO_H_
15#define ISCSI_SEQ_EQ(s1, s2) ((s1) == (s2))
16#define ISCSI_SEQ_LT(s1, s2) \
18 (((INT32) (s1) < (INT32) (s2)) && (s2 - s1) < ((UINT32) 1 << 31)) || \
19 (((INT32) (s1) > (INT32) (s2)) && (s1 - s2) > ((UINT32) 1 << 31)) \
21#define ISCSI_SEQ_GT(s1, s2) \
23 (((INT32) (s1) < (INT32) (s2)) && (s2 - s1) > ((UINT32) 1 << 31)) || \
24 (((INT32) (s1) > (INT32) (s2)) && (s1 - s2) < ((UINT32) 1 << 31)) \
27#define ISCSI_WELL_KNOWN_PORT 3260
28#define ISCSI_MAX_CONNS_PER_SESSION 1
30#define DEFAULT_MAX_RECV_DATA_SEG_LEN 8192
31#define MAX_RECV_DATA_SEG_LEN_IN_FFP 65536
32#define DEFAULT_MAX_OUTSTANDING_R2T 1
34#define ISCSI_VERSION_MAX 0x00
35#define ISCSI_VERSION_MIN 0x00
37#define ISCSI_CHECK_MEDIA_LOGIN_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
38#define ISCSI_CHECK_MEDIA_GET_DHCP_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
40#define ISCSI_REDIRECT_ADDR_START_DELIMITER '['
41#define ISCSI_REDIRECT_ADDR_END_DELIMITER ']'
43#define ISCSI_KEY_AUTH_METHOD "AuthMethod"
44#define ISCSI_KEY_HEADER_DIGEST "HeaderDigest"
45#define ISCSI_KEY_DATA_DIGEST "DataDigest"
46#define ISCSI_KEY_MAX_CONNECTIONS "MaxConnections"
47#define ISCSI_KEY_TARGET_NAME "TargetName"
48#define ISCSI_KEY_INITIATOR_NAME "InitiatorName"
49#define ISCSI_KEY_TARGET_ALIAS "TargetAlias"
50#define ISCSI_KEY_INITIATOR_ALIAS "InitiatorAlias"
51#define ISCSI_KEY_TARGET_ADDRESS "TargetAddress"
52#define ISCSI_KEY_INITIAL_R2T "InitialR2T"
53#define ISCSI_KEY_IMMEDIATE_DATA "ImmediateData"
54#define ISCSI_KEY_TARGET_PORTAL_GROUP_TAG "TargetPortalGroupTag"
55#define ISCSI_KEY_MAX_BURST_LENGTH "MaxBurstLength"
56#define ISCSI_KEY_FIRST_BURST_LENGTH "FirstBurstLength"
57#define ISCSI_KEY_DEFAULT_TIME2WAIT "DefaultTime2Wait"
58#define ISCSI_KEY_DEFAULT_TIME2RETAIN "DefaultTime2Retain"
59#define ISCSI_KEY_MAX_OUTSTANDING_R2T "MaxOutstandingR2T"
60#define ISCSI_KEY_DATA_PDU_IN_ORDER "DataPDUInOrder"
61#define ISCSI_KEY_DATA_SEQUENCE_IN_ORDER "DataSequenceInOrder"
62#define ISCSI_KEY_ERROR_RECOVERY_LEVEL "ErrorRecoveryLevel"
63#define ISCSI_KEY_SESSION_TYPE "SessionType"
64#define ISCSI_KEY_MAX_RECV_DATA_SEGMENT_LENGTH "MaxRecvDataSegmentLength"
66#define ISCSI_KEY_VALUE_NONE "None"
72#define CONN_STATE_FREE 0
73#define CONN_STATE_XPT_WAIT 1
74#define CONN_STATE_IN_LOGIN 2
75#define CONN_STATE_LOGGED_IN 3
76#define CONN_STATE_IN_LOGOUT 4
77#define CONN_STATE_LOGOUT_REQUESTED 5
78#define CONN_STATE_CLEANUP_WAIT 6
79#define CONN_STATE_IN_CLEANUP 7
84#define SESSION_STATE_FREE 0
85#define SESSION_STATE_LOGGED_IN 1
86#define SESSION_STATE_FAILED 2
88#define ISCSI_RESERVED_TAG 0xffffffff
90#define ISCSI_REQ_IMMEDIATE 0x40
91#define ISCSI_OPCODE_MASK 0x3F
93#define ISCSI_SET_OPCODE(PduHdr, Op, Flgs) ((((ISCSI_BASIC_HEADER *) (PduHdr))->OpCode) = ((Op) | (Flgs)))
94#define ISCSI_GET_OPCODE(PduHdr) ((((ISCSI_BASIC_HEADER *) (PduHdr))->OpCode) & ISCSI_OPCODE_MASK)
95#define ISCSI_CHECK_OPCODE(PduHdr, Op) ((((PduHdr)->OpCode) & ISCSI_OPCODE_MASK) == (Op))
96#define ISCSI_IMMEDIATE_ON(PduHdr) ((PduHdr)->OpCode & ISCSI_REQ_IMMEDIATE)
97#define ISCSI_SET_FLAG(PduHdr, Flag) (((ISCSI_BASIC_HEADER *) (PduHdr))->Flags |= (BOOLEAN)(Flag))
98#define ISCSI_CLEAR_FLAG(PduHdr, Flag) (((ISCSI_BASIC_HEADER *) (PduHdr))->Flags &= ~(Flag))
99#define ISCSI_FLAG_ON(PduHdr, Flag) ((BOOLEAN) ((((ISCSI_BASIC_HEADER *) (PduHdr))->Flags & (Flag)) == (Flag)))
100#define ISCSI_SET_STAGES(PduHdr, Cur, Nxt) ((PduHdr)->Flags = (UINT8) ((PduHdr)->Flags | ((Cur) << 2 | (Nxt))))
101#define ISCSI_GET_CURRENT_STAGE(PduHdr) ((UINT8) (((PduHdr)->Flags >> 2) & 0x3))
102#define ISCSI_GET_NEXT_STAGE(PduHdr) ((UINT8) (((PduHdr)->Flags) & 0x3))
104#define ISCSI_GET_PAD_LEN(DataLen) ((~(DataLen) + 1) & 0x3)
105#define ISCSI_ROUNDUP(DataLen) (((DataLen) + 3) &~(0x3))
107#define HTON24(Dst, Src) \
109 (Dst)[0] = (UINT8) ((UINT8) ((Src) >> 16) & 0xFF); \
110 (Dst)[1] = (UINT8) ((UINT8) ((Src) >> 8) & 0xFF); \
111 (Dst)[2] = (UINT8) ((UINT8) (Src) & 0xFF); \
114#define NTOH24(src) (((src)[0] << 16) | ((src)[1] << 8) | ((src)[2]))
116#define ISCSI_GET_DATASEG_LEN(PduHdr) NTOH24 (((ISCSI_BASIC_HEADER *) (PduHdr))->DataSegmentLength)
117#define ISCSI_SET_DATASEG_LEN(PduHdr, Len) HTON24 (((ISCSI_BASIC_HEADER *) (PduHdr))->DataSegmentLength, (Len))
118#define ISCSI_GET_BUFFER_OFFSET(PduHdr) NTOHL (((ISCSI_SCSI_DATA_IN *) (PduHdr))->BufferOffset)
123#define ISCSI_OPCODE_NOP_OUT 0x00
124#define ISCSI_OPCODE_SCSI_CMD 0x01
125#define ISCSI_OPCODE_SCSI_TMF_REQ 0x02
126#define ISCSI_OPCODE_LOGIN_REQ 0x03
127#define ISCSI_OPCODE_TEXT_REQ 0x04
128#define ISCSI_OPCODE_SCSI_DATA_OUT 0x05
129#define ISCSI_OPCODE_LOGOUT_REQ 0x06
130#define ISCSI_OPCODE_SNACK_REQ 0x10
131#define ISCSI_OPCODE_VENDOR_I0 0x1c
132#define ISCSI_OPCODE_VENDOR_I1 0x1d
133#define ISCSI_OPCODE_VENDOR_I2 0x1e
138#define ISCSI_OPCODE_NOP_IN 0x20
139#define ISCSI_OPCODE_SCSI_RSP 0x21
140#define ISCSI_OPCODE_SCSI_TMF_RSP 0x22
141#define ISCSI_OPCODE_LOGIN_RSP 0x23
142#define ISCSI_OPCODE_TEXT_RSP 0x24
143#define ISCSI_OPCODE_SCSI_DATA_IN 0x25
144#define ISCSI_OPCODE_LOGOUT_RSP 0x26
145#define ISCSI_OPCODE_R2T 0x31
146#define ISCSI_OPCODE_ASYNC_MSG 0x32
147#define ISCSI_OPCODE_VENDOR_T0 0x3c
148#define ISCSI_OPCODE_VENDOR_T1 0x3d
149#define ISCSI_OPCODE_VENDOR_T2 0x3e
150#define ISCSI_OPCODE_REJECT 0x3f
152#define ISCSI_BHS_FLAG_FINAL 0x80
157#define ISCSI_AHS_TYPE_EXT_CDB 0x1
158#define ISCSI_AHS_TYPE_BI_EXP_READ_DATA_LEN 0x2
160#define SCSI_CMD_PDU_FLAG_READ 0x40
161#define SCSI_CMD_PDU_FLAG_WRITE 0x20
163#define ISCSI_CMD_PDU_TASK_ATTR_MASK 0x07
168#define ISCSI_TASK_ATTR_UNTAGGED 0x00
169#define ISCSI_TASK_ATTR_SIMPLE 0x01
170#define ISCSI_TASK_ATTR_ORDERD 0x02
171#define ISCSI_TASK_ATTR_HOQ 0x03
172#define ISCSI_TASK_ATTR_ACA 0x04
177#define SCSI_RSP_PDU_FLAG_BI_READ_OVERFLOW 0x10
178#define SCSI_RSP_PDU_FLAG_BI_READ_UNDERFLOW 0x08
179#define SCSI_RSP_PDU_FLAG_OVERFLOW 0x04
180#define SCSI_RSP_PDU_FLAG_UNDERFLOW 0x02
185#define ISCSI_SERVICE_RSP_COMMAND_COMPLETE_AT_TARGET 0x00
186#define ISCSI_SERVICE_RSP_TARGET_FAILURE 0x01
188#define ISCSI_TMF_RSP_PDU_RSP_FUNCTION_COMPLETE 0
189#define ISCSI_TMF_RSP_PDU_RSP_TASK_NOT_EXIST 1
190#define ISCSI_TMF_RSP_PDU_RSP_LUN_NOT_EXIST 2
191#define ISCSI_TMF_RSP_PDU_RSP_TASK_STILL_ALLEGIANT 3
192#define ISCSI_TMF_RSP_PDU_RSP_TASK_REASSGIN_NOT_SUPPORTED 4
193#define ISCSI_TMF_RSP_PDU_RSP_NOT_SUPPORTED 5
194#define ISCSI_TMF_RSP_PDU_RSP_FUNCTION_AHTH_FAILED 6
195#define ISCSI_TMF_RSP_PDU_RSP_FUNCTION_REJECTED 255
197#define SCSI_DATA_IN_PDU_FLAG_ACKKNOWLEDGE 0x40
198#define SCSI_DATA_IN_PDU_FLAG_OVERFLOW SCSI_RSP_PDU_FLAG_OVERFLOW
199#define SCSI_DATA_IN_PDU_FLAG_UNDERFLOW SCSI_RSP_PDU_FLAG_UNDERFLOW
200#define SCSI_DATA_IN_PDU_FLAG_STATUS_VALID 0x01
202#define ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT 0x80
203#define ISCSI_LOGIN_REQ_PDU_FLAG_CONTINUE 0x40
205#define ISCSI_LOGIN_RSP_PDU_FLAG_TRANSIT ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT
206#define ISCSI_LOGIN_RSP_PDU_FLAG_CONTINUE ISCSI_LOGIN_REQ_PDU_FLAG_CONTINUE
208#define ISCSI_LOGIN_STATUS_SUCCESS 0
209#define ISCSI_LOGIN_STATUS_REDIRECTION 1
210#define ISCSI_LOGIN_STATUS_INITIATOR_ERROR 2
211#define ISCSI_LOGIN_STATUS_TARGET_ERROR 3
213#define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
214#define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
215#define ISCSI_LOGOUT_REASON_REMOVE_CONNECTION_FOR_RECOVERY 2
217#define ISCSI_LOGOUT_RESPONSE_SESSION_CLOSED_SUCCESS 0
218#define ISCSI_LOGOUT_RESPONSE_CID_NOT_FOUND 1
219#define ISCSI_LOGOUT_RESPONSE_RECOVERY_NOT_SUPPORTED 2
220#define ISCSI_LOGOUT_RESPONSE_CLEANUP_FAILED 3
222#define ISCSI_SNACK_REQUEST_TYPE_DATA_OR_R2T 0
223#define ISCSI_SNACK_REQUEST_TYPE_STATUS 1
224#define ISCSI_SNACK_REQUEST_TYPE_DATA_ACK 2
225#define ISCSI_SNACK_REQUEST_TYPE_RDATA 3
227#define ISCSI_SECURITY_NEGOTIATION 0
228#define ISCSI_LOGIN_OPERATIONAL_NEGOTIATION 1
229#define ISCSI_FULL_FEATURE_PHASE 3
246 UINT16 OpCodeSpecific1;
247 UINT8 TotalAHSLength;
248 UINT8 DataSegmentLength[3];
250 UINT32 InitiatorTaskTag;
251 UINT32 OpCodeSpecific2[7];
257 UINT8 TypeSpecific[1];
264 UINT32 ExpReadDataLength;
274 UINT8 TotalAHSLength;
275 UINT8 DataSegmentLength[3];
277 UINT32 InitiatorTaskTag;
278 UINT32 ExpDataXferLength;
292 UINT8 TotalAHSLength;
293 UINT8 DataSegmentLength[3];
295 UINT32 InitiatorTaskTag;
301 UINT32 BiReadResidualCount;
302 UINT32 ResidualCount;
317 UINT8 TotalAHSLength;
318 UINT8 DataSegmentLength[3];
320 UINT32 InitiatorTaskTag;
321 UINT32 ReferencedTaskTag;
337 UINT8 TotalAHSLength;
338 UINT8 DataSegmentLength[3];
340 UINT32 InitiatorTaskTag;
354 UINT8 TotalAHSLength;
355 UINT8 DataSegmentLength[3];
357 UINT32 InitiatorTaskTag;
358 UINT32 TargetTransferTag;
375 UINT8 TotalAHSLength;
376 UINT8 DataSegmentLength[3];
378 UINT32 InitiatorTaskTag;
379 UINT32 TargetTransferTag;
385 UINT32 ResidualCount;
394 UINT8 TotalAHSLength;
395 UINT8 DataSegmentLength[3];
397 UINT32 InitiatorTaskTag;
398 UINT32 TargetTransferTag;
404 UINT32 DesiredDataTransferLength;
410 UINT8 TotalAHSLength;
411 UINT8 DataSegmentLength[3];
413 UINT32 InitiatorTaskTag;
434 UINT8 TotalAHSLength;
435 UINT8 DataSegmentLength[3];
438 UINT32 InitiatorTaskTag;
454 UINT8 TotalAHSLength;
455 UINT8 DataSegmentLength[3];
458 UINT32 InitiatorTaskTag;
475 UINT8 TotalAHSLength;
476 UINT8 DataSegmentLength[3];
478 UINT32 InitiatorTaskTag;
494 UINT8 TotalAHSLength;
495 UINT8 DataSegmentLength[3];
497 UINT32 InitiatorTaskTag;
515 UINT8 TotalAHSLength;
516 UINT8 DataSegmentLength[3];
518 UINT32 InitiatorTaskTag;
519 UINT32 TargetTransferTag;
535 UINT8 TotalAHSLength;
536 UINT8 DataSegmentLength[3];
538 UINT32 InitiatorTaskTag;
553 UINT8 TotalAHSLength;
554 UINT8 DataSegmentLength[3];
556 UINT32 InitiatorTaskTag;
557 UINT32 TargetTransferTag;
569 UINT8 TotalAHSLength;
570 UINT8 DataSegmentLength[3];
572 UINT32 InitiatorTaskTag;
573 UINT32 TargetTransferTag;
586 UINT32 TargetTransferTag;
588 UINT32 DesiredLength;
600 BOOLEAN SoFarInOrder;
602 BOOLEAN FbitReceived;
607 UINT32 InitiatorTaskTag;
863 IN BOOLEAN HeaderDigest,
864 IN BOOLEAN DataDigest,
EFI_STATUS IScsiSessionReinstatement(IN ISCSI_SESSION *Session)
EFI_STATUS IScsiSendLoginReq(IN ISCSI_CONNECTION *Conn)
EFI_STATUS IScsiReceiveLoginRsp(IN ISCSI_CONNECTION *Conn)
VOID EFIAPI IScsiFreeNbufList(VOID *Arg)
struct _ISCSI_SNACK_REQUEST ISCSI_SNACK_REQUEST
struct _ISCSI_LOGIN_RESPONSE ISCSI_LOGIN_RESPONSE
VOID IScsiAttatchConnection(IN OUT ISCSI_SESSION *Session, IN OUT ISCSI_CONNECTION *Conn)
EFI_STATUS IScsiExecuteScsiCommand(IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru, IN UINT8 *Target, IN UINT64 Lun, IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet)
VOID IScsiSessionAbort(IN OUT ISCSI_SESSION *Session)
NET_BUF * IScsiPrepareLoginReq(IN OUT ISCSI_CONNECTION *Conn)
EFI_STATUS IScsiProcessLoginRsp(IN OUT ISCSI_CONNECTION *Conn, IN OUT NET_BUF *Pdu)
VOID IScsiFillOpParams(IN ISCSI_CONNECTION *Conn, IN OUT NET_BUF *Pdu)
struct _ISCSI_REJECT ISCSI_REJECT
VOID IScsiDestroyConnection(IN ISCSI_CONNECTION *Conn)
VOID IScsiFreeKeyValueList(IN LIST_ENTRY *KeyValueList)
CHAR8 * IScsiGetValueByKeyFromList(IN OUT LIST_ENTRY *KeyValueList, IN CHAR8 *Key)
EFI_STATUS IScsiUpdateTargetAddress(IN OUT ISCSI_SESSION *Session, IN CHAR8 *Data, IN UINT32 Len)
struct _ISCSI_LOGIN_REQUEST ISCSI_LOGIN_REQUEST
struct _SCSI_RESPONSE SCSI_RESPONSE
EFI_STATUS IScsiPadSegment(IN OUT NET_BUF *Pdu, IN UINT32 Len)
VOID IScsiDetatchConnection(IN OUT ISCSI_CONNECTION *Conn)
EFI_STATUS IScsiCheckOpParams(IN OUT ISCSI_CONNECTION *Conn)
EFI_STATUS IScsiConnLogin(IN OUT ISCSI_CONNECTION *Conn, IN UINT16 Timeout)
EFI_STATUS IScsiSessionLogin(IN ISCSI_SESSION *Session)
EFI_STATUS IScsiNormalizeName(IN OUT CHAR8 *Name, IN UINTN Len)
LIST_ENTRY * IScsiBuildKeyValueList(IN CHAR8 *Data, IN UINT32 Len)
struct _ISCSI_TMF_RESPONSE ISCSI_TMF_RESPONSE
struct _ISCSI_NOP_IN ISCSI_NOP_IN
struct _ISCSI_BASIC_HEADER ISCSI_BASIC_HEADER
struct _ISCSI_NOP_OUT ISCSI_NOP_OUT
EFI_STATUS IScsiAddKeyValuePair(IN OUT NET_BUF *Pdu, IN CHAR8 *Key, IN CHAR8 *Value)
EFI_STATUS IScsiSessionReLogin(IN ISCSI_SESSION *Session)
struct _ISCSI_SCSI_DATA_IN ISCSI_SCSI_DATA_IN
ISCSI_CONNECTION * IScsiCreateConnection(IN ISCSI_SESSION *Session)
struct _ISCSI_READY_TO_TRANSFER ISCSI_READY_TO_TRANSFER
VOID IScsiSessionInit(IN OUT ISCSI_SESSION *Session, IN BOOLEAN Recovery)
struct _ISCSI_LOGOUT_RESPONSE ISCSI_LOGOUT_RESPONSE
struct _ISCSI_TMF_REQUEST ISCSI_TMF_REQUEST
struct _SCSI_COMMAND SCSI_COMMAND
struct _ISCSI_LOGOUT_REQUEST ISCSI_LOGOUT_REQUEST
struct _ISCSI_SCSI_DATA_OUT ISCSI_SCSI_DATA_OUT
EFI_STATUS IScsiReceivePdu(IN ISCSI_CONNECTION *Conn, OUT NET_BUF **Pdu, IN ISCSI_IN_BUFFER_CONTEXT *Context OPTIONAL, IN BOOLEAN HeaderDigest, IN BOOLEAN DataDigest, IN EFI_EVENT TimeoutEvent OPTIONAL)