]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/Initialize.c
MdeModulePkg: Refine SNP driver's media status check logic.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Initialize.c
index 5337b1cc2eab3124a750e26695f9107f9a3ab22a..21513752de05645b874fae98211abe2c78987c81 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
                Implementation of initializing a network adapter.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. <BR> \r
-All rights reserved. This program and the accompanying materials are licensed \r
+Copyright (c) 2004 - 2008, 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
@@ -16,14 +16,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "Snp.h"\r
 \r
 /**\r
-  this routine calls undi to initialize the interface.\r
+  Call UNDI to initialize the interface.\r
 \r
-  @param  Snp                   pointer to snp driver structure\r
-  @param  CableDetectFlag       Do/don't detect the cable (depending on what undi supports)\r
+  @param  Snp                   Pointer to snp driver structure.\r
+  @param  CableDetectFlag       Do/don't detect the cable (depending on what \r
+                                undi supports).\r
   \r
-  @retval EFI_SUCCESS           UNDI is initialized successfully\r
-  @retval EFI_DEVICE_ERROR      UNDI could not be initialized\r
-  @retval Other                 other errors \r
+  @retval EFI_SUCCESS           UNDI is initialized successfully.\r
+  @retval EFI_DEVICE_ERROR      UNDI could not be initialized.\r
+  @retval Other                 Other errors as indicated.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -83,8 +84,8 @@ PxeInit (
   Snp->Cdb.OpCode     = PXE_OPCODE_INITIALIZE;\r
   Snp->Cdb.OpFlags    = CableDetectFlag;\r
 \r
-  Snp->Cdb.CPBsize    = sizeof (PXE_CPB_INITIALIZE);\r
-  Snp->Cdb.DBsize     = sizeof (PXE_DB_INITIALIZE);\r
+  Snp->Cdb.CPBsize    = (UINT16) sizeof (PXE_CPB_INITIALIZE);\r
+  Snp->Cdb.DBsize     = (UINT16) sizeof (PXE_DB_INITIALIZE);\r
 \r
   Snp->Cdb.CPBaddr    = (UINT64)(UINTN) Snp->Cpb;\r
   Snp->Cdb.DBaddr     = (UINT64)(UINTN) Snp->Db;\r
@@ -228,7 +229,10 @@ SnpUndi32Initialize (
   //\r
   Snp->TxRxBufferSize = (UINT32) (Snp->InitInfo.MemoryRequired + ExtraRxBufferSize + ExtraTxBufferSize);\r
 \r
-  if (Snp->Mode.MediaPresentSupported) {\r
+  //\r
+  // If UNDI support cable detect for INITIALIZE command, try it first.\r
+  //\r
+  if (Snp->CableDetectSupported) {\r
     if (PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) == EFI_SUCCESS) {\r
       Snp->Mode.MediaPresent = TRUE;\r
       goto ON_EXIT;\r
@@ -241,6 +245,14 @@ SnpUndi32Initialize (
 \r
   if (EFI_ERROR (EfiStatus)) {\r
     gBS->CloseEvent (Snp->Snp.WaitForPacket);\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  //\r
+  // Try to update the MediaPresent field of EFI_SIMPLE_NETWORK_MODE if the UNDI support it.\r
+  //\r
+  if (Snp->MediaStatusSupported) {\r
+    PxeGetStatus (Snp, NULL, FALSE);\r
   }\r
 \r
 ON_EXIT:\r