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
|
/*++
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:
TcbRcb.C
Abstract:
This module contains miniport functions for handling Send & Receive
packets and other helper routines called by these miniport functions.
In order to excercise the send and receive code path of this driver,
you should install more than one instance of the miniport. If there
is only one instance installed, the driver throws the send packet on
the floor and completes the send successfully. If there are more
instances present, it indicates the incoming send packet to the other
instances. For example, if there 3 instances: A, B, & C installed.
Packets coming in for A instance would be indicated to B & C; packets
coming into B would be indicated to C, & A; and packets coming to C
would be indicated to A & B.
Revision History:
Notes:
--*/
#include "netvmin6.h"
#include "tcbrcb.tmh"
VOID
ReturnTCB(
_In_ PMP_ADAPTER Adapter,
_In_ PTCB Tcb)
{
TXNblRelease(Adapter, NBL_FROM_SEND_NB(Tcb->NetBuffer), TRUE);
Tcb->NetBuffer = NULL;
NdisInterlockedInsertTailList(
&Adapter->FreeTcbList,
&Tcb->TcbLink,
&Adapter->FreeTcbListLock);
}
_Must_inspect_result_
_Success_(return != NULL)
PRCB
GetRCB(
_In_ PMP_ADAPTER Adapter,
_In_ PNDIS_NET_BUFFER_LIST_8021Q_INFO Nbl1QInfo,
_In_ PFRAME Frame)
/*++
Routine Description:
This routine gets an unused RCB from the pool.
Runs at IRQL <= DISPATCH_LEVEL
Arguments:
Adapter The receiving adapter
Nbl1QInfo 8021Q Tag information for the FRAME being received
Frame The frame that will be attached to the RCB
Return Value:
NULL if an RCB could not be allocated.
Else, a pointer to an initialized RCB.
--*/
{
NDIS_STATUS Status = NDIS_STATUS_RESOURCES;
PRCB Rcb = NULL;
DEBUGP(MP_TRACE, "[%p] ---> GetRCB.\n", Adapter);
if(VMQ_ENABLED(Adapter))
{
//
// Retrieve the RCB from the target VMQ queue for the frame
//
GetRcbForRxQueue(Adapter, Frame, Nbl1QInfo, &Rcb);
}
else
{
//
// Retrieve the RCB from the global RCB pool
//
PLIST_ENTRY pEntry = NdisInterlockedRemoveHeadList(
&Adapter->FreeRcbList,
&Adapter->FreeRcbListLock);
if (pEntry)
{
Rcb = CONTAINING_RECORD(pEntry, RCB, RcbLink);
//
// Receiving on the default receive queue, increment its pending count
//
Status = NICReferenceReceiveBlock(Adapter, 0);
if(Status != NDIS_STATUS_SUCCESS)
{
//
// The adapter is no longer in a ready state, so we were not able to take a reference on the
// receive block. Add the RCB back to the free list and fail this receive.
//
NdisInterlockedInsertTailList(
&Adapter->FreeRcbList,
&Rcb->RcbLink,
&Adapter->FreeRcbListLock);
Rcb = NULL;
}
}
}
if (Rcb)
{
//
// Simulate the hardware DMA'ing the received frame into the NB's MDL.
//
Status = HWBeginReceiveDma(Adapter, Nbl1QInfo, Rcb, Frame);
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_TRACE, "[%p] HWBeginReceiveDma failed with error 0x%08x, aborting RCB allocation.\n", Adapter, Status);
//
// Increase failure counters if appropriate
//
if(Status == NDIS_STATUS_RESOURCES)
{
++Adapter->RxResourceErrors;
}
else if(Status != NDIS_STATUS_INVALID_ADDRESS)
{
++Adapter->RxRuntErrors;
}
//
// Recover RCB
//
ReturnRCB(Adapter, Rcb);
Rcb = NULL;
}
}
else
{
DEBUGP(MP_LOUD, "[%p] An RCB could not be retrieved. Status: 0x%08x.\n", Adapter, Status);
++Adapter->RxResourceErrors;
}
DEBUGP(MP_LOUD, "[%p] Allocated RCB: %p.", Adapter, Rcb);
DEBUGP(MP_TRACE, "[%p] <--- GetRCB.\n", Adapter);
return Rcb;
}
VOID
ReturnRCB(
_In_ PMP_ADAPTER Adapter,
_In_ PRCB Rcb)
/*++
Routine Description:
This routine frees an RCB back to the unused pool, recovers relevant memory used in the RCB.
Runs at IRQL <= DISPATCH_LEVEL
Arguments:
Adapter - The receiving adapter (the one that owns the RCB).
Rcb - The RCB to be freed.
Return Value:
None.
--*/
{
PUCHAR Data = Rcb->Data;
ASSERT(Data);
DEBUGP(MP_TRACE, "[%p] ---> ReturnRCB. RCB: %p\n", Adapter, Rcb);
if(VMQ_ENABLED(Adapter))
{
//
// Recover RCB back to owner VMQ queue
//
RecoverRxQueueRcb(Adapter, Rcb);
}
else
{
//
// Recover RCB to global RCB pool
//
NdisInterlockedInsertTailList(
&Adapter->FreeRcbList,
&Rcb->RcbLink,
&Adapter->FreeRcbListLock);
Rcb = NULL;
//
// We receive on the default receive queue, decrement its pending count
//
NICDereferenceReceiveBlock(Adapter, 0, NULL);
HWFrameRelease((PFRAME)Data);
}
DEBUGP(MP_TRACE, "[%p] <--- ReturnRCB.\n", Adapter);
}
|