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

📄 miniport.c

📁 wince底层驱动开发代码 ARM作为一种嵌入式系统处理器
💻 C
📖 第 1 页 / 共 3 页
字号:
			&IOAddressStr,
			NdisParameterHexInteger
			);

		if (Status == NDIS_STATUS_SUCCESS) {
	    	IoBaseAddr = (PVOID)(ReturnedValue->ParameterData.IntegerData);
		}

		//
		// Read	interrupt number
		//
		NdisReadConfiguration(
			&Status,
			&ReturnedValue,
			ConfigHandle,
			&InterruptStr,
			NdisParameterInteger
			);

		if (Status == NDIS_STATUS_SUCCESS) {
	    	InterruptNumber = (CCHAR)(ReturnedValue->ParameterData.IntegerData);
		}
    }

    //
    // Read MaxMulticastList
	//
    NdisReadConfiguration(
		&Status,
	    &ReturnedValue,
	    ConfigHandle,
	    &MaxMulticastListStr,
	    NdisParameterInteger
	    );

    if (Status == NDIS_STATUS_SUCCESS) {
		MaxMulticastList = ReturnedValue->ParameterData.IntegerData;
		if (ReturnedValue->ParameterData.IntegerData <=	DEFAULT_MULTICASTLISTMAX)
			MaxMulticastList = ReturnedValue->ParameterData.IntegerData;
    }


	// RegisterAdapter:

    //
    // Now to use this information and register	with the wrapper
    // and initialize the adapter.
    //

    //
    // First close the configuration space.
    //
    NdisCloseConfiguration(ConfigHandle);

    DEBUGMSG(1, (TEXT("CS8900:Card type: 0x%x\r\n"), Adapter->CardType));
    DEBUGMSG(1, (TEXT("CS8900:I/O base	addr 0x%lx\r\n"), IoBaseAddr));
    DEBUGMSG(1, (TEXT("CS8900:interrupt number	%ld\r\n"),
	InterruptNumber));
    DEBUGMSG(1, (TEXT("CS8900:max multicast %ld\r\n"),
	DEFAULT_MULTICASTLISTMAX));
    DEBUGMSG(1, (TEXT("CS8900:attribute memory	address	0x%X\r\n"),
	Adapter->AttributeMemoryAddress));
    DEBUGMSG(1, (TEXT("CS8900:attribute memory	size 0x%X\r\n"),
	Adapter->AttributeMemorySize));
    DEBUGMSG(1, (TEXT("CS8900:Bus type: %d\r\n"), Adapter->BusType));

    //
    // Set up the parameters.
    //
    Adapter->IoBaseAddr	= IoBaseAddr;

	Adapter->InterruptNumber = InterruptNumber;

    Adapter->MulticastListMax =	MaxMulticastList;
    Adapter->MiniportAdapterHandle = MiniportAdapterHandle;

    Adapter->MaxLookAhead = CS8900_MAX_LOOKAHEAD;

    //
    // Now do the work.
    //
    if (CS8900RegisterAdapter(Adapter,
		ConfigurationHandle,
		ConfigError,
		ConfigErrorValue
		) != NDIS_STATUS_SUCCESS) {

		//
		// CS8900RegisterAdapter failed.
		//
		NdisFreeMemory(Adapter,	sizeof(CS8900_ADAPTER),	0);

		return NDIS_STATUS_FAILURE;

	}

    DEBUGMSG(1, (TEXT("-CS8900:CS8900Initialize Success!\r\n")));
    return NDIS_STATUS_SUCCESS;
}


#pragma	NDIS_PAGEABLE_FUNCTION(CS8900RegisterAdapter)
NDIS_STATUS
CS8900RegisterAdapter(
    IN PCS8900_ADAPTER Adapter,
    IN NDIS_HANDLE ConfigurationHandle,
    IN BOOLEAN ConfigError,
    IN ULONG ConfigErrorValue
    )

/*++

Routine	Description:

    Called when	a new adapter should be	registered. It allocates space for
    the	adapter, initializes the adapter's block, registers resources
    with the wrapper and initializes the physical adapter.

Arguments:

    Adapter - The adapter structure.

    ConfigurationHandle	- Handle passed	to CS8900Initialize.

    ConfigError	- Was there an error during configuration reading.

    ConfigErrorValue - Value to	log if there is	an error.

Return Value:

    Indicates the success or failure of	the registration.

--*/

{
    //
    // Temporary looping variable.
    //
    unsigned char *m_pCS8900IoPort;

    //
    // General purpose return from NDIS	calls
    //
    NDIS_STATUS	status;

	DEBUGMSG(1, (TEXT("+CS8900:CS8900RegisterAdapter\r\n")));

    //
    // Check for a configuration error
    //
    if (ConfigError)
    {
		//
		// Log Error and exit.
		//
		NdisWriteErrorLogEntry(
			Adapter->MiniportAdapterHandle,
			NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION,
			1,
			ConfigErrorValue
			);
		DEBUGMSG(1,
			(TEXT("CS8900:RegisterAdapter: CS8900Initialize had	a config error %d\r\n"),
			ConfigErrorValue));

		return(NDIS_STATUS_FAILURE);
	}

    //
    // Inform the wrapper of the physical attributes of	this adapter.
    //
	DEBUGMSG(1, (TEXT("CS8900: -> NdisMSetAttributes\r\n")));
		
    NdisMSetAttributes(
		Adapter->MiniportAdapterHandle,
		(NDIS_HANDLE)Adapter,
		FALSE,
		Adapter->BusType
		);

	m_pCS8900IoPort	= VirtualAlloc(0, 0x1000, MEM_RESERVE, PAGE_NOACCESS);
	DEBUGMSG(1,
		(TEXT("[CS8900] VirtualAlloc of m_pCS8900IoPort returns %x\r\n"), m_pCS8900IoPort));

	if (!VirtualCopy(m_pCS8900IoPort, (LPVOID)((IO_PACKET_PAGE_BASE_ADDR) & 0xFFFFF000),
						0x1000,	PAGE_READWRITE|PAGE_NOCACHE) )
		DEBUGMSG(1, (TEXT("[CS8900] m_pCS8900IoPort Virtual Copy failed\r\n")));
	else
		DEBUGMSG(1, (TEXT("[CS8900] m_pCS8900IoPort Virtual Copy OK!\r\n")));


	ioPacketPage = (volatile unsigned char *)(m_pCS8900IoPort + 
		(IO_PACKET_PAGE_BASE_ADDR - ((IO_PACKET_PAGE_BASE_ADDR) & 0xFFFFF000)) );
	Adapter->IoPAddr = (unsigned long)ioPacketPage;

	DEBUGMSG(1, (TEXT("[CS8900] m_pCS8900IoPort= %x\r\n"), Adapter->IoPAddr));


/*    
    //
    // Register	the port addresses.
    //

	DEBUGMSG(1,
		(TEXT("CS8900: -> NdisMRegisterIoPortRange\r\n")));
    status = NdisMRegisterIoPortRange(
		 (PVOID	*)(&(Adapter->IoPAddr)),
		 Adapter->MiniportAdapterHandle,
		 (ULONG)Adapter->IoBaseAddr,
		 0x20
	     );

    if (status != NDIS_STATUS_SUCCESS)
    {
	DEBUGMSG(1,
			(TEXT("CS8900:NdisMRegisterIoPortRange unsuccessful!\r\n")));
	return(status);
	}     
*/
    if (Adapter->IoPAddr == 0)
    {
		DEBUGMSG(1, (TEXT("CS8900:Invalid IoPAddr!\r\n")));
		return NDIS_STATUS_FAILURE;
    }

    //
    // Initialize the card.
    //
    DEBUGMSG(1, (TEXT("+CS8900:CS8900Initialize\r\n")));

    if (!CS8900Initialize(Adapter))
    {
		DEBUGMSG(1, (TEXT("-CS8900:CS8900Initialize - Fail!\r\n")));

		NdisWriteErrorLogEntry(
	    	Adapter->MiniportAdapterHandle,
	    	NDIS_ERROR_CODE_ADAPTER_NOT_FOUND,
	    	0
			);

		status = NDIS_STATUS_ADAPTER_NOT_FOUND;

		goto fail2;
    }

    DEBUGMSG(1, (TEXT("-CS8900:CS8900Initialize	- Success!\r\n")));

    //
    // Read the	Ethernet address off of	the PROM.
    //
    if (!CS8900ReadEthernetAddress(Adapter))
    {
		DEBUGMSG(1, (TEXT("CS8900:RegisterAdapter Could	not read the ethernet address\n")));

		NdisWriteErrorLogEntry(
			Adapter->MiniportAdapterHandle,
	    	NDIS_ERROR_CODE_ADAPTER_NOT_FOUND,
			0
	    	);

		status = NDIS_STATUS_ADAPTER_NOT_FOUND;

		goto fail2;
    }

    //
    // Initialize the interrupt.
    //
    status = NdisMRegisterInterrupt(
		 &Adapter->Interrupt,
		 Adapter->MiniportAdapterHandle,
		 Adapter->InterruptNumber,
		 Adapter->InterruptNumber,
		 TRUE,
		 FALSE,
		 NdisInterruptLatched
	     );

    if (status != NDIS_STATUS_SUCCESS)
    {
		DEBUGMSG(1, (TEXT("CS8900:RegisterAdapter -> NdisMRegisterInterrupt failed 0x%x\r\n"), status));
		NdisWriteErrorLogEntry(
	    	Adapter->MiniportAdapterHandle,
	    	NDIS_ERROR_CODE_INTERRUPT_CONNECT,
	    	0
		);

		goto fail3;
    }

    DEBUGMSG(1,
	(TEXT("CS8900:RegisterAdapter Interrupt Connected\r\n")));

    // register	a shutdown handler for this card
	NdisMRegisterAdapterShutdownHandler(
		Adapter->MiniportAdapterHandle,		// miniport handle.
		Adapter,							// shutdown context.
		CS8900Shutdown						// shutdown handler.
		);
    
	/* Initialize The Interrupt */

	DEBUGMSG(1, (TEXT("CS8900RegisterAdapter:Initialize the Interrupt!\r\n")));

    //
    // Initialization completed	successfully.
    //
    DEBUGMSG(1, (TEXT("CS8900:RegisterAdapter OK\r\n")));

    return(NDIS_STATUS_SUCCESS);

    //
    // Code to unwind what has already been set	up when	a part of
    // initialization fails, which is jumped into at various
    // points based on where the failure occured. Jumping to
    // a higher-numbered failure point will execute the	code
    // for that	block and all lower-numbered ones.
    //

fail3:

    //
    // Take us out of the AdapterQueue.
    //

    if (CS8900MiniportBlock.AdapterQueue == Adapter)
    {
		CS8900MiniportBlock.AdapterQueue = Adapter->NextAdapter;
    }
    else
    {
		PCS8900_ADAPTER	TmpAdapter = CS8900MiniportBlock.AdapterQueue;

		while (TmpAdapter->NextAdapter != Adapter)
		{
			TmpAdapter = TmpAdapter->NextAdapter;
		}

		TmpAdapter->NextAdapter	= TmpAdapter->NextAdapter->NextAdapter;
    }

fail2:

    NdisMDeregisterIoPortRange(
		Adapter->MiniportAdapterHandle,
		(ULONG)Adapter->IoBaseAddr,
		0x20,
		(PVOID)Adapter->IoPAddr
    	);

    return(status);
}

extern
VOID
CS8900Shutdown(
    IN NDIS_HANDLE MiniportAdapterContext
    )
/*++

Routine	Description:

    CS8900Shutdown is called to	shut down the adapter. We need to unblock any
    threads which may be called	in, and	terminate any loops.  This function is
    called by the WinCE	NDIS.DLL when a	PCMCIA card removal is detected.  At that
    point, any access to the CS8900 registers may return random	data, as the bus
    is floating.

Arguments:

    MiniportAdapterContext - The context value that the	Miniport returned
	from CS8900Initialize; actually	as pointer to an CS8900_ADAPTER.

Return Value:

    None.

--*/	
{
    PCS8900_ADAPTER Adapter;

    Adapter = PCS8900_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);

    Adapter->ShuttingDown = TRUE;

	DEBUGMSG(1, (TEXT("+CS8900:CS8900Shutdown - Not Implemented!\r\n")));
}


extern
VOID
CS8900Halt(
    IN NDIS_HANDLE MiniportAdapterContext
    )

/*++

Routine	Description:

    CS8900Halt removes an adapter that was previously initialized.

Arguments:

    MiniportAdapterContext - The context value that the	Miniport returned
	from CS8900Initialize; actually	as pointer to an CS8900_ADAPTER.

Return Value:

    None.

--*/

{
    PCS8900_ADAPTER Adapter;

    Adapter = PCS8900_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);

	DEBUGMSG(1, (TEXT("+CS8900:CS8900Halt\r\n")));
//	while(1);
	
    return;
}




NDIS_STATUS
CS8900Reset(
    OUT	PBOOLEAN AddressingReset,
    IN NDIS_HANDLE MiniportAdapterContext
    )
/*++

Routine	Description:

    The	CS8900Reset request instructs the Miniport to issue a hardware reset
    to the network adapter.  The driver	also resets its	software state.	 See
    the	description of NdisMReset for a	detailed description of	this request.

Arguments:

    AddressingReset - Does the adapter need the	addressing information reloaded.

    MiniportAdapterContext - Pointer to	the adapter structure.

Return Value:

    The	function value is the status of	the operation.

--*/

{
    //
    // Pointer to the adapter structure.
    //
    PCS8900_ADAPTER Adapter = (PCS8900_ADAPTER)MiniportAdapterContext;

	DEBUGMSG(1, (TEXT("+CS8900:CS8900Reset\r\n")));
	RETAILMSG(1, (TEXT("----- !!!!!!!! reset !!!!!!!!!!! ------\r\n")));
//	while (1);

	return NDIS_STATUS_SUCCESS;
}

NDIS_STATUS
CS8900QueryInformation(
    IN NDIS_HANDLE MiniportAdapterContext,
    IN NDIS_OID	Oid,
    IN PVOID InformationBuffer,
    IN ULONG InformationBufferLength,
    OUT	PULONG BytesWritten,
    OUT	PULONG BytesNeeded
)

/*++

Routine	Description:

    The	CS8900QueryInformation process a Query request for
    NDIS_OIDs that are specific	about the Driver.

Arguments:

    MiniportAdapterContext - a pointer to the adapter.

    Oid	- the NDIS_OID to process.

    InformationBuffer -	 a pointer into	the
    NdisRequest->InformationBuffer into	which store the	result of the query.

    InformationBufferLength - a	pointer	to the number of bytes left in the
    InformationBuffer.

    BytesWritten - a pointer to	the number of bytes written into the
    InformationBuffer.

    BytesNeeded	- If there is not enough room in the information buffer
    then this will contain the number of bytes needed to complete the
    request.

Return Value:

    The	function value is the status of	the operation.

--*/
{

    //
    // Pointer to the adapter structure.
    //
    PCS8900_ADAPTER Adapter = (PCS8900_ADAPTER)MiniportAdapterContext;

    //
    //	 General Algorithm:
    //
    //	    Switch(Request)
    //	       Get requested information
    //	       Store results in	a common variable.
    //	    default:
    //	       Try protocol query information
    //	       If that fails, fail query.
    //
    //	    Copy result	in common variable to result buffer.
    //	 Finish	processing

    UINT BytesLeft = InformationBufferLength;
    PUCHAR InfoBuffer =	(PUCHAR)(InformationBuffer);
    NDIS_STATUS	StatusToReturn = NDIS_STATUS_SUCCESS;
    NDIS_HARDWARE_STATUS HardwareStatus	= NdisHardwareStatusReady;
    NDIS_MEDIUM	Medium = NdisMedium802_3;

⌨️ 快捷键说明

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