Exemple #1
0
NDIS_STATUS
shared_interrupt_register(OUT PNDIS_MINIPORT_INTERRUPT Interrupt,
NDIS_HANDLE MiniportAdapterHandle,
UINT InterruptVector,
UINT InterruptLevel,
BOOLEAN RequestIsr,
BOOLEAN SharedInterrupt,
NDIS_INTERRUPT_MODE InterruptMode,
shared_info_t *sh,
void (*isr_cb)(PBOOLEAN, PBOOLEAN, NDIS_HANDLE),
void *isr_arg,
void (*dpc_cb)(NDIS_HANDLE),
void *dpc_arg)
{
	if (sh->BusType == NdisInterfacePci || sh->BusType == NdisInterfacePcMcia) {
		return NdisMRegisterInterrupt(Interrupt, MiniportAdapterHandle,
		                        InterruptVector, InterruptLevel,
		                        RequestIsr,
		                        SharedInterrupt,
		                        InterruptMode);
	}
	else if (sh->BusType == NdisInterfaceSDIO) {
		sh->isr_cb  = isr_cb;
		sh->isr_arg = isr_arg;

		NdisInitializeEvent(&sh->dpc_event);
		NdisResetEvent(&sh->dpc_event);
		sh->dpc_handle = CreateThread(NULL,		/* security atributes */
						0,		/* initial stack size */
			(LPTHREAD_START_ROUTINE)shared_dpc_thread,	/* Main() function */
						sh,		/* arg to reader thread */
						0,		/* creation flags */
						&sh->dpc_thread_id); /* returned thread id */
		if (!sh->dpc_handle)
			return NDIS_STATUS_FAILURE;

		if (bcmsdh_intr_reg(sh->sdh, shared_isr, sh))
			return NDIS_STATUS_FAILURE;

	}

	sh->dpc_cb  = dpc_cb;
	sh->dpc_arg = dpc_arg;

	/* Initilize the timer required to reschdule the DPC, if necessary */
	NdisInitializeTimer(&sh->dpc_reshed_timer, shared_dpc_reschedule, (PVOID)sh);

	return NDIS_STATUS_SUCCESS;
}
Exemple #2
0
	/* Initilize the timer required to reschdule the DPC, if necessary */
	NdisInitializeTimer(&sh->dpc_reshed_timer, shared_dpc_reschedule, (PVOID)sh);

	return NDIS_STATUS_SUCCESS;
}
#else /* !NDIS60 */
NDIS_STATUS
shared_interrupt_register(NDIS_HANDLE MiniportAdapterHandle,
shared_info_t *sh,
void (*isr_cb)(PBOOLEAN, PBOOLEAN, NDIS_HANDLE),
void *isr_arg,
void (*dpc_cb)(NDIS_HANDLE),
void *dpc_arg)
{
	if (sh->BusType == NdisInterfaceSDIO) {
		sh->isr_cb  = isr_cb;
		sh->isr_arg = isr_arg;

		sh->dpc_handle = CreateThread(NULL,		/* security atributes */
						0,		/* initial stack size */
			(LPTHREAD_START_ROUTINE)shared_dpc_thread,	/* Main() function */
						sh,		/* arg to reader thread */
						0,		/* creation flags */
						&sh->dpc_thread_id); /* returned thread id */
		if (!sh->dpc_handle)
		{
			 printf("---> shared_interrupt_register error 1\n");

			return NDIS_STATUS_FAILURE;
		}

		NdisInitializeEvent(&sh->dpc_event);
		NdisResetEvent(&sh->dpc_event);

		if (bcmsdh_intr_reg(sh->sdh, shared_isr, sh))
		{
			 printf("---> shared_interrupt_register Error 2\n");

			return NDIS_STATUS_FAILURE;
		}
	}

	sh->dpc_cb  = dpc_cb;
	sh->dpc_arg = dpc_arg;
	/* WM7 TODO: do we need this? */
	/* Initilize the timer required to reschdule the DPC, if necessary */
	NdisInitializeTimer(&sh->dpc_reshed_timer, shared_dpc_reschedule, (PVOID)sh);

	return NDIS_STATUS_SUCCESS;
}
Exemple #3
0
NDIS_STATUS
LtInitRegisterAdapter(
	IN NDIS_HANDLE 			LtMacHandle,
	IN NDIS_HANDLE 			WrapperConfigurationContext,
	IN PNDIS_STRING 		AdapterName,
	IN NDIS_INTERFACE_TYPE 	BusType,
	IN UCHAR				SuggestedNodeId,
	IN UINT 				IoBaseAddress,
	IN UINT 				MaxAdapters,
	IN NDIS_STATUS			ConfigError
	)
/*++

Routine Description:

	This routine (and its interface) are not portable.  They are
	defined by the OS, the architecture, and the particular Lt
	implementation.

	This routine is responsible for the allocation of the datastructures
	for the driver as well as any hardware specific details necessary
	to talk with the device.

Arguments:

	LtMacHandle		:	The handle given back to the mac from ndis when
						the mac registered itself.

	WrapperConfigurationContext
					:	configuration context passed in by NDIS in the AddAdapter
						call.

	AdapterName		:	The string containing the name to give to the device adapter.
	BusType 		:	The type of bus in use. (MCA, ISA, EISA ...)
	IoBaseAddress 	:	The base IO address of the card.
	MaxAdapters 	:	The maximum number of opens at any one time.
	ConfigError		:	Error with the Config parameters if any.

Return Value:

	NDIS_STATUS_SUCCESS	: 	If successful, error otherwise.

--*/
{
	// Pointer for the adapter root.
	PLT_ADAPTER 	Adapter;
	NDIS_STATUS 	Status, RefStatus;
	NDIS_ERROR_CODE	LogErrorCode;

	// Holds information needed when registering the adapter.
	NDIS_ADAPTER_INFORMATION AdapterInformation;

	// Allocate the Adapter block.
	NdisAllocateMemory(
		(PVOID)&Adapter,
		sizeof(LT_ADAPTER),
		0,
		LtNdisPhyAddr);

	if (Adapter == NULL)
	{
		return(NDIS_STATUS_RESOURCES);
	}

	NdisZeroMemory(
		Adapter,
		sizeof(LT_ADAPTER));

	Adapter->NdisMacHandle = LtMacHandle;

	// Set up the AdapterInformation structure.
	NdisZeroMemory (&AdapterInformation, sizeof(NDIS_ADAPTER_INFORMATION));

	AdapterInformation.DmaChannel 						= 0;
	AdapterInformation.Master 							= FALSE ;
	AdapterInformation.Dma32BitAddresses 				= FALSE ;
	AdapterInformation.AdapterType 						= BusType ;
	AdapterInformation.PhysicalMapRegistersNeeded 		= 0;
	AdapterInformation.MaximumPhysicalMapping 			= 0;
	AdapterInformation.NumberOfPortDescriptors 			= 1 ;
	AdapterInformation.PortDescriptors[0].InitialPort 	= IoBaseAddress;
	AdapterInformation.PortDescriptors[0].NumberOfPorts	= 4;
	AdapterInformation.PortDescriptors[0].PortOffset	= (PVOID *)(&(Adapter->MappedIoBaseAddr));

	DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
			("LtInitRegisterAdapter: IoBaseAddr %lx\n", IoBaseAddress));

	// Register the adapter with NDIS.
	if ((Status = NdisRegisterAdapter(
						&Adapter->NdisAdapterHandle,
						Adapter->NdisMacHandle,
						Adapter,
						WrapperConfigurationContext,
						AdapterName,
						&AdapterInformation)) != NDIS_STATUS_SUCCESS)
	{
		//	Could not register the adapter, so we cannot log any errors
		//	either.
		DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_FATAL,
				("LtInitRegisterAdapter: Failed %lx\n", Status));

		//	Free up the memory allocated.
		NdisFreeMemory(
			Adapter,
			sizeof(LT_ADAPTER),
			0);

		return(Status);
	}

	DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_ERR,
			("LtInitRegisterAdapter: MappedIoBaseAddr %lx\n", Adapter->MappedIoBaseAddr));

	do
	{
		//	Ok. We are all set.
		Adapter->BusType 		= BusType;

		InitializeListHead(&Adapter->Request);
		InitializeListHead(&Adapter->OpenBindings);

		InitializeListHead(&Adapter->LoopBack);
		InitializeListHead(&Adapter->Transmit);
		InitializeListHead(&Adapter->Receive);

		NdisAllocateSpinLock(&Adapter->Lock);

		Adapter->OpenCount 	= 0;

		//	Set refcount to 1 - creation
		Adapter->RefCount	= 1;	

		NdisInitializeTimer(
			&Adapter->PollingTimer,
			LtTimerPoll,
			(PVOID)Adapter);

		//	If there were no configuration errors, then go ahead with the
		//	initialize.

		if (ConfigError == NDIS_STATUS_SUCCESS)
		{
			// Start the card up. This writes an error
			// log entry if it fails.
			if (LtFirmInitialize(Adapter, SuggestedNodeId))
			{
				//	Ok, the firmware code has been downloaded to the card.
				//	Start the poll timer. We should do this before we call
				//	GetAddress. Add a reference for the timer.
				NdisAcquireSpinLock(&Adapter->Lock);
				LtReferenceAdapterNonInterlock(Adapter, &RefStatus);

				ASSERTMSG("LtInitRegisterAdapter: RefAdater Failed!\n",
						 (RefStatus == NDIS_STATUS_SUCCESS));

				Adapter->Flags |= ADAPTER_TIMER_QUEUED;
				NdisSetTimer(&Adapter->PollingTimer, LT_POLLING_TIME);
				NdisReleaseSpinLock(&Adapter->Lock);
				break;
			}

			LogErrorCode = NDIS_ERROR_CODE_HARDWARE_FAILURE;

		}
		else
		{
			LogErrorCode = NDIS_ERROR_CODE_MISSING_CONFIGURATION_PARAMETER;
		}


		//	We either could not initialize the hardware or get the node
		//	address. OR there was a config error. Log it and deregister
		//	the adapter.
		LOGERROR(Adapter->NdisAdapterHandle, LogErrorCode);

		//	Deregister the adapter. This calls LtInitRemoveAdapter which
		//	will do all necessary cleanup.
		NdisDeregisterAdapter(Adapter->NdisAdapterHandle);
				
		Status = NDIS_STATUS_FAILURE;
		break;

	} while (FALSE);

	return(Status);
}
Exemple #4
0
/*************************************************************************
 * SteMiniportinitialize()
 *
 *  NDIS エントリポイント
 *   ネットワーク I/O 操作のために NIC ドライバがネットワーク I/O 操作を
 *   するために必要なリソースを確保する。
 *
 *  引数:
 *
 *         OpenErrorStatus              OUT PNDIS_STATUS 
 *         SelectedMediumIndex          OUT PUINT        
 *         MediumArray                  IN PNDIS_MEDIUM  
 *         MediumArraySize              IN UINT          
 *         MiniportAdapterHandle        IN NDIS_HANDLE   
 *         WrapperConfigurationContext  IN NDIS_HANDLE   
 *
 *  返り値:
 *    
 *     正常時: NDIS_STATUS_SUCCESS
 *
 *************************************************************************/
NDIS_STATUS 
SteMiniportInitialize(
    OUT PNDIS_STATUS OpenErrorStatus,
    OUT PUINT        SelectedMediumIndex,
    IN PNDIS_MEDIUM  MediumArray,
    IN UINT          MediumArraySize,
    IN NDIS_HANDLE   MiniportAdapterHandle,
    IN NDIS_HANDLE   WrapperConfigurationContext
    )
{
    UINT             i;
    NDIS_STATUS     Status  = NDIS_STATUS_SUCCESS;
    STE_ADAPTER    *Adapter = NULL;
    BOOLEAN          MediaFound = FALSE;

    DEBUG_PRINT0(3, "SteMiniportInitialize called\n");    

    *SelectedMediumIndex = 0;
    
    for ( i = 0 ; i < MediumArraySize ; i++){
        if (MediumArray[i] == NdisMedium802_3){
            *SelectedMediumIndex = i;
            MediaFound = TRUE;
            break;
        }
    }

    // 途中で break するためだけの Do-While 文
    do {
        if(!MediaFound){
            // 上記の for 文で見つけられなかったようだ
            DEBUG_PRINT0(1, "SteMiniportInitialize: No Media much\n");        
            Status = NDIS_STATUS_UNSUPPORTED_MEDIA;
            break;
        }

        //
        // Adapter を確保し、初期化する
        //
        if ((Status = SteCreateAdapter(&Adapter)) != NDIS_STATUS_SUCCESS){
            DEBUG_PRINT0(1, "SteMiniportInitialize: Can't allocate memory for STE_ADAPTER\n");
            Status = NDIS_STATUS_RESOURCES;
            break;
        }

        DEBUG_PRINT1(3, "SteMiniportInitialize: Adapter = 0x%p\n", Adapter);        

        Adapter->MiniportAdapterHandle = MiniportAdapterHandle;

        //
        // Registory を読む処理。...省略。
        //    NdisOpenConfiguration();
        //    NdisReadConfiguration();
        //
        // NIC のためのハードウェアリソースのリストを得る。...省略。
        //    NdisMQueryAdapterResources()
        //

        //
        // NDIS に NIC の情報を伝える。
        // かならず NdisXxx 関数を呼び出すより前に、以下の NdisMSetAttributesEx
        // を呼び出さなければならない。
        //
        NdisMSetAttributesEx(
            MiniportAdapterHandle,       //IN NDIS_HANDLE 
            (NDIS_HANDLE) Adapter,       //IN NDIS_HANDLE 
            0,                           //IN UINT  
            NDIS_ATTRIBUTE_DESERIALIZE,  //IN ULONG  Deserialized ミニポートドライバ
            NdisInterfaceInternal        //IN NDIS_INTERFACE_TYPE 
            );

        //
        // NDIS 5.0 の場合はかならず SHUTDOWN_HANDLER を登録しなければならない。
        //
        NdisMRegisterAdapterShutdownHandler(
            MiniportAdapterHandle,                         // IN NDIS_HANDLE
            (PVOID) Adapter,                               // IN PVOID 
            (ADAPTER_SHUTDOWN_HANDLER) SteMiniportShutdown // IN ADAPTER_SHUTDOWN_HANDLER  
            );

        //
        // 仮想 NIC デーモンからの IOCT/ReadFile/WriteFile 用の
        // デバイスを作成し、Dispatch ルーチンを登録する。
        //
        SteRegisterDevice(Adapter);
    
        //
        // SteRecvTimerFunc() を呼ぶためのタイマーオブジェクトを初期化
        //

        NdisInitializeTimer(
            &Adapter->RecvTimer,     //IN OUT PNDIS_TIMER  
            SteRecvTimerFunc,        //IN PNDIS_TIMER_FUNCTION      
            (PVOID)Adapter           //IN PVOID
            );
        //
        // SteResetTimerFunc() を呼ぶためのタイマーオブジェクトを初期化
        //
        NdisInitializeTimer(
            &Adapter->ResetTimer,    //IN OUT PNDIS_TIMER  
            SteResetTimerFunc,       //IN PNDIS_TIMER_FUNCTION      
            (PVOID)Adapter           //IN PVOID
            );
        
    } while (FALSE);
    
    
    return(Status);
}