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.web10.10681.1591264219524140877 for ; Thu, 04 Jun 2020 02:50:19 -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 23BA5101E; Thu, 4 Jun 2020 02:50:19 -0700 (PDT) Received: from localhost.localdomain (unknown [10.37.8.209]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 66E543F6CF; Thu, 4 Jun 2020 02:50:17 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jared McNeill , Andrei Warkentin , Samer El-Haj-Mahmoud , Leif Lindholm , Pete Batard , Jeremy Linton Subject: [PATCH edk2-platforms 1/3] Silicon/Broadcom/BcmGenetDxe: program MAC also when not connected Date: Thu, 4 Jun 2020 11:50:05 +0200 Message-Id: <20200604095007.45693-2-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200604095007.45693-1-ard.biesheuvel@arm.com> References: <20200604095007.45693-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In preparation of removing the EfiBootManagerConnectAll() from the ordinary boot path, ensure that the MAC programming of the GENET occurs even if the SNP driver for it is never invoked by the BDS. Signed-off-by: Ard Biesheuvel --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 66 ++++++++++++= ++++++++ 1 file changed, 66 insertions(+) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Sil= icon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index f37da3b65511..7f93c68cd608 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -12,6 +12,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -20,6 +21,9 @@ =0D #include "BcmGenetDxe.h"=0D =0D +STATIC EFI_EVENT mProtocolNotifyEvent;=0D +STATIC VOID *mProtocolNotifyEventRegistration;=0D +=0D /**=0D Tests to see if this driver supports a given controller.=0D =0D @@ -305,6 +309,57 @@ STATIC EFI_DRIVER_BINDING_PROTOCOL mGenetDriverBinding= =3D { NULL=0D };=0D =0D +STATIC=0D +VOID=0D +EFIAPI=0D +OnProtocolNotify (=0D + IN EFI_EVENT Event,=0D + IN VOID *Context=0D + )=0D +{=0D + BCM_GENET_PLATFORM_DEVICE_PROTOCOL *GenetDevice;=0D + EFI_STATUS Status;=0D + EFI_HANDLE *HandleBuffer;=0D + UINTN HandleCount;=0D + UINTN Index;=0D + UINT32 Mac0, Mac1;=0D +=0D + while (TRUE) {=0D + Status =3D gBS->LocateHandleBuffer (ByRegisterNotify, NULL,=0D + mProtocolNotifyEventRegistration, &HandleCount,=0D + &HandleBuffer);=0D + if (EFI_ERROR (Status)) {=0D + break;=0D + }=0D +=0D + for (Index =3D 0; Index < HandleCount; Index++) {=0D + Status =3D gBS->HandleProtocol (HandleBuffer[Index],=0D + &gBcmGenetPlatformDeviceProtocolGuid,=0D + (VOID **)&GenetDevice);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Mac0 =3D (GenetDevice->MacAddress.Addr[3]) |=0D + (GenetDevice->MacAddress.Addr[2] << 8) |=0D + (GenetDevice->MacAddress.Addr[1] << 16) |=0D + (GenetDevice->MacAddress.Addr[0] << 24);=0D + Mac1 =3D (GenetDevice->MacAddress.Addr[5]) |=0D + (GenetDevice->MacAddress.Addr[4] << 8);=0D +=0D + MmioOr32 (GenetDevice->BaseAddress + GENET_SYS_RBUF_FLUSH_CTRL,=0D + GENET_SYS_RBUF_FLUSH_RESET);=0D + gBS->Stall (10);=0D + MmioAnd32 (GenetDevice->BaseAddress + GENET_SYS_RBUF_FLUSH_CTRL,=0D + ~GENET_SYS_RBUF_FLUSH_RESET);=0D +=0D + MemoryFence ();=0D +=0D + MmioWrite32 (GenetDevice->BaseAddress + GENET_UMAC_MAC0, Mac0);=0D + MmioWrite32 (GenetDevice->BaseAddress + GENET_UMAC_MAC1, Mac1);=0D + }=0D + FreePool (HandleBuffer);=0D + }=0D +}=0D +=0D /**=0D The entry point of GENET UEFI Driver.=0D =0D @@ -336,6 +391,17 @@ GenetEntryPoint ( =0D ASSERT_EFI_ERROR (Status);=0D =0D + //=0D + // We need to program the MAC address into each existing controller,=0D + // regardless of whether UEFI ever makes use of the interface, so that=0D + // the OS driver will not have to care about this.=0D + //=0D + mProtocolNotifyEvent =3D EfiCreateProtocolNotifyEvent (=0D + &gBcmGenetPlatformDeviceProtocolGuid,=0D + TPL_CALLBACK, OnProtocolNotify, NULL,=0D + &mProtocolNotifyEventRegistration);=0D + ASSERT (mProtocolNotifyEvent !=3D NULL);=0D +=0D DEBUG ((DEBUG_INIT | DEBUG_INFO, "Installed GENET UEFI driver!\n"));=0D =0D return EFI_SUCCESS;=0D --=20 2.26.2