X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4Dxe%2FIp4Driver.c;h=85cc6afb50fc876d313afaf930169cd6f5cf0889;hp=0d308c05211c98867622e060eb6cbbd181031f47;hb=e48e37fce2611df7a52aff271835ff72ee396d9b;hpb=83cbd279b64f3081af5c06d50fa26e15a99fc066 diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c index 0d308c0521..85cc6afb50 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c @@ -161,7 +161,7 @@ Ip4CreateService ( // empty resources, so if any thing goes wrong when allocating // resources, Ip4CleanService can be called to clean it up. // - IpSb = NetAllocatePool (sizeof (IP4_SERVICE)); + IpSb = AllocatePool (sizeof (IP4_SERVICE)); if (IpSb == NULL) { return EFI_OUT_OF_RESOURCES; @@ -174,16 +174,16 @@ Ip4CreateService ( IpSb->InDestory = FALSE; IpSb->NumChildren = 0; - NetListInit (&IpSb->Children); + InitializeListHead (&IpSb->Children); - NetListInit (&IpSb->Interfaces); + InitializeListHead (&IpSb->Interfaces); IpSb->DefaultInterface = NULL; IpSb->DefaultRouteTable = NULL; Ip4InitAssembleTable (&IpSb->Assemble); IpSb->IgmpCtrl.Igmpv1QuerySeen = 0; - NetListInit (&IpSb->IgmpCtrl.Groups); + InitializeListHead (&IpSb->IgmpCtrl.Groups); IpSb->Image = ImageHandle; IpSb->Controller = Controller; @@ -202,12 +202,13 @@ Ip4CreateService ( IpSb->MnpConfigData.EnableReceiveTimestamps = FALSE; IpSb->MnpConfigData.DisableBackgroundPolling = FALSE; - NetZeroMem (&IpSb->SnpMode, sizeof (EFI_SIMPLE_NETWORK_MODE)); + ZeroMem (&IpSb->SnpMode, sizeof (EFI_SIMPLE_NETWORK_MODE)); IpSb->Timer = NULL; IpSb->Ip4Config = NULL; IpSb->DoneEvent = NULL; IpSb->ReconfigEvent = NULL; + IpSb->ActiveEvent = NULL; // // Create various resources. First create the route table, timer @@ -282,7 +283,7 @@ Ip4CreateService ( goto ON_ERROR; } - NetListInsertHead (&IpSb->Interfaces, &IpSb->DefaultInterface->Link); + InsertHeadList (&IpSb->Interfaces, &IpSb->DefaultInterface->Link); IpSb->MacString = NULL; @@ -291,7 +292,7 @@ Ip4CreateService ( ON_ERROR: Ip4CleanService (IpSb); - NetFreePool (IpSb); + gBS->FreePool (IpSb); return Status; } @@ -375,6 +376,7 @@ Ip4CleanService ( gBS->CloseEvent (IpSb->DoneEvent); gBS->CloseEvent (IpSb->ReconfigEvent); + IpSb->ActiveEvent = NULL; IpSb->Ip4Config = NULL; } @@ -475,7 +477,7 @@ UNINSTALL_PROTOCOL: FREE_SERVICE: Ip4CleanService (IpSb); - NetFreePool (IpSb); + gBS->FreePool (IpSb); return Status; } @@ -510,6 +512,7 @@ Ip4DriverBindingStop ( EFI_STATUS Status; EFI_TPL OldTpl; INTN State; + BOOLEAN IsArp; // // IP4 driver opens the MNP child, ARP children or the IP4_CONFIG protocol @@ -547,12 +550,12 @@ Ip4DriverBindingStop ( ); if (EFI_ERROR (Status)) { - return EFI_SUCCESS; + return EFI_DEVICE_ERROR; } IpSb = IP4_SERVICE_FROM_PROTOCOL (ServiceBinding); - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (IpSb->Ip4Config && (IpSb->State != IP4_SERVICE_DESTORY)) { @@ -566,7 +569,7 @@ Ip4DriverBindingStop ( ); if (EFI_ERROR (Status)) { - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; } @@ -582,7 +585,7 @@ Ip4DriverBindingStop ( gBS->CloseEvent (IpSb->ReconfigEvent); } - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return EFI_SUCCESS; } @@ -592,14 +595,16 @@ Ip4DriverBindingStop ( // service binding is installed on the NIC handle. So, need to open // the protocol info to find the NIC handle. // + IsArp = FALSE; NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiManagedNetworkProtocolGuid); if (NicHandle == NULL) { NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiArpProtocolGuid); + IsArp = TRUE; } if (NicHandle == NULL) { - return EFI_SUCCESS; + return EFI_DEVICE_ERROR; } // @@ -620,70 +625,96 @@ Ip4DriverBindingStop ( IpSb = IP4_SERVICE_FROM_PROTOCOL (ServiceBinding); - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (IpSb->InDestory) { - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return EFI_SUCCESS; } - IpSb->InDestory = TRUE; + if (IsArp) { + while (!IsListEmpty (&IpSb->Children)) { + IpInstance = NET_LIST_HEAD (&IpSb->Children, IP4_PROTOCOL, Link); - State = IpSb->State; - IpSb->State = IP4_SERVICE_DESTORY; + ServiceBinding->DestroyChild (ServiceBinding, IpInstance->Handle); + } - // - // Destory all the children first. If not all children are destoried, - // the IP driver can operate correctly, so restore it state. Don't - // use NET_LIST_FOR_EACH_SAFE here, because it will cache the next - // pointer, which may point to the child that has already been destoried. - // For example, if there are two child in the list, the first is UDP - // listen child, the send is the MTFTP's child. When Udp child is - // destoried, it will destory the MTFTP's child. Then Next point to - // a invalid child. - // - while (!NetListIsEmpty (&IpSb->Children)) { - IpInstance = NET_LIST_HEAD (&IpSb->Children, IP4_PROTOCOL, Link); - Ip4ServiceBindingDestroyChild (ServiceBinding, IpInstance->Handle); - } + if (IpSb->NumChildren != 0) { + Status = EFI_DEVICE_ERROR; + goto ON_ERROR; + } - if (IpSb->NumChildren != 0) { - IpSb->State = State; - Status = EFI_DEVICE_ERROR; - goto ON_ERROR; - } + IpSb->InDestory = TRUE; - // - // Clear the variable data. - // - Ip4ClearVariableData (IpSb); + State = IpSb->State; + IpSb->State = IP4_SERVICE_DESTORY; - // - // OK, clean other resources then uninstall the service binding protocol. - // - Status = Ip4CleanService (IpSb); + // + // Clear the variable data. + // + Ip4ClearVariableData (IpSb); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } + // + // OK, clean other resources then uninstall the service binding protocol. + // + Status = Ip4CleanService (IpSb); - Status = gBS->UninstallProtocolInterface ( - NicHandle, - &gEfiIp4ServiceBindingProtocolGuid, - ServiceBinding - ); + if (EFI_ERROR (Status)) { + IpSb->State = State; + goto ON_ERROR; + } - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } + gBS->UninstallProtocolInterface ( + NicHandle, + &gEfiIp4ServiceBindingProtocolGuid, + ServiceBinding + ); - NET_RESTORE_TPL (OldTpl); - NetFreePool (IpSb); - return EFI_SUCCESS; + gBS->FreePool (IpSb); + } else if (NumberOfChildren == 0) { + IpSb->InDestory = TRUE; + + State = IpSb->State; + IpSb->State = IP4_SERVICE_DESTORY; + + // + // Clear the variable data. + // + Ip4ClearVariableData (IpSb); + + // + // OK, clean other resources then uninstall the service binding protocol. + // + Status = Ip4CleanService (IpSb); + + if (EFI_ERROR (Status)) { + IpSb->State = State; + goto ON_ERROR; + } + + gBS->UninstallProtocolInterface ( + NicHandle, + &gEfiIp4ServiceBindingProtocolGuid, + ServiceBinding + ); + + gBS->FreePool (IpSb); + } else { + + while (!IsListEmpty (&IpSb->Children)) { + IpInstance = NET_LIST_HEAD (&IpSb->Children, IP4_PROTOCOL, Link); + + ServiceBinding->DestroyChild (ServiceBinding, IpInstance->Handle); + } + + if (IpSb->NumChildren != 0) { + Status = EFI_DEVICE_ERROR; + } + } ON_ERROR: - IpSb->InDestory = FALSE; - NET_RESTORE_TPL (OldTpl); + + gBS->RestoreTPL (OldTpl); return Status; } @@ -721,7 +752,7 @@ Ip4ServiceBindingCreateChild ( } IpSb = IP4_SERVICE_FROM_PROTOCOL (This); - IpInstance = NetAllocatePool (sizeof (IP4_PROTOCOL)); + IpInstance = AllocatePool (sizeof (IP4_PROTOCOL)); if (IpInstance == NULL) { return EFI_OUT_OF_RESOURCES; @@ -770,12 +801,12 @@ Ip4ServiceBindingCreateChild ( // // Insert it into the service binding instance. // - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - NetListInsertTail (&IpSb->Children, &IpInstance->Link); + InsertTailList (&IpSb->Children, &IpInstance->Link); IpSb->NumChildren++; - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); ON_ERROR: @@ -783,7 +814,7 @@ ON_ERROR: Ip4CleanProtocol (IpInstance); - NetFreePool (IpInstance); + gBS->FreePool (IpInstance); } return Status; @@ -848,7 +879,7 @@ Ip4ServiceBindingDestroyChild ( return EFI_INVALID_PARAMETER; } - OldTpl = NET_RAISE_TPL (NET_TPL_LOCK); + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); // // A child can be destoried more than once. For example, @@ -857,7 +888,7 @@ Ip4ServiceBindingDestroyChild ( // the IP child it opens. // if (IpInstance->State == IP4_STATE_DESTORY) { - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return EFI_SUCCESS; } @@ -913,17 +944,17 @@ Ip4ServiceBindingDestroyChild ( goto ON_ERROR; } - NetListRemoveEntry (&IpInstance->Link); + RemoveEntryList (&IpInstance->Link); IpSb->NumChildren--; - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); - NetFreePool (IpInstance); + gBS->FreePool (IpInstance); return EFI_SUCCESS; ON_ERROR: IpInstance->State = State; - NET_RESTORE_TPL (OldTpl); + gBS->RestoreTPL (OldTpl); return Status; }