X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FArpDxe%2FArpDriver.c;h=632d691d75886b5d4f2c24262059d1d93bc93cc4;hp=d01451b951e833898b6ad54a21c5f671a3ceb0c5;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=e5eed7d3641d71d7ea539e5379ea9c6a5cd97004 diff --git a/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c b/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c index d01451b951..632d691d75 100644 --- a/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c +++ b/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c @@ -1,14 +1,8 @@ /** @file ARP driver functions. - -Copyright (c) 2006 - 2009, 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) 2006 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -35,7 +29,7 @@ EFI_DRIVER_BINDING_PROTOCOL gArpDriverBinding = { context data. @retval EFI_SUCCESS The arp service context is initialized. - + @retval EFI_UNSUPPORTED The underlayer Snp mode type is not ethernet. Failed to initialize the service context. @retval other Failed to initialize the arp service context. @@ -54,6 +48,14 @@ ArpCreateService ( ArpService->Signature = ARP_SERVICE_DATA_SIGNATURE; + // + // Init the lists. + // + InitializeListHead (&ArpService->ChildrenList); + InitializeListHead (&ArpService->PendingRequestTable); + InitializeListHead (&ArpService->DeniedCacheTable); + InitializeListHead (&ArpService->ResolvedCacheTable); + // // Init the servicebinding protocol members. // @@ -168,17 +170,6 @@ ArpCreateService ( TimerPeriodic, ARP_PERIODIC_TIMER_INTERVAL ); - if (EFI_ERROR (Status)) { - goto ERROR_EXIT; - } - - // - // Init the lists. - // - InitializeListHead (&ArpService->ChildrenList); - InitializeListHead (&ArpService->PendingRequestTable); - InitializeListHead (&ArpService->DeniedCacheTable); - InitializeListHead (&ArpService->ResolvedCacheTable); ERROR_EXIT: @@ -245,31 +236,61 @@ ArpCleanService ( } /** - Tests to see if this driver supports a given controller. - - If a child device is provided, it further tests to see if this driver supports + 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 +EFIAPI +ArpDestroyChildEntryInHandleBuffer ( + IN LIST_ENTRY *Entry, + IN VOID *Context + ) +{ + ARP_INSTANCE_DATA *Instance; + EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; + + if (Entry == NULL || Context == NULL) { + return EFI_INVALID_PARAMETER; + } + + Instance = NET_LIST_USER_STRUCT_S (Entry, ARP_INSTANCE_DATA, List, ARP_INSTANCE_DATA_SIGNATURE); + ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context; + + return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle); +} + +/** + Tests to see if this driver supports a given controller. + + If a child device is provided, it further tests to see if this driver supports creating a handle for the specified child device. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. - @param[in] ControllerHandle The handle of the controller to test. This handle - must support a protocol interface that supplies + @param[in] ControllerHandle The handle of the controller to test. This handle + must support a protocol interface that supplies an I/O abstraction to the driver. - @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. - This parameter is ignored by device drivers, + @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. + This parameter is ignored by device drivers, and is optional for bus drivers. @retval EFI_SUCCESS The device specified by ControllerHandle and - RemainingDevicePath is supported by the driver + RemainingDevicePath is supported by the driver specified by This. @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and - RemainingDevicePath is already being managed + RemainingDevicePath is already being managed by the driver specified by This. @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and - RemainingDevicePath is already being managed by - a different driver or an application that + RemainingDevicePath is already being managed by + a different driver or an application that requires exclusive acces. Currently not implemented. @retval EFI_UNSUPPORTED The device specified by ControllerHandle and - RemainingDevicePath is not supported by the + RemainingDevicePath is not supported by the driver specified by This. **/ @@ -315,32 +336,32 @@ ArpDriverBindingSupported ( /** - Start this driver on ControllerHandle. - - The Start() function is designed to be invoked from the EFI boot service ConnectController(). - As a result, much of the error checking on the parameters to Start() has been - moved into this common boot service. It is legal to call Start() from other locations, - but the following calling restrictions must be followed or the system behavior + Start this driver on ControllerHandle. + + The Start() function is designed to be invoked from the EFI boot service ConnectController(). + As a result, much of the error checking on the parameters to Start() has been + moved into this common boot service. It is legal to call Start() from other locations, + but the following calling restrictions must be followed or the system behavior will not be deterministic. 1. ControllerHandle must be a valid EFI_HANDLE. - 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally + 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned EFI_DEVICE_PATH_PROTOCOL. - 3. Prior to calling Start(), the Supported() function for the driver specified - by This must have been called with the same calling parameters, and Supported() - must have returned EFI_SUCCESS. + 3. Prior to calling Start(), the Supported() function for the driver specified + by This must have been called with the same calling parameters, and Supported() + must have returned EFI_SUCCESS. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. - @param[in] ControllerHandle The handle of the controller to start. This handle - must support a protocol interface that supplies + @param[in] ControllerHandle The handle of the controller to start. This handle + must support a protocol interface that supplies an I/O abstraction to the driver. - @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. - This parameter is ignored by device drivers, + @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. + This parameter is ignored by device drivers, and is optional for bus drivers. @retval EFI_SUCCESS The device was started. @retval EFI_DEVICE_ERROR The device could not be started due to a device error. Currently not implemented. - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. @retval Others The driver failded to start the device. @@ -408,13 +429,13 @@ ERROR: /** - Stop this driver on ControllerHandle. - + Stop this driver on ControllerHandle. + Release the control of this controller and remove the IScsi functions. The Stop() - function is designed to be invoked from the EFI boot service DisconnectController(). - As a result, much of the error checking on the parameters to Stop() has been moved - into this common boot service. It is legal to call Stop() from other locations, - but the following calling restrictions must be followed or the system behavior + function is designed to be invoked from the EFI boot service DisconnectController(). + As a result, much of the error checking on the parameters to Stop() has been moved + into this common boot service. It is legal to call Stop() from other locations, + but the following calling restrictions must be followed or the system behavior will not be deterministic. 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this same driver's Start() function. @@ -422,14 +443,14 @@ ERROR: EFI_HANDLE. In addition, all of these handles must have been created in this driver's Start() function, and the Start() function must have called OpenProtocol() on ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER. - + @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. - @param[in] ControllerHandle A handle to the device being stopped. The handle must - support a bus specific I/O protocol for the driver + @param[in] ControllerHandle A handle to the device being stopped. The handle must + support a bus specific I/O protocol for the driver to use to stop the device. @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer. Not used. - @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL + @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL if NumberOfChildren is 0.Not used. @retval EFI_SUCCESS The device was stopped. @@ -449,14 +470,14 @@ ArpDriverBindingStop ( EFI_HANDLE NicHandle; EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding; ARP_SERVICE_DATA *ArpService; - ARP_INSTANCE_DATA *Instance; + LIST_ENTRY *List; // // Get the NicHandle which the arp servicebinding is installed on. // NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiManagedNetworkProtocolGuid); if (NicHandle == NULL) { - return EFI_DEVICE_ERROR; + return EFI_SUCCESS; } // @@ -477,7 +498,21 @@ ArpDriverBindingStop ( ArpService = ARP_SERVICE_DATA_FROM_THIS (ServiceBinding); - if (NumberOfChildren == 0) { + if (NumberOfChildren != 0) { + // + // NumberOfChildren is not zero, destroy all the ARP children instances. + // + List = &ArpService->ChildrenList; + Status = NetDestroyLinkList ( + List, + ArpDestroyChildEntryInHandleBuffer, + ServiceBinding, + NULL + ); + ASSERT (IsListEmpty (&ArpService->PendingRequestTable)); + ASSERT (IsListEmpty (&ArpService->DeniedCacheTable)); + ASSERT (IsListEmpty (&ArpService->ResolvedCacheTable)); + } else if (IsListEmpty (&ArpService->ChildrenList)) { // // Uninstall the ARP ServiceBinding protocol. // @@ -494,17 +529,6 @@ ArpDriverBindingStop ( ArpCleanService (ArpService); FreePool (ArpService); - } else { - - while (!IsListEmpty (&ArpService->ChildrenList)) { - Instance = NET_LIST_HEAD (&ArpService->ChildrenList, ARP_INSTANCE_DATA, List); - - ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle); - } - - ASSERT (IsListEmpty (&ArpService->PendingRequestTable)); - ASSERT (IsListEmpty (&ArpService->DeniedCacheTable)); - ASSERT (IsListEmpty (&ArpService->ResolvedCacheTable)); } return EFI_SUCCESS; @@ -512,20 +536,20 @@ ArpDriverBindingStop ( /** Creates a child handle and installs a protocol. - - The CreateChild() function installs a protocol on ChildHandle. - If ChildHandle is a pointer to NULL, then a new handle is created and returned - in ChildHandle. If ChildHandle is not a pointer to NULL, then the protocol + + The CreateChild() function installs a protocol on ChildHandle. + If ChildHandle is a pointer to NULL, then a new handle is created and returned + in ChildHandle. If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance. @param ChildHandle Pointer to the handle of the child to create. If it is NULL, - then a new handle is created. If it is a pointer to an existing + then a new handle is created. If it is a pointer to an existing UEFI handle, then the protocol is added to the existing UEFI handle. @retval EFI_SUCCES The protocol was added to ChildHandle. @retval EFI_INVALID_PARAMETER ChildHandle is NULL. - @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create + @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create the child @retval other The child handle was not created @@ -640,18 +664,18 @@ ERROR: /** Destroys a child handle with a protocol installed on it. - - The DestroyChild() function does the opposite of CreateChild(). It removes a protocol - that was installed by CreateChild() from ChildHandle. If the removed protocol is the + + The DestroyChild() function does the opposite of CreateChild(). It removes a protocol + that was installed by CreateChild() from ChildHandle. If the removed protocol is the last protocol on ChildHandle, then ChildHandle is destroyed. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance. @param ChildHandle Handle of the child to destroy @retval EFI_SUCCES The protocol was removed from ChildHandle. - @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is + @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed. - @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle. + @retval EFI_INVALID_PARAMETER Child handle is NULL. @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle because its services are being used. @retval other The child handle was not destroyed @@ -693,14 +717,14 @@ ArpServiceBindingDestroyChild ( Instance = ARP_INSTANCE_DATA_FROM_THIS (Arp); - if (Instance->Destroyed) { + if (Instance->InDestroy) { return EFI_SUCCESS; } // - // Use the Destroyed as a flag to avoid re-entrance. + // Use the InDestroy as a flag to avoid re-entrance. // - Instance->Destroyed = TRUE; + Instance->InDestroy = TRUE; // // Close the Managed Network protocol. @@ -725,7 +749,7 @@ ArpServiceBindingDestroyChild ( DEBUG ((EFI_D_ERROR, "ArpSBDestroyChild: Failed to uninstall the arp protocol, %r.\n", Status)); - Instance->Destroyed = FALSE; + Instance->InDestroy = FALSE; return Status; } @@ -763,7 +787,7 @@ ArpServiceBindingDestroyChild ( @param[in] ImageHandle The image handle of the driver. @param[in] SystemTable The system table. - @retval EFI_SUCCESS if the driver binding and component name protocols + @retval EFI_SUCCESS if the driver binding and component name protocols are successfully @retval Others Failed to install the protocols.