2 The implementation of iSCSI protocol based on RFC3720.
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 UINT32 mDataSegPad
= 0;
14 Attach the iSCSI connection to the iSCSI session.
16 @param[in, out] Session The iSCSI session.
17 @param[in, out] Conn The iSCSI connection.
21 IScsiAttatchConnection (
22 IN OUT ISCSI_SESSION
*Session
,
23 IN OUT ISCSI_CONNECTION
*Conn
26 InsertTailList (&Session
->Conns
, &Conn
->Link
);
27 Conn
->Session
= Session
;
32 Detach the iSCSI connection from the session it belongs to.
34 @param[in, out] Conn The iSCSI connection.
38 IScsiDetatchConnection (
39 IN OUT ISCSI_CONNECTION
*Conn
42 RemoveEntryList (&Conn
->Link
);
43 Conn
->Session
->NumConns
--;
49 Check the sequence number according to RFC3720.
51 @param[in, out] ExpSN The currently expected sequence number.
52 @param[in] NewSN The sequence number to check.
54 @retval EFI_SUCCESS The check passed and the ExpSN is increased.
55 @retval EFI_NOT_READY Response was sent due to a retransmission request.
56 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
65 if (!ISCSI_SEQ_EQ (NewSN
, *ExpSN
)) {
66 if (ISCSI_SEQ_LT (NewSN
, *ExpSN
)) {
72 return EFI_PROTOCOL_ERROR
;
85 Update the sequence numbers for the iSCSI command.
87 @param[in, out] Session The iSCSI session.
88 @param[in] MaxCmdSN Maximum CmdSN from the target.
89 @param[in] ExpCmdSN Next expected CmdSN from the target.
94 IN OUT ISCSI_SESSION
*Session
,
99 if (ISCSI_SEQ_LT (MaxCmdSN
, ExpCmdSN
- 1)) {
103 if (ISCSI_SEQ_GT (MaxCmdSN
, Session
->MaxCmdSN
)) {
104 Session
->MaxCmdSN
= MaxCmdSN
;
107 if (ISCSI_SEQ_GT (ExpCmdSN
, Session
->ExpCmdSN
)) {
108 Session
->ExpCmdSN
= ExpCmdSN
;
114 This function does the iSCSI connection login.
116 @param[in, out] Conn The iSCSI connection to login.
117 @param Timeout The timeout value in millisecond.
119 @retval EFI_SUCCESS The iSCSI connection is logged into the iSCSI target.
120 @retval EFI_TIMEOUT Timeout occurred during the login procedure.
121 @retval Others Other errors as indicated.
126 IN OUT ISCSI_CONNECTION
*Conn
,
133 // Start the timer, and wait Timeout seconds to establish the TCP connection.
135 Status
= gBS
->SetTimer (
138 MultU64x32 (Timeout
, TICKS_PER_MS
)
140 if (EFI_ERROR (Status
)) {
145 // Try to establish the tcp connection.
147 Status
= TcpIoConnect (&Conn
->TcpIo
, Conn
->TimeoutEvent
);
148 gBS
->SetTimer (Conn
->TimeoutEvent
, TimerCancel
, 0);
150 if (EFI_ERROR (Status
)) {
154 Conn
->State
= CONN_STATE_IN_LOGIN
;
157 // Connection is established, start the iSCSI Login.
160 Status
= IScsiSendLoginReq (Conn
);
161 if (EFI_ERROR (Status
)) {
165 Status
= IScsiReceiveLoginRsp (Conn
);
166 if (EFI_ERROR (Status
)) {
169 } while (Conn
->CurrentStage
!= ISCSI_FULL_FEATURE_PHASE
);
176 Reset the iSCSI connection.
178 @param[in, out] Conn The iSCSI connection to reset.
183 IN OUT ISCSI_CONNECTION
*Conn
186 TcpIoReset (&Conn
->TcpIo
);
191 Create a TCP connection for the iSCSI session.
193 @param[in] Session Points to the iSCSI session.
195 @return The newly created iSCSI connection.
199 IScsiCreateConnection (
200 IN ISCSI_SESSION
*Session
203 ISCSI_DRIVER_DATA
*Private
;
204 ISCSI_SESSION_CONFIG_NVDATA
*NvData
;
205 ISCSI_CONNECTION
*Conn
;
206 TCP_IO_CONFIG_DATA TcpIoConfig
;
207 TCP4_IO_CONFIG_DATA
*Tcp4IoConfig
;
208 TCP6_IO_CONFIG_DATA
*Tcp6IoConfig
;
211 Private
= Session
->Private
;
212 NvData
= &Session
->ConfigData
->SessionConfigData
;
214 Conn
= AllocateZeroPool (sizeof (ISCSI_CONNECTION
));
219 Conn
->Signature
= ISCSI_CONNECTION_SIGNATURE
;
220 Conn
->State
= CONN_STATE_FREE
;
221 Conn
->CurrentStage
= ISCSI_SECURITY_NEGOTIATION
;
222 Conn
->NextStage
= ISCSI_LOGIN_OPERATIONAL_NEGOTIATION
;
223 Conn
->AuthStep
= ISCSI_AUTH_INITIAL
;
225 Conn
->PartialReqSent
= FALSE
;
226 Conn
->PartialRspRcvd
= FALSE
;
227 Conn
->ParamNegotiated
= FALSE
;
228 Conn
->Cid
= Session
->NextCid
++;
229 Conn
->Ipv6Flag
= NvData
->IpMode
== IP_MODE_IP6
|| Session
->ConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP6
;
231 Status
= gBS
->CreateEvent (
238 if (EFI_ERROR (Status
)) {
243 NetbufQueInit (&Conn
->RspQue
);
246 // Set the default connection-only parameters.
248 Conn
->MaxRecvDataSegmentLength
= DEFAULT_MAX_RECV_DATA_SEG_LEN
;
249 Conn
->HeaderDigest
= IScsiDigestNone
;
250 Conn
->DataDigest
= IScsiDigestNone
;
252 if (NvData
->DnsMode
) {
254 // perform dns process if target address expressed by domain name.
256 if (!Conn
->Ipv6Flag
) {
257 Status
= IScsiDns4 (Private
->Image
, Private
->Controller
, NvData
);
259 Status
= IScsiDns6 (Private
->Image
, Private
->Controller
, NvData
);
262 if (EFI_ERROR(Status
)) {
263 DEBUG ((DEBUG_ERROR
, "The configuration of Target address or DNS server address is invalid!\n"));
269 if (!Conn
->Ipv6Flag
) {
270 Tcp4IoConfig
= &TcpIoConfig
.Tcp4IoConfigData
;
272 CopyMem (&Tcp4IoConfig
->LocalIp
, &NvData
->LocalIp
, sizeof (EFI_IPv4_ADDRESS
));
273 CopyMem (&Tcp4IoConfig
->SubnetMask
, &NvData
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
274 CopyMem (&Tcp4IoConfig
->Gateway
, &NvData
->Gateway
, sizeof (EFI_IPv4_ADDRESS
));
275 CopyMem (&Tcp4IoConfig
->RemoteIp
, &NvData
->TargetIp
, sizeof (EFI_IPv4_ADDRESS
));
277 Tcp4IoConfig
->RemotePort
= NvData
->TargetPort
;
278 Tcp4IoConfig
->ActiveFlag
= TRUE
;
279 Tcp4IoConfig
->StationPort
= 0;
281 Tcp6IoConfig
= &TcpIoConfig
.Tcp6IoConfigData
;
283 CopyMem (&Tcp6IoConfig
->RemoteIp
, &NvData
->TargetIp
, sizeof (EFI_IPv6_ADDRESS
));
284 Tcp6IoConfig
->RemotePort
= NvData
->TargetPort
;
285 Tcp6IoConfig
->ActiveFlag
= TRUE
;
286 Tcp6IoConfig
->StationPort
= 0;
290 // Create the TCP IO for this connection.
292 Status
= TcpIoCreateSocket (
295 (UINT8
) (!Conn
->Ipv6Flag
? TCP_VERSION_4
: TCP_VERSION_6
),
299 if (EFI_ERROR (Status
)) {
300 gBS
->CloseEvent (Conn
->TimeoutEvent
);
310 Destroy an iSCSI connection.
312 @param[in] Conn The connection to destroy.
316 IScsiDestroyConnection (
317 IN ISCSI_CONNECTION
*Conn
320 TcpIoDestroySocket (&Conn
->TcpIo
);
322 NetbufQueFlush (&Conn
->RspQue
);
323 gBS
->CloseEvent (Conn
->TimeoutEvent
);
328 Retrieve the IPv6 Address/Prefix/Gateway from the established TCP connection, these informations
329 will be filled in the iSCSI Boot Firmware Table.
331 @param[in] Conn The connection used in the iSCSI login phase.
333 @retval EFI_SUCCESS Get the NIC information successfully.
334 @retval Others Other errors as indicated.
339 IN ISCSI_CONNECTION
*Conn
342 ISCSI_SESSION_CONFIG_NVDATA
*NvData
;
343 EFI_TCP6_PROTOCOL
*Tcp6
;
344 EFI_IP6_MODE_DATA Ip6ModeData
;
346 EFI_IPv6_ADDRESS
*TargetIp
;
348 UINT8 SubnetPrefixLength
;
351 NvData
= &Conn
->Session
->ConfigData
->SessionConfigData
;
352 TargetIp
= &NvData
->TargetIp
.v6
;
353 Tcp6
= Conn
->TcpIo
.Tcp
.Tcp6
;
355 ZeroMem (&Ip6ModeData
, sizeof (EFI_IP6_MODE_DATA
));
356 Status
= Tcp6
->GetModeData (
364 if (EFI_ERROR (Status
)) {
368 if (!Ip6ModeData
.IsConfigured
) {
369 Status
= EFI_ABORTED
;
373 IP6_COPY_ADDRESS (&NvData
->LocalIp
, &Ip6ModeData
.ConfigData
.StationAddress
);
375 NvData
->PrefixLength
= 0;
376 for (Index
= 0; Index
< Ip6ModeData
.AddressCount
; Index
++) {
377 if (EFI_IP6_EQUAL (&NvData
->LocalIp
.v6
, &Ip6ModeData
.AddressList
[Index
].Address
)) {
378 NvData
->PrefixLength
= Ip6ModeData
.AddressList
[Index
].PrefixLength
;
383 SubnetPrefixLength
= 0;
384 RouteEntry
= Ip6ModeData
.RouteCount
;
385 for (Index
= 0; Index
< Ip6ModeData
.RouteCount
; Index
++) {
386 if (NetIp6IsNetEqual (TargetIp
, &Ip6ModeData
.RouteTable
[Index
].Destination
, Ip6ModeData
.RouteTable
[Index
].PrefixLength
)) {
387 if (SubnetPrefixLength
< Ip6ModeData
.RouteTable
[Index
].PrefixLength
) {
388 SubnetPrefixLength
= Ip6ModeData
.RouteTable
[Index
].PrefixLength
;
393 if (RouteEntry
!= Ip6ModeData
.RouteCount
) {
394 IP6_COPY_ADDRESS (&NvData
->Gateway
, &Ip6ModeData
.RouteTable
[RouteEntry
].Gateway
);
398 if (Ip6ModeData
.AddressList
!= NULL
) {
399 FreePool (Ip6ModeData
.AddressList
);
401 if (Ip6ModeData
.GroupTable
!= NULL
) {
402 FreePool (Ip6ModeData
.GroupTable
);
404 if (Ip6ModeData
.RouteTable
!= NULL
) {
405 FreePool (Ip6ModeData
.RouteTable
);
407 if (Ip6ModeData
.NeighborCache
!= NULL
) {
408 FreePool (Ip6ModeData
.NeighborCache
);
410 if (Ip6ModeData
.PrefixTable
!= NULL
) {
411 FreePool (Ip6ModeData
.PrefixTable
);
413 if (Ip6ModeData
.IcmpTypeList
!= NULL
) {
414 FreePool (Ip6ModeData
.IcmpTypeList
);
421 Re-set any stateful session-level authentication information that is used by
422 the leading login / leading connection.
424 (Note that this driver only supports a single connection per session -- see
425 ISCSI_MAX_CONNS_PER_SESSION.)
427 @param[in,out] Session The iSCSI session.
431 IScsiSessionResetAuthData (
432 IN OUT ISCSI_SESSION
*Session
435 if (Session
->AuthType
== ISCSI_AUTH_TYPE_CHAP
) {
436 Session
->AuthData
.CHAP
.Hash
= NULL
;
441 Login the iSCSI session.
443 @param[in] Session The iSCSI session.
445 @retval EFI_SUCCESS The iSCSI session login procedure finished.
446 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
447 @retval EFI_NO_MEDIA There was a media error.
448 @retval Others Other errors as indicated.
453 IN ISCSI_SESSION
*Session
457 ISCSI_CONNECTION
*Conn
;
459 EFI_GUID
*ProtocolGuid
;
461 EFI_STATUS MediaStatus
;
464 // Check media status before session login.
466 MediaStatus
= EFI_SUCCESS
;
467 NetLibDetectMediaWaitTimeout (Session
->Private
->Controller
, ISCSI_CHECK_MEDIA_LOGIN_WAITING_TIME
, &MediaStatus
);
468 if (MediaStatus
!= EFI_SUCCESS
) {
473 // Set session identifier
475 CopyMem (Session
->Isid
, Session
->ConfigData
->SessionConfigData
.IsId
, 6);
481 // Create a connection for the session.
483 Conn
= IScsiCreateConnection (Session
);
485 return EFI_OUT_OF_RESOURCES
;
488 IScsiAttatchConnection (Session
, Conn
);
491 // Login through the newly created connection.
493 IScsiSessionResetAuthData (Session
);
494 Status
= IScsiConnLogin (Conn
, Session
->ConfigData
->SessionConfigData
.ConnectTimeout
);
495 if (EFI_ERROR (Status
)) {
496 IScsiConnReset (Conn
);
497 IScsiDetatchConnection (Conn
);
498 IScsiDestroyConnection (Conn
);
501 if (Status
!= EFI_TIMEOUT
) {
506 } while (RetryCount
<= Session
->ConfigData
->SessionConfigData
.ConnectRetryCount
);
508 if (!EFI_ERROR (Status
)) {
509 Session
->State
= SESSION_STATE_LOGGED_IN
;
511 if (!Conn
->Ipv6Flag
) {
512 ProtocolGuid
= &gEfiTcp4ProtocolGuid
;
514 ProtocolGuid
= &gEfiTcp6ProtocolGuid
;
517 Status
= gBS
->OpenProtocol (
521 Session
->Private
->Image
,
522 Session
->Private
->ExtScsiPassThruHandle
,
523 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
526 ASSERT_EFI_ERROR (Status
);
528 if (Conn
->Ipv6Flag
) {
529 Status
= IScsiGetIp6NicInfo (Conn
);
538 Wait for IPsec negotiation, then try to login the iSCSI session again.
540 @param[in] Session The iSCSI session.
542 @retval EFI_SUCCESS The iSCSI session login procedure finished.
543 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
544 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
548 IScsiSessionReLogin (
549 IN ISCSI_SESSION
*Session
554 EFI_STATUS TimerStatus
;
557 Status
= gBS
->CreateEvent (EVT_TIMER
, TPL_CALLBACK
, NULL
, NULL
, &Timer
);
558 if (EFI_ERROR (Status
)) {
562 Status
= gBS
->SetTimer (
565 ISCSI_WAIT_IPSEC_TIMEOUT
568 if (EFI_ERROR (Status
)) {
569 gBS
->CloseEvent (Timer
);
575 TimerStatus
= gBS
->CheckEvent (Timer
);
577 if (!EFI_ERROR (TimerStatus
)) {
578 Status
= IScsiSessionLogin (Session
);
581 } while (TimerStatus
== EFI_NOT_READY
);
583 gBS
->CloseEvent (Timer
);
589 Build and send the iSCSI login request to the iSCSI target according to
590 the current login stage.
592 @param[in] Conn The connection in the iSCSI login phase.
594 @retval EFI_SUCCESS The iSCSI login request PDU is built and sent on this
596 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
597 @retval EFI_DEVICE_ERROR Some kind of device error occurred.
602 IN ISCSI_CONNECTION
*Conn
609 // Build the Login Request PDU.
611 Pdu
= IScsiPrepareLoginReq (Conn
);
613 return EFI_DEVICE_ERROR
;
616 // Send it to the iSCSI target.
618 Status
= TcpIoTransmit (&Conn
->TcpIo
, Pdu
);
627 Receive and process the iSCSI login response.
629 @param[in] Conn The connection in the iSCSI login phase.
631 @retval EFI_SUCCESS The iSCSI login response PDU is received and processed.
632 @retval Others Other errors as indicated.
636 IScsiReceiveLoginRsp (
637 IN ISCSI_CONNECTION
*Conn
646 // Receive the iSCSI login response.
648 Status
= IScsiReceivePdu (Conn
, &Pdu
, NULL
, FALSE
, FALSE
, NULL
);
649 if (EFI_ERROR (Status
)) {
652 ASSERT (Pdu
!= NULL
);
655 // A Login Response is received; process it.
657 Status
= IScsiProcessLoginRsp (Conn
, Pdu
);
666 Add an iSCSI key-value pair as a string into the data segment of the Login Request PDU.
667 The DataSegmentLength and the actual size of the net buffer containing this PDU will be
670 @param[in, out] Pdu The iSCSI PDU whose data segment the key-value pair will
672 @param[in] Key The key name string.
673 @param[in] Value The value string.
675 @retval EFI_SUCCESS The key-value pair is added to the PDU's data segment and
676 the correspondence length fields are updated.
677 @retval EFI_OUT_OF_RESOURCES There is not enough space in the PDU to add the key-value
679 @retval EFI_PROTOCOL_ERROR There is no such data in the net buffer.
682 IScsiAddKeyValuePair (
692 ISCSI_LOGIN_REQUEST
*LoginReq
;
695 LoginReq
= (ISCSI_LOGIN_REQUEST
*) NetbufGetByte (Pdu
, 0, NULL
);
696 if (LoginReq
== NULL
) {
697 return EFI_PROTOCOL_ERROR
;
699 DataSegLen
= NTOH24 (LoginReq
->DataSegmentLength
);
701 KeyLen
= (UINT32
) AsciiStrLen (Key
);
702 ValueLen
= (UINT32
) AsciiStrLen (Value
);
705 // 1 byte for the key value separator '=' and 1 byte for the null
706 // delimiter after the value.
708 TotalLen
= KeyLen
+ 1 + ValueLen
+ 1;
711 // Allocate the space for the key-value pair.
713 Data
= (CHAR8
*) NetbufAllocSpace (Pdu
, TotalLen
, NET_BUF_TAIL
);
715 return EFI_OUT_OF_RESOURCES
;
720 CopyMem (Data
, Key
, KeyLen
);
729 CopyMem (Data
, Value
, ValueLen
);
735 // Update the DataSegmentLength
737 ISCSI_SET_DATASEG_LEN (LoginReq
, DataSegLen
+ TotalLen
);
744 Prepare the iSCSI login request to be sent according to the current login status.
746 @param[in, out] Conn The connection in the iSCSI login phase.
748 @return The pointer to the net buffer containing the iSCSI login request built.
749 @retval NULL Other errors as indicated.
753 IScsiPrepareLoginReq (
754 IN OUT ISCSI_CONNECTION
*Conn
757 ISCSI_SESSION
*Session
;
759 ISCSI_LOGIN_REQUEST
*LoginReq
;
762 Session
= Conn
->Session
;
764 Nbuf
= NetbufAlloc (sizeof (ISCSI_LOGIN_REQUEST
) + DEFAULT_MAX_RECV_DATA_SEG_LEN
);
769 LoginReq
= (ISCSI_LOGIN_REQUEST
*) NetbufAllocSpace (Nbuf
, sizeof (ISCSI_LOGIN_REQUEST
), NET_BUF_TAIL
);
770 if (LoginReq
== NULL
) {
774 ZeroMem (LoginReq
, sizeof (ISCSI_LOGIN_REQUEST
));
777 // Init the login request pdu
779 ISCSI_SET_OPCODE (LoginReq
, ISCSI_OPCODE_LOGIN_REQ
, ISCSI_REQ_IMMEDIATE
);
780 ISCSI_SET_STAGES (LoginReq
, Conn
->CurrentStage
, Conn
->NextStage
);
781 LoginReq
->VersionMax
= ISCSI_VERSION_MAX
;
782 LoginReq
->VersionMin
= ISCSI_VERSION_MIN
;
783 LoginReq
->Tsih
= HTONS (Session
->Tsih
);
784 LoginReq
->InitiatorTaskTag
= HTONL (Session
->InitiatorTaskTag
);
785 LoginReq
->Cid
= HTONS (Conn
->Cid
);
786 LoginReq
->CmdSN
= HTONL (Session
->CmdSN
);
789 // For the first Login Request on a connection this is ExpStatSN for the
790 // old connection, and this field is only valid if the Login Request restarts
792 // For subsequent Login Requests it is used to acknowledge the Login Responses
793 // with their increasing StatSN values.
795 LoginReq
->ExpStatSN
= HTONL (Conn
->ExpStatSN
);
796 CopyMem (LoginReq
->Isid
, Session
->Isid
, sizeof (LoginReq
->Isid
));
798 if (Conn
->PartialRspRcvd
) {
800 // A partial response. The initiator must send an empty Login Request.
805 Status
= EFI_SUCCESS
;
807 switch (Conn
->CurrentStage
) {
808 case ISCSI_SECURITY_NEGOTIATION
:
810 // Both none authentication and CHAP authentication share the CHAP path.
813 if (Session
->AuthType
!= ISCSI_AUTH_TYPE_KRB
) {
814 Status
= IScsiCHAPToSendReq (Conn
, Nbuf
);
819 case ISCSI_LOGIN_OPERATIONAL_NEGOTIATION
:
821 // Only negotiate the parameter once.
823 if (!Conn
->ParamNegotiated
) {
824 IScsiFillOpParams (Conn
, Nbuf
);
827 ISCSI_SET_FLAG (LoginReq
, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT
);
832 // An error occurs...
834 Status
= EFI_DEVICE_ERROR
;
838 if (EFI_ERROR (Status
)) {
843 // Pad the data segment if needed.
845 IScsiPadSegment (Nbuf
, ISCSI_GET_DATASEG_LEN (LoginReq
));
847 // Check whether we will issue the stage transition signal?
849 Conn
->TransitInitiated
= ISCSI_FLAG_ON (LoginReq
, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT
);
857 Process the iSCSI Login Response.
859 @param[in, out] Conn The connection on which the iSCSI login response is received.
860 @param[in, out] Pdu The iSCSI login response PDU.
862 @retval EFI_SUCCESS The iSCSI login response PDU is processed, and all checks are passed.
863 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
864 @retval EFI_MEDIA_CHANGED Target is redirected.
865 @retval Others Other errors as indicated.
869 IScsiProcessLoginRsp (
870 IN OUT ISCSI_CONNECTION
*Conn
,
875 ISCSI_SESSION
*Session
;
876 ISCSI_LOGIN_RESPONSE
*LoginRsp
;
884 Status
= EFI_SUCCESS
;
885 Session
= Conn
->Session
;
887 LoginRsp
= (ISCSI_LOGIN_RESPONSE
*) NetbufGetByte (Pdu
, 0, NULL
);
888 if (LoginRsp
== NULL
) {
889 return EFI_PROTOCOL_ERROR
;
891 if (!ISCSI_CHECK_OPCODE (LoginRsp
, ISCSI_OPCODE_LOGIN_RSP
)) {
893 // It is not a Login Response.
895 return EFI_PROTOCOL_ERROR
;
898 // Get the data segment, if any.
900 DataSegLen
= ISCSI_GET_DATASEG_LEN (LoginRsp
);
901 if (DataSegLen
!= 0) {
902 DataSeg
= NetbufGetByte (Pdu
, sizeof (ISCSI_LOGIN_RESPONSE
), NULL
);
907 // Check the status class in the login response PDU.
909 switch (LoginRsp
->StatusClass
) {
910 case ISCSI_LOGIN_STATUS_SUCCESS
:
912 // Just break here; the response and the data segment will be processed later.
916 case ISCSI_LOGIN_STATUS_REDIRECTION
:
918 // The target may be moved to a different address.
920 if (DataSeg
== NULL
) {
921 return EFI_PROTOCOL_ERROR
;
924 // Process the TargetAddress key-value strings in the data segment to update the
925 // target address info.
927 Status
= IScsiUpdateTargetAddress (Session
, (CHAR8
*) DataSeg
, DataSegLen
);
928 if (EFI_ERROR (Status
)) {
932 // Session will be restarted on this error status because the Target is
933 // redirected by this Login Response.
935 return EFI_MEDIA_CHANGED
;
939 // Initiator Error, Target Error, or any other undefined error code.
941 return EFI_PROTOCOL_ERROR
;
944 // The status is success; extract the wanted fields from the header segment.
946 Transit
= ISCSI_FLAG_ON (LoginRsp
, ISCSI_LOGIN_RSP_PDU_FLAG_TRANSIT
);
947 Continue
= ISCSI_FLAG_ON (LoginRsp
, ISCSI_LOGIN_RSP_PDU_FLAG_CONTINUE
);
949 CurrentStage
= ISCSI_GET_CURRENT_STAGE (LoginRsp
);
950 NextStage
= ISCSI_GET_NEXT_STAGE (LoginRsp
);
952 LoginRsp
->InitiatorTaskTag
= NTOHL (LoginRsp
->InitiatorTaskTag
);
954 if ((Transit
&& Continue
) ||
955 (CurrentStage
!= Conn
->CurrentStage
) ||
956 (!Conn
->TransitInitiated
&& Transit
) ||
957 (Transit
&& (NextStage
!= Conn
->NextStage
)) ||
958 (CompareMem (Session
->Isid
, LoginRsp
->Isid
, sizeof (LoginRsp
->Isid
)) != 0) ||
959 (LoginRsp
->InitiatorTaskTag
!= Session
->InitiatorTaskTag
)
962 // A Login Response with the C bit set to 1 MUST have the T bit set to 0.
963 // The CSG in the Login Response MUST be the same with the I-end of this connection.
964 // The T bit can't be 1 if the last Login Response sent by the initiator doesn't
965 // initiate the transition.
966 // The NSG MUST be the same with the I-end of this connection if Transit is required.
967 // The ISID in the Login Response MUST be the same with this session.
969 return EFI_PROTOCOL_ERROR
;
972 LoginRsp
->StatSN
= NTOHL (LoginRsp
->StatSN
);
973 LoginRsp
->ExpCmdSN
= NTOHL (LoginRsp
->ExpCmdSN
);
974 LoginRsp
->MaxCmdSN
= NTOHL (LoginRsp
->MaxCmdSN
);
976 if ((Conn
->CurrentStage
== ISCSI_SECURITY_NEGOTIATION
) && (Conn
->AuthStep
== ISCSI_AUTH_INITIAL
)) {
978 // If the Login Request is a leading Login Request, the target MUST use
979 // the value presented in CmdSN as the target value for ExpCmdSN.
981 if ((Session
->State
== SESSION_STATE_FREE
) && (Session
->CmdSN
!= LoginRsp
->ExpCmdSN
)) {
982 return EFI_PROTOCOL_ERROR
;
986 // It's the initial Login Response, initialize the local ExpStatSN, MaxCmdSN
989 Conn
->ExpStatSN
= LoginRsp
->StatSN
+ 1;
990 Session
->MaxCmdSN
= LoginRsp
->MaxCmdSN
;
991 Session
->ExpCmdSN
= LoginRsp
->ExpCmdSN
;
994 // Check the StatSN of this PDU.
996 Status
= IScsiCheckSN (&Conn
->ExpStatSN
, LoginRsp
->StatSN
);
997 if (!EFI_ERROR (Status
)) {
999 // Update the MaxCmdSN and ExpCmdSN.
1001 IScsiUpdateCmdSN (Session
, LoginRsp
->MaxCmdSN
, LoginRsp
->ExpCmdSN
);
1007 // Trim off the header segment.
1009 NetbufTrim (Pdu
, sizeof (ISCSI_LOGIN_RESPONSE
), NET_BUF_HEAD
);
1012 // Queue this login response first in case it's a partial response so that
1013 // later when the full response list is received we can combine these scattered
1014 // responses' data segment and then process it.
1017 NetbufQueAppend (&Conn
->RspQue
, Pdu
);
1019 Conn
->PartialRspRcvd
= Continue
;
1022 // It is a partial response; must wait for another or more Request/Response
1023 // conversations to get the full response.
1028 switch (CurrentStage
) {
1029 case ISCSI_SECURITY_NEGOTIATION
:
1031 // In security negotiation stage, let CHAP module handle it.
1033 if (Session
->AuthType
!= ISCSI_AUTH_TYPE_KRB
) {
1034 Status
= IScsiCHAPOnRspReceived (Conn
);
1038 case ISCSI_LOGIN_OPERATIONAL_NEGOTIATION
:
1040 // Response received with negotiation response on iSCSI parameters: check them.
1042 Status
= IScsiCheckOpParams (Conn
);
1043 if (!EFI_ERROR (Status
)) {
1044 Conn
->ParamNegotiated
= TRUE
;
1051 // Should never get here.
1053 Status
= EFI_PROTOCOL_ERROR
;
1057 if (Transit
&& (Status
== EFI_SUCCESS
)) {
1059 // Do the state transition.
1061 Conn
->CurrentStage
= Conn
->NextStage
;
1063 if (Conn
->CurrentStage
== ISCSI_LOGIN_OPERATIONAL_NEGOTIATION
) {
1064 Conn
->NextStage
= ISCSI_FULL_FEATURE_PHASE
;
1067 // CurrentStage is iSCSI Full Feature. It is the Login-Final Response;
1068 // get the TSIH from the Login Response.
1070 Session
->Tsih
= NTOHS (LoginRsp
->Tsih
);
1074 // Flush the response(s) received.
1076 NetbufQueFlush (&Conn
->RspQue
);
1083 Updated the target information according the data received in the iSCSI
1084 login response with an target redirection status.
1086 @param[in, out] Session The iSCSI session.
1087 @param[in] Data The data segment that should contain the
1088 TargetAddress key-value list.
1089 @param[in] Len Length of the data.
1091 @retval EFI_SUCCESS The target address is updated.
1092 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1093 @retval EFI_NOT_FOUND The TargetAddress key is not found.
1094 @retval Others Other errors as indicated.
1098 IScsiUpdateTargetAddress (
1099 IN OUT ISCSI_SESSION
*Session
,
1104 LIST_ENTRY
*KeyValueList
;
1105 CHAR8
*TargetAddress
;
1110 ISCSI_SESSION_CONFIG_NVDATA
*NvData
;
1112 KeyValueList
= IScsiBuildKeyValueList (Data
, Len
);
1113 if (KeyValueList
== NULL
) {
1114 return EFI_OUT_OF_RESOURCES
;
1117 Status
= EFI_NOT_FOUND
;
1118 NvData
= &Session
->ConfigData
->SessionConfigData
;
1121 TargetAddress
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_TARGET_ADDRESS
);
1122 if (TargetAddress
== NULL
) {
1127 // RFC 3720 defines format of the TargetAddress=domainname[:port][,portal-group-tag]
1128 // The domainname can be specified as either a DNS host name, adotted-decimal IPv4 address,
1129 // or a bracketed IPv6 address as specified in [RFC2732].
1131 if (NET_IS_DIGIT (TargetAddress
[0])) {
1133 // The domainname of the target is presented in a dotted-decimal IPv4 address format.
1135 IpStr
= TargetAddress
;
1137 while ((*TargetAddress
!= '\0') && (*TargetAddress
!= ':') && (*TargetAddress
!= ',')) {
1139 // NULL, ':', or ',' ends the IPv4 string.
1143 } else if (*TargetAddress
== ISCSI_REDIRECT_ADDR_START_DELIMITER
){
1145 // The domainname of the target is presented in a bracketed IPv6 address format.
1148 IpStr
= TargetAddress
;
1149 while ((*TargetAddress
!= '\0') && (*TargetAddress
!= ISCSI_REDIRECT_ADDR_END_DELIMITER
)) {
1151 // ']' ends the IPv6 string.
1156 if (*TargetAddress
!= ISCSI_REDIRECT_ADDR_END_DELIMITER
) {
1160 *TargetAddress
= '\0';
1165 // The domainname of the target is presented in the format of a DNS host name.
1167 IpStr
= TargetAddress
;
1169 while ((*TargetAddress
!= '\0') && (*TargetAddress
!= ':') && (*TargetAddress
!= ',')) {
1172 NvData
->DnsMode
= TRUE
;
1176 // Save the original user setting which specifies the proxy/virtual iSCSI target.
1178 NvData
->OriginalTargetPort
= NvData
->TargetPort
;
1180 if (*TargetAddress
== ',') {
1182 // Comma and the portal group tag MUST be omitted if the TargetAddress is sent
1183 // as the result of a redirection.
1186 } else if (*TargetAddress
== ':') {
1187 *TargetAddress
= '\0';
1191 Number
= AsciiStrDecimalToUintn (TargetAddress
);
1192 if (Number
> 0xFFFF) {
1195 NvData
->TargetPort
= (UINT16
) Number
;
1199 // The string only contains the Target address. Use the well-known port.
1201 NvData
->TargetPort
= ISCSI_WELL_KNOWN_PORT
;
1205 // Save the original user setting which specifies the proxy/virtual iSCSI target.
1207 CopyMem (&NvData
->OriginalTargetIp
, &NvData
->TargetIp
, sizeof (EFI_IP_ADDRESS
));
1210 // Update the target IP address.
1212 if (NvData
->IpMode
< IP_MODE_AUTOCONFIG
) {
1213 IpMode
= NvData
->IpMode
;
1215 IpMode
= Session
->ConfigData
->AutoConfigureMode
;
1218 if (NvData
->DnsMode
) {
1220 // Target address is expressed as URL format, just save it and
1221 // do DNS resolution when creating a TCP connection.
1223 if (AsciiStrSize (IpStr
) > sizeof (Session
->ConfigData
->SessionConfigData
.TargetUrl
)){
1224 return EFI_INVALID_PARAMETER
;
1226 CopyMem (&Session
->ConfigData
->SessionConfigData
.TargetUrl
, IpStr
, AsciiStrSize (IpStr
));
1228 Status
= IScsiAsciiStrToIp (
1231 &Session
->ConfigData
->SessionConfigData
.TargetIp
1234 if (EFI_ERROR (Status
)) {
1237 NvData
->RedirectFlag
= TRUE
;
1243 IScsiFreeKeyValueList (KeyValueList
);
1250 The callback function to free the net buffer list.
1252 @param[in] Arg The opaque parameter.
1261 ASSERT (Arg
!= NULL
);
1263 NetbufFreeList ((LIST_ENTRY
*) Arg
);
1269 The callback function called in NetBufFree; it does nothing.
1271 @param[in] Arg The opaque parameter.
1284 Receive an iSCSI response PDU. An iSCSI response PDU contains an iSCSI PDU header and
1285 an optional data segment. The two parts will be put into two blocks of buffers in the
1286 net buffer. The digest check will be conducted in this function if needed and the digests
1287 will be trimmed from the PDU buffer.
1289 @param[in] Conn The iSCSI connection to receive data from.
1290 @param[out] Pdu The received iSCSI pdu.
1291 @param[in] Context The context used to describe information on the caller provided
1292 buffer to receive data segment of the iSCSI pdu. It is optional.
1293 @param[in] HeaderDigest Whether there will be header digest received.
1294 @param[in] DataDigest Whether there will be data digest.
1295 @param[in] TimeoutEvent The timeout event. It is optional.
1297 @retval EFI_SUCCESS An iSCSI pdu is received.
1298 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1299 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
1300 @retval Others Other errors as indicated.
1305 IN ISCSI_CONNECTION
*Conn
,
1307 IN ISCSI_IN_BUFFER_CONTEXT
*Context
, OPTIONAL
1308 IN BOOLEAN HeaderDigest
,
1309 IN BOOLEAN DataDigest
,
1310 IN EFI_EVENT TimeoutEvent OPTIONAL
1313 LIST_ENTRY
*NbufList
;
1319 UINT32 InDataOffset
;
1320 NET_FRAGMENT Fragment
[2];
1321 UINT32 FragmentCount
;
1323 UINT32 PadAndCRC32
[2];
1325 NbufList
= AllocatePool (sizeof (LIST_ENTRY
));
1326 if (NbufList
== NULL
) {
1327 return EFI_OUT_OF_RESOURCES
;
1330 InitializeListHead (NbufList
);
1333 // The header digest will be received together with the PDU header, if exists.
1335 Len
= sizeof (ISCSI_BASIC_HEADER
) + (HeaderDigest
? sizeof (UINT32
) : 0);
1336 PduHdr
= NetbufAlloc (Len
);
1337 if (PduHdr
== NULL
) {
1338 Status
= EFI_OUT_OF_RESOURCES
;
1342 Header
= NetbufAllocSpace (PduHdr
, Len
, NET_BUF_TAIL
);
1343 if (Header
== NULL
) {
1344 Status
= EFI_OUT_OF_RESOURCES
;
1347 InsertTailList (NbufList
, &PduHdr
->List
);
1350 // First step, receive the BHS of the PDU.
1352 Status
= TcpIoReceive (&Conn
->TcpIo
, PduHdr
, FALSE
, TimeoutEvent
);
1354 if (EFI_ERROR (Status
)) {
1360 // TODO: check the header-digest.
1363 // Trim off the digest.
1365 NetbufTrim (PduHdr
, sizeof (UINT32
), NET_BUF_TAIL
);
1368 Len
= ISCSI_GET_DATASEG_LEN (Header
);
1376 // Get the length of the padding bytes of the data segment.
1378 PadLen
= ISCSI_GET_PAD_LEN (Len
);
1380 switch (ISCSI_GET_OPCODE (Header
)) {
1381 case ISCSI_OPCODE_SCSI_DATA_IN
:
1383 // To reduce memory copy overhead, try to use the buffer described by Context
1384 // if the PDU is an iSCSI SCSI data.
1386 InDataOffset
= ISCSI_GET_BUFFER_OFFSET (Header
);
1387 if ((Context
== NULL
) || ((InDataOffset
+ Len
) > Context
->InDataLen
)) {
1388 Status
= EFI_PROTOCOL_ERROR
;
1392 Fragment
[0].Len
= Len
;
1393 Fragment
[0].Bulk
= Context
->InData
+ InDataOffset
;
1395 if (DataDigest
|| (PadLen
!= 0)) {
1397 // The data segment is padded. Use two fragments to receive it:
1398 // the first to receive the useful data; the second to receive the padding.
1400 Fragment
[1].Len
= PadLen
+ (DataDigest
? sizeof (UINT32
) : 0);
1401 Fragment
[1].Bulk
= (UINT8
*)PadAndCRC32
+ (4 - PadLen
);
1408 DataSeg
= NetbufFromExt (&Fragment
[0], FragmentCount
, 0, 0, IScsiNbufExtFree
, NULL
);
1409 if (DataSeg
== NULL
) {
1410 Status
= EFI_OUT_OF_RESOURCES
;
1416 case ISCSI_OPCODE_SCSI_RSP
:
1417 case ISCSI_OPCODE_NOP_IN
:
1418 case ISCSI_OPCODE_LOGIN_RSP
:
1419 case ISCSI_OPCODE_TEXT_RSP
:
1420 case ISCSI_OPCODE_ASYNC_MSG
:
1421 case ISCSI_OPCODE_REJECT
:
1422 case ISCSI_OPCODE_VENDOR_T0
:
1423 case ISCSI_OPCODE_VENDOR_T1
:
1424 case ISCSI_OPCODE_VENDOR_T2
:
1426 // Allocate buffer to receive the data segment.
1428 Len
+= PadLen
+ (DataDigest
? sizeof (UINT32
) : 0);
1429 DataSeg
= NetbufAlloc (Len
);
1430 if (DataSeg
== NULL
) {
1431 Status
= EFI_OUT_OF_RESOURCES
;
1435 NetbufAllocSpace (DataSeg
, Len
, NET_BUF_TAIL
);
1439 Status
= EFI_PROTOCOL_ERROR
;
1443 InsertTailList (NbufList
, &DataSeg
->List
);
1446 // Receive the data segment with the data digest, if any.
1448 Status
= TcpIoReceive (&Conn
->TcpIo
, DataSeg
, FALSE
, TimeoutEvent
);
1450 if (EFI_ERROR (Status
)) {
1456 // TODO: Check the data digest.
1458 NetbufTrim (DataSeg
, sizeof (UINT32
), NET_BUF_TAIL
);
1463 // Trim off the padding bytes in the data segment.
1465 NetbufTrim (DataSeg
, PadLen
, NET_BUF_TAIL
);
1470 // Form the pdu from a list of pdu segments.
1472 *Pdu
= NetbufFromBufList (NbufList
, 0, 0, IScsiFreeNbufList
, NbufList
);
1474 Status
= EFI_OUT_OF_RESOURCES
;
1479 if (EFI_ERROR (Status
)) {
1481 // Free the Nbufs in this NbufList and the NbufList itself.
1483 IScsiFreeNbufList (NbufList
);
1491 Check and get the result of the parameter negotiation.
1493 @param[in, out] Conn The connection in iSCSI login.
1495 @retval EFI_SUCCESS The parameter check is passed and negotiation is finished.
1496 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
1497 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1501 IScsiCheckOpParams (
1502 IN OUT ISCSI_CONNECTION
*Conn
1506 LIST_ENTRY
*KeyValueList
;
1509 ISCSI_SESSION
*Session
;
1513 ASSERT (Conn
->RspQue
.BufNum
!= 0);
1515 Session
= Conn
->Session
;
1517 Len
= Conn
->RspQue
.BufSize
;
1518 Data
= AllocatePool (Len
);
1520 return EFI_OUT_OF_RESOURCES
;
1523 NetbufQueCopy (&Conn
->RspQue
, 0, Len
, (UINT8
*) Data
);
1525 Status
= EFI_PROTOCOL_ERROR
;
1528 // Extract the Key-Value pairs into a list.
1530 KeyValueList
= IScsiBuildKeyValueList (Data
, Len
);
1531 if (KeyValueList
== NULL
) {
1538 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_HEADER_DIGEST
);
1539 if (Value
== NULL
) {
1543 if (AsciiStrCmp (Value
, "CRC32") == 0) {
1544 if (Conn
->HeaderDigest
!= IScsiDigestCRC32
) {
1547 } else if (AsciiStrCmp (Value
, ISCSI_KEY_VALUE_NONE
) == 0) {
1548 Conn
->HeaderDigest
= IScsiDigestNone
;
1555 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_DIGEST
);
1556 if (Value
== NULL
) {
1560 if (AsciiStrCmp (Value
, "CRC32") == 0) {
1561 if (Conn
->DataDigest
!= IScsiDigestCRC32
) {
1564 } else if (AsciiStrCmp (Value
, ISCSI_KEY_VALUE_NONE
) == 0) {
1565 Conn
->DataDigest
= IScsiDigestNone
;
1570 // ErrorRecoveryLevel: result function is Minimum.
1572 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_ERROR_RECOVERY_LEVEL
);
1573 if (Value
== NULL
) {
1577 NumericValue
= IScsiNetNtoi (Value
);
1578 if (NumericValue
> 2) {
1582 Session
->ErrorRecoveryLevel
= (UINT8
) MIN (Session
->ErrorRecoveryLevel
, NumericValue
);
1585 // InitialR2T: result function is OR.
1587 if (!Session
->InitialR2T
) {
1588 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_INITIAL_R2T
);
1589 if (Value
== NULL
) {
1593 Session
->InitialR2T
= (BOOLEAN
) (AsciiStrCmp (Value
, "Yes") == 0);
1597 // ImmediateData: result function is AND.
1599 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_IMMEDIATE_DATA
);
1600 if (Value
== NULL
) {
1604 Session
->ImmediateData
= (BOOLEAN
) (Session
->ImmediateData
&& (BOOLEAN
) (AsciiStrCmp (Value
, "Yes") == 0));
1607 // MaxRecvDataSegmentLength is declarative.
1609 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_MAX_RECV_DATA_SEGMENT_LENGTH
);
1610 if (Value
!= NULL
) {
1611 Conn
->MaxRecvDataSegmentLength
= (UINT32
) IScsiNetNtoi (Value
);
1614 // MaxBurstLength: result function is Minimum.
1616 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_MAX_BURST_LENGTH
);
1617 if (Value
== NULL
) {
1621 NumericValue
= IScsiNetNtoi (Value
);
1622 Session
->MaxBurstLength
= (UINT32
) MIN (Session
->MaxBurstLength
, NumericValue
);
1625 // FirstBurstLength: result function is Minimum. Irrelevant when InitialR2T=Yes and
1626 // ImmediateData=No.
1628 if (!(Session
->InitialR2T
&& !Session
->ImmediateData
)) {
1629 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_FIRST_BURST_LENGTH
);
1630 if (Value
== NULL
) {
1634 NumericValue
= IScsiNetNtoi (Value
);
1635 Session
->FirstBurstLength
= (UINT32
) MIN (Session
->FirstBurstLength
, NumericValue
);
1639 // MaxConnections: result function is Minimum.
1641 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_MAX_CONNECTIONS
);
1642 if (Value
== NULL
) {
1646 NumericValue
= IScsiNetNtoi (Value
);
1647 if ((NumericValue
== 0) || (NumericValue
> 65535)) {
1651 Session
->MaxConnections
= (UINT32
) MIN (Session
->MaxConnections
, NumericValue
);
1654 // DataPDUInOrder: result function is OR.
1656 if (!Session
->DataPDUInOrder
) {
1657 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_PDU_IN_ORDER
);
1658 if (Value
== NULL
) {
1662 Session
->DataPDUInOrder
= (BOOLEAN
) (AsciiStrCmp (Value
, "Yes") == 0);
1666 // DataSequenceInorder: result function is OR.
1668 if (!Session
->DataSequenceInOrder
) {
1669 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_SEQUENCE_IN_ORDER
);
1670 if (Value
== NULL
) {
1674 Session
->DataSequenceInOrder
= (BOOLEAN
) (AsciiStrCmp (Value
, "Yes") == 0);
1678 // DefaultTime2Wait: result function is Maximum.
1680 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DEFAULT_TIME2WAIT
);
1681 if (Value
== NULL
) {
1685 NumericValue
= IScsiNetNtoi (Value
);
1686 if (NumericValue
== 0) {
1687 Session
->DefaultTime2Wait
= 0;
1688 } else if (NumericValue
> 3600) {
1691 Session
->DefaultTime2Wait
= (UINT32
) MAX (Session
->DefaultTime2Wait
, NumericValue
);
1694 // DefaultTime2Retain: result function is Minimum.
1696 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DEFAULT_TIME2RETAIN
);
1697 if (Value
== NULL
) {
1701 NumericValue
= IScsiNetNtoi (Value
);
1702 if (NumericValue
== 0) {
1703 Session
->DefaultTime2Retain
= 0;
1704 } else if (NumericValue
> 3600) {
1707 Session
->DefaultTime2Retain
= (UINT32
) MIN (Session
->DefaultTime2Retain
, NumericValue
);
1710 // MaxOutstandingR2T: result function is Minimum.
1712 Value
= IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_MAX_OUTSTANDING_R2T
);
1713 if (Value
== NULL
) {
1717 NumericValue
= IScsiNetNtoi (Value
);
1718 if ((NumericValue
== 0) || (NumericValue
> 65535)) {
1722 Session
->MaxOutstandingR2T
= (UINT16
) MIN (Session
->MaxOutstandingR2T
, NumericValue
);
1725 // Remove declarative key-value pairs, if any.
1727 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_SESSION_TYPE
);
1728 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_TARGET_ALIAS
);
1729 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_TARGET_PORTAL_GROUP_TAG
);
1733 // Remove the key-value that may not needed for result function is OR.
1735 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_INITIAL_R2T
);
1736 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_PDU_IN_ORDER
);
1737 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_DATA_SEQUENCE_IN_ORDER
);
1740 // Remove irrelevant parameter, if any.
1742 if (Session
->InitialR2T
&& !Session
->ImmediateData
) {
1743 IScsiGetValueByKeyFromList (KeyValueList
, ISCSI_KEY_FIRST_BURST_LENGTH
);
1746 if (IsListEmpty (KeyValueList
)) {
1748 // Succeed if no more keys in the list.
1750 Status
= EFI_SUCCESS
;
1755 IScsiFreeKeyValueList (KeyValueList
);
1764 Fill the operational parameters.
1766 @param[in] Conn The connection in iSCSI login.
1767 @param[in, out] Pdu The iSCSI login request PDU to fill the parameters.
1772 IN ISCSI_CONNECTION
*Conn
,
1776 ISCSI_SESSION
*Session
;
1779 Session
= Conn
->Session
;
1781 AsciiSPrint (Value
, sizeof (Value
), "%a", (Conn
->HeaderDigest
== IScsiDigestCRC32
) ? "None,CRC32" : "None");
1782 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_HEADER_DIGEST
, Value
);
1784 AsciiSPrint (Value
, sizeof (Value
), "%a", (Conn
->DataDigest
== IScsiDigestCRC32
) ? "None,CRC32" : "None");
1785 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DATA_DIGEST
, Value
);
1787 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->ErrorRecoveryLevel
);
1788 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_ERROR_RECOVERY_LEVEL
, Value
);
1790 AsciiSPrint (Value
, sizeof (Value
), "%a", Session
->InitialR2T
? "Yes" : "No");
1791 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_INITIAL_R2T
, Value
);
1793 AsciiSPrint (Value
, sizeof (Value
), "%a", Session
->ImmediateData
? "Yes" : "No");
1794 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_IMMEDIATE_DATA
, Value
);
1796 AsciiSPrint (Value
, sizeof (Value
), "%d", MAX_RECV_DATA_SEG_LEN_IN_FFP
);
1797 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_MAX_RECV_DATA_SEGMENT_LENGTH
, Value
);
1799 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->MaxBurstLength
);
1800 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_MAX_BURST_LENGTH
, Value
);
1802 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->FirstBurstLength
);
1803 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_FIRST_BURST_LENGTH
, Value
);
1805 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->MaxConnections
);
1806 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_MAX_CONNECTIONS
, Value
);
1808 AsciiSPrint (Value
, sizeof (Value
), "%a", Session
->DataPDUInOrder
? "Yes" : "No");
1809 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DATA_PDU_IN_ORDER
, Value
);
1811 AsciiSPrint (Value
, sizeof (Value
), "%a", Session
->DataSequenceInOrder
? "Yes" : "No");
1812 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DATA_SEQUENCE_IN_ORDER
, Value
);
1814 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->DefaultTime2Wait
);
1815 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DEFAULT_TIME2WAIT
, Value
);
1817 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->DefaultTime2Retain
);
1818 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_DEFAULT_TIME2RETAIN
, Value
);
1820 AsciiSPrint (Value
, sizeof (Value
), "%d", Session
->MaxOutstandingR2T
);
1821 IScsiAddKeyValuePair (Pdu
, ISCSI_KEY_MAX_OUTSTANDING_R2T
, Value
);
1826 Pad the iSCSI AHS or data segment to an integer number of 4 byte words.
1828 @param[in, out] Pdu The iSCSI pdu which contains segments to pad.
1829 @param[in] Len The length of the last segment in the PDU.
1831 @retval EFI_SUCCESS The segment is padded or there is no need to pad it.
1832 @retval EFI_OUT_OF_RESOURCES There is not enough remaining free space to add the
1837 IN OUT NET_BUF
*Pdu
,
1844 PadLen
= ISCSI_GET_PAD_LEN (Len
);
1847 Data
= NetbufAllocSpace (Pdu
, PadLen
, NET_BUF_TAIL
);
1849 return EFI_OUT_OF_RESOURCES
;
1852 ZeroMem (Data
, PadLen
);
1860 Build a key-value list from the data segment.
1862 @param[in] Data The data segment containing the key-value pairs.
1863 @param[in] Len Length of the data segment.
1865 @return The key-value list.
1866 @retval NULL Other errors as indicated.
1870 IScsiBuildKeyValueList (
1875 LIST_ENTRY
*ListHead
;
1876 ISCSI_KEY_VALUE_PAIR
*KeyValuePair
;
1878 ListHead
= AllocatePool (sizeof (LIST_ENTRY
));
1879 if (ListHead
== NULL
) {
1883 InitializeListHead (ListHead
);
1886 KeyValuePair
= AllocatePool (sizeof (ISCSI_KEY_VALUE_PAIR
));
1887 if (KeyValuePair
== NULL
) {
1891 InitializeListHead (&KeyValuePair
->List
);
1893 KeyValuePair
->Key
= Data
;
1895 while ((Len
> 0) && (*Data
!= '=')) {
1906 FreePool (KeyValuePair
);
1910 KeyValuePair
->Value
= Data
;
1912 InsertTailList (ListHead
, &KeyValuePair
->List
);;
1914 Data
+= AsciiStrLen (KeyValuePair
->Value
) + 1;
1915 Len
-= (UINT32
) AsciiStrLen (KeyValuePair
->Value
) + 1;
1922 IScsiFreeKeyValueList (ListHead
);
1929 Get the value string by the key name from the key-value list. If found,
1930 the key-value entry will be removed from the list.
1932 @param[in, out] KeyValueList The key-value list.
1933 @param[in] Key The key name to find.
1935 @return The value string.
1936 @retval NULL The key value pair cannot be found.
1940 IScsiGetValueByKeyFromList (
1941 IN OUT LIST_ENTRY
*KeyValueList
,
1946 ISCSI_KEY_VALUE_PAIR
*KeyValuePair
;
1951 NET_LIST_FOR_EACH (Entry
, KeyValueList
) {
1952 KeyValuePair
= NET_LIST_USER_STRUCT (Entry
, ISCSI_KEY_VALUE_PAIR
, List
);
1954 if (AsciiStrCmp (KeyValuePair
->Key
, Key
) == 0) {
1955 Value
= KeyValuePair
->Value
;
1957 RemoveEntryList (&KeyValuePair
->List
);
1958 FreePool (KeyValuePair
);
1968 Free the key-value list.
1970 @param[in] KeyValueList The key-value list.
1974 IScsiFreeKeyValueList (
1975 IN LIST_ENTRY
*KeyValueList
1979 ISCSI_KEY_VALUE_PAIR
*KeyValuePair
;
1981 while (!IsListEmpty (KeyValueList
)) {
1982 Entry
= NetListRemoveHead (KeyValueList
);
1983 KeyValuePair
= NET_LIST_USER_STRUCT (Entry
, ISCSI_KEY_VALUE_PAIR
, List
);
1985 FreePool (KeyValuePair
);
1988 FreePool (KeyValueList
);
1993 Normalize the iSCSI name according to RFC.
1995 @param[in, out] Name The iSCSI name.
1996 @param[in] Len Length of the iSCSI name.
1998 @retval EFI_SUCCESS The iSCSI name is valid and normalized.
1999 @retval EFI_PROTOCOL_ERROR The iSCSI name is malformatted or not in the IQN format.
2003 IScsiNormalizeName (
2010 for (Index
= 0; Index
< Len
; Index
++) {
2011 if (NET_IS_UPPER_CASE_CHAR (Name
[Index
])) {
2013 // Convert the upper-case characters to lower-case ones.
2015 Name
[Index
] = (CHAR8
) (Name
[Index
] - 'A' + 'a');
2018 if (!NET_IS_LOWER_CASE_CHAR (Name
[Index
]) &&
2019 !NET_IS_DIGIT (Name
[Index
]) &&
2020 (Name
[Index
] != '-') &&
2021 (Name
[Index
] != '.') &&
2022 (Name
[Index
] != ':')
2025 // ASCII dash, dot, colon lower-case characters and digit characters
2028 return EFI_PROTOCOL_ERROR
;
2032 if ((Len
< 4) || (CompareMem (Name
, "iqn.", 4) != 0)) {
2034 // Only IQN format is accepted now.
2036 return EFI_PROTOCOL_ERROR
;
2044 Create an iSCSI task control block.
2046 @param[in] Conn The connection on which the task control block will be created.
2047 @param[out] Tcb The newly created task control block.
2049 @retval EFI_SUCCESS The task control block is created.
2050 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
2051 @retval EFI_NOT_READY The target cannot accept new commands.
2056 IN ISCSI_CONNECTION
*Conn
,
2060 ISCSI_SESSION
*Session
;
2063 ASSERT (Tcb
!= NULL
);
2065 Session
= Conn
->Session
;
2067 if (ISCSI_SEQ_GT (Session
->CmdSN
, Session
->MaxCmdSN
)) {
2068 return EFI_NOT_READY
;
2071 NewTcb
= AllocateZeroPool (sizeof (ISCSI_TCB
));
2072 if (NewTcb
== NULL
) {
2073 return EFI_OUT_OF_RESOURCES
;
2076 InitializeListHead (&NewTcb
->Link
);
2078 NewTcb
->SoFarInOrder
= TRUE
;
2079 NewTcb
->InitiatorTaskTag
= Session
->InitiatorTaskTag
;
2080 NewTcb
->CmdSN
= Session
->CmdSN
;
2081 NewTcb
->Conn
= Conn
;
2083 InsertTailList (&Session
->TcbList
, &NewTcb
->Link
);
2086 // Advance the initiator task tag.
2088 Session
->InitiatorTaskTag
++;
2098 Delete the tcb from the connection and destroy it.
2100 @param[in] Tcb The tcb to delete.
2108 RemoveEntryList (&Tcb
->Link
);
2115 Create a data segment, pad it, and calculate the CRC if needed.
2117 @param[in] Data The data to fill into the data segment.
2118 @param[in] Len Length of the data.
2119 @param[in] DataDigest Whether to calculate CRC for this data segment.
2121 @return The net buffer wrapping the data segment.
2125 IScsiNewDataSegment (
2128 IN BOOLEAN DataDigest
2131 NET_FRAGMENT Fragment
[2];
2132 UINT32 FragmentCount
;
2136 Fragment
[0].Len
= Len
;
2137 Fragment
[0].Bulk
= Data
;
2139 PadLen
= ISCSI_GET_PAD_LEN (Len
);
2141 Fragment
[1].Len
= PadLen
;
2142 Fragment
[1].Bulk
= (UINT8
*) &mDataSegPad
;
2149 DataSeg
= NetbufFromExt (&Fragment
[0], FragmentCount
, 0, 0, IScsiNbufExtFree
, NULL
);
2156 Create a iSCSI SCSI command PDU to encapsulate the command issued
2157 by SCSI through the EXT SCSI PASS THRU Protocol.
2159 @param[in] Packet The EXT SCSI PASS THRU request packet containing the SCSI command.
2160 @param[in] Lun The LUN.
2161 @param[in] Tcb The tcb associated with this SCSI command.
2163 @return The created iSCSI SCSI command PDU.
2164 @retval NULL Other errors as indicated.
2168 IScsiNewScsiCmdPdu (
2169 IN EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
,
2174 LIST_ENTRY
*NbufList
;
2178 SCSI_COMMAND
*ScsiCmd
;
2181 ISCSI_ADDITIONAL_HEADER
*Header
;
2182 ISCSI_BI_EXP_READ_DATA_LEN_AHS
*BiExpReadDataLenAHS
;
2183 ISCSI_SESSION
*Session
;
2184 UINT32 ImmediateDataLen
;
2188 if (Packet
->DataDirection
== DataBi
) {
2190 // Bidirectional Read/Write command, the bidirectional expected
2191 // read data length AHS is required.
2193 AHSLength
+= sizeof (ISCSI_BI_EXP_READ_DATA_LEN_AHS
);
2196 if (Packet
->CdbLength
> 16) {
2198 // The CDB exceeds 16 bytes. An extended CDB AHS is required.
2200 AHSLength
= (UINT8
) (AHSLength
+ ISCSI_ROUNDUP (Packet
->CdbLength
- 16) + sizeof (ISCSI_ADDITIONAL_HEADER
));
2203 Length
= sizeof (SCSI_COMMAND
) + AHSLength
;
2204 PduHeader
= NetbufAlloc (Length
);
2205 if (PduHeader
== NULL
) {
2209 ScsiCmd
= (SCSI_COMMAND
*) NetbufAllocSpace (PduHeader
, Length
, NET_BUF_TAIL
);
2210 if (ScsiCmd
== NULL
) {
2211 NetbufFree (PduHeader
);
2214 Header
= (ISCSI_ADDITIONAL_HEADER
*) (ScsiCmd
+ 1);
2216 ZeroMem (ScsiCmd
, Length
);
2218 ISCSI_SET_OPCODE (ScsiCmd
, ISCSI_OPCODE_SCSI_CMD
, 0);
2219 ISCSI_SET_FLAG (ScsiCmd
, ISCSI_TASK_ATTR_SIMPLE
);
2222 // Set the READ/WRITE flags according to the IO type of this request.
2224 switch (Packet
->DataDirection
) {
2226 ISCSI_SET_FLAG (ScsiCmd
, SCSI_CMD_PDU_FLAG_READ
);
2227 ScsiCmd
->ExpDataXferLength
= NTOHL (Packet
->InTransferLength
);
2231 ISCSI_SET_FLAG (ScsiCmd
, SCSI_CMD_PDU_FLAG_WRITE
);
2232 ScsiCmd
->ExpDataXferLength
= NTOHL (Packet
->OutTransferLength
);
2236 ISCSI_SET_FLAG (ScsiCmd
, SCSI_CMD_PDU_FLAG_READ
| SCSI_CMD_PDU_FLAG_WRITE
);
2237 ScsiCmd
->ExpDataXferLength
= NTOHL (Packet
->OutTransferLength
);
2240 // Fill the bidirectional expected read data length AHS.
2242 BiExpReadDataLenAHS
= (ISCSI_BI_EXP_READ_DATA_LEN_AHS
*) Header
;
2243 Header
= (ISCSI_ADDITIONAL_HEADER
*) (BiExpReadDataLenAHS
+ 1);
2245 BiExpReadDataLenAHS
->Length
= NTOHS (5);
2246 BiExpReadDataLenAHS
->Type
= ISCSI_AHS_TYPE_BI_EXP_READ_DATA_LEN
;
2247 BiExpReadDataLenAHS
->ExpReadDataLength
= NTOHL (Packet
->InTransferLength
);
2252 ScsiCmd
->TotalAHSLength
= AHSLength
;
2253 CopyMem (ScsiCmd
->Lun
, &Lun
, sizeof (ScsiCmd
->Lun
));
2254 ScsiCmd
->InitiatorTaskTag
= NTOHL (Tcb
->InitiatorTaskTag
);
2255 ScsiCmd
->CmdSN
= NTOHL (Tcb
->CmdSN
);
2256 ScsiCmd
->ExpStatSN
= NTOHL (Tcb
->Conn
->ExpStatSN
);
2258 CopyMem (ScsiCmd
->Cdb
, Packet
->Cdb
, sizeof (ScsiCmd
->Cdb
));
2260 if (Packet
->CdbLength
> 16) {
2261 Header
->Length
= NTOHS ((UINT16
) (Packet
->CdbLength
- 15));
2262 Header
->Type
= ISCSI_AHS_TYPE_EXT_CDB
;
2264 CopyMem (Header
+ 1, (UINT8
*) Packet
->Cdb
+ 16, Packet
->CdbLength
- 16);
2268 Session
= Tcb
->Conn
->Session
;
2269 ImmediateDataLen
= 0;
2271 if (Session
->ImmediateData
&& (Packet
->OutTransferLength
!= 0)) {
2273 // Send immediate data in this SCSI Command PDU. The length of the immediate
2274 // data is the minimum of FirstBurstLength, the data length to be xfered, and
2275 // the MaxRecvdataSegmentLength on this connection.
2277 ImmediateDataLen
= MIN (Session
->FirstBurstLength
, Packet
->OutTransferLength
);
2278 ImmediateDataLen
= MIN (ImmediateDataLen
, Tcb
->Conn
->MaxRecvDataSegmentLength
);
2281 // Update the data segment length in the PDU header.
2283 ISCSI_SET_DATASEG_LEN (ScsiCmd
, ImmediateDataLen
);
2286 // Create the data segment.
2288 DataSeg
= IScsiNewDataSegment ((UINT8
*) Packet
->OutDataBuffer
, ImmediateDataLen
, FALSE
);
2289 if (DataSeg
== NULL
) {
2290 NetbufFree (PduHeader
);
2295 NbufList
= AllocatePool (sizeof (LIST_ENTRY
));
2296 if (NbufList
== NULL
) {
2297 NetbufFree (PduHeader
);
2298 NetbufFree (DataSeg
);
2304 InitializeListHead (NbufList
);
2305 InsertTailList (NbufList
, &PduHeader
->List
);
2306 InsertTailList (NbufList
, &DataSeg
->List
);
2308 Pdu
= NetbufFromBufList (NbufList
, 0, 0, IScsiFreeNbufList
, NbufList
);
2310 IScsiFreeNbufList (NbufList
);
2314 if (Session
->InitialR2T
||
2315 (ImmediateDataLen
== Session
->FirstBurstLength
) ||
2316 (ImmediateDataLen
== Packet
->OutTransferLength
)
2319 // Unsolicited data out sequence is not allowed,
2320 // or FirstBustLength data is already sent out by immediate data,
2321 // or all the OUT data accompany this SCSI packet are sent as
2322 // immediate data. The final flag should be set on this SCSI Command
2325 ISCSI_SET_FLAG (ScsiCmd
, ISCSI_BHS_FLAG_FINAL
);
2335 Create a new iSCSI SCSI Data Out PDU.
2337 @param[in] Data The data to put into the Data Out PDU.
2338 @param[in] Len Length of the data.
2339 @param[in] DataSN The DataSN of the Data Out PDU.
2340 @param[in] Tcb The task control block of this Data Out PDU.
2341 @param[in] Lun The LUN.
2343 @return The net buffer wrapping the Data Out PDU.
2344 @retval NULL Other errors as indicated.
2348 IScsiNewDataOutPdu (
2356 LIST_ENTRY
*NbufList
;
2360 ISCSI_SCSI_DATA_OUT
*DataOutHdr
;
2361 ISCSI_XFER_CONTEXT
*XferContext
;
2363 NbufList
= AllocatePool (sizeof (LIST_ENTRY
));
2364 if (NbufList
== NULL
) {
2368 InitializeListHead (NbufList
);
2371 // Allocate memory for the BHS.
2373 PduHdr
= NetbufAlloc (sizeof (ISCSI_SCSI_DATA_OUT
));
2374 if (PduHdr
== NULL
) {
2375 FreePool (NbufList
);
2379 // Insert the BHS into the buffer list.
2381 InsertTailList (NbufList
, &PduHdr
->List
);
2383 DataOutHdr
= (ISCSI_SCSI_DATA_OUT
*) NetbufAllocSpace (PduHdr
, sizeof (ISCSI_SCSI_DATA_OUT
), NET_BUF_TAIL
);
2384 if (DataOutHdr
== NULL
) {
2385 IScsiFreeNbufList (NbufList
);
2388 XferContext
= &Tcb
->XferContext
;
2390 ZeroMem (DataOutHdr
, sizeof (ISCSI_SCSI_DATA_OUT
));
2393 // Set the flags and fields of the Data Out PDU BHS.
2395 ISCSI_SET_OPCODE (DataOutHdr
, ISCSI_OPCODE_SCSI_DATA_OUT
, 0);
2396 ISCSI_SET_DATASEG_LEN (DataOutHdr
, Len
);
2398 DataOutHdr
->InitiatorTaskTag
= HTONL (Tcb
->InitiatorTaskTag
);
2399 DataOutHdr
->TargetTransferTag
= HTONL (XferContext
->TargetTransferTag
);
2400 DataOutHdr
->ExpStatSN
= HTONL (Tcb
->Conn
->ExpStatSN
);
2401 DataOutHdr
->DataSN
= HTONL (DataSN
);
2402 DataOutHdr
->BufferOffset
= HTONL (XferContext
->Offset
);
2404 if (XferContext
->TargetTransferTag
!= ISCSI_RESERVED_TAG
) {
2405 CopyMem (&DataOutHdr
->Lun
, &Lun
, sizeof (DataOutHdr
->Lun
));
2408 // Build the data segment for this Data Out PDU.
2410 DataSeg
= IScsiNewDataSegment (Data
, Len
, FALSE
);
2411 if (DataSeg
== NULL
) {
2412 IScsiFreeNbufList (NbufList
);
2416 // Put the data segment into the buffer list and combine it with the BHS
2417 // into a full Data Out PDU.
2419 InsertTailList (NbufList
, &DataSeg
->List
);
2420 Pdu
= NetbufFromBufList (NbufList
, 0, 0, IScsiFreeNbufList
, NbufList
);
2422 IScsiFreeNbufList (NbufList
);
2430 Generate a consecutive sequence of iSCSI SCSI Data Out PDUs.
2432 @param[in] Data The data which will be carried by the sequence of iSCSI SCSI Data Out PDUs.
2433 @param[in] Tcb The task control block of the data to send out.
2434 @param[in] Lun The LUN the data will be sent to.
2436 @return A list of net buffers with each of them wrapping an iSCSI SCSI Data Out PDU.
2437 @retval NULL Other errors as indicated.
2441 IScsiGenerateDataOutPduSequence (
2447 LIST_ENTRY
*PduList
;
2450 NET_BUF
*DataOutPdu
;
2451 ISCSI_CONNECTION
*Conn
;
2452 ISCSI_XFER_CONTEXT
*XferContext
;
2453 UINT8
*DataOutPacket
;
2455 PduList
= AllocatePool (sizeof (LIST_ENTRY
));
2456 if (PduList
== NULL
) {
2460 InitializeListHead (PduList
);
2465 XferContext
= &Tcb
->XferContext
;
2467 while (XferContext
->DesiredLength
> 0) {
2469 // Determine the length of data this Data Out PDU can carry.
2471 DataLen
= MIN (XferContext
->DesiredLength
, Conn
->MaxRecvDataSegmentLength
);
2474 // Create a Data Out PDU.
2476 DataOutPdu
= IScsiNewDataOutPdu (Data
, DataLen
, DataSN
, Tcb
, Lun
);
2477 if (DataOutPdu
== NULL
) {
2478 IScsiFreeNbufList (PduList
);
2484 InsertTailList (PduList
, &DataOutPdu
->List
);
2487 // Update the context and DataSN.
2490 XferContext
->Offset
+= DataLen
;
2491 XferContext
->DesiredLength
-= DataLen
;
2495 // Set the F bit for the last data out PDU in this sequence.
2497 DataOutPacket
= NetbufGetByte (DataOutPdu
, 0, NULL
);
2498 if (DataOutPacket
== NULL
) {
2499 IScsiFreeNbufList (PduList
);
2504 ISCSI_SET_FLAG (DataOutPacket
, ISCSI_BHS_FLAG_FINAL
);
2512 Send the Data in a sequence of Data Out PDUs one by one.
2514 @param[in] Data The data to carry by Data Out PDUs.
2515 @param[in] Lun The LUN the data will be sent to.
2516 @param[in] Tcb The task control block.
2518 @retval EFI_SUCCESS The data is sent out to the LUN.
2519 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
2520 @retval Others Other errors as indicated.
2524 IScsiSendDataOutPduSequence (
2530 LIST_ENTRY
*DataOutPduList
;
2536 // Generate the Data Out PDU sequence.
2538 DataOutPduList
= IScsiGenerateDataOutPduSequence (Data
, Tcb
, Lun
);
2539 if (DataOutPduList
== NULL
) {
2540 return EFI_OUT_OF_RESOURCES
;
2543 Status
= EFI_SUCCESS
;
2546 // Send the Data Out PDU's one by one.
2548 NET_LIST_FOR_EACH (Entry
, DataOutPduList
) {
2549 Pdu
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
2551 Status
= TcpIoTransmit (&Tcb
->Conn
->TcpIo
, Pdu
);
2553 if (EFI_ERROR (Status
)) {
2558 IScsiFreeNbufList (DataOutPduList
);
2565 Process the received iSCSI SCSI Data In PDU.
2567 @param[in] Pdu The Data In PDU received.
2568 @param[in] Tcb The task control block.
2569 @param[in, out] Packet The EXT SCSI PASS THRU request packet.
2571 @retval EFI_SUCCESS The check on the Data IN PDU is passed and some update
2573 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
2574 @retval EFI_BAD_BUFFER_SIZEE The buffer was not the proper size for the request.
2575 @retval Others Other errors as indicated.
2582 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
2585 ISCSI_SCSI_DATA_IN
*DataInHdr
;
2588 DataInHdr
= (ISCSI_SCSI_DATA_IN
*) NetbufGetByte (Pdu
, 0, NULL
);
2589 if (DataInHdr
== NULL
) {
2590 return EFI_PROTOCOL_ERROR
;
2593 DataInHdr
->InitiatorTaskTag
= NTOHL (DataInHdr
->InitiatorTaskTag
);
2594 DataInHdr
->ExpCmdSN
= NTOHL (DataInHdr
->ExpCmdSN
);
2595 DataInHdr
->MaxCmdSN
= NTOHL (DataInHdr
->MaxCmdSN
);
2596 DataInHdr
->DataSN
= NTOHL (DataInHdr
->DataSN
);
2599 // Check the DataSN.
2601 Status
= IScsiCheckSN (&Tcb
->ExpDataSN
, DataInHdr
->DataSN
);
2602 if (EFI_ERROR (Status
)) {
2606 if (DataInHdr
->InitiatorTaskTag
!= Tcb
->InitiatorTaskTag
) {
2607 return EFI_PROTOCOL_ERROR
;
2610 // Update the command related sequence numbers.
2612 IScsiUpdateCmdSN (Tcb
->Conn
->Session
, DataInHdr
->MaxCmdSN
, DataInHdr
->ExpCmdSN
);
2614 if (ISCSI_FLAG_ON (DataInHdr
, SCSI_DATA_IN_PDU_FLAG_STATUS_VALID
)) {
2615 if (!ISCSI_FLAG_ON (DataInHdr
, ISCSI_BHS_FLAG_FINAL
)) {
2617 // The S bit is on but the F bit is off.
2619 return EFI_PROTOCOL_ERROR
;
2622 Tcb
->StatusXferd
= TRUE
;
2624 if (ISCSI_FLAG_ON (DataInHdr
, SCSI_DATA_IN_PDU_FLAG_OVERFLOW
| SCSI_DATA_IN_PDU_FLAG_UNDERFLOW
)) {
2626 // Underflow and Overflow are mutual flags.
2628 return EFI_PROTOCOL_ERROR
;
2631 // S bit is on, the StatSN is valid.
2633 Status
= IScsiCheckSN (&Tcb
->Conn
->ExpStatSN
, NTOHL (DataInHdr
->StatSN
));
2634 if (EFI_ERROR (Status
)) {
2638 Packet
->HostAdapterStatus
= 0;
2639 Packet
->TargetStatus
= DataInHdr
->Status
;
2641 if (ISCSI_FLAG_ON (DataInHdr
, SCSI_RSP_PDU_FLAG_OVERFLOW
)) {
2642 Packet
->InTransferLength
+= NTOHL (DataInHdr
->ResidualCount
);
2643 Status
= EFI_BAD_BUFFER_SIZE
;
2646 if (ISCSI_FLAG_ON (DataInHdr
, SCSI_RSP_PDU_FLAG_UNDERFLOW
)) {
2647 Packet
->InTransferLength
-= NTOHL (DataInHdr
->ResidualCount
);
2656 Process the received iSCSI R2T PDU.
2658 @param[in] Pdu The R2T PDU received.
2659 @param[in] Tcb The task control block.
2660 @param[in] Lun The Lun.
2661 @param[in, out] Packet The EXT SCSI PASS THRU request packet.
2663 @retval EFI_SUCCESS The R2T PDU is valid and the solicited data is sent out.
2664 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
2665 @retval Others Other errors as indicated.
2673 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
2676 ISCSI_READY_TO_TRANSFER
*R2THdr
;
2678 ISCSI_XFER_CONTEXT
*XferContext
;
2681 R2THdr
= (ISCSI_READY_TO_TRANSFER
*) NetbufGetByte (Pdu
, 0, NULL
);
2682 if (R2THdr
== NULL
) {
2683 return EFI_PROTOCOL_ERROR
;
2686 R2THdr
->InitiatorTaskTag
= NTOHL (R2THdr
->InitiatorTaskTag
);
2687 R2THdr
->TargetTransferTag
= NTOHL (R2THdr
->TargetTransferTag
);
2688 R2THdr
->StatSN
= NTOHL (R2THdr
->StatSN
);
2689 R2THdr
->R2TSeqNum
= NTOHL (R2THdr
->R2TSeqNum
);
2690 R2THdr
->BufferOffset
= NTOHL (R2THdr
->BufferOffset
);
2691 R2THdr
->DesiredDataTransferLength
= NTOHL (R2THdr
->DesiredDataTransferLength
);
2693 if ((R2THdr
->InitiatorTaskTag
!= Tcb
->InitiatorTaskTag
) || !ISCSI_SEQ_EQ (R2THdr
->StatSN
, Tcb
->Conn
->ExpStatSN
)) {
2694 return EFI_PROTOCOL_ERROR
;;
2697 // Check the sequence number.
2699 Status
= IScsiCheckSN (&Tcb
->ExpDataSN
, R2THdr
->R2TSeqNum
);
2700 if (EFI_ERROR (Status
)) {
2704 XferContext
= &Tcb
->XferContext
;
2705 XferContext
->TargetTransferTag
= R2THdr
->TargetTransferTag
;
2706 XferContext
->Offset
= R2THdr
->BufferOffset
;
2707 XferContext
->DesiredLength
= R2THdr
->DesiredDataTransferLength
;
2709 if (((XferContext
->Offset
+ XferContext
->DesiredLength
) > Packet
->OutTransferLength
) ||
2710 (XferContext
->DesiredLength
> Tcb
->Conn
->Session
->MaxBurstLength
)
2712 return EFI_PROTOCOL_ERROR
;
2715 // Send the data solicited by this R2T.
2717 Data
= (UINT8
*) Packet
->OutDataBuffer
+ XferContext
->Offset
;
2718 Status
= IScsiSendDataOutPduSequence (Data
, Lun
, Tcb
);
2725 Process the received iSCSI SCSI Response PDU.
2727 @param[in] Pdu The Response PDU received.
2728 @param[in] Tcb The task control block.
2729 @param[in, out] Packet The EXT SCSI PASS THRU request packet.
2731 @retval EFI_SUCCESS The Response PDU is processed.
2732 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
2733 @retval EFI_BAD_BUFFER_SIZEE The buffer was not the proper size for the request.
2734 @retval Others Other errors as indicated.
2738 IScsiOnScsiRspRcvd (
2741 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
2744 SCSI_RESPONSE
*ScsiRspHdr
;
2745 ISCSI_SENSE_DATA
*SenseData
;
2749 ScsiRspHdr
= (SCSI_RESPONSE
*) NetbufGetByte (Pdu
, 0, NULL
);
2750 if (ScsiRspHdr
== NULL
) {
2751 return EFI_PROTOCOL_ERROR
;
2754 ScsiRspHdr
->InitiatorTaskTag
= NTOHL (ScsiRspHdr
->InitiatorTaskTag
);
2755 if (ScsiRspHdr
->InitiatorTaskTag
!= Tcb
->InitiatorTaskTag
) {
2756 return EFI_PROTOCOL_ERROR
;
2759 ScsiRspHdr
->StatSN
= NTOHL (ScsiRspHdr
->StatSN
);
2761 Status
= IScsiCheckSN (&Tcb
->Conn
->ExpStatSN
, ScsiRspHdr
->StatSN
);
2762 if (EFI_ERROR (Status
)) {
2766 ScsiRspHdr
->MaxCmdSN
= NTOHL (ScsiRspHdr
->MaxCmdSN
);
2767 ScsiRspHdr
->ExpCmdSN
= NTOHL (ScsiRspHdr
->ExpCmdSN
);
2768 IScsiUpdateCmdSN (Tcb
->Conn
->Session
, ScsiRspHdr
->MaxCmdSN
, ScsiRspHdr
->ExpCmdSN
);
2770 Tcb
->StatusXferd
= TRUE
;
2772 Packet
->HostAdapterStatus
= ScsiRspHdr
->Response
;
2773 if (Packet
->HostAdapterStatus
!= ISCSI_SERVICE_RSP_COMMAND_COMPLETE_AT_TARGET
) {
2777 Packet
->TargetStatus
= ScsiRspHdr
->Status
;
2779 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_BI_READ_OVERFLOW
| SCSI_RSP_PDU_FLAG_BI_READ_UNDERFLOW
) ||
2780 ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_OVERFLOW
| SCSI_RSP_PDU_FLAG_UNDERFLOW
)
2782 return EFI_PROTOCOL_ERROR
;
2785 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_BI_READ_OVERFLOW
)) {
2786 Packet
->InTransferLength
+= NTOHL (ScsiRspHdr
->BiReadResidualCount
);
2787 Status
= EFI_BAD_BUFFER_SIZE
;
2790 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_BI_READ_UNDERFLOW
)) {
2791 Packet
->InTransferLength
-= NTOHL (ScsiRspHdr
->BiReadResidualCount
);
2794 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_OVERFLOW
)) {
2795 if (Packet
->DataDirection
== DataIn
) {
2796 Packet
->InTransferLength
+= NTOHL (ScsiRspHdr
->ResidualCount
);
2798 Packet
->OutTransferLength
+= NTOHL (ScsiRspHdr
->ResidualCount
);
2801 Status
= EFI_BAD_BUFFER_SIZE
;
2804 if (ISCSI_FLAG_ON (ScsiRspHdr
, SCSI_RSP_PDU_FLAG_UNDERFLOW
)) {
2805 if (Packet
->DataDirection
== DataIn
) {
2806 Packet
->InTransferLength
-= NTOHL (ScsiRspHdr
->ResidualCount
);
2808 Packet
->OutTransferLength
-= NTOHL (ScsiRspHdr
->ResidualCount
);
2812 DataSegLen
= ISCSI_GET_DATASEG_LEN (ScsiRspHdr
);
2813 if (DataSegLen
!= 0) {
2814 SenseData
= (ISCSI_SENSE_DATA
*) NetbufGetByte (Pdu
, sizeof (SCSI_RESPONSE
), NULL
);
2815 if (SenseData
== NULL
) {
2816 return EFI_PROTOCOL_ERROR
;
2819 SenseData
->Length
= NTOHS (SenseData
->Length
);
2821 Packet
->SenseDataLength
= (UINT8
) MIN (SenseData
->Length
, Packet
->SenseDataLength
);
2822 if (Packet
->SenseDataLength
!= 0) {
2823 CopyMem (Packet
->SenseData
, &SenseData
->Data
[0], Packet
->SenseDataLength
);
2826 Packet
->SenseDataLength
= 0;
2834 Process the received NOP In PDU.
2836 @param[in] Pdu The NOP In PDU received.
2837 @param[in] Tcb The task control block.
2839 @retval EFI_SUCCESS The NOP In PDU is processed and the related sequence
2840 numbers are updated.
2841 @retval EFI_PROTOCOL_ERROR Some kind of iSCSI protocol error occurred.
2850 ISCSI_NOP_IN
*NopInHdr
;
2853 NopInHdr
= (ISCSI_NOP_IN
*) NetbufGetByte (Pdu
, 0, NULL
);
2854 if (NopInHdr
== NULL
) {
2855 return EFI_PROTOCOL_ERROR
;
2858 NopInHdr
->StatSN
= NTOHL (NopInHdr
->StatSN
);
2859 NopInHdr
->ExpCmdSN
= NTOHL (NopInHdr
->ExpCmdSN
);
2860 NopInHdr
->MaxCmdSN
= NTOHL (NopInHdr
->MaxCmdSN
);
2862 if (NopInHdr
->InitiatorTaskTag
== ISCSI_RESERVED_TAG
) {
2863 if (NopInHdr
->StatSN
!= Tcb
->Conn
->ExpStatSN
) {
2864 return EFI_PROTOCOL_ERROR
;
2867 Status
= IScsiCheckSN (&Tcb
->Conn
->ExpStatSN
, NopInHdr
->StatSN
);
2868 if (EFI_ERROR (Status
)) {
2873 IScsiUpdateCmdSN (Tcb
->Conn
->Session
, NopInHdr
->MaxCmdSN
, NopInHdr
->ExpCmdSN
);
2880 Execute the SCSI command issued through the EXT SCSI PASS THRU protocol.
2882 @param[in] PassThru The EXT SCSI PASS THRU protocol.
2883 @param[in] Target The target ID.
2884 @param[in] Lun The LUN.
2885 @param[in, out] Packet The request packet containing IO request, SCSI command
2886 buffer and buffers to read/write.
2888 @retval EFI_SUCCESS The SCSI command is executed and the result is updated to
2890 @retval EFI_DEVICE_ERROR Session state was not as required.
2891 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
2892 @retval EFI_PROTOCOL_ERROR There is no such data in the net buffer.
2893 @retval EFI_NOT_READY The target can not accept new commands.
2894 @retval Others Other errors as indicated.
2898 IScsiExecuteScsiCommand (
2899 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*PassThru
,
2902 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
2906 ISCSI_DRIVER_DATA
*Private
;
2907 ISCSI_SESSION
*Session
;
2908 EFI_EVENT TimeoutEvent
;
2909 ISCSI_CONNECTION
*Conn
;
2912 ISCSI_XFER_CONTEXT
*XferContext
;
2914 ISCSI_IN_BUFFER_CONTEXT InBufferContext
;
2918 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru
);
2919 Session
= Private
->Session
;
2920 Status
= EFI_SUCCESS
;
2922 TimeoutEvent
= NULL
;
2925 if (Session
->State
!= SESSION_STATE_LOGGED_IN
) {
2926 Status
= EFI_DEVICE_ERROR
;
2930 Conn
= NET_LIST_USER_STRUCT_S (
2931 Session
->Conns
.ForwardLink
,
2934 ISCSI_CONNECTION_SIGNATURE
2937 if (Packet
->Timeout
!= 0) {
2938 Timeout
= MultU64x32 (Packet
->Timeout
, 4);
2941 Status
= IScsiNewTcb (Conn
, &Tcb
);
2942 if (EFI_ERROR (Status
)) {
2946 // Encapsulate the SCSI request packet into an iSCSI SCSI Command PDU.
2948 Pdu
= IScsiNewScsiCmdPdu (Packet
, Lun
, Tcb
);
2950 Status
= EFI_OUT_OF_RESOURCES
;
2954 XferContext
= &Tcb
->XferContext
;
2955 PduHdr
= NetbufGetByte (Pdu
, 0, NULL
);
2956 if (PduHdr
== NULL
) {
2957 Status
= EFI_PROTOCOL_ERROR
;
2961 XferContext
->Offset
= ISCSI_GET_DATASEG_LEN (PduHdr
);
2964 // Transmit the SCSI Command PDU.
2966 Status
= TcpIoTransmit (&Conn
->TcpIo
, Pdu
);
2970 if (EFI_ERROR (Status
)) {
2974 if (!Session
->InitialR2T
&&
2975 (XferContext
->Offset
< Session
->FirstBurstLength
) &&
2976 (XferContext
->Offset
< Packet
->OutTransferLength
)
2979 // Unsolicited Data-Out sequence is allowed. There is remaining SCSI
2980 // OUT data, and the limit of FirstBurstLength is not reached.
2982 XferContext
->TargetTransferTag
= ISCSI_RESERVED_TAG
;
2983 XferContext
->DesiredLength
= MIN (
2984 Session
->FirstBurstLength
,
2985 Packet
->OutTransferLength
- XferContext
->Offset
2988 Data
= (UINT8
*) Packet
->OutDataBuffer
+ XferContext
->Offset
;
2989 Status
= IScsiSendDataOutPduSequence (Data
, Lun
, Tcb
);
2990 if (EFI_ERROR (Status
)) {
2995 InBufferContext
.InData
= (UINT8
*) Packet
->InDataBuffer
;
2996 InBufferContext
.InDataLen
= Packet
->InTransferLength
;
2998 while (!Tcb
->StatusXferd
) {
3000 // Start the timeout timer.
3003 Status
= gBS
->SetTimer (Conn
->TimeoutEvent
, TimerRelative
, Timeout
);
3004 if (EFI_ERROR (Status
)) {
3008 TimeoutEvent
= Conn
->TimeoutEvent
;
3012 // Try to receive PDU from target.
3014 Status
= IScsiReceivePdu (Conn
, &Pdu
, &InBufferContext
, FALSE
, FALSE
, TimeoutEvent
);
3015 if (EFI_ERROR (Status
)) {
3019 PduHdr
= NetbufGetByte (Pdu
, 0, NULL
);
3020 if (PduHdr
== NULL
) {
3021 Status
= EFI_PROTOCOL_ERROR
;
3025 switch (ISCSI_GET_OPCODE (PduHdr
)) {
3026 case ISCSI_OPCODE_SCSI_DATA_IN
:
3027 Status
= IScsiOnDataInRcvd (Pdu
, Tcb
, Packet
);
3030 case ISCSI_OPCODE_R2T
:
3031 Status
= IScsiOnR2TRcvd (Pdu
, Tcb
, Lun
, Packet
);
3034 case ISCSI_OPCODE_SCSI_RSP
:
3035 Status
= IScsiOnScsiRspRcvd (Pdu
, Tcb
, Packet
);
3038 case ISCSI_OPCODE_NOP_IN
:
3039 Status
= IScsiOnNopInRcvd (Pdu
, Tcb
);
3042 case ISCSI_OPCODE_VENDOR_T0
:
3043 case ISCSI_OPCODE_VENDOR_T1
:
3044 case ISCSI_OPCODE_VENDOR_T2
:
3046 // These messages are vendor specific. Skip them.
3051 Status
= EFI_PROTOCOL_ERROR
;
3057 if (EFI_ERROR (Status
)) {
3064 if (TimeoutEvent
!= NULL
) {
3065 gBS
->SetTimer (TimeoutEvent
, TimerCancel
, 0);
3077 Reinstate the session on some error.
3079 @param[in] Session The iSCSI session
3081 @retval EFI_SUCCESS The session is reinstated from some error.
3082 @retval Other Reinstatement failed.
3086 IScsiSessionReinstatement (
3087 IN ISCSI_SESSION
*Session
3092 ASSERT (Session
->State
!= SESSION_STATE_FREE
);
3095 // Abort the session and re-init it.
3097 IScsiSessionAbort (Session
);
3098 IScsiSessionInit (Session
, TRUE
);
3103 Status
= IScsiSessionLogin (Session
);
3110 Initialize some session parameters before login.
3112 @param[in, out] Session The iSCSI session.
3113 @param[in] Recovery Whether the request is from a fresh new start or recovery.
3118 IN OUT ISCSI_SESSION
*Session
,
3123 Session
->Signature
= ISCSI_SESSION_SIGNATURE
;
3124 Session
->State
= SESSION_STATE_FREE
;
3126 InitializeListHead (&Session
->Conns
);
3127 InitializeListHead (&Session
->TcbList
);
3133 Session
->InitiatorTaskTag
= 1;
3134 Session
->NextCid
= 1;
3136 Session
->TargetPortalGroupTag
= 0;
3137 Session
->MaxConnections
= ISCSI_MAX_CONNS_PER_SESSION
;
3138 Session
->InitialR2T
= FALSE
;
3139 Session
->ImmediateData
= TRUE
;
3140 Session
->MaxBurstLength
= 262144;
3141 Session
->FirstBurstLength
= MAX_RECV_DATA_SEG_LEN_IN_FFP
;
3142 Session
->DefaultTime2Wait
= 2;
3143 Session
->DefaultTime2Retain
= 20;
3144 Session
->MaxOutstandingR2T
= DEFAULT_MAX_OUTSTANDING_R2T
;
3145 Session
->DataPDUInOrder
= TRUE
;
3146 Session
->DataSequenceInOrder
= TRUE
;
3147 Session
->ErrorRecoveryLevel
= 0;
3152 Abort the iSCSI session. That is, reset all the connection(s), and free the
3155 @param[in, out] Session The iSCSI session.
3160 IN OUT ISCSI_SESSION
*Session
3163 ISCSI_CONNECTION
*Conn
;
3164 EFI_GUID
*ProtocolGuid
;
3166 if (Session
->State
!= SESSION_STATE_LOGGED_IN
) {
3170 ASSERT (!IsListEmpty (&Session
->Conns
));
3172 while (!IsListEmpty (&Session
->Conns
)) {
3173 Conn
= NET_LIST_USER_STRUCT_S (
3174 Session
->Conns
.ForwardLink
,
3177 ISCSI_CONNECTION_SIGNATURE
3179 if (!Conn
->Ipv6Flag
) {
3180 ProtocolGuid
= &gEfiTcp4ProtocolGuid
;
3182 ProtocolGuid
= &gEfiTcp6ProtocolGuid
;
3185 gBS
->CloseProtocol (
3188 Session
->Private
->Image
,
3189 Session
->Private
->ExtScsiPassThruHandle
3192 IScsiConnReset (Conn
);
3194 IScsiDetatchConnection (Conn
);
3195 IScsiDestroyConnection (Conn
);
3198 Session
->State
= SESSION_STATE_FAILED
;