X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FSnpDxe%2FInitialize.c;h=4d33154241361f52ada732829f125d59b5ace469;hp=43b517e9e6c1360640a6e831fba894f162fd47b8;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=f381602727922e793de5826ee390344cb907e07a diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Initialize.c b/MdeModulePkg/Universal/Network/SnpDxe/Initialize.c index 43b517e9e6..4d33154241 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Initialize.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Initialize.c @@ -1,14 +1,8 @@ /** @file - Implementation of initializing a network adapter. + Implementation of initializing a network adapter. -Copyright (c) 2004 - 2008, Intel Corporation.
-All rights reserved. This program and the accompanying materials are licensed -and made available under the terms and conditions of the BSD License which -accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -19,9 +13,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Call UNDI to initialize the interface. @param Snp Pointer to snp driver structure. - @param CableDetectFlag Do/don't detect the cable (depending on what + @param CableDetectFlag Do/don't detect the cable (depending on what undi supports). - + @retval EFI_SUCCESS UNDI is initialized successfully. @retval EFI_DEVICE_ERROR UNDI could not be initialized. @retval Other Other errors as indicated. @@ -37,6 +31,8 @@ PxeInit ( VOID *Addr; EFI_STATUS Status; + Status = EFI_SUCCESS; + Cpb = Snp->Cpb; if (Snp->TxRxBufferSize != 0) { Status = Snp->PciIo->AllocateBuffer ( @@ -84,8 +80,8 @@ PxeInit ( Snp->Cdb.OpCode = PXE_OPCODE_INITIALIZE; Snp->Cdb.OpFlags = CableDetectFlag; - Snp->Cdb.CPBsize = sizeof (PXE_CPB_INITIALIZE); - Snp->Cdb.DBsize = sizeof (PXE_DB_INITIALIZE); + Snp->Cdb.CPBsize = (UINT16) sizeof (PXE_CPB_INITIALIZE); + Snp->Cdb.DBsize = (UINT16) sizeof (PXE_DB_INITIALIZE); Snp->Cdb.CPBaddr = (UINT64)(UINTN) Snp->Cpb; Snp->Cdb.DBaddr = (UINT64)(UINTN) Snp->Db; @@ -95,17 +91,37 @@ PxeInit ( Snp->Cdb.IFnum = Snp->IfNum; Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; - DEBUG ((EFI_D_INFO | EFI_D_NET, "\nSnp->undi.initialize() ")); + DEBUG ((EFI_D_NET, "\nSnp->undi.initialize() ")); (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (Snp->Cdb.StatCode == PXE_STATCODE_SUCCESS) { - Snp->Mode.State = EfiSimpleNetworkInitialized; + // + // There are two fields need to be checked here: + // First is the upper two bits (14 & 15) in the CDB.StatFlags field. Until these bits change to report + // PXE_STATFLAGS_COMMAND_COMPLETE or PXE_STATFLAGS_COMMAND_FAILED, the command has not been executed by the UNDI. + // Second is the CDB.StatCode field. After command execution completes, either successfully or not, + // the CDB.StatCode field contains the result of the command execution. + // + if ((((Snp->Cdb.StatFlags) & PXE_STATFLAGS_STATUS_MASK) == PXE_STATFLAGS_COMMAND_COMPLETE) && + (Snp->Cdb.StatCode == PXE_STATCODE_SUCCESS)) { + // + // If cable detect feature is enabled in CDB.OpFlags, check the CDB.StatFlags to see if there is an + // active connection to this network device. If the no media StatFlag is set, the UNDI and network + // device are still initialized. + // + if (CableDetectFlag == PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) { + if(((Snp->Cdb.StatFlags) & PXE_STATFLAGS_INITIALIZED_NO_MEDIA) != PXE_STATFLAGS_INITIALIZED_NO_MEDIA) { + Snp->Mode.MediaPresent = TRUE; + } else { + Snp->Mode.MediaPresent = FALSE; + } + } - Status = EFI_SUCCESS; + Snp->Mode.State = EfiSimpleNetworkInitialized; + Status = EFI_SUCCESS; } else { DEBUG ( - (EFI_D_ERROR, + (EFI_D_WARN, "\nSnp->undi.initialize() %xh:%xh\n", Snp->Cdb.StatFlags, Snp->Cdb.StatCode) @@ -129,8 +145,8 @@ PxeInit ( /** - Resets a network adapter and allocates the transmit and receive buffers - required by the network interface; optionally, also requests allocation of + Resets a network adapter and allocates the transmit and receive buffers + required by the network interface; optionally, also requests allocation of additional transmit and receive buffers. This function allocates the transmit and receive buffers required by the network @@ -142,8 +158,8 @@ PxeInit ( @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space that the driver should allocate for the network interface. - Some network interfaces will not be able to use the - extra buffer, and the caller will not know if it is + Some network interfaces will not be able to use the + extra buffer, and the caller will not know if it is actually being used. @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space that the driver should allocate for the network interface. @@ -229,9 +245,11 @@ SnpUndi32Initialize ( // Snp->TxRxBufferSize = (UINT32) (Snp->InitInfo.MemoryRequired + ExtraRxBufferSize + ExtraTxBufferSize); - if (Snp->Mode.MediaPresentSupported) { + // + // If UNDI support cable detect for INITIALIZE command, try it first. + // + if (Snp->CableDetectSupported) { if (PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) == EFI_SUCCESS) { - Snp->Mode.MediaPresent = TRUE; goto ON_EXIT; } } @@ -242,6 +260,14 @@ SnpUndi32Initialize ( if (EFI_ERROR (EfiStatus)) { gBS->CloseEvent (Snp->Snp.WaitForPacket); + goto ON_EXIT; + } + + // + // Try to update the MediaPresent field of EFI_SIMPLE_NETWORK_MODE if the UNDI support it. + // + if (Snp->MediaStatusSupported) { + PxeGetStatus (Snp, NULL, FALSE); } ON_EXIT: