X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FArpDxe%2FArpDriver.c;h=632d691d75886b5d4f2c24262059d1d93bc93cc4;hp=c33ce4d98a712b4b171b8f1d8abe44ef3a6db9eb;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=e48e37fce2611df7a52aff271835ff72ee396d9b diff --git a/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c b/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c index c33ce4d98a..632d691d75 100644 --- a/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c +++ b/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c @@ -1,24 +1,11 @@ /** @file + ARP driver functions. -Copyright (c) 2006 - 2007, 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. - -Module Name: - - ArpDriver.c - -Abstract: - +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ - #include "ArpDriver.h" #include "ArpImpl.h" @@ -35,22 +22,24 @@ EFI_DRIVER_BINDING_PROTOCOL gArpDriverBinding = { /** Create and initialize the arp service context data. - @param ImageHandle The image handle representing the loaded driver - image. - @param ControllerHandle The controller handle the driver binds to. - @param ArpService Pointer to the buffer containing the arp service - context data. + @param[in] ImageHandle The image handle representing the loaded driver + image. + @param[in] ControllerHandle The controller handle the driver binds to. + @param[in, out] ArpService Pointer to the buffer containing the arp service + context data. + + @retval EFI_SUCCESS The arp service context is initialized. - @retval EFI_SUCCESS The arp service context is initialized. - @retval other Failed to initialize the arp service context. + @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. **/ -STATIC EFI_STATUS ArpCreateService ( IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ControllerHandle, - IN ARP_SERVICE_DATA *ArpService + IN OUT ARP_SERVICE_DATA *ArpService ) { EFI_STATUS Status; @@ -59,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. // @@ -173,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: @@ -194,16 +180,15 @@ ERROR_EXIT: /** Clean the arp service context data. - @param ArpService Pointer to the buffer containing the arp service - context data. + @param[in, out] ArpService Pointer to the buffer containing the arp service + context data. @return None. **/ -STATIC VOID ArpCleanService ( - IN ARP_SERVICE_DATA *ArpService + IN OUT ARP_SERVICE_DATA *ArpService ) { NET_CHECK_SIGNATURE (ArpService, ARP_SERVICE_DATA_SIGNATURE); @@ -250,18 +235,63 @@ ArpCleanService ( } } - /** - Test to see if this driver supports ControllerHandle. + 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; + } - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to test. - @param RemainingDevicePath Optional parameter use to pick a specific child - device to start. + Instance = NET_LIST_USER_STRUCT_S (Entry, ARP_INSTANCE_DATA, List, ARP_INSTANCE_DATA_SIGNATURE); + ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *) Context; - @retval EFI_SUCCES This driver supports this device - @retval EFI_ALREADY_STARTED This driver is already running on this device. - @retval other This driver does not support this device. + 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 + 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, + and is optional for bus drivers. + + @retval EFI_SUCCESS The device specified by ControllerHandle and + RemainingDevicePath is supported by the driver + specified by This. + @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and + 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 + requires exclusive acces. Currently not implemented. + @retval EFI_UNSUPPORTED The device specified by ControllerHandle and + RemainingDevicePath is not supported by the + driver specified by This. **/ EFI_STATUS @@ -308,14 +338,32 @@ ArpDriverBindingSupported ( /** Start this driver on ControllerHandle. - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to bind driver to - @param RemainingDevicePath Optional parameter use to pick a specific child - device to start. - - @retval EFI_SUCCES This driver is added to ControllerHandle - @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle - @retval other This driver does not support this device + 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 + 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. + + @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 + 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, + 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 + resources. + @retval Others The driver failded to start the device. **/ EFI_STATUS @@ -374,7 +422,7 @@ ERROR: // On error, clean the arp service context data, and free the memory allocated. // ArpCleanService (ArpService); - gBS->FreePool (ArpService); + FreePool (ArpService); return Status; } @@ -383,14 +431,30 @@ ERROR: /** Stop this driver on ControllerHandle. - @param This Protocol instance pointer. - @param ControllerHandle Handle of device to stop driver on - @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number - of children is zero stop the entire bus driver. - @param ChildHandleBuffer List of Child Handles to Stop. - - @retval EFI_SUCCES This driver is removed ControllerHandle - @retval other This driver was not removed from this device + 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 + 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. + 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid + 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 + 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 + if NumberOfChildren is 0.Not used. + + @retval EFI_SUCCESS The device was stopped. + @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error. **/ EFI_STATUS @@ -406,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; } // @@ -434,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. // @@ -450,37 +528,30 @@ ArpDriverBindingStop ( // ArpCleanService (ArpService); - gBS->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)); + FreePool (ArpService); } return EFI_SUCCESS; } /** - Creates a child handle with a set of I/O services. + 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 + installs on the existing ChildHandle. - @param This Protocol instance pointer. - @param ChildHandle Pointer to the handle of the child to create. If - it is NULL, then a new handle is created. If it is - not NULL, then the I/O services are added to the - existing child handle. + @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 + UEFI handle, then the protocol is added to the existing UEFI handle. - @retval EFI_SUCCES The child handle was created with the I/O - services. - @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create - the child. - @retval other The child handle was not created. + @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 available to create + the child + @retval other The child handle was not created **/ EFI_STATUS @@ -529,7 +600,7 @@ ArpServiceBindingCreateChild ( if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "ArpSBCreateChild: faild to install ARP protocol, %r.\n", Status)); - gBS->FreePool (Instance); + FreePool (Instance); return Status; } @@ -584,7 +655,7 @@ ERROR: // // Free the allocated memory. // - gBS->FreePool (Instance); + FreePool (Instance); } return Status; @@ -592,19 +663,22 @@ ERROR: /** - Destroys a child handle with a set of I/O services. + Destroys a child handle with a protocol installed on it. - @param This Protocol instance pointer. - @param ChildHandle Handle of the child to destroy. + 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. - @retval EFI_SUCCES The I/O services were removed from the child - handle. - @retval EFI_UNSUPPORTED The child handle does not support the I/O services - that are being removed. - @retval EFI_INVALID_PARAMETER Child handle is not a valid EFI Handle. - @retval EFI_ACCESS_DENIED The child handle could not be destroyed because - its I/O services are being used. - @retval other The child handle was not 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 + being removed. + @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 **/ EFI_STATUS @@ -643,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. @@ -675,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; } @@ -701,36 +775,29 @@ ArpServiceBindingDestroyChild ( gBS->RestoreTPL (OldTpl); - gBS->FreePool (Instance); + FreePool (Instance); return Status; } +/** + The entry point for Arp driver which installs the driver binding and component name + protocol on its ImageHandle. + + @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 + are successfully + @retval Others Failed to install the protocols. + +**/ EFI_STATUS EFIAPI ArpDriverEntryPoint ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) -/*++ - -Routine Description: - - The entry point for Arp driver which installs the driver binding and component name - protocol on its ImageHandle. - -Arguments: - - ImageHandle - The image handle of the driver. - SystemTable - The system table. - -Returns: - - EFI_SUCCESS - if the driver binding and component name protocols are successfully - installed, otherwise if failed. - ---*/ { return EfiLibInstallDriverBindingComponentName2 ( ImageHandle,