]> xenbits.xensource.com Git - ovmf.git/commitdiff
RedfishPkg: Create RestEx child on selected interface
authorVu Nguyen <vunguyen@os.amperecomputing.com>
Mon, 28 Jun 2021 10:26:55 +0000 (17:26 +0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 8 May 2023 13:12:01 +0000 (13:12 +0000)
When a MAC address matching interface is found, a RestEx child will be
created to provide the Redfish communication on that interface.
Currently, It will try to locate all RestEx binding services and choose
the first satisfied instance without taking care about current selected
interface. This might raise an issue on the system with multiple network
devices that the RestEx child was installed on wrong interface.

Signed-off-by: Minh Nguyen <minhnguyen1@os.amperecomputing.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
Reviewed-by: Abner Chang <Abner.Chang@amd.com>
RedfishPkg/Include/Library/RestExLib.h
RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c
RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c

index bc4e4ca6caa7d0231d18390b7ad06eae5c95bb3c..2c32c3684cf4b8f0512f92a37c29fdda5f24a95a 100644 (file)
@@ -2,6 +2,7 @@
   This library provides help functions for REST EX Protocol.\r
 \r
   (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
+  Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>\r
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -20,6 +21,7 @@
   This function allows the caller to create child handle for specific\r
   REST server.\r
 \r
+  @param[in]  Controller           The controller handle used of selected interface.\r
   @param[in]  Image                The image handle used to open service.\r
   @param[in]  AccessMode           Access mode of REST server.\r
   @param[in]  ConfigType           Underlying configuration to communicate with REST server.\r
@@ -32,6 +34,7 @@
 **/\r
 EFI_STATUS\r
 RestExLibCreateChild (\r
+  IN EFI_HANDLE                       Controller,\r
   IN EFI_HANDLE                       Image,\r
   IN EFI_REST_EX_SERVICE_ACCESS_MODE  AccessMode,\r
   IN EFI_REST_EX_CONFIG_TYPE          ConfigType,\r
index d9acad24dec1805d7dd77896f1dcdc56f99d4123..96533a6eb36ada94fcd953eea8fb2a059c98af73 100644 (file)
@@ -2,6 +2,7 @@
   This library provides help functions for REST EX Protocol.\r
 \r
   (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
+  Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>\r
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -9,6 +10,7 @@
 \r
 #include <Uefi.h>\r
 #include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/NetLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
@@ -21,6 +23,7 @@
   This function allows the caller to create child handle for specific\r
   REST server.\r
 \r
+  @param[in]  Controller           The controller handle used of selected interface.\r
   @param[in]  Image                The image handle used to open service.\r
   @param[in]  AccessMode           Access mode of REST server.\r
   @param[in]  ConfigType           Underlying configuration to communicate with REST server.\r
@@ -33,6 +36,7 @@
 **/\r
 EFI_STATUS\r
 RestExLibCreateChild (\r
+  IN EFI_HANDLE                       Controller,\r
   IN EFI_HANDLE                       Image,\r
   IN EFI_REST_EX_SERVICE_ACCESS_MODE  AccessMode,\r
   IN EFI_REST_EX_CONFIG_TYPE          ConfigType,\r
@@ -41,8 +45,6 @@ RestExLibCreateChild (
   )\r
 {\r
   EFI_STATUS                Status;\r
-  UINTN                     NoBuffer;\r
-  EFI_HANDLE                *Handle;\r
   EFI_HANDLE                ChildHandle;\r
   EFI_REST_EX_PROTOCOL      *RestEx;\r
   EFI_REST_EX_SERVICE_INFO  *RestExServiceInfo;\r
@@ -59,116 +61,83 @@ RestExLibCreateChild (
   }\r
 \r
   *ChildInstanceHandle = NULL;\r
-  //\r
-  // Locate all REST EX binding service.\r
-  //\r
-  Handle   = NULL;\r
-  NoBuffer = 0;\r
-  Status   = gBS->LocateHandleBuffer (\r
-                    ByProtocol,\r
-                    &gEfiRestExServiceBindingProtocolGuid,\r
-                    NULL,\r
-                    &NoBuffer,\r
-                    &Handle\r
-                    );\r
-  if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {\r
-    return Status;\r
-  }\r
 \r
-  Handle = (EFI_HANDLE *)AllocateZeroPool (sizeof (EFI_HANDLE) * NoBuffer);\r
-  if (Handle == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+  ChildHandle = NULL;\r
+  Status      = NetLibCreateServiceChild (\r
+                  Controller,\r
+                  Image,\r
+                  &gEfiRestExServiceBindingProtocolGuid,\r
+                  &ChildHandle\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "%a: Failed to create service child - %r \n",\r
+      __func__,\r
+      Status\r
+      ));\r
+    return Status;\r
   }\r
 \r
-  Status = gBS->LocateHandleBuffer (\r
-                  ByProtocol,\r
-                  &gEfiRestExServiceBindingProtocolGuid,\r
+  Status = gBS->OpenProtocol (\r
+                  ChildHandle,\r
+                  &gEfiRestExProtocolGuid,\r
+                  (VOID **)&RestEx,\r
+                  Image,\r
                   NULL,\r
-                  &NoBuffer,\r
-                  &Handle\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (Handle);\r
-    return Status;\r
+    goto ON_ERROR;\r
+  }\r
+\r
+  //\r
+  // Get the information of REST service provided by this EFI REST EX driver\r
+  //\r
+  Status = RestEx->GetService (\r
+                     RestEx,\r
+                     &RestExServiceInfo\r
+                     );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
   }\r
 \r
   //\r
-  // Search for the proper REST EX instance.\r
+  // Check REST EX property.\r
   //\r
-  while (NoBuffer != 0) {\r
-    ChildHandle = NULL;\r
-    Status      = NetLibCreateServiceChild (\r
-                    *(Handle + (NoBuffer - 1)),\r
-                    Image,\r
-                    &gEfiRestExServiceBindingProtocolGuid,\r
-                    &ChildHandle\r
-                    );\r
-    if (!EFI_ERROR (Status)) {\r
-      Status = gBS->OpenProtocol (\r
-                      ChildHandle,\r
-                      &gEfiRestExProtocolGuid,\r
-                      (VOID **)&RestEx,\r
-                      Image,\r
-                      NULL,\r
-                      EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                      );\r
-      if (EFI_ERROR (Status)) {\r
-        goto ON_ERROR;\r
-      }\r
-\r
-      //\r
-      // Get the information of REST service provided by this EFI REST EX driver\r
-      //\r
-      Status = RestEx->GetService (\r
-                         RestEx,\r
-                         &RestExServiceInfo\r
-                         );\r
-      if (EFI_ERROR (Status)) {\r
-        goto ON_ERROR;\r
-      }\r
-\r
-      //\r
-      // Check REST EX property.\r
-      //\r
-      switch (ConfigType) {\r
-        case EfiRestExConfigHttp:\r
-          LenOfConfig = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA);\r
-          break;\r
-\r
-        case EfiRestExConfigUnspecific:\r
-          LenOfConfig = REST_EX_CONFIG_DATA_LEN_UNKNOWN;\r
-          break;\r
-\r
-        default:\r
-          goto ON_ERROR;\r
-      }\r
-\r
-      if ((RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceAccessMode != AccessMode) ||\r
-          (RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType != ServiceType) ||\r
-          (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType != ConfigType) ||\r
-          ((LenOfConfig != REST_EX_CONFIG_DATA_LEN_UNKNOWN) && (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength != LenOfConfig)))\r
-      {\r
-        goto ON_ERROR;\r
-      }\r
-    }\r
-\r
-    //\r
-    // This is proper REST EX instance.\r
-    //\r
-    *ChildInstanceHandle = ChildHandle;\r
-    FreePool (Handle);\r
-    return EFI_SUCCESS;\r
+  switch (ConfigType) {\r
+    case EfiRestExConfigHttp:\r
+      LenOfConfig = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA);\r
+      break;\r
 \r
-ON_ERROR:;\r
-    NetLibDestroyServiceChild (\r
-      *(Handle + (NoBuffer - 1)),\r
-      Image,\r
-      &gEfiRestExServiceBindingProtocolGuid,\r
-      ChildHandle\r
-      );\r
-    NoBuffer--;\r
+    case EfiRestExConfigUnspecific:\r
+      LenOfConfig = REST_EX_CONFIG_DATA_LEN_UNKNOWN;\r
+      break;\r
+\r
+    default:\r
+      goto ON_ERROR;\r
+  }\r
+\r
+  if ((RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceAccessMode != AccessMode) ||\r
+      (RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType != ServiceType) ||\r
+      (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType != ConfigType) ||\r
+      ((LenOfConfig != REST_EX_CONFIG_DATA_LEN_UNKNOWN) && (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength != LenOfConfig)))\r
+  {\r
+    goto ON_ERROR;\r
   }\r
 \r
-  FreePool (Handle);\r
+  //\r
+  // This is proper REST EX instance.\r
+  //\r
+  *ChildInstanceHandle = ChildHandle;\r
+  return EFI_SUCCESS;\r
+\r
+ON_ERROR:;\r
+  NetLibDestroyServiceChild (\r
+    Controller,\r
+    Image,\r
+    &gEfiRestExServiceBindingProtocolGuid,\r
+    ChildHandle\r
+    );\r
   return EFI_NOT_FOUND;\r
 }\r
index 14702748813b5d941a5d511e8fb444c49ddaf14d..0b86a7b5cc4bbb31b91735909ec0da01bc530751 100644 (file)
@@ -87,6 +87,7 @@ CreateRestExInstance (
   EFI_STATUS  Status;\r
 \r
   Status = RestExLibCreateChild (\r
+             Instance->NetworkInterface->OpenDriverControllerHandle,\r
              Instance->Owner,\r
              FixedPcdGetBool (PcdRedfishDiscoverAccessModeInBand) ? EfiRestExServiceInBandAccess : EfiRestExServiceOutOfBandAccess,\r
              EfiRestExConfigHttp,\r