]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/Initialize.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Initialize.c
index 21513752de05645b874fae98211abe2c78987c81..4d33154241361f52ada732829f125d59b5ace469 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
 /** @file\r
-               Implementation of initializing a network adapter.\r
+     Implementation of initializing a network adapter.\r
 \r
 \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
-\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
 \r
 **/\r
 \r
@@ -19,9 +13,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   Call UNDI to initialize the interface.\r
 \r
   @param  Snp                   Pointer to snp driver structure.\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 \r
+  @param  CableDetectFlag       Do/don't detect the cable (depending on what\r
                                 undi supports).\r
                                 undi supports).\r
-  \r
+\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
   @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
@@ -37,6 +31,8 @@ PxeInit (
   VOID                *Addr;\r
   EFI_STATUS          Status;\r
 \r
   VOID                *Addr;\r
   EFI_STATUS          Status;\r
 \r
+  Status = EFI_SUCCESS;\r
+\r
   Cpb = Snp->Cpb;\r
   if (Snp->TxRxBufferSize != 0) {\r
     Status = Snp->PciIo->AllocateBuffer (\r
   Cpb = Snp->Cpb;\r
   if (Snp->TxRxBufferSize != 0) {\r
     Status = Snp->PciIo->AllocateBuffer (\r
@@ -99,10 +95,30 @@ PxeInit (
 \r
   (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);\r
 \r
 \r
   (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);\r
 \r
-  if (Snp->Cdb.StatCode == PXE_STATCODE_SUCCESS) {\r
-    Snp->Mode.State = EfiSimpleNetworkInitialized;\r
+  //\r
+  // There are two fields need to be checked here:\r
+  // First is the upper two bits (14 & 15) in the CDB.StatFlags field. Until these bits change to report\r
+  // PXE_STATFLAGS_COMMAND_COMPLETE or PXE_STATFLAGS_COMMAND_FAILED, the command has not been executed by the UNDI.\r
+  // Second is the CDB.StatCode field. After command execution completes, either successfully or not,\r
+  // the CDB.StatCode field contains the result of the command execution.\r
+  //\r
+  if ((((Snp->Cdb.StatFlags) & PXE_STATFLAGS_STATUS_MASK) == PXE_STATFLAGS_COMMAND_COMPLETE) &&\r
+      (Snp->Cdb.StatCode == PXE_STATCODE_SUCCESS)) {\r
+    //\r
+    // If cable detect feature is enabled in CDB.OpFlags, check the CDB.StatFlags to see if there is an\r
+    // active connection to this network device. If the no media StatFlag is set, the UNDI and network\r
+    // device are still initialized.\r
+    //\r
+    if (CableDetectFlag == PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) {\r
+      if(((Snp->Cdb.StatFlags) & PXE_STATFLAGS_INITIALIZED_NO_MEDIA) != PXE_STATFLAGS_INITIALIZED_NO_MEDIA) {\r
+        Snp->Mode.MediaPresent = TRUE;\r
+      } else {\r
+        Snp->Mode.MediaPresent = FALSE;\r
+      }\r
+    }\r
 \r
 \r
-    Status          = EFI_SUCCESS;\r
+    Snp->Mode.State   = EfiSimpleNetworkInitialized;\r
+    Status            = EFI_SUCCESS;\r
   } else {\r
     DEBUG (\r
       (EFI_D_WARN,\r
   } else {\r
     DEBUG (\r
       (EFI_D_WARN,\r
@@ -129,8 +145,8 @@ PxeInit (
 \r
 \r
 /**\r
 \r
 \r
 /**\r
-  Resets a network adapter and allocates the transmit and receive buffers \r
-  required by the network interface; optionally, also requests allocation of \r
+  Resets a network adapter and allocates the transmit and receive buffers\r
+  required by the network interface; optionally, also requests allocation of\r
   additional transmit and receive buffers.\r
 \r
   This function allocates the transmit and receive buffers required by the network\r
   additional transmit and receive buffers.\r
 \r
   This function allocates the transmit and receive buffers required by the network\r
@@ -142,8 +158,8 @@ PxeInit (
 \r
   @param ExtraRxBufferSize  The size, in bytes, of the extra receive buffer space\r
                             that the driver should allocate for the network interface.\r
 \r
   @param ExtraRxBufferSize  The size, in bytes, of the extra receive buffer space\r
                             that the driver should allocate for the network interface.\r
-                            Some network interfaces will not be able to use the \r
-                            extra buffer, and the caller will not know if it is \r
+                            Some network interfaces will not be able to use the\r
+                            extra buffer, and the caller will not know if it is\r
                             actually being used.\r
   @param ExtraTxBufferSize  The size, in bytes, of the extra transmit buffer space\r
                             that the driver should allocate for the network interface.\r
                             actually being used.\r
   @param ExtraTxBufferSize  The size, in bytes, of the extra transmit buffer space\r
                             that the driver should allocate for the network interface.\r
@@ -234,7 +250,6 @@ SnpUndi32Initialize (
   //\r
   if (Snp->CableDetectSupported) {\r
     if (PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) == EFI_SUCCESS) {\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
     }\r
   }\r
       goto ON_EXIT;\r
     }\r
   }\r