From nobody Thu Apr 25 19:41:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61349+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61349+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1592331448; cv=none; d=zohomail.com; s=zohoarc; b=aAxlhUJy9oyJ744OSylDfohpkMTb4Y6RffWoN8fqyrcrUDmag6L4KmzxP82p5M65nY3G4XXJCfFKGS4x4kB2BVBJceY4rwpOyT6yj/8n4/0diQim9bmdCY+P30Zfd1qT0LgBsF9R7NumlJbtSc45N9ZKM5xpeuKRBg0HpRAl8aI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592331448; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=fhCJd9+RElnerr4RgQ68rrUqMCD1gMazvoSzyJE7jmA=; b=SbskQXK76U8WqsK4Y6BQ4HXQe9aq2UV8Mv8ibHhScI16uonyvR/X/qesVbhNFoOUu6GDHkBd7hjkdch0zaNtS87Brb2PsJ/2bi6IEGJzyB+hti7YeSjw4dZidfMus4/reADEjtHDiqKMNTcDwdjoy7XS5tE/tpQFHKqV/qdzy7E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61349+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1592331448704260.204641137762; Tue, 16 Jun 2020 11:17:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MBETYY1788612x1gUiTIPqPJ; Tue, 16 Jun 2020 11:17:26 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.1457.1592331445474659061 for ; Tue, 16 Jun 2020 11:17:25 -0700 X-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 556031FB; Tue, 16 Jun 2020 11:17:24 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.36]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0CCC23F73C; Tue, 16 Jun 2020 11:17:22 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Pete Batard , Andrei Warkentin , Samer El-Haj-Mahmoud Subject: [edk2-devel] [PATCH edk2-platforms] Silicon/Broadcom/BcmGenetDxe: implement media state adapter info protocol Date: Tue, 16 Jun 2020 20:17:12 +0200 Message-Id: <20200616181712.1124353-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: 1MYONMCkmRHGZi9Kph0NHkCcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1592331446; bh=/zfuy9/lT/g040yfT1rJR5Ir8rM5bVIhncBhDVkMDHc=; h=Cc:Date:From:Reply-To:Subject:To; b=vpoDUg1nNFU92SuXEHptaIlxyxXlVztTHr4NpeAFQitb497l1LUBK3fc8Rpmh876EKU xOqlkJGaaCHAe5mgSnefCUhplS3DcLLYtvxOUFES/niFd7ocrGB3uvmJsV9sfoCI5FOmL hteKij5avBDB1hkREzaIvuiN/UPSbTXNuiI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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. Cc: Pete Batard Cc: Andrei Warkentin (awarkentin@vmware.com) Cc: Samer El-Haj-Mahmoud Signed-off-by: Ard Biesheuvel --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 3 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h | 4 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/AdapterInfo.c | 109 +++++++++++= +++++++++ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 12 ++- 4 files changed, 123 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 =20 [Sources] + AdapterInfo.c BcmGenetDxe.h ComponentName.c DriverBinding.c @@ -49,10 +50,12 @@ [LibraryClasses] =20 [Protocols] gBcmGenetPlatformDeviceProtocolGuid ## TO_START + gEfiAdapterInformationProtocolGuid ## BY_START gEfiDevicePathProtocolGuid ## BY_START gEfiSimpleNetworkProtocolGuid ## BY_START =20 [Guids] + gEfiAdapterInfoMediaStateGuid gEfiEventExitBootServicesGuid =20 [FixedPcd] diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h b/Silic= on/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h index 0af9d5209cf2..48bb8550426f 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -209,6 +210,8 @@ typedef struct { EFI_SIMPLE_NETWORK_PROTOCOL Snp; EFI_SIMPLE_NETWORK_MODE SnpMode; =20 + EFI_ADAPTER_INFORMATION_PROTOCOL Aip; + BCM_GENET_PLATFORM_DEVICE_PROTOCOL *Dev; =20 GENERIC_PHY_PRIVATE_DATA Phy; @@ -234,6 +237,7 @@ extern EFI_COMPONENT_NAME_PROTOCOL gGenetCom= ponentName; extern EFI_COMPONENT_NAME2_PROTOCOL gGenetComponentName2; =20 extern CONST EFI_SIMPLE_NETWORK_PROTOCOL gGenetSimpleNetworkTemplate; +extern CONST EFI_ADAPTER_INFORMATION_PROTOCOL gGenetAdapterInfoTemplate; =20 #define GENET_DRIVER_SIGNATURE SIGNATURE_32('G', 'N', 'E', = 'T') #define GENET_PRIVATE_DATA_FROM_SNP_THIS(a) CR(a, GENET_PRIVATE_DATA, Sn= p, GENET_DRIVER_SIGNATURE) 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..cb7733bbba76 --- /dev/null +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/AdapterInfo.c @@ -0,0 +1,109 @@ +/** @file + + Copyright (c) 2020 Arm, Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +#include "BcmGenetDxe.h" + +STATIC +EFI_STATUS +EFIAPI +GenetAipGetInformation ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + IN EFI_GUID *InformationType, + OUT VOID **InformationBlock, + OUT UINTN *InformationBlockSize + ) +{ + EFI_ADAPTER_INFO_MEDIA_STATE *AdapterInfo; + GENET_PRIVATE_DATA *Genet; + + if (This =3D=3D NULL || InformationBlock =3D=3D NULL || + InformationBlockSize =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (!CompareGuid (InformationType, &gEfiAdapterInfoMediaStateGuid)) { + return EFI_UNSUPPORTED; + } + + AdapterInfo =3D AllocateZeroPool (sizeof (EFI_ADAPTER_INFO_MEDIA_STATE)); + if (AdapterInfo =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + *InformationBlock =3D AdapterInfo; + *InformationBlockSize =3D sizeof (EFI_ADAPTER_INFO_MEDIA_STATE); + + Genet =3D GENET_PRIVATE_DATA_FROM_SNP_THIS (This); + if (Genet->Snp.Mode->MediaPresent) { + AdapterInfo->MediaState =3D EFI_SUCCESS; + } else { + AdapterInfo->MediaState =3D EFI_NOT_READY; + } + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +EFIAPI +GenetAipSetInformation ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN VOID *InformationBlock, + IN UINTN InformationBlockSize + ) +{ + if (This =3D=3D NULL || InformationBlock =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (CompareGuid (InformationType, &gEfiAdapterInfoMediaStateGuid)) { + return EFI_WRITE_PROTECTED; + } + + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +GenetAipGetSupportedTypes ( + IN EFI_ADAPTER_INFORMATION_PROTOCOL *This, + OUT EFI_GUID **InfoTypesBuffer, + OUT UINTN *InfoTypesBufferCount + ) +{ + EFI_GUID *Guid; + + if (This =3D=3D NULL || InfoTypesBuffer =3D=3D NULL || + InfoTypesBufferCount =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Guid =3D AllocatePool (sizeof *Guid); + if (Guid =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyGuid (Guid, &gEfiAdapterInfoMediaStateGuid); + + *InfoTypesBuffer =3D Guid; + *InfoTypesBufferCount =3D 1; + + return EFI_SUCCESS; +} + +CONST EFI_ADAPTER_INFORMATION_PROTOCOL gGenetAdapterInfoTemplate =3D { + GenetAipGetInformation, + GenetAipSetInformation, + GenetAipGetSupportedTypes, +}; 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 ( =20 EfiInitializeLock (&Genet->Lock, TPL_CALLBACK); CopyMem (&Genet->Snp, &gGenetSimpleNetworkTemplate, sizeof Genet->Snp); + CopyMem (&Genet->Aip, &gGenetAdapterInfoTemplate, sizeof Genet->Aip); =20 Genet->Snp.Mode =3D &Genet->SnpMode; Genet->SnpMode.State =3D EfiSimpleNetworkStopped; @@ -203,7 +204,8 @@ GenetDriverBindingStart ( } =20 Status =3D gBS->InstallMultipleProtocolInterfaces (&ControllerHandle, - &gEfiSimpleNetworkProtocolGuid, &Genet->Snp, + &gEfiSimpleNetworkProtocolGuid, &Genet->Snp, + &gEfiAdapterInformationProtocolGuid, &Genet->Aip, NULL); =20 if (EFI_ERROR (Status)) { @@ -273,10 +275,10 @@ GenetDriverBindingStop ( =20 ASSERT (Genet->ControllerHandle =3D=3D ControllerHandle); =20 - Status =3D gBS->UninstallProtocolInterface (ControllerHandle, - &gEfiSimpleNetworkProtocolGuid, - &Genet->Snp - ); + Status =3D gBS->UninstallMultipleProtocolInterfaces (ControllerHandle, + &gEfiSimpleNetworkProtocolGuid, &Genet->Snp, + &gEfiAdapterInformationProtocolGuid, &Genet->Aip, + NULL); if (EFI_ERROR (Status)) { return Status; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61349): https://edk2.groups.io/g/devel/message/61349 Mute This Topic: https://groups.io/mt/74922265/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-