Пример #1
0
U32		C_DM9000::DeviceReadDataWithoutIncrement(void)
{
	U32		value,tmp;

	ENTER_CRITICAL_SECTION

	VALIDATE_ADDR_PORT(DM9_MRCMDX);

	switch (m_nIoMode)
	{
		case BYTE_MODE:
			NdisRawReadPortUchar(
				m_szCurrentSettings[SID_PORT_BASE_ADDRESS] 
				+ DM9000_DATA_OFFSET, (PU8)&tmp);
			NdisRawReadPortUchar(
				m_szCurrentSettings[SID_PORT_BASE_ADDRESS] 
				+ DM9000_DATA_OFFSET, (PU8)&value);
			value = (value&0x000000FF);
			break;

		case WORD_MODE:
			NdisRawReadPortUshort(
				m_szCurrentSettings[SID_PORT_BASE_ADDRESS] 
				+ DM9000_DATA_OFFSET, (PU16)&tmp);
			NdisRawReadPortUshort(
				m_szCurrentSettings[SID_PORT_BASE_ADDRESS] 
				+ DM9000_DATA_OFFSET, (PU16)&value);
			value = (value&0x0000FFFF);
			break;
				
		case DWORD_MODE:
			NdisRawReadPortUlong(
				m_szCurrentSettings[SID_PORT_BASE_ADDRESS] 
				+ DM9000_DATA_OFFSET, (PU32)&tmp);
			NdisRawReadPortUlong(
				m_szCurrentSettings[SID_PORT_BASE_ADDRESS] 
				+ DM9000_DATA_OFFSET, (PU32)&value);
			break;
				
		default:
			break;
	} // of switch

	LEAVE_CRITICAL_SECTION
	
	return value;
}
Пример #2
0
u8 cf_read8(struct intf_hdl *pintfhdl, u32 addr)
{
	_irqL irqL;
	uint	res;
	u8	val;
	struct _SyncContext synccontext;
	struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
	//u8 *rwmem = pintfpriv->io_rwmem;
	struct dvobj_priv * pcfiodev = (struct dvobj_priv * )(pintfpriv->intf_dev);
	u32 iobase_addr = pcfiodev->io_base_address;
	

	// Please remember, you just can't only use lock/unlock to 
	// protect the rw functions...
	// since, i/o is quite common in call-back and isr routines...
	
	_func_enter_;
	_enter_hwio_critical(&pintfpriv->rwlock, &irqL);	

#ifdef PLATFORM_WINDOWS

     
      if( addr >= RTL8711_HCICTRL_ && addr <= (RTL8711_HCICTRL_+0x1FFFF) )
      {  //the address is in HCI local register 

          addr = (addr&0x00003FFF);
	   NdisRawReadPortUchar((u32)(iobase_addr+addr), (u8 *)&val);

		  
       }else{

          synccontext.pintfpriv = pintfpriv;
          synccontext.lbusaddr = addr;
	   synccontext.bytecnt = 1; // 1-byte
	   synccontext.pdata=(u8 *)&val;
		
	   irqL = KeGetCurrentIrql();	   

	   if ( irqL <= DISPATCH_LEVEL )
		res = NdisMSynchronizeWithInterrupt(&pcfiodev->interrupt, cfbus_read, (void *)&synccontext);				
	   else//IRQL > DISPATCH_LEVEL
	       res = cfbus_read((void *)&synccontext);

		//NdisMoveMemory(&val, rwmem, 1);
       }

#endif	
	
       _exit_hwio_critical(&pintfpriv->rwlock, &irqL);    
	_func_exit_;
	return val;	
	
}
Пример #3
0
void
PlatformDisableHostL0s(struct net_device *dev)
{
	struct r8192_priv 	*priv = (struct r8192_priv *)rtllib_priv(dev);
	u32				PciCfgAddrPort=0;
	u8				Num4Bytes;
	u8				uPciBridgeASPMSetting = 0;

	
	if( (priv->NdisAdapter.BusNumber == 0xff && 
		priv->NdisAdapter.DevNumber == 0xff && 
		priv->NdisAdapter.FuncNumber == 0xff) ||
		(priv->NdisAdapter.PciBridgeBusNum == 0xff && 
		priv->NdisAdapter.PciBridgeDevNum == 0xff && 
		priv->NdisAdapter.PciBridgeFuncNum == 0xff) )
	{
		printk("PlatformDisableHostL0s(): Fail to enable ASPM. "
		"Cannot find the Bus of PCI(Bridge).\n");
		return;
	}
	
	PciCfgAddrPort= (priv->NdisAdapter.PciBridgeBusNum << 16)|
			(priv->NdisAdapter.PciBridgeDevNum<< 11)|
			(priv->NdisAdapter.PciBridgeFuncNum <<  8)|(1 << 31);
	Num4Bytes = (priv->NdisAdapter.PciBridgePCIeHdrOffset+0x10)/4;


	NdisRawWritePortUlong(PCI_CONF_ADDRESS , PciCfgAddrPort+(Num4Bytes << 2));

	NdisRawReadPortUchar(PCI_CONF_DATA, &uPciBridgeASPMSetting);

	if(uPciBridgeASPMSetting & BIT0)
		uPciBridgeASPMSetting &=  ~(BIT0);

	NdisRawWritePortUlong(PCI_CONF_ADDRESS , PciCfgAddrPort+(Num4Bytes << 2));
	NdisRawWritePortUchar(PCI_CONF_DATA, uPciBridgeASPMSetting);

	udelay(50);

	printk("PlatformDisableHostL0s():PciBridge BusNumber[%x], "
		"DevNumbe[%x], FuncNumber[%x], Write reg[%x] = %x\n",
		priv->NdisAdapter.PciBridgeBusNum, 
		priv->NdisAdapter.PciBridgeDevNum, 
		priv->NdisAdapter.PciBridgeFuncNum, 
		(priv->NdisAdapter.PciBridgePCIeHdrOffset+0x10), 
		(priv->NdisAdapter.PciBridgeLinkCtrlReg | 
		(priv->RegDevicePciASPMSetting&~BIT0)));
}
Пример #4
0
U32	C_DM9000::DeviceReadPort(
	U32		uPort)
{
	U16		val;

	ENTER_CRITICAL_SECTION

	VALIDATE_ADDR_PORT(uPort);

	NdisRawReadPortUchar(
		m_szCurrentSettings[SID_PORT_BASE_ADDRESS] + DM9000_DATA_OFFSET, &val);
	
	LEAVE_CRITICAL_SECTION
	
	return (U32)val;
}
Пример #5
0
BOOLEAN
LanceHardwareDetails(
    IN PLANCE_ADAPTER Adapter
    )

/*++

Routine Description:

    This routine gets the network address from the hardware.

Arguments:

    Adapter - Where to store the network address.

Return Value:

    TRUE - if successful.

--*/

{
    UCHAR Signature[] = { 0xff, 0x00, 0x55, 0xaa, 0xff, 0x00, 0x55, 0xaa};
    UCHAR BytesRead[8];

    UINT ReadCount;

    UINT Place;

    //
    // Reset E-PROM state
    //
    // To do this we first read from the E-PROM address until the
    // specific signature is reached (then the next bytes read from
    // the E-PROM address will be the ethernet address of the card).
    //



    //
    // Read first part of the signature
    //

    for (Place=0; Place < 8; Place++){

        NdisRawReadPortUchar((ULONG)(Adapter->NetworkHardwareAddress),
                             &(BytesRead[Place]));

    }

    ReadCount = 8;

    //
    // This advances to the front of the circular buffer.
    //

    while (ReadCount < 40) {

        //
        // Check if we have read the signature.
        //

        for (Place = 0; Place < 8; Place++){

            if (BytesRead[Place] != Signature[Place]){

                Place = 10;
                break;

            }

        }

        //
        // If we have read the signature, stop.
        //

        if (Place != 10){

            break;

        }

        //
        // else, move all the bytes down one and read then
        // next byte.
        //

        for (Place = 0; Place < 7; Place++){

            BytesRead[Place] = BytesRead[Place+1];

        }

        NdisRawReadPortUchar((ULONG)(Adapter->NetworkHardwareAddress),
                             &(BytesRead[7]));

        ReadCount++;
    }


    if (ReadCount == 40){

        return(FALSE);

    }


    //
    // Now read the ethernet address of the card.
    //


    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(Adapter->NetworkAddress[0])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(Adapter->NetworkAddress[1])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(Adapter->NetworkAddress[2])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(Adapter->NetworkAddress[3])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(Adapter->NetworkAddress[4])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(Adapter->NetworkAddress[5])
                      );



    if (!(Adapter->LanceCard & (LANCE_DE201 | LANCE_DE422))) {

        if (Adapter->LanceCard == LANCE_DEPCA){

            //
            // Reset Lan Interface port.
            //

            NdisRawWritePortUchar(
                               (ULONG)(LANCE_DEPCA_LAN_CFG_OFFSET +
                                       Adapter->Nicsr),
                               0x00);

            //
            // Reset Network Interface Control Status Register
            //

            NdisRawWritePortUshort((ULONG)(Adapter->Nicsr), 0x00);
        }

        return(TRUE);

    }




    //
    // Now do the EPROM Hardware check as outlined in the tech ref.
    //


    //
    // Check for NULL address.
    //

    for (Place = 0; Place < 6; Place++) {

        if (Adapter->NetworkAddress[Place] != 0) {

            Place = 10;
            break;

        }

    }

    if (Place != 10) {

        return(FALSE);

    }



    //
    // Check that bit 0 is not a 1
    //

    if (Adapter->NetworkAddress[0] & 0x1) {

        return(FALSE);

    }





    //
    // Check that octet[0]->octet[7] == octet[15]->octet[8]
    //

    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[6])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[7])
                      );

    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[0])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[1])
                      );

    if ((BytesRead[7] != BytesRead[0]) ||
        (BytesRead[6] != BytesRead[1])) {

        return(FALSE);

    }


    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[5])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[4])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[3])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[2])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[1])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[0])
                      );

    for (Place = 0; Place < 6; Place++) {

        if (BytesRead[Place] != (UCHAR)(Adapter->NetworkAddress[Place])) {

            return(FALSE);

        }

    }


    //
    // Check that octet[0]->octet[8] == octet[16]->octet[23]
    //

    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[0])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[1])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[2])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[3])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[4])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[5])
                      );

    for (Place = 0; Place < 6; Place++) {

        if (BytesRead[Place] != (UCHAR)(Adapter->NetworkAddress[Place])) {

            return(FALSE);

        }

    }


    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[0])
                      );
    NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[1])
                      );

    if ((BytesRead[6] != BytesRead[0]) ||
        (BytesRead[7] != BytesRead[1])) {

        return(FALSE);

    }

    //
    // Check that octet[24] -> octet[31] == signature bytes
    //


    for (Place = 0; Place < 8; Place++){


        NdisRawReadPortUchar(
                      (ULONG)(Adapter->NetworkHardwareAddress),
                      &(BytesRead[Place])
                      );

        if (BytesRead[Place] != Signature[Place]){

#if DBG
            DbgPrint("Lance: Hardware failure\n");
#endif
            return(FALSE);

        }

    }

    if (Adapter->LanceCard == LANCE_DEPCA){

        //
        // Reset Lan Interface port.
        //

        NdisRawWritePortUchar(
                           (ULONG)(LANCE_DEPCA_LAN_CFG_OFFSET +
                                   Adapter->Nicsr),
                           0x00);

        //
        // Reset Network Interface Control Status Register
        //

        NdisRawWritePortUshort((ULONG)(Adapter->Nicsr), 0x00);
    }

    if (Adapter->LanceCard & (LANCE_DE201 | LANCE_DE422)) {

        //
        // Reset Network Interface Control Status Register
        //

        NdisRawWritePortUshort((ULONG)(Adapter->Nicsr), 0x00);

    }

    return(TRUE);

}
Пример #6
0
BOOLEAN
LtFirmInitialize(
	IN	PLT_ADAPTER Adapter,
	IN	UCHAR		SuggestedNodeId
	)
/*++

Routine Description:

	This routine initializes the card, downloads the firmware to it.

Arguments:

	Adapter		:	Pointer to the adapter structure.

Return Value:

	TRUE		:	If successful, false otherwise

--*/
{
	PUCHAR 	Firmware;
	UINT 	FirmwareLen;
	UINT 	RetryCount;
	UCHAR 	Data;
	BOOLEAN	Result = FALSE;

	// Clear the request Latch
	NdisRawReadPortUchar(XFER_PORT, &Data);

	// Clear the TX_READY FLOP
	NdisRawWritePortUchar(XFER_PORT, (UCHAR)0);

	// Reset the card.
	NdisRawWritePortUchar(RESET_PORT, (UCHAR)0);

	NdisStallExecution(LT_FIRM_INIT_STALL_TIME*5);

	for (RetryCount = 0; RetryCount < MAX_READ_RETRY_COUNT; RetryCount++)
	{
		// Get Card Status.
		NdisRawReadPortUchar(SC_PORT, &Data);

		if (Data & TX_READY)
		{
			break;
		}
		else DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_WARN,
					("LtFirmInitialize: Waiting for card ready SC_PORT %x\n", Data));

		NdisStallExecution(LT_FIRM_INIT_STALL_TIME);
	}

	//	BUGBUG:
	//	!!!!!!
	//	For DAYNA, it will not be ready at this point. DCH is going to
	//	send information to fix this.

	do
	{
		if (RetryCount == MAX_READ_RETRY_COUNT)
		{
			LOGERROR(
				Adapter->NdisAdapterHandle,
				NDIS_ERROR_CODE_HARDWARE_FAILURE);

			DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_FATAL,
					("LtFirmInitialize: Card Not Ready after Reset\n"));
			break;
		}

		//	Copy the firmware to the card.
		Firmware 	= LtMicroCode;
		FirmwareLen = sizeof(LtMicroCode);

		DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_INFO,
				("LtFirmInitialize: DownLoad %d bytes of firmware\n", FirmwareLen));

		// Well... the card is alive and well and in a reset state.
		// Next we need to output the first byte of the firmware and
		// check for TX_READY.
		NdisRawWritePortUchar(XFER_PORT, *Firmware);

		DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_INFO,
				("LtFirmInitialize: First byte of Firmware on card\n"));

		NdisRawReadPortUchar(SC_PORT, &Data);

		if (Data & TX_READY)
		{
			DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_FATAL,
					("LtFirmInitialize: Card Not Ready During Download\n"));

			LOGERROR(
				Adapter->NdisAdapterHandle,
				NDIS_ERROR_CODE_HARDWARE_FAILURE);
			break;
		}

		// Skip over the first byte because it already out there.
		Firmware ++;
		FirmwareLen --;

		NdisRawWritePortBufferUchar(XFER_PORT,
									Firmware,
									FirmwareLen);

		// Tell the card to start
		NdisRawReadPortUchar(XFER_PORT, &Data);

		// Wait for the card to start
		for (RetryCount = 0; RetryCount < MAX_START_RETRY_COUNT; RetryCount++)
		{
			NdisStallExecution(LT_FIRM_INIT_STALL_TIME);

			// Get Status
			NdisRawReadPortUchar(SC_PORT, &Data);

			DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_WARN,
					("LtFirmInitialize: Waiting for start - SC_PORT Data %x\n",
					(UCHAR)Data));

			if (Data & RX_READY)
			{
				break;
			}
		}

		//	!!!	This seems to be the only way the MCA card works according to
		//	!!!	Dave Hornbaker. It seems that the MCA card doesnt get ready at
		//	!!! this point, but works later on.
		if (RetryCount == MAX_START_RETRY_COUNT)
		{
			ASSERT(Adapter->BusType !=  NdisInterfaceMca);

			DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_FATAL,
					("LtFirmInitialize: Card Not Ready, could not get status\n"));

			LOGERROR(
				Adapter->NdisAdapterHandle,
				NDIS_ERROR_CODE_INVALID_VALUE_FROM_ADAPTER);
			break;
		}

		// Clear the initial ready signal.
		NdisRawReadPortUchar(XFER_PORT, &Data);

		// Now loop here for a finite time till the card acquires a node id.
		// If it fails to do so in the specified time, fail the load.
		if (!LtInitGetAddressSetPoll(Adapter, SuggestedNodeId))
		{
			break;
		}

		// We need to catch the card fast after it acquire the node id and before it
		// receives any packets. If it does receive any packets, then ask it acquire
		// the node id again. The stall happens ONLY IF A PACKET IS RECVD.
		for (RetryCount = 0; RetryCount < MAX_START_RETRY_COUNT*200; RetryCount++)
		{
			USHORT 				ResponseLength;
			UCHAR 				ResponseType;
			LT_INIT_RESPONSE 	InitPacket;

			//	Check for receive data
			NdisRawReadPortUchar(SC_PORT, &Data);

			if (Data & RX_READY)
			{
				// Get the length of the response on the card
				NdisRawReadPortUchar(XFER_PORT, &Data);

				ResponseLength = (USHORT)(Data & 0xFF);

				NdisRawReadPortUchar(XFER_PORT, &Data);

				ResponseLength |= (Data << 8);

				// Now get the IO code.
				NdisRawReadPortUchar(XFER_PORT, &ResponseType);

				DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_INFO,
						("LtFirmInitialize: RespType = %x, RespLength = %d\n",
							ResponseType, ResponseLength));

				if ((ResponseType == LT_RSP_LAP_INIT) &&
					(ResponseLength == sizeof(LT_INIT_RESPONSE)))
				{
					NdisRawReadPortBufferUchar(XFER_PORT,
												(PUCHAR)&InitPacket,
												ResponseLength);

					Adapter->NodeId = InitPacket.NodeId;
					Adapter->Flags |= ADAPTER_NODE_ID_VALID;

					//	This should start off a worker thread to write the
					//	node id into the pram.
					//	BUGBUG: Implement using worker threads.
					//	LtRegWritePramNodeId(Adapter);

					DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_INFO,
							("LtFirmInitailize: Node id acquired %x\n", InitPacket.NodeId));
					break;
				}
				DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_WARN,
						("LtFirmInitailize: Node id not valid yet !!\n"));

				// Suck in the packet and throw it away
				while (ResponseLength-- > 0)
				{
					NdisRawReadPortUchar(XFER_PORT, &Data);
				}

				// The response was probably over-written by incoming packet.
				// Try again.
				NdisStallExecution(LT_FIRM_INIT_STALL_TIME);
				DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_WARN,
						("LtFirmInitailize: Re-acquire node after packet recv\n"));
				if (!LtInitGetAddressSetPoll(Adapter, SuggestedNodeId))
				{
					break;
				}
			}
			else
			{
				DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_WARN,
						("LtFirmInitialize: Waiting for node - SC_PORT Data %x\n",
						(UCHAR)Data)); 
			}
			NdisStallExecution(500);	// 500us
		}
		Result = ((Adapter->Flags & ADAPTER_NODE_ID_VALID) != 0);
	} while (FALSE);

	return(Result);
}
Пример #7
0
VOID
NTAPI
MiniportHandleInterrupt (
    IN NDIS_HANDLE MiniportAdapterContext
    )
{
    PRTL_ADAPTER adapter = (PRTL_ADAPTER)MiniportAdapterContext;
    ULONG txStatus;
    UCHAR command;
    PPACKET_HEADER nicHeader;
    PETH_HEADER ethHeader;
        
    NdisDprAcquireSpinLock(&adapter->Lock);
    
    NDIS_DbgPrint(MAX_TRACE, ("Interrupts pending: 0x%x\n", adapter->InterruptPending));
    
    //
    // Handle a link change
    //
    if (adapter->LinkChange)
    {
        NdisDprReleaseSpinLock(&adapter->Lock);
        NdisMIndicateStatus(adapter->MiniportAdapterHandle,
                            adapter->MediaState == NdisMediaStateConnected ?
                                NDIS_STATUS_MEDIA_CONNECT : NDIS_STATUS_MEDIA_DISCONNECT,
                            NULL,
                            0);
        NdisMIndicateStatusComplete(adapter->MiniportAdapterHandle);
        NdisDprAcquireSpinLock(&adapter->Lock);
        adapter->LinkChange = FALSE;
    }                            
    
    //
    // Handle a TX interrupt
    //
    if (adapter->InterruptPending & (R_I_TXOK | R_I_TXERR))
    {
        while (adapter->TxFull || adapter->DirtyTxDesc != adapter->CurrentTxDesc)
        {
            NdisRawReadPortUlong(adapter->IoBase + R_TXSTS0 +
                                 (adapter->DirtyTxDesc * sizeof(ULONG)), &txStatus);
            
            if (!(txStatus & (R_TXS_STATOK | R_TXS_UNDERRUN | R_TXS_ABORTED)))
            {
                //
                // Not sent yet
                //
                break;
            }
            
            NDIS_DbgPrint(MAX_TRACE, ("Transmission for desc %d complete: 0x%x\n",
                                      adapter->DirtyTxDesc, txStatus));
            
            if (txStatus & R_TXS_STATOK)
            {
                adapter->TransmitOk++;
            }
            else
            {
                adapter->TransmitError++;
            }

            adapter->DirtyTxDesc++;
            adapter->DirtyTxDesc %= TX_DESC_COUNT;
            adapter->InterruptPending &= ~(R_I_TXOK | R_I_TXERR);
            adapter->TxFull = FALSE;
        }
    }
    
    //
    // Handle a good RX interrupt
    //
    if (adapter->InterruptPending & (R_I_RXOK | R_I_RXERR))
    {
        for (;;)
        {
            NdisRawReadPortUchar(adapter->IoBase + R_CMD, &command);
            if (command & R_CMD_RXEMPTY)
            {
                //
                // The buffer is empty
                //
                adapter->InterruptPending &= ~(R_I_RXOK | R_I_RXERR);
                break;
            }
            
            adapter->ReceiveOffset %= RECEIVE_BUFFER_SIZE;
            
            NDIS_DbgPrint(MAX_TRACE, ("Looking for a packet at offset 0x%x\n",
                            adapter->ReceiveOffset));
            nicHeader = (PPACKET_HEADER)(adapter->ReceiveBuffer + adapter->ReceiveOffset);
            if (!(nicHeader->Status & RSR_ROK))
            {
                //
                // Receive failed
                //
                NDIS_DbgPrint(MIN_TRACE, ("Receive failed: 0x%x\n", nicHeader->Status));
                
                if (nicHeader->Status & RSR_FAE)
                {
                    adapter->ReceiveAlignmentError++;
                }
                else if (nicHeader->Status & RSR_CRC)
                {
                    adapter->ReceiveCrcError++;
                }
                adapter->ReceiveError++;
                
                goto NextPacket;
            }
            
            NDIS_DbgPrint(MAX_TRACE, ("Indicating %d byte packet to NDIS\n",
                           nicHeader->PacketLength - RECV_CRC_LENGTH));
   
            ethHeader = (PETH_HEADER)(nicHeader + 1);
            NdisMEthIndicateReceive(adapter->MiniportAdapterHandle,
                                    NULL,
                                    (PVOID)(ethHeader),
                                    sizeof(ETH_HEADER),
                                    (PVOID)(ethHeader + 1),
                                    nicHeader->PacketLength - sizeof(ETH_HEADER) - RECV_CRC_LENGTH,
                                    nicHeader->PacketLength - sizeof(ETH_HEADER) - RECV_CRC_LENGTH);
            adapter->ReceiveOk++;
            
        NextPacket:
            adapter->ReceiveOffset += nicHeader->PacketLength + sizeof(PACKET_HEADER);
            adapter->ReceiveOffset = (adapter->ReceiveOffset + 3) & ~3;
            NdisRawWritePortUshort(adapter->IoBase + R_CAPR, adapter->ReceiveOffset - 0x10);
            
            if (adapter->InterruptPending & (R_I_RXOVRFLW | R_I_FIFOOVR))
            {
                //
                // We can only clear these interrupts once CAPR has been reset
                //
                NdisRawWritePortUshort(adapter->IoBase + R_IS, R_I_RXOVRFLW | R_I_FIFOOVR);
                adapter->InterruptPending &= ~(R_I_RXOVRFLW | R_I_FIFOOVR);
            }
        }
        
        NdisMEthIndicateReceiveComplete(adapter->MiniportAdapterHandle);
    }
    
    NdisDprReleaseSpinLock(&adapter->Lock);
}