]> git.proxmox.com Git - mirror_edk2.git/commitdiff
RedfishPkg/RedfishDiscoverDxe: Install protocol on each network interface
authorAbner Chang <abner.chang@amd.com>
Tue, 30 Aug 2022 04:15:47 +0000 (12:15 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 6 Sep 2022 10:09:41 +0000 (10:09 +0000)
BZ 4037:
Install EFI_DISCOVER_PROTOCOL on each network interface.

This fixes the issue that causes the high-level Redfish driver
on the network interface is stopped when:
1. EFI_DISCOVER_PROTOCOL is reinstalled on a new-found network
   interface, or
2. EFI_DISCOVER_PROTOCOL is stopped on the network interface
   other than the one which is used to communicate with Redfish
   service.

Cc: Nickle Wang <nickle@csie.io>
Cc: Igor Kulchytskyy <igork@ami.com>
Signed-off-by: Abner Chang <abner.chang@amd.com>
Reviewed-by: Nickle Wang <nickle@csie.io>
Reviewed-by: Igor Kulchytskyy <igork@ami.com>
RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h

index bf50c78c9280da25c1c33c38660adc1b1dcc8f9a..35dba40473a1410142a48d968da2a1727568d7d4 100644 (file)
@@ -3,6 +3,7 @@
   The implementation of EFI Redfidh Discover Protocol.\r
 \r
   (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>\r
   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
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -23,8 +24,6 @@ EFI_GUID  mRedfishDiscoverTcp4InstanceGuid   = EFI_REDFISH_DISCOVER_TCP4_INSTANC
 EFI_GUID  mRedfishDiscoverTcp6InstanceGuid   = EFI_REDFISH_DISCOVER_TCP6_INSTANCE_GUID;\r
 EFI_GUID  mRedfishDiscoverRestExInstanceGuid = EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_GUID;\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
 EFI_STATUS\r
 EFIAPI\r
 Tcp4GetSubnetInfo (\r
@@ -325,6 +324,38 @@ GetTargetNetworkInterfaceInternal (
   return NULL;\r
 }\r
 \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
 /**\r
   This function validate if target network interface is ready for discovering\r
   Redfish service.\r
@@ -1619,29 +1650,30 @@ BuildupNetworkInterface (
                       EFI_OPEN_PROTOCOL_BY_DRIVER\r
                       );\r
       if (!EFI_ERROR (Status)) {\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
         }\r
       }\r
 \r
@@ -1724,6 +1756,7 @@ StopServiceOnNetworkInterface (
   EFI_STATUS                                       Status;\r
   VOID                                             *Interface;\r
   EFI_TPL                                          OldTpl;\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
   EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL  *ThisNetworkInterface;\r
   EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL   *RestExInstance;\r
 \r
@@ -1743,8 +1776,11 @@ StopServiceOnNetworkInterface (
         ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);\r
         while (TRUE) {\r
           if (ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle == ControllerHandle) {\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
             Status = CloseProtocolService (\r
-                       // Close protocol and destroy service.\r
                        ThisBindingProtocol,\r
                        ControllerHandle,\r
                        &gRequiredProtocol[Index],\r
                        ThisBindingProtocol,\r
                        ControllerHandle,\r
                        &gRequiredProtocol[Index],\r
@@ -1756,17 +1792,18 @@ StopServiceOnNetworkInterface (
             }\r
 \r
             gBS->RestoreTPL (OldTpl);\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
             }\r
 \r
             return Status;\r
@@ -2032,20 +2069,5 @@ RedfishDiscoverUnload (
     StopServiceOnNetworkInterface (&gRedfishDiscoverDriverBinding, ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle);\r
   }\r
 \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
   return Status;\r
 }\r
index 4d1319b26411783f665738ba74a8b3e274423444..04fa09e1cc23e1258f586bd069f51e6323586ea6 100644 (file)
@@ -2,6 +2,7 @@
   This file defines the EFI Redfish Discover Protocol interface.\r
 \r
   (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>\r
   This file defines the EFI Redfish Discover Protocol interface.\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
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -107,6 +108,12 @@ typedef struct {
                                                                                ///< NETWORK_INTERFACE_PROTOCOL_TYPE.\r
   REDFISH_DISCOVER_NETWORK_INTERFACE_PROTOCOL    NetworkInterfaceProtocolInfo; ///< Network interface protocol information.\r
   EFI_HANDLE                                     RestExHandle;                 ///< REST EX handle associated with this network interface.\r
                                                                                ///< NETWORK_INTERFACE_PROTOCOL_TYPE.\r
   REDFISH_DISCOVER_NETWORK_INTERFACE_PROTOCOL    NetworkInterfaceProtocolInfo; ///< Network interface protocol information.\r
   EFI_HANDLE                                     RestExHandle;                 ///< REST EX handle associated with this network interface.\r
+  //\r
+  // EFI_REDFISH_DISCOVER_PROTOCOL instance installed\r
+  // on this network interface.\r
+  //\r
+  EFI_HANDLE                                     EfiRedfishDiscoverProtocolHandle; ///< EFI_REDFISH_DISCOVER_PROTOTOCOL instance installed\r
+                                                                                   ///< on this network interface.\r
 } EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL;\r
 \r
 //\r
 } EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL;\r
 \r
 //\r