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.web11.1945.1592417710110510454 for ; Wed, 17 Jun 2020 11:15:10 -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 A33DE1045; Wed, 17 Jun 2020 11:15:08 -0700 (PDT) Received: from dogfood.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AF20B3F71F; Wed, 17 Jun 2020 11:15:07 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Pete Batard , Andrei Warkentin , Samer El-Haj-Mahmoud Subject: [PATCH edk2-platforms v2] Silicon/Broadcom/BcmGenetDxe: implement media state adapter info protocol Date: Wed, 17 Jun 2020 20:15:01 +0200 Message-Id: <20200617181501.1184090-1-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable NetLibDetectMedia () in DxeNetLib is used as a fallback on implementations of the SNP protocol that do not also carry an implementation of the adapter info protocol to provide media state information, and it does all kinds of terrible things to the network interface (stopping and restarting multiple times, reprogramming the multicast filters etc etc) to workaround some alleged UNDI shortcoming. Although our GENET code should be bullet proof and therefore able to take this kind of abuse, it is better to avoid it, and provide an implementation of the adapter info protocol that returns the media state directly, without the need to mistreat the SNP layer. =0D Cc: Pete Batard =0D Cc: Andrei Warkentin (awarkentin@vmware.com) =0D Cc: Samer El-Haj-Mahmoud =0D Signed-off-by: Ard Biesheuvel ---=0D v2:=0D - use the correct accessor to retrieve the GENET_PRIVATE_DATA pointer=0D - call into the PHY routines to get the state, to ensure it is not stale=0D Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 3 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h | 5 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/AdapterInfo.c | 106 +++++++++++= +++++++++ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 12 ++- 4 files changed, 121 insertions(+), 5 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Sil= icon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index 28f3e66ebaf0..89dee9f10c83 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -19,6 +19,7 @@ [Defines] UNLOAD_IMAGE =3D GenetUnload=0D =0D [Sources]=0D + AdapterInfo.c=0D BcmGenetDxe.h=0D ComponentName.c=0D DriverBinding.c=0D @@ -49,10 +50,12 @@ [LibraryClasses] =0D [Protocols]=0D gBcmGenetPlatformDeviceProtocolGuid ## TO_START=0D + gEfiAdapterInformationProtocolGuid ## BY_START=0D gEfiDevicePathProtocolGuid ## BY_START=0D gEfiSimpleNetworkProtocolGuid ## BY_START=0D =0D [Guids]=0D + gEfiAdapterInfoMediaStateGuid=0D gEfiEventExitBootServicesGuid=0D =0D [FixedPcd]=0D diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h b/Silic= on/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h index 0af9d5209cf2..1a117b25f87f 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h @@ -14,6 +14,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -209,6 +210,8 @@ typedef struct { EFI_SIMPLE_NETWORK_PROTOCOL Snp;=0D EFI_SIMPLE_NETWORK_MODE SnpMode;=0D =0D + EFI_ADAPTER_INFORMATION_PROTOCOL Aip;=0D +=0D BCM_GENET_PLATFORM_DEVICE_PROTOCOL *Dev;=0D =0D GENERIC_PHY_PRIVATE_DATA Phy;=0D @@ -234,9 +237,11 @@ extern EFI_COMPONENT_NAME_PROTOCOL gGenetCo= mponentName; extern EFI_COMPONENT_NAME2_PROTOCOL gGenetComponentName2;=0D =0D extern CONST EFI_SIMPLE_NETWORK_PROTOCOL gGenetSimpleNetworkTemplate;= =0D +extern CONST EFI_ADAPTER_INFORMATION_PROTOCOL gGenetAdapterInfoTemplate;=0D =0D #define GENET_DRIVER_SIGNATURE SIGNATURE_32('G', 'N', 'E', = 'T')=0D #define GENET_PRIVATE_DATA_FROM_SNP_THIS(a) CR(a, GENET_PRIVATE_DATA, Sn= p, GENET_DRIVER_SIGNATURE)=0D +#define GENET_PRIVATE_DATA_FROM_AIP_THIS(a) CR(a, GENET_PRIVATE_DATA, Ai= p, GENET_DRIVER_SIGNATURE)=0D =0D #define GENET_RX_BUFFER(g, idx) ((UINT8 *)(UINTN)(g)->RxBuff= er + GENET_MAX_PACKET_SIZE * (idx))=0D =0D diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/AdapterInfo.c b/Silic= on/Broadcom/Drivers/Net/BcmGenetDxe/AdapterInfo.c new file mode 100644 index 000000000000..4b42b2bba67a --- /dev/null +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/AdapterInfo.c @@ -0,0 +1,106 @@ +/** @file=0D +=0D + Copyright (c) 2020 Arm, Limited. All rights reserved.=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#include "BcmGenetDxe.h"=0D +=0D +STATIC=0D +EFI_STATUS=0D +EFIAPI=0D +GenetAipGetInformation (=0D + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,=0D + IN EFI_GUID *InformationType,=0D + OUT VOID **InformationBlock,=0D + OUT UINTN *InformationBlockSize=0D + )=0D +{=0D + EFI_ADAPTER_INFO_MEDIA_STATE *AdapterInfo;=0D + GENET_PRIVATE_DATA *Genet;=0D +=0D + if (This =3D=3D NULL || InformationBlock =3D=3D NULL ||=0D + InformationBlockSize =3D=3D NULL) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (!CompareGuid (InformationType, &gEfiAdapterInfoMediaStateGuid)) {=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + AdapterInfo =3D AllocateZeroPool (sizeof (EFI_ADAPTER_INFO_MEDIA_STATE))= ;=0D + if (AdapterInfo =3D=3D NULL) {=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + *InformationBlock =3D AdapterInfo;=0D + *InformationBlockSize =3D sizeof (EFI_ADAPTER_INFO_MEDIA_STATE);=0D +=0D + Genet =3D GENET_PRIVATE_DATA_FROM_AIP_THIS (This);=0D + AdapterInfo->MediaState =3D GenericPhyUpdateConfig (&Genet->Phy);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +STATIC=0D +EFI_STATUS=0D +EFIAPI=0D +GenetAipSetInformation (=0D + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,=0D + IN EFI_GUID *InformationType,=0D + IN VOID *InformationBlock,=0D + IN UINTN InformationBlockSize=0D + )=0D +{=0D + if (This =3D=3D NULL || InformationBlock =3D=3D NULL) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (CompareGuid (InformationType, &gEfiAdapterInfoMediaStateGuid)) {=0D + return EFI_WRITE_PROTECTED;=0D + }=0D +=0D + return EFI_UNSUPPORTED;=0D +}=0D +=0D +STATIC=0D +EFI_STATUS=0D +EFIAPI=0D +GenetAipGetSupportedTypes (=0D + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This,=0D + OUT EFI_GUID **InfoTypesBuffer,=0D + OUT UINTN *InfoTypesBufferCount=0D + )=0D +{=0D + EFI_GUID *Guid;=0D +=0D + if (This =3D=3D NULL || InfoTypesBuffer =3D=3D NULL ||=0D + InfoTypesBufferCount =3D=3D NULL) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + Guid =3D AllocatePool (sizeof *Guid);=0D + if (Guid =3D=3D NULL) {=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + CopyGuid (Guid, &gEfiAdapterInfoMediaStateGuid);=0D +=0D + *InfoTypesBuffer =3D Guid;=0D + *InfoTypesBufferCount =3D 1;=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +CONST EFI_ADAPTER_INFORMATION_PROTOCOL gGenetAdapterInfoTemplate =3D {=0D + GenetAipGetInformation,=0D + GenetAipSetInformation,=0D + GenetAipGetSupportedTypes,=0D +};=0D diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Sil= icon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index 7f93c68cd608..f9aa006dc799 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -163,6 +163,7 @@ GenetDriverBindingStart ( =0D EfiInitializeLock (&Genet->Lock, TPL_CALLBACK);=0D CopyMem (&Genet->Snp, &gGenetSimpleNetworkTemplate, sizeof Genet->Snp);= =0D + CopyMem (&Genet->Aip, &gGenetAdapterInfoTemplate, sizeof Genet->Aip);=0D =0D Genet->Snp.Mode =3D &Genet->SnpMode;=0D Genet->SnpMode.State =3D EfiSimpleNetworkStopped;=0D @@ -203,7 +204,8 @@ GenetDriverBindingStart ( }=0D =0D Status =3D gBS->InstallMultipleProtocolInterfaces (&ControllerHandle,=0D - &gEfiSimpleNetworkProtocolGuid, &Genet->Snp,=0D + &gEfiSimpleNetworkProtocolGuid, &Genet->Snp,=0D + &gEfiAdapterInformationProtocolGuid, &Genet->Aip,=0D NULL);=0D =0D if (EFI_ERROR (Status)) {=0D @@ -273,10 +275,10 @@ GenetDriverBindingStop ( =0D ASSERT (Genet->ControllerHandle =3D=3D ControllerHandle);=0D =0D - Status =3D gBS->UninstallProtocolInterface (ControllerHandle,=0D - &gEfiSimpleNetworkProtocolGuid= ,=0D - &Genet->Snp=0D - );=0D + Status =3D gBS->UninstallMultipleProtocolInterfaces (ControllerHandle,=0D + &gEfiSimpleNetworkProtocolGuid, &Genet->Snp,=0D + &gEfiAdapterInformationProtocolGuid, &Genet->Aip,=0D + NULL);=0D if (EFI_ERROR (Status)) {=0D return Status;=0D }=0D --=20 2.27.0