X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=NetworkPkg%2FIScsiDxe%2FIScsiDriver.c;h=51ce16911bcb4365a5faf032022f817871d1eab3;hb=5346adbb18004b27a1ca428f40efa815c31f617e;hp=8d1742455c2ca2cf17b0fe61ebea5ac0779f2965;hpb=9c12f2d77fe8ac958e6da4ceb92378227dd6c676;p=mirror_edk2.git diff --git a/NetworkPkg/IScsiDxe/IScsiDriver.c b/NetworkPkg/IScsiDxe/IScsiDriver.c index 8d1742455c..51ce16911b 100644 --- a/NetworkPkg/IScsiDxe/IScsiDriver.c +++ b/NetworkPkg/IScsiDxe/IScsiDriver.c @@ -1,7 +1,7 @@ /** @file The entry point of IScsi driver. -Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -74,6 +74,145 @@ IScsiIsDevicePathSupported ( return EFI_SUCCESS; } +/** + Check whether an iSCSI HBA adapter already installs an AIP instance with + network boot policy matching the value specified in PcdIScsiAIPNetworkBootPolicy. + If yes, return EFI_SUCCESS. + + @retval EFI_SUCCESS Found an AIP with matching network boot policy. + @retval EFI_NOT_FOUND AIP is unavailable or the network boot policy + not matched. +**/ +EFI_STATUS +IScsiCheckAip ( + ) +{ + UINTN AipHandleCount; + EFI_HANDLE *AipHandleBuffer; + UINTN AipIndex; + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; + EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiPassThru; + EFI_GUID *InfoTypesBuffer; + UINTN InfoTypeBufferCount; + UINTN TypeIndex; + VOID *InfoBlock; + UINTN InfoBlockSize; + BOOLEAN Supported; + EFI_ADAPTER_INFO_NETWORK_BOOT *NetworkBoot; + EFI_STATUS Status; + UINT8 NetworkBootPolicy; + + // + // Check any AIP instances exist in system. + // + AipHandleCount = 0; + AipHandleBuffer = NULL; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiAdapterInformationProtocolGuid, + NULL, + &AipHandleCount, + &AipHandleBuffer + ); + if (EFI_ERROR (Status) || AipHandleCount == 0) { + return EFI_NOT_FOUND; + } + + ASSERT (AipHandleBuffer != NULL); + + InfoBlock = NULL; + + for (AipIndex = 0; AipIndex < AipHandleCount; AipIndex++) { + Status = gBS->HandleProtocol ( + AipHandleBuffer[AipIndex], + &gEfiAdapterInformationProtocolGuid, + (VOID *) &Aip + ); + ASSERT_EFI_ERROR (Status); + ASSERT (Aip != NULL); + + Status = gBS->HandleProtocol ( + AipHandleBuffer[AipIndex], + &gEfiExtScsiPassThruProtocolGuid, + (VOID *) &ExtScsiPassThru + ); + if (EFI_ERROR (Status) || ExtScsiPassThru == NULL) { + continue; + } + + InfoTypesBuffer = NULL; + InfoTypeBufferCount = 0; + Status = Aip->GetSupportedTypes (Aip, &InfoTypesBuffer, &InfoTypeBufferCount); + if (EFI_ERROR (Status) || InfoTypesBuffer == NULL) { + continue; + } + // + // Check whether the AIP instance has Network boot information block. + // + Supported = FALSE; + for (TypeIndex = 0; TypeIndex < InfoTypeBufferCount; TypeIndex++) { + if (CompareGuid (&InfoTypesBuffer[TypeIndex], &gEfiAdapterInfoNetworkBootGuid)) { + Supported = TRUE; + break; + } + } + + FreePool (InfoTypesBuffer); + if (!Supported) { + continue; + } + + // + // We now have network boot information block. + // + InfoBlock = NULL; + InfoBlockSize = 0; + Status = Aip->GetInformation (Aip, &gEfiAdapterInfoNetworkBootGuid, &InfoBlock, &InfoBlockSize); + if (EFI_ERROR (Status) || InfoBlock == NULL) { + continue; + } + + // + // Check whether the network boot policy matches. + // + NetworkBoot = (EFI_ADAPTER_INFO_NETWORK_BOOT *) InfoBlock; + NetworkBootPolicy = PcdGet8 (PcdIScsiAIPNetworkBootPolicy); + + if (NetworkBootPolicy == STOP_UEFI_ISCSI_IF_HBA_INSTALL_AIP) { + Status = EFI_SUCCESS; + goto Exit; + } + if (((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP4) != 0 && + !NetworkBoot->iScsiIpv4BootCapablity) || + ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP6) != 0 && + !NetworkBoot->iScsiIpv6BootCapablity) || + ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_SUPPORT_OFFLOAD) != 0 && + !NetworkBoot->OffloadCapability) || + ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_SUPPORT_MPIO) != 0 && + !NetworkBoot->iScsiMpioCapability) || + ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP4) != 0 && + !NetworkBoot->iScsiIpv4Boot) || + ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP6) != 0 && + !NetworkBoot->iScsiIpv6Boot)) { + FreePool (InfoBlock); + continue; + } + + Status = EFI_SUCCESS; + goto Exit; + } + + Status = EFI_NOT_FOUND; + +Exit: + if (InfoBlock != NULL) { + FreePool (InfoBlock); + } + if (AipHandleBuffer != NULL) { + FreePool (AipHandleBuffer); + } + return Status; +} /** Tests to see if this driver supports a given controller. This is the worker function for @@ -215,6 +354,7 @@ IScsiStart ( BOOLEAN NeedUpdate; VOID *Interface; EFI_GUID *ProtocolGuid; + UINT8 NetworkBootPolicy; // // Test to see if iSCSI driver supports the given controller. @@ -256,6 +396,20 @@ IScsiStart ( return EFI_UNSUPPORTED; } + NetworkBootPolicy = PcdGet8 (PcdIScsiAIPNetworkBootPolicy); + if (NetworkBootPolicy != ALWAYS_USE_UEFI_ISCSI_AND_IGNORE_AIP) { + // + // Check existing iSCSI AIP. + // + Status = IScsiCheckAip (); + if (!EFI_ERROR (Status)) { + // + // Find iSCSI AIP with specified network boot policy. return EFI_ABORTED. + // + return EFI_ABORTED; + } + } + // // Record the incoming NIC info. // @@ -290,7 +444,7 @@ IScsiStart ( } Status = gBS->OpenProtocol ( - Private->ChildHandle, + Private->ChildHandle, /// Default Tcp child ProtocolGuid, &Interface, Image, @@ -477,7 +631,7 @@ IScsiStart ( // Don't process the autoconfigure path if it is already established. // if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG && - AttemptConfigData->AutoConfigureMode == IP_MODE_AUTOCONFIG_SUCCESS) { + AttemptConfigData->AutoConfigureSuccess) { continue; } @@ -576,7 +730,7 @@ IScsiStart ( // IScsi session success. Update the attempt state to NVR. // if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG) { - AttemptConfigData->AutoConfigureMode = IP_MODE_AUTOCONFIG_SUCCESS; + AttemptConfigData->AutoConfigureSuccess = TRUE; } gRT->SetVariable ( @@ -750,6 +904,30 @@ IScsiStart ( goto ON_ERROR; } + // + // ISCSI children should share the default Tcp child, just open the default Tcp child via BY_CHILD_CONTROLLER. + // + Status = gBS->OpenProtocol ( + Private->ChildHandle, /// Default Tcp child + ProtocolGuid, + &Interface, + Image, + Private->ExtScsiPassThruHandle, + EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER + ); + if (EFI_ERROR (Status)) { + gBS->UninstallMultipleProtocolInterfaces ( + Private->ExtScsiPassThruHandle, + &gEfiExtScsiPassThruProtocolGuid, + &Private->IScsiExtScsiPassThru, + &gEfiDevicePathProtocolGuid, + Private->DevicePath, + NULL + ); + + goto ON_ERROR; + } + ON_EXIT: // @@ -838,6 +1016,13 @@ IScsiStop ( ProtocolGuid = &gEfiTcp6ProtocolGuid; } + gBS->CloseProtocol ( + Private->ChildHandle, + ProtocolGuid, + Private->Image, + Private->ExtScsiPassThruHandle + ); + gBS->CloseProtocol ( Conn->TcpIo.Handle, ProtocolGuid, @@ -847,6 +1032,7 @@ IScsiStop ( return EFI_SUCCESS; } + // // Get the handle of the controller we are controling. //