The implementation of EFI Redfidh Discover Protocol.\r
\r
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>\r
+ Copyright (c) 2022, AMD Incorporated. All rights reserved.\r
\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
EFI_GUID mRedfishDiscoverTcp6InstanceGuid = EFI_REDFISH_DISCOVER_TCP6_INSTANCE_GUID;\r
EFI_GUID mRedfishDiscoverRestExInstanceGuid = EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_GUID;\r
\r
-EFI_HANDLE EfiRedfishDiscoverProtocolHandle = NULL;\r
-\r
EFI_STATUS\r
EFIAPI\r
Tcp4GetSubnetInfo (\r
return NULL;\r
}\r
\r
+/**\r
+ This function searches EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL\r
+ instance with the given Controller handle.\r
+\r
+ @param[in] ControllerHandle The controller handle associated with network interface.\r
+\r
+ @retval Non-NULL EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL is returned.\r
+ @retval NULL Non of EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL instance is returned.\r
+**/\r
+EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *\r
+GetTargetNetworkInterfaceInternalByController (\r
+ IN EFI_HANDLE ControllerHandle\r
+ )\r
+{\r
+ EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;\r
+\r
+ ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);\r
+ while (TRUE) {\r
+ if (ThisNetworkInterface->OpenDriverControllerHandle == ControllerHandle) {\r
+ return ThisNetworkInterface;\r
+ }\r
+\r
+ if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {\r
+ return NULL;\r
+ }\r
+\r
+ ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);\r
+ }\r
+\r
+ return NULL;\r
+}\r
+\r
/**\r
This function validate if target network interface is ready for discovering\r
Redfish service.\r
EFI_OPEN_PROTOCOL_BY_DRIVER\r
);\r
if (!EFI_ERROR (Status)) {\r
- if ((EfiRedfishDiscoverProtocolHandle == NULL) &&\r
- (gRequiredProtocol[Index].ProtocolType == ProtocolTypeRestEx) &&\r
- !IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)\r
- )\r
- {\r
- // Install the fisrt Redfish Discover Protocol when EFI REST EX protcol is discovered.\r
- // This ensures EFI REST EX is ready while EFI_REDFISH_DISCOVER_PROTOCOL consumer acquires\r
- // Redfish serivce over network interface.\r
-\r
- Status = gBS->InstallProtocolInterface (\r
- &EfiRedfishDiscoverProtocolHandle,\r
- &gEfiRedfishDiscoverProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- (VOID *)&mRedfishDiscover\r
- );\r
- } else if ((EfiRedfishDiscoverProtocolHandle != NULL) && NewNetworkInterfaceInstalled) {\r
- Status = gBS->ReinstallProtocolInterface (\r
- EfiRedfishDiscoverProtocolHandle,\r
- &gEfiRedfishDiscoverProtocolGuid,\r
- (VOID *)&mRedfishDiscover,\r
- (VOID *)&mRedfishDiscover\r
- );\r
- NewNetworkInterfaceInstalled = FALSE;\r
+ if ((gRequiredProtocol[Index].ProtocolType == ProtocolTypeRestEx)) {\r
+ // Install Redfish Discover Protocol when EFI REST EX protcol is discovered.\r
+ // This ensures EFI REST EX is ready while the consumer of EFI_REDFISH_DISCOVER_PROTOCOL\r
+ // acquires Redfish serivce over network interface.\r
+\r
+ if (!NewNetworkInterfaceInstalled) {\r
+ NetworkInterface = GetTargetNetworkInterfaceInternalByController (ControllerHandle);\r
+ if (NetworkInterface == NULL) {\r
+ DEBUG ((DEBUG_ERROR, "%a: Can't find network interface by ControllerHandle\n", __FUNCTION__));\r
+ return Status;\r
+ }\r
+ }\r
+\r
+ NewNetworkInterfaceInstalled = FALSE;\r
+ NetworkInterface->EfiRedfishDiscoverProtocolHandle = NULL;\r
+ Status = gBS->InstallProtocolInterface (\r
+ &NetworkInterface->EfiRedfishDiscoverProtocolHandle,\r
+ &gEfiRedfishDiscoverProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ (VOID *)&mRedfishDiscover\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "%a: Fail to install EFI_REDFISH_DISCOVER_PROTOCOL\n", __FUNCTION__));\r
+ }\r
}\r
}\r
\r
EFI_STATUS Status;\r
VOID *Interface;\r
EFI_TPL OldTpl;\r
+ EFI_HANDLE DiscoverProtocolHandle;\r
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;\r
EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance;\r
\r
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);\r
while (TRUE) {\r
if (ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle == ControllerHandle) {\r
+ DiscoverProtocolHandle = ThisNetworkInterface->EfiRedfishDiscoverProtocolHandle;\r
+ //\r
+ // Close protocol and destroy service.\r
+ //\r
Status = CloseProtocolService (\r
- // Close protocol and destroy service.\r
ThisBindingProtocol,\r
ControllerHandle,\r
&gRequiredProtocol[Index],\r
}\r
\r
gBS->RestoreTPL (OldTpl);\r
- // Reinstall Redfish Discover protocol to notify network\r
- // interface change.\r
-\r
- Status = gBS->ReinstallProtocolInterface (\r
- EfiRedfishDiscoverProtocolHandle,\r
- &gEfiRedfishDiscoverProtocolGuid,\r
- (VOID *)&mRedfishDiscover,\r
- (VOID *)&mRedfishDiscover\r
- );\r
- if (EFI_ERROR (Status)) {\r
- DEBUG ((DEBUG_ERROR, "%a: Reinstall gEfiRedfishDiscoverProtocolGuid fail.", __FUNCTION__));\r
+\r
+ //\r
+ // Disconnect EFI Redfish discover driver controller to notify the\r
+ // clinet which uses .EFI Redfish discover protocol.\r
+ //\r
+ if (DiscoverProtocolHandle != NULL) {\r
+ gBS->DisconnectController (DiscoverProtocolHandle, NULL, NULL);\r
+ Status = gBS->UninstallProtocolInterface (\r
+ DiscoverProtocolHandle,\r
+ &gEfiRedfishDiscoverProtocolGuid,\r
+ (VOID *)&mRedfishDiscover\r
+ );\r
}\r
\r
return Status;\r
StopServiceOnNetworkInterface (&gRedfishDiscoverDriverBinding, ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle);\r
}\r
\r
- // Disconnect EFI Redfish discover driver controller to notify the\r
- // clinet which uses .EFI Redfish discover protocol.\r
-\r
- if (EfiRedfishDiscoverProtocolHandle != NULL) {\r
- //\r
- // Notify user EFI_REDFISH_DISCOVER_PROTOCOL is unloaded.\r
- //\r
- gBS->DisconnectController (EfiRedfishDiscoverProtocolHandle, NULL, NULL);\r
- Status = gBS->UninstallProtocolInterface (\r
- EfiRedfishDiscoverProtocolHandle,\r
- &gEfiRedfishDiscoverProtocolGuid,\r
- (VOID *)&mRedfishDiscover\r
- );\r
- }\r
-\r
return Status;\r
}\r