* [PATCH edk2-platforms v4 0/9] BCM genet fixes @ 2020-05-11 14:55 Ard Biesheuvel 2020-05-11 14:55 ` [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Ard Biesheuvel ` (9 more replies) 0 siblings, 10 replies; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton This fixes the multicast/broadcast/promisc handling, and switches to ordinary page allocations for RX buffers. Patch #1 is cosmetic only. Note that these apply on top of the series sent out by Samer, and is intended to be squashed into that series before merging. Changes since v3: - more cosmetic tweaks in #1 - move DmaUnmap() for TX buffers to the correct place - use MemoryFence() instead of DSB for MMIO write ordering - add unload support to the driver - remove the Ax88772b driver from the RPi4 build - it is no longer needed, and misbehaves when no cable is connected. Changes since v2: - fix MDF filter handling (fixes issue reported by Samer) - add patch to deal with ExitBootServices() so we don't leave the RX DMA ring running when we enter the OS https://github.com/pftf/edk2-platforms/tree/rpi4_genet_v4_ardb Cc: Pete Batard <pete@akeo.ie> Cc: Jared McNeill <jmcneill@invisible.ca> Cc: Andrei Warkentin <awarkentin@vmware.com> Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com> Cc: Jeremy Linton <jeremy.linton@arm.com> Ard Biesheuvel (9): Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Silicon/Broadcom/BcmGenetDxe: fix multicast/broadcast handling Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering Silicon/Broadcom/BcmGenetDxe: add unload support Platform/RaspberryPi4: remove ASIX 88772b driver Platform/RaspberryPi/RPi4/RPi4.dsc | 1 - Platform/RaspberryPi/RPi4/RPi4.fdf | 1 - .../Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 13 +- .../Drivers/Net/BcmGenetDxe/GenetUtil.h | 51 +- .../Drivers/Net/BcmGenetDxe/DriverBinding.c | 122 ++- .../Drivers/Net/BcmGenetDxe/GenericPhy.c | 16 +- .../Drivers/Net/BcmGenetDxe/GenetUtil.c | 787 +++++++++--------- .../Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 115 ++- 8 files changed, 621 insertions(+), 485 deletions(-) -- 2.17.1 ^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel @ 2020-05-11 14:55 ` Ard Biesheuvel 2020-05-11 16:36 ` Samer El-Haj-Mahmoud 2020-05-11 21:14 ` [edk2-devel] " Philippe Mathieu-Daudé 2020-05-11 14:55 ` [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Ard Biesheuvel ` (8 subsequent siblings) 9 siblings, 2 replies; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 2 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 38 +- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 19 +- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c | 16 +- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 744 ++++++++++---------- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 90 ++- 6 files changed, 456 insertions(+), 453 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index e74fa02ad209..1f1aeca7dd6b 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -21,7 +21,9 @@ [Sources] ComponentName.c DriverBinding.c GenericPhy.c + GenericPhy.h GenetUtil.c + GenetUtil.h SimpleNetwork.c [Packages] diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index 2e7b78322bcd..b21a284b6221 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -185,7 +185,7 @@ #define GENET_TX_SCB_BURST_SIZE (GENET_TX_BASE + 0x1040 + 0x0c) typedef struct { - EFI_PHYSICAL_ADDRESS Pa; + EFI_PHYSICAL_ADDRESS PhysAddress; VOID * Mapping; } GENET_MAP_INFO; @@ -198,32 +198,32 @@ typedef enum { } GENET_PHY_MODE; typedef struct { - UINT32 Signature; - EFI_HANDLE ControllerHandle; + UINT32 Signature; + EFI_HANDLE ControllerHandle; - EFI_LOCK Lock; + EFI_LOCK Lock; - EFI_SIMPLE_NETWORK_PROTOCOL Snp; - EFI_SIMPLE_NETWORK_MODE SnpMode; + EFI_SIMPLE_NETWORK_PROTOCOL Snp; + EFI_SIMPLE_NETWORK_MODE SnpMode; - BCM_GENET_PLATFORM_DEVICE_PROTOCOL *Dev; + BCM_GENET_PLATFORM_DEVICE_PROTOCOL *Dev; - GENERIC_PHY_PRIVATE_DATA Phy; + GENERIC_PHY_PRIVATE_DATA Phy; - UINT8 * TxBuffer[GENET_DMA_DESC_COUNT]; - UINT8 TxQueued; - UINT16 TxNext; - UINT16 TxConsIndex; - UINT16 TxProdIndex; + UINT8 *TxBuffer[GENET_DMA_DESC_COUNT]; + UINT8 TxQueued; + UINT16 TxNext; + UINT16 TxConsIndex; + UINT16 TxProdIndex; - UINT8 * RxBuffer[GENET_DMA_DESC_COUNT]; - GENET_MAP_INFO RxBufferMap[GENET_DMA_DESC_COUNT]; - UINT16 RxConsIndex; - UINT16 RxProdIndex; + UINT8 *RxBuffer[GENET_DMA_DESC_COUNT]; + GENET_MAP_INFO RxBufferMap[GENET_DMA_DESC_COUNT]; + UINT16 RxConsIndex; + UINT16 RxProdIndex; - GENET_PHY_MODE PhyMode; + GENET_PHY_MODE PhyMode; - UINTN RegBase; + UINTN RegBase; } GENET_PRIVATE_DATA; extern EFI_COMPONENT_NAME_PROTOCOL gGenetComponentName; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index e3d015dd0820..c23847ba9b52 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -55,14 +55,12 @@ GenetDriverBindingSupported ( // Status = gBS->OpenProtocol (ControllerHandle, &gBcmGenetPlatformDeviceProtocolGuid, - (VOID **) &Dev, + (VOID **)&Dev, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER); if (EFI_ERROR (Status)) { return Status; - } else { - Status = EFI_SUCCESS; } // @@ -73,7 +71,7 @@ GenetDriverBindingSupported ( This->DriverBindingHandle, ControllerHandle); - return Status; + return EFI_SUCCESS; } @@ -111,7 +109,7 @@ GenetDriverBindingStart ( Genet = AllocateZeroPool (sizeof (GENET_PRIVATE_DATA)); if (Genet == NULL) { DEBUG ((DEBUG_ERROR, - "GenetDriverBindingStart: Couldn't allocate private data\n")); + "%a: Couldn't allocate private data\n", __FUNCTION__)); return EFI_OUT_OF_RESOURCES; } @@ -123,14 +121,14 @@ GenetDriverBindingStart ( EFI_OPEN_PROTOCOL_BY_DRIVER); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, - "GenetDriverBindingStart: Couldn't open protocol: %r\n", Status)); + "%a: Couldn't open protocol: %r\n", __FUNCTION__, Status)); goto FreeDevice; } Status = GenetDmaAlloc (Genet); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, - "GenetDriverBindingStart: Couldn't allocate DMA buffers: %r\n", Status)); + "%a: Couldn't allocate DMA buffers: %r\n", __FUNCTION__, Status)); goto FreeDevice; } @@ -180,8 +178,7 @@ GenetDriverBindingStart ( if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, - "GenetDriverBindingStart: Couldn't install protocol interfaces: %r\n", - Status)); + "%a: Couldn't install protocol interfaces: %r\n", __FUNCTION__, Status)); gBS->CloseProtocol (ControllerHandle, &gBcmGenetPlatformDeviceProtocolGuid, This->DriverBindingHandle, @@ -190,10 +187,10 @@ GenetDriverBindingStart ( } Genet->ControllerHandle = ControllerHandle; - return Status; + return EFI_SUCCESS; FreeDevice: - DEBUG ((DEBUG_WARN, "GenetDriverBindingStart: Returning %r\n", Status)); + DEBUG ((DEBUG_WARN, "%a: Returning %r\n", __FUNCTION__, Status)); FreePool (Genet); return Status; } diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c index a3c709891bc9..cd2788adc52c 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c @@ -115,8 +115,8 @@ GenericPhyDetect ( if (Id1 != 0xFFFF && Id2 != 0xFFFF) { Phy->PhyAddr = PhyAddr; DEBUG ((DEBUG_INFO, - "GenericPhyDetect: PHY detected at address 0x%02X (PHYIDR1=0x%04X, PHYIDR2=0x%04X)\n", - PhyAddr, Id1, Id2)); + "%a: PHY detected at address 0x%02X (PHYIDR1=0x%04X, PHYIDR2=0x%04X)\n", + __FUNCTION__, PhyAddr, Id1, Id2)); return EFI_SUCCESS; } } @@ -348,8 +348,8 @@ GenericPhyGetConfig ( *Duplex = (An & GENERIC_PHY_ANAR_10BASET_FDX) ? PHY_DUPLEX_FULL : PHY_DUPLEX_HALF; } - DEBUG ((DEBUG_INFO, "GenericPhyGetConfig: Link speed %d Mbps, %a-duplex\n", - *Speed, *Duplex == PHY_DUPLEX_FULL ? "full" : "half")); + DEBUG ((DEBUG_INFO, "%a: Link speed %d Mbps, %a-duplex\n", + __FUNCTION__, *Speed, *Duplex == PHY_DUPLEX_FULL ? "full" : "half")); return EFI_SUCCESS; } @@ -367,8 +367,8 @@ GenericPhyGetConfig ( EFI_STATUS EFIAPI GenericPhyUpdateConfig ( - IN GENERIC_PHY_PRIVATE_DATA *Phy - ) + IN GENERIC_PHY_PRIVATE_DATA *Phy + ) { EFI_STATUS Status; GENERIC_PHY_SPEED Speed; @@ -380,7 +380,7 @@ GenericPhyUpdateConfig ( if (Phy->LinkUp != LinkUp) { if (LinkUp) { - DEBUG ((DEBUG_VERBOSE, "GenericPhyUpdateConfig: Link is up\n")); + DEBUG ((DEBUG_VERBOSE, "%a: Link is up\n", __FUNCTION__)); Status = GenericPhyGetConfig (Phy, &Speed, &Duplex); if (EFI_ERROR (Status)) { @@ -389,7 +389,7 @@ GenericPhyUpdateConfig ( GenericPhyConfigure (Phy, Speed, Duplex); } else { - DEBUG ((DEBUG_VERBOSE, "GenericPhyUpdateConfig: Link is down\n")); + DEBUG ((DEBUG_VERBOSE, "%a: Link is down\n", __FUNCTION__)); } } diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index d471b1cadadc..7ae9acec4c78 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -31,13 +31,13 @@ STATIC UINT32 GenetMmioRead ( - IN GENET_PRIVATE_DATA *Genet, - IN UINT32 Offset - ) + IN GENET_PRIVATE_DATA *Genet, + IN UINT32 Offset + ) { - ASSERT((Offset & 3) == 0); + ASSERT ((Offset & 3) == 0); - return MmioRead32 (Genet->RegBase + Offset); + return MmioRead32 (Genet->RegBase + Offset); } /** @@ -53,15 +53,15 @@ GenetMmioRead ( STATIC VOID GenetMmioWrite ( - IN GENET_PRIVATE_DATA *Genet, - IN UINT32 Offset, - IN UINT32 Data - ) + IN GENET_PRIVATE_DATA *Genet, + IN UINT32 Offset, + IN UINT32 Data + ) { - ASSERT((Offset & 3) == 0); + ASSERT ((Offset & 3) == 0); - ArmDataSynchronizationBarrier (); - MmioWrite32 (Genet->RegBase + Offset, Data); + ArmDataSynchronizationBarrier (); + MmioWrite32 (Genet->RegBase + Offset, Data); } /** @@ -79,37 +79,38 @@ GenetMmioWrite ( EFI_STATUS EFIAPI GenetPhyRead ( - IN VOID *Priv, - IN UINT8 PhyAddr, - IN UINT8 Reg, - OUT UINT16 *Data - ) + IN VOID *Priv, + IN UINT8 PhyAddr, + IN UINT8 Reg, + OUT UINT16 *Data + ) { - GENET_PRIVATE_DATA *Genet = Priv; - UINTN Retry; - UINT32 Value; + GENET_PRIVATE_DATA *Genet = Priv; + UINTN Retry; + UINT32 Value; - Value = GENET_MDIO_READ | - GENET_MDIO_START_BUSY | - __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | - __SHIFTIN(Reg, GENET_MDIO_REG); - GenetMmioWrite (Genet, GENET_MDIO_CMD, Value); + Value = GENET_MDIO_READ | + GENET_MDIO_START_BUSY | + __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | + __SHIFTIN(Reg, GENET_MDIO_REG); + GenetMmioWrite (Genet, GENET_MDIO_CMD, Value); - for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { - Value = GenetMmioRead (Genet, GENET_MDIO_CMD); - if ((Value & GENET_MDIO_START_BUSY) == 0) { - *Data = Value & 0xffff; - break; - } - gBS->Stall (10); + for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { + Value = GenetMmioRead (Genet, GENET_MDIO_CMD); + if ((Value & GENET_MDIO_START_BUSY) == 0) { + *Data = Value & 0xffff; + break; } + gBS->Stall (10); + } - if (Retry == 0) { - DEBUG ((DEBUG_ERROR, "GenetPhyRead: Timeout reading PhyAddr %d, Reg %d\n", PhyAddr, Reg)); - return EFI_DEVICE_ERROR; - } + if (Retry == 0) { + DEBUG ((DEBUG_ERROR, + "%a: Timeout reading PhyAddr %d, Reg %d\n", __FUNCTION__, PhyAddr, Reg)); + return EFI_DEVICE_ERROR; + } - return EFI_SUCCESS; + return EFI_SUCCESS; } /** @@ -127,36 +128,37 @@ GenetPhyRead ( EFI_STATUS EFIAPI GenetPhyWrite ( - IN VOID *Priv, - IN UINT8 PhyAddr, - IN UINT8 Reg, - IN UINT16 Data - ) + IN VOID *Priv, + IN UINT8 PhyAddr, + IN UINT8 Reg, + IN UINT16 Data + ) { - GENET_PRIVATE_DATA *Genet = Priv; - UINTN Retry; - UINT32 Value; + GENET_PRIVATE_DATA *Genet = Priv; + UINTN Retry; + UINT32 Value; - Value = GENET_MDIO_WRITE | - GENET_MDIO_START_BUSY | - __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | - __SHIFTIN(Reg, GENET_MDIO_REG); - GenetMmioWrite (Genet, GENET_MDIO_CMD, Value | Data); + Value = GENET_MDIO_WRITE | + GENET_MDIO_START_BUSY | + __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | + __SHIFTIN(Reg, GENET_MDIO_REG); + GenetMmioWrite (Genet, GENET_MDIO_CMD, Value | Data); - for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { - Value = GenetMmioRead (Genet, GENET_MDIO_CMD); - if ((Value & GENET_MDIO_START_BUSY) == 0) { - break; - } - gBS->Stall (10); + for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { + Value = GenetMmioRead (Genet, GENET_MDIO_CMD); + if ((Value & GENET_MDIO_START_BUSY) == 0) { + break; } + gBS->Stall (10); + } - if (Retry == 0) { - DEBUG ((DEBUG_ERROR, "GenetPhyRead: Timeout writing PhyAddr %d, Reg %d\n", PhyAddr, Reg)); - return EFI_DEVICE_ERROR; - } + if (Retry == 0) { + DEBUG ((DEBUG_ERROR, + "%a: Timeout writing PhyAddr %d, Reg %d\n", __FUNCTION__, PhyAddr, Reg)); + return EFI_DEVICE_ERROR; + } - return EFI_SUCCESS; + return EFI_SUCCESS; } /** @@ -170,44 +172,44 @@ GenetPhyWrite ( VOID EFIAPI GenetPhyConfigure ( - IN VOID *Priv, - IN GENERIC_PHY_SPEED Speed, - IN GENERIC_PHY_DUPLEX Duplex - ) + IN VOID *Priv, + IN GENERIC_PHY_SPEED Speed, + IN GENERIC_PHY_DUPLEX Duplex + ) { - GENET_PRIVATE_DATA *Genet = Priv; - UINT32 Value; + GENET_PRIVATE_DATA *Genet = Priv; + UINT32 Value; - Value = GenetMmioRead (Genet, GENET_EXT_RGMII_OOB_CTRL); - Value &= ~GENET_EXT_RGMII_OOB_OOB_DISABLE; - Value |= GENET_EXT_RGMII_OOB_RGMII_LINK; - Value |= GENET_EXT_RGMII_OOB_RGMII_MODE_EN; - if (Genet->PhyMode == GENET_PHY_MODE_RGMII) { - Value |= GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; - } else { - Value &= ~GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; - } - GenetMmioWrite (Genet, GENET_EXT_RGMII_OOB_CTRL, Value); + Value = GenetMmioRead (Genet, GENET_EXT_RGMII_OOB_CTRL); + Value &= ~GENET_EXT_RGMII_OOB_OOB_DISABLE; + Value |= GENET_EXT_RGMII_OOB_RGMII_LINK; + Value |= GENET_EXT_RGMII_OOB_RGMII_MODE_EN; + if (Genet->PhyMode == GENET_PHY_MODE_RGMII) { + Value |= GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; + } else { + Value &= ~GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; + } + GenetMmioWrite (Genet, GENET_EXT_RGMII_OOB_CTRL, Value); - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); - Value &= ~GENET_UMAC_CMD_SPEED; - switch (Speed) { - case PHY_SPEED_1000: - Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_1000, GENET_UMAC_CMD_SPEED); - break; - case PHY_SPEED_100: - Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_100, GENET_UMAC_CMD_SPEED); - break; - default: - Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_10, GENET_UMAC_CMD_SPEED); - break; - } - if (Duplex == PHY_DUPLEX_FULL) { - Value &= ~GENET_UMAC_CMD_HD_EN; - } else { - Value |= GENET_UMAC_CMD_HD_EN; - } - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); + Value &= ~GENET_UMAC_CMD_SPEED; + switch (Speed) { + case PHY_SPEED_1000: + Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_1000, GENET_UMAC_CMD_SPEED); + break; + case PHY_SPEED_100: + Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_100, GENET_UMAC_CMD_SPEED); + break; + default: + Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_10, GENET_UMAC_CMD_SPEED); + break; + } + if (Duplex == PHY_DUPLEX_FULL) { + Value &= ~GENET_UMAC_CMD_HD_EN; + } else { + Value |= GENET_UMAC_CMD_HD_EN; + } + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); } /** @@ -231,12 +233,12 @@ GenetPhyResetAction ( BRGPHY_AUXCTL_SHADOW_MISC | BRGPHY_AUXCTL_SHADOW_MISC << BRGPHY_AUXCTL_MISC_READ_SHIFT); if (EFI_ERROR (Status)) { - return Status; + return Status; } Status = GenetPhyRead (Priv, Genet->Phy.PhyAddr, BRGPHY_MII_AUXCTL, &Value); if (EFI_ERROR (Status)) { - return Status; + return Status; } Value &= BRGPHY_AUXCTL_MISC_DATA_MASK; @@ -252,18 +254,18 @@ GenetPhyResetAction ( BRGPHY_AUXCTL_MISC_WRITE_EN | BRGPHY_AUXCTL_SHADOW_MISC | Value); if (EFI_ERROR (Status)) { - return Status; + return Status; } Status = GenetPhyWrite (Priv, Genet->Phy.PhyAddr, BRGPHY_MII_SHADOW_1C, - BRGPHY_SHADOW_1C_CLK_CTRL); + BRGPHY_SHADOW_1C_CLK_CTRL); if (EFI_ERROR (Status)) { - return Status; + return Status; } Status = GenetPhyRead (Priv, Genet->Phy.PhyAddr, BRGPHY_MII_SHADOW_1C, &Value); if (EFI_ERROR (Status)) { - return Status; + return Status; } Value &= BRGPHY_SHADOW_1C_DATA_MASK; @@ -279,7 +281,7 @@ GenetPhyResetAction ( BRGPHY_SHADOW_1C_WRITE_EN | BRGPHY_SHADOW_1C_CLK_CTRL | Value); if (EFI_ERROR (Status)) { - return Status; + return Status; } return EFI_SUCCESS; @@ -293,38 +295,40 @@ GenetPhyResetAction ( **/ VOID GenetReset ( - IN GENET_PRIVATE_DATA *Genet - ) + IN GENET_PRIVATE_DATA *Genet + ) { - UINT32 Value; + UINT32 Value; - Value = GenetMmioRead (Genet, GENET_SYS_RBUF_FLUSH_CTRL); - Value |= GENET_SYS_RBUF_FLUSH_RESET; - GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); - gBS->Stall (10); + Value = GenetMmioRead (Genet, GENET_SYS_RBUF_FLUSH_CTRL); + Value |= GENET_SYS_RBUF_FLUSH_RESET; + GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); + gBS->Stall (10); - Value &= ~GENET_SYS_RBUF_FLUSH_RESET; - GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); - gBS->Stall (10); + Value &= ~GENET_SYS_RBUF_FLUSH_RESET; + GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); + gBS->Stall (10); - GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, 0); - gBS->Stall (10); + GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, 0); + gBS->Stall (10); - GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); - GenetMmioWrite (Genet, GENET_UMAC_CMD, GENET_UMAC_CMD_LCL_LOOP_EN | GENET_UMAC_CMD_SW_RESET); - gBS->Stall (10); - GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); + GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); + GenetMmioWrite (Genet, GENET_UMAC_CMD, + GENET_UMAC_CMD_LCL_LOOP_EN | GENET_UMAC_CMD_SW_RESET); + gBS->Stall (10); + GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); - GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, GENET_UMAC_MIB_RESET_RUNT | GENET_UMAC_MIB_RESET_RX | GENET_UMAC_MIB_RESET_TX); - GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, 0); + GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, + GENET_UMAC_MIB_RESET_RUNT | GENET_UMAC_MIB_RESET_RX | GENET_UMAC_MIB_RESET_TX); + GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, 0); - GenetMmioWrite (Genet, GENET_UMAC_MAX_FRAME_LEN, 1536); + GenetMmioWrite (Genet, GENET_UMAC_MAX_FRAME_LEN, 1536); - Value = GenetMmioRead (Genet, GENET_RBUF_CTRL); - Value |= GENET_RBUF_ALIGN_2B; - GenetMmioWrite (Genet, GENET_RBUF_CTRL, Value); + Value = GenetMmioRead (Genet, GENET_RBUF_CTRL); + Value |= GENET_RBUF_ALIGN_2B; + GenetMmioWrite (Genet, GENET_RBUF_CTRL, Value); - GenetMmioWrite (Genet, GENET_RBUF_TBUF_SIZE_CTRL, 1); + GenetMmioWrite (Genet, GENET_RBUF_TBUF_SIZE_CTRL, 1); } /** @@ -337,20 +341,20 @@ GenetReset ( VOID EFIAPI GenetSetMacAddress ( - IN GENET_PRIVATE_DATA *Genet, - IN EFI_MAC_ADDRESS *MacAddr - ) + IN GENET_PRIVATE_DATA *Genet, + IN EFI_MAC_ADDRESS *MacAddr + ) { - UINT32 Value; + UINT32 Value; - Value = MacAddr->Addr[3] | - MacAddr->Addr[2] << 8 | - MacAddr->Addr[1] << 16 | - MacAddr->Addr[0] << 24; - GenetMmioWrite (Genet, GENET_UMAC_MAC0, Value); - Value = MacAddr->Addr[5] | - MacAddr->Addr[4] << 8; - GenetMmioWrite (Genet, GENET_UMAC_MAC1, Value); + Value = MacAddr->Addr[3] | + MacAddr->Addr[2] << 8 | + MacAddr->Addr[1] << 16 | + MacAddr->Addr[0] << 24; + GenetMmioWrite (Genet, GENET_UMAC_MAC0, Value); + Value = MacAddr->Addr[5] | + MacAddr->Addr[4] << 8; + GenetMmioWrite (Genet, GENET_UMAC_MAC1, Value); } /** @@ -362,24 +366,24 @@ GenetSetMacAddress ( **/ VOID GenetSetPhyMode ( - IN GENET_PRIVATE_DATA *Genet, - IN GENET_PHY_MODE PhyMode - ) + IN GENET_PRIVATE_DATA *Genet, + IN GENET_PHY_MODE PhyMode + ) { - UINT32 Value; + UINT32 Value; - switch (PhyMode) { - case GENET_PHY_MODE_RGMII: - case GENET_PHY_MODE_RGMII_RXID: - case GENET_PHY_MODE_RGMII_TXID: - case GENET_PHY_MODE_RGMII_ID: - Value = GENET_SYS_PORT_MODE_EXT_GPHY; - break; - default: - Value = 0; - break; - } - GenetMmioWrite (Genet, GENET_SYS_PORT_CTRL, Value); + switch (PhyMode) { + case GENET_PHY_MODE_RGMII: + case GENET_PHY_MODE_RGMII_RXID: + case GENET_PHY_MODE_RGMII_TXID: + case GENET_PHY_MODE_RGMII_ID: + Value = GENET_SYS_PORT_MODE_EXT_GPHY; + break; + default: + Value = 0; + break; + } + GenetMmioWrite (Genet, GENET_SYS_PORT_CTRL, Value); } /** @@ -390,31 +394,32 @@ GenetSetPhyMode ( **/ VOID GenetEnableTxRx ( - IN GENET_PRIVATE_DATA *Genet - ) + IN GENET_PRIVATE_DATA *Genet + ) { - UINT32 Value; - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; + UINT32 Value; + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; - // Start TX DMA on default queue - Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); - Value |= GENET_TX_DMA_CTRL_EN; - Value |= GENET_TX_DMA_CTRL_RBUF_EN(Qid); - GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); + // Start TX DMA on default queue + Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); + Value |= GENET_TX_DMA_CTRL_EN; + Value |= GENET_TX_DMA_CTRL_RBUF_EN (Qid); + GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); - // Start RX DMA on default queue - Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); - Value |= GENET_RX_DMA_CTRL_EN; - Value |= GENET_RX_DMA_CTRL_RBUF_EN(Qid); - GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); + // Start RX DMA on default queue + Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); + Value |= GENET_RX_DMA_CTRL_EN; + Value |= GENET_RX_DMA_CTRL_RBUF_EN (Qid); + GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); - // Enable transmitter and receiver - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); - Value |= GENET_UMAC_CMD_TXEN | GENET_UMAC_CMD_RXEN; - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); + // Enable transmitter and receiver + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); + Value |= GENET_UMAC_CMD_TXEN | GENET_UMAC_CMD_RXEN; + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); - // Enable interrupts - GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR_MASK, GENET_IRQ_TXDMA_DONE | GENET_IRQ_RXDMA_DONE); + // Enable interrupts + GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR_MASK, + GENET_IRQ_TXDMA_DONE | GENET_IRQ_RXDMA_DONE); } /** @@ -425,42 +430,42 @@ GenetEnableTxRx ( **/ VOID GenetDisableTxRx ( - IN GENET_PRIVATE_DATA *Genet - ) + IN GENET_PRIVATE_DATA *Genet + ) { - UINT32 Value; - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; + UINT32 Value; + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; - // Disable interrupts - GenetMmioWrite (Genet, GENET_INTRL2_CPU_SET_MASK, 0xFFFFFFFF); - GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR, 0xFFFFFFFF); + // Disable interrupts + GenetMmioWrite (Genet, GENET_INTRL2_CPU_SET_MASK, 0xFFFFFFFF); + GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR, 0xFFFFFFFF); - // Disable receiver - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); - Value &= ~GENET_UMAC_CMD_RXEN; - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); + // Disable receiver + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); + Value &= ~GENET_UMAC_CMD_RXEN; + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); - // Stop RX DMA - Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); - Value &= ~GENET_RX_DMA_CTRL_EN; - Value &= ~GENET_RX_DMA_CTRL_RBUF_EN(Qid); - GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); + // Stop RX DMA + Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); + Value &= ~GENET_RX_DMA_CTRL_EN; + Value &= ~GENET_RX_DMA_CTRL_RBUF_EN (Qid); + GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); - // Stop TX DMA - Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); - Value &= ~GENET_TX_DMA_CTRL_EN; - Value &= ~GENET_TX_DMA_CTRL_RBUF_EN(Qid); - GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); + // Stop TX DMA + Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); + Value &= ~GENET_TX_DMA_CTRL_EN; + Value &= ~GENET_TX_DMA_CTRL_RBUF_EN (Qid); + GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); - // Flush data in the TX FIFO - GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 1); - gBS->Stall (10); - GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 0); + // Flush data in the TX FIFO + GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 1); + gBS->Stall (10); + GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 0); - // Disable transmitter - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); - Value &= ~GENET_UMAC_CMD_TXEN; - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); + // Disable transmitter + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); + Value &= ~GENET_UMAC_CMD_TXEN; + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); } /** @@ -472,19 +477,19 @@ GenetDisableTxRx ( **/ VOID GenetSetPromisc ( - IN GENET_PRIVATE_DATA *Genet, - IN BOOLEAN Enable - ) + IN GENET_PRIVATE_DATA *Genet, + IN BOOLEAN Enable + ) { - UINT32 Value; + UINT32 Value; - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); - if (Enable) { - Value |= GENET_UMAC_CMD_PROMISC; - } else { - Value &= ~GENET_UMAC_CMD_PROMISC; - } - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); + if (Enable) { + Value |= GENET_UMAC_CMD_PROMISC; + } else { + Value &= ~GENET_UMAC_CMD_PROMISC; + } + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); } /** @@ -495,63 +500,63 @@ GenetSetPromisc ( **/ VOID GenetDmaInitRings ( - IN GENET_PRIVATE_DATA *Genet - ) + IN GENET_PRIVATE_DATA *Genet + ) { - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; - Genet->TxQueued = 0; - Genet->TxNext = 0; - Genet->TxConsIndex = 0; - Genet->TxProdIndex = 0; + Genet->TxQueued = 0; + Genet->TxNext = 0; + Genet->TxConsIndex = 0; + Genet->TxProdIndex = 0; - Genet->RxConsIndex = 0; - Genet->RxProdIndex = 0; + Genet->RxConsIndex = 0; + Genet->RxProdIndex = 0; - // Configure TX queue - GenetMmioWrite (Genet, GENET_TX_SCB_BURST_SIZE, 0x08); - GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_LO(Qid), 0); - GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_HI(Qid), 0); - GenetMmioWrite (Genet, GENET_TX_DMA_CONS_INDEX(Qid), 0); - GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX(Qid), 0); - GenetMmioWrite (Genet, GENET_TX_DMA_RING_BUF_SIZE(Qid), - __SHIFTIN(GENET_DMA_DESC_COUNT, GENET_TX_DMA_RING_BUF_SIZE_DESC_COUNT) | - __SHIFTIN(GENET_MAX_PACKET_SIZE, GENET_TX_DMA_RING_BUF_SIZE_BUF_LENGTH)); - GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_LO(Qid), 0); - GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_HI(Qid), 0); - GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_LO(Qid), - GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); - GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_HI(Qid), 0); - GenetMmioWrite (Genet, GENET_TX_DMA_MBUF_DONE_THRES(Qid), 1); - GenetMmioWrite (Genet, GENET_TX_DMA_FLOW_PERIOD(Qid), 0); - GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_LO(Qid), 0); - GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_HI(Qid), 0); + // Configure TX queue + GenetMmioWrite (Genet, GENET_TX_SCB_BURST_SIZE, 0x08); + GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_LO (Qid), 0); + GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_HI (Qid), 0); + GenetMmioWrite (Genet, GENET_TX_DMA_CONS_INDEX (Qid), 0); + GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX (Qid), 0); + GenetMmioWrite (Genet, GENET_TX_DMA_RING_BUF_SIZE (Qid), + __SHIFTIN(GENET_DMA_DESC_COUNT, GENET_TX_DMA_RING_BUF_SIZE_DESC_COUNT) | + __SHIFTIN(GENET_MAX_PACKET_SIZE, GENET_TX_DMA_RING_BUF_SIZE_BUF_LENGTH)); + GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_LO (Qid), 0); + GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_HI (Qid), 0); + GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_LO (Qid), + GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); + GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_HI (Qid), 0); + GenetMmioWrite (Genet, GENET_TX_DMA_MBUF_DONE_THRES (Qid), 1); + GenetMmioWrite (Genet, GENET_TX_DMA_FLOW_PERIOD (Qid), 0); + GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_LO (Qid), 0); + GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_HI (Qid), 0); - // Enable TX queue - GenetMmioWrite (Genet, GENET_TX_DMA_RING_CFG, (1U << Qid)); + // Enable TX queue + GenetMmioWrite (Genet, GENET_TX_DMA_RING_CFG, (1U << Qid)); - // Configure RX queue - GenetMmioWrite (Genet, GENET_RX_SCB_BURST_SIZE, 0x08); - GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_LO(Qid), 0); - GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_HI(Qid), 0); - GenetMmioWrite (Genet, GENET_RX_DMA_PROD_INDEX(Qid), 0); - GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX(Qid), 0); - GenetMmioWrite (Genet, GENET_RX_DMA_RING_BUF_SIZE(Qid), - __SHIFTIN(GENET_DMA_DESC_COUNT, GENET_RX_DMA_RING_BUF_SIZE_DESC_COUNT) | - __SHIFTIN(GENET_MAX_PACKET_SIZE, GENET_RX_DMA_RING_BUF_SIZE_BUF_LENGTH)); - GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_LO(Qid), 0); - GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_HI(Qid), 0); - GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_LO(Qid), - GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); - GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_HI(Qid), 0); - GenetMmioWrite (Genet, GENET_RX_DMA_XON_XOFF_THRES(Qid), - __SHIFTIN(5, GENET_RX_DMA_XON_XOFF_THRES_LO) | - __SHIFTIN(GENET_DMA_DESC_COUNT >> 4, GENET_RX_DMA_XON_XOFF_THRES_HI)); - GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_LO(Qid), 0); - GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_HI(Qid), 0); + // Configure RX queue + GenetMmioWrite (Genet, GENET_RX_SCB_BURST_SIZE, 0x08); + GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_LO (Qid), 0); + GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_HI (Qid), 0); + GenetMmioWrite (Genet, GENET_RX_DMA_PROD_INDEX (Qid), 0); + GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (Qid), 0); + GenetMmioWrite (Genet, GENET_RX_DMA_RING_BUF_SIZE (Qid), + __SHIFTIN(GENET_DMA_DESC_COUNT, GENET_RX_DMA_RING_BUF_SIZE_DESC_COUNT) | + __SHIFTIN(GENET_MAX_PACKET_SIZE, GENET_RX_DMA_RING_BUF_SIZE_BUF_LENGTH)); + GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_LO (Qid), 0); + GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_HI (Qid), 0); + GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_LO (Qid), + GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); + GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_HI (Qid), 0); + GenetMmioWrite (Genet, GENET_RX_DMA_XON_XOFF_THRES (Qid), + __SHIFTIN(5, GENET_RX_DMA_XON_XOFF_THRES_LO) | + __SHIFTIN(GENET_DMA_DESC_COUNT >> 4, GENET_RX_DMA_XON_XOFF_THRES_HI)); + GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_LO (Qid), 0); + GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_HI (Qid), 0); - // Enable RX queue - GenetMmioWrite (Genet, GENET_RX_DMA_RING_CFG, (1U << Qid)); + // Enable RX queue + GenetMmioWrite (Genet, GENET_RX_DMA_RING_CFG, (1U << Qid)); } /** @@ -564,22 +569,22 @@ GenetDmaInitRings ( **/ EFI_STATUS GenetDmaAlloc ( - IN GENET_PRIVATE_DATA *Genet - ) + IN GENET_PRIVATE_DATA *Genet + ) { - EFI_STATUS Status; - UINTN n; + EFI_STATUS Status; + UINTN Idx; - for (n = 0; n < GENET_DMA_DESC_COUNT; n++) { - Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[n]); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "GenetDmaAlloc: Failed to allocate RX buffer: %r\n", Status)); - GenetDmaFree (Genet); - return Status; - } + for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { + Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[Idx]); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate RX buffer: %r\n", __FUNCTION__, Status)); + GenetDmaFree (Genet); + return Status; } + } - return EFI_SUCCESS; + return EFI_SUCCESS; } /** @@ -594,33 +599,34 @@ GenetDmaAlloc ( **/ EFI_STATUS GenetDmaMapRxDescriptor ( - IN GENET_PRIVATE_DATA * Genet, - IN UINT8 DescIndex - ) + IN GENET_PRIVATE_DATA * Genet, + IN UINT8 DescIndex + ) { - EFI_STATUS Status; - UINTN DmaNumberOfBytes; + EFI_STATUS Status; + UINTN DmaNumberOfBytes; - ASSERT (Genet->RxBufferMap[DescIndex].Mapping == NULL); - ASSERT (Genet->RxBuffer[DescIndex] != NULL); + ASSERT (Genet->RxBufferMap[DescIndex].Mapping == NULL); + ASSERT (Genet->RxBuffer[DescIndex] != NULL); - DmaNumberOfBytes = GENET_MAX_PACKET_SIZE; - Status = DmaMap (MapOperationBusMasterWrite, - (VOID *)Genet->RxBuffer[DescIndex], - &DmaNumberOfBytes, - &Genet->RxBufferMap[DescIndex].Pa, - &Genet->RxBufferMap[DescIndex].Mapping); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "GenetDmaMapRxDescriptor: Failed to map RX buffer: %r\n", Status)); - return Status; - } + DmaNumberOfBytes = GENET_MAX_PACKET_SIZE; + Status = DmaMap (MapOperationBusMasterWrite, + (VOID *)Genet->RxBuffer[DescIndex], + &DmaNumberOfBytes, + &Genet->RxBufferMap[DescIndex].PhysAddress, + &Genet->RxBufferMap[DescIndex].Mapping); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to map RX buffer: %r\n", + __FUNCTION__, Status)); + return Status; + } - //DEBUG ((DEBUG_INFO, "GenetDmaMapRxDescriptor: Desc 0x%X mapped to 0x%X\n", DescIndex, Genet->RxBufferMap[DescIndex].Pa)); + GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_LO (DescIndex), + Genet->RxBufferMap[DescIndex].PhysAddress & 0xFFFFFFFF); + GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex), + (Genet->RxBufferMap[DescIndex].PhysAddress >> 32) & 0xFFFFFFFF); - GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_LO (DescIndex), Genet->RxBufferMap[DescIndex].Pa & 0xFFFFFFFF); - GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex), (Genet->RxBufferMap[DescIndex].Pa >> 32) & 0xFFFFFFFF); - - return EFI_SUCCESS; + return EFI_SUCCESS; } /** @@ -632,14 +638,14 @@ GenetDmaMapRxDescriptor ( **/ VOID GenetDmaUnmapRxDescriptor ( - IN GENET_PRIVATE_DATA * Genet, - IN UINT8 DescIndex - ) + IN GENET_PRIVATE_DATA * Genet, + IN UINT8 DescIndex + ) { - if (Genet->RxBufferMap[DescIndex].Mapping != NULL) { - DmaUnmap (Genet->RxBufferMap[DescIndex].Mapping); - Genet->RxBufferMap[DescIndex].Mapping = NULL; - } + if (Genet->RxBufferMap[DescIndex].Mapping != NULL) { + DmaUnmap (Genet->RxBufferMap[DescIndex].Mapping); + Genet->RxBufferMap[DescIndex].Mapping = NULL; + } } /** @@ -651,19 +657,20 @@ GenetDmaUnmapRxDescriptor ( **/ VOID GenetDmaFree ( - IN GENET_PRIVATE_DATA *Genet - ) + IN GENET_PRIVATE_DATA *Genet + ) { - UINTN n; + UINTN Idx; - for (n = 0; n < GENET_DMA_DESC_COUNT; n++) { - GenetDmaUnmapRxDescriptor (Genet, n); + for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { + GenetDmaUnmapRxDescriptor (Genet, Idx); - if (Genet->RxBuffer[n] != NULL) { - DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), Genet->RxBuffer[n]); - Genet->RxBuffer[n] = NULL; - } + if (Genet->RxBuffer[Idx] != NULL) { + DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), + Genet->RxBuffer[Idx]); + Genet->RxBuffer[Idx] = NULL; } + } } /** @@ -677,26 +684,29 @@ GenetDmaFree ( **/ VOID GenetDmaTriggerTx ( - IN GENET_PRIVATE_DATA * Genet, - IN UINT8 DescIndex, - IN EFI_PHYSICAL_ADDRESS PhysAddr, - IN UINTN NumberOfBytes - ) + IN GENET_PRIVATE_DATA * Genet, + IN UINT8 DescIndex, + IN EFI_PHYSICAL_ADDRESS PhysAddr, + IN UINTN NumberOfBytes + ) { - UINT32 DescStatus; - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; + UINT32 DescStatus; + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; - DescStatus = GENET_TX_DESC_STATUS_SOP | - GENET_TX_DESC_STATUS_EOP | - GENET_TX_DESC_STATUS_CRC | - GENET_TX_DESC_STATUS_QTAG | - __SHIFTIN(NumberOfBytes, GENET_TX_DESC_STATUS_BUFLEN); + DescStatus = GENET_TX_DESC_STATUS_SOP | + GENET_TX_DESC_STATUS_EOP | + GENET_TX_DESC_STATUS_CRC | + GENET_TX_DESC_STATUS_QTAG | + __SHIFTIN(NumberOfBytes, GENET_TX_DESC_STATUS_BUFLEN); - GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_LO(DescIndex), PhysAddr & 0xFFFFFFFF); - GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_HI(DescIndex), (PhysAddr >> 32) & 0xFFFFFFFF); - GenetMmioWrite (Genet, GENET_TX_DESC_STATUS(DescIndex), DescStatus); + GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_LO (DescIndex), + PhysAddr & 0xFFFFFFFF); + GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_HI (DescIndex), + (PhysAddr >> 32) & 0xFFFFFFFF); + GenetMmioWrite (Genet, GENET_TX_DESC_STATUS (DescIndex), DescStatus); - GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX (Qid), (DescIndex + 1) & 0xFFFF); + GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX (Qid), + (DescIndex + 1) & 0xFFFF); } /** @@ -708,24 +718,24 @@ GenetDmaTriggerTx ( **/ VOID GenetTxIntr ( - IN GENET_PRIVATE_DATA *Genet, - OUT VOID **TxBuf - ) + IN GENET_PRIVATE_DATA *Genet, + OUT VOID **TxBuf + ) { - UINT32 ConsIndex, Total; - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; + UINT32 ConsIndex, Total; + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; - ConsIndex = GenetMmioRead (Genet, GENET_TX_DMA_CONS_INDEX (Qid)) & 0xFFFF; + ConsIndex = GenetMmioRead (Genet, GENET_TX_DMA_CONS_INDEX (Qid)) & 0xFFFF; - Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; - if (Genet->TxQueued > 0 && Total > 0) { - *TxBuf = Genet->TxBuffer[Genet->TxNext]; - Genet->TxQueued--; - Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT; - Genet->TxConsIndex++; - } else { - *TxBuf = NULL; - } + Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; + if (Genet->TxQueued > 0 && Total > 0) { + *TxBuf = Genet->TxBuffer[Genet->TxNext]; + Genet->TxQueued--; + Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT; + Genet->TxConsIndex++; + } else { + *TxBuf = NULL; + } } /** @@ -742,32 +752,30 @@ GenetTxIntr ( **/ EFI_STATUS GenetRxIntr ( - IN GENET_PRIVATE_DATA *Genet, - OUT UINT8 *DescIndex, - OUT UINTN *FrameLength - ) + IN GENET_PRIVATE_DATA *Genet, + OUT UINT8 *DescIndex, + OUT UINTN *FrameLength + ) { - EFI_STATUS Status; - UINT32 ProdIndex, Total; - UINT32 DescStatus; - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; + EFI_STATUS Status; + UINT32 ProdIndex, Total; + UINT32 DescStatus; + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; - ProdIndex = GenetMmioRead (Genet, GENET_RX_DMA_PROD_INDEX (Qid)) & 0xFFFF; + ProdIndex = GenetMmioRead (Genet, GENET_RX_DMA_PROD_INDEX (Qid)) & 0xFFFF; - Total = (ProdIndex - Genet->RxConsIndex) & 0xFFFF; - if (Total > 0) { - *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT; - DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS (*DescIndex)); - *FrameLength = __SHIFTOUT (DescStatus, GENET_RX_DESC_STATUS_BUFLEN); + Total = (ProdIndex - Genet->RxConsIndex) & 0xFFFF; + if (Total > 0) { + *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT; + DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS (*DescIndex)); + *FrameLength = __SHIFTOUT (DescStatus, GENET_RX_DESC_STATUS_BUFLEN); - //DEBUG ((DEBUG_INFO, "GenetRxIntr: DescIndex=0x%X FrameLength=0x%X\n", *DescIndex, *FrameLength)); + Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0xFFFF; + GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (Qid), Genet->RxConsIndex); + Status = EFI_SUCCESS; + } else { + Status = EFI_NOT_READY; + } - Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0xFFFF; - GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (Qid), Genet->RxConsIndex); - Status = EFI_SUCCESS; - } else { - Status = EFI_NOT_READY; - } - - return Status; + return Status; } diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c index bf28448445d1..951495127ce9 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c @@ -31,7 +31,7 @@ GenetSimpleNetworkStart ( IN EFI_SIMPLE_NETWORK_PROTOCOL *This ) { - GENET_PRIVATE_DATA *Genet; + GENET_PRIVATE_DATA *Genet; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -67,7 +67,7 @@ GenetSimpleNetworkStop ( IN EFI_SIMPLE_NETWORK_PROTOCOL *This ) { - GENET_PRIVATE_DATA *Genet; + GENET_PRIVATE_DATA *Genet; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -194,8 +194,8 @@ GenetSimpleNetworkReset ( IN BOOLEAN ExtendedVerification ) { - GENET_PRIVATE_DATA *Genet; - EFI_STATUS Status; + GENET_PRIVATE_DATA *Genet; + EFI_STATUS Status; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -299,7 +299,7 @@ GenetSimpleNetworkReceiveFilters ( IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL ) { - GENET_PRIVATE_DATA *Genet; + GENET_PRIVATE_DATA *Genet; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -347,7 +347,7 @@ GenetSimpleNetworkStationAddress ( IN EFI_MAC_ADDRESS *New OPTIONAL ) { - GENET_PRIVATE_DATA *Genet; + GENET_PRIVATE_DATA *Genet; if (This == NULL || This->Mode == NULL) { return EFI_INVALID_PARAMETER; @@ -480,8 +480,8 @@ GenetSimpleNetworkGetStatus ( OUT VOID **TxBuf OPTIONAL ) { - GENET_PRIVATE_DATA *Genet; - EFI_STATUS Status; + GENET_PRIVATE_DATA *Genet; + EFI_STATUS Status; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -555,17 +555,17 @@ GenetSimpleNetworkTransmit ( IN UINT16 *Protocol OPTIONAL ) { - GENET_PRIVATE_DATA *Genet; - EFI_STATUS Status; - UINT8 *Frame = Buffer; - UINT8 Desc; - PHYSICAL_ADDRESS DmaDeviceAddress; - UINTN DmaNumberOfBytes; - VOID *DmaMapping; + GENET_PRIVATE_DATA *Genet; + EFI_STATUS Status; + UINT8 *Frame = Buffer; + UINT8 Desc; + PHYSICAL_ADDRESS DmaDeviceAddress; + UINTN DmaNumberOfBytes; + VOID *DmaMapping; if (This == NULL || Buffer == NULL) { - DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkTransmit: Invalid parameter (missing handle or buffer)\n")); + DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or buffer)\n", + __FUNCTION__)); return EFI_INVALID_PARAMETER; } @@ -587,32 +587,33 @@ GenetSimpleNetworkTransmit ( if (HeaderSize != 0) { if (HeaderSize != Genet->SnpMode.MediaHeaderSize) { DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkTransmit: Invalid parameter (header size mismatch; HeaderSize 0x%X, SnpMode.MediaHeaderSize 0x%X))\n", HeaderSize, Genet->SnpMode.MediaHeaderSize)); + "%a: Invalid parameter (header size mismatch; HeaderSize 0x%X, SnpMode.MediaHeaderSize 0x%X))\n", + __FUNCTION__, HeaderSize, Genet->SnpMode.MediaHeaderSize)); return EFI_INVALID_PARAMETER; } if (DestAddr == NULL || Protocol == NULL) { DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkTransmit: Invalid parameter (dest addr or protocol missing)\n")); + "%a: Invalid parameter (dest addr or protocol missing)\n", + __FUNCTION__)); return EFI_INVALID_PARAMETER; } } if (BufferSize < Genet->SnpMode.MediaHeaderSize) { - DEBUG ((DEBUG_ERROR, "GenetSimpleNetworkTransmit: Buffer too small\n")); + DEBUG ((DEBUG_ERROR, "%a: Buffer too small\n", __FUNCTION__)); return EFI_BUFFER_TOO_SMALL; } Status = EfiAcquireLockOrFail (&Genet->Lock); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkTransmit: Couldn't get lock: %r\n", Status)); + DEBUG ((DEBUG_ERROR, "%a: Couldn't get lock: %r\n", __FUNCTION__, Status)); return EFI_ACCESS_DENIED; } if (Genet->TxQueued == GENET_DMA_DESC_COUNT - 1) { EfiReleaseLock (&Genet->Lock); - DEBUG ((DEBUG_ERROR, "GenetSimpleNetworkTransmit: Queue full\n")); + DEBUG ((DEBUG_ERROR, "%a: Queue full\n", __FUNCTION__)); return EFI_NOT_READY; } @@ -634,8 +635,7 @@ GenetSimpleNetworkTransmit ( &DmaDeviceAddress, &DmaMapping); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkTransmit: DmaMap failed: %r\n", Status)); + DEBUG ((DEBUG_ERROR, "%a: DmaMap failed: %r\n", __FUNCTION__, Status)); EfiReleaseLock (&Genet->Lock); return Status; } @@ -703,8 +703,8 @@ GenetSimpleNetworkReceive ( UINTN FrameLength; if (This == NULL || Buffer == NULL) { - DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkReceive: Invalid parameter (missing handle or buffer)\n")); + DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or buffer)\n", + __FUNCTION__)); return EFI_INVALID_PARAMETER; } @@ -718,8 +718,7 @@ GenetSimpleNetworkReceive ( Status = EfiAcquireLockOrFail (&Genet->Lock); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkReceive: Couldn't get lock: %r\n", Status)); + DEBUG ((DEBUG_ERROR, "%a: Couldn't get lock: %r\n", __FUNCTION__, Status)); return EFI_ACCESS_DENIED; } @@ -742,12 +741,12 @@ GenetSimpleNetworkReceive ( if (*BufferSize < FrameLength) { DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkReceive: Buffer size (0x%X) is too small for frame (0x%X)\n", - *BufferSize, FrameLength)); + "%a: Buffer size (0x%X) is too small for frame (0x%X)\n", + __FUNCTION__, *BufferSize, FrameLength)); Status = GenetDmaMapRxDescriptor (Genet, DescIndex); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkReceive: Failed to remap RX descriptor!\n")); + DEBUG ((DEBUG_ERROR, "%a: Failed to remap RX descriptor!\n", + __FUNCTION__)); } EfiReleaseLock (&Genet->Lock); return EFI_BUFFER_TOO_SMALL; @@ -771,16 +770,14 @@ GenetSimpleNetworkReceive ( Status = EFI_SUCCESS; } else { - DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkReceive: Short packet (FrameLength 0x%X)", - FrameLength)); + DEBUG ((DEBUG_ERROR, "%a: Short packet (FrameLength 0x%X)", + __FUNCTION__, FrameLength)); Status = EFI_NOT_READY; } Status = GenetDmaMapRxDescriptor (Genet, DescIndex); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, - "GenetSimpleNetworkReceive: Failed to remap RX descriptor!\n")); + DEBUG ((DEBUG_ERROR, "%a: Failed to remap RX descriptor!\n", __FUNCTION__)); } EfiReleaseLock (&Genet->Lock); @@ -791,12 +788,12 @@ GenetSimpleNetworkReceive ( This function converts a multicast IP address to a multicast HW MAC address for all packet transactions. - @param [in] pSimpleNetwork Protocol instance pointer - @param [in] bIPv6 Set to TRUE if the multicast IP address is IPv6 [RFC2460]. + @param [in] SimpleNetwork Protocol instance pointer + @param [in] IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC2460]. Set to FALSE if the multicast IP address is IPv4 [RFC 791]. - @param [in] pIP The multicast IP address that is to be converted to a + @param [in] IP The multicast IP address that is to be converted to a multicast HW MAC address. - @param [in] pMAC The multicast HW MAC address that is to be generated from IP. + @param [in] MAC The multicast HW MAC address that is to be generated from IP. @retval EFI_SUCCESS This operation was successful. @retval EFI_NOT_STARTED The network interface was not started. @@ -810,10 +807,10 @@ STATIC EFI_STATUS EFIAPI GenetSimpleNetworkMCastIPtoMAC ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *pSimpleNetwork, - IN BOOLEAN bIPv6, - IN EFI_IP_ADDRESS *pIP, - OUT EFI_MAC_ADDRESS *pMAC + IN EFI_SIMPLE_NETWORK_PROTOCOL *SimpleNetwork, + IN BOOLEAN IPv6, + IN EFI_IP_ADDRESS *IP, + OUT EFI_MAC_ADDRESS *MAC ) { return EFI_UNSUPPORTED; @@ -822,7 +819,6 @@ GenetSimpleNetworkMCastIPtoMAC ( /// /// Simple Network Protocol instance /// -GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_SIMPLE_NETWORK_PROTOCOL gGenetSimpleNetworkTemplate = { EFI_SIMPLE_NETWORK_PROTOCOL_REVISION, // Revision GenetSimpleNetworkStart, // Start -- 2.17.1 ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup 2020-05-11 14:55 ` [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Ard Biesheuvel @ 2020-05-11 16:36 ` Samer El-Haj-Mahmoud 2020-05-11 21:14 ` [edk2-devel] " Philippe Mathieu-Daudé 1 sibling, 0 replies; 25+ messages in thread From: Samer El-Haj-Mahmoud @ 2020-05-11 16:36 UTC (permalink / raw) To: Ard Biesheuvel, devel@edk2.groups.io Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin (awarkentin@vmware.com), Jeremy Linton Reviewed-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com> > -----Original Message----- > From: Ard Biesheuvel <ard.biesheuvel@arm.com> > Sent: Monday, May 11, 2020 10:55 AM > To: devel@edk2.groups.io > Cc: Ard Biesheuvel <Ard.Biesheuvel@arm.com>; Pete Batard > <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin > (awarkentin@vmware.com) <awarkentin@vmware.com>; Samer El-Haj- > Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton > <Jeremy.Linton@arm.com> > Subject: [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: > whitespace/cosmetic cleanup > > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> > --- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 2 + > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 38 +- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 19 +- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c | 16 +- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 744 > ++++++++++---------- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 90 ++- > 6 files changed, 456 insertions(+), 453 deletions(-) > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > index e74fa02ad209..1f1aeca7dd6b 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > @@ -21,7 +21,9 @@ [Sources] > ComponentName.c > DriverBinding.c > GenericPhy.c > + GenericPhy.h > GenetUtil.c > + GenetUtil.h > SimpleNetwork.c > > [Packages] > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > index 2e7b78322bcd..b21a284b6221 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > @@ -185,7 +185,7 @@ > #define GENET_TX_SCB_BURST_SIZE (GENET_TX_BASE + 0x1040 + > 0x0c) > > typedef struct { > - EFI_PHYSICAL_ADDRESS Pa; > + EFI_PHYSICAL_ADDRESS PhysAddress; > VOID * Mapping; > } GENET_MAP_INFO; > > @@ -198,32 +198,32 @@ typedef enum { > } GENET_PHY_MODE; > > typedef struct { > - UINT32 Signature; > - EFI_HANDLE ControllerHandle; > + UINT32 Signature; > + EFI_HANDLE ControllerHandle; > > - EFI_LOCK Lock; > + EFI_LOCK Lock; > > - EFI_SIMPLE_NETWORK_PROTOCOL Snp; > - EFI_SIMPLE_NETWORK_MODE SnpMode; > + EFI_SIMPLE_NETWORK_PROTOCOL Snp; > + EFI_SIMPLE_NETWORK_MODE SnpMode; > > - BCM_GENET_PLATFORM_DEVICE_PROTOCOL *Dev; > + BCM_GENET_PLATFORM_DEVICE_PROTOCOL *Dev; > > - GENERIC_PHY_PRIVATE_DATA Phy; > + GENERIC_PHY_PRIVATE_DATA Phy; > > - UINT8 * TxBuffer[GENET_DMA_DESC_COUNT]; > - UINT8 TxQueued; > - UINT16 TxNext; > - UINT16 TxConsIndex; > - UINT16 TxProdIndex; > + UINT8 *TxBuffer[GENET_DMA_DESC_COUNT]; > + UINT8 TxQueued; > + UINT16 TxNext; > + UINT16 TxConsIndex; > + UINT16 TxProdIndex; > > - UINT8 * RxBuffer[GENET_DMA_DESC_COUNT]; > - GENET_MAP_INFO RxBufferMap[GENET_DMA_DESC_COUNT]; > - UINT16 RxConsIndex; > - UINT16 RxProdIndex; > + UINT8 *RxBuffer[GENET_DMA_DESC_COUNT]; > + GENET_MAP_INFO > RxBufferMap[GENET_DMA_DESC_COUNT]; > + UINT16 RxConsIndex; > + UINT16 RxProdIndex; > > - GENET_PHY_MODE PhyMode; > + GENET_PHY_MODE PhyMode; > > - UINTN RegBase; > + UINTN RegBase; > } GENET_PRIVATE_DATA; > > extern EFI_COMPONENT_NAME_PROTOCOL > gGenetComponentName; > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > index e3d015dd0820..c23847ba9b52 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > @@ -55,14 +55,12 @@ GenetDriverBindingSupported ( > // > Status = gBS->OpenProtocol (ControllerHandle, > &gBcmGenetPlatformDeviceProtocolGuid, > - (VOID **) &Dev, > + (VOID **)&Dev, > This->DriverBindingHandle, > ControllerHandle, > EFI_OPEN_PROTOCOL_BY_DRIVER); > if (EFI_ERROR (Status)) { > return Status; > - } else { > - Status = EFI_SUCCESS; > } > > // > @@ -73,7 +71,7 @@ GenetDriverBindingSupported ( > This->DriverBindingHandle, > ControllerHandle); > > - return Status; > + return EFI_SUCCESS; > } > > > @@ -111,7 +109,7 @@ GenetDriverBindingStart ( > Genet = AllocateZeroPool (sizeof (GENET_PRIVATE_DATA)); > if (Genet == NULL) { > DEBUG ((DEBUG_ERROR, > - "GenetDriverBindingStart: Couldn't allocate private data\n")); > + "%a: Couldn't allocate private data\n", __FUNCTION__)); > return EFI_OUT_OF_RESOURCES; > } > > @@ -123,14 +121,14 @@ GenetDriverBindingStart ( > EFI_OPEN_PROTOCOL_BY_DRIVER); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, > - "GenetDriverBindingStart: Couldn't open protocol: %r\n", Status)); > + "%a: Couldn't open protocol: %r\n", __FUNCTION__, Status)); > goto FreeDevice; > } > > Status = GenetDmaAlloc (Genet); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, > - "GenetDriverBindingStart: Couldn't allocate DMA buffers: %r\n", Status)); > + "%a: Couldn't allocate DMA buffers: %r\n", __FUNCTION__, > + Status)); > goto FreeDevice; > } > > @@ -180,8 +178,7 @@ GenetDriverBindingStart ( > > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, > - "GenetDriverBindingStart: Couldn't install protocol interfaces: %r\n", > - Status)); > + "%a: Couldn't install protocol interfaces: %r\n", __FUNCTION__, > + Status)); > gBS->CloseProtocol (ControllerHandle, > &gBcmGenetPlatformDeviceProtocolGuid, > This->DriverBindingHandle, @@ -190,10 +187,10 @@ > GenetDriverBindingStart ( > } > > Genet->ControllerHandle = ControllerHandle; > - return Status; > + return EFI_SUCCESS; > > FreeDevice: > - DEBUG ((DEBUG_WARN, "GenetDriverBindingStart: Returning %r\n", > Status)); > + DEBUG ((DEBUG_WARN, "%a: Returning %r\n", __FUNCTION__, Status)); > FreePool (Genet); > return Status; > } > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c > index a3c709891bc9..cd2788adc52c 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c > @@ -115,8 +115,8 @@ GenericPhyDetect ( > if (Id1 != 0xFFFF && Id2 != 0xFFFF) { > Phy->PhyAddr = PhyAddr; > DEBUG ((DEBUG_INFO, > - "GenericPhyDetect: PHY detected at address 0x%02X > (PHYIDR1=0x%04X, PHYIDR2=0x%04X)\n", > - PhyAddr, Id1, Id2)); > + "%a: PHY detected at address 0x%02X (PHYIDR1=0x%04X, > PHYIDR2=0x%04X)\n", > + __FUNCTION__, PhyAddr, Id1, Id2)); > return EFI_SUCCESS; > } > } > @@ -348,8 +348,8 @@ GenericPhyGetConfig ( > *Duplex = (An & GENERIC_PHY_ANAR_10BASET_FDX) ? > PHY_DUPLEX_FULL : PHY_DUPLEX_HALF; > } > > - DEBUG ((DEBUG_INFO, "GenericPhyGetConfig: Link speed %d Mbps, %a- > duplex\n", > - *Speed, *Duplex == PHY_DUPLEX_FULL ? "full" : "half")); > + DEBUG ((DEBUG_INFO, "%a: Link speed %d Mbps, %a-duplex\n", > + __FUNCTION__, *Speed, *Duplex == PHY_DUPLEX_FULL ? "full" : > + "half")); > > return EFI_SUCCESS; > } > @@ -367,8 +367,8 @@ GenericPhyGetConfig ( EFI_STATUS EFIAPI > GenericPhyUpdateConfig ( > - IN GENERIC_PHY_PRIVATE_DATA *Phy > - ) > + IN GENERIC_PHY_PRIVATE_DATA *Phy > + ) > { > EFI_STATUS Status; > GENERIC_PHY_SPEED Speed; > @@ -380,7 +380,7 @@ GenericPhyUpdateConfig ( > > if (Phy->LinkUp != LinkUp) { > if (LinkUp) { > - DEBUG ((DEBUG_VERBOSE, "GenericPhyUpdateConfig: Link is up\n")); > + DEBUG ((DEBUG_VERBOSE, "%a: Link is up\n", __FUNCTION__)); > > Status = GenericPhyGetConfig (Phy, &Speed, &Duplex); > if (EFI_ERROR (Status)) { > @@ -389,7 +389,7 @@ GenericPhyUpdateConfig ( > > GenericPhyConfigure (Phy, Speed, Duplex); > } else { > - DEBUG ((DEBUG_VERBOSE, "GenericPhyUpdateConfig: Link is down\n")); > + DEBUG ((DEBUG_VERBOSE, "%a: Link is down\n", __FUNCTION__)); > } > } > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > index d471b1cadadc..7ae9acec4c78 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > @@ -31,13 +31,13 @@ > STATIC > UINT32 > GenetMmioRead ( > - IN GENET_PRIVATE_DATA *Genet, > - IN UINT32 Offset > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN UINT32 Offset > + ) > { > - ASSERT((Offset & 3) == 0); > + ASSERT ((Offset & 3) == 0); > > - return MmioRead32 (Genet->RegBase + Offset); > + return MmioRead32 (Genet->RegBase + Offset); > } > > /** > @@ -53,15 +53,15 @@ GenetMmioRead ( > STATIC > VOID > GenetMmioWrite ( > - IN GENET_PRIVATE_DATA *Genet, > - IN UINT32 Offset, > - IN UINT32 Data > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN UINT32 Offset, > + IN UINT32 Data > + ) > { > - ASSERT((Offset & 3) == 0); > + ASSERT ((Offset & 3) == 0); > > - ArmDataSynchronizationBarrier (); > - MmioWrite32 (Genet->RegBase + Offset, Data); > + ArmDataSynchronizationBarrier (); > + MmioWrite32 (Genet->RegBase + Offset, Data); > } > > /** > @@ -79,37 +79,38 @@ GenetMmioWrite ( > EFI_STATUS > EFIAPI > GenetPhyRead ( > - IN VOID *Priv, > - IN UINT8 PhyAddr, > - IN UINT8 Reg, > - OUT UINT16 *Data > - ) > + IN VOID *Priv, > + IN UINT8 PhyAddr, > + IN UINT8 Reg, > + OUT UINT16 *Data > + ) > { > - GENET_PRIVATE_DATA *Genet = Priv; > - UINTN Retry; > - UINT32 Value; > + GENET_PRIVATE_DATA *Genet = Priv; > + UINTN Retry; > + UINT32 Value; > > - Value = GENET_MDIO_READ | > - GENET_MDIO_START_BUSY | > - __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | > - __SHIFTIN(Reg, GENET_MDIO_REG); > - GenetMmioWrite (Genet, GENET_MDIO_CMD, Value); > + Value = GENET_MDIO_READ | > + GENET_MDIO_START_BUSY | > + __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | > + __SHIFTIN(Reg, GENET_MDIO_REG); GenetMmioWrite (Genet, > + GENET_MDIO_CMD, Value); > > - for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { > - Value = GenetMmioRead (Genet, GENET_MDIO_CMD); > - if ((Value & GENET_MDIO_START_BUSY) == 0) { > - *Data = Value & 0xffff; > - break; > - } > - gBS->Stall (10); > + for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { > + Value = GenetMmioRead (Genet, GENET_MDIO_CMD); > + if ((Value & GENET_MDIO_START_BUSY) == 0) { > + *Data = Value & 0xffff; > + break; > } > + gBS->Stall (10); > + } > > - if (Retry == 0) { > - DEBUG ((DEBUG_ERROR, "GenetPhyRead: Timeout reading PhyAddr > %d, Reg %d\n", PhyAddr, Reg)); > - return EFI_DEVICE_ERROR; > - } > + if (Retry == 0) { > + DEBUG ((DEBUG_ERROR, > + "%a: Timeout reading PhyAddr %d, Reg %d\n", __FUNCTION__, > PhyAddr, Reg)); > + return EFI_DEVICE_ERROR; > + } > > - return EFI_SUCCESS; > + return EFI_SUCCESS; > } > > /** > @@ -127,36 +128,37 @@ GenetPhyRead ( > EFI_STATUS > EFIAPI > GenetPhyWrite ( > - IN VOID *Priv, > - IN UINT8 PhyAddr, > - IN UINT8 Reg, > - IN UINT16 Data > - ) > + IN VOID *Priv, > + IN UINT8 PhyAddr, > + IN UINT8 Reg, > + IN UINT16 Data > + ) > { > - GENET_PRIVATE_DATA *Genet = Priv; > - UINTN Retry; > - UINT32 Value; > + GENET_PRIVATE_DATA *Genet = Priv; > + UINTN Retry; > + UINT32 Value; > > - Value = GENET_MDIO_WRITE | > - GENET_MDIO_START_BUSY | > - __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | > - __SHIFTIN(Reg, GENET_MDIO_REG); > - GenetMmioWrite (Genet, GENET_MDIO_CMD, Value | Data); > + Value = GENET_MDIO_WRITE | > + GENET_MDIO_START_BUSY | > + __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | > + __SHIFTIN(Reg, GENET_MDIO_REG); GenetMmioWrite (Genet, > + GENET_MDIO_CMD, Value | Data); > > - for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { > - Value = GenetMmioRead (Genet, GENET_MDIO_CMD); > - if ((Value & GENET_MDIO_START_BUSY) == 0) { > - break; > - } > - gBS->Stall (10); > + for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { > + Value = GenetMmioRead (Genet, GENET_MDIO_CMD); > + if ((Value & GENET_MDIO_START_BUSY) == 0) { > + break; > } > + gBS->Stall (10); > + } > > - if (Retry == 0) { > - DEBUG ((DEBUG_ERROR, "GenetPhyRead: Timeout writing PhyAddr %d, > Reg %d\n", PhyAddr, Reg)); > - return EFI_DEVICE_ERROR; > - } > + if (Retry == 0) { > + DEBUG ((DEBUG_ERROR, > + "%a: Timeout writing PhyAddr %d, Reg %d\n", __FUNCTION__, PhyAddr, > Reg)); > + return EFI_DEVICE_ERROR; > + } > > - return EFI_SUCCESS; > + return EFI_SUCCESS; > } > > /** > @@ -170,44 +172,44 @@ GenetPhyWrite ( > VOID > EFIAPI > GenetPhyConfigure ( > - IN VOID *Priv, > - IN GENERIC_PHY_SPEED Speed, > - IN GENERIC_PHY_DUPLEX Duplex > - ) > + IN VOID *Priv, > + IN GENERIC_PHY_SPEED Speed, > + IN GENERIC_PHY_DUPLEX Duplex > + ) > { > - GENET_PRIVATE_DATA *Genet = Priv; > - UINT32 Value; > + GENET_PRIVATE_DATA *Genet = Priv; > + UINT32 Value; > > - Value = GenetMmioRead (Genet, GENET_EXT_RGMII_OOB_CTRL); > - Value &= ~GENET_EXT_RGMII_OOB_OOB_DISABLE; > - Value |= GENET_EXT_RGMII_OOB_RGMII_LINK; > - Value |= GENET_EXT_RGMII_OOB_RGMII_MODE_EN; > - if (Genet->PhyMode == GENET_PHY_MODE_RGMII) { > - Value |= GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; > - } else { > - Value &= ~GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; > - } > - GenetMmioWrite (Genet, GENET_EXT_RGMII_OOB_CTRL, Value); > + Value = GenetMmioRead (Genet, GENET_EXT_RGMII_OOB_CTRL); Value > &= > + ~GENET_EXT_RGMII_OOB_OOB_DISABLE; Value |= > + GENET_EXT_RGMII_OOB_RGMII_LINK; Value |= > + GENET_EXT_RGMII_OOB_RGMII_MODE_EN; > + if (Genet->PhyMode == GENET_PHY_MODE_RGMII) { > + Value |= GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; > + } else { > + Value &= ~GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; > + } > + GenetMmioWrite (Genet, GENET_EXT_RGMII_OOB_CTRL, Value); > > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - Value &= ~GENET_UMAC_CMD_SPEED; > - switch (Speed) { > - case PHY_SPEED_1000: > - Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_1000, > GENET_UMAC_CMD_SPEED); > - break; > - case PHY_SPEED_100: > - Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_100, > GENET_UMAC_CMD_SPEED); > - break; > - default: > - Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_10, > GENET_UMAC_CMD_SPEED); > - break; > - } > - if (Duplex == PHY_DUPLEX_FULL) { > - Value &= ~GENET_UMAC_CMD_HD_EN; > - } else { > - Value |= GENET_UMAC_CMD_HD_EN; > - } > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); Value &= > + ~GENET_UMAC_CMD_SPEED; switch (Speed) { > + case PHY_SPEED_1000: > + Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_1000, > GENET_UMAC_CMD_SPEED); > + break; > + case PHY_SPEED_100: > + Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_100, > GENET_UMAC_CMD_SPEED); > + break; > + default: > + Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_10, > GENET_UMAC_CMD_SPEED); > + break; > + } > + if (Duplex == PHY_DUPLEX_FULL) { > + Value &= ~GENET_UMAC_CMD_HD_EN; > + } else { > + Value |= GENET_UMAC_CMD_HD_EN; > + } > + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > } > > /** > @@ -231,12 +233,12 @@ GenetPhyResetAction ( > BRGPHY_AUXCTL_SHADOW_MISC | > BRGPHY_AUXCTL_SHADOW_MISC > << BRGPHY_AUXCTL_MISC_READ_SHIFT); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Status = GenetPhyRead (Priv, Genet->Phy.PhyAddr, BRGPHY_MII_AUXCTL, > &Value); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Value &= BRGPHY_AUXCTL_MISC_DATA_MASK; @@ -252,18 +254,18 @@ > GenetPhyResetAction ( > BRGPHY_AUXCTL_MISC_WRITE_EN | > BRGPHY_AUXCTL_SHADOW_MISC | > Value); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Status = GenetPhyWrite (Priv, Genet->Phy.PhyAddr, > BRGPHY_MII_SHADOW_1C, > - BRGPHY_SHADOW_1C_CLK_CTRL); > + BRGPHY_SHADOW_1C_CLK_CTRL); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Status = GenetPhyRead (Priv, Genet->Phy.PhyAddr, > BRGPHY_MII_SHADOW_1C, &Value); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Value &= BRGPHY_SHADOW_1C_DATA_MASK; > @@ -279,7 +281,7 @@ GenetPhyResetAction ( > BRGPHY_SHADOW_1C_WRITE_EN | > BRGPHY_SHADOW_1C_CLK_CTRL | > Value); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > return EFI_SUCCESS; > @@ -293,38 +295,40 @@ GenetPhyResetAction ( **/ VOID GenetReset ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINT32 Value; > + UINT32 Value; > > - Value = GenetMmioRead (Genet, GENET_SYS_RBUF_FLUSH_CTRL); > - Value |= GENET_SYS_RBUF_FLUSH_RESET; > - GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); > - gBS->Stall (10); > + Value = GenetMmioRead (Genet, GENET_SYS_RBUF_FLUSH_CTRL); Value > |= > + GENET_SYS_RBUF_FLUSH_RESET; GenetMmioWrite (Genet, > + GENET_SYS_RBUF_FLUSH_CTRL, Value); gBS->Stall (10); > > - Value &= ~GENET_SYS_RBUF_FLUSH_RESET; > - GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); > - gBS->Stall (10); > + Value &= ~GENET_SYS_RBUF_FLUSH_RESET; GenetMmioWrite (Genet, > + GENET_SYS_RBUF_FLUSH_CTRL, Value); gBS->Stall (10); > > - GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, 0); > - gBS->Stall (10); > + GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, 0); gBS->Stall > + (10); > > - GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); > - GenetMmioWrite (Genet, GENET_UMAC_CMD, > GENET_UMAC_CMD_LCL_LOOP_EN | GENET_UMAC_CMD_SW_RESET); > - gBS->Stall (10); > - GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); > + GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); GenetMmioWrite > (Genet, > + GENET_UMAC_CMD, > + GENET_UMAC_CMD_LCL_LOOP_EN | GENET_UMAC_CMD_SW_RESET); > gBS->Stall > + (10); GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); > > - GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, > GENET_UMAC_MIB_RESET_RUNT | GENET_UMAC_MIB_RESET_RX | > GENET_UMAC_MIB_RESET_TX); > - GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, 0); > + GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, > + GENET_UMAC_MIB_RESET_RUNT | GENET_UMAC_MIB_RESET_RX | > + GENET_UMAC_MIB_RESET_TX); GenetMmioWrite (Genet, > GENET_UMAC_MIB_CTRL, > + 0); > > - GenetMmioWrite (Genet, GENET_UMAC_MAX_FRAME_LEN, 1536); > + GenetMmioWrite (Genet, GENET_UMAC_MAX_FRAME_LEN, 1536); > > - Value = GenetMmioRead (Genet, GENET_RBUF_CTRL); > - Value |= GENET_RBUF_ALIGN_2B; > - GenetMmioWrite (Genet, GENET_RBUF_CTRL, Value); > + Value = GenetMmioRead (Genet, GENET_RBUF_CTRL); Value |= > + GENET_RBUF_ALIGN_2B; GenetMmioWrite (Genet, GENET_RBUF_CTRL, > Value); > > - GenetMmioWrite (Genet, GENET_RBUF_TBUF_SIZE_CTRL, 1); > + GenetMmioWrite (Genet, GENET_RBUF_TBUF_SIZE_CTRL, 1); > } > > /** > @@ -337,20 +341,20 @@ GenetReset ( > VOID > EFIAPI > GenetSetMacAddress ( > - IN GENET_PRIVATE_DATA *Genet, > - IN EFI_MAC_ADDRESS *MacAddr > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN EFI_MAC_ADDRESS *MacAddr > + ) > { > - UINT32 Value; > + UINT32 Value; > > - Value = MacAddr->Addr[3] | > - MacAddr->Addr[2] << 8 | > - MacAddr->Addr[1] << 16 | > - MacAddr->Addr[0] << 24; > - GenetMmioWrite (Genet, GENET_UMAC_MAC0, Value); > - Value = MacAddr->Addr[5] | > - MacAddr->Addr[4] << 8; > - GenetMmioWrite (Genet, GENET_UMAC_MAC1, Value); > + Value = MacAddr->Addr[3] | > + MacAddr->Addr[2] << 8 | > + MacAddr->Addr[1] << 16 | > + MacAddr->Addr[0] << 24; > + GenetMmioWrite (Genet, GENET_UMAC_MAC0, Value); Value = > + MacAddr->Addr[5] | > + MacAddr->Addr[4] << 8; > + GenetMmioWrite (Genet, GENET_UMAC_MAC1, Value); > } > > /** > @@ -362,24 +366,24 @@ GenetSetMacAddress ( **/ VOID > GenetSetPhyMode ( > - IN GENET_PRIVATE_DATA *Genet, > - IN GENET_PHY_MODE PhyMode > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN GENET_PHY_MODE PhyMode > + ) > { > - UINT32 Value; > + UINT32 Value; > > - switch (PhyMode) { > - case GENET_PHY_MODE_RGMII: > - case GENET_PHY_MODE_RGMII_RXID: > - case GENET_PHY_MODE_RGMII_TXID: > - case GENET_PHY_MODE_RGMII_ID: > - Value = GENET_SYS_PORT_MODE_EXT_GPHY; > - break; > - default: > - Value = 0; > - break; > - } > - GenetMmioWrite (Genet, GENET_SYS_PORT_CTRL, Value); > + switch (PhyMode) { > + case GENET_PHY_MODE_RGMII: > + case GENET_PHY_MODE_RGMII_RXID: > + case GENET_PHY_MODE_RGMII_TXID: > + case GENET_PHY_MODE_RGMII_ID: > + Value = GENET_SYS_PORT_MODE_EXT_GPHY; > + break; > + default: > + Value = 0; > + break; > + } > + GenetMmioWrite (Genet, GENET_SYS_PORT_CTRL, Value); > } > > /** > @@ -390,31 +394,32 @@ GenetSetPhyMode ( > **/ > VOID > GenetEnableTxRx ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINT32 Value; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT32 Value; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - // Start TX DMA on default queue > - Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); > - Value |= GENET_TX_DMA_CTRL_EN; > - Value |= GENET_TX_DMA_CTRL_RBUF_EN(Qid); > - GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); > + // Start TX DMA on default queue > + Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); Value |= > + GENET_TX_DMA_CTRL_EN; Value |= GENET_TX_DMA_CTRL_RBUF_EN > (Qid); > + GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); > > - // Start RX DMA on default queue > - Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); > - Value |= GENET_RX_DMA_CTRL_EN; > - Value |= GENET_RX_DMA_CTRL_RBUF_EN(Qid); > - GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); > + // Start RX DMA on default queue > + Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); Value |= > + GENET_RX_DMA_CTRL_EN; Value |= GENET_RX_DMA_CTRL_RBUF_EN > (Qid); > + GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); > > - // Enable transmitter and receiver > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - Value |= GENET_UMAC_CMD_TXEN | GENET_UMAC_CMD_RXEN; > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + // Enable transmitter and receiver > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); Value |= > + GENET_UMAC_CMD_TXEN | GENET_UMAC_CMD_RXEN; > GenetMmioWrite (Genet, > + GENET_UMAC_CMD, Value); > > - // Enable interrupts > - GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR_MASK, > GENET_IRQ_TXDMA_DONE | GENET_IRQ_RXDMA_DONE); > + // Enable interrupts > + GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR_MASK, > + GENET_IRQ_TXDMA_DONE | GENET_IRQ_RXDMA_DONE); > } > > /** > @@ -425,42 +430,42 @@ GenetEnableTxRx ( > **/ > VOID > GenetDisableTxRx ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINT32 Value; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT32 Value; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - // Disable interrupts > - GenetMmioWrite (Genet, GENET_INTRL2_CPU_SET_MASK, 0xFFFFFFFF); > - GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR, 0xFFFFFFFF); > + // Disable interrupts > + GenetMmioWrite (Genet, GENET_INTRL2_CPU_SET_MASK, 0xFFFFFFFF); > + GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR, 0xFFFFFFFF); > > - // Disable receiver > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - Value &= ~GENET_UMAC_CMD_RXEN; > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + // Disable receiver > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); Value &= > + ~GENET_UMAC_CMD_RXEN; GenetMmioWrite (Genet, > GENET_UMAC_CMD, Value); > > - // Stop RX DMA > - Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); > - Value &= ~GENET_RX_DMA_CTRL_EN; > - Value &= ~GENET_RX_DMA_CTRL_RBUF_EN(Qid); > - GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); > + // Stop RX DMA > + Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); Value &= > + ~GENET_RX_DMA_CTRL_EN; Value &= ~GENET_RX_DMA_CTRL_RBUF_EN > (Qid); > + GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); > > - // Stop TX DMA > - Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); > - Value &= ~GENET_TX_DMA_CTRL_EN; > - Value &= ~GENET_TX_DMA_CTRL_RBUF_EN(Qid); > - GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); > + // Stop TX DMA > + Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); Value &= > + ~GENET_TX_DMA_CTRL_EN; Value &= ~GENET_TX_DMA_CTRL_RBUF_EN > (Qid); > + GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); > > - // Flush data in the TX FIFO > - GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 1); > - gBS->Stall (10); > - GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 0); > + // Flush data in the TX FIFO > + GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 1); gBS->Stall (10); > + GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 0); > > - // Disable transmitter > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - Value &= ~GENET_UMAC_CMD_TXEN; > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + // Disable transmitter > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); Value &= > + ~GENET_UMAC_CMD_TXEN; GenetMmioWrite (Genet, > GENET_UMAC_CMD, Value); > } > > /** > @@ -472,19 +477,19 @@ GenetDisableTxRx ( **/ VOID GenetSetPromisc ( > - IN GENET_PRIVATE_DATA *Genet, > - IN BOOLEAN Enable > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN BOOLEAN Enable > + ) > { > - UINT32 Value; > + UINT32 Value; > > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - if (Enable) { > - Value |= GENET_UMAC_CMD_PROMISC; > - } else { > - Value &= ~GENET_UMAC_CMD_PROMISC; > - } > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); if (Enable) { > + Value |= GENET_UMAC_CMD_PROMISC; > + } else { > + Value &= ~GENET_UMAC_CMD_PROMISC; > + } > + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > } > > /** > @@ -495,63 +500,63 @@ GenetSetPromisc ( > **/ > VOID > GenetDmaInitRings ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - Genet->TxQueued = 0; > - Genet->TxNext = 0; > - Genet->TxConsIndex = 0; > - Genet->TxProdIndex = 0; > + Genet->TxQueued = 0; > + Genet->TxNext = 0; > + Genet->TxConsIndex = 0; > + Genet->TxProdIndex = 0; > > - Genet->RxConsIndex = 0; > - Genet->RxProdIndex = 0; > + Genet->RxConsIndex = 0; > + Genet->RxProdIndex = 0; > > - // Configure TX queue > - GenetMmioWrite (Genet, GENET_TX_SCB_BURST_SIZE, 0x08); > - GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_CONS_INDEX(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_RING_BUF_SIZE(Qid), > - __SHIFTIN(GENET_DMA_DESC_COUNT, > GENET_TX_DMA_RING_BUF_SIZE_DESC_COUNT) | > - __SHIFTIN(GENET_MAX_PACKET_SIZE, > GENET_TX_DMA_RING_BUF_SIZE_BUF_LENGTH)); > - GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_LO(Qid), > - GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); > - GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_MBUF_DONE_THRES(Qid), 1); > - GenetMmioWrite (Genet, GENET_TX_DMA_FLOW_PERIOD(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_HI(Qid), 0); > + // Configure TX queue > + GenetMmioWrite (Genet, GENET_TX_SCB_BURST_SIZE, 0x08); > + GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_CONS_INDEX (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_RING_BUF_SIZE (Qid), > + __SHIFTIN(GENET_DMA_DESC_COUNT, > GENET_TX_DMA_RING_BUF_SIZE_DESC_COUNT) | > + __SHIFTIN(GENET_MAX_PACKET_SIZE, > GENET_TX_DMA_RING_BUF_SIZE_BUF_LENGTH)); > + GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_LO (Qid), > + GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); > + GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_MBUF_DONE_THRES (Qid), 1); > + GenetMmioWrite (Genet, GENET_TX_DMA_FLOW_PERIOD (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_HI (Qid), 0); > > - // Enable TX queue > - GenetMmioWrite (Genet, GENET_TX_DMA_RING_CFG, (1U << Qid)); > + // Enable TX queue > + GenetMmioWrite (Genet, GENET_TX_DMA_RING_CFG, (1U << Qid)); > > - // Configure RX queue > - GenetMmioWrite (Genet, GENET_RX_SCB_BURST_SIZE, 0x08); > - GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_PROD_INDEX(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_RING_BUF_SIZE(Qid), > - __SHIFTIN(GENET_DMA_DESC_COUNT, > GENET_RX_DMA_RING_BUF_SIZE_DESC_COUNT) | > - __SHIFTIN(GENET_MAX_PACKET_SIZE, > GENET_RX_DMA_RING_BUF_SIZE_BUF_LENGTH)); > - GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_LO(Qid), > - GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); > - GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_XON_XOFF_THRES(Qid), > - __SHIFTIN(5, GENET_RX_DMA_XON_XOFF_THRES_LO) | > - __SHIFTIN(GENET_DMA_DESC_COUNT >> 4, > GENET_RX_DMA_XON_XOFF_THRES_HI)); > - GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_HI(Qid), 0); > + // Configure RX queue > + GenetMmioWrite (Genet, GENET_RX_SCB_BURST_SIZE, 0x08); > + GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_PROD_INDEX (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_RING_BUF_SIZE (Qid), > + __SHIFTIN(GENET_DMA_DESC_COUNT, > GENET_RX_DMA_RING_BUF_SIZE_DESC_COUNT) | > + __SHIFTIN(GENET_MAX_PACKET_SIZE, > GENET_RX_DMA_RING_BUF_SIZE_BUF_LENGTH)); > + GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_LO (Qid), > + GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); > + GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_XON_XOFF_THRES (Qid), > + __SHIFTIN(5, GENET_RX_DMA_XON_XOFF_THRES_LO) | > + __SHIFTIN(GENET_DMA_DESC_COUNT >> 4, > GENET_RX_DMA_XON_XOFF_THRES_HI)); > + GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_HI (Qid), 0); > > - // Enable RX queue > - GenetMmioWrite (Genet, GENET_RX_DMA_RING_CFG, (1U << Qid)); > + // Enable RX queue > + GenetMmioWrite (Genet, GENET_RX_DMA_RING_CFG, (1U << Qid)); > } > > /** > @@ -564,22 +569,22 @@ GenetDmaInitRings ( > **/ > EFI_STATUS > GenetDmaAlloc ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - EFI_STATUS Status; > - UINTN n; > + EFI_STATUS Status; > + UINTN Idx; > > - for (n = 0; n < GENET_DMA_DESC_COUNT; n++) { > - Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES > (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[n]); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "GenetDmaAlloc: Failed to allocate RX > buffer: %r\n", Status)); > - GenetDmaFree (Genet); > - return Status; > - } > + for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { > + Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES > (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[Idx]); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate RX buffer: %r\n", > __FUNCTION__, Status)); > + GenetDmaFree (Genet); > + return Status; > } > + } > > - return EFI_SUCCESS; > + return EFI_SUCCESS; > } > > /** > @@ -594,33 +599,34 @@ GenetDmaAlloc ( > **/ > EFI_STATUS > GenetDmaMapRxDescriptor ( > - IN GENET_PRIVATE_DATA * Genet, > - IN UINT8 DescIndex > - ) > + IN GENET_PRIVATE_DATA * Genet, > + IN UINT8 DescIndex > + ) > { > - EFI_STATUS Status; > - UINTN DmaNumberOfBytes; > + EFI_STATUS Status; > + UINTN DmaNumberOfBytes; > > - ASSERT (Genet->RxBufferMap[DescIndex].Mapping == NULL); > - ASSERT (Genet->RxBuffer[DescIndex] != NULL); > + ASSERT (Genet->RxBufferMap[DescIndex].Mapping == NULL); > + ASSERT (Genet->RxBuffer[DescIndex] != NULL); > > - DmaNumberOfBytes = GENET_MAX_PACKET_SIZE; > - Status = DmaMap (MapOperationBusMasterWrite, > - (VOID *)Genet->RxBuffer[DescIndex], > - &DmaNumberOfBytes, > - &Genet->RxBufferMap[DescIndex].Pa, > - &Genet->RxBufferMap[DescIndex].Mapping); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "GenetDmaMapRxDescriptor: Failed to map > RX buffer: %r\n", Status)); > - return Status; > - } > + DmaNumberOfBytes = GENET_MAX_PACKET_SIZE; > + Status = DmaMap (MapOperationBusMasterWrite, > + (VOID *)Genet->RxBuffer[DescIndex], > + &DmaNumberOfBytes, > + &Genet->RxBufferMap[DescIndex].PhysAddress, > + &Genet->RxBufferMap[DescIndex].Mapping); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: Failed to map RX buffer: %r\n", > + __FUNCTION__, Status)); > + return Status; > + } > > - //DEBUG ((DEBUG_INFO, "GenetDmaMapRxDescriptor: Desc 0x%X > mapped to 0x%X\n", DescIndex, Genet->RxBufferMap[DescIndex].Pa)); > + GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_LO (DescIndex), > + Genet->RxBufferMap[DescIndex].PhysAddress & 0xFFFFFFFF); > + GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex), > + (Genet->RxBufferMap[DescIndex].PhysAddress >> 32) & 0xFFFFFFFF); > > - GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_LO (DescIndex), > Genet->RxBufferMap[DescIndex].Pa & 0xFFFFFFFF); > - GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex), > (Genet->RxBufferMap[DescIndex].Pa >> 32) & 0xFFFFFFFF); > - > - return EFI_SUCCESS; > + return EFI_SUCCESS; > } > > /** > @@ -632,14 +638,14 @@ GenetDmaMapRxDescriptor ( > **/ > VOID > GenetDmaUnmapRxDescriptor ( > - IN GENET_PRIVATE_DATA * Genet, > - IN UINT8 DescIndex > - ) > + IN GENET_PRIVATE_DATA * Genet, > + IN UINT8 DescIndex > + ) > { > - if (Genet->RxBufferMap[DescIndex].Mapping != NULL) { > - DmaUnmap (Genet->RxBufferMap[DescIndex].Mapping); > - Genet->RxBufferMap[DescIndex].Mapping = NULL; > - } > + if (Genet->RxBufferMap[DescIndex].Mapping != NULL) { > + DmaUnmap (Genet->RxBufferMap[DescIndex].Mapping); > + Genet->RxBufferMap[DescIndex].Mapping = NULL; > + } > } > > /** > @@ -651,19 +657,20 @@ GenetDmaUnmapRxDescriptor ( > **/ > VOID > GenetDmaFree ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINTN n; > + UINTN Idx; > > - for (n = 0; n < GENET_DMA_DESC_COUNT; n++) { > - GenetDmaUnmapRxDescriptor (Genet, n); > + for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { > + GenetDmaUnmapRxDescriptor (Genet, Idx); > > - if (Genet->RxBuffer[n] != NULL) { > - DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), > Genet->RxBuffer[n]); > - Genet->RxBuffer[n] = NULL; > - } > + if (Genet->RxBuffer[Idx] != NULL) { > + DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), > + Genet->RxBuffer[Idx]); > + Genet->RxBuffer[Idx] = NULL; > } > + } > } > > /** > @@ -677,26 +684,29 @@ GenetDmaFree ( > **/ > VOID > GenetDmaTriggerTx ( > - IN GENET_PRIVATE_DATA * Genet, > - IN UINT8 DescIndex, > - IN EFI_PHYSICAL_ADDRESS PhysAddr, > - IN UINTN NumberOfBytes > - ) > + IN GENET_PRIVATE_DATA * Genet, > + IN UINT8 DescIndex, > + IN EFI_PHYSICAL_ADDRESS PhysAddr, > + IN UINTN NumberOfBytes > + ) > { > - UINT32 DescStatus; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT32 DescStatus; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - DescStatus = GENET_TX_DESC_STATUS_SOP | > - GENET_TX_DESC_STATUS_EOP | > - GENET_TX_DESC_STATUS_CRC | > - GENET_TX_DESC_STATUS_QTAG | > - __SHIFTIN(NumberOfBytes, GENET_TX_DESC_STATUS_BUFLEN); > + DescStatus = GENET_TX_DESC_STATUS_SOP | > + GENET_TX_DESC_STATUS_EOP | > + GENET_TX_DESC_STATUS_CRC | > + GENET_TX_DESC_STATUS_QTAG | > + __SHIFTIN(NumberOfBytes, GENET_TX_DESC_STATUS_BUFLEN); > > - GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_LO(DescIndex), > PhysAddr & 0xFFFFFFFF); > - GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_HI(DescIndex), > (PhysAddr >> 32) & 0xFFFFFFFF); > - GenetMmioWrite (Genet, GENET_TX_DESC_STATUS(DescIndex), > DescStatus); > + GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_LO (DescIndex), > + PhysAddr & 0xFFFFFFFF); > + GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_HI (DescIndex), > + (PhysAddr >> 32) & 0xFFFFFFFF); > + GenetMmioWrite (Genet, GENET_TX_DESC_STATUS (DescIndex), > DescStatus); > > - GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX (Qid), > (DescIndex + 1) & 0xFFFF); > + GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX (Qid), > + (DescIndex + 1) & 0xFFFF); > } > > /** > @@ -708,24 +718,24 @@ GenetDmaTriggerTx ( > **/ > VOID > GenetTxIntr ( > - IN GENET_PRIVATE_DATA *Genet, > - OUT VOID **TxBuf > - ) > + IN GENET_PRIVATE_DATA *Genet, > + OUT VOID **TxBuf > + ) > { > - UINT32 ConsIndex, Total; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT32 ConsIndex, Total; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - ConsIndex = GenetMmioRead (Genet, GENET_TX_DMA_CONS_INDEX > (Qid)) & 0xFFFF; > + ConsIndex = GenetMmioRead (Genet, GENET_TX_DMA_CONS_INDEX > (Qid)) & 0xFFFF; > > - Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; > - if (Genet->TxQueued > 0 && Total > 0) { > - *TxBuf = Genet->TxBuffer[Genet->TxNext]; > - Genet->TxQueued--; > - Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT; > - Genet->TxConsIndex++; > - } else { > - *TxBuf = NULL; > - } > + Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; > + if (Genet->TxQueued > 0 && Total > 0) { > + *TxBuf = Genet->TxBuffer[Genet->TxNext]; > + Genet->TxQueued--; > + Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT; > + Genet->TxConsIndex++; > + } else { > + *TxBuf = NULL; > + } > } > > /** > @@ -742,32 +752,30 @@ GenetTxIntr ( > **/ > EFI_STATUS > GenetRxIntr ( > - IN GENET_PRIVATE_DATA *Genet, > - OUT UINT8 *DescIndex, > - OUT UINTN *FrameLength > - ) > + IN GENET_PRIVATE_DATA *Genet, > + OUT UINT8 *DescIndex, > + OUT UINTN *FrameLength > + ) > { > - EFI_STATUS Status; > - UINT32 ProdIndex, Total; > - UINT32 DescStatus; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + EFI_STATUS Status; > + UINT32 ProdIndex, Total; > + UINT32 DescStatus; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - ProdIndex = GenetMmioRead (Genet, GENET_RX_DMA_PROD_INDEX > (Qid)) & 0xFFFF; > + ProdIndex = GenetMmioRead (Genet, GENET_RX_DMA_PROD_INDEX > (Qid)) & 0xFFFF; > > - Total = (ProdIndex - Genet->RxConsIndex) & 0xFFFF; > - if (Total > 0) { > - *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT; > - DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS > (*DescIndex)); > - *FrameLength = __SHIFTOUT (DescStatus, > GENET_RX_DESC_STATUS_BUFLEN); > + Total = (ProdIndex - Genet->RxConsIndex) & 0xFFFF; > + if (Total > 0) { > + *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT; > + DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS > (*DescIndex)); > + *FrameLength = __SHIFTOUT (DescStatus, > GENET_RX_DESC_STATUS_BUFLEN); > > - //DEBUG ((DEBUG_INFO, "GenetRxIntr: DescIndex=0x%X > FrameLength=0x%X\n", *DescIndex, *FrameLength)); > + Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0xFFFF; > + GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (Qid), Genet- > >RxConsIndex); > + Status = EFI_SUCCESS; > + } else { > + Status = EFI_NOT_READY; > + } > > - Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0xFFFF; > - GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (Qid), Genet- > >RxConsIndex); > - Status = EFI_SUCCESS; > - } else { > - Status = EFI_NOT_READY; > - } > - > - return Status; > + return Status; > } > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > index bf28448445d1..951495127ce9 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > @@ -31,7 +31,7 @@ GenetSimpleNetworkStart ( > IN EFI_SIMPLE_NETWORK_PROTOCOL *This > ) > { > - GENET_PRIVATE_DATA *Genet; > + GENET_PRIVATE_DATA *Genet; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -67,7 +67,7 @@ GenetSimpleNetworkStop ( > IN EFI_SIMPLE_NETWORK_PROTOCOL *This > ) > { > - GENET_PRIVATE_DATA *Genet; > + GENET_PRIVATE_DATA *Genet; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -194,8 +194,8 @@ GenetSimpleNetworkReset ( > IN BOOLEAN ExtendedVerification > ) > { > - GENET_PRIVATE_DATA *Genet; > - EFI_STATUS Status; > + GENET_PRIVATE_DATA *Genet; > + EFI_STATUS Status; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -299,7 +299,7 @@ GenetSimpleNetworkReceiveFilters ( > IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL > ) > { > - GENET_PRIVATE_DATA *Genet; > + GENET_PRIVATE_DATA *Genet; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -347,7 +347,7 @@ GenetSimpleNetworkStationAddress ( > IN EFI_MAC_ADDRESS *New OPTIONAL > ) > { > - GENET_PRIVATE_DATA *Genet; > + GENET_PRIVATE_DATA *Genet; > > if (This == NULL || This->Mode == NULL) { > return EFI_INVALID_PARAMETER; > @@ -480,8 +480,8 @@ GenetSimpleNetworkGetStatus ( > OUT VOID **TxBuf OPTIONAL > ) > { > - GENET_PRIVATE_DATA *Genet; > - EFI_STATUS Status; > + GENET_PRIVATE_DATA *Genet; > + EFI_STATUS Status; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -555,17 +555,17 @@ GenetSimpleNetworkTransmit ( > IN UINT16 *Protocol OPTIONAL > ) > { > - GENET_PRIVATE_DATA *Genet; > - EFI_STATUS Status; > - UINT8 *Frame = Buffer; > - UINT8 Desc; > - PHYSICAL_ADDRESS DmaDeviceAddress; > - UINTN DmaNumberOfBytes; > - VOID *DmaMapping; > + GENET_PRIVATE_DATA *Genet; > + EFI_STATUS Status; > + UINT8 *Frame = Buffer; > + UINT8 Desc; > + PHYSICAL_ADDRESS DmaDeviceAddress; > + UINTN DmaNumberOfBytes; > + VOID *DmaMapping; > > if (This == NULL || Buffer == NULL) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: Invalid parameter (missing handle or > buffer)\n")); > + DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or > buffer)\n", > + __FUNCTION__)); > return EFI_INVALID_PARAMETER; > } > > @@ -587,32 +587,33 @@ GenetSimpleNetworkTransmit ( > if (HeaderSize != 0) { > if (HeaderSize != Genet->SnpMode.MediaHeaderSize) { > DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: Invalid parameter (header size > mismatch; HeaderSize 0x%X, SnpMode.MediaHeaderSize 0x%X))\n", > HeaderSize, Genet->SnpMode.MediaHeaderSize)); > + "%a: Invalid parameter (header size mismatch; HeaderSize 0x%X, > SnpMode.MediaHeaderSize 0x%X))\n", > + __FUNCTION__, HeaderSize, Genet->SnpMode.MediaHeaderSize)); > return EFI_INVALID_PARAMETER; > } > if (DestAddr == NULL || Protocol == NULL) { > DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: Invalid parameter (dest addr or > protocol missing)\n")); > + "%a: Invalid parameter (dest addr or protocol missing)\n", > + __FUNCTION__)); > return EFI_INVALID_PARAMETER; > } > } > > if (BufferSize < Genet->SnpMode.MediaHeaderSize) { > - DEBUG ((DEBUG_ERROR, "GenetSimpleNetworkTransmit: Buffer too > small\n")); > + DEBUG ((DEBUG_ERROR, "%a: Buffer too small\n", __FUNCTION__)); > return EFI_BUFFER_TOO_SMALL; > } > > Status = EfiAcquireLockOrFail (&Genet->Lock); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: Couldn't get lock: %r\n", Status)); > + DEBUG ((DEBUG_ERROR, "%a: Couldn't get lock: %r\n", __FUNCTION__, > Status)); > return EFI_ACCESS_DENIED; > } > > if (Genet->TxQueued == GENET_DMA_DESC_COUNT - 1) { > EfiReleaseLock (&Genet->Lock); > > - DEBUG ((DEBUG_ERROR, "GenetSimpleNetworkTransmit: Queue full\n")); > + DEBUG ((DEBUG_ERROR, "%a: Queue full\n", __FUNCTION__)); > return EFI_NOT_READY; > } > > @@ -634,8 +635,7 @@ GenetSimpleNetworkTransmit ( > &DmaDeviceAddress, > &DmaMapping); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: DmaMap failed: %r\n", Status)); > + DEBUG ((DEBUG_ERROR, "%a: DmaMap failed: %r\n", __FUNCTION__, > Status)); > EfiReleaseLock (&Genet->Lock); > return Status; > } > @@ -703,8 +703,8 @@ GenetSimpleNetworkReceive ( > UINTN FrameLength; > > if (This == NULL || Buffer == NULL) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Invalid parameter (missing handle or > buffer)\n")); > + DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or > buffer)\n", > + __FUNCTION__)); > return EFI_INVALID_PARAMETER; > } > > @@ -718,8 +718,7 @@ GenetSimpleNetworkReceive ( > > Status = EfiAcquireLockOrFail (&Genet->Lock); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Couldn't get lock: %r\n", Status)); > + DEBUG ((DEBUG_ERROR, "%a: Couldn't get lock: %r\n", __FUNCTION__, > Status)); > return EFI_ACCESS_DENIED; > } > > @@ -742,12 +741,12 @@ GenetSimpleNetworkReceive ( > > if (*BufferSize < FrameLength) { > DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Buffer size (0x%X) is too small for frame > (0x%X)\n", > - *BufferSize, FrameLength)); > + "%a: Buffer size (0x%X) is too small for frame (0x%X)\n", > + __FUNCTION__, *BufferSize, FrameLength)); > Status = GenetDmaMapRxDescriptor (Genet, DescIndex); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Failed to remap RX descriptor!\n")); > + DEBUG ((DEBUG_ERROR, "%a: Failed to remap RX descriptor!\n", > + __FUNCTION__)); > } > EfiReleaseLock (&Genet->Lock); > return EFI_BUFFER_TOO_SMALL; > @@ -771,16 +770,14 @@ GenetSimpleNetworkReceive ( > > Status = EFI_SUCCESS; > } else { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Short packet (FrameLength 0x%X)", > - FrameLength)); > + DEBUG ((DEBUG_ERROR, "%a: Short packet (FrameLength 0x%X)", > + __FUNCTION__, FrameLength)); > Status = EFI_NOT_READY; > } > > Status = GenetDmaMapRxDescriptor (Genet, DescIndex); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Failed to remap RX descriptor!\n")); > + DEBUG ((DEBUG_ERROR, "%a: Failed to remap RX descriptor!\n", > __FUNCTION__)); > } > > EfiReleaseLock (&Genet->Lock); > @@ -791,12 +788,12 @@ GenetSimpleNetworkReceive ( > This function converts a multicast IP address to a multicast HW MAC > address > for all packet transactions. > > - @param [in] pSimpleNetwork Protocol instance pointer > - @param [in] bIPv6 Set to TRUE if the multicast IP address is IPv6 > [RFC2460]. > + @param [in] SimpleNetwork Protocol instance pointer > + @param [in] IPv6 Set to TRUE if the multicast IP address is IPv6 > [RFC2460]. > Set to FALSE if the multicast IP address is IPv4 [RFC 791]. > - @param [in] pIP The multicast IP address that is to be converted to > a > + @param [in] IP The multicast IP address that is to be converted to > a > multicast HW MAC address. > - @param [in] pMAC The multicast HW MAC address that is to be > generated from IP. > + @param [in] MAC The multicast HW MAC address that is to be > generated from IP. > > @retval EFI_SUCCESS This operation was successful. > @retval EFI_NOT_STARTED The network interface was not started. > @@ -810,10 +807,10 @@ STATIC > EFI_STATUS > EFIAPI > GenetSimpleNetworkMCastIPtoMAC ( > - IN EFI_SIMPLE_NETWORK_PROTOCOL *pSimpleNetwork, > - IN BOOLEAN bIPv6, > - IN EFI_IP_ADDRESS *pIP, > - OUT EFI_MAC_ADDRESS *pMAC > + IN EFI_SIMPLE_NETWORK_PROTOCOL *SimpleNetwork, > + IN BOOLEAN IPv6, > + IN EFI_IP_ADDRESS *IP, > + OUT EFI_MAC_ADDRESS *MAC > ) > { > return EFI_UNSUPPORTED; > @@ -822,7 +819,6 @@ GenetSimpleNetworkMCastIPtoMAC ( > /// > /// Simple Network Protocol instance > /// > -GLOBAL_REMOVE_IF_UNREFERENCED > CONST EFI_SIMPLE_NETWORK_PROTOCOL gGenetSimpleNetworkTemplate > = { > EFI_SIMPLE_NETWORK_PROTOCOL_REVISION, // Revision > GenetSimpleNetworkStart, // Start > -- > 2.17.1 IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup 2020-05-11 14:55 ` [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Ard Biesheuvel 2020-05-11 16:36 ` Samer El-Haj-Mahmoud @ 2020-05-11 21:14 ` Philippe Mathieu-Daudé 1 sibling, 0 replies; 25+ messages in thread From: Philippe Mathieu-Daudé @ 2020-05-11 21:14 UTC (permalink / raw) To: devel, ard.biesheuvel Cc: Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton On 5/11/20 4:55 PM, Ard Biesheuvel wrote: > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> > --- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 2 + > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 38 +- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 19 +- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c | 16 +- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 744 ++++++++++---------- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 90 ++- > 6 files changed, 456 insertions(+), 453 deletions(-) > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > index e74fa02ad209..1f1aeca7dd6b 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > @@ -21,7 +21,9 @@ [Sources] > ComponentName.c > DriverBinding.c > GenericPhy.c > + GenericPhy.h > GenetUtil.c > + GenetUtil.h > SimpleNetwork.c > > [Packages] > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > index 2e7b78322bcd..b21a284b6221 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > @@ -185,7 +185,7 @@ > #define GENET_TX_SCB_BURST_SIZE (GENET_TX_BASE + 0x1040 + 0x0c) > > typedef struct { > - EFI_PHYSICAL_ADDRESS Pa; > + EFI_PHYSICAL_ADDRESS PhysAddress; > VOID * Mapping; > } GENET_MAP_INFO; > > @@ -198,32 +198,32 @@ typedef enum { > } GENET_PHY_MODE; > > typedef struct { > - UINT32 Signature; > - EFI_HANDLE ControllerHandle; > + UINT32 Signature; > + EFI_HANDLE ControllerHandle; > > - EFI_LOCK Lock; > + EFI_LOCK Lock; > > - EFI_SIMPLE_NETWORK_PROTOCOL Snp; > - EFI_SIMPLE_NETWORK_MODE SnpMode; > + EFI_SIMPLE_NETWORK_PROTOCOL Snp; > + EFI_SIMPLE_NETWORK_MODE SnpMode; > > - BCM_GENET_PLATFORM_DEVICE_PROTOCOL *Dev; > + BCM_GENET_PLATFORM_DEVICE_PROTOCOL *Dev; > > - GENERIC_PHY_PRIVATE_DATA Phy; > + GENERIC_PHY_PRIVATE_DATA Phy; > > - UINT8 * TxBuffer[GENET_DMA_DESC_COUNT]; > - UINT8 TxQueued; > - UINT16 TxNext; > - UINT16 TxConsIndex; > - UINT16 TxProdIndex; > + UINT8 *TxBuffer[GENET_DMA_DESC_COUNT]; > + UINT8 TxQueued; > + UINT16 TxNext; > + UINT16 TxConsIndex; > + UINT16 TxProdIndex; > > - UINT8 * RxBuffer[GENET_DMA_DESC_COUNT]; > - GENET_MAP_INFO RxBufferMap[GENET_DMA_DESC_COUNT]; > - UINT16 RxConsIndex; > - UINT16 RxProdIndex; > + UINT8 *RxBuffer[GENET_DMA_DESC_COUNT]; > + GENET_MAP_INFO RxBufferMap[GENET_DMA_DESC_COUNT]; > + UINT16 RxConsIndex; > + UINT16 RxProdIndex; > > - GENET_PHY_MODE PhyMode; > + GENET_PHY_MODE PhyMode; > > - UINTN RegBase; > + UINTN RegBase; > } GENET_PRIVATE_DATA; > > extern EFI_COMPONENT_NAME_PROTOCOL gGenetComponentName; > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > index e3d015dd0820..c23847ba9b52 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > @@ -55,14 +55,12 @@ GenetDriverBindingSupported ( > // > Status = gBS->OpenProtocol (ControllerHandle, > &gBcmGenetPlatformDeviceProtocolGuid, > - (VOID **) &Dev, > + (VOID **)&Dev, > This->DriverBindingHandle, > ControllerHandle, > EFI_OPEN_PROTOCOL_BY_DRIVER); > if (EFI_ERROR (Status)) { > return Status; > - } else { > - Status = EFI_SUCCESS; > } > > // > @@ -73,7 +71,7 @@ GenetDriverBindingSupported ( > This->DriverBindingHandle, > ControllerHandle); > > - return Status; > + return EFI_SUCCESS; Considering this is a cosmetic change, Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com> > } > > > @@ -111,7 +109,7 @@ GenetDriverBindingStart ( > Genet = AllocateZeroPool (sizeof (GENET_PRIVATE_DATA)); > if (Genet == NULL) { > DEBUG ((DEBUG_ERROR, > - "GenetDriverBindingStart: Couldn't allocate private data\n")); > + "%a: Couldn't allocate private data\n", __FUNCTION__)); > return EFI_OUT_OF_RESOURCES; > } > > @@ -123,14 +121,14 @@ GenetDriverBindingStart ( > EFI_OPEN_PROTOCOL_BY_DRIVER); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, > - "GenetDriverBindingStart: Couldn't open protocol: %r\n", Status)); > + "%a: Couldn't open protocol: %r\n", __FUNCTION__, Status)); > goto FreeDevice; > } > > Status = GenetDmaAlloc (Genet); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, > - "GenetDriverBindingStart: Couldn't allocate DMA buffers: %r\n", Status)); > + "%a: Couldn't allocate DMA buffers: %r\n", __FUNCTION__, Status)); > goto FreeDevice; > } > > @@ -180,8 +178,7 @@ GenetDriverBindingStart ( > > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, > - "GenetDriverBindingStart: Couldn't install protocol interfaces: %r\n", > - Status)); > + "%a: Couldn't install protocol interfaces: %r\n", __FUNCTION__, Status)); > gBS->CloseProtocol (ControllerHandle, > &gBcmGenetPlatformDeviceProtocolGuid, > This->DriverBindingHandle, > @@ -190,10 +187,10 @@ GenetDriverBindingStart ( > } > > Genet->ControllerHandle = ControllerHandle; > - return Status; > + return EFI_SUCCESS; > > FreeDevice: > - DEBUG ((DEBUG_WARN, "GenetDriverBindingStart: Returning %r\n", Status)); > + DEBUG ((DEBUG_WARN, "%a: Returning %r\n", __FUNCTION__, Status)); > FreePool (Genet); > return Status; > } > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c > index a3c709891bc9..cd2788adc52c 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenericPhy.c > @@ -115,8 +115,8 @@ GenericPhyDetect ( > if (Id1 != 0xFFFF && Id2 != 0xFFFF) { > Phy->PhyAddr = PhyAddr; > DEBUG ((DEBUG_INFO, > - "GenericPhyDetect: PHY detected at address 0x%02X (PHYIDR1=0x%04X, PHYIDR2=0x%04X)\n", > - PhyAddr, Id1, Id2)); > + "%a: PHY detected at address 0x%02X (PHYIDR1=0x%04X, PHYIDR2=0x%04X)\n", > + __FUNCTION__, PhyAddr, Id1, Id2)); > return EFI_SUCCESS; > } > } > @@ -348,8 +348,8 @@ GenericPhyGetConfig ( > *Duplex = (An & GENERIC_PHY_ANAR_10BASET_FDX) ? PHY_DUPLEX_FULL : PHY_DUPLEX_HALF; > } > > - DEBUG ((DEBUG_INFO, "GenericPhyGetConfig: Link speed %d Mbps, %a-duplex\n", > - *Speed, *Duplex == PHY_DUPLEX_FULL ? "full" : "half")); > + DEBUG ((DEBUG_INFO, "%a: Link speed %d Mbps, %a-duplex\n", > + __FUNCTION__, *Speed, *Duplex == PHY_DUPLEX_FULL ? "full" : "half")); > > return EFI_SUCCESS; > } > @@ -367,8 +367,8 @@ GenericPhyGetConfig ( > EFI_STATUS > EFIAPI > GenericPhyUpdateConfig ( > - IN GENERIC_PHY_PRIVATE_DATA *Phy > - ) > + IN GENERIC_PHY_PRIVATE_DATA *Phy > + ) > { > EFI_STATUS Status; > GENERIC_PHY_SPEED Speed; > @@ -380,7 +380,7 @@ GenericPhyUpdateConfig ( > > if (Phy->LinkUp != LinkUp) { > if (LinkUp) { > - DEBUG ((DEBUG_VERBOSE, "GenericPhyUpdateConfig: Link is up\n")); > + DEBUG ((DEBUG_VERBOSE, "%a: Link is up\n", __FUNCTION__)); > > Status = GenericPhyGetConfig (Phy, &Speed, &Duplex); > if (EFI_ERROR (Status)) { > @@ -389,7 +389,7 @@ GenericPhyUpdateConfig ( > > GenericPhyConfigure (Phy, Speed, Duplex); > } else { > - DEBUG ((DEBUG_VERBOSE, "GenericPhyUpdateConfig: Link is down\n")); > + DEBUG ((DEBUG_VERBOSE, "%a: Link is down\n", __FUNCTION__)); > } > } > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > index d471b1cadadc..7ae9acec4c78 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > @@ -31,13 +31,13 @@ > STATIC > UINT32 > GenetMmioRead ( > - IN GENET_PRIVATE_DATA *Genet, > - IN UINT32 Offset > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN UINT32 Offset > + ) > { > - ASSERT((Offset & 3) == 0); > + ASSERT ((Offset & 3) == 0); > > - return MmioRead32 (Genet->RegBase + Offset); > + return MmioRead32 (Genet->RegBase + Offset); > } > > /** > @@ -53,15 +53,15 @@ GenetMmioRead ( > STATIC > VOID > GenetMmioWrite ( > - IN GENET_PRIVATE_DATA *Genet, > - IN UINT32 Offset, > - IN UINT32 Data > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN UINT32 Offset, > + IN UINT32 Data > + ) > { > - ASSERT((Offset & 3) == 0); > + ASSERT ((Offset & 3) == 0); > > - ArmDataSynchronizationBarrier (); > - MmioWrite32 (Genet->RegBase + Offset, Data); > + ArmDataSynchronizationBarrier (); > + MmioWrite32 (Genet->RegBase + Offset, Data); > } > > /** > @@ -79,37 +79,38 @@ GenetMmioWrite ( > EFI_STATUS > EFIAPI > GenetPhyRead ( > - IN VOID *Priv, > - IN UINT8 PhyAddr, > - IN UINT8 Reg, > - OUT UINT16 *Data > - ) > + IN VOID *Priv, > + IN UINT8 PhyAddr, > + IN UINT8 Reg, > + OUT UINT16 *Data > + ) > { > - GENET_PRIVATE_DATA *Genet = Priv; > - UINTN Retry; > - UINT32 Value; > + GENET_PRIVATE_DATA *Genet = Priv; > + UINTN Retry; > + UINT32 Value; > > - Value = GENET_MDIO_READ | > - GENET_MDIO_START_BUSY | > - __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | > - __SHIFTIN(Reg, GENET_MDIO_REG); > - GenetMmioWrite (Genet, GENET_MDIO_CMD, Value); > + Value = GENET_MDIO_READ | > + GENET_MDIO_START_BUSY | > + __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | > + __SHIFTIN(Reg, GENET_MDIO_REG); > + GenetMmioWrite (Genet, GENET_MDIO_CMD, Value); > > - for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { > - Value = GenetMmioRead (Genet, GENET_MDIO_CMD); > - if ((Value & GENET_MDIO_START_BUSY) == 0) { > - *Data = Value & 0xffff; > - break; > - } > - gBS->Stall (10); > + for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { > + Value = GenetMmioRead (Genet, GENET_MDIO_CMD); > + if ((Value & GENET_MDIO_START_BUSY) == 0) { > + *Data = Value & 0xffff; > + break; > } > + gBS->Stall (10); > + } > > - if (Retry == 0) { > - DEBUG ((DEBUG_ERROR, "GenetPhyRead: Timeout reading PhyAddr %d, Reg %d\n", PhyAddr, Reg)); > - return EFI_DEVICE_ERROR; > - } > + if (Retry == 0) { > + DEBUG ((DEBUG_ERROR, > + "%a: Timeout reading PhyAddr %d, Reg %d\n", __FUNCTION__, PhyAddr, Reg)); > + return EFI_DEVICE_ERROR; > + } > > - return EFI_SUCCESS; > + return EFI_SUCCESS; > } > > /** > @@ -127,36 +128,37 @@ GenetPhyRead ( > EFI_STATUS > EFIAPI > GenetPhyWrite ( > - IN VOID *Priv, > - IN UINT8 PhyAddr, > - IN UINT8 Reg, > - IN UINT16 Data > - ) > + IN VOID *Priv, > + IN UINT8 PhyAddr, > + IN UINT8 Reg, > + IN UINT16 Data > + ) > { > - GENET_PRIVATE_DATA *Genet = Priv; > - UINTN Retry; > - UINT32 Value; > + GENET_PRIVATE_DATA *Genet = Priv; > + UINTN Retry; > + UINT32 Value; > > - Value = GENET_MDIO_WRITE | > - GENET_MDIO_START_BUSY | > - __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | > - __SHIFTIN(Reg, GENET_MDIO_REG); > - GenetMmioWrite (Genet, GENET_MDIO_CMD, Value | Data); > + Value = GENET_MDIO_WRITE | > + GENET_MDIO_START_BUSY | > + __SHIFTIN(PhyAddr, GENET_MDIO_PMD) | > + __SHIFTIN(Reg, GENET_MDIO_REG); > + GenetMmioWrite (Genet, GENET_MDIO_CMD, Value | Data); > > - for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { > - Value = GenetMmioRead (Genet, GENET_MDIO_CMD); > - if ((Value & GENET_MDIO_START_BUSY) == 0) { > - break; > - } > - gBS->Stall (10); > + for (Retry = GENET_PHY_RETRY; Retry > 0; Retry--) { > + Value = GenetMmioRead (Genet, GENET_MDIO_CMD); > + if ((Value & GENET_MDIO_START_BUSY) == 0) { > + break; > } > + gBS->Stall (10); > + } > > - if (Retry == 0) { > - DEBUG ((DEBUG_ERROR, "GenetPhyRead: Timeout writing PhyAddr %d, Reg %d\n", PhyAddr, Reg)); > - return EFI_DEVICE_ERROR; > - } > + if (Retry == 0) { > + DEBUG ((DEBUG_ERROR, > + "%a: Timeout writing PhyAddr %d, Reg %d\n", __FUNCTION__, PhyAddr, Reg)); > + return EFI_DEVICE_ERROR; > + } > > - return EFI_SUCCESS; > + return EFI_SUCCESS; > } > > /** > @@ -170,44 +172,44 @@ GenetPhyWrite ( > VOID > EFIAPI > GenetPhyConfigure ( > - IN VOID *Priv, > - IN GENERIC_PHY_SPEED Speed, > - IN GENERIC_PHY_DUPLEX Duplex > - ) > + IN VOID *Priv, > + IN GENERIC_PHY_SPEED Speed, > + IN GENERIC_PHY_DUPLEX Duplex > + ) > { > - GENET_PRIVATE_DATA *Genet = Priv; > - UINT32 Value; > + GENET_PRIVATE_DATA *Genet = Priv; > + UINT32 Value; > > - Value = GenetMmioRead (Genet, GENET_EXT_RGMII_OOB_CTRL); > - Value &= ~GENET_EXT_RGMII_OOB_OOB_DISABLE; > - Value |= GENET_EXT_RGMII_OOB_RGMII_LINK; > - Value |= GENET_EXT_RGMII_OOB_RGMII_MODE_EN; > - if (Genet->PhyMode == GENET_PHY_MODE_RGMII) { > - Value |= GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; > - } else { > - Value &= ~GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; > - } > - GenetMmioWrite (Genet, GENET_EXT_RGMII_OOB_CTRL, Value); > + Value = GenetMmioRead (Genet, GENET_EXT_RGMII_OOB_CTRL); > + Value &= ~GENET_EXT_RGMII_OOB_OOB_DISABLE; > + Value |= GENET_EXT_RGMII_OOB_RGMII_LINK; > + Value |= GENET_EXT_RGMII_OOB_RGMII_MODE_EN; > + if (Genet->PhyMode == GENET_PHY_MODE_RGMII) { > + Value |= GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; > + } else { > + Value &= ~GENET_EXT_RGMII_OOB_ID_MODE_DISABLE; > + } > + GenetMmioWrite (Genet, GENET_EXT_RGMII_OOB_CTRL, Value); > > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - Value &= ~GENET_UMAC_CMD_SPEED; > - switch (Speed) { > - case PHY_SPEED_1000: > - Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_1000, GENET_UMAC_CMD_SPEED); > - break; > - case PHY_SPEED_100: > - Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_100, GENET_UMAC_CMD_SPEED); > - break; > - default: > - Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_10, GENET_UMAC_CMD_SPEED); > - break; > - } > - if (Duplex == PHY_DUPLEX_FULL) { > - Value &= ~GENET_UMAC_CMD_HD_EN; > - } else { > - Value |= GENET_UMAC_CMD_HD_EN; > - } > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > + Value &= ~GENET_UMAC_CMD_SPEED; > + switch (Speed) { > + case PHY_SPEED_1000: > + Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_1000, GENET_UMAC_CMD_SPEED); > + break; > + case PHY_SPEED_100: > + Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_100, GENET_UMAC_CMD_SPEED); > + break; > + default: > + Value |= __SHIFTIN(GENET_UMAC_CMD_SPEED_10, GENET_UMAC_CMD_SPEED); > + break; > + } > + if (Duplex == PHY_DUPLEX_FULL) { > + Value &= ~GENET_UMAC_CMD_HD_EN; > + } else { > + Value |= GENET_UMAC_CMD_HD_EN; > + } > + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > } > > /** > @@ -231,12 +233,12 @@ GenetPhyResetAction ( > BRGPHY_AUXCTL_SHADOW_MISC | BRGPHY_AUXCTL_SHADOW_MISC > << BRGPHY_AUXCTL_MISC_READ_SHIFT); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Status = GenetPhyRead (Priv, Genet->Phy.PhyAddr, BRGPHY_MII_AUXCTL, &Value); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Value &= BRGPHY_AUXCTL_MISC_DATA_MASK; > @@ -252,18 +254,18 @@ GenetPhyResetAction ( > BRGPHY_AUXCTL_MISC_WRITE_EN | BRGPHY_AUXCTL_SHADOW_MISC | > Value); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Status = GenetPhyWrite (Priv, Genet->Phy.PhyAddr, BRGPHY_MII_SHADOW_1C, > - BRGPHY_SHADOW_1C_CLK_CTRL); > + BRGPHY_SHADOW_1C_CLK_CTRL); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Status = GenetPhyRead (Priv, Genet->Phy.PhyAddr, BRGPHY_MII_SHADOW_1C, &Value); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > Value &= BRGPHY_SHADOW_1C_DATA_MASK; > @@ -279,7 +281,7 @@ GenetPhyResetAction ( > BRGPHY_SHADOW_1C_WRITE_EN | BRGPHY_SHADOW_1C_CLK_CTRL | > Value); > if (EFI_ERROR (Status)) { > - return Status; > + return Status; > } > > return EFI_SUCCESS; > @@ -293,38 +295,40 @@ GenetPhyResetAction ( > **/ > VOID > GenetReset ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINT32 Value; > + UINT32 Value; > > - Value = GenetMmioRead (Genet, GENET_SYS_RBUF_FLUSH_CTRL); > - Value |= GENET_SYS_RBUF_FLUSH_RESET; > - GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); > - gBS->Stall (10); > + Value = GenetMmioRead (Genet, GENET_SYS_RBUF_FLUSH_CTRL); > + Value |= GENET_SYS_RBUF_FLUSH_RESET; > + GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); > + gBS->Stall (10); > > - Value &= ~GENET_SYS_RBUF_FLUSH_RESET; > - GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); > - gBS->Stall (10); > + Value &= ~GENET_SYS_RBUF_FLUSH_RESET; > + GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, Value); > + gBS->Stall (10); > > - GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, 0); > - gBS->Stall (10); > + GenetMmioWrite (Genet, GENET_SYS_RBUF_FLUSH_CTRL, 0); > + gBS->Stall (10); > > - GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); > - GenetMmioWrite (Genet, GENET_UMAC_CMD, GENET_UMAC_CMD_LCL_LOOP_EN | GENET_UMAC_CMD_SW_RESET); > - gBS->Stall (10); > - GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); > + GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); > + GenetMmioWrite (Genet, GENET_UMAC_CMD, > + GENET_UMAC_CMD_LCL_LOOP_EN | GENET_UMAC_CMD_SW_RESET); > + gBS->Stall (10); > + GenetMmioWrite (Genet, GENET_UMAC_CMD, 0); > > - GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, GENET_UMAC_MIB_RESET_RUNT | GENET_UMAC_MIB_RESET_RX | GENET_UMAC_MIB_RESET_TX); > - GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, 0); > + GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, > + GENET_UMAC_MIB_RESET_RUNT | GENET_UMAC_MIB_RESET_RX | GENET_UMAC_MIB_RESET_TX); > + GenetMmioWrite (Genet, GENET_UMAC_MIB_CTRL, 0); > > - GenetMmioWrite (Genet, GENET_UMAC_MAX_FRAME_LEN, 1536); > + GenetMmioWrite (Genet, GENET_UMAC_MAX_FRAME_LEN, 1536); > > - Value = GenetMmioRead (Genet, GENET_RBUF_CTRL); > - Value |= GENET_RBUF_ALIGN_2B; > - GenetMmioWrite (Genet, GENET_RBUF_CTRL, Value); > + Value = GenetMmioRead (Genet, GENET_RBUF_CTRL); > + Value |= GENET_RBUF_ALIGN_2B; > + GenetMmioWrite (Genet, GENET_RBUF_CTRL, Value); > > - GenetMmioWrite (Genet, GENET_RBUF_TBUF_SIZE_CTRL, 1); > + GenetMmioWrite (Genet, GENET_RBUF_TBUF_SIZE_CTRL, 1); > } > > /** > @@ -337,20 +341,20 @@ GenetReset ( > VOID > EFIAPI > GenetSetMacAddress ( > - IN GENET_PRIVATE_DATA *Genet, > - IN EFI_MAC_ADDRESS *MacAddr > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN EFI_MAC_ADDRESS *MacAddr > + ) > { > - UINT32 Value; > + UINT32 Value; > > - Value = MacAddr->Addr[3] | > - MacAddr->Addr[2] << 8 | > - MacAddr->Addr[1] << 16 | > - MacAddr->Addr[0] << 24; > - GenetMmioWrite (Genet, GENET_UMAC_MAC0, Value); > - Value = MacAddr->Addr[5] | > - MacAddr->Addr[4] << 8; > - GenetMmioWrite (Genet, GENET_UMAC_MAC1, Value); > + Value = MacAddr->Addr[3] | > + MacAddr->Addr[2] << 8 | > + MacAddr->Addr[1] << 16 | > + MacAddr->Addr[0] << 24; > + GenetMmioWrite (Genet, GENET_UMAC_MAC0, Value); > + Value = MacAddr->Addr[5] | > + MacAddr->Addr[4] << 8; > + GenetMmioWrite (Genet, GENET_UMAC_MAC1, Value); > } > > /** > @@ -362,24 +366,24 @@ GenetSetMacAddress ( > **/ > VOID > GenetSetPhyMode ( > - IN GENET_PRIVATE_DATA *Genet, > - IN GENET_PHY_MODE PhyMode > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN GENET_PHY_MODE PhyMode > + ) > { > - UINT32 Value; > + UINT32 Value; > > - switch (PhyMode) { > - case GENET_PHY_MODE_RGMII: > - case GENET_PHY_MODE_RGMII_RXID: > - case GENET_PHY_MODE_RGMII_TXID: > - case GENET_PHY_MODE_RGMII_ID: > - Value = GENET_SYS_PORT_MODE_EXT_GPHY; > - break; > - default: > - Value = 0; > - break; > - } > - GenetMmioWrite (Genet, GENET_SYS_PORT_CTRL, Value); > + switch (PhyMode) { > + case GENET_PHY_MODE_RGMII: > + case GENET_PHY_MODE_RGMII_RXID: > + case GENET_PHY_MODE_RGMII_TXID: > + case GENET_PHY_MODE_RGMII_ID: > + Value = GENET_SYS_PORT_MODE_EXT_GPHY; > + break; > + default: > + Value = 0; > + break; > + } > + GenetMmioWrite (Genet, GENET_SYS_PORT_CTRL, Value); > } > > /** > @@ -390,31 +394,32 @@ GenetSetPhyMode ( > **/ > VOID > GenetEnableTxRx ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINT32 Value; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT32 Value; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - // Start TX DMA on default queue > - Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); > - Value |= GENET_TX_DMA_CTRL_EN; > - Value |= GENET_TX_DMA_CTRL_RBUF_EN(Qid); > - GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); > + // Start TX DMA on default queue > + Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); > + Value |= GENET_TX_DMA_CTRL_EN; > + Value |= GENET_TX_DMA_CTRL_RBUF_EN (Qid); > + GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); > > - // Start RX DMA on default queue > - Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); > - Value |= GENET_RX_DMA_CTRL_EN; > - Value |= GENET_RX_DMA_CTRL_RBUF_EN(Qid); > - GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); > + // Start RX DMA on default queue > + Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); > + Value |= GENET_RX_DMA_CTRL_EN; > + Value |= GENET_RX_DMA_CTRL_RBUF_EN (Qid); > + GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); > > - // Enable transmitter and receiver > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - Value |= GENET_UMAC_CMD_TXEN | GENET_UMAC_CMD_RXEN; > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + // Enable transmitter and receiver > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > + Value |= GENET_UMAC_CMD_TXEN | GENET_UMAC_CMD_RXEN; > + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > > - // Enable interrupts > - GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR_MASK, GENET_IRQ_TXDMA_DONE | GENET_IRQ_RXDMA_DONE); > + // Enable interrupts > + GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR_MASK, > + GENET_IRQ_TXDMA_DONE | GENET_IRQ_RXDMA_DONE); > } > > /** > @@ -425,42 +430,42 @@ GenetEnableTxRx ( > **/ > VOID > GenetDisableTxRx ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINT32 Value; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT32 Value; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - // Disable interrupts > - GenetMmioWrite (Genet, GENET_INTRL2_CPU_SET_MASK, 0xFFFFFFFF); > - GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR, 0xFFFFFFFF); > + // Disable interrupts > + GenetMmioWrite (Genet, GENET_INTRL2_CPU_SET_MASK, 0xFFFFFFFF); > + GenetMmioWrite (Genet, GENET_INTRL2_CPU_CLEAR, 0xFFFFFFFF); > > - // Disable receiver > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - Value &= ~GENET_UMAC_CMD_RXEN; > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + // Disable receiver > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > + Value &= ~GENET_UMAC_CMD_RXEN; > + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > > - // Stop RX DMA > - Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); > - Value &= ~GENET_RX_DMA_CTRL_EN; > - Value &= ~GENET_RX_DMA_CTRL_RBUF_EN(Qid); > - GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); > + // Stop RX DMA > + Value = GenetMmioRead (Genet, GENET_RX_DMA_CTRL); > + Value &= ~GENET_RX_DMA_CTRL_EN; > + Value &= ~GENET_RX_DMA_CTRL_RBUF_EN (Qid); > + GenetMmioWrite (Genet, GENET_RX_DMA_CTRL, Value); > > - // Stop TX DMA > - Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); > - Value &= ~GENET_TX_DMA_CTRL_EN; > - Value &= ~GENET_TX_DMA_CTRL_RBUF_EN(Qid); > - GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); > + // Stop TX DMA > + Value = GenetMmioRead (Genet, GENET_TX_DMA_CTRL); > + Value &= ~GENET_TX_DMA_CTRL_EN; > + Value &= ~GENET_TX_DMA_CTRL_RBUF_EN (Qid); > + GenetMmioWrite (Genet, GENET_TX_DMA_CTRL, Value); > > - // Flush data in the TX FIFO > - GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 1); > - gBS->Stall (10); > - GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 0); > + // Flush data in the TX FIFO > + GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 1); > + gBS->Stall (10); > + GenetMmioWrite (Genet, GENET_UMAC_TX_FLUSH, 0); > > - // Disable transmitter > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - Value &= ~GENET_UMAC_CMD_TXEN; > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + // Disable transmitter > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > + Value &= ~GENET_UMAC_CMD_TXEN; > + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > } > > /** > @@ -472,19 +477,19 @@ GenetDisableTxRx ( > **/ > VOID > GenetSetPromisc ( > - IN GENET_PRIVATE_DATA *Genet, > - IN BOOLEAN Enable > - ) > + IN GENET_PRIVATE_DATA *Genet, > + IN BOOLEAN Enable > + ) > { > - UINT32 Value; > + UINT32 Value; > > - Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > - if (Enable) { > - Value |= GENET_UMAC_CMD_PROMISC; > - } else { > - Value &= ~GENET_UMAC_CMD_PROMISC; > - } > - GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > + Value = GenetMmioRead (Genet, GENET_UMAC_CMD); > + if (Enable) { > + Value |= GENET_UMAC_CMD_PROMISC; > + } else { > + Value &= ~GENET_UMAC_CMD_PROMISC; > + } > + GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > } > > /** > @@ -495,63 +500,63 @@ GenetSetPromisc ( > **/ > VOID > GenetDmaInitRings ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - Genet->TxQueued = 0; > - Genet->TxNext = 0; > - Genet->TxConsIndex = 0; > - Genet->TxProdIndex = 0; > + Genet->TxQueued = 0; > + Genet->TxNext = 0; > + Genet->TxConsIndex = 0; > + Genet->TxProdIndex = 0; > > - Genet->RxConsIndex = 0; > - Genet->RxProdIndex = 0; > + Genet->RxConsIndex = 0; > + Genet->RxProdIndex = 0; > > - // Configure TX queue > - GenetMmioWrite (Genet, GENET_TX_SCB_BURST_SIZE, 0x08); > - GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_CONS_INDEX(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_RING_BUF_SIZE(Qid), > - __SHIFTIN(GENET_DMA_DESC_COUNT, GENET_TX_DMA_RING_BUF_SIZE_DESC_COUNT) | > - __SHIFTIN(GENET_MAX_PACKET_SIZE, GENET_TX_DMA_RING_BUF_SIZE_BUF_LENGTH)); > - GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_LO(Qid), > - GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); > - GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_MBUF_DONE_THRES(Qid), 1); > - GenetMmioWrite (Genet, GENET_TX_DMA_FLOW_PERIOD(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_HI(Qid), 0); > + // Configure TX queue > + GenetMmioWrite (Genet, GENET_TX_SCB_BURST_SIZE, 0x08); > + GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_READ_PTR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_CONS_INDEX (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_RING_BUF_SIZE (Qid), > + __SHIFTIN(GENET_DMA_DESC_COUNT, GENET_TX_DMA_RING_BUF_SIZE_DESC_COUNT) | > + __SHIFTIN(GENET_MAX_PACKET_SIZE, GENET_TX_DMA_RING_BUF_SIZE_BUF_LENGTH)); > + GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_START_ADDR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_LO (Qid), > + GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); > + GenetMmioWrite (Genet, GENET_TX_DMA_END_ADDR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_MBUF_DONE_THRES (Qid), 1); > + GenetMmioWrite (Genet, GENET_TX_DMA_FLOW_PERIOD (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_TX_DMA_WRITE_PTR_HI (Qid), 0); > > - // Enable TX queue > - GenetMmioWrite (Genet, GENET_TX_DMA_RING_CFG, (1U << Qid)); > + // Enable TX queue > + GenetMmioWrite (Genet, GENET_TX_DMA_RING_CFG, (1U << Qid)); > > - // Configure RX queue > - GenetMmioWrite (Genet, GENET_RX_SCB_BURST_SIZE, 0x08); > - GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_PROD_INDEX(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_RING_BUF_SIZE(Qid), > - __SHIFTIN(GENET_DMA_DESC_COUNT, GENET_RX_DMA_RING_BUF_SIZE_DESC_COUNT) | > - __SHIFTIN(GENET_MAX_PACKET_SIZE, GENET_RX_DMA_RING_BUF_SIZE_BUF_LENGTH)); > - GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_LO(Qid), > - GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); > - GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_HI(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_XON_XOFF_THRES(Qid), > - __SHIFTIN(5, GENET_RX_DMA_XON_XOFF_THRES_LO) | > - __SHIFTIN(GENET_DMA_DESC_COUNT >> 4, GENET_RX_DMA_XON_XOFF_THRES_HI)); > - GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_LO(Qid), 0); > - GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_HI(Qid), 0); > + // Configure RX queue > + GenetMmioWrite (Genet, GENET_RX_SCB_BURST_SIZE, 0x08); > + GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_WRITE_PTR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_PROD_INDEX (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_RING_BUF_SIZE (Qid), > + __SHIFTIN(GENET_DMA_DESC_COUNT, GENET_RX_DMA_RING_BUF_SIZE_DESC_COUNT) | > + __SHIFTIN(GENET_MAX_PACKET_SIZE, GENET_RX_DMA_RING_BUF_SIZE_BUF_LENGTH)); > + GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_START_ADDR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_LO (Qid), > + GENET_DMA_DESC_COUNT * GENET_DMA_DESC_SIZE / 4 - 1); > + GenetMmioWrite (Genet, GENET_RX_DMA_END_ADDR_HI (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_XON_XOFF_THRES (Qid), > + __SHIFTIN(5, GENET_RX_DMA_XON_XOFF_THRES_LO) | > + __SHIFTIN(GENET_DMA_DESC_COUNT >> 4, GENET_RX_DMA_XON_XOFF_THRES_HI)); > + GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_LO (Qid), 0); > + GenetMmioWrite (Genet, GENET_RX_DMA_READ_PTR_HI (Qid), 0); > > - // Enable RX queue > - GenetMmioWrite (Genet, GENET_RX_DMA_RING_CFG, (1U << Qid)); > + // Enable RX queue > + GenetMmioWrite (Genet, GENET_RX_DMA_RING_CFG, (1U << Qid)); > } > > /** > @@ -564,22 +569,22 @@ GenetDmaInitRings ( > **/ > EFI_STATUS > GenetDmaAlloc ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - EFI_STATUS Status; > - UINTN n; > + EFI_STATUS Status; > + UINTN Idx; > > - for (n = 0; n < GENET_DMA_DESC_COUNT; n++) { > - Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[n]); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "GenetDmaAlloc: Failed to allocate RX buffer: %r\n", Status)); > - GenetDmaFree (Genet); > - return Status; > - } > + for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { > + Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[Idx]); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate RX buffer: %r\n", __FUNCTION__, Status)); > + GenetDmaFree (Genet); > + return Status; > } > + } > > - return EFI_SUCCESS; > + return EFI_SUCCESS; > } > > /** > @@ -594,33 +599,34 @@ GenetDmaAlloc ( > **/ > EFI_STATUS > GenetDmaMapRxDescriptor ( > - IN GENET_PRIVATE_DATA * Genet, > - IN UINT8 DescIndex > - ) > + IN GENET_PRIVATE_DATA * Genet, > + IN UINT8 DescIndex > + ) > { > - EFI_STATUS Status; > - UINTN DmaNumberOfBytes; > + EFI_STATUS Status; > + UINTN DmaNumberOfBytes; > > - ASSERT (Genet->RxBufferMap[DescIndex].Mapping == NULL); > - ASSERT (Genet->RxBuffer[DescIndex] != NULL); > + ASSERT (Genet->RxBufferMap[DescIndex].Mapping == NULL); > + ASSERT (Genet->RxBuffer[DescIndex] != NULL); > > - DmaNumberOfBytes = GENET_MAX_PACKET_SIZE; > - Status = DmaMap (MapOperationBusMasterWrite, > - (VOID *)Genet->RxBuffer[DescIndex], > - &DmaNumberOfBytes, > - &Genet->RxBufferMap[DescIndex].Pa, > - &Genet->RxBufferMap[DescIndex].Mapping); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "GenetDmaMapRxDescriptor: Failed to map RX buffer: %r\n", Status)); > - return Status; > - } > + DmaNumberOfBytes = GENET_MAX_PACKET_SIZE; > + Status = DmaMap (MapOperationBusMasterWrite, > + (VOID *)Genet->RxBuffer[DescIndex], > + &DmaNumberOfBytes, > + &Genet->RxBufferMap[DescIndex].PhysAddress, > + &Genet->RxBufferMap[DescIndex].Mapping); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: Failed to map RX buffer: %r\n", > + __FUNCTION__, Status)); > + return Status; > + } > > - //DEBUG ((DEBUG_INFO, "GenetDmaMapRxDescriptor: Desc 0x%X mapped to 0x%X\n", DescIndex, Genet->RxBufferMap[DescIndex].Pa)); > + GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_LO (DescIndex), > + Genet->RxBufferMap[DescIndex].PhysAddress & 0xFFFFFFFF); > + GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex), > + (Genet->RxBufferMap[DescIndex].PhysAddress >> 32) & 0xFFFFFFFF); > > - GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_LO (DescIndex), Genet->RxBufferMap[DescIndex].Pa & 0xFFFFFFFF); > - GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex), (Genet->RxBufferMap[DescIndex].Pa >> 32) & 0xFFFFFFFF); > - > - return EFI_SUCCESS; > + return EFI_SUCCESS; > } > > /** > @@ -632,14 +638,14 @@ GenetDmaMapRxDescriptor ( > **/ > VOID > GenetDmaUnmapRxDescriptor ( > - IN GENET_PRIVATE_DATA * Genet, > - IN UINT8 DescIndex > - ) > + IN GENET_PRIVATE_DATA * Genet, > + IN UINT8 DescIndex > + ) > { > - if (Genet->RxBufferMap[DescIndex].Mapping != NULL) { > - DmaUnmap (Genet->RxBufferMap[DescIndex].Mapping); > - Genet->RxBufferMap[DescIndex].Mapping = NULL; > - } > + if (Genet->RxBufferMap[DescIndex].Mapping != NULL) { > + DmaUnmap (Genet->RxBufferMap[DescIndex].Mapping); > + Genet->RxBufferMap[DescIndex].Mapping = NULL; > + } > } > > /** > @@ -651,19 +657,20 @@ GenetDmaUnmapRxDescriptor ( > **/ > VOID > GenetDmaFree ( > - IN GENET_PRIVATE_DATA *Genet > - ) > + IN GENET_PRIVATE_DATA *Genet > + ) > { > - UINTN n; > + UINTN Idx; > > - for (n = 0; n < GENET_DMA_DESC_COUNT; n++) { > - GenetDmaUnmapRxDescriptor (Genet, n); > + for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { > + GenetDmaUnmapRxDescriptor (Genet, Idx); > > - if (Genet->RxBuffer[n] != NULL) { > - DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), Genet->RxBuffer[n]); > - Genet->RxBuffer[n] = NULL; > - } > + if (Genet->RxBuffer[Idx] != NULL) { > + DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), > + Genet->RxBuffer[Idx]); > + Genet->RxBuffer[Idx] = NULL; > } > + } > } > > /** > @@ -677,26 +684,29 @@ GenetDmaFree ( > **/ > VOID > GenetDmaTriggerTx ( > - IN GENET_PRIVATE_DATA * Genet, > - IN UINT8 DescIndex, > - IN EFI_PHYSICAL_ADDRESS PhysAddr, > - IN UINTN NumberOfBytes > - ) > + IN GENET_PRIVATE_DATA * Genet, > + IN UINT8 DescIndex, > + IN EFI_PHYSICAL_ADDRESS PhysAddr, > + IN UINTN NumberOfBytes > + ) > { > - UINT32 DescStatus; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT32 DescStatus; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - DescStatus = GENET_TX_DESC_STATUS_SOP | > - GENET_TX_DESC_STATUS_EOP | > - GENET_TX_DESC_STATUS_CRC | > - GENET_TX_DESC_STATUS_QTAG | > - __SHIFTIN(NumberOfBytes, GENET_TX_DESC_STATUS_BUFLEN); > + DescStatus = GENET_TX_DESC_STATUS_SOP | > + GENET_TX_DESC_STATUS_EOP | > + GENET_TX_DESC_STATUS_CRC | > + GENET_TX_DESC_STATUS_QTAG | > + __SHIFTIN(NumberOfBytes, GENET_TX_DESC_STATUS_BUFLEN); > > - GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_LO(DescIndex), PhysAddr & 0xFFFFFFFF); > - GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_HI(DescIndex), (PhysAddr >> 32) & 0xFFFFFFFF); > - GenetMmioWrite (Genet, GENET_TX_DESC_STATUS(DescIndex), DescStatus); > + GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_LO (DescIndex), > + PhysAddr & 0xFFFFFFFF); > + GenetMmioWrite (Genet, GENET_TX_DESC_ADDRESS_HI (DescIndex), > + (PhysAddr >> 32) & 0xFFFFFFFF); > + GenetMmioWrite (Genet, GENET_TX_DESC_STATUS (DescIndex), DescStatus); > > - GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX (Qid), (DescIndex + 1) & 0xFFFF); > + GenetMmioWrite (Genet, GENET_TX_DMA_PROD_INDEX (Qid), > + (DescIndex + 1) & 0xFFFF); > } > > /** > @@ -708,24 +718,24 @@ GenetDmaTriggerTx ( > **/ > VOID > GenetTxIntr ( > - IN GENET_PRIVATE_DATA *Genet, > - OUT VOID **TxBuf > - ) > + IN GENET_PRIVATE_DATA *Genet, > + OUT VOID **TxBuf > + ) > { > - UINT32 ConsIndex, Total; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + UINT32 ConsIndex, Total; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - ConsIndex = GenetMmioRead (Genet, GENET_TX_DMA_CONS_INDEX (Qid)) & 0xFFFF; > + ConsIndex = GenetMmioRead (Genet, GENET_TX_DMA_CONS_INDEX (Qid)) & 0xFFFF; > > - Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; > - if (Genet->TxQueued > 0 && Total > 0) { > - *TxBuf = Genet->TxBuffer[Genet->TxNext]; > - Genet->TxQueued--; > - Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT; > - Genet->TxConsIndex++; > - } else { > - *TxBuf = NULL; > - } > + Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; > + if (Genet->TxQueued > 0 && Total > 0) { > + *TxBuf = Genet->TxBuffer[Genet->TxNext]; > + Genet->TxQueued--; > + Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT; > + Genet->TxConsIndex++; > + } else { > + *TxBuf = NULL; > + } > } > > /** > @@ -742,32 +752,30 @@ GenetTxIntr ( > **/ > EFI_STATUS > GenetRxIntr ( > - IN GENET_PRIVATE_DATA *Genet, > - OUT UINT8 *DescIndex, > - OUT UINTN *FrameLength > - ) > + IN GENET_PRIVATE_DATA *Genet, > + OUT UINT8 *DescIndex, > + OUT UINTN *FrameLength > + ) > { > - EFI_STATUS Status; > - UINT32 ProdIndex, Total; > - UINT32 DescStatus; > - UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > + EFI_STATUS Status; > + UINT32 ProdIndex, Total; > + UINT32 DescStatus; > + UINT8 Qid = GENET_DMA_DEFAULT_QUEUE; > > - ProdIndex = GenetMmioRead (Genet, GENET_RX_DMA_PROD_INDEX (Qid)) & 0xFFFF; > + ProdIndex = GenetMmioRead (Genet, GENET_RX_DMA_PROD_INDEX (Qid)) & 0xFFFF; > > - Total = (ProdIndex - Genet->RxConsIndex) & 0xFFFF; > - if (Total > 0) { > - *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT; > - DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS (*DescIndex)); > - *FrameLength = __SHIFTOUT (DescStatus, GENET_RX_DESC_STATUS_BUFLEN); > + Total = (ProdIndex - Genet->RxConsIndex) & 0xFFFF; > + if (Total > 0) { > + *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT; > + DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS (*DescIndex)); > + *FrameLength = __SHIFTOUT (DescStatus, GENET_RX_DESC_STATUS_BUFLEN); > > - //DEBUG ((DEBUG_INFO, "GenetRxIntr: DescIndex=0x%X FrameLength=0x%X\n", *DescIndex, *FrameLength)); > + Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0xFFFF; > + GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (Qid), Genet->RxConsIndex); > + Status = EFI_SUCCESS; > + } else { > + Status = EFI_NOT_READY; > + } > > - Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0xFFFF; > - GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (Qid), Genet->RxConsIndex); > - Status = EFI_SUCCESS; > - } else { > - Status = EFI_NOT_READY; > - } > - > - return Status; > + return Status; > } > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > index bf28448445d1..951495127ce9 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > @@ -31,7 +31,7 @@ GenetSimpleNetworkStart ( > IN EFI_SIMPLE_NETWORK_PROTOCOL *This > ) > { > - GENET_PRIVATE_DATA *Genet; > + GENET_PRIVATE_DATA *Genet; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -67,7 +67,7 @@ GenetSimpleNetworkStop ( > IN EFI_SIMPLE_NETWORK_PROTOCOL *This > ) > { > - GENET_PRIVATE_DATA *Genet; > + GENET_PRIVATE_DATA *Genet; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -194,8 +194,8 @@ GenetSimpleNetworkReset ( > IN BOOLEAN ExtendedVerification > ) > { > - GENET_PRIVATE_DATA *Genet; > - EFI_STATUS Status; > + GENET_PRIVATE_DATA *Genet; > + EFI_STATUS Status; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -299,7 +299,7 @@ GenetSimpleNetworkReceiveFilters ( > IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL > ) > { > - GENET_PRIVATE_DATA *Genet; > + GENET_PRIVATE_DATA *Genet; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -347,7 +347,7 @@ GenetSimpleNetworkStationAddress ( > IN EFI_MAC_ADDRESS *New OPTIONAL > ) > { > - GENET_PRIVATE_DATA *Genet; > + GENET_PRIVATE_DATA *Genet; > > if (This == NULL || This->Mode == NULL) { > return EFI_INVALID_PARAMETER; > @@ -480,8 +480,8 @@ GenetSimpleNetworkGetStatus ( > OUT VOID **TxBuf OPTIONAL > ) > { > - GENET_PRIVATE_DATA *Genet; > - EFI_STATUS Status; > + GENET_PRIVATE_DATA *Genet; > + EFI_STATUS Status; > > if (This == NULL) { > return EFI_INVALID_PARAMETER; > @@ -555,17 +555,17 @@ GenetSimpleNetworkTransmit ( > IN UINT16 *Protocol OPTIONAL > ) > { > - GENET_PRIVATE_DATA *Genet; > - EFI_STATUS Status; > - UINT8 *Frame = Buffer; > - UINT8 Desc; > - PHYSICAL_ADDRESS DmaDeviceAddress; > - UINTN DmaNumberOfBytes; > - VOID *DmaMapping; > + GENET_PRIVATE_DATA *Genet; > + EFI_STATUS Status; > + UINT8 *Frame = Buffer; > + UINT8 Desc; > + PHYSICAL_ADDRESS DmaDeviceAddress; > + UINTN DmaNumberOfBytes; > + VOID *DmaMapping; > > if (This == NULL || Buffer == NULL) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: Invalid parameter (missing handle or buffer)\n")); > + DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or buffer)\n", > + __FUNCTION__)); > return EFI_INVALID_PARAMETER; > } > > @@ -587,32 +587,33 @@ GenetSimpleNetworkTransmit ( > if (HeaderSize != 0) { > if (HeaderSize != Genet->SnpMode.MediaHeaderSize) { > DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: Invalid parameter (header size mismatch; HeaderSize 0x%X, SnpMode.MediaHeaderSize 0x%X))\n", HeaderSize, Genet->SnpMode.MediaHeaderSize)); > + "%a: Invalid parameter (header size mismatch; HeaderSize 0x%X, SnpMode.MediaHeaderSize 0x%X))\n", > + __FUNCTION__, HeaderSize, Genet->SnpMode.MediaHeaderSize)); > return EFI_INVALID_PARAMETER; > } > if (DestAddr == NULL || Protocol == NULL) { > DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: Invalid parameter (dest addr or protocol missing)\n")); > + "%a: Invalid parameter (dest addr or protocol missing)\n", > + __FUNCTION__)); > return EFI_INVALID_PARAMETER; > } > } > > if (BufferSize < Genet->SnpMode.MediaHeaderSize) { > - DEBUG ((DEBUG_ERROR, "GenetSimpleNetworkTransmit: Buffer too small\n")); > + DEBUG ((DEBUG_ERROR, "%a: Buffer too small\n", __FUNCTION__)); > return EFI_BUFFER_TOO_SMALL; > } > > Status = EfiAcquireLockOrFail (&Genet->Lock); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: Couldn't get lock: %r\n", Status)); > + DEBUG ((DEBUG_ERROR, "%a: Couldn't get lock: %r\n", __FUNCTION__, Status)); > return EFI_ACCESS_DENIED; > } > > if (Genet->TxQueued == GENET_DMA_DESC_COUNT - 1) { > EfiReleaseLock (&Genet->Lock); > > - DEBUG ((DEBUG_ERROR, "GenetSimpleNetworkTransmit: Queue full\n")); > + DEBUG ((DEBUG_ERROR, "%a: Queue full\n", __FUNCTION__)); > return EFI_NOT_READY; > } > > @@ -634,8 +635,7 @@ GenetSimpleNetworkTransmit ( > &DmaDeviceAddress, > &DmaMapping); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkTransmit: DmaMap failed: %r\n", Status)); > + DEBUG ((DEBUG_ERROR, "%a: DmaMap failed: %r\n", __FUNCTION__, Status)); > EfiReleaseLock (&Genet->Lock); > return Status; > } > @@ -703,8 +703,8 @@ GenetSimpleNetworkReceive ( > UINTN FrameLength; > > if (This == NULL || Buffer == NULL) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Invalid parameter (missing handle or buffer)\n")); > + DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or buffer)\n", > + __FUNCTION__)); > return EFI_INVALID_PARAMETER; > } > > @@ -718,8 +718,7 @@ GenetSimpleNetworkReceive ( > > Status = EfiAcquireLockOrFail (&Genet->Lock); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Couldn't get lock: %r\n", Status)); > + DEBUG ((DEBUG_ERROR, "%a: Couldn't get lock: %r\n", __FUNCTION__, Status)); > return EFI_ACCESS_DENIED; > } > > @@ -742,12 +741,12 @@ GenetSimpleNetworkReceive ( > > if (*BufferSize < FrameLength) { > DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Buffer size (0x%X) is too small for frame (0x%X)\n", > - *BufferSize, FrameLength)); > + "%a: Buffer size (0x%X) is too small for frame (0x%X)\n", > + __FUNCTION__, *BufferSize, FrameLength)); > Status = GenetDmaMapRxDescriptor (Genet, DescIndex); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Failed to remap RX descriptor!\n")); > + DEBUG ((DEBUG_ERROR, "%a: Failed to remap RX descriptor!\n", > + __FUNCTION__)); > } > EfiReleaseLock (&Genet->Lock); > return EFI_BUFFER_TOO_SMALL; > @@ -771,16 +770,14 @@ GenetSimpleNetworkReceive ( > > Status = EFI_SUCCESS; > } else { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Short packet (FrameLength 0x%X)", > - FrameLength)); > + DEBUG ((DEBUG_ERROR, "%a: Short packet (FrameLength 0x%X)", > + __FUNCTION__, FrameLength)); > Status = EFI_NOT_READY; > } > > Status = GenetDmaMapRxDescriptor (Genet, DescIndex); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, > - "GenetSimpleNetworkReceive: Failed to remap RX descriptor!\n")); > + DEBUG ((DEBUG_ERROR, "%a: Failed to remap RX descriptor!\n", __FUNCTION__)); > } > > EfiReleaseLock (&Genet->Lock); > @@ -791,12 +788,12 @@ GenetSimpleNetworkReceive ( > This function converts a multicast IP address to a multicast HW MAC address > for all packet transactions. > > - @param [in] pSimpleNetwork Protocol instance pointer > - @param [in] bIPv6 Set to TRUE if the multicast IP address is IPv6 [RFC2460]. > + @param [in] SimpleNetwork Protocol instance pointer > + @param [in] IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC2460]. > Set to FALSE if the multicast IP address is IPv4 [RFC 791]. > - @param [in] pIP The multicast IP address that is to be converted to a > + @param [in] IP The multicast IP address that is to be converted to a > multicast HW MAC address. > - @param [in] pMAC The multicast HW MAC address that is to be generated from IP. > + @param [in] MAC The multicast HW MAC address that is to be generated from IP. > > @retval EFI_SUCCESS This operation was successful. > @retval EFI_NOT_STARTED The network interface was not started. > @@ -810,10 +807,10 @@ STATIC > EFI_STATUS > EFIAPI > GenetSimpleNetworkMCastIPtoMAC ( > - IN EFI_SIMPLE_NETWORK_PROTOCOL *pSimpleNetwork, > - IN BOOLEAN bIPv6, > - IN EFI_IP_ADDRESS *pIP, > - OUT EFI_MAC_ADDRESS *pMAC > + IN EFI_SIMPLE_NETWORK_PROTOCOL *SimpleNetwork, > + IN BOOLEAN IPv6, > + IN EFI_IP_ADDRESS *IP, > + OUT EFI_MAC_ADDRESS *MAC > ) > { > return EFI_UNSUPPORTED; > @@ -822,7 +819,6 @@ GenetSimpleNetworkMCastIPtoMAC ( > /// > /// Simple Network Protocol instance > /// > -GLOBAL_REMOVE_IF_UNREFERENCED > CONST EFI_SIMPLE_NETWORK_PROTOCOL gGenetSimpleNetworkTemplate = { > EFI_SIMPLE_NETWORK_PROTOCOL_REVISION, // Revision > GenetSimpleNetworkStart, // Start > ^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel 2020-05-11 14:55 ` [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Ard Biesheuvel @ 2020-05-11 14:55 ` Ard Biesheuvel 2020-05-11 16:44 ` Andrei Warkentin 2020-05-11 20:34 ` Jeremy Linton 2020-05-11 14:55 ` [PATCH edk2-platforms v4 3/9] Silicon/Broadcom/BcmGenetDxe: fix multicast/broadcast handling Ard Biesheuvel ` (7 subsequent siblings) 9 siblings, 2 replies; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton Add a helper to configure the first MDF filter for filtering the broadcast Ethernet address. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 7 +++++ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 33 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index b21a284b6221..b491ea4665b0 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -107,6 +107,7 @@ #define GENET_UMAC_MDF_CTRL 0xe50 #define GENET_UMAC_MDF_ADDR0(n) (0xe54 + (n) * 0x8) #define GENET_UMAC_MDF_ADDR1(n) (0xe58 + (n) * 0x8) +#define GENET_MAX_MDF_FILTER 17 #define GENET_DMA_DESC_COUNT 256 #define GENET_DMA_DESC_SIZE 12 @@ -300,6 +301,12 @@ GenetSetPromisc ( IN BOOLEAN Enable ); +VOID +GenetEnableBroadcastFilter ( + IN GENET_PRIVATE_DATA *Genet, + IN BOOLEAN Enable + ); + VOID GenetDmaInitRings ( IN GENET_PRIVATE_DATA *Genet diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index 7ae9acec4c78..71c659e7f882 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -492,6 +492,39 @@ GenetSetPromisc ( GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); } +/** + Enable the MAC filter for the Ethernet broadcast address + + @param Genet[in] Pointer to GENET_PRIVATE_DATA. + @param Enable[in] Promiscuous mode state. + +**/ +VOID +GenetEnableBroadcastFilter ( + IN GENET_PRIVATE_DATA *Genet, + IN BOOLEAN Enable + ) +{ + CONST EFI_MAC_ADDRESS *MacAddr = &Genet->SnpMode.CurrentAddress; + UINT32 Value; + + if (Enable) { + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR0 (0), + MacAddr->Addr[1] | MacAddr->Addr[0] << 8); + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR1 (0), + MacAddr->Addr[5] | MacAddr->Addr[4] << 8 | + MacAddr->Addr[3] << 16 | MacAddr->Addr[2] << 24); + + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR0 (1), 0xffff); + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR1 (1), 0xffffffff); + + Value = (1U << GENET_MAX_MDF_FILTER) & ~(BIT1 | BIT0); + } else { + Value = 0; + } + GenetMmioWrite (Genet, GENET_UMAC_MDF_CTRL, Value); +} + /** Configure DMA TX and RX queues, enabling them. -- 2.17.1 ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering 2020-05-11 14:55 ` [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Ard Biesheuvel @ 2020-05-11 16:44 ` Andrei Warkentin 2020-05-11 20:34 ` Jeremy Linton 1 sibling, 0 replies; 25+ messages in thread From: Andrei Warkentin @ 2020-05-11 16:44 UTC (permalink / raw) To: Ard Biesheuvel, devel@edk2.groups.io Cc: Pete Batard, Jared McNeill, Samer El-Haj-Mahmoud, Jeremy Linton [-- Attachment #1: Type: text/plain, Size: 3297 bytes --] Reviewed-by: Andrei Warkentin <andrey.warkentin@gmail.com> ________________________________ From: Ard Biesheuvel <ard.biesheuvel@arm.com> Sent: Monday, May 11, 2020 9:55 AM To: devel@edk2.groups.io <devel@edk2.groups.io> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Pete Batard <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin <awarkentin@vmware.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton <jeremy.linton@arm.com> Subject: [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Add a helper to configure the first MDF filter for filtering the broadcast Ethernet address. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 7 +++++ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 33 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index b21a284b6221..b491ea4665b0 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -107,6 +107,7 @@ #define GENET_UMAC_MDF_CTRL 0xe50 #define GENET_UMAC_MDF_ADDR0(n) (0xe54 + (n) * 0x8) #define GENET_UMAC_MDF_ADDR1(n) (0xe58 + (n) * 0x8) +#define GENET_MAX_MDF_FILTER 17 #define GENET_DMA_DESC_COUNT 256 #define GENET_DMA_DESC_SIZE 12 @@ -300,6 +301,12 @@ GenetSetPromisc ( IN BOOLEAN Enable ); +VOID +GenetEnableBroadcastFilter ( + IN GENET_PRIVATE_DATA *Genet, + IN BOOLEAN Enable + ); + VOID GenetDmaInitRings ( IN GENET_PRIVATE_DATA *Genet diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index 7ae9acec4c78..71c659e7f882 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -492,6 +492,39 @@ GenetSetPromisc ( GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); } +/** + Enable the MAC filter for the Ethernet broadcast address + + @param Genet[in] Pointer to GENET_PRIVATE_DATA. + @param Enable[in] Promiscuous mode state. + +**/ +VOID +GenetEnableBroadcastFilter ( + IN GENET_PRIVATE_DATA *Genet, + IN BOOLEAN Enable + ) +{ + CONST EFI_MAC_ADDRESS *MacAddr = &Genet->SnpMode.CurrentAddress; + UINT32 Value; + + if (Enable) { + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR0 (0), + MacAddr->Addr[1] | MacAddr->Addr[0] << 8); + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR1 (0), + MacAddr->Addr[5] | MacAddr->Addr[4] << 8 | + MacAddr->Addr[3] << 16 | MacAddr->Addr[2] << 24); + + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR0 (1), 0xffff); + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR1 (1), 0xffffffff); + + Value = (1U << GENET_MAX_MDF_FILTER) & ~(BIT1 | BIT0); + } else { + Value = 0; + } + GenetMmioWrite (Genet, GENET_UMAC_MDF_CTRL, Value); +} + /** Configure DMA TX and RX queues, enabling them. -- 2.17.1 [-- Attachment #2: Type: text/html, Size: 6152 bytes --] ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering 2020-05-11 14:55 ` [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Ard Biesheuvel 2020-05-11 16:44 ` Andrei Warkentin @ 2020-05-11 20:34 ` Jeremy Linton 2020-05-11 21:21 ` Ard Biesheuvel 1 sibling, 1 reply; 25+ messages in thread From: Jeremy Linton @ 2020-05-11 20:34 UTC (permalink / raw) To: Ard Biesheuvel, devel Cc: Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud Hi, On 5/11/20 9:55 AM, Ard Biesheuvel wrote: > Add a helper to configure the first MDF filter for filtering the > broadcast Ethernet address. > > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> > --- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 7 +++++ > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 33 ++++++++++++++++++++ > 2 files changed, 40 insertions(+) > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > index b21a284b6221..b491ea4665b0 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > @@ -107,6 +107,7 @@ > #define GENET_UMAC_MDF_CTRL 0xe50 > #define GENET_UMAC_MDF_ADDR0(n) (0xe54 + (n) * 0x8) > #define GENET_UMAC_MDF_ADDR1(n) (0xe58 + (n) * 0x8) > +#define GENET_MAX_MDF_FILTER 17 > > #define GENET_DMA_DESC_COUNT 256 > #define GENET_DMA_DESC_SIZE 12 > @@ -300,6 +301,12 @@ GenetSetPromisc ( > IN BOOLEAN Enable > ); > > +VOID > +GenetEnableBroadcastFilter ( > + IN GENET_PRIVATE_DATA *Genet, > + IN BOOLEAN Enable > + ); > + > VOID > GenetDmaInitRings ( > IN GENET_PRIVATE_DATA *Genet > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > index 7ae9acec4c78..71c659e7f882 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > @@ -492,6 +492,39 @@ GenetSetPromisc ( > GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); > } > > +/** > + Enable the MAC filter for the Ethernet broadcast address > + > + @param Genet[in] Pointer to GENET_PRIVATE_DATA. > + @param Enable[in] Promiscuous mode state. > + > +**/ > +VOID > +GenetEnableBroadcastFilter ( > + IN GENET_PRIVATE_DATA *Genet, > + IN BOOLEAN Enable > + ) > +{ > + CONST EFI_MAC_ADDRESS *MacAddr = &Genet->SnpMode.CurrentAddress; > + UINT32 Value; > + > + if (Enable) { > + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR0 (0), > + MacAddr->Addr[1] | MacAddr->Addr[0] << 8); > + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR1 (0), > + MacAddr->Addr[5] | MacAddr->Addr[4] << 8 | > + MacAddr->Addr[3] << 16 | MacAddr->Addr[2] << 24); > + > + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR0 (1), 0xffff); > + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR1 (1), 0xffffffff); > + > + Value = (1U << GENET_MAX_MDF_FILTER) & ~(BIT1 | BIT0); Is this right? Looking at the linux code, it looks like the a filter is enabled in a big endian field starting at bit 16 and working its way down. AFAIK, you want bit 16, and bit 15 set for two filters? > + } else { > + Value = 0; > + } > + GenetMmioWrite (Genet, GENET_UMAC_MDF_CTRL, Value); > +} > + > /** > Configure DMA TX and RX queues, enabling them. > > ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering 2020-05-11 20:34 ` Jeremy Linton @ 2020-05-11 21:21 ` Ard Biesheuvel 0 siblings, 0 replies; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 21:21 UTC (permalink / raw) To: Jeremy Linton, devel Cc: Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud On 5/11/20 10:34 PM, Jeremy Linton wrote: > Hi, > > On 5/11/20 9:55 AM, Ard Biesheuvel wrote: >> Add a helper to configure the first MDF filter for filtering the >> broadcast Ethernet address. >> >> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> >> --- >> Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 7 +++++ >> Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 33 >> ++++++++++++++++++++ >> 2 files changed, 40 insertions(+) >> >> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h >> b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h >> index b21a284b6221..b491ea4665b0 100644 >> --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h >> +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h >> @@ -107,6 +107,7 @@ >> #define GENET_UMAC_MDF_CTRL 0xe50 >> #define GENET_UMAC_MDF_ADDR0(n) (0xe54 + (n) * 0x8) >> #define GENET_UMAC_MDF_ADDR1(n) (0xe58 + (n) * 0x8) >> +#define GENET_MAX_MDF_FILTER 17 >> #define GENET_DMA_DESC_COUNT 256 >> #define GENET_DMA_DESC_SIZE 12 >> @@ -300,6 +301,12 @@ GenetSetPromisc ( >> IN BOOLEAN Enable >> ); >> +VOID >> +GenetEnableBroadcastFilter ( >> + IN GENET_PRIVATE_DATA *Genet, >> + IN BOOLEAN Enable >> + ); >> + >> VOID >> GenetDmaInitRings ( >> IN GENET_PRIVATE_DATA *Genet >> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c >> b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c >> index 7ae9acec4c78..71c659e7f882 100644 >> --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c >> +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c >> @@ -492,6 +492,39 @@ GenetSetPromisc ( >> GenetMmioWrite (Genet, GENET_UMAC_CMD, Value); >> } >> +/** >> + Enable the MAC filter for the Ethernet broadcast address >> + >> + @param Genet[in] Pointer to GENET_PRIVATE_DATA. >> + @param Enable[in] Promiscuous mode state. >> + >> +**/ >> +VOID >> +GenetEnableBroadcastFilter ( >> + IN GENET_PRIVATE_DATA *Genet, >> + IN BOOLEAN Enable >> + ) >> +{ >> + CONST EFI_MAC_ADDRESS *MacAddr = &Genet->SnpMode.CurrentAddress; >> + UINT32 Value; >> + >> + if (Enable) { >> + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR0 (0), >> + MacAddr->Addr[1] | MacAddr->Addr[0] << 8); >> + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR1 (0), >> + MacAddr->Addr[5] | MacAddr->Addr[4] << 8 | >> + MacAddr->Addr[3] << 16 | MacAddr->Addr[2] << 24); >> + >> + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR0 (1), 0xffff); >> + GenetMmioWrite (Genet, GENET_UMAC_MDF_ADDR1 (1), 0xffffffff); >> + >> + Value = (1U << GENET_MAX_MDF_FILTER) & ~(BIT1 | BIT0); > Is this right? Looking at the linux code, it looks like the a filter is > enabled in a big endian field starting at bit 16 and working its way down. > > AFAIK, you want bit 16, and bit 15 set for two filters? > Yeah, you're right. I was reading both the BSD code and Linux code wrong. That solves the mystery why value = 0x0 works as expected as well. So I will change this to Value = BIT16 | BIT15; instead. Thanks, ^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH edk2-platforms v4 3/9] Silicon/Broadcom/BcmGenetDxe: fix multicast/broadcast handling 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel 2020-05-11 14:55 ` [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Ard Biesheuvel 2020-05-11 14:55 ` [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Ard Biesheuvel @ 2020-05-11 14:55 ` Ard Biesheuvel 2020-05-11 14:55 ` [PATCH edk2-platforms v4 4/9] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA Ard Biesheuvel ` (6 subsequent siblings) 9 siblings, 0 replies; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton Move the handling of the promiscuous receive control to the SNP ReceiveFilters() method where it belongs. Given that we do not support multicast filtering, only minimal handling is required to test the promiscuous bit and program the MAC accordingly. Any multicast handling will be done by the MNP layer above it. For reception of broadcast frames, wire up the new helper that programs the MDF filter bank accordingly. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 7 +++---- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 20 +++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index c23847ba9b52..dacb3ac7d762 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -152,11 +152,10 @@ GenetDriverBindingStart ( Genet->SnpMode.NvRamSize = 0; Genet->SnpMode.NvRamAccessSize = 0; Genet->SnpMode.ReceiveFilterMask = 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_MULTICAST; - Genet->SnpMode.ReceiveFilterSetting = Genet->SnpMode.ReceiveFilterMask; + EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; + Genet->SnpMode.ReceiveFilterSetting = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST | + EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST; Genet->SnpMode.MaxMCastFilterCount = 0; Genet->SnpMode.MCastFilterCount = 0; Genet->SnpMode.IfType = NET_IFTYPE_ETHERNET; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c index 951495127ce9..72ab55619b0e 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c @@ -148,10 +148,6 @@ GenetSimpleNetworkInitialize ( } GenetSetMacAddress (Genet, &Genet->SnpMode.CurrentAddress); - /* - * TODO: this belongs in GenetSimpleNetworkReceiveFilters, not here. - */ - GenetSetPromisc (Genet, TRUE); GenetDmaInitRings (Genet); @@ -306,6 +302,10 @@ GenetSimpleNetworkReceiveFilters ( } Genet = GENET_PRIVATE_DATA_FROM_SNP_THIS (This); + if (((Enable | Disable) & ~Genet->SnpMode.ReceiveFilterMask) != 0 || + (!ResetMCastFilter && MCastFilterCnt > Genet->SnpMode.MaxMCastFilterCount)) { + return EFI_INVALID_PARAMETER; + } if (Genet->SnpMode.State == EfiSimpleNetworkStopped) { return EFI_NOT_STARTED; } @@ -313,13 +313,11 @@ GenetSimpleNetworkReceiveFilters ( return EFI_DEVICE_ERROR; } - // - // Can't actually return EFI_UNSUPPORTED, so just ignore the filters - // (we set promiscuous mode ON inside GenetSimpleNetworkInitialize). - // - // TODO: move promisc handling here. - // TODO 2: support multicast/broadcast. - // + GenetEnableBroadcastFilter (Genet, + (Enable & ~Disable & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST) != 0); + + GenetSetPromisc (Genet, + (Enable & ~Disable & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS) != 0); return EFI_SUCCESS; } -- 2.17.1 ^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH edk2-platforms v4 4/9] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel ` (2 preceding siblings ...) 2020-05-11 14:55 ` [PATCH edk2-platforms v4 3/9] Silicon/Broadcom/BcmGenetDxe: fix multicast/broadcast handling Ard Biesheuvel @ 2020-05-11 14:55 ` Ard Biesheuvel 2020-05-11 16:42 ` Andrei Warkentin 2020-05-11 14:55 ` [PATCH edk2-platforms v4 5/9] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() Ard Biesheuvel ` (5 subsequent siblings) 9 siblings, 1 reply; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton The non-coherent version of DmaAllocateBuffer () returns uncached memory, to ensure that the CPU and the device see the same data, even we they are accessing the buffer at the same time. This is not really necessary for our RX ring: the CPU never accesses the buffer while it is mapped for writing by the device, and so we can simply use the streaming DMA model, which uses ordinary cached buffers, but issues a cache invalidate at DMA unmap time. While at it, reduce the max packet size to 1536 bytes, and allocate the entire buffer array using a single call. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 4 +++ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 6 ++-- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 36 +++++++++----------- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 2 +- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index 1f1aeca7dd6b..248164249c6e 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -51,3 +51,7 @@ [Protocols] gBcmGenetPlatformDeviceProtocolGuid ## TO_START gEfiDevicePathProtocolGuid ## BY_START gEfiSimpleNetworkProtocolGuid ## BY_START + +[FixedPcd] + gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset + gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index b491ea4665b0..ddfbc0806c07 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -50,7 +50,7 @@ #define BRGPHY_SHADOW_1C_GTXCLK_EN 0x0200 #define GENET_VERSION 0x0a -#define GENET_MAX_PACKET_SIZE 2048 +#define GENET_MAX_PACKET_SIZE 1536 #define GENET_SYS_REV_CTRL 0x000 #define SYS_REV_MAJOR (BIT27|BIT26|BIT25|BIT24) @@ -217,7 +217,7 @@ typedef struct { UINT16 TxConsIndex; UINT16 TxProdIndex; - UINT8 *RxBuffer[GENET_DMA_DESC_COUNT]; + EFI_PHYSICAL_ADDRESS RxBuffer; GENET_MAP_INFO RxBufferMap[GENET_DMA_DESC_COUNT]; UINT16 RxConsIndex; UINT16 RxProdIndex; @@ -235,6 +235,8 @@ extern CONST EFI_SIMPLE_NETWORK_PROTOCOL gGenetSimpleNetworkTemplate; #define GENET_DRIVER_SIGNATURE SIGNATURE_32('G', 'N', 'E', 'T') #define GENET_PRIVATE_DATA_FROM_SNP_THIS(a) CR(a, GENET_PRIVATE_DATA, Snp, GENET_DRIVER_SIGNATURE) +#define GENET_RX_BUFFER(g, idx) ((UINT8 *)(UINTN)(g)->RxBuffer + GENET_MAX_PACKET_SIZE * (idx)) + EFI_STATUS EFIAPI GenetPhyRead ( diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index 71c659e7f882..94b578a10aa1 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -19,6 +19,10 @@ #define GENET_PHY_RETRY 1000 +STATIC CONST +EFI_PHYSICAL_ADDRESS mDmaAddressLimit = FixedPcdGet64 (PcdDmaDeviceLimit) - + FixedPcdGet64 (PcdDmaDeviceOffset); + /** Read a memory-mapped device CSR. @@ -605,19 +609,17 @@ GenetDmaAlloc ( IN GENET_PRIVATE_DATA *Genet ) { - EFI_STATUS Status; - UINTN Idx; + EFI_STATUS Status; - for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { - Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[Idx]); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Failed to allocate RX buffer: %r\n", __FUNCTION__, Status)); - GenetDmaFree (Genet); - return Status; - } + Genet->RxBuffer = mDmaAddressLimit; + Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, + EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE * GENET_DMA_DESC_COUNT), + &Genet->RxBuffer); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "%a: Failed to allocate RX buffer: %r\n", __FUNCTION__, Status)); } - - return EFI_SUCCESS; + return Status; } /** @@ -640,11 +642,11 @@ GenetDmaMapRxDescriptor ( UINTN DmaNumberOfBytes; ASSERT (Genet->RxBufferMap[DescIndex].Mapping == NULL); - ASSERT (Genet->RxBuffer[DescIndex] != NULL); + ASSERT (Genet->RxBuffer != 0); DmaNumberOfBytes = GENET_MAX_PACKET_SIZE; Status = DmaMap (MapOperationBusMasterWrite, - (VOID *)Genet->RxBuffer[DescIndex], + GENET_RX_BUFFER (Genet, DescIndex), &DmaNumberOfBytes, &Genet->RxBufferMap[DescIndex].PhysAddress, &Genet->RxBufferMap[DescIndex].Mapping); @@ -697,13 +699,9 @@ GenetDmaFree ( for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { GenetDmaUnmapRxDescriptor (Genet, Idx); - - if (Genet->RxBuffer[Idx] != NULL) { - DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), - Genet->RxBuffer[Idx]); - Genet->RxBuffer[Idx] = NULL; - } } + gBS->FreePages (Genet->RxBuffer, + EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE * GENET_DMA_DESC_COUNT)); } /** diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c index 72ab55619b0e..9746f210d1f2 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c @@ -730,7 +730,7 @@ GenetSimpleNetworkReceive ( GenetDmaUnmapRxDescriptor (Genet, DescIndex); - Frame = Genet->RxBuffer[DescIndex]; + Frame = GENET_RX_BUFFER (Genet, DescIndex); if (FrameLength > 2 + Genet->SnpMode.MediaHeaderSize) { // Received frame has 2 bytes of padding at the start -- 2.17.1 ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 4/9] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA 2020-05-11 14:55 ` [PATCH edk2-platforms v4 4/9] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA Ard Biesheuvel @ 2020-05-11 16:42 ` Andrei Warkentin 2020-05-11 16:53 ` Ard Biesheuvel 0 siblings, 1 reply; 25+ messages in thread From: Andrei Warkentin @ 2020-05-11 16:42 UTC (permalink / raw) To: Ard Biesheuvel, devel@edk2.groups.io Cc: Pete Batard, Jared McNeill, Samer El-Haj-Mahmoud, Jeremy Linton [-- Attachment #1: Type: text/plain, Size: 7112 bytes --] Is 1500 the max MTU that UEFI uses? Wasn't clear from the spec. Otherwise looks good - esp optimizing the allocations instead of wasting half page on every alloc 🙂. LGTM Reviewed-by: Andrei Warkentin <andrey.warkentin@gmail.com> ________________________________ From: Ard Biesheuvel <ard.biesheuvel@arm.com> Sent: Monday, May 11, 2020 9:55 AM To: devel@edk2.groups.io <devel@edk2.groups.io> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Pete Batard <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin <awarkentin@vmware.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton <jeremy.linton@arm.com> Subject: [PATCH edk2-platforms v4 4/9] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA The non-coherent version of DmaAllocateBuffer () returns uncached memory, to ensure that the CPU and the device see the same data, even we they are accessing the buffer at the same time. This is not really necessary for our RX ring: the CPU never accesses the buffer while it is mapped for writing by the device, and so we can simply use the streaming DMA model, which uses ordinary cached buffers, but issues a cache invalidate at DMA unmap time. While at it, reduce the max packet size to 1536 bytes, and allocate the entire buffer array using a single call. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 4 +++ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 6 ++-- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 36 +++++++++----------- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 2 +- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index 1f1aeca7dd6b..248164249c6e 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -51,3 +51,7 @@ [Protocols] gBcmGenetPlatformDeviceProtocolGuid ## TO_START gEfiDevicePathProtocolGuid ## BY_START gEfiSimpleNetworkProtocolGuid ## BY_START + +[FixedPcd] + gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset + gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index b491ea4665b0..ddfbc0806c07 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -50,7 +50,7 @@ #define BRGPHY_SHADOW_1C_GTXCLK_EN 0x0200 #define GENET_VERSION 0x0a -#define GENET_MAX_PACKET_SIZE 2048 +#define GENET_MAX_PACKET_SIZE 1536 #define GENET_SYS_REV_CTRL 0x000 #define SYS_REV_MAJOR (BIT27|BIT26|BIT25|BIT24) @@ -217,7 +217,7 @@ typedef struct { UINT16 TxConsIndex; UINT16 TxProdIndex; - UINT8 *RxBuffer[GENET_DMA_DESC_COUNT]; + EFI_PHYSICAL_ADDRESS RxBuffer; GENET_MAP_INFO RxBufferMap[GENET_DMA_DESC_COUNT]; UINT16 RxConsIndex; UINT16 RxProdIndex; @@ -235,6 +235,8 @@ extern CONST EFI_SIMPLE_NETWORK_PROTOCOL gGenetSimpleNetworkTemplate; #define GENET_DRIVER_SIGNATURE SIGNATURE_32('G', 'N', 'E', 'T') #define GENET_PRIVATE_DATA_FROM_SNP_THIS(a) CR(a, GENET_PRIVATE_DATA, Snp, GENET_DRIVER_SIGNATURE) +#define GENET_RX_BUFFER(g, idx) ((UINT8 *)(UINTN)(g)->RxBuffer + GENET_MAX_PACKET_SIZE * (idx)) + EFI_STATUS EFIAPI GenetPhyRead ( diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index 71c659e7f882..94b578a10aa1 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -19,6 +19,10 @@ #define GENET_PHY_RETRY 1000 +STATIC CONST +EFI_PHYSICAL_ADDRESS mDmaAddressLimit = FixedPcdGet64 (PcdDmaDeviceLimit) - + FixedPcdGet64 (PcdDmaDeviceOffset); + /** Read a memory-mapped device CSR. @@ -605,19 +609,17 @@ GenetDmaAlloc ( IN GENET_PRIVATE_DATA *Genet ) { - EFI_STATUS Status; - UINTN Idx; + EFI_STATUS Status; - for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { - Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[Idx]); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Failed to allocate RX buffer: %r\n", __FUNCTION__, Status)); - GenetDmaFree (Genet); - return Status; - } + Genet->RxBuffer = mDmaAddressLimit; + Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, + EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE * GENET_DMA_DESC_COUNT), + &Genet->RxBuffer); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "%a: Failed to allocate RX buffer: %r\n", __FUNCTION__, Status)); } - - return EFI_SUCCESS; + return Status; } /** @@ -640,11 +642,11 @@ GenetDmaMapRxDescriptor ( UINTN DmaNumberOfBytes; ASSERT (Genet->RxBufferMap[DescIndex].Mapping == NULL); - ASSERT (Genet->RxBuffer[DescIndex] != NULL); + ASSERT (Genet->RxBuffer != 0); DmaNumberOfBytes = GENET_MAX_PACKET_SIZE; Status = DmaMap (MapOperationBusMasterWrite, - (VOID *)Genet->RxBuffer[DescIndex], + GENET_RX_BUFFER (Genet, DescIndex), &DmaNumberOfBytes, &Genet->RxBufferMap[DescIndex].PhysAddress, &Genet->RxBufferMap[DescIndex].Mapping); @@ -697,13 +699,9 @@ GenetDmaFree ( for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { GenetDmaUnmapRxDescriptor (Genet, Idx); - - if (Genet->RxBuffer[Idx] != NULL) { - DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), - Genet->RxBuffer[Idx]); - Genet->RxBuffer[Idx] = NULL; - } } + gBS->FreePages (Genet->RxBuffer, + EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE * GENET_DMA_DESC_COUNT)); } /** diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c index 72ab55619b0e..9746f210d1f2 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c @@ -730,7 +730,7 @@ GenetSimpleNetworkReceive ( GenetDmaUnmapRxDescriptor (Genet, DescIndex); - Frame = Genet->RxBuffer[DescIndex]; + Frame = GENET_RX_BUFFER (Genet, DescIndex); if (FrameLength > 2 + Genet->SnpMode.MediaHeaderSize) { // Received frame has 2 bytes of padding at the start -- 2.17.1 [-- Attachment #2: Type: text/html, Size: 13137 bytes --] ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 4/9] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA 2020-05-11 16:42 ` Andrei Warkentin @ 2020-05-11 16:53 ` Ard Biesheuvel 0 siblings, 0 replies; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 16:53 UTC (permalink / raw) To: Andrei Warkentin, devel@edk2.groups.io Cc: Pete Batard, Jared McNeill, Samer El-Haj-Mahmoud, Jeremy Linton On 5/11/20 6:42 PM, Andrei Warkentin wrote: > Is 1500 the max MTU that UEFI uses? Wasn't clear from the spec. > > Otherwise looks good - esp optimizing the allocations instead of wasting > half page on every alloc 🙂. > > LGTM > > Reviewed-by: Andrei Warkentin <andrey.warkentin@gmail.com> > Thanks. I couldn't disentangle that mess either, but I *think* we should probably be using 1500 for SnpMode.MaxPacketSize, since MNP adds the VLAN tag lan and Ethernet FCS size to that. Currently, we have Genet->SnpMode.MaxPacketSize = GENET_MAX_PACKET_SIZE; which is definitely wrong. (1536 is a multiple of 512 so it is guaranteed to be cacheline aligned, which helps the non-coherent DMA lib map the buffers without having to do cache maintenance) > ------------------------------------------------------------------------ > *From:* Ard Biesheuvel <ard.biesheuvel@arm.com> > *Sent:* Monday, May 11, 2020 9:55 AM > *To:* devel@edk2.groups.io <devel@edk2.groups.io> > *Cc:* Ard Biesheuvel <ard.biesheuvel@arm.com>; Pete Batard > <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin > <awarkentin@vmware.com>; Samer El-Haj-Mahmoud > <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton <jeremy.linton@arm.com> > *Subject:* [PATCH edk2-platforms v4 4/9] Silicon/Broadcom/BcmGenetDxe: > avoid uncached memory for streaming DMA > The non-coherent version of DmaAllocateBuffer () returns uncached > memory, to ensure that the CPU and the device see the same data, > even we they are accessing the buffer at the same time. > > This is not really necessary for our RX ring: the CPU never accesses > the buffer while it is mapped for writing by the device, and so we > can simply use the streaming DMA model, which uses ordinary cached > buffers, but issues a cache invalidate at DMA unmap time. > > While at it, reduce the max packet size to 1536 bytes, and allocate > the entire buffer array using a single call. > > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> > --- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 4 +++ > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 6 ++-- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 36 > +++++++++----------- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 2 +- > 4 files changed, 26 insertions(+), 22 deletions(-) > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > index 1f1aeca7dd6b..248164249c6e 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > @@ -51,3 +51,7 @@ [Protocols] > gBcmGenetPlatformDeviceProtocolGuid ## TO_START > gEfiDevicePathProtocolGuid ## BY_START > gEfiSimpleNetworkProtocolGuid ## BY_START > + > +[FixedPcd] > + gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset > + gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > index b491ea4665b0..ddfbc0806c07 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h > @@ -50,7 +50,7 @@ > #define BRGPHY_SHADOW_1C_GTXCLK_EN 0x0200 > > #define GENET_VERSION 0x0a > -#define GENET_MAX_PACKET_SIZE 2048 > +#define GENET_MAX_PACKET_SIZE 1536 > > #define GENET_SYS_REV_CTRL 0x000 > #define SYS_REV_MAJOR (BIT27|BIT26|BIT25|BIT24) > @@ -217,7 +217,7 @@ typedef struct { > UINT16 TxConsIndex; > UINT16 TxProdIndex; > > - UINT8 *RxBuffer[GENET_DMA_DESC_COUNT]; > + EFI_PHYSICAL_ADDRESS RxBuffer; > GENET_MAP_INFO RxBufferMap[GENET_DMA_DESC_COUNT]; > UINT16 RxConsIndex; > UINT16 RxProdIndex; > @@ -235,6 +235,8 @@ extern CONST EFI_SIMPLE_NETWORK_PROTOCOL > gGenetSimpleNetworkTemplate; > #define GENET_DRIVER_SIGNATURE SIGNATURE_32('G', 'N', > 'E', 'T') > #define GENET_PRIVATE_DATA_FROM_SNP_THIS(a) CR(a, > GENET_PRIVATE_DATA, Snp, GENET_DRIVER_SIGNATURE) > > +#define GENET_RX_BUFFER(g, idx) ((UINT8 > *)(UINTN)(g)->RxBuffer + GENET_MAX_PACKET_SIZE * (idx)) > + > EFI_STATUS > EFIAPI > GenetPhyRead ( > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > index 71c659e7f882..94b578a10aa1 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > @@ -19,6 +19,10 @@ > > #define GENET_PHY_RETRY 1000 > > +STATIC CONST > +EFI_PHYSICAL_ADDRESS mDmaAddressLimit = FixedPcdGet64 > (PcdDmaDeviceLimit) - > + FixedPcdGet64 > (PcdDmaDeviceOffset); > + > /** > Read a memory-mapped device CSR. > > @@ -605,19 +609,17 @@ GenetDmaAlloc ( > IN GENET_PRIVATE_DATA *Genet > ) > { > - EFI_STATUS Status; > - UINTN Idx; > + EFI_STATUS Status; > > - for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { > - Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES > (GENET_MAX_PACKET_SIZE), (VOID **)&Genet->RxBuffer[Idx]); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "%a: Failed to allocate RX buffer: %r\n", > __FUNCTION__, Status)); > - GenetDmaFree (Genet); > - return Status; > - } > + Genet->RxBuffer = mDmaAddressLimit; > + Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, > + EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE * > GENET_DMA_DESC_COUNT), > + &Genet->RxBuffer); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, > + "%a: Failed to allocate RX buffer: %r\n", __FUNCTION__, Status)); > } > - > - return EFI_SUCCESS; > + return Status; > } > > /** > @@ -640,11 +642,11 @@ GenetDmaMapRxDescriptor ( > UINTN DmaNumberOfBytes; > > ASSERT (Genet->RxBufferMap[DescIndex].Mapping == NULL); > - ASSERT (Genet->RxBuffer[DescIndex] != NULL); > + ASSERT (Genet->RxBuffer != 0); > > DmaNumberOfBytes = GENET_MAX_PACKET_SIZE; > Status = DmaMap (MapOperationBusMasterWrite, > - (VOID *)Genet->RxBuffer[DescIndex], > + GENET_RX_BUFFER (Genet, DescIndex), > &DmaNumberOfBytes, > &Genet->RxBufferMap[DescIndex].PhysAddress, > &Genet->RxBufferMap[DescIndex].Mapping); > @@ -697,13 +699,9 @@ GenetDmaFree ( > > for (Idx = 0; Idx < GENET_DMA_DESC_COUNT; Idx++) { > GenetDmaUnmapRxDescriptor (Genet, Idx); > - > - if (Genet->RxBuffer[Idx] != NULL) { > - DmaFreeBuffer (EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE), > - Genet->RxBuffer[Idx]); > - Genet->RxBuffer[Idx] = NULL; > - } > } > + gBS->FreePages (Genet->RxBuffer, > + EFI_SIZE_TO_PAGES (GENET_MAX_PACKET_SIZE * GENET_DMA_DESC_COUNT)); > } > > /** > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > index 72ab55619b0e..9746f210d1f2 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c > @@ -730,7 +730,7 @@ GenetSimpleNetworkReceive ( > > GenetDmaUnmapRxDescriptor (Genet, DescIndex); > > - Frame = Genet->RxBuffer[DescIndex]; > + Frame = GENET_RX_BUFFER (Genet, DescIndex); > > if (FrameLength > 2 + Genet->SnpMode.MediaHeaderSize) { > // Received frame has 2 bytes of padding at the start > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH edk2-platforms v4 5/9] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel ` (3 preceding siblings ...) 2020-05-11 14:55 ` [PATCH edk2-platforms v4 4/9] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA Ard Biesheuvel @ 2020-05-11 14:55 ` Ard Biesheuvel 2020-05-11 16:32 ` Andrei Warkentin 2020-05-11 14:55 ` [PATCH edk2-platforms v4 6/9] Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer Ard Biesheuvel ` (4 subsequent siblings) 9 siblings, 1 reply; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton When the OS takes over the machine, it calls ExitBootServices() in order to shut down all resident services and event notifications so that all asynchronous activity is stopped. At this point, any DMA masters that are still active should be shut down. This is especially important for network controllers, since any activity on the network will trigger DMA writes into memory, which will no longer be reserved for this purpose once the OS takes over. So register for the ExitBootServices event, and shut down the controller at this point if it was started before. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 4 +++ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 35 +++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index 248164249c6e..9b3dc5e62ecf 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -44,6 +44,7 @@ [LibraryClasses] IoLib MemoryAllocationLib NetLib + UefiBootServicesTableLib UefiDriverEntryPoint UefiLib @@ -52,6 +53,9 @@ [Protocols] gEfiDevicePathProtocolGuid ## BY_START gEfiSimpleNetworkProtocolGuid ## BY_START +[Guids] + gEfiEventExitBootServicesGuid + [FixedPcd] gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index ddfbc0806c07..c43bdbe1d6da 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -203,6 +203,7 @@ typedef struct { EFI_HANDLE ControllerHandle; EFI_LOCK Lock; + EFI_EVENT ExitBootServicesEvent; EFI_SIMPLE_NETWORK_PROTOCOL Snp; EFI_SIMPLE_NETWORK_MODE SnpMode; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index dacb3ac7d762..00fbfbc109bb 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -74,6 +74,23 @@ GenetDriverBindingSupported ( return EFI_SUCCESS; } +/** + Callback function to shut down the network device at ExitBootServices + + @param Event Pointer to this event + @param Context Event handler private data + +**/ +STATIC +VOID +EFIAPI +GenetNotifyExitBootServices ( + EFI_EVENT Event, + VOID *Context + ) +{ + GenetDisableTxRx ((GENET_PRIVATE_DATA *)Context); +} /** Starts a device controller or a bus controller. @@ -171,6 +188,17 @@ GenetDriverBindingStart ( CopyMem (&Genet->SnpMode.CurrentAddress, &Genet->Dev->MacAddress, sizeof(EFI_MAC_ADDRESS)); + Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK, + GenetNotifyExitBootServices, Genet, + &gEfiEventExitBootServicesGuid, + &Genet->ExitBootServicesEvent); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, + "GenetDriverBindingStart: failed to register for ExitBootServices event - %r\n", + Status)); + goto FreeDevice; + } + Status = gBS->InstallMultipleProtocolInterfaces (&ControllerHandle, &gEfiSimpleNetworkProtocolGuid, &Genet->Snp, NULL); @@ -182,12 +210,14 @@ GenetDriverBindingStart ( &gBcmGenetPlatformDeviceProtocolGuid, This->DriverBindingHandle, ControllerHandle); - goto FreeDevice; + goto FreeEvent; } Genet->ControllerHandle = ControllerHandle; return EFI_SUCCESS; +FreeEvent: + gBS->CloseEvent (Genet->ExitBootServicesEvent); FreeDevice: DEBUG ((DEBUG_WARN, "%a: Returning %r\n", __FUNCTION__, Status)); FreePool (Genet); @@ -248,6 +278,9 @@ GenetDriverBindingStop ( return Status; } + Status = gBS->CloseEvent (Genet->ExitBootServicesEvent); + ASSERT_EFI_ERROR (Status); + GenetDmaFree (Genet); Status = gBS->CloseProtocol (ControllerHandle, -- 2.17.1 ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 5/9] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() 2020-05-11 14:55 ` [PATCH edk2-platforms v4 5/9] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() Ard Biesheuvel @ 2020-05-11 16:32 ` Andrei Warkentin 0 siblings, 0 replies; 25+ messages in thread From: Andrei Warkentin @ 2020-05-11 16:32 UTC (permalink / raw) To: Ard Biesheuvel, devel@edk2.groups.io Cc: Pete Batard, Jared McNeill, Samer El-Haj-Mahmoud, Jeremy Linton [-- Attachment #1: Type: text/plain, Size: 5312 bytes --] LGTM. I agree that we just need to stop TX/RX. We do not want to reset controller (as that will nuke the programmed-in MAC address). Reviewed-by: Andrei Warkentin <andrey.warkentin@gmail.com> ________________________________ From: Ard Biesheuvel <ard.biesheuvel@arm.com> Sent: Monday, May 11, 2020 9:55 AM To: devel@edk2.groups.io <devel@edk2.groups.io> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Pete Batard <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin <awarkentin@vmware.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton <jeremy.linton@arm.com> Subject: [PATCH edk2-platforms v4 5/9] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() When the OS takes over the machine, it calls ExitBootServices() in order to shut down all resident services and event notifications so that all asynchronous activity is stopped. At this point, any DMA masters that are still active should be shut down. This is especially important for network controllers, since any activity on the network will trigger DMA writes into memory, which will no longer be reserved for this purpose once the OS takes over. So register for the ExitBootServices event, and shut down the controller at this point if it was started before. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 4 +++ Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 35 +++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index 248164249c6e..9b3dc5e62ecf 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -44,6 +44,7 @@ [LibraryClasses] IoLib MemoryAllocationLib NetLib + UefiBootServicesTableLib UefiDriverEntryPoint UefiLib @@ -52,6 +53,9 @@ [Protocols] gEfiDevicePathProtocolGuid ## BY_START gEfiSimpleNetworkProtocolGuid ## BY_START +[Guids] + gEfiEventExitBootServicesGuid + [FixedPcd] gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index ddfbc0806c07..c43bdbe1d6da 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -203,6 +203,7 @@ typedef struct { EFI_HANDLE ControllerHandle; EFI_LOCK Lock; + EFI_EVENT ExitBootServicesEvent; EFI_SIMPLE_NETWORK_PROTOCOL Snp; EFI_SIMPLE_NETWORK_MODE SnpMode; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index dacb3ac7d762..00fbfbc109bb 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -74,6 +74,23 @@ GenetDriverBindingSupported ( return EFI_SUCCESS; } +/** + Callback function to shut down the network device at ExitBootServices + + @param Event Pointer to this event + @param Context Event handler private data + +**/ +STATIC +VOID +EFIAPI +GenetNotifyExitBootServices ( + EFI_EVENT Event, + VOID *Context + ) +{ + GenetDisableTxRx ((GENET_PRIVATE_DATA *)Context); +} /** Starts a device controller or a bus controller. @@ -171,6 +188,17 @@ GenetDriverBindingStart ( CopyMem (&Genet->SnpMode.CurrentAddress, &Genet->Dev->MacAddress, sizeof(EFI_MAC_ADDRESS)); + Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK, + GenetNotifyExitBootServices, Genet, + &gEfiEventExitBootServicesGuid, + &Genet->ExitBootServicesEvent); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, + "GenetDriverBindingStart: failed to register for ExitBootServices event - %r\n", + Status)); + goto FreeDevice; + } + Status = gBS->InstallMultipleProtocolInterfaces (&ControllerHandle, &gEfiSimpleNetworkProtocolGuid, &Genet->Snp, NULL); @@ -182,12 +210,14 @@ GenetDriverBindingStart ( &gBcmGenetPlatformDeviceProtocolGuid, This->DriverBindingHandle, ControllerHandle); - goto FreeDevice; + goto FreeEvent; } Genet->ControllerHandle = ControllerHandle; return EFI_SUCCESS; +FreeEvent: + gBS->CloseEvent (Genet->ExitBootServicesEvent); FreeDevice: DEBUG ((DEBUG_WARN, "%a: Returning %r\n", __FUNCTION__, Status)); FreePool (Genet); @@ -248,6 +278,9 @@ GenetDriverBindingStop ( return Status; } + Status = gBS->CloseEvent (Genet->ExitBootServicesEvent); + ASSERT_EFI_ERROR (Status); + GenetDmaFree (Genet); Status = gBS->CloseProtocol (ControllerHandle, -- 2.17.1 [-- Attachment #2: Type: text/html, Size: 9357 bytes --] ^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH edk2-platforms v4 6/9] Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel ` (4 preceding siblings ...) 2020-05-11 14:55 ` [PATCH edk2-platforms v4 5/9] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() Ard Biesheuvel @ 2020-05-11 14:55 ` Ard Biesheuvel 2020-05-11 16:19 ` Andrei Warkentin 2020-05-11 14:55 ` [PATCH edk2-platforms v4 7/9] Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering Ard Biesheuvel ` (3 subsequent siblings) 9 siblings, 1 reply; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton The DMA api requires that DMA mappings are kept in place during the time the device may access the memory. This may not matter for the way GENET is used on the RPi4, but it could break bounce buffering on platforms that impose DMA memory limits, since the bounce buffer may have been reused by the time the device gets to look at the data. So defer the DmaUnmap() of TX buffers to the point where they are recycled and returned to the caller. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 5 +---- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index c43bdbe1d6da..16890f723cb2 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -213,6 +213,7 @@ typedef struct { GENERIC_PHY_PRIVATE_DATA Phy; UINT8 *TxBuffer[GENET_DMA_DESC_COUNT]; + VOID *TxBufferMap[GENET_DMA_DESC_COUNT]; UINT8 TxQueued; UINT16 TxNext; UINT16 TxConsIndex; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index 94b578a10aa1..35a3c7abdf1e 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -760,6 +760,7 @@ GenetTxIntr ( Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; if (Genet->TxQueued > 0 && Total > 0) { + DmaUnmap (Genet->TxBufferMap[Genet->TxNext]); *TxBuf = Genet->TxBuffer[Genet->TxNext]; Genet->TxQueued--; Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c index 9746f210d1f2..b2cae687b3d4 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c @@ -559,7 +559,6 @@ GenetSimpleNetworkTransmit ( UINT8 Desc; PHYSICAL_ADDRESS DmaDeviceAddress; UINTN DmaNumberOfBytes; - VOID *DmaMapping; if (This == NULL || Buffer == NULL) { DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or buffer)\n", @@ -631,7 +630,7 @@ GenetSimpleNetworkTransmit ( (VOID *)(UINTN)Frame, &DmaNumberOfBytes, &DmaDeviceAddress, - &DmaMapping); + &Genet->TxBufferMap[Desc]); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: DmaMap failed: %r\n", __FUNCTION__, Status)); EfiReleaseLock (&Genet->Lock); @@ -643,8 +642,6 @@ GenetSimpleNetworkTransmit ( Genet->TxProdIndex = (Genet->TxProdIndex + 1) % 0xFFFF; Genet->TxQueued++; - DmaUnmap (DmaMapping); - EfiReleaseLock (&Genet->Lock); return EFI_SUCCESS; -- 2.17.1 ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 6/9] Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer 2020-05-11 14:55 ` [PATCH edk2-platforms v4 6/9] Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer Ard Biesheuvel @ 2020-05-11 16:19 ` Andrei Warkentin 0 siblings, 0 replies; 25+ messages in thread From: Andrei Warkentin @ 2020-05-11 16:19 UTC (permalink / raw) To: Ard Biesheuvel, devel@edk2.groups.io Cc: Pete Batard, Jared McNeill, Samer El-Haj-Mahmoud, Jeremy Linton [-- Attachment #1: Type: text/plain, Size: 4076 bytes --] Yeah if this code ever runs on a system with some kind of SMMU, definitely want the fix. (could we mention SMMU as a reason for why mappings must be valid during hw access?) Reviewed-by: Andrei Warkentin <andrey.warkentin@gmail.com> ________________________________ From: Ard Biesheuvel <ard.biesheuvel@arm.com> Sent: Monday, May 11, 2020 9:55 AM To: devel@edk2.groups.io <devel@edk2.groups.io> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Pete Batard <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin <awarkentin@vmware.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton <jeremy.linton@arm.com> Subject: [PATCH edk2-platforms v4 6/9] Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer The DMA api requires that DMA mappings are kept in place during the time the device may access the memory. This may not matter for the way GENET is used on the RPi4, but it could break bounce buffering on platforms that impose DMA memory limits, since the bounce buffer may have been reused by the time the device gets to look at the data. So defer the DmaUnmap() of TX buffers to the point where they are recycled and returned to the caller. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 5 +---- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h index c43bdbe1d6da..16890f723cb2 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.h @@ -213,6 +213,7 @@ typedef struct { GENERIC_PHY_PRIVATE_DATA Phy; UINT8 *TxBuffer[GENET_DMA_DESC_COUNT]; + VOID *TxBufferMap[GENET_DMA_DESC_COUNT]; UINT8 TxQueued; UINT16 TxNext; UINT16 TxConsIndex; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index 94b578a10aa1..35a3c7abdf1e 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -760,6 +760,7 @@ GenetTxIntr ( Total = (ConsIndex - Genet->TxConsIndex) & 0xFFFF; if (Genet->TxQueued > 0 && Total > 0) { + DmaUnmap (Genet->TxBufferMap[Genet->TxNext]); *TxBuf = Genet->TxBuffer[Genet->TxNext]; Genet->TxQueued--; Genet->TxNext = (Genet->TxNext + 1) % GENET_DMA_DESC_COUNT; diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c index 9746f210d1f2..b2cae687b3d4 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c @@ -559,7 +559,6 @@ GenetSimpleNetworkTransmit ( UINT8 Desc; PHYSICAL_ADDRESS DmaDeviceAddress; UINTN DmaNumberOfBytes; - VOID *DmaMapping; if (This == NULL || Buffer == NULL) { DEBUG ((DEBUG_ERROR, "%a: Invalid parameter (missing handle or buffer)\n", @@ -631,7 +630,7 @@ GenetSimpleNetworkTransmit ( (VOID *)(UINTN)Frame, &DmaNumberOfBytes, &DmaDeviceAddress, - &DmaMapping); + &Genet->TxBufferMap[Desc]); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: DmaMap failed: %r\n", __FUNCTION__, Status)); EfiReleaseLock (&Genet->Lock); @@ -643,8 +642,6 @@ GenetSimpleNetworkTransmit ( Genet->TxProdIndex = (Genet->TxProdIndex + 1) % 0xFFFF; Genet->TxQueued++; - DmaUnmap (DmaMapping); - EfiReleaseLock (&Genet->Lock); return EFI_SUCCESS; -- 2.17.1 [-- Attachment #2: Type: text/html, Size: 7527 bytes --] ^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH edk2-platforms v4 7/9] Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel ` (5 preceding siblings ...) 2020-05-11 14:55 ` [PATCH edk2-platforms v4 6/9] Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer Ard Biesheuvel @ 2020-05-11 14:55 ` Ard Biesheuvel 2020-05-11 16:55 ` [edk2-devel] " Andrei Warkentin 2020-05-11 21:11 ` Philippe Mathieu-Daudé 2020-05-11 14:55 ` [PATCH edk2-platforms v4 8/9] Silicon/Broadcom/BcmGenetDxe: add unload support Ard Biesheuvel ` (2 subsequent siblings) 9 siblings, 2 replies; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton ARM synchronization barriers can be used to stall execution and wait for cache or TLB maintenance to complete. TLB maintenance is irrelevant in the context of the GENET driver, but cache maintenance is important for non-cache coherent DMA, and synchronization barriers are needed to ensure that outgoing data is cleaned before starting DMA for TX frames. However, this cache maintenance is already taken care of by the cache maintenance routines, and so all we need to do in our I/O routines is ensure that MMIO writes are issued in the right order, and for this, an ordinary MemoryFence () is sufficient. This means we don't need to depend on ArmLib either. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 2 -- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 1 - Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 3 +-- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index 9b3dc5e62ecf..e3e4ebbddb93 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -27,7 +27,6 @@ [Sources] SimpleNetwork.c [Packages] - ArmPkg/ArmPkg.dec EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec @@ -35,7 +34,6 @@ [Packages] Silicon/Broadcom/Drivers/Net/BcmNet.dec [LibraryClasses] - ArmLib BaseLib BaseMemoryLib DebugLib diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index 00fbfbc109bb..630a92ef210b 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -9,7 +9,6 @@ **/ -#include <Library/ArmLib.h> #include <Library/DebugLib.h> #include <Library/IoLib.h> #include <Library/MemoryAllocationLib.h> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index 35a3c7abdf1e..e3ce8614aeb2 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -8,7 +8,6 @@ #include "GenetUtil.h" -#include <Library/ArmLib.h> #include <Library/DmaLib.h> #include <Library/IoLib.h> #include <Library/UefiBootServicesTableLib.h> @@ -64,7 +63,7 @@ GenetMmioWrite ( { ASSERT ((Offset & 3) == 0); - ArmDataSynchronizationBarrier (); + MemoryFence (); MmioWrite32 (Genet->RegBase + Offset, Data); } -- 2.17.1 ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH edk2-platforms v4 7/9] Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering 2020-05-11 14:55 ` [PATCH edk2-platforms v4 7/9] Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering Ard Biesheuvel @ 2020-05-11 16:55 ` Andrei Warkentin 2020-05-11 21:11 ` Philippe Mathieu-Daudé 1 sibling, 0 replies; 25+ messages in thread From: Andrei Warkentin @ 2020-05-11 16:55 UTC (permalink / raw) To: devel@edk2.groups.io, ard.biesheuvel@arm.com Cc: Pete Batard, Jared McNeill, Samer El-Haj-Mahmoud, Jeremy Linton [-- Attachment #1: Type: text/plain, Size: 3421 bytes --] Reviewed-by: Andrei Warkentin <andrey.warkentin@gmail.com> ________________________________ From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of Ard Biesheuvel via groups.io <ard.biesheuvel=arm.com@groups.io> Sent: Monday, May 11, 2020 9:55 AM To: devel@edk2.groups.io <devel@edk2.groups.io> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Pete Batard <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin <awarkentin@vmware.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton <jeremy.linton@arm.com> Subject: [edk2-devel] [PATCH edk2-platforms v4 7/9] Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering ARM synchronization barriers can be used to stall execution and wait for cache or TLB maintenance to complete. TLB maintenance is irrelevant in the context of the GENET driver, but cache maintenance is important for non-cache coherent DMA, and synchronization barriers are needed to ensure that outgoing data is cleaned before starting DMA for TX frames. However, this cache maintenance is already taken care of by the cache maintenance routines, and so all we need to do in our I/O routines is ensure that MMIO writes are issued in the right order, and for this, an ordinary MemoryFence () is sufficient. This means we don't need to depend on ArmLib either. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 2 -- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 1 - Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 3 +-- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index 9b3dc5e62ecf..e3e4ebbddb93 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -27,7 +27,6 @@ [Sources] SimpleNetwork.c [Packages] - ArmPkg/ArmPkg.dec EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec @@ -35,7 +34,6 @@ [Packages] Silicon/Broadcom/Drivers/Net/BcmNet.dec [LibraryClasses] - ArmLib BaseLib BaseMemoryLib DebugLib diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index 00fbfbc109bb..630a92ef210b 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -9,7 +9,6 @@ **/ -#include <Library/ArmLib.h> #include <Library/DebugLib.h> #include <Library/IoLib.h> #include <Library/MemoryAllocationLib.h> diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c index 35a3c7abdf1e..e3ce8614aeb2 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c @@ -8,7 +8,6 @@ #include "GenetUtil.h" -#include <Library/ArmLib.h> #include <Library/DmaLib.h> #include <Library/IoLib.h> #include <Library/UefiBootServicesTableLib.h> @@ -64,7 +63,7 @@ GenetMmioWrite ( { ASSERT ((Offset & 3) == 0); - ArmDataSynchronizationBarrier (); + MemoryFence (); MmioWrite32 (Genet->RegBase + Offset, Data); } -- 2.17.1 [-- Attachment #2: Type: text/html, Size: 4993 bytes --] ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH edk2-platforms v4 7/9] Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering 2020-05-11 14:55 ` [PATCH edk2-platforms v4 7/9] Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering Ard Biesheuvel 2020-05-11 16:55 ` [edk2-devel] " Andrei Warkentin @ 2020-05-11 21:11 ` Philippe Mathieu-Daudé 1 sibling, 0 replies; 25+ messages in thread From: Philippe Mathieu-Daudé @ 2020-05-11 21:11 UTC (permalink / raw) To: devel, ard.biesheuvel Cc: Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton On 5/11/20 4:55 PM, Ard Biesheuvel wrote: > ARM synchronization barriers can be used to stall execution and wait > for cache or TLB maintenance to complete. TLB maintenance is irrelevant > in the context of the GENET driver, but cache maintenance is important > for non-cache coherent DMA, and synchronization barriers are needed to > ensure that outgoing data is cleaned before starting DMA for TX frames. > > However, this cache maintenance is already taken care of by the cache > maintenance routines, and so all we need to do in our I/O routines is > ensure that MMIO writes are issued in the right order, and for this, > an ordinary MemoryFence () is sufficient. > > This means we don't need to depend on ArmLib either. > > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com> > --- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 2 -- > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 1 - > Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 3 +-- > 3 files changed, 1 insertion(+), 5 deletions(-) > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > index 9b3dc5e62ecf..e3e4ebbddb93 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf > @@ -27,7 +27,6 @@ [Sources] > SimpleNetwork.c > > [Packages] > - ArmPkg/ArmPkg.dec > EmbeddedPkg/EmbeddedPkg.dec > MdeModulePkg/MdeModulePkg.dec > MdePkg/MdePkg.dec > @@ -35,7 +34,6 @@ [Packages] > Silicon/Broadcom/Drivers/Net/BcmNet.dec > > [LibraryClasses] > - ArmLib > BaseLib > BaseMemoryLib > DebugLib > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > index 00fbfbc109bb..630a92ef210b 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c > @@ -9,7 +9,6 @@ > > **/ > > -#include <Library/ArmLib.h> > #include <Library/DebugLib.h> > #include <Library/IoLib.h> > #include <Library/MemoryAllocationLib.h> > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > index 35a3c7abdf1e..e3ce8614aeb2 100644 > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c > @@ -8,7 +8,6 @@ > > #include "GenetUtil.h" > > -#include <Library/ArmLib.h> > #include <Library/DmaLib.h> > #include <Library/IoLib.h> > #include <Library/UefiBootServicesTableLib.h> > @@ -64,7 +63,7 @@ GenetMmioWrite ( > { > ASSERT ((Offset & 3) == 0); > > - ArmDataSynchronizationBarrier (); > + MemoryFence (); > MmioWrite32 (Genet->RegBase + Offset, Data); > } > > ^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH edk2-platforms v4 8/9] Silicon/Broadcom/BcmGenetDxe: add unload support 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel ` (6 preceding siblings ...) 2020-05-11 14:55 ` [PATCH edk2-platforms v4 7/9] Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering Ard Biesheuvel @ 2020-05-11 14:55 ` Ard Biesheuvel 2020-05-11 16:17 ` Andrei Warkentin 2020-05-11 14:55 ` [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX 88772b driver Ard Biesheuvel 2020-05-11 23:20 ` [PATCH edk2-platforms v4 0/9] BCM genet fixes Jeremy Linton 9 siblings, 1 reply; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton Add unload support to the GENET driver Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 60 ++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index e3e4ebbddb93..3e98983c6b07 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -16,6 +16,7 @@ [Defines] MODULE_TYPE = UEFI_DRIVER VERSION_STRING = 1.0 ENTRY_POINT = GenetEntryPoint + UNLOAD_IMAGE = GenetUnload [Sources] ComponentName.c diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index 630a92ef210b..238b336d55f6 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -340,3 +340,63 @@ GenetEntryPoint ( return EFI_SUCCESS; } + +/** + Unload function of GENET UEFI Driver. + + @param ImageHandle The allocated handle for the EFI image + + @retval EFI_SUCCESS The driver was unloaded successfully + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + +**/ +EFI_STATUS +EFIAPI +GenetUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN HandleCount; + UINTN Index; + + // + // Retrieve all USB I/O handles in the handle database + // + Status = gBS->LocateHandleBuffer (ByProtocol, + &gBcmGenetPlatformDeviceProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Disconnect the driver from the handles in the handle database + // + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->DisconnectController (HandleBuffer[Index], + gImageHandle, + NULL); + } + + // + // Free the handle array + // + gBS->FreePool (HandleBuffer); + + // + // Uninstall protocols installed by the driver in its entrypoint + // + Status = EfiLibUninstallDriverBindingComponentName2 ( + &mGenetDriverBinding, + &gGenetComponentName, + &gGenetComponentName2 + ); + + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} -- 2.17.1 ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 8/9] Silicon/Broadcom/BcmGenetDxe: add unload support 2020-05-11 14:55 ` [PATCH edk2-platforms v4 8/9] Silicon/Broadcom/BcmGenetDxe: add unload support Ard Biesheuvel @ 2020-05-11 16:17 ` Andrei Warkentin 0 siblings, 0 replies; 25+ messages in thread From: Andrei Warkentin @ 2020-05-11 16:17 UTC (permalink / raw) To: Ard Biesheuvel, devel@edk2.groups.io Cc: Pete Batard, Jared McNeill, Samer El-Haj-Mahmoud, Jeremy Linton [-- Attachment #1: Type: text/plain, Size: 3475 bytes --] Hi Ard, Can DisconnectController fail? Should this check for that? Other than that and the USB comment, looks fine... A ________________________________ From: Ard Biesheuvel <ard.biesheuvel@arm.com> Sent: Monday, May 11, 2020 9:55 AM To: devel@edk2.groups.io <devel@edk2.groups.io> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Pete Batard <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin <awarkentin@vmware.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton <jeremy.linton@arm.com> Subject: [PATCH edk2-platforms v4 8/9] Silicon/Broadcom/BcmGenetDxe: add unload support Add unload support to the GENET driver Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 1 + Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c | 60 ++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf index e3e4ebbddb93..3e98983c6b07 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf @@ -16,6 +16,7 @@ [Defines] MODULE_TYPE = UEFI_DRIVER VERSION_STRING = 1.0 ENTRY_POINT = GenetEntryPoint + UNLOAD_IMAGE = GenetUnload [Sources] ComponentName.c diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c index 630a92ef210b..238b336d55f6 100644 --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/DriverBinding.c @@ -340,3 +340,63 @@ GenetEntryPoint ( return EFI_SUCCESS; } + +/** + Unload function of GENET UEFI Driver. + + @param ImageHandle The allocated handle for the EFI image + + @retval EFI_SUCCESS The driver was unloaded successfully + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + +**/ +EFI_STATUS +EFIAPI +GenetUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN HandleCount; + UINTN Index; + + // + // Retrieve all USB I/O handles in the handle database + // + Status = gBS->LocateHandleBuffer (ByProtocol, + &gBcmGenetPlatformDeviceProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Disconnect the driver from the handles in the handle database + // + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->DisconnectController (HandleBuffer[Index], + gImageHandle, + NULL); + } + + // + // Free the handle array + // + gBS->FreePool (HandleBuffer); + + // + // Uninstall protocols installed by the driver in its entrypoint + // + Status = EfiLibUninstallDriverBindingComponentName2 ( + &mGenetDriverBinding, + &gGenetComponentName, + &gGenetComponentName2 + ); + + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} -- 2.17.1 [-- Attachment #2: Type: text/html, Size: 7795 bytes --] ^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX 88772b driver 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel ` (7 preceding siblings ...) 2020-05-11 14:55 ` [PATCH edk2-platforms v4 8/9] Silicon/Broadcom/BcmGenetDxe: add unload support Ard Biesheuvel @ 2020-05-11 14:55 ` Ard Biesheuvel 2020-05-11 16:06 ` Andrei Warkentin 2020-05-11 16:24 ` Samer El-Haj-Mahmoud 2020-05-11 23:20 ` [PATCH edk2-platforms v4 0/9] BCM genet fixes Jeremy Linton 9 siblings, 2 replies; 25+ messages in thread From: Ard Biesheuvel @ 2020-05-11 14:55 UTC (permalink / raw) To: devel Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud, Jeremy Linton The Raspberry Pi4 has gigabit ethernet builtin, for which we now have a UEFI driver. So no need for the ASIX 88772b driver. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Platform/RaspberryPi/RPi4/RPi4.dsc | 1 - Platform/RaspberryPi/RPi4/RPi4.fdf | 1 - 2 files changed, 2 deletions(-) diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4/RPi4.dsc index 5910082deb04..cbff9d9946e2 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -669,7 +669,6 @@ [Components.common] MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf - Drivers/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf # # SD/MMC support diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf b/Platform/RaspberryPi/RPi4/RPi4.fdf index b1f7aa2387df..1e13909a57ba 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.fdf +++ b/Platform/RaspberryPi/RPi4/RPi4.fdf @@ -293,7 +293,6 @@ [FV.FvMain] INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf - INF Drivers/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf # # SD/MMC support -- 2.17.1 ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX 88772b driver 2020-05-11 14:55 ` [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX 88772b driver Ard Biesheuvel @ 2020-05-11 16:06 ` Andrei Warkentin 2020-05-11 16:24 ` Samer El-Haj-Mahmoud 1 sibling, 0 replies; 25+ messages in thread From: Andrei Warkentin @ 2020-05-11 16:06 UTC (permalink / raw) To: Ard Biesheuvel, devel@edk2.groups.io Cc: Pete Batard, Jared McNeill, Samer El-Haj-Mahmoud, Jeremy Linton [-- Attachment #1: Type: text/plain, Size: 1926 bytes --] LGTM Reviewed-by: Andrei Warkentin <andrey.warkentin@gmail.com> ________________________________ From: Ard Biesheuvel <ard.biesheuvel@arm.com> Sent: Monday, May 11, 2020 9:55 AM To: devel@edk2.groups.io <devel@edk2.groups.io> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Pete Batard <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin <awarkentin@vmware.com>; Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton <jeremy.linton@arm.com> Subject: [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX 88772b driver The Raspberry Pi4 has gigabit ethernet builtin, for which we now have a UEFI driver. So no need for the ASIX 88772b driver. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> --- Platform/RaspberryPi/RPi4/RPi4.dsc | 1 - Platform/RaspberryPi/RPi4/RPi4.fdf | 1 - 2 files changed, 2 deletions(-) diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4/RPi4.dsc index 5910082deb04..cbff9d9946e2 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -669,7 +669,6 @@ [Components.common] MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf - Drivers/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf # # SD/MMC support diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf b/Platform/RaspberryPi/RPi4/RPi4.fdf index b1f7aa2387df..1e13909a57ba 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.fdf +++ b/Platform/RaspberryPi/RPi4/RPi4.fdf @@ -293,7 +293,6 @@ [FV.FvMain] INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf - INF Drivers/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf # # SD/MMC support -- 2.17.1 [-- Attachment #2: Type: text/html, Size: 3212 bytes --] ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX 88772b driver 2020-05-11 14:55 ` [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX 88772b driver Ard Biesheuvel 2020-05-11 16:06 ` Andrei Warkentin @ 2020-05-11 16:24 ` Samer El-Haj-Mahmoud 1 sibling, 0 replies; 25+ messages in thread From: Samer El-Haj-Mahmoud @ 2020-05-11 16:24 UTC (permalink / raw) To: Ard Biesheuvel, devel@edk2.groups.io Cc: Ard Biesheuvel, Pete Batard, Jared McNeill, Andrei Warkentin (awarkentin@vmware.com), Jeremy Linton, Samer El-Haj-Mahmoud Reviewed-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com> > -----Original Message----- > From: Ard Biesheuvel <ard.biesheuvel@arm.com> > Sent: Monday, May 11, 2020 10:55 AM > To: devel@edk2.groups.io > Cc: Ard Biesheuvel <Ard.Biesheuvel@arm.com>; Pete Batard > <pete@akeo.ie>; Jared McNeill <jmcneill@invisible.ca>; Andrei Warkentin > (awarkentin@vmware.com) <awarkentin@vmware.com>; Samer El-Haj- > Mahmoud <Samer.El-Haj-Mahmoud@arm.com>; Jeremy Linton > <Jeremy.Linton@arm.com> > Subject: [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX > 88772b driver > > The Raspberry Pi4 has gigabit ethernet builtin, for which we now have a UEFI > driver. So no need for the ASIX 88772b driver. > > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> > --- > Platform/RaspberryPi/RPi4/RPi4.dsc | 1 - > Platform/RaspberryPi/RPi4/RPi4.fdf | 1 - > 2 files changed, 2 deletions(-) > > diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc > b/Platform/RaspberryPi/RPi4/RPi4.dsc > index 5910082deb04..cbff9d9946e2 100644 > --- a/Platform/RaspberryPi/RPi4/RPi4.dsc > +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc > @@ -669,7 +669,6 @@ [Components.common] > MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf > MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf > MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf > - Drivers/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf > > # > # SD/MMC support > diff --git a/Platform/RaspberryPi/RPi4/RPi4.fdf > b/Platform/RaspberryPi/RPi4/RPi4.fdf > index b1f7aa2387df..1e13909a57ba 100644 > --- a/Platform/RaspberryPi/RPi4/RPi4.fdf > +++ b/Platform/RaspberryPi/RPi4/RPi4.fdf > @@ -293,7 +293,6 @@ [FV.FvMain] > INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf > INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf > INF > MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf > - INF > Drivers/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf > > # > # SD/MMC support > -- > 2.17.1 IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH edk2-platforms v4 0/9] BCM genet fixes 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel ` (8 preceding siblings ...) 2020-05-11 14:55 ` [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX 88772b driver Ard Biesheuvel @ 2020-05-11 23:20 ` Jeremy Linton 9 siblings, 0 replies; 25+ messages in thread From: Jeremy Linton @ 2020-05-11 23:20 UTC (permalink / raw) To: Ard Biesheuvel, devel Cc: Pete Batard, Jared McNeill, Andrei Warkentin, Samer El-Haj-Mahmoud Hi, Well it looks like you fixed the tx map/unmap issue I noticed yesterday on discord as well as a couple other things that were discussed. So with the fix 2/9, Reviewed-by: Jeremy Linton <jeremy.linton@arm.com> Thanks, On 5/11/20 9:55 AM, Ard Biesheuvel wrote: > This fixes the multicast/broadcast/promisc handling, and switches to > ordinary page allocations for RX buffers. Patch #1 is cosmetic only. > > Note that these apply on top of the series sent out by Samer, and is > intended to be squashed into that series before merging. > > Changes since v3: > - more cosmetic tweaks in #1 > - move DmaUnmap() for TX buffers to the correct place > - use MemoryFence() instead of DSB for MMIO write ordering > - add unload support to the driver > - remove the Ax88772b driver from the RPi4 build - it is no longer needed, > and misbehaves when no cable is connected. > > Changes since v2: > - fix MDF filter handling (fixes issue reported by Samer) > - add patch to deal with ExitBootServices() so we don't leave the RX DMA > ring running when we enter the OS > > https://github.com/pftf/edk2-platforms/tree/rpi4_genet_v4_ardb > > Cc: Pete Batard <pete@akeo.ie> > Cc: Jared McNeill <jmcneill@invisible.ca> > Cc: Andrei Warkentin <awarkentin@vmware.com> > Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com> > Cc: Jeremy Linton <jeremy.linton@arm.com> > > Ard Biesheuvel (9): > Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup > Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering > Silicon/Broadcom/BcmGenetDxe: fix multicast/broadcast handling > Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA > Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() > Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA > transfer > Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write > ordering > Silicon/Broadcom/BcmGenetDxe: add unload support > Platform/RaspberryPi4: remove ASIX 88772b driver > > Platform/RaspberryPi/RPi4/RPi4.dsc | 1 - > Platform/RaspberryPi/RPi4/RPi4.fdf | 1 - > .../Drivers/Net/BcmGenetDxe/BcmGenetDxe.inf | 13 +- > .../Drivers/Net/BcmGenetDxe/GenetUtil.h | 51 +- > .../Drivers/Net/BcmGenetDxe/DriverBinding.c | 122 ++- > .../Drivers/Net/BcmGenetDxe/GenericPhy.c | 16 +- > .../Drivers/Net/BcmGenetDxe/GenetUtil.c | 787 +++++++++--------- > .../Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 115 ++- > 8 files changed, 621 insertions(+), 485 deletions(-) > ^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2020-05-11 23:20 UTC | newest] Thread overview: 25+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-05-11 14:55 [PATCH edk2-platforms v4 0/9] BCM genet fixes Ard Biesheuvel 2020-05-11 14:55 ` [PATCH edk2-platforms v4 1/9] Silicon/Broadcom/BcmGenetDxe: whitespace/cosmetic cleanup Ard Biesheuvel 2020-05-11 16:36 ` Samer El-Haj-Mahmoud 2020-05-11 21:14 ` [edk2-devel] " Philippe Mathieu-Daudé 2020-05-11 14:55 ` [PATCH edk2-platforms v4 2/9] Silicon/Broadcom/BcmGenetDxe: add support for broadcast filtering Ard Biesheuvel 2020-05-11 16:44 ` Andrei Warkentin 2020-05-11 20:34 ` Jeremy Linton 2020-05-11 21:21 ` Ard Biesheuvel 2020-05-11 14:55 ` [PATCH edk2-platforms v4 3/9] Silicon/Broadcom/BcmGenetDxe: fix multicast/broadcast handling Ard Biesheuvel 2020-05-11 14:55 ` [PATCH edk2-platforms v4 4/9] Silicon/Broadcom/BcmGenetDxe: avoid uncached memory for streaming DMA Ard Biesheuvel 2020-05-11 16:42 ` Andrei Warkentin 2020-05-11 16:53 ` Ard Biesheuvel 2020-05-11 14:55 ` [PATCH edk2-platforms v4 5/9] Silicon/Broadcom/BcmGenetDxe: shut down devices on ExitBootServices() Ard Biesheuvel 2020-05-11 16:32 ` Andrei Warkentin 2020-05-11 14:55 ` [PATCH edk2-platforms v4 6/9] Silicon/Broadcom/BcmGenetDxe: keep TX buffer mapped during DMA transfer Ard Biesheuvel 2020-05-11 16:19 ` Andrei Warkentin 2020-05-11 14:55 ` [PATCH edk2-platforms v4 7/9] Silicon/Broadcom/BcmGenetDxe: use MemoryFence() for MMIO write ordering Ard Biesheuvel 2020-05-11 16:55 ` [edk2-devel] " Andrei Warkentin 2020-05-11 21:11 ` Philippe Mathieu-Daudé 2020-05-11 14:55 ` [PATCH edk2-platforms v4 8/9] Silicon/Broadcom/BcmGenetDxe: add unload support Ard Biesheuvel 2020-05-11 16:17 ` Andrei Warkentin 2020-05-11 14:55 ` [PATCH edk2-platforms v4 9/9] Platform/RaspberryPi4: remove ASIX 88772b driver Ard Biesheuvel 2020-05-11 16:06 ` Andrei Warkentin 2020-05-11 16:24 ` Samer El-Haj-Mahmoud 2020-05-11 23:20 ` [PATCH edk2-platforms v4 0/9] BCM genet fixes Jeremy Linton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox