2 The entry point of IScsi driver.
4 Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "IScsiImpl.h"
19 EFI_DRIVER_BINDING_PROTOCOL gIScsiIp4DriverBinding
= {
20 IScsiIp4DriverBindingSupported
,
21 IScsiIp4DriverBindingStart
,
22 IScsiIp4DriverBindingStop
,
28 EFI_DRIVER_BINDING_PROTOCOL gIScsiIp6DriverBinding
= {
29 IScsiIp6DriverBindingSupported
,
30 IScsiIp6DriverBindingStart
,
31 IScsiIp6DriverBindingStop
,
37 EFI_GUID gIScsiV4PrivateGuid
= ISCSI_V4_PRIVATE_GUID
;
38 EFI_GUID gIScsiV6PrivateGuid
= ISCSI_V6_PRIVATE_GUID
;
39 ISCSI_PRIVATE_DATA
*mPrivate
= NULL
;
42 Tests to see if this driver supports the RemainingDevicePath.
44 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
45 parameter is ignored by device drivers, and is optional for bus
46 drivers. For bus drivers, if this parameter is not NULL, then
47 the bus driver must determine if the bus controller specified
48 by ControllerHandle and the child controller specified
49 by RemainingDevicePath are both supported by this
52 @retval EFI_SUCCESS The RemainingDevicePath is supported or NULL.
53 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
54 RemainingDevicePath is not supported by the driver specified by This.
57 IScsiIsDevicePathSupported (
58 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
61 EFI_DEVICE_PATH_PROTOCOL
*CurrentDevicePath
;
63 CurrentDevicePath
= RemainingDevicePath
;
64 if (CurrentDevicePath
!= NULL
) {
65 while (!IsDevicePathEnd (CurrentDevicePath
)) {
66 if ((CurrentDevicePath
->Type
== MESSAGING_DEVICE_PATH
) && (CurrentDevicePath
->SubType
== MSG_ISCSI_DP
)) {
70 CurrentDevicePath
= NextDevicePathNode (CurrentDevicePath
);
73 return EFI_UNSUPPORTED
;
80 Check whether an iSCSI HBA adapter already installs an AIP instance with
81 network boot policy matching the value specified in PcdIScsiAIPNetworkBootPolicy.
82 If yes, return EFI_SUCCESS.
84 @retval EFI_SUCCESS Found an AIP with matching network boot policy.
85 @retval EFI_NOT_FOUND AIP is unavailable or the network boot policy
93 EFI_HANDLE
*AipHandleBuffer
;
95 EFI_ADAPTER_INFORMATION_PROTOCOL
*Aip
;
96 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExtScsiPassThru
;
97 EFI_GUID
*InfoTypesBuffer
;
98 UINTN InfoTypeBufferCount
;
103 EFI_ADAPTER_INFO_NETWORK_BOOT
*NetworkBoot
;
105 UINT8 NetworkBootPolicy
;
108 // Check any AIP instances exist in system.
111 AipHandleBuffer
= NULL
;
112 Status
= gBS
->LocateHandleBuffer (
114 &gEfiAdapterInformationProtocolGuid
,
119 if (EFI_ERROR (Status
) || AipHandleCount
== 0) {
120 return EFI_NOT_FOUND
;
123 ASSERT (AipHandleBuffer
!= NULL
);
127 for (AipIndex
= 0; AipIndex
< AipHandleCount
; AipIndex
++) {
128 Status
= gBS
->HandleProtocol (
129 AipHandleBuffer
[AipIndex
],
130 &gEfiAdapterInformationProtocolGuid
,
133 ASSERT_EFI_ERROR (Status
);
134 ASSERT (Aip
!= NULL
);
136 Status
= gBS
->HandleProtocol (
137 AipHandleBuffer
[AipIndex
],
138 &gEfiExtScsiPassThruProtocolGuid
,
139 (VOID
*) &ExtScsiPassThru
141 if (EFI_ERROR (Status
) || ExtScsiPassThru
== NULL
) {
145 InfoTypesBuffer
= NULL
;
146 InfoTypeBufferCount
= 0;
147 Status
= Aip
->GetSupportedTypes (Aip
, &InfoTypesBuffer
, &InfoTypeBufferCount
);
148 if (EFI_ERROR (Status
) || InfoTypesBuffer
== NULL
) {
152 // Check whether the AIP instance has Network boot information block.
155 for (TypeIndex
= 0; TypeIndex
< InfoTypeBufferCount
; TypeIndex
++) {
156 if (CompareGuid (&InfoTypesBuffer
[TypeIndex
], &gEfiAdapterInfoNetworkBootGuid
)) {
162 FreePool (InfoTypesBuffer
);
168 // We now have network boot information block.
172 Status
= Aip
->GetInformation (Aip
, &gEfiAdapterInfoNetworkBootGuid
, &InfoBlock
, &InfoBlockSize
);
173 if (EFI_ERROR (Status
) || InfoBlock
== NULL
) {
178 // Check whether the network boot policy matches.
180 NetworkBoot
= (EFI_ADAPTER_INFO_NETWORK_BOOT
*) InfoBlock
;
181 NetworkBootPolicy
= PcdGet8 (PcdIScsiAIPNetworkBootPolicy
);
183 if (NetworkBootPolicy
== STOP_UEFI_ISCSI_IF_HBA_INSTALL_AIP
) {
184 Status
= EFI_SUCCESS
;
187 if (((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP4
) != 0 &&
188 !NetworkBoot
->iScsiIpv4BootCapablity
) ||
189 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP6
) != 0 &&
190 !NetworkBoot
->iScsiIpv6BootCapablity
) ||
191 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_SUPPORT_OFFLOAD
) != 0 &&
192 !NetworkBoot
->OffloadCapability
) ||
193 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_SUPPORT_MPIO
) != 0 &&
194 !NetworkBoot
->iScsiMpioCapability
) ||
195 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP4
) != 0 &&
196 !NetworkBoot
->iScsiIpv4Boot
) ||
197 ((NetworkBootPolicy
& STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP6
) != 0 &&
198 !NetworkBoot
->iScsiIpv6Boot
)) {
199 FreePool (InfoBlock
);
203 Status
= EFI_SUCCESS
;
207 Status
= EFI_NOT_FOUND
;
210 if (InfoBlock
!= NULL
) {
211 FreePool (InfoBlock
);
213 if (AipHandleBuffer
!= NULL
) {
214 FreePool (AipHandleBuffer
);
220 Tests to see if this driver supports a given controller. This is the worker function for
221 IScsiIp4(6)DriverBindingSupported.
223 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
224 @param[in] ControllerHandle The handle of the controller to test. This handle
225 must support a protocol interface that supplies
226 an I/O abstraction to the driver.
227 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
228 parameter is ignored by device drivers, and is optional for bus
229 drivers. For bus drivers, if this parameter is not NULL, then
230 the bus driver must determine if the bus controller specified
231 by ControllerHandle and the child controller specified
232 by RemainingDevicePath are both supported by this
234 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
236 @retval EFI_SUCCESS The device specified by ControllerHandle and
237 RemainingDevicePath is supported by the driver specified by This.
238 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
239 RemainingDevicePath is already being managed by the driver
241 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
242 RemainingDevicePath is not supported by the driver specified by This.
247 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
248 IN EFI_HANDLE ControllerHandle
,
249 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
,
254 EFI_GUID
*IScsiServiceBindingGuid
;
255 EFI_GUID
*TcpServiceBindingGuid
;
256 EFI_GUID
*DhcpServiceBindingGuid
;
257 EFI_GUID
*DnsServiceBindingGuid
;
259 if (IpVersion
== IP_VERSION_4
) {
260 IScsiServiceBindingGuid
= &gIScsiV4PrivateGuid
;
261 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
262 DhcpServiceBindingGuid
= &gEfiDhcp4ServiceBindingProtocolGuid
;
263 DnsServiceBindingGuid
= &gEfiDns4ServiceBindingProtocolGuid
;
266 IScsiServiceBindingGuid
= &gIScsiV6PrivateGuid
;
267 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
268 DhcpServiceBindingGuid
= &gEfiDhcp6ServiceBindingProtocolGuid
;
269 DnsServiceBindingGuid
= &gEfiDns6ServiceBindingProtocolGuid
;
272 Status
= gBS
->OpenProtocol (
274 IScsiServiceBindingGuid
,
276 This
->DriverBindingHandle
,
278 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
280 if (!EFI_ERROR (Status
)) {
281 return EFI_ALREADY_STARTED
;
284 Status
= gBS
->OpenProtocol (
286 TcpServiceBindingGuid
,
288 This
->DriverBindingHandle
,
290 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
292 if (EFI_ERROR (Status
)) {
293 return EFI_UNSUPPORTED
;
296 Status
= IScsiIsDevicePathSupported (RemainingDevicePath
);
297 if (EFI_ERROR (Status
)) {
298 return EFI_UNSUPPORTED
;
301 if (IScsiDhcpIsConfigured (ControllerHandle
, IpVersion
)) {
302 Status
= gBS
->OpenProtocol (
304 DhcpServiceBindingGuid
,
306 This
->DriverBindingHandle
,
308 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
310 if (EFI_ERROR (Status
)) {
311 return EFI_UNSUPPORTED
;
315 if (IScsiDnsIsConfigured (ControllerHandle
)) {
316 Status
= gBS
->OpenProtocol (
318 DnsServiceBindingGuid
,
320 This
->DriverBindingHandle
,
322 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
324 if (EFI_ERROR (Status
)) {
325 return EFI_UNSUPPORTED
;
334 Start to manage the controller. This is the worker function for
335 IScsiIp4(6)DriverBindingStart.
337 @param[in] Image Handle of the image.
338 @param[in] ControllerHandle Handle of the controller.
339 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
341 @retval EFI_SUCCES This driver was started.
342 @retval EFI_ALREADY_STARTED This driver is already running on this device.
343 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
344 @retval EFI_NOT_FOUND There is no sufficient information to establish
346 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
347 @retval EFI_DEVICE_ERROR Failed to get TCP connection device path.
348 @retval EFI_ACCESS_DENIED The protocol could not be removed from the Handle
349 because its interfaces are being used.
355 IN EFI_HANDLE ControllerHandle
,
360 ISCSI_DRIVER_DATA
*Private
;
362 LIST_ENTRY
*NextEntry
;
363 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
364 ISCSI_SESSION
*Session
;
366 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExistIScsiExtScsiPassThru
;
367 ISCSI_DRIVER_DATA
*ExistPrivate
;
368 UINT8
*AttemptConfigOrder
;
369 UINTN AttemptConfigOrderSize
;
371 EFI_HANDLE
*HandleBuffer
;
372 UINTN NumberOfHandles
;
373 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
374 EFI_GUID
*IScsiPrivateGuid
;
375 EFI_GUID
*TcpServiceBindingGuid
;
378 EFI_GUID
*ProtocolGuid
;
379 UINT8 NetworkBootPolicy
;
380 ISCSI_SESSION_CONFIG_NVDATA
*NvData
;
383 // Test to see if iSCSI driver supports the given controller.
386 if (IpVersion
== IP_VERSION_4
) {
387 IScsiPrivateGuid
= &gIScsiV4PrivateGuid
;
388 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
389 ProtocolGuid
= &gEfiTcp4ProtocolGuid
;
390 } else if (IpVersion
== IP_VERSION_6
) {
391 IScsiPrivateGuid
= &gIScsiV6PrivateGuid
;
392 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
393 ProtocolGuid
= &gEfiTcp6ProtocolGuid
;
395 return EFI_INVALID_PARAMETER
;
398 Status
= gBS
->OpenProtocol (
404 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
406 if (!EFI_ERROR (Status
)) {
407 return EFI_ALREADY_STARTED
;
410 Status
= gBS
->OpenProtocol (
412 TcpServiceBindingGuid
,
416 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
418 if (EFI_ERROR (Status
)) {
419 return EFI_UNSUPPORTED
;
422 NetworkBootPolicy
= PcdGet8 (PcdIScsiAIPNetworkBootPolicy
);
423 if (NetworkBootPolicy
== ALWAYS_USE_ISCSI_HBA_AND_IGNORE_UEFI_ISCSI
) {
427 if (NetworkBootPolicy
!= ALWAYS_USE_UEFI_ISCSI_AND_IGNORE_ISCSI_HBA
) {
429 // Check existing iSCSI AIP.
431 Status
= IScsiCheckAip ();
432 if (!EFI_ERROR (Status
)) {
434 // Find iSCSI AIP with specified network boot policy. return EFI_ABORTED.
441 // Record the incoming NIC info.
443 Status
= IScsiAddNic (ControllerHandle
, Image
);
444 if (EFI_ERROR (Status
)) {
449 // Create the instance private data.
451 Private
= IScsiCreateDriverData (Image
, ControllerHandle
);
452 if (Private
== NULL
) {
453 return EFI_OUT_OF_RESOURCES
;
457 // Create a underlayer child instance, but not need to configure it. Just open ChildHandle
458 // via BY_DRIVER. That is, establishing the relationship between ControllerHandle and ChildHandle.
459 // Therefore, when DisconnectController(), especially VLAN virtual controller handle,
460 // IScsiDriverBindingStop() will be called.
462 Status
= NetLibCreateServiceChild (
465 TcpServiceBindingGuid
,
466 &Private
->ChildHandle
469 if (EFI_ERROR (Status
)) {
473 Status
= gBS
->OpenProtocol (
474 Private
->ChildHandle
, /// Default Tcp child
479 EFI_OPEN_PROTOCOL_BY_DRIVER
482 if (EFI_ERROR (Status
)) {
487 // Always install private protocol no matter what happens later. We need to
488 // keep the relationship between ControllerHandle and ChildHandle.
490 Status
= gBS
->InstallProtocolInterface (
493 EFI_NATIVE_INTERFACE
,
494 &Private
->IScsiIdentifier
496 if (EFI_ERROR (Status
)) {
500 if (IpVersion
== IP_VERSION_4
) {
501 mPrivate
->Ipv6Flag
= FALSE
;
503 mPrivate
->Ipv6Flag
= TRUE
;
507 // Get the current iSCSI configuration data.
509 Status
= IScsiGetConfigData (Private
);
510 if (EFI_ERROR (Status
)) {
515 // If there is already a successul attempt, check whether this attempt is the
516 // first "enabled for MPIO" attempt. If not, still try the first attempt.
517 // In single path mode, try all attempts.
520 Status
= EFI_NOT_FOUND
;
522 if (mPrivate
->OneSessionEstablished
&& mPrivate
->EnableMpio
) {
523 AttemptConfigData
= NULL
;
524 NET_LIST_FOR_EACH (Entry
, &mPrivate
->AttemptConfigs
) {
525 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
526 if (AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_ENABLED_FOR_MPIO
) {
531 if (AttemptConfigData
== NULL
) {
535 if (AttemptConfigData
->AttemptConfigIndex
== mPrivate
->BootSelectedIndex
) {
540 // Uninstall the original ExtScsiPassThru first.
544 // Locate all ExtScsiPassThru protocol instances.
546 Status
= gBS
->LocateHandleBuffer (
548 &gEfiExtScsiPassThruProtocolGuid
,
553 if (EFI_ERROR (Status
)) {
558 // Find ExtScsiPassThru protocol instance produced by this driver.
560 ExistIScsiExtScsiPassThru
= NULL
;
561 for (Index
= 0; Index
< NumberOfHandles
&& ExistIScsiExtScsiPassThru
== NULL
; Index
++) {
562 Status
= gBS
->HandleProtocol (
564 &gEfiDevicePathProtocolGuid
,
565 (VOID
**) &DevicePath
567 if (EFI_ERROR (Status
)) {
571 while (!IsDevicePathEnd (DevicePath
)) {
572 if ((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) && (DevicePath
->SubType
== MSG_MAC_ADDR_DP
)) {
574 // Get the ExtScsiPassThru protocol instance.
576 Status
= gBS
->HandleProtocol (
578 &gEfiExtScsiPassThruProtocolGuid
,
579 (VOID
**) &ExistIScsiExtScsiPassThru
581 ASSERT_EFI_ERROR (Status
);
585 DevicePath
= NextDevicePathNode (DevicePath
);
589 FreePool (HandleBuffer
);
591 if (ExistIScsiExtScsiPassThru
== NULL
) {
592 Status
= EFI_NOT_FOUND
;
596 ExistPrivate
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (ExistIScsiExtScsiPassThru
);
598 Status
= gBS
->UninstallProtocolInterface (
599 ExistPrivate
->ExtScsiPassThruHandle
,
600 &gEfiExtScsiPassThruProtocolGuid
,
601 &ExistPrivate
->IScsiExtScsiPassThru
603 if (EFI_ERROR (Status
)) {
609 // Install the Ext SCSI PASS THRU protocol.
611 Status
= gBS
->InstallProtocolInterface (
612 &Private
->ExtScsiPassThruHandle
,
613 &gEfiExtScsiPassThruProtocolGuid
,
614 EFI_NATIVE_INTERFACE
,
615 &Private
->IScsiExtScsiPassThru
617 if (EFI_ERROR (Status
)) {
623 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &mPrivate
->AttemptConfigs
) {
624 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
626 // Don't process the attempt that does not associate with the current NIC or
627 // this attempt is disabled or established.
629 if (AttemptConfigData
->NicIndex
!= mPrivate
->CurrentNic
||
630 AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_DISABLED
||
631 AttemptConfigData
->ValidPath
) {
636 // In multipath mode, don't process attempts configured for single path.
637 // In default single path mode, don't process attempts configured for multipath.
639 if ((mPrivate
->EnableMpio
&&
640 AttemptConfigData
->SessionConfigData
.Enabled
!= ISCSI_ENABLED_FOR_MPIO
) ||
641 (!mPrivate
->EnableMpio
&&
642 AttemptConfigData
->SessionConfigData
.Enabled
!= ISCSI_ENABLED
)) {
647 // Don't process the attempt that fails to get the init/target information from DHCP.
649 if (AttemptConfigData
->SessionConfigData
.InitiatorInfoFromDhcp
&&
650 !AttemptConfigData
->DhcpSuccess
) {
651 if (!mPrivate
->EnableMpio
&& mPrivate
->ValidSinglePathCount
> 0) {
652 mPrivate
->ValidSinglePathCount
--;
658 // Don't process the autoconfigure path if it is already established.
660 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
661 AttemptConfigData
->AutoConfigureSuccess
) {
666 // Don't process the attempt if its IP mode is not in the current IP version.
668 if (!mPrivate
->Ipv6Flag
) {
669 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP6
) {
672 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
673 AttemptConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP6
) {
677 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP4
) {
680 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
681 AttemptConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP4
) {
687 // Fill in the Session and init it.
689 Session
= (ISCSI_SESSION
*) AllocateZeroPool (sizeof (ISCSI_SESSION
));
690 if (Session
== NULL
) {
691 Status
= EFI_OUT_OF_RESOURCES
;
695 Session
->Private
= Private
;
696 Session
->ConfigData
= AttemptConfigData
;
697 Session
->AuthType
= AttemptConfigData
->AuthenticationType
;
700 mPrivate
->PortString
,
701 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
703 (UINTN
) AttemptConfigData
->AttemptConfigIndex
706 if (Session
->AuthType
== ISCSI_AUTH_TYPE_CHAP
) {
707 Session
->AuthData
.CHAP
.AuthConfig
= &AttemptConfigData
->AuthConfigData
.CHAP
;
710 IScsiSessionInit (Session
, FALSE
);
713 // Try to login and create an iSCSI session according to the configuration.
715 Status
= IScsiSessionLogin (Session
);
716 if (Status
== EFI_MEDIA_CHANGED
) {
718 // The specified target is not available, and the redirection information is
719 // received. Login the session again with the updated target address.
721 Status
= IScsiSessionLogin (Session
);
722 } else if (Status
== EFI_NOT_READY
) {
723 Status
= IScsiSessionReLogin (Session
);
727 // Restore the origial user setting which specifies the proxy/virtual iSCSI target to NV region.
729 NvData
= &AttemptConfigData
->SessionConfigData
;
730 if (NvData
->RedirectFlag
) {
731 NvData
->TargetPort
= NvData
->OriginalTargetPort
;
732 CopyMem (&NvData
->TargetIp
, &NvData
->OriginalTargetIp
, sizeof (EFI_IP_ADDRESS
));
733 NvData
->RedirectFlag
= FALSE
;
736 mPrivate
->PortString
,
737 &gEfiIScsiInitiatorNameProtocolGuid
,
738 ISCSI_CONFIG_VAR_ATTR
,
739 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
),
744 if (EFI_ERROR (Status
)) {
746 // In Single path mode, only the successful attempt will be recorded in iBFT;
747 // in multi-path mode, all the attempt entries in MPIO will be recorded in iBFT.
749 if (!mPrivate
->EnableMpio
&& mPrivate
->ValidSinglePathCount
> 0) {
750 mPrivate
->ValidSinglePathCount
--;
756 AttemptConfigData
->ValidPath
= TRUE
;
759 // Do not record the attempt in iBFT if it login with KRB5.
760 // TODO: record KRB5 attempt information in the iSCSI device path.
762 if (Session
->AuthType
== ISCSI_AUTH_TYPE_KRB
) {
763 if (!mPrivate
->EnableMpio
&& mPrivate
->ValidSinglePathCount
> 0) {
764 mPrivate
->ValidSinglePathCount
--;
767 AttemptConfigData
->ValidiBFTPath
= FALSE
;
769 AttemptConfigData
->ValidiBFTPath
= TRUE
;
773 // IScsi session success. Update the attempt state to NVR.
775 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
) {
776 AttemptConfigData
->AutoConfigureSuccess
= TRUE
;
780 mPrivate
->PortString
,
781 &gEfiIScsiInitiatorNameProtocolGuid
,
782 ISCSI_CONFIG_VAR_ATTR
,
783 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
),
788 // Select the first login session. Abort others.
790 if (Private
->Session
== NULL
) {
791 Private
->Session
= Session
;
792 BootSelected
= AttemptConfigData
->AttemptConfigIndex
;
794 // Don't validate other attempt in multipath mode if one is success.
796 if (mPrivate
->EnableMpio
) {
800 IScsiSessionAbort (Session
);
807 // All attempts configured for this driver instance are not valid.
809 if (Private
->Session
== NULL
) {
810 Status
= gBS
->UninstallProtocolInterface (
811 Private
->ExtScsiPassThruHandle
,
812 &gEfiExtScsiPassThruProtocolGuid
,
813 &Private
->IScsiExtScsiPassThru
815 ASSERT_EFI_ERROR (Status
);
816 Private
->ExtScsiPassThruHandle
= NULL
;
819 // Reinstall the original ExtScsiPassThru back.
821 if (mPrivate
->OneSessionEstablished
&& ExistPrivate
!= NULL
) {
822 Status
= gBS
->InstallProtocolInterface (
823 &ExistPrivate
->ExtScsiPassThruHandle
,
824 &gEfiExtScsiPassThruProtocolGuid
,
825 EFI_NATIVE_INTERFACE
,
826 &ExistPrivate
->IScsiExtScsiPassThru
828 if (EFI_ERROR (Status
)) {
835 Status
= EFI_NOT_FOUND
;
842 // More than one attempt successes.
844 if (Private
->Session
!= NULL
&& mPrivate
->OneSessionEstablished
) {
846 AttemptConfigOrder
= IScsiGetVariableAndSize (
849 &AttemptConfigOrderSize
851 if (AttemptConfigOrder
== NULL
) {
854 for (Index
= 0; Index
< AttemptConfigOrderSize
/ sizeof (UINT8
); Index
++) {
855 if (AttemptConfigOrder
[Index
] == mPrivate
->BootSelectedIndex
||
856 AttemptConfigOrder
[Index
] == BootSelected
) {
861 if (mPrivate
->EnableMpio
) {
863 // Use the attempt in earlier order. Abort the later one in MPIO.
865 if (AttemptConfigOrder
[Index
] == mPrivate
->BootSelectedIndex
) {
866 IScsiSessionAbort (Private
->Session
);
867 FreePool (Private
->Session
);
868 Private
->Session
= NULL
;
869 gBS
->UninstallProtocolInterface (
870 Private
->ExtScsiPassThruHandle
,
871 &gEfiExtScsiPassThruProtocolGuid
,
872 &Private
->IScsiExtScsiPassThru
874 Private
->ExtScsiPassThruHandle
= NULL
;
877 // Reinstall the original ExtScsiPassThru back.
879 Status
= gBS
->InstallProtocolInterface (
880 &ExistPrivate
->ExtScsiPassThruHandle
,
881 &gEfiExtScsiPassThruProtocolGuid
,
882 EFI_NATIVE_INTERFACE
,
883 &ExistPrivate
->IScsiExtScsiPassThru
885 if (EFI_ERROR (Status
)) {
891 if (AttemptConfigOrder
[Index
] != BootSelected
) {
894 mPrivate
->BootSelectedIndex
= BootSelected
;
896 // Clear the resource in ExistPrivate.
898 gBS
->UninstallProtocolInterface (
899 ExistPrivate
->Controller
,
901 &ExistPrivate
->IScsiIdentifier
904 IScsiRemoveNic (ExistPrivate
->Controller
);
905 if (ExistPrivate
->Session
!= NULL
) {
906 IScsiSessionAbort (ExistPrivate
->Session
);
909 if (ExistPrivate
->DevicePath
!= NULL
) {
910 Status
= gBS
->UninstallProtocolInterface (
911 ExistPrivate
->ExtScsiPassThruHandle
,
912 &gEfiDevicePathProtocolGuid
,
913 ExistPrivate
->DevicePath
915 if (EFI_ERROR (Status
)) {
919 FreePool (ExistPrivate
->DevicePath
);
922 gBS
->CloseEvent (ExistPrivate
->ExitBootServiceEvent
);
923 FreePool (ExistPrivate
);
928 // Use the attempt in earlier order as boot selected in single path mode.
930 if (AttemptConfigOrder
[Index
] == mPrivate
->BootSelectedIndex
) {
938 mPrivate
->OneSessionEstablished
= TRUE
;
939 mPrivate
->BootSelectedIndex
= BootSelected
;
943 // Duplicate the Session's tcp connection device path. The source port field
944 // will be set to zero as one iSCSI session is comprised of several iSCSI
947 Private
->DevicePath
= IScsiGetTcpConnDevicePath (Private
->Session
);
948 if (Private
->DevicePath
== NULL
) {
949 Status
= EFI_DEVICE_ERROR
;
953 // Install the updated device path onto the ExtScsiPassThruHandle.
955 Status
= gBS
->InstallProtocolInterface (
956 &Private
->ExtScsiPassThruHandle
,
957 &gEfiDevicePathProtocolGuid
,
958 EFI_NATIVE_INTERFACE
,
961 if (EFI_ERROR (Status
)) {
966 // ISCSI children should share the default Tcp child, just open the default Tcp child via BY_CHILD_CONTROLLER.
968 Status
= gBS
->OpenProtocol (
969 Private
->ChildHandle
, /// Default Tcp child
973 Private
->ExtScsiPassThruHandle
,
974 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
976 if (EFI_ERROR (Status
)) {
977 gBS
->UninstallMultipleProtocolInterfaces (
978 Private
->ExtScsiPassThruHandle
,
979 &gEfiExtScsiPassThruProtocolGuid
,
980 &Private
->IScsiExtScsiPassThru
,
981 &gEfiDevicePathProtocolGuid
,
992 // Update/Publish the iSCSI Boot Firmware Table.
994 if (mPrivate
->BootSelectedIndex
!= 0) {
1002 if (Private
->Session
!= NULL
) {
1003 IScsiSessionAbort (Private
->Session
);
1010 Stops a device controller or a bus controller. This is the worker function for
1011 IScsiIp4(6)DriverBindingStop.
1013 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1014 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1015 support a bus specific I/O protocol for the driver
1016 to use to stop the device.
1017 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1018 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1019 if NumberOfChildren is 0.
1020 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
1022 @retval EFI_SUCCESS The device was stopped.
1023 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1024 @retval EFI_INVALID_PARAMETER Child handle is NULL.
1025 @retval EFI_ACCESS_DENIED The protocol could not be removed from the Handle
1026 because its interfaces are being used.
1032 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1033 IN EFI_HANDLE ControllerHandle
,
1034 IN UINTN NumberOfChildren
,
1035 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
,
1039 EFI_HANDLE IScsiController
;
1041 ISCSI_PRIVATE_PROTOCOL
*IScsiIdentifier
;
1042 ISCSI_DRIVER_DATA
*Private
;
1043 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*PassThru
;
1044 ISCSI_CONNECTION
*Conn
;
1045 EFI_GUID
*ProtocolGuid
;
1046 EFI_GUID
*TcpServiceBindingGuid
;
1047 EFI_GUID
*TcpProtocolGuid
;
1050 if (NumberOfChildren
!= 0) {
1052 // We should have only one child.
1054 Status
= gBS
->OpenProtocol (
1055 ChildHandleBuffer
[0],
1056 &gEfiExtScsiPassThruProtocolGuid
,
1057 (VOID
**) &PassThru
,
1058 This
->DriverBindingHandle
,
1060 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1062 if (EFI_ERROR (Status
)) {
1063 return EFI_DEVICE_ERROR
;
1066 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru
);
1067 Conn
= NET_LIST_HEAD (&Private
->Session
->Conns
, ISCSI_CONNECTION
, Link
);
1070 // Previously the TCP protocol is opened BY_CHILD_CONTROLLER. Just close
1071 // the protocol here, but do not uninstall the device path protocol and
1072 // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle.
1074 if (IpVersion
== IP_VERSION_4
) {
1075 ProtocolGuid
= &gEfiTcp4ProtocolGuid
;
1077 ProtocolGuid
= &gEfiTcp6ProtocolGuid
;
1080 gBS
->CloseProtocol (
1081 Private
->ChildHandle
,
1084 Private
->ExtScsiPassThruHandle
1087 gBS
->CloseProtocol (
1091 Private
->ExtScsiPassThruHandle
1098 // Get the handle of the controller we are controling.
1100 if (IpVersion
== IP_VERSION_4
) {
1101 ProtocolGuid
= &gIScsiV4PrivateGuid
;
1102 TcpProtocolGuid
= &gEfiTcp4ProtocolGuid
;
1103 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
1105 ProtocolGuid
= &gIScsiV6PrivateGuid
;
1106 TcpProtocolGuid
= &gEfiTcp6ProtocolGuid
;
1107 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
1109 IScsiController
= NetLibGetNicHandle (ControllerHandle
, TcpProtocolGuid
);
1110 if (IScsiController
== NULL
) {
1114 Status
= gBS
->OpenProtocol (
1117 (VOID
**) &IScsiIdentifier
,
1118 This
->DriverBindingHandle
,
1120 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1122 if (EFI_ERROR (Status
)) {
1123 return EFI_DEVICE_ERROR
;
1126 Private
= ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier
);
1127 ASSERT (Private
!= NULL
);
1129 if (Private
->ChildHandle
!= NULL
) {
1130 Status
= gBS
->CloseProtocol (
1131 Private
->ChildHandle
,
1133 This
->DriverBindingHandle
,
1137 ASSERT (!EFI_ERROR (Status
));
1139 Status
= NetLibDestroyServiceChild (
1141 This
->DriverBindingHandle
,
1142 TcpServiceBindingGuid
,
1143 Private
->ChildHandle
1146 ASSERT (!EFI_ERROR (Status
));
1149 gBS
->UninstallProtocolInterface (
1152 &Private
->IScsiIdentifier
1158 IScsiRemoveNic (IScsiController
);
1161 // Update the iSCSI Boot Firware Table.
1163 IScsiPublishIbft ();
1165 if (Private
->Session
!= NULL
) {
1166 IScsiSessionAbort (Private
->Session
);
1169 Status
= IScsiCleanDriverData (Private
);
1171 if (EFI_ERROR (Status
)) {
1179 Tests to see if this driver supports a given controller. If a child device is provided,
1180 it tests to see if this driver supports creating a handle for the specified child device.
1182 This function checks to see if the driver specified by This supports the device specified by
1183 ControllerHandle. Drivers typically use the device path attached to
1184 ControllerHandle and/or the services from the bus I/O abstraction attached to
1185 ControllerHandle to determine if the driver supports ControllerHandle. This function
1186 may be called many times during platform initialization. In order to reduce boot times, the tests
1187 performed by this function must be very small and take as little time as possible to execute. This
1188 function must not change the state of any hardware devices, and this function must be aware that the
1189 device specified by ControllerHandle may already be managed by the same driver or a
1190 different driver. This function must match its calls to AllocatePages() with FreePages(),
1191 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
1192 Since ControllerHandle may have been previously started by the same driver, if a protocol is
1193 already in the opened state, then it must not be closed with CloseProtocol(). This is required
1194 to guarantee the state of ControllerHandle is not modified by this function.
1196 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1197 @param[in] ControllerHandle The handle of the controller to test. This handle
1198 must support a protocol interface that supplies
1199 an I/O abstraction to the driver.
1200 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1201 parameter is ignored by device drivers, and is optional for bus
1202 drivers. For bus drivers, if this parameter is not NULL, then
1203 the bus driver must determine if the bus controller specified
1204 by ControllerHandle and the child controller specified
1205 by RemainingDevicePath are both supported by this
1208 @retval EFI_SUCCESS The device specified by ControllerHandle and
1209 RemainingDevicePath is supported by the driver specified by This.
1210 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
1211 RemainingDevicePath is already managed by the driver
1213 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
1214 RemainingDevicePath is already managed by a different
1215 driver or an application that requires exclusive access.
1216 Currently not implemented.
1217 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
1218 RemainingDevicePath is not supported by the driver specified by This.
1222 IScsiIp4DriverBindingSupported (
1223 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1224 IN EFI_HANDLE ControllerHandle
,
1225 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1228 return IScsiSupported (
1231 RemainingDevicePath
,
1237 Starts a device controller or a bus controller.
1239 The Start() function is designed to be invoked from the EFI boot service ConnectController().
1240 As a result, much of the error checking on the parameters to Start() has been moved into this
1241 common boot service. It is legal to call Start() from other locations,
1242 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1243 1. ControllerHandle must be a valid EFI_HANDLE.
1244 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
1245 EFI_DEVICE_PATH_PROTOCOL.
1246 3. Prior to calling Start(), the Supported() function for the driver specified by This must
1247 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
1249 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1250 @param[in] ControllerHandle The handle of the controller to start. This handle
1251 must support a protocol interface that supplies
1252 an I/O abstraction to the driver.
1253 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1254 parameter is ignored by device drivers, and is optional for bus
1255 drivers. For a bus driver, if this parameter is NULL, then handles
1256 for all the children of Controller are created by this driver.
1257 If this parameter is not NULL and the first Device Path Node is
1258 not the End of Device Path Node, then only the handle for the
1259 child device specified by the first Device Path Node of
1260 RemainingDevicePath is created by this driver.
1261 If the first Device Path Node of RemainingDevicePath is
1262 the End of Device Path Node, no child handle is created by this
1265 @retval EFI_SUCCESS The device was started.
1266 @retval EFI_DEVICE_ERROR The device could not be started due to a device error. Currently not implemented.
1267 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1268 @retval Others The driver failed to start the device.
1273 IScsiIp4DriverBindingStart (
1274 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1275 IN EFI_HANDLE ControllerHandle
,
1276 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1281 Status
= IScsiStart (This
->DriverBindingHandle
, ControllerHandle
, IP_VERSION_4
);
1282 if (Status
== EFI_ALREADY_STARTED
) {
1283 Status
= EFI_SUCCESS
;
1290 Stops a device controller or a bus controller.
1292 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1293 As a result, much of the error checking on the parameters to Stop() has been moved
1294 into this common boot service. It is legal to call Stop() from other locations,
1295 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1296 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1297 same driver's Start() function.
1298 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1299 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1300 Start() function, and the Start() function must have called OpenProtocol() on
1301 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1303 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1304 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1305 support a bus specific I/O protocol for the driver
1306 to use to stop the device.
1307 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1308 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1309 if NumberOfChildren is 0.
1311 @retval EFI_SUCCESS The device was stopped.
1312 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1317 IScsiIp4DriverBindingStop (
1318 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1319 IN EFI_HANDLE ControllerHandle
,
1320 IN UINTN NumberOfChildren
,
1321 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
1334 Tests to see if this driver supports a given controller. If a child device is provided,
1335 it tests to see if this driver supports creating a handle for the specified child device.
1337 This function checks to see if the driver specified by This supports the device specified by
1338 ControllerHandle. Drivers typically use the device path attached to
1339 ControllerHandle and/or the services from the bus I/O abstraction attached to
1340 ControllerHandle to determine if the driver supports ControllerHandle. This function
1341 may be called many times during platform initialization. In order to reduce boot times, the tests
1342 performed by this function must be very small and take as little time as possible to execute. This
1343 function must not change the state of any hardware devices, and this function must be aware that the
1344 device specified by ControllerHandle may already be managed by the same driver or a
1345 different driver. This function must match its calls to AllocatePages() with FreePages(),
1346 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
1347 Since ControllerHandle may have been previously started by the same driver, if a protocol is
1348 already in the opened state, then it must not be closed with CloseProtocol(). This is required
1349 to guarantee the state of ControllerHandle is not modified by this function.
1351 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1352 @param[in] ControllerHandle The handle of the controller to test. This handle
1353 must support a protocol interface that supplies
1354 an I/O abstraction to the driver.
1355 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1356 parameter is ignored by device drivers, and is optional for bus
1357 drivers. For bus drivers, if this parameter is not NULL, then
1358 the bus driver must determine if the bus controller specified
1359 by ControllerHandle and the child controller specified
1360 by RemainingDevicePath are both supported by this
1363 @retval EFI_SUCCESS The device specified by ControllerHandle and
1364 RemainingDevicePath is supported by the driver specified by This.
1365 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
1366 RemainingDevicePath is already managed by the driver
1368 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
1369 RemainingDevicePath is already managed by a different
1370 driver or an application that requires exclusive access.
1371 Currently not implemented.
1372 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
1373 RemainingDevicePath is not supported by the driver specified by This.
1377 IScsiIp6DriverBindingSupported (
1378 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1379 IN EFI_HANDLE ControllerHandle
,
1380 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1383 return IScsiSupported (
1386 RemainingDevicePath
,
1392 Starts a device controller or a bus controller.
1394 The Start() function is designed to be invoked from the EFI boot service ConnectController().
1395 As a result, much of the error checking on the parameters to Start() has been moved into this
1396 common boot service. It is legal to call Start() from other locations,
1397 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1398 1. ControllerHandle must be a valid EFI_HANDLE.
1399 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
1400 EFI_DEVICE_PATH_PROTOCOL.
1401 3. Prior to calling Start(), the Supported() function for the driver specified by This must
1402 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
1404 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1405 @param[in] ControllerHandle The handle of the controller to start. This handle
1406 must support a protocol interface that supplies
1407 an I/O abstraction to the driver.
1408 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1409 parameter is ignored by device drivers, and is optional for bus
1410 drivers. For a bus driver, if this parameter is NULL, then handles
1411 for all the children of Controller are created by this driver.
1412 If this parameter is not NULL and the first Device Path Node is
1413 not the End of Device Path Node, then only the handle for the
1414 child device specified by the first Device Path Node of
1415 RemainingDevicePath is created by this driver.
1416 If the first Device Path Node of RemainingDevicePath is
1417 the End of Device Path Node, no child handle is created by this
1420 @retval EFI_SUCCESS The device was started.
1421 @retval EFI_DEVICE_ERROR The device could not be started due to a device error. Currently not implemented.
1422 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1423 @retval Others The driver failed to start the device.
1428 IScsiIp6DriverBindingStart (
1429 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1430 IN EFI_HANDLE ControllerHandle
,
1431 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1436 Status
= IScsiStart (This
->DriverBindingHandle
, ControllerHandle
, IP_VERSION_6
);
1437 if (Status
== EFI_ALREADY_STARTED
) {
1438 Status
= EFI_SUCCESS
;
1445 Stops a device controller or a bus controller.
1447 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1448 As a result, much of the error checking on the parameters to Stop() has been moved
1449 into this common boot service. It is legal to call Stop() from other locations,
1450 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1451 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1452 same driver's Start() function.
1453 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1454 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1455 Start() function, and the Start() function must have called OpenProtocol() on
1456 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1458 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1459 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1460 support a bus specific I/O protocol for the driver
1461 to use to stop the device.
1462 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1463 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1464 if NumberOfChildren is 0.
1466 @retval EFI_SUCCESS The device was stopped.
1467 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1472 IScsiIp6DriverBindingStop (
1473 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1474 IN EFI_HANDLE ControllerHandle
,
1475 IN UINTN NumberOfChildren
,
1476 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
1489 Unload the iSCSI driver.
1491 @param[in] ImageHandle The handle of the driver image.
1493 @retval EFI_SUCCESS The driver is unloaded.
1494 @retval EFI_DEVICE_ERROR An unexpected error occurred.
1500 IN EFI_HANDLE ImageHandle
1504 UINTN DeviceHandleCount
;
1505 EFI_HANDLE
*DeviceHandleBuffer
;
1507 EFI_COMPONENT_NAME_PROTOCOL
*ComponentName
;
1508 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
1511 // Try to disonnect the driver from the devices it's controlling.
1513 Status
= gBS
->LocateHandleBuffer (
1520 if (EFI_ERROR (Status
)) {
1525 // Disconnect the iSCSI4 driver from the controlled device.
1527 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
1528 Status
= IScsiTestManagedDevice (
1529 DeviceHandleBuffer
[Index
],
1530 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1531 &gEfiTcp4ProtocolGuid
)
1533 if (EFI_ERROR (Status
)) {
1536 Status
= gBS
->DisconnectController (
1537 DeviceHandleBuffer
[Index
],
1538 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1541 if (EFI_ERROR (Status
)) {
1547 // Disconnect the iSCSI6 driver from the controlled device.
1549 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
1550 Status
= IScsiTestManagedDevice (
1551 DeviceHandleBuffer
[Index
],
1552 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1553 &gEfiTcp6ProtocolGuid
1555 if (EFI_ERROR (Status
)) {
1558 Status
= gBS
->DisconnectController (
1559 DeviceHandleBuffer
[Index
],
1560 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1563 if (EFI_ERROR (Status
)) {
1569 // Unload the iSCSI configuration form.
1571 Status
= IScsiConfigFormUnload (gIScsiIp4DriverBinding
.DriverBindingHandle
);
1572 if (EFI_ERROR (Status
)) {
1577 // Uninstall the protocols installed by iSCSI driver.
1579 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1581 &gEfiAuthenticationInfoProtocolGuid
,
1582 &gIScsiAuthenticationInfo
,
1585 if (EFI_ERROR (Status
)) {
1589 if (gIScsiControllerNameTable
!= NULL
) {
1590 Status
= FreeUnicodeStringTable (gIScsiControllerNameTable
);
1591 if (EFI_ERROR (Status
)) {
1594 gIScsiControllerNameTable
= NULL
;
1598 // Uninstall the ComponentName and ComponentName2 protocol from iSCSI4 driver binding handle
1599 // if it has been installed.
1601 Status
= gBS
->HandleProtocol (
1602 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1603 &gEfiComponentNameProtocolGuid
,
1604 (VOID
**) &ComponentName
1606 if (!EFI_ERROR (Status
)) {
1607 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1608 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1609 &gEfiComponentNameProtocolGuid
,
1613 if (EFI_ERROR (Status
)) {
1618 Status
= gBS
->HandleProtocol (
1619 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1620 &gEfiComponentName2ProtocolGuid
,
1621 (VOID
**) &ComponentName2
1623 if (!EFI_ERROR (Status
)) {
1624 gBS
->UninstallMultipleProtocolInterfaces (
1625 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1626 &gEfiComponentName2ProtocolGuid
,
1630 if (EFI_ERROR (Status
)) {
1636 // Uninstall the ComponentName and ComponentName2 protocol from iSCSI6 driver binding handle
1637 // if it has been installed.
1639 Status
= gBS
->HandleProtocol (
1640 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1641 &gEfiComponentNameProtocolGuid
,
1642 (VOID
**) &ComponentName
1644 if (!EFI_ERROR (Status
)) {
1645 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1646 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1647 &gEfiComponentNameProtocolGuid
,
1651 if (EFI_ERROR (Status
)) {
1656 Status
= gBS
->HandleProtocol (
1657 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1658 &gEfiComponentName2ProtocolGuid
,
1659 (VOID
**) &ComponentName2
1661 if (!EFI_ERROR (Status
)) {
1662 gBS
->UninstallMultipleProtocolInterfaces (
1663 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1664 &gEfiComponentName2ProtocolGuid
,
1668 if (EFI_ERROR (Status
)) {
1674 // Uninstall the IScsiInitiatorNameProtocol and all the driver binding protocols.
1676 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1677 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1678 &gEfiDriverBindingProtocolGuid
,
1679 &gIScsiIp4DriverBinding
,
1680 &gEfiIScsiInitiatorNameProtocolGuid
,
1681 &gIScsiInitiatorName
,
1684 if (EFI_ERROR (Status
)) {
1688 Status
= gBS
->UninstallMultipleProtocolInterfaces (
1689 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1690 &gEfiDriverBindingProtocolGuid
,
1691 &gIScsiIp6DriverBinding
,
1697 if (DeviceHandleBuffer
!= NULL
) {
1698 FreePool (DeviceHandleBuffer
);
1705 This is the declaration of an EFI image entry point. This entry point is
1706 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1707 both device drivers and bus drivers.
1709 The entry point for iSCSI driver which initializes the global variables and
1710 installs the driver binding, component name protocol, iSCSI initiator name
1711 protocol and Authentication Info protocol on its image.
1713 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
1714 @param[in] SystemTable A pointer to the EFI System Table.
1716 @retval EFI_SUCCESS The operation completed successfully.
1717 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1722 IScsiDriverEntryPoint (
1723 IN EFI_HANDLE ImageHandle
,
1724 IN EFI_SYSTEM_TABLE
*SystemTable
1728 EFI_ISCSI_INITIATOR_NAME_PROTOCOL
*IScsiInitiatorName
;
1729 EFI_AUTHENTICATION_INFO_PROTOCOL
*AuthenticationInfo
;
1732 // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.
1734 Status
= gBS
->LocateProtocol (
1735 &gEfiIScsiInitiatorNameProtocolGuid
,
1737 (VOID
**) &IScsiInitiatorName
1739 if (!EFI_ERROR (Status
)) {
1740 return EFI_ACCESS_DENIED
;
1744 // Initialize the EFI Driver Library.
1746 Status
= EfiLibInstallDriverBindingComponentName2 (
1749 &gIScsiIp4DriverBinding
,
1751 &gIScsiComponentName
,
1752 &gIScsiComponentName2
1754 if (EFI_ERROR (Status
)) {
1758 Status
= EfiLibInstallDriverBindingComponentName2 (
1761 &gIScsiIp6DriverBinding
,
1763 &gIScsiComponentName
,
1764 &gIScsiComponentName2
1766 if (EFI_ERROR (Status
)) {
1771 // Install the iSCSI Initiator Name Protocol.
1773 Status
= gBS
->InstallProtocolInterface (
1775 &gEfiIScsiInitiatorNameProtocolGuid
,
1776 EFI_NATIVE_INTERFACE
,
1777 &gIScsiInitiatorName
1779 if (EFI_ERROR (Status
)) {
1784 // Create the private data structures.
1786 mPrivate
= AllocateZeroPool (sizeof (ISCSI_PRIVATE_DATA
));
1787 if (mPrivate
== NULL
) {
1788 Status
= EFI_OUT_OF_RESOURCES
;
1792 InitializeListHead (&mPrivate
->NicInfoList
);
1793 InitializeListHead (&mPrivate
->AttemptConfigs
);
1796 // Initialize the configuration form of iSCSI.
1798 Status
= IScsiConfigFormInit (gIScsiIp4DriverBinding
.DriverBindingHandle
);
1799 if (EFI_ERROR (Status
)) {
1804 // Create the Maximum Attempts.
1806 Status
= IScsiCreateAttempts (PcdGet8 (PcdMaxIScsiAttemptNumber
));
1807 if (EFI_ERROR (Status
)) {
1812 // Create Keywords for all the Attempts.
1814 Status
= IScsiCreateKeywords (PcdGet8 (PcdMaxIScsiAttemptNumber
));
1815 if (EFI_ERROR (Status
)) {
1820 // There should be only one EFI_AUTHENTICATION_INFO_PROTOCOL. If already exists,
1821 // do not produce the protocol instance.
1823 Status
= gBS
->LocateProtocol (
1824 &gEfiAuthenticationInfoProtocolGuid
,
1826 (VOID
**) &AuthenticationInfo
1828 if (Status
== EFI_NOT_FOUND
) {
1829 Status
= gBS
->InstallProtocolInterface (
1831 &gEfiAuthenticationInfoProtocolGuid
,
1832 EFI_NATIVE_INTERFACE
,
1833 &gIScsiAuthenticationInfo
1835 if (EFI_ERROR (Status
)) {
1843 IScsiCleanAttemptVariable ();
1846 IScsiConfigFormUnload (gIScsiIp4DriverBinding
.DriverBindingHandle
);
1849 if (mPrivate
!= NULL
) {
1850 FreePool (mPrivate
);
1855 gBS
->UninstallMultipleProtocolInterfaces (
1857 &gEfiIScsiInitiatorNameProtocolGuid
,
1858 &gIScsiInitiatorName
,
1863 gBS
->UninstallMultipleProtocolInterfaces (
1864 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1865 &gEfiDriverBindingProtocolGuid
,
1866 &gIScsiIp6DriverBinding
,
1867 &gEfiComponentName2ProtocolGuid
,
1868 &gIScsiComponentName2
,
1869 &gEfiComponentNameProtocolGuid
,
1870 &gIScsiComponentName
,
1875 gBS
->UninstallMultipleProtocolInterfaces (
1877 &gEfiDriverBindingProtocolGuid
,
1878 &gIScsiIp4DriverBinding
,
1879 &gEfiComponentName2ProtocolGuid
,
1880 &gIScsiComponentName2
,
1881 &gEfiComponentNameProtocolGuid
,
1882 &gIScsiComponentName
,