⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lan91c111_init.c

📁 This driver was developed to ARM SMSC LAN91C11 (PXA CPU)
💻 C
📖 第 1 页 / 共 3 页
字号:
 Parameters    :
					MINIPORT_ADAPTER *Adapter	- Pointer to the adapter structure
					NDIS_HANDLE       ConfigurationContext - Context handler, from the NDIS wrapper
			
 Return Value  :
					NDIS_STATUS		Status
*/

NDIS_STATUS GetRegistrySettings(MINIPORT_ADAPTER *Adapter,
							 NDIS_HANDLE       ConfigurationContext)
{
	NDIS_STATUS                   Status;
	NDIS_HANDLE                   ConfigurationHandle;
	PNDIS_CONFIGURATION_PARAMETER ConfigurationParameter;

	UCHAR                        *	NewNetworkAddress=NULL;
    UINT							NewNetworkAddressLength;

	NDIS_STRING                   BusTypeString		= NDIS_STRING_CONST("BusType");
	NDIS_STRING                   BusNumberString	= NDIS_STRING_CONST("BusNumber");
	NDIS_STRING                   DuplexString		= NDIS_STRING_CONST("DUPLEX");
	NDIS_STRING                   FullDupString		= NDIS_STRING_CONST("FULL");
    NDIS_STRING                   HalfDupString		= NDIS_STRING_CONST("HALF");
	NDIS_STRING                   SpeedString		= NDIS_STRING_CONST("SPEED");
    NDIS_STRING                   Speed100String	= NDIS_STRING_CONST("100");
    NDIS_STRING                   Speed10String		= NDIS_STRING_CONST("10");
    NDIS_STRING                   AutoNegString		= NDIS_STRING_CONST("AUTO-NEGOTIATION");
    NDIS_STRING                   DefDupString		= NDIS_STRING_CONST("DEFAULT");
	NDIS_STRING                   IOBase          = NDIS_STRING_CONST("IoBaseAddress");
    NDIS_STRING                   Interrupt       = NDIS_STRING_CONST("InterruptNumber");

	PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111 ==> GetRegistrySettings  \r\n")));

	//Set up the default values
	Adapter->InterruptVector =
	Adapter->InterruptLevel  = DEFAULT_IRQ;
    Adapter->IOBase          = DEFAULT_IO_BASE;
    Adapter->LookAhead       = MAX_LOOKAHEAD_SIZE;
	Adapter->Speed           = SPEED100;
	Adapter->Auto_Negotiation = TRUE;
	Adapter->LinkStatus		 = MEDIA_DISCONNECTED;
	Adapter->MACAddress[0] = 
		Adapter->MACAddress[1] = 
		Adapter->MACAddress[2] = 
		Adapter->MACAddress[3] = 
		Adapter->MACAddress[4] = 
		Adapter->MACAddress[5] = 0;		
	
	//Open the Registry tree for this adapter.
    NdisOpenConfiguration((PNDIS_STATUS) &Status,(PNDIS_HANDLE) &ConfigurationHandle,ConfigurationContext);
	if(Status != NDIS_STATUS_SUCCESS)
    {
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111 : ERROR - No information for adapter!\r\n")));
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111 <== Configure Adapter\r\n")));
        return(NDIS_STATUS_FAILURE);
    }

	//Get configured bus type value from registry,
	NdisReadConfiguration((PNDIS_STATUS) &Status,   
		&ConfigurationParameter,
		ConfigurationHandle,
		(PNDIS_STRING) &BusTypeString,
		NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		Adapter->BusType = (USHORT) ConfigurationParameter->ParameterData.IntegerData;
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:BusType    = 0x%x\r\n"), Adapter->BusType));
	}
	else
	{
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111 : ERROR - BusType not in Registry!\r\n")));
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111 <== Configure Adapter\r\n")));
		NdisCloseConfiguration(ConfigurationHandle);
		return(NDIS_STATUS_FAILURE);
	}

	//Get bus number value from registry.
	NdisReadConfiguration((PNDIS_STATUS) &Status,
		&ConfigurationParameter,
		ConfigurationHandle,
		(PNDIS_STRING) &BusNumberString,
		NdisParameterInteger);
	if(Status == NDIS_STATUS_SUCCESS)
	{
		Adapter->BusNumber = (USHORT) ConfigurationParameter->ParameterData.IntegerData;
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:BusNumber    = 0x%x\r\n"), Adapter->BusNumber));
	}	
	else
	{
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - BusNumber not in Registry!\r\n")));
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111<== Configure Adapter\r\n")));
		NdisCloseConfiguration(ConfigurationHandle);
		return(NDIS_STATUS_FAILURE);
	}

	
	//If both Duplex AND Speed are selected, in the registry, then Auto_Negotiation is false
	//If either of speed or duplex is default or AutoNeg then Auto_Negotiation is turned on !!
	Adapter->Duplex = DEFAULT_VALUE;
	NdisReadConfiguration((PNDIS_STATUS) &Status,
		&ConfigurationParameter,
		ConfigurationHandle,
		(PNDIS_STRING) &DuplexString,
		NdisParameterString);
	
	if(Status == NDIS_STATUS_SUCCESS)
	{
		if( NdisEqualString( (PNDIS_STRING) &ConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &AutoNegString,TRUE ) ) 
		{
			PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:Config is Auto-Negotiation\r\n")));
			Adapter->Duplex = AUTO_NEGOTIATION;
		}
		else
			if( NdisEqualString( (PNDIS_STRING) &ConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &DefDupString,	TRUE ) ) 
			{
				PrintDebugMsg(ZONE_INIT, (TEXT("Config is Default\r\n")));
				Adapter->Duplex = DEFAULT_VALUE;
			}
			else
				if( NdisEqualString( (PNDIS_STRING) &ConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &FullDupString,TRUE ) ) 
				{
					PrintDebugMsg(ZONE_INIT, (TEXT("Config is Full Duplex\r\n")));
					Adapter->Duplex = FULL_DUPLEX;
				}
				else
					if( NdisEqualString( (PNDIS_STRING) &ConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &HalfDupString,TRUE ) ) 
					{
						PrintDebugMsg(ZONE_INIT, (TEXT("Config is Half Duplex\r\n")));
						Adapter->Duplex = HALF_DUPLEX;
					}
					
	}	
	
	Adapter->Speed = DEFAULT_VALUE;
	NdisReadConfiguration((PNDIS_STATUS) &Status, 
		&ConfigurationParameter, 
		ConfigurationHandle,
		(PNDIS_STRING) &SpeedString,
		NdisParameterString);
	if(Status == NDIS_STATUS_SUCCESS) 
	{
		if( NdisEqualString( (PNDIS_STRING) &ConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &AutoNegString,TRUE ) )
		{
			PrintDebugMsg(ZONE_INIT, (TEXT("Config is Auto-Negotiation\r\n")));					
			Adapter->Speed = AUTO_NEGOTIATION;
		}
		else
			if( NdisEqualString( (PNDIS_STRING) &ConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &DefDupString,	TRUE ) )
			{
				PrintDebugMsg(ZONE_INIT, (TEXT("Config is Default\r\n")));						
				Adapter->Speed = DEFAULT_VALUE;
			}
			else
				if( NdisEqualString( (PNDIS_STRING) &ConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &Speed100String,TRUE ) ) 
				{
					PrintDebugMsg(ZONE_INIT, (TEXT("Config is 100 Mbps\r\n")));
					Adapter->Speed = SPEED100;
				}
				else
					if( NdisEqualString( (PNDIS_STRING) &ConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &Speed10String,TRUE ) )
					{
						PrintDebugMsg(ZONE_INIT, (TEXT("Config is 10 Mbps\r\n")));
						Adapter->Speed = SPEED10;
					}
	}
	if ((Adapter->Speed == DEFAULT_VALUE)  || (Adapter->Speed == AUTO_NEGOTIATION) ||
	   ((Adapter->Duplex == DEFAULT_VALUE) || ( Adapter->Duplex == AUTO_NEGOTIATION )))
		Adapter->Auto_Negotiation = TRUE;
	else
		Adapter->Auto_Negotiation = FALSE;

	//Check for updates to IRQ value.
    NdisReadConfiguration((PNDIS_STATUS) &Status,
		&ConfigurationParameter,
		ConfigurationHandle,
		(PNDIS_STRING) &Interrupt,
		NdisParameterInteger);	
    if(Status == NDIS_STATUS_SUCCESS)
    {
        PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:New IRQ Value found in register.. overiding the default value\r\n")));
		Adapter->InterruptVector	=
		Adapter->InterruptLevel		= (USHORT) (ConfigurationParameter->ParameterData.IntegerData);
	}
	else
	{
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:Unable to read Interrupt from Registry using default value!!!\r\n")));
	}	

	//Check for update IOBase address
	NdisReadConfiguration((PNDIS_STATUS) &Status,
		&ConfigurationParameter,
		ConfigurationHandle,
		(PNDIS_STRING) &IOBase,
		NdisParameterInteger);
	if (Status == NDIS_STATUS_SUCCESS)
	{
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:New IOBase address found in register.. overiding the default value\r\n")));
		Adapter->IOBase = (ULONG) (ConfigurationParameter->ParameterData.IntegerData);
	}

	//Make sure we're still okay.
	if(Status != NDIS_STATUS_SUCCESS)
	{
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:<== Configure Adapter\r\n")));
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:ERROR: Config Handler Failed!\n")));
		return(Status);
	}
				
	PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:BusNumber  = %d\r\n"), Adapter->BusNumber));
	PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:BusType    = %d\r\n"), Adapter->BusType));
	PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:IoBase     = 0x%08x\r\n"), Adapter->IOBase));
	PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:Interrupt  = %d\r\n"), Adapter->InterruptLevel));
	PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:Speed		= %d\r\n"), Adapter->Speed));
	PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:Duplex		= %d\r\n"), Adapter->Duplex));
		
	//See if user has defined new MAC address.
	NdisReadNetworkAddress((PNDIS_STATUS) &Status,
		(PVOID *) &NewNetworkAddress,
		&NewNetworkAddressLength,
		ConfigurationHandle);
				
	if((Status == NDIS_STATUS_SUCCESS) && (NewNetworkAddressLength != 0))
	{
		PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:H/W MAC Address over-ride!\r\n")));
		if((NewNetworkAddressLength != ETH_LENGTH_OF_ADDRESS)) 
		{
			PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:Invalid MAC address length!\r\n")));
		}
		else
		{
			Adapter->MACAddress[0] = NewNetworkAddress[0];
			Adapter->MACAddress[1] = NewNetworkAddress[1];
			Adapter->MACAddress[2] = NewNetworkAddress[2];
			Adapter->MACAddress[3] = NewNetworkAddress[3];
			Adapter->MACAddress[4] = NewNetworkAddress[4];
			Adapter->MACAddress[5] = NewNetworkAddress[5];

			PrintDebugMsg(ZONE_INIT,(TEXT("Registry reads = %02X-%02X-%02X-%02X-%02X-%02X\r\n"),
				NewNetworkAddress[0], 
				NewNetworkAddress[1],
				NewNetworkAddress[2],
				NewNetworkAddress[3],
				NewNetworkAddress[4],
				NewNetworkAddress[5]));

			PrintDebugMsg(ZONE_INIT,(TEXT("Adapter->MACAddress reads = %02X-%02X-%02X-%02X-%02X-%02X\r\n"),
				Adapter->MACAddress[0],
				Adapter->MACAddress[1],
				Adapter->MACAddress[2],
				Adapter->MACAddress[3],
				Adapter->MACAddress[4],
				Adapter->MACAddress[5]));
		}
	}
	else
	{
		Status = NDIS_STATUS_SUCCESS;
	}
	NdisCloseConfiguration(ConfigurationHandle);
	if(Status != NDIS_STATUS_SUCCESS)
	{
			PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:ERROR: Specific Configuration Handler Failed!\r\n")));
			PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:<== Configure Adapter\r\n")));
			return(Status);
	}
	
	PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111 <== GetRegistrySettings  \r\n")));
	return(Status);
}


/*
 Function Name : 	AdapterVerify
 Description   :    
                    Verifies if the current driver supports the chip.
                       This driver supports only LAN91C111/LAN91C113
 Parameters    :
                    MINIPORT_ADAPTER *Adapter - Pointer to the adapter structure
 Return Value  :
                    TRUE - Supported
                    FALSE - This driver doesn't support the chip.
*/

BOOLEAN AdapterVerify(MINIPORT_ADAPTER  *Adapter)
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -