Example #1
0
/*
 Function Name : 	LPC3xxx_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’s 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 LPC3xxx_MiniportInitialize(	PNDIS_STATUS	pOpenErrorStatus,
										PUINT			pMediumIndex,
										PNDIS_MEDIUM	pMediumArray,
										UINT			nMediumArraySize,
										NDIS_HANDLE		hAdapterHandle,
										NDIS_HANDLE		hConfigurationContext)
{
	NDIS_STATUS         Status = NDIS_STATUS_SUCCESS;
	UINT                nArrayIndex;
	PMINIPORT_ADAPTER   pAdapter;
	PHYSICAL_ADDRESS pa;

	DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS ==> MiniportInitialize\r\n")));

	//Check for the supported 802.3 media
	for(nArrayIndex = 0; nArrayIndex < nMediumArraySize; nArrayIndex++)
	{
		if(NdisMedium802_3 == pMediumArray[nArrayIndex])
			break;
	}

    if(nArrayIndex == nMediumArraySize)
    {
		DEBUGMSG(ZONE_INIT | ZONE_ERROR, (TEXT("LPC3xxx NDIS :  ERROR - No Supported Media types \r\n")));
        DEBUGMSG(ZONE_INIT | ZONE_ERROR, (TEXT("LPC3xxx NDIS <== MiniportInitialize  \r\n")));
        return(NDIS_STATUS_UNSUPPORTED_MEDIA);
    }

    *pMediumIndex = nArrayIndex;

	//Allocate memory for the adapter structure
	Status = NdisAllocateMemory((PVOID *) &pAdapter, MINIPORT_ADAPTER_SIZE, 0, HighestAcceptedMax);

    if(Status != NDIS_STATUS_SUCCESS)
    {
        DEBUGMSG(ZONE_INIT | ZONE_ERROR, (TEXT("LPC3xxx NDIS:   ERROR - No Memory for Adapter Structure!\r\n")));
		DEBUGMSG(ZONE_INIT | ZONE_ERROR, (TEXT("LPC3xxx NDIS <== MiniPort Initialize\r\n")));
        return(NDIS_STATUS_RESOURCES);
    }
    NdisZeroMemory(pAdapter, MINIPORT_ADAPTER_SIZE); //Clean it up

//Set up the default values
	pAdapter->hAdapter			= hAdapterHandle;
	pAdapter->eState			= INITIALIZING_STATE;
	pAdapter->IsInterruptSet	= FALSE;
	pAdapter->IsPortRegistered	= FALSE;

	pAdapter->dwIRQNumber		= -1;
	pAdapter->bMediaConnected	= FALSE;
	pAdapter->bAutoNeg			= TRUE;		//	Autoneg per default (overriden by registry settings)
	pAdapter->bFullDuplex		= TRUE;		//	Full duplex per default
	pAdapter->b100Mbps			= TRUE;		//	100 Mbps per default
	pAdapter->bRMII				= TRUE;		//	RMII interface per default

	//Setup Receive control Register
	pAdapter->bPerfectMatch		= TRUE;		//	We want to receive the frames for this station
	pAdapter->bPromiscuous		= FALSE;	//	Not in Promescuous mode per default
	pAdapter->bRxBroadcast		= TRUE;		//	We do forward the broadcasted frames (DHCP required at least)
	pAdapter->bRxMulticastHash	= TRUE;		//	We forward matched multicast frames
	pAdapter->bRxMulticastAll	= FALSE;	//	We do not forward all multicast frames
	pAdapter->bRxUnicastHash	= TRUE;	//	We do not forward matched unicast frames
	pAdapter->bRxUnicastAll		= TRUE;	//	We do not forward all unicast frames

	pAdapter->dwBufferPhyAddr	= 0;
	pAdapter->dwTxStrides		= 0;
	pAdapter->dwRxStrides		= 0;
	pAdapter->dwControllerAddress	= 0;

	pAdapter->pEMACRegs		= NULL;
	pAdapter->dwEMACBuffersSize = 0;
	pAdapter->pPATXDesc		= 0;
	pAdapter->pPARXDesc		= 0;
	pAdapter->pPATXBuffer	= 0;
	pAdapter->pPARXBuffer	= 0;
	pAdapter->pPATXStatus	= 0;
	pAdapter->pPARXStatus	= 0;
	pAdapter->pVAEMACBuffers= NULL;
	pAdapter->pVATXDesc		= NULL;
	pAdapter->pVARXDesc		= NULL;
	pAdapter->pVATXStatus	= NULL;
	pAdapter->pVARXStatus	= NULL;

	//Allocate memory for the LookAhead buffer
	pAdapter->dwLookAheadBufferSize = MAX_FRAME_SIZE;
	Status = NdisAllocateMemory((PVOID *) &pAdapter->pVALookAheadBuffer, pAdapter->dwLookAheadBufferSize, 0, HighestAcceptedMax);

    if(Status != NDIS_STATUS_SUCCESS)
    {
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS: ERROR - No Memory for LookAhead buffer!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== MiniPort Initialize\r\n")));
        BackOut(pAdapter);
        return(NDIS_STATUS_RESOURCES);
    }
    NdisZeroMemory(pAdapter->pVALookAheadBuffer, pAdapter->dwLookAheadBufferSize); //Clean it up

	pAdapter->MACAddress[0]	= 0x02;
	pAdapter->MACAddress[1]	= 0x03;
	pAdapter->MACAddress[2]	= 0x04;
	pAdapter->MACAddress[3]	= 0x06;
	pAdapter->MACAddress[4]	= 0x06;
	pAdapter->MACAddress[5]	= 0x08;

	//Get the adapter information from the registry
	Status = GetRegistrySettings(pAdapter, hConfigurationContext);
	if(Status != NDIS_STATUS_SUCCESS)
    {
        DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS: ERROR - Configure Adapter failed!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== MiniPort Initialize\r\n")));
        BackOut(pAdapter);
        return(NDIS_STATUS_FAILURE);
    }

	//	Allocate the memory for Buffers

	//		Computing required space
	pAdapter->dwEMACBuffersSize = pAdapter->dwRxStrides * (	  sizeof(LPCS_ETH_DESC)
															+ sizeof(LPCS_ETH_RX_STATUS)
															+ MAX_FRAME_SIZE)
								+ pAdapter->dwTxStrides * (	  sizeof(LPCS_ETH_DESC) 
															+ sizeof(LPCS_ETH_TX_STATUS)
															+ MAX_FRAME_SIZE);

	//		Allocating space
	pAdapter->pVAEMACBuffers = MapRegisters (pAdapter->dwBufferPhyAddr,
											pAdapter->dwEMACBuffersSize);

	if(pAdapter->pVAEMACBuffers == NULL)
    {
        RETAILMSG(1, (TEXT("LPC3xxx NDIS:ERROR : Can't Allocate Buffer!\r\n")));
		BackOut(pAdapter);
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:<== MiniPort Initialize FAILED !!\r\n")));
        return(NDIS_STATUS_RESOURCES);
    }

	DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Allocated DMA Buffers Successfully!\r\n")));

	//		Splitting allocated buffers into smaller areas
	//			Physical Addresses
	pAdapter->pPARXDesc		= pAdapter->dwBufferPhyAddr;
	pAdapter->pPARXStatus	= pAdapter->pPARXDesc	+ pAdapter->dwRxStrides * sizeof(LPCS_ETH_DESC);
	pAdapter->pPATXDesc		= pAdapter->pPARXStatus + pAdapter->dwRxStrides * sizeof(LPCS_ETH_RX_STATUS);
	pAdapter->pPATXStatus	= pAdapter->pPATXDesc	+ pAdapter->dwTxStrides * sizeof(LPCS_ETH_DESC);
	pAdapter->pPARXBuffer	= pAdapter->pPATXStatus	+ pAdapter->dwTxStrides * sizeof(LPCS_ETH_TX_STATUS);
	pAdapter->pPATXBuffer	= pAdapter->pPARXBuffer	+ pAdapter->dwRxStrides * MAX_FRAME_SIZE;
	//			Virtual Addresses
	pAdapter->pVARXDesc		= pAdapter->pVAEMACBuffers;
	pAdapter->pVARXStatus	= (PVOID)((DWORD)pAdapter->pVARXDesc	+ pAdapter->dwRxStrides * sizeof(LPCS_ETH_DESC));
	pAdapter->pVATXDesc		= (PVOID)((DWORD)pAdapter->pVARXStatus	+ pAdapter->dwRxStrides * sizeof(LPCS_ETH_RX_STATUS));
	pAdapter->pVATXStatus	= (PVOID)((DWORD)pAdapter->pVATXDesc	+ pAdapter->dwTxStrides * sizeof(LPCS_ETH_DESC));
	pAdapter->pVARXBuffer	= (PVOID)((DWORD)pAdapter->pVATXStatus	+ pAdapter->dwTxStrides * sizeof(LPCS_ETH_TX_STATUS));
	pAdapter->pVATXBuffer	= (PVOID)((DWORD)pAdapter->pVARXBuffer	+ pAdapter->dwRxStrides * MAX_FRAME_SIZE);

	//	Allocating the TX Packet buffer
	Status = NdisAllocateMemory((PVOID *) &pAdapter->pTXPackets, sizeof(TX_PACKET) * pAdapter->dwTxStrides, 0, HighestAcceptedMax);
    if(Status != NDIS_STATUS_SUCCESS)
    {
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS: ERROR - No Memory for TXBuffers buffer!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== MiniPort Initialize\r\n")));
        BackOut(pAdapter);
        return(NDIS_STATUS_RESOURCES);
    }
	NdisZeroMemory(pAdapter->pTXPackets, sizeof(TX_PACKET) * pAdapter->dwTxStrides); //Clean it up

	//Register the interrupt
	NdisMSetAttributes(pAdapter->hAdapter, (NDIS_HANDLE) pAdapter, TRUE, NdisInterfaceInternal);
	Status = NdisMRegisterInterrupt(&pAdapter->InterruptInfo,
									pAdapter->hAdapter,
									pAdapter->dwIRQNumber,
									0,
									TRUE,
									FALSE,
									NdisInterruptLatched);

	if(Status != NDIS_STATUS_SUCCESS)
    {
        DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - Can't Attach to Interrupt!\r\n")));
		BackOut(pAdapter);
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:<== MiniPort Initialize\r\n")));
        return(Status);
    }
	else
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS: Interrupt Registered !!! \r\n")));

	pAdapter->IsInterruptSet = TRUE;

	//Register the IOBase address. Modify this code according to the platform
	Status = NdisMRegisterIoPortRange((PVOID *) &(pAdapter->pEMACRegs),
			pAdapter->hAdapter,
			pAdapter->dwControllerAddress,
			sizeof(ETHERNET_REGS_T));
	if(Status != NDIS_STATUS_SUCCESS)
	{
		RETAILMSG(1, (TEXT("LAN91C9111 : ERROR - Can't Register I/O Port Range!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LAN91C9111 <== MiniPort Initialize\r\n")));
        BackOut(pAdapter);
		return(NDIS_STATUS_RESOURCES);
	}

	pAdapter->IsPortRegistered = TRUE;

	//EnablePeriphClock(ETHERNET);
	pa.QuadPart = CLK_PM_BASE;
	n_pCLKPWRRegs = (CLKPWR_REGS_T *)
		MmMapIoSpace(pa, sizeof (CLKPWR_REGS_T), FALSE);
	
	if (n_pCLKPWRRegs == NULL)
	{
		RETAILMSG(1, (_T("LCD: lpc32xx_hw_init: Critcal error: cannot map registers!\r\n")));
		MmUnmapIoSpace(n_pCLKPWRRegs, sizeof(CLKPWR_REGS_T));
		return;
	}

	n_pCLKPWRRegs->clkpwr_macclk_ctrl = CLKPWR_MACCTRL_HRCCLK_EN|
										CLKPWR_MACCTRL_MMIOCLK_EN|
										CLKPWR_MACCTRL_DMACLK_EN|
										CLKPWR_MACCTRL_USE_RMII_PINS;
	//	//	Initialize Tx and Rx DMA Descriptors
	//DEBUGMSG(ZONE_INIT, (L"LPC_EthInit: Initializing Descriptor engine\r\n"));
	//EMAC_InitEngine(pAdapter);

	if(!HardReset(pAdapter))
	{
		return NDIS_STATUS_FAILURE;
	}

	DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== MiniportInitialize  \r\n")));

	//Ready

	return NDIS_STATUS_SUCCESS;
}
Example #2
0
/*
 *************************************************************************
 *  MiniportInitialize
 *************************************************************************
 *
 *
 *  Initializes the network interface card.
 *
 *
 *
 */
NDIS_STATUS MiniportInitialize	(	PNDIS_STATUS OpenErrorStatus,
									PUINT SelectedMediumIndex,
									PNDIS_MEDIUM MediumArray,
									UINT MediumArraySize,
									NDIS_HANDLE NdisAdapterHandle,
									NDIS_HANDLE WrapperConfigurationContext
								)
{
	UINT mediumIndex;
	IrDevice *thisDev = NULL;	
	NDIS_STATUS retStat, result = NDIS_STATUS_SUCCESS;

	DBGOUT(("MiniportInitialize()"));

	/*
	 *  Search the passed-in array of supported media for the IrDA medium.
	 */
	for (mediumIndex = 0; mediumIndex < MediumArraySize; mediumIndex++){
		if (MediumArray[mediumIndex] == NdisMediumIrda){
			break;
		}
	}
	if (mediumIndex < MediumArraySize){
		*SelectedMediumIndex = mediumIndex;
	}
	else {
		/*
		 *  Didn't see the IrDA medium
		 */
		DBGERR(("Didn't see the IRDA medium in MiniportInitialize"));
		result = NDIS_STATUS_UNSUPPORTED_MEDIA;
		goto _initDone;
	}

	/*
	 *  Allocate a new device object to represent this connection.
	 */
	thisDev = NewDevice();
	if (!thisDev){
		return NDIS_STATUS_NOT_ACCEPTED;
	}

	/*
	 *  Allocate resources for this connection.
	 */
	if (!OpenDevice(thisDev)){
		DBGERR(("OpenDevice failed"));
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


	/*
	 *  Read the system registry to get parameters like COM port number, etc.
	 */
	if (!Configure(thisDev, WrapperConfigurationContext)){
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


	/*
	 *  This call will associate our adapter handle with the wrapper's
	 *  adapter handle.  The wrapper will then always use our handle
	 *  when calling us.  We use a pointer to the device object as the context.
	 */
   	NdisMSetAttributes	(	NdisAdapterHandle,
							(NDIS_HANDLE)thisDev,
							FALSE,
							NdisInterfaceInternal  
						);

							
	/*
	 *  Tell NDIS about the range of IO space that we'll be using.
	 */
	retStat = NdisMRegisterIoPortRange(	(PVOID)thisDev->mappedPortRange,
										NdisAdapterHandle,
										thisDev->portInfo.ioBase,
										8);
	if (retStat != NDIS_STATUS_SUCCESS){
		DBGERR(("NdisMRegisterIoPortRange failed"));
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


	/*
	 *  Record the NDIS wrapper's handle for this adapter, which we use
	 *  when we call up to the wrapper.
	 *  (This miniport's adapter handle is just thisDev, the pointer to the device object.).
	 */
	DBGOUT(("NDIS handle: %xh <-> IRMINI handle: %xh", (UINT)NdisAdapterHandle, (UINT)thisDev));
	thisDev->ndisAdapterHandle = NdisAdapterHandle;


	/*
	 *  Open COMM communication channel.
	 *  This will let the dongle driver update its capabilities from their default values.
	 */
	if (!DoOpen(thisDev)){
		DBGERR(("DoOpen failed"));
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


	/*
	 *  Register an interrupt with NDIS.
	 */
	retStat = NdisMRegisterInterrupt(	(PNDIS_MINIPORT_INTERRUPT)&thisDev->interruptObj,
										NdisAdapterHandle,
										thisDev->portInfo.irq,
										thisDev->portInfo.irq,
										TRUE,	// want ISR
										TRUE,	// MUST share interrupts
										NdisInterruptLevelSensitive
									);
	if (retStat != NDIS_STATUS_SUCCESS){
		DBGERR(("NdisMRegisterInterrupt failed"));
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


 _initDone:
	if (result == NDIS_STATUS_SUCCESS){

		/*
		 *  Add this device object to the beginning of our global list.
		 */
		thisDev->next = firstIrDevice;
		firstIrDevice = thisDev;

		DBGOUT(("MiniportInitialize succeeded"));
	}
	else {
		if (thisDev){
			FreeDevice(thisDev);
		}
		DBGOUT(("MiniportInitialize failed"));
	}
	return result;

}
Example #3
0
// Initialization handler of adapter
NDIS_STATUS NeoNdisInit(NDIS_STATUS *OpenErrorStatus,
					UINT *SelectedMediumIndex,
					NDIS_MEDIUM *MediumArray,
					UINT MediumArraySize,
					NDIS_HANDLE MiniportAdapterHandle,
					NDIS_HANDLE WrapperConfigurationContext)
{
	BOOL media_check;
	UINT i;

	if (ctx == NULL)
	{
		return NDIS_STATUS_FAILURE;
	}

	if (ctx->NdisWrapper == NULL)
	{
		ctx->NdisWrapper = ndis_wrapper_handle;
	}

	// Prevention of multiple start
	if (ctx->Initing != FALSE)
	{
		// Multiple started
		return NDIS_STATUS_FAILURE;
	}
	ctx->Initing = TRUE;

	// Examine whether it has already been initialized
	if (ctx->Inited != FALSE)
	{
		// Driver is started on another instance already.
		// PacketiX VPN driver can start only one instance per one service.
		// User can start multiple drivers with different instance ID
		return NDIS_STATUS_FAILURE;
	}

	// Current value of the packet filter
	ctx->CurrentPacketFilter = NDIS_PACKET_TYPE_ALL_LOCAL | NDIS_PACKET_TYPE_BROADCAST | NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_ALL_FUNCTIONAL;

	// Examine whether the Ethernet is available
	media_check = FALSE;
	for (i = 0;i < MediumArraySize;i++)
	{
		if (MediumArray[i] == NEO_MEDIA)
		{
			media_check = TRUE;
			break;
		}
	}
	if (media_check == FALSE)
	{
		// Ethernet is unavailable
		ctx->Initing = FALSE;
		return NDIS_STATUS_FAILURE;
	}

	// Media number to use
	*SelectedMediumIndex = i;

	// Initialize the adapter information
	ctx->NdisMiniport = MiniportAdapterHandle;
	ctx->NdisConfig = WrapperConfigurationContext;
	ctx->NdisContext = ctx;
	ctx->HardwareStatus = NdisHardwareStatusReady;
	ctx->Halting = FALSE;
	ctx->Connected = ctx->ConnectedOld = FALSE;

	if (keep_link == false)
	{
		ctx->ConnectedForce = TRUE;
	}

	// Read the information from the registry
	if (NeoLoadRegistory() == FALSE)
	{
		// Failure
		ctx->Initing = FALSE;
		return NDIS_STATUS_FAILURE;
	}

	// Register the device attributes

	if (g_is_win8 == false)
	{
		NdisMSetAttributes(ctx->NdisMiniport, ctx->NdisContext, FALSE, NdisInterfaceInternal);
	}
	else
	{
		NdisMSetAttributesEx(ctx->NdisMiniport, ctx->NdisContext, 16,
			NDIS_ATTRIBUTE_DESERIALIZE | NDIS_ATTRIBUTE_IGNORE_PACKET_TIMEOUT | NDIS_ATTRIBUTE_IGNORE_REQUEST_TIMEOUT | NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND,
			NdisInterfaceInternal);
	}

	// Initialize the received packet array
	NeoInitPacketArray();

	// Initialize the control device
	NeoInitControlDevice();

	// Start the adapter
	NeoStartAdapter();

	// Flag setting
	ctx->Initing = FALSE;
	ctx->Inited = TRUE;

	// Notify the connection state
	NeoSetConnectState(FALSE);

	return NDIS_STATUS_SUCCESS;
}