From 216f79703b8cb8dc65abdd768bedb2bcdbc1a1f8 Mon Sep 17 00:00:00 2001 From: sfu5 Date: Thu, 13 Dec 2012 06:47:06 +0000 Subject: 1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support. 2. Fix the driver binding Stop() hang issue in the network stack. 3. Add Ip4 raw data support. 4. Add iSCSI Dhcp option 60 support. Signed-off-by: Fu Siyuan Reviewed-by: Ye Ting Reviewed-by: Ouyang Qian git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13995 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Universal/Network/MnpDxe/ComponentName.c | 171 ++++++++++++++++++++- .../Universal/Network/MnpDxe/ComponentName.h | 3 +- MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c | 61 +++++--- MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c | 86 ++++++++--- MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.h | 8 +- 5 files changed, 284 insertions(+), 45 deletions(-) (limited to 'MdeModulePkg/Universal/Network/MnpDxe') diff --git a/MdeModulePkg/Universal/Network/MnpDxe/ComponentName.c b/MdeModulePkg/Universal/Network/MnpDxe/ComponentName.c index c56ad061e1..9e66dc254b 100644 --- a/MdeModulePkg/Universal/Network/MnpDxe/ComponentName.c +++ b/MdeModulePkg/Universal/Network/MnpDxe/ComponentName.c @@ -1,7 +1,7 @@ /** @file UEFI Component Name(2) protocol implementation for MnpDxe driver. -Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2012, 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 @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ -#include "MnpDriver.h" +#include "MnpImpl.h" // // EFI Component Name Protocol @@ -44,6 +44,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mMnpDriverNameTable[ } }; +GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gMnpControllerNameTable = NULL; + /** Retrieves a Unicode string that is the user readable name of the driver. @@ -100,6 +102,106 @@ MnpComponentNameGetDriverName ( ); } +/** + Update the component name for the MNP child handle. + + @param Mnp[in] A pointer to the EFI_MANAGED_NETWORK_PROTOCOL. + + + @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully. + @retval EFI_INVALID_PARAMETER The input parameter is invalid. + +**/ +EFI_STATUS +UpdateName ( + IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp + ) +{ + EFI_STATUS Status; + MNP_INSTANCE_DATA *Instance; + CHAR16 HandleName[80]; + EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData; + EFI_SIMPLE_NETWORK_MODE SnpModeData; + UINTN OffSet; + UINTN Index; + + if (Mnp == NULL) { + return EFI_INVALID_PARAMETER; + } + + Instance = MNP_INSTANCE_DATA_FROM_THIS (Mnp); + // + // Format the child name into the string buffer as: + // MNP (MAC=FF-FF-FF-FF-FF-FF, ProtocolType=0x0800, VlanId=0) + // + Status = Mnp->GetModeData (Mnp, &MnpConfigData, &SnpModeData); + if (!EFI_ERROR (Status)) { + OffSet = 0; + // + // Print the MAC address. + // + OffSet += UnicodeSPrint ( + HandleName, + sizeof (HandleName), + L"MNP (MAC=" + ); + for (Index = 0; Index < SnpModeData.HwAddressSize; Index++) { + OffSet += UnicodeSPrint ( + HandleName + OffSet, + sizeof (HandleName) - OffSet, + L"%02X-", + SnpModeData.CurrentAddress.Addr[Index] + ); + } + // + // Remove the last '-' + // + OffSet--; + // + // Print the ProtocolType and VLAN ID for this instance. + // + OffSet += UnicodeSPrint ( + HandleName + OffSet, + sizeof (HandleName) - OffSet, + L", ProtocolType=0x%X, VlanId=%d)", + MnpConfigData.ProtocolTypeFilter, + Instance->MnpServiceData->VlanId + ); + } else if (Status == EFI_NOT_STARTED) { + UnicodeSPrint ( + HandleName, + sizeof (HandleName), + L"MNP (Not started)" + ); + } else { + return Status; + } + + if (gMnpControllerNameTable != NULL) { + FreeUnicodeStringTable (gMnpControllerNameTable); + gMnpControllerNameTable = NULL; + } + + Status = AddUnicodeString2 ( + "eng", + gMnpComponentName.SupportedLanguages, + &gMnpControllerNameTable, + HandleName, + TRUE + ); + if (EFI_ERROR (Status)) { + return Status; + } + + return AddUnicodeString2 ( + "en", + gMnpComponentName2.SupportedLanguages, + &gMnpControllerNameTable, + HandleName, + FALSE + ); +} + /** Retrieves a Unicode string that is the user readable name of the controller that is being managed by a driver. @@ -178,5 +280,68 @@ MnpComponentNameGetControllerName ( OUT CHAR16 **ControllerName ) { - return EFI_UNSUPPORTED; + EFI_STATUS Status; + EFI_MANAGED_NETWORK_PROTOCOL *Mnp; + + // + // Only provide names for MNP child handles. + // + if (ChildHandle == NULL) { + return EFI_UNSUPPORTED; + } + + // + // Make sure this driver is currently managing ControllerHandle + // + Status = EfiTestManagedDevice ( + ControllerHandle, + gMnpDriverBinding.DriverBindingHandle, + &gEfiSimpleNetworkProtocolGuid + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Make sure this driver produced ChildHandle + // + Status = EfiTestChildHandle ( + ControllerHandle, + ChildHandle, + &gEfiManagedNetworkServiceBindingProtocolGuid + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Retrieve an instance of a produced protocol from ChildHandle + // + Status = gBS->OpenProtocol ( + ChildHandle, + &gEfiManagedNetworkProtocolGuid, + (VOID **)&Mnp, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Update the component name for this child handle. + // + Status = UpdateName (Mnp); + if (EFI_ERROR (Status)) { + return Status; + } + + return LookupUnicodeString2 ( + Language, + This->SupportedLanguages, + gMnpControllerNameTable, + ControllerName, + (BOOLEAN)(This == &gMnpComponentName) + ); } diff --git a/MdeModulePkg/Universal/Network/MnpDxe/ComponentName.h b/MdeModulePkg/Universal/Network/MnpDxe/ComponentName.h index 6f60ef7e69..6232c3e1ed 100644 --- a/MdeModulePkg/Universal/Network/MnpDxe/ComponentName.h +++ b/MdeModulePkg/Universal/Network/MnpDxe/ComponentName.h @@ -1,7 +1,7 @@ /** @file The header file of UEFI Component Name(2) protocol. -Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2012, 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 @@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. extern EFI_COMPONENT_NAME2_PROTOCOL gMnpComponentName2; extern EFI_COMPONENT_NAME_PROTOCOL gMnpComponentName; +extern EFI_UNICODE_STRING_TABLE *gMnpControllerNameTable; /** Retrieves a Unicode string that is the user readable name of the driver. diff --git a/MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c b/MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c index c19c71b411..9586db7a2e 100644 --- a/MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c +++ b/MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c @@ -1,7 +1,7 @@ /** @file Implementation of Managed Network Protocol private services. -Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2012, 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 @@ -45,7 +45,6 @@ EFI_MANAGED_NETWORK_CONFIG_DATA mMnpDefaultConfigData = { FALSE }; - /** Add Count of net buffers to MnpDeviceData->FreeNbufQue. The length of the net buffer is specified by MnpDeviceData->BufferLength. @@ -686,6 +685,30 @@ MnpDestroyServiceData ( return Status; } +/** + Callback function which provided by user to remove one node in NetDestroyLinkList process. + + @param[in] Entry The entry to be removed. + @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList. + + @retval EFI_SUCCESS The entry has been removed successfully. + @retval Others Fail to remove the entry. + +**/ +EFI_STATUS +MnpDestoryChildEntry ( + IN LIST_ENTRY *Entry, + IN VOID *Context +) +{ + MNP_INSTANCE_DATA *Instance; + EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; + + ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context; + Instance = CR (Entry, MNP_INSTANCE_DATA, InstEntry, MNP_INSTANCE_DATA_SIGNATURE); + return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle); +} + /** Destroy all child of the MNP service data. @@ -700,26 +723,20 @@ MnpDestroyServiceChild ( IN OUT MNP_SERVICE_DATA *MnpServiceData ) { - EFI_STATUS Status; - MNP_INSTANCE_DATA *Instance; - EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; - - ServiceBinding = &MnpServiceData->ServiceBinding; - while (!IsListEmpty (&MnpServiceData->ChildrenList)) { - // - // Don't use NetListRemoveHead here, the remove opreration will be done - // in ServiceBindingDestroyChild. - // - Instance = NET_LIST_HEAD ( - &MnpServiceData->ChildrenList, - MNP_INSTANCE_DATA, - InstEntry - ); - - Status = ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle); - if (EFI_ERROR (Status)) { - return Status; - } + LIST_ENTRY *List; + EFI_STATUS Status; + UINTN ListLength; + + List = &MnpServiceData->ChildrenList; + + Status = NetDestroyLinkList ( + List, + MnpDestoryChildEntry, + &MnpServiceData->ServiceBinding, + &ListLength + ); + if (EFI_ERROR (Status) || ListLength != 0) { + return EFI_DEVICE_ERROR; } return EFI_SUCCESS; diff --git a/MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c b/MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c index 03ddfb7ccc..84c618c27d 100644 --- a/MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c +++ b/MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c @@ -1,7 +1,7 @@ /** @file Implementation of driver entry point and driver binding protocol. -Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2012, 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 @@ -26,6 +26,50 @@ EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = { NULL }; +/** + Callback function which provided by user to remove one node in NetDestroyLinkList process. + + @param[in] Entry The entry to be removed. + @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList. + + @retval EFI_SUCCESS The entry has been removed successfully. + @retval Others Fail to remove the entry. + +**/ +EFI_STATUS +MnpDestroyServiceDataEntry ( + IN LIST_ENTRY *Entry, + IN VOID *Context +) +{ + MNP_SERVICE_DATA *MnpServiceData; + + MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry); + return MnpDestroyServiceData (MnpServiceData); +} + +/** + Callback function which provided by user to remove one node in NetDestroyLinkList process. + + @param[in] Entry The entry to be removed. + @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList. + + @retval EFI_SUCCESS The entry has been removed successfully. + @retval Others Fail to remove the entry. + +**/ +EFI_STATUS +MnpDestroyServiceChildEntry ( + IN LIST_ENTRY *Entry, + IN VOID *Context +) +{ + MNP_SERVICE_DATA *MnpServiceData; + + MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry); + return MnpDestroyServiceChild (MnpServiceData); +} + /** Test to see if this driver supports ControllerHandle. This service is called by the EFI boot service ConnectController(). In @@ -276,8 +320,8 @@ MnpDriverBindingStop ( EFI_VLAN_CONFIG_PROTOCOL *VlanConfig; MNP_DEVICE_DATA *MnpDeviceData; MNP_SERVICE_DATA *MnpServiceData; - BOOLEAN AllChildrenStopped; - LIST_ENTRY *Entry; + LIST_ENTRY *List; + UINTN ListLength; // // Try to retrieve MNP service binding protocol from the ControllerHandle @@ -317,10 +361,15 @@ MnpDriverBindingStop ( // // Destroy all MNP service data // - while (!IsListEmpty (&MnpDeviceData->ServiceList)) { - Entry = GetFirstNode (&MnpDeviceData->ServiceList); - MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry); - MnpDestroyServiceData (MnpServiceData); + List = &MnpDeviceData->ServiceList; + Status = NetDestroyLinkList ( + List, + MnpDestroyServiceDataEntry, + NULL, + &ListLength + ); + if (EFI_ERROR (Status) || ListLength !=0) { + return EFI_DEVICE_ERROR; } // @@ -341,23 +390,24 @@ MnpDriverBindingStop ( MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle); FreePool (MnpDeviceData); + if (gMnpControllerNameTable != NULL) { + FreeUnicodeStringTable (gMnpControllerNameTable); + gMnpControllerNameTable = NULL; + } return EFI_SUCCESS; } // // Stop all MNP child // - AllChildrenStopped = TRUE; - NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) { - MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry); - - Status = MnpDestroyServiceChild (MnpServiceData); - if (EFI_ERROR (Status)) { - AllChildrenStopped = FALSE; - } - } - - if (!AllChildrenStopped) { + List = &MnpDeviceData->ServiceList; + Status = NetDestroyLinkList ( + List, + MnpDestroyServiceChildEntry, + NULL, + &ListLength + ); + if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } diff --git a/MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.h b/MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.h index f096862485..35a9b710db 100644 --- a/MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.h +++ b/MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.h @@ -1,7 +1,7 @@ /** @file Declaration of strctures and functions for MnpDxe driver. -Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2012, 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 @@ -33,11 +33,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include "ComponentName.h" #define MNP_DEVICE_DATA_SIGNATURE SIGNATURE_32 ('M', 'n', 'p', 'D') +// +// Global Variables +// +extern EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding; + typedef struct { UINT32 Signature; -- cgit v1.2.3