-
Notifications
You must be signed in to change notification settings - Fork 7
/
interrupt.cpp
163 lines (133 loc) · 3.7 KB
/
interrupt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "precomp.h"
#include "trace.h"
#include "adapter.h"
#include "interrupt.h"
#include "link.h"
NTSTATUS
RtInterruptCreate(
_In_ WDFDEVICE wdfDevice,
_In_ RT_ADAPTER* adapter,
_Out_ RT_INTERRUPT** interrupt)
{
TraceEntryRtAdapter(adapter);
*interrupt = nullptr;
WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, RT_INTERRUPT);
WDF_INTERRUPT_CONFIG config;
WDF_INTERRUPT_CONFIG_INIT(&config, EvtInterruptIsr, EvtInterruptDpc);
NTSTATUS status = STATUS_SUCCESS;
WDFINTERRUPT wdfInterrupt;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
WdfInterruptCreate(wdfDevice, &config, &attributes, &wdfInterrupt));
*interrupt = RtGetInterruptContext(wdfInterrupt);
(*interrupt)->Adapter = adapter;
(*interrupt)->Handle = wdfInterrupt;
Exit:
TraceExitResult(status);
return status;
}
_Use_decl_annotations_
BOOLEAN
EvtInterruptIsr(
_In_ WDFINTERRUPT wdfInterrupt,
ULONG MessageID)
{
UNREFERENCED_PARAMETER((MessageID));
RT_INTERRUPT* interrupt = RtGetInterruptContext(wdfInterrupt);
RT_ADAPTER* adapter = interrupt->Adapter;
re_softc* sc = &adapter->bsdData;
BOOLEAN queueDPC = FALSE;
UINT32 status;
if (adapter->isRTL8125) {
// Check if our hardware is active
status = CSR_READ_4(sc, RE_ISR0_8125);
/* hotplug/major error/no more work/shared irq */
if ((status == 0xFFFFFFFF) || !status)
goto done;
CSR_WRITE_4(sc, RE_IMR0_8125, 0x00);
CSR_WRITE_4(sc, RE_ISR0_8125, status & ~RE_ISR_FIFO_OFLOW);
}
else {
status = CSR_READ_2(sc, RE_ISR);
/* hotplug/major error/no more work/shared irq */
if ((status == 0xFFFF) || !status)
goto done;
CSR_WRITE_2(sc, RE_IMR, 0x00);
CSR_WRITE_2(sc, RE_ISR, status & ~RE_ISR_FIFO_OFLOW);
//TODO: workaround needed on MACFG_21
}
if (status & RE_ISR_SYSTEM_ERR) {
if (!InterlockedExchange8(&interrupt->pciInterrupt, TRUE))
queueDPC = TRUE;
goto done;
}
/* Rx interrupt */
if (status & (RE_ISR_RX_OK | RE_ISR_FIFO_OFLOW | RE_ISR_RX_ERR)) {
if (!InterlockedExchange8(&interrupt->rxInterrupt, TRUE))
queueDPC = TRUE;
}
/* Tx interrupt */
if (status & (RE_ISR_TX_OK | RE_ISR_TX_ERR)) {
if (!InterlockedExchange8(&interrupt->txInterrupt, TRUE))
queueDPC = TRUE;
}
if (status & RE_ISR_LINKCHG) {
if (!InterlockedExchange8(&interrupt->linkChg, TRUE))
queueDPC = TRUE;
}
done:
if (queueDPC) {
WdfInterruptQueueDpcForIsr(wdfInterrupt);
}
else {
if (adapter->isRTL8125)
CSR_WRITE_4(sc, RE_IMR0_8125, RE_INTRS);
else
CSR_WRITE_2(sc, RE_IMR, RE_INTRS);
}
return true;
}
static
void
RtRxNotify(
_In_ RT_INTERRUPT* interrupt,
_In_ ULONG queueId
)
{
if (InterlockedExchange(&interrupt->RxNotifyArmed[queueId], false))
{
NetRxQueueNotifyMoreReceivedPacketsAvailable(
interrupt->Adapter->RxQueues[queueId]);
}
}
_Use_decl_annotations_
VOID
EvtInterruptDpc(
_In_ WDFINTERRUPT Interrupt,
_In_ WDFOBJECT AssociatedObject)
{
UNREFERENCED_PARAMETER(AssociatedObject);
RT_INTERRUPT* interrupt = RtGetInterruptContext(Interrupt);
RT_ADAPTER* adapter = interrupt->Adapter;
re_softc* sc = &adapter->bsdData;
if (InterlockedExchange8(&interrupt->pciInterrupt, FALSE)) {
DbgPrint("PCI Interrupt!");
}
if (InterlockedExchange8(&interrupt->txInterrupt, FALSE)) {
if (InterlockedExchange(&interrupt->TxNotifyArmed, false)) {
NetTxQueueNotifyMoreCompletedPacketsAvailable(adapter->TxQueues[0]);
}
}
if (InterlockedExchange8(&interrupt->rxInterrupt, FALSE)) {
RtRxNotify(interrupt, 0);
}
if (InterlockedExchange8(&interrupt->linkChg, FALSE)) {
RtlCheckLinkStatus(adapter);
}
WdfInterruptAcquireLock(adapter->Interrupt->Handle);
if (adapter->isRTL8125)
CSR_WRITE_4(sc, RE_IMR0_8125, RE_INTRS);
else
CSR_WRITE_2(sc, RE_IMR, RE_INTRS);
WdfInterruptReleaseLock(adapter->Interrupt->Handle);
}