public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chang, Abner via groups.io" <abner.chang=amd.com@groups.io>
To: <devel@edk2.groups.io>
Cc: Nickle Wang <nicklew@nvidia.com>,
	Igor Kulchytskyy <igork@ami.com>,
	Mike Maslenkin <mike.maslenkin@gmail.com>
Subject: [edk2-devel] [PATCH V2 3/8] RedfishPkg/RedfishConfigHandler: Use Redfish HI readiness notification
Date: Thu, 23 Nov 2023 14:47:13 +0800	[thread overview]
Message-ID: <20231123064719.1248-4-abner.chang@amd.com> (raw)
In-Reply-To: <20231123064719.1248-1-abner.chang@amd.com>

From: Abner Chang <abner.chang@amd.com>

Wait until Redfish Host Interface is installed on
the system then acquire Redfish service.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Mike Maslenkin <mike.maslenkin@gmail.com>
---
 .../RedfishConfigHandlerDriver.inf            |   9 +-
 .../RedfishConfigHandlerDriver.c              | 168 ++++++++++++------
 2 files changed, 116 insertions(+), 61 deletions(-)

diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf
index b167c6e1ee4..aed93f570cf 100644
--- a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf
+++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf
@@ -46,11 +46,12 @@
   UefiDriverEntryPoint
 
 [Protocols]
-  gEfiRedfishDiscoverProtocolGuid         ## CONSUMES
+  gEfiRedfishDiscoverProtocolGuid              ## CONSUMES
   gEfiRestExServiceBindingProtocolGuid
-  gEfiRestExProtocolGuid                  ## CONSUMES
-  gEdkIIRedfishCredentialProtocolGuid     ## CONSUMES
-  gEdkIIRedfishConfigHandlerProtocolGuid  ## CONSUMES
+  gEfiRestExProtocolGuid                       ## CONSUMES
+  gEdkIIRedfishCredentialProtocolGuid          ## CONSUMES
+  gEdkIIRedfishConfigHandlerProtocolGuid       ## CONSUMES
+  gEdkIIRedfishHostInterfaceReadyProtocolGuid  ## CONSUMES
 
 [Guids]
   gEfiEventExitBootServicesGuid           ## CONSUMES ## Event
diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c
index f987cc67a69..b421f51374d 100644
--- a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c
+++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c
@@ -17,11 +17,15 @@ EFI_EVENT  gEfiRedfishDiscoverProtocolEvent = NULL;
 //
 // Variables for using RFI Redfish Discover Protocol
 //
-VOID                           *gEfiRedfishDiscoverRegistration;
-EFI_HANDLE                     gEfiRedfishDiscoverControllerHandle = NULL;
-EFI_REDFISH_DISCOVER_PROTOCOL  *gEfiRedfishDiscoverProtocol        = NULL;
-BOOLEAN                        gRedfishDiscoverActivated           = FALSE;
-BOOLEAN                        gRedfishServiceDiscovered           = FALSE;
+VOID                                    *gEfiRedfishDiscoverRegistration;
+EFI_HANDLE                              gEfiRedfishDiscoverControllerHandle = NULL;
+EFI_REDFISH_DISCOVER_PROTOCOL           *gEfiRedfishDiscoverProtocol        = NULL;
+BOOLEAN                                 gRedfishDiscoverActivated           = FALSE;
+BOOLEAN                                 gRedfishServiceDiscovered           = FALSE;
+EFI_REDFISH_DISCOVER_NETWORK_INTERFACE  *mNetworkInterfaces                 = NULL;
+UINTN                                   mNumberOfNetworkInterfaces;
+EFI_EVENT                               mEdkIIRedfishHostInterfaceReadyEvent;
+VOID                                    *mEdkIIRedfishHostInterfaceRegistration;
 
 ///
 /// Driver Binding Protocol instance
@@ -339,6 +343,83 @@ RedfishServiceDiscoveredCallback (
   FreePool (RedfishDiscoveredToken);
 }
 
+/**
+  Callback function executed when the gEdkIIRedfishHostInterfaceReadyProtocolGuid
+  protocol interface is installed.
+
+  @param[in]   Event    Event whose notification function is being invoked.
+  @param[in]   Context  Pointer to the Context buffer
+
+**/
+VOID
+EFIAPI
+AcquireRedfishServiceOnNetworkInterfaceCallback (
+  IN  EFI_EVENT  Event,
+  IN  VOID       *Context
+  )
+{
+  EFI_STATUS                              Status;
+  EFI_REDFISH_DISCOVER_NETWORK_INTERFACE  *ThisNetworkInterface;
+  UINTN                                   NetworkInterfaceIndex;
+  EFI_REDFISH_DISCOVERED_TOKEN            *ThisRedfishDiscoveredToken;
+
+  ThisNetworkInterface = mNetworkInterfaces;
+  //
+  // Loop to discover Redfish service on each network interface.
+  //
+  for (NetworkInterfaceIndex = 0; NetworkInterfaceIndex < mNumberOfNetworkInterfaces; NetworkInterfaceIndex++) {
+    ThisRedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_TOKEN));
+    if (ThisRedfishDiscoveredToken == NULL) {
+      DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_TOKEN.\n", __func__));
+      return;
+    }
+
+    ThisRedfishDiscoveredToken->Signature = REDFISH_DISCOVER_TOKEN_SIGNATURE;
+
+    //
+    // Initial this Redfish Discovered Token
+    //
+    Status = gBS->CreateEvent (
+                    EVT_NOTIFY_SIGNAL,
+                    TPL_CALLBACK,
+                    RedfishServiceDiscoveredCallback,
+                    (VOID *)ThisRedfishDiscoveredToken,
+                    &ThisRedfishDiscoveredToken->Event
+                    );
+    if (EFI_ERROR (Status)) {
+      FreePool (ThisRedfishDiscoveredToken);
+      DEBUG ((DEBUG_ERROR, "%a: Failed to create event for Redfish discovered token.\n", __func__));
+      return;
+    }
+
+    //
+    // Acquire for Redfish service which is reported by
+    // Redfish Host Interface.
+    //
+    Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService (
+                                            gEfiRedfishDiscoverProtocol,
+                                            gRedfishConfigData.Image,
+                                            ThisNetworkInterface,
+                                            EFI_REDFISH_DISCOVER_HOST_INTERFACE,
+                                            ThisRedfishDiscoveredToken
+                                            );
+
+    //
+    // Free Redfish Discovered Token if Discover Instance was not created and
+    // Redfish Service Discovered Callback event was not triggered.
+    //
+    if ((ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound == 0) ||
+        EFI_ERROR (ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances->Status))
+    {
+      gBS->CloseEvent (ThisRedfishDiscoveredToken->Event);
+      DEBUG ((DEBUG_ERROR, "%a: Free Redfish discovered token - %x.\n", __func__, ThisRedfishDiscoveredToken));
+      FreePool (ThisRedfishDiscoveredToken);
+    }
+
+    ThisNetworkInterface++;
+  }
+}
+
 /**
   Callback function executed when the EFI_REDFISH_DISCOVER_PROTOCOL
   protocol interface is installed.
@@ -354,13 +435,10 @@ RedfishDiscoverProtocolInstalled (
   OUT VOID       *Context
   )
 {
-  EFI_STATUS                              Status;
-  UINTN                                   BufferSize;
-  EFI_HANDLE                              HandleBuffer;
-  UINTN                                   NetworkInterfaceIndex;
-  EFI_REDFISH_DISCOVER_NETWORK_INTERFACE  *ThisNetworkInterface;
-  EFI_REDFISH_DISCOVERED_TOKEN            *ThisRedfishDiscoveredToken;
-  UINTN                                   NumberOfNetworkInterfaces;
+  EFI_STATUS  Status;
+  UINTN       BufferSize;
+  EFI_HANDLE  HandleBuffer;
+  VOID        *RedfishHostInterfaceReadyProtocol;
 
   DEBUG ((DEBUG_MANAGEABILITY, "%a: New network interface is installed on system by EFI Redfish discover driver.\n", __func__));
 
@@ -401,67 +479,43 @@ RedfishDiscoverProtocolInstalled (
   Status = gEfiRedfishDiscoverProtocol->GetNetworkInterfaceList (
                                           gEfiRedfishDiscoverProtocol,
                                           gRedfishConfigData.Image,
-                                          &NumberOfNetworkInterfaces,
-                                          &ThisNetworkInterface
+                                          &mNumberOfNetworkInterfaces,
+                                          &mNetworkInterfaces
                                           );
-  if (EFI_ERROR (Status) || (NumberOfNetworkInterfaces == 0)) {
+  if (EFI_ERROR (Status) || (mNumberOfNetworkInterfaces == 0)) {
     DEBUG ((DEBUG_ERROR, "%a: No network interfaces found on the handle.\n", __func__));
     return;
   }
 
   //
-  // Loop to discover Redfish service on each network interface.
+  // Check if Redfish Host Interface is ready or not.
   //
-  for (NetworkInterfaceIndex = 0; NetworkInterfaceIndex < NumberOfNetworkInterfaces; NetworkInterfaceIndex++) {
-    ThisRedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)AllocateZeroPool (sizeof (EFI_REDFISH_DISCOVERED_TOKEN));
-    if (ThisRedfishDiscoveredToken == NULL) {
-      DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_TOKEN.\n", __func__));
-      return;
-    }
-
-    ThisRedfishDiscoveredToken->Signature = REDFISH_DISCOVER_TOKEN_SIGNATURE;
-
-    //
-    // Initial this Redfish Discovered Token
-    //
+  Status = gBS->LocateProtocol (&gEdkIIRedfishHostInterfaceReadyProtocolGuid, NULL, &RedfishHostInterfaceReadyProtocol);
+  if (!EFI_ERROR (Status)) {
+    // Acquire Redfish service;
+    AcquireRedfishServiceOnNetworkInterfaceCallback ((EFI_EVENT)NULL, (VOID *)NULL);
+  } else {
     Status = gBS->CreateEvent (
                     EVT_NOTIFY_SIGNAL,
                     TPL_CALLBACK,
-                    RedfishServiceDiscoveredCallback,
-                    (VOID *)ThisRedfishDiscoveredToken,
-                    &ThisRedfishDiscoveredToken->Event
+                    AcquireRedfishServiceOnNetworkInterfaceCallback,
+                    NULL,
+                    &mEdkIIRedfishHostInterfaceReadyEvent
                     );
     if (EFI_ERROR (Status)) {
-      FreePool (ThisRedfishDiscoveredToken);
-      DEBUG ((DEBUG_ERROR, "%a: Failed to create event for Redfish discovered token.\n", __func__));
+      DEBUG ((DEBUG_ERROR, "%a: Failed to create event for gEdkIIRedfishHostInterfaceReadyProtocolGuid installation.", __func__));
       return;
     }
 
-    //
-    // Acquire for Redfish service which is reported by
-    // Redfish Host Interface.
-    //
-    Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService (
-                                            gEfiRedfishDiscoverProtocol,
-                                            gRedfishConfigData.Image,
-                                            ThisNetworkInterface,
-                                            EFI_REDFISH_DISCOVER_HOST_INTERFACE,
-                                            ThisRedfishDiscoveredToken
-                                            );
-
-    //
-    // Free Redfish Discovered Token if Discover Instance was not created and
-    // Redfish Service Discovered Callback event was not triggered.
-    //
-    if ((ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound == 0) ||
-        EFI_ERROR (ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances->Status))
-    {
-      gBS->CloseEvent (ThisRedfishDiscoveredToken->Event);
-      DEBUG ((DEBUG_ERROR, "%a: Free Redfish discovered token - %x.\n", __func__, ThisRedfishDiscoveredToken));
-      FreePool (ThisRedfishDiscoveredToken);
+    Status = gBS->RegisterProtocolNotify (
+                    &gEdkIIRedfishHostInterfaceReadyProtocolGuid,
+                    mEdkIIRedfishHostInterfaceReadyEvent,
+                    &mEdkIIRedfishHostInterfaceRegistration
+                    );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installation of gEdkIIRedfishHostInterfaceReadyProtocolGuid.", __func__));
+      return;
     }
-
-    ThisNetworkInterface++;
   }
 
   return;
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111663): https://edk2.groups.io/g/devel/message/111663
Mute This Topic: https://groups.io/mt/102763126/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2023-11-23  6:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23  6:47 [edk2-devel] [PATCH V2 0/8] Refine BMC USB NIC discovery and Redfish service enablement Chang, Abner via groups.io
2023-11-23  6:47 ` [edk2-devel] [PATCH V2 1/8] RedfishPkg/BmcUsbNicLib: Update BMC USB NIC searching algorithm Chang, Abner via groups.io
2023-11-26 19:38   ` Mike Maslenkin
2023-11-27  4:32     ` Chang, Abner via groups.io
2023-11-23  6:47 ` [edk2-devel] [PATCH V2 2/8] RedfishPkg/RedfishHostInterfaceDxe: Add Redfish HI readiness notification Chang, Abner via groups.io
2023-11-26 19:35   ` Mike Maslenkin
2023-11-27  4:33     ` Chang, Abner via groups.io
2023-11-23  6:47 ` Chang, Abner via groups.io [this message]
2023-11-23  6:47 ` [edk2-devel] [PATCH V2 4/8] RedfishPkg/RedfishConfigHandler: Correct the prototype of callback function Chang, Abner via groups.io
2023-11-23  6:47 ` [edk2-devel] [PATCH V2 5/8] RedfishPkg/RedfishDiscovery: Add more debug message Chang, Abner via groups.io
2023-11-23  6:47 ` [edk2-devel] [PATCH V2 6/8] RedfishPkg/RedfishDiscovery: Refine SMBIOS 42h code Chang, Abner via groups.io
2023-11-23  6:47 ` [edk2-devel] [PATCH V2 7/8] RedfishPkg/HostInterfaceBmcUsbNic: Fix incorrect reference of MAC address pointer Chang, Abner via groups.io
2023-11-23  6:47 ` [edk2-devel] [PATCH V2 8/8] RedfishPkg/HostInterfaceBmcUsbNic: Fix incorrect HI protocol record size Chang, Abner via groups.io
2023-11-26 19:30   ` Mike Maslenkin
2023-11-27  4:38     ` Chang, Abner via groups.io
2023-11-26 19:46 ` [edk2-devel] [PATCH V2 0/8] Refine BMC USB NIC discovery and Redfish service enablement Mike Maslenkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231123064719.1248-4-abner.chang@amd.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox