X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Nt32Pkg%2FSnpNt32Dxe%2FSnpNt32.c;h=88c2e22badfab7414b9182d0b6e464bfd349e594;hb=9d2eedba985bea28c8821691355d447d61f4f6ed;hp=be9eb78fb5c0066b71691dc241a3b23b63591218;hpb=a00ec39b52224a40bf9a0a813b69cb43e14407a8;p=mirror_edk2.git diff --git a/Nt32Pkg/SnpNt32Dxe/SnpNt32.c b/Nt32Pkg/SnpNt32Dxe/SnpNt32.c index be9eb78fb5..88c2e22bad 100644 --- a/Nt32Pkg/SnpNt32Dxe/SnpNt32.c +++ b/Nt32Pkg/SnpNt32Dxe/SnpNt32.c @@ -1,13 +1,7 @@ /** @file -Copyright (c) 2006 - 2009, 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. +Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent Module Name: @@ -393,6 +387,9 @@ SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate = { NULL, NULL }, // Entry + NULL, // RecycledTxBuf + 0, // RecycledTxBufCount + 32, // MaxRecycledTxBuf NULL, // GlobalData NULL, // DeviceHandle NULL, // DevicePath @@ -440,7 +437,7 @@ SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate = { NET_IFTYPE_ETHERNET, // IfType FALSE, // MacAddressChangeable FALSE, // MultipleTxSupported - FALSE, // MediaPresentSupported + TRUE, // MediaPresentSupported TRUE // MediaPresent }, { @@ -704,7 +701,7 @@ SnpNt32ReceiveFilters ( ReturnValue = GlobalData->NtNetUtilityTable.SetReceiveFilter ( Instance->InterfaceInfo.InterfaceIndex, EnableBits, - McastFilterCount, + (UINT32)McastFilterCount, McastFilter ); @@ -861,9 +858,17 @@ SnpNt32GetStatus ( OUT VOID **TxBuffer ) { + SNPNT32_INSTANCE_DATA *Instance; + + Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This); if (TxBuffer != NULL) { - *((UINT8 **) TxBuffer) = (UINT8 *) 1; + if (Instance->RecycledTxBufCount != 0) { + Instance->RecycledTxBufCount --; + *((UINT8 **) TxBuffer) = (UINT8 *) (UINTN)Instance->RecycledTxBuf[Instance->RecycledTxBufCount]; + } else { + *((UINT8 **) TxBuffer) = NULL; + } } if (InterruptStatus != NULL) { @@ -918,6 +923,7 @@ SnpNt32Transmit ( SNPNT32_INSTANCE_DATA *Instance; SNPNT32_GLOBAL_DATA *GlobalData; INT32 ReturnValue; + UINT64 *Tmp; Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This); @@ -933,8 +939,8 @@ SnpNt32Transmit ( ReturnValue = GlobalData->NtNetUtilityTable.Transmit ( Instance->InterfaceInfo.InterfaceIndex, - HeaderSize, - BufferSize, + (UINT32)HeaderSize, + (UINT32)BufferSize, Buffer, SrcAddr, DestAddr, @@ -945,6 +951,24 @@ SnpNt32Transmit ( if (ReturnValue < 0) { return EFI_DEVICE_ERROR; + } else { + if ((Instance->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >= SNP_MAX_TX_BUFFER_NUM) { + return EFI_NOT_READY; + } + + if (Instance->RecycledTxBufCount < Instance->MaxRecycledTxBuf) { + Instance->RecycledTxBuf[Instance->RecycledTxBufCount] = (UINT64) Buffer; + Instance->RecycledTxBufCount ++; + } else { + Tmp = AllocatePool (sizeof (UINT64) * (Instance->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT)); + if (Tmp == NULL) { + return EFI_DEVICE_ERROR; + } + CopyMem (Tmp, Instance->RecycledTxBuf, sizeof (UINT64) * Instance->RecycledTxBufCount); + FreePool (Instance->RecycledTxBuf); + Instance->RecycledTxBuf = Tmp; + Instance->MaxRecycledTxBuf += SNP_TX_BUFFER_INCREASEMENT; + } } return EFI_SUCCESS; @@ -995,6 +1019,9 @@ SnpNt32Receive ( SNPNT32_INSTANCE_DATA *Instance; SNPNT32_GLOBAL_DATA *GlobalData; INT32 ReturnValue; + UINTN BufSize; + + BufSize = *BuffSize; Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This); @@ -1042,7 +1069,7 @@ SnpNt32Receive ( *Protocol = NTOHS (*((UINT16 *) (((UINT8 *) Buffer) + 12))); } - return EFI_SUCCESS; + return (*BuffSize <= BufSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL; } /** @@ -1172,7 +1199,7 @@ SnpNt32InitializeGlobalData ( // for (Index = 0; Index < InterfaceCount; Index++) { - Instance = AllocatePool (sizeof (SNPNT32_INSTANCE_DATA)); + Instance = AllocateZeroPool (sizeof (SNPNT32_INSTANCE_DATA)); if (NULL == Instance) { Status = EFI_OUT_OF_RESOURCES; @@ -1183,10 +1210,18 @@ SnpNt32InitializeGlobalData ( // CopyMem (Instance, &gSnpNt32InstanceTemplate, sizeof (SNPNT32_INSTANCE_DATA)); + // + // Allocate the RecycledTxBuf. + // + Instance->RecycledTxBuf = AllocatePool (sizeof (UINT64) * Instance->MaxRecycledTxBuf); + if (Instance->RecycledTxBuf == NULL) { + return EFI_OUT_OF_RESOURCES; + } + // // Set the interface information. // - Instance->InterfaceInfo = NetInterfaceInfoBuffer[Index]; + CopyMem (&Instance->InterfaceInfo, &NetInterfaceInfoBuffer[Index], sizeof(Instance->InterfaceInfo)); // // Initialize this instance // @@ -1262,8 +1297,8 @@ SnpNt32InitializeInstanceData ( // // Copy Current/PermanentAddress MAC address // - Instance->Mode.CurrentAddress = Instance->InterfaceInfo.MacAddr; - Instance->Mode.PermanentAddress = Instance->InterfaceInfo.MacAddr; + CopyMem (&Instance->Mode.CurrentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.CurrentAddress)); + CopyMem (&Instance->Mode.PermanentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.PermanentAddress)); // // Since the fake SNP is based on a real NIC, to avoid conflict with the host