Skip to content

Commit f7da805

Browse files
changabmergify[bot]
authored andcommitted
RedfishPkg/RedfishDiscoverDxe: Install protocol on each network interface
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>
1 parent 39596c4 commit f7da805

File tree

2 files changed

+81
-52
lines changed

2 files changed

+81
-52
lines changed

RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
The implementation of EFI Redfidh Discover Protocol.
44
55
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
6+
Copyright (c) 2022, AMD Incorporated. All rights reserved.
67
78
SPDX-License-Identifier: BSD-2-Clause-Patent
89
@@ -23,8 +24,6 @@ EFI_GUID mRedfishDiscoverTcp4InstanceGuid = EFI_REDFISH_DISCOVER_TCP4_INSTANC
2324
EFI_GUID mRedfishDiscoverTcp6InstanceGuid = EFI_REDFISH_DISCOVER_TCP6_INSTANCE_GUID;
2425
EFI_GUID mRedfishDiscoverRestExInstanceGuid = EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_GUID;
2526

26-
EFI_HANDLE EfiRedfishDiscoverProtocolHandle = NULL;
27-
2827
EFI_STATUS
2928
EFIAPI
3029
Tcp4GetSubnetInfo (
@@ -325,6 +324,38 @@ GetTargetNetworkInterfaceInternal (
325324
return NULL;
326325
}
327326

327+
/**
328+
This function searches EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL
329+
instance with the given Controller handle.
330+
331+
@param[in] ControllerHandle The controller handle associated with network interface.
332+
333+
@retval Non-NULL EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL is returned.
334+
@retval NULL Non of EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL instance is returned.
335+
**/
336+
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *
337+
GetTargetNetworkInterfaceInternalByController (
338+
IN EFI_HANDLE ControllerHandle
339+
)
340+
{
341+
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
342+
343+
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
344+
while (TRUE) {
345+
if (ThisNetworkInterface->OpenDriverControllerHandle == ControllerHandle) {
346+
return ThisNetworkInterface;
347+
}
348+
349+
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry)) {
350+
return NULL;
351+
}
352+
353+
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterface->Entry);
354+
}
355+
356+
return NULL;
357+
}
358+
328359
/**
329360
This function validate if target network interface is ready for discovering
330361
Redfish service.
@@ -1619,29 +1650,30 @@ BuildupNetworkInterface (
16191650
EFI_OPEN_PROTOCOL_BY_DRIVER
16201651
);
16211652
if (!EFI_ERROR (Status)) {
1622-
if ((EfiRedfishDiscoverProtocolHandle == NULL) &&
1623-
(gRequiredProtocol[Index].ProtocolType == ProtocolTypeRestEx) &&
1624-
!IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)
1625-
)
1626-
{
1627-
// Install the fisrt Redfish Discover Protocol when EFI REST EX protcol is discovered.
1628-
// This ensures EFI REST EX is ready while EFI_REDFISH_DISCOVER_PROTOCOL consumer acquires
1629-
// Redfish serivce over network interface.
1630-
1631-
Status = gBS->InstallProtocolInterface (
1632-
&EfiRedfishDiscoverProtocolHandle,
1633-
&gEfiRedfishDiscoverProtocolGuid,
1634-
EFI_NATIVE_INTERFACE,
1635-
(VOID *)&mRedfishDiscover
1636-
);
1637-
} else if ((EfiRedfishDiscoverProtocolHandle != NULL) && NewNetworkInterfaceInstalled) {
1638-
Status = gBS->ReinstallProtocolInterface (
1639-
EfiRedfishDiscoverProtocolHandle,
1640-
&gEfiRedfishDiscoverProtocolGuid,
1641-
(VOID *)&mRedfishDiscover,
1642-
(VOID *)&mRedfishDiscover
1643-
);
1644-
NewNetworkInterfaceInstalled = FALSE;
1653+
if ((gRequiredProtocol[Index].ProtocolType == ProtocolTypeRestEx)) {
1654+
// Install Redfish Discover Protocol when EFI REST EX protcol is discovered.
1655+
// This ensures EFI REST EX is ready while the consumer of EFI_REDFISH_DISCOVER_PROTOCOL
1656+
// acquires Redfish serivce over network interface.
1657+
1658+
if (!NewNetworkInterfaceInstalled) {
1659+
NetworkInterface = GetTargetNetworkInterfaceInternalByController (ControllerHandle);
1660+
if (NetworkInterface == NULL) {
1661+
DEBUG ((DEBUG_ERROR, "%a: Can't find network interface by ControllerHandle\n", __FUNCTION__));
1662+
return Status;
1663+
}
1664+
}
1665+
1666+
NewNetworkInterfaceInstalled = FALSE;
1667+
NetworkInterface->EfiRedfishDiscoverProtocolHandle = NULL;
1668+
Status = gBS->InstallProtocolInterface (
1669+
&NetworkInterface->EfiRedfishDiscoverProtocolHandle,
1670+
&gEfiRedfishDiscoverProtocolGuid,
1671+
EFI_NATIVE_INTERFACE,
1672+
(VOID *)&mRedfishDiscover
1673+
);
1674+
if (EFI_ERROR (Status)) {
1675+
DEBUG ((DEBUG_ERROR, "%a: Fail to install EFI_REDFISH_DISCOVER_PROTOCOL\n", __FUNCTION__));
1676+
}
16451677
}
16461678
}
16471679

@@ -1724,6 +1756,7 @@ StopServiceOnNetworkInterface (
17241756
EFI_STATUS Status;
17251757
VOID *Interface;
17261758
EFI_TPL OldTpl;
1759+
EFI_HANDLE DiscoverProtocolHandle;
17271760
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;
17281761
EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance;
17291762

@@ -1743,8 +1776,11 @@ StopServiceOnNetworkInterface (
17431776
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
17441777
while (TRUE) {
17451778
if (ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle == ControllerHandle) {
1779+
DiscoverProtocolHandle = ThisNetworkInterface->EfiRedfishDiscoverProtocolHandle;
1780+
//
1781+
// Close protocol and destroy service.
1782+
//
17461783
Status = CloseProtocolService (
1747-
// Close protocol and destroy service.
17481784
ThisBindingProtocol,
17491785
ControllerHandle,
17501786
&gRequiredProtocol[Index],
@@ -1756,17 +1792,18 @@ StopServiceOnNetworkInterface (
17561792
}
17571793

17581794
gBS->RestoreTPL (OldTpl);
1759-
// Reinstall Redfish Discover protocol to notify network
1760-
// interface change.
1761-
1762-
Status = gBS->ReinstallProtocolInterface (
1763-
EfiRedfishDiscoverProtocolHandle,
1764-
&gEfiRedfishDiscoverProtocolGuid,
1765-
(VOID *)&mRedfishDiscover,
1766-
(VOID *)&mRedfishDiscover
1767-
);
1768-
if (EFI_ERROR (Status)) {
1769-
DEBUG ((DEBUG_ERROR, "%a: Reinstall gEfiRedfishDiscoverProtocolGuid fail.", __FUNCTION__));
1795+
1796+
//
1797+
// Disconnect EFI Redfish discover driver controller to notify the
1798+
// clinet which uses .EFI Redfish discover protocol.
1799+
//
1800+
if (DiscoverProtocolHandle != NULL) {
1801+
gBS->DisconnectController (DiscoverProtocolHandle, NULL, NULL);
1802+
Status = gBS->UninstallProtocolInterface (
1803+
DiscoverProtocolHandle,
1804+
&gEfiRedfishDiscoverProtocolGuid,
1805+
(VOID *)&mRedfishDiscover
1806+
);
17701807
}
17711808

17721809
return Status;
@@ -2032,20 +2069,5 @@ RedfishDiscoverUnload (
20322069
StopServiceOnNetworkInterface (&gRedfishDiscoverDriverBinding, ThisNetworkInterface->NetworkInterfaceProtocolInfo.ProtocolControllerHandle);
20332070
}
20342071

2035-
// Disconnect EFI Redfish discover driver controller to notify the
2036-
// clinet which uses .EFI Redfish discover protocol.
2037-
2038-
if (EfiRedfishDiscoverProtocolHandle != NULL) {
2039-
//
2040-
// Notify user EFI_REDFISH_DISCOVER_PROTOCOL is unloaded.
2041-
//
2042-
gBS->DisconnectController (EfiRedfishDiscoverProtocolHandle, NULL, NULL);
2043-
Status = gBS->UninstallProtocolInterface (
2044-
EfiRedfishDiscoverProtocolHandle,
2045-
&gEfiRedfishDiscoverProtocolGuid,
2046-
(VOID *)&mRedfishDiscover
2047-
);
2048-
}
2049-
20502072
return Status;
20512073
}

RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This file defines the EFI Redfish Discover Protocol interface.
33
44
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
5+
Copyright (c) 2022, AMD Incorporated. All rights reserved.
56
67
SPDX-License-Identifier: BSD-2-Clause-Patent
78
@@ -107,6 +108,12 @@ typedef struct {
107108
///< NETWORK_INTERFACE_PROTOCOL_TYPE.
108109
REDFISH_DISCOVER_NETWORK_INTERFACE_PROTOCOL NetworkInterfaceProtocolInfo; ///< Network interface protocol information.
109110
EFI_HANDLE RestExHandle; ///< REST EX handle associated with this network interface.
111+
//
112+
// EFI_REDFISH_DISCOVER_PROTOCOL instance installed
113+
// on this network interface.
114+
//
115+
EFI_HANDLE EfiRedfishDiscoverProtocolHandle; ///< EFI_REDFISH_DISCOVER_PROTOTOCOL instance installed
116+
///< on this network interface.
110117
} EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL;
111118

112119
//

0 commit comments

Comments
 (0)