From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: tzy.way.ooi@intel.com) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by groups.io with SMTP; Wed, 03 Jul 2019 23:17:31 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jul 2019 23:17:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,449,1557212400"; d="scan'208";a="187487469" Received: from kmsmsx157.gar.corp.intel.com ([172.21.138.134]) by fmsmga004.fm.intel.com with ESMTP; 03 Jul 2019 23:17:26 -0700 Received: from pgsmsx109.gar.corp.intel.com ([169.254.14.91]) by kmsmsx157.gar.corp.intel.com ([169.254.5.204]) with mapi id 14.03.0439.000; Thu, 4 Jul 2019 14:17:25 +0800 From: "Ooi, Tzy Way" To: "devel@edk2.groups.io" , "leif.lindholm@linaro.org" CC: Ard BieSheuvel , "Kinney, Michael D" , "Loh, Tien Hock" Subject: Re: [edk2-devel] [PATCH v5 edk2-platforms 1/1] Silicon/DesignWare/Driver: DwEmacSnpDxe: Add DesignWare EMAC driver Thread-Topic: [edk2-devel] [PATCH v5 edk2-platforms 1/1] Silicon/DesignWare/Driver: DwEmacSnpDxe: Add DesignWare EMAC driver Thread-Index: AQHVL+rQTkXLudbDtEqOSTbDI9IAraa40EsAgAErEUA= Date: Thu, 4 Jul 2019 06:17:25 +0000 Message-ID: <5F1105621EDF844291AF8B109E27C06D34D28B03@PGSMSX109.gar.corp.intel.com> References: <20190701085517.2587-1-tzy.way.ooi@intel.com> <20190703200846.eedetm6chvzt2zfv@bivouac.eciton.net> In-Reply-To: <20190703200846.eedetm6chvzt2zfv@bivouac.eciton.net> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMDY0ZWQwMGMtNDc5Yy00NTdhLTk1OWMtNThmNGViNGFkZGMxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiYUF1TXo3a1Z0d0QrTlwvTTd1THlWYjIraEtETWxiRHBXSTJiM2tcLzBtNzdyR281KzBwMjBEQ0RXWVRoV21PYWk0In0= x-originating-ip: [172.30.20.206] MIME-Version: 1.0 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Leif, Thank you for reviewing the source code. I will change the source code acc= ording to the comment. I would like to confirm with you about my understand= ing about the comment as shown below: =3D=3D 1 =3D=3D >>- Use recent version for EDK2 specific file formats >This does not appear to be the case. Have you sent out the correct revision? Tzy Way: Sorry, this is my fault. I misunderstand Ard's comment. I thought= I should change the format to 1.xx instead of using 0xXXXXXXX to become re= cent format. May I confirm with you the recent version is 1.27? =3D=3D 2 =3D=3D > +// Libraries used by this driver > +#include > +#include > +#include > +#include > +#include > +#include > +#include >I get the impression both here and from the .c files below that these >include all the headers required by the .c files, as opposed to the >ones required for definitions in here. >That hides useful information when looking through the source code. >Please include in .h files only the headers required for definitions, >and let the .c files declare their own includes. >(This applies to all .h files in this patch.) Tzy Way: The above include files are needed by the file DwEmacSnpDxe.c. So= rry that I couldn't get what you are trying to explain. Would you mind to e= xplain it to me again? Do you mean I should place the library include to .c= file?=20 =3D=3D 3 =3D=3D > +typedef struct { > + UINT32 Tdes0; > + UINT32 Tdes1; > + UINT32 Addr; =A0 >32-bit addresses? Is this a hardware limitation? This could be >problematic on some platforms. Tzy Way: The Addr is refer to the buffer address. According to the user gu= ide for the EMAC controller, it is stated as 32 bits. Hence, it is coded as= 32 bit addresses. Is it ok to maintain it? =3D=3D 4 =3D=3D >Also, PHY_DXE is too generic an include guard. >Please add DW_EMAC_ or something to prevent accidental future clashes. Tzy Way: Is it ok if I named it as KSZ9031_PHY_DXE? =3D=3D 5 =3D=3D > + Status =3D DmaAllocateBuffer (EfiBootServicesData, > + EFI_SIZE_TO_PAGES (sizeof (DESIGNWARE_HW_DESCRIPTOR)), (VO= ID*)&Snp->MacDriver.TxdescRing[Index]); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a () for TxdescRing: %r\n", __FUNCTION__, St= atus)); > + return Status Please indent whole block. Tzy Way: May I confirm with you where indent whole block means I should ch= ange to the format as shown below: Status =3D DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (siz= eof (DESIGNWARE_HW_DESCRIPTOR)),=20 (VOID*)&Snp->MacDriver= .TxdescRing[Index]); Thank you Best regards, Tzy Way -----Original Message----- From: devel@edk2.groups.io On Behalf Of Leif Lindho= lm Sent: Thursday, July 4, 2019 4:09 AM To: Ooi, Tzy Way Cc: devel@edk2.groups.io; Ard BieSheuvel ; Kinn= ey, Michael D ; Loh, Tien Hock Subject: Re: [edk2-devel] [PATCH v5 edk2-platforms 1/1] Silicon/DesignWare= /Driver: DwEmacSnpDxe: Add DesignWare EMAC driver Hi Tzy Way, Ard is away for an extended holiday, so I'll take over the review of this driver. (This probably means I'll nitpick on a few things Ard didn't - sorry.) On Mon, Jul 01, 2019 at 04:55:17PM +0800, tzy.way.ooi@intel.com wrote: > From: Ooi Tzy Way >=20 > Add driver support for the Ethernet MAC based on Synopsys DesignWare > 3504-0 Universal 10/100/1000 Ethernet MAC and KSZ9031 PHY >=20 > Cc: Ard BieSheuvel > Cc: Leif Lindholm > Cc: Michael D Kinney > Cc: Loh Tien Hock >=20 > Contributed-under: Tianocore Contribution Agreement 1.1 > Signed-off-by: Ooi Tzy Way >=20 > --- > v5: > - Use recent version for EDK2 specific file formats This does not appear to be the case. Have you sent out the correct revision? > - Removed base address which specified via a PCD > - Removed header files which are not needed > - Removed EFI_prefix for local data structures > - Added base address to driver struct > - Clean up the indentation > - Map ordinary buffers for TX and RX buffers > - Added comment on the operation as per requested > --- > --- > Silicon/DesignWare/DesignWare.dec | 30 + Hmm... It's a bit late in the game to suggest changing directory layout, but we generally tend to name the subdirectory of Silicon/Platform after the organisation, not the product line. So arguably, this should be Silicon/Synopsys/DesignWare. Secondly, could you also add a DesignWare.dsc that lets us build this driver without manually adding it to a platform? (I would recommend starting from something simple like Silicon/Openmoko/Openmoko.dsc and add library resolutions as required. > Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.inf | 72 ++ > Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.h | 220 ++++ > Silicon/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.h | 383 ++++++ > Silicon/DesignWare/Drivers/DwEmacSnpDxe/PhyDxeUtil.h | 333 +++++ > Silicon/DesignWare/Drivers/DwEmacSnpDxe/ComponentName.c | 327 +++++ > Silicon/DesignWare/Drivers/DwEmacSnpDxe/DriverBinding.c | 372 ++++++ > Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.c | 1275 +++++++= +++++++++++++ > Silicon/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.c | 683 +++++++= ++++ > Silicon/DesignWare/Drivers/DwEmacSnpDxe/PhyDxeUtil.c | 699 +++++++= ++++ > 10 files changed, 4394 insertions(+) >=20 > diff --git a/Silicon/DesignWare/DesignWare.dec b/Silicon/DesignWare/Desi= gnWare.dec > new file mode 100755 > index 000000000000..909b4bd2733c > --- /dev/null > +++ b/Silicon/DesignWare/DesignWare.dec > @@ -0,0 +1,30 @@ > + #Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > + #This program and the accompanying materials > + #are licensed and made available under the terms and conditions of th= e BSD License > + #which accompanies this distribution. The full text of the license m= ay be found at > + #http://opensource.org/licenses/bsd-license.php > + #THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS= , > + #WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR= IMPLIED. We have fully transitioned from 2-Clause BSD to 2-Clause BSD Plus Patent license. Please replace all but the Copyright line with=20 SPDX-License-Identifier: BSD-2-Clause-Patent > + > +[Defines] > + DEC_SPECIFICATION =3D 1.05 The current version is 1.27. > + PACKAGE_NAME =3D DesignWarePkg > + PACKAGE_GUID =3D 3b5936d8-c72d-412d-b4d9-3bf0dea735= 98 > + PACKAGE_VERSION =3D 0.1 > + > +#######################################################################= ######### > +# > +# Include Section - list of Include Paths that are provided by this pac= kage. > +# Comments are used for Keywords and Module Types. > +# > +# Supported Module Types: > +# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SM= M_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION > +# > +#######################################################################= ######### > + > +[Guids.common] > + gDesignWareTokenSpaceGuid =3D { 0x89cb1241, 0xd283, 0x4543, { 0x88, 0= x9c, 0x6b, 0x62, 0x36, 0x1a, 0x95, 0x7a } } > + gDwEmacNetNonDiscoverableDeviceGuid =3D { 0x401950CD, 0xF9CD, 0x4A65,= { 0xAD, 0x8E, 0x84, 0x9F, 0x3B, 0xAF, 0x23, 0x04 } } > + > + > + > diff --git a/Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.inf b/= Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.inf > new file mode 100755 > index 000000000000..f67b4ca13c67 > --- /dev/null > +++ b/Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.inf > @@ -0,0 +1,72 @@ > +#/** @file > +# DW Emac Simple Networking Protocol Driver (SNP) DXE Driver > +# > +# Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > +# This program and the accompanying materials > +# are licensed and made available under the terms and conditions of th= e BSD License > +# which accompanies this distribution. The full text of the license m= ay be found at > +# http://opensource.org/licenses/bsd-license.php > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS= , > +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR= IMPLIED. > +# > +# The original software modules are licensed as follows: > +# > +# Copyright (c) 2012-2014, ARM Limited. All rights reserved. > +# > +# This program and the accompanying materials > +# are licensed and made available under the terms and conditions of th= e BSD License > +# which accompanies this distribution. The full text of the license m= ay be found at > +# http://opensource.org/licenses/bsd-license.php > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS= , > +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR= IMPLIED. Above are two different statements of using the 2-Clause BSD license. Please replace both with the same SPDX stanza as above, keeping the two Copyright lines above it. (The same change is already applied to EmbeddedPkg/Drivers/Lan9118Dxe/) > +# > +#**/ > +[Defines] > + INF_VERSION =3D 1.05 Current is 1.27. > + BASE_NAME =3D DwEmacSnpDxe > + FILE_GUID =3D 06f3315f-9fe6-4938-b83f-2c072af802= ba > + MODULE_TYPE =3D UEFI_DRIVER > + VERSION_STRING =3D 0.1 > + ENTRY_POINT =3D DwEmacSnpDxeEntry > + > +[Sources.common] > + ComponentName.c > + DriverBinding.c > + DwEmacSnpDxe.c > + EmacDxeUtil.c > + PhyDxeUtil.c > + DwEmacSnpDxe.h > + EmacDxeUtil.h > + PhyDxeUtil.h > + > +[Packages] > + EmbeddedPkg/EmbeddedPkg.dec > + NetworkPkg/NetworkPkg.dec > + MdeModulePkg/MdeModulePkg.dec > + MdePkg/MdePkg.dec > + Silicon/DesignWare/DesignWare.dec > + > +[LibraryClasses] > + BaseLib > + UefiLib > + NetLib > + UefiDriverEntryPoint > + BaseMemoryLib > + IoLib > + TimerLib > + DevicePathLib > + DebugLib > + DmaLib Please sort the above library classes alphabetically. > + > +[Protocols] > + gEfiSimpleNetworkProtocolGuid > + gEfiMetronomeArchProtocolGuid > + gEfiPxeBaseCodeProtocolGuid Is gEfiPxeBaseCodeProtocolGuid used by this driver? I can't spot a reference (and I wouldn't have thought it necessary for an SNP driver). > + gEfiDevicePathProtocolGuid > + gEfiDriverBindingProtocolGuid > + gEdkiiNonDiscoverableDeviceProtocolGuid Please sort the above protocols alphabetically. > + > +[Guids] > + gDwEmacNetNonDiscoverableDeviceGuid ## TO_START > + > diff --git a/Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.h b/Si= licon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.h > new file mode 100755 > index 000000000000..4754a5b06689 > --- /dev/null > +++ b/Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.h > @@ -0,0 +1,220 @@ > +/** @file > + > + Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > + > + The original software modules are licensed as follows: > + > + Copyright (c) 2012-2014, ARM Limited. All rights reserved. > + > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD 3 Clause LICENSE ON AN "AS I= S" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. SPDX > +**/ > + > + > +#ifndef __DWEMAC_SNP_DXE_H__ > +#define __DWEMAC_SNP_DXE_H__ Please drop leading __ from include guard (it is reserved for toolchain, and when you crank up the warning levels on clang, it complains). > + > +// Protocols used by this driver > +#include > +#include > +#include Is PxeBaseCode actually used by this driver? > +#include > +#include > + > +// Libraries used by this driver > +#include > +#include > +#include > +#include > +#include > +#include > +#include I get the impression both here and from the .c files below that these include all the headers required by the .c files, as opposed to the ones required for definitions in here. That hides useful information when looking through the source code. Please include in .h files only the headers required for definitions, and let the .c files declare their own includes. (This applies to all .h files in this patch.) > + > +#include "PhyDxeUtil.h" > +#include "EmacDxeUtil.h" > + > +/*---------------------------------------------------------------------= --------- > + Information Structure > +-----------------------------------------------------------------------= -------*/ > + > +typedef struct { > + MAC_ADDR_DEVICE_PATH MacAddrDP; > + EFI_DEVICE_PATH_PROTOCOL End; > +} SIMPLE_NETWORK_DEVICE_PATH; > + > +typedef struct { > + // Driver signature > + UINT32 Signature; > + EFI_HANDLE ControllerHandle; > + > + // EFI SNP protocol instances > + EFI_SIMPLE_NETWORK_PROTOCOL Snp; > + EFI_SIMPLE_NETWORK_MODE SnpMode; > + > + // EFI Snp statistics instance > + EFI_NETWORK_STATISTICS Stats; > + > + EMAC_DRIVER MacDriver; > + PHY_DRIVER PhyDriver; > + > + NON_DISCOVERABLE_DEVICE *Dev; > + > + EFI_LOCK Lock; > + > + UINTN MacBase; > + > + // Array of the recycled transmit buffer address=20 > + UINT64 *RecycledTxBuf; > + > + // The maximum number of recycled buffer pointers in RecycledTxBuf. > + UINT32 MaxRecycledTxBuf; > + > + // Current number of recycled buffer pointers in RecycledTxBuf. > + UINT32 RecycledTxBufCount; > + > + // For TX buffer DmaUnmap=20 > + VOID *MappingTxbuf; > + > +} SIMPLE_NETWORK_DRIVER; > + > +extern EFI_COMPONENT_NAME_PROTOCOL gSnpComponentName; > +extern EFI_COMPONENT_NAME2_PROTOCOL gSnpComponentName2; > + > +#define SNP_DRIVER_SIGNATURE SIGNATURE_32('A', 'S', 'N', 'P= ') > +#define INSTANCE_FROM_SNP_THIS(a) CR(a, SIMPLE_NETWORK_DRIVER, S= np, SNP_DRIVER_SIGNATURE) > +#define SNP_TX_BUFFER_INCREASE 32 > +#define SNP_MAX_TX_BUFFER_NUM 65536 > +#define DESC_NUM 10 > +#define ETH_BUFSIZE 0x800 > +/*---------------------------------------------------------------------= ------------------------------------------------ > + > + UEFI-Compliant functions for EFI_SIMPLE_NETWORK_PROTOCOL > + > + Refer to the Simple Network Protocol section (21.1) in the UEFI 2.3.1= Specification for related definitions Worth updating the comment to match the current specification version and chapter? > + > +-----------------------------------------------------------------------= ----------------------------------------------*/ > + > +EFI_STATUS > +EFIAPI > +SnpStart ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp > + ); > + > +EFI_STATUS > +EFIAPI > +SnpStop ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp > + ); > + > +EFI_STATUS > +EFIAPI > +SnpInitialize ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + IN UINTN ExtraRxBufferSize OPTIONAL, > + IN UINTN ExtraTxBufferSize OPTIONAL > + ); > + > +EFI_STATUS > +EFIAPI > +SnpReset ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + IN BOOLEAN ExtendedVerification > + ); > + > +EFI_STATUS > +EFIAPI > +SnpShutdown ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp > + ); > + > +EFI_STATUS > +EFIAPI > +SnpReceiveFilters ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + IN UINT32 Enable, > + IN UINT32 Disable, > + IN BOOLEAN ResetMCastFilter, > + IN UINTN MCastFilterCnt OPTIONAL, > + IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL > + ); > + > +EFI_STATUS > +EFIAPI > +SnpStationAddress ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + IN BOOLEAN Reset, > + IN EFI_MAC_ADDRESS *NewMac > +); > + > +EFI_STATUS > +EFIAPI > +SnpStatistics ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + IN BOOLEAN Reset, > + IN OUT UINTN *StatSize, > + OUT EFI_NETWORK_STATISTICS *Statistics > + ); > + > +EFI_STATUS > +EFIAPI > +SnpMcastIptoMac ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + IN BOOLEAN IsIpv6, > + IN EFI_IP_ADDRESS *Ip, > + OUT EFI_MAC_ADDRESS *McastMac > + ); > + > +EFI_STATUS > +EFIAPI > +SnpNvData ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + IN BOOLEAN ReadWrite, > + IN UINTN Offset, > + IN UINTN BufferSize, > + IN OUT VOID *Buffer > + ); > + > +EFI_STATUS > +EFIAPI > +SnpGetStatus ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + OUT UINT32 *IrqStat OPTIONAL, > + OUT VOID **TxBuff OPTIONAL > + ); > + > +EFI_STATUS > +EFIAPI > +SnpTransmit ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + IN UINTN HdrSize, > + IN UINTN BuffSize, > + IN VOID *Data, > + IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL, > + IN EFI_MAC_ADDRESS *DstAddr OPTIONAL, > + IN UINT16 *Protocol OPTIONAL > + ); > + > +EFI_STATUS > +EFIAPI > +SnpReceive ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp, > + OUT UINTN *HdrSize OPTIONAL, > + IN OUT UINTN *BuffSize, > + OUT VOID *Data, > + OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL, > + OUT EFI_MAC_ADDRESS *DstAddr OPTIONAL, > + OUT UINT16 *Protocol OPTIONAL > + ); > + > +#endif // __DWEMAC_SNP_DXE_H__ > diff --git a/Silicon/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.h b/Sil= icon/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.h > new file mode 100755 > index 000000000000..33195335cdde > --- /dev/null > +++ b/Silicon/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.h > @@ -0,0 +1,383 @@ > +/** @file > + > + Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > + > + The original software modules are licensed as follows: > + > + Copyright (c) 2008 - 2009, Apple Inc. All rights reserved. > + Copyright (c) 2011 - 2014, ARM Limited. All rights reserved. > + > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD 3 Clause LICENSE ON AN "AS I= S" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > +**/ SPDX > + > + > +#ifndef __EMAC_DXE_UTIL_H__ > +#define __EMAC_DXE_UTIL_H__ Drop leading __. > + > +#include > +#include > +#include > +#include > +#include > + > +// Protocols used by this driver > +#include > +#include > +#include > +#include > + > +// Most common CRC32 Polynomial for little endian machines > +#define CRC_POLYNOMIAL 0xEDB= 88320 > +#define HASH_TABLE_REG(n) 0x500= + (0x4 * n) > +#define RX_MAX_PACKET 1600 > + > +#define CONFIG_ETH_BUFSIZE 2048 > +#define CONFIG_TX_DESCR_NUM 10 > +#define CONFIG_RX_DESCR_NUM 10 > +#define TX_TOTAL_BUFSIZE (CON= FIG_ETH_BUFSIZE * CONFIG_TX_DESCR_NUM) > +#define RX_TOTAL_BUFSIZE (CON= FIG_ETH_BUFSIZE * CONFIG_RX_DESCR_NUM) > + > +// DMA status error bit > +#define RX_DMA_WRITE_DATA_TRANSFER_ERROR 0x0 > +#define TX_DMA_READ_DATA_TRANSFER_ERROR 0x3 > +#define RX_DMA_DESCRIPTOR_WRITE_ACCESS_ERROR 0x4 > +#define TX_DMA_DESCRIPTOR_WRITE_ACCESS_ERROR 0x5 > +#define RX_DMA_DESCRIPTOR_READ_ACCESS_ERROR 0x6 > +#define TX_DMA_DESCRIPTOR_READ_ACCESS_ERROR 0x7 > + > +// tx descriptor > +#define TDES0_OWN BIT3= 1 > +#define TDES0_TXINT BIT3= 0 > +#define TDES0_TXLAST BIT2= 9 > +#define TDES0_TXFIRST BIT2= 8 > +#define TDES0_TXCRCDIS BIT2= 7 > +#define TDES0_TXRINGEND BIT2= 1 > +#define TDES0_TXCHAIN BIT2= 0 > + > +#define TDES1_SIZE1MASK (0x1= FFF << 0) > +#define TDES1_SIZE1SHFT (0) > +#define TDES1_SIZE2MASK (0x1= FFF << 16) > +#define TDES1_SIZE2SHFT (16) > + > +// rx descriptor > +#define RDES0_FL_MASK 0x3= fff > +#define RDES0_FL_SHIFT 16 > +#define RDES1_CHAINED BIT= 14 > + > +#define RDES0_CE BIT= 1 > +#define RDES0_DBE BIT= 2 > +#define RDES0_RE BIT= 3 > +#define RDES0_RWT BIT= 4 > +#define RDES0_LC BIT= 6 > +#define RDES0_GF BIT= 7 > +#define RDES0_OE BIT= 11 > +#define RDES0_LE BIT= 12 > +#define RDES0_SAF BIT= 13 > +#define RDES0_DE BIT= 14 > +#define RDES0_ES BIT= 15 > +#define RDES0_AFM BIT= 30 > +#define RDES0_OWN BIT= 31 > + > + > +// emac config phy interface setting > +#define PHY_INTERFACE_MODE_GMII 0 > +#define PHY_INTERFACE_MODE_MII 1 > +#define PHY_INTERFACE_MODE_RGMII 2 > +#define PHY_INTERFACE_MODE_RMII 3 > + > +// DW emac mask > +#define DW_EMAC_DMAGRP_BUS_MODE_SWR_SET_MSK 0x0= 0000001 > +#define DW_EMAC_DMAGRP_BUS_MODE_FB_SET_MSK 0x0= 0010000 > +#define DW_EMAC_DMAGRP_BUS_MODE_PBL_SET_MSK 0x0= 0003f00 > +#define DW_EMAC_DMAGRP_BUS_MODE_PR_SET_MSK 0x0= 000c000 > +#define DW_EMAC_DMAGRP_OPERATION_MODE_FTF_SET_MSK 0x0= 0100000 > +#define DW_EMAC_DMAGRP_OPERATION_MODE_TSF_SET_MSK 0x0= 0200000 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_TIE_SET_MSK 0x0= 0000001 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_RIE_SET_MSK 0x0= 0000040 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_NIE_SET_MSK 0x0= 0010000 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_AIE_SET_MSK 0x0= 0008000 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_FBE_SET_MSK 0x0= 0002000 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_UNE_SET_MSK 0x0= 0000020 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_TSE_SET_MSK 0x0= 0000002 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_TUE_SET_MSK 0x0= 0000004 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_TJE_SET_MSK 0x0= 0000008 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_OVE_SET_MSK 0x0= 0000010 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_RUE_SET_MSK 0x0= 0000080 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_RSE_SET_MSK 0x0= 0000100 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_RWE_SET_MSK 0x0= 0000200 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_ETE_SET_MSK 0x0= 0000400 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_ERE_SET_MSK 0x0= 0004000 > +#define DW_EMAC_DMAGRP_OPERATION_MODE_ST_SET_MSK 0x0= 0002000 > +#define DW_EMAC_DMAGRP_OPERATION_MODE_SR_SET_MSK 0x0= 0000002 > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_RE_SET_MSK 0x0= 0000004 > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_TE_SET_MSK 0x0= 0000008 > +#define DW_EMAC_GMACGRP_MAC_FRAME_FILTER_RESET 0x0= 0000000 > +#define DW_EMAC_GMACGRP_MAC_FRAME_FILTER_HMC_SET_MSK 0x0= 0000004 > +#define DW_EMAC_GMACGRP_MAC_FRAME_FILTER_DBF_SET_MSK 0x0= 0000020 > +#define DW_EMAC_GMACGRP_MAC_FRAME_FILTER_PR_SET_MSK 0x0= 0000001 > +#define DW_EMAC_GMACGRP_MAC_FRAME_FILTER_PM_SET_MSK 0x0= 0000010 > +#define DW_EMAC_DMAGRP_OPERATION_MODE_ST_CLR_MSK 0xf= fffdfff > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_RE_CLR_MSK 0xf= ffffffb > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_TE_CLR_MSK 0xf= ffffff7 > +#define DW_EMAC_DMAGRP_OPERATION_MODE_SR_CLR_MSK 0xf= ffffffd > +#define DW_EMAC_DMAGRP_STATUS_NIS_SET_MSK 0x0= 0010000 > +#define DW_EMAC_DMAGRP_STATUS_RI_SET_MSK 0x0= 0000040 > +#define DW_EMAC_DMAGRP_STATUS_TI_SET_MSK 0x0= 0000001 > +#define DW_EMAC_DMAGRP_STATUS_TU_SET_MSK 0x0= 0000004 > +#define DW_EMAC_DMAGRP_STATUS_ERI_SET_MSK 0x0= 0004000 > +#define DW_EMAC_DMAGRP_STATUS_AIS_SET_MSK 0x0= 0008000 > +#define DW_EMAC_DMAGRP_STATUS_TPS_SET_MSK 0x0= 0000002 > +#define DW_EMAC_DMAGRP_STATUS_TJT_SET_MSK 0x0= 0000008 > +#define DW_EMAC_DMAGRP_STATUS_OVF_SET_MSK 0x0= 0000010 > +#define DW_EMAC_DMAGRP_STATUS_UNF_SET_MSK 0x0= 0000020 > +#define DW_EMAC_DMAGRP_STATUS_RU_SET_MSK 0x0= 0000080 > +#define DW_EMAC_DMAGRP_STATUS_RPS_SET_MSK 0x0= 0000100 > +#define DW_EMAC_DMAGRP_STATUS_RWT_SET_MSK 0x0= 0000200 > +#define DW_EMAC_DMAGRP_STATUS_ETI_SET_MSK 0x0= 0000400 > +#define DW_EMAC_DMAGRP_STATUS_FBI_SET_MSK 0x0= 0002000 > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_PS_SET_MSK 0x0= 0008000 > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_FES_SET_MSK 0x0= 0004000 > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_DM_SET_MSK 0x0= 0000800 > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_BE_SET_MSK 0x0= 0200000 > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_DO_SET_MSK 0x0= 0002000 > + > +#define DW_EMAC_DMAGRP_BUS_MODE_SWR_GET(value) (((= value) & 0x00000001) >> 0) > +#define DW_EMAC_DMAGRP_STATUS_EB_GET(value) (((= value) & 0x03800000) >> 23) > +#define DW_EMAC_GMACGRP_GMII_ADDRESS_GB_GET(value) (((= value) & 0x00000001) >> 0) > +#define DW_EMAC_GMACGRP_GMII_DATA_GD_GET(value) (((= value) & 0x0000ffff) >> 0) > +#define DW_EMAC_DMAGRP_OPERATION_MODE_FTF_GET(value) (((= value) & 0x00100000) >> 20) > + > +// DW emac registers offset > + > +#define DW_EMAC_GMACGRP_MAC_CONFIGURATION_OFST 0x= 000 > +#define DW_EMAC_GMACGRP_MAC_FRAME_FILTER_OFST 0x= 004 > +#define DW_EMAC_GMACGRP_GMII_ADDRESS_OFST 0x= 010 > +#define DW_EMAC_GMACGRP_GMII_DATA_OFST 0x= 014 > +#define DW_EMAC_GMACGRP_FLOW_CONTROL_OFST 0x= 018 > +#define DW_EMAC_GMACGRP_VLAN_TAG_OFST 0x= 01c > +#define DW_EMAC_GMACGRP_VERSION_OFST 0x= 020 > +#define DW_EMAC_GMACGRP_DEBUG_OFST 0x= 024 > +#define DW_EMAC_GMACGRP_LPI_CONTROL_STATUS_OFST 0x= 030 > +#define DW_EMAC_GMACGRP_LPI_TIMERS_CONTROL_OFST 0x= 034 > +#define DW_EMAC_GMACGRP_INTERRUPT_STATUS_OFST 0x= 038 > +#define DW_EMAC_GMACGRP_INTERRUPT_MASK_OFST 0x= 03c > +#define DW_EMAC_GMACGRP_MAC_ADDRESS0_HIGH_OFST 0x= 040 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS0_LOW_OFST 0x= 044 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS1_HIGH_OFST 0x= 048 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS1_LOW_OFST 0x= 04c > +#define DW_EMAC_GMACGRP_MAC_ADDRESS2_HIGH_OFST 0x= 050 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS2_LOW_OFST 0x= 054 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS3_HIGH_OFST 0x= 058 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS3_LOW_OFST 0x= 05c > +#define DW_EMAC_GMACGRP_MAC_ADDRESS4_HIGH_OFST 0x= 060 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS4_LOW_OFST 0x= 064 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS5_HIGH_OFST 0x= 068 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS5_LOW_OFST 0x= 06c > +#define DW_EMAC_GMACGRP_MAC_ADDRESS6_HIGH_OFST 0x= 070 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS6_LOW_OFST 0x= 074 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS7_HIGH_OFST 0x= 078 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS7_LOW_OFST 0x= 07c > +#define DW_EMAC_GMACGRP_MAC_ADDRESS8_HIGH_OFST 0x= 080 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS8_LOW_OFST 0x= 084 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS9_HIGH_OFST 0x= 088 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS9_LOW_OFST 0x= 08c > +#define DW_EMAC_GMACGRP_MAC_ADDRESS10_HIGH_OFST 0x= 090 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS10_LOW_OFST 0x= 094 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS11_HIGH_OFST 0x= 098 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS11_LOW_OFST 0x= 09c > +#define DW_EMAC_GMACGRP_MAC_ADDRESS12_HIGH_OFST 0x= 0a0 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS12_LOW_OFST 0x= 0a4 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS13_HIGH_OFST 0x= 0a8 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS13_LOW_OFST 0x= 0ac > +#define DW_EMAC_GMACGRP_MAC_ADDRESS14_HIGH_OFST 0x= 0b0 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS14_LOW_OFST 0x= 0b4 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS15_HIGH_OFST 0x= 0b8 > +#define DW_EMAC_GMACGRP_MAC_ADDRESS15_LOW_OFST 0x= 0bc > +#define DW_EMAC_GMACGRP_SGMII_RGMII_SMII_CONTROL_STATUS_OFST 0x= 0d8 > +#define DW_EMAC_GMACGRP_WDOG_TIMEOUT_OFST 0x= 0dc > +#define DW_EMAC_GMACGRP_GENPIO_OFST 0x= 0e0 > +#define DW_EMAC_GMACGRP_MMC_CONTROL_OFST 0x= 100 > +#define DW_EMAC_GMACGRP_MMC_RECEIVE_INTERRUPT_OFST 0x= 104 > +#define DW_EMAC_GMACGRP_MMC_TRANSMIT_INTERRUPT_OFST 0x= 108 > +#define DW_EMAC_GMACGRP_MMC_RECEIVE_INTERRUPT_MASK_OFST 0x= 10c > +#define DW_EMAC_GMACGRP_MMC_TRANSMIT_INTERRUPT_MASK_OFST 0x= 110 > +#define DW_EMAC_GMACGRP_TXOCTETCOUNT_GB_OFST 0x= 114 > +#define DW_EMAC_GMACGRP_TXFRAMECOUNT_GB_OFST 0x= 118 > +#define DW_EMAC_GMACGRP_TXBROADCASTFRAMES_G_OFST 0x= 11c > +#define DW_EMAC_GMACGRP_TXMULTICASTFRAMES_G_OFST 0x= 120 > +#define DW_EMAC_GMACGRP_TXUNICASTFRAMES_GB_OFST 0x= 13c > +#define DW_EMAC_GMACGRP_TXLATECOL_OFST 0x= 158 > +#define DW_EMAC_GMACGRP_TXEXESSCOL_OFST 0x= 15c > +#define DW_EMAC_GMACGRP_TXFRAMECOUNT_G_OFST 0x= 168 > +#define DW_EMAC_GMACGRP_TXOVERSIZE_G_OFST 0x= 178 > +#define DW_EMAC_GMACGRP_RXFRAMECOUNT_GB_OFST 0x= 180 > +#define DW_EMAC_GMACGRP_RXOCTETCOUNT_GB_OFST 0x= 184 > +#define DW_EMAC_GMACGRP_RXBROADCASTFRAMES_G_OFST 0x= 18c > +#define DW_EMAC_GMACGRP_RXMULTICASTFRAMES_G_OFST 0x= 190 > +#define DW_EMAC_GMACGRP_RXCRCERROR_OFST 0x= 194 > +#define DW_EMAC_GMACGRP_RXUNDERSIZE_G_OFST 0x= 1a4 > +#define DW_EMAC_GMACGRP_RXOVERSIZE_G_OFST 0x= 1a8 > +#define DW_EMAC_GMACGRP_RXUNICASTFRAMES_G_OFST 0x= 1c4 > +#define DW_EMAC_DMAGRP_BUS_MODE_OFST 0x= 1000 > +#define DW_EMAC_DMAGRP_TRANSMIT_POLL_DEMAND_OFST 0x= 1004 > +#define DW_EMAC_DMAGRP_RECEIVE_POLL_DEMAND_OFST 0x= 1008 > +#define DW_EMAC_DMAGRP_RECEIVE_DESCRIPTOR_LIST_ADDRESS_OFST 0x= 100c > +#define DW_EMAC_DMAGRP_TRANSMIT_DESCRIPTOR_LIST_ADDRESS_OFST 0x= 1010 > +#define DW_EMAC_DMAGRP_STATUS_OFST 0x= 1014 > +#define DW_EMAC_DMAGRP_OPERATION_MODE_OFST 0x= 1018 > +#define DW_EMAC_DMAGRP_INTERRUPT_ENABLE_OFST 0x= 101c > +#define DW_EMAC_DMAGRP_MISSED_FRAME_AND_BUFFER_OVERFLOW_COUNTER_OFST 0x= 1020 > +#define DW_EMAC_DMAGRP_RECEIVE_INTERRUPT_WATCHDOG_TIMER_OFST 0x= 1024 > +#define DW_EMAC_DMAGRP_AXI_BUS_MODE_OFST 0x= 1028 > +#define DW_EMAC_DMAGRP_AHB_OR_AXI_STATUS_OFST 0x= 102c > +#define DW_EMAC_DMAGRP_CURRENT_HOST_TRANSMIT_DESCRIPTOR_OFST 0x= 1048 > +#define DW_EMAC_DMAGRP_CURRENT_HOST_RECEIVE_DESCRIPTOR_OFST 0x= 104c > +#define DW_EMAC_DMAGRP_CURRENT_HOST_TRANSMIT_BUFFER_ADDRESS_OFST 0x= 1050 > +#define DW_EMAC_DMAGRP_CURRENT_HOST_RECEIVE_BUFFER_ADDRESS_OFST 0x= 1054 > +#define DW_EMAC_DMAGRP_HW_FEATURE_OFST 0x= 1058 > + > +typedef struct { > + UINT32 Tdes0; > + UINT32 Tdes1; > + UINT32 Addr; 32-bit addresses? Is this a hardware limitation? This could be problematic on some platforms. > + UINT32 AddrNext; > +} DESIGNWARE_HW_DESCRIPTOR; > + > +typedef struct { > + EFI_PHYSICAL_ADDRESS AddrMap; > + void *Mapping;=20 > +} MAP_INFO; > + > +typedef struct { > + DESIGNWARE_HW_DESCRIPTOR *TxdescRing[CONFIG_TX_DESCR_NUM]; > + DESIGNWARE_HW_DESCRIPTOR *RxdescRing[CONFIG_RX_DESCR_NUM]; > + CHAR8 TxBuffer[TX_TOTAL_BUFSIZE]; > + CHAR8 RxBuffer[RX_TOTAL_BUFSIZE]; > + MAP_INFO TxdescRingMap[CONFIG_TX_DESCR_NUM ]; > + MAP_INFO RxdescRingMap[CONFIG_RX_DESCR_NUM ]; > + MAP_INFO RxBufNum[CONFIG_TX_DESCR_NUM]; > + UINT32 TxCurrentDescriptorNum; > + UINT32 TxNextDescriptorNum; > + UINT32 RxCurrentDescriptorNum; > + UINT32 RxNextDescriptorNum; > +} EMAC_DRIVER; > + > +VOID > +EFIAPI > +EmacSetMacAddress ( > + IN EFI_MAC_ADDRESS *MacAddress, > + IN UINTN MacBaseAddress > + ); > + > +VOID > +EFIAPI > +EmacReadMacAddress ( > + OUT EFI_MAC_ADDRESS *MacAddress, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +EmacDxeInitialization ( > + IN EMAC_DRIVER *EmacDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +EmacDmaInit ( > + IN EMAC_DRIVER *EmacDriver, > + IN UINTN MacBaseAddress > + );=20 > + > +EFI_STATUS > +EFIAPI > +EmacSetupTxdesc ( > + IN EMAC_DRIVER *EmacDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +EmacSetupRxdesc ( > + IN EMAC_DRIVER *EmacDriver, > + IN UINTN MacBaseAddress > + ); > + > +VOID > +EFIAPI > +EmacStartTransmission ( > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +EmacRxFilters ( > + IN UINT32 ReceiveFilterSetting, > + IN BOOLEAN Reset, > + IN UINTN NumMfilter OPTIONAL, > + IN EFI_MAC_ADDRESS *Mfilter OPTIONAL, > + IN UINTN MacBaseAddress > + ); > + > +UINT32 > +EFIAPI > +GenEtherCrc32 ( > + IN EFI_MAC_ADDRESS *Mac, > + IN UINT32 AddrLen > + ); > + > +UINT8 > +EFIAPI > +BitReverse ( > + UINT8 X > + ); > + > +VOID > +EFIAPI > +EmacStopTxRx ( > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +EmacDmaStart ( > + IN UINTN MacBaseAddress > + ); > + > + > +VOID > +EFIAPI > +EmacGetDmaStatus ( > + OUT UINT32 *IrqStat OPTIONAL, > + IN UINTN MacBaseAddress > + ); > + > +VOID > +EFIAPI > +EmacGetStatistic ( > + IN EFI_NETWORK_STATISTICS *Stats, > + IN UINTN MacBaseAddress > + ); > + > +VOID > +EFIAPI > +EmacConfigAdjust ( > + IN UINT32 Speed, > + IN UINT32 Duplex, > + IN UINTN MacBaseAddress > + ); > + > +#endif // __EMAC_DXE_UTIL_H__ > diff --git a/Silicon/DesignWare/Drivers/DwEmacSnpDxe/PhyDxeUtil.h b/Sili= con/DesignWare/Drivers/DwEmacSnpDxe/PhyDxeUtil.h > new file mode 100755 > index 000000000000..94c94ec449c7 > --- /dev/null > +++ b/Silicon/DesignWare/Drivers/DwEmacSnpDxe/PhyDxeUtil.h > @@ -0,0 +1,333 @@ > +/** @file > + > + Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > + > + The original software modules are licensed as follows: > + > + Copyright (c) 2008 - 2009, Apple Inc. All rights reserved. > + Copyright (c) 2011 - 2014, ARM Limited. All rights reserved. > + > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD 3 Clause LICENSE ON AN "AS I= S" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > +**/ SPDX > + > + > +#ifndef __PHY_DXE_H__ > +#define __PHY_DXE_H__ Drop leading __. Also, PHY_DXE is too generic an include guard. Please add DW_EMAC_ or something to prevent accidental future clashes. > + > +#include > + > +typedef struct { > + UINT32 PhyAddr; > + UINT32 PhyCurrentLink; > + UINT32 PhyOldLink; > +} PHY_DRIVER; > + > + > +// > +// PHY Registers > +// > +#define PHY_BASIC_CTRL 0 > +#define PHY_BASIC_STATUS 1 > +#define PHY_ID1 2 > +#define PHY_ID2 3 > +#define PHY_AUTO_NEG_ADVERT 4 > +#define PHY_AUTO_NEG_LINK_ABILITY 5 > +#define PHY_AUTO_NEG_EXP 6 > +#define PHY_1000BASE_T_CONTROL 9 > +#define PHY_1000BASE_T_STATUS 10 The two lines above have tabs in them. Please replace with spaces. In fact, running BaseTools/Scripts/PatchCheck.py on this patch finds quite a few whitespace errors. Please address all of them. > +#define PHY_MODE 17 > +#define PHY_SPECIAL_MODES 18 > +#define PHY_SPECIAL_CTLR 27 > +#define PHY_INT_SRC 29 > +#define PHY_INT_MASK 30 > +#define PHY_SPECIAL_PHY_CTLR 31 > + > +// PHY control register bits > +#define PHYCTRL_COLL_TEST BIT7 // Collis= ion test enable > +#define PHYCTRL_DUPLEX_MODE BIT8 // Set Du= plex Mode > +#define PHYCTRL_RST_AUTO BIT9 // Restar= t Auto-Negotiation of Link abilities > +#define PHYCTRL_PD BIT11 // Power-= Down switch > +#define PHYCTRL_AUTO_EN BIT12 // Auto-N= egotiation Enable > +#define PHYCTRL_SPEED_SEL BIT13 // Link S= peed Selection > +#define PHYCTRL_LOOPBK BIT14 // Set lo= opback mode > +#define PHYCTRL_RESET BIT15 // Do a P= HY reset > + > +// PHY status register bits > +#define PHYSTS_EXT_CAP BIT0 // Extend= ed Capabilities Register capability > +#define PHYSTS_JABBER BIT1 // Jabber= condition detected > +#define PHYSTS_LINK_STS BIT2 // Link S= tatus > +#define PHYSTS_AUTO_CAP BIT3 // Auto-N= egotiation Capability > +#define PHYSTS_REMOTE_FAULT BIT4 // Remote= fault detected > +#define PHYSTS_AUTO_COMP BIT5 // Auto-N= egotiation Completed > +#define PHYSTS_10BASET_HDPLX BIT11 // 10Mbps= Half-Duplex ability > +#define PHYSTS_10BASET_FDPLX BIT12 // 10Mbps= Full-Duplex ability > +#define PHYSTS_100BASETX_HDPLX BIT13 // 100Mbp= s Half-Duplex ability > +#define PHYSTS_100BASETX_FDPLX BIT14 // 100Mbp= s Full-Duplex ability > +#define PHYSTS_100BASE_T4 BIT15 // Base T= 4 ability > + > +// PHY Auto-Negotiation advertisement > +#define PHYANA_SEL_MASK ((UINT32)0x1F) // Link = type selector > +#define PHYANA_10BASET BIT5 // Adver= tise 10BASET capability > +#define PHYANA_10BASETFD BIT6 // Adver= tise 10BASET Full duplex capability > +#define PHYANA_100BASETX BIT7 // Adver= tise 100BASETX capability > +#define PHYANA_100BASETXFD BIT8 // Adver= tise 100 BASETX Full duplex capability > +#define PHYANA_PAUSE_OP_MASK (3 << 10) // Adver= tise PAUSE frame capability > +#define PHYANA_REMOTE_FAULT BIT13 // Remot= e fault detected > + > +#define PHYLPA_SLCT =09 0x001f // Same a= s advertise selector > +#define PHYLPA_10HALF =09 0x0020 // Can do 1= 0mbps half-duplex > +#define PHYLPA_1000XFULL =09 0x0020 // Can do 10= 00BASE-X full-duplex > +#define PHYLPA_10FULL =09 0x0040 // Can do 1= 0mbps full-duplex > +#define PHYLPA_1000XHALF =09 0x0040 // Can do 10= 00BASE-X half-duplex > +#define PHYLPA_100HALF =09 0x0080 // Can do = 100mbps half-duplex > +#define PHYLPA_1000XPAUSE =09 0x0080 // Can do 1= 000BASE-X pause > +#define PHYLPA_100FULL =09 0x0100 // Can do = 100mbps full-duplex > +#define PHYLPA_1000XPAUSE_ASYM 0x0100 // Can do= 1000BASE-X pause asym > +#define PHYLPA_100BASE4 =09 0x0200 // Can do= 100mbps 4k packets > +#define PHYLPA_PAUSE_CAP =09 0x0400 // Can pause > +#define PHYLPA_PAUSE_ASYM =09 0x0800 // Can paus= e asymetrically > +#define PHYLPA_RESV =09 0x1000 // Unused > +#define PHYLPA_RFAULT =09 0x2000 // Link par= tner faulted > +#define PHYLPA_LPACK =09 0x4000 // Link part= ner acked us > +#define PHYLPA_NPAGE =09 0x8000 // Next page= bit > + > +#define PHYLPA_DUPLEX =09 (LPA_10FULL | LPA_100FULL) > +#define PHYLPA_100 =09 (LPA_100FULL | LPA_100HALF | LP= A_100BASE4) > + > +// 1000BASE-T Status register > +#define PHYLPA_1000FULL =09 0x0800 // Link p= artner 1000BASE-T full duplex=20 > +#define PHYLPA_1000HALF =09 0x0400 // Link p= artner 1000BASE-T half duplex=20 > + > +// 1000BASE-T Control register > +#define PHYADVERTISE_1000FULL 0x0200 // Adverti= se 1000BASE-T full duplex=20 > +#define PHYADVERTISE_1000HALF 0x0100 // Adverti= se 1000BASE-T half duplex=20 > + > +#define SPEED_1000 1000 > +#define SPEED_100 100 > +#define SPEED_10 10 > + > +#define DUPLEX_FULL 1 > +#define DUPLEX_HALF 0 > + > +// PHY Super Special control/status > +#define PHYSSCS_HCDSPEED_MASK (7 << 2) // Speed = indication > +#define PHYSSCS_AUTODONE BIT12 // Auto-N= egotiation Done > + > +// Flags for PHY reset > +#define PHY_RESET_PMT BIT0 > +#define PHY_RESET_BCR BIT1 > +#define PHY_RESET_CHECK_LINK BIT2 > + > +// Flags for auto negotiation > +#define AUTO_NEGOTIATE_COLLISION_TEST BIT0 > +#define AUTO_NEGOTIATE_ADVERTISE_ALL BIT1 > + > + > +// Micrel KSZ9031 Extended registers > +#define PHY_KSZ9031RN_CONTROL_PAD_SKEW_REG 4 > +#define PHY_KSZ9031RN_RX_DATA_PAD_SKEW_REG 5 > +#define PHY_KSZ9031RN_TX_DATA_PAD_SKEW_REG 6 > +#define PHY_KSZ9031RN_CLK_PAD_SKEW_REG 8 > + > +// Data operations > +#define PHY_KSZ9031_MOD_DATA_NO_POST_INC 0x1 > +#define PHY_KSZ9031_MOD_DATA_POST_INC_RW 0x2 > +#define PHY_KSZ9031_MOD_DATA_POST_INC_W 0x3 > + > +#define PHY_KSZ9031RN_MMD_CTRL_REG 0x0d > +#define PHY_KSZ9031RN_MMD_REGDATA_REG 0x0e > + > +#define PHY_KSZ9031RN_CLK_SKEW_CLR_MASK 0x3FF > +#define PHY_KSZ9031RN_CONTROL_SKEW_CLR_MASK 0xFF > +#define PHY_KSZ9031RN_RX_DATA_SKEW_CLR_MASK 0xFF > +#define PHY_KSZ9031RN_TX_DATA_SKEW_CLR_MASK 0xFF > + > +#define PHY_KSZ9031RN_CLK_PAD_SKEW_VALUE 0x3FC > +#define PHY_KSZ9031RN_CONTROL_PAD_SKEW_VALUE 0x70 > +#define PHY_KSZ9031RN_RX_DATA_PAD_SKEW_VALUE 0x7777 > +#define PHY_KSZ9031RN_TX_DATA_PAD_SKEW_VALUE 0x0 > + > + > +#define PHY_KSZ9031RN_DEV_ADDR 0x2 > + > +// MMD Address 0h, Auto-Negotiation FLP burst transmit timing > +#define PHY_KSZ9031RN_MMD_DEV_ADDR_00 0x00 > +#define PHY_KSZ9031RN_MMD_D0_FLP_LO_REG 3 > +#define PHY_KSZ9031RN_MMD_D0_FLP_16MS_LO 0x1A80 > +#define PHY_KSZ9031RN_MMD_D0_FLP_HI_REG 4 > +#define PHY_KSZ9031RN_MMD_D0_FLP_16MS_HI 0x0006 > + > +// HPS MII > +#define MII_BUSY =09 (1 << 0) > +#define MII_WRITE =09 (1 << 1) > +#define MII_CLKRANGE_60_100M (0x0) > +#define MII_CLKRANGE_100_150M (0x4) > +#define MII_CLKRANGE_20_35M (0x8) > +#define MII_CLKRANGE_35_60M (0xC) > +#define MII_CLKRANGE_150_250M (0x10) > +#define MII_CLKRANGE_250_300M (0x14) > + > +#define MIIADDRSHIFT =09 (11) > +#define MIIREGSHIFT =09 (6) > +#define MII_REGMSK =09 (0x1F << 6) > +#define MII_ADDRMSK =09 (0x1F << 11) > + > +// Others > +#define PHY_INVALID_ID 0xFFFF > +#define LINK_UP =09 =09 1 > +#define LINK_DOWN 0 > +#define PHY_TIMEOUT 200000 > + > + > +EFI_STATUS > +EFIAPI > +PhyDxeInitialization ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +PhyDetectDevice ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +PhyConfig ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +PhySoftReset ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +PhyReadId ( > + IN UINT32 PhyAddr, > + IN UINTN MacBaseAddress > + ); > + > +VOID > +EFIAPI > +PhyConfigSkew ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +VOID > +EFIAPI > +PhyDisplayConfigSkew ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +VOID > +EFIAPI > +PhyConfigFlpBurstTiming ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +VOID > +EFIAPI > +PhyDisplayFlpBurstTiming ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +PhyAutoNego ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +PhyLinkAdjustEmacConfig ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +PhyCheckLinkStatus ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +PhyReadCapability ( > + IN PHY_DRIVER *PhyDriver, > + IN UINT32 *Speed, > + IN UINT32 *Duplex, > + IN UINTN MacBaseAddress > + ); > + > +VOID > +EFIAPI > +PhyDisplayAbility ( > + IN UINT32 Speed, > + IN UINT32 Duplex > + ); > + > +EFI_STATUS > +EFIAPI > +PhyRead ( > + IN UINT32 Addr, > + IN UINT32 Reg, > + OUT UINT32 *Data, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +PhyWrite ( > + IN UINT32 Addr, > + IN UINT32 Reg, > + IN UINT32 Data, > + IN UINTN MacBaseAddress > + ); > + > +EFI_STATUS > +EFIAPI > +Phy9031ExtendedWrite ( > + IN PHY_DRIVER *PhyDriver, > + IN UINT32 Mode, > + IN UINT32 DevAddr, > + IN UINT32 Regnum, > + IN UINT16 Val, > + IN UINTN MacBaseAddress > + ); > + > +UINT32 > +EFIAPI > +Phy9031ExtendedRead ( > + IN PHY_DRIVER *PhyDriver, > + IN UINT32 Mode, > + IN UINT32 DevAddr, > + IN UINT32 Regnum, > + IN UINTN MacBaseAddress > + ); > + > +#endif /* __PHY_DXE_H__ */ > diff --git a/Silicon/DesignWare/Drivers/DwEmacSnpDxe/ComponentName.c b/S= ilicon/DesignWare/Drivers/DwEmacSnpDxe/ComponentName.c > new file mode 100755 > index 000000000000..b9dc048e6209 > --- /dev/null > +++ b/Silicon/DesignWare/Drivers/DwEmacSnpDxe/ComponentName.c > @@ -0,0 +1,327 @@ > +/** @file > +Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > + > + The original software modules are licensed as follows: > + > + Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > + SPDX. > +Module Name: > + > + ComponentName.c > + > +Abstract: > + > + > +**/ > + > +#include "DwEmacSnpDxe.h" > + > +// > +// EFI Component Name Functions > +// > +/** > + Retrieves a Unicode string that is the user readable name of the driv= er. > + > + This function retrieves the user readable name of a driver in the for= m of a > + Unicode string. If the driver specified by This has a user readable n= ame in > + the language specified by Language, then a pointer to the driver name= is > + returned in DriverName, and EFI_SUCCESS is returned. If the driver sp= ecified > + by This does not support the language specified by Language, > + then EFI_UNSUPPORTED is returned. > + > + @param This[in] A pointer to the EFI_COMPONENT_NAME2_PR= OTOCOL or > + EFI_COMPONENT_NAME_PROTOCOL instance. > + > + @param Language[in] A pointer to a Null-terminated ASCII st= ring > + array indicating the language. This is = the > + language of the driver name that the ca= ller is > + requesting, and it must match one of th= e > + languages specified in SupportedLanguag= es. The > + number of languages supported by a driv= er is up > + to the driver writer. Language is speci= fied > + in RFC 4646 or ISO 639-2 language code = format. > + > + @param DriverName[out] A pointer to the Unicode string to retu= rn. > + This Unicode string is the name of the > + driver specified by This in the languag= e > + specified by Language. > + > + @retval EFI_SUCCESS The Unicode string for the Driver speci= fied by > + This and the language specified by Lang= uage was > + returned in DriverName. > + > + @retval EFI_INVALID_PARAMETER Language is NULL. > + > + @retval EFI_INVALID_PARAMETER DriverName is NULL. > + > + @retval EFI_UNSUPPORTED The driver specified by This does not s= upport > + the language specified by Language. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpGetDriverName ( > + IN EFI_COMPONENT_NAME_PROTOCOL *This, > + IN CHAR8 *Language, > + OUT CHAR16 **DriverName > + ); > + > + > +/** > + Retrieves a Unicode string that is the user readable name of the cont= roller > + that is being managed by a driver. > + > + This function retrieves the user readable name of the controller spec= ified by > + ControllerHandle and ChildHandle in the form of a Unicode string. If = the > + driver specified by This has a user readable name in the language spe= cified by > + Language, then a pointer to the controller name is returned in Contro= llerName, > + and EFI_SUCCESS is returned. If the driver specified by This is not = currently > + managing the controller specified by ControllerHandle and ChildHandle= , > + then EFI_UNSUPPORTED is returned. If the driver specified by This do= es not > + support the language specified by Language, then EFI_UNSUPPORTED is r= eturned. > + > + @param This[in] A pointer to the EFI_COMPONENT_NAME2_PR= OTOCOL or > + EFI_COMPONENT_NAME_PROTOCOL instance. > + > + @param ControllerHandle[in] The handle of a controller that the dri= ver > + specified by This is managing. This ha= ndle > + specifies the controller whose name is = to be > + returned. > + > + @param ChildHandle[in] The handle of the child controller to r= etrieve > + the name of. This is an optional param= eter that > + may be NULL. It will be NULL for devic= e > + drivers. It will also be NULL for a bu= s drivers > + that wish to retrieve the name of the b= us > + controller. It will not be NULL for a = bus > + driver that wishes to retrieve the name= of a > + child controller. > + > + @param Language[in] A pointer to a Null-terminated ASCII st= ring > + array indicating the language. This is= the > + language of the driver name that the ca= ller is > + requesting, and it must match one of th= e > + languages specified in SupportedLanguag= es. The > + number of languages supported by a driv= er is up > + to the driver writer. Language is speci= fied in > + RFC 4646 or ISO 639-2 language code for= mat. > + > + @param ControllerName[out] A pointer to the Unicode string to retu= rn. > + This Unicode string is the name of the > + controller specified by ControllerHandl= e and > + ChildHandle in the language specified b= y > + Language from the point of view of the = driver > + specified by This. > + > + @retval EFI_SUCCESS The Unicode string for the user readabl= e name in > + the language specified by Language for = the > + driver specified by This was returned i= n > + DriverName. > + > + @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HAN= DLE. > + > + @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a= valid > + EFI_HANDLE. > + > + @retval EFI_INVALID_PARAMETER Language is NULL. > + > + @retval EFI_INVALID_PARAMETER ControllerName is NULL. > + > + @retval EFI_UNSUPPORTED The driver specified by This is not cur= rently > + managing the controller specified by > + ControllerHandle and ChildHandle. > + > + @retval EFI_UNSUPPORTED The driver specified by This does not s= upport > + the language specified by Language. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpGetControllerName ( > + IN EFI_COMPONENT_NAME_PROTOCOL *This, > + IN EFI_HANDLE ControllerHandle, > + IN EFI_HANDLE ChildHandle OPTIONAL, > + IN CHAR8 *Language, > + OUT CHAR16 **ControllerName > + ); > + > + > +// > +// EFI Component Name Protocol > +// > +GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gSnpComponen= tName =3D { > + SnpGetDriverName, > + SnpGetControllerName, > + "eng" > +}; > + > +// > +// EFI Component Name 2 Protocol > +// > +GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gSnpComponen= tName2 =3D { > + (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) SnpGetDriverName, > + (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) SnpGetControllerName, > + "en" > +}; > + > + > +GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mSnpNameTable[] = = =3D { > + { > + "eng;en", > + L"SNP DesignWare EMAC Driver" > + }, > + { > + NULL, > + NULL > + } > +}; > + > +/** > + Retrieves a Unicode string that is the user readable name of the driv= er. > + > + This function retrieves the user readable name of a driver in the for= m of a > + Unicode string. If the driver specified by This has a user readable n= ame in > + the language specified by Language, then a pointer to the driver name= is > + returned in DriverName, and EFI_SUCCESS is returned. If the driver sp= ecified > + by This does not support the language specified by Language, > + then EFI_UNSUPPORTED is returned. > + > + @param This[in] A pointer to the EFI_COMPONENT_NAME2_PR= OTOCOL or > + EFI_COMPONENT_NAME_PROTOCOL instance. > + > + @param Language[in] A pointer to a Null-terminated ASCII st= ring > + array indicating the language. This is = the > + language of the driver name that the ca= ller is > + requesting, and it must match one of th= e > + languages specified in SupportedLanguag= es. The > + number of languages supported by a driv= er is up > + to the driver writer. Language is speci= fied > + in RFC 4646 or ISO 639-2 language code = format. > + > + @param DriverName[out] A pointer to the Unicode string to retu= rn. > + This Unicode string is the name of the > + driver specified by This in the languag= e > + specified by Language. > + > + @retval EFI_SUCCESS The Unicode string for the Driver speci= fied by > + This and the language specified by Lang= uage was > + returned in DriverName. > + > + @retval EFI_INVALID_PARAMETER Language is NULL. > + > + @retval EFI_INVALID_PARAMETER DriverName is NULL. > + > + @retval EFI_UNSUPPORTED The driver specified by This does not s= upport > + the language specified by Language. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpGetDriverName ( > + IN EFI_COMPONENT_NAME_PROTOCOL *This, > + IN CHAR8 *Language, > + OUT CHAR16 **DriverName > + ) > +{ > + return LookupUnicodeString2 ( > + Language, > + This->SupportedLanguages, > + mSnpNameTable, > + DriverName, > + (BOOLEAN)(This =3D=3D &gSnpComponentName) > + ); > +} > + > +/** > + Retrieves a Unicode string that is the user readable name of the cont= roller > + that is being managed by a driver. > + > + This function retrieves the user readable name of the controller spec= ified by > + ControllerHandle and ChildHandle in the form of a Unicode string. If = the > + driver specified by This has a user readable name in the language spe= cified by > + Language, then a pointer to the controller name is returned in Contro= llerName, > + and EFI_SUCCESS is returned. If the driver specified by This is not = currently > + managing the controller specified by ControllerHandle and ChildHandle= , > + then EFI_UNSUPPORTED is returned. If the driver specified by This do= es not > + support the language specified by Language, then EFI_UNSUPPORTED is r= eturned. > + > + @param This[in] A pointer to the EFI_COMPONENT_NAME2_PR= OTOCOL or > + EFI_COMPONENT_NAME_PROTOCOL instance. > + > + @param ControllerHandle[in] The handle of a controller that the dri= ver > + specified by This is managing. This ha= ndle > + specifies the controller whose name is = to be > + returned. > + > + @param ChildHandle[in] The handle of the child controller to r= etrieve > + the name of. This is an optional param= eter that > + may be NULL. It will be NULL for devic= e > + drivers. It will also be NULL for a bu= s drivers > + that wish to retrieve the name of the b= us > + controller. It will not be NULL for a = bus > + driver that wishes to retrieve the name= of a > + child controller. > + > + @param Language[in] A pointer to a Null-terminated ASCII st= ring > + array indicating the language. This is= the > + language of the driver name that the ca= ller is > + requesting, and it must match one of th= e > + languages specified in SupportedLanguag= es. The > + number of languages supported by a driv= er is up > + to the driver writer. Language is speci= fied in > + RFC 4646 or ISO 639-2 language code for= mat. > + > + @param ControllerName[out] A pointer to the Unicode string to retu= rn. > + This Unicode string is the name of the > + controller specified by ControllerHandl= e and > + ChildHandle in the language specified b= y > + Language from the point of view of the = driver > + specified by This. > + > + @retval EFI_SUCCESS The Unicode string for the user readabl= e name in > + the language specified by Language for = the > + driver specified by This was returned i= n > + DriverName. > + > + @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HAN= DLE. > + > + @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a= valid > + EFI_HANDLE. > + > + @retval EFI_INVALID_PARAMETER Language is NULL. > + > + @retval EFI_INVALID_PARAMETER ControllerName is NULL. > + > + @retval EFI_UNSUPPORTED The driver specified by This is not cur= rently > + managing the controller specified by > + ControllerHandle and ChildHandle. > + > + @retval EFI_UNSUPPORTED The driver specified by This does not s= upport > + the language specified by Language. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpGetControllerName ( > + IN EFI_COMPONENT_NAME_PROTOCOL *This, > + IN EFI_HANDLE ControllerHandle, > + IN EFI_HANDLE ChildHandle OPTIONAL, > + IN CHAR8 *Language, > + OUT CHAR16 **ControllerName > + ) > +{ > + return EFI_UNSUPPORTED; > +} > diff --git a/Silicon/DesignWare/Drivers/DwEmacSnpDxe/DriverBinding.c b/S= ilicon/DesignWare/Drivers/DwEmacSnpDxe/DriverBinding.c > new file mode 100755 > index 000000000000..fd0a39798b8e > --- /dev/null > +++ b/Silicon/DesignWare/Drivers/DwEmacSnpDxe/DriverBinding.c > @@ -0,0 +1,372 @@ > +/** @file > + > + Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > + **/ SPDX. > + > +#include "DwEmacSnpDxe.h" > + > +STATIC > +EFI_STATUS > +EFIAPI > +DriverSupported ( > + IN EFI_DRIVER_BINDING_PROTOCOL *This, > + IN EFI_HANDLE Controller, > + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath > + ); > + > +STATIC > +EFI_STATUS > +EFIAPI > +DriverStart ( > + IN EFI_DRIVER_BINDING_PROTOCOL *This, > + IN EFI_HANDLE Controller, > + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath > + ); > + > +STATIC > +EFI_STATUS > +EFIAPI > +DriverStop ( > + IN EFI_DRIVER_BINDING_PROTOCOL *This, > + IN EFI_HANDLE Controller, > + IN UINTN NumberOfChildren, > + IN EFI_HANDLE *ChildHandleBuffer > + ); > + > +STATIC > +EFI_DRIVER_BINDING_PROTOCOL mDriverBinding =3D { > + DriverSupported, > + DriverStart, > + DriverStop, > + 0xa, > + NULL, > + NULL > +}; > + > +STATIC > +SIMPLE_NETWORK_DEVICE_PATH PathTemplate =3D { > + { > + { > + MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, > + { (UINT8) (sizeof(MAC_ADDR_DEVICE_PATH)), (UINT8) ((sizeof(MAC_AD= DR_DEVICE_PATH)) >> 8) } No space after either (UINT8), but space after both sieof. > + }, > + { { 0 } }, > + 0 > + }, > + { > + END_DEVICE_PATH_TYPE, > + END_ENTIRE_DEVICE_PATH_SUBTYPE, > + { sizeof(EFI_DEVICE_PATH_PROTOCOL), 0 } > + } > +}; > + > +STATIC > +EFI_STATUS > +EFIAPI > +DriverSupported ( > + IN EFI_DRIVER_BINDING_PROTOCOL *This, > + IN EFI_HANDLE Controller, > + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath > + ) > +{ > + NON_DISCOVERABLE_DEVICE *Dev; > + EFI_STATUS Status; > + > + // Connect to the non-discoverable device > + Status =3D gBS->OpenProtocol (Controller, > + &gEdkiiNonDiscoverableDeviceProtocolGuid, > + (VOID **) &Dev, No space after ). > + This->DriverBindingHandle, > + Controller, > + EFI_OPEN_PROTOCOL_BY_DRIVER); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // Clean up. > + gBS->CloseProtocol (Controller, > + &gEdkiiNonDiscoverableDeviceProtocolGuid, > + This->DriverBindingHandle, > + Controller); > + > + return Status; > +} > + > +STATIC > +EFI_STATUS > +EFIAPI > +DriverStart ( > + IN EFI_DRIVER_BINDING_PROTOCOL *This, > + IN EFI_HANDLE Controller, > + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath > + ) > +{ > + EFI_STATUS Status; > + SIMPLE_NETWORK_DRIVER *Snp; > + EFI_SIMPLE_NETWORK_MODE *SnpMode; > + SIMPLE_NETWORK_DEVICE_PATH *DevicePath; > + UINT64 DefaultMacAddress; > + EFI_MAC_ADDRESS *SwapMacAddressPtr; > + UINTN DescriptorSize; > + UINTN BufferSize; > + UINTN *RxBufferAddr; > + EFI_PHYSICAL_ADDRESS RxBufferAddrMap; > + > + // Allocate Resources > + Snp =3D AllocatePages (EFI_SIZE_TO_PAGES (sizeof (SIMPLE_NETWORK_DRIV= ER))); > + if (Snp =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + Status =3D gBS->OpenProtocol (Controller, > + &gEdkiiNonDiscoverableDeviceProtocolGuid, > + (VOID **)&Snp->Dev, > + This->DriverBindingHandle, > + Controller, > + EFI_OPEN_PROTOCOL_BY_DRIVER); > + > + // Size for descriptor > + DescriptorSize =3D EFI_PAGES_TO_SIZE (sizeof (DESIGNWARE_HW_DESCRIPTO= R)); > + // Size for transmit and receive buffer > + BufferSize =3D ETH_BUFSIZE; > + > + //DMA TxdescRing allocate buffer and map > + for (int Index=3D0; Index < DESC_NUM; Index++) { Misleading indentation from here... > + Status =3D DmaAllocateBuffer (EfiBootServicesData, > + EFI_SIZE_TO_PAGES (sizeof (DESIGNWARE_HW_DESCRIPTOR)), (VO= ID*)&Snp->MacDriver.TxdescRing[Index]); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a () for TxdescRing: %r\n", __FUNCTION__, St= atus)); > + return Status; > + } > + > + Status =3D DmaMap (MapOperationBusMasterCommonBuffer, Snp->MacDriver.= TxdescRing[Index],=20 > + &DescriptorSize, &Snp->MacDriver.TxdescRingMap[Index].Addr= Map, &Snp->MacDriver.TxdescRingMap[Index].Mapping); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a () for TxdescRing: %r\n", __FUNCTION__, St= atus)); > + return Status; > + } > + > + // DMA RxdescRing allocte buffer and map > + Status =3D DmaAllocateBuffer (EfiBootServicesData,=20 > + EFI_SIZE_TO_PAGES (sizeof (DESIGNWARE_HW_DESCRIPTOR)), (VO= ID*)&Snp->MacDriver.RxdescRing[Index]); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a () for RxdescRing: %r\n", __FUNCTION__, St= atus)); > + return Status; > + } > + > + Status =3D DmaMap (MapOperationBusMasterCommonBuffer, Snp->MacDriver.= RxdescRing[Index],=20 > + &DescriptorSize, &Snp->MacDriver.RxdescRingMap[Index].Addr= Map, &Snp->MacDriver.RxdescRingMap[Index].Mapping); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a () for RxdescRing: %r\n", __FUNCTION__, St= atus)); > + return Status;=20 > + } > + > + //Dma mapping for receive buffer > + RxBufferAddr =3D (VOID*)Snp->MacDriver.RxBuffer + (Index * BufferSize= ); > + Status =3D DmaMap (MapOperationBusMasterWrite, (VOID*) RxBufferAddr,= = =20 > + &BufferSize, &RxBufferAddrMap, &Snp->MacDriver.RxBufNum[In= dex].Mapping); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a () for Rxbuffer: %r\n", __FUNCTION__, Stat= us)); > + return Status;=20 > + } > + Snp->MacDriver.RxBufNum[Index].AddrMap=3D RxBufferAddrMap; ... to here. Please indent whole block. > + } > + > + DevicePath =3D (SIMPLE_NETWORK_DEVICE_PATH*)AllocateCopyPool (sizeof = (SIMPLE_NETWORK_DEVICE_PATH), &PathTemplate); > + if (DevicePath =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + // Initialized signature (used by INSTANCE_FROM_SNP_THIS macro) > + Snp->Signature =3D SNP_DRIVER_SIGNATURE; > + > + EfiInitializeLock (&Snp->Lock, TPL_CALLBACK); > + > + // Initialize pointers > + SnpMode =3D &Snp->SnpMode; > + Snp->Snp.Mode =3D SnpMode; > + > + // Get MAC controller base address > + Snp->MacBase =3D (UINTN)Snp->Dev->Resources[0].AddrRangeMin; > + > + // Assign fields and func pointers > + Snp->Snp.Revision =3D EFI_SIMPLE_NETWORK_PROTOCOL_REVISION; > + Snp->Snp.WaitForPacket =3D NULL; > + Snp->Snp.Initialize =3D SnpInitialize; > + Snp->Snp.Start =3D SnpStart; > + Snp->Snp.Stop =3D SnpStop; > + Snp->Snp.Reset =3D SnpReset; > + Snp->Snp.Shutdown =3D SnpShutdown; > + Snp->Snp.ReceiveFilters =3D SnpReceiveFilters; > + Snp->Snp.StationAddress =3D SnpStationAddress; > + Snp->Snp.Statistics =3D SnpStatistics; > + Snp->Snp.MCastIpToMac =3D SnpMcastIptoMac; > + Snp->Snp.NvData =3D SnpNvData; > + Snp->Snp.GetStatus =3D SnpGetStatus; > + Snp->Snp.Transmit =3D SnpTransmit; > + Snp->Snp.Receive =3D SnpReceive; > +=20 > + Snp->RecycledTxBuf =3D AllocatePool (sizeof (UINT64) * SNP_TX_BUFFER_= INCREASE); > + if (Snp->RecycledTxBuf =3D=3D NULL) { > + Status =3D EFI_OUT_OF_RESOURCES; > + } > + > + Snp->MaxRecycledTxBuf =3D SNP_TX_BUFFER_INCREASE; > + Snp->RecycledTxBufCount =3D 0; > + > + // Start completing simple network mode structure > + SnpMode->State =3D EfiSimpleNetworkStopped; > + SnpMode->HwAddressSize =3D NET_ETHER_ADDR_LEN; // HW address is 6 = bytes > + SnpMode->MediaHeaderSize =3D sizeof (ETHER_HEAD); > + SnpMode->MaxPacketSize =3D EFI_PAGE_SIZE; // Preamble + SOF += Ether Frame (with VLAN tag +4bytes) > + SnpMode->NvRamSize =3D 0; // No NVRAM with th= is device > + SnpMode->NvRamAccessSize =3D 0; // No NVRAM with th= is device > + > + // Update network mode information > + SnpMode->ReceiveFilterMask =3D EFI_SIMPLE_NETWORK_RECEIVE_UNICAST = | > + EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST | > + EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST | > + EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS | > + EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_M= ULTICAST; > + > + // We do not intend to receive anything for the time being. > + SnpMode->ReceiveFilterSetting =3D 0; > + > + // EMAC has 64bit hash table, can filter 64 MCast MAC Addresses > + SnpMode->MaxMCastFilterCount =3D MAX_MCAST_FILTER_CNT; > + SnpMode->MCastFilterCount =3D 0; > + ZeroMem (&SnpMode->MCastFilter, MAX_MCAST_FILTER_CNT * sizeof (EFI_MA= C_ADDRESS)); > + > + // Set the interface type (1: Ethernet or 6: IEEE 802 Networks) > + SnpMode->IfType =3D NET_IFTYPE_ETHERNET; > + > + // Mac address is changeable as it is loaded from erasable memory > + SnpMode->MacAddressChangeable =3D TRUE; > + > + // Can only transmit one packet at a time > + SnpMode->MultipleTxSupported =3D FALSE; > + > + // MediaPresent checks for cable connection and partner link > + SnpMode->MediaPresentSupported =3D TRUE; > + SnpMode->MediaPresent =3D FALSE; > + > + // Set broadcast address > + SetMem (&SnpMode->BroadcastAddress, sizeof (EFI_MAC_ADDRESS), 0xFF); > + > + //Set current address > + DefaultMacAddress =3D Snp->Dev->Resources[1].AddrRangeMin; > + // Swap PCD human readable form to correct endianess > + SwapMacAddressPtr =3D (EFI_MAC_ADDRESS *) &DefaultMacAddress; > + SnpMode->CurrentAddress.Addr[0] =3D SwapMacAddressPtr->Addr[5]; > + SnpMode->CurrentAddress.Addr[1] =3D SwapMacAddressPtr->Addr[4]; > + SnpMode->CurrentAddress.Addr[2] =3D SwapMacAddressPtr->Addr[3]; > + SnpMode->CurrentAddress.Addr[3] =3D SwapMacAddressPtr->Addr[2]; > + SnpMode->CurrentAddress.Addr[4] =3D SwapMacAddressPtr->Addr[1]; > + SnpMode->CurrentAddress.Addr[5] =3D SwapMacAddressPtr->Addr[0]; > + > + // Assign fields for device path > + CopyMem (&DevicePath->MacAddrDP.MacAddress, &Snp->Snp.Mode->CurrentAd= dress, NET_ETHER_ADDR_LEN); > + DevicePath->MacAddrDP.IfType =3D Snp->Snp.Mode->IfType; > + > + Status =3D gBS->InstallMultipleProtocolInterfaces ( > + &Controller, > + &gEfiSimpleNetworkProtocolGuid, &(Snp->Snp), > + &gEfiDevicePathProtocolGuid, DevicePath, > + NULL > + ); > + > + if (EFI_ERROR(Status)) { > + gBS->CloseProtocol (Controller, > + &gEdkiiNonDiscoverableDeviceProtocolGuid,=20 > + This->DriverBindingHandle, > + Controller); > + > + FreePages (Snp, EFI_SIZE_TO_PAGES (sizeof (SIMPLE_NETWORK_DRIVER)))= ; > + } else { > + Snp->ControllerHandle =3D Controller; > + } > + > + return Status; > +} > + > +STATIC > +EFI_STATUS > +EFIAPI > +DriverStop ( > + IN EFI_DRIVER_BINDING_PROTOCOL *This, > + IN EFI_HANDLE Controller, > + IN UINTN NumberOfChildren, > + IN EFI_HANDLE *ChildHandleBuffer > + ) > +{ > + EFI_STATUS Status; > + EFI_SIMPLE_NETWORK_PROTOCOL *SnpProtocol; > + SIMPLE_NETWORK_DRIVER *Snp; > + > + Status =3D gBS->HandleProtocol ( > + Controller, > + &gEfiSimpleNetworkProtocolGuid, > + (VOID **)&SnpProtocol > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a (): HandleProtocol: %r\n", __FUNCTION__, S= tatus)); > + return Status; > + } > + > + Snp =3D INSTANCE_FROM_SNP_THIS(SnpProtocol); > + > + Status =3D gBS->UninstallMultipleProtocolInterfaces ( > + Controller, > + &gEfiSimpleNetworkProtocolGuid, > + &Snp->Snp, > + NULL); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a (): UninstallMultipleProtocolInterfaces: %= r\n", __FUNCTION__, Status)); > + return Status; > + } > + > + FreePool (Snp->RecycledTxBuf); > + FreePages (Snp, EFI_SIZE_TO_PAGES (sizeof (SIMPLE_NETWORK_DRIVER)));= =20 > + > + return Status; > +} > + > + > +/** > + UEFI Driver Entry Point API > + @param ImageHandle EFI_HANDLE. > + @param SystemTable EFI_SYSTEM_TABLE. > + @return EFI_SUCCESS Success. > + EFI_DEVICE_ERROR Fail. > +**/ > + > +EFI_STATUS > +EFIAPI > +DwEmacSnpDxeEntry ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + EFI_HANDLE Handle; > + > + Handle =3D NULL; > + > + Status =3D EfiLibInstallDriverBindingComponentName2 ( > + ImageHandle, > + SystemTable, > + &mDriverBinding, > + ImageHandle, > + &gSnpComponentName, > + &gSnpComponentName2 > + ); > + > + return Status; > + > +} > \ No newline at end of file > diff --git a/Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.c b/Si= licon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.c > new file mode 100755 > index 000000000000..30fc33dadf35 > --- /dev/null > +++ b/Silicon/DesignWare/Drivers/DwEmacSnpDxe/DwEmacSnpDxe.c > @@ -0,0 +1,1275 @@ > +/** @file > + DW EMAC SNP DXE driver > + > + Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > + > + The original software modules are licensed as follows: > + > + Copyright (c) 2012 - 2014, ARM Limited. All rights reserved. > + Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved. > + > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD 3 Clause LICENSE ON AN "AS I= S" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > +**/ SPDX. > + > +#include "DwEmacSnpDxe.h" > +#include "EmacDxeUtil.h" > +#include "PhyDxeUtil.h" > + > +/** > + Change the state of a network interface from "stopped" to "started." > + > + This function starts a network interface. If the network interface su= ccessfully > + starts, then EFI_SUCCESS will be returned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PR= OTOCOL instance. > + > + @retval EFI_SUCCESS The network interface was started. > + @retval EFI_ALREADY_STARTED The network interface is already in th= e started state. > + @retval EFI_INVALID_PARAMETER This parameter was NULL or did not poi= nt to a valid > + EFI_SIMPLE_NETWORK_PROTOCOL structure. > + @retval EFI_DEVICE_ERROR The command could not be sent to the n= etwork interface. > + @retval EFI_UNSUPPORTED This function is not supported by the = network interface. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpStart ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This > + ) > +{ > + SIMPLE_NETWORK_DRIVER *Snp; > + > + DEBUG ((DEBUG_INFO,"SNP:DXE: %a ()\r\n", __FUNCTION__)); > + > + // Check Snp instance > + if (This =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + Snp =3D INSTANCE_FROM_SNP_THIS(This); > + // Check state > + if ((Snp->SnpMode.State =3D=3D EfiSimpleNetworkStarted) || > + (Snp->SnpMode.State =3D=3D EfiSimpleNetworkInitialized) ) { > + return EFI_ALREADY_STARTED; > + } > + > + // Change state > + Snp->SnpMode.State =3D EfiSimpleNetworkStarted; > + return EFI_SUCCESS; > +} > + > + > +/** > + Changes the state of a network interface from "started" to "stopped." > + > + This function stops a network interface. This call is only valid if t= he network > + interface is in the started state. If the network interface was succe= ssfully > + stopped, then EFI_SUCCESS will be returned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_P= ROTOCOL > + instance. > + > + > + @retval EFI_SUCCESS The network interface was stopped. > + @retval EFI_NOT_STARTED The network interface has not been st= arted. > + @retval EFI_INVALID_PARAMETER This parameter was NULL or did not po= int to a > + valid EFI_SIMPLE_NETWORK_PROTOCOL str= ucture. > + @retval EFI_DEVICE_ERROR The command could not be sent to the = network > + interface. > + @retval EFI_UNSUPPORTED This function is not supported by the= network > + interface. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpStop ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL* This > + ) > +{ > + SIMPLE_NETWORK_DRIVER *Snp; > + > + DEBUG ((DEBUG_INFO, "SNP:DXE: %a ()\r\n", __FUNCTION__)); > + > + // Check Snp Instance > + if (This =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + Snp =3D INSTANCE_FROM_SNP_THIS(This); > + // Check state of the driver > + if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStopped) { > + return EFI_NOT_STARTED; > + } > + > + // Stop the Tx and Rx > + EmacStopTxRx (Snp->MacBase); > + // Change the state > + switch (Snp->SnpMode.State) { > + case EfiSimpleNetworkStarted: > + case EfiSimpleNetworkInitialized: > + Snp->SnpMode.State =3D EfiSimpleNetworkStopped; > + break; > + default: > + return EFI_DEVICE_ERROR; > + } > + > + // Put the device into a power saving mode=20 > + return EFI_SUCCESS; > +} > + > + > +/** > + Resets a network adapter and allocates the transmit and receive buffe= rs > + required by the network interface; optionally, also requests allocati= on of > + additional transmit and receive buffers. > + > + This function allocates the transmit and receive buffers required by = the network > + interface. If this allocation fails, then EFI_OUT_OF_RESOURCES is ret= urned. > + If the allocation succeeds and the network interface is successfully = initialized, > + then EFI_SUCCESS will be returned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTOCO= L instance. > + > + @param ExtraRxBufferSize The size, in bytes, of the extra receive bu= ffer space > + that the driver should allocate for the net= work interface. > + Some network interfaces will not be able to= use the > + extra buffer, and the caller will not know = if it is > + actually being used. > + @param ExtraTxBufferSize The size, in bytes, of the extra transmit b= uffer space > + that the driver should allocate for the net= work interface. > + Some network interfaces will not be able to= use the > + extra buffer, and the caller will not know = if it is > + actually being used. > + > + @retval EFI_SUCCESS The network interface was initialized. > + @retval EFI_NOT_STARTED The network interface has not been star= ted. > + @retval EFI_OUT_OF_RESOURCES There was not enough memory for the tra= nsmit and > + receive buffers. > + @retval EFI_INVALID_PARAMETER This parameter was NULL or did not poin= t to a valid > + EFI_SIMPLE_NETWORK_PROTOCOL structure. > + @retval EFI_DEVICE_ERROR The command could not be sent to the ne= twork interface. > + @retval EFI_UNSUPPORTED The increased buffer size feature is no= t supported. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpInitialize ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + IN UINTN ExtraRxBufferSize OPTIONAL, > + IN UINTN ExtraTxBufferSize OPTIONAL > + ) > +{ > + EFI_STATUS Status; > + SIMPLE_NETWORK_DRIVER *Snp; > + > + > + DEBUG ((DEBUG_INFO, "SNP:DXE: %a ()\r\n", __FUNCTION__)); > + > + // Check Snp Instance > + if (This =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + Snp =3D INSTANCE_FROM_SNP_THIS (This); > + // First check that driver has not already been initialized > + if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkInitialized) { > + return EFI_SUCCESS; > + } else if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStopped) { > + return EFI_NOT_STARTED; > + } > + > + // Init PHY > + Status =3D PhyDxeInitialization (&Snp->PhyDriver, Snp->MacBase); > + if (EFI_ERROR (Status)) { > + return EFI_DEVICE_ERROR; > + } > + > + // Init EMAC > + Status =3D EmacDxeInitialization (&Snp->MacDriver, Snp->MacBase); > + if (EFI_ERROR (Status)) { > + return EFI_DEVICE_ERROR; > + } > + > + // Set MAC Address > + EmacSetMacAddress (&Snp->SnpMode.CurrentAddress, Snp->MacBase); > + EmacReadMacAddress (&Snp->SnpMode.CurrentAddress, Snp->MacBase); > + > + // Init Link > + DEBUG ((DEBUG_INFO, "SNP:DXE: Auto-Negotiating Ethernet PHY Link ...\= n")); > + Status =3D PhyLinkAdjustEmacConfig (&Snp->PhyDriver, Snp->MacBase); > + if (EFI_ERROR(Status)) { > + DEBUG ((DEBUG_INFO, "SNP:DXE: Link is Down - Network Cable is not p= lugged in?\n")); > + return EFI_DEVICE_ERROR; > + } > + > + EmacStartTransmission (Snp->MacBase); > + > + // Declare the driver as initialized > + Snp->SnpMode.State =3D EfiSimpleNetworkInitialized; > + > + return EFI_SUCCESS; > +} > + > + > +/** > + Resets a network adapter and reinitializes it with the parameters tha= t were > + provided in the previous call to Initialize(). > + > + This function resets a network adapter and reinitializes it with the = parameters > + that were provided in the previous call to Initialize(). The transmit= and > + receive queues are emptied and all pending interrupts are cleared. > + Receive filters, the station address, the statistics, and the multica= st-IP-to-HW > + MAC addresses are not reset by this call. If the network interface wa= s > + successfully reset, then EFI_SUCCESS will be returned. If the driver = has not > + been initialized, EFI_DEVICE_ERROR will be returned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTO= COL instance. > + @param ExtendedVerification Indicates that the driver may perform a m= ore > + exhaustive verification operation of the = device > + during reset. > + > + @retval EFI_SUCCESS The network interface was reset. > + @retval EFI_NOT_STARTED The network interface has not been star= ted. > + @retval EFI_INVALID_PARAMETER One or more of the parameters has an un= supported value. > + @retval EFI_DEVICE_ERROR The command could not be sent to the ne= twork interface. > + @retval EFI_UNSUPPORTED This function is not supported by the n= etwork interface. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpReset ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + IN BOOLEAN ExtendedVerification > + ) > +{ > + EFI_STATUS Status; > + SIMPLE_NETWORK_DRIVER *Snp; > + > + Snp =3D INSTANCE_FROM_SNP_THIS (This); > + > + DEBUG ((DEBUG_INFO, "SNP:DXE: %a ()\r\n", __FUNCTION__)); > + > + // Check Snp Instance > + if (This =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + // First check that driver has not already been initialized > + if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStarted) { > + return EFI_DEVICE_ERROR; > + } else if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStopped) { > + return EFI_NOT_STARTED; > + } > + > + // Initiate a PHY reset > + Status =3D PhySoftReset (&Snp->PhyDriver, Snp->MacBase); > + if (EFI_ERROR (Status)) { > + Snp->SnpMode.State =3D EfiSimpleNetworkStopped; > + return EFI_NOT_STARTED; > + } > + > + return EFI_SUCCESS; > +} > + > + > +/** > + Resets a network adapter and leaves it in a state that is safe for an= other > + driver to initialize. > + > + This function releases the memory buffers assigned in the Initialize(= ) call. > + Pending transmits and receives are lost, and interrupts are cleared a= nd disabled. > + After this call, only the Initialize() and Stop() calls may be used. = If the > + network interface was successfully shutdown, then EFI_SUCCESS will be= returned. > + If the driver has not been initialized, EFI_DEVICE_ERROR will be retu= rned. > + > + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. > + > + @retval EFI_SUCCESS The network interface was shutdown. > + @retval EFI_NOT_STARTED The network interface has not been star= ted. > + @retval EFI_INVALID_PARAMETER This parameter was NULL or did not poin= t to a valid > + EFI_SIMPLE_NETWORK_PROTOCOL structure. > + @retval EFI_DEVICE_ERROR The command could not be sent to the ne= twork interface. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpShutdown ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL* This > + ) > +{ > + SIMPLE_NETWORK_DRIVER *Snp; > + > + DEBUG ((DEBUG_INFO, "SNP:DXE: %a ()\r\n", __FUNCTION__)); > + > + // Check Snp Instance > + if (This =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + Snp =3D INSTANCE_FROM_SNP_THIS (This); > + // First check that driver has not already been initialized > + if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStarted) { > + return EFI_DEVICE_ERROR; > + } else if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStopped) { > + return EFI_NOT_STARTED; > + } > + > + EmacStopTxRx (Snp->MacBase); > + > + Snp->SnpMode.State =3D EfiSimpleNetworkStopped; > + > + return EFI_SUCCESS; > +} > + > + > +/** > + Manages the multicast receive filters of a network interface. > + > + This function is used enable and disable the hardware and software re= ceive > + filters for the underlying network device. > + The receive filter change is broken down into three steps: > + * The filter mask bits that are set (ON) in the Enable parameter are = added to > + the current receive filter settings. > + * The filter mask bits that are set (ON) in the Disable parameter are= subtracted > + from the updated receive filter settings. > + * If the resulting receive filter setting is not supported by the har= dware a > + more liberal setting is selected. > + If the same bits are set in the Enable and Disable parameters, then t= he bits > + in the Disable parameter takes precedence. > + If the ResetMCastFilter parameter is TRUE, then the multicast address= list > + filter is disabled (irregardless of what other multicast bits are set= in the > + Enable and Disable parameters). The SNP->Mode->MCastFilterCount field= is set > + to zero. The Snp->Mode->MCastFilter contents are undefined. > + After enabling or disabling receive filter settings, software should = verify > + the new settings by checking the Snp->Mode->ReceiveFilterSettings, > + Snp->Mode->MCastFilterCount and Snp->Mode->MCastFilter fields. > + Note: Some network drivers and/or devices will automatically promote = receive > + filter settings if the requested setting can not be honored. For ex= ample, if > + a request for four multicast addresses is made and the underlying h= ardware > + only supports two multicast addresses the driver might set the prom= iscuous > + or promiscuous multicast receive filters instead. The receiving sof= tware is > + responsible for discarding any extra packets that get through the h= ardware > + receive filters. > + Note: Note: To disable all receive filter hardware, the network dri= ver must > + be Shutdown() and Stopped(). Calling ReceiveFilters() with Disabl= e set to > + Snp->Mode->ReceiveFilterSettings will make it so no more packets = are > + returned by the Receive() function, but the receive hardware may = still be > + moving packets into system memory before inspecting and discardin= g them. > + Unexpected system errors, reboots and hangs can occur if an OS is= loaded > + and the network devices are not Shutdown() and Stopped(). > + If ResetMCastFilter is TRUE, then the multicast receive filter list o= n the > + network interface will be reset to the default multicast receive filt= er list. > + If ResetMCastFilter is FALSE, and this network interface allows the m= ulticast > + receive filter list to be modified, then the MCastFilterCnt and MCast= Filter > + are used to update the current multicast receive filter list. The mod= ified > + receive filter list settings can be found in the MCastFilter field of > + EFI_SIMPLE_NETWORK_MODE. If the network interface does not allow the = multicast > + receive filter list to be modified, then EFI_INVALID_PARAMETER will b= e returned. > + If the driver has not been initialized, EFI_DEVICE_ERROR will be retu= rned. > + If the receive filter mask and multicast receive filter list have bee= n > + successfully updated on the network interface, EFI_SUCCESS will be re= turned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL = instance. > + @param Enable A bit mask of receive filters to enable on th= e network > + interface. > + @param Disable A bit mask of receive filters to disable on t= he network > + interface. For backward compatibility with EF= I 1.1 > + platforms, the EFI_SIMPLE_NETWORK_RECEIVE_MUL= TICAST bit > + must be set when the ResetMCastFilter paramet= er is TRUE. > + @param ResetMCastFilter Set to TRUE to reset the contents of the mult= icast > + receive filters on the network interface to t= heir > + default values. > + @param MCastFilterCnt Number of multicast HW MAC addresses in the n= ew MCastFilter > + list. This value must be less than or equal t= o the > + MCastFilterCnt field of EFI_SIMPLE_NETWORK_MO= DE. > + This field is optional if ResetMCastFilter is= TRUE. > + @param MCastFilter A pointer to a list of new multicast receive = filter HW > + MAC addresses. This list will replace any exi= sting > + multicast HW MAC address list. This field is = optional > + if ResetMCastFilter is TRUE. > + > + @retval EFI_SUCCESS The multicast receive filter list was = updated. > + @retval EFI_NOT_STARTED The network interface has not been sta= rted. > + @retval EFI_INVALID_PARAMETER One or more of the following condition= s is TRUE: > + * This is NULL > + * There are bits set in Enable that ar= e not set > + in Snp->Mode->ReceiveFilterMask > + * There are bits set in Disable that a= re not set > + in Snp->Mode->ReceiveFilterMask > + * Multicast is being enabled (the > + EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST= bit is > + set in Enable, it is not set in Disa= ble, and > + ResetMCastFilter is FALSE) and MCast= FilterCount > + is zero > + * Multicast is being enabled and MCast= FilterCount > + is greater than Snp->Mode->MaxMCastF= ilterCount > + * Multicast is being enabled and MCast= Filter is NULL > + * Multicast is being enabled and one o= r more of > + the addresses in the MCastFilter lis= t are not > + valid multicast MAC addresses > + @retval EFI_DEVICE_ERROR One or more of the following condition= s is TRUE: > + * The network interface has been start= ed but has > + not been initialized > + * An unexpected error was returned by = the > + underlying network driver or device > + @retval EFI_UNSUPPORTED This function is not supported by the = network > + interface. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpReceiveFilters ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + IN UINT32 Enable, > + IN UINT32 Disable, > + IN BOOLEAN ResetMCastFilter, > + IN UINTN MCastFilterCnt OPTIONAL, > + IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL > + ) > +{ > + UINT32 ReceiveFilterSetting; > + SIMPLE_NETWORK_DRIVER *Snp; > + > + Snp =3D INSTANCE_FROM_SNP_THIS (This); > + > + // Check Snp Instance > + if (Snp =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + // Check that driver was started and initialised > + if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStarted) { > + return EFI_DEVICE_ERROR; > + } else if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStopped) { > + return EFI_NOT_STARTED; > + } > + > + // Check that bits set in Enable/Disable are set in ReceiveFilterMask > + if ((Enable & (~Snp->SnpMode.ReceiveFilterMask)) || > + (Disable & (~Snp->SnpMode.ReceiveFilterMask)) ) { > + return EFI_INVALID_PARAMETER; > + } > + > + // Get the filter mask bits that are set in Enable parameter or Disab= le Parameter > + // Same bits that are set in Enable/Disable parameters, then bits in = the Disable parameter takes precedance > + ReceiveFilterSetting =3D (Snp->SnpMode.ReceiveFilterSetting | Enable)= & (~Disable); > + > + EmacRxFilters (ReceiveFilterSetting, ResetMCastFilter, MCastFilterCnt= , MCastFilter, Snp->MacBase); > + > + return EFI_SUCCESS; > +} > + > + > +/** > + Modifies or resets the current station address, if supported. > + > + This function modifies or resets the current station address of a net= work > + interface, if supported. If Reset is TRUE, then the current station a= ddress is > + set to the network interface's permanent address. If Reset is FALSE, = and the > + network interface allows its station address to be modified, then the= current > + station address is changed to the address specified by New. If the ne= twork > + interface does not allow its station address to be modified, then > + EFI_INVALID_PARAMETER will be returned. If the station address is suc= cessfully > + updated on the network interface, EFI_SUCCESS will be returned. If th= e driver > + has not been initialized, EFI_DEVICE_ERROR will be returned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance= . > + @param Reset Flag used to reset the station address to the network= interface's > + permanent address. > + @param NewMac New station address to be used for the network interf= ace. > + > + > + @retval EFI_SUCCESS The network interface's station address= was updated. > + @retval EFI_NOT_STARTED The Simple Network Protocol interface h= as not been > + started by calling Start(). > + @retval EFI_INVALID_PARAMETER The New station address was not accepte= d by the NIC. > + @retval EFI_INVALID_PARAMETER Reset is FALSE and New is NULL. > + @retval EFI_DEVICE_ERROR The Simple Network Protocol interface h= as not > + been initialized by calling Initialize(= ). > + @retval EFI_DEVICE_ERROR An error occurred attempting to set the= new > + station address. > + @retval EFI_UNSUPPORTED The NIC does not support changing the n= etwork > + interface's station address. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpStationAddress ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + IN BOOLEAN Reset, > + IN EFI_MAC_ADDRESS *NewMac > +) > +{ > + return EFI_UNSUPPORTED; > +} > + > + > + > +/** > + Resets or collects the statistics on a network interface. > + > + This function resets or collects the statistics on a network interfac= e. If the > + size of the statistics table specified by StatisticsSize is not big e= nough for > + all the statistics that are collected by the network interface, then = a partial > + buffer of statistics is returned in StatisticsTable, StatisticsSize i= s set to > + the size required to collect all the available statistics, and > + EFI_BUFFER_TOO_SMALL is returned. > + If StatisticsSize is big enough for all the statistics, then Statisti= csTable > + will be filled, StatisticsSize will be set to the size of the returne= d > + StatisticsTable structure, and EFI_SUCCESS is returned. > + If the driver has not been initialized, EFI_DEVICE_ERROR will be retu= rned. > + If Reset is FALSE, and both StatisticsSize and StatisticsTable are NU= LL, then > + no operations will be performed, and EFI_SUCCESS will be returned. > + If Reset is TRUE, then all of the supported statistics counters on th= is network > + interface will be reset to zero. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL i= nstance. > + @param Reset Set to TRUE to reset the statistics for the ne= twork interface. > + @param StatSize On input the size, in bytes, of StatisticsTabl= e. On output > + the size, in bytes, of the resulting table of = statistics. > + @param Statistics A pointer to the EFI_NETWORK_STATISTICS struct= ure that > + contains the statistics. Type EFI_NETWORK_STAT= ISTICS is > + defined in "Related Definitions" below. > + > + @retval EFI_SUCCESS The requested operation succeeded. > + @retval EFI_NOT_STARTED The Simple Network Protocol interface h= as not been > + started by calling Start(). > + @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and Statisti= csTable is > + NULL. The current buffer size that is n= eeded to > + hold all the statistics is returned in = StatisticsSize. > + @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and Statisti= csTable is > + not NULL. The current buffer size that = is needed > + to hold all the statistics is returned = in > + StatisticsSize. A partial set of statis= tics is > + returned in StatisticsTable. > + @retval EFI_INVALID_PARAMETER StatisticsSize is NULL and StatisticsTa= ble is not > + NULL. > + @retval EFI_DEVICE_ERROR The Simple Network Protocol interface h= as not > + been initialized by calling Initialize(= ). > + @retval EFI_DEVICE_ERROR An error was encountered collecting sta= tistics > + from the NIC. > + @retval EFI_UNSUPPORTED The NIC does not support collecting sta= tistics > + from the network interface. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpStatistics ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + IN BOOLEAN Reset, > + IN OUT UINTN *StatSize, > + OUT EFI_NETWORK_STATISTICS *Statistics > + ) > +{ > + > + SIMPLE_NETWORK_DRIVER *Snp; > + > + Snp =3D INSTANCE_FROM_SNP_THIS (This); > + > + DEBUG ((DEBUG_INFO, "SNP:DXE: %a ()\r\n", __FUNCTION__)); > + > + // Check Snp instance > + if (This =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + // Check that driver was started and initialised > + if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStarted) { > + return EFI_DEVICE_ERROR; > + } else if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStopped) { > + return EFI_NOT_STARTED; > + } > + > + // Check the parameters > + if ((StatSize =3D=3D NULL) && (Statistics !=3D NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + // Do a reset if required > + if (Reset) { > + ZeroMem (&Snp->Stats, sizeof(EFI_NETWORK_STATISTICS)); > + } > + > + // Check buffer size > + if (*StatSize < sizeof(EFI_NETWORK_STATISTICS)) { > + *StatSize =3D sizeof(EFI_NETWORK_STATISTICS); > + return EFI_BUFFER_TOO_SMALL; > + } > + > + // read statistic counters > + EmacGetStatistic (&Snp->Stats, Snp->MacBase); > + > + // Fill in the statistics > + CopyMem (&Statistics, &Snp->Stats, sizeof(EFI_NETWORK_STATISTICS)); > + > + return EFI_SUCCESS; > +} > + > + > +/** > + Converts a multicast IP address to a multicast HW MAC address. > + > + This function converts a multicast IP address to a multicast HW MAC a= ddress > + for all packet transactions. If the mapping is accepted, then EFI_SUC= CESS will > + be returned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL insta= nce. > + @param IsIpv6 Set to TRUE if the multicast IP address is IPv6 [R= FC 2460]. > + Set to FALSE if the multicast IP address is IPv4 [= RFC 791]. > + @param Ip The multicast IP address that is to be converted t= o a multicast > + HW MAC address. > + @param McastMac The multicast HW MAC address that is to be generat= ed from IP. > + > + @retval EFI_SUCCESS The multicast IP address was mapped to = the > + multicast HW MAC address. > + @retval EFI_NOT_STARTED The Simple Network Protocol interface h= as not > + been started by calling Start(). > + @retval EFI_INVALID_PARAMETER IP is NULL. > + @retval EFI_INVALID_PARAMETER MAC is NULL. > + @retval EFI_INVALID_PARAMETER IP does not point to a valid IPv4 or IP= v6 > + multicast address. > + @retval EFI_DEVICE_ERROR The Simple Network Protocol interface h= as not > + been initialized by calling Initialize(= ). > + @retval EFI_UNSUPPORTED IPv6 is TRUE and the implementation doe= s not > + support IPv6 multicast to MAC address c= onversion. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpMcastIptoMac ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + IN BOOLEAN IsIpv6, > + IN EFI_IP_ADDRESS *Ip, > + OUT EFI_MAC_ADDRESS *McastMac > + ) > +{ > + > + DEBUG ((DEBUG_INFO, "SNP:DXE: %a ()\r\n", __FUNCTION__)); > + > + // Check Snp instance > + if (This =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + SIMPLE_NETWORK_DRIVER *Snp; > + > + Snp =3D INSTANCE_FROM_SNP_THIS (This); > + > + // Check that driver was started and initialised > + if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStarted) { > + return EFI_DEVICE_ERROR; > + } else if (Snp->SnpMode.State =3D=3D EfiSimpleNetworkStopped) { > + return EFI_NOT_STARTED; > + } > + > + // Check parameters > + if ((McastMac =3D=3D NULL) || (Ip =3D=3D NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + // Make sure MAC address is empty > + ZeroMem (McastMac, sizeof(EFI_MAC_ADDRESS)); > + > + // If we need ipv4 address > + if (!IsIpv6) { > + // Most significant 25 bits of a multicast HW address are set. > + // 01-00-5E is the IPv4 Ethernet Multicast Address (see RFC 1112) > + McastMac->Addr[0] =3D 0x01; > + McastMac->Addr[1] =3D 0x00; > + McastMac->Addr[2] =3D 0x5E; > + > + // Lower 23 bits from ipv4 address > + McastMac->Addr[3] =3D (Ip->v4.Addr[1] & 0x7F); // Clear the most si= gnificant bit (25th bit of MAC must be 0) > + McastMac->Addr[4] =3D Ip->v4.Addr[2]; > + McastMac->Addr[5] =3D Ip->v4.Addr[3]; > + } else { > + // Most significant 16 bits of multicast v6 HW address are set > + // 33-33 is the IPv6 Ethernet Multicast Address (see RFC 2464) > + McastMac->Addr[0] =3D 0x33; > + McastMac->Addr[1] =3D 0x33; > + > + // lower four octets are taken from ipv6 address > + McastMac->Addr[2] =3D Ip->v6.Addr[8]; > + McastMac->Addr[3] =3D Ip->v6.Addr[9]; > + McastMac->Addr[4] =3D Ip->v6.Addr[10]; > + McastMac->Addr[5] =3D Ip->v6.Addr[11]; > + } > + > + return EFI_SUCCESS; > +} > + > + > +/** > + Performs read and write operations on the NVRAM device attached to a = network > + interface. > + > + This function performs read and write operations on the NVRAM device = attached > + to a network interface. If ReadWrite is TRUE, a read operation is per= formed. > + If ReadWrite is FALSE, a write operation is performed. Offset specifi= es the > + byte offset at which to start either operation. Offset must be a mult= iple of > + NvRamAccessSize , and it must have a value between zero and NvRamSize= . > + BufferSize specifies the length of the read or write operation. Buffe= rSize must > + also be a multiple of NvRamAccessSize, and Offset + BufferSize must n= ot exceed > + NvRamSize. > + If any of the above conditions is not met, then EFI_INVALID_PARAMETER= will be > + returned. > + If all the conditions are met and the operation is "read," the NVRAM = device > + attached to the network interface will be read into Buffer and EFI_SU= CCESS > + will be returned. If this is a write operation, the contents of Buffe= r will be > + used to update the contents of the NVRAM device attached to the netwo= rk > + interface and EFI_SUCCESS will be returned. > + > + It does the basic checking on the input parameters and retrieves snp = structure > + and then calls the read_nvdata() call which does the actual reading > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instan= ce. > + @param ReadWrite TRUE for read operations, FALSE for write operation= s. > + @param Offset Byte offset in the NVRAM device at which to start t= he read or > + write operation. This must be a multiple of NvRamAc= cessSize > + and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MO= DE) > + @param BufferSize The number of bytes to read or write from the NVRAM= device. > + This must also be a multiple of NvramAccessSize. > + @param Buffer A pointer to the data buffer. > + > + @retval EFI_SUCCESS The NVRAM access was performed. > + @retval EFI_NOT_STARTED The network interface has not been star= ted. > + @retval EFI_INVALID_PARAMETER One or more of the following conditions= is TRUE: > + * The This parameter is NULL > + * The This parameter does not point to = a valid > + EFI_SIMPLE_NETWORK_PROTOCOL structur= e > + * The Offset parameter is not a multipl= e of > + EFI_SIMPLE_NETWORK_MODE.NvRamAccessSi= ze > + * The Offset parameter is not less than > + EFI_SIMPLE_NETWORK_MODE.NvRamSize > + * The BufferSize parameter is not a mul= tiple of > + EFI_SIMPLE_NETWORK_MODE.NvRamAccessSi= ze > + * The Buffer parameter is NULL > + @retval EFI_DEVICE_ERROR The command could not be sent to the ne= twork > + interface. > + @retval EFI_UNSUPPORTED This function is not supported by the n= etwork > + interface. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpNvData ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + IN BOOLEAN ReadWrite, > + IN UINTN Offset, > + IN UINTN BufferSize, > + IN OUT VOID *Buffer > + ) > +{ > + return EFI_UNSUPPORTED; > +} > + > + > +/** > + Reads the current interrupt status and recycled transmit buffer statu= s from a > + network interface. > + > + This function gets the current interrupt and recycled transmit buffer= status > + from the network interface. The interrupt status is returned as a bit= mask in > + InterruptStatus. If InterruptStatus is NULL, the interrupt status wil= l not be > + read. If TxBuf is not NULL, a recycled transmit buffer address will b= e retrieved. > + If a recycled transmit buffer address is returned in TxBuf, then the = buffer has > + been successfully transmitted, and the status for that buffer is clea= red. If > + the status of the network interface is successfully collected, EFI_SU= CCESS > + will be returned. If the driver has not been initialized, EFI_DEVICE_= ERROR will > + be returned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL i= nstance. > + @param IrqStat A pointer to the bit mask of the currently act= ive > + interrupts (see "Related Definitions"). If thi= s is NULL, > + the interrupt status will not be read from the= device. > + If this is not NULL, the interrupt status will= be read > + from the device. When the interrupt status is = read, it > + will also be cleared. Clearing the transmit in= terrupt does > + not empty the recycled transmit buffer array. > + @param TxBuff Recycled transmit buffer address. The network = interface > + will not transmit if its internal recycled tra= nsmit > + buffer array is full. Reading the transmit buf= fer does > + not clear the transmit interrupt. If this is N= ULL, then > + the transmit buffer status will not be read. I= f there > + are no transmit buffers to recycle and TxBuf i= s not NULL, > + TxBuf will be set to NULL. > + > + @retval EFI_SUCCESS The status of the network interface was= retrieved. > + @retval EFI_NOT_STARTED The network interface has not been star= ted. > + @retval EFI_INVALID_PARAMETER This parameter was NULL or did not poin= t to a valid > + EFI_SIMPLE_NETWORK_PROTOCOL structure. > + @retval EFI_DEVICE_ERROR The command could not be sent to the ne= twork > + interface. > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpGetStatus ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + OUT UINT32 *IrqStat OPTIONAL, > + OUT VOID **TxBuff OPTIONAL > + ) > +{ > + EFI_STATUS Status; > + SIMPLE_NETWORK_DRIVER *Snp; > + > + Snp =3D INSTANCE_FROM_SNP_THIS (This); > + > + // Check preliminaries > + if (This =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + if (Snp->SnpMode.State !=3D EfiSimpleNetworkInitialized) { > + return EFI_NOT_STARTED; > + } > + > + // Update the media status > + Status =3D PhyLinkAdjustEmacConfig (&Snp->PhyDriver, Snp->MacBase); > + if (EFI_ERROR(Status)) { > + Snp->SnpMode.MediaPresent =3D FALSE; > + } else { > + Snp->SnpMode.MediaPresent =3D TRUE; > + } > + > + // TxBuff > + if (TxBuff !=3D NULL) { > + // > + // Get a recycled buf from Snp->RecycledTxBuf > + // > + if (Snp->RecycledTxBufCount =3D=3D 0) { > + *TxBuff =3D NULL; > + } else { > + Snp->RecycledTxBufCount--; > + *TxBuff =3D (VOID *)(UINTN) Snp->RecycledTxBuf[Snp->RecycledTxBuf= Count]; > + } > + } > + > + // Check DMA Irq status > + EmacGetDmaStatus (IrqStat, Snp->MacBase); > + > + return EFI_SUCCESS; > +} > + > + > +/** > + Places a packet in the transmit queue of a network interface. > + > + This function places the packet specified by Header and Buffer on the= transmit > + queue. If HeaderSize is nonzero and HeaderSize is not equal to > + This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be retur= ned. If > + BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_= TOO_SMALL > + will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will = be > + returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, = then > + EFI_INVALID_PARAMETER will be returned. If the transmit engine of the= network > + interface is busy, then EFI_NOT_READY will be returned. If this packe= t can be > + accepted by the transmit engine of the network interface, the packet = contents > + specified by Buffer will be placed on the transmit queue of the netwo= rk > + interface, and EFI_SUCCESS will be returned. GetStatus() can be used = to > + determine when the packet has actually been transmitted. The contents= of the > + Buffer must not be modified until the packet has actually been transm= itted. > + The Transmit() function performs nonblocking I/O. A caller who wants = to perform > + blocking I/O, should call Transmit(), and then GetStatus() until the > + transmitted buffer shows up in the recycled transmit buffer. > + If the driver has not been initialized, EFI_DEVICE_ERROR will be retu= rned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instan= ce. > + @param HdrSize The size, in bytes, of the media header to be fille= d in by the > + Transmit() function. If HeaderSize is nonzero, then= it must > + be equal to This->Mode->MediaHeaderSize and the Des= tAddr and > + Protocol parameters must not be NULL. > + @param BuffSize The size, in bytes, of the entire packet (media hea= der and > + data) to be transmitted through the network interfa= ce. > + @param Data A pointer to the packet (media header followed by d= ata) to be > + transmitted. This parameter cannot be NULL. If Head= erSize is > + zero, then the media header in Buffer must already = be filled > + in by the caller. If HeaderSize is nonzero, then th= e media > + header will be filled in by the Transmit() function= . > + @param SrcAddr The source HW MAC address. If HeaderSize is zero, t= hen this > + parameter is ignored. If HeaderSize is nonzero and = SrcAddr > + is NULL, then This->Mode->CurrentAddress is used fo= r the > + source HW MAC address. > + @param DstAddr The destination HW MAC address. If HeaderSize is ze= ro, then > + this parameter is ignored. > + @param Protocol The type of header to build. If HeaderSize is zero,= then this > + parameter is ignored. See RFC 1700, section "Ether = Types," > + for examples. > + > + @retval EFI_SUCCESS The packet was placed on the transmit q= ueue. > + @retval EFI_NOT_STARTED The network interface has not been star= ted. > + @retval EFI_NOT_READY The network interface is too busy to ac= cept this > + transmit request. > + @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small. > + @retval EFI_INVALID_PARAMETER One or more of the parameters has an un= supported > + value. > + @retval EFI_DEVICE_ERROR The command could not be sent to the ne= twork interface. > + @retval EFI_UNSUPPORTED This function is not supported by the n= etwork interface. > + @retval EFI_ACCESS_DENIED Error acquire global lock for operation= . > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpTransmit ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + IN UINTN HdrSize, > + IN UINTN BuffSize, > + IN VOID *Data, > + IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL, > + IN EFI_MAC_ADDRESS *DstAddr OPTIONAL, > + IN UINT16 *Protocol OPTIONAL > + ) > +{ > + SIMPLE_NETWORK_DRIVER *Snp; > + UINT32 DescNum; > + DESIGNWARE_HW_DESCRIPTOR *TxDescriptor; > + DESIGNWARE_HW_DESCRIPTOR *TxDescriptorMap; > + UINT8 *EthernetPacket; > + UINT64 *Tmp; > + EFI_STATUS Status; > + UINTN BufferSizeBuf; > + EFI_PHYSICAL_ADDRESS TxBufferAddrMap; > + > + BufferSizeBuf =3D ETH_BUFSIZE; > + EthernetPacket =3D Data; > + > + Snp =3D INSTANCE_FROM_SNP_THIS (This); > + > + if (EFI_ERROR (EfiAcquireLockOrFail (&Snp->Lock))) { > + return EFI_ACCESS_DENIED; > + } > + > + if ((Snp->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASE) >=3D SNP_MAX_TX_= BUFFER_NUM) { > + return EFI_NOT_READY; > + } > + > + // Check preliminaries > + if ((This =3D=3D NULL) || (Data =3D=3D NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + if (Snp->SnpMode.State !=3D EfiSimpleNetworkInitialized) { > + return EFI_NOT_STARTED; > + } > + > + Snp->MacDriver.TxCurrentDescriptorNum =3D Snp->MacDriver.TxNextDescri= ptorNum; > + DescNum =3D Snp->MacDriver.TxCurrentDescriptorNum; > + > + TxDescriptor =3D Snp->MacDriver.TxdescRing[DescNum]; > + TxDescriptorMap =3D (VOID *)Snp->MacDriver.TxdescRingMap[DescNum].Add= rMap; > + > + // Ensure header is correct size if non-zero > + if (HdrSize) { > + if (HdrSize !=3D Snp->SnpMode.MediaHeaderSize) { > + return EFI_INVALID_PARAMETER; > + } > + > + if ((DstAddr =3D=3D NULL) || (Protocol =3D=3D NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + } > + > + // Ensure buffer size is valid > + if (BuffSize < Snp->SnpMode.MediaHeaderSize) { > + return EFI_BUFFER_TOO_SMALL; > + } > + > + if (HdrSize) { > + EthernetPacket[0] =3D DstAddr->Addr[0]; > + EthernetPacket[1] =3D DstAddr->Addr[1]; > + EthernetPacket[2] =3D DstAddr->Addr[2]; > + EthernetPacket[3] =3D DstAddr->Addr[3]; > + EthernetPacket[4] =3D DstAddr->Addr[4]; > + EthernetPacket[5] =3D DstAddr->Addr[5]; > + > + EthernetPacket[6] =3D SrcAddr->Addr[0]; > + EthernetPacket[7] =3D SrcAddr->Addr[1]; > + EthernetPacket[8] =3D SrcAddr->Addr[2]; > + EthernetPacket[9] =3D SrcAddr->Addr[3]; > + EthernetPacket[10] =3D SrcAddr->Addr[4]; > + EthernetPacket[11] =3D SrcAddr->Addr[5]; > + > + EthernetPacket[13] =3D *Protocol & 0xFF; > + EthernetPacket[12] =3D (*Protocol & 0xFF00) >> 8; > + } > + > + CopyMem ((VOID *)(UINTN)TxDescriptor->Addr, EthernetPacket, BuffSize)= ; > + > + Status =3D DmaMap (MapOperationBusMasterRead, (VOID *)(UINTN)TxDescri= ptor->Addr, &BufferSizeBuf, &TxBufferAddrMap, &Snp->MappingTxbuf); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a () for Txbuffer: %r\n", __FUNCTION__, Stat= us)); > + return Status; > + } > + TxDescriptorMap->Addr =3D TxBufferAddrMap; > + > + TxDescriptor->Tdes1 =3D (BuffSize << TDES1_SIZE1SHFT) & > + TDES1_SIZE1MASK; > + > + TxDescriptor->Tdes0 |=3D (TDES0_TXFIRST | > + TDES0_TXLAST | > + TDES0_OWN); > + > + // Increase descriptor number > + DescNum++; > + > + if (DescNum >=3D CONFIG_TX_DESCR_NUM) { > + DescNum =3D 0; > + } > + > + Snp->MacDriver.TxNextDescriptorNum =3D DescNum; > + > + if (Snp->RecycledTxBufCount < Snp->MaxRecycledTxBuf) { > + Snp->RecycledTxBuf[Snp->RecycledTxBufCount] =3D (UINT64) Data; > + Snp->RecycledTxBufCount ++; > + } else { > + Tmp =3D AllocatePool (sizeof (UINT64) * (Snp->MaxRecycledTxBuf + SN= P_TX_BUFFER_INCREASE)); > + if (Tmp =3D=3D NULL) { > + return EFI_DEVICE_ERROR; > + } > + CopyMem (Tmp, Snp->RecycledTxBuf, sizeof (UINT64) * Snp->RecycledTx= BufCount); > + FreePool (Snp->RecycledTxBuf); > + Snp->RecycledTxBuf =3D Tmp; > + Snp->MaxRecycledTxBuf +=3D SNP_TX_BUFFER_INCREASE; > + } > + > + // Start the transmission > + EmacDmaStart (Snp->MacBase); > + > + DmaUnmap (Snp->MappingTxbuf); > + EfiReleaseLock (&Snp->Lock); > + return EFI_SUCCESS; > +} > + > +/** > + Receives a packet from a network interface. > + > + This function retrieves one packet from the receive queue of a networ= k interface. > + If there are no packets on the receive queue, then EFI_NOT_READY will= be > + returned. If there is a packet on the receive queue, and the size of = the packet > + is smaller than BufferSize, then the contents of the packet will be p= laced in > + Buffer, and BufferSize will be updated with the actual size of the pa= cket. > + In addition, if SrcAddr, DestAddr, and Protocol are not NULL, then th= ese values > + will be extracted from the media header and returned. EFI_SUCCESS wil= l be > + returned if a packet was successfully received. > + If BufferSize is smaller than the received packet, then the size of t= he receive > + packet will be placed in BufferSize and EFI_BUFFER_TOO_SMALL will be = returned. > + If the driver has not been initialized, EFI_DEVICE_ERROR will be retu= rned. > + > + @param Snp A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instan= ce. > + @param HdrSize The size, in bytes, of the media header received on= the network > + interface. If this parameter is NULL, then the medi= a header size > + will not be returned. > + @param BuffSize On entry, the size, in bytes, of Buffer. On exit, t= he size, in > + bytes, of the packet that was received on the netwo= rk interface. > + @param Data A pointer to the data buffer to receive both the me= dia > + header and the data. > + @param SrcAddr The source HW MAC address. If this parameter is NUL= L, the HW > + MAC source address will not be extracted from the m= edia header. > + @param DstAddr The destination HW MAC address. If this parameter is= NULL, > + the HW MAC destination address will not be extracte= d from > + the media header. > + @param Protocol The media header type. If this parameter is NULL, t= hen the > + protocol will not be extracted from the media heade= r. See > + RFC 1700 section "Ether Types" for examples. > + > + @retval EFI_SUCCESS The received data was stored in Buffer,= and > + BufferSize has been updated to the numb= er of > + bytes received. > + @retval EFI_NOT_STARTED The network interface has not been star= ted. > + @retval EFI_NOT_READY No packets have been received on the ne= twork interface. > + @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the receive= d packets. > + BufferSize has been updated to the requ= ired size. > + @retval EFI_INVALID_PARAMETER One or more of the following conditions= is TRUE: > + * The This parameter is NULL > + * The This parameter does not point to = a valid > + EFI_SIMPLE_NETWORK_PROTOCOL structure= . > + * The BufferSize parameter is NULL > + * The Buffer parameter is NULL > + @retval EFI_DEVICE_ERROR The command could not be sent to the ne= twork interface. > + @retval EFI_ACCESS_DENIED Error acquire global lock for operation= . > + > +**/ > +EFI_STATUS > +EFIAPI > +SnpReceive ( > + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, > + OUT UINTN *HdrSize OPTIONAL, > + IN OUT UINTN *BuffSize, > + OUT VOID *Data, > + OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL, > + OUT EFI_MAC_ADDRESS *DstAddr OPTIONAL, > + OUT UINT16 *Protocol OPTIONAL > + ) > +{ > + SIMPLE_NETWORK_DRIVER *Snp; > + EFI_MAC_ADDRESS Dst; > + EFI_MAC_ADDRESS Src; > + UINT32 Length; > + UINT32 DescriptorStatus; > + UINT8 *RawData; > + UINT32 DescNum; > + DESIGNWARE_HW_DESCRIPTOR *RxDescriptor; > + DESIGNWARE_HW_DESCRIPTOR *RxDescriptorMap; > + UINTN BufferSizeBuf; > + UINTN *RxBufferAddr; > + EFI_PHYSICAL_ADDRESS RxBufferAddrMap; > + EFI_STATUS Status; > + > + BufferSizeBuf =3D ETH_BUFSIZE; > + > + Snp =3D INSTANCE_FROM_SNP_THIS (This); > + > + // Check preliminaries > + if ((This =3D=3D NULL) || (Data =3D=3D NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (Snp->SnpMode.State !=3D EfiSimpleNetworkInitialized) { > + return EFI_NOT_STARTED; > + } > + > + if (EFI_ERROR (EfiAcquireLockOrFail (&Snp->Lock))) { > + return EFI_ACCESS_DENIED; > + } > + > + Snp->MacDriver.RxCurrentDescriptorNum =3D Snp->MacDriver.RxNextDescri= ptorNum; > + DescNum =3D Snp->MacDriver.RxCurrentDescriptorNum; > + RxDescriptor =3D Snp->MacDriver.RxdescRing[DescNum]; > + RxBufferAddr =3D (VOID *)Snp->MacDriver.RxBuffer + (DescNum * BufferS= izeBuf); > + RxDescriptorMap =3D (VOID *)Snp->MacDriver.RxdescRingMap[DescNum].Add= rMap; > + > + RawData =3D (UINT8 *) Data; > + > + DescriptorStatus =3D RxDescriptor->Tdes0; > + if (DescriptorStatus & ((UINT32)RDES0_OWN)) { > + goto ReleaseLock; > + } > + > + if (DescriptorStatus & RDES0_SAF) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: Source Ad= dress Filter Fail\n")); > + return EFI_DEVICE_ERROR; > + } > + > + if (DescriptorStatus & RDES0_AFM) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: Destinati= on Address Filter Fail\n")); > + return EFI_DEVICE_ERROR; > + } > + > + if (DescriptorStatus & RDES0_ES) { > + // Check for errors > + if (DescriptorStatus & RDES0_RE) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: Receive= Error\n")); > + } > + if (DescriptorStatus & RDES0_DE) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: Receive= Error\n")); > + } > + if (DescriptorStatus & RDES0_RWT) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: Watchdo= g Timeout\n")); > + } > + if (DescriptorStatus & RDES0_LC) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: Late Co= llision\n")); > + } > + if (DescriptorStatus & RDES0_GF) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: Giant F= rame\n")); > + } > + if (DescriptorStatus & RDES0_OE) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: Overflo= w Error\n")); > + } > + if (DescriptorStatus & RDES0_LE) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error:Length E= rror\n")); > + } > + if (DescriptorStatus & RDES0_DBE) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: Dribble= Bit Error\n")); > + } > + > + // Check descriptor error status > + if (DescriptorStatus & RDES0_CE) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Rx Descritpor Status Error: CRC Err= or\n")); > + } > + return EFI_DEVICE_ERROR; > + } > + > + Length =3D (DescriptorStatus >> RDES0_FL_SHIFT) & RDES0_FL_MASK; > + if (!Length) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Error: Invalid Frame Packet length \r= \n")); > + return EFI_NOT_READY; > + } > + // Check buffer size > + if (*BuffSize < Length) { > + DEBUG ((DEBUG_WARN, "SNP:DXE: Error: Buffer size is too small\n")); > + return EFI_BUFFER_TOO_SMALL; > + } > + *BuffSize =3D Length; > + > + if (HdrSize !=3D NULL) > + *HdrSize =3D Snp->SnpMode.MediaHeaderSize; > + > + DmaUnmap (Snp->MacDriver.RxBufNum[DescNum].Mapping); > + Snp->MacDriver.RxBufNum[DescNum].Mapping =3D NULL; > + > + CopyMem (RawData, (VOID *)RxBufferAddr, *BuffSize); > + > + if (DstAddr !=3D NULL) { > + Dst.Addr[0] =3D RawData[0]; > + Dst.Addr[1] =3D RawData[1]; > + Dst.Addr[2] =3D RawData[2]; > + Dst.Addr[3] =3D RawData[3]; > + Dst.Addr[4] =3D RawData[4]; > + Dst.Addr[5] =3D RawData[5]; > + CopyMem (DstAddr, &Dst, NET_ETHER_ADDR_LEN); > + DEBUG ((DEBUG_INFO, "received from source address %x %x\r\n", DstAd= dr, &Dst)); > + } > +=20 > + // Get the source address > + if (SrcAddr !=3D NULL) { > + Src.Addr[0] =3D RawData[6]; > + Src.Addr[1] =3D RawData[7]; > + Src.Addr[2] =3D RawData[8]; > + Src.Addr[3] =3D RawData[9]; > + Src.Addr[4] =3D RawData[10]; > + Src.Addr[5] =3D RawData[11]; > + DEBUG ((DEBUG_INFO, "received from source address %x %x\r\n", SrcAd= dr, &Src)); > + CopyMem (SrcAddr, &Src, NET_ETHER_ADDR_LEN); > + } > + > + // Get the protocol > + if (Protocol !=3D NULL) { > + *Protocol =3D NTOHS (RawData[12] | (RawData[13] >> 8) | (RawData[14= ] >> 16) | (RawData[15] >> 24)); > + } > + > + // DMA map for the current receive buffer > + Status =3D DmaMap (MapOperationBusMasterWrite, (VOID *)RxBufferAddr,= &BufferSizeBuf, &RxBufferAddrMap, &Snp->MacDriver.RxBufNum[DescNum].Mappin= g); Please wrap very long line. > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a () for Rxbuffer: %r\n", __FUNCTION__, Stat= us)); > + return Status; > + } > + Snp->MacDriver.RxBufNum[DescNum].AddrMap =3D RxBufferAddrMap; > + RxDescriptorMap->Addr =3D Snp->MacDriver.RxBufNum[DescNum].AddrMap; > + > + RxDescriptor->Tdes0 |=3D (UINT32)RDES0_OWN; > + > + // Increase descriptor number > + DescNum++; > + > + if (DescNum >=3D CONFIG_RX_DESCR_NUM) { > + DescNum =3D 0; > + } > + Snp->MacDriver.RxNextDescriptorNum =3D DescNum; > + > + EfiReleaseLock (&Snp->Lock); > + return EFI_SUCCESS; > + > +ReleaseLock: > + EfiReleaseLock (&Snp->Lock); > + return EFI_NOT_READY; > +} > + > diff --git a/Silicon/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.c b/Sil= icon/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.c > new file mode 100755 > index 000000000000..1cf3110ffcfd > --- /dev/null > +++ b/Silicon/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.c > @@ -0,0 +1,683 @@ > +/** @file > + > + Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > + > + The original software modules are licensed as follows: > + > + Copyright (c) 2012 - 2014, ARM Limited. All rights reserved. > + Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved. > + > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD 3 Clause LICENSE ON AN "AS I= S" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > +**/ SPDX. > + > +#include "EmacDxeUtil.h" > +#include "PhyDxeUtil.h" > + > +VOID > +EFIAPI > +EmacSetMacAddress ( > + IN EFI_MAC_ADDRESS *MacAddress, > + IN UINTN MacBaseAddress > + ) > +{ > + DEBUG ((DEBUG_INFO, "SNP:MAC: %a ()\r\n", __FUNCTION__)); > + > + // Note: This MAC_ADDR0 registers programming sequence cannot be swap= : > + // Must program HIGH Offset first before LOW Offset > + // because synchronization is triggered when MAC Address0 Low Registe= r are written. > + MmioWrite32 (MacBaseAddress +DW_EMAC_GMACGRP_MAC_ADDRESS0_HIGH_OFST, > + (UINT32)(MacAddress->Addr[4] & 0xFF) | > + ((MacAddress->Addr[5] & 0xFF) << 8) > + ); > + // MacAddress->Addr[0,1,2] is the 3 bytes OUI > + MmioWrite32 (MacBaseAddress + DW_EMAC_GMACGRP_MAC_ADDRESS0_LOW_OFST, > + (MacAddress->Addr[0] & 0xFF) | > + ((MacAddress->Addr[1] & 0xFF) << 8) | > + ((MacAddress->Addr[2] & 0xFF) << 16) | > + ((MacAddress->Addr[3] & 0xFF) << 24) > + ); > + > + DEBUG ((DEBUG_INFO, "SNP:MAC: gmacgrp_mac_address0_low =3D 0x%08X \r= \n", MmioRead32 (MacBaseAddress + DW_EMAC_GMACGRP_MAC_ADDRESS0_LOW_OFST))); > + DEBUG ((DEBUG_INFO, "SNP:MAC: gmacgrp_mac_address0_high =3D 0x%08X \r= \n", MmioRead32 (MacBaseAddress +DW_EMAC_GMACGRP_MAC_ADDRESS0_HIGH_OFST))); > +} > + > + > +VOID > +EFIAPI > +EmacReadMacAddress ( > + OUT EFI_MAC_ADDRESS *MacAddress, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 MacAddrHighValue; > + UINT32 MacAddrLowValue; > + > + DEBUG ((DEBUG_INFO, "SNP:MAC: %a ()\r\n", __FUNCTION__)); > + > + // Read the Mac Addr high register > + MacAddrHighValue =3D (MmioRead32 (MacBaseAddress + DW_EMAC_GMACGRP_MA= C_ADDRESS0_HIGH_OFST) & 0xFFFF); > + // Read the Mac Addr low register > + MacAddrLowValue =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMACGRP_MAC_= ADDRESS0_LOW_OFST); > + > + SetMem (MacAddress, sizeof(*MacAddress), 0); > + MacAddress->Addr[0] =3D (MacAddrLowValue & 0xFF); > + MacAddress->Addr[1] =3D (MacAddrLowValue & 0xFF00) >> 8; > + MacAddress->Addr[2] =3D (MacAddrLowValue & 0xFF0000) >> 16; > + MacAddress->Addr[3] =3D (MacAddrLowValue & 0xFF000000) >> 24; > + MacAddress->Addr[4] =3D (MacAddrHighValue & 0xFF); > + MacAddress->Addr[5] =3D (MacAddrHighValue & 0xFF00) >> 8; > + > + DEBUG ((DEBUG_INFO, "SNP:MAC: MAC Address =3D %02X:%02X:%02X:%02X:%02= X:%02X\r\n", > + MacAddress->Addr[0], MacAddress->Addr[1], MacAddress->Addr[2], > + MacAddress->Addr[3], MacAddress->Addr[4], MacAddress->Addr[5] > + )); > +} > + > +EFI_STATUS > +EFIAPI > +EmacDxeInitialization ( > + IN EMAC_DRIVER *EmacDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + DEBUG ((DEBUG_INFO, "SNP:MAC: %a ()\r\n", __FUNCTION__)); > + > + // Init EMAC DMA > + EmacDmaInit (EmacDriver, MacBaseAddress); > + > + return EFI_SUCCESS; > +} > + > + > +EFI_STATUS > +EFIAPI > +EmacDmaInit ( > + IN EMAC_DRIVER *EmacDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 DmaConf; > + UINT32 DmaOpmode; > + UINT32 InterruptEnable; > + > + DEBUG ((DEBUG_INFO, "SNP:MAC: %a ()\r\n", __FUNCTION__)); > + > + // This section provides the instructions for initializing the DMA re= gisters in the proper sequence. This > + // initialization sequence can be done after the EMAC interface initi= alization has been completed. Perform > + // the following steps to initialize the DMA: > + // 1. Provide a software reset to reset all of the EMAC internal regi= sters and logic. (DMA Register 0 (Bus > + // Mode Register) ? bit 0). > + > + MmioOr32 (MacBaseAddress + > + DW_EMAC_DMAGRP_BUS_MODE_OFST, > + DW_EMAC_DMAGRP_BUS_MODE_SWR_SET_MSK); > + > + // 2. Wait for the completion of the reset process (poll bit 0 of the= DMA Register 0 (Bus Mode Register), > + // which is only cleared after the reset operation is completed). > + while (DW_EMAC_DMAGRP_BUS_MODE_SWR_GET (MmioRead32 (MacBaseAddress + = DW_EMAC_DMAGRP_BUS_MODE_OFST))); > + > + // 3. Poll the bits of Register 11 (AHB or AXI Status) to confirm tha= t all previously initiated (before > + // software reset) or ongoing transactions are complete. > + // Note: If the application cannot poll the register after soft reset= (because of performance reasons), then > + // it is recommended that you continue with the next steps and check = this register again (as > + // mentioned in 12 on page 1-72) before triggering the DMA operations= .? > + > + // 4. Program the following fields to initialize the Bus Mode Registe= r by setting values in DMA Register 0 > + // (Bus Mode Register): > + // ? Mixed Burst and AAL > + // ? Fixed burst or undefined burst > + // ? Burst length values and burst mode values > + // ? Descriptor Length (only valid if Ring Mode is used) > + // ? TX and RX DMA Arbitration scheme > + // 5. Program the interface options in Register 10 (AXI Bus Mode Regi= ster). If fixed burst-length is enabled, > + // then select the maximum burst-length possible on the bus (bits[7:1= ]).? > + > + DmaConf =3D DW_EMAC_DMAGRP_BUS_MODE_FB_SET_MSK | DW_EMAC_DMAGRP_BUS_M= ODE_PBL_SET_MSK | DW_EMAC_DMAGRP_BUS_MODE_PR_SET_MSK; > + MmioOr32 (MacBaseAddress + > + DW_EMAC_DMAGRP_BUS_MODE_OFST, > + DmaConf); > + > + // 6. Create a proper descriptor chain for transmit and receive. In a= ddition, ensure that the receive descriptors > + // are owned by DMA (bit 31 of descriptor should be set). When OSF mo= de is used, at least two > + // descriptors are required. > + // 7. Make sure that your software creates three or more different tr= ansmit or receive descriptors in the > + // chain before reusing any of the descriptors. > + // 8. Initialize receive and transmit descriptor list address with th= e base address of the transmit and receive > + // descriptor (Register 3 (Receive Descriptor List Address Register) = and Register 4 (Transmit Descriptor > + // List Address Register) respectively). > + > + EmacSetupTxdesc (EmacDriver, MacBaseAddress); > + EmacSetupRxdesc (EmacDriver, MacBaseAddress); > + > + // 9. Program the following fields to initialize the mode of operatio= n in Register 6 (Operation Mode > + // Register): > + // ? Receive and Transmit Store And Forward? > + // ? Receive and Transmit Threshold Control (RTC and TTC)? > + // ? Hardware Flow Control enable? > + // ? Flow Control Activation and De-activation thresholds for MTL Rec= eive and Transmit FIFO buffers > + // (RFA and RFD)? > + // ? Error frame and undersized good frame forwarding enable? > + // ? OSF Mode? > + > + DmaOpmode =3D DW_EMAC_DMAGRP_OPERATION_MODE_FTF_SET_MSK | DW_EMAC_DMA= GRP_OPERATION_MODE_TSF_SET_MSK; > + MmioOr32 (MacBaseAddress + > + DW_EMAC_DMAGRP_OPERATION_MODE_OFST, > + DmaOpmode); > + //while (DW_EMAC_DMAGRP_OPERATION_MODE_FTF_GET (MmioRead32 (MacBaseAd= dress + DW_EMAC_DMAGRP_OPERATION_MODE_OFST))); > +=20 > + // 10.Clear the interrupt requests, by writing to those bits of the s= tatus register (interrupt bits only) that are > + // set. For example, by writing 1 into bit 16, the normal interrupt s= ummary clears this bit (DMA Register 5 (Status Register)). > + MmioOr32 (MacBaseAddress + > + DW_EMAC_DMAGRP_STATUS_OFST, > + 0x1FFFF); > + > + // 11.Enable the interrupts by programming Register 7 (Interrupt Enab= le Register). > + InterruptEnable =3D DW_EMAC_DMAGRP_INTERRUPT_ENABLE_TIE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_RIE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_NIE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_AIE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_FBE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_UNE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_TSE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_TUE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_TJE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_OVE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_RUE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_RSE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_RWE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_ETE_SET_MSK | > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_ERE_SET_MSK; > + MmioWrite32 (MacBaseAddress + > + DW_EMAC_DMAGRP_INTERRUPT_ENABLE_OFST, > + InterruptEnable); > + > + // 12.Read Register 11 (AHB or AXI Status) to confirm that all previo= us transactions are complete.? > + // Note: If any previous transaction is still in progress when you re= ad the Register 11 (AHB or AXI > + // Status), then it is strongly recommended to check the slave compon= ents addressed by the > + // master interface. > + if (MmioRead32 (MacBaseAddress + DW_EMAC_DMAGRP_AHB_OR_AXI_STATUS_OFS= T) !=3D 0) { > + DEBUG ((DEBUG_INFO, "SNP:MAC: Error! Previous AXI transaction is st= ill in progress\r\n")); > + //check the slave components addressed by the master interface > + return EFI_DEVICE_ERROR; > + } > + > + DmaOpmode =3D DW_EMAC_DMAGRP_OPERATION_MODE_ST_SET_MSK | DW_EMAC_DMAG= RP_OPERATION_MODE_SR_SET_MSK; > + MmioOr32 (MacBaseAddress + > + DW_EMAC_DMAGRP_OPERATION_MODE_OFST, > + DmaOpmode); > + > + return EFI_SUCCESS; > +} > + > + > +EFI_STATUS > +EFIAPI > +EmacSetupTxdesc ( > + IN EMAC_DRIVER *EmacDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + INTN Index; > + DESIGNWARE_HW_DESCRIPTOR *TxDescriptor; > + > + for (Index =3D 0; Index < CONFIG_TX_DESCR_NUM; Index++) { > + TxDescriptor =3D (VOID *)EmacDriver->TxdescRingMap[Index].AddrMap; > + TxDescriptor->Addr =3D (UINT32)(UINTN) &EmacDriver->TxBuffer[Index = * CONFIG_ETH_BUFSIZE]; > + TxDescriptor->AddrNext =3D (UINT32)(UINTN) EmacDriver->TxdescRingMa= p[Index + 1].AddrMap Drop space after (UINTN), 2 lines above. > + TxDescriptor->Tdes0 =3D TDES0_TXCHAIN; > + TxDescriptor->Tdes1 =3D 0; > + } > + > + // Correcting the last pointer of the chain > + TxDescriptor->AddrNext =3D (UINT32)(UINTN) EmacDriver->TxdescRingMap[= 0].AddrMap; Drop space after (UINTN). > + > + // Write the address of tx descriptor list > + MmioWrite32 (MacBaseAddress + > + DW_EMAC_DMAGRP_TRANSMIT_DESCRIPTOR_LIST_ADDRESS_OFST, > + (UINT32)(UINTN) EmacDriver->TxdescRingMap[0].AddrMap); Drop space after (UINTN). (Please do a search/replace on (UINT32)(UINTN) below, the pattern repeats a lot.) > + > + // Initialize the descriptor number > + EmacDriver->TxCurrentDescriptorNum =3D 0; > + EmacDriver->TxNextDescriptorNum =3D 0; > + > + return EFI_SUCCESS; > +} > + > + > +EFI_STATUS > +EFIAPI > +EmacSetupRxdesc ( > + IN EMAC_DRIVER *EmacDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + INTN Index; > + DESIGNWARE_HW_DESCRIPTOR *RxDescriptor; > + > + for (Index =3D 0; Index < CONFIG_RX_DESCR_NUM; Index++) { > + RxDescriptor =3D (VOID *)EmacDriver->RxdescRingMap[Index].AddrMap; > + RxDescriptor->Addr =3D EmacDriver->RxBufNum[Index].AddrMap; > + RxDescriptor->AddrNext =3D (UINT32)(UINTN) EmacDriver->RxdescRingMa= p[Index + 1].AddrMap; > + RxDescriptor->Tdes0 =3D RDES0_OWN; > + RxDescriptor->Tdes1 =3D RDES1_CHAINED | RX_MAX_PACKET; > + } > + > + // Correcting the last pointer of the chain > + RxDescriptor->AddrNext =3D (UINT32)(UINTN) EmacDriver->RxdescRingMap[= 0].AddrMap; > + > + // Write the address of tx descriptor list > + MmioWrite32(MacBaseAddress + > + DW_EMAC_DMAGRP_RECEIVE_DESCRIPTOR_LIST_ADDRESS_OFST, > + (UINT32)(UINTN) EmacDriver->RxdescRingMap[0].AddrMap); > + > + // Initialize the descriptor number > + EmacDriver->RxCurrentDescriptorNum =3D 0; > + EmacDriver->RxNextDescriptorNum =3D 0; > + > + return EFI_SUCCESS; > +} > + > + > +VOID > +EFIAPI > +EmacStartTransmission ( > + IN UINTN MacBaseAddress > + ) > +{ > + DEBUG ((DEBUG_INFO, "SNP:MAC: %a ()\r\n", __FUNCTION__)); > + MmioOr32 (MacBaseAddress + > + DW_EMAC_GMACGRP_MAC_CONFIGURATION_OFST, > + DW_EMAC_GMACGRP_MAC_CONFIGURATION_RE_SET_MSK | > + DW_EMAC_GMACGRP_MAC_CONFIGURATION_TE_SET_MSK > + ); > +} > + > + > +EFI_STATUS > +EFIAPI > +EmacRxFilters ( > + IN UINT32 ReceiveFilterSetting, > + IN BOOLEAN Reset, > + IN UINTN NumMfilter OPTIONAL, > + IN EFI_MAC_ADDRESS *Mfilter OPTIONAL, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 MacFilter; > + UINT32 Crc; > + UINT32 Count; > + UINT32 HashReg; > + UINT32 HashBit; > + UINT32 Reg; > + UINT32 Val; > + > + // If reset then clear the filter registers > + if (Reset) { > + for (Count =3D 0; Count < NumMfilter; Count++) > + { > + MmioWrite32 (MacBaseAddress + HASH_TABLE_REG(Count), 0x00000000); > + } > + } > + > + // Set MacFilter to the reset value of the DW_EMAC_GMACGRP_MAC_FRAME= _FILTER register. > + MacFilter =3D DW_EMAC_GMACGRP_MAC_FRAME_FILTER_RESET; > + > + if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_UNICAST) { > + //DEBUG ((DEBUG_INFO, "SNP:MAC: Enable Unicast Frame Reception\n"))= ; > + } > + > + if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) { > + > + //DEBUG ((DEBUG_INFO, "SNP:MAC: Enable Hash Multicast Frame Recepti= on\n")); > + MacFilter |=3D DW_EMAC_GMACGRP_MAC_FRAME_FILTER_HMC_SET_MSK; > + > + // Set the hash tables > + if ((NumMfilter > 0) && (!Reset)) { > + // Go through each filter address and set appropriate bits on has= h table > + for (Count =3D 0; Count < NumMfilter; Count++) { > + // Generate a 32-bit CRC > + Crc =3D GenEtherCrc32 (&Mfilter[Count], 6); > + // reserve CRC + take upper 8 bit =3D take lower 8 bit and reve= rse it > + Val =3D BitReverse(Crc & 0xff); > + // The most significant bits determines the register to be used= (Hash Table Register X), > + // and the least significant five bits determine the bit within= the register. > + // For example, a hash value of 8b'10111111 selects Bit 31 of t= he Hash Table Register 5. > + HashReg =3D (Val >> 5); > + HashBit =3D (Val & 31); Please use 0x1f rather than decimal 31 for the mask. > + > + Reg =3D MmioRead32(MacBaseAddress + HASH_TABLE_REG(HashReg)); > + // set 1 to HashBit of HashReg > + // for example, set 1 to bit 31 to Reg 5 as in above example > + Reg |=3D (1 << HashBit); > + MmioWrite32(MacBaseAddress + HASH_TABLE_REG(HashReg), Reg); > + } > + } > + } > + > + if ((ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST) =3D= = =3D 0) { > + MacFilter |=3D DW_EMAC_GMACGRP_MAC_FRAME_FILTER_DBF_SET_MSK; > + } else if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAS= T) { Hmm? Empty? > + } > + > + if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS) { > + MacFilter |=3D DW_EMAC_GMACGRP_MAC_FRAME_FILTER_PR_SET_MSK; > + } > + > + if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MUL= TICAST) { > + MacFilter |=3D ( DW_EMAC_GMACGRP_MAC_FRAME_FILTER_PM_SET_MSK); > + } > + > + // Set MacFilter to EMAC register > + MmioWrite32 (MacBaseAddress + DW_EMAC_GMACGRP_MAC_FRAME_FILTER_OFST,= MacFilter); > + return EFI_SUCCESS; > +} > + > + > +UINT32 > +EFIAPI > +GenEtherCrc32 ( > + IN EFI_MAC_ADDRESS *Mac, > + IN UINT32 AddrLen > + ) > +{ > + INT32 Iter; > + UINT32 Remainder; > + UINT8 *Ptr; > + > + Iter =3D 0; > + Remainder =3D 0xFFFFFFFF; // 0xFFFFFFFF is standard seed for Ether= net > + > + // Convert Mac Address to array of bytes > + Ptr =3D (UINT8 *)Mac; > + > + // Generate the Crc bit-by-bit (LSB first) > + while (AddrLen--) { > + Remainder ^=3D *Ptr++; > + for (Iter =3D 0; Iter < 8; Iter++) { > + // Check if exponent is set > + if (Remainder & 1) { > + Remainder =3D (Remainder >> 1) ^ CRC_POLYNOMIAL; > + } else { > + Remainder =3D (Remainder >> 1) ^ 0; > + } > + } > + } > + > + return (~Remainder); > +} > + > + > +STATIC CONST UINT8 NibbleTab[] =3D { > + /* 0x0 0000 -> 0000 */ 0x0, > + /* 0x1 0001 -> 1000 */ 0x8, > + /* 0x2 0010 -> 0100 */ 0x4, > + /* 0x3 0011 -> 1100 */ 0xc, > + /* 0x4 0100 -> 0010 */ 0x2, > + /* 0x5 0101 -> 1010 */ 0xa, > + /* 0x6 0110 -> 0110 */ 0x6, > + /* 0x7 0111 -> 1110 */ 0xe, > + /* 0x8 1000 -> 0001 */ 0x1, > + /* 0x9 1001 -> 1001 */ 0x9, > + /* 0xa 1010 -> 0101 */ 0x5, > + /* 0xb 1011 -> 1101 */ 0xd, > + /* 0xc 1100 -> 0011 */ 0x3, > + /* 0xd 1101 -> 1011 */ 0xb, > + /* 0xe 1110 -> 0111 */ 0x7, > + /* 0xf 1111 -> 1111 */ 0xf > +}; > + > +UINT8 > +EFIAPI > +BitReverse ( > + UINT8 X X is not a good parameter name. Byte? > + ) > +{ > + return (NibbleTab[X & 0xf] << 4) | NibbleTab[X >> 4]; > +} > + > + > +VOID > +EFIAPI > +EmacStopTxRx ( > + IN UINTN MacBaseAddress > + ) > +{ > + DEBUG ((DEBUG_INFO, "SNP:MAC: %a ()\r\n", __FUNCTION__)); > + > + // Stop DMA TX > + MmioAnd32 (MacBaseAddress + > + DW_EMAC_DMAGRP_OPERATION_MODE_OFST, > + DW_EMAC_DMAGRP_OPERATION_MODE_ST_CLR_MSK); Indentation funky. > + > + // Flush TX > + MmioOr32 (MacBaseAddress + > + DW_EMAC_DMAGRP_OPERATION_MODE_OFST, > + DW_EMAC_DMAGRP_OPERATION_MODE_FTF_SET_MSK); Indentation fine. > + > + // Stop transmitters > + MmioAnd32 (MacBaseAddress + > + DW_EMAC_GMACGRP_MAC_CONFIGURATION_OFST, > + DW_EMAC_GMACGRP_MAC_CONFIGURATION_RE_CLR_MSK & > + DW_EMAC_GMACGRP_MAC_CONFIGURATION_TE_CLR_MSK); Indentation funky. > + > + // Stop DMA RX > + MmioAnd32 (MacBaseAddress + > + DW_EMAC_DMAGRP_OPERATION_MODE_OFST, > + DW_EMAC_DMAGRP_OPERATION_MODE_SR_CLR_MSK); Indentation funky. > + > +} > + > + > +EFI_STATUS > +EFIAPI > +EmacDmaStart ( > + IN UINTN MacBaseAddress > + ) > +{ > + // Start the transmission > + MmioWrite32(MacBaseAddress + > + DW_EMAC_DMAGRP_TRANSMIT_POLL_DEMAND_OFST, > + 0x1); > + return EFI_SUCCESS; > +} > + > + > +VOID > +EFIAPI > +EmacGetDmaStatus ( > + OUT UINT32 *IrqStat OPTIONAL, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 DmaStatus; > + UINT32 ErrorBit; > + UINT32 Mask =3D 0; > + > + DmaStatus =3D MmioRead32 (MacBaseAddress + > + DW_EMAC_DMAGRP_STATUS_OFST); > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_NIS_SET_MSK) { > + Mask |=3D DW_EMAC_DMAGRP_STATUS_NIS_SET_MSK; > + // Rx interrupt > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_RI_SET_MSK) { > + *IrqStat |=3D EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; > + Mask |=3D DW_EMAC_DMAGRP_STATUS_RI_SET_MSK; > + } else { > + *IrqStat &=3D ~EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; > + } > + // Tx interrupt > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_TI_SET_MSK) { > + *IrqStat |=3D EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT; > + Mask |=3D DW_EMAC_DMAGRP_STATUS_TI_SET_MSK; > + } else { > + *IrqStat &=3D ~EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT; > + } > + // Tx Buffer > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_TU_SET_MSK){ > + Mask |=3D DW_EMAC_DMAGRP_STATUS_TU_SET_MSK; > + } > + // Early receive interrupt > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_ERI_SET_MSK) { > + Mask |=3D DW_EMAC_DMAGRP_STATUS_ERI_SET_MSK; > + } > + } > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_AIS_SET_MSK) { > + Mask |=3D DW_EMAC_DMAGRP_STATUS_AIS_SET_MSK; > + // Transmit process stop > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_TPS_SET_MSK) { > + DEBUG ((DEBUG_INFO, "SNP:MAC: Transmit process stop\n")); > + Mask |=3D DW_EMAC_DMAGRP_STATUS_TPS_SET_MSK; > + } > + // Transmit jabber timeout > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_TJT_SET_MSK) { > + DEBUG ((DEBUG_INFO, "SNP:MAC: Transmit jabber timeout\n")); > + Mask |=3D DW_EMAC_DMAGRP_STATUS_TJT_SET_MSK; > + } > + // Receive FIFO overflow > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_OVF_SET_MSK) { > + DEBUG ((DEBUG_INFO, "SNP:MAC: Receive FIFO overflow\n")); > + Mask |=3D DW_EMAC_DMAGRP_STATUS_OVF_SET_MSK; > + } > + // Transmit FIFO underflow > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_UNF_SET_MSK) { > + DEBUG ((DEBUG_INFO, "SNP:MAC: Receive FIFO underflow\n")); > + Mask |=3D DW_EMAC_DMAGRP_STATUS_UNF_SET_MSK; > + } > + // Receive buffer unavailable > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_RU_SET_MSK) { > + //DEBUG ((DEBUG_INFO, "SNP:MAC: Receive buffer unavailable\n")); > + Mask |=3D DW_EMAC_DMAGRP_STATUS_RU_SET_MSK; > + } > + > + // Receive process stop > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_RPS_SET_MSK) { > + DEBUG ((DEBUG_INFO, "SNP:MAC: Receive process stop\n")); > + Mask |=3D DW_EMAC_DMAGRP_STATUS_RPS_SET_MSK; > + } > + // Receive watchdog timeout > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_RWT_SET_MSK) { > + DEBUG ((DEBUG_INFO, "SNP:MAC: Receive watchdog timeout\n")); > + Mask |=3D DW_EMAC_DMAGRP_STATUS_RWT_SET_MSK; > + } > + // Early transmit interrupt > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_ETI_SET_MSK) { > + //DEBUG ((DEBUG_INFO, "SNP:MAC: Early transmit interrupt\n")); > + Mask |=3D DW_EMAC_DMAGRP_STATUS_ETI_SET_MSK; > + } > + // Fatal bus error > + if (DmaStatus & DW_EMAC_DMAGRP_STATUS_FBI_SET_MSK) { > + DEBUG ((DEBUG_INFO, "SNP:MAC: Fatal bus error:\n")); > + Mask |=3D DW_EMAC_DMAGRP_STATUS_FBI_SET_MSK; > + > + ErrorBit =3D DW_EMAC_DMAGRP_STATUS_EB_GET (DmaStatus); > + switch (ErrorBit) { > + case RX_DMA_WRITE_DATA_TRANSFER_ERROR: > + DEBUG ((DEBUG_INFO, "SNP:MAC: Rx Dma write data transfer erro= r\n")); > + break; > + case TX_DMA_READ_DATA_TRANSFER_ERROR: > + DEBUG ((DEBUG_INFO, "SNP:MAC: Tx Dma read data transfer error= \n")); > + break; > + case RX_DMA_DESCRIPTOR_WRITE_ACCESS_ERROR: > + DEBUG ((DEBUG_INFO, "SNP:MAC: Rx Dma descriptor write access = error\n")); > + break; > + case RX_DMA_DESCRIPTOR_READ_ACCESS_ERROR: > + DEBUG ((DEBUG_INFO, "SNP:MAC: Rx Dma descriptor read access e= rror\n")); > + break; > + case TX_DMA_DESCRIPTOR_WRITE_ACCESS_ERROR: > + DEBUG ((DEBUG_INFO, "SNP:MAC: Tx Dma descriptor write access = error\n")); > + break; > + case TX_DMA_DESCRIPTOR_READ_ACCESS_ERROR: > + DEBUG ((DEBUG_INFO, "SNP:MAC: Tx Dma descriptor read access e= rror\n")); > + break; > + default: > + DEBUG ((DEBUG_INFO, "SNP:MAC: Undefined error\n")); > + break; > + } > + } > + } > + MmioOr32 (MacBaseAddress + > + DW_EMAC_DMAGRP_STATUS_OFST, > + Mask); > +} > + > + > +VOID > +EFIAPI > +EmacGetStatistic ( > + OUT EFI_NETWORK_STATISTICS *Statistic, > + IN UINTN MacBaseAddress > + ) > +{ > + EFI_NETWORK_STATISTICS *Stats; > + > + DEBUG ((DEBUG_INFO, "SNP:MAC: %a ()\r\n", __FUNCTION__)); > + > + // Allocate Resources > + Stats =3D AllocateZeroPool (sizeof (EFI_NETWORK_STATISTICS)); > + if (Stats =3D=3D NULL) { > + return; > + } > + > + Stats->RxTotalFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_RXFRAMECOUNT_GB_OFST); > + Stats->RxUndersizeFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_RXUNDERSIZE_G_OFST); > + Stats->RxOversizeFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_RXOVERSIZE_G_OFST); > + Stats->RxUnicastFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_RXUNICASTFRAMES_G_OFST); > + Stats->RxBroadcastFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_RXBROADCASTFRAMES_G_OFST); > + Stats->RxMulticastFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_RXMULTICASTFRAMES_G_OFST); > + Stats->RxCrcErrorFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_RXCRCERROR_OFST); > + Stats->RxTotalBytes =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_RXOCTETCOUNT_GB_OFST); > + Stats->RxGoodFrames =3D Stats->RxUnicastFrames + Stats->RxBroadc= astFrames + Stats->RxMulticastFrames; > + > + Stats->TxTotalFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_TXFRAMECOUNT_GB_OFST); > + Stats->TxGoodFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_TXFRAMECOUNT_G_OFST); > + Stats->TxOversizeFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_TXOVERSIZE_G_OFST); > + Stats->TxUnicastFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_TXUNICASTFRAMES_GB_OFST); > + Stats->TxBroadcastFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_TXBROADCASTFRAMES_G_OFST); > + Stats->TxMulticastFrames =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_TXMULTICASTFRAMES_G_OFST); > + Stats->TxTotalBytes =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_TXOCTETCOUNT_GB_OFST); > + Stats->Collisions =3D MmioRead32 (MacBaseAddress + DW_EMAC_GMA= CGRP_TXLATECOL_OFST) + > + MmioRead32 (MacBaseAddress + DW_EMAC_GMACG= RP_TXEXESSCOL_OFST); > + > + // Fill in the statistics > + CopyMem (Statistic, Stats, sizeof (EFI_NETWORK_STATISTICS)); > +} > + > + > +VOID > +EFIAPI > +EmacConfigAdjust ( > + IN UINT32 Speed, > + IN UINT32 Duplex, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 Config; > + > + Config =3D 0; > + if (Speed !=3D SPEED_1000) > + Config |=3D DW_EMAC_GMACGRP_MAC_CONFIGURATION_PS_SET_MSK; Always use { and } with if statements. Throughout. > + > + if (Speed =3D=3D SPEED_100) > + Config |=3D DW_EMAC_GMACGRP_MAC_CONFIGURATION_FES_SET_MSK; > + > + if (Duplex =3D=3D DUPLEX_FULL) > + Config |=3D DW_EMAC_GMACGRP_MAC_CONFIGURATION_DM_SET_MSK; > + > + MmioOr32 (MacBaseAddress + > + DW_EMAC_GMACGRP_MAC_CONFIGURATION_OFST, > + DW_EMAC_GMACGRP_MAC_CONFIGURATION_BE_SET_MSK | > + DW_EMAC_GMACGRP_MAC_CONFIGURATION_DO_SET_MSK | > + Config); > + > +} > diff --git a/Silicon/DesignWare/Drivers/DwEmacSnpDxe/PhyDxeUtil.c b/Sili= con/DesignWare/Drivers/DwEmacSnpDxe/PhyDxeUtil.c > new file mode 100755 > index 000000000000..de7936d31489 > --- /dev/null > +++ b/Silicon/DesignWare/Drivers/DwEmacSnpDxe/PhyDxeUtil.c > @@ -0,0 +1,699 @@ > +/** @file > + > + Copyright (c) 2011 - 2019, Intel Corporaton. All rights reserved. > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > + > + The original software modules are licensed as follows: > + > + Copyright (c) 2012 - 2014, ARM Limited. All rights reserved. > + Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved. > + > + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the= BSD License > + which accompanies this distribution. The full text of the license ma= y be found at > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD 3 Clause LICENSE ON AN "AS I= S" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR = IMPLIED. > +**/ SPDX. > + > + > +#include "PhyDxeUtil.h" > +#include "EmacDxeUtil.h" > + > +EFI_STATUS > +EFIAPI > +PhyDxeInitialization ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + EFI_STATUS Status; > + > + DEBUG ((EFI_D_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); > + > + // initialize the phyaddr > + PhyDriver->PhyAddr =3D 0; > + PhyDriver->PhyCurrentLink =3D LINK_DOWN; > + PhyDriver->PhyOldLink =3D LINK_DOWN; > + > + Status =3D PhyDetectDevice (PhyDriver, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return EFI_NOT_FOUND; > + } > + > + PhyConfig (PhyDriver, MacBaseAddress); > + > + return EFI_SUCCESS; > +} > + > + > +// PHY detect device=20 > +EFI_STATUS > +EFIAPI > +PhyDetectDevice ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 PhyAddr; > + EFI_STATUS Status; > + > + DEBUG ((EFI_D_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); > + > + for (PhyAddr =3D 0; PhyAddr < 32; PhyAddr++) { > + Status =3D PhyReadId (PhyAddr, MacBaseAddress); > + if (EFI_ERROR(Status)) { > + continue; > + } > + > + PhyDriver->PhyAddr =3D PhyAddr; > + return EFI_SUCCESS; > + } > + > + DEBUG ((DEBUG_INFO, "SNP:PHY: Fail to detect Ethernet PHY!\r\n")); > + return EFI_NOT_FOUND; > + > +} > + > + > +EFI_STATUS > +EFIAPI > +PhyConfig ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + EFI_STATUS Status; > + > + DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); > + > + Status =3D PhySoftReset (PhyDriver, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return EFI_DEVICE_ERROR; > + } > + > + // Configure TX/RX Skew > + PhyConfigSkew (PhyDriver, MacBaseAddress); > + > + // Read back and display Skew settings > + PhyDisplayConfigSkew (PhyDriver, MacBaseAddress); > + > + // Configure AN FLP Burst Trasmit timing interval > + PhyConfigFlpBurstTiming (PhyDriver, MacBaseAddress); > + PhyDisplayFlpBurstTiming (PhyDriver, MacBaseAddress); > + > + // Configure AN and Advertise > + PhyAutoNego (PhyDriver, MacBaseAddress); > + > + return EFI_SUCCESS; > +} > + > + > +// Perform PHY software reset > +EFI_STATUS > +EFIAPI > +PhySoftReset ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 TimeOut; > + UINT32 Data32; > + EFI_STATUS Status; > + > + DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); > + > + // PHY Basic Control Register reset > + PhyWrite (PhyDriver->PhyAddr, PHY_BASIC_CTRL, PHYCTRL_RESET, MacBaseA= ddress); > + > + // Wait for completion > + TimeOut =3D 0; > + do { > + // Read PHY_BASIC_CTRL register from PHY > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_BASIC_CTRL, &Data32, Ma= cBaseAddress); > + if (EFI_ERROR(Status)) { > + return Status; > + } > + // Wait until PHYCTRL_RESET become zero > + if ((Data32 & PHYCTRL_RESET) =3D=3D 0) { > + break; > + } > + MicroSecondDelay(1); > + } while (TimeOut++ < PHY_TIMEOUT); > + if (TimeOut >=3D PHY_TIMEOUT) { > + DEBUG ((DEBUG_INFO, "SNP:PHY: ERROR! PhySoftReset timeout\n")); > + return EFI_TIMEOUT; > + } > + > + return EFI_SUCCESS; > +} > + > + > +// PHY read ID > +EFI_STATUS > +EFIAPI > +PhyReadId ( > + IN UINT32 PhyAddr, > + IN UINTN MacBaseAddress > + ) > +{ > + EFI_STATUS Status; > + UINT32 PhyId1; > + UINT32 PhyId2; > + > + //DEBUG ((DEBUG_INFO, "SNP:PHY: %a (0x%02X)\r\n", __FUNCTION__, PhyAd= dr)); No commented-out code please - either delete the line or uncomment it (or change the level to DEBUG_VERBOSE). > + > + Status =3D PhyRead (PhyAddr, PHY_ID1, &PhyId1, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + Status =3D PhyRead (PhyAddr, PHY_ID2, &PhyId2, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + if (PhyId1 =3D=3D PHY_INVALID_ID || PhyId2 =3D=3D PHY_INVALID_ID) { > + return EFI_NOT_FOUND; > + } > + > + DEBUG ((DEBUG_INFO, "SNP:PHY: Ethernet PHY detected. PHY_ID1=3D0x%04X= , PHY_ID2=3D0x%04X, PHY_ADDR=3D0x%02X\r\n", > + PhyId1, PhyId2, PhyAddr)); > + return EFI_SUCCESS; > +} > + > + > +VOID > +EFIAPI > +PhyConfigSkew ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + Phy9031ExtendedWrite (PhyDriver,=20 > + PHY_KSZ9031_MOD_DATA_NO_POST_INC, > + PHY_KSZ9031RN_DEV_ADDR, PHY_KSZ9031RN_CONTROL_P= AD_SKEW_REG,=20 > + PHY_KSZ9031RN_CONTROL_PAD_SKEW_VALUE, > + MacBaseAddress); > + Phy9031ExtendedWrite (PhyDriver, > + PHY_KSZ9031_MOD_DATA_NO_POST_INC, > + PHY_KSZ9031RN_DEV_ADDR, PHY_KSZ9031RN_CLK_PAD_S= KEW_REG, > + PHY_KSZ9031RN_CLK_PAD_SKEW_VALUE, > + MacBaseAddress); > + Phy9031ExtendedWrite (PhyDriver, > + PHY_KSZ9031_MOD_DATA_NO_POST_INC, > + PHY_KSZ9031RN_DEV_ADDR, > + PHY_KSZ9031RN_RX_DATA_PAD_SKEW_REG, > + PHY_KSZ9031RN_RX_DATA_PAD_SKEW_VALUE, > + MacBaseAddress); > + Phy9031ExtendedWrite (PhyDriver, > + PHY_KSZ9031_MOD_DATA_NO_POST_INC, > + PHY_KSZ9031RN_DEV_ADDR, > + PHY_KSZ9031RN_TX_DATA_PAD_SKEW_REG, > + PHY_KSZ9031RN_TX_DATA_PAD_SKEW_VALUE, > + MacBaseAddress); > +} > + > + > +VOID > +EFIAPI > +PhyDisplayConfigSkew ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + // Display skew configuration > + DEBUG ((DEBUG_INFO, "SNP:PHY: Control Signal Pad Skew =3D 0x%04X\r\n"= , > + Phy9031ExtendedRead (PhyDriver, PHY_KSZ9031_MOD_DATA_NO_POST_INC,= =20 > + PHY_KSZ9031RN_DEV_ADDR, PHY_KSZ9031RN_CONTROL_PAD_SKEW_REG, MacBase= Address))); > + > + DEBUG ((DEBUG_INFO, "SNP:PHY: RGMII Clock Pad Skew =3D 0x%04X\r\n"= , > + Phy9031ExtendedRead (PhyDriver, PHY_KSZ9031_MOD_DATA_NO_POST_INC, > + PHY_KSZ9031RN_DEV_ADDR, PHY_KSZ9031RN_CLK_PAD_SKEW_REG, MacBaseAddr= ess))); > + > + DEBUG ((DEBUG_INFO, "SNP:PHY: RGMII RX Data Pad Skew =3D 0x%04X\r\n"= , > + Phy9031ExtendedRead (PhyDriver, PHY_KSZ9031_MOD_DATA_NO_POST_INC, > + PHY_KSZ9031RN_DEV_ADDR, PHY_KSZ9031RN_RX_DATA_PAD_SKEW_REG, MacBase= Address))); > + > + DEBUG ((DEBUG_INFO, "SNP:PHY: RGMII TX Data Pad Skew =3D 0x%04X\r\n"= , > + Phy9031ExtendedRead (PhyDriver, PHY_KSZ9031_MOD_DATA_NO_POST_INC,= =20 > + PHY_KSZ9031RN_DEV_ADDR, PHY_KSZ9031RN_TX_DATA_PAD_SKEW_REG, MacBase= Address))); > +} > + > +VOID > +EFIAPI > +PhyConfigFlpBurstTiming ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + Phy9031ExtendedWrite (PhyDriver, > + PHY_KSZ9031_MOD_DATA_NO_POST_INC, > + PHY_KSZ9031RN_MMD_DEV_ADDR_00, > + PHY_KSZ9031RN_MMD_D0_FLP_LO_REG, > + PHY_KSZ9031RN_MMD_D0_FLP_16MS_LO, > + MacBaseAddress); > + Phy9031ExtendedWrite (PhyDriver, > + PHY_KSZ9031_MOD_DATA_NO_POST_INC, > + PHY_KSZ9031RN_MMD_DEV_ADDR_00, > + PHY_KSZ9031RN_MMD_D0_FLP_HI_REG, > + PHY_KSZ9031RN_MMD_D0_FLP_16MS_HI, > + MacBaseAddress); > +} > + > +VOID > +EFIAPI > +PhyDisplayFlpBurstTiming ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + // Display Auto-Negotiation FLP burst transmit timing > + DEBUG ((DEBUG_INFO, "SNP:PHY: AN FLP Burst Transmit - LO =3D 0x%04X\r= \n", > + Phy9031ExtendedRead (PhyDriver, PHY_KSZ9031_MOD_DATA_NO_POST_= INC, > + PHY_KSZ9031RN_MMD_DEV_ADDR_00, PHY_KSZ9031RN_MMD_D0_FLP_LO_RE= G, MacBaseAddress))); > + DEBUG ((DEBUG_INFO, "SNP:PHY: AN FLP Burst Transmit - HI =3D 0x%04X\r= \n", > + Phy9031ExtendedRead (PhyDriver, PHY_KSZ9031_MOD_DATA_NO_POST_= INC, PHY_KSZ9031RN_MMD_DEV_ADDR_00, > + PHY_KSZ9031RN_MMD_D0_FLP_HI_REG, MacBaseAddress))); > +} > + > +// Do auto-negotiation > +EFI_STATUS > +EFIAPI > +PhyAutoNego ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + EFI_STATUS Status; > + UINT32 PhyControl; > + UINT32 PhyStatus; > + UINT32 Features; > + > + DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); > + > + // Read PHY Status > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_BASIC_STATUS, &PhyStatus,= MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // Check PHY Status if auto-negotiation is supported > + if ((PhyStatus & PHYSTS_AUTO_CAP) =3D=3D 0) { > + DEBUG ((DEBUG_INFO, "SNP:PHY: Auto-negotiation is not supported.\n"= )); > + return EFI_DEVICE_ERROR; > + } > + > + // Read PHY Auto-Nego Advertise capabilities register for 10/100 Base= -T > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_AUTO_NEG_ADVERT, &Feature= s, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // Set Advertise capabilities for 10Base-T/10Base-T full-duplex/100Ba= se-T/100Base-T full-duplex > + Features |=3D (PHYANA_10BASET | PHYANA_10BASETFD | PHYANA_100BASETX |= PHYANA_100BASETXFD); > + PhyWrite (PhyDriver->PhyAddr, PHY_AUTO_NEG_ADVERT, Features, MacBaseA= ddress); > + > + // Read PHY Auto-Nego Advertise capabilities register for 1000 Base-T > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_1000BASE_T_CONTROL, &Feat= ures, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // Set Advertise capabilities for 1000 Base-T/1000 Base-T full-duplex > + Features |=3D (PHYADVERTISE_1000FULL | PHYADVERTISE_1000HALF); > + PhyWrite (PhyDriver->PhyAddr, PHY_1000BASE_T_CONTROL, Features, MacBa= seAddress); > + > + // Read control register > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_BASIC_CTRL, &PhyControl, = MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + // Enable Auto-Negotiation > + PhyControl |=3D PHYCTRL_AUTO_EN; > + // Restart auto-negotiation > + PhyControl |=3D PHYCTRL_RST_AUTO; > + // Write this configuration > + PhyWrite (PhyDriver->PhyAddr, PHY_BASIC_CTRL, PhyControl, MacBaseAddr= ess);=20 > + > + return EFI_SUCCESS; > +} > + > + > +EFI_STATUS > +EFIAPI > +PhyLinkAdjustEmacConfig ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 Speed; > + UINT32 Duplex; > + EFI_STATUS Status; > + > + //DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); No commented-out code please. > + > + Status =3D EFI_SUCCESS; > + Speed =3D SPEED_10; > + Duplex =3D DUPLEX_HALF; > + > + Status =3D PhyCheckLinkStatus (PhyDriver, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + PhyDriver->PhyCurrentLink =3D LINK_DOWN; > + } else { > + PhyDriver->PhyCurrentLink =3D LINK_UP; > + } > + > + if (PhyDriver->PhyOldLink !=3D PhyDriver->PhyCurrentLink) { > + if (PhyDriver->PhyCurrentLink =3D=3D LINK_UP) { > + DEBUG ((DEBUG_INFO, "SNP:PHY: Link is up - Network Cable is Plugg= ed\r\n")); > + PhyReadCapability (PhyDriver, &Speed, &Duplex, MacBaseAddress); > + EmacConfigAdjust (Speed, Duplex, MacBaseAddress); > + Status =3D EFI_SUCCESS; > + } else { > + DEBUG ((DEBUG_INFO, "SNP:PHY: Link is Down - Network Cable is Unp= lugged?\r\n")); > + Status =3D EFI_NOT_READY; > + } > + } else if (PhyDriver->PhyCurrentLink =3D=3D LINK_DOWN) { > + Status =3D EFI_NOT_READY; > + } > + > + PhyDriver->PhyOldLink =3D PhyDriver->PhyCurrentLink; > + > + return Status; > +} > + > + > +EFI_STATUS > +EFIAPI > +PhyCheckLinkStatus ( > + IN PHY_DRIVER *PhyDriver, > + IN UINTN MacBaseAddress > + ) > +{ > + EFI_STATUS Status; > + UINT32 Data32; > + UINTN TimeOut; > + UINT32 PhyBasicStatus; > + > + //DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); No commented-out code, please. > + > + // Get the PHY Status > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_BASIC_STATUS, &PhyBasicSt= atus, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // if Link is already up then dont need to proceed anymore > + if (PhyBasicStatus & PHYSTS_LINK_STS) { > + return EFI_SUCCESS; > + } > + > + // Wait until it is up or until Time Out > + TimeOut =3D 0; > + do { > + // Read PHY_BASIC_STATUS register from PHY > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_BASIC_STATUS, &Data32, = MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + // Wait until PHYSTS_LINK_STS become one > + if (Data32 & PHYSTS_LINK_STS) { > + // Link is up > + break; > + } > + MicroSecondDelay (1); > + } while (TimeOut++ < PHY_TIMEOUT); > + if (TimeOut >=3D PHY_TIMEOUT) { > + // Link is down > + return EFI_TIMEOUT; > + } > + > + // Wait until autonego process has completed > + TimeOut =3D 0; > + do { > + // Read PHY_BASIC_STATUS register from PHY > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_BASIC_STATUS, &Data32, = MacBaseAddress); > + if (EFI_ERROR(Status)) { > + return Status; > + } > + // Wait until PHYSTS_AUTO_COMP become one > + if (Data32 & PHYSTS_AUTO_COMP) { > + DEBUG ((DEBUG_INFO, "SNP:PHY: Auto Negotiation completed\r\n")); > + break; > + } > + MicroSecondDelay (1); > + } while (TimeOut++ < PHY_TIMEOUT); > + if (TimeOut >=3D PHY_TIMEOUT) { > + DEBUG ((DEBUG_INFO, "SNP:PHY: Error! Auto Negotiation timeout\n")); > + return EFI_TIMEOUT; > + } > + > + return EFI_SUCCESS; > +} > + > + > +EFI_STATUS > +EFIAPI > +PhyReadCapability ( > + IN PHY_DRIVER *PhyDriver, > + IN UINT32 *Speed, > + IN UINT32 *Duplex, > + IN UINTN MacBaseAddress > + ) > +{ > + EFI_STATUS Status; > + UINT32 PartnerAbilityGb; > + UINT32 AdvertisingGb; > + UINT32 CommonAbilityGb; > + UINT32 PartnerAbility; > + UINT32 Advertising; > + UINT32 CommonAbility; > + > + //DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); No commented-out code, please. > + > + // For 1000 Base-T > + > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_1000BASE_T_STATUS, &Partn= erAbilityGb, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_1000BASE_T_CONTROL, &Adve= rtisingGb, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + CommonAbilityGb =3D PartnerAbilityGb & (AdvertisingGb << 2); > + > + // For 10/100 Base-T > + > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_AUTO_NEG_LINK_ABILITY, &P= artnerAbility, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_AUTO_NEG_EXP, &Advertisin= g, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + CommonAbility =3D PartnerAbility & Advertising; > + > + // Determine the Speed and Duplex > + if (PartnerAbilityGb & (PHYLPA_1000FULL | PHYLPA_1000HALF)) { > + *Speed =3D SPEED_1000; > + if (CommonAbilityGb & PHYLPA_1000FULL) { > + *Duplex =3D DUPLEX_FULL; > + } > + } else if (CommonAbility & (PHYLPA_100FULL | PHYLPA_100HALF)) { > + *Speed =3D SPEED_100; > + if (CommonAbility & PHYLPA_100FULL) { > + *Duplex =3D DUPLEX_FULL; > + } else if (CommonAbility & PHYLPA_10FULL) { > + *Duplex =3D DUPLEX_FULL; > + } > + } > + > + PhyDisplayAbility (*Speed, *Duplex); > + > + return EFI_SUCCESS; > +} > + > + > +VOID > +EFIAPI > +PhyDisplayAbility ( > + IN UINT32 Speed, > + IN UINT32 Duplex > + ) > +{ > + //DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); No commented-out code, please. > + > + DEBUG ((DEBUG_INFO, "SNP:PHY: ")); > + switch (Speed) { > + case SPEED_1000: > + DEBUG ((DEBUG_INFO, "1 Gbps - ")); > + break; > + case SPEED_100: > + DEBUG ((DEBUG_INFO, "100 Mbps - ")); > + break; > + case SPEED_10: > + DEBUG ((DEBUG_INFO, "10 Mbps - ")); > + break; > + default: > + DEBUG ((DEBUG_INFO, "Invalid link speed")); > + break; > + } > + > + switch (Duplex) { > + case DUPLEX_FULL: > + DEBUG ((DEBUG_INFO, "Full Duplex\n")); > + break; > + case DUPLEX_HALF: > + DEBUG ((DEBUG_INFO, "Half Duplex\n")); > + break; > + default: > + DEBUG ((DEBUG_INFO, "Invalid duplex mode\n")); > + break; > + } > +} > + > + > +// Function to read from MII register (PHY Access) > +EFI_STATUS > +EFIAPI > +PhyRead ( > + IN UINT32 Addr, > + IN UINT32 Reg, > + OUT UINT32 *Data, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 MiiConfig; > + UINT32 Count; > + > + //DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); No commented-out code, please. > + > + // Check it is a valid Reg > + ASSERT(Reg < 31); > + > + MiiConfig =3D ((Addr << MIIADDRSHIFT) & MII_ADDRMSK) | > + ((Reg << MIIREGSHIFT) & MII_REGMSK)| > + MII_CLKRANGE_150_250M | > + MII_BUSY; > + > + // write this config to register > + MmioWrite32 (MacBaseAddress + DW_EMAC_GMACGRP_GMII_ADDRESS_OFST, MiiC= onfig); > + > + // Wait for busy bit to clear > + Count =3D 0; > + while (Count < 10000) { > + if (!(DW_EMAC_GMACGRP_GMII_ADDRESS_GB_GET (MmioRead32 (MacBaseAddre= ss + DW_EMAC_GMACGRP_GMII_ADDRESS_OFST)))) { > + *Data =3D DW_EMAC_GMACGRP_GMII_DATA_GD_GET (MmioRead32 (MacBaseAd= dress + DW_EMAC_GMACGRP_GMII_DATA_OFST)); > + return EFI_SUCCESS; > + } > + MemoryFence (); > + Count++; > + }; > + DEBUG ((DEBUG_INFO, "SNP:PHY: MDIO busy bit timeout\r\n")); > + return EFI_TIMEOUT; > +} > + > + > +// Function to write to the MII register (PHY Access) > +EFI_STATUS > +EFIAPI > +PhyWrite ( > + IN UINT32 Addr, > + IN UINT32 Reg, > + IN UINT32 Data, > + IN UINTN MacBaseAddress > + ) > +{ > + UINT32 MiiConfig; > + UINT32 Count; > + > + //DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); No commented-out code, please. > + > + // Check it is a valid Reg > + ASSERT(Reg < 31); Space before (. > + > + MiiConfig =3D ((Addr << MIIADDRSHIFT) & MII_ADDRMSK) | > + ((Reg << MIIREGSHIFT) & MII_REGMSK)| Missing space before | > + MII_WRITE | Indentation of this line, and the two below, should line up with the two lines above it. > + MII_CLKRANGE_150_250M | > + MII_BUSY; > + // Write the desired value to the register first > + MmioWrite32 (MacBaseAddress + DW_EMAC_GMACGRP_GMII_DATA_OFST, (Data &= 0xFFFF)); > + > + // write this config to register > + MmioWrite32 (MacBaseAddress + DW_EMAC_GMACGRP_GMII_ADDRESS_OFST, MiiC= onfig); > + > + // Wait for busy bit to clear > + Count =3D 0; > + while (Count < 1000) { > + if (!(DW_EMAC_GMACGRP_GMII_ADDRESS_GB_GET (MmioRead32 (MacBaseAddre= ss + DW_EMAC_GMACGRP_GMII_ADDRESS_OFST)))) { > + return EFI_SUCCESS; > + } > + MemoryFence (); > + Count++; > + }; > + > + return EFI_TIMEOUT; > +} > + > + > +EFI_STATUS > +EFIAPI > +Phy9031ExtendedWrite ( > + IN PHY_DRIVER *PhyDriver, > + IN UINT32 Mode, > + IN UINT32 DevAddr, > + IN UINT32 Regnum, > + IN UINT16 Val, > + IN UINTN MacBaseAddress > + ) > +{ > + //DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); No commented-out code, please. > + > + PhyWrite (PhyDriver->PhyAddr, PHY_KSZ9031RN_MMD_CTRL_REG, DevAddr, Ma= cBaseAddress); > + PhyWrite (PhyDriver->PhyAddr, PHY_KSZ9031RN_MMD_REGDATA_REG, Regnum, = MacBaseAddress); > + PhyWrite (PhyDriver->PhyAddr, PHY_KSZ9031RN_MMD_CTRL_REG, (Mode << 14= ) | DevAddr, MacBaseAddress); > + return PhyWrite (PhyDriver->PhyAddr, PHY_KSZ9031RN_MMD_REGDATA_REG, V= al, MacBaseAddress); > +} > + > + > +UINT32 > +EFIAPI > +Phy9031ExtendedRead ( > + IN PHY_DRIVER *PhyDriver, > + IN UINT32 Mode, > + IN UINT32 DevAddr, > + IN UINT32 Regnum, > + IN UINTN MacBaseAddress > + ) > +{ > + EFI_STATUS Status; > + UINT32 Data32; > + > + //DEBUG ((DEBUG_INFO, "SNP:PHY: %a ()\r\n", __FUNCTION__)); No commented-out code, please. / Leif > + > + PhyWrite (PhyDriver->PhyAddr, PHY_KSZ9031RN_MMD_CTRL_REG, DevAddr, Ma= cBaseAddress); > + PhyWrite (PhyDriver->PhyAddr, PHY_KSZ9031RN_MMD_REGDATA_REG, Regnum, = MacBaseAddress); > + PhyWrite (PhyDriver->PhyAddr, PHY_KSZ9031RN_MMD_CTRL_REG, (Mode << 14= ) | DevAddr, MacBaseAddress); > + > + Status =3D PhyRead (PhyDriver->PhyAddr, PHY_KSZ9031RN_MMD_REGDATA_REG= , &Data32, MacBaseAddress); > + if (EFI_ERROR (Status)) { > + return 0; > + } > + > + return Data32; > +} > + > + > --=20 > 2.17.1 >=20