2 The entry point of IScsi driver.
4 Copyright (c) 2004 - 2016, 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
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.
15 #include "IScsiImpl.h"
17 EFI_DRIVER_BINDING_PROTOCOL gIScsiIp4DriverBinding
= {
18 IScsiIp4DriverBindingSupported
,
19 IScsiIp4DriverBindingStart
,
20 IScsiIp4DriverBindingStop
,
26 EFI_DRIVER_BINDING_PROTOCOL gIScsiIp6DriverBinding
= {
27 IScsiIp6DriverBindingSupported
,
28 IScsiIp6DriverBindingStart
,
29 IScsiIp6DriverBindingStop
,
35 EFI_GUID gIScsiV4PrivateGuid
= ISCSI_V4_PRIVATE_GUID
;
36 EFI_GUID gIScsiV6PrivateGuid
= ISCSI_V6_PRIVATE_GUID
;
37 ISCSI_PRIVATE_DATA
*mPrivate
= NULL
;
40 Tests to see if this driver supports the RemainingDevicePath.
42 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
43 parameter is ignored by device drivers, and is optional for bus
44 drivers. For bus drivers, if this parameter is not NULL, then
45 the bus driver must determine if the bus controller specified
46 by ControllerHandle and the child controller specified
47 by RemainingDevicePath are both supported by this
50 @retval EFI_SUCCESS The RemainingDevicePath is supported or NULL.
51 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
52 RemainingDevicePath is not supported by the driver specified by This.
55 IScsiIsDevicePathSupported (
56 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
59 EFI_DEVICE_PATH_PROTOCOL
*CurrentDevicePath
;
61 CurrentDevicePath
= RemainingDevicePath
;
62 if (CurrentDevicePath
!= NULL
) {
63 while (!IsDevicePathEnd (CurrentDevicePath
)) {
64 if ((CurrentDevicePath
->Type
== MESSAGING_DEVICE_PATH
) && (CurrentDevicePath
->SubType
== MSG_ISCSI_DP
)) {
68 CurrentDevicePath
= NextDevicePathNode (CurrentDevicePath
);
71 return EFI_UNSUPPORTED
;
78 Check whether an iSCSI HBA adapter already installs an AIP instance with
79 network boot policy matching the value specified in PcdIScsiAIPNetworkBootPolicy.
80 If yes, return EFI_SUCCESS.
82 @retval EFI_SUCCESS Found an AIP with matching network boot policy.
83 @retval EFI_NOT_FOUND AIP is unavailable or the network boot policy
91 EFI_HANDLE
*AipHandleBuffer
;
93 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
94 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExtScsiPassThru
;
95 EFI_GUID
*InfoTypesBuffer
;
96 UINTN InfoTypeBufferCount
;
101 EFI_ADAPTER_INFO_NETWORK_BOOT
*NetworkBoot
;
103 UINT8 NetworkBootPolicy
;
106 // Check any AIP instances exist in system.
109 AipHandleBuffer
= NULL
;
110 Status
= gBS
->LocateHandleBuffer (
112 &gEfiAdapterInformationProtocolGuid
,
117 if (EFI_ERROR (Status
) || AipHandleCount
== 0) {
118 return EFI_NOT_FOUND
;
121 ASSERT (AipHandleBuffer
!= NULL
);
125 for (AipIndex
= 0; AipIndex
< AipHandleCount
; AipIndex
++) {
126 Status
= gBS
->HandleProtocol (
127 AipHandleBuffer
[AipIndex
],
128 &gEfiAdapterInformationProtocolGuid
,
131 ASSERT_EFI_ERROR (Status
);
132 ASSERT (Aip
!= NULL
);
134 Status
= gBS
->HandleProtocol (
135 AipHandleBuffer
[AipIndex
],
136 &gEfiExtScsiPassThruProtocolGuid
,
137 (VOID
*) &ExtScsiPassThru
139 if (EFI_ERROR (Status
) || ExtScsiPassThru
== NULL
) {
143 InfoTypesBuffer
= NULL
;
144 InfoTypeBufferCount
= 0;
145 Status
= Aip
->GetSupportedTypes (Aip
, &InfoTypesBuffer
, &InfoTypeBufferCount
);
146 if (EFI_ERROR (Status
) || InfoTypesBuffer
== NULL
) {
150 // Check whether the AIP instance has Network boot information block.
153 for (TypeIndex
= 0; TypeIndex
< InfoTypeBufferCount
; TypeIndex
++) {
154 if (CompareGuid (&InfoTypesBuffer
[TypeIndex
], &gEfiAdapterInfoNetworkBootGuid
)) {
160 FreePool (InfoTypesBuffer
);
166 // We now have network boot information block.
170 Status
= Aip
->GetInformation (Aip
, &gEfiAdapterInfoNetworkBootGuid
, &InfoBlock
, &InfoBlockSize
);
171 if (EFI_ERROR (Status
) || InfoBlock
== NULL
) {
176 // Check whether the network boot policy matches.
178 NetworkBoot
= (EFI_ADAPTER_INFO_NETWORK_BOOT
*) InfoBlock
;
179 NetworkBootPolicy
= PcdGet8 (PcdIScsiAIPNetworkBootPolicy
);
181 if (NetworkBootPolicy
== STOP_UEFI_ISCSI_IF_HBA_INSTALL_AIP
) {
182 Status
= EFI_SUCCESS
;
185 if (((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP4
) != 0 &&
186 !NetworkBoot
->iScsiIpv4BootCapablity
) ||
187 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP6
) != 0 &&
188 !NetworkBoot
->iScsiIpv6BootCapablity
) ||
189 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_SUPPORT_OFFLOAD
) != 0 &&
190 !NetworkBoot
->OffloadCapability
) ||
191 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_SUPPORT_MPIO
) != 0 &&
192 !NetworkBoot
->iScsiMpioCapability
) ||
193 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP4
) != 0 &&
194 !NetworkBoot
->iScsiIpv4Boot
) ||
195 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP6
) != 0 &&
196 !NetworkBoot
->iScsiIpv6Boot
)) {
197 FreePool (InfoBlock
);
201 Status
= EFI_SUCCESS
;
205 Status
= EFI_NOT_FOUND
;
208 if (InfoBlock
!= NULL
) {
209 FreePool (InfoBlock
);
211 if (AipHandleBuffer
!= NULL
) {
212 FreePool (AipHandleBuffer
);
218 Tests to see if this driver supports a given controller. This is the worker function for
219 IScsiIp4(6)DriverBindingSupported.
221 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
222 @param[in] ControllerHandle The handle of the controller to test. This handle
223 must support a protocol interface that supplies
224 an I/O abstraction to the driver.
225 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
226 parameter is ignored by device drivers, and is optional for bus
227 drivers. For bus drivers, if this parameter is not NULL, then
228 the bus driver must determine if the bus controller specified
229 by ControllerHandle and the child controller specified
230 by RemainingDevicePath are both supported by this
232 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
234 @retval EFI_SUCCESS The device specified by ControllerHandle and
235 RemainingDevicePath is supported by the driver specified by This.
236 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
237 RemainingDevicePath is already being managed by the driver
239 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
240 RemainingDevicePath is not supported by the driver specified by This.
245 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
246 IN EFI_HANDLE ControllerHandle
,
247 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
,
252 EFI_GUID
*IScsiServiceBindingGuid
;
253 EFI_GUID
*TcpServiceBindingGuid
;
254 EFI_GUID
*DhcpServiceBindingGuid
;
256 if (IpVersion
== IP_VERSION_4
) {
257 IScsiServiceBindingGuid
= &gIScsiV4PrivateGuid
;
258 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
259 DhcpServiceBindingGuid
= &gEfiDhcp4ServiceBindingProtocolGuid
;
261 IScsiServiceBindingGuid
= &gIScsiV6PrivateGuid
;
262 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
263 DhcpServiceBindingGuid
= &gEfiDhcp6ServiceBindingProtocolGuid
;
266 Status
= gBS
->OpenProtocol (
268 IScsiServiceBindingGuid
,
270 This
->DriverBindingHandle
,
272 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
274 if (!EFI_ERROR (Status
)) {
275 return EFI_ALREADY_STARTED
;
278 Status
= gBS
->OpenProtocol (
280 TcpServiceBindingGuid
,
282 This
->DriverBindingHandle
,
284 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
286 if (EFI_ERROR (Status
)) {
287 return EFI_UNSUPPORTED
;
290 Status
= IScsiIsDevicePathSupported (RemainingDevicePath
);
291 if (EFI_ERROR (Status
)) {
292 return EFI_UNSUPPORTED
;
295 if (IScsiDhcpIsConfigured (ControllerHandle
, IpVersion
)) {
296 Status
= gBS
->OpenProtocol (
298 DhcpServiceBindingGuid
,
300 This
->DriverBindingHandle
,
302 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
304 if (EFI_ERROR (Status
)) {
305 return EFI_UNSUPPORTED
;
314 Start to manage the controller. This is the worker function for
315 IScsiIp4(6)DriverBindingStart.
317 @param[in] Image Handle of the image.
318 @param[in] ControllerHandle Handle of the controller.
319 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
321 @retval EFI_SUCCES This driver was started.
322 @retval EFI_ALREADY_STARTED This driver is already running on this device.
323 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
324 @retval EFI_NOT_FOUND There is no sufficient information to establish
326 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
327 @retval EFI_DEVICE_ERROR Failed to get TCP connection device path.
328 @retval EFI_ACCESS_DENIED The protocol could not be removed from the Handle
329 because its interfaces are being used.
335 IN EFI_HANDLE ControllerHandle
,
340 ISCSI_DRIVER_DATA
*Private
;
342 LIST_ENTRY
*NextEntry
;
343 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
344 ISCSI_SESSION
*Session
;
346 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExistIScsiExtScsiPassThru
;
347 ISCSI_DRIVER_DATA
*ExistPrivate
;
348 UINT8
*AttemptConfigOrder
;
349 UINTN AttemptConfigOrderSize
;
351 EFI_HANDLE
*HandleBuffer
;
352 UINTN NumberOfHandles
;
353 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
354 EFI_GUID
*IScsiPrivateGuid
;
355 EFI_GUID
*TcpServiceBindingGuid
;
356 CHAR16 MacString
[ISCSI_MAX_MAC_STRING_LEN
];
359 EFI_GUID
*ProtocolGuid
;
360 UINT8 NetworkBootPolicy
;
363 // Test to see if iSCSI driver supports the given controller.
366 if (IpVersion
== IP_VERSION_4
) {
367 IScsiPrivateGuid
= &gIScsiV4PrivateGuid
;
368 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
369 ProtocolGuid
= &gEfiTcp4ProtocolGuid
;
370 } else if (IpVersion
== IP_VERSION_6
) {
371 IScsiPrivateGuid
= &gIScsiV6PrivateGuid
;
372 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
373 ProtocolGuid
= &gEfiTcp6ProtocolGuid
;
375 return EFI_INVALID_PARAMETER
;
378 Status
= gBS
->OpenProtocol (
384 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
386 if (!EFI_ERROR (Status
)) {
387 return EFI_ALREADY_STARTED
;
390 Status
= gBS
->OpenProtocol (
392 TcpServiceBindingGuid
,
396 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
398 if (EFI_ERROR (Status
)) {
399 return EFI_UNSUPPORTED
;
402 NetworkBootPolicy
= PcdGet8 (PcdIScsiAIPNetworkBootPolicy
);
403 if (NetworkBootPolicy
!= ALWAYS_USE_UEFI_ISCSI_AND_IGNORE_AIP
) {
405 // Check existing iSCSI AIP.
407 Status
= IScsiCheckAip ();
408 if (!EFI_ERROR (Status
)) {
410 // Find iSCSI AIP with specified network boot policy. return EFI_ABORTED.
417 // Record the incoming NIC info.
419 Status
= IScsiAddNic (ControllerHandle
);
420 if (EFI_ERROR (Status
)) {
425 // Create the instance private data.
427 Private
= IScsiCreateDriverData (Image
, ControllerHandle
);
428 if (Private
== NULL
) {
429 return EFI_OUT_OF_RESOURCES
;
433 // Create a underlayer child instance, but not need to configure it. Just open ChildHandle
434 // via BY_DRIVER. That is, establishing the relationship between ControllerHandle and ChildHandle.
435 // Therefore, when DisconnectController(), especially VLAN virtual controller handle,
436 // IScsiDriverBindingStop() will be called.
438 Status
= NetLibCreateServiceChild (
441 TcpServiceBindingGuid
,
442 &Private
->ChildHandle
445 if (EFI_ERROR (Status
)) {
449 Status
= gBS
->OpenProtocol (
450 Private
->ChildHandle
, /// Default Tcp child
455 EFI_OPEN_PROTOCOL_BY_DRIVER
458 if (EFI_ERROR (Status
)) {
463 // Always install private protocol no matter what happens later. We need to
464 // keep the relationship between ControllerHandle and ChildHandle.
466 Status
= gBS
->InstallProtocolInterface (
469 EFI_NATIVE_INTERFACE
,
470 &Private
->IScsiIdentifier
472 if (EFI_ERROR (Status
)) {
476 if (IpVersion
== IP_VERSION_4
) {
477 mPrivate
->Ipv6Flag
= FALSE
;
479 mPrivate
->Ipv6Flag
= TRUE
;
483 // Get the current iSCSI configuration data.
485 Status
= IScsiGetConfigData (Private
);
486 if (EFI_ERROR (Status
)) {
491 // If there is already a successul attempt, check whether this attempt is the
492 // first "enabled for MPIO" attempt. If not, still try the first attempt.
493 // In single path mode, try all attempts.
496 Status
= EFI_NOT_FOUND
;
498 if (mPrivate
->OneSessionEstablished
&& mPrivate
->EnableMpio
) {
499 AttemptConfigData
= NULL
;
500 NET_LIST_FOR_EACH (Entry
, &mPrivate
->AttemptConfigs
) {
501 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
502 if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
507 if (AttemptConfigData
== NULL
) {
511 if (AttemptConfigData
->AttemptConfigIndex
== mPrivate
->BootSelectedIndex
) {
516 // Uninstall the original ExtScsiPassThru first.
520 // Locate all ExtScsiPassThru protocol instances.
522 Status
= gBS
->LocateHandleBuffer (
524 &gEfiExtScsiPassThruProtocolGuid
,
529 if (EFI_ERROR (Status
)) {
534 // Find ExtScsiPassThru protocol instance produced by this driver.
536 ExistIScsiExtScsiPassThru
= NULL
;
537 for (Index
= 0; Index
< NumberOfHandles
&& ExistIScsiExtScsiPassThru
== NULL
; Index
++) {
538 Status
= gBS
->HandleProtocol (
540 &gEfiDevicePathProtocolGuid
,
541 (VOID
**) &DevicePath
543 if (EFI_ERROR (Status
)) {
547 while (!IsDevicePathEnd (DevicePath
)) {
548 if ((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) && (DevicePath
->SubType
== MSG_MAC_ADDR_DP
)) {
550 // Get the ExtScsiPassThru protocol instance.
552 Status
= gBS
->HandleProtocol (
554 &gEfiExtScsiPassThruProtocolGuid
,
555 (VOID
**) &ExistIScsiExtScsiPassThru
557 ASSERT_EFI_ERROR (Status
);
561 DevicePath
= NextDevicePathNode (DevicePath
);
565 FreePool (HandleBuffer
);
567 if (ExistIScsiExtScsiPassThru
== NULL
) {
568 Status
= EFI_NOT_FOUND
;
572 ExistPrivate
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (ExistIScsiExtScsiPassThru
);
574 Status
= gBS
->UninstallProtocolInterface (
575 ExistPrivate
->ExtScsiPassThruHandle
,
576 &gEfiExtScsiPassThruProtocolGuid
,
577 &ExistPrivate
->IScsiExtScsiPassThru
579 if (EFI_ERROR (Status
)) {
585 // Install the Ext SCSI PASS THRU protocol.
587 Status
= gBS
->InstallProtocolInterface (
588 &Private
->ExtScsiPassThruHandle
,
589 &gEfiExtScsiPassThruProtocolGuid
,
590 EFI_NATIVE_INTERFACE
,
591 &Private
->IScsiExtScsiPassThru
593 if (EFI_ERROR (Status
)) {
599 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &mPrivate
->AttemptConfigs
) {
600 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
602 // Don't process the attempt that does not associate with the current NIC or
603 // this attempt is disabled or established.
605 if (AttemptConfigData
->NicIndex
!= mPrivate
->CurrentNic
||
606 AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_DISABLED
||
607 AttemptConfigData
->ValidPath
) {
612 // In multipath mode, don't process attempts configured for single path.
613 // In default single path mode, don't process attempts configured for multipath.
615 if ((mPrivate
->EnableMpio
&&
616 AttemptConfigData
->SessionConfigData
.Enabled
!= ISCSI_ENABLED_FOR_MPIO
) ||
617 (!mPrivate
->EnableMpio
&&
618 AttemptConfigData
->SessionConfigData
.Enabled
!= ISCSI_ENABLED
)) {
623 // Don't process the attempt that fails to get the init/target information from DHCP.
625 if (AttemptConfigData
->SessionConfigData
.InitiatorInfoFromDhcp
&&
626 !AttemptConfigData
->DhcpSuccess
) {
627 if (!mPrivate
->EnableMpio
&& mPrivate
->ValidSinglePathCount
> 0) {
628 mPrivate
->ValidSinglePathCount
--;
634 // Don't process the autoconfigure path if it is already established.
636 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
637 AttemptConfigData
->AutoConfigureSuccess
) {
642 // Don't process the attempt if its IP mode is not in the current IP version.
644 if (!mPrivate
->Ipv6Flag
) {
645 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP6
) {
648 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
649 AttemptConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP6
) {
653 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP4
) {
656 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
657 AttemptConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP4
) {
663 // Fill in the Session and init it.
665 Session
= (ISCSI_SESSION
*) AllocateZeroPool (sizeof (ISCSI_SESSION
));
666 if (Session
== NULL
) {
667 Status
= EFI_OUT_OF_RESOURCES
;
671 Session
->Private
= Private
;
672 Session
->ConfigData
= AttemptConfigData
;
673 Session
->AuthType
= AttemptConfigData
->AuthenticationType
;
675 AsciiStrToUnicodeStrS (AttemptConfigData
->MacString
, MacString
, sizeof (MacString
) / sizeof (MacString
[0]));
677 mPrivate
->PortString
,
678 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
681 (UINTN
) AttemptConfigData
->AttemptConfigIndex
684 if (Session
->AuthType
== ISCSI_AUTH_TYPE_CHAP
) {
685 Session
->AuthData
.CHAP
.AuthConfig
= &AttemptConfigData
->AuthConfigData
.CHAP
;
688 IScsiSessionInit (Session
, FALSE
);
691 // Try to login and create an iSCSI session according to the configuration.
693 Status
= IScsiSessionLogin (Session
);
694 if (Status
== EFI_MEDIA_CHANGED
) {
696 // The specified target is not available, and the redirection information is
697 // received. Login the session again with the updated target address.
699 Status
= IScsiSessionLogin (Session
);
700 } else if (Status
== EFI_NOT_READY
) {
701 Status
= IScsiSessionReLogin (Session
);
704 if (EFI_ERROR (Status
)) {
706 // In Single path mode, only the successful attempt will be recorded in iBFT;
707 // in multi-path mode, all the attempt entries in MPIO will be recorded in iBFT.
709 if (!mPrivate
->EnableMpio
&& mPrivate
->ValidSinglePathCount
> 0) {
710 mPrivate
->ValidSinglePathCount
--;
716 AttemptConfigData
->ValidPath
= TRUE
;
719 // Do not record the attempt in iBFT if it login with KRB5.
720 // TODO: record KRB5 attempt information in the iSCSI device path.
722 if (Session
->AuthType
== ISCSI_AUTH_TYPE_KRB
) {
723 if (!mPrivate
->EnableMpio
&& mPrivate
->ValidSinglePathCount
> 0) {
724 mPrivate
->ValidSinglePathCount
--;
727 AttemptConfigData
->ValidiBFTPath
= FALSE
;
729 AttemptConfigData
->ValidiBFTPath
= TRUE
;
733 // IScsi session success. Update the attempt state to NVR.
735 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
) {
736 AttemptConfigData
->AutoConfigureSuccess
= TRUE
;
740 mPrivate
->PortString
,
741 &gEfiIScsiInitiatorNameProtocolGuid
,
742 ISCSI_CONFIG_VAR_ATTR
,
743 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
),
748 // Select the first login session. Abort others.
750 if (Private
->Session
== NULL
) {
751 Private
->Session
= Session
;
752 BootSelected
= AttemptConfigData
->AttemptConfigIndex
;
754 // Don't validate other attempt in multipath mode if one is success.
756 if (mPrivate
->EnableMpio
) {
760 IScsiSessionAbort (Session
);
767 // All attempts configured for this driver instance are not valid.
769 if (Private
->Session
== NULL
) {
770 Status
= gBS
->UninstallProtocolInterface (
771 Private
->ExtScsiPassThruHandle
,
772 &gEfiExtScsiPassThruProtocolGuid
,
773 &Private
->IScsiExtScsiPassThru
775 ASSERT_EFI_ERROR (Status
);
776 Private
->ExtScsiPassThruHandle
= NULL
;
779 // Reinstall the original ExtScsiPassThru back.
781 if (mPrivate
->OneSessionEstablished
&& ExistPrivate
!= NULL
) {
782 Status
= gBS
->InstallProtocolInterface (
783 &ExistPrivate
->ExtScsiPassThruHandle
,
784 &gEfiExtScsiPassThruProtocolGuid
,
785 EFI_NATIVE_INTERFACE
,
786 &ExistPrivate
->IScsiExtScsiPassThru
788 if (EFI_ERROR (Status
)) {
795 Status
= EFI_NOT_FOUND
;
802 // More than one attempt successes.
804 if (Private
->Session
!= NULL
&& mPrivate
->OneSessionEstablished
) {
806 AttemptConfigOrder
= IScsiGetVariableAndSize (
809 &AttemptConfigOrderSize
811 if (AttemptConfigOrder
== NULL
) {
814 for (Index
= 0; Index
< AttemptConfigOrderSize
/ sizeof (UINT8
); Index
++) {
815 if (AttemptConfigOrder
[Index
] == mPrivate
->BootSelectedIndex
||
816 AttemptConfigOrder
[Index
] == BootSelected
) {
821 if (mPrivate
->EnableMpio
) {
823 // Use the attempt in earlier order. Abort the later one in MPIO.
825 if (AttemptConfigOrder
[Index
] == mPrivate
->BootSelectedIndex
) {
826 IScsiSessionAbort (Private
->Session
);
827 FreePool (Private
->Session
);
828 Private
->Session
= NULL
;
829 gBS
->UninstallProtocolInterface (
830 Private
->ExtScsiPassThruHandle
,
831 &gEfiExtScsiPassThruProtocolGuid
,
832 &Private
->IScsiExtScsiPassThru
834 Private
->ExtScsiPassThruHandle
= NULL
;
837 // Reinstall the original ExtScsiPassThru back.
839 Status
= gBS
->InstallProtocolInterface (
840 &ExistPrivate
->ExtScsiPassThruHandle
,
841 &gEfiExtScsiPassThruProtocolGuid
,
842 EFI_NATIVE_INTERFACE
,
843 &ExistPrivate
->IScsiExtScsiPassThru
845 if (EFI_ERROR (Status
)) {
851 if (AttemptConfigOrder
[Index
] != BootSelected
) {
854 mPrivate
->BootSelectedIndex
= BootSelected
;
856 // Clear the resource in ExistPrivate.
858 gBS
->UninstallProtocolInterface (
859 ExistPrivate
->Controller
,
861 &ExistPrivate
->IScsiIdentifier
864 IScsiRemoveNic (ExistPrivate
->Controller
);
865 if (ExistPrivate
->Session
!= NULL
) {
866 IScsiSessionAbort (ExistPrivate
->Session
);
869 if (ExistPrivate
->DevicePath
!= NULL
) {
870 Status
= gBS
->UninstallProtocolInterface (
871 ExistPrivate
->ExtScsiPassThruHandle
,
872 &gEfiDevicePathProtocolGuid
,
873 ExistPrivate
->DevicePath
875 if (EFI_ERROR (Status
)) {
879 FreePool (ExistPrivate
->DevicePath
);
882 gBS
->CloseEvent (ExistPrivate
->ExitBootServiceEvent
);
883 FreePool (ExistPrivate
);
888 // Use the attempt in earlier order as boot selected in single path mode.
890 if (AttemptConfigOrder
[Index
] == mPrivate
->BootSelectedIndex
) {
898 mPrivate
->OneSessionEstablished
= TRUE
;
899 mPrivate
->BootSelectedIndex
= BootSelected
;
903 // Duplicate the Session's tcp connection device path. The source port field
904 // will be set to zero as one iSCSI session is comprised of several iSCSI
907 Private
->DevicePath
= IScsiGetTcpConnDevicePath (Private
->Session
);
908 if (Private
->DevicePath
== NULL
) {
909 Status
= EFI_DEVICE_ERROR
;
913 // Install the updated device path onto the ExtScsiPassThruHandle.
915 Status
= gBS
->InstallProtocolInterface (
916 &Private
->ExtScsiPassThruHandle
,
917 &gEfiDevicePathProtocolGuid
,
918 EFI_NATIVE_INTERFACE
,
921 if (EFI_ERROR (Status
)) {
926 // ISCSI children should share the default Tcp child, just open the default Tcp child via BY_CHILD_CONTROLLER.
928 Status
= gBS
->OpenProtocol (
929 Private
->ChildHandle
, /// Default Tcp child
933 Private
->ExtScsiPassThruHandle
,
934 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
936 if (EFI_ERROR (Status
)) {
937 gBS
->UninstallMultipleProtocolInterfaces (
938 Private
->ExtScsiPassThruHandle
,
939 &gEfiExtScsiPassThruProtocolGuid
,
940 &Private
->IScsiExtScsiPassThru
,
941 &gEfiDevicePathProtocolGuid
,
952 // Update/Publish the iSCSI Boot Firmware Table.
954 if (mPrivate
->BootSelectedIndex
!= 0) {
962 if (Private
->Session
!= NULL
) {
963 IScsiSessionAbort (Private
->Session
);
970 Stops a device controller or a bus controller. This is the worker function for
971 IScsiIp4(6)DriverBindingStop.
973 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
974 @param[in] ControllerHandle A handle to the device being stopped. The handle must
975 support a bus specific I/O protocol for the driver
976 to use to stop the device.
977 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
978 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
979 if NumberOfChildren is 0.
980 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
982 @retval EFI_SUCCESS The device was stopped.
983 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
984 @retval EFI_INVALID_PARAMETER Child handle is NULL.
985 @retval EFI_ACCESS_DENIED The protocol could not be removed from the Handle
986 because its interfaces are being used.
992 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
993 IN EFI_HANDLE ControllerHandle
,
994 IN UINTN NumberOfChildren
,
995 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
,
999 EFI_HANDLE IScsiController
;
1001 ISCSI_PRIVATE_PROTOCOL
*IScsiIdentifier
;
1002 ISCSI_DRIVER_DATA
*Private
;
1003 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*PassThru
;
1004 ISCSI_CONNECTION
*Conn
;
1005 EFI_GUID
*ProtocolGuid
;
1006 EFI_GUID
*TcpServiceBindingGuid
;
1007 EFI_GUID
*TcpProtocolGuid
;
1010 if (NumberOfChildren
!= 0) {
1012 // We should have only one child.
1014 Status
= gBS
->OpenProtocol (
1015 ChildHandleBuffer
[0],
1016 &gEfiExtScsiPassThruProtocolGuid
,
1017 (VOID
**) &PassThru
,
1018 This
->DriverBindingHandle
,
1020 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1022 if (EFI_ERROR (Status
)) {
1023 return EFI_DEVICE_ERROR
;
1026 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru
);
1027 Conn
= NET_LIST_HEAD (&Private
->Session
->Conns
, ISCSI_CONNECTION
, Link
);
1030 // Previously the TCP protocol is opened BY_CHILD_CONTROLLER. Just close
1031 // the protocol here, but do not uninstall the device path protocol and
1032 // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle.
1034 if (IpVersion
== IP_VERSION_4
) {
1035 ProtocolGuid
= &gEfiTcp4ProtocolGuid
;
1037 ProtocolGuid
= &gEfiTcp6ProtocolGuid
;
1040 gBS
->CloseProtocol (
1041 Private
->ChildHandle
,
1044 Private
->ExtScsiPassThruHandle
1047 gBS
->CloseProtocol (
1051 Private
->ExtScsiPassThruHandle
1058 // Get the handle of the controller we are controling.
1060 if (IpVersion
== IP_VERSION_4
) {
1061 ProtocolGuid
= &gIScsiV4PrivateGuid
;
1062 TcpProtocolGuid
= &gEfiTcp4ProtocolGuid
;
1063 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
1065 ProtocolGuid
= &gIScsiV6PrivateGuid
;
1066 TcpProtocolGuid
= &gEfiTcp6ProtocolGuid
;
1067 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
1069 IScsiController
= NetLibGetNicHandle (ControllerHandle
, TcpProtocolGuid
);
1070 if (IScsiController
== NULL
) {
1074 Status
= gBS
->OpenProtocol (
1077 (VOID
**) &IScsiIdentifier
,
1078 This
->DriverBindingHandle
,
1080 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1082 if (EFI_ERROR (Status
)) {
1083 return EFI_DEVICE_ERROR
;
1086 Private
= ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier
);
1087 ASSERT (Private
!= NULL
);
1089 if (Private
->ChildHandle
!= NULL
) {
1090 Status
= gBS
->CloseProtocol (
1091 Private
->ChildHandle
,
1093 This
->DriverBindingHandle
,
1097 ASSERT (!EFI_ERROR (Status
));
1099 Status
= NetLibDestroyServiceChild (
1101 This
->DriverBindingHandle
,
1102 TcpServiceBindingGuid
,
1103 Private
->ChildHandle
1106 ASSERT (!EFI_ERROR (Status
));
1109 gBS
->UninstallProtocolInterface (
1112 &Private
->IScsiIdentifier
1118 IScsiRemoveNic (IScsiController
);
1121 // Update the iSCSI Boot Firware Table.
1123 IScsiPublishIbft ();
1125 if (Private
->Session
!= NULL
) {
1126 IScsiSessionAbort (Private
->Session
);
1129 Status
= IScsiCleanDriverData (Private
);
1131 if (EFI_ERROR (Status
)) {
1139 Tests to see if this driver supports a given controller. If a child device is provided,
1140 it tests to see if this driver supports creating a handle for the specified child device.
1142 This function checks to see if the driver specified by This supports the device specified by
1143 ControllerHandle. Drivers typically use the device path attached to
1144 ControllerHandle and/or the services from the bus I/O abstraction attached to
1145 ControllerHandle to determine if the driver supports ControllerHandle. This function
1146 may be called many times during platform initialization. In order to reduce boot times, the tests
1147 performed by this function must be very small and take as little time as possible to execute. This
1148 function must not change the state of any hardware devices, and this function must be aware that the
1149 device specified by ControllerHandle may already be managed by the same driver or a
1150 different driver. This function must match its calls to AllocatePages() with FreePages(),
1151 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
1152 Since ControllerHandle may have been previously started by the same driver, if a protocol is
1153 already in the opened state, then it must not be closed with CloseProtocol(). This is required
1154 to guarantee the state of ControllerHandle is not modified by this function.
1156 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1157 @param[in] ControllerHandle The handle of the controller to test. This handle
1158 must support a protocol interface that supplies
1159 an I/O abstraction to the driver.
1160 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1161 parameter is ignored by device drivers, and is optional for bus
1162 drivers. For bus drivers, if this parameter is not NULL, then
1163 the bus driver must determine if the bus controller specified
1164 by ControllerHandle and the child controller specified
1165 by RemainingDevicePath are both supported by this
1168 @retval EFI_SUCCESS The device specified by ControllerHandle and
1169 RemainingDevicePath is supported by the driver specified by This.
1170 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
1171 RemainingDevicePath is already managed by the driver
1173 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
1174 RemainingDevicePath is already managed by a different
1175 driver or an application that requires exclusive access.
1176 Currently not implemented.
1177 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
1178 RemainingDevicePath is not supported by the driver specified by This.
1182 IScsiIp4DriverBindingSupported (
1183 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1184 IN EFI_HANDLE ControllerHandle
,
1185 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1188 return IScsiSupported (
1191 RemainingDevicePath
,
1197 Starts a device controller or a bus controller.
1199 The Start() function is designed to be invoked from the EFI boot service ConnectController().
1200 As a result, much of the error checking on the parameters to Start() has been moved into this
1201 common boot service. It is legal to call Start() from other locations,
1202 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1203 1. ControllerHandle must be a valid EFI_HANDLE.
1204 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
1205 EFI_DEVICE_PATH_PROTOCOL.
1206 3. Prior to calling Start(), the Supported() function for the driver specified by This must
1207 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
1209 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1210 @param[in] ControllerHandle The handle of the controller to start. This handle
1211 must support a protocol interface that supplies
1212 an I/O abstraction to the driver.
1213 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1214 parameter is ignored by device drivers, and is optional for bus
1215 drivers. For a bus driver, if this parameter is NULL, then handles
1216 for all the children of Controller are created by this driver.
1217 If this parameter is not NULL and the first Device Path Node is
1218 not the End of Device Path Node, then only the handle for the
1219 child device specified by the first Device Path Node of
1220 RemainingDevicePath is created by this driver.
1221 If the first Device Path Node of RemainingDevicePath is
1222 the End of Device Path Node, no child handle is created by this
1225 @retval EFI_SUCCESS The device was started.
1226 @retval EFI_DEVICE_ERROR The device could not be started due to a device error. Currently not implemented.
1227 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1228 @retval Others The driver failed to start the device.
1233 IScsiIp4DriverBindingStart (
1234 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1235 IN EFI_HANDLE ControllerHandle
,
1236 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1241 Status
= IScsiStart (This
->DriverBindingHandle
, ControllerHandle
, IP_VERSION_4
);
1242 if (Status
== EFI_ALREADY_STARTED
) {
1243 Status
= EFI_SUCCESS
;
1250 Stops a device controller or a bus controller.
1252 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1253 As a result, much of the error checking on the parameters to Stop() has been moved
1254 into this common boot service. It is legal to call Stop() from other locations,
1255 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1256 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1257 same driver's Start() function.
1258 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1259 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1260 Start() function, and the Start() function must have called OpenProtocol() on
1261 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1263 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1264 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1265 support a bus specific I/O protocol for the driver
1266 to use to stop the device.
1267 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1268 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1269 if NumberOfChildren is 0.
1271 @retval EFI_SUCCESS The device was stopped.
1272 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1277 IScsiIp4DriverBindingStop (
1278 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1279 IN EFI_HANDLE ControllerHandle
,
1280 IN UINTN NumberOfChildren
,
1281 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
1294 Tests to see if this driver supports a given controller. If a child device is provided,
1295 it tests to see if this driver supports creating a handle for the specified child device.
1297 This function checks to see if the driver specified by This supports the device specified by
1298 ControllerHandle. Drivers typically use the device path attached to
1299 ControllerHandle and/or the services from the bus I/O abstraction attached to
1300 ControllerHandle to determine if the driver supports ControllerHandle. This function
1301 may be called many times during platform initialization. In order to reduce boot times, the tests
1302 performed by this function must be very small and take as little time as possible to execute. This
1303 function must not change the state of any hardware devices, and this function must be aware that the
1304 device specified by ControllerHandle may already be managed by the same driver or a
1305 different driver. This function must match its calls to AllocatePages() with FreePages(),
1306 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
1307 Since ControllerHandle may have been previously started by the same driver, if a protocol is
1308 already in the opened state, then it must not be closed with CloseProtocol(). This is required
1309 to guarantee the state of ControllerHandle is not modified by this function.
1311 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1312 @param[in] ControllerHandle The handle of the controller to test. This handle
1313 must support a protocol interface that supplies
1314 an I/O abstraction to the driver.
1315 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1316 parameter is ignored by device drivers, and is optional for bus
1317 drivers. For bus drivers, if this parameter is not NULL, then
1318 the bus driver must determine if the bus controller specified
1319 by ControllerHandle and the child controller specified
1320 by RemainingDevicePath are both supported by this
1323 @retval EFI_SUCCESS The device specified by ControllerHandle and
1324 RemainingDevicePath is supported by the driver specified by This.
1325 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
1326 RemainingDevicePath is already managed by the driver
1328 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
1329 RemainingDevicePath is already managed by a different
1330 driver or an application that requires exclusive access.
1331 Currently not implemented.
1332 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
1333 RemainingDevicePath is not supported by the driver specified by This.
1337 IScsiIp6DriverBindingSupported (
1338 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1339 IN EFI_HANDLE ControllerHandle
,
1340 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1343 return IScsiSupported (
1346 RemainingDevicePath
,
1352 Starts a device controller or a bus controller.
1354 The Start() function is designed to be invoked from the EFI boot service ConnectController().
1355 As a result, much of the error checking on the parameters to Start() has been moved into this
1356 common boot service. It is legal to call Start() from other locations,
1357 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1358 1. ControllerHandle must be a valid EFI_HANDLE.
1359 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
1360 EFI_DEVICE_PATH_PROTOCOL.
1361 3. Prior to calling Start(), the Supported() function for the driver specified by This must
1362 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
1364 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1365 @param[in] ControllerHandle The handle of the controller to start. This handle
1366 must support a protocol interface that supplies
1367 an I/O abstraction to the driver.
1368 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1369 parameter is ignored by device drivers, and is optional for bus
1370 drivers. For a bus driver, if this parameter is NULL, then handles
1371 for all the children of Controller are created by this driver.
1372 If this parameter is not NULL and the first Device Path Node is
1373 not the End of Device Path Node, then only the handle for the
1374 child device specified by the first Device Path Node of
1375 RemainingDevicePath is created by this driver.
1376 If the first Device Path Node of RemainingDevicePath is
1377 the End of Device Path Node, no child handle is created by this
1380 @retval EFI_SUCCESS The device was started.
1381 @retval EFI_DEVICE_ERROR The device could not be started due to a device error. Currently not implemented.
1382 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1383 @retval Others The driver failed to start the device.
1388 IScsiIp6DriverBindingStart (
1389 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1390 IN EFI_HANDLE ControllerHandle
,
1391 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1396 Status
= IScsiStart (This
->DriverBindingHandle
, ControllerHandle
, IP_VERSION_6
);
1397 if (Status
== EFI_ALREADY_STARTED
) {
1398 Status
= EFI_SUCCESS
;
1405 Stops a device controller or a bus controller.
1407 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1408 As a result, much of the error checking on the parameters to Stop() has been moved
1409 into this common boot service. It is legal to call Stop() from other locations,
1410 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1411 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1412 same driver's Start() function.
1413 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1414 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1415 Start() function, and the Start() function must have called OpenProtocol() on
1416 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1418 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1419 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1420 support a bus specific I/O protocol for the driver
1421 to use to stop the device.
1422 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1423 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1424 if NumberOfChildren is 0.
1426 @retval EFI_SUCCESS The device was stopped.
1427 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1432 IScsiIp6DriverBindingStop (
1433 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1434 IN EFI_HANDLE ControllerHandle
,
1435 IN UINTN NumberOfChildren
,
1436 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
1449 Unload the iSCSI driver.
1451 @param[in] ImageHandle The handle of the driver image.
1453 @retval EFI_SUCCESS The driver is unloaded.
1454 @retval EFI_DEVICE_ERROR An unexpected error occurred.
1460 IN EFI_HANDLE ImageHandle
1464 UINTN DeviceHandleCount
;
1465 EFI_HANDLE
*DeviceHandleBuffer
;
1467 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
1468 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
1471 // Try to disonnect the driver from the devices it's controlling.
1473 Status
= gBS
->LocateHandleBuffer (
1480 if (EFI_ERROR (Status
)) {
1485 // Disconnect the iSCSI4 driver from the controlled device.
1487 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
1488 Status
= IScsiTestManagedDevice (
1489 DeviceHandleBuffer
[Index
],
1490 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1491 &gEfiTcp4ProtocolGuid
)
1493 if (EFI_ERROR (Status
)) {
1496 Status
= gBS
->DisconnectController (
1497 DeviceHandleBuffer
[Index
],
1498 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1501 if (EFI_ERROR (Status
)) {
1507 // Disconnect the iSCSI6 driver from the controlled device.
1509 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
1510 Status
= IScsiTestManagedDevice (
1511 DeviceHandleBuffer
[Index
],
1512 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1513 &gEfiTcp6ProtocolGuid
1515 if (EFI_ERROR (Status
)) {
1518 Status
= gBS
->DisconnectController (
1519 DeviceHandleBuffer
[Index
],
1520 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1523 if (EFI_ERROR (Status
)) {
1529 // Unload the iSCSI configuration form.
1531 Status
= IScsiConfigFormUnload (gIScsiIp4DriverBinding
.DriverBindingHandle
);
1532 if (EFI_ERROR (Status
)) {
1537 // Uninstall the protocols installed by iSCSI driver.
1539 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1541 &gEfiAuthenticationInfoProtocolGuid
,
1542 &gIScsiAuthenticationInfo
,
1545 if (EFI_ERROR (Status
)) {
1549 if (gIScsiControllerNameTable
!= NULL
) {
1550 Status
= FreeUnicodeStringTable (gIScsiControllerNameTable
);
1551 if (EFI_ERROR (Status
)) {
1554 gIScsiControllerNameTable
= NULL
;
1558 // Uninstall the ComponentName and ComponentName2 protocol from iSCSI4 driver binding handle
1559 // if it has been installed.
1561 Status
= gBS
->HandleProtocol (
1562 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1563 &gEfiComponentNameProtocolGuid
,
1564 (VOID
**) &ComponentName
1566 if (!EFI_ERROR (Status
)) {
1567 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1568 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1569 &gEfiComponentNameProtocolGuid
,
1573 if (EFI_ERROR (Status
)) {
1578 Status
= gBS
->HandleProtocol (
1579 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1580 &gEfiComponentName2ProtocolGuid
,
1581 (VOID
**) &ComponentName2
1583 if (!EFI_ERROR (Status
)) {
1584 gBS
->UninstallMultipleProtocolInterfaces (
1585 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1586 &gEfiComponentName2ProtocolGuid
,
1590 if (EFI_ERROR (Status
)) {
1596 // Uninstall the ComponentName and ComponentName2 protocol from iSCSI6 driver binding handle
1597 // if it has been installed.
1599 Status
= gBS
->HandleProtocol (
1600 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1601 &gEfiComponentNameProtocolGuid
,
1602 (VOID
**) &ComponentName
1604 if (!EFI_ERROR (Status
)) {
1605 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1606 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1607 &gEfiComponentNameProtocolGuid
,
1611 if (EFI_ERROR (Status
)) {
1616 Status
= gBS
->HandleProtocol (
1617 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1618 &gEfiComponentName2ProtocolGuid
,
1619 (VOID
**) &ComponentName2
1621 if (!EFI_ERROR (Status
)) {
1622 gBS
->UninstallMultipleProtocolInterfaces (
1623 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1624 &gEfiComponentName2ProtocolGuid
,
1628 if (EFI_ERROR (Status
)) {
1634 // Uninstall the IScsiInitiatorNameProtocol and all the driver binding protocols.
1636 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1637 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1638 &gEfiDriverBindingProtocolGuid
,
1639 &gIScsiIp4DriverBinding
,
1640 &gEfiIScsiInitiatorNameProtocolGuid
,
1641 &gIScsiInitiatorName
,
1644 if (EFI_ERROR (Status
)) {
1648 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1649 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1650 &gEfiDriverBindingProtocolGuid
,
1651 &gIScsiIp6DriverBinding
,
1657 if (DeviceHandleBuffer
!= NULL
) {
1658 FreePool (DeviceHandleBuffer
);
1665 This is the declaration of an EFI image entry point. This entry point is
1666 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1667 both device drivers and bus drivers.
1669 The entry point for iSCSI driver which initializes the global variables and
1670 installs the driver binding, component name protocol, iSCSI initiator name
1671 protocol and Authentication Info protocol on its image.
1673 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
1674 @param[in] SystemTable A pointer to the EFI System Table.
1676 @retval EFI_SUCCESS The operation completed successfully.
1677 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1682 IScsiDriverEntryPoint (
1683 IN EFI_HANDLE ImageHandle
,
1684 IN EFI_SYSTEM_TABLE
*SystemTable
1688 EFI_ISCSI_INITIATOR_NAME_PROTOCOL
*IScsiInitiatorName
;
1689 EFI_AUTHENTICATION_INFO_PROTOCOL
*AuthenticationInfo
;
1692 // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.
1694 Status
= gBS
->LocateProtocol (
1695 &gEfiIScsiInitiatorNameProtocolGuid
,
1697 (VOID
**) &IScsiInitiatorName
1699 if (!EFI_ERROR (Status
)) {
1700 return EFI_ACCESS_DENIED
;
1704 // Initialize the EFI Driver Library.
1706 Status
= EfiLibInstallDriverBindingComponentName2 (
1709 &gIScsiIp4DriverBinding
,
1711 &gIScsiComponentName
,
1712 &gIScsiComponentName2
1714 if (EFI_ERROR (Status
)) {
1718 Status
= EfiLibInstallDriverBindingComponentName2 (
1721 &gIScsiIp6DriverBinding
,
1723 &gIScsiComponentName
,
1724 &gIScsiComponentName2
1726 if (EFI_ERROR (Status
)) {
1731 // Install the iSCSI Initiator Name Protocol.
1733 Status
= gBS
->InstallProtocolInterface (
1735 &gEfiIScsiInitiatorNameProtocolGuid
,
1736 EFI_NATIVE_INTERFACE
,
1737 &gIScsiInitiatorName
1739 if (EFI_ERROR (Status
)) {
1744 // Create the private data structures.
1746 mPrivate
= AllocateZeroPool (sizeof (ISCSI_PRIVATE_DATA
));
1747 if (mPrivate
== NULL
) {
1748 Status
= EFI_OUT_OF_RESOURCES
;
1752 InitializeListHead (&mPrivate
->NicInfoList
);
1753 InitializeListHead (&mPrivate
->AttemptConfigs
);
1756 // Initialize the configuration form of iSCSI.
1758 Status
= IScsiConfigFormInit (gIScsiIp4DriverBinding
.DriverBindingHandle
);
1759 if (EFI_ERROR (Status
)) {
1764 // There should be only one EFI_AUTHENTICATION_INFO_PROTOCOL. If already exists,
1765 // do not produce the protocol instance.
1767 Status
= gBS
->LocateProtocol (
1768 &gEfiAuthenticationInfoProtocolGuid
,
1770 (VOID
**) &AuthenticationInfo
1772 if (Status
== EFI_NOT_FOUND
) {
1773 Status
= gBS
->InstallProtocolInterface (
1775 &gEfiAuthenticationInfoProtocolGuid
,
1776 EFI_NATIVE_INTERFACE
,
1777 &gIScsiAuthenticationInfo
1779 if (EFI_ERROR (Status
)) {
1787 IScsiConfigFormUnload (gIScsiIp4DriverBinding
.DriverBindingHandle
);
1790 FreePool (mPrivate
);
1793 gBS
->UninstallMultipleProtocolInterfaces (
1795 &gEfiIScsiInitiatorNameProtocolGuid
,
1796 &gIScsiInitiatorName
,
1801 gBS
->UninstallMultipleProtocolInterfaces (
1802 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1803 &gEfiDriverBindingProtocolGuid
,
1804 &gIScsiIp6DriverBinding
,
1805 &gEfiComponentName2ProtocolGuid
,
1806 &gIScsiComponentName2
,
1807 &gEfiComponentNameProtocolGuid
,
1808 &gIScsiComponentName
,
1813 gBS
->UninstallMultipleProtocolInterfaces (
1815 &gEfiDriverBindingProtocolGuid
,
1816 &gIScsiIp4DriverBinding
,
1817 &gEfiComponentName2ProtocolGuid
,
1818 &gIScsiComponentName2
,
1819 &gEfiComponentNameProtocolGuid
,
1820 &gIScsiComponentName
,