From nobody Fri Apr 26 03:36:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+101408+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1679300077503246.52933277837644; Mon, 20 Mar 2023 01:14:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eeJ3YY1788612xRZXxRuwNqU; Mon, 20 Mar 2023 01:14:37 -0700 X-Received: from NAM04-BN8-obe.outbound.protection.outlook.com (NAM04-BN8-obe.outbound.protection.outlook.com [40.107.100.68]) by mx.groups.io with SMTP id smtpd.web10.8872.1679300076184908899 for ; Mon, 20 Mar 2023 01:14:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dlT94I6rTRQUCQTEPCz98goluUBCRb4JeYKBwcci03XMwxiWYDSCBWBGIVHyTopXkoQKjLBjslsPQKtZ8jG5ngPCfwPnHQjjW573UVuNT+If3VXZMehuBFiT3GSrH5yMggo8Y8PLpAdpPwIDn6I3Z+SnyTN3teqUXAvpL0gWQROp8jhxHuyP5qMV0aidcBFXDnyXbNpV45pDhrdedXmi+UURyNddgSa6MAn6bv1p3V38PS6naBB/vrS36fQy++h8Rid/DO1jSG70httgR75H52GkABDAYkw18kCGrOOxl6QNclyasFQiyxQrMTMq0DSob1FEV39NAxhLSG7PsqtmLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5XkpIXuyLckFGiQcPPBENqXLDOtg+7bBroQYvhBAmg0=; b=kcQqQIv3XqTkzzmZFa2jeqEzJriaYMI7JxInNI/1s9WDFoOV4JmgiVyxJPIIcglADWF9e9ygdI1csxNKgZCJtnTSupP5Gru+eq8xELkNpyxN789ZH2n9NRz9hdkC8zalgleQq0ID9+w9w3eBlAGEP5qjZ+V6TnocY1n2+NOTKtYm/k6v544HijunuSFlDzKRfLFmlLFUe+qcSSHxIOsvh98puVofDowiba5iY23Z/f5qRSxZC30kzSNRfPSWSz8fV+0RyoTyAesoqMMKKCIYHSU6fmy8oC9PJdQ/3EP/M9H18Ur0L2rEVqiq+A3UNGjLKN/1WER/EyjWgi8WJvtPKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from BN9PR03CA0655.namprd03.prod.outlook.com (2603:10b6:408:13b::30) by LV2PR12MB5917.namprd12.prod.outlook.com (2603:10b6:408:175::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Mon, 20 Mar 2023 08:14:32 +0000 X-Received: from BN8NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13b:cafe::fa) by BN9PR03CA0655.outlook.office365.com (2603:10b6:408:13b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Mon, 20 Mar 2023 08:14:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+101408+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT028.mail.protection.outlook.com (10.13.176.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.15 via Frontend Transport; Mon, 20 Mar 2023 08:14:31 +0000 X-Received: from TPE-L1-ABNCHANG.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 20 Mar 2023 03:14:29 -0500 From: "Chang, Abner via groups.io" To: CC: Nickle Wang , Igor Kulchytskyy Subject: [edk2-devel] [PATCH v2 1/3] RedfishPkg/Library: Redfish BMC USBNIC Host Interface Date: Mon, 20 Mar 2023 16:13:51 +0800 Message-ID: <20230320081353.1335-2-abner.chang@amd.com> In-Reply-To: <20230320081353.1335-1-abner.chang@amd.com> References: <20230320081353.1335-1-abner.chang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT028:EE_|LV2PR12MB5917:EE_ X-MS-Office365-Filtering-Correlation-Id: 1844de25-51f2-4f67-ffd6-08db291b2252 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: Sbb/lnA+yuPvspNNGo9Qs5oaUU05gJFXXTbVtoCEotqBNp9N4eQdYAyAs1QWJjMb2gDagE9alsTlNbM4/uW1Mf5ikNp+Wc/ZMolrOvI6qeFRu+lE8pIURIk1u6YROx//50XzV3l7SZfrb7ckwCc1yyyH32bZnccE2v1687Zb0AzQiCzIquhQ71BIivkQKnMeVQ21xz3tyxyA+rVKHKRvATb/QHrBS7/NehB/RDL8VLdooJf4JC/lvzvsHMt1NHz0qxIUV4StizjZRJT6LXZSuqzdyOpyRcTZRoMxEOufwCqMKhRHD+bYDDz3IvecdlnIHX3sbtgCEy//cf7is52FA27mlzZhWeSg0Fs+gNMfYsfikthujUXcxS8QNpurZyRZhQ6PDF/EQCFwvbUYhObKlbf2lAQhO5WgXBvz9YirQD/UijChj/VJ+TXfm4iPzq0TIQzTScKEKMAc+FWYZoQULzAbKmyx2GuOik9V6y1mjC31SGoGuPDgnkojFjek133KViBiogJL6PacfRhgdFw98JchplHsAMeBXQQBH4LC66Mv0dNBT8KckaUUNpIX3m8fGv5IHHJptS7z6z5vWO4ZRz/v4nC2xUBCGr+PVs57VPdz6sX+QSCbW9F55Bj2iod6U1daqhp+YgvgTOm2SufO1eWwVDJL7kWtj42r4N7kNFJmzZEv20aKwIy23W3ekIZwsJrD/ztFRJWm5QZ9ouoS0OQ7fvHqmHP9PoGFlLJsIDQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2023 08:14:31.9465 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1844de25-51f2-4f67-ffd6-08db291b2252 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5917 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@amd.com X-Gm-Message-State: MUkL8CYDCHijYSh7vBAywEmix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679300077; bh=6DPNefnYFGyKg5QpSDF97+kNCu/D7BSj/DDJGYctZDo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=LC+t/lOM9nxMeyhNzO60FrXqDfjRl78T77z75BcmhhYPrzraAgjvy+MOg4TLg9G8os7 GGaGWEpMPj97waR2+MgRdPdKcs8Eie6RbvB2zP+g1mkLcG6OKkG0j8Wwv3vAWNzo0Nk/R cBz2Sc/OCsVr8i1WwYEv04NrgtL6aHDX8v8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679300079859100002 Content-Type: text/plain; charset="utf-8" From: Abner Chang BMC exposed USB NIC platform Redfish Host Interface library implementation. Signed-off-by: Abner Chang Cc: Nickle Wang Cc: Igor Kulchytskyy Reviewed-by: Nickle Wang --- RedfishPkg/RedfishPkg.dec | 10 + .../PlatformHostInterfaceBmcUsbNicLib.inf | 48 + RedfishPkg/Include/Library/RedfishDebugLib.h | 3 +- .../PlatformHostInterfaceBmcUsbNicLib.h | 84 ++ .../PlatformHostInterfaceBmcUsbNicLib.c | 1291 +++++++++++++++++ 5 files changed, 1435 insertions(+), 1 deletion(-) create mode 100644 RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/Pl= atformHostInterfaceBmcUsbNicLib.inf create mode 100644 RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/Pl= atformHostInterfaceBmcUsbNicLib.h create mode 100644 RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/Pl= atformHostInterfaceBmcUsbNicLib.c diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec index 53e52c2b008..42d28d6dac3 100644 --- a/RedfishPkg/RedfishPkg.dec +++ b/RedfishPkg/RedfishPkg.dec @@ -113,3 +113,13 @@ # Default is set to not add. # gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExAddingExpect|FALSE|BOOLEAN|= 0x00001004 + # + # Use PCD to declare the Redfish host nmae becasue there is no + # specification for that. + # + gEfiRedfishPkgTokenSpaceGuid.PcdRedfishHostName|"Redfish service"|VOID*|= 0x00001005 + # + # Use PCD to declare the Redfish service UUID becasue there is no + # specification for that. + # + gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceUuid|L"00000000-0000-0000-= 0000-000000000000"|VOID*|0x00001006 diff --git a/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformH= ostInterfaceBmcUsbNicLib.inf b/RedfishPkg/Library/PlatformHostInterfaceBmcU= sbNicLib/PlatformHostInterfaceBmcUsbNicLib.inf new file mode 100644 index 00000000000..f2c7d7fec89 --- /dev/null +++ b/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformHostInte= rfaceBmcUsbNicLib.inf @@ -0,0 +1,48 @@ +## @file +# Module to provide the platform Redfish Host Interface information +# of USB NIC Device exposed by BMC. +# +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001000b + BASE_NAME =3D PlatformHostInterfaceBmcUsbNicLib + FILE_GUID =3D C4837B58-225E-4352-8FDC-4C52A5D65891 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PlatformHostInterfaceBmcUsbNicLib + +[Sources] + PlatformHostInterfaceBmcUsbNicLib.c + PlatformHostInterfaceBmcUsbNicLib.h + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + NetworkPkg/NetworkPkg.dec + RedfishPkg/RedfishPkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + IpmiLib + IpmiCommandLib + MemoryAllocationLib + UefiLib + UefiBootServicesTableLib + +[Protocols] + gEfiSimpleNetworkProtocolGuid ## CONSUMED + gEfiUsbIoProtocolGuid ## CONSUMED + gEfiDevicePathProtocolGuid ## CONSUMED + +[Pcd] + gEfiRedfishPkgTokenSpaceGuid.PcdRedfishHostName ## CONSUMED + gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceUuid ## CONSUMED + +[Depex] + gIpmiProtocolGuid diff --git a/RedfishPkg/Include/Library/RedfishDebugLib.h b/RedfishPkg/Incl= ude/Library/RedfishDebugLib.h index 21f01353ede..913f2b2f358 100644 --- a/RedfishPkg/Include/Library/RedfishDebugLib.h +++ b/RedfishPkg/Include/Library/RedfishDebugLib.h @@ -14,7 +14,8 @@ #include #include =20 -#define DEBUG_REDFISH_NETWORK DEBUG_INFO ///< Debug error level for Red= fish networking function +#define DEBUG_REDFISH_NETWORK DEBUG_INFO ///< Debug error level = for Redfish networking function +#define DEBUG_REDFISH_HOST_INTERFACE DEBUG_INFO ///< Debug error level = for Redfish networking function =20 /** =20 diff --git a/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformH= ostInterfaceBmcUsbNicLib.h b/RedfishPkg/Library/PlatformHostInterfaceBmcUsb= NicLib/PlatformHostInterfaceBmcUsbNicLib.h new file mode 100644 index 00000000000..669c304fc3d --- /dev/null +++ b/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformHostInte= rfaceBmcUsbNicLib.h @@ -0,0 +1,84 @@ +/** @file + Header file to provide the platform Redfish Host Interface information + of USB NIC Device exposed by BMC. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PLATFORM_HOST_INTERFACE_BMC_USB_NIC_LIB_H_ +#define PLATFORM_HOST_INTERFACE_BMC_USB_NIC_LIB_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define BMC_USB_NIC_HOST_INTERFASCE_READINESS_GUID \ + { \ + 0xDD96F5D7, 0x4AE1, 0x4E6C, {0xA1, 0x30, 0xA5, 0xAC, 0x77, 0xDD, 0xE= 4, 0xA5} \ + } + +// +// This is the structure for BMC exposed +// USB NIC information. +// +typedef struct { + LIST_ENTRY NextInstance; ///< Link to t= he next instance. + BOOLEAN IsExposedByBmc; ///< Flag indi= cates this USB NIC is + ///< exposed b= y BMC. + BOOLEAN IsSuppportedHostInterface; ///< This BMC = USB NIC is supported + ///< as Redfis= h host interface + EFI_SIMPLE_NETWORK_PROTOCOL *ThisSnp; ///< The SNP i= nstance associated with + ///< this USB = NIC. + EFI_USB_IO_PROTOCOL *ThisUsbIo; ///< The USBIO= instance associated with + ///< this USB = NIC. + UINT16 UsbVendorId; ///< USB Vendo= r ID of this BMC exposed USB NIC. + UINT16 UsbProductId; ///< USB Produ= ct ID of this BMC exposed USB NIC. + UINTN MacAddressSize; ///< HW addres= s size. + UINT8 *MacAddress; ///< HW addres= s. + UINT8 IpmiLanChannelNumber; ///< BMC IPMI = Lan Channel number. + + // + // Below is the infortmation for building SMBIOS type 42. + // + UINT8 IpAssignedType; ///< Redfish ser= vice IP assign type. + UINT8 IpAddressFormat; ///< Redfish ser= vice IP version. + UINT8 HostIpAddressIpv4[4]; ///< Host IP add= ress. + UINT8 RedfishIpAddressIpv4[4]; ///< Redfish ser= vice IP address. + UINT8 SubnetMaskIpv4[4]; ///< Subnet mask. + UINT8 GatewayIpv4[4]; ///< Gateway IP = address. + UINT16 VLanId; ///< VLAN ID. + BOOLEAN CredentialBootstrapping; ///< If Credenti= al bootstrapping is + ///< supported. +} HOST_INTERFACE_BMC_USB_NIC_INFO; + +// +// This is the structure for caching +// BMC IPMI LAN Channel +// +typedef struct { + LIST_ENTRY NextInstance; ///< Link to the next IPMI L= AN Channel. + UINT8 Channel; ///< IPMI Channel number. + EFI_MAC_ADDRESS MacAddress; ///< IPMI LAN Channel MAC ad= dress. + UINT8 MacAddressSize; ///< MAC address size; +} BMC_IPMI_LAN_CHANNEL_INFO; +#endif diff --git a/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformH= ostInterfaceBmcUsbNicLib.c b/RedfishPkg/Library/PlatformHostInterfaceBmcUsb= NicLib/PlatformHostInterfaceBmcUsbNicLib.c new file mode 100644 index 00000000000..718f05c98fc --- /dev/null +++ b/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformHostInte= rfaceBmcUsbNicLib.c @@ -0,0 +1,1291 @@ +/** @file + Source file to provide the platform Redfish Host Interface information + of USB NIC Device exposed by BMC. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "PlatformHostInterfaceBmcUsbNicLib.h" + +static EFI_GUID mPlatformHostInterfaceBmcUsbNicReadinessGuid =3D + BMC_USB_NIC_HOST_INTERFASCE_READINESS_GUID; +static EFI_EVENT mPlatformHostInterfaceSnpEvent =3D NULL; +static VOID *mPlatformHostInterfaceSnpRegistration =3D NULL; + +static LIST_ENTRY mBmcUsbNic; +static LIST_ENTRY mBmcIpmiLan; + +/** + Probe if the system supports Redfish Host Interface Credentail + Bootstrapping. + + @retval TRUE Yes, it is supported. + TRUE No, it is not supported. + +**/ +BOOLEAN +ProbeRedfishCredentialBootstrap ( + VOID + ) +{ + EFI_STATUS Status; + IPMI_BOOTSTRAP_CREDENTIALS_COMMAND_DATA CommandData; + IPMI_BOOTSTRAP_CREDENTIALS_RESULT_RESPONSE ResponseData; + UINT32 ResponseSize; + BOOLEAN ReturnBool; + + DEBUG ((DEBUG_INFO, "%a: Entry\n", __FUNCTION__)); + + // + // IPMI callout to NetFn 2C, command 02 + // Request data: + // Byte 1: REDFISH_IPMI_GROUP_EXTENSION + // Byte 2: DisableBootstrapControl + // + CommandData.GroupExtensionId =3D REDFISH_IPMI_GROUP_EXTENSION; + CommandData.DisableBootstrapControl =3D REDFISH_IPMI_BOOTSTRAP_CREDENTIA= L_ENABLE; + ResponseData.CompletionCode =3D IPMI_COMP_CODE_UNSPECIFIED; + ResponseSize =3D sizeof (ResponseData); + // + // Response data: Ignored. + // + Status =3D IpmiSubmitCommand ( + IPMI_NETFN_GROUP_EXT, + REDFISH_IPMI_GET_BOOTSTRAP_CREDENTIALS_CMD, + (UINT8 *)&CommandData, + sizeof (CommandData), + (UINT8 *)&ResponseData, + &ResponseSize + ); + if (!EFI_ERROR (Status) && + ((ResponseData.CompletionCode =3D=3D IPMI_COMP_CODE_NORMAL) || + (ResponseData.CompletionCode =3D=3D REDFISH_IPMI_COMP_CODE_BOOTSTRA= P_CREDENTIAL_DISABLED) + )) + { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " Redfish Credentail Bootstra= pping is supported\n", __FUNCTION__)); + ReturnBool =3D TRUE; + } else { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " Redfish Credentail Bootstra= pping is not supported\n", __FUNCTION__)); + ReturnBool =3D FALSE; + } + + return ReturnBool; +} + +/** + Get platform Redfish host interface device descriptor. + + @param[in] DeviceType Pointer to retrieve device type. + @param[out] DeviceDescriptor Pointer to retrieve REDFISH_INTERFACE_DATA= , caller has to free + this memory using FreePool(). + + @retval EFI_NOT_FOUND No Redfish host interface descriptor provided on= this platform. + +**/ +EFI_STATUS +RedfishPlatformHostInterfaceDeviceDescriptor ( + IN UINT8 *DeviceType, + OUT REDFISH_INTERFACE_DATA **DeviceDescriptor + ) +{ + HOST_INTERFACE_BMC_USB_NIC_INFO *ThisInstance; + REDFISH_INTERFACE_DATA *InterfaceData; + + DEBUG ((DEBUG_INFO, "%a: Entry\n", __FUNCTION__)); + + if (IsListEmpty (&mBmcUsbNic)) { + return EFI_NOT_FOUND; + } + + // Check if BMC exposed USB NIC is found and ready for using. + ThisInstance =3D (HOST_INTERFACE_BMC_USB_NIC_INFO *)GetFirstNode (&mBmcU= sbNic); + while (TRUE) { + if (ThisInstance->IsExposedByBmc && ThisInstance->IsSuppportedHostInte= rface) { + *DeviceType =3D REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2; + + // Fill up REDFISH_INTERFACE_DATA defined in Redfish host interface = spec v1.3 + InterfaceData =3D (REDFISH_INTERFACE_DATA *)AllocateZeroPool (USB_IN= TERFACE_DEVICE_DESCRIPTOR_V2_SIZE_1_3); + if (InterfaceData =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "Failed to allocate memory for REDFISH_INTERF= ACE_DATA\n")); + return EFI_OUT_OF_RESOURCES; + } + + InterfaceData->DeviceType =3D REDF= ISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2; + InterfaceData->DeviceDescriptor.UsbDeviceV2.Length =3D USB_= INTERFACE_DEVICE_DESCRIPTOR_V2_SIZE_1_3; + InterfaceData->DeviceDescriptor.UsbDeviceV2.IdVendor =3D This= Instance->UsbVendorId; + InterfaceData->DeviceDescriptor.UsbDeviceV2.IdProduct =3D This= Instance->UsbProductId; + InterfaceData->DeviceDescriptor.UsbDeviceV2.SerialNumberStr =3D 0; + CopyMem ( + (VOID *)&InterfaceData->DeviceDescriptor.UsbDeviceV2.MacAddress, + (VOID *)&ThisInstance->MacAddress, + sizeof (InterfaceData->DeviceDescriptor.UsbDeviceV2.MacAddress) + ); + InterfaceData->DeviceDescriptor.UsbDeviceV2.Characteristics = |=3D (UINT16)ThisInstance->CredentialBootstrapping; + InterfaceData->DeviceDescriptor.UsbDeviceV2.CredentialBootstrappingH= andle =3D 0; + *DeviceDescriptor = =3D InterfaceData; + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " REDFISH_INTERFACE_DATA is= returned successfully.\n")); + return EFI_SUCCESS; + } + + if (IsNodeAtEnd (&mBmcUsbNic, &ThisInstance->NextInstance)) { + break; + } + + ThisInstance =3D (HOST_INTERFACE_BMC_USB_NIC_INFO *) + GetNextNode (&mBmcUsbNic, &ThisInstance->NextInstance); + } + + return EFI_NOT_FOUND; +} + +/** + Get platform Redfish host interface protocol data. + Caller should pass NULL in ProtocolRecord to retrive the first protocol = record. + Then continuously pass previous ProtocolRecord for retrieving the next P= rotocolRecord. + + @param[in, out] ProtocolRecord Pointer to retrieve the first or the nex= t protocol record. + caller has to free the new protocol reco= rd returned from + this function using FreePool(). + @param[in] IndexOfProtocolData The index of protocol data. + + @retval EFI_NOT_FOUND No more protocol records. + +**/ +EFI_STATUS +RedfishPlatformHostInterfaceProtocolData ( + IN OUT MC_HOST_INTERFACE_PROTOCOL_RECORD **ProtocolRecord, + IN UINT8 IndexOfProtocolData + ) +{ + HOST_INTERFACE_BMC_USB_NIC_INFO *ThisInstance; + MC_HOST_INTERFACE_PROTOCOL_RECORD *ThisProtocolRecord; + REDFISH_OVER_IP_PROTOCOL_DATA *RedfishOverIpData; + UINT8 HostNameLength; + CHAR8 *HostNameString; + + DEBUG ((DEBUG_INFO, "%a: Entry\n", __FUNCTION__)); + + if (IsListEmpty (&mBmcUsbNic) || (IndexOfProtocolData > 0)) { + return EFI_NOT_FOUND; + } + + ThisInstance =3D (HOST_INTERFACE_BMC_USB_NIC_INFO *)GetFirstNode (&mBmcU= sbNic); + while (TRUE) { + if (ThisInstance->IsExposedByBmc && ThisInstance->IsSuppportedHostInt= erface) { + // Get the host name before allocating memory. + HostNameString =3D (CHAR8 *)PcdGetPtr (PcdRedfishHostName); + HostNameLength =3D (UINT8)AsciiStrSize (HostNameString); + ThisProtocolRecord =3D (MC_HOST_INTERFACE_PROTOCOL_RECORD *)Allocate= ZeroPool ( + sizeof (= MC_HOST_INTERFACE_PROTOCOL_RECORD) - 1 + + sizeof (= REDFISH_OVER_IP_PROTOCOL_DATA) + + HostName= Length + ); + if (ThisProtocolRecord =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, " Allocate memory fail for MC_HOST_INTERFA= CE_PROTOCOL_RECORD.\n")); + return EFI_OUT_OF_RESOURCES; + } + + ThisProtocolRecord->ProtocolType =3D MCHostInterfaceProtocolT= ypeRedfishOverIP; + ThisProtocolRecord->ProtocolTypeDataLen =3D sizeof (REDFISH_OVER_IP_= PROTOCOL_DATA) + HostNameLength; + RedfishOverIpData =3D (REDFISH_OVER_IP_PROTOCO= L_DATA *)&ThisProtocolRecord->ProtocolTypeData[0]; + // + // Fill up REDFISH_OVER_IP_PROTOCOL_DATA + // + + // Service UUID + ZeroMem ((VOID *)&RedfishOverIpData->ServiceUuid, sizeof (EFI_GUID)); + if (StrLen ((CONST CHAR16 *)PcdGetPtr (PcdRedfishServiceUuid)) !=3D = 0) { + StrToGuid ((CONST CHAR16 *)PcdGetPtr (PcdRedfishServiceUuid), &Red= fishOverIpData->ServiceUuid); + DEBUG((DEBUG_REDFISH_HOST_INTERFACE, " Service UUID: %g", &Redfish= OverIpData->ServiceUuid)); + } + + // HostIpAddressFormat and RedfishServiceIpDiscoveryType + RedfishOverIpData->HostIpAssignmentType =3D RedfishHostIpAs= signmentUnknown; + RedfishOverIpData->RedfishServiceIpDiscoveryType =3D RedfishHostIpAs= signmentUnknown; + if (ThisInstance->IpAssignedType =3D=3D IpmiStaticAddrsss) { + RedfishOverIpData->HostIpAssignmentType =3D RedfishHostIp= AssignmentStatic; + RedfishOverIpData->RedfishServiceIpDiscoveryType =3D RedfishHostIp= AssignmentStatic; + } else if (ThisInstance->IpAssignedType =3D=3D IpmiDynamicAddressBmc= Dhcp) { + RedfishOverIpData->HostIpAssignmentType =3D RedfishHostIp= AssignmentDhcp; + RedfishOverIpData->RedfishServiceIpDiscoveryType =3D RedfishHostIp= AssignmentDhcp; + } + + // HostIpAddressFormat and RedfishServiceIpAddressFormat, only suppo= rt IPv4 for now. + RedfishOverIpData->HostIpAddressFormat =3D REDFISH_HOST_IN= TERFACE_HOST_IP_ADDRESS_FORMAT_IP4; + RedfishOverIpData->RedfishServiceIpAddressFormat =3D REDFISH_HOST_IN= TERFACE_HOST_IP_ADDRESS_FORMAT_IP4; + + // HostIpAddress + CopyMem ( + (VOID *)RedfishOverIpData->HostIpAddress, + (VOID *)ThisInstance->HostIpAddressIpv4, + sizeof (ThisInstance->HostIpAddressIpv4) + ); + + // HostIpMask and RedfishServiceIpMask + CopyMem ( + (VOID *)RedfishOverIpData->HostIpMask, + (VOID *)ThisInstance->SubnetMaskIpv4, + sizeof (ThisInstance->SubnetMaskIpv4) + ); + CopyMem ( + (VOID *)RedfishOverIpData->RedfishServiceIpMask, + (VOID *)ThisInstance->SubnetMaskIpv4, + sizeof (ThisInstance->SubnetMaskIpv4) + ); + + // RedfishServiceIpAddress + CopyMem ( + (VOID *)RedfishOverIpData->RedfishServiceIpAddress, + (VOID *)ThisInstance->RedfishIpAddressIpv4, + sizeof (ThisInstance->RedfishIpAddressIpv4) + ); + + // RedfishServiceIpPort + RedfishOverIpData->RedfishServiceIpPort =3D 0; + + // RedfishServiceVlanId + RedfishOverIpData->RedfishServiceVlanId =3D ThisInstance->VLanId; + + // RedfishServiceHostnameLength + RedfishOverIpData->RedfishServiceHostnameLength =3D HostNameLength; + + // Redfish host name. + CopyMem ( + (VOID *)&RedfishOverIpData->RedfishServiceHostname, + (VOID *)HostNameString, + HostNameLength + ); + + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " MC_HOST_INTERFACE_PROTOCO= L_RECORD is returned successfully.\n")); + *ProtocolRecord =3D ThisProtocolRecord; + return EFI_SUCCESS; + } + + if (IsNodeAtEnd (&mBmcUsbNic, &ThisInstance->NextInstance)) { + break; + } + + ThisInstance =3D (HOST_INTERFACE_BMC_USB_NIC_INFO *) + GetNextNode (&mBmcUsbNic, &ThisInstance->NextInstance); + } + + return EFI_NOT_FOUND; +} + +/** + This function retrieve the information of BMC USB NIC. + + @retval EFI_SUCCESS All necessary information is retrieved. + @retval EFI_NOT_FOUND There is no BMC exposed USB NIC. + @retval Others Other errors. + +**/ +EFI_STATUS +RetrievedBmcUsbNicInfo ( + VOID + ) +{ + EFI_STATUS Status; + UINT32 ResponseDataSize; + HOST_INTERFACE_BMC_USB_NIC_INFO *ThisInstance; + IPMI_GET_LAN_CONFIGURATION_PARAMETERS_REQUEST GetLanConfigReq; + IPMI_GET_LAN_CONFIGURATION_PARAMETERS_RESPONSE *GetLanConfigReps; + IPMI_LAN_IP_ADDRESS_SRC *IpAddressSrc; + IPMI_LAN_IP_ADDRESS *DestIpAddress; + IPMI_LAN_SUBNET_MASK *SubnetMask; + IPMI_LAN_DEFAULT_GATEWAY *DefaultGateway; + IPMI_LAN_VLAN_ID *LanVlanId; + EFI_USB_DEVICE_DESCRIPTOR UsbDeviceDescriptor; + + DEBUG ((DEBUG_INFO, "%a: Entry\n", __FUNCTION__)); + + if (IsListEmpty (&mBmcUsbNic)) { + return EFI_NOT_FOUND; + } + + ThisInstance =3D (HOST_INTERFACE_BMC_USB_NIC_INFO *)GetFirstNode (&mBmcU= sbNic); + while (TRUE) { + if (ThisInstance->IsExposedByBmc) { + ThisInstance->IsSuppportedHostInterface =3D FALSE; + + // Probe if Redfish Host Interface Credential Bootstrapping is suppo= rted. + ThisInstance->CredentialBootstrapping =3D ProbeRedfishCredentialBoot= strap (); + + // Get IP address source + GetLanConfigReq.SetSelector =3D 0; + GetLanConfigReq.BlockSelector =3D 0; + GetLanConfigReq.ChannelNumber.Bits.ChannelNo =3D ThisInstance->Ip= miLanChannelNumber; + GetLanConfigReq.ChannelNumber.Bits.GetParameter =3D 0; + GetLanConfigReq.ChannelNumber.Bits.Reserved =3D 0; + GetLanConfigReq.ParameterSelector =3D IpmiLanIpAddress= Source; + ResponseDataSize =3D sizeof (IPMI_GET= _LAN_CONFIGURATION_PARAMETERS_RESPONSE) + sizeof (IPMI_LAN_IP_ADDRESS_SRC); + GetLanConfigReps =3D (IPMI_GET_LAN_CO= NFIGURATION_PARAMETERS_RESPONSE *)AllocateZeroPool (ResponseDataSize); + GetLanConfigReps->CompletionCode =3D IPMI_COMP_CODE_U= NSPECIFIED; + Status =3D IpmiGetLanConfig= urationParameters ( + &GetLanConfigReq, + GetLanConfigReps, + &ResponseDataSize + ); + if (EFI_ERROR (Status) || (GetLanConfigReps->CompletionCode !=3D IPM= I_COMP_CODE_NORMAL)) { + DEBUG ((DEBUG_ERROR, " Failed to get IP address source at chann= el %d: %r, 0x%02x.\n", ThisInstance->IpmiLanChannelNumber, Status, GetLanCo= nfigReps->CompletionCode)); + FreePool (GetLanConfigReps); + return Status; + } + + IpAddressSrc =3D (IPMI_LAN_IP_ADDRESS_SRC *)(GetLanConfigReps + 1); + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " IP address source at chan= nel %d: %x\n", ThisInstance->IpmiLanChannelNumber, IpAddressSrc->Bits.Addre= ssSrc)); + ThisInstance->IpAssignedType =3D IpAddressSrc->Bits.AddressSrc; + FreePool (GetLanConfigReps); + + // Get LAN IPv4 IP address + GetLanConfigReq.ParameterSelector =3D IpmiLanIpAddress; + ResponseDataSize =3D sizeof (IPMI_GET_LAN_CONFIGURA= TION_PARAMETERS_RESPONSE) + sizeof (IPMI_LAN_IP_ADDRESS); + GetLanConfigReps =3D (IPMI_GET_LAN_CONFIGURATION_PA= RAMETERS_RESPONSE *)AllocateZeroPool (ResponseDataSize); + GetLanConfigReps->CompletionCode =3D IPMI_COMP_CODE_UNSPECIFIED; + Status =3D IpmiGetLanConfigurationParamet= ers ( + &GetLanConfigReq, + GetLanConfigReps, + &ResponseDataSize + ); + if (EFI_ERROR (Status) || (GetLanConfigReps->CompletionCode !=3D IPM= I_COMP_CODE_NORMAL)) { + DEBUG ((DEBUG_ERROR, " Failed to get Dest IP address at channel= %d: %r, 0x%02x.\n", ThisInstance->IpmiLanChannelNumber, Status, GetLanConf= igReps->CompletionCode)); + FreePool (GetLanConfigReps); + return Status; + } + + DestIpAddress =3D (IPMI_LAN_IP_ADDRESS *)(GetLanConfigReps + 1); + DEBUG (( + DEBUG_REDFISH_HOST_INTERFACE, + " Dest IP address at channel %d: %d.%d.%d.%d\n", + ThisInstance->IpmiLanChannelNumber, + DestIpAddress->IpAddress[0], + DestIpAddress->IpAddress[1], + DestIpAddress->IpAddress[2], + DestIpAddress->IpAddress[3] + )); + CopyMem ((VOID *)&ThisInstance->RedfishIpAddressIpv4, (VOID *)&DestI= pAddress->IpAddress, sizeof (DestIpAddress->IpAddress)); + // + // According to UEFI spec, the IP address at BMC USB NIC host end is= the IP address at BMC end minus 1. + // + CopyMem ((VOID *)&ThisInstance->HostIpAddressIpv4, (VOID *)&DestIpAd= dress->IpAddress, sizeof (DestIpAddress->IpAddress)); + ThisInstance->HostIpAddressIpv4[sizeof (ThisInstance->HostIpAddressI= pv4) - 1] -=3D 1; + FreePool (GetLanConfigReps); + DEBUG (( + DEBUG_REDFISH_HOST_INTERFACE, + " Host IP address at channel %d: %d.%d.%d.%d\n", + ThisInstance->IpmiLanChannelNumber, + ThisInstance->HostIpAddressIpv4[0], + ThisInstance->HostIpAddressIpv4[1], + ThisInstance->HostIpAddressIpv4[2], + ThisInstance->HostIpAddressIpv4[3] + )); + + // Get IPv4 subnet mask + GetLanConfigReq.ParameterSelector =3D IpmiLanSubnetMask; + ResponseDataSize =3D sizeof (IPMI_GET_LAN_CONFIGURA= TION_PARAMETERS_RESPONSE) + sizeof (IPMI_LAN_SUBNET_MASK); + GetLanConfigReps =3D (IPMI_GET_LAN_CONFIGURATION_PA= RAMETERS_RESPONSE *)AllocateZeroPool (ResponseDataSize); + GetLanConfigReps->CompletionCode =3D IPMI_COMP_CODE_UNSPECIFIED; + Status =3D IpmiGetLanConfigurationParamet= ers ( + &GetLanConfigReq, + GetLanConfigReps, + &ResponseDataSize + ); + if ((EFI_ERROR (Status)) || (GetLanConfigReps->CompletionCode !=3D I= PMI_COMP_CODE_NORMAL)) { + DEBUG ((DEBUG_ERROR, " Failed to get subnet mask at channel %d:= %r, 0x%02x.\n", ThisInstance->IpmiLanChannelNumber, Status, GetLanConfigRe= ps->CompletionCode)); + FreePool (GetLanConfigReps); + return Status; + } + + SubnetMask =3D (IPMI_LAN_SUBNET_MASK *)(GetLanConfigReps + 1); + DEBUG (( + DEBUG_REDFISH_HOST_INTERFACE, + " Subnet mask at channel %d: %d.%d.%d.%d\n", + ThisInstance->IpmiLanChannelNumber, + SubnetMask->IpAddress[0], + SubnetMask->IpAddress[1], + SubnetMask->IpAddress[2], + SubnetMask->IpAddress[3] + )); + CopyMem ((VOID *)&ThisInstance->SubnetMaskIpv4, (VOID *)&SubnetMask-= >IpAddress, sizeof (SubnetMask->IpAddress)); + FreePool (GetLanConfigReps); + + // Get Gateway IP address. + GetLanConfigReq.ParameterSelector =3D IpmiLanDefaultGateway; + ResponseDataSize =3D sizeof (IPMI_GET_LAN_CONFIGURA= TION_PARAMETERS_RESPONSE) + sizeof (IPMI_LAN_DEFAULT_GATEWAY); + GetLanConfigReps =3D (IPMI_GET_LAN_CONFIGURATION_PA= RAMETERS_RESPONSE *)AllocateZeroPool (ResponseDataSize); + GetLanConfigReps->CompletionCode =3D IPMI_COMP_CODE_UNSPECIFIED; + Status =3D IpmiGetLanConfigurationParamet= ers ( + &GetLanConfigReq, + GetLanConfigReps, + &ResponseDataSize + ); + if ((EFI_ERROR (Status)) || (GetLanConfigReps->CompletionCode !=3D I= PMI_COMP_CODE_NORMAL)) { + DEBUG ((DEBUG_ERROR, " Failed to get default gateway at channel= %d: %r, 0x%02x.\n", ThisInstance->IpmiLanChannelNumber, Status, GetLanConf= igReps->CompletionCode)); + FreePool (GetLanConfigReps); + return Status; + } + + DefaultGateway =3D (IPMI_LAN_DEFAULT_GATEWAY *)(GetLanConfigReps + 1= ); + DEBUG (( + DEBUG_REDFISH_HOST_INTERFACE, + " Gateway at channel %d: %d.%d.%d.%d\n", + ThisInstance->IpmiLanChannelNumber, + DefaultGateway->IpAddress[0], + DefaultGateway->IpAddress[1], + DefaultGateway->IpAddress[2], + DefaultGateway->IpAddress[3] + )); + CopyMem ((VOID *)&ThisInstance->GatewayIpv4, (VOID *)&DefaultGateway= ->IpAddress, sizeof (DefaultGateway->IpAddress)); + FreePool (GetLanConfigReps); + + // Get VLAN ID + GetLanConfigReq.ParameterSelector =3D IpmiLanVlanId; + ResponseDataSize =3D sizeof (IPMI_GET_LAN_CONFIGURA= TION_PARAMETERS_RESPONSE) + sizeof (IPMI_LAN_VLAN_ID); + GetLanConfigReps =3D (IPMI_GET_LAN_CONFIGURATION_PA= RAMETERS_RESPONSE *)AllocateZeroPool (ResponseDataSize); + GetLanConfigReps->CompletionCode =3D IPMI_COMP_CODE_UNSPECIFIED; + Status =3D IpmiGetLanConfigurationParamet= ers ( + &GetLanConfigReq, + GetLanConfigReps, + &ResponseDataSize + ); + if ((EFI_ERROR (Status)) || (GetLanConfigReps->CompletionCode !=3D I= PMI_COMP_CODE_NORMAL)) { + DEBUG ((DEBUG_ERROR, " Failed to get VLAN ID at channel %d: %r,= 0x%02x.\n", ThisInstance->IpmiLanChannelNumber, Status, GetLanConfigReps->= CompletionCode)); + FreePool (GetLanConfigReps); + return Status; + } + + LanVlanId =3D (IPMI_LAN_VLAN_ID *)(GetLanConfigReps + 1); + ThisInstance->VLanId =3D 0; + if (LanVlanId->Data2.Bits.Enabled =3D=3D 1) { + ThisInstance->VLanId =3D LanVlanId->Data1.VanIdLowByte | (LanVlanI= d->Data2.Bits.VanIdHighByte << 8); + } + + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " VLAN ID %x\n", ThisInstan= ce->VLanId)); + + FreePool (GetLanConfigReps); + + // + // Read USB device information. + // + if (ThisInstance->ThisUsbIo !=3D NULL) { + Status =3D ThisInstance->ThisUsbIo->UsbGetDeviceDescriptor (ThisIn= stance->ThisUsbIo, &UsbDeviceDescriptor); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " USB NIC Vendor ID: 0x= %04x, Device ID: 0x%04x\n", UsbDeviceDescriptor.IdVendor, UsbDeviceDescript= or.IdProduct)); + ThisInstance->UsbVendorId =3D UsbDeviceDescriptor.IdVendor; + ThisInstance->UsbProductId =3D UsbDeviceDescriptor.IdProduct; + } else { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " Fail to get USB devic= e descriptor.\n")); + } + } + + // All information is retrieved. + ThisInstance->IsSuppportedHostInterface =3D TRUE; + return EFI_SUCCESS; + } + + if (IsNodeAtEnd (&mBmcUsbNic, &ThisInstance->NextInstance)) { + break; + } + + ThisInstance =3D (HOST_INTERFACE_BMC_USB_NIC_INFO *) + GetNextNode (&mBmcUsbNic, &ThisInstance->NextInstance); + } + + return EFI_NOT_FOUND; +} + +/** + This function caches the found IPMI LAN channel. So we + don't have to sedn IPMI commands again if the USB NIC is + connected later. + + @param[in] ChannelNum The IPMI channel number. + @param[in] IpmiLanChannelMacAddress Pointer to EFI_MAC_ADDRESS. + @param[in] IpmiLanMacAddressSize The MAC address size. + + @retval EFI_SUCCESS IPMI LAN channel is cached. + @retval EFI_OUT_OF_RESOURCE Memory allocated failed. + @retval Others Other errors. + +**/ +EFI_STATUS +CacheIpmiLanMac ( + IN UINT8 ChannelNum, + IN EFI_MAC_ADDRESS *IpmiLanChannelMacAddress, + IN UINT8 IpmiLanMacAddressSize + ) +{ + BMC_IPMI_LAN_CHANNEL_INFO *ChannelInfo; + + ChannelInfo =3D (BMC_IPMI_LAN_CHANNEL_INFO *)AllocateZeroPool (sizeof (B= MC_IPMI_LAN_CHANNEL_INFO)); + if (ChannelInfo =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + ChannelInfo->Channel =3D ChannelNum; + CopyMem ((VOID *)&ChannelInfo->MacAddress.Addr, (VOID *)IpmiLanChannelMa= cAddress->Addr, IpmiLanMacAddressSize); + ChannelInfo->MacAddressSize =3D IpmiLanMacAddressSize; + InitializeListHead (&ChannelInfo->NextInstance); + InsertTailList (&mBmcIpmiLan, &ChannelInfo->NextInstance); + return EFI_SUCCESS; +} + +/** + This function checks if the IPMI channel already identified + previously. + + @param[in] ChannelNum The IPMI channel number. + @param[out] CachedIpmiLanChannel Pointer to retrieve the cached + BMC_IPMI_LAN_CHANNEL_INFO. + + @retval EFI_SUCCESS IPMI LAN channel is found. + @retval Others Other errors. + +**/ +EFI_STATUS +CheckCachedIpmiLanMac ( + IN UINT8 ChannelNum, + OUT BMC_IPMI_LAN_CHANNEL_INFO **CachedIpmiLanChannel + ) +{ + BMC_IPMI_LAN_CHANNEL_INFO *ThisInstance; + + if (IsListEmpty (&mBmcIpmiLan)) { + return EFI_NOT_FOUND; + } + + ThisInstance =3D (BMC_IPMI_LAN_CHANNEL_INFO *)GetFirstNode (&mBmcIpmiLan= ); + while (TRUE) { + if (ThisInstance->Channel =3D=3D ChannelNum) { + *CachedIpmiLanChannel =3D ThisInstance; + return EFI_SUCCESS; + } + + if (IsNodeAtEnd (&mBmcIpmiLan, &ThisInstance->NextInstance)) { + break; + } + + ThisInstance =3D (BMC_IPMI_LAN_CHANNEL_INFO *) + GetNextNode (&mBmcIpmiLan, &ThisInstance->NextInstance); + } + + return EFI_NOT_FOUND; +} + +/** + This function goes through IPMI channels to find the + mactched MAC addrss of BMC USB NIC endpoint. + + @param[in] UsbNicInfo The instance of HOST_INTERFACE_BMC_USB_NIC_INFO. + + @retval EFI_SUCCESS Yes, USB NIC exposed by BMC is found. + @retval EFI_NOT_FOUND No, USB NIC exposed by BMC is not found + on the existing SNP handle. + @retval Others Other errors. + +**/ +EFI_STATUS +HostInterfaceIpmiCheckMacAddress ( + IN HOST_INTERFACE_BMC_USB_NIC_INFO *UsbNicInfo + ) +{ + EFI_STATUS Status; + EFI_STATUS ExitStatus; + UINTN ChannelNum; + UINT32 ResponseDataSize; + IPMI_GET_CHANNEL_INFO_REQUEST GetChanelInfoRequest; + IPMI_GET_CHANNEL_INFO_RESPONSE GetChanelInfoResponse; + IPMI_GET_LAN_CONFIGURATION_PARAMETERS_REQUEST GetLanConfigReq; + IPMI_GET_LAN_CONFIGURATION_PARAMETERS_RESPONSE *GetLanConfigReps; + BMC_IPMI_LAN_CHANNEL_INFO *CachedIpmiLanChannel; + UINT8 IpmiLanMacAddressSize; + EFI_MAC_ADDRESS IpmiLanChannelMacAddress; + BOOLEAN AlreadyCached; + + DEBUG ((DEBUG_INFO, "%a: Entry.\n", __FUNCTION__)); + + GetLanConfigReps =3D NULL; + AlreadyCached =3D FALSE; + if (!IsListEmpty (&mBmcIpmiLan)) { + AlreadyCached =3D TRUE; + } + + // Initial the get MAC address request. + GetLanConfigReq.SetSelector =3D 0; + GetLanConfigReq.BlockSelector =3D 0; + GetLanConfigReq.ParameterSelector =3D IpmiLanMacAddress; + + ExitStatus =3D EFI_NOT_FOUND; + for (ChannelNum =3D IPMI_CHANNEL_NUMBER_IMPLEMENTATION_SPECIFIC_1; + ChannelNum <=3D IPMI_CHANNEL_NUMBER_IMPLEMENTATION_SPECIFIC_11; + ChannelNum++) + { + IpmiLanMacAddressSize =3D 0; + + // Check if the IPMI channel information is already cached. + Status =3D EFI_NOT_FOUND; + if (AlreadyCached) { + Status =3D CheckCachedIpmiLanMac ((UINT8)ChannelNum, &CachedIpmiLanC= hannel); + } + + if (Status =3D=3D EFI_SUCCESS) { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " Got cached IPMI LAN info.\n= ")); + IpmiLanMacAddressSize =3D sizeof (IPMI_LAN_MAC_ADDRESS); + CopyMem ((VOID *)&IpmiLanChannelMacAddress.Addr, (VOID *)&CachedIpmi= LanChannel->MacAddress.Addr, IpmiLanMacAddressSize); + } else { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " No cached IPMI LAN info\n")= ); + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " Send NetFn =3D App, Command= =3D 0x42 to channel %d\n", ChannelNum)); + GetChanelInfoRequest.ChannelNumber.Bits.ChannelNo =3D (UINT8)Channel= Num; + Status =3D IpmiGetChannel= Info ( + &GetChanelInfo= Request, + &GetChanelInfo= Response, + &ResponseDataS= ize + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, " - Fails to send command.\n", ChannelNum)= ); + continue; + } + + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " - Response data size =3D = 0x%x\n", ResponseDataSize)); + if ((GetChanelInfoResponse.CompletionCode !=3D IPMI_COMP_CODE_NORMAL= ) || (ResponseDataSize =3D=3D 0)) { + DEBUG ((DEBUG_ERROR, " - Command returned fail: 0x%x.\n", GetCh= anelInfoResponse.CompletionCode)); + continue; + } + + DEBUG (( + DEBUG_REDFISH_HOST_INTERFACE, + " - Channel protocol =3D 0x%x, Media =3D 0x%x\n", + GetChanelInfoResponse.ProtocolType.Bits.ChannelProtocolType, + GetChanelInfoResponse.MediumType.Bits.ChannelMediumType + )); + + if (GetChanelInfoResponse.ChannelNumber.Bits.ChannelNo !=3D ChannelN= um) { + DEBUG (( + DEBUG_ERROR, + " - ChannelNumber =3D %d in the response which is not macthed= to the request.\n", + GetChanelInfoResponse.ChannelNumber.Bits.ChannelNo + )); + continue; + } + + if ((GetChanelInfoResponse.MediumType.Bits.ChannelMediumType =3D=3D = IPMI_CHANNEL_MEDIA_TYPE_802_3_LAN) && + (GetChanelInfoResponse.ProtocolType.Bits.ChannelProtocolType =3D= =3D IPMI_CHANNEL_PROTOCOL_TYPE_IPMB_1_0)) + { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " - Channel %d is a LAN d= evice!\n", ChannelNum)); + + ResponseDataSize =3D sizeof (IPMI_GET_LAN_CONFIGURATION_PARAMETERS= _RESPONSE) + + sizeof (IPMI_LAN_MAC_ADDRESS); + if (GetLanConfigReps =3D=3D NULL) { + GetLanConfigReps =3D + (IPMI_GET_LAN_CONFIGURATION_PARAMETERS_RESPONSE *)AllocateZero= Pool (ResponseDataSize); + if (GetLanConfigReps =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, " Allocate memory failed for getting M= AC address.\n")); + continue; + } + } + + GetLanConfigReq.ChannelNumber.Bits.ChannelNo =3D (UINT8)ChannelNum; + GetLanConfigReps->CompletionCode =3D IPMI_COMP_CODE_UN= SPECIFIED; + Status =3D IpmiGetLanConfigu= rationParameters ( + &GetLanConfigReq, + GetLanConfigReps, + &ResponseDataSize + ); + if (EFI_ERROR (Status) || (GetLanConfigReps->CompletionCode !=3D I= PMI_COMP_CODE_NORMAL)) { + DEBUG (( + DEBUG_ERROR, + " Fails to get MAC address of channel %d, CompletionCode = =3D %02x.\n", + ChannelNum, + GetLanConfigReps->CompletionCode + )); + continue; + } else { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " The MAC address of ch= annel %d.\n", ChannelNum)); + DEBUG (( + DEBUG_REDFISH_HOST_INTERFACE, + " %02x:%02x:%02x:%02x:%02x:%02x\n", + *((UINT8 *)(GetLanConfigReps + 1) + 0), + *((UINT8 *)(GetLanConfigReps + 1) + 1), + *((UINT8 *)(GetLanConfigReps + 1) + 2), + *((UINT8 *)(GetLanConfigReps + 1) + 3), + *((UINT8 *)(GetLanConfigReps + 1) + 4), + *((UINT8 *)(GetLanConfigReps + 1) + 5) + )); + IpmiLanMacAddressSize =3D sizeof (IPMI_LAN_MAC_ADDRESS); + CopyMem ((VOID *)&IpmiLanChannelMacAddress.Addr, (VOID *)(GetLan= ConfigReps + 1), IpmiLanMacAddressSize); + } + } + } + + if (IpmiLanMacAddressSize !=3D 0) { + if (!AlreadyCached) { + // Cache this IPMI LAN channel. + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " Cache this IPMI LAN cha= nnel.\n")); + CacheIpmiLanMac ((UINT8)ChannelNum, &IpmiLanChannelMacAddress, Ipm= iLanMacAddressSize); + } + + // + // According to design spec in Readme file under RedfishPkg. + // Compare the first five MAC address and + // the 6th MAC address. + // + if ((IpmiLanMacAddressSize !=3D UsbNicInfo->MacAddressSize) || + (CompareMem ( + (VOID *)UsbNicInfo->MacAddress, + (VOID *)&IpmiLanChannelMacAddress.Addr, + IpmiLanMacAddressSize - 1 + ) !=3D 0) || + (IpmiLanChannelMacAddress.Addr[IpmiLanMacAddressSize - 1] !=3D + *(UsbNicInfo->MacAddress + IpmiLanMacAddressSize - 1) - 1) + ) + { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " MAC address is not matc= hed.\n")); + continue; + } + + // This is the NIC exposed by BMC. + UsbNicInfo->IpmiLanChannelNumber =3D (UINT8)ChannelNum; + UsbNicInfo->IsExposedByBmc =3D TRUE; + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " MAC address is matched.\n= ")); + ExitStatus =3D EFI_SUCCESS; + break; + } + } + + if (GetLanConfigReps !=3D NULL) { + FreePool (GetLanConfigReps); + } + + return ExitStatus; +} + +/** + This function searches the next MSG_USB_DP device path node. + + @param[in] ThisDevicePath Device path to search. + + @retval NULL MSG_USB_DP is not found. + Otherwise MSG_USB_DP is found. + +**/ +EFI_DEVICE_PATH_PROTOCOL * +UsbNicGetNextMsgUsbDp ( + IN EFI_DEVICE_PATH_PROTOCOL *ThisDevicePath + ) +{ + if (ThisDevicePath =3D=3D NULL) { + return NULL; + } + + while (TRUE) { + ThisDevicePath =3D NextDevicePathNode (ThisDevicePath); + if (IsDevicePathEnd (ThisDevicePath)) { + return NULL; + } + + if ((ThisDevicePath->Type =3D=3D MESSAGING_DEVICE_PATH) && (ThisDevice= Path->SubType =3D=3D MSG_USB_DP)) { + return ThisDevicePath; + } + } + + return NULL; +} + +/** + This function search the UsbIo handle that matches the UsbDevicePath. + + @param[in] UsbDevicePath Device path of this SNP handle. + @param[out] UsbIo Return the UsbIo protocol. + + @retval EFI_SUCCESS Yes, UsbIo protocl is found. + @retval EFI_NOT_FOUND No, UsbIo protocl is not found + @retval Others Other errors. + +**/ +EFI_STATUS +UsbNicSearchUsbIo ( + IN EFI_DEVICE_PATH_PROTOCOL *UsbDevicePath, + OUT EFI_USB_IO_PROTOCOL **UsbIo + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + EFI_HANDLE *HandleBuffer; + UINT16 Length; + UINTN Index; + CHAR16 *DevicePathStr; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; + EFI_DEVICE_PATH_PROTOCOL *ThisDevicePath; + EFI_DEVICE_PATH_PROTOCOL *ThisDevicePathEnd; + EFI_DEVICE_PATH_PROTOCOL *ThisUsbDevicePath; + EFI_DEVICE_PATH_PROTOCOL *ThisUsbDevicePathEnd; + + DEBUG ((DEBUG_INFO, "%a: Entry.\n", __FUNCTION__)); + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "Device path on the EFI handle whi= ch has UsbIo and SNP instaleld on it.\n")); + DevicePathStr =3D ConvertDevicePathToText (UsbDevicePath, FALSE, FALSE); + if (DevicePathStr !=3D NULL) { + DEBUG((DEBUG_REDFISH_HOST_INTERFACE, "%s\n", DevicePathStr)); + FreePool (DevicePathStr); + } else { + DEBUG((DEBUG_ERROR, "Failed to convert device path.\n")); + return EFI_INVALID_PARAMETER; + } + + BufferSize =3D 0; + HandleBuffer =3D NULL; + *UsbIo =3D NULL; + Status =3D gBS->LocateHandle ( + ByProtocol, + &gEfiUsbIoProtocolGuid, + NULL, + &BufferSize, + NULL + ); + if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " %d UsbIo protocol instances.\= n", BufferSize/sizeof (EFI_HANDLE))); + HandleBuffer =3D AllocateZeroPool (BufferSize); + if (HandleBuffer =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, " Falied to allocate buffer for the handles.= \n")); + return EFI_OUT_OF_RESOURCES; + } + + Status =3D gBS->LocateHandle ( + ByProtocol, + &gEfiUsbIoProtocolGuid, + NULL, + &BufferSize, + HandleBuffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, " Falied to locate UsbIo protocol handles.\n")= ); + FreePool (HandleBuffer); + return Status; + } + } else { + return Status; + } + + for (Index =3D 0; Index < (BufferSize/sizeof (EFI_HANDLE)); Index++) { + Status =3D gBS->HandleProtocol ( + *(HandleBuffer + Index), + &gEfiDevicePathProtocolGuid, + (VOID **)&ThisDevicePath + ); + if (EFI_ERROR (Status)) { + continue; + } + + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "Device path on #%d instance of = UsbIo.\n", Index)); + DevicePathStr =3D ConvertDevicePathToText (ThisDevicePath, FALSE, FALS= E); + if (DevicePathStr !=3D NULL) { + DEBUG((DEBUG_REDFISH_HOST_INTERFACE, "%s\n", DevicePathStr)); + FreePool (DevicePathStr); + } else { + DEBUG((DEBUG_ERROR, "Failed to convert device path on #%d instance o= f UsbIo.\n", Index)); + continue; + } + + Status =3D EFI_NOT_FOUND; + + // Search for the starting MSG_USB_DP node. + ThisUsbDevicePath =3D UsbDevicePath; + if ((DevicePathType (ThisUsbDevicePath) !=3D MESSAGING_DEVICE_PATH) || + (DevicePathSubType (ThisUsbDevicePath) !=3D MSG_USB_DP)) + { + ThisUsbDevicePath =3D UsbNicGetNextMsgUsbDp (ThisUsbDevicePath); + if (ThisUsbDevicePath =3D=3D NULL) { + continue; + } + } + + if ((DevicePathType (ThisDevicePath) !=3D MESSAGING_DEVICE_PATH) || + (DevicePathSubType (ThisDevicePath) !=3D MSG_USB_DP)) + { + ThisDevicePath =3D UsbNicGetNextMsgUsbDp (ThisDevicePath); + if (ThisDevicePath =3D=3D NULL) { + continue; + } + } + + // Search for the ending MSG_USB_DP node. + ThisDevicePathEnd =3D ThisDevicePath; + ThisUsbDevicePathEnd =3D ThisUsbDevicePath; + while (TRUE) { + TempDevicePath =3D UsbNicGetNextMsgUsbDp (ThisDevicePathEnd); + if (TempDevicePath =3D=3D NULL) { + break; + } + + ThisDevicePathEnd =3D TempDevicePath; + } + + while (TRUE) { + TempDevicePath =3D UsbNicGetNextMsgUsbDp (ThisUsbDevicePathEnd); + if (TempDevicePath =3D=3D NULL) { + break; + } + + ThisUsbDevicePathEnd =3D TempDevicePath; + } + + // Compare these two device paths + Length =3D (UINT16)((UINTN)(UINT8 *)ThisDevicePathEnd + DevicePathNode= Length (ThisDevicePathEnd) - (UINTN)(UINT8 *)ThisDevicePath); + if (Length !=3D ((UINTN)(UINT8 *)ThisUsbDevicePathEnd + DevicePathNode= Length (ThisUsbDevicePathEnd) - (UINTN)(UINT8 *)ThisUsbDevicePath)) { + continue; + } + + if (CompareMem ( + (VOID *)ThisDevicePath, + (VOID *)ThisUsbDevicePath, + Length + ) =3D=3D 0) + { + Status =3D EFI_SUCCESS; + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "EFI handle with the correct U= sbIo is found at #%d instance of UsbIo.\n", Index)); + break; + } + } + + if (Status =3D=3D EFI_SUCCESS) { + // Locate UsbIo from this handle. + Status =3D gBS->HandleProtocol ( + *(HandleBuffer + Index), + &gEfiUsbIoProtocolGuid, + (VOID **)UsbIo + ); + return Status; + } + + return EFI_NOT_FOUND; +} + +/** + This function identifies if the USB NIC is exposed by BMC as + the host-BMC channel. + + @param[in] Handle This is the EFI handle with SNP installed. + @param[in] UsbDevicePath USB device path. + + @retval EFI_SUCCESS Yes, USB NIC exposed by BMC is found. + @retval EFI_NOT_FOUND No, USB NIC exposed by BMC is not found + on the existing SNP handle. + @retval Others Other errors. + +**/ +EFI_STATUS +IdentifyUsbNicBmcChannel ( + IN EFI_HANDLE Handle, + IN EFI_DEVICE_PATH_PROTOCOL *UsbDevicePath + ) +{ + UINTN Index; + EFI_STATUS Status; + EFI_SIMPLE_NETWORK_PROTOCOL *Snp; + EFI_USB_IO_PROTOCOL *UsbIo; + HOST_INTERFACE_BMC_USB_NIC_INFO *BmcUsbNic; + + DEBUG ((DEBUG_INFO, "%a: Entry.\n", __FUNCTION__)); + Status =3D gBS->HandleProtocol ( + Handle, + &gEfiSimpleNetworkProtocolGuid, + (VOID **)&Snp + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, " Failed to locate SNP.\n")); + return Status; + } + + Status =3D UsbNicSearchUsbIo (UsbDevicePath, &UsbIo); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, " Failed to find USBIO.\n")); + return Status; + } + + // Get the MAC address of this SNP instance. + BmcUsbNic =3D AllocateZeroPool (sizeof (HOST_INTERFACE_BMC_USB_NIC_INFO)= ); + if (BmcUsbNic =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, " Failed to allocate memory for HOST_INTERFACE= _BMC_USB_NIC_INFO.\n")); + return EFI_OUT_OF_RESOURCES; + } + + InitializeListHead (&BmcUsbNic->NextInstance); + BmcUsbNic->MacAddressSize =3D Snp->Mode->HwAddressSize; + BmcUsbNic->MacAddress =3D AllocateZeroPool (sizeof (BmcUsbNic->MacAd= dressSize)); + if (BmcUsbNic->MacAddress =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, " Failed to allocate memory for HW MAC address= s.\n")); + FreePool (BmcUsbNic); + return EFI_OUT_OF_RESOURCES; + } + + CopyMem ( + (VOID *)BmcUsbNic->MacAddress, + (VOID *)&Snp->Mode->CurrentAddress, + BmcUsbNic->MacAddressSize + ); + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " MAC address (in size %d) for = this SNP instance:\n ", BmcUsbNic->MacAddressSize)); + for (Index =3D 0; Index < BmcUsbNic->MacAddressSize; Index++) { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "%02x ", *(BmcUsbNic->MacAddress= + Index))); + } + + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "\n")); + BmcUsbNic->ThisSnp =3D Snp; + BmcUsbNic->ThisUsbIo =3D UsbIo; + + Status =3D HostInterfaceIpmiCheckMacAddress (BmcUsbNic); + if (Status =3D=3D EFI_SUCCESS) { + BmcUsbNic->IsExposedByBmc =3D TRUE; + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " BMC exposed USB NIC is foun= d.\n")); + } else { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " BMC exposed USB NIC is not = found.\n")); + } + + InsertTailList (&mBmcUsbNic, &BmcUsbNic->NextInstance); + return Status; +} + +/** + This function checks if the USB NIC exposed by BMC + on each handle has SNP protocol installed on it. + + @param[in] HandleNumer Number of handles to check. + @param[in] HandleBuffer Handles buffer. + + @retval EFI_SUCCESS Yes, USB NIC exposed by BMC is found. + @retval EFI_NOT_FOUND No, USB NIC exposed by BMC is not found + on the existing SNP handle. + @retval Others Other errors. + +**/ +EFI_STATUS +CheckBmcUsbNicOnHandles ( + IN UINTN HandleNumer, + IN EFI_HANDLE *HandleBuffer + ) +{ + UINTN Index; + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + BOOLEAN GotOneUsbNIc; + + if ((HandleNumer =3D=3D 0) || (HandleBuffer =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + DEBUG ((DEBUG_INFO, "%a: Entry, #%d SNP handle\n", __FUNCTION__, HandleN= umer)); + + GotOneUsbNIc =3D FALSE; + for (Index =3D 0; Index < HandleNumer; Index++) { + Status =3D gBS->HandleProtocol ( + *(HandleBuffer + Index), + &gEfiDevicePathProtocolGuid, + (VOID **)&DevicePath + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, " Failed to locate SNP on %d handle.\n", __F= UNCTION__, Index)); + continue; + } + + // Check if this is an BMC exposed USB NIC device. + while (TRUE) { + if ((DevicePath->Type =3D=3D MESSAGING_DEVICE_PATH) && (DevicePath->= SubType =3D=3D MSG_USB_DP)) { + Status =3D IdentifyUsbNicBmcChannel (*(HandleBuffer + Index), Devi= cePath); + if (!EFI_ERROR (Status)) { + GotOneUsbNIc =3D TRUE; + break; + } + } + + DevicePath =3D NextDevicePathNode (DevicePath); + if (IsDevicePathEnd (DevicePath)) { + break; + } + } + } + + if (GotOneUsbNIc) { + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; +} + +/** + This function checks if the USB NIC exposed by BMC + is already connected. + + @param[in] Registration Locate SNP protocol from the notification + registeration key. + NULL means locate SNP protocol from the exi= sting + handles. + + @retval EFI_SUCCESS Yes, USB NIC exposed by BMC is found. + @retval EFI_NOT_FOUND No, USB NIC exposed by BMC is not found + on the existing SNP handle. + @retval Others Other errors. + +**/ +EFI_STATUS +CheckBmcUsbNic ( + VOID *Registration + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + UINTN BufferSize; + EFI_HANDLE *HandleBuffer; + + DEBUG ((DEBUG_INFO, "%a: Entry, the registration key - 0x%08x.\n", __FUN= CTION__, Registration)); + + Handle =3D NULL; + Status =3D EFI_SUCCESS; + BufferSize =3D 0; + + Status =3D gBS->LocateHandle ( + Registration =3D=3D NULL ? ByProtocol : ByRegisterNotify, + &gEfiSimpleNetworkProtocolGuid, + Registration, + &BufferSize, + NULL + ); + if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " %d SNP protocol instances.\= n", BufferSize/sizeof (EFI_HANDLE))); + HandleBuffer =3D AllocateZeroPool (BufferSize); + if (HandleBuffer =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, " Falied to allocate buffer for the handles.= \n")); + return EFI_OUT_OF_RESOURCES; + } + + Status =3D gBS->LocateHandle ( + Registration =3D=3D NULL ? ByProtocol : ByRegisterNoti= fy, + &gEfiSimpleNetworkProtocolGuid, + Registration, + &BufferSize, + HandleBuffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, " Falied to locate SNP protocol handles.\n")= ); + FreePool (HandleBuffer); + return Status; + } + } else if (EFI_ERROR (Status)) { + return Status; + } + + // Check USB NIC on handles. + Status =3D CheckBmcUsbNicOnHandles (BufferSize/sizeof (EFI_HANDLE), Hand= leBuffer); + if (!EFI_ERROR (Status)) { + // Retrieve the rest of BMC USB NIC information for Redfish over IP in= formation + // and USB Network Interface V2. + Status =3D RetrievedBmcUsbNicInfo (); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, " Install protocol to notif= y the platform Redfish Host Interface information is ready.\n")); + Status =3D gBS->InstallProtocolInterface ( + &Handle, + &mPlatformHostInterfaceBmcUsbNicReadinessGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, " Install protocol fail %r.\n", Status)); + } + } + } + + FreePool (HandleBuffer); + return Status; +} + +/** + Notification event of SNP readiness. + + @param[in] Event Event whose notification function is b= eing invoked. + @param[in] Context The pointer to the notification functi= on's context, + which is implementation-dependent. + +**/ +VOID +EFIAPI +PlatformHostInterfaceSnpCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + DEBUG ((DEBUG_INFO, "%a: Entry.\n", __FUNCTION__)); + + CheckBmcUsbNic (mPlatformHostInterfaceSnpRegistration); + return; +} + +/** + Get the EFI protocol GUID installed by platform library which + indicates the necessary information is ready for building + SMBIOS 42h record. + + @param[out] InformationReadinessGuid Pointer to retrive the protocol + GUID. + + @retval EFI_SUCCESS Notification is required for building up + SMBIOS type 42h record. + @retval EFI_UNSUPPORTED Notification is not required for building up + SMBIOS type 42h record. + @retval EFI_ALREADY_STARTED Platform host information is already ready. + @retval Others Other errors. +**/ +EFI_STATUS +RedfishPlatformHostInterfaceNotification ( + OUT EFI_GUID **InformationReadinessGuid + ) +{ + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "%a: Entry\n", __FUNCTION__)); + + *InformationReadinessGuid =3D NULL; + InitializeListHead (&mBmcUsbNic); + InitializeListHead (&mBmcIpmiLan); + + // + // Check if USB NIC exposed by BMC is already + // connected. + // + Status =3D CheckBmcUsbNic (NULL); + if (!EFI_ERROR (Status)) { + return EFI_ALREADY_STARTED; + } + + if (Status =3D=3D EFI_NOT_FOUND) { + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "%a: BMC USB NIC is not found. R= egister the notification.\n", __FUNCTION__)); + + // Register the notification of SNP installation. + Status =3D gBS->CreateEvent ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + PlatformHostInterfaceSnpCallback, + NULL, + &mPlatformHostInterfaceSnpEvent + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to create event for the installation = of SNP protocol.", __FUNCTION__)); + return Status; + } + + Status =3D gBS->RegisterProtocolNotify ( + &gEfiSimpleNetworkProtocolGuid, + mPlatformHostInterfaceSnpEvent, + &mPlatformHostInterfaceSnpRegistration + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installatio= n of SNP protocol.", __FUNCTION__)); + return Status; + } + + *InformationReadinessGuid =3D &mPlatformHostInterfaceBmcUsbNicReadines= sGuid; + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_ERROR, "%a: Something wrong when look for BMC USB NIC.\n",= __FUNCTION__)); + return Status; +} --=20 2.37.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#101408): https://edk2.groups.io/g/devel/message/101408 Mute This Topic: https://groups.io/mt/97726812/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 03:36:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+101407+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1679300076938687.2734373051646; Mon, 20 Mar 2023 01:14:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mRevYY1788612xfm3MaS07ei; Mon, 20 Mar 2023 01:14:36 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.80]) by mx.groups.io with SMTP id smtpd.web11.8854.1679300075650018535 for ; Mon, 20 Mar 2023 01:14:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nLqghyb+yFJMrGwpSehYaFchk4zdYSKrtyCnzSRDzJlhE+JohvP2dHTbCQZt2TEizFZpFJTl7u7klk+oArtvXsHmvdM/FpFBFH16+/2jRbNqdLduwpuhiRUU0+e4GkcblbGF8atmgIVsn3t/YkW1lnQ433TItH8yOhAfUgrfHmYZkyp/kFm+FGNgfNSzi/PKRkbNUQPusUDf8Wyhi2Qgrx9IJbh/Dyroc0ak+bMjrGg7Y4470AH2fDYcu4sgkDdPnr+qRzXt/kS8mg3dPbapYlM3ktsc0b/PA/B4ypuClhiMdQoKaGwvUDK8JUzAZ9RCE/tou0eKaYbh/T2P82b1aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GWeto21i6wwm5blGJX0L9bNRQa/2k5OkVTtcSS1JIDA=; b=BSN4338j0DU2+vkZFMrb4s03BONC8uaItzMqYFpJeShW41QXRf/g6G6uYSOPqc6qhE1cWw38AZ8BzwKExGsDOrLVP+fBGetLYO21UcaA8q9ZbPQRboTRDGA/xwrHQVGizEgR7pF+A+09KvtnwpmnV60UGhXy26Yd8CCXgsJYJdCEyFl8YrJ89VClJKtyEHcL6jm5XjA98gCvxyiUbp0o+MnpcxTCGx68UPTDB7x18bZK7wm2zDK8H+4VNWECc+WBztdK5Bwv0twqMa6a8KQp5ybUj5a5UZwMQhwMPlyWAedjLUrLLAvWVxj0G6zoka3J46q0sUG5eSvcgpoIcgKU9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from BN9PR03CA0643.namprd03.prod.outlook.com (2603:10b6:408:13b::18) by DS0PR12MB8564.namprd12.prod.outlook.com (2603:10b6:8:167::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Mon, 20 Mar 2023 08:14:33 +0000 X-Received: from BN8NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13b:cafe::cd) by BN9PR03CA0643.outlook.office365.com (2603:10b6:408:13b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Mon, 20 Mar 2023 08:14:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+101407+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT028.mail.protection.outlook.com (10.13.176.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.15 via Frontend Transport; Mon, 20 Mar 2023 08:14:33 +0000 X-Received: from TPE-L1-ABNCHANG.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 20 Mar 2023 03:14:31 -0500 From: "Chang, Abner via groups.io" To: CC: Nickle Wang , Igor Kulchytskyy Subject: [edk2-devel] [PATCH v2 2/3] RedfishPkg: Update Redfish DSC Date: Mon, 20 Mar 2023 16:13:52 +0800 Message-ID: <20230320081353.1335-3-abner.chang@amd.com> In-Reply-To: <20230320081353.1335-1-abner.chang@amd.com> References: <20230320081353.1335-1-abner.chang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT028:EE_|DS0PR12MB8564:EE_ X-MS-Office365-Filtering-Correlation-Id: ec151ff8-7a5e-4d9d-cca7-08db291b2305 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: WTC1nYRLFIsVctWm/gqPxJkyG+fM3Xlf5o31zU8WUD1B++pNn1aqDVpKGWzsmIHEl9d3EBcSdqkCVwSaUsDyLhJft0FGgzbOvHOzDvnxOHyi4dmLEGiShYhsd1QizzcNdMCPHF5TuxQYA1ZZrRD0vmaUJSVS2dx1jOaws1gdyH1FsE34zZjBqNY852nftdq4Ou5XGsjPO6eon5QHyKo3IiNpXSWfaQp3+Ez0/qSFgWoMhlhMOA+t6KYj2Co9Zue7H+Q8vbX+SCeIKbEzT0UcyGXn/GuUE5T3C5c0W7227EZc0MTHOBYKhs1dPEZU2YP+LOxnusx8NUn7/CnFPzksSetBQ193Jrqpv/0oDBdf98j+x46EJ/sJ43nbsChUnjaMnlM1lcAOmVTW7gMyapZDQaw0TEdcMc3tgJhxJ3SKmM/V2MQPNRoX8WYR0mW3zwIv8fCv/iRB3zV+kIk+Z1UYOhNCz24Q6/WL7paEqJBt7UAYG8hVajjto+ztJzNh1dqGtSbNXDOF5KybartY4BqdL0qWdUBFz8tzlLVN3WwyoQgf33qfaOIz0bF4+hhdJL4InuFQStFdkrbaznn6yi34rUyinsOszJbOHNX9+P7lMPrszWPjbqXyH6mCsq5FufRozXUm/0XgSsAhE1eKKbTMpuUWqQ0Gd0oUX4iOLask4t8zSUWgjWV75/z/Z3QM9+O97N4FmmwCrSU2OFGdvN807qPMR6Df5abgkR2McsVdpz8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2023 08:14:33.1183 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec151ff8-7a5e-4d9d-cca7-08db291b2305 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8564 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@amd.com X-Gm-Message-State: wK5ym1GzU7NAcZzVg9TueIGZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679300076; bh=5ZFIfY8Unh2DDI/vIaITF/L6QcmgwCqt3d+G5I+JcEI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UT17oyIca5mXyn/9321vs+MWsGxXHHrXApxIrXvxCxE9lsPBE0oXt0e8EVcdyiO/3rM R9kqVssxjZqPygk+EyG3hz6hB+XSxn7t9z3PT6lUd/LHUAMhZeGj/gTh46itxk1quvSJ4 fYotRDqLGSeXdEumq3LUYW0vYwa8AJWqkLo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679300077628100005 Content-Type: text/plain; charset="utf-8" From: Abner Chang Update Redfish DSC for PlatformHostInterfaceBmcUsbNicLib. Signed-off-by: Abner Chang Cc: Nickle Wang Cc: Igor Kulchytskyy Reviewed-by: Nickle Wang --- RedfishPkg/RedfishPkg.dsc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc index cf25b63cc29..223ab72c1db 100644 --- a/RedfishPkg/RedfishPkg.dsc +++ b/RedfishPkg/RedfishPkg.dsc @@ -3,6 +3,7 @@ # # Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.
# (C) Copyright 2021 Hewlett-Packard Enterprise Development LP. +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -34,6 +35,7 @@ DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseD= ebugPrintErrorLevelLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf RedfishPlatformHostInterfaceLib|RedfishPkg/Library/PlatformHostInterface= LibNull/PlatformHostInterfaceLibNull.inf + RedfishPlatformHostInterfaceLib|RedfishPkg/Library/PlatformHostInterface= BmcUsbNicLib/PlatformHostInterfaceBmcUsbNicLib.inf HttpLib|NetworkPkg/Library/DxeHttpLib/DxeHttpLib.inf HttpIoLib|NetworkPkg/Library/DxeHttpIoLib/DxeHttpIoLib.inf NetLib|NetworkPkg/Library/DxeNetLib/DxeNetLib.inf @@ -41,6 +43,10 @@ RedfishPlatformCredentialLib|RedfishPkg/Library/PlatformCredentialLibNul= l/PlatformCredentialLibNull.inf RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/R= edfishContentCodingLibNull.inf =20 + # NULL instance of IPMI related library. + IpmiLib|MdeModulePkg/Library/BaseIpmiLibNull/BaseIpmiLibNull.inf + IpmiCommandLib|MdeModulePkg/Library/BaseIpmiCommandLibNull/BaseIpmiComma= ndLibNull.inf + [LibraryClasses.ARM, LibraryClasses.AARCH64] # # This library provides the instrinsic functions generated by a given co= mpiler. @@ -51,6 +57,7 @@ =20 [Components] RedfishPkg/Library/PlatformHostInterfaceLibNull/PlatformHostInterfaceLib= Null.inf + RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformHostInterfa= ceBmcUsbNicLib.inf RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.i= nf RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNu= ll.inf RedfishPkg/Library/DxeRestExLib/DxeRestExLib.inf --=20 2.37.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#101407): https://edk2.groups.io/g/devel/message/101407 Mute This Topic: https://groups.io/mt/97726811/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 03:36:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+101410+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1679300082072287.84795005521835; Mon, 20 Mar 2023 01:14:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id xD6UYY1788612xS5yCRUcDnL; Mon, 20 Mar 2023 01:14:41 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.84]) by mx.groups.io with SMTP id smtpd.web10.8874.1679300080421046132 for ; Mon, 20 Mar 2023 01:14:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ia4InRlnF64mTltJAzUgxBQTZKu1/cdxT8+mK/+Yh7TFzvOnPX24T8C+VBJCWsiItly5fYoclRbBoiuIMvBYEoI5Ywil/AqqMCQ0TgBbiZohOLNo7aoY435qyP/upct6Mw6sxA/Rs7+WL0Z8t7qXSZeenEH36BNXKUElYuIOU85j5XWjqsEbryoW/Lq+KpYbFnH7qToQOQqll6jo0jstFrQv8j0iiH+IrIF3wqaPDU8g+vgxsRHsGm956KsNtE34HL07AZw+RNaAzZDjRcONYkp9VGpl4txDkWv2T/S0CrIoNeNRlKHVWBSg47Uwfw3Wgv7wPVphgJUlorxeXYTycA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ptrCZnNH08YUFtz+OUZFXi/e8aV7psdL7bUbQ31eieQ=; b=UHI2pzcyylVYqRZzy1dz8dLCt3CagwsHcqVwXsS/4AUE8HVzAZ82dcLKWKs6lFFiuRLkUgbupiFI+v1lH1y/L5bc1nklOJ3x2ITnIF6eGPZWCgzZ/rkC91JNMecrVlOvaADArfNhJqnP+aWlaTpuzDbd3K2Wr0tdP/vlU3CLod6UgzMPfar7MTD5nHG2otQGHNzXF9bVZ168fwDyJdj188vf3ilMgb40GkfELoCZcfEIlvVKSne6Cz8p6gKRQSKGYCLCCxOZxyv9SKZIzCcP2ppDLhLGKLBqcyBOdIPBzeF4IbspIUoVAxELVsLIpcQlV1jw8KwnlowA6AVMlADHzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from BN8PR04CA0005.namprd04.prod.outlook.com (2603:10b6:408:70::18) by DM4PR12MB8451.namprd12.prod.outlook.com (2603:10b6:8:182::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.33; Mon, 20 Mar 2023 08:14:35 +0000 X-Received: from BN8NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:408:70:cafe::81) by BN8PR04CA0005.outlook.office365.com (2603:10b6:408:70::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Mon, 20 Mar 2023 08:14:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+101410+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT031.mail.protection.outlook.com (10.13.177.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.15 via Frontend Transport; Mon, 20 Mar 2023 08:14:34 +0000 X-Received: from TPE-L1-ABNCHANG.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 20 Mar 2023 03:14:33 -0500 From: "Chang, Abner via groups.io" To: CC: Nickle Wang , Igor Kulchytskyy Subject: [edk2-devel] [PATCH v2 3/3] RedfishPkg: Update Readme.md Date: Mon, 20 Mar 2023 16:13:53 +0800 Message-ID: <20230320081353.1335-4-abner.chang@amd.com> In-Reply-To: <20230320081353.1335-1-abner.chang@amd.com> References: <20230320081353.1335-1-abner.chang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT031:EE_|DM4PR12MB8451:EE_ X-MS-Office365-Filtering-Correlation-Id: cb6525e6-6753-490e-eaa4-08db291b2420 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: lz0AvoTtLo5Wdv2VHWwd4Q9CoCXr9ewwYDoEbsnSpIJlzaeAomQE9071+CYc1Z2L2sQG1Imb2qwjRBh2Re7cDFlNawm6zDcBQKLwlaQ/t13wTN8zXOQ/FWskgMrjghcRyiSyRMM3/K4x/meva7Emstwd3kUkEIwMVq8a2veNLEgaaHwz3NRMffRRyRZXlcoCZ8gFAhspw9/vnCUJuWpugSElmDzorfQuv1MQcH2gMTBgrudskY5dAhBQZvFVyR6xDsPgVxbsYA2pUWZO1ypSIhjbM03tBoNJgXAJ+XrLYQZoRNT8cm1KLMfwJ4ieA/4+fV52aPpioqWU2c/PF6wbDj9cyYKYwalChuqHYhZiCPJnmuJe6PcoCjIMlS+JnlaZzK5EcgYf2HttDxapBVNkqlV16uCc0TALD3S1h+/18KkHPyHsQJnxDnJX2OFUXC7t6XXJzl6XhY9rOOuOfF3e56U2mpFX0p7JJGy063OOFucvFqY1uxt3cMKb7nW0s9UrQV3QhQYwl3KYDeiG3BZt0TujRJMy/OJ4A7D0kZ+L+uCM2mg1qWODyM9F/dIrDAHx58yA5JoKa788nKWiRKCkSmicGI4o0nfmbO4bzpvPtRwBBqln7oGYRPKALKusRUHJrFwBHidWsHbsEXXoW3fQTA3ABxy5KCY0xZK/wCL6Jd6CjXK9vexnBk9C/7+SSGGdpkNckpGz7dZ1fc1s/42qHpWCNKam2/wSZ3fJSLTfBhp4x5zZRHTwymfULNrCG9ol/uMXRaurCFuD1QJ7wavdIp4l/jFMd9e1UhoWcospXogOTY/An2lrae04Gxr7AhGQKv1rXEelIiK93UAR7PLBmg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2023 08:14:34.9581 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cb6525e6-6753-490e-eaa4-08db291b2420 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB8451 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@amd.com X-Gm-Message-State: fhhtfn8zvGfSaPe1Eqw83UyZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679300081; bh=WwMorr/28+sB44mPo1FLutEXn8twqV+lViDYKlPnAFo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Soy6vbitA27p1CLSPT3Ss8jhc6BdxWLD7++gc31SjHrbkEN4xzvobVfGmWDmh7WqXoG ReN9nFLScdp5QIe5xdY66crImYR/ZctHP2e0JcrfZrlaVIfz+NN2qDHffsxLf6CmlHgHj qN03Qw4P1sqPPjJty35si4wb5k275G9raDY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679300083755100001 Content-Type: text/plain; charset="utf-8" From: Abner Chang Update readme.md and add figures to delineate the relationship of edk2 Redfish, USB NIC and IPMI. Signed-off-by: Abner Chang Cc: Nickle Wang Cc: Igor Kulchytskyy Reviewed-by: Nickle Wang --- RedfishPkg/Readme.md | 112 +++++- .../Documents/Media/BmcExposedUsbNic.svg | 283 +++++++++++++++ .../Media/EmualtorPlatformLibrary.svg | 286 +++++++++++++++ .../Media/PlatformWihtBmcLibrary.svg | 328 ++++++++++++++++++ 4 files changed, 1001 insertions(+), 8 deletions(-) create mode 100644 RedfishPkg/Documents/Media/BmcExposedUsbNic.svg create mode 100644 RedfishPkg/Documents/Media/EmualtorPlatformLibrary.svg create mode 100644 RedfishPkg/Documents/Media/PlatformWihtBmcLibrary.svg diff --git a/RedfishPkg/Readme.md b/RedfishPkg/Readme.md index a0e9f0892c2..7defe78eb1e 100644 --- a/RedfishPkg/Readme.md +++ b/RedfishPkg/Readme.md @@ -50,12 +50,107 @@ The library is incorporated with RedfishLib ***[[13]](= #[0])*** to encode and dec * **RedfishPkg\Library\JsonLib** ***[[14]](#[0])*** This is the wrapper of open source project ***[Jansson](https://digip.or= g/jansson)***, which is the library that provides APIs to manipulate JSON = payload. =20 -## Platform Components for EDK2 EmulatorPkg: - * **RedfishPlatformCredentialLib** - the EDK2 Emulator platform implementation of acquiring credential to bui= ld up the communication between UEFI firmware and Redfish service. ***[[10]= ](#[0])*** - - * **RedfishPlatformHostInterfaceLib** - EDK2 Emulator platform implementation which provides the information of = building up SMBIOS type 42h record. ***[[11]](#[0])*** +## Platform Components +### **EDK2 EmulatorPkg** +![EDK2 EmulatorPkg Figure](https://github.com/tianocore/edk2/blob/master/R= edfishPkg/Documents/Media/EmualtorPlatformLibrary.svg?raw=3Dtrue) + + * **RedfishPlatformCredentialLib**
+ The EDK2 Emulator platform implementation of acquiring credential to b= uild up the communication between + UEFI firmware and Redfish service. ***[[10]](#[0])*** + + The Redfish credential is hardcoded in the EmulatorPkg RedfishPlatform= CredentialLib. The credential is + used to access to the Redfish service hosted by [Redfish Profile Simul= ator](https://github.com/DMTF/Redfish-Profile-Simulator). + + * **RedfishPlatformHostInterfaceLib**
+ EDK2 Emulator platform implementation which provides the information o= f building up SMBIOS type 42h + record. ***[[11]](#[0])*** + + EmulatorPkg RedfishPlatformHostInterfaceLib library consumes the EFI V= ariable which is created + by [RedfishPlatformConfig EFI application](https://github.com/tianocor= e/edk2/tree/master/EmulatorPkg/Application/RedfishPlatformConfig). RedfishP= latformConfig EFI application stores not all of SMBIOS + Type42 record information but the necessary network properties of Redf= ish Host Interface in EFI + Variable. + +### **Platform with BMC and the BMC-Exposed USB Network Device** +![Platform with BMC Figure](https://github.com/tianocore/edk2/blob/master/= RedfishPkg/Documents/Media/BmcExposedUsbNic.svg?raw=3Dtrue) + +Server platform with BMC as the server management entity may expose the [U= SB Network Interface Device (NIC)](https://www.usb.org/document-library/cla= ss-definitions-communication-devices-12) +to the platform, which is so called the in-band host-BMC transport interfa= ce. The USB NIC exposed by BMC is +usually a link-local network device which has two network endpoints at hos= t and BMC ends. The endpoint at +host side is connected to the platform USB port, and it is enumerated by e= dk2 USB BUS driver. The edk2 USB +NIC driver then produces the **EFI Network Interface Identifier Protocol** +*(EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID_31)* and connected by EFI= Simple +Network Protocol (SNP) driver and the upper layer edk2 network drivers. Th= e applications can then utilize +the network stack built up on top of USB NIC to communicate with Redfish s= ervice hosted by BMC.
+BMC-exposed USB NIC is mainly designed for the communication between host = and BMC-hosted Redfish service. +BMC-exposed USB NIC can be public to host through [Redfish Host Interface = Specification](https://www.dmtf.org/sites/default/files/standards/documents= /DSP0270_1.3.0.pdf) and discovered by edk2 Redfish discovery +driver. The [Redfish Host Interface Specification](https://www.dmtf.org/si= tes/default/files/standards/documents/DSP0270_1.3.0.pdf) describes the dedi= cated host interface between host and +BMC. The specification follows the [SMBIOS Type 42 format](https://www.dmt= f.org/sites/default/files/standards/documents/DSP0134_3.6.0.pdf) and define= s the host interface as: +- Network Host Interface type (40h) +- Redfish over IP Protocol (04h) + +
+ +![Platform BMC Library Figure](https://github.com/tianocore/edk2/blob/mast= er/RedfishPkg/Documents/Media/PlatformWihtBmcLibrary.svg?raw=3Dtrue) + + * **RedfishPlatformCredentialLib**
+RedfishPlatformCredentialLib library instance on the platform with BMC use= s Redfish Credential +Bootstrapping IPMI commands defined in [Redfish Host Interface Specificati= on](https://www.dmtf.org/sites/default/files/standards/documents/DSP0270_1.= 3.0.pdf) to acquire the Redfish credential from BMC. edk2 +Redfish firmware then uses this credential to access to Redfish service ho= sted by BMC. + + * **RedfishPlatformHostInterfaceLib**
+BMC-exposed USB NIC, a IPMI Message channel is reported by BMC as a "IPMB-= 1.0" protocol and "802.3 LAN" +medium channel. edk2 firmware can issue a series of IPMI commands to acqui= re the channel +application information (NetFn App), transport network properties (NetFn T= ransport) and other necessary +information to build up the SMBIOS type 42h record. +In order to recognize the specific BMC-exposed USB NIC in case the platfor= m has more than one USB NIC +devices attached, the MAC address specified in the EFI Device Path Protoco= l of SNP EFI handle is used to +match with the MAC address of IPMI message channel. Due to the network inf= ormation such as the MAC +address, IP address, Subnet mask and Gateway are assigned by BMC, edk2 Red= fish implementation needs a +programmatic way to recognize the BMC-exposed USB NIC. + + * **MAC address:** Searching for the BMC-exposed USB NIC
+ The last byte of host-end USB NIC MAC address is the last byte of BMC-= end USB NIC MAC address minus 1. + RedfishPlatformHostInterfaceLib issues the NetFn Transport IPMI comman= d to get the MAC address of each + channel and checks them with the MAC address specified in the EFI Devi= ce Path Protocol.
+ + **_For example:_**
+ BMC-end USB NIC MAC address: 11-22-33-44-55-00
+ Host-end USB NIC MAC address: 11-22-33-44-55-ff + + * **IP Address:** Acquiring the host-end USB NIC IP Address
+ The last byte of host-end USB NIC IPv4 address is the last byte of BMC= -end USB NIC IPv4 address minus 1. + + **_For example:_**
+ BMC-end USB NIC IPv4 address: 165.10.0.10
+ Host-end USB NIC IPv4 address: 165.10.0.9 + + * **Other Network Properties**:
+ Due to the host-end USB NIC and BMC-end USB NIC is a link-local networ= k. Both of them have the same + network properties such as subnet mask and gateway. RedfishPlatformHos= tInterfaceLib issues the NetFn + Transport IPMI command to get the network properties of BMC-end USB NI= C and apply it on host-end USB + NIC. + + * **IPMI Commands that Used to Build up Redfish Host Interface** + + Standard IPMI commands those are used to build up the Redfish Host Int= erface for BMC-exposed USB NIC. + The USB NIC exposed by BMC must be reported as one of the message chan= nels as 802.3 LAN/IPMB 1.0 message + channel. + + | IPMI NetFn | IPMI Command| Purpose | Corresponding Host Interface Fi= eld| + |------------|-------------|---------|--------------------------------= ---| + | App
(0x06) | 0x42 | Check the message channel's medium type and p= rotocol.
Medium: 802.3 LAN
Protocol: IPMB 1.0| None| + | Transport
(0x0C) | 0x02 | Get MAC address of message channel. Use= d to match with the MAC address populated in EFI Device Path of network dev= ice| None| + | Group Ext
(0x2C) | Group Extension ID: 0x52
Command: 0x02 | Ch= eck if Redfish bootstrap credential is supported or not.| In Device Descrip= tor Data, Credential Bootstrapping Handle| + | Transport
(0x0C) | Command: 0x02
Parameter: 0x04 | Get BMC-end= message channel IP address source| In Protocol Specific Record Data
- H= ost IP Assignment Type
- Redfish Service IP Discovery Type
- Generate= the Host-side IP address|. + | Transport
(0x0C) | Command: 0x02
Parameter: 0x03 | Get BMC-end= message channel IPv4 address| In Protocol Specific Record Data
- Host I= P Address Format
- Host IP Address| + | Transport
(0x0C) | Command: 0x02
Parameter: 0x06 | Get BMC-end= message channel IPv4 subnet mask| In Protocol Specific Record Data
- Ho= st IP Mask
- Redfish Service IP Mask| + | Transport
(0x0C) | Command: 0x02
Parameter: 0x12 | Get BMC-end= message channel gateway IP address| None, used to configure edk2 network c= onfiguration| + | Transport
(0x0C) | Command: 0x02
Parameter: 0x14 | Get BMC-end= message channel VLAN ID| In Protocol Specific Record Data
Redfish Serv= ice VLAN ID| + + **__NOTE__** +``` +Current RedfishPlatformHostInterfaceLib implementation of BMC-exposed USB = NIC can only support IPv4 address format. +``` =20 ## Miscellaneous: =20 @@ -65,7 +160,6 @@ The library is incorporated with RedfishLib ***[[13]](#[= 0])*** to encode and dec For example, run shell command "RedfishPlatformConfig.efi -s 192.168.1= 0.101 255.255.255.0 192.168.10.123 255.255.255.0", which means the source IP address is 192.168.10.101, and the Redfish Server IP a= ddress is 192.168.10.123. ``` - * **Redfish Profile Simulator** Refer to [Redfish Profile Simulator](https://github.com/DMTF/Redfish-Pr= ofile-Simulator) to set up the Redfish service. We are also in the progress to contribute bug fixes and enhancements to= the mainstream Redfish Profile Simulator in order to incorporate with EDK2= Redfish solution. @@ -121,7 +215,9 @@ The library is incorporated with RedfishLib ***[[13]](#= [0])*** to encode and dec 1. [DSP0270](https://www.dmtf.org/sites/default/files/standards/documents/= DSP0270_1.3.0.pdf) - Redfish Host Interface Specification, 1.3.0 2. [DSP0266](https://www.dmtf.org/sites/default/files/standards/documents/= DSP0266_1.12.0.pdf) - Redfish Specification, 1.12.0 3. Redfish Schemas - https://redfish.dmtf.org/schemas/v1/ -4. UEFI Specification - http://uefi.org/specifications +4. SMBIOS - https://www.dmtf.org/sites/default/files/standards/documents/D= SP0134_3.6.0.pdf +5. USB CDC - https://www.usb.org/document-library/class-definitions-commun= ication-devices-12 +6. UEFI Specification - http://uefi.org/specifications =20 ## The Contributors Thanks to the below predecessors who contributed to the UEFI EDK2 Redfish = Prove of Concept code.\ diff --git a/RedfishPkg/Documents/Media/BmcExposedUsbNic.svg b/RedfishPkg/D= ocuments/Media/BmcExposedUsbNic.svg new file mode 100644 index 00000000000..c7088eb8d54 --- /dev/null +++ b/RedfishPkg/Documents/Media/BmcExposedUsbNic.svg @@ -0,0 +1,283 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + EDKII Network Stack= s(UEFI Driver Model) + + + + + + + + EFI REST EX= (UEFI Driver Model) + + + + + + + + BMC ExposedUSB Network Interface Device + + + + + + + + + + Redfish Service= + + + + + + + + + + + + + + + + + + + + EDKII Redfish Host = Interf= ace(DXE Driver) + + + + + + BMC + + + + + + On Network<= /text> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + EDKII Redfish Crede= ntial(DXE Driver) + + + + + + + + + + + + + + + + + + + + + + EDKII USB Stacks(UEFI Driver Model) + + + + + + + + + + + + + + + + + + + + + + EFI Redfish Discove= ry(UEFI Driver Model) + + + + + + + + diff --git a/RedfishPkg/Documents/Media/EmualtorPlatformLibrary.svg b/Redfi= shPkg/Documents/Media/EmualtorPlatformLibrary.svg new file mode 100644 index 00000000000..33aa6c79df0 --- /dev/null +++ b/RedfishPkg/Documents/Media/EmualtorPlatformLibrary.svg @@ -0,0 +1,286 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Redfish Service= + + + + + + + + + + + + On Network + + + + + + + + EDKII Redfish Creden= tial(DXE Driver) + + + + + + + + EDKII Redfish Host = Interf= ace(DXE Driver) + + + + + + + + Platform Redfish Credenti= al Library + + + + + + + + Platform Redfish Ho= st Int= erface Library + + + + + + EmulatorPkg Library Instan= ce + + + + + + EmulatorPkg Library Insta= nce + + + + + + + + + + + + + + + + + + + + + EFI Variable<= /text> + + + + + + + + + + + + + + + RedfishPlatformConfg.efi= + + + + + + + + + + + + + Information of <= /tspan>SMBIOS 42 Record + + + + + + Hardcoded Redfish Credential<= /tspan> + + + + + + Redfish Profile = Simulator + + + + + + + + + + + + + + + + + diff --git a/RedfishPkg/Documents/Media/PlatformWihtBmcLibrary.svg b/Redfis= hPkg/Documents/Media/PlatformWihtBmcLibrary.svg new file mode 100644 index 00000000000..e52d8478a88 --- /dev/null +++ b/RedfishPkg/Documents/Media/PlatformWihtBmcLibrary.svg @@ -0,0 +1,328 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Redfish Service= + + + + + + + + + + + + On Network + + + + + + + + EDKII Redfish Creden= tial(DXE Driver) + + + + + + + + EDKII Redfish Host = Interf= ace(DXE Driver) + + + + + + + + Platform Redfish Credenti= al Library + + + + + + + + Platform Redfish Ho= st Int= erface Library + + + + + + Platform with BMC Library = Instance + + + + + + + + + + + + + + + + + + + + Send IPMI NetFn App and I= PMI NetFn Transprort commands to acquire the network Information to build up SMBIOS 42 Record + + + + + + Platform with BMC Library= Instance + + + + + + + + + + + + BMC + + + + + + + + IpmiCommandLibrary= + + + + + + + + IpmiTransportProto= col + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BMC ExposedUSB Network Interface Device + + + + + + + + + + + + + Get Redfish Credential us= ing IPMI Group Extension (Body code 52h for Redfish) + + + + + + + + --=20 2.37.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#101410): https://edk2.groups.io/g/devel/message/101410 Mute This Topic: https://groups.io/mt/97726813/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-