From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.52]) by mx.groups.io with SMTP id smtpd.web10.72960.1680534344369146343 for ; Mon, 03 Apr 2023 08:05:44 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=Cd75ihhj; 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.93.52, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XDowjhKmGk/f67YraznKpsqPiHRKRpQuRnMSWSHydWePmZhAexN4atdGAlz+krYWmkUEDBPKtSjQ2bBVbUxVJllkdlR5Fj27pkWOUUJJQMnVIn4pcFMTh9SMg/A+w4ctjBP8G2xo/zBqpRcFKYLaFXb8LzvyxZCikQvol4IUg85fE5wbVX6GANXvAWU5R+U72u1ojEeplsqatXv2ZltmuFP2ofVGUoLCzigTJk6uv7Ac/CV2N2DWUgnesfV/37U3KZVMwHNeu/sVNi7w/u8lPQfOKi4dph126WT5an9TBZAlXey5n4xeUDUqis6eoT6Ydgee+7k4eROB/ApA+g5BjA== 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=F1iMToc5vqeBvYa7pzgmT+3rOhED5QBEaILJEHa1jAk=; b=MRp8g1LtpsFHR+oh3QtHS0USilyX18G4NdI3MOlb9KSrsaPdiL3yDILRUyNfhvTl2VDsRo66x1me3F5Rwtwsu33w6xOorTrN+WO6dc/f3V24O+8vBsAXklrrQUk4qO6IF9QphD7vMAHcrt20jBc7XhmZXhZGQa477m0MDQ0BZwQBpLfwXIFXsmQ9RmaV1f64V31gwhxVfzgrHFvwd3ROkmrAaVQlueJLsz3o7z8Sp1O/YwwlKdaDbaGzSCEop1N1XjIHPmcrfDJ0hyy1UWfCEoPxpLs1sg98m67as0WCmWyKpCKQopLsbG/GzSlX68uCPhLDKmEmROoszEymgOms1w== 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=F1iMToc5vqeBvYa7pzgmT+3rOhED5QBEaILJEHa1jAk=; b=Cd75ihhjZWPMHHfGsPg+9wmRnky2zHK0cOaSzNtm/E1zW3P3QjHjsd9rzqgnpkilT0uQrOpBJdZbZZA+BYaDj5vQ7rGdzl+Qb7gNt0YwzFQNfvjFCxpojmd5ENzQgBmNqqec3l5GgRrgPYlK1BqSY3BQmpz5aYOUBXde59QNaDc= Received: from DM6PR03CA0006.namprd03.prod.outlook.com (2603:10b6:5:40::19) by PH7PR12MB6882.namprd12.prod.outlook.com (2603:10b6:510:1b8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.33; Mon, 3 Apr 2023 15:05:41 +0000 Received: from DS1PEPF0000B073.namprd05.prod.outlook.com (2603:10b6:5:40:cafe::5c) by DM6PR03CA0006.outlook.office365.com (2603:10b6:5:40::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.22 via Frontend Transport; Mon, 3 Apr 2023 15:05:41 +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 DS1PEPF0000B073.mail.protection.outlook.com (10.167.17.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.29 via Frontend Transport; Mon, 3 Apr 2023 15:05:41 +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; Mon, 3 Apr 2023 10:05:36 -0500 From: "Chang, Abner" To: CC: Isaac Oram , Abdul Lateef Attar , Nickle Wang , Igor Kulchytskyy Subject: [edk2-platforms][PATCH 10/14] ManageabilityPkg: Add MCTP transport interface Date: Mon, 3 Apr 2023 23:04:55 +0800 Message-ID: <20230403150459.925-11-abner.chang@amd.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20230403150459.925-1-abner.chang@amd.com> References: <20230403150459.925-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: DS1PEPF0000B073:EE_|PH7PR12MB6882:EE_ X-MS-Office365-Filtering-Correlation-Id: 76421c23-2570-4ee5-77f8-08db3454e424 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AeX8pWetExQqhI9YqPwqtNv0MC1JA2sNVflE10Rp0DKrEiyZSIG+5NA0IvzR8r3Fu1JnQ2ZN+nFc8QdWs6a+awuKKfmaykeVchECkhpqprFLrviIKPSa5fg+YlwQDM0wVjr4emgAyBHTl9n95cigM+/38KAgUbz0LTvZBfAcwJEi+TkiZrOpzyYgfldo2wsC2KSMhIMERa7HK9U2ANQOsRVV2rfNFJhp+cPjLakjYvoMED0lX9/6mGscTqxhwa74hr9nuPzL4ZwriXtXgwBQUdf/CpyekakdmhEM5d+WbRixLMMb6W5AmiGajHr61mubpmW8g67qscH1+ynxpqZiBe42Lcht2sRmRrYL9Kr3d75yBUoMXf2rD7SqTO30Ph6cKCsSSf1fCS/nzCoagH4VEc678XJLKrQcQosb1J9m7QGcLofFLbzsqzA+8aFCaz/q2cV+oNxy0kCD0TzVEO5gdo1bahmcVXEHuSuqi/bSc77o6GcRyPnWsU/mR40oW1s40vEO/MhKskfPSSbe/3t0aPu3YiFLFOmCgeE9+YrGBidTtfEdAVwwVnAp1Z7RW7Srfmr7v8lMGqpPCjN7QFHhfZXIofdq5AaZEbUb/F9yjSBff9ONXrnniounuqWypUF2fStMMfne8gnKWLkuyiT4jP50cHKY2Y5c337yXxCgA1R1Zv0OBLUAnibLIbK6IwuQLzOIe5HhCg7U5ElBWatALuPjeIU4lmuZy3Fy2vbw6/r2AouVszomRcTNHdU+msgeu6Qv4kYlrt6KmrxxCdExig== 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)(396003)(376002)(346002)(39860400002)(136003)(451199021)(46966006)(36840700001)(40470700004)(54906003)(316002)(1076003)(26005)(2616005)(478600001)(336012)(426003)(36860700001)(47076005)(16526019)(82740400003)(186003)(6666004)(7696005)(70586007)(70206006)(4326008)(83380400001)(8676002)(6916009)(86362001)(356005)(30864003)(81166007)(41300700001)(5660300002)(2906002)(40460700003)(2876002)(8936002)(40480700001)(36756003)(82310400005)(36900700001)(44824005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Apr 2023 15:05:41.1768 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76421c23-2570-4ee5-77f8-08db3454e424 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: DS1PEPF0000B073.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6882 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Abner Chang Add MCTP manageability transport interface library. The functionality is verified by checking the binary debug output of payload. Signed-off-by: Abner Chang Cc: Isaac Oram Cc: Abdul Lateef Attar Cc: Nickle Wang Cc: Igor Kulchytskyy --- .../ManageabilityPkg/ManageabilityPkg.dsc | 1 + .../Dxe/DxeManageabilityTransportMctp.inf | 44 +++ .../Library/ManageabilityTransportMctpLib.h | 54 +++ .../Dxe/ManageabilityTransportMctp.h | 26 ++ .../Dxe/ManageabilityTransportMctp.c | 367 ++++++++++++++++++ .../Dxe/ManageabilityTransportMctp.uni | 13 + 6 files changed, 505 insertions(+) create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTranspor= tMctpLib/Dxe/DxeManageabilityTransportMctp.inf create mode 100644 Features/ManageabilityPkg/Include/Library/Manageability= TransportMctpLib.h create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTranspor= tMctpLib/Dxe/ManageabilityTransportMctp.h create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTranspor= tMctpLib/Dxe/ManageabilityTransportMctp.c create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTranspor= tMctpLib/Dxe/ManageabilityTransportMctp.uni diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc b/Features/Mana= geabilityPkg/ManageabilityPkg.dsc index 412029ef6c..959b3eabd2 100644 --- a/Features/ManageabilityPkg/ManageabilityPkg.dsc +++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc @@ -37,6 +37,7 @@ =20 [Components] ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/DxeManageabili= tyTransportKcs.inf + ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/DxeManageabil= ityTransportMctp.inf ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf =20 [LibraryClasses] diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLi= b/Dxe/DxeManageabilityTransportMctp.inf b/Features/ManageabilityPkg/Library= /ManageabilityTransportMctpLib/Dxe/DxeManageabilityTransportMctp.inf new file mode 100644 index 0000000000..22ea37c516 --- /dev/null +++ b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/D= xeManageabilityTransportMctp.inf @@ -0,0 +1,44 @@ +## @file +# MCTP instance of Manageability Transport Library +# +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D DxeManageabilityTransportMctp + MODULE_UNI_FILE =3D ManageabilityTransportMctp.uni + FILE_GUID =3D 7770FA0F-4808-47BD-89F4-717185332486 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ManageabilityTransportLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# + +[Sources] + ManageabilityTransportMctp.c + ManageabilityTransportMctp.h + +[Packages] + ManageabilityPkg/ManageabilityPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib + MemoryAllocationLib + UefiBootServicesTableLib + +[Protocols] + gEdkiiMctpProtocolGuid + +[Guids] + gManageabilityProtocolPldmGuid + gManageabilityTransportMctpGuid + +[Depex] + gEdkiiMctpProtocolGuid ## ALWAYS_CONSUMES + diff --git a/Features/ManageabilityPkg/Include/Library/ManageabilityTranspo= rtMctpLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTransp= ortMctpLib.h new file mode 100644 index 0000000000..43bd142f4c --- /dev/null +++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportMctpL= ib.h @@ -0,0 +1,54 @@ +/** @file + + This file defines the manageability MCTP protocol specific transport dat= a. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MANAGEABILITY_TRANSPORT_MCTP_LIB_H_ +#define MANAGEABILITY_TRANSPORT_MCTP_LIB_H_ + +#include + +#define MCTP_KCS_HEADER_VERSION 0x01 + +// According to SMBUS spec, the polynomial is: +// C(x) =3D X^8 + X^2 + X^1 + 1, which is 0x107, +// just ignore bit8 in definition. +#define MCTP_KCS_PACKET_ERROR_CODE_POLY 0x07 + +/// +/// The MCTP Message header which is apart from +/// the payload. +/// + +typedef struct { + UINT8 IntegrityCheck : 1; ///< Message integrity check. + UINT8 MessageType : 7; ///< Message type. +} MANAGEABILITY_MCTP_MESSAGE_HEADER; + +typedef struct { + UINT8 SourceEndpointId; + UINT8 DestinationEndpointId; + MANAGEABILITY_MCTP_MESSAGE_HEADER MessageHeader; +} MANAGEABILITY_MCTP_TRANSPORT_HEADER; + +typedef struct { + UINT8 NetFunc; ///< Message integrity check. + UINT8 DefiningBody; ///< Message type. + UINT8 ByteCount; ///< Byte count of payload. +} MANAGEABILITY_MCTP_KCS_HEADER; +#define MCTP_KCS_NETFN_LUN 0xb0 +#define DEFINING_BODY_DMTF_PRE_OS_WORKING_GROUP 0x01 + +// This is used to track the response message. This value +// is not defined by the specification. +#define MCTP_MESSAGE_TAG 0x1 + +#define MCTP_MESSAGE_TAG_OWNER_REQUEST 0x01 +#define MCTP_MESSAGE_TAG_OWNER_RESPONSE 0x01 + +#define MCTP_PACKET_SEQUENCE_MASK 0x3 + +#endif // MANAGEABILITY_TRANSPORT_MCTP_LIB_H_ diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLi= b/Dxe/ManageabilityTransportMctp.h b/Features/ManageabilityPkg/Library/Mana= geabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h new file mode 100644 index 0000000000..1ce0d3a8bc --- /dev/null +++ b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/M= anageabilityTransportMctp.h @@ -0,0 +1,26 @@ +/** @file + + Manageability transport MCTP internal used definitions. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MANAGEABILITY_TRANSPORT_MCTP_LIB_INTERNAL_H_ +#define MANAGEABILITY_TRANSPORT_MCTP_LIB_INTERNAL_H_ + +#include + +#define MANAGEABILITY_TRANSPORT_MCTP_SIGNATURE SIGNATURE_32 ('M', 'T', 'M= ', 'C') + +/// +/// Manageability transport KCS internal data structure. +/// +typedef struct { + UINTN Signature; + MANAGEABILITY_TRANSPORT_TOKEN Token; +} MANAGEABILITY_TRANSPORT_MCTP; + +#define MANAGEABILITY_TRANSPORT_MCTP_FROM_LINK(a) CR (a, MANAGEABILITY_TR= ANSPORT_MCTP, Token, MANAGEABILITY_TRANSPORT_MCTP_SIGNATURE) + +#endif // MANAGEABILITY_TRANSPORT_MCTP_LIB_INTERNAL_H_ diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLi= b/Dxe/ManageabilityTransportMctp.c b/Features/ManageabilityPkg/Library/Mana= geabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.c new file mode 100644 index 0000000000..2d9b059157 --- /dev/null +++ b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/M= anageabilityTransportMctp.c @@ -0,0 +1,367 @@ +/** @file + + MCTP instance of Manageability Transport Library + + 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 "ManageabilityTransportMctp.h" + +MANAGEABILITY_TRANSPORT_MCTP *mSingleSessionToken =3D NULL; +EDKII_MCTP_PROTOCOL *mMctpProtocol =3D NULL; + +EFI_GUID *SupportedManageabilityProtocol[] =3D { + &gManageabilityProtocolPldmGuid +}; + +UINT8 NumberOfSupportedProtocol =3D (sizeof (SupportedManageabilityProtoc= ol)/sizeof (EFI_GUID *)); + +/** + This function initializes the transport interface. + + @param [in] TransportToken The transport token acquired throu= gh + AcquireTransportSession function. + @param [in] HardwareInfo The hardware information + assigned to MCTP transport interfa= ce. + + @retval EFI_SUCCESS Transport interface is initialized + successfully. + @retval EFI_INVALID_PARAMETER The invalid transport token. + @retval EFI_NOT_READY The transport interface works fine= but + @retval is not ready. + @retval EFI_DEVICE_ERROR The transport interface has proble= ms. + @retval EFI_ALREADY_STARTED Teh protocol interface has already= initialized. + @retval Otherwise Other errors. + +**/ +EFI_STATUS +EFIAPI +MctpTransportInit ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + IN MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION HardwareInfo OPTIONAL + ) +{ + return EFI_SUCCESS; +} + +/** + This function returns the transport interface status. + The generic EFI_STATUS is returned to caller directly, The additional + information of transport interface could be optionally returned in + TransportAdditionalStatus to describes the status that can't be + described obviously through EFI_STATUS. + See the definition of MANAGEABILITY_TRANSPORT_STATUS. + + @param [in] TransportToken The transport token acquired th= rough + AcquireTransportSession functio= n. + @param [out] TransportAdditionalStatus The additional status of transp= ort + interface. + NULL means no additional status= of this + transport interface. + + @retval EFI_SUCCESS Transport interface status is retu= rned. + @retval EFI_INVALID_PARAMETER The invalid transport token. + @retval EFI_DEVICE_ERROR The transport interface has proble= ms to return + @retval EFI_UNSUPPORTED The transport interface doesn't ha= ve status report. + Otherwise Other errors. + +**/ +EFI_STATUS +EFIAPI +MctpTransportStatus ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *TransportAdditionalStatu= s OPTIONAL + ) +{ + if (TransportToken =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Invalid transport token.\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + if (TransportAdditionalStatus !=3D NULL) { + *TransportAdditionalStatus =3D MANAGEABILITY_TRANSPORT_ADDITIONAL_STAT= US_NO_ERRORS; + } + + return EFI_SUCCESS; +} + +/** + This function resets the transport interface. + The generic EFI_STATUS is returned to caller directly after reseting tra= nsport + interface. The additional information of transport interface could be op= tionally + returned in TransportAdditionalStatus to describes the status that can't= be + described obviously through EFI_STATUS. + See the definition of MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS. + + @param [in] TransportToken The transport token acquired th= rough + AcquireTransportSession functio= n. + @param [out] TransportAdditionalStatus The additional status of specif= ic transport + interface after the reset. + NULL means no additional status= of this + transport interface. + + @retval EFI_SUCCESS Transport interface status is retu= rned. + @retval EFI_INVALID_PARAMETER The invalid transport token. + @retval EFI_TIMEOUT The reset process is time out. + @retval EFI_DEVICE_ERROR The transport interface has proble= ms to return + status. + Otherwise Other errors. + +**/ +EFI_STATUS +EFIAPI +MctpTransportReset ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *TransportAdditionalStatu= s OPTIONAL + ) +{ + if (TransportAdditionalStatus !=3D NULL) { + *TransportAdditionalStatus =3D MANAGEABILITY_TRANSPORT_ADDITIONAL_STAT= US_NOT_AVAILABLE; + } + + return EFI_UNSUPPORTED; +} + +/** + This function transmit the request over target transport interface. + The generic EFI_STATUS is returned to caller directly after reseting tra= nsport + interface. The additional information of transport interface could be op= tionally + returned in TransportAdditionalStatus to describes the status that can't= be + described obviously through EFI_STATUS. + See the definition of MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS. + + @param [in] TransportToken The transport token acquired throu= gh + AcquireTransportSession function. + @param [in] TransferToken The transfer token, see the defini= tion of + MANAGEABILITY_TRANSFER_TOKEN. + + @retval The EFI status is returned in MANAGEABILITY_TRANSFER_TOKEN. + +**/ +VOID +EFIAPI +MctpTransportTransmitReceive ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + IN MANAGEABILITY_TRANSFER_TOKEN *TransferToken + ) +{ + EFI_STATUS Status; + MANAGEABILITY_MCTP_TRANSPORT_HEADER *TransmitHeader; + + if (TransportToken =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Invalid transport token.\n", __FUNCTION__)); + TransferToken->TransportAdditionalStatus =3D MANAGEABILITY_TRANSPORT_A= DDITIONAL_STATUS_NOT_AVAILABLE; + return; + } + + TransmitHeader =3D (MANAGEABILITY_MCTP_TRANSPORT_HEADER *)TransferToken-= >TransmitHeader; + if (TransmitHeader =3D=3D NULL) { + TransferToken->TransferStatus =3D EFI_INVALID_PARAMETER; + TransferToken->TransportAdditionalStatus =3D MANAGEABILITY_TRANSPORT_A= DDITIONAL_STATUS_NOT_AVAILABLE; + return; + } + + if (mMctpProtocol =3D=3D NULL) { + Status =3D gBS->LocateProtocol ( + &gEdkiiMctpProtocolGuid, + NULL, + (VOID **)&mMctpProtocol + ); + if (EFI_ERROR (Status)) { + // + // Dxe MCTP Protocol is not installed. + // + DEBUG ((DEBUG_ERROR, "%a: EDKII MCTP protocol is not found - %r\n", = Status)); + return; + } + } + + DEBUG (( + DEBUG_INFO, + "%a: MCTP message type: 0x%x, SourceEndpointId: 0x%x, DestinationEndpo= intId: 0x%x\n", + __FUNCTION__, + TransmitHeader->MessageHeader.MessageType, + TransmitHeader->SourceEndpointId, + TransmitHeader->DestinationEndpointId + )); + DEBUG (( + DEBUG_INFO, + " - Request message size: 0x%x, Response message size: %x\n", + TransferToken->TransmitPackage.TransmitSizeInByte, + TransferToken->ReceivePackage.ReceiveSizeInByte + )); + Status =3D mMctpProtocol->Functions.Version1_0->MctpSubmitCommand ( + mMctpProtocol, + TransmitHeader->MessageH= eader.MessageType, + TransmitHeader->SourceEn= dpointId, + TransmitHeader->Destinat= ionEndpointId, + (BOOLEAN)TransmitHeader-= >MessageHeader.IntegrityCheck, + TransferToken->TransmitP= ackage.TransmitPayload, + TransferToken->TransmitP= ackage.TransmitSizeInByte, + TransferToken->TransmitP= ackage.TransmitTimeoutInMillisecond, + TransferToken->ReceivePa= ckage.ReceiveBuffer, + &TransferToken->ReceiveP= ackage.ReceiveSizeInByte, + TransferToken->ReceivePa= ckage.TransmitTimeoutInMillisecond, + &TransferToken->Transpor= tAdditionalStatus + ); + TransferToken->TransferStatus =3D Status; +} + +/** + This function acquires to create a transport session to transmit managea= bility + packet. A transport token is returned to caller for the follow up operat= ions. + + @param [in] ManageabilityProtocolSpec The protocol spec the transport= interface is acquired. + @param [out] TransportToken The pointer to receive the tran= sport token created by + the target transport interface = library. + @retval EFI_SUCCESS Token is created successfully. + @retval EFI_OUT_OF_RESOURCES Out of resource to create a new= transport session. + @retval EFI_UNSUPPORTED Protocol is not supported on th= is transport interface. + @retval Otherwise Other errors. + +**/ +EFI_STATUS +AcquireTransportSession ( + IN EFI_GUID *ManageabilityProtocolSpec, + OUT MANAGEABILITY_TRANSPORT_TOKEN **TransportToken + ) +{ + EFI_STATUS Status; + MANAGEABILITY_TRANSPORT_MCTP *MctpTransportToken; + + if (ManageabilityProtocolSpec =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: No Manageability protocol specification spec= ified.\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + Status =3D HelperManageabilityCheckSupportedSpec ( + &gManageabilityTransportMctpGuid, + SupportedManageabilityProtocol, + NumberOfSupportedProtocol, + ManageabilityProtocolSpec + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Protocol is not supported on this transport = interface.\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + if (mSingleSessionToken !=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: This manageability transport library only su= pports one session transport token.\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + MctpTransportToken =3D (MANAGEABILITY_TRANSPORT_MCTP *)AllocateZeroPool = (sizeof (MANAGEABILITY_TRANSPORT_MCTP)); + if (MctpTransportToken =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TR= ANSPORT_MCTP\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + MctpTransportToken->Token.Transport =3D AllocateZeroPool (sizeof (MANAGE= ABILITY_TRANSPORT)); + if (MctpTransportToken->Token.Transport =3D=3D NULL) { + FreePool (MctpTransportToken); + DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TR= ANSPORT\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + MctpTransportToken->Signature = =3D MANAGEABILITY_TRANSPORT_MCTP_SIGNATURE; + MctpTransportToken->Token.ManageabilityProtocolSpecification = =3D ManageabilityProtocolSpec; + MctpTransportToken->Token.Transport->TransportVersion = =3D MANAGEABILITY_TRANSPORT_TOKEN_VERSION; + MctpTransportToken->Token.Transport->ManageabilityTransportSpecification= =3D &gManageabilityTransportMctpGuid; + MctpTransportToken->Token.Transport->TransportName = =3D L"MCTP"; + MctpTransportToken->Token.Transport->Function.Version1_0 = =3D AllocateZeroPool (sizeof (MANAGEABILITY_TRANSPORT_FUNCTION_V1_0)); + if (MctpTransportToken->Token.Transport->Function.Version1_0 =3D=3D NULL= ) { + DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TR= ANSPORT_FUNCTION_V1_0\n", __FUNCTION__)); + FreePool (MctpTransportToken); + FreePool (MctpTransportToken->Token.Transport); + return EFI_OUT_OF_RESOURCES; + } + + MctpTransportToken->Token.Transport->Function.Version1_0->TransportInit = =3D MctpTransportInit; + MctpTransportToken->Token.Transport->Function.Version1_0->TransportReset= =3D MctpTransportReset; + MctpTransportToken->Token.Transport->Function.Version1_0->TransportStatu= s =3D MctpTransportStatus; + MctpTransportToken->Token.Transport->Function.Version1_0->TransportTrans= mitReceive =3D MctpTransportTransmitReceive; + + mSingleSessionToken =3D MctpTransportToken; + *TransportToken =3D &MctpTransportToken->Token; + return EFI_SUCCESS; +} + +/** + This function returns the transport capabilities according to + the manageability protocol. + + @param [in] TransportToken Transport token acquired from m= anageability + transport library. + @param [out] TransportFeature Pointer to receive transport ca= pabilities. + See the definitions of + MANAGEABILITY_TRANSPORT_CAPABIL= ITY. + @retval EFI_SUCCESS TransportCapability is returned= successfully. + @retval EFI_INVALID_PARAMETER TransportToken is not a valid t= oken. +**/ +EFI_STATUS +GetTransportCapability ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + OUT MANAGEABILITY_TRANSPORT_CAPABILITY *TransportCapability + ) +{ + if ((TransportToken =3D=3D NULL) || (TransportCapability =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + *TransportCapability =3D 0; + return EFI_SUCCESS; +} + +/** + This function releases the manageability session. + + @param [in] TransportToken The transport token acquired through + AcquireTransportSession. + @retval EFI_SUCCESS Token is released successfully. + @retval EFI_INVALID_PARAMETER Invalid TransportToken. + @retval Otherwise Other errors. + +**/ +EFI_STATUS +ReleaseTransportSession ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken + ) +{ + EFI_STATUS Status; + MANAGEABILITY_TRANSPORT_MCTP *MctpTransportToken; + + if (TransportToken =3D=3D NULL) { + Status =3D EFI_INVALID_PARAMETER; + } + + MctpTransportToken =3D MANAGEABILITY_TRANSPORT_MCTP_FROM_LINK (Transport= Token); + if (mSingleSessionToken !=3D MctpTransportToken) { + Status =3D EFI_INVALID_PARAMETER; + } + + if (MctpTransportToken !=3D NULL) { + FreePool (MctpTransportToken->Token.Transport->Function.Version1_0); + FreePool (MctpTransportToken->Token.Transport); + FreePool (MctpTransportToken); + mSingleSessionToken =3D NULL; + Status =3D EFI_SUCCESS; + } + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to release MCTP transport token (%r).\n= ", __FUNCTION__, Status)); + } + + return Status; +} diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLi= b/Dxe/ManageabilityTransportMctp.uni b/Features/ManageabilityPkg/Library/Ma= nageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.uni new file mode 100644 index 0000000000..ca8125a4a7 --- /dev/null +++ b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/M= anageabilityTransportMctp.uni @@ -0,0 +1,13 @@ +// /** @file +// MCTP instance of Manageability Transport Library +// +// Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "MCTP instance of = Manageability Transport Library" + +#string STR_MODULE_DESCRIPTION #language en-US "MCTP Manageabilit= y Transport library implementation." + --=20 2.37.1.windows.1