X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FArpDxe%2FArpDriver.c;h=632d691d75886b5d4f2c24262059d1d93bc93cc4;hp=6a52ed1958673cf715489e3cbc604b50f028417c;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=7203045841f51a8d241b719bfd868a1d249aef33 diff --git a/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c b/MdeModulePkg/Universal/Network/ArpDxe/ArpDriver.c index 6a52ed1958..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, 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 other Failed to initialize the arp service context. + @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. **/ -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. // @@ -142,7 +139,7 @@ ArpCreateService ( // Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL, - NET_TPL_EVENT, + TPL_NOTIFY, ArpOnFrameRcvd, ArpService, &ArpService->RxToken.Event @@ -156,7 +153,7 @@ ArpCreateService ( // Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL | EVT_TIMER, - NET_TPL_TIMER, + TPL_CALLBACK, ArpTimerHandler, ArpService, &ArpService->PeriodicTimer @@ -173,22 +170,6 @@ ArpCreateService ( TimerPeriodic, ARP_PERIODIC_TIMER_INTERVAL ); - if (EFI_ERROR (Status)) { - goto ERROR_EXIT; - } - - // - // Init the lock. - // - NET_LOCK_INIT (&ArpService->Lock); - - // - // Init the lists. - // - NetListInit (&ArpService->ChildrenList); - NetListInit (&ArpService->PendingRequestTable); - NetListInit (&ArpService->DeniedCacheTable); - NetListInit (&ArpService->ResolvedCacheTable); ERROR_EXIT: @@ -199,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); @@ -255,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 This Protocol instance pointer. - @param ControllerHandle Handle of device to test. - @param RemainingDevicePath Optional parameter use to pick a specific child - device to start. + @param[in] Entry The entry to be removed. + @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList. - @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. + @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 + 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 @@ -313,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 @@ -337,7 +380,7 @@ ArpDriverBindingStart ( // // Allocate a zero pool for ArpService. // - ArpService = NetAllocateZeroPool (sizeof(ARP_SERVICE_DATA)); + ArpService = AllocateZeroPool (sizeof(ARP_SERVICE_DATA)); if (ArpService == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -379,7 +422,7 @@ ERROR: // On error, clean the arp service context data, and free the memory allocated. // ArpCleanService (ArpService); - NetFreePool (ArpService); + FreePool (ArpService); return Status; } @@ -388,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 @@ -411,7 +470,7 @@ 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. @@ -433,66 +492,66 @@ ArpDriverBindingStop ( EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { - ARP_DEBUG_ERROR (("ArpDriverBindingStop: Open ArpSb failed, %r.\n", Status)); - return Status; + DEBUG ((EFI_D_ERROR, "ArpDriverBindingStop: Open ArpSb failed, %r.\n", Status)); + return EFI_DEVICE_ERROR; } ArpService = ARP_SERVICE_DATA_FROM_THIS (ServiceBinding); - while (!NetListIsEmpty (&ArpService->ChildrenList)) { + if (NumberOfChildren != 0) { // - // Iterate all the instances. + // NumberOfChildren is not zero, destroy all the ARP children instances. // - Instance = NET_LIST_HEAD (&ArpService->ChildrenList, ARP_INSTANCE_DATA, List); - + 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)) { // - // Destroy this arp child. + // Uninstall the ARP ServiceBinding protocol. // - ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle); - } + gBS->UninstallMultipleProtocolInterfaces ( + NicHandle, + &gEfiArpServiceBindingProtocolGuid, + &ArpService->ServiceBinding, + NULL + ); - ASSERT (NetListIsEmpty (&ArpService->PendingRequestTable)); - ASSERT (NetListIsEmpty (&ArpService->DeniedCacheTable)); - ASSERT (NetListIsEmpty (&ArpService->ResolvedCacheTable)); + // + // Clean the arp servicebinding context data and free the memory allocated. + // + ArpCleanService (ArpService); - // - // Uninstall the ARP ServiceBinding protocol. - // - Status = gBS->UninstallMultipleProtocolInterfaces ( - NicHandle, - &gEfiArpServiceBindingProtocolGuid, - &ArpService->ServiceBinding, - NULL - ); - if (EFI_ERROR (Status)) { - ARP_DEBUG_ERROR (("ArpDriverBindingStop: Failed to uninstall ArpSb, %r.\n", Status)); - return Status; + FreePool (ArpService); } - // - // Clean the arp servicebinding context data and free the memory allocated. - // - ArpCleanService (ArpService); - NetFreePool (ArpService); - - return Status; + 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 @@ -506,6 +565,7 @@ ArpServiceBindingCreateChild ( ARP_SERVICE_DATA *ArpService; ARP_INSTANCE_DATA *Instance; VOID *Mnp; + EFI_TPL OldTpl; if ((This == NULL) || (ChildHandle == NULL)) { return EFI_INVALID_PARAMETER; @@ -516,9 +576,9 @@ ArpServiceBindingCreateChild ( // // Allocate memory for the instance context data. // - Instance = NetAllocateZeroPool (sizeof(ARP_INSTANCE_DATA)); + Instance = AllocateZeroPool (sizeof(ARP_INSTANCE_DATA)); if (Instance == NULL) { - ARP_DEBUG_ERROR (("ArpSBCreateChild: Failed to allocate memory for Instance.\n")); + DEBUG ((EFI_D_ERROR, "ArpSBCreateChild: Failed to allocate memory for Instance.\n")); return EFI_OUT_OF_RESOURCES; } @@ -538,9 +598,9 @@ ArpServiceBindingCreateChild ( NULL ); if (EFI_ERROR (Status)) { - ARP_DEBUG_ERROR (("ArpSBCreateChild: faild to install ARP protocol, %r.\n", Status)); + DEBUG ((EFI_D_ERROR, "ArpSBCreateChild: faild to install ARP protocol, %r.\n", Status)); - NetFreePool (Instance); + FreePool (Instance); return Status; } @@ -564,19 +624,15 @@ ArpServiceBindingCreateChild ( goto ERROR; } - if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) { - - Status = EFI_ACCESS_DENIED; - goto ERROR; - } + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); // // Insert the instance into children list managed by the arp service context data. // - NetListInsertTail (&ArpService->ChildrenList, &Instance->List); + InsertTailList (&ArpService->ChildrenList, &Instance->List); ArpService->ChildrenNumber++; - NET_UNLOCK (&ArpService->Lock); + gBS->RestoreTPL (OldTpl); ERROR: @@ -599,7 +655,7 @@ ERROR: // // Free the allocated memory. // - NetFreePool (Instance); + FreePool (Instance); } return Status; @@ -607,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 @@ -633,6 +692,7 @@ ArpServiceBindingDestroyChild ( ARP_SERVICE_DATA *ArpService; ARP_INSTANCE_DATA *Instance; EFI_ARP_PROTOCOL *Arp; + EFI_TPL OldTpl; if ((This == NULL) || (ChildHandle == NULL)) { return EFI_INVALID_PARAMETER; @@ -657,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. @@ -686,17 +746,14 @@ ArpServiceBindingDestroyChild ( NULL ); if (EFI_ERROR (Status)) { - ARP_DEBUG_ERROR (("ArpSBDestroyChild: Failed to uninstall the arp protocol, %r.\n", + DEBUG ((EFI_D_ERROR, "ArpSBDestroyChild: Failed to uninstall the arp protocol, %r.\n", Status)); - Instance->Destroyed = FALSE; + Instance->InDestroy = FALSE; return Status; } - if (EFI_ERROR (NET_TRYLOCK (&ArpService->Lock))) { - Instance->Destroyed = FALSE; - return EFI_ACCESS_DENIED; - } + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); if (Instance->Configured) { // @@ -713,50 +770,42 @@ ArpServiceBindingDestroyChild ( // // Remove this instance from the ChildrenList. // - NetListRemoveEntry (&Instance->List); + RemoveEntryList (&Instance->List); ArpService->ChildrenNumber--; - NET_UNLOCK (&ArpService->Lock); + gBS->RestoreTPL (OldTpl); - NetFreePool (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 NetLibInstallAllDriverProtocols ( + return EfiLibInstallDriverBindingComponentName2 ( ImageHandle, SystemTable, &gArpDriverBinding, ImageHandle, &gArpComponentName, - NULL, - NULL + &gArpComponentName2 ); }