]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c
1. Fix timer unit bug in MNP: default rx/tx timeout value should be 10,000,000 (10s...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpConfig.c
index c842991f302b673109093c3ff79ca4657f52e554..381f8b87b8bc68ba3cf48bfc27e8288041763a46 100644 (file)
@@ -1,23 +1,15 @@
 /** @file\r
+  Implementation of Managed Network Protocol private services.\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation\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
-http://opensource.org/licenses/bsd-license.php\r
+Copyright (c) 2005 - 2009, Intel Corporation. <BR> \r
+All rights reserved. This program and the accompanying materials are licensed \r
+and made available under the terms and conditions of the BSD License which \r
+accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
 \r
 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
-  MnpConfig.c\r
-\r
-Abstract:\r
-\r
-  Implementation of Managed Network Protocol private services.\r
-\r
-\r
 **/\r
 \r
 \r
@@ -40,8 +32,8 @@ EFI_MANAGED_NETWORK_PROTOCOL    mMnpProtocolTemplate = {
 };\r
 \r
 EFI_MANAGED_NETWORK_CONFIG_DATA mMnpDefaultConfigData = {\r
-  10000,\r
-  10000,\r
+  10000000,\r
+  10000000,\r
   0,\r
   FALSE,\r
   FALSE,\r
@@ -52,80 +44,23 @@ EFI_MANAGED_NETWORK_CONFIG_DATA mMnpDefaultConfigData = {
   FALSE\r
 };\r
 \r
-STATIC\r
-EFI_STATUS\r
-MnpAddFreeNbuf (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN UINTN             Count\r
-  );\r
-\r
-STATIC\r
-EFI_STATUS\r
-MnpStartSnp (\r
-  IN EFI_SIMPLE_NETWORK_PROTOCOL  *Snp\r
-  );\r
-\r
-STATIC\r
-EFI_STATUS\r
-MnpStopSnp (\r
-  IN EFI_SIMPLE_NETWORK_PROTOCOL  *Snp\r
-  );\r
-\r
-STATIC\r
-EFI_STATUS\r
-MnpStart (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN BOOLEAN           IsConfigUpdate,\r
-  IN BOOLEAN           EnableSystemPoll\r
-  );\r
-\r
-STATIC\r
-EFI_STATUS\r
-MnpStop (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\r
-  );\r
-\r
-STATIC\r
-EFI_STATUS\r
-MnpConfigReceiveFilters (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\r
-  );\r
-\r
-STATIC\r
-EFI_STATUS\r
-MnpGroupOpAddCtrlBlk (\r
-  IN MNP_INSTANCE_DATA        *Instance,\r
-  IN MNP_GROUP_CONTROL_BLOCK  *CtrlBlk,\r
-  IN MNP_GROUP_ADDRESS        *GroupAddress OPTIONAL,\r
-  IN EFI_MAC_ADDRESS          *MacAddress,\r
-  IN UINT32                   HwAddressSize\r
-  );\r
-\r
-STATIC\r
-BOOLEAN\r
-MnpGroupOpDelCtrlBlk (\r
-  IN MNP_INSTANCE_DATA        *Instance,\r
-  IN MNP_GROUP_CONTROL_BLOCK  *CtrlBlk\r
-  );\r
-\r
 \r
 /**\r
-  Add some NET_BUF into MnpServiceData->FreeNbufQue. The buffer length of\r
-  the NET_BUF is specified by MnpServiceData->BufferLength.\r
+  Add Count of net buffers to MnpServiceData->FreeNbufQue. The length of the net\r
+  buffer is specified by MnpServiceData->BufferLength. \r
 \r
-  @param  MnpServiceData        Pointer to the MNP_SERVICE_DATA.\r
-  @param  Count                 Number of NET_BUFFERs to add.\r
+  @param[in, out]  MnpServiceData        Pointer to the MNP_SERVICE_DATA.\r
+  @param[in]       Count                 Number of NET_BUFFERs to add.\r
 \r
-  @retval EFI_SUCCESS           The specified amount of NET_BUFs are allocated and\r
-                                added into MnpServiceData->FreeNbufQue.\r
+  @retval EFI_SUCCESS           The specified amount of NET_BUFs are allocated \r
+                                and added to MnpServiceData->FreeNbufQue.\r
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate a NET_BUF structure.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpAddFreeNbuf (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN UINTN             Count\r
+  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
+  IN UINTN                 Count\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -139,14 +74,22 @@ MnpAddFreeNbuf (
 \r
   for (Index = 0; Index < Count; Index++) {\r
 \r
-    Nbuf = NetbufAlloc (MnpServiceData->BufferLength);\r
+    Nbuf = NetbufAlloc (MnpServiceData->BufferLength + MnpServiceData->PaddingSize);\r
     if (Nbuf == NULL) {\r
 \r
-      MNP_DEBUG_ERROR (("MnpAddFreeNbuf: NetBufAlloc failed.\n"));\r
+      DEBUG ((EFI_D_ERROR, "MnpAddFreeNbuf: NetBufAlloc failed.\n"));\r
       Status = EFI_OUT_OF_RESOURCES;\r
       break;\r
     }\r
 \r
+    if (MnpServiceData->PaddingSize > 0) {\r
+      //\r
+      // Pad padding bytes before the media header\r
+      //\r
+      NetbufAllocSpace (Nbuf, MnpServiceData->PaddingSize, NET_BUF_TAIL);\r
+      NetbufTrim (Nbuf, MnpServiceData->PaddingSize, NET_BUF_HEAD);\r
+    }\r
+\r
     NetbufQueAppend (&MnpServiceData->FreeNbufQue, Nbuf);\r
   }\r
 \r
@@ -161,14 +104,15 @@ MnpAddFreeNbuf (
   in the queue, first try to allocate some and add them into the queue, then\r
   fetch the NET_BUF from the updated FreeNbufQue.\r
 \r
-  @param  MnpServiceData        Pointer to the MNP_SERVICE_DATA.\r
+  @param[in, out]  MnpServiceData        Pointer to the MNP_SERVICE_DATA.\r
 \r
-  @return Pointer to the allocated free NET_BUF structure, if NULL the operation is failed.\r
+  @return     Pointer to the allocated free NET_BUF structure, if NULL the \r
+              operation is failed.\r
 \r
 **/\r
 NET_BUF *\r
 MnpAllocNbuf (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\r
+  IN OUT MNP_SERVICE_DATA  *MnpServiceData\r
   )\r
 {\r
   EFI_STATUS    Status;\r
@@ -180,7 +124,7 @@ MnpAllocNbuf (
 \r
   FreeNbufQue = &MnpServiceData->FreeNbufQue;\r
 \r
-  OldTpl = NET_RAISE_TPL (NET_TPL_RECYCLE);\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
   //\r
   // Check whether there are available buffers, or else try to add some.\r
@@ -189,8 +133,9 @@ MnpAllocNbuf (
 \r
     if ((MnpServiceData->NbufCnt + MNP_NET_BUFFER_INCREASEMENT) > MNP_MAX_NET_BUFFER_NUM) {\r
 \r
-      MNP_DEBUG_ERROR (\r
-        ("MnpAllocNbuf: The maximum NET_BUF size is reached for MNP driver instance %p.\n",\r
+      DEBUG (\r
+        (EFI_D_ERROR,\r
+        "MnpAllocNbuf: The maximum NET_BUF size is reached for MNP driver instance %p.\n",\r
         MnpServiceData)\r
         );\r
 \r
@@ -201,8 +146,9 @@ MnpAllocNbuf (
     Status = MnpAddFreeNbuf (MnpServiceData, MNP_NET_BUFFER_INCREASEMENT);\r
     if (EFI_ERROR (Status)) {\r
 \r
-      MNP_DEBUG_ERROR (\r
-        ("MnpAllocNbuf: Failed to add NET_BUFs into the FreeNbufQue, %r.\n",\r
+      DEBUG (\r
+        (EFI_D_ERROR,\r
+        "MnpAllocNbuf: Failed to add NET_BUFs into the FreeNbufQue, %r.\n",\r
         Status)\r
         );\r
       //\r
@@ -222,7 +168,7 @@ MnpAllocNbuf (
   }\r
 \r
 ON_EXIT:\r
-  NET_RESTORE_TPL (OldTpl);\r
+  gBS->RestoreTPL (OldTpl);\r
 \r
   return Nbuf;\r
 }\r
@@ -231,16 +177,14 @@ ON_EXIT:
 /**\r
   Try to reclaim the Nbuf into the buffer pool.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-  @param  Nbuf                  Pointer to the NET_BUF to free.\r
-\r
-  @return None.\r
+  @param[in, out]  MnpServiceData        Pointer to the mnp service context data.\r
+  @param[in, out]  Nbuf                  Pointer to the NET_BUF to free.\r
 \r
 **/\r
 VOID\r
 MnpFreeNbuf (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN NET_BUF           *Nbuf\r
+  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
+  IN OUT NET_BUF           *Nbuf\r
   )\r
 {\r
   EFI_TPL  OldTpl;\r
@@ -248,7 +192,7 @@ MnpFreeNbuf (
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
   ASSERT (Nbuf->RefCnt > 1);\r
 \r
-  OldTpl = NET_RAISE_TPL (NET_TPL_RECYCLE);\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
   NET_PUT_REF (Nbuf);\r
 \r
@@ -260,25 +204,27 @@ MnpFreeNbuf (
     NetbufQueAppend (&MnpServiceData->FreeNbufQue, Nbuf);\r
   }\r
 \r
-  NET_RESTORE_TPL (OldTpl);\r
+  gBS->RestoreTPL (OldTpl);\r
 }\r
 \r
 \r
 /**\r
   Initialize the mnp service context data.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-  @param  Snp                   Pointer to the simple network protocol.\r
+  @param[in, out]  MnpServiceData     Pointer to the mnp service context data.\r
+  @param[in]       ImageHandle        The driver image handle.\r
+  @param[in]       ControllerHandle   Handle of device to bind driver to.\r
 \r
   @retval EFI_SUCCESS           The mnp service context is initialized.\r
-  @retval Other                 Some error occurs.\r
+  @retval EFI_UNSUPPORTED       ControllerHandle does not support Simple Network Protocol.\r
+  @retval Others                Other errors as indicated.\r
 \r
 **/\r
 EFI_STATUS\r
 MnpInitializeServiceData (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_HANDLE        ControllerHandle\r
+  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
+  IN EFI_HANDLE            ImageHandle,\r
+  IN EFI_HANDLE            ControllerHandle\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
@@ -319,8 +265,8 @@ MnpInitializeServiceData (
   //\r
   // Initialize the lists.\r
   //\r
-  NetListInit (&MnpServiceData->GroupAddressList);\r
-  NetListInit (&MnpServiceData->ChildrenList);\r
+  InitializeListHead (&MnpServiceData->GroupAddressList);\r
+  InitializeListHead (&MnpServiceData->ChildrenList);\r
 \r
   //\r
   // Get the buffer length used to allocate NET_BUF to hold data received\r
@@ -328,6 +274,12 @@ MnpInitializeServiceData (
   //\r
   MnpServiceData->BufferLength = MnpServiceData->Mtu + SnpMode->MediaHeaderSize + NET_ETHER_FCS_SIZE;\r
 \r
+  //\r
+  // Make sure the protocol headers immediately following the media header\r
+  // 4-byte aligned\r
+  //\r
+  MnpServiceData->PaddingSize = (4 - SnpMode->MediaHeaderSize) & 0x3;\r
+\r
   //\r
   // Initialize the FreeNetBufQue and pre-allocate some NET_BUFs.\r
   //\r
@@ -335,7 +287,7 @@ MnpInitializeServiceData (
   Status = MnpAddFreeNbuf (MnpServiceData, MNP_INIT_NET_BUFFER_NUM);\r
   if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (("MnpInitializeServiceData: MnpAddFreeNbuf failed, %r.\n", Status));\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: MnpAddFreeNbuf failed, %r.\n", Status));\r
     goto ERROR;\r
   }\r
   //\r
@@ -351,10 +303,10 @@ MnpInitializeServiceData (
   //\r
   // Allocate buffer pool for tx.\r
   //\r
-  MnpServiceData->TxBuf = NetAllocatePool (MnpServiceData->Mtu + SnpMode->MediaHeaderSize);\r
+  MnpServiceData->TxBuf = AllocatePool (MnpServiceData->Mtu + SnpMode->MediaHeaderSize);\r
   if (MnpServiceData->TxBuf == NULL) {\r
 \r
-    MNP_DEBUG_ERROR (("MnpInitializeServiceData: NetAllocatePool failed.\n"));\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: AllocatePool failed.\n"));\r
     Status = EFI_OUT_OF_RESOURCES;\r
 \r
     goto ERROR;\r
@@ -365,14 +317,14 @@ MnpInitializeServiceData (
   //\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
-                  NET_TPL_LOCK,\r
+                  TPL_CALLBACK,\r
                   MnpSystemPoll,\r
                   MnpServiceData,\r
                   &MnpServiceData->PollTimer\r
                   );\r
   if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (("MnpInitializeServiceData: CreateEvent for poll timer failed.\n"));\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: CreateEvent for poll timer failed.\n"));\r
     goto ERROR;\r
   }\r
 \r
@@ -381,14 +333,14 @@ MnpInitializeServiceData (
   //\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
-                  NET_TPL_EVENT,\r
+                  TPL_CALLBACK,\r
                   MnpCheckPacketTimeout,\r
                   MnpServiceData,\r
                   &MnpServiceData->TimeoutCheckTimer\r
                   );\r
   if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (("MnpInitializeServiceData: CreateEvent for packet timeout check failed.\n"));\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: CreateEvent for packet timeout check failed.\n"));\r
     goto ERROR;\r
   }\r
 \r
@@ -397,14 +349,14 @@ MnpInitializeServiceData (
   //\r
   Status = gBS->CreateEvent (\r
                   EVT_TIMER,\r
-                  NET_TPL_SLOW_TIMER,\r
+                  TPL_CALLBACK,\r
                   NULL,\r
                   NULL,\r
                   &MnpServiceData->TxTimeoutEvent\r
                   );\r
   if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (("MnpInitializeServiceData: CreateEvent for tx timeout event failed.\n"));\r
+    DEBUG ((EFI_D_ERROR, "MnpInitializeServiceData: CreateEvent for tx timeout event failed.\n"));\r
   }\r
 \r
 ERROR:\r
@@ -425,7 +377,7 @@ ERROR:
 \r
     if (MnpServiceData->TxBuf != NULL) {\r
 \r
-      NetFreePool (MnpServiceData->TxBuf);\r
+      gBS->FreePool (MnpServiceData->TxBuf);\r
     }\r
 \r
     if (MnpServiceData->RxNbufCache != NULL) {\r
@@ -446,14 +398,14 @@ ERROR:
 /**\r
   Flush the mnp service context data.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-\r
-  @return None.\r
+  @param[in, out]  MnpServiceData    Pointer to the mnp service context data.\r
+  @param[in]       ImageHandle       The driver image handle.\r
 \r
 **/\r
 VOID\r
 MnpFlushServiceData (\r
-  MNP_SERVICE_DATA  *MnpServiceData\r
+  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
+  IN EFI_HANDLE            ImageHandle\r
   )\r
 {\r
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
@@ -461,7 +413,7 @@ MnpFlushServiceData (
   //\r
   // The GroupAddressList must be empty.\r
   //\r
-  ASSERT (NetListIsEmpty (&MnpServiceData->GroupAddressList));\r
+  ASSERT (IsListEmpty (&MnpServiceData->GroupAddressList));\r
 \r
   //\r
   // Close the event.\r
@@ -473,7 +425,7 @@ MnpFlushServiceData (
   //\r
   // Free the tx buffer.\r
   //\r
-  NetFreePool (MnpServiceData->TxBuf);\r
+  gBS->FreePool (MnpServiceData->TxBuf);\r
 \r
   //\r
   // Free the RxNbufCache.\r
@@ -488,28 +440,36 @@ MnpFlushServiceData (
 \r
   DEBUG_CODE (\r
 \r
-    if (MnpServiceData->NbufCnt != 0) {\r
+  if (MnpServiceData->NbufCnt != 0) {\r
 \r
-    MNP_DEBUG_WARN (("MnpFlushServiceData: Memory leak, MnpServiceData->NbufCnt != 0.\n"));\r
+    DEBUG ((EFI_D_WARN, "MnpFlushServiceData: Memory leak, MnpServiceData->NbufCnt != 0.\n"));\r
   }\r
   );\r
+\r
+  //\r
+  // Close the Simple Network Protocol.\r
+  //\r
+  gBS->CloseProtocol (\r
+        MnpServiceData->ControllerHandle,\r
+        &gEfiSimpleNetworkProtocolGuid,\r
+        ImageHandle,\r
+        MnpServiceData->ControllerHandle\r
+        );\r
 }\r
 \r
 \r
 /**\r
   Initialize the mnp instance context data.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-  @param  Instance              Pointer to the mnp instance context data to\r
-                                initialize.\r
-\r
-  @return None.\r
+  @param[in]       MnpServiceData   Pointer to the mnp service context data.\r
+  @param[in, out]  Instance         Pointer to the mnp instance context data \r
+                                    to initialize.\r
 \r
 **/\r
 VOID\r
 MnpInitializeInstanceData (\r
-  IN MNP_SERVICE_DATA   *MnpServiceData,\r
-  IN MNP_INSTANCE_DATA  *Instance\r
+  IN MNP_SERVICE_DATA       *MnpServiceData,\r
+  IN OUT MNP_INSTANCE_DATA  *Instance\r
   )\r
 {\r
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
@@ -523,19 +483,19 @@ MnpInitializeInstanceData (
   //\r
   // Copy the MNP Protocol interfaces from the template.\r
   //\r
-  Instance->ManagedNetwork = mMnpProtocolTemplate;\r
+  CopyMem (&Instance->ManagedNetwork, &mMnpProtocolTemplate, sizeof (Instance->ManagedNetwork));\r
 \r
   //\r
   // Copy the default config data.\r
   //\r
-  Instance->ConfigData = mMnpDefaultConfigData;\r
+  CopyMem (&Instance->ConfigData, &mMnpDefaultConfigData, sizeof (Instance->ConfigData));\r
 \r
   //\r
   // Initialize the lists.\r
   //\r
-  NetListInit (&Instance->GroupCtrlBlkList);\r
-  NetListInit (&Instance->RcvdPacketQueue);\r
-  NetListInit (&Instance->RxDeliveredPacketQueue);\r
+  InitializeListHead (&Instance->GroupCtrlBlkList);\r
+  InitializeListHead (&Instance->RcvdPacketQueue);\r
+  InitializeListHead (&Instance->RxDeliveredPacketQueue);\r
 \r
   //\r
   // Initialize the RxToken Map.\r
@@ -550,11 +510,11 @@ MnpInitializeInstanceData (
 \r
 \r
 /**\r
-  Check whether the token specified by Arg maches the token in Item.\r
+  Check whether the token specified by Arg matches the token in Item.\r
 \r
-  @param  Map                   Pointer to the NET_MAP.\r
-  @param  Item                  Pointer to the NET_MAP_ITEM\r
-  @param  Arg                   Pointer to the Arg, it's a pointer to the token to\r
+  @param[in]  Map               Pointer to the NET_MAP.\r
+  @param[in]  Item              Pointer to the NET_MAP_ITEM.\r
+  @param[in]  Arg               Pointer to the Arg, it's a pointer to the token to\r
                                 check.\r
 \r
   @retval EFI_SUCCESS           The token specified by Arg is different from the\r
@@ -587,27 +547,26 @@ MnpTokenExist (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Cancel the token specified by Arg if it matches the token in Item.\r
 \r
-  @param  Map                   Pointer to the NET_MAP.\r
-  @param  Item                  Pointer to the NET_MAP_ITEM\r
-  @param  Arg                   Pointer to the Arg, it's a pointer to the token to\r
-                                cancel.\r
+  @param[in, out]  Map               Pointer to the NET_MAP.\r
+  @param[in, out]  Item              Pointer to the NET_MAP_ITEM.\r
+  @param[in]       Arg               Pointer to the Arg, it's a pointer to the \r
+                                     token to cancel.\r
 \r
-  @retval EFI_SUCCESS           The Arg is NULL, and the token in Item is\r
-                                cancelled, or the Arg isn't NULL, and the token in\r
-                                Item is different from the Arg.\r
-  @retval EFI_ABORTED           The Arg isn't NULL, the token in Item mathces the\r
-                                Arg, and the token is cancelled.\r
+  @retval EFI_SUCCESS       The Arg is NULL, and the token in Item is cancelled, \r
+                            or the Arg isn't NULL, and the token in Item is\r
+                            different from the Arg.\r
+  @retval EFI_ABORTED       The Arg isn't NULL, the token in Item mathces the\r
+                            Arg, and the token is cancelled.\r
 \r
 **/\r
 EFI_STATUS\r
 MnpCancelTokens (\r
-  IN NET_MAP       *Map,\r
-  IN NET_MAP_ITEM  *Item,\r
-  IN VOID          *Arg\r
+  IN OUT NET_MAP       *Map,\r
+  IN OUT NET_MAP_ITEM  *Item,\r
+  IN VOID              *Arg\r
   )\r
 {\r
   EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *TokenToCancel;\r
@@ -622,15 +581,15 @@ MnpCancelTokens (
   TokenToCancel         = (EFI_MANAGED_NETWORK_COMPLETION_TOKEN *) Item->Key;\r
 \r
   //\r
-  // Cancel this token with status set to EFI_ABORTED.\r
+  // Remove the item from the map.\r
   //\r
-  TokenToCancel->Status = EFI_ABORTED;\r
-  gBS->SignalEvent (TokenToCancel->Event);\r
+  NetMapRemoveItem (Map, Item, NULL);\r
 \r
   //\r
-  // Remove the item from the map.\r
+  // Cancel this token with status set to EFI_ABORTED.\r
   //\r
-  NetMapRemoveItem (Map, Item, NULL);\r
+  TokenToCancel->Status = EFI_ABORTED;\r
+  gBS->SignalEvent (TokenToCancel->Event);\r
 \r
   if (Arg != NULL) {\r
     //\r
@@ -646,13 +605,12 @@ MnpCancelTokens (
 /**\r
   Start and initialize the simple network.\r
 \r
-  @param  Snp                   Pointer to the simple network protocol.\r
+  @param[in]  Snp               Pointer to the simple network protocol.\r
 \r
   @retval EFI_SUCCESS           The simple network protocol is started.\r
-  @retval Other                 Some error occurs.\r
+  @retval Others                Other errors as indicated.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpStartSnp (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL  *Snp\r
@@ -681,13 +639,12 @@ MnpStartSnp (
 /**\r
   Stop the simple network.\r
 \r
-  @param  Snp                   Pointer to the simple network protocol.\r
+  @param[in]  Snp               Pointer to the simple network protocol.\r
 \r
   @retval EFI_SUCCESS           The simple network is stopped.\r
-  @retval Other                 Some error occurs.\r
+  @retval Others                Other errors as indicated.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpStopSnp (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL  *Snp\r
@@ -717,22 +674,21 @@ MnpStopSnp (
   Start the managed network, this function is called when one instance is configured\r
   or reconfigured.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
-  @param  IsConfigUpdate        The instance is reconfigured or it's the first time\r
-                                 the instanced is configured.\r
-  @param  EnableSystemPoll      Enable the system polling or not.\r
+  @param[in, out]  MnpServiceData       Pointer to the mnp service context data.\r
+  @param[in]       IsConfigUpdate       The instance is reconfigured or it's the first\r
+                                        time the instanced is configured.\r
+  @param[in]       EnableSystemPoll     Enable the system polling or not.\r
 \r
-  @retval EFI_SUCCESS           The managed network is started and some\r
-                                configuration is updated.\r
-  @retval Other                 Some error occurs.\r
+  @retval EFI_SUCCESS                   The managed network is started and some\r
+                                        configuration is updated.\r
+  @retval Others                        Other errors as indicated.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpStart (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN BOOLEAN           IsConfigUpdate,\r
-  IN BOOLEAN           EnableSystemPoll\r
+  IN OUT MNP_SERVICE_DATA  *MnpServiceData,\r
+  IN BOOLEAN               IsConfigUpdate,\r
+  IN BOOLEAN               EnableSystemPoll\r
   )\r
 {\r
   EFI_STATUS      Status;\r
@@ -755,7 +711,7 @@ MnpStart (
       Status = MnpStartSnp (MnpServiceData->Snp);\r
       if (EFI_ERROR (Status)) {\r
 \r
-        MNP_DEBUG_ERROR (("MnpStart: MnpStartSnp failed, %r.\n", Status));\r
+        DEBUG ((EFI_D_ERROR, "MnpStart: MnpStartSnp failed, %r.\n", Status));\r
         goto ErrorExit;\r
       }\r
 \r
@@ -769,8 +725,9 @@ MnpStart (
                       );\r
       if (EFI_ERROR (Status)) {\r
 \r
-        MNP_DEBUG_ERROR (\r
-          ("MnpStart, gBS->SetTimer for TimeoutCheckTimer %r.\n",\r
+        DEBUG (\r
+          (EFI_D_ERROR,\r
+          "MnpStart, gBS->SetTimer for TimeoutCheckTimer %r.\n",\r
           Status)\r
           );\r
         goto ErrorExit;\r
@@ -788,7 +745,7 @@ MnpStart (
     Status      = gBS->SetTimer (MnpServiceData->PollTimer, TimerOpType, MNP_SYS_POLL_INTERVAL);\r
     if (EFI_ERROR (Status)) {\r
 \r
-      MNP_DEBUG_ERROR (("MnpStart: gBS->SetTimer for PollTimer failed, %r.\n", Status));\r
+      DEBUG ((EFI_D_ERROR, "MnpStart: gBS->SetTimer for PollTimer failed, %r.\n", Status));\r
       goto ErrorExit;\r
     }\r
 \r
@@ -809,16 +766,15 @@ ErrorExit:
 /**\r
   Stop the managed network.\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           The managed network is stopped.\r
-  @retval Other                 Some error occurs.\r
+  @retval EFI_SUCCESS                The managed network is stopped.\r
+  @retval Others                     Other errors as indicated.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpStop (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\r
+  IN OUT MNP_SERVICE_DATA  *MnpServiceData\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -873,14 +829,12 @@ MnpStop (
 /**\r
   Flush the instance's received data.\r
 \r
-  @param  Instance              Pointer to the mnp instance context data.\r
-\r
-  @return None.\r
+  @param[in, out]  Instance              Pointer to the mnp instance context data.\r
 \r
 **/\r
 VOID\r
 MnpFlushRcvdDataQueue (\r
-  IN MNP_INSTANCE_DATA  *Instance\r
+  IN OUT MNP_INSTANCE_DATA  *Instance\r
   )\r
 {\r
   EFI_TPL          OldTpl;\r
@@ -888,9 +842,9 @@ MnpFlushRcvdDataQueue (
 \r
   NET_CHECK_SIGNATURE (Instance, MNP_INSTANCE_DATA_SIGNATURE);\r
 \r
-  OldTpl = NET_RAISE_TPL (NET_TPL_RECYCLE);\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  while (!NetListIsEmpty (&Instance->RcvdPacketQueue)) {\r
+  while (!IsListEmpty (&Instance->RcvdPacketQueue)) {\r
     //\r
     // Remove all the Wraps.\r
     //\r
@@ -905,27 +859,27 @@ MnpFlushRcvdDataQueue (
 \r
   ASSERT (Instance->RcvdPacketQueueSize == 0);\r
 \r
-  NET_RESTORE_TPL (OldTpl);\r
+  gBS->RestoreTPL (OldTpl);\r
 }\r
 \r
 \r
 /**\r
   Configure the Instance using ConfigData.\r
 \r
-  @param  Instance              Pointer to the mnp instance context data.\r
-  @param  ConfigData            Pointer to the configuration data used to configure\r
+  @param[in, out]  Instance     Pointer to the mnp instance context data.\r
+  @param[in]       ConfigData   Pointer to the configuration data used to configure\r
                                 the isntance.\r
 \r
   @retval EFI_SUCCESS           The Instance is configured.\r
   @retval EFI_UNSUPPORTED       EnableReceiveTimestamps is on and the\r
                                 implementation doesn't support it.\r
-  @retval Other                 Some error occurs.\r
+  @retval Others                Other errors as indicated.\r
 \r
 **/\r
 EFI_STATUS\r
 MnpConfigureInstance (\r
-  IN MNP_INSTANCE_DATA                *Instance,\r
-  IN EFI_MANAGED_NETWORK_CONFIG_DATA  *ConfigData OPTIONAL\r
+  IN OUT MNP_INSTANCE_DATA              *Instance,\r
+  IN EFI_MANAGED_NETWORK_CONFIG_DATA    *ConfigData OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                      Status;\r
@@ -1013,7 +967,7 @@ MnpConfigureInstance (
 \r
   if (ConfigData == NULL) {\r
 \r
-    NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, NULL);\r
+    Instance->ManagedNetwork.Cancel (&Instance->ManagedNetwork, NULL);\r
   }\r
 \r
   if (!NewConfigData->EnableMulticastReceive) {\r
@@ -1024,7 +978,7 @@ MnpConfigureInstance (
   //\r
   // Save the new configuration data.\r
   //\r
-  *OldConfigData        = *NewConfigData;\r
+  CopyMem (OldConfigData, NewConfigData, sizeof (*OldConfigData));\r
 \r
   Instance->Configured  = (BOOLEAN) (ConfigData != NULL);\r
 \r
@@ -1035,7 +989,7 @@ MnpConfigureInstance (
     Status = MnpStart (\r
               MnpServiceData,\r
               IsConfigUpdate,\r
-              !NewConfigData->DisableBackgroundPolling\r
+              (BOOLEAN) !NewConfigData->DisableBackgroundPolling\r
               );\r
   } else {\r
     //\r
@@ -1047,19 +1001,17 @@ MnpConfigureInstance (
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Configure the Snp receive filters according to the instances' receive filter\r
   settings.\r
 \r
-  @param  MnpServiceData        Pointer to the mnp service context data.\r
+  @param[in]  MnpServiceData        Pointer to the mnp service context data.\r
 \r
-  @retval EFI_SUCCESS           The receive filters is configured.\r
-  @retval EFI_OUT_OF_RESOURCES  The receive filters can't be configured due to lack\r
-                                of memory resource.\r
+  @retval     EFI_SUCCESS           The receive filters is configured.\r
+  @retval     EFI_OUT_OF_RESOURCES  The receive filters can't be configured due \r
+                                    to lack of memory resource.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpConfigReceiveFilters (\r
   IN MNP_SERVICE_DATA  *MnpServiceData\r
@@ -1072,7 +1024,7 @@ MnpConfigReceiveFilters (
   UINT32                      EnableFilterBits;\r
   UINT32                      DisableFilterBits;\r
   BOOLEAN                     ResetMCastFilters;\r
-  NET_LIST_ENTRY              *Entry;\r
+  LIST_ENTRY                  *Entry;\r
   UINT32                      Index;\r
   MNP_GROUP_ADDRESS           *GroupAddress;\r
 \r
@@ -1124,10 +1076,10 @@ MnpConfigReceiveFilters (
       // Allocate pool for the mulicast addresses.\r
       //\r
       MCastFilterCnt  = MnpServiceData->GroupAddressCount;\r
-      MCastFilter     = NetAllocatePool (sizeof (EFI_MAC_ADDRESS) * MCastFilterCnt);\r
+      MCastFilter     = AllocatePool (sizeof (EFI_MAC_ADDRESS) * MCastFilterCnt);\r
       if (MCastFilter == NULL) {\r
 \r
-        MNP_DEBUG_ERROR (("MnpConfigReceiveFilters: Failed to allocate memory resource for MCastFilter.\n"));\r
+        DEBUG ((EFI_D_ERROR, "MnpConfigReceiveFilters: Failed to allocate memory resource for MCastFilter.\n"));\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
 \r
@@ -1138,7 +1090,7 @@ MnpConfigReceiveFilters (
       NET_LIST_FOR_EACH (Entry, &MnpServiceData->GroupAddressList) {\r
 \r
         GroupAddress            = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);\r
-        *(MCastFilter + Index)  = GroupAddress->Address;\r
+        CopyMem (MCastFilter + Index, &GroupAddress->Address, sizeof (*(MCastFilter + Index)));\r
         Index++;\r
 \r
         ASSERT (Index <= MCastFilterCnt);\r
@@ -1149,7 +1101,7 @@ MnpConfigReceiveFilters (
       // multicast.\r
       //\r
 \r
-      if (Snp->Mode->ReceiveFilterMask & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) {\r
+      if ((Snp->Mode->ReceiveFilterMask & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) != 0) {\r
         EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;\r
       } else {\r
         //\r
@@ -1188,8 +1140,9 @@ MnpConfigReceiveFilters (
   DEBUG_CODE (\r
     if (EFI_ERROR (Status)) {\r
 \r
-    MNP_DEBUG_ERROR (\r
-      ("MnpConfigReceiveFilters: Snp->ReceiveFilters failed, %r.\n",\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "MnpConfigReceiveFilters: Snp->ReceiveFilters failed, %r.\n",\r
       Status)\r
       );\r
   }\r
@@ -1199,7 +1152,7 @@ MnpConfigReceiveFilters (
     //\r
     // Free the buffer used to hold the group addresses.\r
     //\r
-    NetFreePool (MCastFilter);\r
+    gBS->FreePool (MCastFilter);\r
   }\r
 \r
   return Status;\r
@@ -1210,24 +1163,23 @@ MnpConfigReceiveFilters (
   Add a group address control block which controls the MacAddress for\r
   this instance.\r
 \r
-  @param  Instance              Pointer to the mnp instance context data.\r
-  @param  CtrlBlk               Pointer to the group address control block.\r
-  @param  GroupAddress          Pointer to the group adress.\r
-  @param  MacAddress            Pointer to the mac address.\r
-  @param  HwAddressSize         The hardware address size.\r
+  @param[in, out]  Instance        Pointer to the mnp instance context data.\r
+  @param[in, out]  CtrlBlk         Pointer to the group address control block.\r
+  @param[in, out]  GroupAddress    Pointer to the group adress.\r
+  @param[in]       MacAddress      Pointer to the mac address.\r
+  @param[in]       HwAddressSize   The hardware address size.\r
 \r
-  @retval EFI_SUCCESS           The group address control block is added.\r
-  @retval EFI_OUT_OF_RESOURCE   Failed due to lack of memory resources.\r
+  @retval EFI_SUCCESS              The group address control block is added.\r
+  @retval EFI_OUT_OF_RESOURCES     Failed due to lack of memory resources.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpGroupOpAddCtrlBlk (\r
-  IN MNP_INSTANCE_DATA        *Instance,\r
-  IN MNP_GROUP_CONTROL_BLOCK  *CtrlBlk,\r
-  IN MNP_GROUP_ADDRESS        *GroupAddress OPTIONAL,\r
-  IN EFI_MAC_ADDRESS          *MacAddress,\r
-  IN UINT32                   HwAddressSize\r
+  IN OUT MNP_INSTANCE_DATA        *Instance,\r
+  IN OUT MNP_GROUP_CONTROL_BLOCK  *CtrlBlk,\r
+  IN OUT MNP_GROUP_ADDRESS        *GroupAddress OPTIONAL,\r
+  IN EFI_MAC_ADDRESS              *MacAddress,\r
+  IN UINT32                       HwAddressSize\r
   )\r
 {\r
   MNP_SERVICE_DATA  *MnpServiceData;\r
@@ -1244,17 +1196,17 @@ MnpGroupOpAddCtrlBlk (
     //\r
     // Allocate a new GroupAddress to be added into MNP's GroupAddressList.\r
     //\r
-    GroupAddress = NetAllocatePool (sizeof (MNP_GROUP_ADDRESS));\r
+    GroupAddress = AllocatePool (sizeof (MNP_GROUP_ADDRESS));\r
     if (GroupAddress == NULL) {\r
 \r
-      MNP_DEBUG_ERROR (("MnpGroupOpFormCtrlBlk: Failed to allocate memory resource.\n"));\r
+      DEBUG ((EFI_D_ERROR, "MnpGroupOpFormCtrlBlk: Failed to allocate memory resource.\n"));\r
 \r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    GroupAddress->Address = *MacAddress;\r
+    CopyMem (&GroupAddress->Address, MacAddress, sizeof (GroupAddress->Address));\r
     GroupAddress->RefCnt  = 0;\r
-    NetListInsertTail (\r
+    InsertTailList (\r
       &MnpServiceData->GroupAddressList,\r
       &GroupAddress->AddrEntry\r
       );\r
@@ -1270,7 +1222,7 @@ MnpGroupOpAddCtrlBlk (
   // Add the CtrlBlk into the instance's GroupCtrlBlkList.\r
   //\r
   CtrlBlk->GroupAddress = GroupAddress;\r
-  NetListInsertTail (&Instance->GroupCtrlBlkList, &CtrlBlk->CtrlBlkEntry);\r
+  InsertTailList (&Instance->GroupCtrlBlkList, &CtrlBlk->CtrlBlkEntry);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -1280,13 +1232,12 @@ MnpGroupOpAddCtrlBlk (
   Delete a group control block from the instance. If the controlled group address's\r
   reference count reaches zero, the group address is removed too.\r
 \r
-  @param  Instance              Pointer to the instance context data.\r
-  @param  CtrlBlk               Pointer to the group control block to delete.\r
+  @param[in]  Instance              Pointer to the instance context data.\r
+  @param[in]  CtrlBlk               Pointer to the group control block to delete.\r
 \r
   @return The group address controlled by the control block is no longer used or not.\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 MnpGroupOpDelCtrlBlk (\r
   IN MNP_INSTANCE_DATA        *Instance,\r
@@ -1305,8 +1256,8 @@ MnpGroupOpDelCtrlBlk (
   // Remove and free the CtrlBlk.\r
   //\r
   GroupAddress = CtrlBlk->GroupAddress;\r
-  NetListRemoveEntry (&CtrlBlk->CtrlBlkEntry);\r
-  NetFreePool (CtrlBlk);\r
+  RemoveEntryList (&CtrlBlk->CtrlBlkEntry);\r
+  gBS->FreePool (CtrlBlk);\r
 \r
   ASSERT (GroupAddress->RefCnt > 0);\r
 \r
@@ -1320,8 +1271,8 @@ MnpGroupOpDelCtrlBlk (
     // Free this GroupAddress entry if no instance uses it.\r
     //\r
     MnpServiceData->GroupAddressCount--;\r
-    NetListRemoveEntry (&GroupAddress->AddrEntry);\r
-    NetFreePool (GroupAddress);\r
+    RemoveEntryList (&GroupAddress->AddrEntry);\r
+    gBS->FreePool (GroupAddress);\r
 \r
     return TRUE;\r
   }\r
@@ -1333,28 +1284,29 @@ MnpGroupOpDelCtrlBlk (
 /**\r
   Do the group operations for this instance.\r
 \r
-  @param  Instance              Pointer to the instance context data.\r
-  @param  JoinFlag              Set to TRUE to join a group. Set to TRUE to leave a\r
-                                group/groups.\r
-  @param  MacAddress            Pointer to the group address to join or leave.\r
-  @param  CtrlBlk               Pointer to the group control block if JoinFlag if\r
-                                FALSE.\r
+  @param[in, out]  Instance        Pointer to the instance context data.\r
+  @param[in]       JoinFlag        Set to TRUE to join a group. Set to TRUE to \r
+                                   leave a group/groups.\r
+  @param[in]       MacAddress      Pointer to the group address to join or leave.\r
+  @param[in]       CtrlBlk         Pointer to the group control block if JoinFlag \r
+                                   is FALSE.\r
 \r
-  @retval EFI_SUCCESS           The group operation finished.\r
-  @retval Other                 Some error occurs.\r
+  @retval EFI_SUCCESS              The group operation finished.\r
+  @retval EFI_OUT_OF_RESOURCES     Failed due to lack of memory resources.\r
+  @retval Others                   Other errors as indicated.\r
 \r
 **/\r
 EFI_STATUS\r
 MnpGroupOp (\r
-  IN MNP_INSTANCE_DATA        *Instance,\r
+  IN OUT MNP_INSTANCE_DATA    *Instance,\r
   IN BOOLEAN                  JoinFlag,\r
   IN EFI_MAC_ADDRESS          *MacAddress OPTIONAL,\r
   IN MNP_GROUP_CONTROL_BLOCK  *CtrlBlk OPTIONAL\r
   )\r
 {\r
   MNP_SERVICE_DATA        *MnpServiceData;\r
-  NET_LIST_ENTRY          *Entry;\r
-  NET_LIST_ENTRY          *NextEntry;\r
+  LIST_ENTRY              *Entry;\r
+  LIST_ENTRY              *NextEntry;\r
   MNP_GROUP_ADDRESS       *GroupAddress;\r
   EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
   MNP_GROUP_CONTROL_BLOCK *NewCtrlBlk;\r
@@ -1378,10 +1330,10 @@ MnpGroupOp (
     //\r
     // Allocate memory for the control block.\r
     //\r
-    NewCtrlBlk    = NetAllocatePool (sizeof (MNP_GROUP_CONTROL_BLOCK));\r
+    NewCtrlBlk    = AllocatePool (sizeof (MNP_GROUP_CONTROL_BLOCK));\r
     if (NewCtrlBlk == NULL) {\r
 \r
-      MNP_DEBUG_ERROR (("MnpGroupOp: Failed to allocate memory resource.\n"));\r
+      DEBUG ((EFI_D_ERROR, "MnpGroupOp: Failed to allocate memory resource.\n"));\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
@@ -1390,7 +1342,7 @@ MnpGroupOp (
       // Check whether the MacAddress is already joined by other instances.\r
       //\r
       GroupAddress = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);\r
-      if (0 == NetCompareMem (\r
+      if (0 == CompareMem (\r
                 MacAddress,\r
                 &GroupAddress->Address,\r
                 SnpMode->HwAddressSize\r