]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/Snp.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Snp.c
index aa5926a6a521321d9d864917267870d75210a4ef..a23af05078bc8939c7ea42dc83f2d26ad9489888 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Implementation of driver entry point and driver binding protocol.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials are licensed\r
-and made available under the terms and conditions of the BSD License which\r
-accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -273,7 +267,9 @@ SimpleNetworkDriverStart (
   PXE_STATFLAGS                             InitStatFlags;\r
   EFI_PCI_IO_PROTOCOL                       *PciIo;\r
   EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR         *BarDesc;\r
-  \r
+  BOOLEAN                                   FoundIoBar;\r
+  BOOLEAN                                   FoundMemoryBar;\r
+\r
   DEBUG ((EFI_D_NET, "\nSnpNotifyNetworkInterfaceIdentifier()  "));\r
 \r
   Status = gBS->OpenProtocol (\r
@@ -401,9 +397,17 @@ SimpleNetworkDriverStart (
 \r
   Snp->TxRxBufferSize     = 0;\r
   Snp->TxRxBuffer         = NULL;\r
\r
+\r
+  Snp->RecycledTxBuf = AllocatePool (sizeof (UINT64) * SNP_TX_BUFFER_INCREASEMENT);\r
+  if (Snp->RecycledTxBuf == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Error_DeleteSNP;\r
+  }\r
+  Snp->MaxRecycledTxBuf    = SNP_TX_BUFFER_INCREASEMENT;\r
+  Snp->RecycledTxBufCount  = 0;\r
+\r
   if (Nii->Revision >= EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION) {\r
-       Snp->IfNum = Nii->IfNum;\r
+    Snp->IfNum = Nii->IfNum;\r
 \r
   } else {\r
     Snp->IfNum = (UINT8) (Nii->IfNum & 0xFF);\r
@@ -455,10 +459,16 @@ SimpleNetworkDriverStart (
   Snp->Db   = (VOID *) ((UINTN) Address + 2048);\r
 \r
   //\r
-  // Find the correct memory and io bar.\r
+  // Find the correct BAR to do IO.\r
+  //\r
+  // Enumerate through the PCI BARs for the device to determine which one is\r
+  // the IO BAR.  Save the index of the BAR into the adapter info structure.\r
+  // for regular 32bit BARs, 0 is memory mapped, 1 is io mapped\r
   //\r
-  Snp->MemoryBarIndex = PCI_MAX_BAR;\r
-  Snp->IoBarIndex     = PCI_MAX_BAR;\r
+  Snp->MemoryBarIndex = 0;\r
+  Snp->IoBarIndex     = 1;\r
+  FoundMemoryBar      = FALSE;\r
+  FoundIoBar          = FALSE;\r
   for (BarIndex = 0; BarIndex < PCI_MAX_BAR; BarIndex++) {\r
     Status = PciIo->GetBarAttributes (\r
                       PciIo,\r
@@ -472,16 +482,19 @@ SimpleNetworkDriverStart (
       goto Error_DeleteSNP;\r
     }\r
 \r
-    if (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {\r
+    if ((!FoundMemoryBar) && (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM)) {\r
       Snp->MemoryBarIndex = BarIndex;\r
-    } else if (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_IO) {\r
+      FoundMemoryBar      = TRUE;\r
+    } else if ((!FoundIoBar) && (BarDesc->ResType == ACPI_ADDRESS_SPACE_TYPE_IO)) {\r
       Snp->IoBarIndex = BarIndex;\r
+      FoundIoBar      = TRUE;\r
     }\r
 \r
     FreePool (BarDesc);\r
-  }\r
-  if ((Snp->MemoryBarIndex == PCI_MAX_BAR) || (Snp->IoBarIndex == PCI_MAX_BAR)) {\r
-    goto Error_DeleteSNP;\r
+\r
+    if (FoundMemoryBar && FoundIoBar) {\r
+      break;\r
+    }\r
   }\r
 \r
   Status = PxeStart (Snp);\r
@@ -535,12 +548,12 @@ SimpleNetworkDriverStart (
 \r
   switch (InitStatFlags & PXE_STATFLAGS_CABLE_DETECT_MASK) {\r
   case PXE_STATFLAGS_CABLE_DETECT_SUPPORTED:\r
-    Snp->Mode.MediaPresentSupported = TRUE;\r
+    Snp->CableDetectSupported = TRUE;\r
     break;\r
 \r
   case PXE_STATFLAGS_CABLE_DETECT_NOT_SUPPORTED:\r
   default:\r
-    Snp->Mode.MediaPresentSupported = FALSE;\r
+    Snp->CableDetectSupported = FALSE;\r
   }\r
 \r
   switch (InitStatFlags & PXE_STATFLAGS_GET_STATUS_NO_MEDIA_MASK) {\r
@@ -553,6 +566,10 @@ SimpleNetworkDriverStart (
     Snp->MediaStatusSupported = FALSE;\r
   }\r
 \r
+  if (Snp->CableDetectSupported || Snp->MediaStatusSupported) {\r
+    Snp->Mode.MediaPresentSupported = TRUE;\r
+  }\r
+\r
   if ((Pxe->hw.Implementation & PXE_ROMID_IMP_STATION_ADDR_SETTABLE) != 0) {\r
     Snp->Mode.MacAddressChangeable = TRUE;\r
   } else {\r
@@ -667,6 +684,10 @@ SimpleNetworkDriverStart (
 \r
 Error_DeleteSNP:\r
 \r
+  if (Snp->RecycledTxBuf != NULL) {\r
+    FreePool (Snp->RecycledTxBuf);\r
+  }\r
+\r
   PciIo->FreeBuffer (\r
            PciIo,\r
            SNP_MEM_PAGES (sizeof (SNP_DRIVER)),\r
@@ -779,6 +800,8 @@ SimpleNetworkDriverStop (
   PxeShutdown (Snp);\r
   PxeStop (Snp);\r
 \r
+  FreePool (Snp->RecycledTxBuf);\r
+\r
   PciIo = Snp->PciIo;\r
   PciIo->FreeBuffer (\r
            PciIo,\r