2018-05-18 22:23:45 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Intel PRO/1000 Driver
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
|
|
* PURPOSE: Interrupt handlers
|
2019-01-21 21:44:25 +00:00
|
|
|
* COPYRIGHT: 2013 Cameron Gutman (cameron.gutman@reactos.org)
|
|
|
|
* 2018 Mark Jansen (mark.jansen@reactos.org)
|
|
|
|
* 2019 Victor Pereertkin (victor.perevertkin@reactos.org)
|
2018-05-18 22:23:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nic.h"
|
|
|
|
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
MiniportISR(
|
|
|
|
OUT PBOOLEAN InterruptRecognized,
|
|
|
|
OUT PBOOLEAN QueueMiniportHandleInterrupt,
|
|
|
|
IN NDIS_HANDLE MiniportAdapterContext)
|
|
|
|
{
|
2018-05-29 20:52:43 +00:00
|
|
|
ULONG Value;
|
2018-05-18 22:23:45 +00:00
|
|
|
PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
|
|
|
|
|
2018-05-29 20:52:43 +00:00
|
|
|
Value = NICInterruptRecognized(Adapter, InterruptRecognized);
|
|
|
|
InterlockedOr(&Adapter->InterruptPending, Value);
|
2018-05-18 22:23:45 +00:00
|
|
|
|
|
|
|
if (!(*InterruptRecognized))
|
|
|
|
{
|
|
|
|
/* This is not ours. */
|
|
|
|
*QueueMiniportHandleInterrupt = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-29 20:52:43 +00:00
|
|
|
/* Mark the events pending service */
|
2018-05-18 22:23:45 +00:00
|
|
|
*QueueMiniportHandleInterrupt = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
MiniportHandleInterrupt(
|
|
|
|
IN NDIS_HANDLE MiniportAdapterContext)
|
|
|
|
{
|
2019-01-21 21:44:25 +00:00
|
|
|
ULONG InterruptPending;
|
2018-05-29 20:52:43 +00:00
|
|
|
PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
|
|
|
|
volatile PE1000_TRANSMIT_DESCRIPTOR TransmitDescriptor;
|
|
|
|
|
2018-05-18 22:23:45 +00:00
|
|
|
NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
|
2018-05-29 20:52:43 +00:00
|
|
|
|
2019-01-21 21:44:25 +00:00
|
|
|
InterruptPending = InterlockedExchange(&Adapter->InterruptPending, 0);
|
2018-05-29 20:52:43 +00:00
|
|
|
|
|
|
|
|
2019-01-21 21:44:25 +00:00
|
|
|
/* Link State Changed */
|
|
|
|
if (InterruptPending & E1000_IMS_LSC)
|
2018-05-29 20:52:43 +00:00
|
|
|
{
|
|
|
|
ULONG Status;
|
2018-06-03 20:43:50 +00:00
|
|
|
|
2019-01-21 21:44:25 +00:00
|
|
|
InterruptPending &= ~E1000_IMS_LSC;
|
|
|
|
NDIS_DbgPrint(MAX_TRACE, ("Link status changed!.\n"));
|
2018-05-29 20:52:43 +00:00
|
|
|
|
|
|
|
NICUpdateLinkStatus(Adapter);
|
|
|
|
|
|
|
|
Status = Adapter->MediaState == NdisMediaStateConnected ? NDIS_STATUS_MEDIA_CONNECT : NDIS_STATUS_MEDIA_DISCONNECT;
|
2019-01-21 21:44:25 +00:00
|
|
|
|
2018-05-29 20:52:43 +00:00
|
|
|
NdisMIndicateStatus(Adapter->AdapterHandle, Status, NULL, 0);
|
|
|
|
NdisMIndicateStatusComplete(Adapter->AdapterHandle);
|
|
|
|
}
|
|
|
|
|
2019-01-21 21:44:25 +00:00
|
|
|
/* Handling receive interrupts */
|
|
|
|
if (InterruptPending & (E1000_IMS_RXDMT0 | E1000_IMS_RXT0))
|
2018-06-03 20:43:50 +00:00
|
|
|
{
|
|
|
|
volatile PE1000_RECEIVE_DESCRIPTOR ReceiveDescriptor;
|
|
|
|
PETH_HEADER EthHeader;
|
|
|
|
ULONG BufferOffset;
|
2019-01-21 21:44:25 +00:00
|
|
|
BOOLEAN bGotAny = FALSE;
|
|
|
|
ULONG RxDescHead, RxDescTail, CurrRxDesc;
|
2018-06-03 20:43:50 +00:00
|
|
|
|
|
|
|
/* Clear out these interrupts */
|
2019-01-21 21:44:25 +00:00
|
|
|
InterruptPending &= ~(E1000_IMS_RXDMT0 | E1000_IMS_RXT0);
|
2018-06-03 20:43:50 +00:00
|
|
|
|
2019-01-21 21:44:25 +00:00
|
|
|
E1000ReadUlong(Adapter, E1000_REG_RDH, &RxDescHead);
|
|
|
|
E1000ReadUlong(Adapter, E1000_REG_RDT, &RxDescTail);
|
|
|
|
|
|
|
|
while (((RxDescTail + 1) % NUM_RECEIVE_DESCRIPTORS) != RxDescHead)
|
2018-06-03 20:43:50 +00:00
|
|
|
{
|
2019-01-21 21:44:25 +00:00
|
|
|
CurrRxDesc = (RxDescTail + 1) % NUM_RECEIVE_DESCRIPTORS;
|
|
|
|
BufferOffset = CurrRxDesc * Adapter->ReceiveBufferEntrySize;
|
|
|
|
ReceiveDescriptor = Adapter->ReceiveDescriptors + CurrRxDesc;
|
2018-06-03 20:43:50 +00:00
|
|
|
|
2019-01-21 21:44:25 +00:00
|
|
|
/* Check if the hardware have released this descriptor (DD - Descriptor Done) */
|
2018-06-03 20:43:50 +00:00
|
|
|
if (!(ReceiveDescriptor->Status & E1000_RDESC_STATUS_DD))
|
|
|
|
{
|
2019-01-21 21:44:25 +00:00
|
|
|
/* No need to check descriptors after the first unfinished one */
|
2018-06-03 20:43:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-01-21 21:44:25 +00:00
|
|
|
/* Ignoring these flags for now */
|
|
|
|
ReceiveDescriptor->Status &= ~(E1000_RDESC_STATUS_IXSM | E1000_RDESC_STATUS_PIF);
|
|
|
|
|
|
|
|
if (ReceiveDescriptor->Status != (E1000_RDESC_STATUS_EOP | E1000_RDESC_STATUS_DD))
|
2018-06-03 20:43:50 +00:00
|
|
|
{
|
2019-01-21 21:44:25 +00:00
|
|
|
NDIS_DbgPrint(MIN_TRACE, ("Unrecognized ReceiveDescriptor status flag: %u\n", ReceiveDescriptor->Status));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ReceiveDescriptor->Length != 0 && ReceiveDescriptor->Address != 0)
|
|
|
|
{
|
|
|
|
EthHeader = (PETH_HEADER)(Adapter->ReceiveBuffer + BufferOffset);
|
2018-06-03 20:43:50 +00:00
|
|
|
|
|
|
|
NdisMEthIndicateReceive(Adapter->AdapterHandle,
|
|
|
|
NULL,
|
2019-01-21 21:44:25 +00:00
|
|
|
(PCHAR)EthHeader,
|
2018-06-03 20:43:50 +00:00
|
|
|
sizeof(ETH_HEADER),
|
2019-01-21 21:44:25 +00:00
|
|
|
(PCHAR)(EthHeader + 1),
|
2018-06-03 20:43:50 +00:00
|
|
|
ReceiveDescriptor->Length - sizeof(ETH_HEADER),
|
|
|
|
ReceiveDescriptor->Length - sizeof(ETH_HEADER));
|
|
|
|
|
2019-01-21 21:44:25 +00:00
|
|
|
bGotAny = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NDIS_DbgPrint(MIN_TRACE, ("Got a NULL descriptor"));
|
2018-06-03 20:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Give the descriptor back */
|
|
|
|
ReceiveDescriptor->Status = 0;
|
2019-01-21 21:44:25 +00:00
|
|
|
|
|
|
|
RxDescTail = CurrRxDesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bGotAny)
|
|
|
|
{
|
|
|
|
/* Write back new tail value */
|
|
|
|
E1000WriteUlong(Adapter, E1000_REG_RDT, RxDescTail);
|
|
|
|
|
|
|
|
NDIS_DbgPrint(MAX_TRACE, ("Rx done (RDH: %u, RDT: %u)\n", RxDescHead, RxDescTail));
|
|
|
|
|
|
|
|
NdisMEthIndicateReceiveComplete(Adapter->AdapterHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handling transmit interrupts */
|
|
|
|
if (InterruptPending & (E1000_IMS_TXD_LOW | E1000_IMS_TXDW | E1000_IMS_TXQE))
|
|
|
|
{
|
|
|
|
PNDIS_PACKET AckPackets[40] = {0};
|
|
|
|
ULONG NumPackets = 0, i;
|
|
|
|
|
|
|
|
/* Clear out these interrupts */
|
|
|
|
InterruptPending &= ~(E1000_IMS_TXD_LOW | E1000_IMS_TXDW | E1000_IMS_TXQE);
|
|
|
|
|
|
|
|
while ((Adapter->TxFull || Adapter->LastTxDesc != Adapter->CurrentTxDesc) && NumPackets < ARRAYSIZE(AckPackets))
|
|
|
|
{
|
|
|
|
TransmitDescriptor = Adapter->TransmitDescriptors + Adapter->LastTxDesc;
|
|
|
|
|
|
|
|
if (TransmitDescriptor->Status & E1000_TDESC_STATUS_DD)
|
|
|
|
{
|
|
|
|
if (Adapter->TransmitPackets[Adapter->LastTxDesc])
|
|
|
|
{
|
|
|
|
AckPackets[NumPackets++] = Adapter->TransmitPackets[Adapter->LastTxDesc];
|
|
|
|
Adapter->TransmitPackets[Adapter->LastTxDesc] = NULL;
|
|
|
|
TransmitDescriptor->Status = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Adapter->LastTxDesc = (Adapter->LastTxDesc + 1) % NUM_TRANSMIT_DESCRIPTORS;
|
|
|
|
Adapter->TxFull = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NumPackets)
|
|
|
|
{
|
|
|
|
NDIS_DbgPrint(MAX_TRACE, ("Tx: (TDH: %u, TDT: %u)\n", Adapter->CurrentTxDesc, Adapter->LastTxDesc));
|
|
|
|
NDIS_DbgPrint(MAX_TRACE, ("Tx Done: %u packets to ack\n", NumPackets));
|
|
|
|
|
|
|
|
for (i = 0; i < NumPackets; ++i)
|
|
|
|
{
|
|
|
|
NdisMSendComplete(Adapter->AdapterHandle, AckPackets[i], NDIS_STATUS_SUCCESS);
|
|
|
|
}
|
2018-06-03 20:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-29 20:52:43 +00:00
|
|
|
|
2019-01-21 21:44:25 +00:00
|
|
|
ASSERT(InterruptPending == 0);
|
2018-05-18 22:23:45 +00:00
|
|
|
}
|