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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
#include "Mp_Precomp.h"
#if WPP_SOFTWARE_TRACE
#include "RxReorder.tmh"
#endif
BOOLEAN
InsertRxReorderList(
IN PADAPTER Adapter,
IN PRT_RFD pRfd,
IN PRX_TS_RECORD pTS,
IN u2Byte SeqNum
)
{
PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
PRX_REORDER_ENTRY pReorderEntry;
PRT_LIST_ENTRY pList = &pTS->RxPendingPktList;
if(!RTIsListEmpty(&pMgntInfo->RxReorder_Unused_List))
{
pReorderEntry = (PRX_REORDER_ENTRY)RTRemoveHeadList(&pMgntInfo->RxReorder_Unused_List);
// Make a reorder entry and insert into a the packet list.
pReorderEntry->SeqNum = SeqNum;
pReorderEntry->pRfd = pRfd;
while(pList->Blink != &pTS->RxPendingPktList)
{
if( SN_LESS(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)pList->Blink)->SeqNum) )
{
// Not reach correct position yet!!
pList = pList->Blink;
}
else if( SN_EQUAL(pReorderEntry->SeqNum, ((PRX_REORDER_ENTRY)pList->Blink)->SeqNum) )
{
// Duplicate entry is found!! Do not insert current entry.
RT_TRACE(COMP_RX_REORDER, DBG_WARNING, ("InsertRxReorderList(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, SeqNum));
RTInsertTailList(&pMgntInfo->RxReorder_Unused_List, &pReorderEntry->List);
return FALSE;
}
else
{
break;
}
}
pReorderEntry->List.Blink = pList->Blink;
pReorderEntry->List.Blink->Flink = &pReorderEntry->List;
pReorderEntry->List.Flink = pList;
pList->Blink = &pReorderEntry->List;
RT_TRACE(COMP_RX_REORDER, DBG_TRACE, ("InsertRxReorderList(): Pkt insert into buffer!! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, SeqNum));
return TRUE;
}
else
{
// This part shall be modified!! We can just indicate all the packets in buffer and get reorder entries.
RT_TRACE(COMP_RX_REORDER, DBG_WARNING, ("InsertRxReorderList(): There is no reorder entry!! Packet is dropped!!\n"));
return FALSE;
}
}
VOID
IndicateRxReorderList(
IN PADAPTER Adapter,
IN PRX_TS_RECORD pTS,
IN BOOLEAN bForced
)
{
PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
PRT_HIGH_THROUGHPUT pHTInfo = pMgntInfo->pHTInfo;
PRX_REORDER_ENTRY pReorderEntry = NULL;
u2Byte index = 0;
BOOLEAN bPktInBuf = FALSE;
// PRT_RFD pRfdIndicateArray[REORDER_WIN_SIZE];
PRT_RFD *pRfdIndicateArray;
PRT_GEN_TEMP_BUFFER pGenBuf;
Adapter->rxReorderIndEnterCnt++;
if(PlatformAtomicExchange(&Adapter->rxReorderRefCount, TRUE) == TRUE)
{
Adapter->rxReorderIndRejectCnt[0]++;
RT_TRACE(COMP_INIT, DBG_LOUD, ("IndicateRxReorderList(): There is already another thread running by AtomicExchange, happened %d times!!!\n", Adapter->rxReorderIndRejectCnt[0]));
return;
}
// Check if there is any other indication thread running.
if(pTS->RxIndicateState == RXTS_INDICATE_PROCESSING)
{
PlatformAtomicExchange(&Adapter->rxReorderRefCount, FALSE);
Adapter->rxReorderIndRejectCnt[1]++;
RT_TRACE(COMP_INIT, DBG_LOUD, ("IndicateRxReorderList(): There is already another thread running by RXTS_INDICATE_PROCESSING, happened %d times!!!\n", Adapter->rxReorderIndRejectCnt[1]));
return;
}
// Handling some condition for forced indicate case.
if(bForced)
{
if(RTIsListEmpty(&pTS->RxPendingPktList))
{
PlatformAtomicExchange(&Adapter->rxReorderRefCount, FALSE);
Adapter->rxReorderIndRejectCnt[2]++;
RT_TRACE(COMP_INIT, DBG_LOUD, ("IndicateRxReorderList(): There is already another thread running by ListEmpty, happened %d times!!!\n", Adapter->rxReorderIndRejectCnt[2]));
return;
}
else
{
pReorderEntry = (PRX_REORDER_ENTRY)RTGetHeadList(&pTS->RxPendingPktList);
pTS->RxIndicateSeq = pReorderEntry->SeqNum;
}
}
Adapter->rxReorderIndAllowCnt++;
pGenBuf = GetGenTempBuffer (Adapter, sizeof(PRT_RFD)*REORDER_WIN_SIZE);
pRfdIndicateArray = (PRT_RFD *)pGenBuf->Buffer.Ptr;
// Prepare indication list and indication.
do{
// Check if there is any packet need indicate.
while(!RTIsListEmpty(&pTS->RxPendingPktList))
{
pReorderEntry = (PRX_REORDER_ENTRY)RTGetHeadList(&pTS->RxPendingPktList);
if(!SN_LESS(pTS->RxIndicateSeq, pReorderEntry->SeqNum))
{
// This protect buffer from overflow.
if(index >= REORDER_WIN_SIZE)
{
RT_ASSERT(FALSE, ("IndicateRxReorderList(): Buffer overflow!! \n"));
bPktInBuf = TRUE;
break;
}
if(index > 0)
{
if(PlatformCompareMemory(pReorderEntry->pRfd->Address3,pRfdIndicateArray[index-1]->Address3,6) != 0)
{
bPktInBuf = TRUE;
break;
}
}
pReorderEntry = (PRX_REORDER_ENTRY)RTRemoveHeadList(&pTS->RxPendingPktList);
if(SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
RT_TRACE(COMP_RX_REORDER, DBG_LOUD, ("RxReorderIndicatePacket(): Packets indication!! IndicateSeq: %d\n", pReorderEntry->SeqNum));
pRfdIndicateArray[index] = pReorderEntry->pRfd;
index++;
RTInsertTailList(&pMgntInfo->RxReorder_Unused_List, &pReorderEntry->List);
}
else
{
bPktInBuf = TRUE;
break;
}
}
// Handling pending timer. Set this timer to prevent from long time Rx buffering.
if(index>0)
{
// Cancel previous pending timer.
{
PlatformCancelTimer(Adapter, &pTS->RxPktPendingTimer);
// Set this as a lock to make sure that only one thread is indicating packet.
pTS->RxIndicateState = RXTS_INDICATE_PROCESSING;
}
// Indicate packets
RT_ASSERT((index<=REORDER_WIN_SIZE), ("RxReorderIndicatePacket(): Rx Reorder buffer full!! \n"));
// Packets indication.
DrvIFIndicatePackets(Adapter, pRfdIndicateArray, index);
// Update local variables.
//bPktInBuf = FALSE;
index = 0;
}
else
{
break;
}
}while(TRUE);
ReturnGenTempBuffer(Adapter, pGenBuf);
// Release the indication lock and set to new indication step.
if(bPktInBuf)
{
u1Byte set_penf_timer=FALSE;
{
if(pTS->RxIndicateState != RXTS_INDICATE_REORDER)
set_penf_timer = TRUE;
}
if (set_penf_timer == TRUE)
{
// Set new pending timer.
pTS->RxIndicateState = RXTS_INDICATE_REORDER;
PlatformSetTimer(Adapter, &pTS->RxPktPendingTimer, pHTInfo->RxReorderPendingTime);
}
}
else
{
pTS->RxIndicateState = RXTS_INDICATE_IDLE;
}
PlatformAtomicExchange(&Adapter->rxReorderRefCount, FALSE);
}
BOOLEAN
ISinWindow(
IN u2Byte NewSeqNum,
IN u2Byte RxIndicateSeq
)
{
if( NewSeqNum == RxIndicateSeq)
return TRUE;
if( NewSeqNum > RxIndicateSeq )
{
if( ( NewSeqNum - RxIndicateSeq ) < REORDER_WIN_SIZE )
return TRUE;
else
return FALSE;
}
else
{
if( ( NewSeqNum + 4096 - RxIndicateSeq ) < REORDER_WIN_SIZE )
return TRUE;
else
return FALSE;
}
}
BOOLEAN
CheckRxTsIndicateSeq(
IN PADAPTER Adapter,
IN PRX_TS_RECORD pTS,
IN u2Byte NewSeqNum
)
{
PRT_HIGH_THROUGHPUT pHTInfo = Adapter->MgntInfo.pHTInfo;
u1Byte WinSize = pHTInfo->RxReorderWinSize;
u2Byte WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
// Rx Reorder initialize condition.
if(pTS->RxIndicateSeq == 0xffff)
pTS->RxIndicateSeq = NewSeqNum;
// Drop out the packet which SeqNum is smaller than WinStart
if( SN_LESS(NewSeqNum, pTS->RxIndicateSeq ) )
{
RT_TRACE(COMP_RX_REORDER, DBG_WARNING, ("CheckRxTsIndicateSeq(): Packet Drop! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, NewSeqNum));
return FALSE;
}
//
// SeqNum "MUST" in Window Size !!
//
if( !ISinWindow(NewSeqNum , pTS->RxIndicateSeq ) )
{
RT_TRACE(COMP_RX_REORDER, DBG_WARNING, ("CheckRxTsIndicateSeq(): out-off squence !! Packet Drop! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, NewSeqNum));
return FALSE;
}
//
// Sliding window manipulation. Conditions includes:
// 1. Incoming SeqNum is equal to WinStart =>Window shift 1
// 2. Incoming SeqNum is larger than the WinEnd => Window shift N
//
if( SN_EQUAL(NewSeqNum, pTS->RxIndicateSeq) )
{
pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
}
else if(SN_LESS(WinEnd, NewSeqNum))
{
RT_TRACE(COMP_RX_REORDER, DBG_WARNING, ("CheckRxTsIndicateSeq(): Window Shift! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, NewSeqNum));
if(NewSeqNum >= (WinSize - 1))
pTS->RxIndicateSeq = NewSeqNum + 1 -WinSize;
else
pTS->RxIndicateSeq = 4095 - (WinSize - (NewSeqNum +1)) + 1;
}
return TRUE;
}
VOID
FlushRxTsPendingPkts(
IN PADAPTER Adapter,
IN PRX_TS_RECORD pTS
)
{
PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
PRX_REORDER_ENTRY pRxReorderEntry;
// PRT_RFD RfdArray[REORDER_WIN_SIZE];
PRT_RFD *RfdArray;
u2Byte RfdCnt = 0;
PRT_GEN_TEMP_BUFFER pGenBuf;
if(RTIsListEmpty(&pTS->RxPendingPktList))
{
pTS->RxIndicateSeq = 0xffff;
pTS->RxIndicateState = RXTS_INDICATE_IDLE;
return;
}
pGenBuf = GetGenTempBuffer (Adapter, sizeof(PRT_RFD)*REORDER_WIN_SIZE);
RfdArray = (PRT_RFD *)pGenBuf->Buffer.Ptr;
PlatformCancelTimer(Adapter, &pTS->RxPktPendingTimer);
while(!RTIsListEmpty(&pTS->RxPendingPktList))
{
pRxReorderEntry = (PRX_REORDER_ENTRY)RTRemoveHeadList(&pTS->RxPendingPktList);
RfdArray[RfdCnt] = pRxReorderEntry->pRfd;
RfdCnt = RfdCnt + 1;
RTInsertTailList(&pMgntInfo->RxReorder_Unused_List, &pRxReorderEntry->List);
}
DrvIFIndicatePackets(Adapter, RfdArray, RfdCnt);
ReturnGenTempBuffer(Adapter, pGenBuf);
pTS->RxIndicateSeq = 0xffff;
pTS->RxIndicateState = RXTS_INDICATE_IDLE;
}
VOID
FlushAllRxTsPendingPkts(
IN PADAPTER Adapter
)
{
PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
PRX_TS_RECORD pTS_Record = (PRX_TS_RECORD) RTGetHeadList(&pMgntInfo->Rx_TS_Admit_List);
while((&pTS_Record->TsCommonInfo.List) != (&pMgntInfo->Rx_TS_Admit_List))
{
FlushRxTsPendingPkts(Adapter, pTS_Record);
pTS_Record = (PRX_TS_RECORD)RTNextEntryList(&pTS_Record->TsCommonInfo.List);
}
}
#if RX_AGGREGATION
VOID
RxReorderAggrBatchIndicate(
IN PADAPTER Adapter,
IN PRT_RFD pRfd
)
{
PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
PRT_HIGH_THROUGHPUT pHTInfo = pMgntInfo->pHTInfo;
PRX_TS_RECORD pTS = pRfd->Status.pRxTS;
u2Byte SeqNum = pRfd->Status.Seq_Num;
u1Byte TmpCnt;
if(!CheckRxTsIndicateSeq(Adapter, pTS, SeqNum))
{
pHTInfo->RxReorderDropCounter++;
ReturnRFDList(Adapter, pRfd);
return;
}
//3 Current packet is going to be inserted into pending list.
if(!InsertRxReorderList(Adapter, pRfd, pTS, SeqNum))
{
ReturnRFDList(Adapter, pRfd);
}
else
{
TmpCnt = 0;
while((TmpCnt<pMgntInfo->IndicateTsCnt) && (pMgntInfo->IndicateTsArray[TmpCnt]!=pTS))
TmpCnt++;
if(TmpCnt == pMgntInfo->IndicateTsCnt)
{
pMgntInfo->IndicateTsArray[pMgntInfo->IndicateTsCnt] = pTS;
pMgntInfo->IndicateTsCnt++;
}
}
if(pRfd->RxAggrInfo.bIsLastPkt)
{
for(TmpCnt=0; TmpCnt<pMgntInfo->IndicateTsCnt; TmpCnt++)
IndicateRxReorderList(Adapter, pMgntInfo->IndicateTsArray[TmpCnt], FALSE);
pMgntInfo->IndicateTsCnt = 0;
}
}
VOID
RxReorderAggrBatchFlushBuf(
IN PADAPTER Adapter
)
{
PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
u1Byte TmpCnt;
for(TmpCnt=0; TmpCnt<pMgntInfo->IndicateTsCnt; TmpCnt++)
IndicateRxReorderList(Adapter, pMgntInfo->IndicateTsArray[TmpCnt], FALSE);
pMgntInfo->IndicateTsCnt = 0;
}
#endif
VOID
RxReorderIndicatePacket(
IN PADAPTER Adapter,
IN PRT_RFD pRfd
)
{
PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
PRT_HIGH_THROUGHPUT pHTInfo = pMgntInfo->pHTInfo;
PRX_TS_RECORD pTS = pRfd->Status.pRxTS;
u2Byte SeqNum = pRfd->Status.Seq_Num;
RT_TRACE(COMP_RX_REORDER, DBG_TRACE, ("==>RxReorderIndicatePacket()\n"));
if(!CheckRxTsIndicateSeq(Adapter, pTS, SeqNum))
{
pHTInfo->RxReorderDropCounter++;
ReturnRFDList(Adapter, pRfd);
RT_TRACE(COMP_RX_REORDER, DBG_TRACE, ("<==RxReorderIndicatePacket(): Packet Drop!!\n"));
return;
}
// Insert all packet into Reorder Queue to maintain its ordering.
if(!InsertRxReorderList(Adapter, pRfd, pTS, SeqNum))
ReturnRFDList(Adapter, pRfd);
//
// Indication process.
// After Packet dropping and Sliding Window shifting as above, we can now just indicate the packets
// with the SeqNum smaller than latest WinStart and buffer other packets.
//
// For Rx Reorder condition:
// 1. All packets with SeqNum smaller than WinStart => Indicate
// 2. All packets with SeqNum larger than or equal to WinStart => Buffer it.
//
IndicateRxReorderList(Adapter, pTS, FALSE);
RT_TRACE(COMP_RX_REORDER, DBG_TRACE, ("<==RxReorderIndicatePacket():\n"));
}
VOID
RxPktPendingTimeout(
PRT_TIMER pTimer
)
{
PADAPTER Adapter = (PADAPTER)pTimer->Adapter;
PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTimer->Context;
BOOLEAN bSupportAvoidRxDpcWatchdogVoilation = FALSE;
RT_TRACE(COMP_RX_REORDER, DBG_WARNING, ("==>RxPktPendingTimeout()\n"));
//Only 8814AE set bSupportAvoidRxDpcWatchdogVoilation true now.
Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_AVOID_RX_DPC_WATCHDOG_VIOLATION, (pu1Byte)(&bSupportAvoidRxDpcWatchdogVoilation));
if(bSupportAvoidRxDpcWatchdogVoilation)
{
if(Adapter->IntrInterruptRefCount == TRUE)
{
PlatformSetTimer(Adapter, &pRxTS->RxPktPendingTimer, 1);
return;
}
if(PlatformAtomicExchange(&Adapter->RxPktPendingTimeoutRefCount, TRUE) == TRUE)
{
PlatformSetTimer(Adapter, &pRxTS->RxPktPendingTimer, 1);
return;
}
}
PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
// Only do indication process in Batch and Reorder state in this function.
if(pRxTS->RxIndicateState==RXTS_INDICATE_BATCH)
IndicateRxReorderList(Adapter, pRxTS, FALSE);
else if(pRxTS->RxIndicateState==RXTS_INDICATE_REORDER)
IndicateRxReorderList(Adapter, pRxTS, TRUE);
PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
if(bSupportAvoidRxDpcWatchdogVoilation)
PlatformAtomicExchange(&Adapter->RxPktPendingTimeoutRefCount, FALSE);
RT_TRACE(COMP_RX_REORDER, DBG_WARNING, ("<==RxPktPendingTimeout()\n"));
}
|