From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.9469.1589651986253220309 for ; Sat, 16 May 2020 10:59:46 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D316F1045; Sat, 16 May 2020 10:59:45 -0700 (PDT) Received: from e123331-lin.nice.arm.com (unknown [10.37.8.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CE5A53F305; Sat, 16 May 2020 10:59:44 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, Ard Biesheuvel Subject: [PATCH edk2-platforms 3/3] Silicon/SynQuacer/NetsecDxe: avoid media detection delay at boot Date: Sat, 16 May 2020 19:59:34 +0200 Message-Id: <20200516175934.31148-4-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200516175934.31148-1-ard.biesheuvel@arm.com> References: <20200516175934.31148-1-ard.biesheuvel@arm.com> Instead of unconditionally delaying the boot up to 5 seconds, even if no network cable is connected in the first place, provide an implementation of the EFI adapter information protocol so that the upper networking layers can wait gracefully for the link to come up, but only when the network is actually used to boot from. Signed-off-by: Ard Biesheuvel --- Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec | 1 - Platform/Socionext/DeveloperBox/DeveloperBox.dsc | 1 - Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf | 3 +- Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h | 5 + Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c | 112 +++++++++++++++++--- 5 files changed, 103 insertions(+), 19 deletions(-) diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec index 3b1de62c6e31..6b9f60293879 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec @@ -37,5 +37,4 @@ [PcdsFixedAtBuild.common] gNetsecDxeTokenSpaceGuid.PcdFlowCtrl|0x0|UINT8|0x00000005 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStartThreshold|0x0|UINT16|0x00000006 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStopThreshold|0x0|UINT16|0x00000007 - gNetsecDxeTokenSpaceGuid.PcdMediaDetectTimeoutOnBoot|0x0|UINT8|0x00000009 gNetsecDxeTokenSpaceGuid.PcdPauseTime|0x0|UINT16|0x00000008 diff --git a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc b/Platform/Socionext/DeveloperBox/DeveloperBox.dsc index 9307edefb11a..a459079b1f26 100644 --- a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc +++ b/Platform/Socionext/DeveloperBox/DeveloperBox.dsc @@ -165,7 +165,6 @@ [PcdsFixedAtBuild] gNetsecDxeTokenSpaceGuid.PcdFlowCtrl|0 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStartThreshold|36 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStopThreshold|48 - gNetsecDxeTokenSpaceGuid.PcdMediaDetectTimeoutOnBoot|5 gNetsecDxeTokenSpaceGuid.PcdPauseTime|256 gSynQuacerTokenSpaceGuid.PcdNetsecEepromBase|0x08080000 diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf index 0efba0bbbf94..8ea959c37bab 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf @@ -47,11 +47,13 @@ [LibraryClasses] UefiLib [Guids] + gEfiAdapterInfoMediaStateGuid gNetsecNonDiscoverableDeviceGuid [Protocols] gEfiCpuArchProtocolGuid ## CONSUMES gEdkiiNonDiscoverableDeviceProtocolGuid ## TO_START + gEfiAdapterInformationProtocolGuid ## BY_START gEfiSimpleNetworkProtocolGuid ## BY_START [FixedPcd] @@ -61,5 +63,4 @@ [FixedPcd] gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStartThreshold gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStopThreshold gNetsecDxeTokenSpaceGuid.PcdJumboPacket - gNetsecDxeTokenSpaceGuid.PcdMediaDetectTimeoutOnBoot gNetsecDxeTokenSpaceGuid.PcdPauseTime diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h index 17a7032f0f41..cf2abb0ab108 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h @@ -20,6 +20,7 @@ #include #include +#include #include #include "netsec_for_uefi/netsec_sdk/include/ogma_api.h" @@ -50,6 +51,9 @@ typedef struct { // EFI Snp statistics instance EFI_NETWORK_STATISTICS Stats; + // Adapter Information protocol + EFI_ADAPTER_INFORMATION_PROTOCOL Aip; + // ogma handle ogma_handle_t Handle; @@ -65,6 +69,7 @@ typedef struct { #define NETSEC_SIGNATURE SIGNATURE_32('n', 't', 's', 'c') #define INSTANCE_FROM_SNP_THIS(a) CR((a), NETSEC_DRIVER, Snp, NETSEC_SIGNATURE) +#define INSTANCE_FROM_AIP_THIS(a) CR((a), NETSEC_DRIVER, Aip, NETSEC_SIGNATURE) /*------------------------------------------------------------------------------ diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c index 4e3c4e6c807a..c9fc4d6e2d8e 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c @@ -279,8 +279,6 @@ SnpInitialize ( ogma_err_t ogma_err; - UINT32 Index; - // Check Snp Instance if (Snp == NULL) { return EFI_INVALID_PARAMETER; @@ -363,20 +361,6 @@ SnpInitialize ( ogma_disable_desc_ring_irq (LanDriver->Handle, OGMA_DESC_RING_ID_NRM_TX, OGMA_CH_IRQ_REG_EMPTY); - // Wait for media linking up - for (Index = 0; Index < (UINT32)FixedPcdGet8 (PcdMediaDetectTimeoutOnBoot) * 10; Index++) { - Status = NetsecUpdateLink (Snp); - if (Status != EFI_SUCCESS) { - ReturnUnlock (EFI_DEVICE_ERROR); - } - - if (Snp->Mode->MediaPresent) { - break; - } - - MicroSecondDelay(100000); - } - // Declare the driver as initialized Snp->Mode->State = EfiSimpleNetworkInitialized; Status = EFI_SUCCESS; @@ -948,6 +932,96 @@ SnpReceive ( return Status; } +STATIC +EFI_STATUS +EFIAPI +NetsecAipGetInformation ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + IN EFI_GUID *InformationType, + OUT VOID **InformationBlock, + OUT UINTN *InformationBlockSize + ) +{ + EFI_ADAPTER_INFO_MEDIA_STATE *AdapterInfo; + NETSEC_DRIVER *LanDriver; + + if (This == NULL || InformationBlock == NULL || + InformationBlockSize == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (!CompareGuid (InformationType, &gEfiAdapterInfoMediaStateGuid)) { + return EFI_UNSUPPORTED; + } + + AdapterInfo = AllocateZeroPool (sizeof (EFI_ADAPTER_INFO_MEDIA_STATE)); + if (AdapterInfo == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + *InformationBlock = AdapterInfo; + *InformationBlockSize = sizeof (EFI_ADAPTER_INFO_MEDIA_STATE); + + LanDriver = INSTANCE_FROM_AIP_THIS (This); + if (LanDriver->Snp.Mode->MediaPresent) { + AdapterInfo->MediaState = EFI_SUCCESS; + } else { + AdapterInfo->MediaState = EFI_NOT_READY; + } + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +EFIAPI +NetsecAipSetInformation ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN VOID *InformationBlock, + IN UINTN InformationBlockSize + ) +{ + if (This == NULL || InformationBlock == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (CompareGuid (InformationType, &gEfiAdapterInfoMediaStateGuid)) { + return EFI_WRITE_PROTECTED; + } + + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +NetsecAipGetSupportedTypes ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + OUT EFI_GUID **InfoTypesBuffer, + OUT UINTN *InfoTypesBufferCount + ) +{ + EFI_GUID *Guid; + + if (This == NULL || InfoTypesBuffer == NULL || + InfoTypesBufferCount == NULL) { + return EFI_INVALID_PARAMETER; + } + + Guid = AllocatePool (sizeof *Guid); + if (Guid == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyGuid (Guid, &gEfiAdapterInfoMediaStateGuid); + + *InfoTypesBuffer = Guid; + *InfoTypesBufferCount = 1; + + return EFI_SUCCESS; +} + EFI_STATUS NetsecInit ( IN EFI_HANDLE DriverBindingHandle, @@ -1046,6 +1120,10 @@ NetsecInit ( SnpMode->MediaPresentSupported = TRUE; SnpMode->MediaPresent = FALSE; + LanDriver->Aip.GetInformation = NetsecAipGetInformation; + LanDriver->Aip.SetInformation = NetsecAipSetInformation; + LanDriver->Aip.GetSupportedTypes = NetsecAipGetSupportedTypes; + // Set broadcast address SetMem (&SnpMode->BroadcastAddress, sizeof (EFI_MAC_ADDRESS), 0xFF); @@ -1055,6 +1133,7 @@ NetsecInit ( Status = gBS->InstallMultipleProtocolInterfaces ( &ControllerHandle, &gEfiSimpleNetworkProtocolGuid, Snp, + &gEfiAdapterInformationProtocolGuid, &LanDriver->Aip, NULL); LanDriver->ControllerHandle = ControllerHandle; @@ -1100,6 +1179,7 @@ NetsecRelease ( Status = gBS->UninstallMultipleProtocolInterfaces (ControllerHandle, &gEfiSimpleNetworkProtocolGuid, Snp, + &gEfiAdapterInformationProtocolGuid, &LanDriver->Aip, NULL); if (EFI_ERROR (Status)) { return Status; -- 2.17.1