From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.47]) by mx.groups.io with SMTP id smtpd.web10.2725.1681802188403058775 for ; Tue, 18 Apr 2023 00:16:28 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=VllCReDH; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.220.47, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sr9mNAcX27uJVsmz7DgfqSIkq9QLYO5Sde8TbByVNYtHPXNuU1L+PkWm5yJqH937LiT9KYb/RfwoZm55Y5lwSgUrm4bZkQrxAwT5e4sy7NduddGX/FikHdCv1t9fNmHYvQxVumJPrQPOcGFdIZ+9aL5v8mUti3ArFvmV/+o39euFsl+BLZPgzRcOHK/GnfwkNVxusoWv6zqB4sDB2IW0QgILEminzsoQrZf1RiXZ/wXeHiT580PFFABxZwNQKoOX+d+Ue7VkXf92UdZRRGW0VnQSHloKtyz4FcQyeOymYSE5o3vOFxD41VKJay/5HxIF45wgdwlVQBHem8ykMI470A== 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=okebGsx0oDq79XkmFMJjyyvecPgSzX+ciqLeXptevhw=; b=nEFgEIyt2hIHEMFaZCI7nDunboDlD4eehVbOy4z5YMWCPgwoWHKniQX9aCuVVsLR+e2OSiRPYVsEWBjlXEouVjWMQbShdy/2ABbsZR1X6tVrJiwS3e8wDdkVAS0KbyvtQN3XxNoLewTu2XoVIBMfKWrfJLHxFWxXwiSk6SB7T/G2ihUhTrihI/gmSrq6LE4Uimj3InuwJ/bDbel4Qt+1C3GkabPvO/uSsltGhGA0vj3GBxJpblqJ9J1xsbw8gA7lyg0I3zND4ktixmcBVOv0OV/+sjxGdVkdVNy7VMbp1ufa/JI1g1XZzQHR2KmMzr2ou4Lc3+xoB7J4RdQiecKnkA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=okebGsx0oDq79XkmFMJjyyvecPgSzX+ciqLeXptevhw=; b=VllCReDHL+BzQByH09qox2MxuvRXY7UtTf8zzCHq4YyW6XNf2VC//3mowWJV1jxx7zNU23gCRnOsST7bZ/6CxK2XU6u32bvrADuedoxye0sqcBSTe3UFcuoKsoFHEzfDKGR9kkfGIYiTrDCs7JTr9cfogs3F75m5gYghL/W6lrQ= Received: from DM6PR02CA0152.namprd02.prod.outlook.com (2603:10b6:5:332::19) by BL0PR12MB4849.namprd12.prod.outlook.com (2603:10b6:208:1c2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.20; Tue, 18 Apr 2023 07:16:23 +0000 Received: from DM6NAM11FT006.eop-nam11.prod.protection.outlook.com (2603:10b6:5:332:cafe::36) by DM6PR02CA0152.outlook.office365.com (2603:10b6:5:332::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.46 via Frontend Transport; Tue, 18 Apr 2023 07:16:23 +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 (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 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT006.mail.protection.outlook.com (10.13.173.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.20 via Frontend Transport; Tue, 18 Apr 2023 07:16:22 +0000 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; Tue, 18 Apr 2023 02:16:20 -0500 From: "Chang, Abner" To: CC: Isaac Oram , Abdul Lateef Attar , Nickle Wang , Igor Kulchytskyy Subject: [edk2-platforms][PATCH V2 09/14] ManageabilityPkg/MctpProtocol: Add MctpProtocol Date: Tue, 18 Apr 2023 15:15:38 +0800 Message-ID: <20230418071543.1951-10-abner.chang@amd.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20230418071543.1951-1-abner.chang@amd.com> References: <20230418071543.1951-1-abner.chang@amd.com> MIME-Version: 1.0 Return-Path: Abner.Chang@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT006:EE_|BL0PR12MB4849:EE_ X-MS-Office365-Filtering-Correlation-Id: d142dc1d-c6a5-4890-24ef-08db3fdcd0bf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sDls05ecy84RMq0dqWcAXUBPstAsyH+kHBgD7WvdpDuEQvCptWJZQRvf6Hx6bNYZcBX2TflMJWWzdnoWJtnLm0jh0ycP2uqj6jHHN1iyQ7QJ6F3AtiKPmu1hzIaleKmJ2j9WEOMoZu0NyB+bEl3wo6MGhqdYGW7UXO028yHJ3k8+AdecHnredzgAZ2Q1mYrp+Y5ASSYr7Iijxhwwg2wOjrZ6+3hp0n4OqjdXk/39HD4QjECB/+DwZ+zKR6b8bH1yqWoZgfvdLRLL1z9Qu/CXFg/20gVuzHQE290yYqiTI7zSmRRp9avT7fZ2SK11FS54nDW8cj3RHxIcUCMfYvD/zAkTRUTRbBfjVjlU9kX2rb3W53Vqoy9x1xc62Y4vnC2k8GrctyY6mEvRLqaISYBtR0eBLUQIVJuQQKjmD8RE9tSiST0P3AzRVyWHC+wvz22fUhlJ8x+8bHMtJHFJVVAQXCdfWjZgNXS60craPhvRCWVyHQRenSCuBbMOktKlT+tYQ9FsYvpdmDNGXtXyxTJlceqEREOY+Ep8t09qNW22PL9NJQcTNocg8hGkCeeRPhdUAqQ2p4yLD1FoY76mKF6Xiuikw0Zm5tucyjJfCA/qSEwgpd4r8FE9sGmCSLT5CDW3aVtVl9E9wZC8tgEyrJgLTkr5fK4IVBW8uFpg87O1Mcg35JXscqoyI0cYvYhysFltXvl57PfNjANdqkDt8UrDeZgCgdnAETPzTBPlxjA2dO8ArzgNStT75/yApwTlKskL/vvvzopiSQM1FgMogmvFQw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(136003)(346002)(396003)(39860400002)(451199021)(40470700004)(36840700001)(46966006)(2906002)(40460700003)(2876002)(30864003)(8936002)(8676002)(41300700001)(82740400003)(81166007)(356005)(5660300002)(82310400005)(36756003)(86362001)(40480700001)(478600001)(54906003)(36860700001)(2616005)(1076003)(26005)(6666004)(16526019)(186003)(7696005)(70586007)(70206006)(47076005)(4326008)(6916009)(83380400001)(316002)(19627235002)(426003)(336012)(36900700001)(579004)(44824005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2023 07:16:22.9818 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d142dc1d-c6a5-4890-24ef-08db3fdcd0bf 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: DM6NAM11FT006.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4849 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Abner Chang MctpProtocol that transmits MCTP message over manageability transport interface library. Signed-off-by: Abner Chang Cc: Isaac Oram Cc: Abdul Lateef Attar Cc: Nickle Wang Cc: Igor Kulchytskyy --- .../Include/Dsc/Manageability.dsc | 1 + .../MctpProtocol/Dxe/MctpProtocolDxe.inf | 53 ++ .../Include/Protocol/MctpProtocol.h | 102 ++++ .../MctpProtocol/Common/MctpProtocolCommon.h | 139 ++++++ .../MctpProtocol/Common/MctpProtocolCommon.c | 472 ++++++++++++++++++ .../Universal/MctpProtocol/Dxe/MctpProtocol.c | 218 ++++++++ 6 files changed, 985 insertions(+) create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/Mc= tpProtocolDxe.inf create mode 100644 Features/ManageabilityPkg/Include/Protocol/MctpProtocol= .h create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Common= /MctpProtocolCommon.h create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Common= /MctpProtocolCommon.c create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/Mc= tpProtocol.c diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Feat= ures/ManageabilityPkg/Include/Dsc/Manageability.dsc index 2a354ad898..17f067c6d0 100644 --- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc +++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc @@ -33,4 +33,5 @@ [Components.X64] ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.i= nf + ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf =20 diff --git a/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProto= colDxe.inf b/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProto= colDxe.inf new file mode 100644 index 0000000000..483fbcc04b --- /dev/null +++ b/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.= inf @@ -0,0 +1,53 @@ +## @file +# MCTP Protocol DXE Driver. +# +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001d + BASE_NAME =3D MctpDxe + FILE_GUID =3D 58AF169A-AA3F-462B-B0F1-25FBE6C97978 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D DxeMctpEntry + UNLOAD_IMAGE =3D MctpUnloadImage + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# + +[Sources] + MctpProtocol.c + ../Common/MctpProtocolCommon.c + ../Common/MctpProtocolCommon.h + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ManageabilityPkg/ManageabilityPkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + MemoryAllocationLib + ManageabilityTransportHelperLib + ManageabilityTransportLib + UefiDriverEntryPoint + UefiBootServicesTableLib + +[Guids] + gManageabilityProtocolMctpGuid + +[Protocols] + gEdkiiMctpProtocolGuid + +[FixedPcd] + gManageabilityPkgTokenSpaceGuid.PcdMctpKcsMemoryMappedIo + gManageabilityPkgTokenSpaceGuid.PcdMctpKcsBaseAddress + gManageabilityPkgTokenSpaceGuid.PcdMctpSourceEndpointId + gManageabilityPkgTokenSpaceGuid.PcdMctpDestinationEndpointId + +[Depex] + TRUE diff --git a/Features/ManageabilityPkg/Include/Protocol/MctpProtocol.h b/Fe= atures/ManageabilityPkg/Include/Protocol/MctpProtocol.h new file mode 100644 index 0000000000..85e42f157d --- /dev/null +++ b/Features/ManageabilityPkg/Include/Protocol/MctpProtocol.h @@ -0,0 +1,102 @@ +/** @file + Protocol of EDKII MCTP Protocol. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EDKII_MCTP_PROTOCOL_H_ +#define EDKII_MCTP_PROTOCOL_H_ + +#include + +typedef struct _EDKII_MCTP_PROTOCOL EDKII_MCTP_PROTOCOL; + +#define EDKII_MCTP_PROTOCOL_GUID \ + { \ + 0xE93465C1, 0x9A31, 0x4C96, 0x92, 0x56, 0x22, 0x0A, 0xE1, 0x80, 0xB4, = 0x1B \ + } + +#define EDKII_MCTP_PROTOCOL_VERSION_MAJOR 1 +#define EDKII_MCTP_PROTOCOL_VERSION_MINOR 0 +#define EDKII_MCTP_PROTOCOL_VERSION ((EDKII_MCTP_PROTOCOL_VERSION_M= AJOR << 8) |\ + EDKII_MCTP_PROTOCOL_VERSION_MINOR) + +/** + This service enables submitting message via EDKII MCTP protocol. + + @param[in] This EDKII_MCTP_PROTOCOL instan= ce. + @param[in] MctpType MCTP message type. + @param[in] MctpSourceEndpointId MCTP source endpoint ID. + @param[in] MctpDestinationEndpointId MCTP source endpoint ID. + @param[in] RequestDataIntegrityCheck Indicates whether MCTP mes= sage has + integrity check byte. + @param[in] RequestData Message Data. + @param[in] RequestDataSize Size of message Data. + @param[in] RequestTimeout Timeout value in milliseco= nds. + MANAGEABILITY_TRANSPORT_NO= _TIMEOUT means no timeout value. + @param[out] ResponseData Message Response Data. The= completion code is the first byte of response data. + @param[in, out] ResponseDataSize Size of Message Response D= ata. + @param[in] ResponseTimeout Timeout value in milliseco= nds. + MANAGEABILITY_TRANSPORT_NO= _TIMEOUT means no timeout value. + @param[out] AdditionalTransferError MANAGEABILITY_TRANSPORT_AD= DITIONAL_STATUS. + + @retval EFI_SUCCESS The message was successfully send to tran= sport interface and a + response was successfully received. + @retval EFI_NOT_FOUND The message was not successfully sent to = transport interface or a response + was not successfully received from transp= ort interface. + @retval EFI_NOT_READY MCTP transport interface is not ready for= MCTP message. + @retval EFI_DEVICE_ERROR MCTP transport interface Device hardware = error. + @retval EFI_TIMEOUT The message time out. + @retval EFI_UNSUPPORTED The message was not successfully sent to = the transport interface. + @retval EFI_OUT_OF_RESOURCES The resource allocation is out of resourc= e or data size error. + @retval EFI_INVALID_PARAMETER Both RequestData and ResponseData are NUL= L +**/ +typedef +EFI_STATUS +(EFIAPI *MCTP_SUBMIT_COMMAND)( + IN EDKII_MCTP_PROTOCOL *This, + IN UINT8 MctpType, + IN UINT8 MctpSourceEndpointId, + IN UINT8 MctpDestinationEndpointId, + IN BOOLEAN RequestDataIntegrityCheck, + IN UINT8 *RequestData, + IN UINT32 RequestDataSize, + IN UINT32 RequestTimeout, + OUT UINT8 *ResponseData, + IN OUT UINT32 *ResponseDataSize, + IN UINT32 ResponseTimeout, + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *AdditionalTransferErro= r + ); + +// +// EDKII_MCTP_PROTOCOL Version 1.0 +// +typedef struct { + MCTP_SUBMIT_COMMAND MctpSubmitCommand; +} EDKII_MCTP_PROTOCOL_V1_0; + +/// +/// Definitions of EDKII_MCTP_PROTOCOL. +/// This is a union that can accommodate the new functionalities defined +/// in MCTP Base specification in the future. +/// The new added function must has its own EDKII_MCTP_PROTOCOL +/// structure with the incremental version number. +/// e.g., EDKII_MCTP_PROTOCOL_V1_1. +/// +/// The new function must be added base on the last version of +/// EDKII_MCTP_PROTOCOL to keep the backward compatibility. +/// +typedef union { + EDKII_MCTP_PROTOCOL_V1_0 *Version1_0; +} EDKII_MCTP_PROTOCOL_FUNCTION; + +struct _EDKII_MCTP_PROTOCOL { + UINT16 ProtocolVersion; + EDKII_MCTP_PROTOCOL_FUNCTION Functions; +}; + +extern EFI_GUID gEdkiiMctpProtocolGuid; + +#endif // EDKII_MCTP_PROTOCOL_H_ diff --git a/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpPr= otocolCommon.h b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/Mc= tpProtocolCommon.h new file mode 100644 index 0000000000..72eded719d --- /dev/null +++ b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolC= ommon.h @@ -0,0 +1,139 @@ +/** @file + MCTP Manageability Protocol common header file. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MANAGEABILITY_MCTP_COMMON_H_ +#define MANAGEABILITY_MCTP_COMMON_H_ + +#include +#include + +#define MCTP_KCS_BASE_ADDRESS PcdGet32(PcdMctpKcsBaseAddress) + +// For I/O mapped I/O +#define MCTP_KCS_REG_DATA_IN_IO MCTP_KCS_BASE_ADDRESS + IPMI_KCS_DATA_IN= _REGISTER_OFFSET +#define MCTP_KCS_REG_DATA_OUT_IO MCTP_KCS_BASE_ADDRESS + IPMI_KCS_DATA_OU= T_REGISTER_OFFSET +#define MCTP_KCS_REG_COMMAND_IO MCTP_KCS_BASE_ADDRESS + IPMI_KCS_COMMAND= _REGISTER_OFFSET +#define MCTP_KCS_REG_STATUS_IO MCTP_KCS_BASE_ADDRESS + IPMI_KCS_STATUS_= REGISTER_OFFSET + +// For memory mapped I/O +#define MCTP_KCS_REG_DATA_IN_MEMMAP MCTP_KCS_BASE_ADDRESS + (IPMI_KCS_DA= TA_IN_REGISTER_OFFSET * 4) +#define MCTP_KCS_REG_DATA_OUT_MEMMAP MCTP_KCS_BASE_ADDRESS + (IPMI_KCS_DA= TA_OUT_REGISTER_OFFSET * 4) +#define MCTP_KCS_REG_COMMAND_MEMMAP MCTP_KCS_BASE_ADDRESS + (IPMI_KCS_CO= MMAND_REGISTER_OFFSET * 4) +#define MCTP_KCS_REG_STATUS_MEMMAP MCTP_KCS_BASE_ADDRESS + (IPMI_KCS_ST= ATUS_REGISTER_OFFSET * 4) + +/** + This functions setup the PLDM transport hardware information according + to the specification of transport token acquired from transport library. + + @param[in] TransportToken The transport interface. + @param[out] HardwareInformation Pointer to receive the hardware = information. + + @retval EFI_SUCCESS Hardware information is returned in Hardw= areInformation. + Caller must free the memory allocated for= HardwareInformation + once it doesn't need it. + @retval EFI_UNSUPPORTED No hardware information for the specifica= tion specified + in the transport token. +**/ +EFI_STATUS +SetupMctpTransportHardwareInformation ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + OUT MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION *HardwareInformation + ); + +/** + This functions setup the final header/body/trailer packets for + the acquired transport interface. + + @param[in] TransportToken The transport interface. + @param[in] MctpType MCTP message type. + @param[in] MctpSourceEndpointId MCTP source endpoint ID. + @param[in] MctpDestinationEndpointId MCTP source endpoint ID. + @param[in] RequestDataIntegrityCheck Indicates whether MCTP mes= sage has + integrity check byte. + @param[out] PacketHeader The pointer to receive hea= der of request. + @param[out] PacketHeaderSize Packet header size. + @param[in, out] PacketBody The request body. + When IN, it is the caller'= s request body. + When OUT and NULL, the req= uest body is not + changed. + Whee out and non-NULL, the= request body is + changed to comfort the tra= nsport interface. + @param[in, out] PacketBodySize The request body size. + When IN and non-zero, it i= s the new data + length of request body. + When IN and zero, the requ= est body is unchanged. + @param[out] PacketTrailer The pointer to receive tra= iler of request. + @param[out] PacketTrailerSize Packet trailer size. + + @retval EFI_SUCCESS Request packet is returned. + @retval EFI_OUT_OF_RESOURCE Not enough resource to create the request + transport packets. + @retval EFI_UNSUPPORTED Request packet is not returned because + the unsupported transport interface. +**/ +EFI_STATUS +SetupMctpRequestTransportPacket ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + IN UINT8 MctpType, + IN UINT8 MctpSourceEndpointId, + IN UINT8 MctpDestinationEndpointId, + IN BOOLEAN RequestDataIntegrityCheck, + OUT MANAGEABILITY_TRANSPORT_HEADER *PacketHeader, + OUT UINT16 *PacketHeaderSize, + IN OUT UINT8 **PacketBody, + IN OUT UINT32 *PacketBodySize, + OUT MANAGEABILITY_TRANSPORT_TRAILER *PacketTrailer, + OUT UINT16 *PacketTrailerSize + ); + +/** + Common code to submit MCTP message + + @param[in] TransportToken Transport token. + @param[in] MctpType MCTP message type. + @param[in] MctpSourceEndpointId MCTP source endpoint ID. + @param[in] MctpDestinationEndpointId MCTP source endpoint ID. + @param[in] RequestDataIntegrityCheck Indicates whether MCTP mes= sage has + integrity check byte. + @param[in] RequestData Message Data. + @param[in] RequestDataSize Size of message Data. + @param[in] RequestTimeout Timeout value in milliseco= nds. + MANAGEABILITY_TRANSPORT_NO= _TIMEOUT means no timeout value. + @param[out] ResponseData Message Response Data. The= completion code is the first byte of response data. + @param[in, out] ResponseDataSize Size of Message Response D= ata. + @param[in] ResponseTimeout Timeout value in milliseco= nds. + MANAGEABILITY_TRANSPORT_NO= _TIMEOUT means no timeout value. + @param[out] AdditionalTransferError MANAGEABILITY_TRANSPORT_AD= DITIONAL_STATUS. + + @retval EFI_SUCCESS The message was successfully send to tran= sport interface and a + response was successfully received. + @retval EFI_NOT_FOUND The message was not successfully sent to = transport interface or a response + was not successfully received from transp= ort interface. + @retval EFI_NOT_READY MCTP transport interface is not ready for= MCTP message. + @retval EFI_DEVICE_ERROR MCTP transport interface Device hardware = error. + @retval EFI_TIMEOUT The message time out. + @retval EFI_UNSUPPORTED The message was not successfully sent to = the transport interface. + @retval EFI_OUT_OF_RESOURCES The resource allocation is out of resourc= e or data size error. + @retval EFI_INVALID_PARAMETER Both RequestData and ResponseData are NUL= L +**/ +EFI_STATUS +CommonMctpSubmitMessage ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + IN UINT8 MctpType, + IN UINT8 MctpSourceEndpointId, + IN UINT8 MctpDestinationEndpoin= tId, + IN BOOLEAN RequestDataIntegrityCh= eck, + IN UINT8 *RequestData, + IN UINT32 RequestDataSize, + IN UINT32 RequestTimeout, + OUT UINT8 *ResponseData, + IN OUT UINT32 *ResponseDataSize, + IN UINT32 ResponseTimeout, + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *AdditionalTransferErr= or + ); + +#endif diff --git a/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpPr= otocolCommon.c b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/Mc= tpProtocolCommon.c new file mode 100644 index 0000000000..8babdfe963 --- /dev/null +++ b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolC= ommon.c @@ -0,0 +1,472 @@ +/** @file + + MCTP Manageability Protocol common file. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "MctpProtocolCommon.h" + +extern CHAR16 *mTransportName; +extern UINT32 mTransportMaximumPayload; + +MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION mHardwareInformation; +UINT8 mMctpPacketSequence; +BOOLEAN mStartOfMessage; +BOOLEAN mEndOfMessage; + +/** + This functions setup the MCTP transport hardware information according + to the specification of transport token acquired from transport library. + + @param[in] TransportToken The transport interface. + @param[out] HardwareInformation Pointer to receive the hardware = information. + + @retval EFI_SUCCESS Hardware information is returned in Hardw= areInformation. + Caller must free the memory allocated for= HardwareInformation + once it doesn't need it. + @retval EFI_UNSUPPORTED No hardware information for the specifica= tion specified + in the transport token. +**/ +EFI_STATUS +SetupMctpTransportHardwareInformation ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + OUT MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION *HardwareInformation + ) +{ + MANAGEABILITY_TRANSPORT_KCS_HARDWARE_INFO *KcsHardwareInfo; + BOOLEAN MctpKcsMemMapIo; + + KcsHardwareInfo =3D NULL; + if (CompareGuid (&gManageabilityTransportKcsGuid, TransportToken->Transp= ort->ManageabilityTransportSpecification)) { + KcsHardwareInfo =3D AllocatePool (sizeof (MANAGEABILITY_TRANSPORT_KCS_= HARDWARE_INFO)); + if (KcsHardwareInfo =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Not enough memory for MANAGEABILITY_TRANSP= ORT_KCS_HARDWARE_INFO.\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + MctpKcsMemMapIo =3D PcdGetBool (PcdMctpKcsMemoryMappedIo); + if (MctpKcsMemMapIo) { + KcsHardwareInfo->MemoryMap =3D MANAGEABILITY_TRAN= SPORT_KCS_MEMORY_MAP_IO; + KcsHardwareInfo->IoBaseAddress.IoAddress32 =3D MCTP_KCS_BASE_ADDR= ESS; + KcsHardwareInfo->IoDataInAddress.IoAddress32 =3D MCTP_KCS_REG_DATA_= IN_MEMMAP; + KcsHardwareInfo->IoDataOutAddress.IoAddress32 =3D MCTP_KCS_REG_DATA_= OUT_MEMMAP; + KcsHardwareInfo->IoCommandAddress.IoAddress32 =3D MCTP_KCS_REG_COMMA= ND_MEMMAP; + KcsHardwareInfo->IoStatusAddress.IoAddress32 =3D MCTP_KCS_REG_STATU= S_MEMMAP; + } else { + KcsHardwareInfo->MemoryMap =3D MANAGEABILITY_TRAN= SPORT_KCS_IO_MAP_IO; + KcsHardwareInfo->IoBaseAddress.IoAddress16 =3D (UINT16)MCTP_KCS_B= ASE_ADDRESS; + KcsHardwareInfo->IoDataInAddress.IoAddress16 =3D (UINT16)MCTP_KCS_R= EG_DATA_IN_IO; + KcsHardwareInfo->IoDataOutAddress.IoAddress16 =3D (UINT16)MCTP_KCS_R= EG_DATA_OUT_IO; + KcsHardwareInfo->IoCommandAddress.IoAddress16 =3D (UINT16)MCTP_KCS_R= EG_COMMAND_IO; + KcsHardwareInfo->IoStatusAddress.IoAddress16 =3D (UINT16)MCTP_KCS_R= EG_STATUS_IO; + } + + HardwareInformation->Kcs =3D KcsHardwareInfo; + return EFI_SUCCESS; + } else { + DEBUG ((DEBUG_ERROR, "%a: No implementation of setting hardware inform= ation.", __FUNCTION__)); + ASSERT (FALSE); + } + + return EFI_UNSUPPORTED; +} + +/** + This functions setup the final header/body/trailer packets for + the acquired transport interface. + + @param[in] TransportToken The transport interface. + @param[in] MctpType MCTP message type. + @param[in] MctpSourceEndpointId MCTP source endpoint ID. + @param[in] MctpDestinationEndpointId MCTP source endpoint ID. + @param[in] RequestDataIntegrityCheck Indicates whether MCTP mes= sage has + integrity check byte. + @param[out] PacketHeader The pointer to receive hea= der of request. + @param[out] PacketHeaderSize Packet header size. + @param[in, out] PacketBody The request body. + When IN, it is the caller'= s request body. + When OUT and NULL, the req= uest body is not + changed. + Whee out and non-NULL, the= request body is + changed to comfort the tra= nsport interface. + @param[in, out] PacketBodySize The request body size. + When IN and non-zero, it i= s the new data + length of request body. + When IN and zero, the requ= est body is unchanged. + @param[out] PacketTrailer The pointer to receive tra= iler of request. + @param[out] PacketTrailerSize Packet trailer size. + + @retval EFI_SUCCESS Request packet is returned. + @retval EFI_OUT_OF_RESOURCE Not enough resource to create the request + transport packets. + @retval EFI_UNSUPPORTED Request packet is not returned because + the unsupported transport interface. +**/ +EFI_STATUS +SetupMctpRequestTransportPacket ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + IN UINT8 MctpType, + IN UINT8 MctpSourceEndpointId, + IN UINT8 MctpDestinationEndpointId, + IN BOOLEAN RequestDataIntegrityCheck, + OUT MANAGEABILITY_TRANSPORT_HEADER *PacketHeader, + OUT UINT16 *PacketHeaderSize, + IN OUT UINT8 **PacketBody, + IN OUT UINT32 *PacketBodySize, + OUT MANAGEABILITY_TRANSPORT_TRAILER *PacketTrailer, + OUT UINT16 *PacketTrailerSize + ) +{ + MANAGEABILITY_MCTP_KCS_HEADER *MctpKcsHeader; + MCTP_TRANSPORT_HEADER *MctpTransportHeader; + MCTP_MESSAGE_HEADER *MctpMessageHeader; + UINT8 *Pec; + UINT8 *ThisPackage; + + if ((PacketHeader =3D=3D NULL) || (PacketHeaderSize =3D=3D NULL) || + (PacketBody =3D=3D NULL) || (PacketBodySize =3D=3D NULL) || + (PacketTrailer =3D=3D NULL) || (PacketTrailerSize =3D=3D NULL) + ) + { + DEBUG ((DEBUG_ERROR, "%a: One or more than one of the input parameter = is invalid.\n")); + return EFI_INVALID_PARAMETER; + } + + if (CompareGuid (&gManageabilityTransportKcsGuid, TransportToken->Transp= ort->ManageabilityTransportSpecification)) { + MctpKcsHeader =3D (MANAGEABILITY_MCTP_KCS_HEADER *)AllocateZeroPool (s= izeof (MANAGEABILITY_MCTP_KCS_HEADER)); + if (MctpKcsHeader =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Not enough resource for MANAGEABILITY_MCTP= _KCS_HEADER.\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + Pec =3D (UINT8 *)AllocateZeroPool (sizeof (UINT8)); + if (Pec =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Not enough resource for PEC.\n", __FUNCTIO= N__)); + FreePool (MctpKcsHeader); + return EFI_OUT_OF_RESOURCES; + } + + // Generate MCTP KCS transport header + MctpKcsHeader->DefiningBody =3D DEFINING_BODY_DMTF_PRE_OS_WORKING_GROU= P; + MctpKcsHeader->NetFunc =3D MCTP_KCS_NETFN_LUN; + MctpKcsHeader->ByteCount =3D (UINT8)(MIN (mTransportMaximumPayload,= *PacketBodySize + (UINT8)sizeof (MCTP_MESSAGE_HEADER) + (UINT8)sizeof (MCT= P_TRANSPORT_HEADER))); + + ThisPackage =3D (UINT8 *)AllocateZeroPool (MctpKcsHeader->ByteCount); + if (ThisPackage =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Not enough resource for package.\n", __FUN= CTION__)); + FreePool (MctpKcsHeader); + FreePool (Pec); + return EFI_OUT_OF_RESOURCES; + } + + // Setup MCTP transport header + MctpTransportHeader =3D (MCTP_TRANSPORT_HE= ADER *)ThisPackage; + MctpTransportHeader->Bits.Reserved =3D 0; + MctpTransportHeader->Bits.HeaderVersion =3D MCTP_KCS_HEADER_VE= RSION; + MctpTransportHeader->Bits.DestinationEndpointId =3D PcdGet8 (PcdMctpDe= stinationEndpointId); + MctpTransportHeader->Bits.SourceEndpointIdId =3D PcdGet8 (PcdMctpSo= urceEndpointId); + MctpTransportHeader->Bits.MessageTag =3D MCTP_MESSAGE_TAG; + MctpTransportHeader->Bits.TagOwner =3D MCTP_MESSAGE_TAG_O= WNER_REQUEST; + MctpTransportHeader->Bits.PacketSequence =3D mMctpPacketSequenc= e & MCTP_PACKET_SEQUENCE_MASK; + MctpTransportHeader->Bits.StartOfMessage =3D mStartOfMessage ? = 1 : 0; + MctpTransportHeader->Bits.EndOfMessage =3D mEndOfMessage ? 1 = : 0; + + // Setup MCTP message header + MctpMessageHeader =3D (MCTP_MESSAGE_HEADER *)(Mct= pTransportHeader + 1); + MctpMessageHeader->Bits.MessageType =3D MctpType; + MctpMessageHeader->Bits.IntegrityCheck =3D RequestDataIntegrityCheck ?= 1 : 0; + + // Copy payload + CopyMem ((VOID *)(MctpMessageHeader + 1), (VOID *)*PacketBody, *Packet= BodySize); + + // + // Generate PEC follow SMBUS 2.0 specification. + *Pec =3D HelperManageabilityGenerateCrc8 (MCTP_KCS_PACKET_ERROR_CODE_P= OLY, 0, ThisPackage, MctpKcsHeader->ByteCount); + + *PacketBody =3D (UINT8 *)ThisPackage; + *PacketBodySize =3D MctpKcsHeader->ByteCount; + *PacketTrailer =3D (MANAGEABILITY_TRANSPORT_TRAILER)Pec; + *PacketHeader =3D (MANAGEABILITY_TRANSPORT_HEADER)MctpKcsHeader; + *PacketHeaderSize =3D sizeof (MANAGEABILITY_MCTP_KCS_HEADER); + *PacketTrailerSize =3D 1; + return EFI_SUCCESS; + } else { + DEBUG ((DEBUG_ERROR, "%a: No implementation of building up packet.", _= _FUNCTION__)); + ASSERT (FALSE); + } + + return EFI_SUCCESS; +} + +/** + Common code to submit MCTP message + + @param[in] TransportToken Transport token. + @param[in] MctpType MCTP message type. + @param[in] MctpSourceEndpointId MCTP source endpoint ID. + @param[in] MctpDestinationEndpointId MCTP source endpoint ID. + @param[in] RequestDataIntegrityCheck Indicates whether MCTP mes= sage has + integrity check byte. + @param[in] RequestData Message Data. + @param[in] RequestDataSize Size of message Data. + @param[in] RequestTimeout Timeout value in milliseco= nds. + MANAGEABILITY_TRANSPORT_NO= _TIMEOUT means no timeout value. + @param[out] ResponseData Message Response Data. The= completion code is the first byte of response data. + @param[in, out] ResponseDataSize Size of Message Response D= ata. + @param[in] ResponseTimeout Timeout value in milliseco= nds. + MANAGEABILITY_TRANSPORT_NO= _TIMEOUT means no timeout value. + @param[out] AdditionalTransferError MANAGEABILITY_TRANSPORT_AD= DITIONAL_STATUS. + + @retval EFI_SUCCESS The message was successfully send to tran= sport interface and a + response was successfully received. + @retval EFI_NOT_FOUND The message was not successfully sent to = transport interface or a response + was not successfully received from transp= ort interface. + @retval EFI_NOT_READY MCTP transport interface is not ready for= MCTP message. + @retval EFI_DEVICE_ERROR MCTP transport interface Device hardware = error. + @retval EFI_TIMEOUT The message time out. + @retval EFI_UNSUPPORTED The message was not successfully sent to = the transport interface. + @retval EFI_OUT_OF_RESOURCES The resource allocation is out of resourc= e or data size error. + @retval EFI_INVALID_PARAMETER Both RequestData and ResponseData are NUL= L +**/ +EFI_STATUS +CommonMctpSubmitMessage ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + IN UINT8 MctpType, + IN UINT8 MctpSourceEndpointId, + IN UINT8 MctpDestinationEndpoin= tId, + IN BOOLEAN RequestDataIntegrityCh= eck, + IN UINT8 *RequestData, + IN UINT32 RequestDataSize, + IN UINT32 RequestTimeout, + OUT UINT8 *ResponseData, + IN OUT UINT32 *ResponseDataSize, + IN UINT32 ResponseTimeout, + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *AdditionalTransferErr= or + ) +{ + EFI_STATUS Status; + UINT16 IndexOfPackage; + UINT8 *ThisRequestData; + UINT32 ThisRequestDataSize; + UINT16 MctpTransportHeaderSize; + UINT16 MctpTransportTrailerSize; + MANAGEABILITY_TRANSFER_TOKEN TransferToken; + MANAGEABILITY_TRANSPORT_HEADER MctpTransportHeader; + MANAGEABILITY_TRANSPORT_TRAILER MctpTransportTrailer; + MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES *MultiPackages; + MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *ThisPackage; + + if (TransportToken =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: No transport toke for MCTP\n", __FUNCTION__)= ); + return EFI_UNSUPPORTED; + } + + Status =3D TransportToken->Transport->Function.Version1_0->TransportStat= us ( + TransportToke= n, + AdditionalTra= nsferError + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Transport %s for MCTP has problem - (%r)\n",= __FUNCTION__, mTransportName, Status)); + return Status; + } + + MultiPackages =3D NULL; + Status =3D HelperManageabilitySplitPayload ( + sizeof (MCTP_TRANSPORT_HEADER) + sizeof (MCTP_MESSAGE_= HEADER), + 0, + RequestData, + RequestDataSize, + mTransportMaximumPayload, + &MultiPackages + ); + if (EFI_ERROR (Status) || (MultiPackages =3D=3D NULL)) { + DEBUG ((DEBUG_ERROR, "%a: Fails to split payload into multiple package= s - (%r)\n", __FUNCTION__, mTransportName, Status)); + return Status; + } + + // Print transmission packages info. + DEBUG ((DEBUG_MANAGEABILITY_INFO, "Manageability Transmission packages:\= n")); + ThisPackage =3D (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *)(MultiPackage= s + 1); + for (IndexOfPackage =3D 0; IndexOfPackage < MultiPackages->NumberOfPacka= ges; IndexOfPackage++) { + DEBUG ((DEBUG_MANAGEABILITY_INFO, "#%d: \n", IndexOfPackage)); + DEBUG ((DEBUG_MANAGEABILITY_INFO, " Packet pointer: 0x%08x\n", This= Package->PayloadPointer)); + DEBUG ((DEBUG_MANAGEABILITY_INFO, " Packet size : 0x%08x\n", This= Package->PayloadSize)); + } + + ThisPackage =3D (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *)(Mult= iPackages + 1); + mMctpPacketSequence =3D 0; + for (IndexOfPackage =3D 0; IndexOfPackage < MultiPackages->NumberOfPacka= ges; IndexOfPackage++) { + MctpTransportHeader =3D NULL; + MctpTransportTrailer =3D NULL; + ThisRequestData =3D ThisPackage->PayloadPointer; + ThisRequestDataSize =3D ThisPackage->PayloadSize; + + // Setup Start of Message bit and End of Message bit. + if (MultiPackages->NumberOfPackages =3D=3D 1) { + mStartOfMessage =3D TRUE; + mEndOfMessage =3D TRUE; + } else if (IndexOfPackage =3D=3D 0) { + mStartOfMessage =3D TRUE; + mEndOfMessage =3D FALSE; + } else if (IndexOfPackage =3D=3D MultiPackages->NumberOfPackages - 1) = { + mStartOfMessage =3D FALSE; + mEndOfMessage =3D TRUE; + } else { + mStartOfMessage =3D FALSE; + mEndOfMessage =3D FALSE; + } + + Status =3D SetupMctpRequestTransportPacket ( + TransportToken, + MctpType, + MctpSourceEndpointId, + MctpDestinationEndpointId, + RequestDataIntegrityCheck, + &MctpTransportHeader, + &MctpTransportHeaderSize, + &ThisRequestData, + &ThisRequestDataSize, + &MctpTransportTrailer, + &MctpTransportTrailerSize + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to build packets - (%r)\n", __FUNCTIO= N__, Status)); + return Status; + } + + ZeroMem (&TransferToken, sizeof (MANAGEABILITY_TRANSFER_TOKEN)); + TransferToken.TransmitHeader =3D MctpTransportHeader; + TransferToken.TransmitHeaderSize =3D MctpTransportHeaderSize; + TransferToken.TransmitTrailer =3D MctpTransportTrailer; + TransferToken.TransmitTrailerSize =3D MctpTransportTrailerSize; + + // Transmit packet. + if ((ThisRequestData =3D=3D NULL) || (ThisRequestDataSize =3D=3D 0)) { + // Transmit parameter were not changed by SetupMctpRequestTransportP= acket(). + TransferToken.TransmitPackage.TransmitPayload =3D ThisPackage->Pa= yloadPointer; + TransferToken.TransmitPackage.TransmitSizeInByte =3D ThisPackage->Pa= yloadSize; + } else { + TransferToken.TransmitPackage.TransmitPayload =3D ThisRequestData= ; + TransferToken.TransmitPackage.TransmitSizeInByte =3D ThisRequestData= Size; + } + + TransferToken.TransmitPackage.TransmitTimeoutInMillisecond =3D MANAGEA= BILITY_TRANSPORT_NO_TIMEOUT; + + // Receive packet. + TransferToken.ReceivePackage.ReceiveBuffer =3D NULL; + TransferToken.ReceivePackage.ReceiveSizeInByte =3D 0; + TransferToken.ReceivePackage.TransmitTimeoutInMillisecond =3D MANAGEAB= ILITY_TRANSPORT_NO_TIMEOUT; + + // Print out MCTP packet. + DEBUG (( + DEBUG_MANAGEABILITY_INFO, + "%a: Send MCTP message type: 0x%x, from source endpoint ID: 0x%x to = destination ID 0x%x: Request size: 0x%x, Response size: 0x%x\n", + __FUNCTION__, + MctpType, + MctpSourceEndpointId, + MctpDestinationEndpointId, + TransferToken.TransmitPackage.TransmitSizeInByte, + TransferToken.ReceivePackage.ReceiveSizeInByte + )); + + if ((MctpTransportHeader !=3D NULL) && (MctpTransportHeaderSize !=3D 0= )) { + HelperManageabilityDebugPrint ( + (VOID *)TransferToken.TransmitHeader, + (UINT32)TransferToken.TransmitHeaderSize, + "MCTP transport header.\n" + ); + } + + HelperManageabilityDebugPrint ( + (VOID *)TransferToken.TransmitPackage.TransmitPayload, + TransferToken.TransmitPackage.TransmitSizeInByte, + "MCTP full request payload.\n" + ); + + if ((MctpTransportTrailer !=3D NULL) && (MctpTransportTrailerSize !=3D= 0)) { + HelperManageabilityDebugPrint ( + (VOID *)TransferToken.TransmitTrailer, + (UINT32)TransferToken.TransmitTrailerSize, + "MCTP transport trailer.\n" + ); + } + + TransportToken->Transport->Function.Version1_0->TransportTransmitRecei= ve ( + TransportToken, + &TransferToken + ); + if (MctpTransportHeader !=3D NULL) { + FreePool ((VOID *)MctpTransportHeader); + } + + if (MctpTransportTrailer !=3D NULL) { + FreePool ((VOID *)MctpTransportTrailer); + } + + if (ThisRequestData !=3D NULL) { + FreePool ((VOID *)ThisRequestData); + ThisRequestData =3D NULL; + } + + // + // Return transfer status. + // + Status =3D TransferToken.TransferStatus; + *AdditionalTransferError =3D TransferToken.TransportAdditionalStatus; + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to send MCTP command over %s\n", __= FUNCTION__, mTransportName)); + FreePool (MultiPackages); + return Status; + } + + mMctpPacketSequence++; + ThisPackage++; + } + + // Receive packet. + TransferToken.TransmitPackage.TransmitPayload =3D NULL; + TransferToken.TransmitPackage.TransmitSizeInByte =3D 0; + TransferToken.ReceivePackage.ReceiveBuffer =3D ResponseDa= ta; + TransferToken.ReceivePackage.ReceiveSizeInByte =3D *ResponseD= ataSize; + TransferToken.TransmitHeader =3D NULL; + TransferToken.TransmitHeaderSize =3D 0; + TransferToken.TransmitTrailer =3D NULL; + TransferToken.TransmitTrailerSize =3D 0; + TransferToken.ReceivePackage.TransmitTimeoutInMillisecond =3D MANAGEABIL= ITY_TRANSPORT_NO_TIMEOUT; + + DEBUG (( + DEBUG_MANAGEABILITY_INFO, + "%a: Retrieve MCTP message Response size: 0x%x\n", + __FUNCTION__, + TransferToken.ReceivePackage.ReceiveSizeInByte + )); + TransportToken->Transport->Function.Version1_0->TransportTransmitReceive= ( + TransportToken, + &TransferToken + ); + + // + // Return transfer status. + // + *AdditionalTransferError =3D TransferToken.TransportAdditionalStatus; + *ResponseDataSize =3D TransferToken.ReceivePackage.ReceiveSizeInB= yte; + Status =3D TransferToken.TransferStatus; + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to send MCTP command over %s: %r\n", = __FUNCTION__, mTransportName, Status)); + return Status; + } + + return Status; +} diff --git a/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProto= col.c b/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocol.c new file mode 100644 index 0000000000..a1cac61e27 --- /dev/null +++ b/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocol.c @@ -0,0 +1,218 @@ +/** @file + This file provides edk2 MCTP Protocol implementation. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "MctpProtocolCommon.h" + +extern MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION mHardwareInformation; + +MANAGEABILITY_TRANSPORT_TOKEN *mTransportToken =3D NULL; +CHAR16 *mTransportName; +UINT32 mTransportMaximumPayload; + +/** + This service enables submitting message via EDKII MCTP protocol. + + @param[in] This EDKII_MCTP_PROTOCOL instan= ce. + @param[in] MctpType MCTP message type. + @param[in] MctpSourceEndpointId MCTP source endpoint ID. + @param[in] MctpDestinationEndpointId MCTP source endpoint ID. + @param[in] RequestDataIntegrityCheck Indicates whether MCTP mes= sage has + integrity check byte. + @param[in] RequestData Message Data. + @param[in] RequestDataSize Size of message Data. + @param[in] RequestTimeout Timeout value in milliseco= nds. + MANAGEABILITY_TRANSPORT_NO= _TIMEOUT means no timeout value. + @param[out] ResponseData Message Response Data. The= completion code is the first byte of response data. + @param[in, out] ResponseDataSize Size of Message Response D= ata. + @param[in] ResponseTimeout Timeout value in milliseco= nds. + MANAGEABILITY_TRANSPORT_NO= _TIMEOUT means no timeout value. + @param[out] AdditionalTransferError MANAGEABILITY_TRANSPORT_AD= DITIONAL_STATUS. + + @retval EFI_SUCCESS The message was successfully send to tran= sport interface and a + response was successfully received. + @retval EFI_NOT_FOUND The message was not successfully sent to = transport interface or a response + was not successfully received from transp= ort interface. + @retval EFI_NOT_READY MCTP transport interface is not ready for= MCTP message. + @retval EFI_DEVICE_ERROR MCTP transport interface Device hardware = error. + @retval EFI_TIMEOUT The message time out. + @retval EFI_UNSUPPORTED The message was not successfully sent to = the transport interface. + @retval EFI_OUT_OF_RESOURCES The resource allocation is out of resourc= e or data size error. + @retval EFI_INVALID_PARAMETER Both RequestData and ResponseData are NUL= L +**/ +EFI_STATUS +EFIAPI +MctpSubmitMessage ( + IN EDKII_MCTP_PROTOCOL *This, + IN UINT8 MctpType, + IN UINT8 MctpSourceEndpointId, + IN UINT8 MctpDestinationEndpoin= tId, + IN BOOLEAN RequestDataIntegrityCh= eck, + IN UINT8 *RequestData, + IN UINT32 RequestDataSize, + IN UINT32 RequestTimeout, + OUT UINT8 *ResponseData, + IN OUT UINT32 *ResponseDataSize, + IN UINT32 ResponseTimeout, + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *AdditionalTransferErr= or + ) +{ + EFI_STATUS Status; + + if ((RequestData =3D=3D NULL) && (ResponseData =3D=3D NULL)) { + DEBUG ((DEBUG_ERROR, "%a: Both RequestData and ResponseData are NULL\n= ", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + Status =3D CommonMctpSubmitMessage ( + mTransportToken, + MctpType, + MctpSourceEndpointId, + MctpDestinationEndpointId, + RequestDataIntegrityCheck, + RequestData, + RequestDataSize, + RequestTimeout, + ResponseData, + ResponseDataSize, + ResponseTimeout, + AdditionalTransferError + ); + return Status; +} + +EDKII_MCTP_PROTOCOL_V1_0 mMctpProtocolV10 =3D { + MctpSubmitMessage +}; + +EDKII_MCTP_PROTOCOL mMctpProtocol; + +/** + The entry point of the MCTP DXE driver. + + @param[in] ImageHandle - Handle of this driver image + @param[in] SystemTable - Table containing standard EFI services + + @retval EFI_SUCCESS - edkii MCTP Protocol is installed successfully. + @retval Otherwise - Other errors. +**/ +EFI_STATUS +EFIAPI +DxeMctpEntry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + MANAGEABILITY_TRANSPORT_CAPABILITY TransportCapability; + MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS TransportAdditionalStatus; + + Status =3D HelperAcquireManageabilityTransport ( + &gManageabilityProtocolMctpGuid, + &mTransportToken + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for MC= TP protocol - %r\n", __FUNCTION__, Status)); + return Status; + } + + Status =3D GetTransportCapability (mTransportToken, &TransportCapability= ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FU= NCTION__)); + return Status; + } + + mTransportMaximumPayload =3D MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_C= APABILITY (TransportCapability); + if (mTransportMaximumPayload =3D=3D (1 << MANAGEABILITY_TRANSPORT_CAPABI= LITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) { + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%a: Transport interface maximum pay= load is undefined.\n", __FUNCTION__)); + } else { + mTransportMaximumPayload -=3D 1; + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%a: Transport interface for MCTP pr= otocol has maximum payload 0x%x.\n", __FUNCTION__, mTransportMaximumPayload= )); + } + + mTransportName =3D HelperManageabilitySpecName (mTransportToken->Transpo= rt->ManageabilityTransportSpecification); + DEBUG ((DEBUG_ERROR, "%a: MCTP protocol over %s.\n", __FUNCTION__, mTran= sportName)); + + // + // Setup hardware information according to the transport interface. + Status =3D SetupMctpTransportHardwareInformation ( + mTransportToken, + &mHardwareInformation + ); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_ERROR, "%a: No hardware information of %s transport in= terface.\n", __FUNCTION__, mTransportName)); + } else { + DEBUG ((DEBUG_ERROR, "%a: Failed to setup hardware information of %s= transport interface.\n", __FUNCTION__, mTransportName)); + } + + return Status; + } + + // Initial transport interface with the hardware information assigned. + Status =3D HelperInitManageabilityTransport ( + mTransportToken, + mHardwareInformation, + &TransportAdditionalStatus + ); + if (EFI_ERROR (Status)) { + return Status; + } + + mMctpProtocol.ProtocolVersion =3D EDKII_MCTP_PROTOCOL_VERSION; + mMctpProtocol.Functions.Version1_0 =3D &mMctpProtocolV10; + Handle =3D NULL; + Status =3D gBS->InstallProtocolInterface ( + &Handle, + &gEdkiiMctpProtocolGuid, + EFI_NATIVE_INTERFACE, + (VOID **)&mMctpProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to install EDKII MCTP protocol - %r\n= ", __FUNCTION__, Status)); + } + + return Status; +} + +/** + This is the unload handler for MCTP protocol module. + + Release the MANAGEABILITY_TRANSPORT_TOKEN acquired at entry point. + + @param[in] ImageHandle The drivers' driver image. + + @retval EFI_SUCCESS The image is unloaded. + @retval Others Failed to unload the image. + +**/ +EFI_STATUS +EFIAPI +MctpUnloadImage ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + + Status =3D EFI_SUCCESS; + if (mTransportToken !=3D NULL) { + Status =3D ReleaseTransportSession (mTransportToken); + } + + return Status; +} --=20 2.37.1.windows.1