public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-platforms][PATCH 00/14] ManageabilityPkg part II
@ 2023-04-03 15:04 Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 01/14] ManageabilityPkg: Add more helper functions Chang, Abner
                   ` (13 more replies)
  0 siblings, 14 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel
  Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy,
	Tinh Nguyen

From: Abner Chang <abner.chang@amd.com>

In part II, we had implemented
- PLDM protocol
- MCTP protocol
- PLDM SMBIOS Transfer protocol
- MCTP manageability transport interface
- Support maximum transfer unit of transport interface
- Add more heler functions
- Add two new fields HeaderSize and TrailerSize in
  MANAGEABILITY_TRANSFER_TOKEN structure.
- Add PCDs to build the manageability modules.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Tinh Nguyen <tinhnguyen@amperemail.onmicrosoft.com>

Abner Chang (9):
  ManageabilityPkg: Add more helper functions
  ManageabilityPkg: Support Maximum Transfer Unit
  ManageabilityPkg: Fix Uncrustify errors
  ManageabilityPkg: Add HeaderSize and TrailerSize
  ManageabilityPkg: Add PldmProtocolLib
  ManageabilityPkg/KCS: KCS transport interface
  ManageabilityPkg/MctpProtocol: Add MctpProtocol
  ManageabilityPkg: Add MCTP transport interface
  ManageabilityPkg/PldmProtocol: Add PLDM protocol

abnchang (5):
  ManageabilityPkg: Add PldmSmbiosTransferDxe driver
  ManageabilityPkg: Add definitions of MCTP
  ManageabilityPkg: Add Manageability PCDs
  ManageabilityPkg: Relocate Manageability.dsc
  ManageabilityPkg: Add Manageability FDFs

 .../ManageabilityPkg/ManageabilityPkg.dec     |  28 +
 .../Include/{Dsc => }/Manageability.dsc       |  21 +
 .../ManageabilityPkg/ManageabilityPkg.dsc     |  14 +-
 .../ManageabilityPkg/Include/PostMemory.fdf   |  28 +
 .../ManageabilityPkg/Include/PreMemory.fdf    |  12 +
 .../BaseManageabilityTransportHelper.inf      |   1 +
 .../Dxe/DxeManageabilityTransportMctp.inf     |  44 ++
 .../Dxe/PldmProtocolLib.inf                   |  42 ++
 .../MctpProtocol/Dxe/MctpProtocolDxe.inf      |  53 ++
 .../PldmProtocol/Dxe/PldmProtocolDxe.inf      |  50 ++
 .../PldmSmbiosTransferDxe.inf                 |  47 ++
 .../Include/Library/BasePldmProtocolLib.h     |  41 ++
 .../Library/ManageabilityTransportHelperLib.h |  98 ++++
 .../Library/ManageabilityTransportLib.h       |  35 +-
 .../Library/ManageabilityTransportMctpLib.h   |  54 ++
 .../Include/Protocol/MctpProtocol.h           | 102 ++++
 .../Include/Protocol/PldmProtocol.h           |  87 +++
 .../Protocol/PldmSmbiosTransferProtocol.h     | 184 +++++++
 .../Common/ManageabilityTransportKcs.h        |  22 +-
 .../Dxe/ManageabilityTransportMctp.h          |  26 +
 .../IpmiProtocol/Common/IpmiProtocolCommon.h  |  36 +-
 .../IpmiProtocol/Pei/IpmiPpiInternal.h        |   8 +-
 .../MctpProtocol/Common/MctpProtocolCommon.h  | 139 +++++
 .../PldmProtocol/Common/PldmProtocolCommon.h  | 109 ++++
 .../BaseManageabilityTransportHelper.c        | 218 +++++++-
 .../BaseManageabilityTransportNull.c          |  18 +-
 .../Common/KcsCommon.c                        | 207 ++++---
 .../Dxe/ManageabilityTransportKcs.c           |  61 ++-
 .../Dxe/ManageabilityTransportMctp.c          | 367 +++++++++++++
 .../PldmProtocolLibrary/Dxe/PldmProtocolLib.c |  87 +++
 .../IpmiProtocol/Common/IpmiProtocolCommon.c  |  63 ++-
 .../Universal/IpmiProtocol/Dxe/IpmiProtocol.c |  22 +-
 .../Universal/IpmiProtocol/Pei/IpmiPpi.c      |  49 +-
 .../Universal/IpmiProtocol/Smm/IpmiProtocol.c |  22 +-
 .../MctpProtocol/Common/MctpProtocolCommon.c  | 461 ++++++++++++++++
 .../Universal/MctpProtocol/Dxe/MctpProtocol.c | 216 ++++++++
 .../PldmProtocol/Common/PldmProtocolCommon.c  | 432 +++++++++++++++
 .../Universal/PldmProtocol/Dxe/PldmProtocol.c | 181 ++++++
 .../PldmSmbiosTransferDxe.c                   | 518 ++++++++++++++++++
 Features/ManageabilityPkg/Readme.md           |  10 +
 .../Dxe/ManageabilityTransportMctp.uni        |  13 +
 .../Dxe/PldmProtocolLib.uni                   |  18 +
 42 files changed, 4050 insertions(+), 194 deletions(-)
 rename Features/ManageabilityPkg/Include/{Dsc => }/Manageability.dsc (50%)
 create mode 100644 Features/ManageabilityPkg/Include/PostMemory.fdf
 create mode 100644 Features/ManageabilityPkg/Include/PreMemory.fdf
 create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/DxeManageabilityTransportMctp.inf
 create mode 100644 Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
 create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf
 create mode 100644 Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
 create mode 100644 Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf
 create mode 100644 Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
 create mode 100644 Features/ManageabilityPkg/Include/Library/ManageabilityTransportMctpLib.h
 create mode 100644 Features/ManageabilityPkg/Include/Protocol/MctpProtocol.h
 create mode 100644 Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
 create mode 100644 Features/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol.h
 create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h
 create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.h
 create mode 100644 Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h
 create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.c
 create mode 100644 Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
 create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.c
 create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocol.c
 create mode 100644 Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.c
 create mode 100644 Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c
 create mode 100644 Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c
 create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.uni
 create mode 100644 Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.uni

-- 
2.37.1.windows.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 01/14] ManageabilityPkg: Add more helper functions
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-10 17:23   ` [edk2-devel] " Tinh Nguyen
  2023-04-03 15:04 ` [edk2-platforms][PATCH 02/14] ManageabilityPkg: Support Maximum Transfer Unit Chang, Abner
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: Abner Chang <abner.chang@amd.com>

1. Add a helper function to output payload binary
   to debug output device.
2. Add a helper function to split payload into
   packages according to maximum transfer unit
   of transport interface.
3. Add a helper function to generate CRC8.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../BaseManageabilityTransportHelper.inf      |   1 +
 .../Library/ManageabilityTransportHelperLib.h |  98 ++++++++
 .../BaseManageabilityTransportHelper.c        | 218 +++++++++++++++++-
 3 files changed, 310 insertions(+), 7 deletions(-)

diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf
index 95c3362ddb..c31a89aa49 100644
--- a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf
+++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf
@@ -25,6 +25,7 @@
 [LibraryClasses]
   BaseMemoryLib
   DebugLib
+  MemoryAllocationLib
 
 [Packages]
   ManageabilityPkg/ManageabilityPkg.dec
diff --git a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h
index 718ac34a1f..0dbf5ccb3c 100644
--- a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h
+++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h
@@ -11,8 +11,24 @@
 
 #include <Library/ManageabilityTransportLib.h>
 
+#define DEBUG_MANAGEABILITY_INFO  DEBUG_INFO
+
 typedef struct _MANAGEABILITY_PROTOCOL_NAME MANAGEABILITY_PROTOCOL_NAME;
 
+typedef struct {
+  UINT8     *PayloadPointer;
+  UINT32    PayloadSize;
+} MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR;
+
+//
+// The information of multi portions of payload it is
+// splitted according to transport interface Maximum
+// Transfer Unit.
+typedef struct {
+  UINT16                                     NumberOfPackages; ///< Number of packages in MultiPackages.
+  MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR    MultiPackages[];
+} MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES;
+
 /**
   Helper function returns the human readable name of Manageability specification.
 
@@ -90,4 +106,86 @@ HelperInitManageabilityTransport (
   OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS     *TransportAdditionalStatus OPTIONAL
   );
 
+/**
+  This function splits payload into multiple packages according to
+  the given transport interface Maximum Transfer Unit (MTU).
+
+  @param[in]  PreambleSize         The additional data size precedes
+                                   each package.
+  @param[in]  PostambleSize        The additional data size succeeds
+                                   each package.
+  @param[in]  Payload              Pointer to payload.
+  @param[in]  PayloadSize          Payload size in byte.
+  @param[in]  MaximumTransferUnit  MTU of transport interface.
+  @param[out] MultiplePackages     Pointer to receive
+                                   MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
+                                   structure. Caller has to free the memory
+                                   allocated for MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES.
+
+  @retval   EFI_SUCCESS          MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure
+                                 is returned successfully.
+  @retval   EFI_OUT_OF_RESOURCE  Not enough resource to create
+                                 MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure.
+**/
+EFI_STATUS
+HelperManageabilitySplitPayload (
+  IN UINT16                                      PreambleSize,
+  IN UINT16                                      PostambleSize,
+  IN UINT8                                       *Payload,
+  IN UINT32                                      PayloadSize,
+  IN UINT32                                      MaximumTransferUnit,
+  OUT MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES  **MultiplePackages
+  );
+
+/**
+  This function generates CRC8 with given polynomial.
+
+  @param[in]  Polynomial       Polynomial in 8-bit.
+  @param[in]  CrcInitialValue  CRC initial value.
+  @param[in]  BufferStart      Pointer to buffer starts the CRC calculation.
+  @param[in]  BufferSize       Size of buffer.
+
+  @retval  UINT8 CRC value.
+**/
+UINT8
+HelperManageabilityGenerateCrc8 (
+  IN UINT8   Polynomial,
+  IN UINT8   CrcInitialValue,
+  IN UINT8   *BufferStart,
+  IN UINT32  BufferSize
+  );
+
+/**
+  Print out manageability transmit payload to the debug output device.
+
+  @param[in]  Payload      Payload to print.
+  @param[in]  PayloadSize  Payload size.
+
+**/
+VOID
+EFIAPI
+HelperManageabilityPayLoadDebugPrint (
+  IN  VOID    *Payload,
+  IN  UINT32  PayloadSize
+  );
+
+/**
+  Prints a debug message and manageability payload to the debug output device.
+
+  @param[in]  Payload      Payload to print.
+  @param[in]  PayloadSize  Payload size.
+  @param[in]  Format       The format string for the debug message to print.
+  @param[in]  ...          The variable argument list whose contents are accessed
+                           based on the format string specified by Format.
+
+**/
+VOID
+EFIAPI
+HelperManageabilityDebugPrint (
+  IN  VOID         *Payload,
+  IN  UINT32       PayloadSize,
+  IN  CONST CHAR8  *Format,
+  ...
+  );
+
 #endif
diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c
index 81da209764..9d20ed49ff 100644
--- a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c
+++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c
@@ -8,11 +8,12 @@
 #include <Uefi.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
 #include <Library/ManageabilityTransportHelperLib.h>
 
 //
 // BaseManageabilityTransportHelper is used by PEI, DXE and SMM.
-// Make sure the global variables added here should be unchangable.
+// Make sure the global variables added here should be unchangeable.
 //
 MANAGEABILITY_SPECIFICATION_NAME  ManageabilitySpecNameTable[] = {
   { &gManageabilityTransportKcsGuid,    L"KCS"     },
@@ -47,8 +48,8 @@ HelperManageabilitySpecName (
     return NULL;
   }
 
-  if (SpecificationGuid == NULL || IsZeroGuid (SpecificationGuid)) {
-    DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__));
+  if ((SpecificationGuid == NULL) || IsZeroGuid (SpecificationGuid)) {
+    DEBUG ((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__));
     return NULL;
   }
 
@@ -99,12 +100,13 @@ HelperManageabilityCheckSupportedSpec (
     return EFI_INVALID_PARAMETER;
   }
 
-  if (TransportGuid == NULL ||
+  if ((TransportGuid == NULL) ||
       IsZeroGuid (TransportGuid) ||
-      ManageabilityProtocolToCheck == NULL ||
+      (ManageabilityProtocolToCheck == NULL) ||
       IsZeroGuid (ManageabilityProtocolToCheck)
-      ) {
-      DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__));
+      )
+  {
+    DEBUG ((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__));
     return EFI_INVALID_PARAMETER;
   }
 
@@ -259,3 +261,205 @@ HelperInitManageabilityTransport (
 
   return Status;
 }
+
+/**
+  This function generates CRC8 with given polynomial.
+
+  @param[in]  Polynomial       Polynomial in 8-bit.
+  @param[in]  CrcInitialValue  CRC initial value.
+  @param[in]  BufferStart      Pointer to buffer starts the CRC calculation.
+  @param[in]  BufferSize       Size of buffer.
+
+  @retval  UINT8 CRC value.
+**/
+UINT8
+HelperManageabilityGenerateCrc8 (
+  IN UINT8   Polynomial,
+  IN UINT8   CrcInitialValue,
+  IN UINT8   *BufferStart,
+  IN UINT32  BufferSize
+  )
+{
+  UINT8   BitIndex;
+  UINT32  BufferIndex;
+
+  BufferIndex = 0;
+  while (BufferIndex < BufferSize) {
+    CrcInitialValue = CrcInitialValue ^ *(BufferStart + BufferIndex);
+    BufferIndex++;
+
+    for (BitIndex = 0; BitIndex < 8; BitIndex++) {
+      if ((CrcInitialValue & 0x80) != 0) {
+        CrcInitialValue = (CrcInitialValue << 1) ^ Polynomial;
+      } else {
+        CrcInitialValue <<= 1;
+      }
+    }
+  }
+
+  return CrcInitialValue;
+}
+
+/**
+  This function splits payload into multiple packages according to
+  the given transport interface Maximum Transfer Unit (MTU).
+
+
+  @param[in]  PreambleSize         The additional data size precedes
+                                   each package.
+  @param[in]  PostambleSize        The additional data size succeeds
+                                   each package.
+  @param[in]  Payload              Pointer to payload.
+  @param[in]  PayloadSize          Payload size in byte.
+  @param[in]  MaximumTransferUnit  MTU of transport interface.
+  @param[out] MultiplePackages     Pointer to receive
+                                   MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
+                                   structure. Caller has to free the memory
+                                   allocated for MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES.
+
+  @retval   EFI_SUCCESS          MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure
+                                 is returned successfully.
+  @retval   EFI_OUT_OF_RESOURCE  Not enough resource to create
+                                 MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure.
+**/
+EFI_STATUS
+HelperManageabilitySplitPayload (
+  IN UINT16                                      PreambleSize,
+  IN UINT16                                      PostambleSize,
+  IN UINT8                                       *Payload,
+  IN UINT32                                      PayloadSize,
+  IN UINT32                                      MaximumTransferUnit,
+  OUT MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES  **MultiplePackages
+  )
+{
+  UINT16                                     NumberOfPackages;
+  UINT16                                     IndexOfPackage;
+  UINT32                                     PackagePayloadSize;
+  UINT32                                     TotalPayloadRemaining;
+  MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES  *ThisMultiplePackages;
+  MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR    *ThisPackage;
+
+  if ((INT16)(MaximumTransferUnit - PreambleSize - PostambleSize) < 0) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: (Preamble 0x%x + PostambleSize 0x%x) is greater than MaximumTransferUnit 0x%x.\n",
+      __FUNCTION__,
+      PreambleSize,
+      PostambleSize,
+      MaximumTransferUnit
+      ));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  PackagePayloadSize   = MaximumTransferUnit -PreambleSize - PostambleSize;
+  NumberOfPackages     = (UINT16)((PayloadSize + (PackagePayloadSize - 1)) / PackagePayloadSize);
+  ThisMultiplePackages = (MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES *)AllocateZeroPool (
+                                                                        sizeof (MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES) +
+                                                                        sizeof (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR) * NumberOfPackages
+                                                                        );
+  if (ThisMultiplePackages == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Not enough memory for MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ThisMultiplePackages->NumberOfPackages = NumberOfPackages;
+  ThisPackage                            = (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *)(ThisMultiplePackages + 1);
+  TotalPayloadRemaining                  = PayloadSize;
+  for (IndexOfPackage = 0; IndexOfPackage < NumberOfPackages; IndexOfPackage++) {
+    ThisPackage->PayloadPointer = Payload + (IndexOfPackage * PackagePayloadSize);
+    ThisPackage->PayloadSize    = MIN (TotalPayloadRemaining, PackagePayloadSize);
+    TotalPayloadRemaining      -= ThisPackage->PayloadSize;
+    ThisPackage++;
+  }
+
+  if (TotalPayloadRemaining != 0) {
+    DEBUG ((DEBUG_ERROR, "%a: Error processing multiple packages (TotalPayloadRemaining != 0)\n", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *MultiplePackages = ThisMultiplePackages;
+  return EFI_SUCCESS;
+}
+
+/**
+  Print out manageability transmit payload to the debug output device.
+
+  @param[in]  Payload      Payload to print.
+  @param[in]  PayloadSize  Payload size.
+
+**/
+VOID
+EFIAPI
+HelperManageabilityPayLoadDebugPrint (
+  IN  VOID    *Payload,
+  IN  UINT32  PayloadSize
+  )
+{
+  UINT16  Page256;
+  UINT16  Row16;
+  UINT16  Column16;
+  UINT32  RemainingBytes;
+  UINT32  TotalBytePrinted;
+
+  RemainingBytes   = PayloadSize;
+  TotalBytePrinted = 0;
+  while (TRUE) {
+    if (TotalBytePrinted % 256 == 0) {
+      Page256 = (UINT16)TotalBytePrinted / 256;
+      DEBUG ((DEBUG_MANAGEABILITY_INFO, "======== Manageability Payload %04xH - %04xH =========\n", Page256 * 256, Page256 * 256 + MIN (RemainingBytes, 256) - 1));
+      DEBUG ((DEBUG_MANAGEABILITY_INFO, "       "));
+      for (Column16 = 0; Column16 < 16; Column16++) {
+        DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", Column16));
+      }
+
+      DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n       -----------------------------------------------\n"));
+    }
+
+    for (Row16 = 0; Row16 < 16; Row16++) {
+      DEBUG ((DEBUG_MANAGEABILITY_INFO, "%04x | ", Page256 * 256 + Row16 * 16));
+      for (Column16 = 0; Column16 < MIN (RemainingBytes, 16); Column16++) {
+        DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", *((UINT8 *)Payload + Page256 * 256 + Row16 * 16 + Column16)));
+      }
+
+      RemainingBytes   -= Column16;
+      TotalBytePrinted += Column16;
+      if (RemainingBytes == 0) {
+        DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n"));
+        return;
+      }
+      DEBUG((DEBUG_MANAGEABILITY_INFO, "\n"));
+    }
+
+    DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n"));
+  }
+
+  DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n"));
+}
+
+/**
+  Prints a debug message and manageability payload to the debug output device.
+
+  @param[in]  Payload      Payload to print.
+  @param[in]  PayloadSize  Payload size.
+  @param[in]  Format       The format string for the debug message to print.
+  @param[in]  ...          The variable argument list whose contents are accessed
+                           based on the format string specified by Format.
+
+**/
+VOID
+EFIAPI
+HelperManageabilityDebugPrint (
+  IN  VOID         *Payload,
+  IN  UINT32       PayloadSize,
+  IN  CONST CHAR8  *Format,
+  ...
+  )
+{
+  VA_LIST  Marker;
+
+  VA_START (Marker, Format);
+  DEBUG ((DEBUG_MANAGEABILITY_INFO, "Manageability Transmission: "));
+  DebugVPrint ((UINTN)DEBUG_MANAGEABILITY_INFO, Format, Marker);
+  HelperManageabilityPayLoadDebugPrint (Payload, PayloadSize);
+  VA_END (Marker);
+}
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 02/14] ManageabilityPkg: Support Maximum Transfer Unit
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 01/14] ManageabilityPkg: Add more helper functions Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 03/14] ManageabilityPkg: Fix Uncrustify errors Chang, Abner
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: Abner Chang <abner.chang@amd.com>

Update GetTransportCapability to support
Maximum Transfer Unit (MTU) of transport interface.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../Library/ManageabilityTransportLib.h       | 31 ++++++++++++++-----
 .../Common/ManageabilityTransportKcs.h        |  2 ++
 .../IpmiProtocol/Pei/IpmiPpiInternal.h        |  8 +++--
 .../BaseManageabilityTransportNull.c          | 18 +++++++----
 .../Dxe/ManageabilityTransportKcs.c           | 25 +++++++++------
 .../Universal/IpmiProtocol/Dxe/IpmiProtocol.c | 20 +++++++++---
 .../Universal/IpmiProtocol/Pei/IpmiPpi.c      | 15 +++++++--
 .../Universal/IpmiProtocol/Smm/IpmiProtocol.c | 21 ++++++++++---
 8 files changed, 103 insertions(+), 37 deletions(-)

diff --git a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
index c022b4ac5c..ad6cd1a464 100644
--- a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
+++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
@@ -14,6 +14,9 @@
 #define MANAGEABILITY_TRANSPORT_TOKEN_VERSION        ((MANAGEABILITY_TRANSPORT_TOKEN_VERSION_MAJOR << 8) |\
                                                 MANAGEABILITY_TRANSPORT_TOKEN_VERSION_MINOR)
 
+#define MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(a)  (1 << ((a & MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_MASK) >>\
+           MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POSITION))
+
 typedef struct  _MANAGEABILITY_TRANSPORT_FUNCTION_V1_0  MANAGEABILITY_TRANSPORT_FUNCTION_V1_0;
 typedef struct  _MANAGEABILITY_TRANSPORT                MANAGEABILITY_TRANSPORT;
 typedef struct  _MANAGEABILITY_TRANSPORT_TOKEN          MANAGEABILITY_TRANSPORT_TOKEN;
@@ -68,8 +71,17 @@ typedef UINT32 MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS;
 /// Additional transport interface features.
 ///
 typedef UINT32 MANAGEABILITY_TRANSPORT_CAPABILITY;
+/// Bit 0
 #define MANAGEABILITY_TRANSPORT_CAPABILITY_MULTIPLE_TRANSFER_TOKENS  0x00000001
+/// Bit 1
 #define MANAGEABILITY_TRANSPORT_CAPABILITY_ASYNCHRONOUS_TRANSFER     0x00000002
+/// Bit 2   - Reserved
+/// Bit 7:3 - Transport interface maximum payload size, which is (2 ^ bit[7:3] - 1)
+///           bit[7:3] means no maximum payload.
+#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_MASK          0x000000f8
+#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POSITION  3
+  #define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE  0x00
+/// Bit 8:31 - Reserved
 
 ///
 /// Definitions of Manageability transport interface functions.
@@ -187,15 +199,20 @@ AcquireTransportSession (
   );
 
 /**
-  This function returns the transport capabilities.
-
-  @param [out]  TransportFeature        Pointer to receive transport capabilities.
-                                        See the definitions of
-                                        MANAGEABILITY_TRANSPORT_CAPABILITY.
-
+  This function returns the transport capabilities according to
+  the manageability protocol.
+
+  @param [in]   TransportToken             Transport token acquired from manageability
+                                           transport library.
+  @param [out]  TransportFeature           Pointer to receive transport capabilities.
+                                           See the definitions of
+                                           MANAGEABILITY_TRANSPORT_CAPABILITY.
+  @retval       EFI_SUCCESS                TransportCapability is returned successfully.
+  @retval       EFI_INVALID_PARAMETER      TransportToken is not a valid token.
 **/
-VOID
+EFI_STATUS
 GetTransportCapability (
+  IN MANAGEABILITY_TRANSPORT_TOKEN        *TransportToken,
   OUT MANAGEABILITY_TRANSPORT_CAPABILITY  *TransportCapability
   );
 
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h
index f1758ffd8f..2cdf60ba7e 100644
--- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h
@@ -32,6 +32,8 @@ typedef struct {
 #define IPMI_KCS_GET_STATE(s)  (s >> 6)
 #define IPMI_KCS_SET_STATE(s)  (s << 6)
 
+#define MCTP_KCS_MTU_IN_POWER_OF_2  8
+
 /// 5 sec, according to IPMI spec
 #define IPMI_KCS_TIMEOUT_5_SEC  5000*1000
 #define IPMI_KCS_TIMEOUT_1MS    1000
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h
index bbe0c8c5cb..7b6ab0f529 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h
@@ -17,9 +17,11 @@
 #define MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK(a)  CR (a, PEI_IPMI_PPI_INTERNAL, PeiIpmiPpi, MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE)
 
 typedef struct {
-  UINT32                         Signature;
-  MANAGEABILITY_TRANSPORT_TOKEN  *TransportToken;
-  PEI_IPMI_PPI                   PeiIpmiPpi;
+  UINT32                              Signature;
+  MANAGEABILITY_TRANSPORT_TOKEN       *TransportToken;
+  MANAGEABILITY_TRANSPORT_CAPABILITY  TransportCapability;
+  UINT32                              TransportMaximumPayload;
+  PEI_IPMI_PPI                        PeiIpmiPpi;
 } PEI_IPMI_PPI_INTERNAL;
 
 #endif // MANAGEABILITY_IPMI_PPI_INTERNAL_H_
diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportNullLib/BaseManageabilityTransportNull.c b/Features/ManageabilityPkg/Library/BaseManageabilityTransportNullLib/BaseManageabilityTransportNull.c
index 49fc8c0f71..3aa68578a6 100644
--- a/Features/ManageabilityPkg/Library/BaseManageabilityTransportNullLib/BaseManageabilityTransportNull.c
+++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportNullLib/BaseManageabilityTransportNull.c
@@ -31,19 +31,25 @@ AcquireTransportSession (
 }
 
 /**
-  This function returns the transport capabilities.
-
-  @param [out]  TransportFeature        Pointer to receive transport capabilities.
-                                        See the definitions of
-                                        MANAGEABILITY_TRANSPORT_CAPABILITY.
+  This function returns the transport capabilities according to
+  the manageability protocol.
 
+  @param [in]   TransportToken             Transport token acquired from manageability
+                                           transport library.
+  @param [out]  TransportFeature           Pointer to receive transport capabilities.
+                                           See the definitions of
+                                           MANAGEABILITY_TRANSPORT_CAPABILITY.
+  @retval       EFI_SUCCESS                TransportCapability is returned successfully.
+  @retval       EFI_INVALID_PARAMETER      TransportToken is not a valid token.
 **/
-VOID
+EFI_STATUS
 GetTransportCapability (
+  IN MANAGEABILITY_TRANSPORT_TOKEN        *TransportToken,
   OUT MANAGEABILITY_TRANSPORT_CAPABILITY  *TransportCapability
   )
 {
   *TransportCapability = 0;
+  return EFI_SUCCESS;
 }
 
 /**
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
index ab416e5449..25d6e49886 100644
--- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
@@ -329,21 +329,28 @@ AcquireTransportSession (
 }
 
 /**
-  This function returns the transport capabilities.
-
-  @param [out]  TransportFeature        Pointer to receive transport capabilities.
-                                        See the definitions of
-                                        MANAGEABILITY_TRANSPORT_CAPABILITY.
-
+  This function returns the transport capabilities according to
+  the manageability protocol.
+
+  @param [in]   TransportToken             Transport token acquired from manageability
+                                           transport library.
+  @param [out]  TransportFeature           Pointer to receive transport capabilities.
+                                           See the definitions of
+                                           MANAGEABILITY_TRANSPORT_CAPABILITY.
+  @retval       EFI_SUCCESS                TransportCapability is returned successfully.
+  @retval       EFI_INVALID_PARAMETER      TransportToken is not a valid token.
 **/
-VOID
+EFI_STATUS
 GetTransportCapability (
+  IN MANAGEABILITY_TRANSPORT_TOKEN        *TransportToken,
   OUT MANAGEABILITY_TRANSPORT_CAPABILITY  *TransportCapability
   )
 {
-  if (TransportCapability != NULL) {
-    *TransportCapability = 0;
+  if (TransportToken == NULL || TransportCapability == NULL) {
+    return EFI_INVALID_PARAMETER;
   }
+  *TransportCapability = 0;
+  return EFI_SUCCESS;
 }
 
 /**
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
index 05175ee448..c30132419d 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
@@ -17,9 +17,9 @@
 
 #include "IpmiProtocolCommon.h"
 
-MANAGEABILITY_TRANSPORT_TOKEN  *mTransportToken = NULL;
-CHAR16                         *mTransportName;
-
+MANAGEABILITY_TRANSPORT_TOKEN                 *mTransportToken = NULL;
+CHAR16                                        *mTransportName;
+UINT32                                        TransportMaximumPayload;
 MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION  mHardwareInformation;
 
 /**
@@ -92,8 +92,6 @@ DxeIpmiEntry (
   MANAGEABILITY_TRANSPORT_CAPABILITY         TransportCapability;
   MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS  TransportAdditionalStatus;
 
-  GetTransportCapability (&TransportCapability);
-
   Status = HelperAcquireManageabilityTransport (
              &gManageabilityProtocolIpmiGuid,
              &mTransportToken
@@ -102,6 +100,18 @@ DxeIpmiEntry (
     DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for IPMI protocol - %r\n", __FUNCTION__, Status));
     return Status;
   }
+  Status = GetTransportCapability (mTransportToken, &TransportCapability);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
+    return Status;
+  }
+  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(TransportCapability);
+  if (TransportMaximumPayload == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
+    DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
+  } else {
+    TransportMaximumPayload -= 1;
+    DEBUG ((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload %x.\n", __FUNCTION__, TransportMaximumPayload));
+  }
 
   mTransportName = HelperManageabilitySpecName (mTransportToken->Transport->ManageabilityTransportSpecification);
   DEBUG ((DEBUG_INFO, "%a: IPMI protocol over %s.\n", __FUNCTION__, mTransportName));
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
index f839cd7387..0dda6d2d47 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
@@ -87,7 +87,6 @@ PeiIpmiEntry (
   CHAR16                                        *TransportName;
   PEI_IPMI_PPI_INTERNAL                         *PeiIpmiPpiinternal;
   EFI_PEI_PPI_DESCRIPTOR                        *PpiDescriptor;
-  MANAGEABILITY_TRANSPORT_CAPABILITY            TransportCapability;
   MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS     TransportAdditionalStatus;
   MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION  HardwareInformation;
 
@@ -109,7 +108,6 @@ PeiIpmiEntry (
   PpiDescriptor->Guid  = &gPeiIpmiPpiGuid;
   PpiDescriptor->Ppi   = &PeiIpmiPpiinternal->PeiIpmiPpi;
 
-  GetTransportCapability (&TransportCapability);
   Status = HelperAcquireManageabilityTransport (
              &gManageabilityProtocolIpmiGuid,
              &PeiIpmiPpiinternal->TransportToken
@@ -118,6 +116,19 @@ PeiIpmiEntry (
     DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for IPMI protocol - %r\n", __FUNCTION__, Status));
     return Status;
   }
+  Status = GetTransportCapability (PeiIpmiPpiinternal->TransportToken, &PeiIpmiPpiinternal->TransportCapability);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
+    return Status;
+  }
+
+  PeiIpmiPpiinternal->TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(PeiIpmiPpiinternal->TransportCapability);
+  if (PeiIpmiPpiinternal->TransportMaximumPayload  == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
+    DEBUG((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
+  } else {
+    PeiIpmiPpiinternal->TransportMaximumPayload -= 1;
+    DEBUG((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, PeiIpmiPpiinternal->TransportMaximumPayload));
+  }
 
   TransportName = HelperManageabilitySpecName (PeiIpmiPpiinternal->TransportToken->Transport->ManageabilityTransportSpecification);
   DEBUG ((DEBUG_INFO, "%a: IPMI protocol over %s.\n", __FUNCTION__, TransportName));
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
index 87a5436bdf..86dee2fa24 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
@@ -18,9 +18,9 @@
 
 #include "IpmiProtocolCommon.h"
 
-MANAGEABILITY_TRANSPORT_TOKEN  *mTransportToken = NULL;
-CHAR16                         *mTransportName;
-
+MANAGEABILITY_TRANSPORT_TOKEN                 *mTransportToken = NULL;
+CHAR16                                        *mTransportName;
+UINT32                                        TransportMaximumPayload;
 MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION  mHardwareInformation;
 
 /**
@@ -93,8 +93,6 @@ SmmIpmiEntry (
   MANAGEABILITY_TRANSPORT_CAPABILITY         TransportCapability;
   MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS  TransportAdditionalStatus;
 
-  GetTransportCapability (&TransportCapability);
-
   Status = HelperAcquireManageabilityTransport (
              &gManageabilityProtocolIpmiGuid,
              &mTransportToken
@@ -104,6 +102,19 @@ SmmIpmiEntry (
     return Status;
   }
 
+  Status = GetTransportCapability (mTransportToken, &TransportCapability);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
+    return Status;
+  }
+  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(TransportCapability);
+  if (TransportMaximumPayload == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
+    DEBUG((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
+  } else {
+    TransportMaximumPayload -= 1;
+    DEBUG((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, TransportMaximumPayload));
+  }
+
   mTransportName = HelperManageabilitySpecName (mTransportToken->Transport->ManageabilityTransportSpecification);
   DEBUG ((DEBUG_INFO, "%a: IPMI protocol over %s.\n", __FUNCTION__, mTransportName));
 
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 03/14] ManageabilityPkg: Fix Uncrustify errors
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 01/14] ManageabilityPkg: Add more helper functions Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 02/14] ManageabilityPkg: Support Maximum Transfer Unit Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-10 17:25   ` [edk2-devel] " Tinh Nguyen
  2023-04-03 15:04 ` [edk2-platforms][PATCH 04/14] ManageabilityPkg: Add HeaderSize and TrailerSize Chang, Abner
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: Abner Chang <abner.chang@amd.com>

Fix Uncrustify errors of IPMI protocol
and KCS manageability transport library.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../Library/ManageabilityTransportLib.h       |  8 ++--
 .../IpmiProtocol/Pei/IpmiPpiInternal.h        | 10 ++---
 .../Dxe/ManageabilityTransportKcs.c           |  6 ++-
 .../Universal/IpmiProtocol/Dxe/IpmiProtocol.c |  4 +-
 .../Universal/IpmiProtocol/Pei/IpmiPpi.c      | 40 ++++++++++---------
 .../Universal/IpmiProtocol/Smm/IpmiProtocol.c |  7 ++--
 6 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
index ad6cd1a464..d86d0d87d5 100644
--- a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
+++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
@@ -74,13 +74,13 @@ typedef UINT32 MANAGEABILITY_TRANSPORT_CAPABILITY;
 /// Bit 0
 #define MANAGEABILITY_TRANSPORT_CAPABILITY_MULTIPLE_TRANSFER_TOKENS  0x00000001
 /// Bit 1
-#define MANAGEABILITY_TRANSPORT_CAPABILITY_ASYNCHRONOUS_TRANSFER     0x00000002
+#define MANAGEABILITY_TRANSPORT_CAPABILITY_ASYNCHRONOUS_TRANSFER  0x00000002
 /// Bit 2   - Reserved
 /// Bit 7:3 - Transport interface maximum payload size, which is (2 ^ bit[7:3] - 1)
 ///           bit[7:3] means no maximum payload.
-#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_MASK          0x000000f8
-#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POSITION  3
-  #define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE  0x00
+#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_MASK           0x000000f8
+#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POSITION   3
+#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE  0x00
 /// Bit 8:31 - Reserved
 
 ///
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h
index 7b6ab0f529..4b6bdc97a9 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h
@@ -17,11 +17,11 @@
 #define MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK(a)  CR (a, PEI_IPMI_PPI_INTERNAL, PeiIpmiPpi, MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE)
 
 typedef struct {
-  UINT32                              Signature;
-  MANAGEABILITY_TRANSPORT_TOKEN       *TransportToken;
-  MANAGEABILITY_TRANSPORT_CAPABILITY  TransportCapability;
-  UINT32                              TransportMaximumPayload;
-  PEI_IPMI_PPI                        PeiIpmiPpi;
+  UINT32                                Signature;
+  MANAGEABILITY_TRANSPORT_TOKEN         *TransportToken;
+  MANAGEABILITY_TRANSPORT_CAPABILITY    TransportCapability;
+  UINT32                                TransportMaximumPayload;
+  PEI_IPMI_PPI                          PeiIpmiPpi;
 } PEI_IPMI_PPI_INTERNAL;
 
 #endif // MANAGEABILITY_IPMI_PPI_INTERNAL_H_
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
index 25d6e49886..91d3517bdb 100644
--- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
@@ -221,7 +221,7 @@ KcsTransportTransmitReceive (
   EFI_STATUS                           Status;
   MANAGEABILITY_IPMI_TRANSPORT_HEADER  *TransmitHeader;
 
-  if (TransportToken == NULL || TransferToken == NULL) {
+  if ((TransportToken == NULL) || (TransferToken == NULL)) {
     DEBUG ((DEBUG_ERROR, "%a: Invalid transport token or transfer token.\n", __FUNCTION__));
     return;
   }
@@ -298,6 +298,7 @@ AcquireTransportSession (
     DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TRANSPORT_KCS\n", __FUNCTION__));
     return EFI_OUT_OF_RESOURCES;
   }
+
   KcsTransportToken->Token.Transport = AllocateZeroPool (sizeof (MANAGEABILITY_TRANSPORT));
   if (KcsTransportToken->Token.Transport == NULL) {
     FreePool (KcsTransportToken);
@@ -346,9 +347,10 @@ GetTransportCapability (
   OUT MANAGEABILITY_TRANSPORT_CAPABILITY  *TransportCapability
   )
 {
-  if (TransportToken == NULL || TransportCapability == NULL) {
+  if ((TransportToken == NULL) || (TransportCapability == NULL)) {
     return EFI_INVALID_PARAMETER;
   }
+
   *TransportCapability = 0;
   return EFI_SUCCESS;
 }
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
index c30132419d..40587a07af 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
@@ -100,12 +100,14 @@ DxeIpmiEntry (
     DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for IPMI protocol - %r\n", __FUNCTION__, Status));
     return Status;
   }
+
   Status = GetTransportCapability (mTransportToken, &TransportCapability);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
     return Status;
   }
-  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(TransportCapability);
+
+  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY (TransportCapability);
   if (TransportMaximumPayload == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
     DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
   } else {
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
index 0dda6d2d47..0a914e513c 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
@@ -51,19 +51,19 @@ PeiIpmiSubmitCommand (
   IN OUT UINT32        *ResponseDataSize
   )
 {
-  EFI_STATUS            Status;
-  PEI_IPMI_PPI_INTERNAL *PeiIpmiPpiinternal;
-
-  PeiIpmiPpiinternal = MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK(This);
-  Status = CommonIpmiSubmitCommand (
-             PeiIpmiPpiinternal->TransportToken,
-             NetFunction,
-             Command,
-             RequestData,
-             RequestDataSize,
-             ResponseData,
-             ResponseDataSize
-             );
+  EFI_STATUS             Status;
+  PEI_IPMI_PPI_INTERNAL  *PeiIpmiPpiinternal;
+
+  PeiIpmiPpiinternal = MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK (This);
+  Status             = CommonIpmiSubmitCommand (
+                         PeiIpmiPpiinternal->TransportToken,
+                         NetFunction,
+                         Command,
+                         RequestData,
+                         RequestDataSize,
+                         ResponseData,
+                         ResponseDataSize
+                         );
   return Status;
 }
 
@@ -90,18 +90,19 @@ PeiIpmiEntry (
   MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS     TransportAdditionalStatus;
   MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION  HardwareInformation;
 
-  PeiIpmiPpiinternal = (PEI_IPMI_PPI_INTERNAL *)AllocateZeroPool (sizeof(PEI_IPMI_PPI_INTERNAL));
+  PeiIpmiPpiinternal = (PEI_IPMI_PPI_INTERNAL *)AllocateZeroPool (sizeof (PEI_IPMI_PPI_INTERNAL));
   if (PeiIpmiPpiinternal == NULL) {
     DEBUG ((DEBUG_ERROR, "%a: Not enough memory for PEI_IPMI_PPI_INTERNAL.\n", __FUNCTION__));
     return EFI_OUT_OF_RESOURCES;
   }
-  PpiDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)AllocateZeroPool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
+
+  PpiDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)AllocateZeroPool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
   if (PpiDescriptor == NULL) {
     DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_PEI_PPI_DESCRIPTOR.\n", __FUNCTION__));
     return EFI_OUT_OF_RESOURCES;
   }
 
-  PeiIpmiPpiinternal->Signature = MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE;
+  PeiIpmiPpiinternal->Signature                    = MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE;
   PeiIpmiPpiinternal->PeiIpmiPpi.IpmiSubmitCommand = PeiIpmiSubmitCommand;
 
   PpiDescriptor->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
@@ -116,18 +117,19 @@ PeiIpmiEntry (
     DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for IPMI protocol - %r\n", __FUNCTION__, Status));
     return Status;
   }
+
   Status = GetTransportCapability (PeiIpmiPpiinternal->TransportToken, &PeiIpmiPpiinternal->TransportCapability);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
     return Status;
   }
 
-  PeiIpmiPpiinternal->TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(PeiIpmiPpiinternal->TransportCapability);
+  PeiIpmiPpiinternal->TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY (PeiIpmiPpiinternal->TransportCapability);
   if (PeiIpmiPpiinternal->TransportMaximumPayload  == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
-    DEBUG((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
+    DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
   } else {
     PeiIpmiPpiinternal->TransportMaximumPayload -= 1;
-    DEBUG((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, PeiIpmiPpiinternal->TransportMaximumPayload));
+    DEBUG ((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, PeiIpmiPpiinternal->TransportMaximumPayload));
   }
 
   TransportName = HelperManageabilitySpecName (PeiIpmiPpiinternal->TransportToken->Transport->ManageabilityTransportSpecification);
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
index 86dee2fa24..41b9a10453 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
@@ -107,12 +107,13 @@ SmmIpmiEntry (
     DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
     return Status;
   }
-  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(TransportCapability);
+
+  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY (TransportCapability);
   if (TransportMaximumPayload == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
-    DEBUG((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
+    DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
   } else {
     TransportMaximumPayload -= 1;
-    DEBUG((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, TransportMaximumPayload));
+    DEBUG ((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, TransportMaximumPayload));
   }
 
   mTransportName = HelperManageabilitySpecName (mTransportToken->Transport->ManageabilityTransportSpecification);
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 04/14] ManageabilityPkg: Add HeaderSize and TrailerSize
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (2 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 03/14] ManageabilityPkg: Fix Uncrustify errors Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 05/14] ManageabilityPkg: Add PldmProtocolLib Chang, Abner
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: Abner Chang <abner.chang@amd.com>

Add HeaderSize and TrailerSize in
MANAGEABILITY_TRANSFER_TOKEN structure.
Manageability transport interface may used by
multiple protocols which have different header
and trailer of payload. (e.g. MCTP over KCS and
IPMI over KCS).

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../Library/ManageabilityTransportLib.h       |   2 +
 .../Common/ManageabilityTransportKcs.h        |  20 ++-
 .../IpmiProtocol/Common/IpmiProtocolCommon.h  |  36 +++--
 .../Common/KcsCommon.c                        | 152 ++++++++++++------
 .../Dxe/ManageabilityTransportKcs.c           |  14 +-
 .../IpmiProtocol/Common/IpmiProtocolCommon.c  |  63 +++++---
 Features/ManageabilityPkg/Readme.md           |  10 ++
 7 files changed, 194 insertions(+), 103 deletions(-)

diff --git a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
index d86d0d87d5..04072aee89 100644
--- a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
+++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
@@ -168,10 +168,12 @@ struct _MANAGEABILITY_TRANSFER_TOKEN {
                                                                           ///< which is sent discretely of payload.
                                                                           ///< This field can be NULL if the transport
                                                                           ///< doesn't require this.
+  UINT16                                       TransmitHeaderSize;        ///< Transmit header size in byte.
   MANAGEABILITY_TRANSPORT_TRAILER              TransmitTrailer;           ///< This is the transport-specific trailer
                                                                           ///< which is sent discretely of payload.
                                                                           ///< This field can be NULL if the transport
                                                                           ///< doesn't require this.
+  UINT16                                       TransmitTrailerSize;       ///< Transmit trailer size in byte.
   MANAGEABILITY_TRANSMIT_PACKAGE               TransmitPackage;           ///< The payload sent to transport interface.
   MANAGEABILITY_RECEIVE_PACKAGE                ReceivePackage;            ///< The buffer to receive the response.
   EFI_STATUS                                   TransferStatus;            ///< The EFI Status of the transfer.
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h
index 2cdf60ba7e..d6685c165e 100644
--- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h
@@ -41,8 +41,10 @@ typedef struct {
 /**
   This service communicates with BMC using KCS protocol.
 
-  @param[in]      NetFunction           Net function of the command.
-  @param[in]      Command               IPMI Command.
+  @param[in]      TransmitHeader        KCS packet header.
+  @param[in]      TransmitHeaderSize    KCS packet header size in byte.
+  @param[in]      TransmitTrailer       KCS packet trailer.
+  @param[in]      TransmitTrailerSize   KCS packet trailer size in byte.
   @param[in]      RequestData           Command Request Data.
   @param[in]      RequestDataSize       Size of Command Request Data.
   @param[out]     ResponseData          Command Response Data. The completion
@@ -69,12 +71,14 @@ typedef struct {
 EFI_STATUS
 EFIAPI
 KcsTransportSendCommand (
-  IN  UINT8      NetFunction,
-  IN  UINT8      Command,
-  IN  UINT8      *RequestData OPTIONAL,
-  IN  UINT32     RequestDataSize,
-  OUT UINT8      *ResponseData OPTIONAL,
-  IN OUT UINT32  *ResponseDataSize OPTIONAL
+  IN  MANAGEABILITY_TRANSPORT_HEADER   TransmitHeader,
+  IN  UINT16                           TransmitHeaderSize,
+  IN  MANAGEABILITY_TRANSPORT_TRAILER  TransmitTrailer OPTIONAL,
+  IN  UINT16                           TransmitTrailerSize,
+  IN  UINT8                            *RequestData OPTIONAL,
+  IN  UINT32                           RequestDataSize,
+  OUT UINT8                            *ResponseData OPTIONAL,
+  IN OUT UINT32                        *ResponseDataSize OPTIONAL
   );
 
 /**
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.h b/Features/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.h
index 5a7236e9a6..8bf16e6277 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.h
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.h
@@ -44,21 +44,23 @@ SetupIpmiTransportHardwareInformation (
   This functions setup the final header/body/trailer packets for
   the acquired transport interface.
 
-  @param[in]         TransportToken  The transport interface.
-  @param[in]         NetFunction     IPMI function.
-  @param[in]         Command         IPMI command.
-  @param[out]        PacketHeader    The pointer to receive header of request.
-  @param[in, out]    PacketBody      The request body.
-                                     When IN, it is the caller's request body.
-                                     When OUT and NULL, the request body is not
-                                     changed.
-                                     Whee out and non-NULL, the request body is
-                                     changed to comfort the transport 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 request body is unchanged.
-  @param[out]        PacketTrailer   The pointer to receive trailer of request.
+  @param[in]         TransportToken     The transport interface.
+  @param[in]         NetFunction        IPMI function.
+  @param[in]         Command            IPMI command.
+  @param[out]        PacketHeader       The pointer to receive header of request.
+  @param[out]        PacketHeaderSize   Pinter to receive packet header size in byte.
+  @param[in, out]    PacketBody         The request body.
+                                        When IN, it is the caller's request body.
+                                        When OUT and NULL, the request body is not
+                                        changed.
+                                        Whee out and non-NULL, the request body is
+                                        changed to comfort the transport 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 request body is unchanged.
+  @param[out]        PacketTrailer      The pointer to receive trailer of request.
+  @param[out]        PacketTrailerSize  Pinter to receive packet trailer size in byte.
 
   @retval EFI_SUCCESS            Request packet is returned.
   @retval EFI_UNSUPPORTED        Request packet is not returned because
@@ -70,9 +72,11 @@ SetupIpmiRequestTransportPacket (
   IN   UINT8                            NetFunction,
   IN   UINT8                            Command,
   OUT  MANAGEABILITY_TRANSPORT_HEADER   *PacketHeader OPTIONAL,
+  OUT  UINT16                           *PacketHeaderSize,
   IN OUT UINT8                          **PacketBody OPTIONAL,
   IN OUT UINT32                         *PacketBodySize OPTIONAL,
-  OUT  MANAGEABILITY_TRANSPORT_TRAILER  *PacketTrailer OPTIONAL
+  OUT  MANAGEABILITY_TRANSPORT_TRAILER  *PacketTrailer OPTIONAL,
+  OUT  UINT16                           *PacketTrailerSize
   );
 
 /**
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/KcsCommon.c b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/KcsCommon.c
index 17e2b8f231..14a7047447 100644
--- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/KcsCommon.c
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/KcsCommon.c
@@ -11,6 +11,7 @@
 #include <Library/BaseMemoryLib.h>
 #include <Library/IoLib.h>
 #include <Library/DebugLib.h>
+#include <Library/ManageabilityTransportHelperLib.h>
 #include <Library/MemoryAllocationLib.h>
 #include <Library/TimerLib.h>
 
@@ -98,8 +99,10 @@ ClearOBF (
   Algorithm is based on flow chart provided in IPMI spec 2.0
   Figure 9-6, KCS Interface BMC to SMS Write Transfer Flow Chart
 
-  @param[in]  NetFunction           Net function of the command.
-  @param[in]  Command               IPMI Command.
+  @param[in]  TransmitHeader        KCS packet header.
+  @param[in]  TransmitHeaderSize    KCS packet header size in byte.
+  @param[in]  TransmitTrailer       KCS packet trailer.
+  @param[in]  TransmitTrailerSize   KCS packet trailer size in byte.
   @param[in]  RequestData           Command Request Data, could be NULL.
                                     RequestDataSize must be zero, if RequestData
                                     is NULL.
@@ -122,10 +125,12 @@ ClearOBF (
 **/
 EFI_STATUS
 KcsTransportWrite (
-  IN  UINT8   NetFunction,
-  IN  UINT8   Command,
-  IN  UINT8   *RequestData OPTIONAL,
-  IN  UINT32  RequestDataSize
+  IN  MANAGEABILITY_TRANSPORT_HEADER   TransmitHeader,
+  IN  UINT16                           TransmitHeaderSize,
+  IN  MANAGEABILITY_TRANSPORT_TRAILER  TransmitTrailer OPTIONAL,
+  IN  UINT16                           TransmitTrailerSize,
+  IN  UINT8                            *RequestData OPTIONAL,
+  IN  UINT32                           RequestDataSize
   )
 {
   EFI_STATUS  Status;
@@ -134,37 +139,63 @@ KcsTransportWrite (
   UINT8       *BufferPtr;
 
   // Validation on RequestData and RequestDataSize.
-  if ((RequestData == NULL && RequestDataSize != 0) ||
-      (RequestData != NULL && RequestDataSize == 0)
-      ) {
+  if (((RequestData == NULL) && (RequestDataSize != 0)) ||
+      ((RequestData != NULL) && (RequestDataSize == 0))
+      )
+  {
     DEBUG ((DEBUG_ERROR, "%a: Mismatched values of RequestData or RequestDataSize.\n", __FUNCTION__));
     return EFI_INVALID_PARAMETER;
   }
 
-  Length = sizeof (NetFunction) + sizeof (Command);
+  // Validation on TransmitHeader and TransmitHeaderSize.
+  if (((TransmitHeader == NULL) && (TransmitHeaderSize != 0)) ||
+      ((TransmitHeader != NULL) && (TransmitHeaderSize == 0))
+      )
+  {
+    DEBUG ((DEBUG_ERROR, "%a: Mismatched values of TransmitHeader or TransmitHeaderSize.\n", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  // Validation on TransmitHeader and TransmitHeaderSize.
+  if (((TransmitTrailer == NULL) && (TransmitTrailerSize != 0)) ||
+      ((TransmitTrailer != NULL) && (TransmitTrailerSize == 0))
+      )
+  {
+    DEBUG ((DEBUG_ERROR, "%a: Mismatched values of TransmitTrailer or TransmitTrailerSize.\n", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Length = TransmitHeaderSize;
   if (RequestData != NULL) {
     Length = Length + RequestDataSize;
   }
 
+  if ((TransmitTrailer != NULL) && (TransmitTrailerSize != 0)) {
+    Length += TransmitTrailerSize;
+  }
+
   Buffer = AllocateZeroPool (Length);
   if (Buffer == NULL) {
     return EFI_OUT_OF_RESOURCES;
   }
 
   //
-  // Buffer[0] = NetFunction
-  // Buffer[1] = Command
-  // Buffer [2..RequestDataSize] = RequestData
+  // Buffer[0..(TransmitHeaderSize - 1)] = TransmitHeader
+  // Buffer [TransmitHeader..(TransmitHeader + RequestDataSize - 1)] = RequestData
+  // Buffer [(TransmitHeader + RequestDataSize)..(TransmitHeader + RequestDataSize + TransmitTrailerSize - 1)] = TransmitTrailer
   //
   BufferPtr = Buffer;
-  CopyMem (BufferPtr, &NetFunction, sizeof (NetFunction));
-  BufferPtr += sizeof (NetFunction);
-  CopyMem (BufferPtr, &Command, sizeof (Command));
-  BufferPtr += sizeof (Command);
-  if (Length > (sizeof (NetFunction) + sizeof (Command))) {
+  CopyMem ((VOID *)BufferPtr, (VOID *)TransmitHeader, TransmitHeaderSize);
+  BufferPtr += TransmitHeaderSize;
+  if (RequestData != NULL) {
     CopyMem (BufferPtr, RequestData, RequestDataSize);
   }
 
+  BufferPtr += RequestDataSize;
+  if (TransmitTrailer != NULL) {
+    CopyMem (BufferPtr, (VOID *)TransmitTrailer, TransmitTrailerSize);
+  }
+
   BufferPtr = Buffer;
 
   // Step 1. wait for IBF to get clear
@@ -293,10 +324,11 @@ KcsTransportRead (
   EFI_STATUS  Status;
   UINT32      ReadLength;
 
-  if (DataByte == NULL || *Length == 0) {
+  if ((DataByte == NULL) || (*Length == 0)) {
     DEBUG ((DEBUG_ERROR, "%a: Either DataByte is NULL or Length is 0.\n", __FUNCTION__));
     return EFI_INVALID_PARAMETER;
   }
+
   ReadLength = 0;
   while (ReadLength < *Length) {
     // Step 1. wait for IBF to get clear
@@ -350,8 +382,10 @@ KcsTransportRead (
 /**
   This service communicates with BMC using KCS protocol.
 
-  @param[in]      NetFunction           Net function of the command.
-  @param[in]      Command               IPMI Command.
+  @param[in]      TransmitHeader        KCS packet header.
+  @param[in]      TransmitHeaderSize    KCS packet header size in byte.
+  @param[in]      TransmitTrailer       KCS packet trailer.
+  @param[in]      TransmitTrailerSize   KCS packet trailer size in byte.
   @param[in]      RequestData           Command Request Data.
   @param[in]      RequestDataSize       Size of Command Request Data.
   @param[out]     ResponseData          Command Response Data. The completion
@@ -380,12 +414,14 @@ KcsTransportRead (
 EFI_STATUS
 EFIAPI
 KcsTransportSendCommand (
-  IN  UINT8      NetFunction,
-  IN  UINT8      Command,
-  IN  UINT8      *RequestData OPTIONAL,
-  IN  UINT32     RequestDataSize,
-  OUT UINT8      *ResponseData OPTIONAL,
-  IN OUT UINT32  *ResponseDataSize OPTIONAL
+  IN  MANAGEABILITY_TRANSPORT_HEADER   TransmitHeader,
+  IN  UINT16                           TransmitHeaderSize,
+  IN  MANAGEABILITY_TRANSPORT_TRAILER  TransmitTrailer OPTIONAL,
+  IN  UINT16                           TransmitTrailerSize,
+  IN  UINT8                            *RequestData OPTIONAL,
+  IN  UINT32                           RequestDataSize,
+  OUT UINT8                            *ResponseData OPTIONAL,
+  IN OUT UINT32                        *ResponseDataSize OPTIONAL
   )
 {
   EFI_STATUS                Status;
@@ -393,30 +429,41 @@ KcsTransportSendCommand (
   IPMI_KCS_RESPONSE_HEADER  RspHeader;
 
   if ((RequestData != NULL) && (RequestDataSize == 0)) {
-    DEBUG((DEBUG_ERROR, "%a: Mismatched values of RequestData and RequestDataSize\n", __FUNCTION__));
+    DEBUG ((DEBUG_ERROR, "%a: Mismatched values of RequestData and RequestDataSize\n", __FUNCTION__));
     return EFI_INVALID_PARAMETER;
   }
 
   if ((ResponseData != NULL) && ((ResponseDataSize != NULL) && (*ResponseDataSize == 0))) {
-    DEBUG((DEBUG_ERROR, "%a: Mismatched values of ResponseData and ResponseDataSize\n", __FUNCTION__));
+    DEBUG ((DEBUG_ERROR, "%a: Mismatched values of ResponseData and ResponseDataSize\n", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (TransmitHeader == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: TransmitHeader is NULL\n", __FUNCTION__));
     return EFI_INVALID_PARAMETER;
   }
 
+  //
+  // Print out the request payloads.
+  HelperManageabilityDebugPrint ((VOID *)TransmitHeader, TransmitHeaderSize, "KCS Transmit Header:\n");
+  if (RequestData != NULL) {
+    HelperManageabilityDebugPrint ((VOID *)RequestData, RequestDataSize, "KCS Request Data:\n");
+  }
+
+  if (TransmitTrailer != NULL) {
+    HelperManageabilityDebugPrint ((VOID *)TransmitTrailer, TransmitTrailerSize, "KCS Transmit Trailer:\n");
+  }
+
   Status = KcsTransportWrite (
-             (NetFunction << 2),
-             Command,
+             TransmitHeader,
+             TransmitHeaderSize,
+             TransmitTrailer,
+             TransmitTrailerSize,
              RequestData,
              RequestDataSize
              );
   if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "IPMI KCS Write Failed with Status(%r) for NetFunction(0x%x)," \
-      " Command(0x%x).\n",
-      Status,
-      NetFunction,
-      Command
-      ));
+    DEBUG ((DEBUG_ERROR, "IPMI KCS Write Failed with Status(%r)", Status));
     return Status;
   }
 
@@ -429,7 +476,7 @@ KcsTransportSendCommand (
       DEBUG_ERROR,
       "IPMI KCS read response header failed Status(%r), " \
       "RspNetFunctionLun = 0x%x, " \
-      "Comamnd = 0x%x \n",
+      "Command = 0x%x \n",
       Status,
       RspHeader.NetFunc,
       RspHeader.Command
@@ -437,16 +484,21 @@ KcsTransportSendCommand (
     return (Status);
   }
 
-  Status = KcsTransportRead ((UINT8 *)ResponseData, ResponseDataSize);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "IPMI KCS response read Failed with Status(%r) for NetFunction(0x%x)," \
-      " Command(0x%x).\n",
-      Status,
-      NetFunction,
-      Command
-      ));
+  //
+  // Print out the response payloads.
+  HelperManageabilityDebugPrint ((VOID *)&RspHeader, (UINT16)RspHeaderSize, "KCS Response Header:\n");
+
+  if ((ResponseData != NULL) && (ResponseDataSize != NULL) && (*ResponseDataSize != 0)) {
+    Status = KcsTransportRead ((UINT8 *)ResponseData, ResponseDataSize);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "IPMI KCS response read Failed with Status(%r)", Status));
+    }
+
+    //
+    // Print out the response payloads.
+    HelperManageabilityDebugPrint ((VOID *)ResponseData, *ResponseDataSize, "KCS Response Data:\n");
+  } else {
+    *ResponseDataSize = 0;
   }
 
   return Status;
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
index 91d3517bdb..a9eff886d0 100644
--- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
@@ -218,23 +218,25 @@ KcsTransportTransmitReceive (
   IN  MANAGEABILITY_TRANSFER_TOKEN   *TransferToken
   )
 {
-  EFI_STATUS                           Status;
-  MANAGEABILITY_IPMI_TRANSPORT_HEADER  *TransmitHeader;
+  EFI_STATUS  Status;
 
   if ((TransportToken == NULL) || (TransferToken == NULL)) {
     DEBUG ((DEBUG_ERROR, "%a: Invalid transport token or transfer token.\n", __FUNCTION__));
     return;
   }
 
-  TransmitHeader = (MANAGEABILITY_IPMI_TRANSPORT_HEADER *)TransferToken->TransmitHeader;
-  if (TransmitHeader == NULL) {
+  // Transmit header is necessary for KCS transport, which could be
+  // NetFn, Command and etc.
+  if (TransferToken->TransmitHeader == NULL) {
     TransferToken->TransferStatus = EFI_INVALID_PARAMETER;
     return;
   }
 
   Status = KcsTransportSendCommand (
-             TransmitHeader->NetFn,
-             TransmitHeader->Command,
+             TransferToken->TransmitHeader,
+             TransferToken->TransmitHeaderSize,
+             TransferToken->TransmitTrailer,
+             TransferToken->TransmitTrailerSize,
              TransferToken->TransmitPackage.TransmitPayload,
              TransferToken->TransmitPackage.TransmitSizeInByte,
              TransferToken->ReceivePackage.ReceiveBuffer,
diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.c
index 82bae58292..b055bad7da 100644
--- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.c
+++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Common/IpmiProtocolCommon.c
@@ -65,21 +65,23 @@ SetupIpmiTransportHardwareInformation (
   This functions setup the final header/body/trailer packets for
   the acquired transport interface.
 
-  @param[in]         TransportToken  The transport interface.
-  @param[in]         NetFunction     IPMI function.
-  @param[in]         Command         IPMI command.
-  @param[out]        PacketHeader    The pointer to receive header of request.
-  @param[in, out]    PacketBody      The request body.
-                                     When IN, it is the caller's request body.
-                                     When OUT and NULL, the request body is not
-                                     changed.
-                                     When OUT and non-NULL, the request body is
-                                     changed to conform the transport interface.
-  @param[in, out]    PacketBodySize  The request body size.
-                                     When OUT and non-zero, it is the new data
-                                     length of request body.
-                                     When OUT and zero, the request body is unchanged.
-  @param[out]        PacketTrailer   The pointer to receive trailer of request.
+  @param[in]         TransportToken     The transport interface.
+  @param[in]         NetFunction        IPMI function.
+  @param[in]         Command            IPMI command.
+  @param[out]        PacketHeader       The pointer to receive header of request.
+  @param[out]        PacketHeaderSize   Pinter to receive packet header size in byte.
+  @param[in, out]    PacketBody         The request body.
+                                        When IN, it is the caller's request body.
+                                        When OUT and NULL, the request body is not
+                                        changed.
+                                        Whee out and non-NULL, the request body is
+                                        changed to comfort the transport 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 request body is unchanged.
+  @param[out]        PacketTrailer      The pointer to receive trailer of request.
+  @param[out]        PacketTrailerSize  Pinter to receive packet trailer size in byte.
 
   @retval EFI_SUCCESS            Request packet is returned.
   @retval EFI_UNSUPPORTED        Request packet is not returned because
@@ -91,9 +93,11 @@ SetupIpmiRequestTransportPacket (
   IN   UINT8                            NetFunction,
   IN   UINT8                            Command,
   OUT  MANAGEABILITY_TRANSPORT_HEADER   *PacketHeader OPTIONAL,
+  OUT  UINT16                           *PacketHeaderSize,
   IN OUT UINT8                          **PacketBody OPTIONAL,
   IN OUT UINT32                         *PacketBodySize OPTIONAL,
-  OUT  MANAGEABILITY_TRANSPORT_TRAILER  *PacketTrailer OPTIONAL
+  OUT  MANAGEABILITY_TRANSPORT_TRAILER  *PacketTrailer OPTIONAL,
+  OUT  UINT16                           *PacketTrailerSize
   )
 {
   MANAGEABILITY_IPMI_TRANSPORT_HEADER  *IpmiHeader;
@@ -105,18 +109,24 @@ SetupIpmiRequestTransportPacket (
       return EFI_OUT_OF_RESOURCES;
     }
 
+    *PacketHeaderSize   = 0;
+    *PacketTrailerSize  = 0;
     IpmiHeader->Command = Command;
     IpmiHeader->Lun     = 0;
     IpmiHeader->NetFn   = NetFunction;
     if (PacketHeader != NULL) {
-      *PacketHeader = (MANAGEABILITY_TRANSPORT_HEADER *)IpmiHeader;
+      *PacketHeader     = (MANAGEABILITY_TRANSPORT_HEADER *)IpmiHeader;
+      *PacketHeaderSize = sizeof (MANAGEABILITY_IPMI_TRANSPORT_HEADER);
     }
+
     if (PacketTrailer != NULL) {
       *PacketTrailer = NULL;
     }
+
     if (PacketBody != NULL) {
       *PacketBody = NULL;
     }
+
     if (PacketBodySize != NULL) {
       *PacketBodySize = 0;
     }
@@ -124,6 +134,7 @@ SetupIpmiRequestTransportPacket (
     DEBUG ((DEBUG_ERROR, "%a: No implementation of building up packet.", __FUNCTION__));
     ASSERT (FALSE);
   }
+
   return EFI_SUCCESS;
 }
 
@@ -164,6 +175,8 @@ CommonIpmiSubmitCommand (
   MANAGEABILITY_TRANSPORT_HEADER             IpmiTransportHeader;
   MANAGEABILITY_TRANSPORT_TRAILER            IpmiTransportTrailer;
   MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS  TransportAdditionalStatus;
+  UINT16                                     HeaderSize;
+  UINT16                                     TrailerSize;
 
   if (TransportToken == NULL) {
     DEBUG ((DEBUG_ERROR, "%a: No transport toke for IPMI\n", __FUNCTION__));
@@ -179,8 +192,8 @@ CommonIpmiSubmitCommand (
     return Status;
   }
 
-  ThisRequestData       = RequestData;
-  ThisRequestDataSize   = RequestDataSize;
+  ThisRequestData      = RequestData;
+  ThisRequestDataSize  = RequestDataSize;
   IpmiTransportHeader  = NULL;
   IpmiTransportTrailer = NULL;
   Status               = SetupIpmiRequestTransportPacket (
@@ -188,9 +201,11 @@ CommonIpmiSubmitCommand (
                            NetFunction,
                            Command,
                            &IpmiTransportHeader,
+                           &HeaderSize,
                            &ThisRequestData,
                            &ThisRequestDataSize,
-                           &IpmiTransportTrailer
+                           &IpmiTransportTrailer,
+                           &TrailerSize
                            );
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a: Fail to build packets - (%r)\n", __FUNCTION__, Status));
@@ -198,12 +213,13 @@ CommonIpmiSubmitCommand (
   }
 
   ZeroMem (&TransferToken, sizeof (MANAGEABILITY_TRANSFER_TOKEN));
-  TransferToken.TransmitHeader  = IpmiTransportHeader;
-  TransferToken.TransmitTrailer = IpmiTransportTrailer;
+  TransferToken.TransmitHeader      = IpmiTransportHeader;
+  TransferToken.TransmitHeaderSize  = HeaderSize;
+  TransferToken.TransmitTrailer     = IpmiTransportTrailer;
+  TransferToken.TransmitTrailerSize = TrailerSize;
 
   // Transmit packet.
   if ((ThisRequestData == NULL) || (ThisRequestDataSize == 0)) {
-
     // Transmit parameter were not changed by SetupIpmiRequestTransportPacket().
     TransferToken.TransmitPackage.TransmitPayload    = RequestData;
     TransferToken.TransmitPackage.TransmitSizeInByte = RequestDataSize;
@@ -247,5 +263,6 @@ CommonIpmiSubmitCommand (
   if (ResponseDataSize != NULL) {
     *ResponseDataSize = TransferToken.ReceivePackage.ReceiveSizeInByte;
   }
+
   return Status;
 }
diff --git a/Features/ManageabilityPkg/Readme.md b/Features/ManageabilityPkg/Readme.md
index 2ecee96313..81c9322b98 100644
--- a/Features/ManageabilityPkg/Readme.md
+++ b/Features/ManageabilityPkg/Readme.md
@@ -99,7 +99,9 @@ library to compliant with the framework of ManageabilityPkg design.
     struct _MANAGEABILITY_TRANSFER_TOKEN {
       EFI_EVENT                                  ReceiveEvent;
       MANAGEABILITY_TRANSPORT_HEADER             TransmitHeader;
+      UINT16                                     TransmitHeaderSize;
       MANAGEABILITY_TRANSPORT_TRAILER            TransmitTrailer;
+      UINT16                                     TransmitTrailerSize;
       MANAGEABILITY_TRANSMIT_PACKAGE             TransmitPackage;
       MANAGEABILITY_RECEIVE_PACKAGE              ReceivePackage;
       EFI_STATUS                                 TransferStatus;
@@ -124,6 +126,10 @@ library to compliant with the framework of ManageabilityPkg design.
     manageability transport library to make the transport implementation agnostic to the
     manageability protocol specification.
 
+* ***TransmitHeaderSize***
+
+    This indicates the size of TransmitHeader.
+
 * ***TransmitTrailer***
 
     The transmit trailer may be different according to the disparate transport
@@ -131,6 +137,10 @@ library to compliant with the framework of ManageabilityPkg design.
     manageability transport library to make the transport implementation agnostic to the
     manageability protocol specification.
 
+* ***TransmitTrailerSize***
+
+    This indicates the size of TransmitTrailer.
+
 * ***TransmitPackage***
 
     The buffer of packet to transmit, this could be a value of NULL if the manageability
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 05/14] ManageabilityPkg: Add PldmProtocolLib
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (3 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 04/14] ManageabilityPkg: Add HeaderSize and TrailerSize Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-11 13:41   ` Nickle Wang
  2023-04-03 15:04 ` [edk2-platforms][PATCH 06/14] ManageabilityPkg: Add PldmSmbiosTransferDxe driver Chang, Abner
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: Abner Chang <abner.chang@amd.com>

PldmProtocolLib provides the library
function to PLDM protocol.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../ManageabilityPkg/ManageabilityPkg.dec     |  3 +
 .../Include/Dsc/Manageability.dsc             |  3 +
 .../ManageabilityPkg/ManageabilityPkg.dsc     |  1 +
 .../Dxe/PldmProtocolLib.inf                   | 42 +++++++++
 .../Include/Library/BasePldmProtocolLib.h     | 41 +++++++++
 .../Include/Protocol/PldmProtocol.h           | 87 +++++++++++++++++++
 .../PldmProtocolLibrary/Dxe/PldmProtocolLib.c | 87 +++++++++++++++++++
 .../Dxe/PldmProtocolLib.uni                   | 18 ++++
 8 files changed, 282 insertions(+)
 create mode 100644 Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
 create mode 100644 Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
 create mode 100644 Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
 create mode 100644 Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
 create mode 100644 Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.uni

diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dec b/Features/ManageabilityPkg/ManageabilityPkg.dec
index 9a930d3e4b..1e9245c8dc 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dec
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dec
@@ -48,3 +48,6 @@
   gManageabilityProtocolMctpGuid    = { 0x76FED8F1, 0x0BE5, 0x4269, { 0xA3, 0x1A, 0x38, 0x0F, 0x54, 0xF1, 0xA1, 0x8A } }
   # Manageability Protocol PLDM
   gManageabilityProtocolPldmGuid    = { 0x3958090D, 0x69DD, 0x4868, { 0x9C, 0x41, 0xC9, 0xAC, 0x31, 0xB5, 0x25, 0xC5 } }
+
+[Protocols]
+  gEdkiiPldmProtocolGuid                = { 0x60997616, 0xDB70, 0x4B5F, { 0x86, 0xA4, 0x09, 0x58, 0xA3, 0x71, 0x47, 0xB4 } }
diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
index 0d868fdf4a..59549eb39a 100644
--- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
+++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
@@ -8,6 +8,9 @@
 [LibraryClasses]
   ManageabilityTransportHelperLib|ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf
 
+[LibraryClasses.common.DXE_DRIVER]
+  PldmProtocolLib|ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
+
 [LibraryClasses.ARM, LibraryClasses.AARCH64]
   #
   # This library provides the instrinsic functions generated by a given compiler.
diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc b/Features/ManageabilityPkg/ManageabilityPkg.dsc
index 6a083385fd..412029ef6c 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dsc
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc
@@ -37,6 +37,7 @@
 
 [Components]
   ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/DxeManageabilityTransportKcs.inf
+  ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
 
 [LibraryClasses]
   ManageabilityTransportLib|ManageabilityPkg/Library/BaseManageabilityTransportNullLib/BaseManageabilityTransportNull.inf
diff --git a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
new file mode 100644
index 0000000000..1233d76726
--- /dev/null
+++ b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
@@ -0,0 +1,42 @@
+## @file
+#  Instance of PLDM Protocol Library in DXE phase.
+#
+#  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = PldmProtocolLib
+  MODULE_UNI_FILE                = PldmProtocolLib.uni
+  FILE_GUID                      = 5B1173E8-6A5A-468B-BDA4-02303530C55C
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = PldmProtocolLib|DXE_RUNTIME_DRIVER DXE_DRIVER DXE_CORE UEFI_DRIVER UEFI_APPLICATION
+
+#
+#  VALID_ARCHITECTURES          = IA32 X64
+#
+
+[Sources]
+  PldmProtocolLib.c
+
+[Packages]
+  ManageabilityPkg/ManageabilityPkg.dec
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  DebugLib
+  ManageabilityTransportHelperLib
+  UefiBootServicesTableLib
+
+[Guids]
+  gManageabilityProtocolPldmGuid
+
+[Protocols]
+  gEdkiiPldmProtocolGuid          ## ALWAYS_CONSUMES
+
diff --git a/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h b/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
new file mode 100644
index 0000000000..5523ac3a4d
--- /dev/null
+++ b/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
@@ -0,0 +1,41 @@
+/** @file
+
+  This file defines EDKII Pldm Protocol library and functions.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef EDKII_PLDM_PROTOCOL_LIB_H_
+#define EDKII_PLDM_PROTOCOL_LIB_H_
+
+/**
+  This service enables submitting commands via EDKII PLDM protocol.
+
+  @param[in]         PldmType          PLDM message type.
+  @param[in]         Command           PLDM Command of PLDM message type.
+  @param[in]         RequestData       Command Request Data.
+  @param[in]         RequestDataSize   Size of Command Request Data.
+  @param[out]        ResponseData      Command Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize  Size of Command Response Data.
+
+  @retval EFI_SUCCESS            PLDM message was successfully sent to transport interface
+                                 and a response was successfully received.
+  @retval EFI_NOT_FOUND          Transport interface is not found.
+  @retval EFI_NOT_READY          Transport interface is not ready for PLDM message.
+  @retval EFI_DEVICE_ERROR       Transport interface has an hardware error.
+  @retval EFI_TIMEOUT            Send PLDM message got a timeout.
+  @retval EFI_UNSUPPORTED        PLDM message is unsupported.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource or data size error.
+**/
+EFI_STATUS
+PldmSubmitCommand (
+  IN     UINT8   PldmType,
+  IN     UINT8   Command,
+  IN     UINT8   *RequestData,
+  IN     UINT32  RequestDataSize,
+  OUT UINT8      *ResponseData,
+  IN OUT UINT32  *ResponseDataSize
+  );
+
+#endif
diff --git a/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h b/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
new file mode 100644
index 0000000000..651997e1ad
--- /dev/null
+++ b/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
@@ -0,0 +1,87 @@
+/** @file
+  Protocol of EDKII PLDM Protocol.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef EDKII_PLDM_PROTOCOL_H_
+#define EDKII_PLDM_PROTOCOL_H_
+
+#include <IndustryStandard/Pldm.h>
+
+typedef struct  _EDKII_PLDM_PROTOCOL EDKII_PLDM_PROTOCOL;
+
+#define EDKII_PLDM_PROTOCOL_GUID \
+  { \
+    0x60997616, 0xDB70, 0x4B5F, 0x86, 0xA4, 0x09, 0x58, 0xA3, 0x71, 0x47, 0xB4 \
+  }
+
+#define EDKII_PLDM_PROTOCOL_VERSION_MAJOR  1
+#define EDKII_PLDM_PROTOCOL_VERSION_MINOR  0
+#define EDKII_PLDM_PROTOCOL_VERSION        ((EDKII_PLDM_PROTOCOL_VERSION_MAJOR << 8) |\
+                                       EDKII_PLDM_PROTOCOL_VERSION_MINOR)
+
+/**
+  This service enables submitting commands via EDKII PLDM protocol.
+
+  @param[in]         This              EDKII_PLDM_PROTOCOL instance.
+  @param[in]         PldmType          PLDM message type.
+  @param[in]         Command           PLDM Command of PLDM message type.
+  @param[in]         RequestData       Command Request Data.
+  @param[in]         RequestDataSize   Size of Command Request Data.
+  @param[out]        ResponseData      Command Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize  Size of Command Response Data.
+
+  @retval EFI_SUCCESS            The command byte stream was successfully submit to the device and a response was successfully received.
+  @retval EFI_NOT_FOUND          The command was not successfully sent to the device or a response was not successfully received from the device.
+  @retval EFI_NOT_READY          PLDM transport interface is not ready for PLDM command access.
+  @retval EFI_DEVICE_ERROR       PLDM transport interface Device hardware error.
+  @retval EFI_TIMEOUT            The command time out.
+  @retval EFI_UNSUPPORTED        The command was not successfully sent to the device.
+  @retval EFI_OUT_OF_RESOURCES   The resource allcation is out of resource or data size error.
+  @retval EFI_INVALID_PARAMETER  Both RequestData and ResponseData are NULL
+**/
+typedef
+EFI_STATUS
+(EFIAPI *PLDM_SUBMIT_COMMAND)(
+  IN     EDKII_PLDM_PROTOCOL  *This,
+  IN     UINT8                PldmType,
+  IN     UINT8                Command,
+  IN     UINT8                *RequestData,
+  IN     UINT32               RequestDataSize,
+  OUT    UINT8                *ResponseData,
+  IN OUT UINT32               *ResponseDataSize
+  );
+
+//
+// EDKII_PLDM_PROTOCOL Version 1.0
+//
+typedef struct {
+  PLDM_SUBMIT_COMMAND    PldmSubmitCommand;
+} EDKII_PLDM_PROTOCOL_V1_0;
+
+///
+/// Definitions of EDKII_PLDM_PROTOCOL.
+/// This is a union that can accommodate the new functionalities defined
+/// in PLDM Base specification in the future.
+/// The new added function must has its own EDKII_PLDM_PROTOCOL
+/// structure with the incremental version number.
+///   e.g., EDKII_PLDM_PROTOCOL_V1_1.
+///
+/// The new function must be added base on the last version of
+/// EDKII_PLDM_PROTOCOL to keep the backward compatability.
+///
+typedef union {
+  EDKII_PLDM_PROTOCOL_V1_0    *Version1_0;
+} EDKII_PLDM_PROTOCOL_FUNCTION;
+
+struct _EDKII_PLDM_PROTOCOL {
+  UINT16                          ProtocolVersion;
+  EDKII_PLDM_PROTOCOL_FUNCTION    Functions;
+};
+
+extern EFI_GUID  gEdkiiPldmProtocolGuid;
+
+#endif // EDKII_PLDM_PROTOCOL_H_
diff --git a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
new file mode 100644
index 0000000000..ac6225ed92
--- /dev/null
+++ b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
@@ -0,0 +1,87 @@
+/** @file
+  Instance of EDKII PLDM Protocol Library in DXE phase
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiDxe.h>
+#include <Protocol/PldmProtocol.h>
+#include <Library/DebugLib.h>
+#include <Library/ManageabilityTransportHelperLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+EDKII_PLDM_PROTOCOL  *mEdkiiPldmProtocol = NULL;
+
+/**
+  This service enables submitting commands via EDKII PLDM protocol.
+
+  @param[in]         PldmType          PLDM message type.
+  @param[in]         Command           PLDM Command of PLDM message type.
+  @param[in]         RequestData       Command Request Data.
+  @param[in]         RequestDataSize   Size of Command Request Data.
+  @param[out]        ResponseData      Command Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize  Size of Command Response Data.
+
+  @retval EFI_SUCCESS            PLDM message was successfully sent to transport interface
+                                 and a response was successfully received.
+  @retval EFI_NOT_FOUND          Transport interface is not found.
+  @retval EFI_NOT_READY          Transport interface is not ready for PLDM message.
+  @retval EFI_DEVICE_ERROR       Transport interface has an hardware error.
+  @retval EFI_TIMEOUT            Send PLDM message got a timeout.
+  @retval EFI_UNSUPPORTED        PLDM message is unsupported.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource or data size error.
+**/
+EFI_STATUS
+PldmSubmitCommand (
+  IN     UINT8   PldmType,
+  IN     UINT8   Command,
+  IN     UINT8   *RequestData,
+  IN     UINT32  RequestDataSize,
+  OUT UINT8      *ResponseData,
+  IN OUT UINT32  *ResponseDataSize
+  )
+{
+  EFI_STATUS  Status;
+
+  if (mEdkiiPldmProtocol == NULL) {
+    Status = gBS->LocateProtocol (
+                    &gEdkiiPldmProtocolGuid,
+                    NULL,
+                    (VOID **)&mEdkiiPldmProtocol
+                    );
+    if (EFI_ERROR (Status)) {
+      //
+      // Dxe PLDM Protocol is not installed. So, PLDM device is not present.
+      //
+      DEBUG ((DEBUG_ERROR, "%a: EDKII PLDM protocol is not found - %r\n", Status));
+      return EFI_NOT_FOUND;
+    }
+  }
+
+  DEBUG ((DEBUG_INFO, "%a: PLDM Type: 0x%x, Command: 0x%x\n", __FUNCTION__, PldmType, Command));
+  if ((RequestData != NULL) && (RequestDataSize != 0)) {
+    HelperManageabilityDebugPrint ((VOID *)RequestData, RequestDataSize, "PLDM PLDM application layer Type/Command specific request payload\n");
+  }
+
+  Status = mEdkiiPldmProtocol->Functions.Version1_0->PldmSubmitCommand (
+                                                       mEdkiiPldmProtocol,
+                                                       PldmType,
+                                                       Command,
+                                                       RequestData,
+                                                       RequestDataSize,
+                                                       ResponseData,
+                                                       ResponseDataSize
+                                                       );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_INFO, "Fails to send PLDM package - %r\n", Status));
+    return Status;
+  }
+
+  if ((ResponseData != NULL) && (*ResponseDataSize != 0)) {
+    HelperManageabilityDebugPrint ((VOID *)ResponseData, *ResponseDataSize, "PLDM application layer response payload\n");
+  }
+
+  return Status;
+}
diff --git a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.uni b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.uni
new file mode 100644
index 0000000000..b58a2ac146
--- /dev/null
+++ b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.uni
@@ -0,0 +1,18 @@
+// /** @file
+// Instance of PLDM Protocol Library in DXE phase.
+//
+//  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+//
+//  SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT
+#language en-US
+"Instance of PLDM Protocol Library in DXE phase."
+
+#string STR_MODULE_DESCRIPTION
+#language en-US
+"Instance of PLDM Protocol Library in DXE phase."
+
+
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 06/14] ManageabilityPkg: Add PldmSmbiosTransferDxe driver
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (4 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 05/14] ManageabilityPkg: Add PldmProtocolLib Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 07/14] ManageabilityPkg/KCS: KCS transport interface Chang, Abner
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: abnchang <abnchang@amd.com>

Add edk2 driver that supports PLDM SMBIOS Transfer
Specification.
https://www.dmtf.org/sites/default/files/standards/documents/DSP0246_1.0.1.pdf

We currently only support "Push" mode of PLDM SMBIOS
transfer. That says only BIOS to BMC direction is
supported.
The functionality is verified by checking the binary
debug output of payload.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../ManageabilityPkg/ManageabilityPkg.dec     |   1 +
 .../Include/Dsc/Manageability.dsc             |   1 +
 .../PldmSmbiosTransferDxe.inf                 |  47 ++
 .../Protocol/PldmSmbiosTransferProtocol.h     | 184 +++++++
 .../PldmSmbiosTransferDxe.c                   | 518 ++++++++++++++++++
 5 files changed, 751 insertions(+)
 create mode 100644 Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf
 create mode 100644 Features/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol.h
 create mode 100644 Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c

diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dec b/Features/ManageabilityPkg/ManageabilityPkg.dec
index 1e9245c8dc..309faa8c98 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dec
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dec
@@ -51,3 +51,4 @@
 
 [Protocols]
   gEdkiiPldmProtocolGuid                = { 0x60997616, 0xDB70, 0x4B5F, { 0x86, 0xA4, 0x09, 0x58, 0xA3, 0x71, 0x47, 0xB4 } }
+  gEdkiiPldmSmbiosTransferProtocolGuid  = { 0xFA431C3C, 0x816B, 0x4B32, { 0xA3, 0xE0, 0xAD, 0x9B, 0x7F, 0x64, 0x27, 0x2E } }
diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
index 59549eb39a..a5a4fd6615 100644
--- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
+++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
@@ -25,4 +25,5 @@
 [Components.X64]
   ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocolDxe.inf
   ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf
+  ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf
 
diff --git a/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf b/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf
new file mode 100644
index 0000000000..da49057982
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf
@@ -0,0 +1,47 @@
+## @file
+# PLDM SMBIOS Transfer DXE Driver.
+#
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001d
+  BASE_NAME                      = PldmSmbiosTransferDxe
+  FILE_GUID                      = 71BF5CF0-CE09-4C7C-912B-944BF4E4CBC0
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = DxePldmSmbiosTransferEntry
+  UNLOAD_IMAGE                   = PldmSmbiosTransferUnloadImage
+
+#
+#  VALID_ARCHITECTURES           = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+  PldmSmbiosTransferDxe.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  ManageabilityPkg/ManageabilityPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  DebugLib
+  ManageabilityTransportLib
+  ManageabilityTransportHelperLib
+  PldmProtocolLib
+  UefiLib
+  UefiDriverEntryPoint
+  UefiBootServicesTableLib
+
+[Guids]
+  gEfiSmbios3TableGuid
+
+[Protocols]
+  gEfiSmbiosProtocolGuid
+  gEdkiiPldmSmbiosTransferProtocolGuid
+
+[Depex]
+  gEdkiiPldmProtocolGuid  ## ALWAYS_CONSUMES
diff --git a/Features/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol.h b/Features/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol.h
new file mode 100644
index 0000000000..7903e12726
--- /dev/null
+++ b/Features/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol.h
@@ -0,0 +1,184 @@
+/** @file
+  Protocol of EDKII PLDM SMBIOS Transfer Protocol.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_H_
+#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_H_
+
+#include <IndustryStandard/Pldm.h>
+
+typedef struct  _EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL;
+
+#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_GUID \
+  { \
+    0xFA431C3C, 0x816B, 0x4B32, 0xA3, 0xE0, 0xAD, 0x9B, 0x7F, 0x64, 0x27, 0x2E \
+  }
+
+#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_VERSION_MAJOR  1
+#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_VERSION_MINOR  0
+#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_VERSION        ((EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_VERSION_MAJOR << 8) |\
+                                                       EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_VERSION_MINOR)
+
+/**
+  This function gets SMBIOS table metadata.
+
+  @param [in]   This         EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+  @param [out]  Buffer       Buffer to receive the SMBIOS table metadata.
+
+  @retval       EFI_SUCCESS            Get SMBIOS table metadata Successfully.
+  @retval       EFI_UNSUPPORTED        The function is unsupported by this
+                                       driver instance.
+  @retval       Other values           Fail to get SMBIOS table metadata.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA)(
+  IN  EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL   *This,
+  OUT PLDM_SMBIOS_STRUCTURE_TABLE_METADATA  *Buffer
+  );
+
+/**
+  This function sets SMBIOS table metadata.
+
+  @param [in]   This         EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+  @param [in]   Buffer       Pointer to SMBIOS table metadata.
+
+  @retval       EFI_SUCCESS            Set SMBIOS table metadata Successfully.
+  @retval       EFI_UNSUPPORTED        The function is unsupported by this
+                                       driver instance.
+  @retval       Other values           Fail to set SMBIOS table metadata.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA)(
+  IN  EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL   *This,
+  IN  PLDM_SMBIOS_STRUCTURE_TABLE_METADATA  *Buffer
+  );
+
+/**
+  This function gets SMBIOS structure table.
+
+  @param [in]   This        EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+  @param [out]  Buffer      Pointer to the returned SMBIOS structure table.
+                            Caller has to free this memory block when it
+                            is no longer needed.
+  @param [out]  BufferSize  Size of the returned message payload in buffer.
+
+  @retval       EFI_SUCCESS            Gets SMBIOS structure table successfully.
+  @retval       EFI_UNSUPPORTED        The function is unsupported by this
+                                       driver instance.
+  @retval       Other values           Fail to get SMBIOS structure table.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *PLDM_GET_SMBIOS_STRUCTURE_TABLE)(
+  IN   EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL   *This,
+  OUT  UINT8                                 **Buffer,
+  OUT  UINT32                                *BufferSize
+  );
+
+/**
+  This function sets SMBIOS structure table.
+
+  @param [in]   This        EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+
+  @retval      EFI_SUCCESS            Successful
+  @retval      EFI_UNSUPPORTED        The function is unsupported by this
+                                      driver instance.
+  @retval      Other values           Fail to set SMBIOS structure table.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *PLDM_SET_SMBIOS_STRUCTURE_TABLE)(
+  IN   EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL  *This
+  );
+
+/**
+  This function gets particular type of SMBIOS structure.
+
+  @param [in]   This                 EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+  @param [in]   TypeId               The type of SMBIOS structure.
+  @param [in]   StructureInstanceId  The instance ID of particular type of SMBIOS structure.
+  @param [out]  Buffer               Pointer to the returned SMBIOS structure.
+                                     Caller has to free this memory block when it
+                                     is no longer needed.
+  @param [out]  BufferSize           Size of the returned message payload in buffer.
+
+  @retval      EFI_SUCCESS           Gets particular type of SMBIOS structure successfully.
+  @retval      EFI_UNSUPPORTED       The function is unsupported by this
+                                     driver instance.
+  @retval      Other values          Fail to set SMBIOS structure table.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *PLDM_GET_SMBIOS_STRUCTURE_BY_TYPE)(
+  IN   EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL  *This,
+  IN   UINT8                                TypeId,
+  IN   UINT16                               StructureInstanceId,
+  OUT  UINT8                                **Buffer,
+  OUT  UINT32                               *BufferSize
+  );
+
+/**
+  This function gets particular handle of SMBIOS structure.
+
+  @param [in]   This                 EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+  @param [in]   Handle               The handle of SMBIOS structure.
+  @param [out]  Buffer               Pointer to the returned SMBIOS structure.
+                                     Caller has to free this memory block when it
+                                     is no longer needed.
+  @param [out]  BufferSize           Size of the returned message payload in buffer.
+
+  @retval      EFI_SUCCESS           Gets particular handle of SMBIOS structure successfully.
+  @retval      EFI_UNSUPPORTED       The function is unsupported by this
+                                     driver instance.
+  @retval      Other values          Fail to set SMBIOS structure table.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *PLDM_GET_SMBIOS_STRUCTURE_BY_HANDLE)(
+  IN   EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL  *This,
+  IN   UINT16                               Handle,
+  OUT  UINT8                                **Buffer,
+  OUT  UINT32                               *BufferSize
+  );
+
+//
+// EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL
+//
+typedef struct {
+  PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA    GetSmbiosStructureTableMetaData;
+  PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA    SetSmbiosStructureTableMetaData;
+  PLDM_GET_SMBIOS_STRUCTURE_TABLE             GetSmbiosStructureTable;
+  PLDM_SET_SMBIOS_STRUCTURE_TABLE             SetSmbiosStructureTable;
+  PLDM_GET_SMBIOS_STRUCTURE_BY_TYPE           GetSmbiosStructureByType;
+  PLDM_GET_SMBIOS_STRUCTURE_BY_HANDLE         GetSmbiosStructureByHandle;
+} EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_V1_0;
+
+///
+/// Definitions of EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL.
+/// This is a union that can accommodate the new functionalities defined
+/// in PLDM SMBIOS Transfer specification in the future.
+/// The new added function must has its own EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL
+/// structure with the incremental version number.
+///   e.g., EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_V1_1.
+///
+/// The new function must be added base on the last version of
+/// EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL to keep the backward compatibility.
+///
+typedef union {
+  EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_V1_0    *Version1_0;
+} EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_FUNCTION;
+
+struct _EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL {
+  UINT16                                          ProtocolVersion;
+  EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_FUNCTION    Functions;
+};
+
+extern EFI_GUID  gEdkiiPldmSmbiosTransferProtocolGuid;
+
+#endif // EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_H_
diff --git a/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c b/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c
new file mode 100644
index 0000000000..5f1b1028f3
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.c
@@ -0,0 +1,518 @@
+/** @file
+  This file provides edk2 PLDM SMBIOS Transfer Protocol implementation.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Revision Reference:
+   Platform Level Data Model (PLDM) for SMBIOS Data Transfer Specification
+   Version 1.0.1
+   https://www.dmtf.org/sites/default/files/standards/documents/DSP0246_1.0.1.pdf
+**/
+
+#include <PiDxe.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+#include <Library/BasePldmProtocolLib.h>
+#include <Library/ManageabilityTransportHelperLib.h>
+#include <IndustryStandard/PldmSmbiosTransfer.h>
+#include <IndustryStandard/SmBios.h>
+#include <Protocol/PldmSmbiosTransferProtocol.h>
+#include <Protocol/Smbios.h>
+
+UINT32  SetSmbiosStructureTableHandle;
+
+/**
+  Get the full size of SMBIOS structure including optional strings that follow the formatted structure.
+
+  @param Head                   Pointer to the beginning of SMBIOS structure.
+  @param NumberOfStrings        The returned number of optional strings that follow the formatted structure.
+
+  @return Size                  The returned size.
+**/
+UINTN
+GetSmbiosStructureSize (
+  IN   EFI_SMBIOS_TABLE_HEADER  *Head,
+  OUT  UINTN                    *NumberOfStrings
+  )
+{
+  UINTN  Size;
+  UINTN  StrLen;
+  CHAR8  *CharInStr;
+  UINTN  StringsNumber;
+
+  CharInStr     = (CHAR8 *)Head + Head->Length;
+  Size          = Head->Length;
+  StringsNumber = 0;
+  StrLen        = 0;
+  //
+  // look for the two consecutive zeros, check the string limit by the way.
+  //
+  while (*CharInStr != 0 || *(CharInStr+1) != 0) {
+    if (*CharInStr == 0) {
+      Size += 1;
+      CharInStr++;
+    }
+
+    for (StrLen = 0; StrLen < SMBIOS_STRING_MAX_LENGTH; StrLen++) {
+      if (*(CharInStr+StrLen) == 0) {
+        break;
+      }
+    }
+
+    if (StrLen == SMBIOS_STRING_MAX_LENGTH) {
+      return 0;
+    }
+
+    //
+    // forward the pointer
+    //
+    CharInStr     += StrLen;
+    Size          += StrLen;
+    StringsNumber += 1;
+  }
+
+  //
+  // count ending two zeros.
+  //
+  Size += 2;
+
+  if (NumberOfStrings != NULL) {
+    *NumberOfStrings = StringsNumber;
+  }
+
+  return Size;
+}
+
+/**
+
+  This function returns full SMBIOS table length.
+
+  @param  TableAddress      SMBIOS table based address
+  @param  TableMaximumSize  Maximum size of SMBIOS table
+
+  @return SMBIOS table length
+
+**/
+UINTN
+GetSmbiosTableLength (
+  IN VOID   *TableAddress,
+  IN UINTN  TableMaximumSize
+  )
+{
+  VOID   *TableEntry;
+  VOID   *TableAddressEnd;
+  UINTN  TableEntryLength;
+
+  TableAddressEnd = (VOID *)((UINTN)TableAddress + TableMaximumSize);
+  TableEntry      = TableAddress;
+  while (TableEntry < TableAddressEnd) {
+    TableEntryLength = GetSmbiosStructureSize (TableEntry, NULL);
+    if (TableEntryLength == 0) {
+      break;
+    }
+
+    if (((SMBIOS_STRUCTURE *)TableEntry)->Type == 127) {
+      TableEntry = (VOID *)((UINTN)TableEntry + TableEntryLength);
+      break;
+    }
+
+    TableEntry = (VOID *)((UINTN)TableEntry + TableEntryLength);
+  }
+
+  return ((UINTN)TableEntry - (UINTN)TableAddress);
+}
+
+/**
+  This function gets SMBIOS table metadata.
+
+  @param [in]   This         EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+  @param [out]  Buffer       Buffer to receive the SMBIOS table metadata.
+
+  @retval       EFI_SUCCESS            Get SMBIOS table metadata Successfully.
+  @retval       EFI_UNSUPPORTED        The function is unsupported by this
+                                       driver instance.
+  @retval       Other values           Fail to get SMBIOS table metadata.
+**/
+EFI_STATUS
+EFIAPI
+GetSmbiosStructureTableMetaData (
+  IN  EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL   *This,
+  OUT PLDM_SMBIOS_STRUCTURE_TABLE_METADATA  *Buffer
+  )
+{
+  EFI_STATUS  Status;
+  UINT32      ResponseSize;
+
+  DEBUG((DEBUG_INFO, "%a: Set SMBIOS structure table metafile.\n", __FUNCTION__));
+
+  ResponseSize = sizeof (PLDM_SMBIOS_STRUCTURE_TABLE_METADATA);
+  Status       = PldmSubmitCommand (
+                   PLDM_TYPE_SMBIOS,
+                   PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_CODE,
+                   NULL,
+                   0,
+                   (UINT8 *)Buffer,
+                   &ResponseSize
+                   );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Fails to get SMBIOS structure table metafile.\n", __FUNCTION__));
+  }
+  if (ResponseSize != 0) {
+    HelperManageabilityDebugPrint(
+     (VOID *)Buffer,
+     ResponseSize,
+     "SMBIOS structure table metafile got from BMC.\n"
+     );
+  }
+  return Status;
+}
+
+/**
+  This function sets SMBIOS table metadata.
+
+  @param [in]   This         EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+
+  @retval       EFI_SUCCESS            Set SMBIOS table metadata Successfully.
+  @retval       EFI_UNSUPPORTED        The function is unsupported by this
+                                       driver instance.
+  @retval       Other values           Fail to set SMBIOS table metadata.
+**/
+EFI_STATUS
+EFIAPI
+SetSmbiosStructureTableMetaData (
+  IN  EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL   *This,
+  IN  PLDM_SMBIOS_STRUCTURE_TABLE_METADATA  *Buffer
+  )
+{
+  EFI_STATUS  Status;
+  UINT32      ResponseSize;
+  UINT32      RequestSize;
+
+  DEBUG((DEBUG_INFO, "%a: Get SMBIOS structure table metafile.\n", __FUNCTION__));
+
+  RequestSize   = sizeof(PLDM_SMBIOS_STRUCTURE_TABLE_METADATA);
+  ResponseSize  = 0;
+
+  Status = PldmSubmitCommand (
+             PLDM_TYPE_SMBIOS,
+             PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_CODE,
+             (UINT8 *)Buffer,
+             RequestSize,
+             (UINT8 *)NULL,
+             &ResponseSize
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Fails to set SMBIOS structure table metafile.\n", __FUNCTION__));
+  }
+
+  return Status;
+}
+
+/**
+  This function gets SMBIOS structure table.
+
+  @param [in]   This        EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+  @param [out]  Buffer      Pointer to the returned SMBIOS structure table.
+                            Caller has to free this memory block when it
+                            is no longer needed.
+  @param [out]  BufferSize  Size of the returned message payload in buffer.
+
+  @retval       EFI_SUCCESS            Gets SMBIOS structure table successfully.
+  @retval       EFI_UNSUPPORTED        The function is unsupported by this
+                                       driver instance.
+  @retval       Other values           Fail to get SMBIOS structure table.
+**/
+EFI_STATUS
+EFIAPI
+GetSmbiosStructureTable (
+  IN   EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL  *This,
+  OUT  UINT8                                **Buffer,
+  OUT  UINT32                               *BufferSize
+  )
+{
+  DEBUG ((DEBUG_INFO, "%a: Unsupported.\n", __FUNCTION__));
+  // Only support PLDM SMBIOS Transfer push mode.
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  This function sets SMBIOS structure table.
+
+  @param [in]   This        EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+
+  @retval      EFI_SUCCESS            Successful
+  @retval      EFI_NOT_FOUND          No SMBIOS record found on system.
+  @retval      EFI_UNSUPPORTED        The function is unsupported by this
+                                      driver instance.
+  @retval      Other values           Fail to set SMBIOS structure table.
+**/
+EFI_STATUS
+EFIAPI
+SetSmbiosStructureTable (
+  IN  EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL  *This
+  )
+{
+  EFI_STATUS                               Status;
+  SMBIOS_TABLE_3_0_ENTRY_POINT             *SmbiosEntry;
+  EFI_SMBIOS_HANDLE                        SmbiosHandle;
+  EFI_SMBIOS_PROTOCOL                      *Smbios;
+  UINT32                                   PaddingSize;
+  UINT32                                   ResponseSize;
+  UINT32                                   RequestSize;
+  UINT8                                    *RequestBuffer;
+  UINT8                                    *DataPointer;
+  UINT32                                   Crc32;
+  UINT16                                   TableLength;
+  EFI_SMBIOS_TABLE_HEADER                  *Record;
+  PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST  *PldmSetSmbiosStructureTable;
+
+  DEBUG((DEBUG_INFO, "%a: Set SMBIOS structure table.\n", __FUNCTION__));
+
+  Status = gBS->LocateProtocol (
+                  &gEfiSmbiosProtocolGuid,
+                  NULL,
+                  (VOID **)&Smbios
+                  );
+  if (EFI_ERROR(Status)) {
+    DEBUG((DEBUG_ERROR, "%a: No Efi SMBIOS Protocol installed.\n"));
+    return EFI_UNSUPPORTED;
+  }
+  if (Smbios->MajorVersion < 3) {
+    DEBUG((DEBUG_ERROR, "%a: We don't support SMBIOS spec version earlier than v3.0.\n"));
+    return EFI_UNSUPPORTED;
+  }
+  Status = EfiGetSystemConfigurationTable (
+             &gEfiSmbios3TableGuid,
+             (VOID **)&SmbiosEntry
+             );
+  if (Status != EFI_SUCCESS) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to get system configuration table.\n"));
+    return Status;
+  }
+
+  //
+  // Print out SMBIOS table information.
+  DEBUG ((DEBUG_INFO, "PldmSetSmbiosStructureTable SmbiosTable:\n"));
+  DEBUG ((
+    DEBUG_INFO,
+    "AnchorString                ------ '%c%c%c%c%c'\n",
+    SmbiosEntry->AnchorString[0],
+    SmbiosEntry->AnchorString[1],
+    SmbiosEntry->AnchorString[2],
+    SmbiosEntry->AnchorString[3],
+    SmbiosEntry->AnchorString[4]
+    ));
+
+  DEBUG((DEBUG_INFO, "EntryPointStructureChecksum ------ 0x%02x\n", SmbiosEntry->EntryPointStructureChecksum));
+  DEBUG((DEBUG_INFO, "EntryPointLength            ------ 0x%02x\n", SmbiosEntry->EntryPointLength));
+  DEBUG((DEBUG_INFO, "MajorVersion                ------ 0x%02x\n", SmbiosEntry->MajorVersion));
+  DEBUG((DEBUG_INFO, "MinorVersion                ------ 0x%02x\n", SmbiosEntry->MinorVersion));
+  DEBUG((DEBUG_INFO, "DocRev                      ------ 0x%02x\n", SmbiosEntry->DocRev));
+  DEBUG((DEBUG_INFO, "MaxStructureSize            ------ 0x%08x\n", SmbiosEntry->TableMaximumSize));
+  DEBUG((DEBUG_INFO, "EntryPointRevision               - 0x%02x\n", SmbiosEntry->EntryPointRevision));
+  DEBUG((DEBUG_INFO, "TableMaximumSize                 - 0x%08x\n", SmbiosEntry->TableMaximumSize));
+  DEBUG((DEBUG_INFO, "TableAddress                     - 0x%016lx\n", SmbiosEntry->TableAddress));
+
+  SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
+  do {
+    Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
+    if (EFI_ERROR(Status)) {
+      break;
+    }
+    DEBUG((DEBUG_INFO, "  SMBIOS type %d to BMC\n", Record->Type));
+  } while(Status == EFI_SUCCESS);
+
+  TableLength = GetSmbiosTableLength ((VOID *)(UINTN)SmbiosEntry->TableAddress, SmbiosEntry->TableMaximumSize);
+
+  // Padding requirement (0 ~ 3 bytes)
+  PaddingSize = (4 - (TableLength % 4)) % 4;
+
+  // Total request buffer size = PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST + SMBIOS tables + padding + checksum
+  RequestSize = (UINT32)(sizeof(PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST) + TableLength + PaddingSize + sizeof(Crc32));
+  RequestBuffer = (UINT8 *)AllocatePool (RequestSize);
+  if (RequestBuffer == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: No memory resource for sending SetSmbiosStructureTable.\n"));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  // Fill in smbios tables
+  CopyMem (
+    (VOID *)((UINT8 *)RequestBuffer + sizeof(PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST)),
+    (VOID *)(UINTN) SmbiosEntry->TableAddress,
+    TableLength
+    );
+
+  // Fill in padding
+  DataPointer = RequestBuffer + sizeof(PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST) + TableLength;
+  ZeroMem ((VOID *)DataPointer, PaddingSize);
+
+  // Fill in checksum
+  gBS->CalculateCrc32 (
+         (VOID *)(RequestBuffer + sizeof(PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST)),
+         TableLength + PaddingSize,
+         &Crc32
+         );
+  DataPointer += PaddingSize;
+  CopyMem ((VOID *)DataPointer, (VOID *)&Crc32, 4);
+
+  PldmSetSmbiosStructureTable                     = (PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST *)RequestBuffer;
+  PldmSetSmbiosStructureTable->DataTransferHandle = SetSmbiosStructureTableHandle;
+  PldmSetSmbiosStructureTable->TransferFlag       = PLDM_TRANSFER_FLAG_START_AND_END;
+  ResponseSize                                    = sizeof (SetSmbiosStructureTableHandle);
+
+  Status = PldmSubmitCommand (
+             PLDM_TYPE_SMBIOS,
+             PLDM_SET_SMBIOS_STRUCTURE_TABLE_COMMAND_CODE,
+             RequestBuffer,
+             RequestSize,
+             (UINT8 *)&SetSmbiosStructureTableHandle,
+             &ResponseSize
+             );
+  if (RequestBuffer != NULL) {
+    FreePool (RequestBuffer);
+  }
+
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Set SMBIOS structure table.\n", __FUNCTION__));
+  }
+  if (ResponseSize != 0 && ResponseSize <= sizeof(SetSmbiosStructureTableHandle)) {
+    HelperManageabilityDebugPrint(
+     (VOID *)&SetSmbiosStructureTableHandle,
+     ResponseSize,
+     "Set SMBIOS structure table response got from BMC.\n"
+     );
+  }
+  return Status;
+}
+
+/**
+  This function gets particular type of SMBIOS structure.
+
+  @param [in]   This                 EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+  @param [in]   TypeId               The type of SMBIOS structure.
+  @param [in]   StructureInstanceId  The instance ID of particular type of SMBIOS structure.
+  @param [out]  Buffer               Pointer to the returned SMBIOS structure.
+                                     Caller has to free this memory block when it
+                                     is no longer needed.
+  @param [out]  BufferSize           Size of the returned message payload in buffer.
+
+  @retval      EFI_SUCCESS           Gets particular type of SMBIOS structure successfully.
+  @retval      EFI_UNSUPPORTED       The function is unsupported by this
+                                     driver instance.
+  @retval      Other values          Fail to set SMBIOS structure table.
+**/
+EFI_STATUS
+EFIAPI
+GetSmbiosStructureByType (
+  IN   EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL  *This,
+  IN   UINT8                                TypeId,
+  IN   UINT16                               StructureInstanceId,
+  OUT  UINT8                                **Buffer,
+  OUT  UINT32                               *BufferSize
+  )
+{
+  DEBUG ((DEBUG_INFO, "%a: Unsupported.\n", __FUNCTION__));
+  // Only support PLDM SMBIOS Transfer push mode.
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  This function gets particular handle of SMBIOS structure.
+
+  @param [in]   This                 EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance.
+  @param [in]   Handle               The handle of SMBIOS structure.
+  @param [out]  Buffer               Pointer to the returned SMBIOS structure.
+                                     Caller has to free this memory block when it
+                                     is no longer needed.
+  @param [out]  BufferSize           Size of the returned message payload in buffer.
+
+  @retval      EFI_SUCCESS           Gets particular handle of SMBIOS structure successfully.
+  @retval      EFI_UNSUPPORTED       The function is unsupported by this
+                                     driver instance.
+  @retval      Other values          Fail to set SMBIOS structure table.
+**/
+EFI_STATUS
+EFIAPI
+GetSmbiosStructureByHandle (
+  IN   EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL  *This,
+  IN   UINT16                               Handle,
+  OUT  UINT8                                **Buffer,
+  OUT  UINT32                               *BufferSize
+  )
+{
+  DEBUG ((DEBUG_INFO, "%a: Unsupported.\n", __FUNCTION__));
+  // Only support PLDM SMBIOS Transfer push mode.
+  return EFI_UNSUPPORTED;
+}
+
+EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_V1_0  mPldmSmbiosTransferProtocolV10 = {
+  GetSmbiosStructureTableMetaData,
+  SetSmbiosStructureTableMetaData,
+  GetSmbiosStructureTable,
+  SetSmbiosStructureTable,
+  GetSmbiosStructureByType,
+  GetSmbiosStructureByHandle
+};
+
+EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL  mPldmSmbiosTransferProtocol;
+
+/**
+  The entry point of the PLDM SMBIOS Transfer DXE driver.
+
+  @param[in] ImageHandle - Handle of this driver image
+  @param[in] SystemTable - Table containing standard EFI services
+
+  @retval EFI_SUCCESS    - IPMI Protocol is installed successfully.
+  @retval Otherwise      - Other errors.
+**/
+EFI_STATUS
+EFIAPI
+DxePldmSmbiosTransferEntry (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_HANDLE  Handle;
+  EFI_STATUS  Status;
+
+  DEBUG ((DEBUG_INFO, "%a: Entry.\n", __FUNCTION__));
+
+  SetSmbiosStructureTableHandle = 0;
+
+  Handle                                           = NULL;
+  mPldmSmbiosTransferProtocol.ProtocolVersion      = EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_VERSION;
+  mPldmSmbiosTransferProtocol.Functions.Version1_0 = &mPldmSmbiosTransferProtocolV10;
+  Status                                           = gBS->InstallProtocolInterface (
+                                                            &Handle,
+                                                            &gEdkiiPldmSmbiosTransferProtocolGuid,
+                                                            EFI_NATIVE_INTERFACE,
+                                                            (VOID **)&mPldmSmbiosTransferProtocol
+                                                            );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Fail to install EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL.\n", __FUNCTION__));
+  }
+
+  return Status;
+}
+
+/**
+  This is the unload handler of PLDM SMBIOS Transfer DXE driver.
+
+  @param[in] ImageHandle           The driver's image handle.
+
+  @retval    EFI_SUCCESS           The image is unloaded.
+  @retval    Others                Failed to unload the image.
+
+**/
+EFI_STATUS
+EFIAPI
+PldmSmbiosTransferUnloadImage (
+  IN EFI_HANDLE  ImageHandle
+  )
+{
+  return EFI_SUCCESS;
+}
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 07/14] ManageabilityPkg/KCS: KCS transport interface
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (5 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 06/14] ManageabilityPkg: Add PldmSmbiosTransferDxe driver Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 08/14] ManageabilityPkg: Add definitions of MCTP Chang, Abner
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: Abner Chang <abner.chang@amd.com>

- Return Maximum Transfer Unit for MCTP over KCS
- Check the parameters

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../Common/ManageabilityTransportKcs.h        |   2 +-
 .../Common/KcsCommon.c                        | 111 ++++++++++--------
 .../Dxe/ManageabilityTransportKcs.c           |  24 ++--
 3 files changed, 77 insertions(+), 60 deletions(-)

diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h
index d6685c165e..8c6a64416a 100644
--- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/ManageabilityTransportKcs.h
@@ -71,7 +71,7 @@ typedef struct {
 EFI_STATUS
 EFIAPI
 KcsTransportSendCommand (
-  IN  MANAGEABILITY_TRANSPORT_HEADER   TransmitHeader,
+  IN  MANAGEABILITY_TRANSPORT_HEADER   TransmitHeader OPTIONAL,
   IN  UINT16                           TransmitHeaderSize,
   IN  MANAGEABILITY_TRANSPORT_TRAILER  TransmitTrailer OPTIONAL,
   IN  UINT16                           TransmitTrailerSize,
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/KcsCommon.c b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/KcsCommon.c
index 14a7047447..6ff14f0c97 100644
--- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/KcsCommon.c
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Common/KcsCommon.c
@@ -99,14 +99,14 @@ ClearOBF (
   Algorithm is based on flow chart provided in IPMI spec 2.0
   Figure 9-6, KCS Interface BMC to SMS Write Transfer Flow Chart
 
-  @param[in]  TransmitHeader        KCS packet header.
-  @param[in]  TransmitHeaderSize    KCS packet header size in byte.
-  @param[in]  TransmitTrailer       KCS packet trailer.
-  @param[in]  TransmitTrailerSize   KCS packet trailer size in byte.
-  @param[in]  RequestData           Command Request Data, could be NULL.
-                                    RequestDataSize must be zero, if RequestData
-                                    is NULL.
-  @param[in]  RequestDataSize       Size of Command Request Data.
+  @param[in]      TransmitHeader        KCS packet header.
+  @param[in]      TransmitHeaderSize    KCS packet header size in byte.
+  @param[in]      TransmitTrailer       KCS packet trailer.
+  @param[in]      TransmitTrailerSize   KCS packet trailer size in byte.
+  @param[in]      RequestData           Command Request Data, could be NULL.
+                                        RequestDataSize must be zero, if RequestData
+                                        is NULL.
+  @param[in]      RequestDataSize       Size of Command Request Data.
 
   @retval     EFI_SUCCESS           The command byte stream was successfully
                                     submit to the device and a response was
@@ -414,7 +414,7 @@ KcsTransportRead (
 EFI_STATUS
 EFIAPI
 KcsTransportSendCommand (
-  IN  MANAGEABILITY_TRANSPORT_HEADER   TransmitHeader,
+  IN  MANAGEABILITY_TRANSPORT_HEADER   TransmitHeader OPTIONAL,
   IN  UINT16                           TransmitHeaderSize,
   IN  MANAGEABILITY_TRANSPORT_TRAILER  TransmitTrailer OPTIONAL,
   IN  UINT16                           TransmitTrailerSize,
@@ -427,6 +427,7 @@ KcsTransportSendCommand (
   EFI_STATUS                Status;
   UINT32                    RspHeaderSize;
   IPMI_KCS_RESPONSE_HEADER  RspHeader;
+  UINT32                    ExpectedResponseDataSize;
 
   if ((RequestData != NULL) && (RequestDataSize == 0)) {
     DEBUG ((DEBUG_ERROR, "%a: Mismatched values of RequestData and RequestDataSize\n", __FUNCTION__));
@@ -438,65 +439,71 @@ KcsTransportSendCommand (
     return EFI_INVALID_PARAMETER;
   }
 
-  if (TransmitHeader == NULL) {
-    DEBUG ((DEBUG_ERROR, "%a: TransmitHeader is NULL\n", __FUNCTION__));
-    return EFI_INVALID_PARAMETER;
+  // Print out the request payloads.
+  if ((TransmitHeader != NULL) && (TransmitHeaderSize != 0)) {
+    HelperManageabilityDebugPrint ((VOID *)TransmitHeader, (UINT32)TransmitHeaderSize, "KCS Transmit Header:\n");
   }
 
-  //
-  // Print out the request payloads.
-  HelperManageabilityDebugPrint ((VOID *)TransmitHeader, TransmitHeaderSize, "KCS Transmit Header:\n");
   if (RequestData != NULL) {
     HelperManageabilityDebugPrint ((VOID *)RequestData, RequestDataSize, "KCS Request Data:\n");
   }
 
-  if (TransmitTrailer != NULL) {
-    HelperManageabilityDebugPrint ((VOID *)TransmitTrailer, TransmitTrailerSize, "KCS Transmit Trailer:\n");
-  }
+  if ((TransmitTrailer != NULL) && (TransmitTrailerSize != 0)) {
+    HelperManageabilityDebugPrint ((VOID *)TransmitTrailer, (UINT32)TransmitTrailerSize, "KCS Transmit Trailer:\n");
+  }
+
+  if ((TransmitHeader != NULL) || (RequestData != NULL)) {
+    Status = KcsTransportWrite (
+               TransmitHeader,
+               TransmitHeaderSize,
+               TransmitTrailer,
+               TransmitTrailerSize,
+               RequestData,
+               RequestDataSize
+               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "KCS Write Failed with Status(%r)", Status));
+      return Status;
+    }
 
-  Status = KcsTransportWrite (
-             TransmitHeader,
-             TransmitHeaderSize,
-             TransmitTrailer,
-             TransmitTrailerSize,
-             RequestData,
-             RequestDataSize
-             );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((DEBUG_ERROR, "IPMI KCS Write Failed with Status(%r)", Status));
-    return Status;
-  }
+    //
+    // Read the response header
+    RspHeaderSize = sizeof (IPMI_KCS_RESPONSE_HEADER);
+    Status        = KcsTransportRead ((UINT8 *)&RspHeader, &RspHeaderSize);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "KCS read response header failed Status(%r), " \
+        "RspNetFunctionLun = 0x%x, " \
+        "Comamnd = 0x%x \n",
+        Status,
+        RspHeader.NetFunc,
+        RspHeader.Command
+        ));
+      return (Status);
+    }
 
-  //
-  // Read the response header
-  RspHeaderSize = sizeof (IPMI_KCS_RESPONSE_HEADER);
-  Status        = KcsTransportRead ((UINT8 *)&RspHeader, &RspHeaderSize);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "IPMI KCS read response header failed Status(%r), " \
-      "RspNetFunctionLun = 0x%x, " \
-      "Command = 0x%x \n",
-      Status,
-      RspHeader.NetFunc,
-      RspHeader.Command
-      ));
-    return (Status);
+    //
+    // Print out the response payloads.
+    HelperManageabilityDebugPrint ((VOID *)&RspHeader, RspHeaderSize, "KCS Response Header:\n");
   }
 
-  //
-  // Print out the response payloads.
-  HelperManageabilityDebugPrint ((VOID *)&RspHeader, (UINT16)RspHeaderSize, "KCS Response Header:\n");
-
   if ((ResponseData != NULL) && (ResponseDataSize != NULL) && (*ResponseDataSize != 0)) {
-    Status = KcsTransportRead ((UINT8 *)ResponseData, ResponseDataSize);
+    ExpectedResponseDataSize = *ResponseDataSize;
+    Status                   = KcsTransportRead ((UINT8 *)ResponseData, ResponseDataSize);
     if (EFI_ERROR (Status)) {
-      DEBUG ((DEBUG_ERROR, "IPMI KCS response read Failed with Status(%r)", Status));
+      DEBUG ((DEBUG_ERROR, "KCS response read Failed with Status(%r)", Status));
     }
 
     //
     // Print out the response payloads.
-    HelperManageabilityDebugPrint ((VOID *)ResponseData, *ResponseDataSize, "KCS Response Data:\n");
+    if (*ResponseDataSize != 0) {
+      if (ExpectedResponseDataSize != *ResponseDataSize) {
+        DEBUG ((DEBUG_ERROR, "Expected KCS response size : %d is not matched to returned size : %d.\n", ExpectedResponseDataSize, *ResponseDataSize));
+        Status = EFI_DEVICE_ERROR;
+      }
+      HelperManageabilityDebugPrint ((VOID *)ResponseData, (UINT32)*ResponseDataSize, "KCS Response Data:\n");
+    }
   } else {
     *ResponseDataSize = 0;
   }
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
index a9eff886d0..db4e707b3a 100644
--- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
@@ -10,6 +10,7 @@
 #include <Uefi.h>
 #include <IndustryStandard/IpmiKcs.h>
 #include <Library/IoLib.h>
+#include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
 #include <Library/MemoryAllocationLib.h>
 #include <Library/ManageabilityTransportLib.h>
@@ -225,13 +226,6 @@ KcsTransportTransmitReceive (
     return;
   }
 
-  // Transmit header is necessary for KCS transport, which could be
-  // NetFn, Command and etc.
-  if (TransferToken->TransmitHeader == NULL) {
-    TransferToken->TransferStatus = EFI_INVALID_PARAMETER;
-    return;
-  }
-
   Status = KcsTransportSendCommand (
              TransferToken->TransmitHeader,
              TransferToken->TransmitHeaderSize,
@@ -354,6 +348,22 @@ GetTransportCapability (
   }
 
   *TransportCapability = 0;
+  if (CompareGuid (
+        TransportToken->ManageabilityProtocolSpecification,
+        &gManageabilityProtocolIpmiGuid
+        ))
+  {
+    *TransportCapability |=
+      (MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POSITION);
+  } else if (CompareGuid (
+               TransportToken->ManageabilityProtocolSpecification,
+               &gManageabilityProtocolMctpGuid
+               ))
+  {
+    *TransportCapability |=
+      (MCTP_KCS_MTU_IN_POWER_OF_2 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POSITION);
+  }
+
   return EFI_SUCCESS;
 }
 
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 08/14] ManageabilityPkg: Add definitions of MCTP
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (6 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 07/14] ManageabilityPkg/KCS: KCS transport interface Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 09/14] ManageabilityPkg/MctpProtocol: Add MctpProtocol Chang, Abner
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: abnchang <abnchang@amd.com>

Add definitions of MCTP manageability transport
interface library.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 Features/ManageabilityPkg/ManageabilityPkg.dec | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dec b/Features/ManageabilityPkg/ManageabilityPkg.dec
index 309faa8c98..025d89a37a 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dec
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dec
@@ -45,6 +45,7 @@
   # Manageability Protocol IPMI
   gManageabilityProtocolIpmiGuid    = { 0x36ACA47C, 0xCC80, 0x473B, { 0xAB, 0xEC, 0xF3, 0x98, 0xFF, 0x87, 0x74, 0x5B } }
   # Manageability Protocol MCTP
+  #  MCTP is a transport interface but also a protocol that can be trasmitted over other transport interfaces.
   gManageabilityProtocolMctpGuid    = { 0x76FED8F1, 0x0BE5, 0x4269, { 0xA3, 0x1A, 0x38, 0x0F, 0x54, 0xF1, 0xA1, 0x8A } }
   # Manageability Protocol PLDM
   gManageabilityProtocolPldmGuid    = { 0x3958090D, 0x69DD, 0x4868, { 0x9C, 0x41, 0xC9, 0xAC, 0x31, 0xB5, 0x25, 0xC5 } }
@@ -52,3 +53,18 @@
 [Protocols]
   gEdkiiPldmProtocolGuid                = { 0x60997616, 0xDB70, 0x4B5F, { 0x86, 0xA4, 0x09, 0x58, 0xA3, 0x71, 0x47, 0xB4 } }
   gEdkiiPldmSmbiosTransferProtocolGuid  = { 0xFA431C3C, 0x816B, 0x4B32, { 0xA3, 0xE0, 0xAD, 0x9B, 0x7F, 0x64, 0x27, 0x2E } }
+  gEdkiiMctpProtocolGuid                = { 0xE93465C1, 0x9A31, 0x4C96, { 0x92, 0x56, 0x22, 0x0A, 0xE1, 0x80, 0xB4, 0x1B } }
+
+[PcdsFixedAtBuild]
+  ## This value is the MCTP Interface source and destination endpoint ID for transmiting MCTP message.
+  # @Prompt MCTP source endpoint ID
+  gManageabilityPkgTokenSpaceGuid.PcdMctpSourceEndpointId|0|UINT8|0x00000001
+  # @Prompt MCTP destination endpoint ID
+  gManageabilityPkgTokenSpaceGuid.PcdMctpDestinationEndpointId|0|UINT8|0x00000002
+  ## This is the value of MCTP KCS I/O base address mode
+  # @Prompt MCTP KCS I/O base address mode
+  gManageabilityPkgTokenSpaceGuid.PcdMctpKcsMemoryMappedIo|0|BOOLEAN|0x00000003
+  ## This is the value of MCTP KCS I/O base address
+  # @Prompt MCTP KCS (Memory mapped) I/O base address
+  gManageabilityPkgTokenSpaceGuid.PcdMctpKcsBaseAddress|0xca2|UINT32|0x00000004
+
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 09/14] ManageabilityPkg/MctpProtocol: Add MctpProtocol
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (7 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 08/14] ManageabilityPkg: Add definitions of MCTP Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 10/14] ManageabilityPkg: Add MCTP transport interface Chang, Abner
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: Abner Chang <abner.chang@amd.com>

MctpProtocol that transmits MCTP message
over manageability transport interface
library.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../Include/Dsc/Manageability.dsc             |   1 +
 .../MctpProtocol/Dxe/MctpProtocolDxe.inf      |  53 ++
 .../Include/Protocol/MctpProtocol.h           | 102 ++++
 .../MctpProtocol/Common/MctpProtocolCommon.h  | 139 ++++++
 .../MctpProtocol/Common/MctpProtocolCommon.c  | 461 ++++++++++++++++++
 .../Universal/MctpProtocol/Dxe/MctpProtocol.c | 216 ++++++++
 6 files changed, 972 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/MctpProtocolCommon.h
 create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.c
 create mode 100644 Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocol.c

diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
index a5a4fd6615..bdb3bc8378 100644
--- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
+++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
@@ -26,4 +26,5 @@
   ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocolDxe.inf
   ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf
   ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf
+  ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf
 
diff --git a/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf b/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf
new file mode 100644
index 0000000000..483fbcc04b
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf
@@ -0,0 +1,53 @@
+## @file
+# MCTP Protocol DXE Driver.
+#
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001d
+  BASE_NAME                      = MctpDxe
+  FILE_GUID                      = 58AF169A-AA3F-462B-B0F1-25FBE6C97978
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = DxeMctpEntry
+  UNLOAD_IMAGE                   = MctpUnloadImage
+
+#
+#  VALID_ARCHITECTURES           = 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..068a30f159
--- /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.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef EDKII_MCTP_PROTOCOL_H_
+#define EDKII_MCTP_PROTOCOL_H_
+
+#include <IndustryStandard/Mctp.h>
+
+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 instance.
+  @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 milliseconds.
+                                                MANAGEABILITY_TRANSPORT_NO_TIMEOUT means no timeout value.
+  @param[out]        ResponseData               Message Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize           Size of Message Response Data.
+  @param[in]         ResponseTimeout            Timeout value in milliseconds.
+                                                MANAGEABILITY_TRANSPORT_NO_TIMEOUT means no timeout value.
+  @param[out]        AdditionalTransferError    MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS.
+
+  @retval EFI_SUCCESS            The message was successfully send to transport interface and a
+                                 response was successfully received.
+  @retval EFI_NOT_FOUND          The message was not successfully sent to transport interface or a response
+                                 was not successfully received from transport interface.
+  @retval EFI_NOT_READY          MCTP transport interface is not ready for MCTP message.
+  @retval EFI_DEVICE_ERROR       MCTP transport interface Device hardware error.
+  @retval EFI_TIMEOUT            The message time out.
+  @retval EFI_UNSUPPORTED        The message was not successfully sent to the transport interface.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource 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/MctpProtocolCommon.h b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.h
new file mode 100644
index 0000000000..b3ee0f303e
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.h
@@ -0,0 +1,139 @@
+/** @file
+    MCTP Manageability Protocol common header file.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MANAGEABILITY_MCTP_COMMON_H_
+#define MANAGEABILITY_MCTP_COMMON_H_
+
+#include <IndustryStandard/IpmiKcs.h>
+#include <Library/ManageabilityTransportLib.h>
+
+#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 library.
+
+  @param[in]         TransportToken       The transport interface.
+  @param[out]        HardwareInformation  Pointer to receive the hardware information.
+
+  @retval EFI_SUCCESS            Hardware information is returned in HardwareInformation.
+                                 Caller must free the memory allocated for 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 header of request.
+  @param[out]        PacketHeaderSize           Packet header size.
+  @param[in, out]    PacketBody                 The request body.
+                                                When IN, it is the caller's request body.
+                                                When OUT and NULL, the request body is not
+                                                changed.
+                                                Whee out and non-NULL, the request body is
+                                                changed to comfort the transport 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 request body is unchanged.
+  @param[out]        PacketTrailer              The pointer to receive trailer 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 milliseconds.
+                                                MANAGEABILITY_TRANSPORT_NO_TIMEOUT means no timeout value.
+  @param[out]        ResponseData               Message Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize           Size of Message Response Data.
+  @param[in]         ResponseTimeout            Timeout value in milliseconds.
+                                                MANAGEABILITY_TRANSPORT_NO_TIMEOUT means no timeout value.
+  @param[out]        AdditionalTransferError    MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS.
+
+  @retval EFI_SUCCESS            The message was successfully send to transport interface and a
+                                 response was successfully received.
+  @retval EFI_NOT_FOUND          The message was not successfully sent to transport interface or a response
+                                 was not successfully received from transport interface.
+  @retval EFI_NOT_READY          MCTP transport interface is not ready for MCTP message.
+  @retval EFI_DEVICE_ERROR       MCTP transport interface Device hardware error.
+  @retval EFI_TIMEOUT            The message time out.
+  @retval EFI_UNSUPPORTED        The message was not successfully sent to the transport interface.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource 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                                      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
+  );
+
+#endif
diff --git a/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.c b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.c
new file mode 100644
index 0000000000..4835da9ef3
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/MctpProtocol/Common/MctpProtocolCommon.c
@@ -0,0 +1,461 @@
+/** @file
+
+  MCTP Manageability Protocol common file.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include <Uefi.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/ManageabilityTransportHelperLib.h>
+#include <Library/ManageabilityTransportMctpLib.h>
+#include <Library/ManageabilityTransportLib.h>
+
+#include <IndustryStandard/Mctp.h>
+
+#include "MctpProtocolCommon.h"
+
+extern CHAR16  *mTransportName;
+extern UINT32  mTransportMaximumPayload;
+
+MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION  mHardwareInformation;
+UINT8                                         mMctpPacketSequence;
+BOOLEAN                                       mStartOfMessage;
+BOOLEAN                                       mEndOfMessage;
+
+/**
+  This functions setup the MCTP transport hardware information according
+  to the specification of transport token acquired from transport library.
+
+  @param[in]         TransportToken       The transport interface.
+  @param[out]        HardwareInformation  Pointer to receive the hardware information.
+
+  @retval EFI_SUCCESS            Hardware information is returned in HardwareInformation.
+                                 Caller must free the memory allocated for 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 = NULL;
+  if (CompareGuid (&gManageabilityTransportKcsGuid, TransportToken->Transport->ManageabilityTransportSpecification)) {
+    KcsHardwareInfo = AllocatePool (sizeof (MANAGEABILITY_TRANSPORT_KCS_HARDWARE_INFO));
+    if (KcsHardwareInfo == NULL) {
+      DEBUG ((DEBUG_ERROR, "%a: Not enough memory for MANAGEABILITY_TRANSPORT_KCS_HARDWARE_INFO.\n", __FUNCTION__));
+      return EFI_OUT_OF_RESOURCES;
+    }
+    MctpKcsMemMapIo = PcdGetBool(PcdMctpKcsMemoryMappedIo);
+    if (MctpKcsMemMapIo) {
+      KcsHardwareInfo->MemoryMap                    = MANAGEABILITY_TRANSPORT_KCS_MEMORY_MAP_IO;
+      KcsHardwareInfo->IoBaseAddress.IoAddress32    = MCTP_KCS_BASE_ADDRESS;
+      KcsHardwareInfo->IoDataInAddress.IoAddress32  = MCTP_KCS_REG_DATA_IN_MEMMAP;
+      KcsHardwareInfo->IoDataOutAddress.IoAddress32 = MCTP_KCS_REG_DATA_OUT_MEMMAP;
+      KcsHardwareInfo->IoCommandAddress.IoAddress32 = MCTP_KCS_REG_COMMAND_MEMMAP;
+      KcsHardwareInfo->IoStatusAddress.IoAddress32  = MCTP_KCS_REG_STATUS_MEMMAP;
+    } else {
+      KcsHardwareInfo->MemoryMap                    = MANAGEABILITY_TRANSPORT_KCS_IO_MAP_IO;
+      KcsHardwareInfo->IoBaseAddress.IoAddress16    = (UINT16)MCTP_KCS_BASE_ADDRESS;
+      KcsHardwareInfo->IoDataInAddress.IoAddress16  = (UINT16)MCTP_KCS_REG_DATA_IN_IO;
+      KcsHardwareInfo->IoDataOutAddress.IoAddress16 = (UINT16)MCTP_KCS_REG_DATA_OUT_IO;
+      KcsHardwareInfo->IoCommandAddress.IoAddress16 = (UINT16)MCTP_KCS_REG_COMMAND_IO;
+      KcsHardwareInfo->IoStatusAddress.IoAddress16  = (UINT16)MCTP_KCS_REG_STATUS_IO;
+    }
+    HardwareInformation->Kcs = 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 header of request.
+  @param[out]        PacketHeaderSize           Packet header size.
+  @param[in, out]    PacketBody                 The request body.
+                                                When IN, it is the caller's request body.
+                                                When OUT and NULL, the request body is not
+                                                changed.
+                                                Whee out and non-NULL, the request body is
+                                                changed to comfort the transport 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 request body is unchanged.
+  @param[out]        PacketTrailer              The pointer to receive trailer 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 == NULL || PacketHeaderSize == NULL ||
+      PacketBody == NULL || PacketBodySize == NULL ||
+      PacketTrailer == NULL || PacketTrailerSize == NULL
+      ) {
+      DEBUG ((DEBUG_ERROR, "%a: One or more than one of the input parameter is invalid.\n"));
+      return EFI_INVALID_PARAMETER;
+  }
+
+  if (CompareGuid (&gManageabilityTransportKcsGuid, TransportToken->Transport->ManageabilityTransportSpecification)) {
+    MctpKcsHeader = (MANAGEABILITY_MCTP_KCS_HEADER *)AllocateZeroPool (sizeof(MANAGEABILITY_MCTP_KCS_HEADER));
+    if (MctpKcsHeader == NULL) {
+      DEBUG ((DEBUG_ERROR, "%a: Not enough resource for MANAGEABILITY_MCTP_KCS_HEADER.\n", __FUNCTION__));
+      return EFI_OUT_OF_RESOURCES;;
+    }
+    Pec = (UINT8 *)AllocateZeroPool (sizeof(UINT8));
+    if (Pec == 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 = DEFINING_BODY_DMTF_PRE_OS_WORKING_GROUP;
+    MctpKcsHeader->NetFunc      = MCTP_KCS_NETFN_LUN;
+    MctpKcsHeader->ByteCount    = (UINT8)(MIN(mTransportMaximumPayload, *PacketBodySize + (UINT8)sizeof(MCTP_MESSAGE_HEADER) + (UINT8)sizeof(MCTP_TRANSPORT_HEADER)));
+
+    ThisPackage = (UINT8 *)AllocateZeroPool (MctpKcsHeader->ByteCount);
+    if (ThisPackage == 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 = (MCTP_TRANSPORT_HEADER *)ThisPackage;
+    MctpTransportHeader->Bits.Reserved              = 0;
+    MctpTransportHeader->Bits.HeaderVersion         = MCTP_KCS_HEADER_VERSION;
+    MctpTransportHeader->Bits.DestinationEndpointId = PcdGet8(PcdMctpDestinationEndpointId);
+    MctpTransportHeader->Bits.SourceEndpointIdId    = PcdGet8(PcdMctpSourceEndpointId);
+    MctpTransportHeader->Bits.MessageTag            = MCTP_MESSAGE_TAG;
+    MctpTransportHeader->Bits.TagOwner              = MCTP_MESSAGE_TAG_OWNER_REQUEST;
+    MctpTransportHeader->Bits.PacketSequence        = mMctpPacketSequence & MCTP_PACKET_SEQUENCE_MASK;
+    MctpTransportHeader->Bits.StartOfMessage        = mStartOfMessage? 1: 0;
+    MctpTransportHeader->Bits.EndOfMessage          = mEndOfMessage? 1: 0;
+
+    // Setup MCTP message header
+    MctpMessageHeader = (MCTP_MESSAGE_HEADER *)(MctpTransportHeader + 1);
+    MctpMessageHeader->Bits.MessageType   = MctpType;
+    MctpMessageHeader->Bits.IntegrityCheck = RequestDataIntegrityCheck? 1: 0;
+
+    // Copy payload
+    CopyMem ((VOID *)(MctpMessageHeader + 1), (VOID *)*PacketBody, *PacketBodySize);
+
+    //
+    // Generate PEC follow SMBUS 2.0 specification.
+    *Pec = HelperManageabilityGenerateCrc8 (MCTP_KCS_PACKET_ERROR_CODE_POLY, 0, ThisPackage, MctpKcsHeader->ByteCount);
+
+    *PacketBody        = (UINT8 *)ThisPackage;
+    *PacketBodySize    = MctpKcsHeader->ByteCount;
+    *PacketTrailer     = (MANAGEABILITY_TRANSPORT_TRAILER)Pec;
+    *PacketHeader      = (MANAGEABILITY_TRANSPORT_HEADER)MctpKcsHeader;
+    *PacketHeaderSize  = sizeof (MANAGEABILITY_MCTP_KCS_HEADER);
+    *PacketTrailerSize = 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 milliseconds.
+                                                MANAGEABILITY_TRANSPORT_NO_TIMEOUT means no timeout value.
+  @param[out]        ResponseData               Message Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize           Size of Message Response Data.
+  @param[in]         ResponseTimeout            Timeout value in milliseconds.
+                                                MANAGEABILITY_TRANSPORT_NO_TIMEOUT means no timeout value.
+  @param[out]        AdditionalTransferError    MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS.
+
+  @retval EFI_SUCCESS            The message was successfully send to transport interface and a
+                                 response was successfully received.
+  @retval EFI_NOT_FOUND          The message was not successfully sent to transport interface or a response
+                                 was not successfully received from transport interface.
+  @retval EFI_NOT_READY          MCTP transport interface is not ready for MCTP message.
+  @retval EFI_DEVICE_ERROR       MCTP transport interface Device hardware error.
+  @retval EFI_TIMEOUT            The message time out.
+  @retval EFI_UNSUPPORTED        The message was not successfully sent to the transport interface.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource 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                                      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
+  )
+{
+  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 == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: No transport toke for MCTP\n", __FUNCTION__));
+    return EFI_UNSUPPORTED;
+  }
+
+  Status = TransportToken->Transport->Function.Version1_0->TransportStatus (
+                                                             TransportToken,
+                                                             AdditionalTransferError
+                                                             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Transport %s for MCTP has problem - (%r)\n", __FUNCTION__, mTransportName, Status));
+    return Status;
+  }
+
+  MultiPackages = NULL;
+  Status = HelperManageabilitySplitPayload (
+             sizeof(MCTP_TRANSPORT_HEADER) + sizeof (MCTP_MESSAGE_HEADER),
+             0,
+             RequestData,
+             RequestDataSize,
+             mTransportMaximumPayload,
+             &MultiPackages
+             );
+  if (EFI_ERROR (Status) || MultiPackages == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Fails to split payload into multiple packages - (%r)\n", __FUNCTION__, mTransportName, Status));
+    return Status;
+  }
+
+  // Print transmission packages info.
+  DEBUG((DEBUG_MANAGEABILITY_INFO, "Manageability Transmission packages:\n"));
+  ThisPackage = (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *)(MultiPackages + 1);
+  for (IndexOfPackage = 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 = (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *)(MultiPackages + 1);
+  mMctpPacketSequence = 0;
+  for (IndexOfPackage = 0; IndexOfPackage < MultiPackages->NumberOfPackages; IndexOfPackage ++) {
+    MctpTransportHeader   = NULL;
+    MctpTransportTrailer  = NULL;
+    ThisRequestData       = ThisPackage->PayloadPointer;
+    ThisRequestDataSize   = ThisPackage->PayloadSize;
+
+    // Setup Start of Message bit and End of Message bit.
+    if (MultiPackages->NumberOfPackages == 1) {
+      mStartOfMessage = TRUE;
+      mEndOfMessage   = TRUE;
+    } else if (IndexOfPackage == 0) {
+      mStartOfMessage = TRUE;
+      mEndOfMessage   = FALSE;
+    }  else if (IndexOfPackage == MultiPackages->NumberOfPackages - 1) {
+      mStartOfMessage = FALSE;
+      mEndOfMessage   = TRUE;
+    } else {
+      mStartOfMessage = FALSE;
+      mEndOfMessage   = FALSE;
+    }
+    Status = 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      = MctpTransportHeader;
+    TransferToken.TransmitHeaderSize  = MctpTransportHeaderSize;
+    TransferToken.TransmitTrailer     = MctpTransportTrailer;
+    TransferToken.TransmitTrailerSize = MctpTransportTrailerSize;
+
+    // Transmit packet.
+    if ((ThisRequestData == NULL) || (ThisRequestDataSize == 0)) {
+
+      // Transmit parameter were not changed by SetupMctpRequestTransportPacket().
+      TransferToken.TransmitPackage.TransmitPayload    = ThisPackage->PayloadPointer;
+      TransferToken.TransmitPackage.TransmitSizeInByte = ThisPackage->PayloadSize;
+    } else {
+      TransferToken.TransmitPackage.TransmitPayload    = ThisRequestData;
+      TransferToken.TransmitPackage.TransmitSizeInByte = ThisRequestDataSize;
+    }
+    TransferToken.TransmitPackage.TransmitTimeoutInMillisecond = MANAGEABILITY_TRANSPORT_NO_TIMEOUT;
+
+    // Receive packet.
+    TransferToken.ReceivePackage.ReceiveBuffer                = NULL;
+    TransferToken.ReceivePackage.ReceiveSizeInByte            = 0;
+    TransferToken.ReceivePackage.TransmitTimeoutInMillisecond = MANAGEABILITY_TRANSPORT_NO_TIMEOUT;
+
+    // Print out MCTP packet.
+    DEBUG((
+      DEBUG_INFO,
+      "%a: Send MCTP message type: 0x%x, from source endpoint ID: 0x%x to destination ID 0x%x: Request size: 0x%x, Response size: 0x%x\n",
+      __FUNCTION__,
+      MctpType,
+      MctpSourceEndpointId,
+      MctpDestinationEndpointId,
+      TransferToken.TransmitPackage.TransmitSizeInByte,
+      TransferToken.ReceivePackage.ReceiveSizeInByte
+    ));
+
+    if (MctpTransportHeader != NULL && MctpTransportHeaderSize != 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 != NULL && MctpTransportTrailerSize != 0) {
+      HelperManageabilityDebugPrint (
+        (VOID *)TransferToken.TransmitTrailer,
+        (UINT32)TransferToken.TransmitTrailerSize,
+        "MCTP transport trailer.\n"
+        );
+    }
+
+    TransportToken->Transport->Function.Version1_0->TransportTransmitReceive (
+                                                      TransportToken,
+                                                      &TransferToken
+                                                      );
+    if (MctpTransportHeader != NULL) {
+      FreePool ((VOID *)MctpTransportHeader);
+    }
+
+    if (MctpTransportTrailer != NULL) {
+      FreePool ((VOID *)MctpTransportTrailer);
+    }
+
+    if (ThisRequestData != NULL) {
+      FreePool ((VOID *)ThisRequestData);
+      ThisRequestData = NULL;
+    }
+    //
+    // Return transfer status.
+    //
+    Status                    = TransferToken.TransferStatus;
+    *AdditionalTransferError  = 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             = NULL;
+  TransferToken.TransmitPackage.TransmitSizeInByte          = 0;
+  TransferToken.ReceivePackage.ReceiveBuffer                = ResponseData;
+  TransferToken.ReceivePackage.ReceiveSizeInByte            = *ResponseDataSize;
+  TransferToken.TransmitHeader                              = NULL;
+  TransferToken.TransmitHeaderSize                          = 0;
+  TransferToken.TransmitTrailer                             = NULL;
+  TransferToken.TransmitTrailerSize                         = 0;
+  TransferToken.ReceivePackage.TransmitTimeoutInMillisecond = MANAGEABILITY_TRANSPORT_NO_TIMEOUT;
+
+  DEBUG((
+    DEBUG_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  = TransferToken.TransportAdditionalStatus;
+  *ResponseDataSize         = TransferToken.ReceivePackage.ReceiveSizeInByte;
+  Status                    = 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..ddada1f246
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocol.c
@@ -0,0 +1,216 @@
+/** @file
+  This file provides edk2 MCTP Protocol implementation.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <PiDxe.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/ManageabilityTransportLib.h>
+#include <Library/ManageabilityTransportHelperLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/MctpProtocol.h>
+
+#include <IndustryStandard/Mctp.h>
+
+#include "MctpProtocolCommon.h"
+
+extern MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION  mHardwareInformation;
+
+MANAGEABILITY_TRANSPORT_TOKEN  *mTransportToken = NULL;
+CHAR16                         *mTransportName;
+UINT32                         mTransportMaximumPayload;
+
+/**
+  This service enables submitting message via EDKII MCTP protocol.
+
+  @param[in]         This                       EDKII_MCTP_PROTOCOL instance.
+  @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 milliseconds.
+                                                MANAGEABILITY_TRANSPORT_NO_TIMEOUT means no timeout value.
+  @param[out]        ResponseData               Message Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize           Size of Message Response Data.
+  @param[in]         ResponseTimeout            Timeout value in milliseconds.
+                                                MANAGEABILITY_TRANSPORT_NO_TIMEOUT means no timeout value.
+  @param[out]        AdditionalTransferError    MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS.
+
+  @retval EFI_SUCCESS            The message was successfully send to transport interface and a
+                                 response was successfully received.
+  @retval EFI_NOT_FOUND          The message was not successfully sent to transport interface or a response
+                                 was not successfully received from transport interface.
+  @retval EFI_NOT_READY          MCTP transport interface is not ready for MCTP message.
+  @retval EFI_DEVICE_ERROR       MCTP transport interface Device hardware error.
+  @retval EFI_TIMEOUT            The message time out.
+  @retval EFI_UNSUPPORTED        The message was not successfully sent to the transport interface.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource 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                                     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
+)
+{
+  EFI_STATUS Status;
+
+  if (RequestData == NULL && ResponseData == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Both RequestData and ResponseData are NULL\n", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+  Status = CommonMctpSubmitMessage (
+             mTransportToken,
+             MctpType,
+             MctpSourceEndpointId,
+             MctpDestinationEndpointId,
+             RequestDataIntegrityCheck,
+             RequestData,
+             RequestDataSize,
+             RequestTimeout,
+             ResponseData,
+             ResponseDataSize,
+             ResponseTimeout,
+             AdditionalTransferError
+             );
+  return Status;
+}
+
+EDKII_MCTP_PROTOCOL_V1_0 mMctpProtocolV10 = {
+  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 = 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 = GetTransportCapability (mTransportToken, &TransportCapability);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
+    return Status;
+  }
+  mTransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(TransportCapability);
+  if (mTransportMaximumPayload == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
+    DEBUG((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
+  } else {
+    mTransportMaximumPayload -= 1;
+    DEBUG((DEBUG_INFO, "%a: Transport interface for MCTP protocol has maximum payload 0x%x.\n", __FUNCTION__, mTransportMaximumPayload));
+  }
+
+  mTransportName = HelperManageabilitySpecName (mTransportToken->Transport->ManageabilityTransportSpecification);
+  DEBUG ((DEBUG_ERROR, "%a: MCTP protocol over %s.\n", __FUNCTION__, mTransportName));
+
+  //
+  // Setup hardware information according to the transport interface.
+  Status = SetupMctpTransportHardwareInformation (
+             mTransportToken,
+             &mHardwareInformation
+             );
+  if (EFI_ERROR (Status)) {
+    if (Status == 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 = HelperInitManageabilityTransport (
+             mTransportToken,
+             mHardwareInformation,
+             &TransportAdditionalStatus
+             );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  mMctpProtocol.ProtocolVersion       = EDKII_MCTP_PROTOCOL_VERSION;
+  mMctpProtocol.Functions.Version1_0  = &mMctpProtocolV10;
+  Handle = NULL;
+  Status = 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 = EFI_SUCCESS;
+  if (mTransportToken != NULL) {
+    Status = ReleaseTransportSession (mTransportToken);
+  }
+
+  return Status;
+}
+
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 10/14] ManageabilityPkg: Add MCTP transport interface
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (8 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 09/14] ManageabilityPkg/MctpProtocol: Add MctpProtocol Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 11/14] ManageabilityPkg/PldmProtocol: Add PLDM protocol Chang, Abner
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: Abner Chang <abner.chang@amd.com>

Add MCTP manageability transport interface library.

The functionality is verified by checking the binary
debug output of payload.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../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/ManageabilityTransportMctpLib/Dxe/DxeManageabilityTransportMctp.inf
 create mode 100644 Features/ManageabilityPkg/Include/Library/ManageabilityTransportMctpLib.h
 create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h
 create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.c
 create mode 100644 Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.uni

diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc b/Features/ManageabilityPkg/ManageabilityPkg.dsc
index 412029ef6c..959b3eabd2 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dsc
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc
@@ -37,6 +37,7 @@
 
 [Components]
   ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/DxeManageabilityTransportKcs.inf
+  ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/DxeManageabilityTransportMctp.inf
   ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
 
 [LibraryClasses]
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/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/DxeManageabilityTransportMctp.inf
@@ -0,0 +1,44 @@
+## @file
+# MCTP instance of Manageability Transport Library
+#
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001B
+  BASE_NAME                      = DxeManageabilityTransportMctp
+  MODULE_UNI_FILE                = ManageabilityTransportMctp.uni
+  FILE_GUID                      = 7770FA0F-4808-47BD-89F4-717185332486
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ManageabilityTransportLib
+
+#
+#  VALID_ARCHITECTURES           = 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/ManageabilityTransportMctpLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportMctpLib.h
new file mode 100644
index 0000000000..43bd142f4c
--- /dev/null
+++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportMctpLib.h
@@ -0,0 +1,54 @@
+/** @file
+
+  This file defines the manageability MCTP protocol specific transport data.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MANAGEABILITY_TRANSPORT_MCTP_LIB_H_
+#define MANAGEABILITY_TRANSPORT_MCTP_LIB_H_
+
+#include <Library/ManageabilityTransportLib.h>
+
+#define MCTP_KCS_HEADER_VERSION  0x01
+
+// According to SMBUS spec, the polynomial is:
+// C(x) = 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/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h
new file mode 100644
index 0000000000..1ce0d3a8bc
--- /dev/null
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.h
@@ -0,0 +1,26 @@
+/** @file
+
+  Manageability transport MCTP internal used definitions.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MANAGEABILITY_TRANSPORT_MCTP_LIB_INTERNAL_H_
+#define MANAGEABILITY_TRANSPORT_MCTP_LIB_INTERNAL_H_
+
+#include <Library/ManageabilityTransportLib.h>
+
+#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_TRANSPORT_MCTP, Token, MANAGEABILITY_TRANSPORT_MCTP_SIGNATURE)
+
+#endif // MANAGEABILITY_TRANSPORT_MCTP_LIB_INTERNAL_H_
diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.c b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.c
new file mode 100644
index 0000000000..2d9b059157
--- /dev/null
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.c
@@ -0,0 +1,367 @@
+/** @file
+
+  MCTP instance of Manageability Transport Library
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+*/
+
+#include <Uefi.h>
+#include <Library/IoLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/ManageabilityTransportLib.h>
+#include <Library/ManageabilityTransportMctpLib.h>
+#include <Library/ManageabilityTransportHelperLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/MctpProtocol.h>
+
+#include "ManageabilityTransportMctp.h"
+
+MANAGEABILITY_TRANSPORT_MCTP  *mSingleSessionToken = NULL;
+EDKII_MCTP_PROTOCOL           *mMctpProtocol       = NULL;
+
+EFI_GUID  *SupportedManageabilityProtocol[] = {
+  &gManageabilityProtocolPldmGuid
+};
+
+UINT8  NumberOfSupportedProtocol = (sizeof (SupportedManageabilityProtocol)/sizeof (EFI_GUID *));
+
+/**
+  This function initializes the transport interface.
+
+  @param [in]  TransportToken           The transport token acquired through
+                                        AcquireTransportSession function.
+  @param [in]  HardwareInfo             The hardware information
+                                        assigned to MCTP transport interface.
+
+  @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 problems.
+  @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 through
+                                           AcquireTransportSession function.
+  @param [out]  TransportAdditionalStatus  The additional status of transport
+                                           interface.
+                                           NULL means no additional status of this
+                                           transport interface.
+
+  @retval      EFI_SUCCESS              Transport interface status is returned.
+  @retval      EFI_INVALID_PARAMETER    The invalid transport token.
+  @retval      EFI_DEVICE_ERROR         The transport interface has problems to return
+  @retval      EFI_UNSUPPORTED          The transport interface doesn't have status report.
+               Otherwise                Other errors.
+
+**/
+EFI_STATUS
+EFIAPI
+MctpTransportStatus (
+  IN  MANAGEABILITY_TRANSPORT_TOKEN              *TransportToken,
+  OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS  *TransportAdditionalStatus OPTIONAL
+  )
+{
+  if (TransportToken == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Invalid transport token.\n", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (TransportAdditionalStatus != NULL) {
+    *TransportAdditionalStatus = MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS_NO_ERRORS;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  This function resets the transport interface.
+  The generic EFI_STATUS is returned to caller directly after reseting transport
+  interface. 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_ADDITIONAL_STATUS.
+
+  @param [in]   TransportToken             The transport token acquired through
+                                           AcquireTransportSession function.
+  @param [out]  TransportAdditionalStatus  The additional status of specific transport
+                                           interface after the reset.
+                                           NULL means no additional status of this
+                                           transport interface.
+
+  @retval      EFI_SUCCESS              Transport interface status is returned.
+  @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 problems to return
+                                        status.
+               Otherwise                Other errors.
+
+**/
+EFI_STATUS
+EFIAPI
+MctpTransportReset (
+  IN  MANAGEABILITY_TRANSPORT_TOKEN              *TransportToken,
+  OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS  *TransportAdditionalStatus OPTIONAL
+  )
+{
+  if (TransportAdditionalStatus != NULL) {
+    *TransportAdditionalStatus = MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS_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 transport
+  interface. 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_ADDITIONAL_STATUS.
+
+  @param [in]  TransportToken           The transport token acquired through
+                                        AcquireTransportSession function.
+  @param [in]  TransferToken            The transfer token, see the definition 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 == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Invalid transport token.\n", __FUNCTION__));
+    TransferToken->TransportAdditionalStatus = MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS_NOT_AVAILABLE;
+    return;
+  }
+
+  TransmitHeader = (MANAGEABILITY_MCTP_TRANSPORT_HEADER *)TransferToken->TransmitHeader;
+  if (TransmitHeader == NULL) {
+    TransferToken->TransferStatus            = EFI_INVALID_PARAMETER;
+    TransferToken->TransportAdditionalStatus = MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS_NOT_AVAILABLE;
+    return;
+  }
+
+  if (mMctpProtocol == NULL) {
+    Status = 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, DestinationEndpointId: 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 = mMctpProtocol->Functions.Version1_0->MctpSubmitCommand (
+                                                  mMctpProtocol,
+                                                  TransmitHeader->MessageHeader.MessageType,
+                                                  TransmitHeader->SourceEndpointId,
+                                                  TransmitHeader->DestinationEndpointId,
+                                                  (BOOLEAN)TransmitHeader->MessageHeader.IntegrityCheck,
+                                                  TransferToken->TransmitPackage.TransmitPayload,
+                                                  TransferToken->TransmitPackage.TransmitSizeInByte,
+                                                  TransferToken->TransmitPackage.TransmitTimeoutInMillisecond,
+                                                  TransferToken->ReceivePackage.ReceiveBuffer,
+                                                  &TransferToken->ReceivePackage.ReceiveSizeInByte,
+                                                  TransferToken->ReceivePackage.TransmitTimeoutInMillisecond,
+                                                  &TransferToken->TransportAdditionalStatus
+                                                  );
+  TransferToken->TransferStatus = Status;
+}
+
+/**
+  This function acquires to create a transport session to transmit manageability
+  packet. A transport token is returned to caller for the follow up operations.
+
+  @param [in]   ManageabilityProtocolSpec  The protocol spec the transport interface is acquired.
+  @param [out]  TransportToken             The pointer to receive the transport 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 this 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 == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: No Manageability protocol specification specified.\n", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Status = 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 != NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: This manageability transport library only supports one session transport token.\n", __FUNCTION__));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  MctpTransportToken = (MANAGEABILITY_TRANSPORT_MCTP *)AllocateZeroPool (sizeof (MANAGEABILITY_TRANSPORT_MCTP));
+  if (MctpTransportToken == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TRANSPORT_MCTP\n", __FUNCTION__));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  MctpTransportToken->Token.Transport = AllocateZeroPool (sizeof (MANAGEABILITY_TRANSPORT));
+  if (MctpTransportToken->Token.Transport == NULL) {
+    FreePool (MctpTransportToken);
+    DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TRANSPORT\n", __FUNCTION__));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  MctpTransportToken->Signature                                            = MANAGEABILITY_TRANSPORT_MCTP_SIGNATURE;
+  MctpTransportToken->Token.ManageabilityProtocolSpecification             = ManageabilityProtocolSpec;
+  MctpTransportToken->Token.Transport->TransportVersion                    = MANAGEABILITY_TRANSPORT_TOKEN_VERSION;
+  MctpTransportToken->Token.Transport->ManageabilityTransportSpecification = &gManageabilityTransportMctpGuid;
+  MctpTransportToken->Token.Transport->TransportName                       = L"MCTP";
+  MctpTransportToken->Token.Transport->Function.Version1_0                 = AllocateZeroPool (sizeof (MANAGEABILITY_TRANSPORT_FUNCTION_V1_0));
+  if (MctpTransportToken->Token.Transport->Function.Version1_0 == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TRANSPORT_FUNCTION_V1_0\n", __FUNCTION__));
+    FreePool (MctpTransportToken);
+    FreePool (MctpTransportToken->Token.Transport);
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  MctpTransportToken->Token.Transport->Function.Version1_0->TransportInit            = MctpTransportInit;
+  MctpTransportToken->Token.Transport->Function.Version1_0->TransportReset           = MctpTransportReset;
+  MctpTransportToken->Token.Transport->Function.Version1_0->TransportStatus          = MctpTransportStatus;
+  MctpTransportToken->Token.Transport->Function.Version1_0->TransportTransmitReceive = MctpTransportTransmitReceive;
+
+  mSingleSessionToken = MctpTransportToken;
+  *TransportToken     = &MctpTransportToken->Token;
+  return EFI_SUCCESS;
+}
+
+/**
+  This function returns the transport capabilities according to
+  the manageability protocol.
+
+  @param [in]   TransportToken             Transport token acquired from manageability
+                                           transport library.
+  @param [out]  TransportFeature           Pointer to receive transport capabilities.
+                                           See the definitions of
+                                           MANAGEABILITY_TRANSPORT_CAPABILITY.
+  @retval       EFI_SUCCESS                TransportCapability is returned successfully.
+  @retval       EFI_INVALID_PARAMETER      TransportToken is not a valid token.
+**/
+EFI_STATUS
+GetTransportCapability (
+  IN MANAGEABILITY_TRANSPORT_TOKEN        *TransportToken,
+  OUT MANAGEABILITY_TRANSPORT_CAPABILITY  *TransportCapability
+  )
+{
+  if ((TransportToken == NULL) || (TransportCapability == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *TransportCapability = 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 == NULL) {
+    Status = EFI_INVALID_PARAMETER;
+  }
+
+  MctpTransportToken = MANAGEABILITY_TRANSPORT_MCTP_FROM_LINK (TransportToken);
+  if (mSingleSessionToken != MctpTransportToken) {
+    Status = EFI_INVALID_PARAMETER;
+  }
+
+  if (MctpTransportToken != NULL) {
+    FreePool (MctpTransportToken->Token.Transport->Function.Version1_0);
+    FreePool (MctpTransportToken->Token.Transport);
+    FreePool (MctpTransportToken);
+    mSingleSessionToken = NULL;
+    Status              = 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/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.uni b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.uni
new file mode 100644
index 0000000000..ca8125a4a7
--- /dev/null
+++ b/Features/ManageabilityPkg/Library/ManageabilityTransportMctpLib/Dxe/ManageabilityTransportMctp.uni
@@ -0,0 +1,13 @@
+// /** @file
+// MCTP instance of Manageability Transport Library
+//
+// Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+//
+// 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 Manageability Transport library implementation."
+
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 11/14] ManageabilityPkg/PldmProtocol: Add PLDM protocol
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (9 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 10/14] ManageabilityPkg: Add MCTP transport interface Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 12/14] ManageabilityPkg: Add Manageability PCDs Chang, Abner
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel; +Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

From: Abner Chang <abner.chang@amd.com>

PldmProtocol that transmits PLDM message
over manageability transport interface
library.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../Include/Dsc/Manageability.dsc             |   1 +
 .../PldmProtocol/Dxe/PldmProtocolDxe.inf      |  50 ++
 .../PldmProtocol/Common/PldmProtocolCommon.h  | 109 +++++
 .../PldmProtocol/Common/PldmProtocolCommon.c  | 432 ++++++++++++++++++
 .../Universal/PldmProtocol/Dxe/PldmProtocol.c | 181 ++++++++
 5 files changed, 773 insertions(+)
 create mode 100644 Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
 create mode 100644 Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h
 create mode 100644 Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.c
 create mode 100644 Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c

diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
index bdb3bc8378..e7659f437a 100644
--- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
+++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
@@ -25,6 +25,7 @@
 [Components.X64]
   ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocolDxe.inf
   ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf
+  ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
   ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf
   ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf
 
diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
new file mode 100644
index 0000000000..006f77b09a
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
@@ -0,0 +1,50 @@
+## @file
+# EDKII PLDM Pootocol module INF file.
+#
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001d
+  BASE_NAME                      = PldmProtocolDxe
+  FILE_GUID                      = DA83FBDC-ECFE-4094-9ED3-EAFD1342333F
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = DxePldmProtocolEntry
+  UNLOAD_IMAGE                   = PldmProtocolUnloadImage
+
+#
+#  VALID_ARCHITECTURES           = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+  PldmProtocol.c
+  ../Common/PldmProtocolCommon.c
+  ../Common/PldmProtocolCommon.h
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  ManageabilityPkg/ManageabilityPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  DebugLib
+  ManageabilityTransportHelperLib
+  ManageabilityTransportLib
+  UefiDriverEntryPoint
+  UefiBootServicesTableLib
+
+[Guids]
+  gManageabilityTransportMctpGuid
+
+[Protocols]
+  gEdkiiPldmProtocolGuid
+
+[FixedPcd]
+  gManageabilityPkgTokenSpaceGuid.PcdMctpSourceEndpointId
+  gManageabilityPkgTokenSpaceGuid.PcdMctpDestinationEndpointId
+
+[Depex]
+  TRUE
diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h
new file mode 100644
index 0000000000..231d6e802e
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.h
@@ -0,0 +1,109 @@
+/** @file
+
+  EDKII PLDM Protocol common header file.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MANAGEABILITY_EDKII_PLDM_COMMON_H_
+#define MANAGEABILITY_EDKII_PLDM_COMMON_H_
+
+#include <IndustryStandard/Pldm.h>
+#include <Library/ManageabilityTransportLib.h>
+
+typedef struct {
+  UINT8     PldmType;
+  UINT8     PldmCommand;
+  UINT32    ResponseSize;
+} PLDM_MESSAGE_PACKET_MAPPING;
+
+/**
+  This functions setup the PLDM transport hardware information according
+  to the specification of transport token acquired from transport library.
+
+  @param[in]         TransportToken       The transport interface.
+  @param[out]        HardwareInformation  Pointer to receive the hardware information.
+
+  @retval EFI_SUCCESS            Hardware information is returned in HardwareInformation.
+                                 Caller must free the memory allocated for HardwareInformation
+                                 once it doesn't need it.
+  @retval EFI_UNSUPPORTED        No hardware information for the specification specified
+                                 in the transport token.
+**/
+EFI_STATUS
+SetupPldmTransportHardwareInformation (
+  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]         PldmType           PLDM message type.
+  @param[in]         PldmCommand        PLDM command of this PLDM type.
+  @param[out]        PacketHeader       The pointer to receive header of request.
+  @param[out]        PacketHeaderSize   Packet header size in bytes.
+  @param[in, out]    PacketBody         The request body.
+                                        When IN, it is the caller's request body.
+                                        When OUT and NULL, the request body is not
+                                        changed.
+                                        Whee out and non-NULL, the request body is
+                                        changed to comfort the transport 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 request body is unchanged.
+  @param[out]        PacketTrailer      The pointer to receive trailer of request.
+  @param[out]        PacketTrailerSize  Packet trailer size in bytes.
+
+  @retval EFI_SUCCESS            Request packet is returned.
+  @retval EFI_UNSUPPORTED        Request packet is not returned because
+                                 the unsupported transport interface.
+**/
+EFI_STATUS
+SetupPldmRequestTransportPacket (
+  IN   MANAGEABILITY_TRANSPORT_TOKEN    *TransportToken,
+  IN   UINT8                            PldmType,
+  IN   UINT8                            PldmCommand,
+  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 PLDM commands
+
+  @param[in]         TransportToken    Transport token.
+  @param[in]         PldmType          PLDM message type.
+  @param[in]         PldmCommand       PLDM command of this PLDM type.
+  @param[in]         RequestData       Command Request Data.
+  @param[in]         RequestDataSize   Size of Command Request Data.
+  @param[out]        ResponseData      Command Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize  Size of Command Response Data.
+
+  @retval EFI_SUCCESS            The command byte stream was successfully submit to the device and a response was successfully received.
+  @retval EFI_NOT_FOUND          The command was not successfully sent to the device or a response was not successfully received from the device.
+  @retval EFI_NOT_READY          PLDM transport interface is not ready for PLDM command access.
+  @retval EFI_DEVICE_ERROR       PLDM Device hardware error.
+  @retval EFI_TIMEOUT            The command time out.
+  @retval EFI_UNSUPPORTED        The command was not successfully sent to the device.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource or data size error.
+**/
+EFI_STATUS
+CommonPldmSubmitCommand (
+  IN     MANAGEABILITY_TRANSPORT_TOKEN  *TransportToken,
+  IN     UINT8                          PldmType,
+  IN     UINT8                          PldmCommand,
+  IN     UINT8                          *RequestData OPTIONAL,
+  IN     UINT32                         RequestDataSize,
+  OUT    UINT8                          *ResponseData OPTIONAL,
+  IN OUT UINT32                         *ResponseDataSize
+  );
+
+#endif // MANAGEABILITY_EDKII_PLDM_COMMON_H_
diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.c b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.c
new file mode 100644
index 0000000000..fd3a4f57e7
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Common/PldmProtocolCommon.c
@@ -0,0 +1,432 @@
+/** @file
+
+  IPMI Manageability Protocol common file.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include <Uefi.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/ManageabilityTransportLib.h>
+#include <Library/ManageabilityTransportHelperLib.h>
+#include <Library/ManageabilityTransportMctpLib.h>
+#include <IndustryStandard/Mctp.h>
+#include <IndustryStandard/Pldm.h>
+#include <IndustryStandard/PldmSmbiosTransfer.h>
+#include "PldmProtocolCommon.h"
+
+extern CHAR16  *mTransportName;
+extern UINT8   mPldmRequestInstanceId;
+
+PLDM_MESSAGE_PACKET_MAPPING  PldmMessagePacketMappingTable[] = {
+  { PLDM_TYPE_SMBIOS, PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_CODE, sizeof (PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA_RESPONSE_FORMAT) },
+  { PLDM_TYPE_SMBIOS, PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_CODE, sizeof (PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA_RESPONSE_FORMAT) },
+  { PLDM_TYPE_SMBIOS, PLDM_SET_SMBIOS_STRUCTURE_TABLE_COMMAND_CODE,          sizeof (PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST_FORMAT)           }
+};
+
+/**
+  This function returns the expected full size of PLDM response message.
+
+  @param[in]         PldmType        PLDM message type.
+  @param[in]         PldmCommand     PLDM command of this PLDM type.
+
+  @retval  Zero       No matched entry for this PldmType/PldmCommand.
+  @retval  None-zero  Size of full packet is returned.
+**/
+UINT32
+GetFullPacketResponseSize (
+  IN UINT8  PldmType,
+  IN UINT8  PldmCommand
+  )
+{
+  INT16                        Index;
+  PLDM_MESSAGE_PACKET_MAPPING  *ThisEntry;
+
+  ThisEntry = PldmMessagePacketMappingTable;
+  for (Index = 0; Index < (sizeof (PldmMessagePacketMappingTable)/ sizeof (PLDM_MESSAGE_PACKET_MAPPING)); Index++) {
+    if ((PldmType == ThisEntry->PldmType) && (PldmCommand == ThisEntry->PldmCommand)) {
+      return ThisEntry->ResponseSize;
+    }
+    ThisEntry++;
+  }
+
+  return 0;
+}
+
+/**
+  This functions setup the final header/body/trailer packets for
+  the acquired transport interface.
+
+  @param[in]         TransportToken     The transport interface.
+  @param[in]         PldmType           PLDM message type.
+  @param[in]         PldmCommand        PLDM command of this PLDM type.
+  @param[out]        PacketHeader       The pointer to receive header of request.
+  @param[out]        PacketHeaderSize   Packet header size in bytes.
+  @param[in, out]    PacketBody         The request body.
+                                        When IN, it is the caller's request body.
+                                        When OUT and NULL, the request body is not
+                                        changed.
+                                        Whee out and non-NULL, the request body is
+                                        changed to comfort the transport 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 request body is unchanged.
+  @param[out]        PacketTrailer      The pointer to receive trailer of request.
+  @param[out]        PacketTrailerSize  Packet trailer size in bytes.
+
+  @retval EFI_SUCCESS            Request packet is returned.
+  @retval EFI_UNSUPPORTED        Request packet is not returned because
+                                 the unsupported transport interface.
+**/
+EFI_STATUS
+SetupPldmRequestTransportPacket (
+  IN   MANAGEABILITY_TRANSPORT_TOKEN    *TransportToken,
+  IN   UINT8                            PldmType,
+  IN   UINT8                            PldmCommand,
+  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_TRANSPORT_HEADER  *MctpHeader;
+  PLDM_REQUEST_HEADER                  *PldmRequestHeader;
+
+  if ((PacketHeader == NULL) || (PacketHeaderSize == NULL) ||
+      (PacketBody   == NULL) || (PacketBodySize == NULL) ||
+      (PacketTrailer == NULL) || (PacketTrailerSize == NULL)
+      )
+  {
+    DEBUG ((DEBUG_ERROR, "%a: One or more than one of the required parameters is NULL.\n", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (CompareGuid (&gManageabilityTransportMctpGuid, TransportToken->Transport->ManageabilityTransportSpecification)) {
+    DEBUG ((DEBUG_INFO, "%a: Setup transport header for PLDM over MCTP.\n", __FUNCTION__));
+
+    // This is MCTP transport interface.
+    MctpHeader = AllocateZeroPool (sizeof (MANAGEABILITY_MCTP_TRANSPORT_HEADER));
+    if (MctpHeader == NULL) {
+      DEBUG ((DEBUG_ERROR, "%a: Not enough memory for MANAGEABILITY_MCTP_TRANSPORT_HEADER.\n", __FUNCTION__));
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    MctpHeader->SourceEndpointId             = PcdGet8 (PcdMctpSourceEndpointId);
+    MctpHeader->SourceEndpointId             = PcdGet8 (PcdMctpDestinationEndpointId);
+    MctpHeader->MessageHeader.IntegrityCheck = FALSE;
+    MctpHeader->MessageHeader.MessageType    = MCTP_MESSAGE_TYPE_PLDM;
+    *PacketHeader                            = (MANAGEABILITY_TRANSPORT_HEADER *)MctpHeader;
+    *PacketHeaderSize                        = sizeof (MANAGEABILITY_TRANSPORT_HEADER);
+    *PacketTrailer                           = NULL;
+    *PacketTrailerSize                       = 0;
+  } else {
+    DEBUG ((DEBUG_ERROR, "%a: No implementation of building up packet.\n", __FUNCTION__));
+    ASSERT (FALSE);
+  }
+
+  //
+  // Create header for the final request message.
+  //
+  PldmRequestHeader = (PLDM_REQUEST_HEADER *)AllocateZeroPool (sizeof (PLDM_REQUEST_HEADER) + *PacketBodySize);
+  if (PldmRequestHeader == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Not enough memory for final PLDM request message.\n", __FUNCTION__));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  PldmRequestHeader->RequestBit          = PLDM_MESSAGE_HEADER_IS_REQUEST;
+  PldmRequestHeader->HeaderVersion       = PLDM_MESSAGE_HEADER_VERSION;
+  PldmRequestHeader->PldmType            = PldmType;
+  PldmRequestHeader->PldmTypeCommandCode = PldmCommand;
+  PldmRequestHeader->InstanceId          = mPldmRequestInstanceId;
+  if ((*PacketBody != NULL) && (*PacketBodySize != 0)) {
+    CopyMem (
+      (VOID *)((UINT8 *)PldmRequestHeader + sizeof (PLDM_REQUEST_HEADER)),
+      (VOID *)*PacketBody,
+      *PacketBodySize
+      );
+  }
+
+  *PacketBody     = (UINT8 *)PldmRequestHeader;
+  *PacketBodySize = sizeof (PLDM_REQUEST_HEADER) + *PacketBodySize;
+  return EFI_SUCCESS;
+}
+
+/**
+  Common code to submit PLDM commands
+
+  @param[in]         TransportToken    Transport token.
+  @param[in]         PldmType          PLDM message type.
+  @param[in]         PldmCommand       PLDM command of this PLDM type.
+  @param[in]         RequestData       Command Request Data.
+  @param[in]         RequestDataSize   Size of Command Request Data.
+  @param[out]        ResponseData      Command Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize  Size of Command Response Data.
+
+  @retval EFI_SUCCESS            The command byte stream was successfully submit to the device and a response was successfully received.
+  @retval EFI_NOT_FOUND          The command was not successfully sent to the device or a response was not successfully received from the device.
+  @retval EFI_NOT_READY          Ipmi Device is not ready for Ipmi command access.
+  @retval EFI_DEVICE_ERROR       Ipmi Device hardware error.
+  @retval EFI_TIMEOUT            The command time out.
+  @retval EFI_UNSUPPORTED        The command was not successfully sent to the device.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource or data size error.
+**/
+EFI_STATUS
+CommonPldmSubmitCommand (
+  IN     MANAGEABILITY_TRANSPORT_TOKEN  *TransportToken,
+  IN     UINT8                          PldmType,
+  IN     UINT8                          PldmCommand,
+  IN     UINT8                          *RequestData OPTIONAL,
+  IN     UINT32                         RequestDataSize,
+  OUT    UINT8                          *ResponseData OPTIONAL,
+  IN OUT UINT32                         *ResponseDataSize
+  )
+{
+  EFI_STATUS                                 Status;
+  UINT8                                      *ThisRequestData;
+  UINT32                                     ThisRequestDataSize;
+  MANAGEABILITY_TRANSFER_TOKEN               TransferToken;
+  MANAGEABILITY_TRANSPORT_HEADER             PldmTransportHeader;
+  MANAGEABILITY_TRANSPORT_TRAILER            PldmTransportTrailer;
+  MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS  TransportAdditionalStatus;
+  UINT8                                      *FullPacketResponseData;
+  UINT32                                     FullPacketResponseDataSize;
+  PLDM_RESPONSE_HEADER                       *ResponseHeader;
+  UINT16                                     HeaderSize;
+  UINT16                                     TrailerSize;
+
+  if (TransportToken == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: No transport token for PLDM\n", __FUNCTION__));
+    return EFI_UNSUPPORTED;
+  }
+
+  Status = TransportToken->Transport->Function.Version1_0->TransportStatus (
+                                                             TransportToken,
+                                                             &TransportAdditionalStatus
+                                                             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Transport %s for PLDM has problem - (%r)\n", __FUNCTION__, mTransportName, Status));
+    return Status;
+  }
+
+  ThisRequestData = RequestData;            // Save the original request data because the request data maybe modified
+                                            // in SetupIpmiRequestTransportPacket() according to transport interface.
+  ThisRequestDataSize = RequestDataSize;    // Save the original request data size because the request data size maybe modified
+                                            //  in SetupIpmiRequestTransportPacket() according to transport interface.
+  PldmTransportHeader  = NULL;
+  PldmTransportTrailer = NULL;
+  Status               = SetupPldmRequestTransportPacket (
+                           TransportToken,
+                           PldmType,
+                           PldmCommand,
+                           &PldmTransportHeader,
+                           &HeaderSize,
+                           &ThisRequestData,
+                           &ThisRequestDataSize,
+                           &PldmTransportTrailer,
+                           &TrailerSize
+                           );
+  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      = PldmTransportHeader;
+  TransferToken.TransmitHeaderSize  = HeaderSize;
+  TransferToken.TransmitTrailer     = PldmTransportTrailer;
+  TransferToken.TransmitTrailerSize = TrailerSize;
+
+  // Transmit packet.
+  if ((ThisRequestData == NULL) || (ThisRequestDataSize == 0)) {
+    // Transmit parameter were not changed by SetupIpmiRequestTransportPacket().
+    TransferToken.TransmitPackage.TransmitPayload    = RequestData;
+    TransferToken.TransmitPackage.TransmitSizeInByte = ThisRequestDataSize;
+  } else {
+    // Transmit parameter were changed by SetupIpmiRequestTransportPacket().
+    TransferToken.TransmitPackage.TransmitPayload    = ThisRequestData;
+    TransferToken.TransmitPackage.TransmitSizeInByte = ThisRequestDataSize;
+  }
+
+  TransferToken.TransmitPackage.TransmitTimeoutInMillisecond = MANAGEABILITY_TRANSPORT_NO_TIMEOUT;
+
+  // Set receive packet.
+  FullPacketResponseDataSize = GetFullPacketResponseSize (PldmType, PldmCommand);
+  if (FullPacketResponseDataSize == 0) {
+    DEBUG ((DEBUG_ERROR, "  No mapping entry in PldmMessagePacketMappingTable for PLDM Type:%d Command %d\n", PldmType, PldmCommand));
+    ASSERT (FALSE);
+  }
+
+  FullPacketResponseData = (UINT8 *)AllocateZeroPool (FullPacketResponseDataSize);
+  if (FullPacketResponseData == NULL) {
+    DEBUG ((DEBUG_ERROR, "  Not enough memory for FullPacketResponseDataSize.\n"));
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ErrorExit2;
+  }
+
+  // Print out PLDM packet.
+  DEBUG ((
+    DEBUG_INFO,
+    "%a: Send PLDM type: 0x%x, Command: 0x%x: Request size: 0x%x, Response size: 0x%x\n",
+    __FUNCTION__,
+    PldmType,
+    PldmCommand,
+    TransferToken.TransmitPackage.TransmitSizeInByte,
+    FullPacketResponseDataSize
+    ));
+
+  HelperManageabilityDebugPrint (
+    (VOID *)TransferToken.TransmitPackage.TransmitPayload,
+    TransferToken.TransmitPackage.TransmitSizeInByte,
+    "PLDM full request payload.\n"
+    );
+
+  TransferToken.ReceivePackage.ReceiveBuffer                = FullPacketResponseData;
+  TransferToken.ReceivePackage.ReceiveSizeInByte            = FullPacketResponseDataSize;
+  TransferToken.ReceivePackage.TransmitTimeoutInMillisecond = MANAGEABILITY_TRANSPORT_NO_TIMEOUT;
+  TransportToken->Transport->Function.Version1_0->TransportTransmitReceive (
+                                                    TransportToken,
+                                                    &TransferToken
+                                                    );
+  //
+  // Check the response size.
+  if (TransferToken.ReceivePackage.ReceiveSizeInByte < sizeof (PLDM_RESPONSE_HEADER)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "Invalid response header size of PLDM Type %d Command %d, Returned size: %d Expected size: %d\n",
+      PldmType,
+      PldmCommand,
+      TransferToken.ReceivePackage.ReceiveSizeInByte,
+      FullPacketResponseDataSize
+      ));
+    if (ResponseDataSize != NULL) {
+      if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInByte) {
+        *ResponseDataSize = TransferToken.ReceivePackage.ReceiveSizeInByte;
+      }
+    }
+    if (ResponseData != NULL) {
+      CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *ResponseDataSize);
+    }
+
+    goto ErrorExit;
+  }
+
+  //
+  // Check the integrity of response. data.
+  ResponseHeader = (PLDM_RESPONSE_HEADER *)FullPacketResponseData;
+  if ((ResponseHeader->PldmHeader.DatagramBit != 0) ||
+      (ResponseHeader->PldmHeader.RequestBit != 0) ||
+      (ResponseHeader->PldmHeader.InstanceId != mPldmRequestInstanceId) ||
+      (ResponseHeader->PldmHeader.PldmType != PldmType) ||
+      (ResponseHeader->PldmHeader.PldmTypeCommandCode != PldmCommand))
+  {
+    DEBUG ((DEBUG_ERROR, "PLDM integrity check of response data is failed.\n"));
+    DEBUG ((DEBUG_ERROR, "    Request bit  = %d (Expected value: 0)\n"));
+    DEBUG ((DEBUG_ERROR, "    Datagram     = %d (Expected value: 0)\n"));
+    DEBUG ((DEBUG_ERROR, "    Instance ID  = %d (Expected value: %d)\n", ResponseHeader->PldmHeader.InstanceId, mPldmRequestInstanceId));
+    DEBUG ((DEBUG_ERROR, "    Pldm Type    = %d (Expected value: %d)\n", ResponseHeader->PldmHeader.PldmType, PldmType));
+    DEBUG ((DEBUG_ERROR, "    Pldm Command = %d (Expected value: %d)\n", ResponseHeader->PldmHeader.PldmTypeCommandCode, PldmCommand));
+    if (ResponseDataSize != NULL) {
+      if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInByte) {
+        *ResponseDataSize = TransferToken.ReceivePackage.ReceiveSizeInByte;
+      }
+    }
+    if (ResponseData != NULL) {
+      CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *ResponseDataSize);
+    }
+
+    goto ErrorExit;
+  }
+
+  //
+  // Check the response size
+  if (TransferToken.ReceivePackage.ReceiveSizeInByte != FullPacketResponseDataSize) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "The response size is incorrect: Response size %d (Expected %d), Completion code %d.\n",
+      TransferToken.ReceivePackage.ReceiveSizeInByte,
+      FullPacketResponseDataSize,
+      ResponseHeader->PldmCompletionCode
+      ));
+    if (ResponseDataSize != NULL) {
+      if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInByte) {
+        *ResponseDataSize = TransferToken.ReceivePackage.ReceiveSizeInByte;
+      }
+    }
+    if (ResponseData != NULL) {
+      CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *ResponseDataSize);
+    }
+
+    goto ErrorExit;
+  }
+
+  if (*ResponseDataSize != (TransferToken.ReceivePackage.ReceiveSizeInByte - sizeof (PLDM_RESPONSE_HEADER))) {
+    DEBUG ((DEBUG_ERROR, "  The size of response is not matched to RequestDataSize assigned by caller.\n"));
+    DEBUG ((
+      DEBUG_ERROR,
+      "Caller expects %d, the response size minus PLDM_RESPONSE_HEADER size is %d, Completion Code %d.\n",
+      *ResponseDataSize,
+      TransferToken.ReceivePackage.ReceiveSizeInByte - sizeof (PLDM_RESPONSE_HEADER),
+      ResponseHeader->PldmCompletionCode
+      ));
+    if (ResponseDataSize != NULL) {
+      if (*ResponseDataSize > TransferToken.ReceivePackage.ReceiveSizeInByte) {
+        *ResponseDataSize = TransferToken.ReceivePackage.ReceiveSizeInByte;
+      }
+    }
+    if (ResponseData != NULL) {
+      CopyMem ((VOID *)ResponseData, (VOID *)FullPacketResponseData, *ResponseDataSize);
+    }
+
+    goto ErrorExit;
+  }
+
+  // Print out PLDM full responses payload.
+  HelperManageabilityDebugPrint ((VOID *)FullPacketResponseData, FullPacketResponseDataSize, "PLDM full response payload\n");
+
+  // Copy response data (without header) to caller's buffer.
+  if ((ResponseData != NULL) && (*ResponseDataSize != 0)) {
+    *ResponseDataSize = FullPacketResponseDataSize - sizeof (PLDM_RESPONSE_HEADER);
+    CopyMem (
+      (VOID *)ResponseData,
+      (VOID *)(FullPacketResponseData + sizeof (PLDM_RESPONSE_HEADER)),
+      *ResponseDataSize
+      );
+  }
+
+  // Return transfer status.
+  //
+ErrorExit:
+  Status = TransferToken.TransferStatus;
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to send PLDM command over %s\n", __FUNCTION__, mTransportName));
+  }
+
+ErrorExit2:
+  if (PldmTransportHeader != NULL) {
+    FreePool ((VOID *)PldmTransportHeader);
+  }
+
+  if (PldmTransportTrailer != NULL) {
+    FreePool ((VOID *)PldmTransportTrailer);
+  }
+
+  if (ThisRequestData != NULL) {
+    FreePool ((VOID *)ThisRequestData);
+  }
+
+  if (FullPacketResponseData != NULL) {
+    FreePool ((VOID *)FullPacketResponseData);
+  }
+
+  //
+  // Update PLDM message instance ID.
+  mPldmRequestInstanceId++;
+  mPldmRequestInstanceId &= PLDM_MESSAGE_HEADER_INSTANCE_ID_MASK;
+  return Status;
+}
diff --git a/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c
new file mode 100644
index 0000000000..9904263cb0
--- /dev/null
+++ b/Features/ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocol.c
@@ -0,0 +1,181 @@
+/** @file
+  This file provides edk2 PLDM SMBIOS Transfer Protocol implementation.
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <PiDxe.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/ManageabilityTransportLib.h>
+#include <Library/ManageabilityTransportHelperLib.h>
+#include <IndustryStandard/Pldm.h>
+#include <Protocol/PldmProtocol.h>
+
+#include "PldmProtocolCommon.h"
+
+MANAGEABILITY_TRANSPORT_TOKEN  *mTransportToken = NULL;
+CHAR16                         *mTransportName;
+UINT8                          mPldmRequestInstanceId;
+UINT32                         TransportMaximumPayload;
+
+/**
+  This service enables submitting commands via EDKII PLDM protocol.
+
+  @param[in]         This              EDKII_PLDM_PROTOCOL instance.
+  @param[in]         PldmType          PLDM message type.
+  @param[in]         Command           PLDM Command of PLDM message type.
+  @param[in]         RequestData       Command Request Data.
+  @param[in]         RequestDataSize   Size of Command Request Data.
+  @param[out]        ResponseData      Command Response Data. The completion code is the first byte of response data.
+  @param[in, out]    ResponseDataSize  Size of Command Response Data.
+
+  @retval EFI_SUCCESS            The command byte stream was successfully submit to the device and a response was successfully received.
+  @retval EFI_NOT_FOUND          The command was not successfully sent to the device or a response was not successfully received from the device.
+  @retval EFI_NOT_READY          PLDM transport interface is not ready for PLDM command access.
+  @retval EFI_DEVICE_ERROR       PLDM transport interface Device hardware error.
+  @retval EFI_TIMEOUT            The command time out.
+  @retval EFI_UNSUPPORTED        The command was not successfully sent to the device.
+  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource or data size error.
+  @retval EFI_INVALID_PARAMETER  Both RequestData and ResponseData are NULL
+**/
+EFI_STATUS
+EFIAPI
+PldmSubmitCommand (
+  IN     EDKII_PLDM_PROTOCOL  *This,
+  IN     UINT8                PldmType,
+  IN     UINT8                Command,
+  IN     UINT8                *RequestData,
+  IN     UINT32               RequestDataSize,
+  OUT    UINT8                *ResponseData,
+  IN OUT UINT32               *ResponseDataSize
+  )
+{
+  EFI_STATUS  Status;
+
+  if ((RequestData == NULL) && (ResponseData == NULL)) {
+    DEBUG ((DEBUG_ERROR, "%a: Both RequestData and ResponseData are NULL\n", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Status = CommonPldmSubmitCommand (
+             mTransportToken,
+             PldmType,
+             Command,
+             RequestData,
+             RequestDataSize,
+             ResponseData,
+             ResponseDataSize
+             );
+  return Status;
+}
+
+EDKII_PLDM_PROTOCOL_V1_0  mPldmProtocolV10 = {
+  PldmSubmitCommand
+};
+
+EDKII_PLDM_PROTOCOL  mPldmProtocol;
+
+/**
+  The entry point of the PLDM SMBIOS Transfer DXE driver.
+
+  @param[in] ImageHandle - Handle of this driver image
+  @param[in] SystemTable - Table containing standard EFI services
+
+  @retval EFI_SUCCESS    - PLDM Protocol is installed successfully.
+  @retval Otherwise      - Other errors.
+**/
+EFI_STATUS
+EFIAPI
+DxePldmProtocolEntry (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS                                    Status;
+  EFI_HANDLE                                    Handle;
+  MANAGEABILITY_TRANSPORT_CAPABILITY            TransportCapability;
+  MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS     TransportAdditionalStatus;
+  MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION  HardwareInfo;
+
+  Status = HelperAcquireManageabilityTransport (
+             &gManageabilityProtocolPldmGuid,
+             &mTransportToken
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for PLDM protocol - %r\n", __FUNCTION__, Status));
+    return Status;
+  }
+
+  Status = GetTransportCapability (mTransportToken, &TransportCapability);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
+    return Status;
+  }
+
+  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY (TransportCapability);
+  if (TransportMaximumPayload == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
+    DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
+  } else {
+    TransportMaximumPayload -= 1;
+    DEBUG ((DEBUG_INFO, "%a: Transport interface for PLDM protocol has maximum payload 0x%x.\n", __FUNCTION__, TransportMaximumPayload));
+  }
+
+  mTransportName = HelperManageabilitySpecName (mTransportToken->Transport->ManageabilityTransportSpecification);
+  DEBUG ((DEBUG_ERROR, "%a: PLDM protocol over %s.\n", __FUNCTION__, mTransportName));
+
+  // Initial transport interface with the hardware information assigned.
+  HardwareInfo.Pointer = NULL;
+  Status               = HelperInitManageabilityTransport (
+                           mTransportToken,
+                           HardwareInfo,
+                           &TransportAdditionalStatus
+                           );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  mPldmRequestInstanceId             = 0;
+  mPldmProtocol.ProtocolVersion      = EDKII_PLDM_PROTOCOL_VERSION;
+  mPldmProtocol.Functions.Version1_0 = &mPldmProtocolV10;
+  Handle                             = NULL;
+  Status                             = gBS->InstallProtocolInterface (
+                                              &Handle,
+                                              &gEdkiiPldmProtocolGuid,
+                                              EFI_NATIVE_INTERFACE,
+                                              (VOID **)&mPldmProtocol
+                                              );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to install EDKII PLDM protocol - %r\n", __FUNCTION__, Status));
+  }
+
+  return Status;
+}
+
+/**
+  This is the unload handler of PLDM SMBIOS Transfer DXE driver.
+
+  @param[in] ImageHandle           The driver's image handle.
+
+  @retval    EFI_SUCCESS           The image is unloaded.
+  @retval    Others                Failed to unload the image.
+
+**/
+EFI_STATUS
+EFIAPI
+PldmProtocolUnloadImage (
+  IN EFI_HANDLE  ImageHandle
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = EFI_SUCCESS;
+  if (mTransportToken != NULL) {
+    Status = ReleaseTransportSession (mTransportToken);
+  }
+
+  return Status;
+}
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 12/14] ManageabilityPkg: Add Manageability PCDs
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (10 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 11/14] ManageabilityPkg/PldmProtocol: Add PLDM protocol Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 13/14] ManageabilityPkg: Relocate Manageability.dsc Chang, Abner
  2023-04-03 15:04 ` [edk2-platforms][PATCH 14/14] ManageabilityPkg: Add Manageability FDFs Chang, Abner
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel
  Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy,
	Tinh Nguyen

From: abnchang <abnchang@amd.com>

Add PCDs to control ManageabilityPkg
modules.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Tinh Nguyen <tinhnguyen@amperemail.onmicrosoft.com>
---
 Features/ManageabilityPkg/ManageabilityPkg.dec  |  8 ++++++++
 .../Include/Dsc/Manageability.dsc               | 17 ++++++++++++++++-
 Features/ManageabilityPkg/ManageabilityPkg.dsc  | 10 ++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dec b/Features/ManageabilityPkg/ManageabilityPkg.dec
index 025d89a37a..d43fbb4729 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dec
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dec
@@ -68,3 +68,11 @@
   # @Prompt MCTP KCS (Memory mapped) I/O base address
   gManageabilityPkgTokenSpaceGuid.PcdMctpKcsBaseAddress|0xca2|UINT32|0x00000004
 
+[PcdsFeatureFlag]
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiEnable|FALSE|BOOLEAN|0x10000001
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilitySmmIpmiEnable|FALSE|BOOLEAN|0x10000002
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityPeiIpmiEnable|FALSE|BOOLEAN|0x10000003
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxePldmEnable|FALSE|BOOLEAN|0x10000004
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeMctpEnable|FALSE|BOOLEAN|0x10000005
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxePldmSmbiosTransferEnable|FALSE|BOOLEAN|0x10000006
+
diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
index e7659f437a..a371e33ca7 100644
--- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
+++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
@@ -20,12 +20,27 @@
   ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf
 
 [Components.IA32]
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityPeiIpmiEnable == TRUE
   ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiPei.inf
+!endif
 
 [Components.X64]
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiEnable == TRUE
   ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocolDxe.inf
+!endif
+
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilitySmmIpmiEnable == TRUE
   ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf
+!endif
+
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxePldmEnable == TRUE
   ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
+!endif
+
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxePldmSmbiosTransferEnable == TRUE
   ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf
-  ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf
+!endif
 
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeMctpEnable == TRUE
+  ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf
+!endif
diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc b/Features/ManageabilityPkg/ManageabilityPkg.dsc
index 959b3eabd2..41a8957954 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dsc
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc
@@ -28,6 +28,16 @@
   gMinPlatformPkgTokenSpaceGuid.PcdUefiSecureBootEnable                   |FALSE
   gMinPlatformPkgTokenSpaceGuid.PcdPerformanceEnable                      |FALSE
 
+  #
+  # Manageability modules
+  #
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiEnable              |TRUE
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilitySmmIpmiEnable              |TRUE
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityPeiIpmiEnable              |TRUE
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxePldmEnable              |TRUE
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeMctpEnable              |TRUE
+  gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxePldmSmbiosTransferEnable|TRUE
+
 #
 # Include common libraries
 #
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 13/14] ManageabilityPkg: Relocate Manageability.dsc
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (11 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 12/14] ManageabilityPkg: Add Manageability PCDs Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  2023-04-10 17:27   ` Tinh Nguyen
  2023-04-03 15:04 ` [edk2-platforms][PATCH 14/14] ManageabilityPkg: Add Manageability FDFs Chang, Abner
  13 siblings, 1 reply; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel
  Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy,
	Tinh Nguyen

From: abnchang <abnchang@amd.com>

Relocate Manageability.dsc to just under \Include
folder.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Tinh Nguyen <tinhnguyen@amperemail.onmicrosoft.com>
---
 Features/ManageabilityPkg/Include/{Dsc => }/Manageability.dsc | 0
 Features/ManageabilityPkg/ManageabilityPkg.dsc                | 2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename Features/ManageabilityPkg/Include/{Dsc => }/Manageability.dsc (100%)

diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Features/ManageabilityPkg/Include/Manageability.dsc
similarity index 100%
rename from Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
rename to Features/ManageabilityPkg/Include/Manageability.dsc
diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc b/Features/ManageabilityPkg/ManageabilityPkg.dsc
index 41a8957954..a0712d1c0a 100644
--- a/Features/ManageabilityPkg/ManageabilityPkg.dsc
+++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc
@@ -53,4 +53,4 @@
 [LibraryClasses]
   ManageabilityTransportLib|ManageabilityPkg/Library/BaseManageabilityTransportNullLib/BaseManageabilityTransportNull.inf
 
-!include Include/Dsc/Manageability.dsc
+!include Include/Manageability.dsc
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [edk2-platforms][PATCH 14/14] ManageabilityPkg: Add Manageability FDFs
  2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
                   ` (12 preceding siblings ...)
  2023-04-03 15:04 ` [edk2-platforms][PATCH 13/14] ManageabilityPkg: Relocate Manageability.dsc Chang, Abner
@ 2023-04-03 15:04 ` Chang, Abner
  13 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-03 15:04 UTC (permalink / raw)
  To: devel
  Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy,
	Tinh Nguyen

From: abnchang <abnchang@amd.com>

Add FDF include files for build in ManageabilityPkg
modules to firmware device.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Tinh Nguyen <tinhnguyen@amperemail.onmicrosoft.com>
---
 .../ManageabilityPkg/Include/PostMemory.fdf   | 28 +++++++++++++++++++
 .../ManageabilityPkg/Include/PreMemory.fdf    | 12 ++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 Features/ManageabilityPkg/Include/PostMemory.fdf
 create mode 100644 Features/ManageabilityPkg/Include/PreMemory.fdf

diff --git a/Features/ManageabilityPkg/Include/PostMemory.fdf b/Features/ManageabilityPkg/Include/PostMemory.fdf
new file mode 100644
index 0000000000..9100cb2646
--- /dev/null
+++ b/Features/ManageabilityPkg/Include/PostMemory.fdf
@@ -0,0 +1,28 @@
+## @file
+# Manageabilty Package post memory initialization firmware
+# volume description.
+#
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeIpmiEnable == TRUE
+  INF ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocolDxe.inf
+!endif
+
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilitySmmIpmiEnable == TRUE
+  INF ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf
+!endif
+
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxePldmEnable == TRUE
+  INF ManageabilityPkg/Universal/PldmProtocol/Dxe/PldmProtocolDxe.inf
+!endif
+
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxePldmSmbiosTransferEnable == TRUE
+  INF ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.inf
+!endif
+
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityDxeMctpEnable == TRUE
+  INF ManageabilityPkg/Universal/MctpProtocol/Dxe/MctpProtocolDxe.inf
+!endif
diff --git a/Features/ManageabilityPkg/Include/PreMemory.fdf b/Features/ManageabilityPkg/Include/PreMemory.fdf
new file mode 100644
index 0000000000..16e079f494
--- /dev/null
+++ b/Features/ManageabilityPkg/Include/PreMemory.fdf
@@ -0,0 +1,12 @@
+## @file
+# Manageabilty Package pre-memory initialization firmware
+# volume description.
+#
+# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+!if gManageabilityPkgTokenSpaceGuid.PcdManageabilityPeiIpmiEnable == TRUE
+  INF  ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiPei.inf
+!endif
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 01/14] ManageabilityPkg: Add more helper functions
  2023-04-03 15:04 ` [edk2-platforms][PATCH 01/14] ManageabilityPkg: Add more helper functions Chang, Abner
@ 2023-04-10 17:23   ` Tinh Nguyen
  2023-04-11  5:29     ` Chang, Abner
  0 siblings, 1 reply; 22+ messages in thread
From: Tinh Nguyen @ 2023-04-10 17:23 UTC (permalink / raw)
  To: devel, abner.chang
  Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

Please find my inline comment below

On 4/3/2023 10:04 PM, Chang, Abner via groups.io wrote:
> From: Abner Chang <abner.chang@amd.com>
>
> 1. Add a helper function to output payload binary
>     to debug output device.
> 2. Add a helper function to split payload into
>     packages according to maximum transfer unit
>     of transport interface.
> 3. Add a helper function to generate CRC8.
>
> Signed-off-by: Abner Chang <abner.chang@amd.com>
> Cc: Isaac Oram <isaac.w.oram@intel.com>
> Cc: Abdul Lateef Attar <abdattar@amd.com>
> Cc: Nickle Wang <nicklew@nvidia.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
>   .../BaseManageabilityTransportHelper.inf      |   1 +
>   .../Library/ManageabilityTransportHelperLib.h |  98 ++++++++
>   .../BaseManageabilityTransportHelper.c        | 218 +++++++++++++++++-
>   3 files changed, 310 insertions(+), 7 deletions(-)
>
> diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf
> index 95c3362ddb..c31a89aa49 100644
> --- a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf
> +++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf
> @@ -25,6 +25,7 @@
>   [LibraryClasses]
>     BaseMemoryLib
>     DebugLib
> +  MemoryAllocationLib
>   
>   [Packages]
>     ManageabilityPkg/ManageabilityPkg.dec
> diff --git a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h
> index 718ac34a1f..0dbf5ccb3c 100644
> --- a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h
> +++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h
> @@ -11,8 +11,24 @@
>   
>   #include <Library/ManageabilityTransportLib.h>
>   
> +#define DEBUG_MANAGEABILITY_INFO  DEBUG_INFO
Why did you redefine this macro?
I saw that you used both DEBUG_INFO and DEBUG_MANAGEABILITY_INFO 
throughout this library. Please use them consistently.

If you want to change the debug level for all statements in a function,
you can declare an argument as the debug level.
> +
>   typedef struct _MANAGEABILITY_PROTOCOL_NAME MANAGEABILITY_PROTOCOL_NAME;
>   
> +typedef struct {
> +  UINT8     *PayloadPointer;
> +  UINT32    PayloadSize;
> +} MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR;
> +
> +//
> +// The information of multi portions of payload it is
> +// splitted according to transport interface Maximum
> +// Transfer Unit.
> +typedef struct {
> +  UINT16                                     NumberOfPackages; ///< Number of packages in MultiPackages.
> +  MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR    MultiPackages[];
> +} MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES;
> +
>   /**
>     Helper function returns the human readable name of Manageability specification.
>   
> @@ -90,4 +106,86 @@ HelperInitManageabilityTransport (
>     OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS     *TransportAdditionalStatus OPTIONAL
>     );
>   
> +/**
> +  This function splits payload into multiple packages according to
> +  the given transport interface Maximum Transfer Unit (MTU).
> +
> +  @param[in]  PreambleSize         The additional data size precedes
> +                                   each package.
> +  @param[in]  PostambleSize        The additional data size succeeds
> +                                   each package.
> +  @param[in]  Payload              Pointer to payload.
> +  @param[in]  PayloadSize          Payload size in byte.
> +  @param[in]  MaximumTransferUnit  MTU of transport interface.
> +  @param[out] MultiplePackages     Pointer to receive
> +                                   MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
> +                                   structure. Caller has to free the memory
> +                                   allocated for MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES.
> +
> +  @retval   EFI_SUCCESS          MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure
> +                                 is returned successfully.
> +  @retval   EFI_OUT_OF_RESOURCE  Not enough resource to create
> +                                 MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure.
> +**/
> +EFI_STATUS
> +HelperManageabilitySplitPayload (
> +  IN UINT16                                      PreambleSize,
> +  IN UINT16                                      PostambleSize,
> +  IN UINT8                                       *Payload,
> +  IN UINT32                                      PayloadSize,
> +  IN UINT32                                      MaximumTransferUnit,
> +  OUT MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES  **MultiplePackages
> +  );
> +
> +/**
> +  This function generates CRC8 with given polynomial.
> +
> +  @param[in]  Polynomial       Polynomial in 8-bit.
> +  @param[in]  CrcInitialValue  CRC initial value.
> +  @param[in]  BufferStart      Pointer to buffer starts the CRC calculation.
> +  @param[in]  BufferSize       Size of buffer.
> +
> +  @retval  UINT8 CRC value.
> +**/
> +UINT8
> +HelperManageabilityGenerateCrc8 (
> +  IN UINT8   Polynomial,
> +  IN UINT8   CrcInitialValue,
> +  IN UINT8   *BufferStart,
> +  IN UINT32  BufferSize
> +  );
> +
> +/**
> +  Print out manageability transmit payload to the debug output device.
> +
> +  @param[in]  Payload      Payload to print.
> +  @param[in]  PayloadSize  Payload size.
> +
> +**/
> +VOID
> +EFIAPI
> +HelperManageabilityPayLoadDebugPrint (
> +  IN  VOID    *Payload,
> +  IN  UINT32  PayloadSize
> +  );
> +
> +/**
> +  Prints a debug message and manageability payload to the debug output device.
> +
> +  @param[in]  Payload      Payload to print.
> +  @param[in]  PayloadSize  Payload size.
> +  @param[in]  Format       The format string for the debug message to print.
> +  @param[in]  ...          The variable argument list whose contents are accessed
> +                           based on the format string specified by Format.
> +
> +**/
> +VOID
> +EFIAPI
> +HelperManageabilityDebugPrint (
> +  IN  VOID         *Payload,
> +  IN  UINT32       PayloadSize,
> +  IN  CONST CHAR8  *Format,
> +  ...
> +  );
> +
>   #endif
> diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c
> index 81da209764..9d20ed49ff 100644
> --- a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c
> +++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c
> @@ -8,11 +8,12 @@
>   #include <Uefi.h>
>   #include <Library/BaseMemoryLib.h>
>   #include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h>
>   #include <Library/ManageabilityTransportHelperLib.h>
>   
>   //
>   // BaseManageabilityTransportHelper is used by PEI, DXE and SMM.
> -// Make sure the global variables added here should be unchangable.
> +// Make sure the global variables added here should be unchangeable.
>   //
>   MANAGEABILITY_SPECIFICATION_NAME  ManageabilitySpecNameTable[] = {
>     { &gManageabilityTransportKcsGuid,    L"KCS"     },
> @@ -47,8 +48,8 @@ HelperManageabilitySpecName (
>       return NULL;
>     }
>   
> -  if (SpecificationGuid == NULL || IsZeroGuid (SpecificationGuid)) {
> -    DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__));
> +  if ((SpecificationGuid == NULL) || IsZeroGuid (SpecificationGuid)) {
> +    DEBUG ((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__));
>       return NULL;
>     }
>   
> @@ -99,12 +100,13 @@ HelperManageabilityCheckSupportedSpec (
>       return EFI_INVALID_PARAMETER;
>     }
>   
> -  if (TransportGuid == NULL ||
> +  if ((TransportGuid == NULL) ||
>         IsZeroGuid (TransportGuid) ||
> -      ManageabilityProtocolToCheck == NULL ||
> +      (ManageabilityProtocolToCheck == NULL) ||
>         IsZeroGuid (ManageabilityProtocolToCheck)
> -      ) {
> -      DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__));
> +      )
> +  {
> +    DEBUG ((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__));
>       return EFI_INVALID_PARAMETER;
>     }
>   
> @@ -259,3 +261,205 @@ HelperInitManageabilityTransport (
>   
>     return Status;
>   }
> +
> +/**
> +  This function generates CRC8 with given polynomial.
> +
> +  @param[in]  Polynomial       Polynomial in 8-bit.
> +  @param[in]  CrcInitialValue  CRC initial value.
> +  @param[in]  BufferStart      Pointer to buffer starts the CRC calculation.
> +  @param[in]  BufferSize       Size of buffer.
> +
> +  @retval  UINT8 CRC value.
> +**/
> +UINT8
> +HelperManageabilityGenerateCrc8 (
> +  IN UINT8   Polynomial,
> +  IN UINT8   CrcInitialValue,
> +  IN UINT8   *BufferStart,
> +  IN UINT32  BufferSize
> +  )
> +{
> +  UINT8   BitIndex;
> +  UINT32  BufferIndex;
> +
> +  BufferIndex = 0;
> +  while (BufferIndex < BufferSize) {
> +    CrcInitialValue = CrcInitialValue ^ *(BufferStart + BufferIndex);
> +    BufferIndex++;
> +
> +    for (BitIndex = 0; BitIndex < 8; BitIndex++) {
> +      if ((CrcInitialValue & 0x80) != 0) {
> +        CrcInitialValue = (CrcInitialValue << 1) ^ Polynomial;
> +      } else {
> +        CrcInitialValue <<= 1;
> +      }
> +    }
> +  }
> +
> +  return CrcInitialValue;
> +}
> +
> +/**
> +  This function splits payload into multiple packages according to
> +  the given transport interface Maximum Transfer Unit (MTU).
> +
> +
> +  @param[in]  PreambleSize         The additional data size precedes
> +                                   each package.
> +  @param[in]  PostambleSize        The additional data size succeeds
> +                                   each package.
> +  @param[in]  Payload              Pointer to payload.
> +  @param[in]  PayloadSize          Payload size in byte.
> +  @param[in]  MaximumTransferUnit  MTU of transport interface.
> +  @param[out] MultiplePackages     Pointer to receive
> +                                   MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
> +                                   structure. Caller has to free the memory
> +                                   allocated for MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES.
> +
> +  @retval   EFI_SUCCESS          MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure
> +                                 is returned successfully.
> +  @retval   EFI_OUT_OF_RESOURCE  Not enough resource to create
> +                                 MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure.
> +**/
> +EFI_STATUS
> +HelperManageabilitySplitPayload (
> +  IN UINT16                                      PreambleSize,
> +  IN UINT16                                      PostambleSize,
> +  IN UINT8                                       *Payload,
> +  IN UINT32                                      PayloadSize,
> +  IN UINT32                                      MaximumTransferUnit,
> +  OUT MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES  **MultiplePackages
> +  )
> +{
> +  UINT16                                     NumberOfPackages;
> +  UINT16                                     IndexOfPackage;
> +  UINT32                                     PackagePayloadSize;
> +  UINT32                                     TotalPayloadRemaining;
> +  MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES  *ThisMultiplePackages;
> +  MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR    *ThisPackage;
> +
> +  if ((INT16)(MaximumTransferUnit - PreambleSize - PostambleSize) < 0) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "%a: (Preamble 0x%x + PostambleSize 0x%x) is greater than MaximumTransferUnit 0x%x.\n",
> +      __FUNCTION__,
> +      PreambleSize,
> +      PostambleSize,
> +      MaximumTransferUnit
> +      ));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  PackagePayloadSize   = MaximumTransferUnit -PreambleSize - PostambleSize;
> +  NumberOfPackages     = (UINT16)((PayloadSize + (PackagePayloadSize - 1)) / PackagePayloadSize);
> +  ThisMultiplePackages = (MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES *)AllocateZeroPool (
> +                                                                        sizeof (MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES) +
> +                                                                        sizeof (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR) * NumberOfPackages
> +                                                                        );
> +  if (ThisMultiplePackages == NULL) {
> +    DEBUG ((DEBUG_ERROR, "%a: Not enough memory for MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES\n"));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  ThisMultiplePackages->NumberOfPackages = NumberOfPackages;
> +  ThisPackage                            = (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *)(ThisMultiplePackages + 1);
> +  TotalPayloadRemaining                  = PayloadSize;
> +  for (IndexOfPackage = 0; IndexOfPackage < NumberOfPackages; IndexOfPackage++) {
> +    ThisPackage->PayloadPointer = Payload + (IndexOfPackage * PackagePayloadSize);
> +    ThisPackage->PayloadSize    = MIN (TotalPayloadRemaining, PackagePayloadSize);
> +    TotalPayloadRemaining      -= ThisPackage->PayloadSize;
> +    ThisPackage++;
> +  }
> +
> +  if (TotalPayloadRemaining != 0) {
> +    DEBUG ((DEBUG_ERROR, "%a: Error processing multiple packages (TotalPayloadRemaining != 0)\n", __FUNCTION__));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  *MultiplePackages = ThisMultiplePackages;
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Print out manageability transmit payload to the debug output device.
> +
> +  @param[in]  Payload      Payload to print.
> +  @param[in]  PayloadSize  Payload size.
> +
> +**/
> +VOID
> +EFIAPI
> +HelperManageabilityPayLoadDebugPrint (
> +  IN  VOID    *Payload,
> +  IN  UINT32  PayloadSize
> +  )
> +{
> +  UINT16  Page256;
> +  UINT16  Row16;
> +  UINT16  Column16;
> +  UINT32  RemainingBytes;
> +  UINT32  TotalBytePrinted;
> +
> +  RemainingBytes   = PayloadSize;
> +  TotalBytePrinted = 0;
> +  while (TRUE) {
> +    if (TotalBytePrinted % 256 == 0) {
> +      Page256 = (UINT16)TotalBytePrinted / 256;
> +      DEBUG ((DEBUG_MANAGEABILITY_INFO, "======== Manageability Payload %04xH - %04xH =========\n", Page256 * 256, Page256 * 256 + MIN (RemainingBytes, 256) - 1));
> +      DEBUG ((DEBUG_MANAGEABILITY_INFO, "       "));
> +      for (Column16 = 0; Column16 < 16; Column16++) {
> +        DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", Column16));
> +      }
> +
> +      DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n       -----------------------------------------------\n"));
> +    }
> +
> +    for (Row16 = 0; Row16 < 16; Row16++) {
> +      DEBUG ((DEBUG_MANAGEABILITY_INFO, "%04x | ", Page256 * 256 + Row16 * 16));
> +      for (Column16 = 0; Column16 < MIN (RemainingBytes, 16); Column16++) {
> +        DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", *((UINT8 *)Payload + Page256 * 256 + Row16 * 16 + Column16)));
> +      }
> +
> +      RemainingBytes   -= Column16;
> +      TotalBytePrinted += Column16;
> +      if (RemainingBytes == 0) {
> +        DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n"));
> +        return;
> +      }
> +      DEBUG((DEBUG_MANAGEABILITY_INFO, "\n"));
> +    }
> +
> +    DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n"));
> +  }
> +
> +  DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n"));
> +}
> +
> +/**
> +  Prints a debug message and manageability payload to the debug output device.
> +
> +  @param[in]  Payload      Payload to print.
> +  @param[in]  PayloadSize  Payload size.
> +  @param[in]  Format       The format string for the debug message to print.
> +  @param[in]  ...          The variable argument list whose contents are accessed
> +                           based on the format string specified by Format.
> +
> +**/
> +VOID
> +EFIAPI
> +HelperManageabilityDebugPrint (
> +  IN  VOID         *Payload,
> +  IN  UINT32       PayloadSize,
> +  IN  CONST CHAR8  *Format,
> +  ...
> +  )
> +{
> +  VA_LIST  Marker;
> +
> +  VA_START (Marker, Format);
> +  DEBUG ((DEBUG_MANAGEABILITY_INFO, "Manageability Transmission: "));
> +  DebugVPrint ((UINTN)DEBUG_MANAGEABILITY_INFO, Format, Marker);
> +  HelperManageabilityPayLoadDebugPrint (Payload, PayloadSize);
> +  VA_END (Marker);
> +}

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 03/14] ManageabilityPkg: Fix Uncrustify errors
  2023-04-03 15:04 ` [edk2-platforms][PATCH 03/14] ManageabilityPkg: Fix Uncrustify errors Chang, Abner
@ 2023-04-10 17:25   ` Tinh Nguyen
  2023-04-11  5:31     ` Chang, Abner
  0 siblings, 1 reply; 22+ messages in thread
From: Tinh Nguyen @ 2023-04-10 17:25 UTC (permalink / raw)
  To: devel, abner.chang
  Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

Hi Abner,

I checked and found that some files were not formatted with uncrustify. 
Please run it for the whole package.

You can append this commit to the of the series.

On 4/3/2023 10:04 PM, Chang, Abner via groups.io wrote:
> From: Abner Chang <abner.chang@amd.com>
>
> Fix Uncrustify errors of IPMI protocol
> and KCS manageability transport library.
>
> Signed-off-by: Abner Chang <abner.chang@amd.com>
> Cc: Isaac Oram <isaac.w.oram@intel.com>
> Cc: Abdul Lateef Attar <abdattar@amd.com>
> Cc: Nickle Wang <nicklew@nvidia.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
>   .../Library/ManageabilityTransportLib.h       |  8 ++--
>   .../IpmiProtocol/Pei/IpmiPpiInternal.h        | 10 ++---
>   .../Dxe/ManageabilityTransportKcs.c           |  6 ++-
>   .../Universal/IpmiProtocol/Dxe/IpmiProtocol.c |  4 +-
>   .../Universal/IpmiProtocol/Pei/IpmiPpi.c      | 40 ++++++++++---------
>   .../Universal/IpmiProtocol/Smm/IpmiProtocol.c |  7 ++--
>   6 files changed, 41 insertions(+), 34 deletions(-)
>
> diff --git a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
> index ad6cd1a464..d86d0d87d5 100644
> --- a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
> +++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.h
> @@ -74,13 +74,13 @@ typedef UINT32 MANAGEABILITY_TRANSPORT_CAPABILITY;
>   /// Bit 0
>   #define MANAGEABILITY_TRANSPORT_CAPABILITY_MULTIPLE_TRANSFER_TOKENS  0x00000001
>   /// Bit 1
> -#define MANAGEABILITY_TRANSPORT_CAPABILITY_ASYNCHRONOUS_TRANSFER     0x00000002
> +#define MANAGEABILITY_TRANSPORT_CAPABILITY_ASYNCHRONOUS_TRANSFER  0x00000002
>   /// Bit 2   - Reserved
>   /// Bit 7:3 - Transport interface maximum payload size, which is (2 ^ bit[7:3] - 1)
>   ///           bit[7:3] means no maximum payload.
> -#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_MASK          0x000000f8
> -#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POSITION  3
> -  #define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE  0x00
> +#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_MASK           0x000000f8
> +#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POSITION   3
> +#define MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE  0x00
>   /// Bit 8:31 - Reserved
>   
>   ///
> diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h
> index 7b6ab0f529..4b6bdc97a9 100644
> --- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h
> +++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal.h
> @@ -17,11 +17,11 @@
>   #define MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK(a)  CR (a, PEI_IPMI_PPI_INTERNAL, PeiIpmiPpi, MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE)
>   
>   typedef struct {
> -  UINT32                              Signature;
> -  MANAGEABILITY_TRANSPORT_TOKEN       *TransportToken;
> -  MANAGEABILITY_TRANSPORT_CAPABILITY  TransportCapability;
> -  UINT32                              TransportMaximumPayload;
> -  PEI_IPMI_PPI                        PeiIpmiPpi;
> +  UINT32                                Signature;
> +  MANAGEABILITY_TRANSPORT_TOKEN         *TransportToken;
> +  MANAGEABILITY_TRANSPORT_CAPABILITY    TransportCapability;
> +  UINT32                                TransportMaximumPayload;
> +  PEI_IPMI_PPI                          PeiIpmiPpi;
>   } PEI_IPMI_PPI_INTERNAL;
>   
>   #endif // MANAGEABILITY_IPMI_PPI_INTERNAL_H_
> diff --git a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
> index 25d6e49886..91d3517bdb 100644
> --- a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
> +++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/ManageabilityTransportKcs.c
> @@ -221,7 +221,7 @@ KcsTransportTransmitReceive (
>     EFI_STATUS                           Status;
>     MANAGEABILITY_IPMI_TRANSPORT_HEADER  *TransmitHeader;
>   
> -  if (TransportToken == NULL || TransferToken == NULL) {
> +  if ((TransportToken == NULL) || (TransferToken == NULL)) {
>       DEBUG ((DEBUG_ERROR, "%a: Invalid transport token or transfer token.\n", __FUNCTION__));
>       return;
>     }
> @@ -298,6 +298,7 @@ AcquireTransportSession (
>       DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for MANAGEABILITY_TRANSPORT_KCS\n", __FUNCTION__));
>       return EFI_OUT_OF_RESOURCES;
>     }
> +
>     KcsTransportToken->Token.Transport = AllocateZeroPool (sizeof (MANAGEABILITY_TRANSPORT));
>     if (KcsTransportToken->Token.Transport == NULL) {
>       FreePool (KcsTransportToken);
> @@ -346,9 +347,10 @@ GetTransportCapability (
>     OUT MANAGEABILITY_TRANSPORT_CAPABILITY  *TransportCapability
>     )
>   {
> -  if (TransportToken == NULL || TransportCapability == NULL) {
> +  if ((TransportToken == NULL) || (TransportCapability == NULL)) {
>       return EFI_INVALID_PARAMETER;
>     }
> +
>     *TransportCapability = 0;
>     return EFI_SUCCESS;
>   }
> diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
> index c30132419d..40587a07af 100644
> --- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
> +++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
> @@ -100,12 +100,14 @@ DxeIpmiEntry (
>       DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for IPMI protocol - %r\n", __FUNCTION__, Status));
>       return Status;
>     }
> +
>     Status = GetTransportCapability (mTransportToken, &TransportCapability);
>     if (EFI_ERROR (Status)) {
>       DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
>       return Status;
>     }
> -  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(TransportCapability);
> +
> +  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY (TransportCapability);
>     if (TransportMaximumPayload == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
>       DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
>     } else {
> diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
> index 0dda6d2d47..0a914e513c 100644
> --- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
> +++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
> @@ -51,19 +51,19 @@ PeiIpmiSubmitCommand (
>     IN OUT UINT32        *ResponseDataSize
>     )
>   {
> -  EFI_STATUS            Status;
> -  PEI_IPMI_PPI_INTERNAL *PeiIpmiPpiinternal;
> -
> -  PeiIpmiPpiinternal = MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK(This);
> -  Status = CommonIpmiSubmitCommand (
> -             PeiIpmiPpiinternal->TransportToken,
> -             NetFunction,
> -             Command,
> -             RequestData,
> -             RequestDataSize,
> -             ResponseData,
> -             ResponseDataSize
> -             );
> +  EFI_STATUS             Status;
> +  PEI_IPMI_PPI_INTERNAL  *PeiIpmiPpiinternal;
> +
> +  PeiIpmiPpiinternal = MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK (This);
> +  Status             = CommonIpmiSubmitCommand (
> +                         PeiIpmiPpiinternal->TransportToken,
> +                         NetFunction,
> +                         Command,
> +                         RequestData,
> +                         RequestDataSize,
> +                         ResponseData,
> +                         ResponseDataSize
> +                         );
>     return Status;
>   }
>   
> @@ -90,18 +90,19 @@ PeiIpmiEntry (
>     MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS     TransportAdditionalStatus;
>     MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION  HardwareInformation;
>   
> -  PeiIpmiPpiinternal = (PEI_IPMI_PPI_INTERNAL *)AllocateZeroPool (sizeof(PEI_IPMI_PPI_INTERNAL));
> +  PeiIpmiPpiinternal = (PEI_IPMI_PPI_INTERNAL *)AllocateZeroPool (sizeof (PEI_IPMI_PPI_INTERNAL));
>     if (PeiIpmiPpiinternal == NULL) {
>       DEBUG ((DEBUG_ERROR, "%a: Not enough memory for PEI_IPMI_PPI_INTERNAL.\n", __FUNCTION__));
>       return EFI_OUT_OF_RESOURCES;
>     }
> -  PpiDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)AllocateZeroPool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
> +
> +  PpiDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)AllocateZeroPool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
>     if (PpiDescriptor == NULL) {
>       DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_PEI_PPI_DESCRIPTOR.\n", __FUNCTION__));
>       return EFI_OUT_OF_RESOURCES;
>     }
>   
> -  PeiIpmiPpiinternal->Signature = MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE;
> +  PeiIpmiPpiinternal->Signature                    = MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE;
>     PeiIpmiPpiinternal->PeiIpmiPpi.IpmiSubmitCommand = PeiIpmiSubmitCommand;
>   
>     PpiDescriptor->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
> @@ -116,18 +117,19 @@ PeiIpmiEntry (
>       DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for IPMI protocol - %r\n", __FUNCTION__, Status));
>       return Status;
>     }
> +
>     Status = GetTransportCapability (PeiIpmiPpiinternal->TransportToken, &PeiIpmiPpiinternal->TransportCapability);
>     if (EFI_ERROR (Status)) {
>       DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
>       return Status;
>     }
>   
> -  PeiIpmiPpiinternal->TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(PeiIpmiPpiinternal->TransportCapability);
> +  PeiIpmiPpiinternal->TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY (PeiIpmiPpiinternal->TransportCapability);
>     if (PeiIpmiPpiinternal->TransportMaximumPayload  == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
> -    DEBUG((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
> +    DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
>     } else {
>       PeiIpmiPpiinternal->TransportMaximumPayload -= 1;
> -    DEBUG((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, PeiIpmiPpiinternal->TransportMaximumPayload));
> +    DEBUG ((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, PeiIpmiPpiinternal->TransportMaximumPayload));
>     }
>   
>     TransportName = HelperManageabilitySpecName (PeiIpmiPpiinternal->TransportToken->Transport->ManageabilityTransportSpecification);
> diff --git a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
> index 86dee2fa24..41b9a10453 100644
> --- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
> +++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
> @@ -107,12 +107,13 @@ SmmIpmiEntry (
>       DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n", __FUNCTION__));
>       return Status;
>     }
> -  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(TransportCapability);
> +
> +  TransportMaximumPayload = MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY (TransportCapability);
>     if (TransportMaximumPayload == (1 << MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AVAILABLE)) {
> -    DEBUG((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
> +    DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is undefined.\n", __FUNCTION__));
>     } else {
>       TransportMaximumPayload -= 1;
> -    DEBUG((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, TransportMaximumPayload));
> +    DEBUG ((DEBUG_INFO, "%a: Transport interface for IPMI protocol has maximum payload 0x%x.\n", __FUNCTION__, TransportMaximumPayload));
>     }
>   
>     mTransportName = HelperManageabilitySpecName (mTransportToken->Transport->ManageabilityTransportSpecification);

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [edk2-platforms][PATCH 13/14] ManageabilityPkg: Relocate Manageability.dsc
  2023-04-03 15:04 ` [edk2-platforms][PATCH 13/14] ManageabilityPkg: Relocate Manageability.dsc Chang, Abner
@ 2023-04-10 17:27   ` Tinh Nguyen
  2023-04-11  5:55     ` Chang, Abner
  0 siblings, 1 reply; 22+ messages in thread
From: Tinh Nguyen @ 2023-04-10 17:27 UTC (permalink / raw)
  To: abner.chang, devel
  Cc: Isaac Oram, Abdul Lateef Attar, Nickle Wang, Igor Kulchytskyy

Hi Abner,

As someone mentioned before, you should move this library for arm/arm64 
to Manageability.dsc

btw, the files that are included in dsc should have the extension dsc.inc.

Regards,

Tinh

On 4/3/2023 10:04 PM, abner.chang@amd.com wrote:
> [EXTERNAL EMAIL NOTICE: This email originated from an external sender. Please be mindful of safe email handling and proprietary information protection practices.]
>
>
> From: abnchang <abnchang@amd.com>
>
> Relocate Manageability.dsc to just under \Include
> folder.
>
> Signed-off-by: Abner Chang <abner.chang@amd.com>
> Cc: Isaac Oram <isaac.w.oram@intel.com>
> Cc: Abdul Lateef Attar <abdattar@amd.com>
> Cc: Nickle Wang <nicklew@nvidia.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> Cc: Tinh Nguyen <tinhnguyen@amperemail.onmicrosoft.com>
> ---
>   Features/ManageabilityPkg/Include/{Dsc => }/Manageability.dsc | 0
>   Features/ManageabilityPkg/ManageabilityPkg.dsc                | 2 +-
>   2 files changed, 1 insertion(+), 1 deletion(-)
>   rename Features/ManageabilityPkg/Include/{Dsc => }/Manageability.dsc (100%)
>
> diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Features/ManageabilityPkg/Include/Manageability.dsc
> similarity index 100%
> rename from Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
> rename to Features/ManageabilityPkg/Include/Manageability.dsc
> diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc b/Features/ManageabilityPkg/ManageabilityPkg.dsc
> index 41a8957954..a0712d1c0a 100644
> --- a/Features/ManageabilityPkg/ManageabilityPkg.dsc
> +++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc
> @@ -53,4 +53,4 @@
>   [LibraryClasses]
>     ManageabilityTransportLib|ManageabilityPkg/Library/BaseManageabilityTransportNullLib/BaseManageabilityTransportNull.inf
>
> -!include Include/Dsc/Manageability.dsc
> +!include Include/Manageability.dsc
> --
> 2.37.1.windows.1
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 01/14] ManageabilityPkg: Add more helper functions
  2023-04-10 17:23   ` [edk2-devel] " Tinh Nguyen
@ 2023-04-11  5:29     ` Chang, Abner
  0 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-11  5:29 UTC (permalink / raw)
  To: Tinh Nguyen, devel@edk2.groups.io
  Cc: Isaac Oram, Attar, AbdulLateef (Abdul Lateef), Nickle Wang,
	Igor Kulchytskyy

[AMD Official Use Only - General]



> -----Original Message-----
> From: Tinh Nguyen <tinhnguyen@amperemail.onmicrosoft.com>
> Sent: Tuesday, April 11, 2023 1:24 AM
> To: devel@edk2.groups.io; Chang, Abner <Abner.Chang@amd.com>
> Cc: Isaac Oram <isaac.w.oram@intel.com>; Attar, AbdulLateef (Abdul Lateef)
> <AbdulLateef.Attar@amd.com>; Nickle Wang <nicklew@nvidia.com>; Igor
> Kulchytskyy <igork@ami.com>
> Subject: Re: [edk2-devel] [edk2-platforms][PATCH 01/14] ManageabilityPkg:
> Add more helper functions
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> Please find my inline comment below
> 
> On 4/3/2023 10:04 PM, Chang, Abner via groups.io wrote:
> > From: Abner Chang <abner.chang@amd.com>
> >
> > 1. Add a helper function to output payload binary
> >     to debug output device.
> > 2. Add a helper function to split payload into
> >     packages according to maximum transfer unit
> >     of transport interface.
> > 3. Add a helper function to generate CRC8.
> >
> > Signed-off-by: Abner Chang <abner.chang@amd.com>
> > Cc: Isaac Oram <isaac.w.oram@intel.com>
> > Cc: Abdul Lateef Attar <abdattar@amd.com>
> > Cc: Nickle Wang <nicklew@nvidia.com>
> > Cc: Igor Kulchytskyy <igork@ami.com>
> > ---
> >   .../BaseManageabilityTransportHelper.inf      |   1 +
> >   .../Library/ManageabilityTransportHelperLib.h |  98 ++++++++
> >   .../BaseManageabilityTransportHelper.c        | 218 +++++++++++++++++-
> >   3 files changed, 310 insertions(+), 7 deletions(-)
> >
> > diff --git
> > a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLi
> > b/BaseManageabilityTransportHelper.inf
> > b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLi
> > b/BaseManageabilityTransportHelper.inf
> > index 95c3362ddb..c31a89aa49 100644
> > ---
> > a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLi
> > b/BaseManageabilityTransportHelper.inf
> > +++
> b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelp
> > +++ erLib/BaseManageabilityTransportHelper.inf
> > @@ -25,6 +25,7 @@
> >   [LibraryClasses]
> >     BaseMemoryLib
> >     DebugLib
> > +  MemoryAllocationLib
> >
> >   [Packages]
> >     ManageabilityPkg/ManageabilityPkg.dec
> > diff --git
> > a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelp
> > erLib.h
> > b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelp
> > erLib.h
> > index 718ac34a1f..0dbf5ccb3c 100644
> > ---
> > a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelp
> > erLib.h
> > +++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransport
> > +++ HelperLib.h
> > @@ -11,8 +11,24 @@
> >
> >   #include <Library/ManageabilityTransportLib.h>
> >
> > +#define DEBUG_MANAGEABILITY_INFO  DEBUG_INFO
> Why did you redefine this macro?
> I saw that you used both DEBUG_INFO and DEBUG_MANAGEABILITY_INFO
> throughout this library. Please use them consistently.
Thanks for reminding me this. I will update those files.

> 
> If you want to change the debug level for all statements in a function, you
> can declare an argument as the debug level.
We would like to propose a debug level for Manageability, that covers both ManageabilityPkg and RedfishPkg.

Thanks
Abner


> > +
> >   typedef struct _MANAGEABILITY_PROTOCOL_NAME
> > MANAGEABILITY_PROTOCOL_NAME;
> >
> > +typedef struct {
> > +  UINT8     *PayloadPointer;
> > +  UINT32    PayloadSize;
> > +} MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR;
> > +
> > +//
> > +// The information of multi portions of payload it is // splitted
> > +according to transport interface Maximum // Transfer Unit.
> > +typedef struct {
> > +  UINT16                                     NumberOfPackages; ///< Number of packages
> in MultiPackages.
> > +  MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR    MultiPackages[];
> > +} MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES;
> > +
> >   /**
> >     Helper function returns the human readable name of Manageability
> specification.
> >
> > @@ -90,4 +106,86 @@ HelperInitManageabilityTransport (
> >     OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS
> *TransportAdditionalStatus OPTIONAL
> >     );
> >
> > +/**
> > +  This function splits payload into multiple packages according to
> > +  the given transport interface Maximum Transfer Unit (MTU).
> > +
> > +  @param[in]  PreambleSize         The additional data size precedes
> > +                                   each package.
> > +  @param[in]  PostambleSize        The additional data size succeeds
> > +                                   each package.
> > +  @param[in]  Payload              Pointer to payload.
> > +  @param[in]  PayloadSize          Payload size in byte.
> > +  @param[in]  MaximumTransferUnit  MTU of transport interface.
> > +  @param[out] MultiplePackages     Pointer to receive
> > +                                   MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
> > +                                   structure. Caller has to free the memory
> > +                                   allocated for
> MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES.
> > +
> > +  @retval   EFI_SUCCESS
> MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure
> > +                                 is returned successfully.
> > +  @retval   EFI_OUT_OF_RESOURCE  Not enough resource to create
> > +                                 MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
> structure.
> > +**/
> > +EFI_STATUS
> > +HelperManageabilitySplitPayload (
> > +  IN UINT16                                      PreambleSize,
> > +  IN UINT16                                      PostambleSize,
> > +  IN UINT8                                       *Payload,
> > +  IN UINT32                                      PayloadSize,
> > +  IN UINT32                                      MaximumTransferUnit,
> > +  OUT MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
> **MultiplePackages
> > +  );
> > +
> > +/**
> > +  This function generates CRC8 with given polynomial.
> > +
> > +  @param[in]  Polynomial       Polynomial in 8-bit.
> > +  @param[in]  CrcInitialValue  CRC initial value.
> > +  @param[in]  BufferStart      Pointer to buffer starts the CRC calculation.
> > +  @param[in]  BufferSize       Size of buffer.
> > +
> > +  @retval  UINT8 CRC value.
> > +**/
> > +UINT8
> > +HelperManageabilityGenerateCrc8 (
> > +  IN UINT8   Polynomial,
> > +  IN UINT8   CrcInitialValue,
> > +  IN UINT8   *BufferStart,
> > +  IN UINT32  BufferSize
> > +  );
> > +
> > +/**
> > +  Print out manageability transmit payload to the debug output device.
> > +
> > +  @param[in]  Payload      Payload to print.
> > +  @param[in]  PayloadSize  Payload size.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +HelperManageabilityPayLoadDebugPrint (
> > +  IN  VOID    *Payload,
> > +  IN  UINT32  PayloadSize
> > +  );
> > +
> > +/**
> > +  Prints a debug message and manageability payload to the debug output
> device.
> > +
> > +  @param[in]  Payload      Payload to print.
> > +  @param[in]  PayloadSize  Payload size.
> > +  @param[in]  Format       The format string for the debug message to print.
> > +  @param[in]  ...          The variable argument list whose contents are
> accessed
> > +                           based on the format string specified by Format.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +HelperManageabilityDebugPrint (
> > +  IN  VOID         *Payload,
> > +  IN  UINT32       PayloadSize,
> > +  IN  CONST CHAR8  *Format,
> > +  ...
> > +  );
> > +
> >   #endif
> > diff --git
> > a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLi
> > b/BaseManageabilityTransportHelper.c
> > b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLi
> > b/BaseManageabilityTransportHelper.c
> > index 81da209764..9d20ed49ff 100644
> > ---
> > a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLi
> > b/BaseManageabilityTransportHelper.c
> > +++
> b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelp
> > +++ erLib/BaseManageabilityTransportHelper.c
> > @@ -8,11 +8,12 @@
> >   #include <Uefi.h>
> >   #include <Library/BaseMemoryLib.h>
> >   #include <Library/DebugLib.h>
> > +#include <Library/MemoryAllocationLib.h>
> >   #include <Library/ManageabilityTransportHelperLib.h>
> >
> >   //
> >   // BaseManageabilityTransportHelper is used by PEI, DXE and SMM.
> > -// Make sure the global variables added here should be unchangable.
> > +// Make sure the global variables added here should be unchangeable.
> >   //
> >   MANAGEABILITY_SPECIFICATION_NAME  ManageabilitySpecNameTable[]
> = {
> >     { &gManageabilityTransportKcsGuid,    L"KCS"     },
> > @@ -47,8 +48,8 @@ HelperManageabilitySpecName (
> >       return NULL;
> >     }
> >
> > -  if (SpecificationGuid == NULL || IsZeroGuid (SpecificationGuid)) {
> > -    DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or
> zero GUID.\n", __FUNCTION__));
> > +  if ((SpecificationGuid == NULL) || IsZeroGuid (SpecificationGuid)) {
> > +    DEBUG ((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or
> > + zero GUID.\n", __FUNCTION__));
> >       return NULL;
> >     }
> >
> > @@ -99,12 +100,13 @@ HelperManageabilityCheckSupportedSpec (
> >       return EFI_INVALID_PARAMETER;
> >     }
> >
> > -  if (TransportGuid == NULL ||
> > +  if ((TransportGuid == NULL) ||
> >         IsZeroGuid (TransportGuid) ||
> > -      ManageabilityProtocolToCheck == NULL ||
> > +      (ManageabilityProtocolToCheck == NULL) ||
> >         IsZeroGuid (ManageabilityProtocolToCheck)
> > -      ) {
> > -      DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or
> zero GUID.\n", __FUNCTION__));
> > +      )
> > +  {
> > +    DEBUG ((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or
> > + zero GUID.\n", __FUNCTION__));
> >       return EFI_INVALID_PARAMETER;
> >     }
> >
> > @@ -259,3 +261,205 @@ HelperInitManageabilityTransport (
> >
> >     return Status;
> >   }
> > +
> > +/**
> > +  This function generates CRC8 with given polynomial.
> > +
> > +  @param[in]  Polynomial       Polynomial in 8-bit.
> > +  @param[in]  CrcInitialValue  CRC initial value.
> > +  @param[in]  BufferStart      Pointer to buffer starts the CRC calculation.
> > +  @param[in]  BufferSize       Size of buffer.
> > +
> > +  @retval  UINT8 CRC value.
> > +**/
> > +UINT8
> > +HelperManageabilityGenerateCrc8 (
> > +  IN UINT8   Polynomial,
> > +  IN UINT8   CrcInitialValue,
> > +  IN UINT8   *BufferStart,
> > +  IN UINT32  BufferSize
> > +  )
> > +{
> > +  UINT8   BitIndex;
> > +  UINT32  BufferIndex;
> > +
> > +  BufferIndex = 0;
> > +  while (BufferIndex < BufferSize) {
> > +    CrcInitialValue = CrcInitialValue ^ *(BufferStart + BufferIndex);
> > +    BufferIndex++;
> > +
> > +    for (BitIndex = 0; BitIndex < 8; BitIndex++) {
> > +      if ((CrcInitialValue & 0x80) != 0) {
> > +        CrcInitialValue = (CrcInitialValue << 1) ^ Polynomial;
> > +      } else {
> > +        CrcInitialValue <<= 1;
> > +      }
> > +    }
> > +  }
> > +
> > +  return CrcInitialValue;
> > +}
> > +
> > +/**
> > +  This function splits payload into multiple packages according to
> > +  the given transport interface Maximum Transfer Unit (MTU).
> > +
> > +
> > +  @param[in]  PreambleSize         The additional data size precedes
> > +                                   each package.
> > +  @param[in]  PostambleSize        The additional data size succeeds
> > +                                   each package.
> > +  @param[in]  Payload              Pointer to payload.
> > +  @param[in]  PayloadSize          Payload size in byte.
> > +  @param[in]  MaximumTransferUnit  MTU of transport interface.
> > +  @param[out] MultiplePackages     Pointer to receive
> > +                                   MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
> > +                                   structure. Caller has to free the memory
> > +                                   allocated for
> MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES.
> > +
> > +  @retval   EFI_SUCCESS
> MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure
> > +                                 is returned successfully.
> > +  @retval   EFI_OUT_OF_RESOURCE  Not enough resource to create
> > +                                 MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
> structure.
> > +**/
> > +EFI_STATUS
> > +HelperManageabilitySplitPayload (
> > +  IN UINT16                                      PreambleSize,
> > +  IN UINT16                                      PostambleSize,
> > +  IN UINT8                                       *Payload,
> > +  IN UINT32                                      PayloadSize,
> > +  IN UINT32                                      MaximumTransferUnit,
> > +  OUT MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
> **MultiplePackages
> > +  )
> > +{
> > +  UINT16                                     NumberOfPackages;
> > +  UINT16                                     IndexOfPackage;
> > +  UINT32                                     PackagePayloadSize;
> > +  UINT32                                     TotalPayloadRemaining;
> > +  MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES
> *ThisMultiplePackages;
> > +  MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR    *ThisPackage;
> > +
> > +  if ((INT16)(MaximumTransferUnit - PreambleSize - PostambleSize) < 0) {
> > +    DEBUG ((
> > +      DEBUG_ERROR,
> > +      "%a: (Preamble 0x%x + PostambleSize 0x%x) is greater than
> MaximumTransferUnit 0x%x.\n",
> > +      __FUNCTION__,
> > +      PreambleSize,
> > +      PostambleSize,
> > +      MaximumTransferUnit
> > +      ));
> > +    return EFI_INVALID_PARAMETER;
> > +  }
> > +
> > +  PackagePayloadSize   = MaximumTransferUnit -PreambleSize -
> PostambleSize;
> > +  NumberOfPackages     = (UINT16)((PayloadSize + (PackagePayloadSize -
> 1)) / PackagePayloadSize);
> > +  ThisMultiplePackages =
> (MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES *)AllocateZeroPool (
> > +                                                                        sizeof
> (MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES) +
> > +                                                                        sizeof
> (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR) * NumberOfPackages
> > +
> > + );  if (ThisMultiplePackages == NULL) {
> > +    DEBUG ((DEBUG_ERROR, "%a: Not enough memory for
> MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES\n"));
> > +    return EFI_INVALID_PARAMETER;
> > +  }
> > +
> > +  ThisMultiplePackages->NumberOfPackages = NumberOfPackages;
> > +  ThisPackage                            =
> (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *)(ThisMultiplePackages
> + 1);
> > +  TotalPayloadRemaining                  = PayloadSize;
> > +  for (IndexOfPackage = 0; IndexOfPackage < NumberOfPackages;
> IndexOfPackage++) {
> > +    ThisPackage->PayloadPointer = Payload + (IndexOfPackage *
> PackagePayloadSize);
> > +    ThisPackage->PayloadSize    = MIN (TotalPayloadRemaining,
> PackagePayloadSize);
> > +    TotalPayloadRemaining      -= ThisPackage->PayloadSize;
> > +    ThisPackage++;
> > +  }
> > +
> > +  if (TotalPayloadRemaining != 0) {
> > +    DEBUG ((DEBUG_ERROR, "%a: Error processing multiple packages
> (TotalPayloadRemaining != 0)\n", __FUNCTION__));
> > +    return EFI_INVALID_PARAMETER;
> > +  }
> > +
> > +  *MultiplePackages = ThisMultiplePackages;
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +/**
> > +  Print out manageability transmit payload to the debug output device.
> > +
> > +  @param[in]  Payload      Payload to print.
> > +  @param[in]  PayloadSize  Payload size.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +HelperManageabilityPayLoadDebugPrint (
> > +  IN  VOID    *Payload,
> > +  IN  UINT32  PayloadSize
> > +  )
> > +{
> > +  UINT16  Page256;
> > +  UINT16  Row16;
> > +  UINT16  Column16;
> > +  UINT32  RemainingBytes;
> > +  UINT32  TotalBytePrinted;
> > +
> > +  RemainingBytes   = PayloadSize;
> > +  TotalBytePrinted = 0;
> > +  while (TRUE) {
> > +    if (TotalBytePrinted % 256 == 0) {
> > +      Page256 = (UINT16)TotalBytePrinted / 256;
> > +      DEBUG ((DEBUG_MANAGEABILITY_INFO, "======== Manageability
> Payload %04xH - %04xH =========\n", Page256 * 256, Page256 * 256 + MIN
> (RemainingBytes, 256) - 1));
> > +      DEBUG ((DEBUG_MANAGEABILITY_INFO, "       "));
> > +      for (Column16 = 0; Column16 < 16; Column16++) {
> > +        DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", Column16));
> > +      }
> > +
> > +      DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n       --------------------------
> ---------------------\n"));
> > +    }
> > +
> > +    for (Row16 = 0; Row16 < 16; Row16++) {
> > +      DEBUG ((DEBUG_MANAGEABILITY_INFO, "%04x | ", Page256 * 256 +
> Row16 * 16));
> > +      for (Column16 = 0; Column16 < MIN (RemainingBytes, 16); Column16++)
> {
> > +        DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", *((UINT8
> *)Payload + Page256 * 256 + Row16 * 16 + Column16)));
> > +      }
> > +
> > +      RemainingBytes   -= Column16;
> > +      TotalBytePrinted += Column16;
> > +      if (RemainingBytes == 0) {
> > +        DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n"));
> > +        return;
> > +      }
> > +      DEBUG((DEBUG_MANAGEABILITY_INFO, "\n"));
> > +    }
> > +
> > +    DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n"));  }
> > +
> > +  DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n")); }
> > +
> > +/**
> > +  Prints a debug message and manageability payload to the debug output
> device.
> > +
> > +  @param[in]  Payload      Payload to print.
> > +  @param[in]  PayloadSize  Payload size.
> > +  @param[in]  Format       The format string for the debug message to print.
> > +  @param[in]  ...          The variable argument list whose contents are
> accessed
> > +                           based on the format string specified by Format.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +HelperManageabilityDebugPrint (
> > +  IN  VOID         *Payload,
> > +  IN  UINT32       PayloadSize,
> > +  IN  CONST CHAR8  *Format,
> > +  ...
> > +  )
> > +{
> > +  VA_LIST  Marker;
> > +
> > +  VA_START (Marker, Format);
> > +  DEBUG ((DEBUG_MANAGEABILITY_INFO, "Manageability Transmission:
> "));
> > +  DebugVPrint ((UINTN)DEBUG_MANAGEABILITY_INFO, Format, Marker);
> > +  HelperManageabilityPayLoadDebugPrint (Payload, PayloadSize);
> > +  VA_END (Marker);
> > +}

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 03/14] ManageabilityPkg: Fix Uncrustify errors
  2023-04-10 17:25   ` [edk2-devel] " Tinh Nguyen
@ 2023-04-11  5:31     ` Chang, Abner
  0 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-11  5:31 UTC (permalink / raw)
  To: Tinh Nguyen, devel@edk2.groups.io
  Cc: Isaac Oram, Attar, AbdulLateef (Abdul Lateef), Nickle Wang,
	Igor Kulchytskyy

[AMD Official Use Only - General]



> -----Original Message-----
> From: Tinh Nguyen <tinhnguyen@amperemail.onmicrosoft.com>
> Sent: Tuesday, April 11, 2023 1:25 AM
> To: devel@edk2.groups.io; Chang, Abner <Abner.Chang@amd.com>
> Cc: Isaac Oram <isaac.w.oram@intel.com>; Attar, AbdulLateef (Abdul Lateef)
> <AbdulLateef.Attar@amd.com>; Nickle Wang <nicklew@nvidia.com>; Igor
> Kulchytskyy <igork@ami.com>
> Subject: Re: [edk2-devel] [edk2-platforms][PATCH 03/14] ManageabilityPkg:
> Fix Uncrustify errors
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> Hi Abner,
> 
> I checked and found that some files were not formatted with uncrustify.
> Please run it for the whole package.
> 
> You can append this commit to the of the series.
I believe I ran Uncrustify check on each commit before sending out the patches.
Will check it again in the next version.

Thanks
Abner
> 
> On 4/3/2023 10:04 PM, Chang, Abner via groups.io wrote:
> > From: Abner Chang <abner.chang@amd.com>
> >
> > Fix Uncrustify errors of IPMI protocol and KCS manageability transport
> > library.
> >
> > Signed-off-by: Abner Chang <abner.chang@amd.com>
> > Cc: Isaac Oram <isaac.w.oram@intel.com>
> > Cc: Abdul Lateef Attar <abdattar@amd.com>
> > Cc: Nickle Wang <nicklew@nvidia.com>
> > Cc: Igor Kulchytskyy <igork@ami.com>
> > ---
> >   .../Library/ManageabilityTransportLib.h       |  8 ++--
> >   .../IpmiProtocol/Pei/IpmiPpiInternal.h        | 10 ++---
> >   .../Dxe/ManageabilityTransportKcs.c           |  6 ++-
> >   .../Universal/IpmiProtocol/Dxe/IpmiProtocol.c |  4 +-
> >   .../Universal/IpmiProtocol/Pei/IpmiPpi.c      | 40 ++++++++++---------
> >   .../Universal/IpmiProtocol/Smm/IpmiProtocol.c |  7 ++--
> >   6 files changed, 41 insertions(+), 34 deletions(-)
> >
> > diff --git
> > a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.
> > h
> > b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.
> > h
> > index ad6cd1a464..d86d0d87d5 100644
> > ---
> > a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportLib.
> > h
> > +++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransport
> > +++ Lib.h
> > @@ -74,13 +74,13 @@ typedef UINT32
> MANAGEABILITY_TRANSPORT_CAPABILITY;
> >   /// Bit 0
> >   #define
> MANAGEABILITY_TRANSPORT_CAPABILITY_MULTIPLE_TRANSFER_TOKENS
> 0x00000001
> >   /// Bit 1
> > -#define
> MANAGEABILITY_TRANSPORT_CAPABILITY_ASYNCHRONOUS_TRANSFER
> 0x00000002
> > +#define
> MANAGEABILITY_TRANSPORT_CAPABILITY_ASYNCHRONOUS_TRANSFER
> > +0x00000002
> >   /// Bit 2   - Reserved
> >   /// Bit 7:3 - Transport interface maximum payload size, which is (2 ^ bit[7:3]
> - 1)
> >   ///           bit[7:3] means no maximum payload.
> > -#define
> MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_MASK
> 0x000000f8
> > -#define
> >
> MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POS
> ITION  3
> > -  #define
> >
> MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AV
> AILABLE  0x00
> > +#define
> MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_MASK
> 0x000000f8
> > +#define
> MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_BIT_POS
> ITION   3
> > +#define
> >
> +MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_A
> VAILABLE
> > +0x00
> >   /// Bit 8:31 - Reserved
> >
> >   ///
> > diff --git
> > a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal
> > .h
> > b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal
> > .h
> > index 7b6ab0f529..4b6bdc97a9 100644
> > ---
> > a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInternal
> > .h
> > +++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiInte
> > +++ rnal.h
> > @@ -17,11 +17,11 @@
> >   #define MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK(a)  CR (a,
> > PEI_IPMI_PPI_INTERNAL, PeiIpmiPpi,
> > MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE)
> >
> >   typedef struct {
> > -  UINT32                              Signature;
> > -  MANAGEABILITY_TRANSPORT_TOKEN       *TransportToken;
> > -  MANAGEABILITY_TRANSPORT_CAPABILITY  TransportCapability;
> > -  UINT32                              TransportMaximumPayload;
> > -  PEI_IPMI_PPI                        PeiIpmiPpi;
> > +  UINT32                                Signature;
> > +  MANAGEABILITY_TRANSPORT_TOKEN         *TransportToken;
> > +  MANAGEABILITY_TRANSPORT_CAPABILITY    TransportCapability;
> > +  UINT32                                TransportMaximumPayload;
> > +  PEI_IPMI_PPI                          PeiIpmiPpi;
> >   } PEI_IPMI_PPI_INTERNAL;
> >
> >   #endif // MANAGEABILITY_IPMI_PPI_INTERNAL_H_
> > diff --git
> >
> a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/M
> > anageabilityTransportKcs.c
> >
> b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/M
> > anageabilityTransportKcs.c
> > index 25d6e49886..91d3517bdb 100644
> > ---
> >
> a/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/M
> > anageabilityTransportKcs.c
> > +++ b/Features/ManageabilityPkg/Library/ManageabilityTransportKcsLib/D
> > +++ xe/ManageabilityTransportKcs.c
> > @@ -221,7 +221,7 @@ KcsTransportTransmitReceive (
> >     EFI_STATUS                           Status;
> >     MANAGEABILITY_IPMI_TRANSPORT_HEADER  *TransmitHeader;
> >
> > -  if (TransportToken == NULL || TransferToken == NULL) {
> > +  if ((TransportToken == NULL) || (TransferToken == NULL)) {
> >       DEBUG ((DEBUG_ERROR, "%a: Invalid transport token or transfer
> token.\n", __FUNCTION__));
> >       return;
> >     }
> > @@ -298,6 +298,7 @@ AcquireTransportSession (
> >       DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for
> MANAGEABILITY_TRANSPORT_KCS\n", __FUNCTION__));
> >       return EFI_OUT_OF_RESOURCES;
> >     }
> > +
> >     KcsTransportToken->Token.Transport = AllocateZeroPool (sizeof
> (MANAGEABILITY_TRANSPORT));
> >     if (KcsTransportToken->Token.Transport == NULL) {
> >       FreePool (KcsTransportToken);
> > @@ -346,9 +347,10 @@ GetTransportCapability (
> >     OUT MANAGEABILITY_TRANSPORT_CAPABILITY  *TransportCapability
> >     )
> >   {
> > -  if (TransportToken == NULL || TransportCapability == NULL) {
> > +  if ((TransportToken == NULL) || (TransportCapability == NULL)) {
> >       return EFI_INVALID_PARAMETER;
> >     }
> > +
> >     *TransportCapability = 0;
> >     return EFI_SUCCESS;
> >   }
> > diff --git
> > a/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
> > b/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
> > index c30132419d..40587a07af 100644
> > ---
> > a/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocol.c
> > +++
> b/Features/ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtoco
> > +++ l.c
> > @@ -100,12 +100,14 @@ DxeIpmiEntry (
> >       DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for
> IPMI protocol - %r\n", __FUNCTION__, Status));
> >       return Status;
> >     }
> > +
> >     Status = GetTransportCapability (mTransportToken,
> &TransportCapability);
> >     if (EFI_ERROR (Status)) {
> >       DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n",
> __FUNCTION__));
> >       return Status;
> >     }
> > -  TransportMaximumPayload =
> >
> MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(Transpor
> tCapabili
> > ty);
> > +
> > +  TransportMaximumPayload =
> > + MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY
> > + (TransportCapability);
> >     if (TransportMaximumPayload == (1 <<
> MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AV
> AILABLE)) {
> >       DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is
> undefined.\n", __FUNCTION__));
> >     } else {
> > diff --git
> > a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
> > b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
> > index 0dda6d2d47..0a914e513c 100644
> > --- a/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
> > +++ b/Features/ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpi.c
> > @@ -51,19 +51,19 @@ PeiIpmiSubmitCommand (
> >     IN OUT UINT32        *ResponseDataSize
> >     )
> >   {
> > -  EFI_STATUS            Status;
> > -  PEI_IPMI_PPI_INTERNAL *PeiIpmiPpiinternal;
> > -
> > -  PeiIpmiPpiinternal =
> > MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK(This);
> > -  Status = CommonIpmiSubmitCommand (
> > -             PeiIpmiPpiinternal->TransportToken,
> > -             NetFunction,
> > -             Command,
> > -             RequestData,
> > -             RequestDataSize,
> > -             ResponseData,
> > -             ResponseDataSize
> > -             );
> > +  EFI_STATUS             Status;
> > +  PEI_IPMI_PPI_INTERNAL  *PeiIpmiPpiinternal;
> > +
> > +  PeiIpmiPpiinternal = MANAGEABILITY_IPMI_PPI_INTERNAL_FROM_LINK
> (This);
> > +  Status             = CommonIpmiSubmitCommand (
> > +                         PeiIpmiPpiinternal->TransportToken,
> > +                         NetFunction,
> > +                         Command,
> > +                         RequestData,
> > +                         RequestDataSize,
> > +                         ResponseData,
> > +                         ResponseDataSize
> > +                         );
> >     return Status;
> >   }
> >
> > @@ -90,18 +90,19 @@ PeiIpmiEntry (
> >     MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS
> TransportAdditionalStatus;
> >     MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION
> HardwareInformation;
> >
> > -  PeiIpmiPpiinternal = (PEI_IPMI_PPI_INTERNAL *)AllocateZeroPool
> > (sizeof(PEI_IPMI_PPI_INTERNAL));
> > +  PeiIpmiPpiinternal = (PEI_IPMI_PPI_INTERNAL *)AllocateZeroPool
> > + (sizeof (PEI_IPMI_PPI_INTERNAL));
> >     if (PeiIpmiPpiinternal == NULL) {
> >       DEBUG ((DEBUG_ERROR, "%a: Not enough memory for
> PEI_IPMI_PPI_INTERNAL.\n", __FUNCTION__));
> >       return EFI_OUT_OF_RESOURCES;
> >     }
> > -  PpiDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)AllocateZeroPool
> > (sizeof(EFI_PEI_PPI_DESCRIPTOR));
> > +
> > +  PpiDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)AllocateZeroPool (sizeof
> > + (EFI_PEI_PPI_DESCRIPTOR));
> >     if (PpiDescriptor == NULL) {
> >       DEBUG ((DEBUG_ERROR, "%a: Not enough memory for
> EFI_PEI_PPI_DESCRIPTOR.\n", __FUNCTION__));
> >       return EFI_OUT_OF_RESOURCES;
> >     }
> >
> > -  PeiIpmiPpiinternal->Signature =
> > MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE;
> > +  PeiIpmiPpiinternal->Signature                    =
> MANAGEABILITY_IPMI_PPI_INTERNAL_SIGNATURE;
> >     PeiIpmiPpiinternal->PeiIpmiPpi.IpmiSubmitCommand =
> > PeiIpmiSubmitCommand;
> >
> >     PpiDescriptor->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI |
> > EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
> > @@ -116,18 +117,19 @@ PeiIpmiEntry (
> >       DEBUG ((DEBUG_ERROR, "%a: Failed to acquire transport interface for
> IPMI protocol - %r\n", __FUNCTION__, Status));
> >       return Status;
> >     }
> > +
> >     Status = GetTransportCapability (PeiIpmiPpiinternal->TransportToken,
> &PeiIpmiPpiinternal->TransportCapability);
> >     if (EFI_ERROR (Status)) {
> >       DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n",
> __FUNCTION__));
> >       return Status;
> >     }
> >
> > -  PeiIpmiPpiinternal->TransportMaximumPayload =
> >
> MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(PeiIpmiP
> piinterna
> > l->TransportCapability);
> > +  PeiIpmiPpiinternal->TransportMaximumPayload =
> > + MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY
> > + (PeiIpmiPpiinternal->TransportCapability);
> >     if (PeiIpmiPpiinternal->TransportMaximumPayload  == (1 <<
> MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AV
> AILABLE)) {
> > -    DEBUG((DEBUG_INFO, "%a: Transport interface maximum payload is
> undefined.\n", __FUNCTION__));
> > +    DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is
> > + undefined.\n", __FUNCTION__));
> >     } else {
> >       PeiIpmiPpiinternal->TransportMaximumPayload -= 1;
> > -    DEBUG((DEBUG_INFO, "%a: Transport interface for IPMI protocol has
> maximum payload 0x%x.\n", __FUNCTION__, PeiIpmiPpiinternal-
> >TransportMaximumPayload));
> > +    DEBUG ((DEBUG_INFO, "%a: Transport interface for IPMI protocol
> > + has maximum payload 0x%x.\n", __FUNCTION__,
> > + PeiIpmiPpiinternal->TransportMaximumPayload));
> >     }
> >
> >     TransportName = HelperManageabilitySpecName
> > (PeiIpmiPpiinternal->TransportToken->Transport->ManageabilityTransport
> > Specification); diff --git
> > a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
> >
> b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
> > index 86dee2fa24..41b9a10453 100644
> > ---
> > a/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocol.c
> > +++
> b/Features/ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtoco
> > +++ l.c
> > @@ -107,12 +107,13 @@ SmmIpmiEntry (
> >       DEBUG ((DEBUG_ERROR, "%a: Failed to GetTransportCapability().\n",
> __FUNCTION__));
> >       return Status;
> >     }
> > -  TransportMaximumPayload =
> >
> MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY(Transpor
> tCapabili
> > ty);
> > +
> > +  TransportMaximumPayload =
> > + MANAGEABILITY_TRANSPORT_PAYLOAD_SIZE_FROM_CAPABILITY
> > + (TransportCapability);
> >     if (TransportMaximumPayload == (1 <<
> MANAGEABILITY_TRANSPORT_CAPABILITY_MAXIMUM_PAYLOAD_NOT_AV
> AILABLE)) {
> > -    DEBUG((DEBUG_INFO, "%a: Transport interface maximum payload is
> undefined.\n", __FUNCTION__));
> > +    DEBUG ((DEBUG_INFO, "%a: Transport interface maximum payload is
> > + undefined.\n", __FUNCTION__));
> >     } else {
> >       TransportMaximumPayload -= 1;
> > -    DEBUG((DEBUG_INFO, "%a: Transport interface for IPMI protocol has
> maximum payload 0x%x.\n", __FUNCTION__, TransportMaximumPayload));
> > +    DEBUG ((DEBUG_INFO, "%a: Transport interface for IPMI protocol
> > + has maximum payload 0x%x.\n", __FUNCTION__,
> > + TransportMaximumPayload));
> >     }
> >
> >     mTransportName = HelperManageabilitySpecName
> > (mTransportToken->Transport->ManageabilityTransportSpecification);

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [edk2-platforms][PATCH 13/14] ManageabilityPkg: Relocate Manageability.dsc
  2023-04-10 17:27   ` Tinh Nguyen
@ 2023-04-11  5:55     ` Chang, Abner
  0 siblings, 0 replies; 22+ messages in thread
From: Chang, Abner @ 2023-04-11  5:55 UTC (permalink / raw)
  To: Tinh Nguyen, devel@edk2.groups.io
  Cc: Isaac Oram, Attar, AbdulLateef (Abdul Lateef), Nickle Wang,
	Igor Kulchytskyy

[AMD Official Use Only - General]



> -----Original Message-----
> From: Tinh Nguyen <tinhnguyen@amperemail.onmicrosoft.com>
> Sent: Tuesday, April 11, 2023 1:27 AM
> To: Chang, Abner <Abner.Chang@amd.com>; devel@edk2.groups.io
> Cc: Isaac Oram <isaac.w.oram@intel.com>; Attar, AbdulLateef (Abdul Lateef)
> <AbdulLateef.Attar@amd.com>; Nickle Wang <nicklew@nvidia.com>; Igor
> Kulchytskyy <igork@ami.com>
> Subject: Re: [edk2-platforms][PATCH 13/14] ManageabilityPkg: Relocate
> Manageability.dsc
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> Hi Abner,
> 
> As someone mentioned before, you should move this library for arm/arm64
> to Manageability.dsc
Ah yes, I will.
> 
> btw, the files that are included in dsc should have the extension dsc.inc.
I personally don’t like to have ".inc" for the included metafiles, that is annoying when I do the search specifically to DSC files.
I don’t see having file extension ".inc" to the included metafiles is a rule that mentioned in the edk2 specs. The example of included metafile in DCS we can see in the edk2 DSC spec is also named without ".inc".
So I would rather just keep it as Manageability.dsc without ".inc' or name it as Manageability.inc.dsc.

Thanks
Abner

> 
> Regards,
> 
> Tinh
> 
> On 4/3/2023 10:04 PM, abner.chang@amd.com wrote:
> > [EXTERNAL EMAIL NOTICE: This email originated from an external sender.
> > Please be mindful of safe email handling and proprietary information
> > protection practices.]
> >
> >
> > From: abnchang <abnchang@amd.com>
> >
> > Relocate Manageability.dsc to just under \Include folder.
> >
> > Signed-off-by: Abner Chang <abner.chang@amd.com>
> > Cc: Isaac Oram <isaac.w.oram@intel.com>
> > Cc: Abdul Lateef Attar <abdattar@amd.com>
> > Cc: Nickle Wang <nicklew@nvidia.com>
> > Cc: Igor Kulchytskyy <igork@ami.com>
> > Cc: Tinh Nguyen <tinhnguyen@amperemail.onmicrosoft.com>
> > ---
> >   Features/ManageabilityPkg/Include/{Dsc => }/Manageability.dsc | 0
> >   Features/ManageabilityPkg/ManageabilityPkg.dsc                | 2 +-
> >   2 files changed, 1 insertion(+), 1 deletion(-)
> >   rename Features/ManageabilityPkg/Include/{Dsc => }/Manageability.dsc
> > (100%)
> >
> > diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
> > b/Features/ManageabilityPkg/Include/Manageability.dsc
> > similarity index 100%
> > rename from Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
> > rename to Features/ManageabilityPkg/Include/Manageability.dsc
> > diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc
> > b/Features/ManageabilityPkg/ManageabilityPkg.dsc
> > index 41a8957954..a0712d1c0a 100644
> > --- a/Features/ManageabilityPkg/ManageabilityPkg.dsc
> > +++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc
> > @@ -53,4 +53,4 @@
> >   [LibraryClasses]
> >
> > ManageabilityTransportLib|ManageabilityPkg/Library/BaseManageabilityTr
> > ansportNullLib/BaseManageabilityTransportNull.inf
> >
> > -!include Include/Dsc/Manageability.dsc
> > +!include Include/Manageability.dsc
> > --
> > 2.37.1.windows.1
> >

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [edk2-platforms][PATCH 05/14] ManageabilityPkg: Add PldmProtocolLib
  2023-04-03 15:04 ` [edk2-platforms][PATCH 05/14] ManageabilityPkg: Add PldmProtocolLib Chang, Abner
@ 2023-04-11 13:41   ` Nickle Wang
  0 siblings, 0 replies; 22+ messages in thread
From: Nickle Wang @ 2023-04-11 13:41 UTC (permalink / raw)
  To: abner.chang@amd.com, devel@edk2.groups.io
  Cc: Isaac Oram, Abdul Lateef Attar, Igor Kulchytskyy

Hi Abner,

It seems to me that some of protocol GUIDs are defined in [Guids] section instead of [Protocol] section in Features/ManageabilityPkg/ManageabilityPkg.dec file. Could you please address this together?

Thanks,
Nickle

> -----Original Message-----
> From: abner.chang@amd.com <abner.chang@amd.com>
> Sent: Monday, April 3, 2023 11:05 PM
> To: devel@edk2.groups.io
> Cc: Isaac Oram <isaac.w.oram@intel.com>; Abdul Lateef Attar
> <abdattar@amd.com>; Nickle Wang <nicklew@nvidia.com>; Igor Kulchytskyy
> <igork@ami.com>
> Subject: [edk2-platforms][PATCH 05/14] ManageabilityPkg: Add
> PldmProtocolLib
> 
> External email: Use caution opening links or attachments
> 
> 
> From: Abner Chang <abner.chang@amd.com>
> 
> PldmProtocolLib provides the library
> function to PLDM protocol.
> 
> Signed-off-by: Abner Chang <abner.chang@amd.com>
> Cc: Isaac Oram <isaac.w.oram@intel.com>
> Cc: Abdul Lateef Attar <abdattar@amd.com>
> Cc: Nickle Wang <nicklew@nvidia.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
>  .../ManageabilityPkg/ManageabilityPkg.dec     |  3 +
>  .../Include/Dsc/Manageability.dsc             |  3 +
>  .../ManageabilityPkg/ManageabilityPkg.dsc     |  1 +
>  .../Dxe/PldmProtocolLib.inf                   | 42 +++++++++
>  .../Include/Library/BasePldmProtocolLib.h     | 41 +++++++++
>  .../Include/Protocol/PldmProtocol.h           | 87 +++++++++++++++++++
>  .../PldmProtocolLibrary/Dxe/PldmProtocolLib.c | 87 +++++++++++++++++++
>  .../Dxe/PldmProtocolLib.uni                   | 18 ++++
>  8 files changed, 282 insertions(+)
>  create mode 100644
> Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.i
> nf
>  create mode 100644
> Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
>  create mode 100644
> Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
>  create mode 100644
> Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.c
>  create mode 100644
> Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.
> uni
> 
> diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dec
> b/Features/ManageabilityPkg/ManageabilityPkg.dec
> index 9a930d3e4b..1e9245c8dc 100644
> --- a/Features/ManageabilityPkg/ManageabilityPkg.dec
> +++ b/Features/ManageabilityPkg/ManageabilityPkg.dec
> @@ -48,3 +48,6 @@
>    gManageabilityProtocolMctpGuid    = { 0x76FED8F1, 0x0BE5, 0x4269, { 0xA3,
> 0x1A, 0x38, 0x0F, 0x54, 0xF1, 0xA1, 0x8A } }
>    # Manageability Protocol PLDM
>    gManageabilityProtocolPldmGuid    = { 0x3958090D, 0x69DD, 0x4868, { 0x9C,
> 0x41, 0xC9, 0xAC, 0x31, 0xB5, 0x25, 0xC5 } }
> +
> +[Protocols]
> +  gEdkiiPldmProtocolGuid                = { 0x60997616, 0xDB70, 0x4B5F, { 0x86,
> 0xA4, 0x09, 0x58, 0xA3, 0x71, 0x47, 0xB4 } }
> diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
> b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
> index 0d868fdf4a..59549eb39a 100644
> --- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
> +++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc
> @@ -8,6 +8,9 @@
>  [LibraryClasses]
> 
> ManageabilityTransportHelperLib|ManageabilityPkg/Library/BaseManageability
> TransportHelperLib/BaseManageabilityTransportHelper.inf
> 
> +[LibraryClasses.common.DXE_DRIVER]
> +
> +PldmProtocolLib|ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmPr
> +otocolLib.inf
> +
>  [LibraryClasses.ARM, LibraryClasses.AARCH64]
>    #
>    # This library provides the instrinsic functions generated by a given compiler.
> diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dsc
> b/Features/ManageabilityPkg/ManageabilityPkg.dsc
> index 6a083385fd..412029ef6c 100644
> --- a/Features/ManageabilityPkg/ManageabilityPkg.dsc
> +++ b/Features/ManageabilityPkg/ManageabilityPkg.dsc
> @@ -37,6 +37,7 @@
> 
>  [Components]
> 
> ManageabilityPkg/Library/ManageabilityTransportKcsLib/Dxe/DxeManageability
> TransportKcs.inf
> +  ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLib.inf
> 
>  [LibraryClasses]
> 
> ManageabilityTransportLib|ManageabilityPkg/Library/BaseManageabilityTransp
> ortNullLib/BaseManageabilityTransportNull.inf
> diff --git
> a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLi
> b.inf
> b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLi
> b.inf
> new file mode 100644
> index 0000000000..1233d76726
> --- /dev/null
> +++ b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProt
> +++ ocolLib.inf
> @@ -0,0 +1,42 @@
> +## @file
> +#  Instance of PLDM Protocol Library in DXE phase.
> +#
> +#  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights
> +reserved.<BR> # #  SPDX-License-Identifier: BSD-2-Clause-Patent # # ##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010005
> +  BASE_NAME                      = PldmProtocolLib
> +  MODULE_UNI_FILE                = PldmProtocolLib.uni
> +  FILE_GUID                      = 5B1173E8-6A5A-468B-BDA4-02303530C55C
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = PldmProtocolLib|DXE_RUNTIME_DRIVER
> DXE_DRIVER DXE_CORE UEFI_DRIVER UEFI_APPLICATION
> +
> +#
> +#  VALID_ARCHITECTURES          = IA32 X64
> +#
> +
> +[Sources]
> +  PldmProtocolLib.c
> +
> +[Packages]
> +  ManageabilityPkg/ManageabilityPkg.dec
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +
> +[LibraryClasses]
> +  DebugLib
> +  ManageabilityTransportHelperLib
> +  UefiBootServicesTableLib
> +
> +[Guids]
> +  gManageabilityProtocolPldmGuid
> +
> +[Protocols]
> +  gEdkiiPldmProtocolGuid          ## ALWAYS_CONSUMES
> +
> diff --git a/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
> b/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
> new file mode 100644
> index 0000000000..5523ac3a4d
> --- /dev/null
> +++ b/Features/ManageabilityPkg/Include/Library/BasePldmProtocolLib.h
> @@ -0,0 +1,41 @@
> +/** @file
> +
> +  This file defines EDKII Pldm Protocol library and functions.
> +
> +  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights
> +reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent **/
> +
> +#ifndef EDKII_PLDM_PROTOCOL_LIB_H_
> +#define EDKII_PLDM_PROTOCOL_LIB_H_
> +
> +/**
> +  This service enables submitting commands via EDKII PLDM protocol.
> +
> +  @param[in]         PldmType          PLDM message type.
> +  @param[in]         Command           PLDM Command of PLDM message type.
> +  @param[in]         RequestData       Command Request Data.
> +  @param[in]         RequestDataSize   Size of Command Request Data.
> +  @param[out]        ResponseData      Command Response Data. The
> completion code is the first byte of response data.
> +  @param[in, out]    ResponseDataSize  Size of Command Response Data.
> +
> +  @retval EFI_SUCCESS            PLDM message was successfully sent to transport
> interface
> +                                 and a response was successfully received.
> +  @retval EFI_NOT_FOUND          Transport interface is not found.
> +  @retval EFI_NOT_READY          Transport interface is not ready for PLDM
> message.
> +  @retval EFI_DEVICE_ERROR       Transport interface has an hardware error.
> +  @retval EFI_TIMEOUT            Send PLDM message got a timeout.
> +  @retval EFI_UNSUPPORTED        PLDM message is unsupported.
> +  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource
> or data size error.
> +**/
> +EFI_STATUS
> +PldmSubmitCommand (
> +  IN     UINT8   PldmType,
> +  IN     UINT8   Command,
> +  IN     UINT8   *RequestData,
> +  IN     UINT32  RequestDataSize,
> +  OUT UINT8      *ResponseData,
> +  IN OUT UINT32  *ResponseDataSize
> +  );
> +
> +#endif
> diff --git a/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
> b/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
> new file mode 100644
> index 0000000000..651997e1ad
> --- /dev/null
> +++ b/Features/ManageabilityPkg/Include/Protocol/PldmProtocol.h
> @@ -0,0 +1,87 @@
> +/** @file
> +  Protocol of EDKII PLDM Protocol.
> +
> +  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef EDKII_PLDM_PROTOCOL_H_
> +#define EDKII_PLDM_PROTOCOL_H_
> +
> +#include <IndustryStandard/Pldm.h>
> +
> +typedef struct  _EDKII_PLDM_PROTOCOL EDKII_PLDM_PROTOCOL;
> +
> +#define EDKII_PLDM_PROTOCOL_GUID \
> +  { \
> +    0x60997616, 0xDB70, 0x4B5F, 0x86, 0xA4, 0x09, 0x58, 0xA3, 0x71,
> +0x47, 0xB4 \
> +  }
> +
> +#define EDKII_PLDM_PROTOCOL_VERSION_MAJOR  1 #define
> +EDKII_PLDM_PROTOCOL_VERSION_MINOR  0
> +#define EDKII_PLDM_PROTOCOL_VERSION
> ((EDKII_PLDM_PROTOCOL_VERSION_MAJOR << 8) |\
> +
> +EDKII_PLDM_PROTOCOL_VERSION_MINOR)
> +
> +/**
> +  This service enables submitting commands via EDKII PLDM protocol.
> +
> +  @param[in]         This              EDKII_PLDM_PROTOCOL instance.
> +  @param[in]         PldmType          PLDM message type.
> +  @param[in]         Command           PLDM Command of PLDM message type.
> +  @param[in]         RequestData       Command Request Data.
> +  @param[in]         RequestDataSize   Size of Command Request Data.
> +  @param[out]        ResponseData      Command Response Data. The
> completion code is the first byte of response data.
> +  @param[in, out]    ResponseDataSize  Size of Command Response Data.
> +
> +  @retval EFI_SUCCESS            The command byte stream was successfully
> submit to the device and a response was successfully received.
> +  @retval EFI_NOT_FOUND          The command was not successfully sent to the
> device or a response was not successfully received from the device.
> +  @retval EFI_NOT_READY          PLDM transport interface is not ready for PLDM
> command access.
> +  @retval EFI_DEVICE_ERROR       PLDM transport interface Device hardware
> error.
> +  @retval EFI_TIMEOUT            The command time out.
> +  @retval EFI_UNSUPPORTED        The command was not successfully sent to
> the device.
> +  @retval EFI_OUT_OF_RESOURCES   The resource allcation is out of resource
> or data size error.
> +  @retval EFI_INVALID_PARAMETER  Both RequestData and ResponseData are
> +NULL **/ typedef EFI_STATUS (EFIAPI *PLDM_SUBMIT_COMMAND)(
> +  IN     EDKII_PLDM_PROTOCOL  *This,
> +  IN     UINT8                PldmType,
> +  IN     UINT8                Command,
> +  IN     UINT8                *RequestData,
> +  IN     UINT32               RequestDataSize,
> +  OUT    UINT8                *ResponseData,
> +  IN OUT UINT32               *ResponseDataSize
> +  );
> +
> +//
> +// EDKII_PLDM_PROTOCOL Version 1.0
> +//
> +typedef struct {
> +  PLDM_SUBMIT_COMMAND    PldmSubmitCommand;
> +} EDKII_PLDM_PROTOCOL_V1_0;
> +
> +///
> +/// Definitions of EDKII_PLDM_PROTOCOL.
> +/// This is a union that can accommodate the new functionalities
> +defined /// in PLDM Base specification in the future.
> +/// The new added function must has its own EDKII_PLDM_PROTOCOL ///
> +structure with the incremental version number.
> +///   e.g., EDKII_PLDM_PROTOCOL_V1_1.
> +///
> +/// The new function must be added base on the last version of ///
> +EDKII_PLDM_PROTOCOL to keep the backward compatability.
> +///
> +typedef union {
> +  EDKII_PLDM_PROTOCOL_V1_0    *Version1_0;
> +} EDKII_PLDM_PROTOCOL_FUNCTION;
> +
> +struct _EDKII_PLDM_PROTOCOL {
> +  UINT16                          ProtocolVersion;
> +  EDKII_PLDM_PROTOCOL_FUNCTION    Functions;
> +};
> +
> +extern EFI_GUID  gEdkiiPldmProtocolGuid;
> +
> +#endif // EDKII_PLDM_PROTOCOL_H_
> diff --git
> a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLi
> b.c
> b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLi
> b.c
> new file mode 100644
> index 0000000000..ac6225ed92
> --- /dev/null
> +++ b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProt
> +++ ocolLib.c
> @@ -0,0 +1,87 @@
> +/** @file
> +  Instance of EDKII PLDM Protocol Library in DXE phase
> +
> +  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiDxe.h>
> +#include <Protocol/PldmProtocol.h>
> +#include <Library/DebugLib.h>
> +#include <Library/ManageabilityTransportHelperLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +EDKII_PLDM_PROTOCOL  *mEdkiiPldmProtocol = NULL;
> +
> +/**
> +  This service enables submitting commands via EDKII PLDM protocol.
> +
> +  @param[in]         PldmType          PLDM message type.
> +  @param[in]         Command           PLDM Command of PLDM message type.
> +  @param[in]         RequestData       Command Request Data.
> +  @param[in]         RequestDataSize   Size of Command Request Data.
> +  @param[out]        ResponseData      Command Response Data. The
> completion code is the first byte of response data.
> +  @param[in, out]    ResponseDataSize  Size of Command Response Data.
> +
> +  @retval EFI_SUCCESS            PLDM message was successfully sent to transport
> interface
> +                                 and a response was successfully received.
> +  @retval EFI_NOT_FOUND          Transport interface is not found.
> +  @retval EFI_NOT_READY          Transport interface is not ready for PLDM
> message.
> +  @retval EFI_DEVICE_ERROR       Transport interface has an hardware error.
> +  @retval EFI_TIMEOUT            Send PLDM message got a timeout.
> +  @retval EFI_UNSUPPORTED        PLDM message is unsupported.
> +  @retval EFI_OUT_OF_RESOURCES   The resource allocation is out of resource
> or data size error.
> +**/
> +EFI_STATUS
> +PldmSubmitCommand (
> +  IN     UINT8   PldmType,
> +  IN     UINT8   Command,
> +  IN     UINT8   *RequestData,
> +  IN     UINT32  RequestDataSize,
> +  OUT UINT8      *ResponseData,
> +  IN OUT UINT32  *ResponseDataSize
> +  )
> +{
> +  EFI_STATUS  Status;
> +
> +  if (mEdkiiPldmProtocol == NULL) {
> +    Status = gBS->LocateProtocol (
> +                    &gEdkiiPldmProtocolGuid,
> +                    NULL,
> +                    (VOID **)&mEdkiiPldmProtocol
> +                    );
> +    if (EFI_ERROR (Status)) {
> +      //
> +      // Dxe PLDM Protocol is not installed. So, PLDM device is not present.
> +      //
> +      DEBUG ((DEBUG_ERROR, "%a: EDKII PLDM protocol is not found - %r\n",
> Status));
> +      return EFI_NOT_FOUND;
> +    }
> +  }
> +
> +  DEBUG ((DEBUG_INFO, "%a: PLDM Type: 0x%x, Command: 0x%x\n",
> + __FUNCTION__, PldmType, Command));  if ((RequestData != NULL) &&
> (RequestDataSize != 0)) {
> +    HelperManageabilityDebugPrint ((VOID *)RequestData,
> + RequestDataSize, "PLDM PLDM application layer Type/Command specific
> + request payload\n");  }
> +
> +  Status = mEdkiiPldmProtocol->Functions.Version1_0->PldmSubmitCommand (
> +                                                       mEdkiiPldmProtocol,
> +                                                       PldmType,
> +                                                       Command,
> +                                                       RequestData,
> +                                                       RequestDataSize,
> +                                                       ResponseData,
> +                                                       ResponseDataSize
> +                                                       );  if
> + (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_INFO, "Fails to send PLDM package - %r\n", Status));
> +    return Status;
> +  }
> +
> +  if ((ResponseData != NULL) && (*ResponseDataSize != 0)) {
> +    HelperManageabilityDebugPrint ((VOID *)ResponseData,
> + *ResponseDataSize, "PLDM application layer response payload\n");  }
> +
> +  return Status;
> +}
> diff --git
> a/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLi
> b.uni
> b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProtocolLi
> b.uni
> new file mode 100644
> index 0000000000..b58a2ac146
> --- /dev/null
> +++ b/Features/ManageabilityPkg/Library/PldmProtocolLibrary/Dxe/PldmProt
> +++ ocolLib.uni
> @@ -0,0 +1,18 @@
> +// /** @file
> +// Instance of PLDM Protocol Library in DXE phase.
> +//
> +//  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights
> +reserved.<BR> // //  SPDX-License-Identifier: BSD-2-Clause-Patent // //
> +**/
> +
> +#string STR_MODULE_ABSTRACT
> +#language en-US
> +"Instance of PLDM Protocol Library in DXE phase."
> +
> +#string STR_MODULE_DESCRIPTION
> +#language en-US
> +"Instance of PLDM Protocol Library in DXE phase."
> +
> +
> --
> 2.37.1.windows.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2023-04-11 13:41 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-03 15:04 [edk2-platforms][PATCH 00/14] ManageabilityPkg part II Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 01/14] ManageabilityPkg: Add more helper functions Chang, Abner
2023-04-10 17:23   ` [edk2-devel] " Tinh Nguyen
2023-04-11  5:29     ` Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 02/14] ManageabilityPkg: Support Maximum Transfer Unit Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 03/14] ManageabilityPkg: Fix Uncrustify errors Chang, Abner
2023-04-10 17:25   ` [edk2-devel] " Tinh Nguyen
2023-04-11  5:31     ` Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 04/14] ManageabilityPkg: Add HeaderSize and TrailerSize Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 05/14] ManageabilityPkg: Add PldmProtocolLib Chang, Abner
2023-04-11 13:41   ` Nickle Wang
2023-04-03 15:04 ` [edk2-platforms][PATCH 06/14] ManageabilityPkg: Add PldmSmbiosTransferDxe driver Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 07/14] ManageabilityPkg/KCS: KCS transport interface Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 08/14] ManageabilityPkg: Add definitions of MCTP Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 09/14] ManageabilityPkg/MctpProtocol: Add MctpProtocol Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 10/14] ManageabilityPkg: Add MCTP transport interface Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 11/14] ManageabilityPkg/PldmProtocol: Add PLDM protocol Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 12/14] ManageabilityPkg: Add Manageability PCDs Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 13/14] ManageabilityPkg: Relocate Manageability.dsc Chang, Abner
2023-04-10 17:27   ` Tinh Nguyen
2023-04-11  5:55     ` Chang, Abner
2023-04-03 15:04 ` [edk2-platforms][PATCH 14/14] ManageabilityPkg: Add Manageability FDFs Chang, Abner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox