MdeModulePkg/SdMmcPciHcDxe: Enhance driver traces
authorAlbecki, Mateusz <>
Thu, 27 Feb 2020 17:25:22 +0000 (01:25 +0800)
committermergify[bot] <37929162+mergify[bot]>
Thu, 5 Mar 2020 01:51:59 +0000 (01:51 +0000)
To allow for easier debug of failing commands we
have added a capability to print TRB and command
packet when we start execution of the TRB(on
DEBUG_VERBOSE level) and when the TRB failed to
execute correctly(on DEBUG_ERROR level). Additionally
we will also print error interrupt status and interrupt
status register on failed SD command.

Cc: Hao A Wu <>
Cc: Marcin Wojtas <>
Cc: Zhichao Gao <>
Cc: Liming Gao <>
Signed-off-by: Mateusz Albecki <>
Tested-by: Hao A Wu <>
Reviewed-by: Hao A Wu <>

index 7971196..d6294eb 100644 (file)
@@ -1647,6 +1647,82 @@ BuildAdmaDescTable (
   return EFI_SUCCESS;\r
+  Prints the contents of the command packet to the debug port.\r
+  @param[in] DebugLevel  Debug level at which the packet should be printed.\r
+  @param[in] Packet      Pointer to packet to print.\r
+SdMmcPrintPacket (\r
+  IN UINT32                               DebugLevel,\r
+  )\r
+  if (Packet == NULL) {\r
+    return;\r
+  }\r
+  DEBUG ((DebugLevel, "Printing EFI_SD_MMC_PASS_THRU_COMMAND_PACKET\n"));\r
+  if (Packet->SdMmcCmdBlk != NULL) {\r
+    DEBUG ((DebugLevel, "Command index: %d, argument: %X\n", Packet->SdMmcCmdBlk->CommandIndex, Packet->SdMmcCmdBlk->CommandArgument));\r
+    DEBUG ((DebugLevel, "Command type: %d, response type: %d\n", Packet->SdMmcCmdBlk->CommandType, Packet->SdMmcCmdBlk->ResponseType));\r
+  }\r
+  if (Packet->SdMmcStatusBlk != NULL) {\r
+    DEBUG ((DebugLevel, "Response 0: %X, 1: %X, 2: %X, 3: %X\n",\r
+                           Packet->SdMmcStatusBlk->Resp0,\r
+                           Packet->SdMmcStatusBlk->Resp1,\r
+                           Packet->SdMmcStatusBlk->Resp2,\r
+                           Packet->SdMmcStatusBlk->Resp3\r
+                           ));\r
+  }\r
+  DEBUG ((DebugLevel, "Timeout: %ld\n", Packet->Timeout));\r
+  DEBUG ((DebugLevel, "InDataBuffer: %p\n", Packet->InDataBuffer));\r
+  DEBUG ((DebugLevel, "OutDataBuffer: %p\n", Packet->OutDataBuffer));\r
+  DEBUG ((DebugLevel, "InTransferLength: %d\n", Packet->InTransferLength));\r
+  DEBUG ((DebugLevel, "OutTransferLength: %d\n", Packet->OutTransferLength));\r
+  DEBUG ((DebugLevel, "TransactionStatus: %r\n", Packet->TransactionStatus));\r
+  Prints the contents of the TRB to the debug port.\r
+  @param[in] DebugLevel  Debug level at which the TRB should be printed.\r
+  @param[in] Trb         Pointer to the TRB structure.\r
+SdMmcPrintTrb (\r
+  IN UINT32         DebugLevel,\r
+  IN SD_MMC_HC_TRB  *Trb\r
+  )\r
+  if (Trb == NULL) {\r
+    return;\r
+  }\r
+  DEBUG ((DebugLevel, "Printing SD_MMC_HC_TRB\n"));\r
+  DEBUG ((DebugLevel, "Slot: %d\n", Trb->Slot));\r
+  DEBUG ((DebugLevel, "BlockSize: %d\n", Trb->BlockSize));\r
+  DEBUG ((DebugLevel, "Data: %p\n", Trb->Data));\r
+  DEBUG ((DebugLevel, "DataLen: %d\n", Trb->DataLen));\r
+  DEBUG ((DebugLevel, "Read: %d\n", Trb->Read));\r
+  DEBUG ((DebugLevel, "DataPhy: %lX\n", Trb->DataPhy));\r
+  DEBUG ((DebugLevel, "DataMap: %p\n", Trb->DataMap));\r
+  DEBUG ((DebugLevel, "Mode: %d\n", Trb->Mode));\r
+  DEBUG ((DebugLevel, "AdmaLengthMode: %d\n", Trb->AdmaLengthMode));\r
+  DEBUG ((DebugLevel, "Event: %p\n", Trb->Event));\r
+  DEBUG ((DebugLevel, "Started: %d\n", Trb->Started));\r
+  DEBUG ((DebugLevel, "Timeout: %ld\n", Trb->Timeout));\r
+  DEBUG ((DebugLevel, "Retries: %d\n", Trb->Retries));\r
+  DEBUG ((DebugLevel, "Adma32Desc: %p\n", Trb->Adma32Desc));\r
+  DEBUG ((DebugLevel, "Adma64V3Desc: %p\n", Trb->Adma64V3Desc));\r
+  DEBUG ((DebugLevel, "Adma64V4Desc: %p\n", Trb->Adma64V4Desc));\r
+  DEBUG ((DebugLevel, "AdmaMap: %p\n", Trb->AdmaMap));\r
+  DEBUG ((DebugLevel, "AdmaPages: %X\n", Trb->AdmaPages));\r
+  SdMmcPrintPacket (DebugLevel, Trb->Packet);\r
   Create a new TRB for the SD/MMC cmd request.\r
@@ -2238,6 +2314,10 @@ SdMmcCheckAndRecoverErrors (
     return Status;\r
+  DEBUG ((DEBUG_ERROR, "Error reported by SDHCI\n"));\r
+  DEBUG ((DEBUG_ERROR, "Interrupt status = %X\n", IntStatus));\r
+  DEBUG ((DEBUG_ERROR, "Error interrupt status = %X\n", ErrIntStatus));\r
   // If the data timeout error is reported\r
   // but data transfer is signaled as completed we\r
@@ -2441,6 +2521,13 @@ Done:
   if (Status != EFI_NOT_READY) {\r
     SdMmcHcLedOnOff (Private->PciIo, Trb->Slot, FALSE);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_ERROR, "TRB failed with %r\n", Status));\r
+      SdMmcPrintTrb (DEBUG_ERROR, Trb);\r
+    } else {\r
+      DEBUG ((DEBUG_VERBOSE, "TRB success\n"));\r
+      SdMmcPrintTrb (DEBUG_VERBOSE, Trb);\r
+    }\r
   return Status;\r