Revision: 16322
          http://sourceforge.net/p/edk2/code/16322
Author:   niruiyu
Date:     2014-11-10 08:47:49 +0000 (Mon, 10 Nov 2014)
Log Message:
-----------
Fix a bug in DebugAgent that hang happens when the ACK for GO is lost.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <[email protected]>
Reviewed-by: Jeff Fan <[email protected]>

Modified Paths:
--------------
    trunk/edk2/SourceLevelDebugPkg/Include/TransferProtocol.h
    
trunk/edk2/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c

Modified: trunk/edk2/SourceLevelDebugPkg/Include/TransferProtocol.h
===================================================================
--- trunk/edk2/SourceLevelDebugPkg/Include/TransferProtocol.h   2014-11-10 
05:46:21 UTC (rev 16321)
+++ trunk/edk2/SourceLevelDebugPkg/Include/TransferProtocol.h   2014-11-10 
08:47:49 UTC (rev 16322)
@@ -2,7 +2,7 @@
   Transfer protocol defintions used by debug agent and host. It is only
   intended to be used by Debug related module implementation.
 
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -53,6 +53,8 @@
 #define DEBUG_COMMAND_REQUEST      (0 << 7)
 #define DEBUG_COMMAND_RESPONSE     (1 << 7)
 
+#define IS_REQUEST(x)              (((x)->Command & DEBUG_COMMAND_RESPONSE) == 
0)
+
 //
 // HOST initiated commands
 //

Modified: 
trunk/edk2/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
===================================================================
--- 
trunk/edk2/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c 
    2014-11-10 05:46:21 UTC (rev 16321)
+++ 
trunk/edk2/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c 
    2014-11-10 08:47:49 UTC (rev 16322)
@@ -605,19 +605,20 @@
     return EFI_CRC_ERROR;
   }
   Mailbox = GetMailboxPointer();
-  if (((DebugHeader->Command & DEBUG_COMMAND_RESPONSE) == 0) &&
-       (DebugHeader->SequenceNo == (UINT8) (Mailbox->HostSequenceNo + 1))) {
-    //
-    // Only updagte HostSequenceNo for new command packet
-    //
-    UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, 
DebugHeader->SequenceNo);
-    return EFI_SUCCESS;
-  } else {
-    //
-    // If one old command or response packet received, skip it
-    //
-    return EFI_DEVICE_ERROR;
+  if (IS_REQUEST (DebugHeader)) {
+    if (DebugHeader->SequenceNo == (UINT8) (Mailbox->HostSequenceNo + 1)) {
+      //
+      // Only updagte HostSequenceNo for new command packet 
+      //
+      UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, 
DebugHeader->SequenceNo);
+      return EFI_SUCCESS;
+    }
+    if (DebugHeader->SequenceNo == Mailbox->HostSequenceNo) {
+      return EFI_SUCCESS;
+    }
   }
+
+  return EFI_DEVICE_ERROR;
 }
 
 /**
@@ -1646,7 +1647,7 @@
 
     DebugAgentMsgPrint (DEBUG_AGENT_INFO, "TARGET: Try to get command from 
HOST...\n");
     Status = ReceivePacket ((UINT8 *)DebugHeader, &BreakReceived, NULL, 
READ_PACKET_TIMEOUT, TRUE);
-    if (Status != RETURN_SUCCESS || (DebugHeader->Command & 
DEBUG_COMMAND_RESPONSE) != 0) {
+    if (Status != RETURN_SUCCESS || !IS_REQUEST (DebugHeader)) {
       DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Get command[%x] 
sequenceno[%x] returned status is [%x] \n", DebugHeader->Command, 
DebugHeader->SequenceNo, Status);
       DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Get command failed or 
it's response packet not expected! \n");
       ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to