]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.c
EmbeddedPkg: remove Lan9118 network controller driver
[mirror_edk2.git] / EmbeddedPkg / Drivers / Lan9118Dxe / Lan9118Dxe.c
diff --git a/EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.c b/EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.c
deleted file mode 100644 (file)
index 2138f75..0000000
+++ /dev/null
@@ -1,1532 +0,0 @@
-/** @file\r
-*\r
-*  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
-*\r
-*  SPDX-License-Identifier: BSD-2-Clause-Patent\r
-*\r
-**/\r
-\r
-#include "Lan9118Dxe.h"\r
-\r
-typedef struct {\r
-  MAC_ADDR_DEVICE_PATH      Lan9118;\r
-  EFI_DEVICE_PATH_PROTOCOL  End;\r
-} LAN9118_DEVICE_PATH;\r
-\r
-LAN9118_DEVICE_PATH Lan9118PathTemplate =  {\r
-  {\r
-    {\r
-      MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP,\r
-      { (UINT8) (sizeof(MAC_ADDR_DEVICE_PATH)), (UINT8) ((sizeof(MAC_ADDR_DEVICE_PATH)) >> 8) }\r
-    },\r
-    { { 0 } },\r
-    0\r
-  },\r
-  {\r
-    END_DEVICE_PATH_TYPE,\r
-    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-    { sizeof(EFI_DEVICE_PATH_PROTOCOL), 0 }\r
-  }\r
-};\r
-\r
-/*\r
-**  Entry point for the LAN9118 driver\r
-**\r
-*/\r
-EFI_STATUS\r
-EFIAPI\r
-Lan9118DxeEntry (\r
-  IN EFI_HANDLE Handle,\r
-  IN EFI_SYSTEM_TABLE *SystemTable\r
-  )\r
-{\r
-  EFI_STATUS                   Status;\r
-  LAN9118_DRIVER              *LanDriver;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
-  EFI_SIMPLE_NETWORK_MODE     *SnpMode;\r
-  LAN9118_DEVICE_PATH         *Lan9118Path;\r
-  EFI_HANDLE                   ControllerHandle;\r
-\r
-  // The PcdLan9118DxeBaseAddress PCD must be defined\r
-  ASSERT (PcdGet32 (PcdLan9118DxeBaseAddress) != 0);\r
-\r
-  // Allocate Resources\r
-  LanDriver = AllocateZeroPool (sizeof (LAN9118_DRIVER));\r
-  if (LanDriver == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  Lan9118Path = (LAN9118_DEVICE_PATH*)AllocateCopyPool (sizeof (LAN9118_DEVICE_PATH), &Lan9118PathTemplate);\r
-  if (Lan9118Path == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  // Initialize pointers\r
-  Snp = &(LanDriver->Snp);\r
-  SnpMode = &(LanDriver->SnpMode);\r
-  Snp->Mode = SnpMode;\r
-\r
-  // Set the signature of the LAN Driver structure\r
-  LanDriver->Signature = LAN9118_SIGNATURE;\r
-\r
-  // Assign fields and func pointers\r
-  Snp->Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION;\r
-  Snp->WaitForPacket = NULL;\r
-  Snp->Initialize = SnpInitialize;\r
-  Snp->Start = SnpStart;\r
-  Snp->Stop = SnpStop;\r
-  Snp->Reset = SnpReset;\r
-  Snp->Shutdown = SnpShutdown;\r
-  Snp->ReceiveFilters = SnpReceiveFilters;\r
-  Snp->StationAddress = SnpStationAddress;\r
-  Snp->Statistics = SnpStatistics;\r
-  Snp->MCastIpToMac = SnpMcastIptoMac;\r
-  Snp->NvData = SnpNvData;\r
-  Snp->GetStatus = SnpGetStatus;\r
-  Snp->Transmit = SnpTransmit;\r
-  Snp->Receive = SnpReceive;\r
-\r
-  // Start completing simple network mode structure\r
-  SnpMode->State = EfiSimpleNetworkStopped;\r
-  SnpMode->HwAddressSize = NET_ETHER_ADDR_LEN; // HW address is 6 bytes\r
-  SnpMode->MediaHeaderSize = sizeof(ETHER_HEAD); // Not sure of this\r
-  SnpMode->MaxPacketSize = EFI_PAGE_SIZE; // Preamble + SOF + Ether Frame (with VLAN tag +4bytes)\r
-  SnpMode->NvRamSize = 0;           // No NVRAM with this device\r
-  SnpMode->NvRamAccessSize = 0; // No NVRAM with this device\r
-\r
-  //\r
-  // Claim that all receive filter settings are supported, though the MULTICAST mode\r
-  // is not completely supported. The LAN9118 Ethernet controller is only able to\r
-  // do a "hash filtering" and not a perfect filtering on multicast addresses. The\r
-  // controller does not filter the multicast addresses directly but a hash value\r
-  // of them. The hash value of a multicast address is derived from its CRC and\r
-  // ranges from 0 to 63 included.\r
-  // We claim that the perfect MULTICAST filtering mode is supported because\r
-  // we do not want the user to switch directly to the PROMISCOUS_MULTICAST mode\r
-  // and thus not being able to take advantage of the hash filtering.\r
-  //\r
-  SnpMode->ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST              |\r
-                               EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST            |\r
-                               EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST            |\r
-                               EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS          |\r
-                               EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;\r
-\r
-  // We do not intend to receive anything for the time being.\r
-  SnpMode->ReceiveFilterSetting = 0;\r
-\r
-  // LAN9118 has 64bit hash table, can filter 64 MCast MAC Addresses\r
-  SnpMode->MaxMCastFilterCount = MAX_MCAST_FILTER_CNT;\r
-  SnpMode->MCastFilterCount = 0;\r
-  ZeroMem (&SnpMode->MCastFilter, MAX_MCAST_FILTER_CNT * sizeof(EFI_MAC_ADDRESS));\r
-\r
-  // Set the interface type (1: Ethernet or 6: IEEE 802 Networks)\r
-  SnpMode->IfType = NET_IFTYPE_ETHERNET;\r
-\r
-  // Mac address is changeable as it is loaded from erasable memory\r
-  SnpMode->MacAddressChangeable = TRUE;\r
-\r
-  // Can only transmit one packet at a time\r
-  SnpMode->MultipleTxSupported = FALSE;\r
-\r
-  // MediaPresent checks for cable connection and partner link\r
-  SnpMode->MediaPresentSupported = TRUE;\r
-  SnpMode->MediaPresent = FALSE;\r
-\r
-  // Set broadcast address\r
-  SetMem (&SnpMode->BroadcastAddress, sizeof (EFI_MAC_ADDRESS), 0xFF);\r
-\r
-  // Power up the device so we can find the MAC address\r
-  Status = Lan9118Initialize (Snp);\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "LAN9118: Error initialising hardware\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  // Assign fields for device path\r
-  CopyMem (&Lan9118Path->Lan9118.MacAddress, &Snp->Mode->CurrentAddress, NET_ETHER_ADDR_LEN);\r
-  Lan9118Path->Lan9118.IfType = Snp->Mode->IfType;\r
-\r
-  // Initialise the protocol\r
-  ControllerHandle = NULL;\r
-  Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &ControllerHandle,\r
-                  &gEfiSimpleNetworkProtocolGuid, Snp,\r
-                  &gEfiDevicePathProtocolGuid, Lan9118Path,\r
-                  NULL\r
-                  );\r
-  // Say what the status of loading the protocol structure is\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool (LanDriver);\r
-  } else {\r
-    LanDriver->ControllerHandle = ControllerHandle;\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/*\r
- *  UEFI Start() function\r
- *\r
- *  Parameters:\r
- *\r
- *  @param Snp:  A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
- *\r
- *  Description:\r
- *\r
- *    This function starts a network interface. If the network interface successfully starts, then\r
- *    EFI_SUCCESS will be returned.\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpStart (\r
-  IN  EFI_SIMPLE_NETWORK_PROTOCOL  *Snp\r
- )\r
-{\r
-  // Check Snp instance\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // Check state\r
-  if ((Snp->Mode->State == EfiSimpleNetworkStarted)    ||\r
-      (Snp->Mode->State == EfiSimpleNetworkInitialized)  ) {\r
-    return EFI_ALREADY_STARTED;\r
-  }\r
-\r
-  // Change state\r
-  Snp->Mode->State = EfiSimpleNetworkStarted;\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/*\r
- *  UEFI Stop() function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpStop (\r
-  IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp\r
-  )\r
-{\r
-  // Check Snp Instance\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // Check state of the driver\r
-  if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Stop the Tx and Rx\r
-  StopTx (STOP_TX_CFG | STOP_TX_MAC, Snp);\r
-  StopRx (0, Snp);\r
-\r
-  // Change the state\r
-  switch (Snp->Mode->State) {\r
-    case EfiSimpleNetworkStarted:\r
-    case EfiSimpleNetworkInitialized:\r
-      Snp->Mode->State = EfiSimpleNetworkStopped;\r
-      break;\r
-    default:\r
-      return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  // Put the device into a power saving mode ?\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-// Allocated receive and transmit buffers\r
-STATIC UINT32 gTxBuffer = 0;\r
-\r
-/*\r
- *  UEFI Initialize() function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpInitialize (\r
-  IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,\r
-  IN        UINTN                        RxBufferSize    OPTIONAL,\r
-  IN        UINTN                        TxBufferSize    OPTIONAL\r
-  )\r
-{\r
-  EFI_STATUS Status;\r
-  UINT32     PmConf;\r
-  INT32      AllocResult;\r
-  UINT32     RxStatusSize;\r
-  UINT32     TxStatusSize;\r
-\r
-  // Initialize variables\r
-  // Global variables to hold tx and rx FIFO allocation\r
-  gTxBuffer = 0;\r
-\r
-  // Check Snp Instance\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // First check that driver has not already been initialized\r
-  if (Snp->Mode->State == EfiSimpleNetworkInitialized) {\r
-    DEBUG ((EFI_D_WARN, "LAN9118 Driver already initialized\n"));\r
-    return EFI_SUCCESS;\r
-  } else\r
-  if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "LAN9118 Driver not started\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Initiate a PHY reset\r
-  Status = PhySoftReset (PHY_RESET_PMT, Snp);\r
-  if (EFI_ERROR (Status)) {\r
-    Snp->Mode->State = EfiSimpleNetworkStopped;\r
-    DEBUG ((EFI_D_WARN, "Warning: Link not ready after TimeOut. Check ethernet cable\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Initiate a software reset\r
-  Status = SoftReset (0, Snp);\r
-  if (EFI_ERROR(Status)) {\r
-    DEBUG ((EFI_D_WARN, "Soft Reset Failed: Hardware Error\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  // Read the PM register\r
-  PmConf = Lan9118MmioRead32 (LAN9118_PMT_CTRL);\r
-\r
-  // MPTCTRL_WOL_EN: Allow Wake-On-Lan to detect wake up frames or magic packets\r
-  // MPTCTRL_ED_EN:  Allow energy detection to allow lowest power consumption mode\r
-  // MPTCTRL_PME_EN: Allow Power Management Events\r
-  PmConf = 0;\r
-  PmConf |= (MPTCTRL_WOL_EN | MPTCTRL_ED_EN | MPTCTRL_PME_EN);\r
-\r
-  // Write the current configuration to the register\r
-  Lan9118MmioWrite32 (LAN9118_PMT_CTRL, PmConf);\r
-\r
-  // Configure GPIO and HW\r
-  Status = ConfigureHardware (HW_CONF_USE_LEDS, Snp);\r
-  if (EFI_ERROR(Status)) {\r
-    return Status;\r
-  }\r
-\r
-  // Assign the transmitter buffer size (default values)\r
-  TxStatusSize = LAN9118_TX_STATUS_SIZE;\r
-  RxStatusSize = LAN9118_RX_STATUS_SIZE;\r
-\r
-  // Check that a buff size was specified\r
-  if (TxBufferSize > 0) {\r
-    if (RxBufferSize == 0) {\r
-      RxBufferSize = LAN9118_RX_DATA_SIZE;\r
-    }\r
-\r
-    AllocResult = ChangeFifoAllocation (\r
-                          ALLOC_USE_FIFOS,\r
-                          &TxBufferSize,\r
-                          &RxBufferSize,\r
-                          &TxStatusSize,\r
-                          &RxStatusSize,\r
-                          Snp\r
-                          );\r
-\r
-    if (AllocResult < 0) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-  }\r
-\r
-  // Do auto-negotiation if supported\r
-  Status = AutoNegotiate (AUTO_NEGOTIATE_ADVERTISE_ALL, Snp);\r
-  if (EFI_ERROR(Status)) {\r
-    DEBUG ((EFI_D_WARN, "LAN9118: Auto Negotiation failed.\n"));\r
-  }\r
-\r
-  // Configure flow control depending on speed capabilities\r
-  Status = ConfigureFlow (0, 0, 0, 0, Snp);\r
-  if (EFI_ERROR(Status)) {\r
-    return Status;\r
-  }\r
-\r
-  // Enable the transmitter\r
-  Status = StartTx (START_TX_MAC | START_TX_CFG, Snp);\r
-  if (EFI_ERROR(Status)) {\r
-    return Status;\r
-  }\r
-\r
-  // Now acknowledge all interrupts\r
-  Lan9118MmioWrite32 (LAN9118_INT_STS, ~0);\r
-\r
-  // Declare the driver as initialized\r
-  Snp->Mode->State = EfiSimpleNetworkInitialized;\r
-\r
-  return Status;\r
-}\r
-\r
-/*\r
- *  UEFI Reset () function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpReset (\r
-  IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,\r
-  IN        BOOLEAN Verification\r
-  )\r
-{\r
-  UINT32     PmConf;\r
-  UINT32     HwConf;\r
-  UINT32     ResetFlags;\r
-  EFI_STATUS Status;\r
-\r
-  PmConf = 0;\r
-  HwConf = 0;\r
-  ResetFlags = 0;\r
-\r
-  // Check Snp Instance\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // First check that driver has not already been initialized\r
-  if (Snp->Mode->State == EfiSimpleNetworkStarted) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not yet initialized\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not started\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Initiate a PHY reset\r
-  Status = PhySoftReset (PHY_RESET_PMT, Snp);\r
-  if (EFI_ERROR (Status)) {\r
-    Snp->Mode->State = EfiSimpleNetworkStopped;\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Initiate a software reset\r
-  ResetFlags |= SOFT_RESET_CHECK_MAC_ADDR_LOAD | SOFT_RESET_CLEAR_INT;\r
-\r
-  if (Verification) {\r
-    ResetFlags |= SOFT_RESET_SELF_TEST;\r
-  }\r
-\r
-  Status = SoftReset (ResetFlags, Snp);\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_WARN, "Warning: Soft Reset Failed: Hardware Error\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  // Read the PM register\r
-  PmConf = Lan9118MmioRead32 (LAN9118_PMT_CTRL);\r
-\r
-  // MPTCTRL_WOL_EN: Allow Wake-On-Lan to detect wake up frames or magic packets\r
-  // MPTCTRL_ED_EN:  Allow energy detection to allow lowest power consumption mode\r
-  // MPTCTRL_PME_EN: Allow Power Management Events\r
-  PmConf |= (MPTCTRL_WOL_EN | MPTCTRL_ED_EN | MPTCTRL_PME_EN);\r
-\r
-  // Write the current configuration to the register\r
-  Lan9118MmioWrite32 (LAN9118_PMT_CTRL, PmConf);\r
-\r
-  // Reactivate the LEDs\r
-  Status = ConfigureHardware (HW_CONF_USE_LEDS, Snp);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  // Check that a buffer size was specified in SnpInitialize\r
-  if (gTxBuffer != 0) {\r
-    HwConf = Lan9118MmioRead32 (LAN9118_HW_CFG);        // Read the HW register\r
-    HwConf &= ~HW_CFG_TX_FIFO_SIZE_MASK;         // Clear buffer bits first\r
-    HwConf |= HW_CFG_TX_FIFO_SIZE(gTxBuffer);    // assign size chosen in SnpInitialize\r
-\r
-    Lan9118MmioWrite32 (LAN9118_HW_CFG, HwConf);        // Write the conf\r
-  }\r
-\r
-  // Enable the receiver and transmitter and clear their contents\r
-  StartRx (START_RX_CLEAR, Snp);\r
-  StartTx (START_TX_MAC | START_TX_CFG | START_TX_CLEAR, Snp);\r
-\r
-  // Now acknowledge all interrupts\r
-  Lan9118MmioWrite32 (LAN9118_INT_STS, ~0);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/*\r
- *  UEFI Shutdown () function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpShutdown (\r
-  IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp\r
-  )\r
-{\r
-  EFI_STATUS Status;\r
-\r
-  // Check Snp Instance\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // First check that driver has not already been initialized\r
-  if (Snp->Mode->State == EfiSimpleNetworkStarted) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not yet initialized\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not started\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Initiate a PHY reset\r
-  Status = PhySoftReset (PHY_RESET_PMT, Snp);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  // Initiate a software reset\r
-  Status = SoftReset (0, Snp);\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_WARN, "Warning: Soft Reset Failed: Hardware Error\n"));\r
-    return Status;\r
-  }\r
-\r
-  // Back to the started and thus not initialized state\r
-  Snp->Mode->State = EfiSimpleNetworkStarted;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Enable and/or disable the receive filters of the LAN9118\r
-\r
-  Please refer to the UEFI specification for the precedence rules among the\r
-  Enable, Disable and ResetMCastFilter parameters.\r
-\r
-  @param[in]  Snp               A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL\r
-                                instance.\r
-  @param[in]  Enable            A bit mask of receive filters to enable.\r
-  @param[in]  Disable           A bit mask of receive filters to disable.\r
-  @param[in]  ResetMCastFilter  Set to TRUE to reset the contents of the multicast\r
-                                receive filters on the network interface to\r
-                                their default values.\r
-  @param[in]  MCastFilterCnt    Number of multicast HW MAC addresses in the new\r
-                                MCastFilter list. This value must be less than or\r
-                                equal to the MCastFilterCnt field of\r
-                                EFI_SIMPLE_NETWORK_MODE. This field is optional if\r
-                                ResetMCastFilter is TRUE.\r
-  @param[in]  MCastFilter       A pointer to a list of new multicast receive\r
-                                filter HW MAC addresses. This list will replace\r
-                                any existing multicast HW MAC address list. This\r
-                                field is optional if ResetMCastFilter is TRUE.\r
-\r
-  @retval  EFI_SUCCESS            The receive filters of the LAN9118 were updated.\r
-  @retval  EFI_NOT_STARTED        The LAN9118 has not been started.\r
-  @retval  EFI_INVALID_PARAMETER  One or more of the following conditions is TRUE :\r
-                                  . This is NULL\r
-                                  . Multicast is being enabled (the\r
-                                    EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST bit is set in\r
-                                    Enable, it is not set in Disable, and ResetMCastFilter\r
-                                    is FALSE) and MCastFilterCount is zero.\r
-                                  . Multicast is being enabled and MCastFilterCount is\r
-                                    greater than Snp->Mode->MaxMCastFilterCount.\r
-                                  . Multicast is being enabled and MCastFilter is NULL\r
-                                  . Multicast is being enabled and one or more of the\r
-                                    addresses in the MCastFilter list are not valid\r
-                                    multicast MAC addresses.\r
-  @retval  EFI_DEVICE_ERROR       The LAN9118 has been started but not initialized.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpReceiveFilters (\r
-  IN  EFI_SIMPLE_NETWORK_PROTOCOL  *Snp,\r
-  IN  UINT32                       Enable,\r
-  IN  UINT32                       Disable,\r
-  IN  BOOLEAN                      ResetMCastFilter,\r
-  IN  UINTN                        MCastFilterCnt  OPTIONAL,\r
-  IN  EFI_MAC_ADDRESS              *MCastFilter  OPTIONAL\r
-  )\r
-{\r
-  EFI_SIMPLE_NETWORK_MODE  *Mode;\r
-  UINT32                   MultHashTableHigh;\r
-  UINT32                   MultHashTableLow;\r
-  UINT32                   Count;\r
-  UINT32                   Crc;\r
-  UINT8                    HashValue;\r
-  UINT32                   MacCSRValue;\r
-  UINT32                   ReceiveFilterSetting;\r
-  EFI_MAC_ADDRESS          *Mac;\r
-  EFI_MAC_ADDRESS          ZeroMac;\r
-\r
-  // Check Snp Instance\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  Mode = Snp->Mode;\r
-\r
-  // Check that driver was started and initialised\r
-  if (Mode->State == EfiSimpleNetworkStarted) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not initialized\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver in stopped state\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  if ((Enable  & (~Mode->ReceiveFilterMask)) ||\r
-      (Disable & (~Mode->ReceiveFilterMask))    ) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // Check the validity of the multicast setting and compute the\r
-  // hash values of the multicast mac addresses to listen to.\r
-  //\r
-\r
-  MultHashTableHigh = 0;\r
-  MultHashTableLow  = 0;\r
-  if ((!ResetMCastFilter)                                     &&\r
-      ((Disable & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) == 0) &&\r
-      ((Enable  & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0)    ) {\r
-    if ((MCastFilterCnt == 0)                        ||\r
-        (MCastFilterCnt > Mode->MaxMCastFilterCount) ||\r
-        (MCastFilter == NULL)                           ) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-    //\r
-    // Check the validity of all multicast addresses before to change\r
-    // anything.\r
-    //\r
-    for (Count = 0; Count < MCastFilterCnt; Count++) {\r
-      if ((MCastFilter[Count].Addr[0] & 1) == 0) {\r
-        return EFI_INVALID_PARAMETER;\r
-      }\r
-    }\r
-\r
-    //\r
-    // Go through each filter address and set appropriate bits on hash table\r
-    //\r
-    for (Count = 0; Count < MCastFilterCnt; Count++) {\r
-      Mac = &(MCastFilter[Count]);\r
-      CopyMem (&Mode->MCastFilter[Count], Mac, sizeof(EFI_MAC_ADDRESS));\r
-\r
-      Crc = GenEtherCrc32 (Mac, NET_ETHER_ADDR_LEN);\r
-      //gBS->CalculateCrc32 ((VOID*)&Mfilter[Count],6,&Crc); <-- doesn't work as desired\r
-\r
-      //\r
-      // The most significant 6 bits of the MAC address CRC constitute the hash\r
-      // value of the MAC address.\r
-      //\r
-      HashValue = (Crc >> 26) & 0x3F;\r
-\r
-      // Select hashlow register if MSB is not set\r
-      if ((HashValue & 0x20) == 0) {\r
-        MultHashTableLow |= (1 << HashValue);\r
-      } else {\r
-        MultHashTableHigh |= (1 << (HashValue & 0x1F));\r
-      }\r
-    }\r
-    Mode->MCastFilterCount = MCastFilterCnt;\r
-  } else if (ResetMCastFilter) {\r
-    Mode->MCastFilterCount = 0;\r
-  } else {\r
-    MultHashTableLow  = IndirectMACRead32 (INDIRECT_MAC_INDEX_HASHL);\r
-    MultHashTableHigh = IndirectMACRead32 (INDIRECT_MAC_INDEX_HASHH);\r
-  }\r
-\r
-  //\r
-  // Before to change anything, stop and reset the reception of\r
-  // packets.\r
-  //\r
-  StopRx (STOP_RX_CLEAR, Snp);\r
-\r
-  //\r
-  // Write the mask of the selected hash values for the multicast filtering.\r
-  // The two masks are set to zero if the multicast filtering is not enabled.\r
-  //\r
-  IndirectMACWrite32 (INDIRECT_MAC_INDEX_HASHL, MultHashTableLow);\r
-  IndirectMACWrite32 (INDIRECT_MAC_INDEX_HASHH, MultHashTableHigh);\r
-\r
-  ReceiveFilterSetting = (Mode->ReceiveFilterSetting | Enable) & (~Disable);\r
-\r
-  //\r
-  // Read MAC controller\r
-  //\r
-  MacCSRValue  = IndirectMACRead32 (INDIRECT_MAC_INDEX_CR);\r
-  MacCSRValue &= ~(MACCR_HPFILT | MACCR_BCAST | MACCR_PRMS | MACCR_MCPAS);\r
-\r
-  if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_UNICAST) {\r
-    Lan9118SetMacAddress (&Mode->CurrentAddress, Snp);\r
-    DEBUG ((DEBUG_NET, "Allowing Unicast Frame Reception\n"));\r
-  } else {\r
-    //\r
-    // The Unicast packets do not have to be listen to, set the MAC\r
-    // address of the LAN9118 to be the "not configured" all zeroes\r
-    // ethernet MAC address.\r
-    //\r
-    ZeroMem (&ZeroMac, NET_ETHER_ADDR_LEN);\r
-    Lan9118SetMacAddress (&ZeroMac, Snp);\r
-  }\r
-\r
-  if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) {\r
-    MacCSRValue |= MACCR_HPFILT;\r
-    DEBUG ((DEBUG_NET, "Allowing Multicast Frame Reception\n"));\r
-  }\r
-\r
-  if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) {\r
-    MacCSRValue |= MACCR_MCPAS;\r
-    DEBUG ((DEBUG_NET, "Enabling Promiscuous Multicast Mode\n"));\r
-  }\r
-\r
-  if ((ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST) == 0) {\r
-    MacCSRValue |= MACCR_BCAST;\r
-  } else {\r
-    DEBUG ((DEBUG_NET, "Allowing Broadcast Frame Reception\n"));\r
-  }\r
-\r
-  if (ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS) {\r
-    MacCSRValue |= MACCR_PRMS;\r
-    DEBUG ((DEBUG_NET, "Enabling Promiscuous Mode\n"));\r
-  }\r
-\r
-  //\r
-  // Write the options to the MAC_CSR\r
-  //\r
-  IndirectMACWrite32 (INDIRECT_MAC_INDEX_CR, MacCSRValue);\r
-\r
-  //\r
-  // If we have to retrieve something, start packet reception.\r
-  //\r
-  Mode->ReceiveFilterSetting = ReceiveFilterSetting;\r
-  if (ReceiveFilterSetting != 0) {\r
-    StartRx (0, Snp);\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Modify of reset the current station address\r
-\r
-  @param[in]  Snp               A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL\r
-                                instance.\r
-  @param[in]  Reset             Flag used to reset the station address to the\r
-                                LAN9118's permanent address.\r
-  @param[in]  New               New station address to be used for the network interface.\r
-\r
-  @retval  EFI_SUCCESS            The LAN9118's station address was updated.\r
-  @retval  EFI_NOT_STARTED        The LAN9118 has not been started.\r
-  @retval  EFI_INVALID_PARAMETER  One or more of the following conditions is TRUE :\r
-                                  . The "New" station address is invalid.\r
-                                  . "Reset" is FALSE and "New" is NULL.\r
-  @retval  EFI_DEVICE_ERROR       The LAN9118 has been started but not initialized.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpStationAddress (\r
-  IN  EFI_SIMPLE_NETWORK_PROTOCOL  *Snp,\r
-  IN  BOOLEAN                      Reset,\r
-  IN  EFI_MAC_ADDRESS              *New\r
-)\r
-{\r
-  UINT32 Count;\r
-  UINT8  PermAddr[NET_ETHER_ADDR_LEN];\r
-\r
-  DEBUG ((DEBUG_NET, "SnpStationAddress()\n"));\r
-\r
-  // Check Snp instance\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // Check that driver was started and initialised\r
-  if (Snp->Mode->State == EfiSimpleNetworkStarted) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not initialized\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver in stopped state\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Get the Permanent MAC address if need reset\r
-  if (Reset) {\r
-    // Try using EEPROM first. Read the first byte of data from EEPROM at the address 0x0\r
-    if ((IndirectEEPROMRead32 (0) & 0xFF) == EEPROM_EXTERNAL_SERIAL_EEPROM) {\r
-      for (Count = 0; Count < NET_ETHER_ADDR_LEN; Count++) {\r
-        PermAddr[Count] = IndirectEEPROMRead32 (Count + 1);\r
-      }\r
-      New = (EFI_MAC_ADDRESS *) PermAddr;\r
-      Lan9118SetMacAddress ((EFI_MAC_ADDRESS *) PermAddr, Snp);\r
-    } else {\r
-      DEBUG ((EFI_D_ERROR, "LAN9118: Warning: No valid MAC address in EEPROM, using fallback\n"));\r
-      New = (EFI_MAC_ADDRESS*) (FixedPcdGet64 (PcdLan9118DefaultMacAddress));\r
-    }\r
-  } else {\r
-    // Otherwise use the specified new MAC address\r
-    if (New == NULL) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-    //\r
-    // If it is a multicast address, it is not valid.\r
-    //\r
-    if (New->Addr[0] & 0x01) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-  }\r
-\r
-  CopyMem (&Snp->Mode->CurrentAddress, New, NET_ETHER_ADDR_LEN);\r
-\r
-  //\r
-  // If packet reception is currently activated, stop and reset it,\r
-  // set the new ethernet address and restart the packet reception.\r
-  // Otherwise, nothing to do, the MAC address will be updated in\r
-  // SnpReceiveFilters() when the UNICAST packet reception will be\r
-  // activated.\r
-  //\r
-  if (Snp->Mode->ReceiveFilterSetting  != 0) {\r
-    StopRx (STOP_RX_CLEAR, Snp);\r
-    Lan9118SetMacAddress (New, Snp);\r
-    StartRx (0, Snp);\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/*\r
- *  UEFI Statistics() function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpStatistics (\r
-  IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,\r
-  IN        BOOLEAN Reset,\r
-  IN  OUT   UINTN *StatSize,\r
-      OUT   EFI_NETWORK_STATISTICS *Statistics\r
-  )\r
-{\r
-  LAN9118_DRIVER  *LanDriver;\r
-  EFI_STATUS      Status;\r
-\r
-  LanDriver = INSTANCE_FROM_SNP_THIS (Snp);\r
-\r
-  DEBUG ((DEBUG_NET, "SnpStatistics()\n"));\r
-\r
-  // Check Snp instance\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // Check that driver was started and initialised\r
-  if (Snp->Mode->State == EfiSimpleNetworkStarted) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not initialized\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver in stopped state\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  //\r
-  // Do a reset if required. It is not clearly stated in the UEFI specification\r
-  // whether the reset has to be done before to copy the statistics in "Statictics"\r
-  // or after. It is a bit strange to do it before but that is what is expected by\r
-  // the SCT test on Statistics() with reset : "0x3de76704,0x4bf5,0x42cd,0x8c,0x89,\r
-  // 0x54,0x7e,0x4f,0xad,0x4f,0x24".\r
-  //\r
-  if (Reset) {\r
-    ZeroMem (&LanDriver->Stats, sizeof(EFI_NETWORK_STATISTICS));\r
-  }\r
-\r
-  Status = EFI_SUCCESS;\r
-  if (StatSize == NULL) {\r
-    if (Statistics != NULL) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-  } else {\r
-    if (Statistics == NULL) {\r
-      Status = EFI_BUFFER_TOO_SMALL;\r
-    } else {\r
-      // Fill in the statistics\r
-      CopyMem (\r
-        Statistics, &LanDriver->Stats,\r
-        MIN (*StatSize, sizeof (EFI_NETWORK_STATISTICS))\r
-        );\r
-      if (*StatSize < sizeof (EFI_NETWORK_STATISTICS)) {\r
-        Status = EFI_BUFFER_TOO_SMALL;\r
-      }\r
-    }\r
-    *StatSize = sizeof (EFI_NETWORK_STATISTICS);\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/*\r
- *  UEFI MCastIPtoMAC() function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpMcastIptoMac (\r
-  IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,\r
-  IN        BOOLEAN IsIpv6,\r
-  IN        EFI_IP_ADDRESS *Ip,\r
-      OUT   EFI_MAC_ADDRESS *McastMac\r
-  )\r
-{\r
-  DEBUG ((DEBUG_NET, "SnpMcastIptoMac()\n"));\r
-\r
-  // Check Snp instance\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // Check that driver was started and initialised\r
-  if (Snp->Mode->State == EfiSimpleNetworkStarted) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not initialized\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver in stopped state\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Check parameters\r
-  if ((McastMac == NULL) || (Ip == NULL)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // Make sure MAC address is empty\r
-  ZeroMem (McastMac, sizeof(EFI_MAC_ADDRESS));\r
-\r
-  // If we need ipv4 address\r
-  if (!IsIpv6) {\r
-    // Most significant 25 bits of a multicast HW address are set.\r
-    // 01-00-5E is the IPv4 Ethernet Multicast Address (see RFC 1112)\r
-    McastMac->Addr[0] = 0x01;\r
-    McastMac->Addr[1] = 0x00;\r
-    McastMac->Addr[2] = 0x5E;\r
-\r
-    // Lower 23 bits from ipv4 address\r
-    McastMac->Addr[3] = (Ip->v4.Addr[1] & 0x7F); // Clear the most significant bit (25th bit of MAC must be 0)\r
-    McastMac->Addr[4] = Ip->v4.Addr[2];\r
-    McastMac->Addr[5] = Ip->v4.Addr[3];\r
-  } else {\r
-    // Most significant 16 bits of multicast v6 HW address are set\r
-    // 33-33 is the IPv6 Ethernet Multicast Address (see RFC 2464)\r
-    McastMac->Addr[0] = 0x33;\r
-    McastMac->Addr[1] = 0x33;\r
-\r
-    // lower four octets are taken from ipv6 address\r
-    McastMac->Addr[2] = Ip->v6.Addr[8];\r
-    McastMac->Addr[3] = Ip->v6.Addr[9];\r
-    McastMac->Addr[4] = Ip->v6.Addr[10];\r
-    McastMac->Addr[5] = Ip->v6.Addr[11];\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/*\r
- *  UEFI NvData() function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNvData (\r
-  IN        EFI_SIMPLE_NETWORK_PROTOCOL* pobj,\r
-  IN        BOOLEAN read_write,\r
-  IN        UINTN offset,\r
-  IN        UINTN buff_size,\r
-  IN  OUT   VOID *data\r
-  )\r
-{\r
-  DEBUG ((DEBUG_NET, "SnpNvData()\n"));\r
-\r
-  return EFI_UNSUPPORTED;\r
-}\r
-\r
-\r
-/*\r
- *  UEFI GetStatus () function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpGetStatus (\r
-  IN   EFI_SIMPLE_NETWORK_PROTOCOL  *Snp,\r
-  OUT  UINT32                       *IrqStat  OPTIONAL,\r
-  OUT  VOID                         **TxBuff  OPTIONAL\r
-  )\r
-{\r
-  UINT32          FifoInt;\r
-  EFI_STATUS      Status;\r
-  UINTN           NumTxStatusEntries;\r
-  UINT32          TxStatus;\r
-  UINT16          PacketTag;\r
-  UINT32          Interrupts;\r
-  LAN9118_DRIVER *LanDriver;\r
-\r
-  LanDriver = INSTANCE_FROM_SNP_THIS (Snp);\r
-\r
-  // Check preliminaries\r
-  if (Snp == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // Check that driver was started and initialised\r
-  if (Snp->Mode->State == EfiSimpleNetworkStarted) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not initialized\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver in stopped state\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Check and acknowledge TX Status interrupt (this will happen if the\r
-  // consumer of SNP does not call GetStatus.)\r
-  // TODO will we lose TxStatuses if this happens? Maybe in SnpTransmit we\r
-  // should check for it and dump the TX Status FIFO.\r
-  FifoInt = Lan9118MmioRead32 (LAN9118_FIFO_INT);\r
-\r
-  // Clear the TX Status FIFO Overflow\r
-  if ((FifoInt & INSTS_TXSO) == 0) {\r
-    FifoInt |= INSTS_TXSO;\r
-    Lan9118MmioWrite32 (LAN9118_FIFO_INT, FifoInt);\r
-  }\r
-\r
-  // Read interrupt status if IrqStat is not NULL\r
-  if (IrqStat != NULL) {\r
-    *IrqStat = 0;\r
-\r
-    // Check for receive interrupt\r
-    if (Lan9118MmioRead32 (LAN9118_INT_STS) & INSTS_RSFL) { // Data moved from rx FIFO\r
-      *IrqStat |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;\r
-      Lan9118MmioWrite32 (LAN9118_INT_STS,INSTS_RSFL);\r
-    }\r
-\r
-    // Check for transmit interrupt\r
-    if (Lan9118MmioRead32 (LAN9118_INT_STS) & INSTS_TSFL) {\r
-      *IrqStat |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;\r
-      Lan9118MmioWrite32 (LAN9118_INT_STS,INSTS_TSFL);\r
-    }\r
-\r
-    // Check for software interrupt\r
-    if (Lan9118MmioRead32 (LAN9118_INT_STS) & INSTS_SW_INT) {\r
-      *IrqStat |= EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT;\r
-      Lan9118MmioWrite32 (LAN9118_INT_STS,INSTS_SW_INT);\r
-    }\r
-  }\r
-\r
-  // Check Status of transmitted packets\r
-  // (We ignore TXSTATUS_NO_CA has it might happen in Full Duplex)\r
-\r
-  NumTxStatusEntries = Lan9118MmioRead32(LAN9118_TX_FIFO_INF) & TXFIFOINF_TXSUSED_MASK;\r
-  if (NumTxStatusEntries > 0) {\r
-    TxStatus = Lan9118MmioRead32 (LAN9118_TX_STATUS);\r
-    PacketTag = TxStatus >> 16;\r
-    TxStatus = TxStatus & 0xFFFF;\r
-    if ((TxStatus & TXSTATUS_ES) && (TxStatus != (TXSTATUS_ES | TXSTATUS_NO_CA))) {\r
-      DEBUG ((EFI_D_ERROR, "LAN9118: There was an error transmitting. TxStatus=0x%08x:", TxStatus));\r
-      if (TxStatus & TXSTATUS_NO_CA) {\r
-        DEBUG ((EFI_D_ERROR, "- No carrier\n"));\r
-      }\r
-      if (TxStatus & TXSTATUS_DEF) {\r
-        DEBUG ((EFI_D_ERROR, "- Packet tx was deferred\n"));\r
-      }\r
-      if (TxStatus & TXSTATUS_EDEF) {\r
-        DEBUG ((EFI_D_ERROR, "- Tx ended because of excessive deferral\n"));\r
-      }\r
-      if (TxStatus & TXSTATUS_ECOLL) {\r
-        DEBUG ((EFI_D_ERROR, "- Tx ended because of Excessive Collisions\n"));\r
-      }\r
-      if (TxStatus & TXSTATUS_LCOLL) {\r
-        DEBUG ((EFI_D_ERROR, "- Packet Tx aborted after coll window of 64 bytes\n"));\r
-      }\r
-      if (TxStatus & TXSTATUS_LOST_CA) {\r
-        DEBUG ((EFI_D_ERROR, "- Lost carrier during Tx\n"));\r
-      }\r
-      return EFI_DEVICE_ERROR;\r
-    } else if (TxBuff != NULL) {\r
-      LanDriver->Stats.TxTotalFrames += 1;\r
-      *TxBuff = LanDriver->TxRing[PacketTag % LAN9118_TX_RING_NUM_ENTRIES];\r
-    }\r
-  } else if (TxBuff != NULL) {\r
-    *TxBuff = NULL;\r
-  }\r
-\r
-  // Check for a TX Error interrupt\r
-  Interrupts = Lan9118MmioRead32 (LAN9118_INT_STS);\r
-  if (Interrupts & INSTS_TXE) {\r
-    DEBUG ((EFI_D_ERROR, "LAN9118: Transmitter error. Restarting..."));\r
-\r
-    // Software reset, the TXE interrupt is cleared by the reset.\r
-    Status = SoftReset (0, Snp);\r
-    if (EFI_ERROR (Status)) {\r
-      DEBUG ((EFI_D_ERROR, "\n\tSoft Reset Failed: Hardware Error\n"));\r
-      return EFI_DEVICE_ERROR;\r
-    }\r
-\r
-    // Reactivate the LEDs\r
-    Status = ConfigureHardware (HW_CONF_USE_LEDS, Snp);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-\r
-    //\r
-    // Restart the transmitter and if necessary the receiver.\r
-    // Do not ask for FIFO reset as it has already been done\r
-    // by SoftReset().\r
-    //\r
-    StartTx (START_TX_MAC | START_TX_CFG, Snp);\r
-    if (Snp->Mode->ReceiveFilterSetting != 0) {\r
-      StartRx (0, Snp);\r
-    }\r
-  }\r
-\r
-  // Update the media status\r
-  Status = CheckLinkStatus (0, Snp);\r
-  if (EFI_ERROR(Status)) {\r
-    Snp->Mode->MediaPresent = FALSE;\r
-  } else {\r
-    Snp->Mode->MediaPresent = TRUE;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/*\r
- *  UEFI Transmit() function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpTransmit (\r
-  IN  EFI_SIMPLE_NETWORK_PROTOCOL  *Snp,\r
-  IN  UINTN                        HdrSize,\r
-  IN  UINTN                        BuffSize,\r
-  IN  VOID*                        Data,\r
-  IN  EFI_MAC_ADDRESS              *SrcAddr  OPTIONAL,\r
-  IN  EFI_MAC_ADDRESS              *DstAddr  OPTIONAL,\r
-  IN  UINT16                       *Protocol OPTIONAL\r
-  )\r
-{\r
-  LAN9118_DRIVER *LanDriver;\r
-  UINT32 TxFreeSpace;\r
-  UINT32 TxStatusSpace;\r
-  INT32 Count;\r
-  UINT32 CommandA;\r
-  UINT32 CommandB;\r
-  UINT16 LocalProtocol;\r
-  UINT32 *LocalData;\r
-  UINT16 PacketTag;\r
-\r
-#if defined(EVAL_PERFORMANCE)\r
-  UINT64 Perf;\r
-  UINT64 StartClock;\r
-  UINT64 EndClock;\r
-\r
-  Perf = GetPerformanceCounterProperties (NULL, NULL);\r
-  StartClock = GetPerformanceCounter ();\r
-#endif\r
-\r
-  LanDriver = INSTANCE_FROM_SNP_THIS (Snp);\r
-\r
-  // Check preliminaries\r
-  if ((Snp == NULL) || (Data == NULL)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // Check that driver was started and initialised\r
-  if (Snp->Mode->State == EfiSimpleNetworkStarted) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not initialized\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver in stopped state\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  // Ensure header is correct size if non-zero\r
-  if (HdrSize) {\r
-    if (HdrSize != Snp->Mode->MediaHeaderSize) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-\r
-    if ((DstAddr == NULL) || (Protocol == NULL)) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Check validity of BufferSize\r
-  //\r
-  if (BuffSize < Snp->Mode->MediaHeaderSize) {\r
-      return EFI_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  // Before transmitting check the link status\r
-  /*if (CheckLinkStatus (0, Snp) < 0) {\r
-    return EFI_NOT_READY;\r
-  }*/\r
-\r
-  // Get DATA FIFO free space in bytes\r
-  TxFreeSpace = TxDataFreeSpace (0, Snp);\r
-  if (TxFreeSpace < BuffSize) {\r
-    return EFI_NOT_READY;\r
-  }\r
-\r
-  // Get STATUS FIFO used space in bytes\r
-  TxStatusSpace = TxStatusUsedSpace (0, Snp);\r
-  if (TxStatusSpace > 500) {\r
-    return EFI_NOT_READY;\r
-  }\r
-\r
-  // If DstAddr is not provided, get it from Buffer (we trust that the caller\r
-  // has provided a well-formed frame).\r
-  if (DstAddr == NULL) {\r
-    DstAddr = (EFI_MAC_ADDRESS *) Data;\r
-  }\r
-\r
-  // Check for the nature of the frame\r
-  if ((DstAddr->Addr[0] & 0x1) == 1) {\r
-    LanDriver->Stats.TxMulticastFrames += 1;\r
-  } else {\r
-    LanDriver->Stats.TxUnicastFrames += 1;\r
-  }\r
-\r
-  // Check if broadcast\r
-  if (DstAddr->Addr[0] == 0xFF) {\r
-    LanDriver->Stats.TxBroadcastFrames += 1;\r
-  }\r
-\r
-  PacketTag = LanDriver->NextPacketTag;\r
-  LanDriver->NextPacketTag++;\r
-\r
-  if (HdrSize) {\r
-\r
-    // Format pointer\r
-    LocalData = (UINT32*) Data;\r
-    LocalProtocol = *Protocol;\r
-\r
-    // Create first buffer to pass to controller (for the header)\r
-    CommandA = TX_CMD_A_FIRST_SEGMENT | TX_CMD_A_BUFF_SIZE (HdrSize);\r
-    CommandB = TX_CMD_B_PACKET_TAG (PacketTag) | TX_CMD_B_PACKET_LENGTH (BuffSize);\r
-\r
-    // Write the commands first\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandA);\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandB);\r
-\r
-    // Write the destination address\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA,\r
-               (DstAddr->Addr[0]) |\r
-               (DstAddr->Addr[1] << 8) |\r
-               (DstAddr->Addr[2] << 16) |\r
-               (DstAddr->Addr[3] << 24)\r
-               );\r
-\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA,\r
-               (DstAddr->Addr[4]) |\r
-               (DstAddr->Addr[5] << 8) |\r
-               (SrcAddr->Addr[0] << 16) | // Write the Source Address\r
-               (SrcAddr->Addr[1] << 24)\r
-               );\r
-\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA,\r
-               (SrcAddr->Addr[2]) |\r
-               (SrcAddr->Addr[3] << 8) |\r
-               (SrcAddr->Addr[4] << 16) |\r
-               (SrcAddr->Addr[5] << 24)\r
-               );\r
-\r
-    // Write the Protocol\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA, (UINT32)(HTONS (LocalProtocol)));\r
-\r
-    // Next buffer is the payload\r
-    CommandA = TX_CMD_A_LAST_SEGMENT | TX_CMD_A_BUFF_SIZE (BuffSize - HdrSize) | TX_CMD_A_COMPLETION_INT | TX_CMD_A_DATA_START_OFFSET (2); // 2 bytes beginning offset\r
-\r
-    // Write the commands\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandA);\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandB);\r
-\r
-    // Write the payload\r
-    for (Count = 0; Count < ((BuffSize + 3) >> 2) - 3; Count++) {\r
-      Lan9118MmioWrite32 (LAN9118_TX_DATA, LocalData[Count + 3]);\r
-    }\r
-  } else {\r
-    // Format pointer\r
-    LocalData = (UINT32*) Data;\r
-\r
-    // Create a buffer to pass to controller\r
-    CommandA = TX_CMD_A_FIRST_SEGMENT | TX_CMD_A_LAST_SEGMENT | TX_CMD_A_BUFF_SIZE (BuffSize) | TX_CMD_A_COMPLETION_INT;\r
-    CommandB = TX_CMD_B_PACKET_TAG (PacketTag) | TX_CMD_B_PACKET_LENGTH (BuffSize);\r
-\r
-    // Write the commands first\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandA);\r
-    Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandB);\r
-\r
-    // Write all the data\r
-    for (Count = 0; Count < ((BuffSize + 3) >> 2); Count++) {\r
-      Lan9118MmioWrite32 (LAN9118_TX_DATA, LocalData[Count]);\r
-    }\r
-  }\r
-\r
-  // Save the address of the submitted packet so we can notify the consumer that\r
-  // it has been sent in GetStatus. When the packet tag appears in the Tx Status\r
-  // Fifo, we will return Buffer in the TxBuff parameter of GetStatus.\r
-  LanDriver->TxRing[PacketTag % LAN9118_TX_RING_NUM_ENTRIES] = Data;\r
-\r
-#if defined(EVAL_PERFORMANCE)\r
-  EndClock = GetPerformanceCounter ();\r
-  DEBUG ((EFI_D_ERROR, "Time processing: %d counts @ %d Hz\n", StartClock - EndClock,Perf));\r
-#endif\r
-\r
-  LanDriver->Stats.TxGoodFrames += 1;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/*\r
- *  UEFI Receive() function\r
- *\r
- */\r
-EFI_STATUS\r
-EFIAPI\r
-SnpReceive (\r
-  IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,\r
-      OUT   UINTN *HdrSize                OPTIONAL,\r
-  IN  OUT   UINTN *BuffSize,\r
-      OUT   VOID *Data,\r
-      OUT   EFI_MAC_ADDRESS *SrcAddr      OPTIONAL,\r
-      OUT   EFI_MAC_ADDRESS *DstAddr      OPTIONAL,\r
-      OUT   UINT16 *Protocol              OPTIONAL\r
-  )\r
-{\r
-  LAN9118_DRIVER  *LanDriver;\r
-  UINT32          IntSts;\r
-  UINT32          RxFifoStatus;\r
-  UINT32          NumPackets;\r
-  UINT32          RxCfgValue;\r
-  UINT32          PLength; // Packet length\r
-  UINT32          ReadLimit;\r
-  UINT32          Count;\r
-  UINT32          Padding;\r
-  UINT32          *RawData;\r
-  EFI_MAC_ADDRESS Dst;\r
-  EFI_MAC_ADDRESS Src;\r
-  UINTN           DroppedFrames;\r
-  EFI_STATUS      Status;\r
-\r
-  LanDriver = INSTANCE_FROM_SNP_THIS (Snp);\r
-\r
-#if defined(EVAL_PERFORMANCE)\r
-  UINT64 Perf = GetPerformanceCounterProperties (NULL, NULL);\r
-  UINT64 StartClock = GetPerformanceCounter ();\r
-#endif\r
-\r
-  // Check preliminaries\r
-  if ((Snp == NULL) || (Data == NULL) || (BuffSize == NULL)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  // Check that driver was started and initialised\r
-  if (Snp->Mode->State == EfiSimpleNetworkStarted) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver not initialized\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  } else if (Snp->Mode->State == EfiSimpleNetworkStopped) {\r
-    DEBUG ((EFI_D_WARN, "Warning: LAN9118 Driver in stopped state\n"));\r
-    return EFI_NOT_STARTED;\r
-  }\r
-\r
-  //\r
-  // If the receiver raised the RXE error bit, check if the receiver status\r
-  // FIFO is full and if not just acknowledge the error. The two other\r
-  // conditions to get a RXE error are :\r
-  // . the RX data FIFO is read whereas being empty.\r
-  // . the RX status FIFO is read whereas being empty.\r
-  // The RX data and status FIFO are read by this driver only in the following\r
-  // code of this function. After the readings, the RXE error bit is checked\r
-  // and if raised, the controller is reset. Thus, at this point, we consider\r
-  // that the only valid reason to get an RXE error is the receiver status\r
-  // FIFO being full. And if this is not the case, we consider that this is\r
-  // a spurious error and we just get rid of it. We experienced such 'spurious'\r
-  // errors when running the driver on an A57 on Juno. No valid reason to\r
-  // explain those errors has been found so far and everything seems to\r
-  // work perfectly when they are just ignored.\r
-  //\r
-  IntSts = Lan9118MmioRead32 (LAN9118_INT_STS);\r
-  if ((IntSts & INSTS_RXE) && (!(IntSts & INSTS_RSFF))) {\r
-    Lan9118MmioWrite32 (LAN9118_INT_STS, INSTS_RXE);\r
-  }\r
-\r
-  // Count dropped frames\r
-  DroppedFrames = Lan9118MmioRead32 (LAN9118_RX_DROP);\r
-  LanDriver->Stats.RxDroppedFrames += DroppedFrames;\r
-\r
-  NumPackets = RxStatusUsedSpace (0, Snp) / 4;\r
-  if (!NumPackets) {\r
-    return EFI_NOT_READY;\r
-  }\r
-\r
-  // Read Rx Status (only if not empty)\r
-  RxFifoStatus = Lan9118MmioRead32 (LAN9118_RX_STATUS);\r
-  LanDriver->Stats.RxTotalFrames += 1;\r
-\r
-  // First check for errors\r
-  if ((RxFifoStatus & RXSTATUS_MII_ERROR) ||\r
-      (RxFifoStatus & RXSTATUS_RXW_TO) ||\r
-      (RxFifoStatus & RXSTATUS_FTL) ||\r
-      (RxFifoStatus & RXSTATUS_LCOLL) ||\r
-      (RxFifoStatus & RXSTATUS_LE) ||\r
-      (RxFifoStatus & RXSTATUS_DB))\r
-  {\r
-    DEBUG ((EFI_D_WARN, "Warning: There was an error on frame reception.\n"));\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  // Check if we got a CRC error\r
-  if (RxFifoStatus & RXSTATUS_CRC_ERROR) {\r
-    DEBUG ((EFI_D_WARN, "Warning: Crc Error\n"));\r
-    LanDriver->Stats.RxCrcErrorFrames += 1;\r
-    LanDriver->Stats.RxDroppedFrames += 1;\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  // Check if we got a runt frame\r
-  if (RxFifoStatus & RXSTATUS_RUNT) {\r
-    DEBUG ((EFI_D_WARN, "Warning: Runt Frame\n"));\r
-    LanDriver->Stats.RxUndersizeFrames += 1;\r
-    LanDriver->Stats.RxDroppedFrames += 1;\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-  // Check filtering status for this packet\r
-  if (RxFifoStatus & RXSTATUS_FILT_FAIL) {\r
-    DEBUG ((EFI_D_WARN, "Warning: Frame Failed Filtering\n"));\r
-    // fast forward?\r
-  }\r
-\r
-  // Check if we got a broadcast frame\r
-  if (RxFifoStatus & RXSTATUS_BCF) {\r
-    LanDriver->Stats.RxBroadcastFrames += 1;\r
-  }\r
-\r
-  // Check if we got a multicast frame\r
-  if (RxFifoStatus & RXSTATUS_MCF) {\r
-    LanDriver->Stats.RxMulticastFrames += 1;\r
-  }\r
-\r
-  // Check if we got a unicast frame\r
-  if ((RxFifoStatus & RXSTATUS_BCF) && ((RxFifoStatus & RXSTATUS_MCF) == 0)) {\r
-    LanDriver->Stats.RxUnicastFrames += 1;\r
-  }\r
-\r
-  // Get the received packet length\r
-  PLength = GET_RXSTATUS_PACKET_LENGTH(RxFifoStatus);\r
-  LanDriver->Stats.RxTotalBytes += (PLength - 4);\r
-\r
-  // If padding is applied, read more DWORDs\r
-  if (PLength % 4) {\r
-    Padding = 4 - (PLength % 4);\r
-    ReadLimit = (PLength + Padding)/4;\r
-  } else {\r
-    ReadLimit = PLength/4;\r
-    Padding = 0;\r
-  }\r
-\r
-  // Check buffer size\r
-  if (*BuffSize < (PLength + Padding)) {\r
-    *BuffSize = PLength + Padding;\r
-    return EFI_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  // Set the amount of data to be transferred out of FIFO for THIS packet\r
-  // This can be used to trigger an interrupt, and status can be checked\r
-  RxCfgValue = Lan9118MmioRead32 (LAN9118_RX_CFG);\r
-  RxCfgValue &= ~(RXCFG_RX_DMA_CNT_MASK);\r
-  RxCfgValue |= RXCFG_RX_DMA_CNT (ReadLimit);\r
-\r
-  // Set end alignment to 4-bytes\r
-  RxCfgValue &= ~(RXCFG_RX_END_ALIGN_MASK);\r
-  Lan9118MmioWrite32 (LAN9118_RX_CFG, RxCfgValue);\r
-\r
-  // Update buffer size\r
-  *BuffSize = PLength; // -4 bytes may be needed: Received in buffer as\r
-                       // 4 bytes longer than packet actually is, unless\r
-                       // packet is < 64 bytes\r
-\r
-  if (HdrSize != NULL)\r
-    *HdrSize = Snp->Mode->MediaHeaderSize;\r
-\r
-  // Format the pointer\r
-  RawData = (UINT32*)Data;\r
-\r
-  // Read Rx Packet\r
-  for (Count = 0; Count < ReadLimit; Count++) {\r
-    RawData[Count] = Lan9118MmioRead32 (LAN9118_RX_DATA);\r
-  }\r
-\r
-  // Get the destination address\r
-  if (DstAddr != NULL) {\r
-    Dst.Addr[0] = (RawData[0] & 0xFF);\r
-    Dst.Addr[1] = (RawData[0] & 0xFF00) >> 8;\r
-    Dst.Addr[2] = (RawData[0] & 0xFF0000) >> 16;\r
-    Dst.Addr[3] = (RawData[0] & 0xFF000000) >> 24;\r
-    Dst.Addr[4] = (RawData[1] & 0xFF);\r
-    Dst.Addr[5] = (RawData[1] & 0xFF00) >> 8;\r
-    CopyMem (DstAddr, &Dst, NET_ETHER_ADDR_LEN);\r
-  }\r
-\r
-  // Get the source address\r
-  if (SrcAddr != NULL) {\r
-    Src.Addr[0] = (RawData[1] & 0xFF0000) >> 16;\r
-    Src.Addr[1] = (RawData[1] & 0xFF000000) >> 24;\r
-    Src.Addr[2] = (RawData[2] & 0xFF);\r
-    Src.Addr[3] = (RawData[2] & 0xFF00) >> 8;\r
-    Src.Addr[4] = (RawData[2] & 0xFF0000) >> 16;\r
-    Src.Addr[5] = (RawData[2] & 0xFF000000) >> 24;\r
-    CopyMem (SrcAddr, &Src, NET_ETHER_ADDR_LEN);\r
-  }\r
-\r
-  // Get the protocol\r
-  if (Protocol != NULL) {\r
-    *Protocol = NTOHS (RawData[3] & 0xFFFF);\r
-  }\r
-\r
-  // Check for Rx errors (worst possible error)\r
-  if (Lan9118MmioRead32 (LAN9118_INT_STS) & INSTS_RXE) {\r
-    DEBUG ((EFI_D_WARN, "Warning: Receiver Error. Restarting...\n"));\r
-\r
-    // Software reset, the RXE interrupt is cleared by the reset.\r
-    Status = SoftReset (0, Snp);\r
-    if (EFI_ERROR (Status)) {\r
-      DEBUG ((EFI_D_ERROR, "Error: Soft Reset Failed: Hardware Error.\n"));\r
-      return EFI_DEVICE_ERROR;\r
-    }\r
-\r
-    // Reactivate the LEDs\r
-    Status = ConfigureHardware (HW_CONF_USE_LEDS, Snp);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-\r
-    //\r
-    // Restart the receiver and the transmitter without resetting the FIFOs\r
-    // as it has been done by SoftReset().\r
-    //\r
-    StartRx (0, Snp);\r
-    StartTx (START_TX_MAC | START_TX_CFG, Snp);\r
-\r
-    // Say that command could not be sent\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
-#if defined(EVAL_PERFORMANCE)\r
-  UINT64 EndClock = GetPerformanceCounter ();\r
-  DEBUG ((EFI_D_ERROR, "Receive Time processing: %d counts @ %d Hz\n", StartClock - EndClock,Perf));\r
-#endif\r
-\r
-  LanDriver->Stats.RxGoodFrames += 1;\r
-\r
-  return EFI_SUCCESS;\r
-}\r