From nobody Mon May 6 21:37:16 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+100952+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 1678376479604517.8975145402151; Thu, 9 Mar 2023 07:41:19 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id tDoiYY1788612x1lszEG0QVo; Thu, 09 Mar 2023 07:41:19 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.68]) by mx.groups.io with SMTP id smtpd.web11.16695.1678376477816265404 for ; Thu, 09 Mar 2023 07:41:18 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SIha52kgMTOC/Gw0QFfHQoEbLwpM1KHoucRtx+f12zFD41DQaoW+0LH0hqPCuCjaOJ1E6lH3FKgSY4F6QsUpYkd4GMAQ9jcwscGFm+yNvGpOAvQoouv4O8235RCUG0ojk3CjZ6tI4tyhkFM3A9piNZz9ZpKSSyXHJcHKtyJAdAw70aJPE0MJPvbqow6ZD9SyRN9SlEN15qpUk+8JMKPHFpX/uAjI6QGoYqumnz+kzU/J87Jpsm3Si7AlLW2ombefoMg7BCvHRW+CMDg03PppN5Tb72ymeXmAXxfFvrgQk07I1eiRk2lCfq0bYZ1XodXhm8kK7PtqK27puQXdZHtMRQ== 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=ZbcXPCbi5Ep91qN89Z6dCZUUtlYNnO9rPemlQFTSi7k=; b=WksuoGMWWQkfSlcDnfagOMrGjEMAAGrLUxMBTtokNMbkJ3YvnaZxKR0ZnrgsARBIc4HeSugC4CMottG48ifN94JtI4RXKgv+b0qT5DNZHdLqCL7EWQkyoLJ/JE49FaGKIoXfLAsXBSzFgpmfcx3OY+/yyTebKsRmO+S0vG0ygIQsl+EslwT+JKXj0bO2Aift7n3YRR86DIpr9G6YvKlJ6SE/0qaLa/XWuvECRUscc8xGpKuww7LY0+v3ncee/ZKurHH/XmlAKLWtIZ0fNnA2gVlxFpRc9HawNZXe5u3cA5ZO1r31M/dcVk1yiIPpn9R5yk6oP0t71zYBtM42/D0e1g== 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 DM6PR07CA0051.namprd07.prod.outlook.com (2603:10b6:5:74::28) by SJ2PR12MB8956.namprd12.prod.outlook.com (2603:10b6:a03:53a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17; Thu, 9 Mar 2023 15:41:14 +0000 X-Received: from DM6NAM11FT036.eop-nam11.prod.protection.outlook.com (2603:10b6:5:74:cafe::ac) by DM6PR07CA0051.outlook.office365.com (2603:10b6:5:74::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.19 via Frontend Transport; Thu, 9 Mar 2023 15:41:14 +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+100952+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 DM6NAM11FT036.mail.protection.outlook.com (10.13.172.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.19 via Frontend Transport; Thu, 9 Mar 2023 15:41:14 +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; Thu, 9 Mar 2023 09:41:12 -0600 From: "Chang, Abner via groups.io" To: CC: Nickle Wang , Igor Kulchytskyy Subject: [edk2-devel] [PATCH 1/3] RedfishPkg/Library: Redfish BMC USBNIC Host Interface Date: Thu, 9 Mar 2023 23:40:53 +0800 Message-ID: <20230309154055.505-2-abner.chang@amd.com> In-Reply-To: <20230309154055.505-1-abner.chang@amd.com> References: <20230309154055.505-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: DM6NAM11FT036:EE_|SJ2PR12MB8956:EE_ X-MS-Office365-Filtering-Correlation-Id: 62c540ee-a754-481d-60a5-08db20b4b76c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: XGS8sJS9vrzwKVHQDVK2Tc9LMt+K7KRsdynmrpx7bUKIOAPR3rqGzZOwfiVzF5/wrfdCEK2p4HzWUGYm3VWv5j4hn/pBIKGqktXQN2IewwVjRmQXUliPEW2s6qgS0jXca6i707FgHNv18p7avl8Z4/M6L1UzecMWN33q+f7/ZTD3nGWZhnx2NnkKVINnYizB67dPBx3LJKmUdl9hlmNgoIRbC+UQhOl8Z+I/Cj+/ChsIWv46UETdyxgK6iTPQ4hYj0Ckl/zhp5IRqp3pXWGgWRxT3iv338tWOyZQVoqyAaGK710ZIF5g94hUo+iAf+jgSyl/ul8bP8N3+V625xOYedDEHiG0YnA6w1Ar+KFg7QWq3IceYhAywQBE0QKSvfhFFeGXJWoWEBOi1l3g3zO4M86KH5eekmM1Bnth/JLYquTqdsyu11GWZyA15MclRisUgZ8Qldb0jRMGxmfGVraaMrA5+T6Rm7rnUWn0WHBmD1z+zi6SJsrYzl0Kr9BqireCB7UBwQ1sMkBJ2rORHU6tKTMSQR1trNDLfaIpcjciE5x8ryBlqc8+O1mcTZ/CmOj5asCX/M4aDQvuTucmA4wsY4GNkxdRpSjcna3h/8vR9fLZEjnIOSCF5N6lKwUn12bqZlq28jHQZOP3SUq7ekgCv7Sej3Osoy12ld1IUwBv13zV1mSL/b5z3s2aaaShc6j+P7n20weN8PdL8cH2FRPKTLn543NUGmjHEgt4k+SZ+BI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 15:41:14.5811 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62c540ee-a754-481d-60a5-08db20b4b76c 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: DM6NAM11FT036.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8956 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: RchxsAdi0YctUgol7RMVAZIPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678376479; bh=yjGDRzcIilXfoSTBCPOPXgVUtrwzOJZKY24jw6FBBeY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=NSrYU9LQ85W0Oel5tmLFZMEZau2fNJ8JW1mJQ4LKdKI/D47Npn9oxTl7A/Z2jjTqw/W OXH9RgiFt40G51QXtQMfOypD+CLk1FYJGkgCagp/opB2aQRM/TxUDvmxjZuPEJnhWIVGY SLzn0ohQ1ppWfpWGD/Jlwfh7CO4TgnLSH0Y= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678376480397100007 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 --- RedfishPkg/RedfishPkg.dec | 10 + .../PlatformHostInterfaceBmcUsbNicLib.inf | 48 + RedfishPkg/Include/Library/RedfishDebugLib.h | 3 +- .../PlatformHostInterfaceBmcUsbNicLib.h | 84 ++ .../PlatformHostInterfaceBmcUsbNicLib.c | 1280 +++++++++++++++++ 5 files changed, 1424 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..251aa5e2b76 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|""|VOID*|0x00001005 + # + # Use PCD to declare the Redfish service UUID becasue there is no + # specification for that. + # + gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceUuid|L""|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..1c530b692e8 --- /dev/null +++ b/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformHostInte= rfaceBmcUsbNicLib.c @@ -0,0 +1,1280 @@ +/** @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, " Aloocate 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); + } + + // 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); + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "%s\n", DevicePathStr)); + FreePool (DevicePathStr); + + 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); + DEBUG ((DEBUG_REDFISH_HOST_INTERFACE, "%s\n", DevicePathStr)); + FreePool (DevicePathStr); + + 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 (#100952): https://edk2.groups.io/g/devel/message/100952 Mute This Topic: https://groups.io/mt/97498499/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 Mon May 6 21:37:16 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+100953+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 1678376479113951.8041610234975; Thu, 9 Mar 2023 07:41:19 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id s6T6YY1788612xylY0dEpcvv; Thu, 09 Mar 2023 07:41:18 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.72]) by mx.groups.io with SMTP id smtpd.web11.16696.1678376478084206625 for ; Thu, 09 Mar 2023 07:41:18 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jxnRmefFKQgzsewjDkEEL6mb5AItTPHeAv+KmhRw+cwRvTUTviAnCYxrV0HWYSZixdhqTXvuSyg2XRJVwQAEk3jaCb+m2IYYMRCsrd9v4F9j3UnpXhFGfP1tK5ojkdxd1I4aLx5aPz12BhLAKpgjFHZunNDym6gpdbjLP5lYewzvUtXxd1fgm+Kd1Fw+WXm4FHDZF3hrjYX5u1XRbZ3PK0uZ4Vnr2RfdzvOgtzjxgJD+mV6FPj4zM6/gHtDvxTw/UcQfpLhmJy2dGGuG6mLcOF+6e3X11/hse/nyiCjda9X16UeoT/LLvEe7EPyseB949yL1PBbTKGaJ3RDMP8PrFw== 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=Cdkz8oXS/7v6UeML8yqbrWNhbRNSktHPU17nVQ0cgD4=; b=ktqOE70ZoYfD5OrjAkrVJ9N7aMNh9SvUlN3yYuQGEZi7GBIqJDuIalXvQwClUbMDVys3zRLH/hfwOEyt09ood0od/eb8BjdPLhVBV5otB9G76PO5ns6xkKLWd5z/5cR9m2omNeBYDFQa1g2xcpXRfULJVmtSAgnIWWy6P9pKRqfD+hJaftXFosQZAsaIR38rIGr0/yBIqeT0ctTtM3qXj150Ntr7mUIquy2RT9rudnAn9zOJoKoLCb9DIH9uiJIJ0NWrS3xX3/baRknW8YQrzXoWp8sxiXfNC7yboVXYu7U2wW7UFrxRq37QDOFrkQfziIr9QtU4/zSzcc+iMFyL9Q== 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 DS7PR05CA0019.namprd05.prod.outlook.com (2603:10b6:5:3b9::24) by BY5PR12MB4082.namprd12.prod.outlook.com (2603:10b6:a03:212::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.19; Thu, 9 Mar 2023 15:41:16 +0000 X-Received: from DM6NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b9:cafe::5) by DS7PR05CA0019.outlook.office365.com (2603:10b6:5:3b9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.19 via Frontend Transport; Thu, 9 Mar 2023 15:41:16 +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+100953+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 DM6NAM11FT004.mail.protection.outlook.com (10.13.172.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.18 via Frontend Transport; Thu, 9 Mar 2023 15:41:15 +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; Thu, 9 Mar 2023 09:41:14 -0600 From: "Chang, Abner via groups.io" To: CC: Nickle Wang , Igor Kulchytskyy Subject: [edk2-devel] [PATCH 2/3] RedfishPkg: Update Redfish DSC Date: Thu, 9 Mar 2023 23:40:54 +0800 Message-ID: <20230309154055.505-3-abner.chang@amd.com> In-Reply-To: <20230309154055.505-1-abner.chang@amd.com> References: <20230309154055.505-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: DM6NAM11FT004:EE_|BY5PR12MB4082:EE_ X-MS-Office365-Filtering-Correlation-Id: 194f5090-d51b-4705-01d6-08db20b4b83b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: zHWj3HsCHR/SsZrQ3OtbAlkcfIEQgROui12UhmyHhT7+2Wgd73dsMCtwT2S/eSTHWzC/e+p6soeIElTGcdPr8LqmpuLAPQgJRn6bNlnjxfA3njNG3qz61LDKPRnXgJQ08cij/rLnJpT6kssJAlSwQfpIhggwkGnu13bGO2aM6U7D8sB0cAOP57cAmthwozfuAqIpCmWuZ1mEun24BWtCNL8YpmBJNYINUqcJLfeH0X4qgAsVd+PU++EaF7w9XofLtT9JVNwPHRjZG94MiTouDclaTJ5NnQJ/+sdT3JEj4R/q/915SKmj+8fH87PI2JmWpIG+DDlDQ4Jsm7wTh3lihrwhMxH6x2nhLECfPcXKA6e4/HUWwv9VO0euC+tHbuu8WaKInJ8KQk14QPu62Y4PTGfLK++2bOR/WVCOk0Zrj0wDrB6DzBl++nPmTtprBvOIzbj11rr0E+rpUj+BGL57JHG6S0o5rOB5l2hPRiPByEdPH5dA9loXuZJGqkDxve/FrOM/JUa+WjeJTpqNDgCdc9EkKqdMKSOvbHHq3F/fNaLD5arb9XTJs3++gC1U/1/VPqwX0XUB7Wy9Pfj5bYh8BVpHLRWmXeSFi9f+AUC+wF8g7d0WouUKtBpDHDvGpnfHJb1JCQk8k6NthfY6A6kXmPZK4r90WMXSWTerFk+G2jGadSlPI/fg7Ur9Vs4odIPMnO/PddRDdS0aYEL6oV3mcTEEvmpsIOa+ma/ET4m6bt8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 15:41:15.9352 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 194f5090-d51b-4705-01d6-08db20b4b83b 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: DM6NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4082 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: uWIKHQtD5RyWKHiO98rAhx3fx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678376478; bh=wS7d2bUJhYokv8ycqcU1g/UyDJ3kNgZXhWUhDyNs3f4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=lP8yWFwKD6DzlhnygUcnNY6xqkr9sc4cIixER5Kzt6YP1rieXVg7PYcgJrPISTVYIUj lqWNIpVFklOSTvGLEr4aZsMLOgCJ75b2oa5AS9Cw9IX5+jKbdCwY6kwTD6hd4GNzWdzH9 2nq1/KId80hELOlM/lCi0buEUk43OihYsAM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678376480329100006 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 (#100953): https://edk2.groups.io/g/devel/message/100953 Mute This Topic: https://groups.io/mt/97498500/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 Mon May 6 21:37:16 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+100954+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 1678376485122237.68840296332326; Thu, 9 Mar 2023 07:41:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 82CxYY1788612x07boFYT4Au; Thu, 09 Mar 2023 07:41:24 -0800 X-Received: from NAM02-DM3-obe.outbound.protection.outlook.com (NAM02-DM3-obe.outbound.protection.outlook.com [40.107.95.77]) by mx.groups.io with SMTP id smtpd.web11.16697.1678376483398554742 for ; Thu, 09 Mar 2023 07:41:23 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j3e7v7nQYFE1PaIwQ2/Ir91t1TVE+bmP8NvKTN+9IM1G8hMdBAM626fhZAnztl7VdVXI0UDMEWK4+58mm7QRDCYSQ43CBtr0B8TVwLHhOKy0HZvfHRKiPt8+LifWx3Y3eh5TZSQpbKYg19zG1vOCkluCCJMDqocjrFk8a42oDlOU3UTKRAJiZ+RFbg4xhrUeev4f9D94DxlU8s9PtRN7zYCRD9ibLZU/y3D8WWeTYJcFKUa6msEaZBJ6W21U089kXjXMk81kufQpWzA2bDJtDv5xtbimnEokEMh+iKT2PXZBGKObrOV80ZRjCYZtSM+hcjyU0pOyM0aKQuUyjtfdvQ== 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=h1CI4s+3WnHcbUKHuzX41xKUvLT6fzHtHhfW4wtc6lI=; b=OhZuiYFTJPudh+KaMPLRn3FhDoaF3d+IvqZsFRs+C/qk5izu6/P/kSOh+u9NN+sh8+RbzmO6gAFmAYTuwT5EUofaxwArp+pvTOWC5L0HrQPsC1f9shx6COb5C444PDAPC+xG6BPB1GL5prryaLsqs88c89GEc0hUjaoLA0Y3Bj7nqF42JUOJTHVv/xvttkAabLZuaCdqBfHySpXB6h7n8S1YMjImHzrXMacKU5ioEh8ilJbdzwwsCIYZ1SmlDApKaSO0yqBek3roeT7fuU/TXesDL1J13u5ROT3HBUQSjxbuW6h74sjr3W23rMBB0FQuWkvLq2qaBRr9xlHqU/6aMg== 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 DS7PR05CA0024.namprd05.prod.outlook.com (2603:10b6:5:3b9::29) by SJ2PR12MB8111.namprd12.prod.outlook.com (2603:10b6:a03:4fe::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29; Thu, 9 Mar 2023 15:41:18 +0000 X-Received: from DM6NAM11FT094.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b9:cafe::33) by DS7PR05CA0024.outlook.office365.com (2603:10b6:5:3b9::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.19 via Frontend Transport; Thu, 9 Mar 2023 15:41:18 +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+100954+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 DM6NAM11FT094.mail.protection.outlook.com (10.13.172.195) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.19 via Frontend Transport; Thu, 9 Mar 2023 15:41:18 +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; Thu, 9 Mar 2023 09:41:15 -0600 From: "Chang, Abner via groups.io" To: CC: Nickle Wang , Igor Kulchytskyy Subject: [edk2-devel] [PATCH 3/3] RedfishPkg: Update Readme.md Date: Thu, 9 Mar 2023 23:40:55 +0800 Message-ID: <20230309154055.505-4-abner.chang@amd.com> In-Reply-To: <20230309154055.505-1-abner.chang@amd.com> References: <20230309154055.505-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: DM6NAM11FT094:EE_|SJ2PR12MB8111:EE_ X-MS-Office365-Filtering-Correlation-Id: 0fa50429-c8cd-436d-6efe-08db20b4b986 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: eZDGdE5VkNtVWB9mcqsfnF6Qdq3woueZjOh0l2qic4jKrZ0E0LmW1mUH628NJSlHznrPsIkBGwXgV63BNFhS3PKau5g8P+AXgz8xs0FWWixvU0AR6LRcITz/ra7ATfGXK2D6rs+pITq7wliyyGFXKOwlMmufsdy13hgt0OyKs+ZRZtKVr5zemwOKnETPjgpiVUHRcH7fUKYacKKnY9P5c4iNwD5YMOXYmmoVWsMcADGMlNnpoOvIrTRv0HpJFfO88d2NWCxC/7FVQm5RYSsaAqKYqMKdPvFTVRBAoIPww+R6g/xb4PqOc1fIr27ZVXz3PkpoyQ4isi/kr7ZsLZWsfVGwGoH+xrLkK8kdZWfajQR44P9h9d+zBqA9rWt2oNKhp0GhepQb1PHnAlBLsVrZFXXP1SjObZW9UgSalPnxOngppqIqJ3ZUlozwJ1LjvD13KnUJsJtikmzdmuqao2W/reaP/EH8Ul/RLQG8FaSQgurSpeB4zfZlow1XrTbvEaP9SYnIqU2l9436aBk1jbwhimN0kIq1KtFaWNT0A3MSzMQ0v4rE4D6RLuTIHYgjvjLbZgVzke+Ms6aD1y4TV66HmWWct8isEUlYw66+xISSqYFa8ZAflYvWSZt5r2rWbO6kJyGNIWyvuxM32u9S0u0ckHnyjBWeqiXJ3uRoDrJx3/Y9K3du6emAZdIFx4YLyO4E1W+WCDX3f6kheauZ8CMV21tdMj4p79p5tOr43iei7mW8wHnA17nX9EqcnZB8ZZjsGsUDaDT9glrbDjRlUjXFHHYsM4QYXTTsXvu5/VshPrfjJNA4GhgfFwhKKTdY7ZWUjKWUQV9e9VzXoea/FxztWw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2023 15:41:18.0917 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0fa50429-c8cd-436d-6efe-08db20b4b986 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: DM6NAM11FT094.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8111 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: xLETDkF3Fc95LrVVjCqXlaN0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678376484; bh=aDzWaooIDE7sTkpK6rJxzqATu3wa8OC8WL519uKJJcs=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=JKhtpmwS1clEwmBcZCvir+DT4IUCCfaVpn1QIZH6AiF7odtYm+ic9DlfUawC2YzYD1a EEptB2KBamf4oNYKQJYZRPd9DBpurP1o5G1oaclrf8vQPwU1I/3gMzn7VpULgIsY0XmGu OS70m/1lSISpK4X8Jws2hDi5YkZBIOqUwCU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678376486655100002 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 (#100954): https://edk2.groups.io/g/devel/message/100954 Mute This Topic: https://groups.io/mt/97498502/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-