public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ard.biesheuvel@arm.com>
To: devel@edk2.groups.io
Cc: leif@nuviainc.com, Ard Biesheuvel <ard.biesheuvel@arm.com>
Subject: [PATCH edk2-platforms 3/3] Silicon/SynQuacer/NetsecDxe: avoid media detection delay at boot
Date: Sat, 16 May 2020 19:59:34 +0200	[thread overview]
Message-ID: <20200516175934.31148-4-ard.biesheuvel@arm.com> (raw)
In-Reply-To: <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 <ard.biesheuvel@arm.com>
---
 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 <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiLib.h>
 
+#include <Protocol/AdapterInformation.h>
 #include <Protocol/NonDiscoverableDevice.h>
 
 #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


  parent reply	other threads:[~2020-05-16 17:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-16 17:59 [PATCH edk2-platforms 0/3] Silicon/SynQuacer: preparatory ConnectAll fixes Ard Biesheuvel
2020-05-16 17:59 ` [PATCH edk2-platforms 1/3] Platform/96Boards/96BoardsI2cDxe: connect I2C controllers at EndOfDxe Ard Biesheuvel
2020-05-18 17:26   ` Leif Lindholm
2020-05-19 10:23     ` Ard Biesheuvel
2020-05-19 10:46       ` Leif Lindholm
2020-05-16 17:59 ` [PATCH edk2-platforms 2/3] Silicon/SynQuacer/NetsecDxe: drop false dependency on device path protocol Ard Biesheuvel
2020-05-16 17:59 ` Ard Biesheuvel [this message]
2020-05-19 12:32 ` [PATCH edk2-platforms 0/3] Silicon/SynQuacer: preparatory ConnectAll fixes Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200516175934.31148-4-ard.biesheuvel@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox