summaryrefslogtreecommitdiff
path: root/network/ndis/netvmini/6x/vmq.h
blob: 98224c027f18765081bf8cc648f334d3281ac72c (plain)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/*++

Copyright (c) Microsoft Corporation.  All rights reserved.

    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
    PURPOSE.

Module Name:

   Vmq.h

Abstract:

   This module declares the VMQ related data types, flags, macros, and functions.

Revision History:

Notes:

--*/


struct _FRAME;
struct _RCB;

#if (NDIS_SUPPORT_NDIS620)


//
// VMQ queue structures
//

//
// Tracks the shared memory segment allocated for indications
//
typedef struct _MP_ADAPTER_SHARED_MEMORY_BLOCK
{
    //
    // MDL for the shared memory segment
    //
    PMDL Mdl;
    //
    // Pointer to shared memory for this block
    //
    PUCHAR                      Buffer;
    //
    // Description of the shared memory block used for the NetBuffer usage
    //
    NET_BUFFER_SHARED_MEMORY    BufferSharedMemoryData;
} MP_ADAPTER_SHARED_MEMORY_BLOCK, *PMP_ADAPTER_SHARED_MEMORY_BLOCK;

//
// Tracks a shared memory buffer allocation, which is then subdivided into individual blocks for indications
//
typedef struct _MP_ADAPTER_SHARED_MEMORY
{
    LIST_ENTRY                      Entry;
    NDIS_HANDLE                     AllocationHandle;
    NDIS_HANDLE                     MemoryHandle;
    PUCHAR                          Buffer;
    ULONG                           EntrySize;
    ULONG                           NumberOfEntries;
} MP_ADAPTER_SHARED_MEMORY, *PMP_ADAPTER_SHARED_MEMORY;

//
// The minimum number of shared memory blocks we require. Used when recovering from
// shared memory allocation failures.
//
#define NIC_MIN_RECV_ENTRY_ALLOCATION_COUNT 32

//
// Flags set to individual queues. Any code changing the flag value should acquire the corresponding
// lock.
//
//
// The queue is initialized, but not yet completed. Receives disabled.
//
#define fMPAQI_INITIALIZED              0x1
//
// Completion of the queue has started. Receives disabled.
//
#define fMPAQI_COMPLETION_STARTED       0x2
//
// Queue completed. Receives enabled.
//
#define fMPAQI_COMPLETION_FINISHED      0x4
//
// Queue is being freed (pending RefCount). Receives disabled.
//
#define fMPAQI_FREEING                  0x8
//
// DMA is being performed for queue
//
#define fMPAQI_DMA_IN_PROGRESS          0x10
//
// The queue has entered DMA stopped state. No copies should occur to receive memory for this queue.
//
#define fMPAQI_DMA_STOPPED              0x20

#define QUEUE_SET_FLAG(_QueueInfo, _Flag)\
    ((_QueueInfo)->QueueInfoFlags |= _Flag)

#define QUEUE_CLEAR_FLAG(_QueueInfo, _Flag)\
    ((_QueueInfo)->QueueInfoFlags &= ~(_Flag))

#define QUEUE_INITIALIZED(_QueueInfo)\
    ((_QueueInfo)->QueueInfoFlags & fMPAQI_INITIALIZED)

#define QUEUE_COMPLETING(_QueueInfo)\
    ((_QueueInfo)->QueueInfoFlags & fMPAQI_COMPLETION_STARTED)

#define QUEUE_COMPLETE(_QueueInfo)\
    ((_QueueInfo)->QueueInfoFlags & fMPAQI_COMPLETION_FINISHED)

#define QUEUE_FREEING(_QueueInfo)\
    ((_QueueInfo)->QueueInfoFlags & fMPAQI_FREEING)

#define QUEUE_DMA_IN_PROGRESS(_QueueInfo)\
    ((_QueueInfo)->QueueInfoFlags & fMPAQI_DMA_IN_PROGRESS)

#define QUEUE_DMA_STOPPED(_QueueInfo)\
    ((_QueueInfo)->QueueInfoFlags & fMPAQI_DMA_STOPPED)

//
// The MP_ADAPTER_QUEUE structure is used to track a specific VMQ queue
//
typedef struct DECLSPEC_CACHEALIGN _MP_ADAPTER_QUEUE
{
    //
    // Lock for Read/Write access to QueueInfoFlags and RefCount.
    //
    PNDIS_RW_LOCK_EX QueueLock;
    //
    // Flags used to track status of Queue (fMPAQI_* flags)
    //
    ULONG QueueInfoFlags;

    //
    // DPC used for receives for this queue
    //
    struct _MP_ADAPTER_RECEIVE_DPC *ReceiveDpc;

    //
    // List of unused RCBs (sliced out of RcbMemoryBlock)
    //
    LIST_ENTRY              FreeRcbList;
    NDIS_SPIN_LOCK          FreeRcbListLock;

    //
    // RCB & NBL memory information
    //
    PUCHAR                  RcbMemoryBlock;
    NDIS_HANDLE             RecvNblPoolHandle;

    //
    // Shared memory information (MP_ADAPTER_SHARED_MEMORY)
    //
    ULONG                   NumReceiveBuffers;
    //
    // List of MP_ADAPTER_SHARED_MEMORY, large shared memory buffers subdivided for use when receiving
    //
    LIST_ENTRY              LookaheadSharedMemoryList;
    LIST_ENTRY              PostLookaheadSharedMemoryList;
    //
    // MP_ADAPTER_SHARED_MEMORY_BLOCK buffers to hold book-keeping info on subdivided shared memory buffers
    //
    PUCHAR                  LookaheadBlocks;
    ULONG                   NumLookaheadBlocks;
    PUCHAR                  PostLookaheadBlocks;
    ULONG                   NumPostLookaheadBlocks;

    //
    // Data passed in through the VMQ Queue configuration related OIDs
    //
    NDIS_RECEIVE_QUEUE_ID QueueId;
    ULONG NumSuggestedReceiveBuffers;
    ULONG LookaheadSize;
    ULONG NdisFlags;
    GROUP_AFFINITY ProcessorAffinity;
} MP_ADAPTER_QUEUE, *PMP_ADAPTER_QUEUE;

//
// Structure used to store receive filter data
//
typedef struct _MP_ADAPTER_FILTER
{
    //
    // Whether the receive filter should be used
    //
    BOOLEAN Valid;
    //
    // Filter matching fields
    //
    BOOLEAN VlanUntaggedOrZero;
    USHORT QueueId;
    USHORT VlanId;
    UCHAR MacAddress[NIC_MACADDR_SIZE];
} MP_ADAPTER_FILTER, *PMP_ADAPTER_FILTER;

#define MP_ADAPTER_FILTER_INDEX(_FilterId_)\
    ((_FilterId_)-1)

//
// Global VMQ configuration structures
//

//
// Flags tracking global VMQ state
//
//
// VMQ is enabled on the adapter.
//
#define fMPVMQD_FILTERING_ENABLED       0x0001
//
// Lookahead split in VMQ indication is enabled on the adapter.
//
#define fMPVMQD_LOOKAHEAD_ENABLED       0x0002
//
// VLAN filtering in VMQ is enabled on the adapter.
//
#define fMPVMQD_VLANFILTER_ENABLED      0x0004

#define VMQ_SET_FLAG(_Adapter, _Flag) \
    ((_Adapter)->VMQData.Flags |= (_Flag))

#define VMQ_ENABLED(_Adapter) \
        ((_Adapter)->VMQData.Flags & fMPVMQD_FILTERING_ENABLED)
#define LOOKAHEAD_SPLIT_ENABLED(_Adapter)\
        ((_Adapter)->VMQData.Flags & fMPVMQD_LOOKAHEAD_ENABLED)
#define VLAN_FILTER_ENABLED(_Adapter)\
        ((_Adapter)->VMQData.Flags & fMPVMQD_VLANFILTER_ENABLED)

#define LOOKAHEAD_SPLIT_REQUIRED(_QueueInfo)\
    ((_QueueInfo)->NdisFlags & NDIS_RECEIVE_QUEUE_PARAMETERS_LOOKAHEAD_SPLIT_REQUIRED)

//
// The MP_ADAPTER_VMQ_DATA structure is used to track the global VMQ configuration for an adapter
//
typedef struct _MP_ADAPTER_VMQ_DATA
{
    //
    // Tracks global VMQ state (fMPVMQD_* flags)
    //
    ULONG Flags;
    //
    // Individual Queues. The MP_ADAPTER_QUEUE array is not dynamically allocated to reduce
    // pointer dereferencing during receives, which can affect performance.
    //
    MP_ADAPTER_QUEUE RxQueues[NIC_SUPPORTED_NUM_QUEUES];
    //
    // Filters used to match packets to Queues
    //
    MP_ADAPTER_FILTER RxFilters[NIC_MAX_HEADER_FILTERS];
} MP_ADAPTER_VMQ_DATA, *PMP_ADAPTER_VMQ_DATA;

NDIS_STATUS
AllocateVMQData(
    _Inout_ struct _MP_ADAPTER *Adapter);

VOID
FreeVMQData(
    _Inout_ struct _MP_ADAPTER *Adapter);

NDIS_STATUS
ReadRxQueueConfig(
    _In_ NDIS_HANDLE ConfigurationHandle,
    _Inout_ struct _MP_ADAPTER *Adapter);

NDIS_STATUS
InitializeRxQueueMPConfig(
    _Inout_ struct _MP_ADAPTER *Adapter);

NDIS_STATUS
AllocateDefaultRxQueue(
    _Inout_ struct _MP_ADAPTER *Adapter);


NDIS_STATUS
AllocateRxQueue(
    _Inout_ struct _MP_ADAPTER *Adapter,
    _In_ PNDIS_RECEIVE_QUEUE_PARAMETERS QueueParams
    );

NDIS_STATUS
CompleteAllocationRxQueue(
    _Inout_ struct _MP_ADAPTER *Adapter,
    _In_ PNDIS_RECEIVE_QUEUE_ALLOCATION_COMPLETE_ARRAY CompleteArray
    );

NDIS_STATUS
UpdateRxQueue(
    _Inout_ struct _MP_ADAPTER *Adapter,
    _In_ PNDIS_RECEIVE_QUEUE_PARAMETERS QueueParams
);

NDIS_STATUS
FreeRxQueue(
    _Inout_ struct _MP_ADAPTER *Adapter,
    _In_ PNDIS_RECEIVE_QUEUE_FREE_PARAMETERS QueueParams,
    _In_opt_ PNDIS_OID_REQUEST   NdisSetRequest
);

VOID
IndicateRxQueue(
           _In_ NDIS_HANDLE AdapterHandle,
           NDIS_RECEIVE_QUEUE_ID QueueId,
           NDIS_RECEIVE_QUEUE_OPERATIONAL_STATE State);

NDIS_STATUS
SetRxFilter(
    _Inout_ struct _MP_ADAPTER *Adapter,
    _In_ PNDIS_RECEIVE_FILTER_PARAMETERS FilterParams
    );

NDIS_STATUS
ClearRxFilter(
    _Inout_ struct _MP_ADAPTER *Adapter,
    _In_ PNDIS_RECEIVE_FILTER_CLEAR_PARAMETERS FilterParams
    );

BOOLEAN
AcquireRxQueueReference(
    _Inout_ struct _MP_ADAPTER *Adapter,
    _In_ _In_range_(0, NIC_SUPPORTED_NUM_QUEUES-1) USHORT QueueId,
    BOOLEAN RequireComplete
    );

VOID
ReleaseRxQueueReference(
    _Inout_ struct _MP_ADAPTER *Adapter,
    _In_ _In_range_(0, NIC_SUPPORTED_NUM_QUEUES-1) USHORT QueueId
   );

VOID
SetPendingRxQueueFree(
    _Inout_ struct _MP_ADAPTER *Adapter,
    _In_ PNDIS_OID_REQUEST NdisSetRequest
    );

VOID
GetRcbForRxQueue(
    _In_  struct _MP_ADAPTER *Adapter,
    _In_  struct _FRAME *Frame,
    _In_  PNDIS_NET_BUFFER_LIST_8021Q_INFO Nbl1QInfo,
    _Outptr_result_maybenull_ struct _RCB **Rcb);

NDIS_STATUS
CopyFrameToRxQueueRcb(
    _In_  struct _MP_ADAPTER *Adapter,
    _In_  struct _FRAME *Frame,
    _In_  PNDIS_NET_BUFFER_LIST_8021Q_INFO Nbl1QInfo,
    _Inout_ struct _RCB *Rcb,
    _Out_ BOOLEAN *Copied);

VOID
RecoverRxQueueRcb(
    _In_ struct _MP_ADAPTER *Adapter,
    _In_ struct _RCB *Rcb);

VOID
AddPendingRcbToRxQueue(
    _In_ struct _MP_ADAPTER *Adapter,
    _In_ struct _RCB *Rcb);

#define GetRxQueueDpc(Adapter, QueueId) (Adapter)->VMQData.RxQueues[(QueueId)].ReceiveDpc

#else

//
// In order to avoid excessible "#if defined(NDIS620_MINIPORT)" statements scattered
// through the miniport implementation, NDIS60 miniports define
// placeholder macros for the VMQ functions which cause the code to always proceed
// as if VMQ were disabled on the adapter.
//

#define VMQ_ENABLED(_Adapter) FALSE
#define LOOKAHEAD_SPLIT_ENABLED(_Adapter) FALSE
#define VLAN_FILTER_ENABLED(_Adapter) FALSE
#define LOOKAHEAD_SPLIT_REQUIRED(_QueueInfo) FALSE
#define AllocateDefaultRxQueue(Adapter) NDIS_STATUS_NOT_SUPPORTED
#define AddPendingRcbToRxQueue(Adapter, Rcb)
#define GetRxQueueDpc(Adapter, QueueId) NULL
#define AllocateVMQData(Adapter) NDIS_STATUS_SUCCESS
#define FreeVMQData(Adapter)
#define ReadRxQueueConfig(ConfigurationHandle, Adapter) NDIS_STATUS_SUCCESS
#define InitializeRxQueueMPConfig(Adapter) NDIS_STATUS_SUCCESS
#define CopyFrameToRxQueueRcb(Adapter, Frame, Nbl1QInfo, Rcb, Copied) FALSE
#define GetRcbForRxQueue(Adapter, Frame, Nbl1QInfo, Rcb) NDIS_STATUS_NOT_SUPPORTED
#define RecoverRxQueueRcb(Adapter, Rcb)

#endif