]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/MnpDxe/MnpIo.c
1. remove duplicated NetLibDispatchDpc() calling in Pool function.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpIo.c
index 91b8d4e0b854e327c8b7413533d66b659052fb8b..57b1f7b5bc98c72dd35fa02aaa6b68a7459a2ffe 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
-\r
-Copyright (c) 2005 - 2007, Intel Corporation\r
+  Implementation of Managed Network Protocol I/O functions.\r
+    \r
+Copyright (c) 2005 - 2007, Intel Corporation. <BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -9,29 +10,15 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-  MnpIo.c\r
-\r
-Abstract:\r
-\r
-  Implementation of Managed Network Protocol I/O functions.\r
-\r
-\r
 **/\r
 \r
-#include <Library/NetLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
 #include "MnpImpl.h"\r
 \r
-\r
 /**\r
   Validates the Mnp transmit token.\r
 \r
-  @param  Instance              Pointer to the Mnp instance context data.\r
-  @param  Token                 Pointer to the transmit token to check.\r
+  @param[in]  Instance            Pointer to the Mnp instance context data.\r
+  @param[in]  Token               Pointer to the transmit token to check.\r
 \r
   @return The Token is valid or not.\r
 \r
@@ -58,7 +45,7 @@ MnpIsValidTxToken (
     // The token is invalid if the Event is NULL, or the TxData is NULL, or\r
     // the fragment count is zero.\r
     //\r
-    MNP_DEBUG_WARN (("MnpIsValidTxToken: Invalid Token.\n"));\r
+    DEBUG ((EFI_D_WARN, "MnpIsValidTxToken: Invalid Token.\n"));\r
     return FALSE;\r
   }\r
 \r
@@ -67,7 +54,7 @@ MnpIsValidTxToken (
     // The token is invalid if the HeaderLength isn't zero while the DestinationAddress\r
     // is NULL (The destination address is already put into the packet).\r
     //\r
-    MNP_DEBUG_WARN (("MnpIsValidTxToken: DestinationAddress isn't NULL, HeaderLength must be 0.\n"));\r
+    DEBUG ((EFI_D_WARN, "MnpIsValidTxToken: DestinationAddress isn't NULL, HeaderLength must be 0.\n"));\r
     return FALSE;\r
   }\r
 \r
@@ -79,7 +66,7 @@ MnpIsValidTxToken (
       //\r
       // The token is invalid if any FragmentLength is zero or any FragmentBuffer is NULL.\r
       //\r
-      MNP_DEBUG_WARN (("MnpIsValidTxToken: Invalid FragmentLength or FragmentBuffer.\n"));\r
+      DEBUG ((EFI_D_WARN, "MnpIsValidTxToken: Invalid FragmentLength or FragmentBuffer.\n"));\r
       return FALSE;\r
     }\r
 \r
@@ -98,7 +85,7 @@ MnpIsValidTxToken (
     // The length calculated from the fragment information doesn't equal to the\r
     // sum of the DataLength and the HeaderLength.\r
     //\r
-    MNP_DEBUG_WARN (("MnpIsValidTxData: Invalid Datalength compared with the sum of fragment length.\n"));\r
+    DEBUG ((EFI_D_WARN, "MnpIsValidTxData: Invalid Datalength compared with the sum of fragment length.\n"));\r
     return FALSE;\r
   }\r
 \r
@@ -106,7 +93,7 @@ MnpIsValidTxToken (
     //\r
     // The total length is larger than the MTU.\r
     //\r
-    MNP_DEBUG_WARN (("MnpIsValidTxData: TxData->DataLength exceeds Mtu.\n"));\r
+    DEBUG ((EFI_D_WARN, "MnpIsValidTxData: TxData->DataLength exceeds Mtu.\n"));\r
     return FALSE;\r
   }\r
 \r
@@ -117,14 +104,12 @@ MnpIsValidTxToken (
 /**\r
   Build the packet to transmit from the TxData passed in.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-  @param  TxData                Pointer to the transmit data containing the\r
-                                information to build the packet.\r
-  @param  PktBuf                Pointer to record the address of the packet.\r
-  @param  PktLen                Pointer to a UINT32 variable used to record the\r
-                                packet's length.\r
-\r
-  @return None.\r
+  @param[in]   MnpServiceData      Pointer to the mnp service context data.\r
+  @param[in]   TxData              Pointer to the transmit data containing the information \r
+                                   to build the packet.\r
+  @param[out]  PktBuf              Pointer to record the address of the packet.\r
+  @param[out]  PktLen              Pointer to a UINT32 variable used to record the packet's \r
+                                   length.\r
 \r
 **/\r
 VOID\r
@@ -169,7 +154,7 @@ MnpBuildTxPacket (
       //\r
       // Copy the data.\r
       //\r
-      NetCopyMem (\r
+      CopyMem (\r
         DstPos,\r
         TxData->FragmentTable[Index].FragmentBuffer,\r
         TxData->FragmentTable[Index].FragmentLength\r
@@ -189,22 +174,22 @@ MnpBuildTxPacket (
 /**\r
   Synchronously send out the packet.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-  @param  Packet                Pointer to the pakcet buffer.\r
-  @param  Length                The length of the packet.\r
-  @param  Token                 Pointer to the token the packet generated from.\r
+  @param[in]       MnpServiceData      Pointer to the mnp service context data.\r
+  @param[in]       Packet              Pointer to the pakcet buffer.\r
+  @param[in]       Length              The length of the packet.\r
+  @param[in, out]  Token               Pointer to the token the packet generated from.\r
 \r
-  @retval EFI_SUCCESS           The packet is sent out.\r
-  @retval EFI_TIMEOUT           Time out occurs, the packet isn't sent.\r
-  @retval EFI_DEVICE_ERROR      An unexpected network error occurs.\r
+  @retval EFI_SUCCESS                  The packet is sent out.\r
+  @retval EFI_TIMEOUT                  Time out occurs, the packet isn't sent.\r
+  @retval EFI_DEVICE_ERROR             An unexpected network error occurs.\r
 \r
 **/\r
 EFI_STATUS\r
 MnpSyncSendPacket (\r
-  IN MNP_SERVICE_DATA                      *MnpServiceData,\r
-  IN UINT8                                 *Packet,\r
-  IN UINT32                                Length,\r
-  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
+  IN MNP_SERVICE_DATA                          *MnpServiceData,\r
+  IN UINT8                                     *Packet,\r
+  IN UINT32                                    Length,\r
+  IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token\r
   )\r
 {\r
   EFI_STATUS                        Status;\r
@@ -294,6 +279,11 @@ SIGNAL_TOKEN:
   Token->Status = Status;\r
   gBS->SignalEvent (Token->Event);\r
 \r
+  //\r
+  // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r
+  //\r
+  NetLibDispatchDpc ();\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -301,7 +291,7 @@ SIGNAL_TOKEN:
 /**\r
   Try to deliver the received packet to the instance.\r
 \r
-  @param  Instance              Pointer to the mnp instance context data.\r
+  @param[in, out]  Instance     Pointer to the mnp instance context data.\r
 \r
   @retval EFI_SUCCESS           The received packet is delivered, or there is no\r
                                 packet to deliver, or there is no available receive\r
@@ -311,7 +301,7 @@ SIGNAL_TOKEN:
 **/\r
 EFI_STATUS\r
 MnpInstanceDeliverPacket (\r
-  IN MNP_INSTANCE_DATA  *Instance\r
+  IN OUT MNP_INSTANCE_DATA  *Instance\r
   )\r
 {\r
   MNP_SERVICE_DATA                      *MnpServiceData;\r
@@ -324,7 +314,7 @@ MnpInstanceDeliverPacket (
   MnpServiceData = Instance->MnpServiceData;\r
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
 \r
-  if (NetMapIsEmpty (&Instance->RxTokenMap) || NetListIsEmpty (&Instance->RcvdPacketQueue)) {\r
+  if (NetMapIsEmpty (&Instance->RxTokenMap) || IsListEmpty (&Instance->RcvdPacketQueue)) {\r
     //\r
     // No pending received data or no available receive token, return.\r
     //\r
@@ -341,7 +331,7 @@ MnpInstanceDeliverPacket (
     //\r
     DupNbuf = MnpAllocNbuf (MnpServiceData);\r
     if (DupNbuf == NULL) {\r
-      MNP_DEBUG_WARN (("MnpDeliverPacket: Failed to allocate a free Nbuf.\n"));\r
+      DEBUG ((EFI_D_WARN, "MnpDeliverPacket: Failed to allocate a free Nbuf.\n"));\r
 \r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
@@ -374,7 +364,7 @@ MnpInstanceDeliverPacket (
   //\r
   // Insert this RxDataWrap into the delivered queue.\r
   //\r
-  NetListInsertTail (&Instance->RxDeliveredPacketQueue, &RxDataWrap->WrapEntry);\r
+  InsertTailList (&Instance->RxDeliveredPacketQueue, &RxDataWrap->WrapEntry);\r
 \r
   //\r
   // Get the receive token from the RxTokenMap.\r
@@ -395,18 +385,15 @@ MnpInstanceDeliverPacket (
 /**\r
   Deliver the received packet for the instances belonging to the MnpServiceData.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-\r
-  @return None.\r
+  @param[in]  MnpServiceData        Pointer to the mnp service context data.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 MnpDeliverPacket (\r
   IN MNP_SERVICE_DATA  *MnpServiceData\r
   )\r
 {\r
-  NET_LIST_ENTRY    *Entry;\r
+  LIST_ENTRY        *Entry;\r
   MNP_INSTANCE_DATA *Instance;\r
 \r
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
@@ -427,10 +414,8 @@ MnpDeliverPacket (
   Recycle the RxData and other resources used to hold and deliver the received\r
   packet.\r
 \r
-  @param  Event                 The event this notify function registered to.\r
-  @param  Context               Pointer to the context data registerd to the Event.\r
-\r
-  @return None.\r
+  @param[in]  Event               The event this notify function registered to.\r
+  @param[in]  Context             Pointer to the context data registerd to the Event.\r
 \r
 **/\r
 VOID\r
@@ -467,27 +452,23 @@ MnpRecycleRxData (
   //\r
   // Remove this Wrap entry from the list.\r
   //\r
-  NetListRemoveEntry (&RxDataWrap->WrapEntry);\r
+  RemoveEntryList (&RxDataWrap->WrapEntry);\r
 \r
-  NetFreePool (RxDataWrap);\r
+  gBS->FreePool (RxDataWrap);\r
 }\r
 \r
 \r
 /**\r
   Queue the received packet into instance's receive queue.\r
 \r
-  @param  Instance              Pointer to the mnp instance context data.\r
-  @param  RxDataWrap            Pointer to the Wrap structure containing the\r
-                                received data and other information.\r
-\r
-  @return None.\r
-\r
+  @param[in, out]  Instance        Pointer to the mnp instance context data.\r
+  @param[in, out]  RxDataWrap      Pointer to the Wrap structure containing the\r
+                                   received data and other information.\r
 **/\r
-STATIC\r
 VOID\r
 MnpQueueRcvdPacket (\r
-  IN MNP_INSTANCE_DATA  *Instance,\r
-  IN MNP_RXDATA_WRAP    *RxDataWrap\r
+  IN OUT MNP_INSTANCE_DATA  *Instance,\r
+  IN OUT MNP_RXDATA_WRAP    *RxDataWrap\r
   )\r
 {\r
   MNP_RXDATA_WRAP *OldRxDataWrap;\r
@@ -500,7 +481,7 @@ MnpQueueRcvdPacket (
   //\r
   if (Instance->RcvdPacketQueueSize == MNP_MAX_RCVD_PACKET_QUE_SIZE) {\r
 \r
-    MNP_DEBUG_WARN (("MnpQueueRcvdPacket: Drop one packet bcz queue size limit reached.\n"));\r
+    DEBUG ((EFI_D_WARN, "MnpQueueRcvdPacket: Drop one packet bcz queue size limit reached.\n"));\r
 \r
     //\r
     // Get the oldest packet.\r
@@ -526,7 +507,7 @@ MnpQueueRcvdPacket (
   //\r
   // Insert this Wrap into the instance queue.\r
   //\r
-  NetListInsertTail (&Instance->RcvdPacketQueue, &RxDataWrap->WrapEntry);\r
+  InsertTailList (&Instance->RcvdPacketQueue, &RxDataWrap->WrapEntry);\r
   Instance->RcvdPacketQueueSize++;\r
 }\r
 \r
@@ -534,18 +515,17 @@ MnpQueueRcvdPacket (
 /**\r
   Match the received packet with the instance receive filters.\r
 \r
-  @param  Instance              Pointer to the mnp instance context data.\r
-  @param  RxData                Pointer to the EFI_MANAGED_NETWORK_RECEIVE_DATA.\r
-  @param  GroupAddress          Pointer to the GroupAddress, the GroupAddress is\r
+  @param[in]  Instance          Pointer to the mnp instance context data.\r
+  @param[in]  RxData            Pointer to the EFI_MANAGED_NETWORK_RECEIVE_DATA.\r
+  @param[in]  GroupAddress      Pointer to the GroupAddress, the GroupAddress is\r
                                 non-NULL and it contains the destination multicast\r
                                 mac address of the received packet if the packet\r
                                 destinated to a multicast mac address.\r
-  @param  PktAttr               The received packets attribute.\r
+  @param[in]  PktAttr           The received packets attribute.\r
 \r
   @return The received packet matches the instance's receive filters or not.\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 MnpMatchPacket (\r
   IN MNP_INSTANCE_DATA                 *Instance,\r
@@ -555,19 +535,13 @@ MnpMatchPacket (
   )\r
 {\r
   EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData;\r
-  NET_LIST_ENTRY                  *Entry;\r
+  LIST_ENTRY                      *Entry;\r
   MNP_GROUP_CONTROL_BLOCK         *GroupCtrlBlk;\r
 \r
   NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
 \r
   ConfigData = &Instance->ConfigData;\r
 \r
-  if (ConfigData->EnablePromiscuousReceive) {\r
-    //\r
-    // Always match if this instance is configured to be promiscuous.\r
-    //\r
-    return TRUE;\r
-  }\r
   //\r
   // Check the protocol type.\r
   //\r
@@ -575,6 +549,13 @@ MnpMatchPacket (
     return FALSE;\r
   }\r
 \r
+  if (ConfigData->EnablePromiscuousReceive) {\r
+    //\r
+    // Always match if this instance is configured to be promiscuous.\r
+    //\r
+    return TRUE;\r
+  }\r
+\r
   //\r
   // The protocol type is matched, check receive filter, include unicast and broadcast.\r
   //\r
@@ -612,33 +593,30 @@ MnpMatchPacket (
 /**\r
   Analyse the received packets.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-  @param  Nbuf                  Pointer to the net buffer holding the received\r
-                                packet.\r
-  @param  RxData                Pointer to the buffer used to save the analysed\r
-                                result in EFI_MANAGED_NETWORK_RECEIVE_DATA.\r
-  @param  GroupAddress          Pointer to pointer to a MNP_GROUP_ADDRESS used to\r
-                                pass out the address of the multicast address the\r
-                                received packet destinated to.\r
-  @param  PktAttr               Pointer to the buffer used to save the analysed\r
-                                packet attribute.\r
-\r
-  @return None.\r
+  @param[in]       MnpServiceData    Pointer to the mnp service context data.\r
+  @param[in]       Nbuf              Pointer to the net buffer holding the received\r
+                                     packet.\r
+  @param[in, out]  RxData            Pointer to the buffer used to save the analysed\r
+                                     result in EFI_MANAGED_NETWORK_RECEIVE_DATA.\r
+  @param[out]      GroupAddress      Pointer to pointer to a MNP_GROUP_ADDRESS used to\r
+                                     pass out the address of the multicast address the\r
+                                     received packet destinated to.\r
+  @param[out]      PktAttr           Pointer to the buffer used to save the analysed\r
+                                     packet attribute.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 MnpAnalysePacket (\r
-  IN  MNP_SERVICE_DATA                  *MnpServiceData,\r
-  IN  NET_BUF                           *Nbuf,\r
-  IN  EFI_MANAGED_NETWORK_RECEIVE_DATA  *RxData,\r
-  OUT MNP_GROUP_ADDRESS                 **GroupAddress,\r
-  OUT UINT8                             *PktAttr\r
+  IN  MNP_SERVICE_DATA                      *MnpServiceData,\r
+  IN  NET_BUF                               *Nbuf,\r
+  IN  OUT EFI_MANAGED_NETWORK_RECEIVE_DATA  *RxData,\r
+  OUT MNP_GROUP_ADDRESS                     **GroupAddress,\r
+  OUT UINT8                                 *PktAttr\r
   )\r
 {\r
   EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
   UINT8                   *BufPtr;\r
-  NET_LIST_ENTRY          *Entry;\r
+  LIST_ENTRY              *Entry;\r
 \r
   SnpMode = MnpServiceData->Snp->Mode;\r
 \r
@@ -701,7 +679,7 @@ MnpAnalysePacket (
     }\r
   }\r
 \r
-  NetZeroMem (&RxData->Timestamp, sizeof (EFI_TIME));\r
+  ZeroMem (&RxData->Timestamp, sizeof (EFI_TIME));\r
 \r
   //\r
   // Fill the common parts of RxData.\r
@@ -717,13 +695,12 @@ MnpAnalysePacket (
 /**\r
   Wrap the RxData.\r
 \r
-  @param  Instance              Pointer to the mnp instance context data.\r
-  @param  RxData                Pointer to the receive data to wrap.\r
+  @param[in]  Instance           Pointer to the mnp instance context data.\r
+  @param[in]  RxData             Pointer to the receive data to wrap.\r
 \r
   @return Pointer to a MNP_RXDATA_WRAP which wraps the RxData.\r
 \r
 **/\r
-STATIC\r
 MNP_RXDATA_WRAP *\r
 MnpWrapRxData (\r
   IN MNP_INSTANCE_DATA                 *Instance,\r
@@ -736,9 +713,9 @@ MnpWrapRxData (
   //\r
   // Allocate memory.\r
   //\r
-  RxDataWrap = NetAllocatePool (sizeof (MNP_RXDATA_WRAP));\r
+  RxDataWrap = AllocatePool (sizeof (MNP_RXDATA_WRAP));\r
   if (RxDataWrap == NULL) {\r
-    MNP_DEBUG_ERROR (("MnpDispatchPacket: Failed to allocate a MNP_RXDATA_WRAP.\n"));\r
+    DEBUG ((EFI_D_ERROR, "MnpDispatchPacket: Failed to allocate a MNP_RXDATA_WRAP.\n"));\r
     return NULL;\r
   }\r
 \r
@@ -747,22 +724,22 @@ MnpWrapRxData (
   //\r
   // Fill the RxData in RxDataWrap,\r
   //\r
-  CopyMem (&RxDataWrap->RxData, RxData, sizeof (EFI_MANAGED_NETWORK_RECEIVE_DATA));\r
+  CopyMem (&RxDataWrap->RxData, RxData, sizeof (RxDataWrap->RxData));\r
 \r
   //\r
   // Create the recycle event.\r
   //\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_SIGNAL,\r
-                  NET_TPL_RECYCLE,\r
+                  TPL_NOTIFY,\r
                   MnpRecycleRxData,\r
                   RxDataWrap,\r
                   &RxDataWrap->RxData.RecycleEvent\r
                   );\r
   if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (("MnpDispatchPacket: gBS->CreateEvent failed, %r.\n", Status));\r
-    NetFreePool (RxDataWrap);\r
+    DEBUG ((EFI_D_ERROR, "MnpDispatchPacket: gBS->CreateEvent failed, %r.\n", Status));\r
+    gBS->FreePool (RxDataWrap);\r
     return NULL;\r
   }\r
 \r
@@ -774,27 +751,26 @@ MnpWrapRxData (
   Enqueue the received the packets to the instances belonging to the\r
   MnpServiceData.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-  @param  Nbuf                  Pointer to the net buffer representing the received\r
+  @param[in]  MnpServiceData    Pointer to the mnp service context data.\r
+  @param[in]  Nbuf              Pointer to the net buffer representing the received\r
                                 packet.\r
 \r
-  @return None.\r
-\r
 **/\r
-STATIC\r
 VOID\r
 MnpEnqueuePacket (\r
   IN MNP_SERVICE_DATA   *MnpServiceData,\r
   IN NET_BUF            *Nbuf\r
   )\r
 {\r
-  NET_LIST_ENTRY                    *Entry;\r
+  LIST_ENTRY                        *Entry;\r
   MNP_INSTANCE_DATA                 *Instance;\r
   EFI_MANAGED_NETWORK_RECEIVE_DATA  RxData;\r
   UINT8                             PktAttr;\r
   MNP_GROUP_ADDRESS                 *GroupAddress;\r
   MNP_RXDATA_WRAP                   *RxDataWrap;\r
 \r
+\r
+  GroupAddress = NULL;\r
   //\r
   // First, analyse the packet header.\r
   //\r
@@ -827,7 +803,7 @@ MnpEnqueuePacket (
       //\r
       // Wrap the RxData.\r
       //\r
-      CopyMem (&RxDataWrap, MnpWrapRxData (Instance, &RxData), sizeof (MNP_RXDATA_WRAP));\r
+      RxDataWrap = MnpWrapRxData (Instance, &RxData);\r
       if (RxDataWrap == NULL) {\r
         continue;\r
       }\r
@@ -850,7 +826,7 @@ MnpEnqueuePacket (
 /**\r
   Try to receive a packet and deliver it.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
+  @param[in, out]  MnpServiceData        Pointer to the mnp service context data.\r
 \r
   @retval EFI_SUCCESS           add return value to function comment\r
   @retval EFI_NOT_STARTED       The simple network protocol is not started.\r
@@ -860,7 +836,7 @@ MnpEnqueuePacket (
 **/\r
 EFI_STATUS\r
 MnpReceivePacket (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\r
+  IN OUT MNP_SERVICE_DATA  *MnpServiceData\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -881,7 +857,7 @@ MnpReceivePacket (
     return EFI_NOT_STARTED;\r
   }\r
 \r
-  if (NetListIsEmpty (&MnpServiceData->ChildrenList)) {\r
+  if (IsListEmpty (&MnpServiceData->ChildrenList)) {\r
     //\r
     // There is no child, no need to receive packets.\r
     //\r
@@ -921,8 +897,8 @@ MnpReceivePacket (
 \r
     DEBUG_CODE (\r
       if (Status != EFI_NOT_READY) {\r
-      MNP_DEBUG_ERROR (("MnpReceivePacket: Snp->Receive() = %r.\n", Status));\r
-    }\r
+        DEBUG ((EFI_D_WARN, "MnpReceivePacket: Snp->Receive() = %r.\n", Status));\r
+      }\r
     );\r
 \r
     return Status;\r
@@ -933,8 +909,9 @@ MnpReceivePacket (
   //\r
   if ((HeaderSize != Snp->Mode->MediaHeaderSize) || (BufLen < HeaderSize)) {\r
 \r
-    MNP_DEBUG_WARN (\r
-      ("MnpReceivePacket: Size error, HL:TL = %d:%d.\n",\r
+    DEBUG (\r
+      (EFI_D_WARN,\r
+      "MnpReceivePacket: Size error, HL:TL = %d:%d.\n",\r
       HeaderSize,\r
       BufLen)\r
       );\r
@@ -965,7 +942,7 @@ MnpReceivePacket (
     Nbuf                        = MnpAllocNbuf (MnpServiceData);\r
     MnpServiceData->RxNbufCache = Nbuf;\r
     if (Nbuf == NULL) {\r
-      MNP_DEBUG_ERROR (("MnpReceivePacket: Alloc packet for receiving cache failed.\n"));\r
+      DEBUG ((EFI_D_ERROR, "MnpReceivePacket: Alloc packet for receiving cache failed.\n"));\r
       return EFI_DEVICE_ERROR;\r
     }\r
 \r
@@ -974,7 +951,10 @@ MnpReceivePacket (
     //\r
     // No receiver for this packet.\r
     //\r
-    NetbufAllocSpace (Nbuf, Trimmed, NET_BUF_TAIL);\r
+    if (Trimmed > 0) {\r
+      NetbufAllocSpace (Nbuf, Trimmed, NET_BUF_TAIL);\r
+    }\r
+\r
     goto EXIT;\r
   }\r
   //\r
@@ -993,12 +973,10 @@ EXIT:
 /**\r
   Remove the received packets if timeout occurs.\r
 \r
-  @param  Event                 The event this notify function registered to.\r
-  @param  Context               Pointer to the context data registered to the\r
+  @param[in]  Event             The event this notify function registered to.\r
+  @param[in]  Context           Pointer to the context data registered to the\r
                                 event.\r
-\r
-  @return None.\r
-\r
+   \r
 **/\r
 VOID\r
 EFIAPI\r
@@ -1008,9 +986,9 @@ MnpCheckPacketTimeout (
   )\r
 {\r
   MNP_SERVICE_DATA  *MnpServiceData;\r
-  NET_LIST_ENTRY    *Entry;\r
-  NET_LIST_ENTRY    *RxEntry;\r
-  NET_LIST_ENTRY    *NextEntry;\r
+  LIST_ENTRY        *Entry;\r
+  LIST_ENTRY        *RxEntry;\r
+  LIST_ENTRY        *NextEntry;\r
   MNP_INSTANCE_DATA *Instance;\r
   MNP_RXDATA_WRAP   *RxDataWrap;\r
   EFI_TPL           OldTpl;\r
@@ -1031,26 +1009,29 @@ MnpCheckPacketTimeout (
       continue;\r
     }\r
 \r
-    OldTpl = NET_RAISE_TPL (NET_TPL_RECYCLE);\r
+    OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
     NET_LIST_FOR_EACH_SAFE (RxEntry, NextEntry, &Instance->RcvdPacketQueue) {\r
 \r
       RxDataWrap = NET_LIST_USER_STRUCT (RxEntry, MNP_RXDATA_WRAP, WrapEntry);\r
 \r
-      if (RxDataWrap->TimeoutTick >= MNP_TIMEOUT_CHECK_INTERVAL) {\r
+      //\r
+      // TimeoutTick unit is ms, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.\r
+      //\r
+      if (RxDataWrap->TimeoutTick >= (MNP_TIMEOUT_CHECK_INTERVAL / 10)) {\r
 \r
-        RxDataWrap->TimeoutTick -= MNP_TIMEOUT_CHECK_INTERVAL;\r
+        RxDataWrap->TimeoutTick -= (MNP_TIMEOUT_CHECK_INTERVAL / 10);\r
       } else {\r
         //\r
         // Drop the timeout packet.\r
         //\r
-        MNP_DEBUG_WARN (("MnpCheckPacketTimeout: Received packet timeout.\n"));\r
+        DEBUG ((EFI_D_WARN, "MnpCheckPacketTimeout: Received packet timeout.\n"));\r
         MnpRecycleRxData (NULL, RxDataWrap);\r
         Instance->RcvdPacketQueueSize--;\r
       }\r
     }\r
 \r
-    NET_RESTORE_TPL (OldTpl);\r
+    gBS->RestoreTPL (OldTpl);\r
   }\r
 }\r
 \r
@@ -1059,18 +1040,15 @@ MnpCheckPacketTimeout (
   Poll to receive the packets from Snp. This function is either called by upperlayer\r
   protocols/applications or the system poll timer notify mechanism.\r
 \r
-  @param  Event                 The event this notify function registered to.\r
-  @param  Context               Pointer to the context data registered to the\r
-                                event.\r
-\r
-  @return None.\r
+  @param[in]       Event        The event this notify function registered to.\r
+  @param[in, out]  Context      Pointer to the context data registered to the event.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 MnpSystemPoll (\r
   IN EFI_EVENT  Event,\r
-  IN VOID       *Context\r
+  IN OUT VOID   *Context\r
   )\r
 {\r
   MNP_SERVICE_DATA  *MnpServiceData;\r
@@ -1082,4 +1060,9 @@ MnpSystemPoll (
   // Try to receive packets from Snp.\r
   //\r
   MnpReceivePacket (MnpServiceData);\r
+\r
+  //\r
+  // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r
+  //\r
+  NetLibDispatchDpc ();\r
 }\r