X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FMnpDxe%2FMnpConfig.c;h=94bbe18847e37fb3e484bc646ba0152147cdd5d8;hp=d03be7fc030aab2605698cbd588ea62de52920af;hb=c57273b0d88617dc88b065486c647c21757ce1a7;hpb=e48e37fce2611df7a52aff271835ff72ee396d9b diff --git a/MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c b/MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c index d03be7fc03..94bbe18847 100644 --- a/MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c +++ b/MdeModulePkg/Universal/Network/MnpDxe/MnpConfig.c @@ -1,23 +1,15 @@ /** @file + Implementation of Managed Network Protocol private services. -Copyright (c) 2005 - 2007, Intel Corporation -All rights reserved. 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 -http://opensource.org/licenses/bsd-license.php +Copyright (c) 2005 - 2008, Intel Corporation.
+All rights reserved. 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 +http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - MnpConfig.c - -Abstract: - - Implementation of Managed Network Protocol private services. - - **/ @@ -52,76 +44,175 @@ EFI_MANAGED_NETWORK_CONFIG_DATA mMnpDefaultConfigData = { FALSE }; -STATIC -EFI_STATUS -MnpAddFreeNbuf ( - IN MNP_SERVICE_DATA *MnpServiceData, - IN UINTN Count - ); - -STATIC -EFI_STATUS -MnpStartSnp ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp - ); - -STATIC -EFI_STATUS -MnpStopSnp ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp - ); +/** + Configure the Snp receive filters according to the instances' receive filter + settings. -STATIC -EFI_STATUS -MnpStart ( - IN MNP_SERVICE_DATA *MnpServiceData, - IN BOOLEAN IsConfigUpdate, - IN BOOLEAN EnableSystemPoll - ); + @param MnpServiceData Pointer to the mnp service context data. -STATIC -EFI_STATUS -MnpStop ( - IN MNP_SERVICE_DATA *MnpServiceData - ); + @retval EFI_SUCCESS The receive filters is configured. + @retval EFI_OUT_OF_RESOURCES The receive filters can't be configured due to + lack of memory resource. -STATIC +**/ EFI_STATUS MnpConfigReceiveFilters ( IN MNP_SERVICE_DATA *MnpServiceData - ); + ) +{ + EFI_STATUS Status; + EFI_SIMPLE_NETWORK_PROTOCOL *Snp; + EFI_MAC_ADDRESS *MCastFilter; + UINT32 MCastFilterCnt; + UINT32 EnableFilterBits; + UINT32 DisableFilterBits; + BOOLEAN ResetMCastFilters; + LIST_ENTRY *Entry; + UINT32 Index; + MNP_GROUP_ADDRESS *GroupAddress; -STATIC -EFI_STATUS -MnpGroupOpAddCtrlBlk ( - IN MNP_INSTANCE_DATA *Instance, - IN MNP_GROUP_CONTROL_BLOCK *CtrlBlk, - IN MNP_GROUP_ADDRESS *GroupAddress OPTIONAL, - IN EFI_MAC_ADDRESS *MacAddress, - IN UINT32 HwAddressSize - ); + NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE); -STATIC -BOOLEAN -MnpGroupOpDelCtrlBlk ( - IN MNP_INSTANCE_DATA *Instance, - IN MNP_GROUP_CONTROL_BLOCK *CtrlBlk + Snp = MnpServiceData->Snp; + + // + // Initialize the enable filter and disable filter. + // + EnableFilterBits = 0; + DisableFilterBits = Snp->Mode->ReceiveFilterMask; + + if (MnpServiceData->UnicastCount != 0) { + // + // Enable unicast if any instance wants to receive unicast. + // + EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST; + } + + if (MnpServiceData->BroadcastCount != 0) { + // + // Enable broadcast if any instance wants to receive broadcast. + // + EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST; + } + + MCastFilter = NULL; + MCastFilterCnt = 0; + ResetMCastFilters = TRUE; + + if ((MnpServiceData->MulticastCount != 0) && (MnpServiceData->GroupAddressCount != 0)) { + // + // There are instances configured to receive multicast and already some group + // addresses are joined. + // + + ResetMCastFilters = FALSE; + + if (MnpServiceData->GroupAddressCount <= Snp->Mode->MaxMCastFilterCount) { + // + // The joind group address is less than simple network's maximum count. + // Just configure the snp to do the multicast filtering. + // + + EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST; + + // + // Allocate pool for the mulicast addresses. + // + MCastFilterCnt = MnpServiceData->GroupAddressCount; + MCastFilter = AllocatePool (sizeof (EFI_MAC_ADDRESS) * MCastFilterCnt); + if (MCastFilter == NULL) { + + DEBUG ((EFI_D_ERROR, "MnpConfigReceiveFilters: Failed to allocate memory resource for MCastFilter.\n")); + return EFI_OUT_OF_RESOURCES; + } + + // + // Fill the multicast HW address buffer. + // + Index = 0; + NET_LIST_FOR_EACH (Entry, &MnpServiceData->GroupAddressList) { + + GroupAddress = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry); + CopyMem (MCastFilter + Index, &GroupAddress->Address, sizeof (*(MCastFilter + Index))); + Index++; + + ASSERT (Index <= MCastFilterCnt); + } + } else { + // + // The maximum multicast is reached, set the filter to be promiscuous + // multicast. + // + + if (Snp->Mode->ReceiveFilterMask & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) { + EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; + } else { + // + // Either MULTICAST or PROMISCUOUS_MULTICAST is not supported by Snp, + // set the NIC to be promiscuous although this will tremendously degrade + // the performance. + // + EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; + } + } + } + + if (MnpServiceData->PromiscuousCount != 0) { + // + // Enable promiscuous if any instance wants to receive promiscuous. + // + EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; + } + + // + // Set the disable filter. + // + DisableFilterBits ^= EnableFilterBits; + + // + // Configure the receive filters of SNP. + // + Status = Snp->ReceiveFilters ( + Snp, + EnableFilterBits, + DisableFilterBits, + ResetMCastFilters, + MCastFilterCnt, + MCastFilter + ); + DEBUG_CODE ( + if (EFI_ERROR (Status)) { + + DEBUG ( + (EFI_D_ERROR, + "MnpConfigReceiveFilters: Snp->ReceiveFilters failed, %r.\n", + Status) + ); + } ); + if (MCastFilter != NULL) { + // + // Free the buffer used to hold the group addresses. + // + gBS->FreePool (MCastFilter); + } + + return Status; +} /** - Add some NET_BUF into MnpServiceData->FreeNbufQue. The buffer length of - the NET_BUF is specified by MnpServiceData->BufferLength. + Add Count of net buffers to MnpServiceData->FreeNbufQue. The length of the net + buffer is specified by MnpServiceData->BufferLength. @param MnpServiceData Pointer to the MNP_SERVICE_DATA. @param Count Number of NET_BUFFERs to add. - @retval EFI_SUCCESS The specified amount of NET_BUFs are allocated and - added into MnpServiceData->FreeNbufQue. + @retval EFI_SUCCESS The specified amount of NET_BUFs are allocated + and added to MnpServiceData->FreeNbufQue. @retval EFI_OUT_OF_RESOURCES Failed to allocate a NET_BUF structure. **/ -STATIC EFI_STATUS MnpAddFreeNbuf ( IN MNP_SERVICE_DATA *MnpServiceData, @@ -171,7 +262,8 @@ MnpAddFreeNbuf ( @param MnpServiceData Pointer to the MNP_SERVICE_DATA. - @return Pointer to the allocated free NET_BUF structure, if NULL the operation is failed. + @return Pointer to the allocated free NET_BUF structure, if NULL the + operation is failed. **/ NET_BUF * @@ -244,8 +336,6 @@ ON_EXIT: @param MnpServiceData Pointer to the mnp service context data. @param Nbuf Pointer to the NET_BUF to free. - @return None. - **/ VOID MnpFreeNbuf ( @@ -278,7 +368,8 @@ MnpFreeNbuf ( Initialize the mnp service context data. @param MnpServiceData Pointer to the mnp service context data. - @param Snp Pointer to the simple network protocol. + @param ImageHandle The driver image handle. + @param ControllerHandle Handle of device to bind driver to. @retval EFI_SUCCESS The mnp service context is initialized. @retval Other Some error occurs. @@ -463,13 +554,13 @@ ERROR: Flush the mnp service context data. @param MnpServiceData Pointer to the mnp service context data. - - @return None. + @param ImageHandle The driver image handle. **/ VOID MnpFlushServiceData ( - MNP_SERVICE_DATA *MnpServiceData + IN MNP_SERVICE_DATA *MnpServiceData, + IN EFI_HANDLE ImageHandle ) { NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE); @@ -509,6 +600,16 @@ MnpFlushServiceData ( DEBUG ((EFI_D_WARN, "MnpFlushServiceData: Memory leak, MnpServiceData->NbufCnt != 0.\n")); } ); + + // + // Close the Simple Network Protocol. + // + gBS->CloseProtocol ( + MnpServiceData->ControllerHandle, + &gEfiSimpleNetworkProtocolGuid, + ImageHandle, + MnpServiceData->ControllerHandle + ); } @@ -519,8 +620,6 @@ MnpFlushServiceData ( @param Instance Pointer to the mnp instance context data to initialize. - @return None. - **/ VOID MnpInitializeInstanceData ( @@ -603,25 +702,24 @@ MnpTokenExist ( return EFI_SUCCESS; } - /** Cancel the token specified by Arg if it matches the token in Item. - @param Map Pointer to the NET_MAP. - @param Item Pointer to the NET_MAP_ITEM - @param Arg Pointer to the Arg, it's a pointer to the token to - cancel. + @param Map Pointer to the NET_MAP. + @param Item Pointer to the NET_MAP_ITEM + @param Arg Pointer to the Arg, it's a pointer to the token to + cancel. - @retval EFI_SUCCESS The Arg is NULL, and the token in Item is - cancelled, or the Arg isn't NULL, and the token in - Item is different from the Arg. - @retval EFI_ABORTED The Arg isn't NULL, the token in Item mathces the - Arg, and the token is cancelled. + @retval EFI_SUCCESS The Arg is NULL, and the token in Item is cancelled, + or the Arg isn't NULL, and the token in Item is + different from the Arg. + @retval EFI_ABORTED The Arg isn't NULL, the token in Item mathces the + Arg, and the token is cancelled. **/ EFI_STATUS MnpCancelTokens ( - IN NET_MAP *Map, + IN OUT NET_MAP *Map, IN NET_MAP_ITEM *Item, IN VOID *Arg ) @@ -668,7 +766,6 @@ MnpCancelTokens ( @retval Other Some error occurs. **/ -STATIC EFI_STATUS MnpStartSnp ( IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp @@ -703,7 +800,6 @@ MnpStartSnp ( @retval Other Some error occurs. **/ -STATIC EFI_STATUS MnpStopSnp ( IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp @@ -735,7 +831,7 @@ MnpStopSnp ( @param MnpServiceData Pointer to the mnp service context data. @param IsConfigUpdate The instance is reconfigured or it's the first time - the instanced is configured. + the instanced is configured. @param EnableSystemPoll Enable the system polling or not. @retval EFI_SUCCESS The managed network is started and some @@ -743,7 +839,6 @@ MnpStopSnp ( @retval Other Some error occurs. **/ -STATIC EFI_STATUS MnpStart ( IN MNP_SERVICE_DATA *MnpServiceData, @@ -832,7 +927,6 @@ ErrorExit: @retval Other Some error occurs. **/ -STATIC EFI_STATUS MnpStop ( IN MNP_SERVICE_DATA *MnpServiceData @@ -892,8 +986,6 @@ MnpStop ( @param Instance Pointer to the mnp instance context data. - @return None. - **/ VOID MnpFlushRcvdDataQueue ( @@ -1065,164 +1157,6 @@ MnpConfigureInstance ( } -/** - Configure the Snp receive filters according to the instances' receive filter - settings. - - @param MnpServiceData Pointer to the mnp service context data. - - @retval EFI_SUCCESS The receive filters is configured. - @retval EFI_OUT_OF_RESOURCES The receive filters can't be configured due to lack - of memory resource. - -**/ -STATIC -EFI_STATUS -MnpConfigReceiveFilters ( - IN MNP_SERVICE_DATA *MnpServiceData - ) -{ - EFI_STATUS Status; - EFI_SIMPLE_NETWORK_PROTOCOL *Snp; - EFI_MAC_ADDRESS *MCastFilter; - UINT32 MCastFilterCnt; - UINT32 EnableFilterBits; - UINT32 DisableFilterBits; - BOOLEAN ResetMCastFilters; - LIST_ENTRY *Entry; - UINT32 Index; - MNP_GROUP_ADDRESS *GroupAddress; - - NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE); - - Snp = MnpServiceData->Snp; - - // - // Initialize the enable filter and disable filter. - // - EnableFilterBits = 0; - DisableFilterBits = Snp->Mode->ReceiveFilterMask; - - if (MnpServiceData->UnicastCount != 0) { - // - // Enable unicast if any instance wants to receive unicast. - // - EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST; - } - - if (MnpServiceData->BroadcastCount != 0) { - // - // Enable broadcast if any instance wants to receive broadcast. - // - EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST; - } - - MCastFilter = NULL; - MCastFilterCnt = 0; - ResetMCastFilters = TRUE; - - if ((MnpServiceData->MulticastCount != 0) && (MnpServiceData->GroupAddressCount != 0)) { - // - // There are instances configured to receive multicast and already some group - // addresses are joined. - // - - ResetMCastFilters = FALSE; - - if (MnpServiceData->GroupAddressCount <= Snp->Mode->MaxMCastFilterCount) { - // - // The joind group address is less than simple network's maximum count. - // Just configure the snp to do the multicast filtering. - // - - EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST; - - // - // Allocate pool for the mulicast addresses. - // - MCastFilterCnt = MnpServiceData->GroupAddressCount; - MCastFilter = AllocatePool (sizeof (EFI_MAC_ADDRESS) * MCastFilterCnt); - if (MCastFilter == NULL) { - - DEBUG ((EFI_D_ERROR, "MnpConfigReceiveFilters: Failed to allocate memory resource for MCastFilter.\n")); - return EFI_OUT_OF_RESOURCES; - } - - // - // Fill the multicast HW address buffer. - // - Index = 0; - NET_LIST_FOR_EACH (Entry, &MnpServiceData->GroupAddressList) { - - GroupAddress = NET_LIST_USER_STRUCT (Entry, MNP_GROUP_ADDRESS, AddrEntry); - CopyMem (MCastFilter + Index, &GroupAddress->Address, sizeof (*(MCastFilter + Index))); - Index++; - - ASSERT (Index <= MCastFilterCnt); - } - } else { - // - // The maximum multicast is reached, set the filter to be promiscuous - // multicast. - // - - if (Snp->Mode->ReceiveFilterMask & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) { - EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; - } else { - // - // Either MULTICAST or PROMISCUOUS_MULTICAST is not supported by Snp, - // set the NIC to be promiscuous although this will tremendously degrade - // the performance. - // - EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; - } - } - } - - if (MnpServiceData->PromiscuousCount != 0) { - // - // Enable promiscuous if any instance wants to receive promiscuous. - // - EnableFilterBits |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; - } - - // - // Set the disable filter. - // - DisableFilterBits ^= EnableFilterBits; - - // - // Configure the receive filters of SNP. - // - Status = Snp->ReceiveFilters ( - Snp, - EnableFilterBits, - DisableFilterBits, - ResetMCastFilters, - MCastFilterCnt, - MCastFilter - ); - DEBUG_CODE ( - if (EFI_ERROR (Status)) { - - DEBUG ( - (EFI_D_ERROR, - "MnpConfigReceiveFilters: Snp->ReceiveFilters failed, %r.\n", - Status) - ); - } - ); - - if (MCastFilter != NULL) { - // - // Free the buffer used to hold the group addresses. - // - gBS->FreePool (MCastFilter); - } - - return Status; -} - /** Add a group address control block which controls the MacAddress for @@ -1238,7 +1172,6 @@ MnpConfigReceiveFilters ( @retval EFI_OUT_OF_RESOURCE Failed due to lack of memory resources. **/ -STATIC EFI_STATUS MnpGroupOpAddCtrlBlk ( IN MNP_INSTANCE_DATA *Instance, @@ -1304,7 +1237,6 @@ MnpGroupOpAddCtrlBlk ( @return The group address controlled by the control block is no longer used or not. **/ -STATIC BOOLEAN MnpGroupOpDelCtrlBlk ( IN MNP_INSTANCE_DATA *Instance,