3
3
The implementation of EFI Redfidh Discover Protocol.
4
4
5
5
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
6
+ Copyright (c) 2022, AMD Incorporated. All rights reserved.
6
7
7
8
SPDX-License-Identifier: BSD-2-Clause-Patent
8
9
@@ -23,8 +24,6 @@ EFI_GUID mRedfishDiscoverTcp4InstanceGuid = EFI_REDFISH_DISCOVER_TCP4_INSTANC
23
24
EFI_GUID mRedfishDiscoverTcp6InstanceGuid = EFI_REDFISH_DISCOVER_TCP6_INSTANCE_GUID ;
24
25
EFI_GUID mRedfishDiscoverRestExInstanceGuid = EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_GUID ;
25
26
26
- EFI_HANDLE EfiRedfishDiscoverProtocolHandle = NULL ;
27
-
28
27
EFI_STATUS
29
28
EFIAPI
30
29
Tcp4GetSubnetInfo (
@@ -325,6 +324,38 @@ GetTargetNetworkInterfaceInternal (
325
324
return NULL ;
326
325
}
327
326
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
+
328
359
/**
329
360
This function validate if target network interface is ready for discovering
330
361
Redfish service.
@@ -1619,29 +1650,30 @@ BuildupNetworkInterface (
1619
1650
EFI_OPEN_PROTOCOL_BY_DRIVER
1620
1651
);
1621
1652
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
+ }
1645
1677
}
1646
1678
}
1647
1679
@@ -1724,6 +1756,7 @@ StopServiceOnNetworkInterface (
1724
1756
EFI_STATUS Status ;
1725
1757
VOID * Interface ;
1726
1758
EFI_TPL OldTpl ;
1759
+ EFI_HANDLE DiscoverProtocolHandle ;
1727
1760
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * ThisNetworkInterface ;
1728
1761
EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL * RestExInstance ;
1729
1762
@@ -1743,8 +1776,11 @@ StopServiceOnNetworkInterface (
1743
1776
ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL * )GetFirstNode (& mEfiRedfishDiscoverNetworkInterface );
1744
1777
while (TRUE) {
1745
1778
if (ThisNetworkInterface -> NetworkInterfaceProtocolInfo .ProtocolControllerHandle == ControllerHandle ) {
1779
+ DiscoverProtocolHandle = ThisNetworkInterface -> EfiRedfishDiscoverProtocolHandle ;
1780
+ //
1781
+ // Close protocol and destroy service.
1782
+ //
1746
1783
Status = CloseProtocolService (
1747
- // Close protocol and destroy service.
1748
1784
ThisBindingProtocol ,
1749
1785
ControllerHandle ,
1750
1786
& gRequiredProtocol [Index ],
@@ -1756,17 +1792,18 @@ StopServiceOnNetworkInterface (
1756
1792
}
1757
1793
1758
1794
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
+ );
1770
1807
}
1771
1808
1772
1809
return Status ;
@@ -2032,20 +2069,5 @@ RedfishDiscoverUnload (
2032
2069
StopServiceOnNetworkInterface (& gRedfishDiscoverDriverBinding , ThisNetworkInterface -> NetworkInterfaceProtocolInfo .ProtocolControllerHandle );
2033
2070
}
2034
2071
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
-
2050
2072
return Status ;
2051
2073
}
0 commit comments