From nobody Fri Apr 26 14:02:30 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+61435+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+61435+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1592417713; cv=none; d=zohomail.com; s=zohoarc; b=eW7mvxSoGOdaIXotFJ4D47s2t+pyUL5fxznvvBb+N8ZCvC3UQGPtg/6zBeoMK/wW7uARrxJOF2t3IZU8D5WPAw28yMMinaYoU2m1T0MdXZJMc2MxZFeJQ9KUAIRU633/1yCazAf3KRHfKsFFUrS/GvW0pyeOjXy5VGNCxnNQfLU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592417713; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=C5LLRwcLBInQAXFMkkTBL/71cedLx9o+Z+OZbHUA7nM=; b=C/wZTagCPWDUqFpDCHKZB25AcGEJbb6y6W6IBwEANToazqLZvjqwiZFr8+2suHAU9FqRjahvNosGOR5Om4WYMBtgqEt6WtW8nEsuwhdD2zbjAnxC9jflicuxLxxYXk5gNZsNbPFMGzQPSZvPxsz9ClqHt1AOGPHhGuB+yevEMis= 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+61435+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1592417712946977.9013117678307; Wed, 17 Jun 2020 11:15:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id yob5YY1788612xf80PDVVFAp; Wed, 17 Jun 2020 11:15:11 -0700 X-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 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 A33DE1045; Wed, 17 Jun 2020 11:15:08 -0700 (PDT) X-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: [edk2-devel] [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> 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: UIsB1NsiTSA57DjwjM4jjecox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1592417711; bh=bHu4unNZ/rsmDvVsZYIRKNQyCrpKlkZSbm3Lj2cJWjo=; h=Cc:Date:From:Reply-To:Subject:To; b=vtj5e8CmbU6D+LedHckQ8vbGOFLzFeTl1W+kFyh/upaMOzQiOpARFesiHb7PxMoL692 Y/EKXy/qOTc677RWQKXdw89lpDLUF3yEwmVBGcUpq4gBtU5dI3xDuA4+361BooU6r7VUt bbuky7nJjd7QAiiiMTbViDJfhFtGb2nu2w8= 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 Reviewed-by: Samer El-Haj-Mahmoud --- v2: - use the correct accessor to retrieve the GENET_PRIVATE_DATA pointer - call into the PHY routines to get the state, to ensure it is not stale 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 =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..1a117b25f87f 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,9 +237,11 @@ extern EFI_COMPONENT_NAME_PROTOCOL gGenetCo= mponentName; 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) +#define GENET_PRIVATE_DATA_FROM_AIP_THIS(a) CR(a, GENET_PRIVATE_DATA, Ai= p, GENET_DRIVER_SIGNATURE) =20 #define GENET_RX_BUFFER(g, idx) ((UINT8 *)(UINTN)(g)->RxBuff= er + GENET_MAX_PACKET_SIZE * (idx)) =20 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 + + 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_AIP_THIS (This); + AdapterInfo->MediaState =3D GenericPhyUpdateConfig (&Genet->Phy); + + 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 (#61435): https://edk2.groups.io/g/devel/message/61435 Mute This Topic: https://groups.io/mt/74943379/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-