]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c
Change the file headers and some function comments.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpConfig.c
index d03be7fc030aab2605698cbd588ea62de52920af..94bbe18847e37fb3e484bc646ba0152147cdd5d8 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 - 2008, 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
@@ -52,76 +44,175 @@ 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
+  Configure the Snp receive filters according to the instances' receive filter\r
+  settings.\r
 \r
-STATIC\r
-EFI_STATUS\r
-MnpStart (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData,\r
-  IN BOOLEAN           IsConfigUpdate,\r
-  IN BOOLEAN           EnableSystemPoll\r
-  );\r
+  @param  MnpServiceData        Pointer to the mnp service context data.\r
 \r
-STATIC\r
-EFI_STATUS\r
-MnpStop (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\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 \r
+                                lack of memory resource.\r
 \r
-STATIC\r
+**/\r
 EFI_STATUS\r
 MnpConfigReceiveFilters (\r
   IN MNP_SERVICE_DATA  *MnpServiceData\r
-  );\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
+  EFI_MAC_ADDRESS             *MCastFilter;\r
+  UINT32                      MCastFilterCnt;\r
+  UINT32                      EnableFilterBits;\r
+  UINT32                      DisableFilterBits;\r
+  BOOLEAN                     ResetMCastFilters;\r
+  LIST_ENTRY                  *Entry;\r
+  UINT32                      Index;\r
+  MNP_GROUP_ADDRESS           *GroupAddress;\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
+  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
 \r
-STATIC\r
-BOOLEAN\r
-MnpGroupOpDelCtrlBlk (\r
-  IN MNP_INSTANCE_DATA        *Instance,\r
-  IN MNP_GROUP_CONTROL_BLOCK  *CtrlBlk\r
+  Snp = MnpServiceData->Snp;\r
+\r
+  //\r
+  // Initialize the enable filter and disable filter.\r
+  //\r
+  EnableFilterBits  = 0;\r
+  DisableFilterBits = Snp->Mode->ReceiveFilterMask;\r
+\r
+  if (MnpServiceData->UnicastCount != 0) {\r
+    //\r
+    // Enable unicast if any instance wants to receive unicast.\r
+    //\r
+    EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST;\r
+  }\r
+\r
+  if (MnpServiceData->BroadcastCount != 0) {\r
+    //\r
+    // Enable broadcast if any instance wants to receive broadcast.\r
+    //\r
+    EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST;\r
+  }\r
+\r
+  MCastFilter       = NULL;\r
+  MCastFilterCnt    = 0;\r
+  ResetMCastFilters = TRUE;\r
+\r
+  if ((MnpServiceData->MulticastCount != 0) && (MnpServiceData->GroupAddressCount != 0)) {\r
+    //\r
+    // There are instances configured to receive multicast and already some group\r
+    // addresses are joined.\r
+    //\r
+\r
+    ResetMCastFilters = FALSE;\r
+\r
+    if (MnpServiceData->GroupAddressCount <= Snp->Mode->MaxMCastFilterCount) {\r
+      //\r
+      // The joind group address is less than simple network's maximum count.\r
+      // Just configure the snp to do the multicast filtering.\r
+      //\r
+\r
+      EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST;\r
+\r
+      //\r
+      // Allocate pool for the mulicast addresses.\r
+      //\r
+      MCastFilterCnt  = MnpServiceData->GroupAddressCount;\r
+      MCastFilter     = AllocatePool (sizeof (EFI_MAC_ADDRESS) * MCastFilterCnt);\r
+      if (MCastFilter == NULL) {\r
+\r
+        DEBUG ((EFI_D_ERROR, "MnpConfigReceiveFilters: Failed to allocate memory resource for MCastFilter.\n"));\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      //\r
+      // Fill the multicast HW address buffer.\r
+      //\r
+      Index = 0;\r
+      NET_LIST_FOR_EACH (Entry, &MnpServiceData->GroupAddressList) {\r
+\r
+        GroupAddress            = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);\r
+        CopyMem (MCastFilter + Index, &GroupAddress->Address, sizeof (*(MCastFilter + Index)));\r
+        Index++;\r
+\r
+        ASSERT (Index <= MCastFilterCnt);\r
+      }\r
+    } else {\r
+      //\r
+      // The maximum multicast is reached, set the filter to be promiscuous\r
+      // multicast.\r
+      //\r
+\r
+      if (Snp->Mode->ReceiveFilterMask & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) {\r
+        EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;\r
+      } else {\r
+        //\r
+        // Either MULTICAST or PROMISCUOUS_MULTICAST is not supported by Snp,\r
+        // set the NIC to be promiscuous although this will tremendously degrade\r
+        // the performance.\r
+        //\r
+        EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;\r
+      }\r
+    }\r
+  }\r
+\r
+  if (MnpServiceData->PromiscuousCount != 0) {\r
+    //\r
+    // Enable promiscuous if any instance wants to receive promiscuous.\r
+    //\r
+    EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;\r
+  }\r
+\r
+  //\r
+  // Set the disable filter.\r
+  //\r
+  DisableFilterBits ^= EnableFilterBits;\r
+\r
+  //\r
+  // Configure the receive filters of SNP.\r
+  //\r
+  Status = Snp->ReceiveFilters (\r
+                  Snp,\r
+                  EnableFilterBits,\r
+                  DisableFilterBits,\r
+                  ResetMCastFilters,\r
+                  MCastFilterCnt,\r
+                  MCastFilter\r
+                  );\r
+  DEBUG_CODE (\r
+    if (EFI_ERROR (Status)) {\r
+\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "MnpConfigReceiveFilters: Snp->ReceiveFilters failed, %r.\n",\r
+      Status)\r
+      );\r
+  }\r
   );\r
 \r
+  if (MCastFilter != NULL) {\r
+    //\r
+    // Free the buffer used to hold the group addresses.\r
+    //\r
+    gBS->FreePool (MCastFilter);\r
+  }\r
+\r
+  return Status;\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
 \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
@@ -171,7 +262,8 @@ MnpAddFreeNbuf (
 \r
   @param  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
@@ -244,8 +336,6 @@ ON_EXIT:
   @param  MnpServiceData        Pointer to the mnp service context data.\r
   @param  Nbuf                  Pointer to the NET_BUF to free.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 MnpFreeNbuf (\r
@@ -278,7 +368,8 @@ MnpFreeNbuf (
   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  ImageHandle           The driver image handle.\r
+  @param  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
@@ -463,13 +554,13 @@ ERROR:
   Flush the mnp service context data.\r
 \r
   @param  MnpServiceData        Pointer to the mnp service context data.\r
-\r
-  @return None.\r
+  @param  ImageHandle           The driver image handle.\r
 \r
 **/\r
 VOID\r
 MnpFlushServiceData (\r
-  MNP_SERVICE_DATA  *MnpServiceData\r
+  IN MNP_SERVICE_DATA  *MnpServiceData,\r
+  IN EFI_HANDLE        ImageHandle\r
   )\r
 {\r
   NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
@@ -509,6 +600,16 @@ MnpFlushServiceData (
     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
@@ -519,8 +620,6 @@ MnpFlushServiceData (
   @param  Instance              Pointer to the mnp instance context data to\r
                                 initialize.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 MnpInitializeInstanceData (\r
@@ -603,25 +702,24 @@ 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  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
 \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 OUT NET_MAP   *Map,\r
   IN NET_MAP_ITEM  *Item,\r
   IN VOID          *Arg\r
   )\r
@@ -668,7 +766,6 @@ MnpCancelTokens (
   @retval Other                 Some error occurs.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpStartSnp (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL  *Snp\r
@@ -703,7 +800,6 @@ MnpStartSnp (
   @retval Other                 Some error occurs.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpStopSnp (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL  *Snp\r
@@ -735,7 +831,7 @@ MnpStopSnp (
 \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
+                                the instanced is configured.\r
   @param  EnableSystemPoll      Enable the system polling or not.\r
 \r
   @retval EFI_SUCCESS           The managed network is started and some\r
@@ -743,7 +839,6 @@ MnpStopSnp (
   @retval Other                 Some error occurs.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpStart (\r
   IN MNP_SERVICE_DATA  *MnpServiceData,\r
@@ -832,7 +927,6 @@ ErrorExit:
   @retval Other                 Some error occurs.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpStop (\r
   IN MNP_SERVICE_DATA  *MnpServiceData\r
@@ -892,8 +986,6 @@ MnpStop (
 \r
   @param  Instance              Pointer to the mnp instance context data.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 MnpFlushRcvdDataQueue (\r
@@ -1065,164 +1157,6 @@ MnpConfigureInstance (
 }\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
-\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
-\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-MnpConfigReceiveFilters (\r
-  IN MNP_SERVICE_DATA  *MnpServiceData\r
-  )\r
-{\r
-  EFI_STATUS                  Status;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
-  EFI_MAC_ADDRESS             *MCastFilter;\r
-  UINT32                      MCastFilterCnt;\r
-  UINT32                      EnableFilterBits;\r
-  UINT32                      DisableFilterBits;\r
-  BOOLEAN                     ResetMCastFilters;\r
-  LIST_ENTRY                  *Entry;\r
-  UINT32                      Index;\r
-  MNP_GROUP_ADDRESS           *GroupAddress;\r
-\r
-  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
-\r
-  Snp = MnpServiceData->Snp;\r
-\r
-  //\r
-  // Initialize the enable filter and disable filter.\r
-  //\r
-  EnableFilterBits  = 0;\r
-  DisableFilterBits = Snp->Mode->ReceiveFilterMask;\r
-\r
-  if (MnpServiceData->UnicastCount != 0) {\r
-    //\r
-    // Enable unicast if any instance wants to receive unicast.\r
-    //\r
-    EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST;\r
-  }\r
-\r
-  if (MnpServiceData->BroadcastCount != 0) {\r
-    //\r
-    // Enable broadcast if any instance wants to receive broadcast.\r
-    //\r
-    EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST;\r
-  }\r
-\r
-  MCastFilter       = NULL;\r
-  MCastFilterCnt    = 0;\r
-  ResetMCastFilters = TRUE;\r
-\r
-  if ((MnpServiceData->MulticastCount != 0) && (MnpServiceData->GroupAddressCount != 0)) {\r
-    //\r
-    // There are instances configured to receive multicast and already some group\r
-    // addresses are joined.\r
-    //\r
-\r
-    ResetMCastFilters = FALSE;\r
-\r
-    if (MnpServiceData->GroupAddressCount <= Snp->Mode->MaxMCastFilterCount) {\r
-      //\r
-      // The joind group address is less than simple network's maximum count.\r
-      // Just configure the snp to do the multicast filtering.\r
-      //\r
-\r
-      EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST;\r
-\r
-      //\r
-      // Allocate pool for the mulicast addresses.\r
-      //\r
-      MCastFilterCnt  = MnpServiceData->GroupAddressCount;\r
-      MCastFilter     = AllocatePool (sizeof (EFI_MAC_ADDRESS) * MCastFilterCnt);\r
-      if (MCastFilter == NULL) {\r
-\r
-        DEBUG ((EFI_D_ERROR, "MnpConfigReceiveFilters: Failed to allocate memory resource for MCastFilter.\n"));\r
-        return EFI_OUT_OF_RESOURCES;\r
-      }\r
-\r
-      //\r
-      // Fill the multicast HW address buffer.\r
-      //\r
-      Index = 0;\r
-      NET_LIST_FOR_EACH (Entry, &MnpServiceData->GroupAddressList) {\r
-\r
-        GroupAddress            = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry);\r
-        CopyMem (MCastFilter + Index, &GroupAddress->Address, sizeof (*(MCastFilter + Index)));\r
-        Index++;\r
-\r
-        ASSERT (Index <= MCastFilterCnt);\r
-      }\r
-    } else {\r
-      //\r
-      // The maximum multicast is reached, set the filter to be promiscuous\r
-      // multicast.\r
-      //\r
-\r
-      if (Snp->Mode->ReceiveFilterMask & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) {\r
-        EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;\r
-      } else {\r
-        //\r
-        // Either MULTICAST or PROMISCUOUS_MULTICAST is not supported by Snp,\r
-        // set the NIC to be promiscuous although this will tremendously degrade\r
-        // the performance.\r
-        //\r
-        EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;\r
-      }\r
-    }\r
-  }\r
-\r
-  if (MnpServiceData->PromiscuousCount != 0) {\r
-    //\r
-    // Enable promiscuous if any instance wants to receive promiscuous.\r
-    //\r
-    EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;\r
-  }\r
-\r
-  //\r
-  // Set the disable filter.\r
-  //\r
-  DisableFilterBits ^= EnableFilterBits;\r
-\r
-  //\r
-  // Configure the receive filters of SNP.\r
-  //\r
-  Status = Snp->ReceiveFilters (\r
-                  Snp,\r
-                  EnableFilterBits,\r
-                  DisableFilterBits,\r
-                  ResetMCastFilters,\r
-                  MCastFilterCnt,\r
-                  MCastFilter\r
-                  );\r
-  DEBUG_CODE (\r
-    if (EFI_ERROR (Status)) {\r
-\r
-    DEBUG (\r
-      (EFI_D_ERROR,\r
-      "MnpConfigReceiveFilters: Snp->ReceiveFilters failed, %r.\n",\r
-      Status)\r
-      );\r
-  }\r
-  );\r
-\r
-  if (MCastFilter != NULL) {\r
-    //\r
-    // Free the buffer used to hold the group addresses.\r
-    //\r
-    gBS->FreePool (MCastFilter);\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
 \r
 /**\r
   Add a group address control block which controls the MacAddress for\r
@@ -1238,7 +1172,6 @@ MnpConfigReceiveFilters (
   @retval EFI_OUT_OF_RESOURCE   Failed due to lack of memory resources.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 MnpGroupOpAddCtrlBlk (\r
   IN MNP_INSTANCE_DATA        *Instance,\r
@@ -1304,7 +1237,6 @@ MnpGroupOpAddCtrlBlk (
   @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