From 150339f262fc2c54a27dc2aae4a4bbe540379a86 Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Wed, 24 Jun 2026 13:54:20 +0100 Subject: [PATCH] ManageabilityPkg: SsifWriteRequest loop refactoring A multi-part request can consist of a Start, zero-to-several Middle, and an End packet. For what I can only assume was an attempt to confuse the enemy, SsifWriteRequest () handled this by setting up three separate loops. Rewrite this as a single loop in order to reduce confusion for revewers and compilers. Signed-off-by: Leif Lindholm --- .../SsifCommon.c | 58 ++++++------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c index 6a9f62ac93..e82eb545ce 100644 --- a/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c +++ b/ManageabilityPkg/Library/ManageabilityTransportSsifLib/SsifCommon.c @@ -58,7 +58,7 @@ SsifWriteRequest ( { EFI_STATUS Status; BOOLEAN IsMultiPartWrite; - UINTN Index; + UINTN BytesLeft; UINTN MiddleCount; UINT8 SsifCmd; UINTN WriteLen; @@ -98,58 +98,34 @@ SsifWriteRequest ( SsifCmd = IPMI_SSIF_SMBUS_CMD_SINGLE_PART_WRITE; } - SmBusWriteBlock ( - SMBUS_LIB_ADDRESS ( - IPMI_SSIF_BMC_SLAVE_ADDR_7BIT, - SsifCmd, - WriteLen, - mPecSupport - ), - RequestData, - &Status - ); - - if ( EFI_ERROR (Status) - || !IsMultiPartWrite) + for (BytesLeft = RequestDataSize, Status = EFI_SUCCESS; + (BytesLeft > 0) && !EFI_ERROR (Status); + BytesLeft -= MIN (BytesLeft, IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES)) { - goto Exit; - } + // Check for SsifCmd transitions if not the first packet + if (BytesLeft < RequestDataSize) { + // Is this the End packet? + if (BytesLeft <= IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES) { + WriteLen = BytesLeft; + SsifCmd = IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_END; + } else if (SsifCmd == IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_START) { + // Did we just write the Start packet of an operation with Middles? + SsifCmd = IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_MIDDLE; + } + } - for (Index = 1; Index <= MiddleCount; Index++) { SmBusWriteBlock ( SMBUS_LIB_ADDRESS ( IPMI_SSIF_BMC_SLAVE_ADDR_7BIT, - IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_MIDDLE, + SsifCmd, WriteLen, mPecSupport ), - &RequestData[Index * IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES], + &RequestData[RequestDataSize - BytesLeft], &Status ); - - if (EFI_ERROR (Status)) { - goto Exit; - } } - // - // Remain RequestData for END - // - WriteLen = RequestDataSize - (MiddleCount + 1) * IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES; - ASSERT (WriteLen > 0); - SmBusWriteBlock ( - SMBUS_LIB_ADDRESS ( - IPMI_SSIF_BMC_SLAVE_ADDR_7BIT, - IPMI_SSIF_SMBUS_CMD_MULTI_PART_WRITE_END, - WriteLen, - mPecSupport - ), - &RequestData[(MiddleCount + 1) * IPMI_SSIF_MAXIMUM_PACKET_SIZE_IN_BYTES], - &Status - ); - -Exit: - return Status; }