-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrxqueue.cpp
175 lines (133 loc) · 4.21 KB
/
rxqueue.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
164
165
166
167
168
169
170
171
172
173
174
175
#include "precomp.h"
#include "rxqueue.h"
#include "device.h"
#include "trace.h"
#include "adapter.h"
_Use_decl_annotations_
NTSTATUS
EvtAdapterCreateRxQueue(
_In_ NETADAPTER netAdapter,
_Inout_ NETRXQUEUE_INIT* rxQueueInit
)
{
NTSTATUS status = STATUS_SUCCESS;
TraceEntryNetAdapter(netAdapter);
MTK_ADAPTER* adapter = MtkGetAdapterContext(netAdapter);
WDF_OBJECT_ATTRIBUTES rxAttributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&rxAttributes, MTK_RXQUEUE);
rxAttributes.EvtDestroyCallback = EvtRxQueueDestroy;
NET_PACKET_QUEUE_CONFIG rxConfig;
NET_PACKET_QUEUE_CONFIG_INIT(
&rxConfig,
EvtRxQueueAdvance,
EvtRxQueueSetNotificationEnabled,
EvtRxQueueCancel);
//rxConfig.EvtStart = EvtRxQueueStart;
//rxConfig.EvtStop = EvtRxQueueStop;
const ULONG queueId = NetRxQueueInitGetQueueId(rxQueueInit);
NETPACKETQUEUE rxQueue;
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
NetRxQueueCreate(rxQueueInit, &rxAttributes, &rxConfig, &rxQueue));
MTK_RXQUEUE* rx = MtkGetRxQueueContext(rxQueue);
NET_EXTENSION_QUERY extension;
NET_EXTENSION_QUERY_INIT(
&extension,
NET_PACKET_EXTENSION_CHECKSUM_NAME,
NET_PACKET_EXTENSION_CHECKSUM_VERSION_1,
NetExtensionTypePacket);
rx->QueueId = queueId;
NetRxQueueGetExtension(rxQueue, &extension, &rx->ChecksumExtension);
NET_EXTENSION_QUERY_INIT(
&extension,
NET_FRAGMENT_EXTENSION_VIRTUAL_ADDRESS_NAME,
NET_FRAGMENT_EXTENSION_VIRTUAL_ADDRESS_VERSION_1,
NetExtensionTypeFragment);
NetRxQueueGetExtension(rxQueue, &extension, &rx->VirtualAddressExtension);
NET_EXTENSION_QUERY_INIT(
&extension,
NET_FRAGMENT_EXTENSION_LOGICAL_ADDRESS_NAME,
NET_FRAGMENT_EXTENSION_LOGICAL_ADDRESS_VERSION_1,
NetExtensionTypeFragment);
NetRxQueueGetExtension(rxQueue, &extension, &rx->LogicalAddressExtension);
NET_EXTENSION_QUERY_INIT(
&extension,
NET_PACKET_EXTENSION_HASH_NAME,
NET_PACKET_EXTENSION_HASH_VERSION_1,
NetExtensionTypePacket);
NetRxQueueGetExtension(rxQueue, &extension, &rx->HashValueExtension);
GOTO_IF_NOT_NT_SUCCESS(Exit, status,
MtkRxQueueInitialize(rxQueue, adapter));
Exit:
TraceExitResult(status);
return status;
}
NTSTATUS
MtkRxQueueInitialize(
_In_ NETPACKETQUEUE rxQueue,
_In_ MTK_ADAPTER* adapter
)
{
NTSTATUS status = STATUS_SUCCESS;
MTK_RXQUEUE* rx = MtkGetRxQueueContext(rxQueue);
rx->Adapter = adapter;
rx->Rings = NetRxQueueGetRingCollection(rxQueue);
Exit:
return status;
}
_Use_decl_annotations_
void
EvtRxQueueDestroy(
_In_ WDFOBJECT rxQueue
)
{
TraceEntry(TraceLoggingPointer(rxQueue, "RxQueue"));
MTK_RXQUEUE* rx = MtkGetRxQueueContext(rxQueue);
if (rx->RxdArray)
WdfObjectDelete(rx->RxdArray);
rx->RxdArray = NULL;
TraceExit();
}
_Use_decl_annotations_
VOID
EvtRxQueueSetNotificationEnabled(
_In_ NETPACKETQUEUE rxQueue,
_In_ BOOLEAN notificationEnabled
)
{
TraceEntry(TraceLoggingPointer(rxQueue), TraceLoggingBoolean(notificationEnabled));
MTK_RXQUEUE* rx = MtkGetRxQueueContext(rxQueue);
TraceExit();
}
_Use_decl_annotations_
void
EvtRxQueueAdvance(
_In_ NETPACKETQUEUE rxQueue
)
{
TraceEntry(TraceLoggingPointer(rxQueue, "RxQueue"));
MTK_RXQUEUE* rx = MtkGetRxQueueContext(rxQueue);
TraceExit();
}
_Use_decl_annotations_
void
EvtRxQueueCancel(
_In_ NETPACKETQUEUE rxQueue
)
{
TraceEntry(TraceLoggingPointer(rxQueue, "RxQueue"));
MTK_RXQUEUE* rx = MtkGetRxQueueContext(rxQueue);
MTK_ADAPTER* adapter = rx->Adapter;
// try (but not very hard) to grab anything that may have been
// indicated during rx disable. advance will continue to be called
// after cancel until all packets are returned to the framework.
NET_RING* pr = NetRingCollectionGetPacketRing(rx->Rings);
while (pr->BeginIndex != pr->EndIndex)
{
NET_PACKET* packet = NetRingGetPacketAtIndex(pr, pr->BeginIndex);
packet->Ignore = 1;
pr->BeginIndex = NetRingIncrementIndex(pr, pr->BeginIndex);
}
NET_RING* fr = NetRingCollectionGetFragmentRing(rx->Rings);
fr->BeginIndex = fr->EndIndex;
TraceExit();
}