From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.50]) by mx.groups.io with SMTP id smtpd.web11.2304.1681974054067850936 for ; Thu, 20 Apr 2023 00:00:54 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=DF4Dl739; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.223.50, mailfrom: nicklew@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lU7dr4CoYy+nbdF6uBLAqUg/VU/ZpcXFfnw2Bjr8c86DSHbZlvXQQgP4mt7JMfaKaU7qdhCBwpBk02Q8aOOkl2uh5X2/HWZCViYDqDVY2BC/ijWCpDLR+zw6ztAH9p93NZ7mt6VuDBhFnw3D0wfepy4wwgOGAtn7e31dxtnn750GQ5jEeDaHfY3aNsrzbkdVGWyz7O6CXU2OfCsZzIh8lKc8bofzpsdoFi9F82Hi2VMiYn4Y75qzSGtkIdaGzWPUw1sJZ+wCIN/ji5JCiRT/6HfIhOLin+wRVg7wzi6mqcEeuLpGzcvvRwCNOv3ePFUH5fZVD2EjgmRuCTSIoSOc+w== 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=wW+H17VJXDR4PUi8qTKRjsW7LBnTMrIdbI+k2N4Grek=; b=UunFVwu9jLKwida0BRxkdsRiySlF5m6BEuOgYYRCw7FHtUMHNXiLu7iFAPAx6DiWK1ozmmnKOtO7WlLwDPNaOAwL25SQqLhU6Rh7eA3MEBNonBAfzUsY4HBTV0+mjqvUOdAVjORYiT8Q4OoT0Gxxv00rplX0I+3rOGDREd8iGvWp9ZNImPsnu7wvK/KSWb8uPFiNmdmLDrtXatpHYh+Fnr1IYll3ejXrniYsEeDyH7if0oI1TPQuGWZE9JjzT3UegEG1uLrJAnpeTe7ACppQb5RGFsyWegz4YmuglTDJ+S8apqQKmazeL7EawVj3qh7Pfp/6Ie4JzzsCcFmbIZbYmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wW+H17VJXDR4PUi8qTKRjsW7LBnTMrIdbI+k2N4Grek=; b=DF4Dl739z25z0Vg29CZ66uu02AQLsCL21Dbs0RMveLud2RiLYuJuPgLlAN47gwxG/dCxLyB0D3e1n0TfX3jGlZ50vmmVzZjTM81JLVQU3Hw8FJNShKO/6jSWkjMVLsjpu5kBgssWWrxVII8St65fQy1KvwnnDoyOhOQI1/i3ET/Mc7dWG0yS9mapJA2P6rAT9kUTM9pbsGhUSu9KLlJVV4+5I+4VBFS8frWFd+VUg9IyjPSio+LcXUMa17Kzrr/sToKi/p7byP4E7izYwKvXKMqCThGdfpWxNcpr4a7wSizMle4Qkvlus6KEIjaZNxWLHbualuUgq7UtLgHZiEt5lw== Received: from MW4PR12MB7031.namprd12.prod.outlook.com (2603:10b6:303:1ef::6) by PH0PR12MB7789.namprd12.prod.outlook.com (2603:10b6:510:283::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Thu, 20 Apr 2023 07:00:50 +0000 Received: from MW4PR12MB7031.namprd12.prod.outlook.com ([fe80::d9df:b45b:2cc1:f017]) by MW4PR12MB7031.namprd12.prod.outlook.com ([fe80::d9df:b45b:2cc1:f017%5]) with mapi id 15.20.6319.022; Thu, 20 Apr 2023 07:00:50 +0000 From: "Nickle Wang" To: "abner.chang@amd.com" , "devel@edk2.groups.io" CC: Isaac Oram , Abdul Lateef Attar , Igor Kulchytskyy Subject: Re: [edk2-platforms][PATCH V2 09/14] ManageabilityPkg/MctpProtocol: Add MctpProtocol Thread-Topic: [edk2-platforms][PATCH V2 09/14] ManageabilityPkg/MctpProtocol: Add MctpProtocol Thread-Index: AQHZccWy/KgUS/1Bvk+UL1tlP9xD/68zxzMQ Date: Thu, 20 Apr 2023 07:00:50 +0000 Message-ID: References: <20230418071543.1951-1-abner.chang@amd.com> <20230418071543.1951-10-abner.chang@amd.com> In-Reply-To: <20230418071543.1951-10-abner.chang@amd.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR12MB7031:EE_|PH0PR12MB7789:EE_ x-ms-office365-filtering-correlation-id: c0903403-685d-4a61-6c15-08db416cf9d5 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: fLC0XNePpMpDSmBBTqrXaDpSKgYfnRqa+zDqxk7ntqyUwEHNMl0iHTd+qF+5N1EfdcCIHvhvPxJnpWhnIZRz07lkfQTqlAHkxZd6K8AjCjRRZ0npXYQGmK+lEC7fOrYhzaSKO4XSZipsqJW9tG4qiC5TEUo5VJAm8jRBdLtaXUYvftcfvq6uLKGgnIHBR/E1MGXq7IRcJOC5RVlnJyrO56bSMTVfu/4QBvtVCcBIi7Ft9tdv23fTw46Vv5bw5kXV8GrVG9Tau5ec5FLTBqShR0wemZLjvf5AJwfJyPAVRKC3xEVGIjMfWhkaHP4f8JQ3U/tjsvKg5Vs2/qFQ1UvpihV8lXU9cXGISWVwsbzqlMjAXVzofi71fcqhiMo14dWp1+JXgoPbS4/lIfTAu+OcH6ZQG47OpHtkIpjyCoO3YzMyF76pvZXHiDl+zllOiTggCsltjMqV79qEmBd7Iej8fr7eHfzVOdBXQu3u5Bb5Qx2QfmcxrcvwIGfKpxU03DgTpR7OzWVDKWZD7DRb+LV16yiOvolVcMUWdS6ZkIAbBABuN+0bnKlw+nibe1aj7H1Pq1yF0gtyRR8wyr5nZHVBDewqSnU1XtnSeOH2e7ccbgUcWlpptKaeLhECbOFkxwy3OC3MqZhLN7L3+Q6VuK3vVg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR12MB7031.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(376002)(346002)(39860400002)(396003)(366004)(451199021)(66946007)(64756008)(66556008)(2906002)(30864003)(66446008)(66476007)(86362001)(4326008)(5660300002)(52536014)(8936002)(41300700001)(55016003)(76116006)(54906003)(478600001)(33656002)(110136005)(19627235002)(316002)(71200400001)(7696005)(26005)(9686003)(186003)(122000001)(6506007)(83380400001)(53546011)(8676002)(38070700005)(38100700002)(579004)(559001)(44824005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?3eQjIB9NMTV2qledOK/3ZxSmjcc0Ov2U4NeSg+1Rd468IDha6fmurt4eURmJ?= =?us-ascii?Q?Cf7Mgy2dwOuT9HLfcOCmWvHU14LaRY/33LxrokmqA9plCIoDExl3XZtLE9tl?= =?us-ascii?Q?7I8TvuxLZfOFhBipPi14SV1byA5DbHvbXEUaG5dpRZCuwxd0IHEpdpmuEpdK?= =?us-ascii?Q?Xh6kErNZtNnyxs0O3adJwxmM2qms/B1IuPIXVvV1Vd4Zvm6dmZ9mRkNN0LGO?= =?us-ascii?Q?eZjN2+EZxc4caHFbYlWjA6Kp9KG27ZyBlkz/4ZVI1itWjkaEpbOabJIBiy5P?= =?us-ascii?Q?AP2u3lkbZusZV7He4z/Cmsm32cBhdYj36o/emV1qTvN0V4nxDwWZFqoi4If7?= =?us-ascii?Q?2gX4df9EGnX44b9B+ZlC0oi/PkCueZ+n61WhDEV43iO2u0I8S2N1yNHfy1KF?= =?us-ascii?Q?TJNu28ClIEkzvxpT41ED7nfBo66zFv8K76GfwD3uQ7+gB/st6pzstwsrS29y?= =?us-ascii?Q?WGnjK22o7gsqGSpU8n001hKdZbJFmTAMpE6s9lCNS4RAMW9bmOiEUg9lMxc9?= =?us-ascii?Q?mfc7weCN/Y9mjvkOaQ9IAoVEgE1loQiMfymKGTGGt4GwYvYBo2ycS0s1e1Ip?= =?us-ascii?Q?PSBvHx14SIBrrQpWUdasKk2NtJ+AGFpf+5PLAFKGwnCbdNiCyqZki5LwyvXl?= =?us-ascii?Q?rF1XeZpkFErVWSLdYDzmgzCBhDavVedsT039WNeVqEsE4Cp70M5JKmISKbkn?= =?us-ascii?Q?5BcCeEzX6A9rrKr+MnGO2hCOI4GRRQL2nVgWe/lk3IXn5ljy5RMaA2JW3bAs?= =?us-ascii?Q?Ic3lTPGGiialxliyr5i1lWmIQdkz65DcIkav7AxMyYFAUq4BHXiHaB21ruGY?= =?us-ascii?Q?QNmZdJqYcTH8HulZzrxah6vY1uKHpopPUAS27txpSV60Pk7fAopx3YXkZNvo?= =?us-ascii?Q?YYOk8um90oDYoHOYYAKFcUszeatmT+6wIqPF+6Va8a84TlXQv9E0wH9iaX/s?= =?us-ascii?Q?hTdsAHj6PvyE2ywgWQMBMPXhB6juuIGD9PSmL6JABZBQg8Q1FC1fiellyoQA?= =?us-ascii?Q?Tx9JU84G7EH1PoBFl3eE1b0RmA+iVBOpSRKADh31lAxOn1M9UUqzvRHsHxMS?= =?us-ascii?Q?l4m8Zj3u4GSVYIQ28yUFbc8pUVlfiY1SrKlwgipbV6QAc7ObkB9Jz5RslSkg?= =?us-ascii?Q?MCEWf6j3jOxZMb3YEy7BBSlkxDPriyBVhn9NpWgsfsB1xN5cqZeNz2gWDkx5?= =?us-ascii?Q?zjDIUaU3gwfBlXDdGpr2azwoY4GeJTV1citb3oHBv9uvkJIAnvBOWZPIzPDp?= =?us-ascii?Q?z982YCEDBF7VM016QKJBUag5Q6Sl6vMWiiGbwkqJskc6zpne46QLmg1LNSdD?= =?us-ascii?Q?mosTQ/m5G+kKTSLNm1ZUpQ6Key4u7fJ8HwFxxwkaVBULc60GVffjp0dID01Z?= =?us-ascii?Q?g7FWvTFk3rwr+pMco4XWqugqecSU1GvUNPiWlVXVhceD4RGIV6qxmQPtF5Xs?= =?us-ascii?Q?G9RN9OglaD7Sa47jn3qN+Qa9xM09iGHWtMJGhunN6o03h7pA+saUMOJ1HCEu?= =?us-ascii?Q?m3x7Kv/0fTv+bcBHX1/116N85UlSdgqLNT8bcubbgwotreApMEVTPl04xnw6?= =?us-ascii?Q?61J4Ey8KYX29O7vNeW0=3D?= MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB7031.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0903403-685d-4a61-6c15-08db416cf9d5 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2023 07:00:50.6426 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 7R1XH+pUFaGoidqpEf7eyuSXJEQadZRelh+WKn3eSUNzdiRG4BCOgTVfwRdGmFZH++ykogppZZHETcSKIExdrA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7789 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Please find my comment below. Thanks, Nickle > -----Original Message----- > From: abner.chang@amd.com > Sent: Tuesday, April 18, 2023 3:16 PM > To: devel@edk2.groups.io > Cc: Isaac Oram ; Abdul Lateef Attar > ; Nickle Wang ; Igor Kulchytskyy > > Subject: [edk2-platforms][PATCH V2 09/14] ManageabilityPkg/MctpProtocol: > Add MctpProtocol >=20 > External email: Use caution opening links or attachments >=20 >=20 > From: Abner Chang >=20 > MctpProtocol that transmits MCTP message over manageability transport > interface library. >=20 > 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/MctpProtocolDxe.inf > create mode 100644 > Features/ManageabilityPkg/Include/Protocol/MctpProtocol.h > create mode 100644 > Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCo > mmon.h > create mode 100644 > Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCo > mmon.c > create mode 100644 > Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocol.c >=20 > diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc > b/Features/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 >=20 > ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.i > nf > + ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf >=20 > diff --git > a/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.in > f > b/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.in > f > new file mode 100644 > index 0000000000..483fbcc04b > --- /dev/null > +++ b/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolD > +++ xe.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-25FBE6C9797= 8 > + 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/Features/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_MAJOR << 8) |\ > + > +EDKII_MCTP_PROTOCOL_VERSION_MINOR) > + > +/** > + This service enables submitting message via EDKII MCTP protocol. > + > + @param[in] This EDKII_MCTP_PROTOCOL inst= ance. > + @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 > message has > + integrity check byte. > + @param[in] RequestData Message Data. > + @param[in] RequestDataSize Size of message Data. > + @param[in] RequestTimeout Timeout value in millise= conds. > + MANAGEABILITY_TRANSPORT_= NO_TIMEOUT means > no timeout value. > + @param[out] ResponseData Message Response Data. T= he > completion code is the first byte of response data. > + @param[in, out] ResponseDataSize Size of Message Response= Data. > + @param[in] ResponseTimeout Timeout value in millise= conds. > + MANAGEABILITY_TRANSPORT_= NO_TIMEOUT means > no timeout value. > + @param[out] AdditionalTransferError > MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS. > + > + @retval EFI_SUCCESS The message was successfully send to tr= ansport > interface and a > + response was successfully received. > + @retval EFI_NOT_FOUND The message was not successfully sent t= o > transport interface or a response > + was not successfully received from tran= sport interface. > + @retval EFI_NOT_READY MCTP transport interface is not ready f= or MCTP > message. > + @retval EFI_DEVICE_ERROR MCTP transport interface Device hardwar= e > error. > + @retval EFI_TIMEOUT The message time out. > + @retval EFI_UNSUPPORTED The message was not successfully sent t= o the > transport interface. > + @retval EFI_OUT_OF_RESOURCES The resource allocation is out of resou= rce > or data size error. > + @retval EFI_INVALID_PARAMETER Both RequestData and ResponseData are > +NULL **/ 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 > *AdditionalTransferError > + ); > + > +// > +// 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/MctpProtocol > Common.h > b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocol > Common.h > new file mode 100644 > index 0000000000..72eded719d > --- /dev/null > +++ > b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtoc > +++ olCommon.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_OUT_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_DATA_IN_REGISTER_OFFSET * 4) > +#define MCTP_KCS_REG_DATA_OUT_MEMMAP MCTP_KCS_BASE_ADDRESS + > (IPMI_KCS_DATA_OUT_REGISTER_OFFSET * 4) > +#define MCTP_KCS_REG_COMMAND_MEMMAP MCTP_KCS_BASE_ADDRESS + > (IPMI_KCS_COMMAND_REGISTER_OFFSET * 4) > +#define MCTP_KCS_REG_STATUS_MEMMAP MCTP_KCS_BASE_ADDRESS + > (IPMI_KCS_STATUS_REGISTER_OFFSET * 4) > + > +/** > + This functions setup the PLDM transport hardware information > +according > + to the specification of transport token acquired from transport librar= y. > + > + @param[in] TransportToken The transport interface. > + @param[out] HardwareInformation Pointer to receive the hardwar= e > information. > + > + @retval EFI_SUCCESS Hardware information is returned in > HardwareInformation. > + Caller must free the memory allocated f= or > HardwareInformation > + once it doesn't need it. > + @retval EFI_UNSUPPORTED No hardware information for the > specification 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 > message has > + integrity check byte. > + @param[out] PacketHeader The pointer to receive h= eader of > request. > + @param[out] PacketHeaderSize Packet header size. > + @param[in, out] PacketBody The request body. > + When IN, it is the calle= r's request body. > + When OUT and NULL, the r= equest body is not > + changed. > + Whee out and non-NULL, t= he request body is > + changed to comfort the t= ransport interface. > + @param[in, out] PacketBodySize The request body size. > + When IN and non-zero, it= is the new data > + length of request body. > + When IN and zero, the re= quest body is unchanged. > + @param[out] PacketTrailer The pointer to receive t= railer 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 > message has > + integrity check byte. > + @param[in] RequestData Message Data. > + @param[in] RequestDataSize Size of message Data. > + @param[in] RequestTimeout Timeout value in millise= conds. > + MANAGEABILITY_TRANSPORT_= NO_TIMEOUT means > no timeout value. > + @param[out] ResponseData Message Response Data. T= he > completion code is the first byte of response data. > + @param[in, out] ResponseDataSize Size of Message Response= Data. > + @param[in] ResponseTimeout Timeout value in millise= conds. > + MANAGEABILITY_TRANSPORT_= NO_TIMEOUT means > no timeout value. > + @param[out] AdditionalTransferError > MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS. > + > + @retval EFI_SUCCESS The message was successfully send to tr= ansport > interface and a > + response was successfully received. > + @retval EFI_NOT_FOUND The message was not successfully sent t= o > transport interface or a response > + was not successfully received from tran= sport interface. > + @retval EFI_NOT_READY MCTP transport interface is not ready f= or MCTP > message. > + @retval EFI_DEVICE_ERROR MCTP transport interface Device hardwar= e > error. > + @retval EFI_TIMEOUT The message time out. > + @retval EFI_UNSUPPORTED The message was not successfully sent t= o the > transport interface. > + @retval EFI_OUT_OF_RESOURCES The resource allocation is out of resou= rce > or data size error. > + @retval EFI_INVALID_PARAMETER Both RequestData and ResponseData are > +NULL **/ EFI_STATUS CommonMctpSubmitMessage ( > + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, > + IN UINT8 MctpType, > + IN UINT8 MctpSourceEndpointId= , > + IN UINT8 MctpDestinationEndpo= intId, > + IN BOOLEAN RequestDataIntegrity= Check, > + IN UINT8 *RequestData, > + IN UINT32 RequestDataSize, > + IN UINT32 RequestTimeout, > + OUT UINT8 *ResponseData, > + IN OUT UINT32 *ResponseDataSize, > + IN UINT32 ResponseTimeout, > + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS > *AdditionalTransferError > + ); > + > +#endif > diff --git > a/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocol > Common.c > b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocol > Common.c > new file mode 100644 > index 0000000000..8babdfe963 > --- /dev/null > +++ > b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtoc > +++ olCommon.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 librar= y. > + > + @param[in] TransportToken The transport interface. > + @param[out] HardwareInformation Pointer to receive the hardwar= e > information. > + > + @retval EFI_SUCCESS Hardware information is returned in > HardwareInformation. > + Caller must free the memory allocated f= or > HardwareInformation > + once it doesn't need it. > + @retval EFI_UNSUPPORTED No hardware information for the > specification 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- > >Transport->ManageabilityTransportSpecification)) { > + KcsHardwareInfo =3D AllocatePool (sizeof > (MANAGEABILITY_TRANSPORT_KCS_HARDWARE_INFO)); > + if (KcsHardwareInfo =3D=3D NULL) { > + DEBUG ((DEBUG_ERROR, "%a: Not enough memory for > MANAGEABILITY_TRANSPORT_KCS_HARDWARE_INFO.\n", __FUNCTION__)); > + return EFI_OUT_OF_RESOURCES; > + } > + > + MctpKcsMemMapIo =3D PcdGetBool (PcdMctpKcsMemoryMappedIo); > + if (MctpKcsMemMapIo) { > + KcsHardwareInfo->MemoryMap =3D > MANAGEABILITY_TRANSPORT_KCS_MEMORY_MAP_IO; > + KcsHardwareInfo->IoBaseAddress.IoAddress32 =3D > MCTP_KCS_BASE_ADDRESS; > + 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_COMMAND_MEMMAP; > + KcsHardwareInfo->IoStatusAddress.IoAddress32 =3D > MCTP_KCS_REG_STATUS_MEMMAP; > + } else { > + KcsHardwareInfo->MemoryMap =3D > MANAGEABILITY_TRANSPORT_KCS_IO_MAP_IO; > + KcsHardwareInfo->IoBaseAddress.IoAddress16 =3D > (UINT16)MCTP_KCS_BASE_ADDRESS; > + KcsHardwareInfo->IoDataInAddress.IoAddress16 =3D > (UINT16)MCTP_KCS_REG_DATA_IN_IO; > + KcsHardwareInfo->IoDataOutAddress.IoAddress16 =3D > (UINT16)MCTP_KCS_REG_DATA_OUT_IO; > + KcsHardwareInfo->IoCommandAddress.IoAddress16 =3D > (UINT16)MCTP_KCS_REG_COMMAND_IO; > + KcsHardwareInfo->IoStatusAddress.IoAddress16 =3D > (UINT16)MCTP_KCS_REG_STATUS_IO; > + } > + > + HardwareInformation->Kcs =3D KcsHardwareInfo; > + return EFI_SUCCESS; > + } else { > + DEBUG ((DEBUG_ERROR, "%a: No implementation of setting hardware > information.", __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 > message has > + integrity check byte. > + @param[out] PacketHeader The pointer to receive h= eader of > request. > + @param[out] PacketHeaderSize Packet header size. > + @param[in, out] PacketBody The request body. > + When IN, it is the calle= r's request body. > + When OUT and NULL, the r= equest body is not > + changed. > + Whee out and non-NULL, t= he request body is > + changed to comfort the t= ransport interface. > + @param[in, out] PacketBodySize The request body size. > + When IN and non-zero, it= is the new data > + length of request body. > + When IN and zero, the re= quest body is unchanged. > + @param[out] PacketTrailer The pointer to receive t= railer 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 paramete= r > is invalid.\n")); __func__ is missing in DEBUG macro. Nickle > + return EFI_INVALID_PARAMETER; > + } > + > + if (CompareGuid (&gManageabilityTransportKcsGuid, TransportToken- > >Transport->ManageabilityTransportSpecification)) { > + MctpKcsHeader =3D (MANAGEABILITY_MCTP_KCS_HEADER *)AllocateZeroPool > (sizeof (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", > __FUNCTION__)); > + FreePool (MctpKcsHeader); > + return EFI_OUT_OF_RESOURCES; > + } > + > + // Generate MCTP KCS transport header > + MctpKcsHeader->DefiningBody =3D > DEFINING_BODY_DMTF_PRE_OS_WORKING_GROUP; > + MctpKcsHeader->NetFunc =3D MCTP_KCS_NETFN_LUN; > + MctpKcsHeader->ByteCount =3D (UINT8)(MIN (mTransportMaximumPayloa= d, > *PacketBodySize + (UINT8)sizeof (MCTP_MESSAGE_HEADER) + (UINT8)sizeof > (MCTP_TRANSPORT_HEADER))); > + > + ThisPackage =3D (UINT8 *)AllocateZeroPool (MctpKcsHeader->ByteCount)= ; > + if (ThisPackage =3D=3D NULL) { > + DEBUG ((DEBUG_ERROR, "%a: Not enough resource for package.\n", > __FUNCTION__)); > + FreePool (MctpKcsHeader); > + FreePool (Pec); > + return EFI_OUT_OF_RESOURCES; > + } > + > + // Setup MCTP transport header > + MctpTransportHeader =3D (MCTP_TRANSPORT_= HEADER > *)ThisPackage; > + MctpTransportHeader->Bits.Reserved =3D 0; > + MctpTransportHeader->Bits.HeaderVersion =3D > MCTP_KCS_HEADER_VERSION; > + MctpTransportHeader->Bits.DestinationEndpointId =3D PcdGet8 > (PcdMctpDestinationEndpointId); > + MctpTransportHeader->Bits.SourceEndpointIdId =3D PcdGet8 > (PcdMctpSourceEndpointId); > + MctpTransportHeader->Bits.MessageTag =3D MCTP_MESSAGE_TAG= ; > + MctpTransportHeader->Bits.TagOwner =3D > MCTP_MESSAGE_TAG_OWNER_REQUEST; > + MctpTransportHeader->Bits.PacketSequence =3D mMctpPacketSeque= nce & > 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 > *)(MctpTransportHeader + 1); > + MctpMessageHeader->Bits.MessageType =3D MctpType; > + MctpMessageHeader->Bits.IntegrityCheck =3D RequestDataIntegrityCheck > + ? 1 : 0; > + > + // Copy payload > + CopyMem ((VOID *)(MctpMessageHeader + 1), (VOID *)*PacketBody, > + *PacketBodySize); > + > + // > + // Generate PEC follow SMBUS 2.0 specification. > + *Pec =3D HelperManageabilityGenerateCrc8 > + (MCTP_KCS_PACKET_ERROR_CODE_POLY, 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 > message has > + integrity check byte. > + @param[in] RequestData Message Data. > + @param[in] RequestDataSize Size of message Data. > + @param[in] RequestTimeout Timeout value in millise= conds. > + MANAGEABILITY_TRANSPORT_= NO_TIMEOUT means > no timeout value. > + @param[out] ResponseData Message Response Data. T= he > completion code is the first byte of response data. > + @param[in, out] ResponseDataSize Size of Message Response= Data. > + @param[in] ResponseTimeout Timeout value in millise= conds. > + MANAGEABILITY_TRANSPORT_= NO_TIMEOUT means > no timeout value. > + @param[out] AdditionalTransferError > MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS. > + > + @retval EFI_SUCCESS The message was successfully send to tr= ansport > interface and a > + response was successfully received. > + @retval EFI_NOT_FOUND The message was not successfully sent t= o > transport interface or a response > + was not successfully received from tran= sport interface. > + @retval EFI_NOT_READY MCTP transport interface is not ready f= or MCTP > message. > + @retval EFI_DEVICE_ERROR MCTP transport interface Device hardwar= e > error. > + @retval EFI_TIMEOUT The message time out. > + @retval EFI_UNSUPPORTED The message was not successfully sent t= o the > transport interface. > + @retval EFI_OUT_OF_RESOURCES The resource allocation is out of resou= rce > or data size error. > + @retval EFI_INVALID_PARAMETER Both RequestData and ResponseData are > +NULL **/ EFI_STATUS CommonMctpSubmitMessage ( > + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, > + IN UINT8 MctpType, > + IN UINT8 MctpSourceEndpointId= , > + IN UINT8 MctpDestinationEndpo= intId, > + IN BOOLEAN RequestDataIntegrity= Check, > + IN UINT8 *RequestData, > + IN UINT32 RequestDataSize, > + IN UINT32 RequestTimeout, > + OUT UINT8 *ResponseData, > + IN OUT UINT32 *ResponseDataSize, > + IN UINT32 ResponseTimeout, > + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS > *AdditionalTransferError > + ) > +{ > + 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->TransportSt= atus ( > + TransportTo= ken, > + AdditionalT= ransferError > + ); 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 packa= ges - > (%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 *)(MultiPackages + 1); for > (IndexOfPackage =3D 0; IndexOfPackage < MultiPackages->NumberOfPackages; > IndexOfPackage++) { > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "#%d: \n", IndexOfPackage)); > + DEBUG ((DEBUG_MANAGEABILITY_INFO, " Packet pointer: 0x%08x\n", > ThisPackage->PayloadPointer)); > + DEBUG ((DEBUG_MANAGEABILITY_INFO, " Packet size : 0x%08x\n", > ThisPackage->PayloadSize)); > + } > + > + ThisPackage =3D (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR > *)(MultiPackages + 1); > + mMctpPacketSequence =3D 0; > + for (IndexOfPackage =3D 0; IndexOfPackage < MultiPackages- > >NumberOfPackages; 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", > __FUNCTION__, 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 > SetupMctpRequestTransportPacket(). > + TransferToken.TransmitPackage.TransmitPayload =3D ThisPackage- > >PayloadPointer; > + TransferToken.TransmitPackage.TransmitSizeInByte =3D ThisPackage- > >PayloadSize; > + } else { > + TransferToken.TransmitPackage.TransmitPayload =3D ThisRequestDa= ta; > + TransferToken.TransmitPackage.TransmitSizeInByte =3D ThisRequestDa= taSize; > + } > + > + TransferToken.TransmitPackage.TransmitTimeoutInMillisecond =3D > + MANAGEABILITY_TRANSPORT_NO_TIMEOUT; > + > + // Receive packet. > + TransferToken.ReceivePackage.ReceiveBuffer =3D NULL; > + TransferToken.ReceivePackage.ReceiveSizeInByte =3D 0; > + TransferToken.ReceivePackage.TransmitTimeoutInMillisecond =3D > + MANAGEABILITY_TRANSPORT_NO_TIMEOUT; > + > + // Print out MCTP packet. > + DEBUG (( > + DEBUG_MANAGEABILITY_INFO, > + "%a: Send MCTP message type: 0x%x, from source endpoint ID: 0x%x t= o > 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- > >TransportTransmitReceive ( > + 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 Response= Data; > + TransferToken.ReceivePackage.ReceiveSizeInByte =3D *Respons= eDataSize; > + TransferToken.TransmitHeader =3D NULL; > + TransferToken.TransmitHeaderSize =3D 0; > + TransferToken.TransmitTrailer =3D NULL; > + TransferToken.TransmitTrailerSize =3D 0; > + TransferToken.ReceivePackage.TransmitTimeoutInMillisecond =3D > + MANAGEABILITY_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.ReceiveSizeI= nByte; > + 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/MctpProtocol.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 inst= ance. > + @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 > message has > + integrity check byte. > + @param[in] RequestData Message Data. > + @param[in] RequestDataSize Size of message Data. > + @param[in] RequestTimeout Timeout value in millise= conds. > + MANAGEABILITY_TRANSPORT_= NO_TIMEOUT means > no timeout value. > + @param[out] ResponseData Message Response Data. T= he > completion code is the first byte of response data. > + @param[in, out] ResponseDataSize Size of Message Response= Data. > + @param[in] ResponseTimeout Timeout value in millise= conds. > + MANAGEABILITY_TRANSPORT_= NO_TIMEOUT means > no timeout value. > + @param[out] AdditionalTransferError > MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS. > + > + @retval EFI_SUCCESS The message was successfully send to tr= ansport > interface and a > + response was successfully received. > + @retval EFI_NOT_FOUND The message was not successfully sent t= o > transport interface or a response > + was not successfully received from tran= sport interface. > + @retval EFI_NOT_READY MCTP transport interface is not ready f= or MCTP > message. > + @retval EFI_DEVICE_ERROR MCTP transport interface Device hardwar= e > error. > + @retval EFI_TIMEOUT The message time out. > + @retval EFI_UNSUPPORTED The message was not successfully sent t= o the > transport interface. > + @retval EFI_OUT_OF_RESOURCES The resource allocation is out of resou= rce > or data size error. > + @retval EFI_INVALID_PARAMETER Both RequestData and ResponseData are > +NULL **/ EFI_STATUS EFIAPI MctpSubmitMessage ( > + IN EDKII_MCTP_PROTOCOL *This, > + IN UINT8 MctpType, > + IN UINT8 MctpSourceEndpointId= , > + IN UINT8 MctpDestinationEndpo= intId, > + IN BOOLEAN RequestDataIntegrity= Check, > + IN UINT8 *RequestData, > + IN UINT32 RequestDataSize, > + IN UINT32 RequestTimeout, > + OUT UINT8 *ResponseData, > + IN OUT UINT32 *ResponseDataSize, > + IN UINT32 ResponseTimeout, > + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS > *AdditionalTransferError > + ) > +{ > + 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 = MCTP > protocol - %r\n", __FUNCTION__, Status)); > + return Status; > + } > + > + Status =3D GetTransportCapability (mTransportToken, > + &TransportCapability); if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", > __FUNCTION__)); > + return Status; > + } > + > + mTransportMaximumPayload =3D > + MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY > (TransportCapability); if (mTransportMaximumPayload =3D=3D (1 << > MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILA > BLE)) { > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%a: Transport interface maximum > + payload is undefined.\n", __FUNCTION__)); } else { > + mTransportMaximumPayload -=3D 1; > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%a: Transport interface for MCTP > + protocol has maximum payload 0x%x.\n", __FUNCTION__, > + mTransportMaximumPayload)); } > + > + mTransportName =3D HelperManageabilitySpecName > + (mTransportToken->Transport->ManageabilityTransportSpecification); > + DEBUG ((DEBUG_ERROR, "%a: MCTP protocol over %s.\n", __FUNCTION__, > + mTransportName)); > + > + // > + // 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 > interface.\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; > +} > -- > 2.37.1.windows.1