<commit_before>/**********************************************************************
 * Copyright (c) 2008  Red Hat, Inc.
 *
 * File: ParaNdis-Common.c
 *
 * This file contains NDIS driver procedures, common for NDIS5 and NDIS6
 *
 * This work is licensed under the terms of the GNU GPL, version 2.  See
 * the COPYING file in the top-level directory.
 *
**********************************************************************/
#include "ndis56common.h"

#ifdef WPP_EVENT_TRACING
#include "ParaNdis-Common.tmh"
#endif

// TODO: remove when the problem solved
void WriteVirtIODeviceByte(ULONG_PTR ulRegister, u8 bValue);

//#define ROUNDSIZE(sz)	((sz + 15) & ~15)


#if 0
void FORCEINLINE DebugDumpPacket(LPCSTR prefix, PVOID header, int level)
{
	PUCHAR peth = (PUCHAR)header;
	DPrintf(level, ("[%s] %02X%02X%02X%02X%02X%02X => %02X%02X%02X%02X%02X%02X", prefix,
		peth[6], peth[7], peth[8], peth[9], peth[10], peth[11],
		peth[0], peth[1], peth[2], peth[3], peth[4], peth[5]));
}
#else
void FORCEINLINE DebugDumpPacket(LPCSTR prefix, PVOID header, int level)
{
}
#endif



/**********************************************************
Validates MAC address
Valid MAC address is not broadcast, not multicast, not empty
if bLocal is set, it must be LOCAL
if not, is must be non-local or local
Parameters:
	PUCHAR pcMacAddress - MAC address to validate
	BOOLEAN bLocal      - TRUE, if we validate locally administered address
Return value:
	TRUE if valid
***********************************************************/
BOOLEAN ParaNdis_ValidateMacAddress(PUCHAR pcMacAddress, BOOLEAN bLocal)
{
	BOOLEAN bLA = FALSE, bEmpty, bBroadcast, bMulticast = FALSE;
	bBroadcast = ETH_IS_BROADCAST(pcMacAddress);
	bLA = !bBroadcast && ETH_IS_LOCALLY_ADMINISTERED(pcMacAddress);
	bMulticast = !bBroadcast && ETH_IS_MULTICAST(pcMacAddress);
	bEmpty = ETH_IS_EMPTY(pcMacAddress);
	return !bBroadcast && !bEmpty && !bMulticast && (!bLocal || bLA);
}

static eInspectedPacketType QueryPacketType(PVOID data)
{
	if (ETH_IS_BROADCAST(data))
		return iptBroadcast;
	if (ETH_IS_MULTICAST(data))
		return iptMilticast;
	return iptUnicast;
}

typedef struct _tagConfigurationEntry
{
	const char		*Name;
	ULONG			ulValue;
	ULONG			ulMinimal;
	ULONG			ulMaximal;
}tConfigurationEntry;

typedef struct _tagConfigurationEntries
{
	tConfigurationEntry isPromiscuous;
	tConfigurationEntry PrioritySupport;
	tConfigurationEntry ConnectRate;
	tConfigurationEntry isLogEnabled;
	tConfigurationEntry debugLevel;
	tConfigurationEntry connectTimer;
	tConfigurationEntry dpcChecker;
	tConfigurationEntry TxCapacity;
	tConfigurationEntry RxCapacity;
	tConfigurationEntry InterruptRecovery;
	tConfigurationEntry LogStatistics;
	tConfigurationEntry HardReset;
	tConfigurationEntry PacketFiltering;
	tConfigurationEntry ScatterGather;
	tConfigurationEntry BatchReceive;
	tConfigurationEntry OffloadTxIP;
	tConfigurationEntry OffloadTxTCP;
	tConfigurationEntry OffloadTxUDP;
	tConfigurationEntry OffloadTxLSO;
	tConfigurationEntry OffloadRxIP;
	tConfigurationEntry HwOffload;
	tConfigurationEntry IPPacketsCheck;
	tConfigurationEntry IPChecksumFix;
	tConfigurationEntry stdIpcsV4;
	tConfigurationEntry stdTcpcsV4;
	tConfigurationEntry stdTcpcsV6;
	tConfigurationEntry stdUdpcsV4;
	tConfigurationEntry stdUdpcsV6;
	tConfigurationEntry stdLsoV1;
	tConfigurationEntry stdLsoV2ip4;
	tConfigurationEntry stdLsoV2ip6;
	tConfigurationEntry PriorityVlanTagging;
	tConfigurationEntry VlanId;
	tConfigurationEntry UseMergeableBuffers;
	tConfigurationEntry PublishIndices;
	tConfigurationEntry MTU;
	tConfigurationEntry NumberOfHandledRXPackersInDPC;
}tConfigurationEntries;

static const tConfigurationEntries defaultConfiguration =
{
	{ "Promiscuous",	0,	0,	1 },
	{ "Priority",		0,	0,	1 },
	{ "ConnectRate",	100,10,10000 },
	{ "DoLog",			1,	0,	1 },
	{ "DebugLevel",		2,	0,	8 },
	{ "ConnectTimer",	0,	0,	300000 },
	{ "DpcCheck",		0,	0,	2 },
	{ "TxCapacity",		64,	16,	1024 },
	{ "RxCapacity",		256, 32, 1024 },
	{ "InterruptRecovery",	0, 0, 1},
	{ "LogStatistics",	0, 0, 10000},
	{ "HardReset",		0, 0, 1},
	{ "PacketFilter",	0, 0, 1},
	{ "Gather",			0, 0, 1},
	{ "BatchReceive",	1, 0, 1},
	{ "Offload.TxIP",	0, 0, 1},
	{ "Offload.TxTCP",	0, 0, 1},
	{ "Offload.TxUDP",	0, 0, 1},
	{ "Offload.TxLSO",	0, 0, 1},
	{ "Offload.RxIP",	0, 0, 1},
	{ "HwOffload",		0, 0, 1 },
	{ "IPPacketsCheck",	0, 0, 1 },
	{ "IPChecksumFix",	1, 0, 1 },
	{ "*IPChecksumOffloadIPv4",	3, 0, 3 },
	{ "*TCPChecksumOffloadIPv4",3, 0, 3 },
	{ "*TCPChecksumOffloadIPv6",3, 0, 3 },
	{ "*UDPChecksumOffloadIPv4",3, 0, 3 },
	{ "*UDPChecksumOffloadIPv6",3, 0, 3 },
	{ "*LsoV1IPv4",	1, 0, 1 },
	{ "*LsoV2IPv4",	1, 0, 1 },
	{ "*LsoV2IPv6",	1, 0, 1 },
	{ "*PriorityVLANTag", 3, 0, 3},
	{ "VlanId", 0, 0, 4095},
	{ "MergeableBuf", 1, 0, 1},
	{ "PublishIndices", 1, 0, 1},
	{ "MTU", 1500, 500, 65500},
	{ "NumberOfHandledRXPackersInDPC", MAX_RX_LOOPS, 1, 10000},
};

static void ParaNdis_ResetVirtIONetDevice(PARANDIS_ADAPTER *pContext)
{
	VirtIODeviceReset(&pContext->IODevice);
	DPrintf(0, ("[%s] Done", __FUNCTION__));
	/* reset all the features in the device */
	WriteVirtIODeviceRegister(pContext->IODevice.addr + VIRTIO_PCI_GUEST_FEATURES, 0);
#ifdef VIRTIO_RESET_VERIFY
	if (1)
	{
		u8 devStatus;
		devStatus = ReadVirtIODeviceByte(pContext->IODevice.addr + VIRTIO_PCI_STATUS);
		if (devStatus)
		{
			DPrintf(0, ("[%s] Device status is still %02X", __FUNCTION__, (ULONG)devStatus));
			VirtIODeviceReset(&pContext->IODevice);
			devStatus = ReadVirtIODeviceByte(pContext->IODevice.addr + VIRTIO_PCI_STATUS);
			DPrintf(0, ("[%s] Device status on retry %02X", __FUNCTION__, (ULONG)devStatus));
		}
	}
#endif
}

/**********************************************************
Gets integer value for specifies in pEntry->Name name
Parameters:
	NDIS_HANDLE cfg  previously open configuration
	tConfigurationEntry *pEntry - Entry to fill value in
***********************************************************/
static void	GetConfigurationEntry(NDIS_HANDLE cfg, tConfigurationEntry *pEntry)
{
	NDIS_STATUS status;
	const char *statusName;
	NDIS_STRING name;
	PNDIS_CONFIGURATION_PARAMETER pParam = NULL;
	NDIS_PARAMETER_TYPE ParameterType = NdisParameterInteger;
	NdisInitializeString(&name, (PUCHAR)pEntry->Name);
	NdisReadConfiguration(
		&status,
		&pParam,
		cfg,
		&name,
		ParameterType);
	if (status == NDIS_STATUS_SUCCESS)
	{
		ULONG ulValue = pParam->ParameterData.IntegerData;
		if (ulValue >= pEntry->ulMinimal && ulValue <= pEntry->ulMaximal)
		{
			pEntry->ulValue = ulValue;
			statusName = "value";
		}
		else
		{
			statusName = "out of range";
		}
	}
	else
	{
		statusName = "nothing";
	}
	DPrintf(2, ("[%s] %s read for %s - 0x%x",
		__FUNCTION__,
		statusName,
		pEntry->Name,
		pEntry->ulValue));
	NdisFreeString(name);
}

static __inline void DisableLSOPermanently(PARANDIS_ADAPTER *pContext, LPCSTR procname, LPCSTR reason)
{
	if (pContext->Offload.flagsValue & osbT4Lso)
	{
		DPrintf(0, ("[%s] Warning: %s", procname, reason));
		pContext->Offload.flagsValue &= ~osbT4Lso;
		ParaNdis_ResetOffloadSettings(pContext, NULL, NULL);
	}
}

/**********************************************************
Loads NIC parameters from adapter registry key
Parameters:
	context
	PUCHAR *ppNewMACAddress - pointer to hold MAC address if configured from host
***********************************************************/
static void ReadNicConfiguration(PARANDIS_ADAPTER *pContext, PUCHAR *ppNewMACAddress)
{
	NDIS_HANDLE cfg;
	tConfigurationEntries *pConfiguration = ParaNdis_AllocateMemory(pContext, sizeof(tConfigurationEntries));
	if (pConfiguration)
	{
		*pConfiguration = defaultConfiguration;
		cfg = ParaNdis_OpenNICConfiguration(pContext);
		if (cfg)
		{
			GetConfigurationEntry(cfg, &pConfiguration->isLogEnabled);
			GetConfigurationEntry(cfg, &pConfiguration->debugLevel);
			GetConfigurationEntry(cfg, &pConfiguration->ConnectRate);
			GetConfigurationEntry(cfg, &pConfiguration->PrioritySupport);
			GetConfigurationEntry(cfg, &pConfiguration->isPromiscuous);
			GetConfigurationEntry(cfg, &pConfiguration->TxCapacity);
			GetConfigurationEntry(cfg, &pConfiguration->RxCapacity);
			GetConfigurationEntry(cfg, &pConfiguration->connectTimer);
			GetConfigurationEntry(cfg, &pConfiguration->dpcChecker);
			GetConfigurationEntry(cfg, &pConfiguration->InterruptRecovery);
			GetConfigurationEntry(cfg, &pConfiguration->LogStatistics);
			GetConfigurationEntry(cfg, &pConfiguration->HardReset);
			GetConfigurationEntry(cfg, &pConfiguration->PacketFiltering);
			GetConfigurationEntry(cfg, &pConfiguration->ScatterGather);
			GetConfigurationEntry(cfg, &pConfiguration->BatchReceive);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadTxIP);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadTxTCP);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadTxUDP);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadTxLSO);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadRxIP);
			GetConfigurationEntry(cfg, &pConfiguration->HwOffload);
			GetConfigurationEntry(cfg, &pConfiguration->IPPacketsCheck);
			GetConfigurationEntry(cfg, &pConfiguration->IPChecksumFix);
			GetConfigurationEntry(cfg, &pConfiguration->stdIpcsV4);
			GetConfigurationEntry(cfg, &pConfiguration->stdTcpcsV4);
			GetConfigurationEntry(cfg, &pConfiguration->stdTcpcsV6);
			GetConfigurationEntry(cfg, &pConfiguration->stdUdpcsV4);
			GetConfigurationEntry(cfg, &pConfiguration->stdUdpcsV6);
			GetConfigurationEntry(cfg, &pConfiguration->stdLsoV1);
			GetConfigurationEntry(cfg, &pConfiguration->stdLsoV2ip4);
			GetConfigurationEntry(cfg, &pConfiguration->stdLsoV2ip6);
			GetConfigurationEntry(cfg, &pConfiguration->PriorityVlanTagging);
			GetConfigurationEntry(cfg, &pConfiguration->VlanId);
			GetConfigurationEntry(cfg, &pConfiguration->UseMergeableBuffers);
			GetConfigurationEntry(cfg, &pConfiguration->PublishIndices);
			GetConfigurationEntry(cfg, &pConfiguration->MTU);
			GetConfigurationEntry(cfg, &pConfiguration->NumberOfHandledRXPackersInDPC);

	#if !defined(WPP_EVENT_TRACING)
			bDebugPrint = pConfiguration->isLogEnabled.ulValue;
			nDebugLevel = pConfiguration->debugLevel.ulValue;
	#endif
			// ignoring promiscuous setting, nothing to do with it
			pContext->maxFreeTxDescriptors = pConfiguration->TxCapacity.ulValue;
			pContext->NetMaxReceiveBuffers = pConfiguration->RxCapacity.ulValue;
			pContext->ulMilliesToConnect = pConfiguration->connectTimer.ulValue;
			pContext->nEnableDPCChecker = pConfiguration->dpcChecker.ulValue;
			pContext->bDoInterruptRecovery = pConfiguration->InterruptRecovery.ulValue != 0;
			pContext->Limits.nPrintDiagnostic = pConfiguration->LogStatistics.ulValue;
			pContext->uNumberOfHandledRXPacketsInDPC = pConfiguration->NumberOfHandledRXPackersInDPC.ulValue;
			pContext->bDoHardReset = pConfiguration->HardReset.ulValue != 0;
			pContext->bDoSupportPriority = pConfiguration->PrioritySupport.ulValue != 0;
			pContext->ulFormalLinkSpeed  = pConfiguration->ConnectRate.ulValue * 1000000;
			pContext->ulFormalLinkSpeed *= 1000000;
			pContext->bDoPacketFiltering = pConfiguration->PacketFiltering.ulValue != 0;
			pContext->bUseScatterGather  = pConfiguration->ScatterGather.ulValue != 0;
			pContext->bBatchReceive      = pConfiguration->BatchReceive.ulValue != 0;
			pContext->bDoHardwareOffload = pConfiguration->HwOffload.ulValue != 0;
			pContext->bDoIPCheck = pConfiguration->IPPacketsCheck.ulValue != 0;
			pContext->bFixIPChecksum = pConfiguration->IPChecksumFix.ulValue != 0;
			pContext->Offload.flagsValue = 0;
			if (pConfiguration->OffloadTxIP.ulValue) pContext->Offload.flagsValue |= osbT4IpChecksum | osbT4IpOptionsChecksum;
			if (pConfiguration->OffloadTxTCP.ulValue) pContext->Offload.flagsValue |= osbT4TcpChecksum | osbT4TcpOptionsChecksum;
			if (pConfiguration->OffloadTxUDP.ulValue) pContext->Offload.flagsValue |= osbT4UdpChecksum;
			if (pConfiguration->OffloadTxLSO.ulValue) pContext->Offload.flagsValue |= osbT4Lso | osbT4LsoIp | osbT4LsoTcp;
			if (pConfiguration->OffloadRxIP.ulValue) pContext->Offload.flagsValue |= osbT4IpRxChecksum | osbT4IpOptionsChecksum;<commit_msg>[NetKVM] fixing wrong connection rate report<commit_after>/**********************************************************************
 * Copyright (c) 2008  Red Hat, Inc.
 *
 * File: ParaNdis-Common.c
 *
 * This file contains NDIS driver procedures, common for NDIS5 and NDIS6
 *
 * This work is licensed under the terms of the GNU GPL, version 2.  See
 * the COPYING file in the top-level directory.
 *
**********************************************************************/
#include "ndis56common.h"

#ifdef WPP_EVENT_TRACING
#include "ParaNdis-Common.tmh"
#endif

// TODO: remove when the problem solved
void WriteVirtIODeviceByte(ULONG_PTR ulRegister, u8 bValue);

//#define ROUNDSIZE(sz)	((sz + 15) & ~15)


#if 0
void FORCEINLINE DebugDumpPacket(LPCSTR prefix, PVOID header, int level)
{
	PUCHAR peth = (PUCHAR)header;
	DPrintf(level, ("[%s] %02X%02X%02X%02X%02X%02X => %02X%02X%02X%02X%02X%02X", prefix,
		peth[6], peth[7], peth[8], peth[9], peth[10], peth[11],
		peth[0], peth[1], peth[2], peth[3], peth[4], peth[5]));
}
#else
void FORCEINLINE DebugDumpPacket(LPCSTR prefix, PVOID header, int level)
{
}
#endif



/**********************************************************
Validates MAC address
Valid MAC address is not broadcast, not multicast, not empty
if bLocal is set, it must be LOCAL
if not, is must be non-local or local
Parameters:
	PUCHAR pcMacAddress - MAC address to validate
	BOOLEAN bLocal      - TRUE, if we validate locally administered address
Return value:
	TRUE if valid
***********************************************************/
BOOLEAN ParaNdis_ValidateMacAddress(PUCHAR pcMacAddress, BOOLEAN bLocal)
{
	BOOLEAN bLA = FALSE, bEmpty, bBroadcast, bMulticast = FALSE;
	bBroadcast = ETH_IS_BROADCAST(pcMacAddress);
	bLA = !bBroadcast && ETH_IS_LOCALLY_ADMINISTERED(pcMacAddress);
	bMulticast = !bBroadcast && ETH_IS_MULTICAST(pcMacAddress);
	bEmpty = ETH_IS_EMPTY(pcMacAddress);
	return !bBroadcast && !bEmpty && !bMulticast && (!bLocal || bLA);
}

static eInspectedPacketType QueryPacketType(PVOID data)
{
	if (ETH_IS_BROADCAST(data))
		return iptBroadcast;
	if (ETH_IS_MULTICAST(data))
		return iptMilticast;
	return iptUnicast;
}

typedef struct _tagConfigurationEntry
{
	const char		*Name;
	ULONG			ulValue;
	ULONG			ulMinimal;
	ULONG			ulMaximal;
}tConfigurationEntry;

typedef struct _tagConfigurationEntries
{
	tConfigurationEntry isPromiscuous;
	tConfigurationEntry PrioritySupport;
	tConfigurationEntry ConnectRate;
	tConfigurationEntry isLogEnabled;
	tConfigurationEntry debugLevel;
	tConfigurationEntry connectTimer;
	tConfigurationEntry dpcChecker;
	tConfigurationEntry TxCapacity;
	tConfigurationEntry RxCapacity;
	tConfigurationEntry InterruptRecovery;
	tConfigurationEntry LogStatistics;
	tConfigurationEntry HardReset;
	tConfigurationEntry PacketFiltering;
	tConfigurationEntry ScatterGather;
	tConfigurationEntry BatchReceive;
	tConfigurationEntry OffloadTxIP;
	tConfigurationEntry OffloadTxTCP;
	tConfigurationEntry OffloadTxUDP;
	tConfigurationEntry OffloadTxLSO;
	tConfigurationEntry OffloadRxIP;
	tConfigurationEntry HwOffload;
	tConfigurationEntry IPPacketsCheck;
	tConfigurationEntry IPChecksumFix;
	tConfigurationEntry stdIpcsV4;
	tConfigurationEntry stdTcpcsV4;
	tConfigurationEntry stdTcpcsV6;
	tConfigurationEntry stdUdpcsV4;
	tConfigurationEntry stdUdpcsV6;
	tConfigurationEntry stdLsoV1;
	tConfigurationEntry stdLsoV2ip4;
	tConfigurationEntry stdLsoV2ip6;
	tConfigurationEntry PriorityVlanTagging;
	tConfigurationEntry VlanId;
	tConfigurationEntry UseMergeableBuffers;
	tConfigurationEntry PublishIndices;
	tConfigurationEntry MTU;
	tConfigurationEntry NumberOfHandledRXPackersInDPC;
}tConfigurationEntries;

static const tConfigurationEntries defaultConfiguration =
{
	{ "Promiscuous",	0,	0,	1 },
	{ "Priority",		0,	0,	1 },
	{ "ConnectRate",	100,10,10000 },
	{ "DoLog",			1,	0,	1 },
	{ "DebugLevel",		2,	0,	8 },
	{ "ConnectTimer",	0,	0,	300000 },
	{ "DpcCheck",		0,	0,	2 },
	{ "TxCapacity",		64,	16,	1024 },
	{ "RxCapacity",		256, 32, 1024 },
	{ "InterruptRecovery",	0, 0, 1},
	{ "LogStatistics",	0, 0, 10000},
	{ "HardReset",		0, 0, 1},
	{ "PacketFilter",	0, 0, 1},
	{ "Gather",			0, 0, 1},
	{ "BatchReceive",	1, 0, 1},
	{ "Offload.TxIP",	0, 0, 1},
	{ "Offload.TxTCP",	0, 0, 1},
	{ "Offload.TxUDP",	0, 0, 1},
	{ "Offload.TxLSO",	0, 0, 1},
	{ "Offload.RxIP",	0, 0, 1},
	{ "HwOffload",		0, 0, 1 },
	{ "IPPacketsCheck",	0, 0, 1 },
	{ "IPChecksumFix",	1, 0, 1 },
	{ "*IPChecksumOffloadIPv4",	3, 0, 3 },
	{ "*TCPChecksumOffloadIPv4",3, 0, 3 },
	{ "*TCPChecksumOffloadIPv6",3, 0, 3 },
	{ "*UDPChecksumOffloadIPv4",3, 0, 3 },
	{ "*UDPChecksumOffloadIPv6",3, 0, 3 },
	{ "*LsoV1IPv4",	1, 0, 1 },
	{ "*LsoV2IPv4",	1, 0, 1 },
	{ "*LsoV2IPv6",	1, 0, 1 },
	{ "*PriorityVLANTag", 3, 0, 3},
	{ "VlanId", 0, 0, 4095},
	{ "MergeableBuf", 1, 0, 1},
	{ "PublishIndices", 1, 0, 1},
	{ "MTU", 1500, 500, 65500},
	{ "NumberOfHandledRXPackersInDPC", MAX_RX_LOOPS, 1, 10000},
};

static void ParaNdis_ResetVirtIONetDevice(PARANDIS_ADAPTER *pContext)
{
	VirtIODeviceReset(&pContext->IODevice);
	DPrintf(0, ("[%s] Done", __FUNCTION__));
	/* reset all the features in the device */
	WriteVirtIODeviceRegister(pContext->IODevice.addr + VIRTIO_PCI_GUEST_FEATURES, 0);
#ifdef VIRTIO_RESET_VERIFY
	if (1)
	{
		u8 devStatus;
		devStatus = ReadVirtIODeviceByte(pContext->IODevice.addr + VIRTIO_PCI_STATUS);
		if (devStatus)
		{
			DPrintf(0, ("[%s] Device status is still %02X", __FUNCTION__, (ULONG)devStatus));
			VirtIODeviceReset(&pContext->IODevice);
			devStatus = ReadVirtIODeviceByte(pContext->IODevice.addr + VIRTIO_PCI_STATUS);
			DPrintf(0, ("[%s] Device status on retry %02X", __FUNCTION__, (ULONG)devStatus));
		}
	}
#endif
}

/**********************************************************
Gets integer value for specifies in pEntry->Name name
Parameters:
	NDIS_HANDLE cfg  previously open configuration
	tConfigurationEntry *pEntry - Entry to fill value in
***********************************************************/
static void	GetConfigurationEntry(NDIS_HANDLE cfg, tConfigurationEntry *pEntry)
{
	NDIS_STATUS status;
	const char *statusName;
	NDIS_STRING name;
	PNDIS_CONFIGURATION_PARAMETER pParam = NULL;
	NDIS_PARAMETER_TYPE ParameterType = NdisParameterInteger;
	NdisInitializeString(&name, (PUCHAR)pEntry->Name);
	NdisReadConfiguration(
		&status,
		&pParam,
		cfg,
		&name,
		ParameterType);
	if (status == NDIS_STATUS_SUCCESS)
	{
		ULONG ulValue = pParam->ParameterData.IntegerData;
		if (ulValue >= pEntry->ulMinimal && ulValue <= pEntry->ulMaximal)
		{
			pEntry->ulValue = ulValue;
			statusName = "value";
		}
		else
		{
			statusName = "out of range";
		}
	}
	else
	{
		statusName = "nothing";
	}
	DPrintf(2, ("[%s] %s read for %s - 0x%x",
		__FUNCTION__,
		statusName,
		pEntry->Name,
		pEntry->ulValue));
	NdisFreeString(name);
}

static __inline void DisableLSOPermanently(PARANDIS_ADAPTER *pContext, LPCSTR procname, LPCSTR reason)
{
	if (pContext->Offload.flagsValue & osbT4Lso)
	{
		DPrintf(0, ("[%s] Warning: %s", procname, reason));
		pContext->Offload.flagsValue &= ~osbT4Lso;
		ParaNdis_ResetOffloadSettings(pContext, NULL, NULL);
	}
}

/**********************************************************
Loads NIC parameters from adapter registry key
Parameters:
	context
	PUCHAR *ppNewMACAddress - pointer to hold MAC address if configured from host
***********************************************************/
static void ReadNicConfiguration(PARANDIS_ADAPTER *pContext, PUCHAR *ppNewMACAddress)
{
	NDIS_HANDLE cfg;
	tConfigurationEntries *pConfiguration = ParaNdis_AllocateMemory(pContext, sizeof(tConfigurationEntries));
	if (pConfiguration)
	{
		*pConfiguration = defaultConfiguration;
		cfg = ParaNdis_OpenNICConfiguration(pContext);
		if (cfg)
		{
			GetConfigurationEntry(cfg, &pConfiguration->isLogEnabled);
			GetConfigurationEntry(cfg, &pConfiguration->debugLevel);
			GetConfigurationEntry(cfg, &pConfiguration->ConnectRate);
			GetConfigurationEntry(cfg, &pConfiguration->PrioritySupport);
			GetConfigurationEntry(cfg, &pConfiguration->isPromiscuous);
			GetConfigurationEntry(cfg, &pConfiguration->TxCapacity);
			GetConfigurationEntry(cfg, &pConfiguration->RxCapacity);
			GetConfigurationEntry(cfg, &pConfiguration->connectTimer);
			GetConfigurationEntry(cfg, &pConfiguration->dpcChecker);
			GetConfigurationEntry(cfg, &pConfiguration->InterruptRecovery);
			GetConfigurationEntry(cfg, &pConfiguration->LogStatistics);
			GetConfigurationEntry(cfg, &pConfiguration->HardReset);
			GetConfigurationEntry(cfg, &pConfiguration->PacketFiltering);
			GetConfigurationEntry(cfg, &pConfiguration->ScatterGather);
			GetConfigurationEntry(cfg, &pConfiguration->BatchReceive);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadTxIP);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadTxTCP);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadTxUDP);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadTxLSO);
			GetConfigurationEntry(cfg, &pConfiguration->OffloadRxIP);
			GetConfigurationEntry(cfg, &pConfiguration->HwOffload);
			GetConfigurationEntry(cfg, &pConfiguration->IPPacketsCheck);
			GetConfigurationEntry(cfg, &pConfiguration->IPChecksumFix);
			GetConfigurationEntry(cfg, &pConfiguration->stdIpcsV4);
			GetConfigurationEntry(cfg, &pConfiguration->stdTcpcsV4);
			GetConfigurationEntry(cfg, &pConfiguration->stdTcpcsV6);
			GetConfigurationEntry(cfg, &pConfiguration->stdUdpcsV4);
			GetConfigurationEntry(cfg, &pConfiguration->stdUdpcsV6);
			GetConfigurationEntry(cfg, &pConfiguration->stdLsoV1);
			GetConfigurationEntry(cfg, &pConfiguration->stdLsoV2ip4);
			GetConfigurationEntry(cfg, &pConfiguration->stdLsoV2ip6);
			GetConfigurationEntry(cfg, &pConfiguration->PriorityVlanTagging);
			GetConfigurationEntry(cfg, &pConfiguration->VlanId);
			GetConfigurationEntry(cfg, &pConfiguration->UseMergeableBuffers);
			GetConfigurationEntry(cfg, &pConfiguration->PublishIndices);
			GetConfigurationEntry(cfg, &pConfiguration->MTU);
			GetConfigurationEntry(cfg, &pConfiguration->NumberOfHandledRXPackersInDPC);

	#if !defined(WPP_EVENT_TRACING)
			bDebugPrint = pConfiguration->isLogEnabled.ulValue;
			nDebugLevel = pConfiguration->debugLevel.ulValue;
	#endif
			// ignoring promiscuous setting, nothing to do with it
			pContext->maxFreeTxDescriptors = pConfiguration->TxCapacity.ulValue;
			pContext->NetMaxReceiveBuffers = pConfiguration->RxCapacity.ulValue;
			pContext->ulMilliesToConnect = pConfiguration->connectTimer.ulValue;
			pContext->nEnableDPCChecker = pConfiguration->dpcChecker.ulValue;
			pContext->bDoInterruptRecovery = pConfiguration->InterruptRecovery.ulValue != 0;
			pContext->Limits.nPrintDiagnostic = pConfiguration->LogStatistics.ulValue;
			pContext->uNumberOfHandledRXPacketsInDPC = pConfiguration->NumberOfHandledRXPackersInDPC.ulValue;
			pContext->bDoHardReset = pConfiguration->HardReset.ulValue != 0;
			pContext->bDoSupportPriority = pConfiguration->PrioritySupport.ulValue != 0;
			pContext->ulFormalLinkSpeed  = pConfiguration->ConnectRate.ulValue;
			pContext->ulFormalLinkSpeed *= 1000000;
			pContext->bDoPacketFiltering = pConfiguration->PacketFiltering.ulValue != 0;
			pContext->bUseScatterGather  = pConfiguration->ScatterGather.ulValue != 0;
			pContext->bBatchReceive      = pConfiguration->BatchReceive.ulValue != 0;
			pContext->bDoHardwareOffload = pConfiguration->HwOffload.ulValue != 0;
			pContext->bDoIPCheck = pConfiguration->IPPacketsCheck.ulValue != 0;
			pContext->bFixIPChecksum = pConfiguration->IPChecksumFix.ulValue != 0;
			pContext->Offload.flagsValue = 0;
			if (pConfiguration->OffloadTxIP.ulValue) pContext->Offload.flagsValue |= osbT4IpChecksum | osbT4IpOptionsChecksum;
			if (pConfiguration->OffloadTxTCP.ulValue) pContext->Offload.flagsValue |= osbT4TcpChecksum | osbT4TcpOptionsChecksum;
			if (pConfiguration->OffloadTxUDP.ulValue) pContext->Offload.flagsValue |= osbT4UdpChecksum;
			if (pConfiguration->OffloadTxLSO.ulValue) pContext->Offload.flagsValue |= osbT4Lso | osbT4LsoIp | osbT4LsoTcp;
			if (pConfiguration->OffloadRxIP.ulValue) pContext->Offload.flagsValue |= osbT4IpRxChecksum | osbT4IpOptionsChecksum;
{'fraction_non_alphanumeric': 0.15168841930805885, 'fraction_numerical': 0.023409985498239073, 'mean_word_length': 6.449382716049382, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 203, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '794240', 'n_tokens_mistral': 8885, 'n_tokens_neox': 8157, 'n_words': 1587}