📄 lan91c111_init.c
字号:
/*
*
* Copyright (c) Standard MicroSystems Corporation. All Rights Reserved.
*
* LAN91C111 Driver for Windows CE .NET
*
* Revision History
*_______________________________________________________________________________
* Author Date Version Description
*_______________________________________________________________________________
* Pramod Bhardwaj 6/18/2002 0.1 Beta Release
* 7/15/2002 1.0 Release
* 1/22/2003 1.1 Removed some platform dependencies
* 3/27/2003 1.2 Used alloc interrupt
* TScho 2/15/2004 1.2.0 Performance changes (Beta)
* TScho 2/20/2004 1.2.1 Multi-packet indication (Beta)
* TScho 2/25/2004 1.2.2 Multicast fixed (Beta)
* TScho 2/26/2004 2.1 Release for CE 5.0
*_______________________________________________________________________________
*
*Description:
* Contains all the initialization functions required for the driver.
*
*
*/
#include <Ndis.h>
#include "LAN91C111_Adapter.H"
//#include "xllp_gpio.h"
#include "bsp.h"
extern NDIS_PHYSICAL_ADDRESS HighestAcceptedMax;
extern VOID LAN91C111_MiniPortHandleInterrupt (IN NDIS_HANDLE AdapterContext);
static char _LAN91C111_Init_C_Date_Code_[] = "082304";
static volatile BULVERDE_GPIO_REG *g_pGPIORegs = NULL;
//volatile INTC_REGS *v_pICReg;
NDIS_STATUS GetRegistrySettings(MINIPORT_ADAPTER *, NDIS_HANDLE);
BOOLEAN AdapterVerify(MINIPORT_ADAPTER *);
BOOLEAN AdapterReset(MINIPORT_ADAPTER *);
void BackOut(MINIPORT_ADAPTER *Adapter);
BOOLEAN EstablishLink(MINIPORT_ADAPTER *Adapter);
BOOL EnableCS3()
{
#define MSCREGS_PHYSADDR 0x48000000
#define MSCREGS_SIZE (4*1024)
#define MSC0_OFFSET 0x08
#define MSC1_OFFSET 0x0c
#define MSC2_OFFSET 0x10
#define CS3_SETUP 0xB88C0000
UINT val;
LPVOID p_mscregs;
DWORD temp;
// map in MSC registers
p_mscregs = VirtualAlloc(0, MSCREGS_SIZE, MEM_RESERVE, PAGE_NOACCESS);
if (!p_mscregs) {
return FALSE;
}
if (!VirtualCopy(p_mscregs, (LPVOID)(MSCREGS_PHYSADDR/256), MSCREGS_SIZE,
PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL)) {
return FALSE;
}
val = CS3_SETUP;
// modify the setup for CS4
*(volatile unsigned int *)((unsigned int)p_mscregs + MSC1_OFFSET) &= 0xFFFF;
*(volatile unsigned int *)((unsigned int)p_mscregs + MSC1_OFFSET) |= val; //CS4_SETUP;
temp = *(volatile unsigned int *)((unsigned int)p_mscregs + MSC1_OFFSET);
PrintDebugMsg(ZONE_INIT, (TEXT("MSC1:----%08X\r\n"),temp));
return TRUE;
}
/*
Function Name : LAN91C111_MiniportInitialize
Description :
Called by the NDIS Wrapper to initialize the adapter.
0. Verify the Adapter v/s the driver
1. Create and initilize the adapter structure
2. Read and load the registry settings
3. Initialize the chip
4. Establish the link
Parameters :
PNDIS_STATUS OpenErrorStatus - Additional error status, if return value is error
PUINT MediumIndex - specifies the medium type the driver or its network adapter uses
PNDIS_MEDIUM MediumArray - Specifies an array of NdisMediumXXX values from which
MiniportInitialize selects one that its network adapter supports
or that the driver supports as an interface to higher-level drivers.
UINT MediumArraySize - Specifies the number of elements at MediumArray
NDIS_HANDLE AdapterHandle - Specifies a handle identifying the miniport抯 network adapter,
which is assigned by the NDIS library
NDIS_HANDLE ConfigurationContext - Specifies a handle used only during initialization for
calls to NdisXXX configuration and initialization functions
Return Value :
NDIS_STATUS Status
*/
NDIS_STATUS LAN91C111_MiniportInitialize(
PNDIS_STATUS OpenErrorStatus,
PUINT MediumIndex,
PNDIS_MEDIUM MediumArray,
UINT MediumArraySize,
NDIS_HANDLE AdapterHandle,
NDIS_HANDLE ConfigurationContext
)
{
NDIS_STATUS Status=NDIS_STATUS_SUCCESS;
UINT i;
PMINIPORT_ADAPTER Adapter;
USHORT temp;
LPVOID lpIOBase;
BOOL RetVal;
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111 ==> MiniportInitialize \r\n")));
//Check for the supported 802.3 media
for(i = 0; i < MediumArraySize; i++)
if(MediumArray[i] == NdisMedium802_3) break;
if(i == MediumArraySize)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111 : ERROR - No Supported Media types \r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111 <== Miniport Initialize\r\n")));
return(NDIS_STATUS_UNSUPPORTED_MEDIA);
}
*MediumIndex = i;
//Allocate memory for the adapter structure
Status = NdisAllocateMemory((PVOID *) &Adapter, MINIPORT_ADAPTER_SIZE, 0, HighestAcceptedMax);
if(Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - No Memory for Adapter Structure!\r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
return(NDIS_STATUS_RESOURCES);
}
NdisZeroMemory(Adapter, MINIPORT_ADAPTER_SIZE); //Clean it up
Adapter->State = INITIALIZING_STATE;
Adapter->AdapterHandle = AdapterHandle;
Adapter->IsInterruptSet = FALSE;
Adapter->IsPortRegistered = FALSE;
//Allocate the TX Buffer memory
Status = NdisAllocateMemory((PVOID *) &Adapter->TxBuffer, MAX_FRAME_SIZE, 0, HighestAcceptedMax);
if(Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - Can't Allocate Tx Buffer!\r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(NDIS_STATUS_RESOURCES);
}
//Allocate the RX Buffer Memory.
//Allocate memory for packet & buffer pool and packet & buffer descriptors and lookahead buffer
NdisAllocatePacketPool(&Status, &Adapter->PacketPool, MAX_PACKETS, PROT_RESERVED); // PacketPool
if (Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - No Memory for PacketPool allocation!\r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(NDIS_STATUS_RESOURCES);
}
NdisAllocateBufferPool(&Status, &Adapter->BufferPool, 1); // BufferPool
if (Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - No Memory for BufferPool allocation!\r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(NDIS_STATUS_RESOURCES);
}
for (i = 0; i < MAX_PACKETS; i++)
{
Status = NdisAllocateMemory((PVOID*)&Adapter->LookAheadBuffer[i], LOOK_AHEAD_BUFFER_SIZE, 0, HighestAcceptedMax);
if(Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - Can't Allocate LookAhead Buffer!\r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(NDIS_STATUS_RESOURCES);
}
NdisAllocateBuffer(&Status, &Adapter->Buffer[i], Adapter->BufferPool, Adapter->LookAheadBuffer[i], LOOK_AHEAD_BUFFER_SIZE);
if (Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - No Memory for Buffer[%d] allocation!\r\n"), i));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(NDIS_STATUS_RESOURCES);
}
NdisAllocatePacket(&Status, &Adapter->Packet[i], Adapter->PacketPool); //Packet
if (Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - No Memory for Packet[%d] allocation!\r\n"), i));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(NDIS_STATUS_RESOURCES);
}
NDIS_SET_PACKET_HEADER_SIZE(Adapter->Packet[i], ETHERNET_HEADER_SIZE);
NdisChainBufferAtBack(Adapter->Packet[i], Adapter->Buffer[i]);
}
//Get the adapter information from the registry
Status = GetRegistrySettings(Adapter, ConfigurationContext);
if(Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - Configure Adapter failed!\r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(NDIS_STATUS_FAILURE);
}
//Register global NIC attributes
NdisMSetAttributes(Adapter->AdapterHandle, (NDIS_HANDLE) Adapter, FALSE, NdisInterfaceInternal);
//Register the interrupt
Status = NdisMRegisterInterrupt(&Adapter->InterruptInfo,
Adapter->AdapterHandle,
Adapter->InterruptLevel,
Adapter->InterruptLevel,
FALSE,
FALSE,
NdisInterruptLatched
);
if(Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - Can't Attach to Interrupt!\r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(Status);
}
Adapter->IsInterruptSet = TRUE;
//Register the IOBase address. Modify this code according to the platform
/* Status = NdisMRegisterIoPortRange((PVOID *) &(Adapter->IOBase),
Adapter->AdapterHandle,
Adapter->IOBase,
16);
if(Status != NDIS_STATUS_SUCCESS)
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C9111: ERROR - Can't Register I/O Port Range!\r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C9111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(NDIS_STATUS_RESOURCES);
}
Adapter->IsPortRegistered = TRUE;
*/
#pragma message( "-- WARNING: Change the IO BASE ADDRESS for VirtualAlloc/VirtualCopy functions in LAN91C111_Init.C" )
lpIOBase = VirtualAlloc(0, 0x1000, MEM_RESERVE, PAGE_NOACCESS);
RetVal = VirtualCopy(lpIOBase, (LPVOID)(Adapter->IOBase/256), 0x1000, PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE);
if (RetVal == TRUE)
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: VirtualAlloc/Copy Succeeded...........\r\n")));
else
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111:ERROR : VirtualAlloc/Copy Failed...........\r\n")));
Adapter->IOBase = (UINT)lpIOBase + 0x300;
// Verifies the driver chip support
if(!AdapterVerify(Adapter))
{
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: ERROR - Adapter failed to Verify!\r\n")));
PrintDebugMsg(ZONE_INIT, (TEXT("LAN91C111: <== MiniPort Initialize\r\n")));
BackOut(Adapter);
return(NDIS_STATUS_FAILURE);
}
//Disable all interrupts until the initzing is completed
NdisRawWritePortUshort( Adapter->IOBase + BANK_SELECT, 2 );
NdisRawWritePortUshort( Adapter->IOBase + BANK2_INT_STS, 0 );
//Check for the MAC Address
//If Adapter->MACAddress != NULL then we need to write the new mac address to the LAN91C111 register
//Else read the LAN91C111 register and store the mac addr. in Adapter->MACAddress
if (Adapter->MACAddress[0] == 0 &&
Adapter->MACAddress[1] == 0 &&
Adapter->MACAddress[2] == 0 &&
Adapter->MACAddress[3] == 0 &&
Adapter->MACAddress[4] == 0 &&
Adapter->MACAddress[5] == 0 )
{
//Read the MAC address from the register
NdisRawWritePortUshort(Adapter->IOBase + BANK_SELECT, 1);
NdisRawReadPortUshort(Adapter->IOBase + BANK1_IA0, &temp);
Adapter->MACAddress[1] = (UCHAR) (temp >> 8);
Adapter->MACAddress[0] = (UCHAR) (temp & 0xFF);
NdisRawReadPortUshort(Adapter->IOBase + BANK1_IA2, &temp);
Adapter->MACAddress[3] = (UCHAR) (temp >> 8);
Adapter->MACAddress[2] = (UCHAR) (temp & 0xFF);
NdisRawReadPortUshort(Adapter->IOBase + BANK1_IA4, &temp);
Adapter->MACAddress[5] = (UCHAR) (temp >> 8);
Adapter->MACAddress[4] = (UCHAR) (temp & 0xFF);
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -