From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.63]) by mx.groups.io with SMTP id smtpd.web11.5105.1682054670485407719 for ; Thu, 20 Apr 2023 22:24:30 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=nOCO1JyY; 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.237.63, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xz3HExZNRBX9m9+ZDhLN0zTql//PDoRsLeIwC7zAnQVgz6p0EN507elTgUNcI6sj/lqwudJFLwavPZhm8I/xNhiBGlQhy8ByEuqnGcYA7oQ+BUqZLfmNE2Y8YVcewp1F+WVYS7fpZmbzQcDDJ497mDScAnxa4onxVH5TvNH1tF4LkdIb+ICqy4veQIp/MdrtxYgA8dKfck65hRVOR+349l2q81YK55a6RexFeGZF0CMiMH5KiaGp9NY1XnNnYUofOorQT3IY98fSIjQsugLtI/lsfLPqAdRXTG+G7puJoFQZGKg31NckkP5NE8x3T5ogejEcA3KQipLfpkIZdjDkYQ== 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=80+EJyeijHimIY8t+0ap0cAf7uXTZ9jD6hUj67ZeNvo=; b=WPIHvQAi7xkgvN01dKApEGOeQoMQpdCsJe4UjlDstrzPH4YqwbDc1CCYM6fuDxP1EeiLZvuT99XxzcxugtzLA04RMznRJAO5FHLMeqXHbTBHLRESOdOPI7hf0UJEl84RWW/fIT2VYh5r5x2vmNPbRA3PZucXlP60coAIwIjw5ENBWoebz8j9EA4UOlAm6p03nqDoEwkNSOECwg5o1cUPDHSz3txnSKJYmg4vHDDZIxmhdp6jK1KX739zj+bQfq6I+skEE8+i5MHF8WGeBg+qr0LC5CCurccX1jjlVXqedqfF8FyyxwS3E7BhRHs9tRiNQ9KBmNqYFfvKlRBZh8CEkg== 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=80+EJyeijHimIY8t+0ap0cAf7uXTZ9jD6hUj67ZeNvo=; b=nOCO1JyY7mRVPjoD3k0Q69mLAcuA6eiIYhq3BHUCVQWWBwz4Ljd8+RbJH4jy2aQT3QyTwkxMw8pkygTrFshLEghZpozfM+ov08NFc21yMUIAZH+3x1OaUrSeeZLI+4NTdfbKPKwdi8yCJW19g+cdVoef4bNl2WftgrWzT0KehW8= Received: from DM5PR07CA0118.namprd07.prod.outlook.com (2603:10b6:4:ae::47) by IA1PR12MB6092.namprd12.prod.outlook.com (2603:10b6:208:3ec::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Fri, 21 Apr 2023 05:24:26 +0000 Received: from DS1PEPF0000B076.namprd05.prod.outlook.com (2603:10b6:4:ae:cafe::55) by DM5PR07CA0118.outlook.office365.com (2603:10b6:4:ae::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.27 via Frontend Transport; Fri, 21 Apr 2023 05:24:26 +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 DS1PEPF0000B076.mail.protection.outlook.com (10.167.17.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6340.15 via Frontend Transport; Fri, 21 Apr 2023 05:24:26 +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; Fri, 21 Apr 2023 00:24:23 -0500 From: "Chang, Abner" To: CC: Isaac Oram , Abdul Lateef Attar , Nickle Wang , Igor Kulchytskyy Subject: [edk2-platforms][PATCH V3 10/14] ManageabilityPkg: Add MCTP transport interface Date: Fri, 21 Apr 2023 13:22:43 +0800 Message-ID: <20230421052247.1520-11-abner.chang@amd.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20230421052247.1520-1-abner.chang@amd.com> References: <20230421052247.1520-1-abner.chang@amd.com> MIME-Version: 1.0 Return-Path: Abner.Chang@amd.com 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: DS1PEPF0000B076:EE_|IA1PR12MB6092:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b684246-e8d8-41af-4392-08db4228ac94 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x7HsAwxtQqEGpmd1r1wapGTSh/amKvtNbQsrqblR6NsSGcFoSYH7XyMltNDNmfOAWF2hR/u7cXcgmefpRwCZD07qk2ndUWPZzKwJGr6kLBC7eH+3Bw2oOJJd5aVMcA2WvMrk0wuJwyJGU/g8qVMzbsKJRpmGq7xLVVGEgtciWoZCJIam4D5vT2QNaukgv9y7fQhJ/AuNAG+50pCxCBK3dhsajTwmSvZORNIvg5z8XdsPZfsoxsX02UUGitH+bYCHqWqw/nkfCYFOdXKb+Q5qQWvU8ZsiZFPz7tb1+l6rn0iKTjgu8qlIyj7RLfyojK7pVnBRM7+jMBuTAJPdhmvE9M9xa3QKzAWmhT5gELFZVUMBVqTtpb6slLSm1LVyzJmI1mNmrAVzMqL4pJOf6sbwXbV5MpbHjKmdUP5dL+4lo7r4Uidd3MZOKnUqtgF6D8sCulSLi9h889m76iKk9tyT8ff/S1qLvP4N0r5tnjvorjt18javhjChNXuG00koiBF3XXa+FO5VeGlKC4MgCpSJXjex8tAvs0ID5Lgxh1r9KCBiyHD4N7BkxkZxuNmuSbnMRSn7fuis5CiGF7Eod/ziP+j1QH3m88/TiT0G4XrYcbBiVShdX9uMU5SBLvn2W3+PkOSG+vqwTHIC4XLpzbxaB1H84Y0Sr7hKKX1Ue9raadSbgTqZo6QLNCn7Bbd13/dBBbBTy5XUtPMYtKS7O7/oQvxWmUDjScC8EFkO9s4GmI5PFvZifvCfqFgH6oeWzL/Pwoz+FUMiGVw946krZpd2SQ== 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)(39860400002)(136003)(346002)(376002)(396003)(451199021)(46966006)(40470700004)(36840700001)(40460700003)(70586007)(70206006)(316002)(6916009)(4326008)(7696005)(40480700001)(6666004)(86362001)(54906003)(82310400005)(478600001)(5660300002)(36756003)(2616005)(8676002)(8936002)(81166007)(356005)(82740400003)(2906002)(83380400001)(30864003)(2876002)(47076005)(336012)(426003)(36860700001)(41300700001)(1076003)(26005)(16526019)(186003)(36900700001)(44824005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2023 05:24:26.3798 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b684246-e8d8-41af-4392-08db4228ac94 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: DS1PEPF0000B076.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6092 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 +++ .../Dxe/ManageabilityTransportMctp.h | 26 ++ .../Dxe/ManageabilityTransportMctp.c | 367 ++++++++++++++++++ .../Dxe/ManageabilityTransportMctp.uni | 13 + 5 files changed, 451 insertions(+) create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTranspor= tMctpLib/Dxe/DxeManageabilityTransportMctp.inf 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/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..eaf02bbb0a --- /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 *mSupportedManageabilityProtocol[] =3D { + &gManageabilityProtocolPldmGuid +}; + +UINT8 mNumberOfSupportedProtocol =3D (sizeof (mSupportedManageabilityProt= ocol)/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", = __FUNCTION__, Status)); + return; + } + } + + DEBUG (( + DEBUG_MANAGEABILITY_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_MANAGEABILITY_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, + mSupportedManageabilityProtocol, + mNumberOfSupportedProtocol, + 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