]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
MdeModulePkg/AtaAtapiPassThru: Trace ATA packets
[mirror_edk2.git] / MdeModulePkg / Bus / Ata / AtaAtapiPassThru / AhciMode.c
index 47275a851aa9132d79b282de68184bb597e9f0c2..e99a812a44e384c44cf1c18d2f7a82be7ea2cb50 100644 (file)
@@ -846,6 +846,54 @@ AhciWaitUntilFisReceived (
   return EFI_TIMEOUT;\r
 }\r
 \r
+/**\r
+  Prints contents of the ATA command block into the debug port.\r
+\r
+  @param[in] AtaCommandBlock  AtaCommandBlock to print.\r
+  @param[in] DebugLevel       Debug level on which to print.\r
+**/\r
+VOID\r
+AhciPrintCommandBlock (\r
+  IN EFI_ATA_COMMAND_BLOCK  *AtaCommandBlock,\r
+  IN UINT32                 DebugLevel\r
+  )\r
+{\r
+  DEBUG ((DebugLevel, "ATA COMMAND BLOCK:\n"));\r
+  DEBUG ((DebugLevel, "AtaCommand: %d\n", AtaCommandBlock->AtaCommand));\r
+  DEBUG ((DebugLevel, "AtaFeatures: %X\n", AtaCommandBlock->AtaFeatures));\r
+  DEBUG ((DebugLevel, "AtaSectorNumber: %d\n", AtaCommandBlock->AtaSectorNumber));\r
+  DEBUG ((DebugLevel, "AtaCylinderLow: %X\n", AtaCommandBlock->AtaCylinderHigh));\r
+  DEBUG ((DebugLevel, "AtaCylinderHigh: %X\n", AtaCommandBlock->AtaCylinderHigh));\r
+  DEBUG ((DebugLevel, "AtaDeviceHead: %d\n", AtaCommandBlock->AtaDeviceHead));\r
+  DEBUG ((DebugLevel, "AtaSectorNumberExp: %d\n", AtaCommandBlock->AtaSectorNumberExp));\r
+  DEBUG ((DebugLevel, "AtaCylinderLowExp: %X\n", AtaCommandBlock->AtaCylinderLowExp));\r
+  DEBUG ((DebugLevel, "AtaCylinderHighExp: %X\n", AtaCommandBlock->AtaCylinderHighExp));\r
+  DEBUG ((DebugLevel, "AtaFeaturesExp: %X\n", AtaCommandBlock->AtaFeaturesExp));\r
+  DEBUG ((DebugLevel, "AtaSectorCount: %d\n", AtaCommandBlock->AtaSectorCount));\r
+  DEBUG ((DebugLevel, "AtaSectorCountExp: %d\n", AtaCommandBlock->AtaSectorCountExp));\r
+}\r
+\r
+/**\r
+  Prints contents of the ATA status block into the debug port.\r
+\r
+  @param[in] AtaStatusBlock   AtaStatusBlock to print.\r
+  @param[in] DebugLevel       Debug level on which to print.\r
+**/\r
+VOID\r
+AhciPrintStatusBlock (\r
+  IN EFI_ATA_STATUS_BLOCK  *AtaStatusBlock,\r
+  IN UINT32                DebugLevel\r
+  )\r
+{\r
+  //\r
+  // Only print status and error since we have all of the rest printed as\r
+  // a part of command block print.\r
+  //\r
+  DEBUG ((DebugLevel, "ATA STATUS BLOCK:\n"));\r
+  DEBUG ((DebugLevel, "AtaStatus: %d\n", AtaStatusBlock->AtaStatus));\r
+  DEBUG ((DebugLevel, "AtaError: %d\n", AtaStatusBlock->AtaError));\r
+}\r
+\r
 /**\r
   Start a PIO data transfer on specific port.\r
 \r
@@ -947,6 +995,8 @@ AhciPioTransfer (
       DataCount\r
       );\r
 \r
+    DEBUG ((DEBUG_VERBOSE, "Starting command for PIO transfer:\n"));\r
+    AhciPrintCommandBlock (AtaCommandBlock, DEBUG_VERBOSE);\r
     Status = AhciStartCommand (\r
               PciIo,\r
               Port,\r
@@ -1000,6 +1050,19 @@ AhciPioTransfer (
     );\r
 \r
   AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock);\r
+\r
+  if (Status == EFI_DEVICE_ERROR) {\r
+    DEBUG ((DEBUG_ERROR, "Failed to execute command for PIO transfer:\n"));\r
+    //\r
+    // Repeat command block here to make sure it is printed on\r
+    // device error debug level.\r
+    //\r
+    AhciPrintCommandBlock (AtaCommandBlock, DEBUG_ERROR);\r
+    AhciPrintStatusBlock (AtaStatusBlock, DEBUG_ERROR);\r
+  } else {\r
+    AhciPrintStatusBlock (AtaStatusBlock, DEBUG_VERBOSE);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -1132,6 +1195,8 @@ AhciDmaTransfer (
         DataCount\r
         );\r
 \r
+      DEBUG ((DEBUG_VERBOSE, "Starting command for sync DMA transfer:\n"));\r
+      AhciPrintCommandBlock (AtaCommandBlock, DEBUG_VERBOSE);\r
       Status = AhciStartCommand (\r
                 PciIo,\r
                 Port,\r
@@ -1168,6 +1233,8 @@ AhciDmaTransfer (
         DataCount\r
         );\r
 \r
+      DEBUG ((DEBUG_VERBOSE, "Starting command for async DMA transfer:\n"));\r
+      AhciPrintCommandBlock (AtaCommandBlock, DEBUG_VERBOSE);\r
       Status = AhciStartCommand (\r
                 PciIo,\r
                 Port,\r
@@ -1238,6 +1305,19 @@ AhciDmaTransfer (
   }\r
 \r
   AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock);\r
+\r
+  if (Status == EFI_DEVICE_ERROR) {\r
+    DEBUG ((DEBUG_ERROR, "Failed to execute command for DMA transfer:\n"));\r
+    //\r
+    // Repeat command block here to make sure it is printed on\r
+    // device error debug level.\r
+    //\r
+    AhciPrintCommandBlock (AtaCommandBlock, DEBUG_ERROR);\r
+    AhciPrintStatusBlock (AtaStatusBlock, DEBUG_ERROR);\r
+  } else {\r
+    AhciPrintStatusBlock (AtaStatusBlock, DEBUG_VERBOSE);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -1307,6 +1387,8 @@ AhciNonDataTransfer (
       0\r
       );\r
 \r
+    DEBUG ((DEBUG_VERBOSE, "Starting command for non data transfer:\n"));\r
+    AhciPrintCommandBlock (AtaCommandBlock, DEBUG_VERBOSE);\r
     Status = AhciStartCommand (\r
                 PciIo,\r
                 Port,\r
@@ -1343,6 +1425,18 @@ AhciNonDataTransfer (
 \r
   AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock);\r
 \r
+  if (Status == EFI_DEVICE_ERROR) {\r
+    DEBUG ((DEBUG_ERROR, "Failed to execute command for non data transfer:\n"));\r
+    //\r
+    // Repeat command block here to make sure it is printed on\r
+    // device error debug level.\r
+    //\r
+    AhciPrintCommandBlock (AtaCommandBlock, DEBUG_ERROR);\r
+    AhciPrintStatusBlock (AtaStatusBlock, DEBUG_ERROR);\r
+  } else {\r
+    AhciPrintStatusBlock (AtaStatusBlock, DEBUG_VERBOSE);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r