1
/******************************************************************************
2
* Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4
* This program is distributed in the hope that it will be useful, but WITHOUT
5
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
9
* You should have received a copy of the GNU General Public License along with
10
* this program; if not, write to the Free Software Foundation, Inc.,
11
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
13
* The full GNU General Public License is included in this distribution in the
14
* file called LICENSE.
16
* Contact Information:
17
* wlanfae <wlanfae@realtek.com>
18
******************************************************************************/
20
#include <linux/etherdevice.h>
21
#include "rtl819x_TS.h"
22
extern void _setup_timer( struct timer_list*, void*, unsigned long);
23
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
24
#define list_for_each_entry_safe(pos, n, head, member) \
25
for (pos = list_entry((head)->next, typeof(*pos), member), \
26
n = list_entry(pos->member.next, typeof(*pos), member); \
27
&pos->member != (head); \
28
pos = n, n = list_entry(n->member.next, typeof(*n), member))
30
void TsSetupTimeOut(unsigned long data)
34
void TsInactTimeout(unsigned long data)
38
void RxPktPendingTimeout(unsigned long data)
40
PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data;
41
struct rtllib_device *ieee = container_of(pRxTs, struct rtllib_device, RxTsRecord[pRxTs->num]);
43
PRX_REORDER_ENTRY pReorderEntry = NULL;
45
unsigned long flags = 0;
46
struct rtllib_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
48
bool bPktInBuf = false;
50
spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
51
if(pRxTs->RxTimeoutIndicateSeq != 0xffff)
53
while(!list_empty(&pRxTs->RxPendingPktList))
55
pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTs->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
57
pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
59
if( SN_LESS(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) ||
60
SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) )
62
list_del_init(&pReorderEntry->List);
64
if(SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq))
65
pRxTs->RxIndicateSeq = (pRxTs->RxIndicateSeq + 1) % 4096;
67
RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): Indicate SeqNum: %d\n",__func__, pReorderEntry->SeqNum);
68
stats_IndicateArray[index] = pReorderEntry->prxb;
71
list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
82
pRxTs->RxTimeoutIndicateSeq = 0xffff;
84
if(index > REORDER_WIN_SIZE){
85
RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
86
spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
89
rtllib_indicate_packets(ieee, stats_IndicateArray, index);
93
if(bPktInBuf && (pRxTs->RxTimeoutIndicateSeq==0xffff)){
94
pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
95
mod_timer(&pRxTs->RxPktPendingTimer, jiffies + MSECS(ieee->pHTInfo->RxReorderPendingTime));
97
spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
100
void TsAddBaProcess(unsigned long data)
102
PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)data;
104
struct rtllib_device *ieee = container_of(pTxTs, struct rtllib_device, TxTsRecord[num]);
106
TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
107
RTLLIB_DEBUG(RTLLIB_DL_BA, "TsAddBaProcess(): ADDBA Req is started!! \n");
111
void ResetTsCommonInfo(PTS_COMMON_INFO pTsCommonInfo)
113
memset(pTsCommonInfo->Addr, 0, 6);
114
memset(&pTsCommonInfo->TSpec, 0, sizeof(TSPEC_BODY));
115
memset(&pTsCommonInfo->TClass, 0, sizeof(QOS_TCLAS)*TCLAS_NUM);
116
pTsCommonInfo->TClasProc = 0;
117
pTsCommonInfo->TClasNum = 0;
120
void ResetTxTsEntry(PTX_TS_RECORD pTS)
122
ResetTsCommonInfo(&pTS->TsCommonInfo);
124
pTS->bAddBaReqInProgress = false;
125
pTS->bAddBaReqDelayed = false;
126
pTS->bUsingBa = false;
127
pTS->bDisable_AddBa = false;
128
ResetBaEntry(&pTS->TxAdmittedBARecord);
129
ResetBaEntry(&pTS->TxPendingBARecord);
132
void ResetRxTsEntry(PRX_TS_RECORD pTS)
134
ResetTsCommonInfo(&pTS->TsCommonInfo);
135
pTS->RxIndicateSeq = 0xffff;
136
pTS->RxTimeoutIndicateSeq = 0xffff;
137
ResetBaEntry(&pTS->RxAdmittedBARecord);
139
#ifdef _RTL8192_EXT_PATCH_
140
void ResetAdmitTRStream(struct rtllib_device *ieee, u8 *Addr)
143
bool search_dir[4] = {0, 0, 0, 0};
144
struct list_head* psearch_list;
145
PTS_COMMON_INFO pRet = NULL;
146
PRX_TS_RECORD pRxTS = NULL;
147
PTX_TS_RECORD pTxTS = NULL;
149
if(ieee->iw_mode != IW_MODE_MESH)
152
search_dir[DIR_DOWN] = true;
153
psearch_list = &ieee->Rx_TS_Admit_List;
154
for(dir = 0; dir <= DIR_BI_DIR; dir++)
156
if(search_dir[dir] ==false )
158
list_for_each_entry(pRet, psearch_list, List){
159
if ((memcmp(pRet->Addr, Addr, 6) == 0) && (pRet->TSpec.f.TSInfo.field.ucDirection == dir))
161
pRxTS = (PRX_TS_RECORD)pRet;
162
pRxTS->RxIndicateSeq = 0xffff;
163
pRxTS->RxTimeoutIndicateSeq = 0xffff;
168
search_dir[DIR_UP] = true;
169
psearch_list = &ieee->Tx_TS_Admit_List;
170
for(dir = 0; dir <= DIR_BI_DIR; dir++)
172
if(search_dir[dir] ==false )
174
list_for_each_entry(pRet, psearch_list, List){
175
if ((memcmp(pRet->Addr, Addr, 6) == 0) && (pRet->TSpec.f.TSInfo.field.ucDirection == dir))
177
pTxTS = (PTX_TS_RECORD)pRet;
178
pTxTS->TxCurSeq = 0xffff;
188
void TSInitialize(struct rtllib_device *ieee)
190
PTX_TS_RECORD pTxTS = ieee->TxTsRecord;
191
PRX_TS_RECORD pRxTS = ieee->RxTsRecord;
192
PRX_REORDER_ENTRY pRxReorderEntry = ieee->RxReorderEntry;
194
RTLLIB_DEBUG(RTLLIB_DL_TS, "==========>%s()\n", __FUNCTION__);
195
INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
196
INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
197
INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
199
for(count = 0; count < TOTAL_TS_NUM; count++)
202
_setup_timer(&pTxTS->TsCommonInfo.SetupTimer,
204
(unsigned long) pTxTS);
206
_setup_timer(&pTxTS->TsCommonInfo.InactTimer,
208
(unsigned long) pTxTS);
210
_setup_timer(&pTxTS->TsAddBaTimer,
212
(unsigned long) pTxTS);
214
_setup_timer(&pTxTS->TxPendingBARecord.Timer,
216
(unsigned long) pTxTS);
217
_setup_timer(&pTxTS->TxAdmittedBARecord.Timer,
219
(unsigned long) pTxTS);
221
ResetTxTsEntry(pTxTS);
222
list_add_tail(&pTxTS->TsCommonInfo.List,
223
&ieee->Tx_TS_Unused_List);
227
INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
228
INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
229
INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
230
for(count = 0; count < TOTAL_TS_NUM; count++)
233
INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
235
_setup_timer(&pRxTS->TsCommonInfo.SetupTimer,
237
(unsigned long) pRxTS);
239
_setup_timer(&pRxTS->TsCommonInfo.InactTimer,
241
(unsigned long) pRxTS);
243
_setup_timer(&pRxTS->RxAdmittedBARecord.Timer,
245
(unsigned long) pRxTS);
247
_setup_timer(&pRxTS->RxPktPendingTimer,
249
(unsigned long) pRxTS);
251
ResetRxTsEntry(pRxTS);
252
list_add_tail(&pRxTS->TsCommonInfo.List, &ieee->Rx_TS_Unused_List);
255
INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
256
for(count = 0; count < REORDER_ENTRY_NUM; count++)
258
list_add_tail( &pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
259
if(count == (REORDER_ENTRY_NUM-1))
261
pRxReorderEntry = &ieee->RxReorderEntry[count+1];
266
void AdmitTS(struct rtllib_device *ieee, PTS_COMMON_INFO pTsCommonInfo, u32 InactTime)
268
del_timer_sync(&pTsCommonInfo->SetupTimer);
269
del_timer_sync(&pTsCommonInfo->InactTimer);
272
mod_timer(&pTsCommonInfo->InactTimer, jiffies + MSECS(InactTime));
276
PTS_COMMON_INFO SearchAdmitTRStream(struct rtllib_device *ieee, u8* Addr, u8 TID, TR_SELECT TxRxSelect)
279
bool search_dir[4] = {0, 0, 0, 0};
280
struct list_head* psearch_list;
281
PTS_COMMON_INFO pRet = NULL;
282
if(ieee->iw_mode == IW_MODE_MASTER)
284
if(TxRxSelect == TX_DIR)
286
search_dir[DIR_DOWN] = true;
287
search_dir[DIR_BI_DIR]= true;
291
search_dir[DIR_UP] = true;
292
search_dir[DIR_BI_DIR]= true;
295
else if(ieee->iw_mode == IW_MODE_ADHOC)
297
if(TxRxSelect == TX_DIR)
298
search_dir[DIR_UP] = true;
300
search_dir[DIR_DOWN] = true;
304
if(TxRxSelect == TX_DIR)
306
search_dir[DIR_UP] = true;
307
search_dir[DIR_BI_DIR]= true;
308
search_dir[DIR_DIRECT]= true;
312
search_dir[DIR_DOWN] = true;
313
search_dir[DIR_BI_DIR]= true;
314
search_dir[DIR_DIRECT]= true;
318
if(TxRxSelect == TX_DIR)
319
psearch_list = &ieee->Tx_TS_Admit_List;
321
psearch_list = &ieee->Rx_TS_Admit_List;
323
for(dir = 0; dir <= DIR_BI_DIR; dir++)
325
if(search_dir[dir] ==false )
327
list_for_each_entry(pRet, psearch_list, List){
328
if (memcmp(pRet->Addr, Addr, 6) == 0)
329
if (pRet->TSpec.f.TSInfo.field.ucTSID == TID)
330
if(pRet->TSpec.f.TSInfo.field.ucDirection == dir)
336
if(&pRet->List != psearch_list)
340
if(&pRet->List != psearch_list){
348
PTS_COMMON_INFO pTsCommonInfo,
358
if(pTsCommonInfo == NULL)
361
memcpy(pTsCommonInfo->Addr, Addr, 6);
364
memcpy((u8*)(&(pTsCommonInfo->TSpec)), (u8*)pTSPEC, sizeof(TSPEC_BODY));
366
for(count = 0; count < TCLAS_Num; count++)
367
memcpy((u8*)(&(pTsCommonInfo->TClass[count])), (u8*)pTCLAS, sizeof(QOS_TCLAS));
369
pTsCommonInfo->TClasProc = TCLAS_Proc;
370
pTsCommonInfo->TClasNum = TCLAS_Num;
373
#ifdef _RTL8192_EXT_PATCH_
374
void dump_ts_list(struct list_head * ts_list)
376
PTS_COMMON_INFO pRet = NULL;
378
list_for_each_entry(pRet, ts_list, List){
379
printk("i=%d ADD:"MAC_FMT", TID:%d, dir:%d\n",i,MAC_ARG(pRet->Addr), pRet->TSpec.f.TSInfo.field.ucTSID, pRet->TSpec.f.TSInfo.field.ucDirection);
387
struct rtllib_device* ieee,
388
PTS_COMMON_INFO *ppTS,
391
TR_SELECT TxRxSelect,
396
if(is_broadcast_ether_addr(Addr) || is_multicast_ether_addr(Addr))
398
RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! get TS for Broadcast or Multicast\n");
402
if(ieee->pStaQos->CurrentQosMode == QOS_DISABLE)
404
else if(ieee->pStaQos->CurrentQosMode & QOS_WMM)
407
if (ieee->current_network.qos_data.supported == 0)
414
RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! in %s(), TID(%d) is not valid\n", __FUNCTION__, TID);
442
*ppTS = SearchAdmitTRStream(
453
if(bAddNewTs == false)
455
RTLLIB_DEBUG(RTLLIB_DL_TS, "add new TS failed(tid:%d)\n", UP);
461
PQOS_TSINFO pTSInfo = &TSpec.f.TSInfo;
462
struct list_head* pUnusedList =
463
(TxRxSelect == TX_DIR)?
464
(&ieee->Tx_TS_Unused_List):
465
(&ieee->Rx_TS_Unused_List);
467
struct list_head* pAddmitList =
468
(TxRxSelect == TX_DIR)?
469
(&ieee->Tx_TS_Admit_List):
470
(&ieee->Rx_TS_Admit_List);
472
DIRECTION_VALUE Dir = (ieee->iw_mode == IW_MODE_MASTER)?
473
((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):
474
((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
475
RTLLIB_DEBUG(RTLLIB_DL_TS, "to add Ts\n");
476
if(!list_empty(pUnusedList))
478
(*ppTS) = list_entry(pUnusedList->next, TS_COMMON_INFO, List);
479
list_del_init(&(*ppTS)->List);
480
if(TxRxSelect==TX_DIR)
482
PTX_TS_RECORD tmp = container_of(*ppTS, TX_TS_RECORD, TsCommonInfo);
486
PRX_TS_RECORD tmp = container_of(*ppTS, RX_TS_RECORD, TsCommonInfo);
490
RTLLIB_DEBUG(RTLLIB_DL_TS, "to init current TS, UP:%d, Dir:%d, addr:"MAC_FMT" ppTs=%p\n", UP, Dir, MAC_ARG(Addr), *ppTS);
491
pTSInfo->field.ucTrafficType = 0;
492
pTSInfo->field.ucTSID = UP;
493
pTSInfo->field.ucDirection = Dir;
494
pTSInfo->field.ucAccessPolicy = 1;
495
pTSInfo->field.ucAggregation = 0;
496
pTSInfo->field.ucPSB = 0;
497
pTSInfo->field.ucUP = UP;
498
pTSInfo->field.ucTSInfoAckPolicy = 0;
499
pTSInfo->field.ucSchedule = 0;
501
MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
502
AdmitTS(ieee, *ppTS, 0);
503
list_add_tail(&((*ppTS)->List), pAddmitList);
509
RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!in function %s() There is not enough dir=%d(0=up down=1) TS record to be used!!", __FUNCTION__,Dir);
517
struct rtllib_device* ieee,
522
del_timer_sync(&pTs->SetupTimer);
523
del_timer_sync(&pTs->InactTimer);
524
TsInitDelBA(ieee, pTs, TxRxSelect);
526
if(TxRxSelect == RX_DIR)
528
PRX_REORDER_ENTRY pRxReorderEntry;
529
PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTs;
531
if(timer_pending(&pRxTS->RxPktPendingTimer))
532
del_timer_sync(&pRxTS->RxPktPendingTimer);
534
while(!list_empty(&pRxTS->RxPendingPktList)){
535
pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
536
RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): Delete SeqNum %d!\n",__FUNCTION__, pRxReorderEntry->SeqNum);
537
list_del_init(&pRxReorderEntry->List);
540
struct rtllib_rxb * prxb = pRxReorderEntry->prxb;
541
if (unlikely(!prxb)){
544
for(i =0; i < prxb->nr_subframes; i++) {
545
dev_kfree_skb(prxb->subframes[i]);
550
list_add_tail(&pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
554
PTX_TS_RECORD pTxTS = (PTX_TS_RECORD)pTs;
555
del_timer_sync(&pTxTS->TsAddBaTimer);
559
void RemovePeerTS(struct rtllib_device* ieee, u8* Addr)
561
PTS_COMMON_INFO pTS, pTmpTS;
562
printk("===========>RemovePeerTS,"MAC_FMT"\n", MAC_ARG(Addr));
564
list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
566
if (memcmp(pTS->Addr, Addr, 6) == 0)
568
RemoveTsEntry(ieee, pTS, TX_DIR);
569
list_del_init(&pTS->List);
570
list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
574
list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
576
if (memcmp(pTS->Addr, Addr, 6) == 0)
578
printk("====>remove Tx_TS_admin_list\n");
579
RemoveTsEntry(ieee, pTS, TX_DIR);
580
list_del_init(&pTS->List);
581
list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
585
list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
587
if (memcmp(pTS->Addr, Addr, 6) == 0)
589
RemoveTsEntry(ieee, pTS, RX_DIR);
590
list_del_init(&pTS->List);
591
list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
595
list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
597
if (memcmp(pTS->Addr, Addr, 6) == 0)
599
RemoveTsEntry(ieee, pTS, RX_DIR);
600
list_del_init(&pTS->List);
601
list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
607
void RemoveAllTS(struct rtllib_device* ieee)
609
PTS_COMMON_INFO pTS, pTmpTS;
611
list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
613
RemoveTsEntry(ieee, pTS, TX_DIR);
614
list_del_init(&pTS->List);
615
list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
618
list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
620
RemoveTsEntry(ieee, pTS, TX_DIR);
621
list_del_init(&pTS->List);
622
list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
625
list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
627
RemoveTsEntry(ieee, pTS, RX_DIR);
628
list_del_init(&pTS->List);
629
list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
632
list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
634
RemoveTsEntry(ieee, pTS, RX_DIR);
635
list_del_init(&pTS->List);
636
list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
641
void TsStartAddBaProcess(struct rtllib_device* ieee, PTX_TS_RECORD pTxTS)
643
if(pTxTS->bAddBaReqInProgress == false)
645
pTxTS->bAddBaReqInProgress = true;
647
if(pTxTS->bAddBaReqDelayed)
649
RTLLIB_DEBUG(RTLLIB_DL_BA, "TsStartAddBaProcess(): Delayed Start ADDBA after 60 sec!!\n");
650
mod_timer(&pTxTS->TsAddBaTimer, jiffies + MSECS(TS_ADDBA_DELAY));
654
RTLLIB_DEBUG(RTLLIB_DL_BA,"TsStartAddBaProcess(): Immediately Start ADDBA now!!\n");
655
mod_timer(&pTxTS->TsAddBaTimer, jiffies+10);
660
RTLLIB_DEBUG(RTLLIB_DL_ERR, "%s()==>BA timer is already added\n", __FUNCTION__);
663
#ifndef BUILT_IN_RTLLIB
664
EXPORT_SYMBOL_RSL(RemovePeerTS);
665
#ifdef _RTL8192_EXT_PATCH_
666
EXPORT_SYMBOL_RSL(ResetAdmitTRStream);