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

📄 smsc100fd.c

📁 smsc公司的网络芯片smsc100fd的wince源码。
💻 C
📖 第 1 页 / 共 5 页
字号:
    //
    gSmsc100FdMiniportBlock.AdapterQueue = (PSMSC100FD_ADAPTER)NULL;

    //
    // Initialize the Miniport characteristics for the call to
    // NdisMRegisterMiniport.
    //
    memset (&Characteristics, 0, sizeof (Characteristics));
    Characteristics.MajorNdisVersion = SMSC100FD_NDIS_MAJOR_VERSION;
    Characteristics.MinorNdisVersion = SMSC100FD_NDIS_MINOR_VERSION;
    Characteristics.CheckForHangHandler = NULL;
    Characteristics.DisableInterruptHandler = Smsc100FdDisableInterrupt;
    Characteristics.EnableInterruptHandler = Smsc100FdEnableInterrupt;
    Characteristics.HaltHandler = Smsc100FdHalt;
    Characteristics.HandleInterruptHandler = Smsc100FdHandleInterrupt;
    Characteristics.InitializeHandler = Smsc100FdInitialize;
    Characteristics.ISRHandler = Smsc100FdIsr;
    Characteristics.QueryInformationHandler = Smsc100FdQueryInformation;
    Characteristics.ReconfigureHandler = NULL;
    Characteristics.ResetHandler = Smsc100FdReset;
    Characteristics.SendHandler = Smsc100FdSend;
    Characteristics.SetInformationHandler = Smsc100FdSetInformation;
    Characteristics.TransferDataHandler = NULL;
    Characteristics.ReturnPacketHandler = NULL;
    Characteristics.SendPacketsHandler = NULL;
    Characteristics.AllocateCompleteHandler = NULL;

    Status = NdisMRegisterMiniport (gSmsc100FdMiniportBlock.NdisWrapperHandle, &Characteristics, sizeof (Characteristics));

	if (Status == NDIS_STATUS_SUCCESS)
		{
		DEBUGMSG (ZONE_INIT | ZONE_FUNCTION, (TEXT (" SMSC100FD:DriverEntry: Success\r\n")));
		Status = STATUS_SUCCESS;
		}
	else
		{
		// Terminate the wrapper.
		NdisTerminateWrapper (gSmsc100FdMiniportBlock.NdisWrapperHandle, NULL);
		gSmsc100FdMiniportBlock.NdisWrapperHandle = NULL;
		Status = STATUS_UNSUCCESSFUL;
		DEBUGMSG (ZONE_INIT | ZONE_FUNCTION, (TEXT ("!SMSC100FD:DriverEntry: Unsuccessful\r\n")));
		}
	DEBUGMSG (ZONE_INIT | ZONE_FUNCTION, (TEXT ("-SMSC100FD:DriverEntry\r\n")));
//	NKDbgPrintfW (L"-SMSC100FD: DriverEntry\r\n");
    return (Status);
	}

/*
 * Description:
 *	The Smsc100FdReset 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:
 *	pbAddressingReset - Does the adapter need the addressing information reloaded.
 *	hMiniportAdapterContext - Pointer to the adapter structure.
 *
 * Return Value:
 *	The status of the operation.
 */
NDIS_STATUS
Smsc100FdReset (OUT PBOOLEAN pbAddressingReset, IN NDIS_HANDLE hMiniportAdapterContext)
	{
	BOOLEAN bResult;
    //
    // Pointer to the adapter structure.
    //
    PSMSC100FD_ADAPTER pAdapter = (PSMSC100FD_ADAPTER)(hMiniportAdapterContext);

    DEBUGMSG (ZONE_FUNCTION, (TEXT ("+SMSC100FD: Reset\r\n")));
    //
    // Physically reset the card.
    //
    pAdapter->usNicInterruptMask = IM_TX_INT | IM_RCV_INT | IM_RX_OVRN_INT | IM_EPH_INT;

    DEBUGMSG (ZONE_FUNCTION, (TEXT ("-SMSC100FD: Reset\r\n")));
	bResult = CardReset (pAdapter);
	if (bResult)
		return (NDIS_STATUS_SUCCESS);
	return (NDIS_STATUS_FAILURE);
	}

/*
 * Description:
 *	This routine is used to turn on the interrupt mask.
 *
 * Arguments:
 *	Context - The adapter for the SMSC100FD to enable.
 *
 * Return Value:
 *	None.
 */
VOID
Smsc100FdEnableInterrupt (IN NDIS_HANDLE hMiniportAdapterContext)
	{
    PSMSC100FD_ADAPTER pAdapter = (PSMSC100FD_ADAPTER)(hMiniportAdapterContext);
	DEBUGMSG (ZONE_INTR, (TEXT ("+SMSC100FD: EnableInterrupt\r\n")));
    CardUnblockInterrupts (pAdapter);
	DEBUGMSG(ZONE_INTR, (TEXT ("-SMSC100FD: EnableInterrupt\r\n")));
	}

/*
 * Description:
 *	This routine is used to turn off the interrupt mask.
 *
 * Arguments:
 *	Context - The adapter for the SMSC100FD to disable.
 *
 * Return Value:
 *	None.
 */
VOID
Smsc100FdDisableInterrupt (IN NDIS_HANDLE hMiniportAdapterContext)
	{
	PSMSC100FD_ADAPTER pAdapter = (PSMSC100FD_ADAPTER)(hMiniportAdapterContext);
	DEBUGMSG (ZONE_INTR, (TEXT ("+SMSC100FD:DisableInterrupt\r\n")));
	CardBlockInterrupts (pAdapter);
	DEBUGMSG(ZONE_INTR, (TEXT ("-SMSC100FD:DisableInterrupt\r\n")));
	}

/*
 * Description:
 *	Smsc100FdHalt removes an adapter that was previously initialized.
 *
 * Arguments:
 *	hMiniportAdapterContext - The context value that the Miniport returned from Smsc100FdInitialize.
 *
 * Return Value:
 *	None.
 */
VOID
Smsc100FdHalt (IN NDIS_HANDLE hMiniportAdapterContext)
	{
    PSMSC100FD_ADAPTER pAdapter = (PSMSC100FD_ADAPTER)(hMiniportAdapterContext);
    DEBUGMSG (ZONE_FUNCTION, (TEXT ("+SMSC100FD: Halt\r\n")));
    //
    // Shut down the chip.
    //
    CardStop (pAdapter);
    //
    // Disconnect the interrupt line.
    //
    NdisMDeregisterInterrupt (&pAdapter->Interrupt);
    //
    // Pause, waiting for any DPC stuff to clear.
    //
    NdisMSleep (250000);
    //
    // Remove the adapter from the global queue of adapters.
    //
    if (gSmsc100FdMiniportBlock.AdapterQueue == pAdapter)
        gSmsc100FdMiniportBlock.AdapterQueue = pAdapter->NextAdapter;
	else
		{
        PSMSC100FD_ADAPTER TmpAdapter = gSmsc100FdMiniportBlock.AdapterQueue;
        while (TmpAdapter->NextAdapter != pAdapter)
            TmpAdapter = TmpAdapter->NextAdapter;
        TmpAdapter->NextAdapter = TmpAdapter->NextAdapter->NextAdapter;
	    }
	//
	// Was this the last NIC?
	//
	if ((gSmsc100FdMiniportBlock.AdapterQueue == NULL) && gSmsc100FdMiniportBlock.NdisWrapperHandle)
		{
		NdisTerminateWrapper (gSmsc100FdMiniportBlock.NdisWrapperHandle, NULL);
		gSmsc100FdMiniportBlock.NdisWrapperHandle = NULL;
		}
	//
	// If the initial VirtualAlloc was successful, then free the allocated memory.
	//
	if (pAdapter->pVirtualRegisterBase)
		VirtualFree ((PVOID)(pAdapter->pVirtualRegisterBase-(pAdapter->ulIoBaseAddress & (PAGE_SIZE-1))), 0, MEM_RELEASE);
    //
    // Free up the memory
    //
    NdisFreeMemory (pAdapter, sizeof (PSMSC100FD_ADAPTER), 0);
    DEBUGMSG (ZONE_FUNCTION, (TEXT ("-SMSC100FD: Halt\r\n")));
    return;
	}

/*
 * Description:
 *	Smsc100FdInitialize starts an adapter and registers resources with the wrapper.
 *
 * Arguments:
 *	OpenErrorStatus - Extra status bytes for opening token ring adapters.
 *  puiSelectedMediumIndex - Pointer to index of the media type chosen by the driver.
 *	MediumArray - Array of media types for the driver to chose from.
 *	uiMediumArraySize - Number of entries in the array.
 *	hMiniportAdapterHandle - Handle for passing to the wrapper when referring to this adapter.
 *	hConfigurationHandle - A handle to pass to NdisOpenConfiguration.
 *
 * Return Value:
 *	NDIS_STATUS_SUCCESS
 *	NDIS_STATUS_PENDING
 *	NDIS_STATUS_UNSUPPORTED_MEDIA
 */
#pragma NDIS_PAGEABLE_FUNCTION (Smsc100FdInitialize)
NDIS_STATUS
Smsc100FdInitialize (OUT PNDIS_STATUS OpenErrorStatus, OUT PUINT puiSelectedMediumIndex, IN PNDIS_MEDIUM MediumArray, IN UINT uiMediumArraySize, IN NDIS_HANDLE hMiniportAdapterHandle, IN NDIS_HANDLE hConfigurationHandle)
	{
    PSMSC100FD_ADAPTER pAdapter;	// Pointer to our newly allocated adapter.
    NDIS_HANDLE hConfigHandle;		// The handle for reading from the registry.
    BOOLEAN bConfigError = FALSE;	// TRUE if there is a configuration error.
    ULONG ulConfigErrorValue = 0;	// A special value to log concerning the error.
    //UCHAR ucInterruptNumber;		// The interrupt number to use.
    UINT uiIndex;					// Temporary looping variable.
    NDIS_STATUS Status;				// Status of Ndis calls.
	NDIS_PHYSICAL_ADDRESS HighestAcceptableMax = NDIS_PHYSICAL_ADDRESS_CONST(-1,-1);

    PNDIS_CONFIGURATION_PARAMETER ReturnedValue;
    NDIS_STRING IOAddressStr = IOADDRESS;
    NDIS_STRING InterruptStr = INTERRUPT;
    NDIS_STRING IOMultiplier = IOMULTIPLIER;


    DEBUGMSG (ZONE_FUNCTION, (TEXT ("+SMSC100FD: Initialize\r\n")));
//	NKDbgPrintfW (L"+SMSC100FD: Initialize\r\n");
    //
    // Search for the medium type (802.3) in the given array.
    //
    for (uiIndex = 0; uiIndex < uiMediumArraySize; uiIndex++)
		{
        if (MediumArray[uiIndex] == NdisMedium802_3)
            break;
	    }

    if (uiIndex == uiMediumArraySize)
		{
        DEBUGMSG (ZONE_INIT | ZONE_ERROR, (TEXT ("!SMSC100FD: Initialize: No supported media\r\n")));
        return (NDIS_STATUS_UNSUPPORTED_MEDIA);
		}
    *puiSelectedMediumIndex = uiIndex;
	DEBUGMSG (ZONE_INIT, (TEXT (" SMSC100FD: Selected media is %d.\r\n"), *puiSelectedMediumIndex));

    //
    // Set default values.
    //
    //ucInterruptNumber = SMSC100FDIrq;

    //
    // Allocate memory for the adapter block now.
    //
    Status = NdisAllocateMemory ((PVOID *)&pAdapter, sizeof (SMSC100FD_ADAPTER), 0, HighestAcceptableMax);
    if (Status != NDIS_STATUS_SUCCESS)
		{
        DEBUGMSG (ZONE_INIT | ZONE_ERROR, (TEXT ("!SMSC100FD: Initialize: NdisAllocateMemory (SMSC100FD_ADAPTER) failed.\r\n")));
        return (Status);
	    }
	DEBUGMSG (ZONE_INIT | ZONE_ERROR, (TEXT (" SMSC100FD: Initialize: pAdapter allocated at 0x%x.\r\n"), pAdapter));
//	NKDbgPrintfW (L" SMSC100FD: Initialize: pAdapter allocated at 0x%x.\r\n", pAdapter);
    //
    // Clear out the adapter block, which sets all default values to FALSE, or NULL.
    //
    NdisZeroMemory (pAdapter, sizeof (SMSC100FD_ADAPTER));
    //
    // Open the configuration space.
    //
    NdisOpenConfiguration (&Status, &hConfigHandle, hConfigurationHandle);
    if (Status != NDIS_STATUS_SUCCESS)		{
        NdisFreeMemory (pAdapter, sizeof (SMSC100FD_ADAPTER), 0);
        DEBUGMSG (ZONE_INIT, (TEXT ("!SMSC100FD: Initialize: NdisOpenConfiguration failed 0x%x\r\n"), Status));
        return (Status);
	}


	NdisReadConfiguration(
		&Status,
		&ReturnedValue,
		hConfigHandle,
		&IOMultiplier,
		NdisParameterHexInteger
		);
	
	if (Status == NDIS_STATUS_SUCCESS) {
		
		pAdapter->uMultiplier= (ReturnedValue->ParameterData.IntegerData);
		
	}
	else
		pAdapter->uMultiplier=1;// Default
	//
	// Read I/O Address
	//
	NdisReadConfiguration(
		&Status,
		&ReturnedValue,
		hConfigHandle,
		&IOAddressStr,
		NdisParameterHexInteger
		);
	
	if (Status == NDIS_STATUS_SUCCESS) {
		
		pAdapter->ulIoBaseAddress= (ReturnedValue->ParameterData.IntegerData);
		
		
		NdisReadConfiguration(
			&Status,
			&ReturnedValue,
			hConfigHandle,
			&InterruptStr,
			NdisParameterInteger
			);
		if (Status == NDIS_STATUS_SUCCESS) {
			
			pAdapter->ucInterruptNumber= (CCHAR)(ReturnedValue->ParameterData.IntegerData);
			
		}
	
	}
	
    DEBUGMSG (ZONE_INIT, (TEXT (" SMSC100FD: IO address 0x%lx, Interrupt number 0x%lx, io multiplier=0x%lx\r\n"), 
		pAdapter->ulIoBaseAddress,pAdapter->ucInterruptNumber,pAdapter->uMultiplier));
    //
    // First close the configuration space.
    //
    NdisCloseConfiguration (hConfigHandle);

	if (Status !=NDIS_STATUS_SUCCESS) {
        NdisFreeMemory (pAdapter, sizeof (SMSC100FD_ADAPTER), 0);
        DEBUGMSG (ZONE_INIT, (TEXT ("!SMSC100FD: Initialize: NdisReadCOnfiguration failed 0x%x\r\n"), Status));
		return Status;
	}

    //
    // Set up the parameters.
    //
//	pAdapter->ucInterruptNumber = ucInterruptNumber;
	pAdapter->hMiniportAdapterHandle = hMiniportAdapterHandle;
	pAdapter->ulMaxLookAhead = MAX_LOOKAHEAD;

    //
    // Now do the work.
    //
    if (Smsc100FdRegisterAdapter (pAdapter, hConfigurationHandle, bConfigError, ulConfigErrorValue) != NDIS_STATUS_SUCCESS)	{
        //
        // Smsc100FdRegisterAdapter failed.
        //
        NdisFreeMemory (pAdapter, sizeof (SMSC100FD_ADAPTER), 0);
        DEBUGMSG (ZONE_INIT, (TEXT ("!SMSC100FD: NdisRegisterAdapter failed.\r\n")));
        return (NDIS_STATUS_FAILURE);
	}

    DEBUGMSG (ZONE_INIT, (TEXT (" SMSC100FD: Initialize succeeded\r\n")));
    DEBUGMSG (ZONE_FUNCTION, (TEXT ("-SMSC100FD: Initialize\r\n")));

	// Dump all the registers before coming out.
	printregs(pAdapter);	
	printregs(pAdapter);	
//	NKDbgPrintfW (L"-SMSC100FD: Initialize\r\n");
    return (NDIS_STATUS_SUCCESS);
}

/*
 * 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:
 *	pAdapter - Pointer to the adapter structure.
 *	hConfigurationHandle - Handle passed to Smsc100FdInitialize.
 *	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.
 */
#pragma NDIS_PAGEABLE_FUNCTION(Smsc100FdRegisterAdapter)
NDIS_STATUS
Smsc100FdRegisterAdapter (IN PSMSC100FD_ADAPTER pAdapter, IN NDIS_HANDLE hConfigurationHandle, IN BOOLEAN bConfigError, IN ULONG ulConfigErrorValue)
{
    NDIS_STATUS status;	// General purpose return from NDIS calls

	DEBUGMSG (ZONE_INIT, (TEXT ("+SMSC100FD: RegisterAdapter: pAdapter is 0x%x\r\n"), pAdapter));
    //
    // Check for a configuration error
    //
    if (bConfigError)
		{
        //
        // Log Error and exit.
        //
        NdisWriteErrorLogEntry (pAdapter->hMiniportAdapterHandle, NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION, 1, ulConfigErrorValue);
        DEBUGMSG (ZONE_INIT, (TEXT ("!SMSC100FD: RegisterAdapter: Smsc100FdInitialize had a config error %d\r\n"), ulConfigErrorValue));
        DEBUGMSG (ZONE_INIT, (TEXT ("-SMSC100FD: RegisterAdapter\r\n")));
        return (NDIS_STATUS_FAILURE);
		}

    //
    // Inform the wrapper of the physical attributes of this adapter.

⌨️ 快捷键说明

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