Skip to content

Commit

Permalink
Revert "RedfishPkg: RedfishDiscoverDxe: Optimize the Redfish Discover…
Browse files Browse the repository at this point in the history
… flow"

This reverts commit 3db76e6.

Signed-off-by: Liming Gao <gaoliming@byosoft.com.cn>
  • Loading branch information
lgao4 authored and mergify[bot] committed Nov 22, 2023
1 parent 23dbb8a commit 15538bc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 105 deletions.
132 changes: 33 additions & 99 deletions RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,9 @@ GetTargetNetworkInterfaceInternal (
{
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;

if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
return NULL;
}

ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
if ((MAC_COMPARE (ThisNetworkInterface, TargetNetworkInterface) == 0) &&
(VALID_TCP6 (TargetNetworkInterface, ThisNetworkInterface) ||
VALID_TCP4 (TargetNetworkInterface, ThisNetworkInterface)))
{
if (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize) == 0) {
return ThisNetworkInterface;
}

Expand Down Expand Up @@ -361,10 +354,6 @@ GetTargetNetworkInterfaceInternalByController (
{
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface;

if (IsListEmpty (&mEfiRedfishDiscoverNetworkInterface)) {
return NULL;
}

ThisNetworkInterface = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
if (ThisNetworkInterface->OpenDriverControllerHandle == ControllerHandle) {
Expand Down Expand Up @@ -487,42 +476,6 @@ CheckIsIpVersion6 (
return FALSE;
}

/**
This function returns the IP type supported by the Host Interface.
@retval 00h is Unknown
01h is Ipv4
02h is Ipv6
**/
UINT8
GetHiIpProtocolType (
VOID
)
{
EFI_STATUS Status;
REDFISH_OVER_IP_PROTOCOL_DATA *Data;
REDFISH_INTERFACE_DATA *DeviceDescriptor;

Data = NULL;
DeviceDescriptor = NULL;
if (mSmbios == NULL) {
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&mSmbios);
if (EFI_ERROR (Status)) {
return REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
}
}

Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor, &Data); // Search for SMBIOS type 42h
if (!EFI_ERROR (Status) && (Data != NULL) &&
(Data->HostIpAssignmentType == RedfishHostIpAssignmentStatic))
{
return Data->HostIpAddressFormat;
}

return REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_UNKNOWN;
}

/**
This function discover Redfish service through SMBIOS host interface.
Expand Down Expand Up @@ -559,18 +512,6 @@ DiscoverRedfishHostInterface (

Status = RedfishGetHostInterfaceProtocolData (mSmbios, &DeviceDescriptor, &Data); // Search for SMBIOS type 42h
if (!EFI_ERROR (Status) && (Data != NULL) && (DeviceDescriptor != NULL)) {
if ((Instance->NetworkInterface->NetworkProtocolType == ProtocolTypeTcp4) &&
(Data->HostIpAddressFormat != REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4)) // IPv4 case
{
DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv4, but Host Interface requires Ipv6\n", __func__));
return EFI_UNSUPPORTED;
} else if ((Instance->NetworkInterface->NetworkProtocolType == ProtocolTypeTcp6) &&
(Data->HostIpAddressFormat != REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6)) // IPv6 case
{
DEBUG ((DEBUG_ERROR, "%a: Network Interface is IPv6, but Host Interface requires IPv4\n", __func__));
return EFI_UNSUPPORTED;
}

//
// Check if we can reach out Redfish service using this network interface.
// Check with MAC address using Device Descriptor Data Device Type 04 and Type 05.
Expand Down Expand Up @@ -1161,7 +1102,6 @@ RedfishServiceGetNetworkInterface (
OUT EFI_REDFISH_DISCOVER_NETWORK_INTERFACE **NetworkIntfInstances
)
{
EFI_STATUS Status;
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterfaceIntn;
EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface;
EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance;
Expand Down Expand Up @@ -1201,23 +1141,13 @@ RedfishServiceGetNetworkInterface (

ThisNetworkInterfaceIntn = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
while (TRUE) {
// If Get Subnet Info failed then skip this interface
Status = NetworkInterfaceGetSubnetInfo (ThisNetworkInterfaceIntn, ImageHandle); // Get subnet info
if (EFI_ERROR (Status)) {
if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterfaceIntn->Entry)) {
break;
}

ThisNetworkInterfaceIntn = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetNextNode (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInterfaceIntn->Entry);
continue;
}

ThisNetworkInterface->IsIpv6 = FALSE;
if (CheckIsIpVersion6 (ThisNetworkInterfaceIntn)) {
ThisNetworkInterface->IsIpv6 = TRUE;
}

CopyMem ((VOID *)&ThisNetworkInterface->MacAddress, &ThisNetworkInterfaceIntn->MacAddress, ThisNetworkInterfaceIntn->HwAddressSize);
NetworkInterfaceGetSubnetInfo (ThisNetworkInterfaceIntn, ImageHandle); // Get subnet info.
if (!ThisNetworkInterface->IsIpv6) {
IP4_COPY_ADDRESS (&ThisNetworkInterface->SubnetId.v4, &ThisNetworkInterfaceIntn->SubnetAddr.v4); // IPv4 subnet information.
} else {
Expand Down Expand Up @@ -1300,12 +1230,7 @@ RedfishServiceAcquireService (

if (TargetNetworkInterface != NULL) {
TargetNetworkInterfaceInternal = GetTargetNetworkInterfaceInternal (TargetNetworkInterface);
if (TargetNetworkInterfaceInternal == NULL) {
DEBUG ((DEBUG_ERROR, "%a:No network interface on platform.\n", __func__));
return EFI_UNSUPPORTED;
}

NumNetworkInterfaces = 1;
NumNetworkInterfaces = 1;
} else {
TargetNetworkInterfaceInternal = (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface);
NumNetworkInterfaces = NumberOfNetworkInterface ();
Expand Down Expand Up @@ -1335,13 +1260,7 @@ RedfishServiceAcquireService (
// Get subnet information in case subnet information is not set because
// RedfishServiceGetNetworkInterfaces hasn't been called yet.
//
Status1 = NetworkInterfaceGetSubnetInfo (TargetNetworkInterfaceInternal, ImageHandle);
if (EFI_ERROR (Status1)) {
DEBUG ((DEBUG_ERROR, "%a: Get subnet information fail.\n", __func__));
FreePool (Instance);
continue;
}

NetworkInterfaceGetSubnetInfo (TargetNetworkInterfaceInternal, ImageHandle);
NewInstance = TRUE;
}

Expand Down Expand Up @@ -1682,22 +1601,10 @@ BuildupNetworkInterface (
EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance;
EFI_TPL OldTpl;
BOOLEAN NewNetworkInterfaceInstalled;
UINT8 IpType;
UINTN ListCount;

ListCount = (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL));
NewNetworkInterfaceInstalled = FALSE;
Index = 0;

// Get IP Type to filter out unnecessary network protocol if possible
IpType = GetHiIpProtocolType ();

for (Index = 0; Index < ListCount; Index++) {
// Check IP Type and skip an unnecessary network protocol if does not match
if (IS_TCP4_MATCH (IpType) || IS_TCP6_MATCH (IpType)) {
continue;
}

do {
Status = gBS->OpenProtocol (
// Already in list?
ControllerHandle,
Expand All @@ -1708,6 +1615,11 @@ BuildupNetworkInterface (
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (!EFI_ERROR (Status)) {
Index++;
if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
break;
}

continue;
}

Expand All @@ -1720,6 +1632,11 @@ BuildupNetworkInterface (
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
Index++;
if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
break;
}

continue;
}

Expand Down Expand Up @@ -1778,6 +1695,11 @@ BuildupNetworkInterface (
ProtocolDiscoverIdPtr
);
if (EFI_ERROR (Status)) {
Index++;
if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
break;
}

continue;
}

Expand Down Expand Up @@ -1834,13 +1756,25 @@ BuildupNetworkInterface (
}
} else {
DEBUG ((DEBUG_MANAGEABILITY, "%a: Not REST EX, continue with next\n", __func__));
Index++;
if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
break;
}

continue;
}
}

return Status;
} else {
Index++;
if (Index == (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL))) {
break;
}

continue;
}
}
} while (Index < (sizeof (gRequiredProtocol) / sizeof (REDFISH_DISCOVER_REQUIRED_PROTOCOL)));

return EFI_DEVICE_ERROR;
}
Expand Down
6 changes: 0 additions & 6 deletions RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
#define REDFISH_DISCOVER_VERSION 0x00010000
#define EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_TPL TPL_NOTIFY

#define MAC_COMPARE(ThisNetworkInterface, TargetNetworkInterface) (CompareMem ((VOID *)&ThisNetworkInterface->MacAddress, &TargetNetworkInterface->MacAddress, ThisNetworkInterface->HwAddressSize))
#define VALID_TCP6(TargetNetworkInterface, ThisNetworkInterface) (TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface->NetworkProtocolType == ProtocolTypeTcp6))
#define VALID_TCP4(TargetNetworkInterface, ThisNetworkInterface) (!TargetNetworkInterface->IsIpv6 && (ThisNetworkInterface->NetworkProtocolType == ProtocolTypeTcp4))
#define IS_TCP4_MATCH(IpType) ((gRequiredProtocol[Index].ProtocolType == ProtocolTypeTcp4) && (IpType != REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP4))
#define IS_TCP6_MATCH(IpType) ((gRequiredProtocol[Index].ProtocolType == ProtocolTypeTcp6) && (IpType != REDFISH_HOST_INTERFACE_HOST_IP_ADDRESS_FORMAT_IP6))

//
// GUID definitions
//
Expand Down

0 comments on commit 15538bc

Please sign in to comment.