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);
24 void TsSetupTimeOut(unsigned long data)
28 void TsInactTimeout(unsigned long data)
32 void RxPktPendingTimeout(unsigned long data)
34 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data;
35 struct rtllib_device *ieee = container_of(pRxTs, struct rtllib_device, RxTsRecord[pRxTs->num]);
37 PRX_REORDER_ENTRY pReorderEntry = NULL;
39 unsigned long flags = 0;
40 struct rtllib_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
42 bool bPktInBuf = false;
44 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
45 if (pRxTs->RxTimeoutIndicateSeq != 0xffff)
47 while(!list_empty(&pRxTs->RxPendingPktList))
49 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTs->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
51 pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
53 if ( SN_LESS(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) ||
54 SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) )
56 list_del_init(&pReorderEntry->List);
58 if (SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq))
59 pRxTs->RxIndicateSeq = (pRxTs->RxIndicateSeq + 1) % 4096;
61 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): Indicate SeqNum: %d\n",__func__, pReorderEntry->SeqNum);
62 stats_IndicateArray[index] = pReorderEntry->prxb;
65 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
76 pRxTs->RxTimeoutIndicateSeq = 0xffff;
78 if (index > REORDER_WIN_SIZE){
79 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
80 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
83 rtllib_indicate_packets(ieee, stats_IndicateArray, index);
87 if (bPktInBuf && (pRxTs->RxTimeoutIndicateSeq==0xffff)){
88 pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
89 mod_timer(&pRxTs->RxPktPendingTimer, jiffies + MSECS(ieee->pHTInfo->RxReorderPendingTime));
91 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
94 void TsAddBaProcess(unsigned long data)
96 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)data;
98 struct rtllib_device *ieee = container_of(pTxTs, struct rtllib_device, TxTsRecord[num]);
100 TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
101 RTLLIB_DEBUG(RTLLIB_DL_BA, "TsAddBaProcess(): ADDBA Req is started!! \n");
105 void ResetTsCommonInfo(PTS_COMMON_INFO pTsCommonInfo)
107 memset(pTsCommonInfo->Addr, 0, 6);
108 memset(&pTsCommonInfo->TSpec, 0, sizeof(TSPEC_BODY));
109 memset(&pTsCommonInfo->TClass, 0, sizeof(QOS_TCLAS)*TCLAS_NUM);
110 pTsCommonInfo->TClasProc = 0;
111 pTsCommonInfo->TClasNum = 0;
114 void ResetTxTsEntry(PTX_TS_RECORD pTS)
116 ResetTsCommonInfo(&pTS->TsCommonInfo);
118 pTS->bAddBaReqInProgress = false;
119 pTS->bAddBaReqDelayed = false;
120 pTS->bUsingBa = false;
121 pTS->bDisable_AddBa = false;
122 ResetBaEntry(&pTS->TxAdmittedBARecord);
123 ResetBaEntry(&pTS->TxPendingBARecord);
126 void ResetRxTsEntry(PRX_TS_RECORD pTS)
128 ResetTsCommonInfo(&pTS->TsCommonInfo);
129 pTS->RxIndicateSeq = 0xffff;
130 pTS->RxTimeoutIndicateSeq = 0xffff;
131 ResetBaEntry(&pTS->RxAdmittedBARecord);
133 #ifdef _RTL8192_EXT_PATCH_
134 void ResetAdmitTRStream(struct rtllib_device *ieee, u8 *Addr)
137 bool search_dir[4] = {0, 0, 0, 0};
138 struct list_head* psearch_list;
139 PTS_COMMON_INFO pRet = NULL;
140 PRX_TS_RECORD pRxTS = NULL;
141 PTX_TS_RECORD pTxTS = NULL;
143 if (ieee->iw_mode != IW_MODE_MESH)
146 search_dir[DIR_DOWN] = true;
147 psearch_list = &ieee->Rx_TS_Admit_List;
148 for (dir = 0; dir <= DIR_BI_DIR; dir++)
150 if (search_dir[dir] ==false )
152 list_for_each_entry(pRet, psearch_list, List){
153 if ((memcmp(pRet->Addr, Addr, 6) == 0) && (pRet->TSpec.f.TSInfo.field.ucDirection == dir))
155 pRxTS = (PRX_TS_RECORD)pRet;
156 pRxTS->RxIndicateSeq = 0xffff;
157 pRxTS->RxTimeoutIndicateSeq = 0xffff;
162 search_dir[DIR_UP] = true;
163 psearch_list = &ieee->Tx_TS_Admit_List;
164 for (dir = 0; dir <= DIR_BI_DIR; dir++)
166 if (search_dir[dir] ==false )
168 list_for_each_entry(pRet, psearch_list, List){
169 if ((memcmp(pRet->Addr, Addr, 6) == 0) && (pRet->TSpec.f.TSInfo.field.ucDirection == dir))
171 pTxTS = (PTX_TS_RECORD)pRet;
172 pTxTS->TxCurSeq = 0xffff;
182 void TSInitialize(struct rtllib_device *ieee)
184 PTX_TS_RECORD pTxTS = ieee->TxTsRecord;
185 PRX_TS_RECORD pRxTS = ieee->RxTsRecord;
186 PRX_REORDER_ENTRY pRxReorderEntry = ieee->RxReorderEntry;
188 RTLLIB_DEBUG(RTLLIB_DL_TS, "==========>%s()\n", __func__);
189 INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
190 INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
191 INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
193 for (count = 0; count < TOTAL_TS_NUM; count++)
196 _setup_timer(&pTxTS->TsCommonInfo.SetupTimer,
198 (unsigned long) pTxTS);
200 _setup_timer(&pTxTS->TsCommonInfo.InactTimer,
202 (unsigned long) pTxTS);
204 _setup_timer(&pTxTS->TsAddBaTimer,
206 (unsigned long) pTxTS);
208 _setup_timer(&pTxTS->TxPendingBARecord.Timer,
210 (unsigned long) pTxTS);
211 _setup_timer(&pTxTS->TxAdmittedBARecord.Timer,
213 (unsigned long) pTxTS);
215 ResetTxTsEntry(pTxTS);
216 list_add_tail(&pTxTS->TsCommonInfo.List,
217 &ieee->Tx_TS_Unused_List);
221 INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
222 INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
223 INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
224 for (count = 0; count < TOTAL_TS_NUM; count++)
227 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
229 _setup_timer(&pRxTS->TsCommonInfo.SetupTimer,
231 (unsigned long) pRxTS);
233 _setup_timer(&pRxTS->TsCommonInfo.InactTimer,
235 (unsigned long) pRxTS);
237 _setup_timer(&pRxTS->RxAdmittedBARecord.Timer,
239 (unsigned long) pRxTS);
241 _setup_timer(&pRxTS->RxPktPendingTimer,
243 (unsigned long) pRxTS);
245 ResetRxTsEntry(pRxTS);
246 list_add_tail(&pRxTS->TsCommonInfo.List, &ieee->Rx_TS_Unused_List);
249 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
250 for (count = 0; count < REORDER_ENTRY_NUM; count++)
252 list_add_tail( &pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
253 if (count == (REORDER_ENTRY_NUM-1))
255 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
260 void AdmitTS(struct rtllib_device *ieee, PTS_COMMON_INFO pTsCommonInfo, u32 InactTime)
262 del_timer_sync(&pTsCommonInfo->SetupTimer);
263 del_timer_sync(&pTsCommonInfo->InactTimer);
266 mod_timer(&pTsCommonInfo->InactTimer, jiffies + MSECS(InactTime));
270 PTS_COMMON_INFO SearchAdmitTRStream(struct rtllib_device *ieee, u8* Addr, u8 TID, TR_SELECT TxRxSelect)
273 bool search_dir[4] = {0, 0, 0, 0};
274 struct list_head* psearch_list;
275 PTS_COMMON_INFO pRet = NULL;
276 if (ieee->iw_mode == IW_MODE_MASTER)
278 if (TxRxSelect == TX_DIR)
280 search_dir[DIR_DOWN] = true;
281 search_dir[DIR_BI_DIR]= true;
285 search_dir[DIR_UP] = true;
286 search_dir[DIR_BI_DIR]= true;
289 else if (ieee->iw_mode == IW_MODE_ADHOC)
291 if (TxRxSelect == TX_DIR)
292 search_dir[DIR_UP] = true;
294 search_dir[DIR_DOWN] = true;
298 if (TxRxSelect == TX_DIR)
300 search_dir[DIR_UP] = true;
301 search_dir[DIR_BI_DIR]= true;
302 search_dir[DIR_DIRECT]= true;
306 search_dir[DIR_DOWN] = true;
307 search_dir[DIR_BI_DIR]= true;
308 search_dir[DIR_DIRECT]= true;
312 if (TxRxSelect == TX_DIR)
313 psearch_list = &ieee->Tx_TS_Admit_List;
315 psearch_list = &ieee->Rx_TS_Admit_List;
317 for (dir = 0; dir <= DIR_BI_DIR; dir++)
319 if (search_dir[dir] ==false )
321 list_for_each_entry(pRet, psearch_list, List){
322 if (memcmp(pRet->Addr, Addr, 6) == 0)
323 if (pRet->TSpec.f.TSInfo.field.ucTSID == TID)
324 if (pRet->TSpec.f.TSInfo.field.ucDirection == dir)
330 if (&pRet->List != psearch_list)
334 if (&pRet->List != psearch_list){
342 PTS_COMMON_INFO pTsCommonInfo,
352 if (pTsCommonInfo == NULL)
355 memcpy(pTsCommonInfo->Addr, Addr, 6);
358 memcpy((u8*)(&(pTsCommonInfo->TSpec)), (u8*)pTSPEC, sizeof(TSPEC_BODY));
360 for (count = 0; count < TCLAS_Num; count++)
361 memcpy((u8*)(&(pTsCommonInfo->TClass[count])), (u8*)pTCLAS, sizeof(QOS_TCLAS));
363 pTsCommonInfo->TClasProc = TCLAS_Proc;
364 pTsCommonInfo->TClasNum = TCLAS_Num;
367 #ifdef _RTL8192_EXT_PATCH_
368 void dump_ts_list(struct list_head * ts_list)
370 PTS_COMMON_INFO pRet = NULL;
372 list_for_each_entry(pRet, ts_list, List){
373 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);
381 struct rtllib_device* ieee,
382 PTS_COMMON_INFO *ppTS,
385 TR_SELECT TxRxSelect,
389 if (is_broadcast_ether_addr(Addr) || is_multicast_ether_addr(Addr))
391 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! get TS for Broadcast or Multicast\n");
394 if (ieee->current_network.qos_data.supported == 0) {
397 if (!IsACValid(TID)) {
398 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! in %s(), TID(%d) is not valid\n", __func__, TID);
422 *ppTS = SearchAdmitTRStream(
433 if (bAddNewTs == false)
435 RTLLIB_DEBUG(RTLLIB_DL_TS, "add new TS failed(tid:%d)\n", UP);
441 PQOS_TSINFO pTSInfo = &TSpec.f.TSInfo;
442 struct list_head* pUnusedList =
443 (TxRxSelect == TX_DIR)?
444 (&ieee->Tx_TS_Unused_List):
445 (&ieee->Rx_TS_Unused_List);
447 struct list_head* pAddmitList =
448 (TxRxSelect == TX_DIR)?
449 (&ieee->Tx_TS_Admit_List):
450 (&ieee->Rx_TS_Admit_List);
452 DIRECTION_VALUE Dir = (ieee->iw_mode == IW_MODE_MASTER)?
453 ((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):
454 ((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
455 RTLLIB_DEBUG(RTLLIB_DL_TS, "to add Ts\n");
456 if (!list_empty(pUnusedList))
458 (*ppTS) = list_entry(pUnusedList->next, TS_COMMON_INFO, List);
459 list_del_init(&(*ppTS)->List);
460 if (TxRxSelect==TX_DIR)
462 PTX_TS_RECORD tmp = container_of(*ppTS, TX_TS_RECORD, TsCommonInfo);
466 PRX_TS_RECORD tmp = container_of(*ppTS, RX_TS_RECORD, TsCommonInfo);
470 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);
471 pTSInfo->field.ucTrafficType = 0;
472 pTSInfo->field.ucTSID = UP;
473 pTSInfo->field.ucDirection = Dir;
474 pTSInfo->field.ucAccessPolicy = 1;
475 pTSInfo->field.ucAggregation = 0;
476 pTSInfo->field.ucPSB = 0;
477 pTSInfo->field.ucUP = UP;
478 pTSInfo->field.ucTSInfoAckPolicy = 0;
479 pTSInfo->field.ucSchedule = 0;
481 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
482 AdmitTS(ieee, *ppTS, 0);
483 list_add_tail(&((*ppTS)->List), pAddmitList);
489 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!in function %s() There is not enough dir=%d(0=up down=1) TS record to be used!!", __func__,Dir);
497 struct rtllib_device* ieee,
502 del_timer_sync(&pTs->SetupTimer);
503 del_timer_sync(&pTs->InactTimer);
504 TsInitDelBA(ieee, pTs, TxRxSelect);
506 if (TxRxSelect == RX_DIR)
508 PRX_REORDER_ENTRY pRxReorderEntry;
509 PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTs;
511 if (timer_pending(&pRxTS->RxPktPendingTimer))
512 del_timer_sync(&pRxTS->RxPktPendingTimer);
514 while(!list_empty(&pRxTS->RxPendingPktList)){
515 pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
516 RTLLIB_DEBUG(RTLLIB_DL_REORDER,"%s(): Delete SeqNum %d!\n",__func__, pRxReorderEntry->SeqNum);
517 list_del_init(&pRxReorderEntry->List);
520 struct rtllib_rxb * prxb = pRxReorderEntry->prxb;
521 if (unlikely(!prxb)){
524 for (i =0; i < prxb->nr_subframes; i++) {
525 dev_kfree_skb(prxb->subframes[i]);
530 list_add_tail(&pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
534 PTX_TS_RECORD pTxTS = (PTX_TS_RECORD)pTs;
535 del_timer_sync(&pTxTS->TsAddBaTimer);
539 void RemovePeerTS(struct rtllib_device* ieee, u8* Addr)
541 PTS_COMMON_INFO pTS, pTmpTS;
542 printk("===========>RemovePeerTS,"MAC_FMT"\n", MAC_ARG(Addr));
544 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
546 if (memcmp(pTS->Addr, Addr, 6) == 0)
548 RemoveTsEntry(ieee, pTS, TX_DIR);
549 list_del_init(&pTS->List);
550 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
554 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
556 if (memcmp(pTS->Addr, Addr, 6) == 0)
558 printk("====>remove Tx_TS_admin_list\n");
559 RemoveTsEntry(ieee, pTS, TX_DIR);
560 list_del_init(&pTS->List);
561 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
565 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
567 if (memcmp(pTS->Addr, Addr, 6) == 0)
569 RemoveTsEntry(ieee, pTS, RX_DIR);
570 list_del_init(&pTS->List);
571 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
575 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
577 if (memcmp(pTS->Addr, Addr, 6) == 0)
579 RemoveTsEntry(ieee, pTS, RX_DIR);
580 list_del_init(&pTS->List);
581 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
586 void RemoveAllTS(struct rtllib_device* ieee)
588 PTS_COMMON_INFO pTS, pTmpTS;
590 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
592 RemoveTsEntry(ieee, pTS, TX_DIR);
593 list_del_init(&pTS->List);
594 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
597 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
599 RemoveTsEntry(ieee, pTS, TX_DIR);
600 list_del_init(&pTS->List);
601 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
604 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
606 RemoveTsEntry(ieee, pTS, RX_DIR);
607 list_del_init(&pTS->List);
608 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
611 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
613 RemoveTsEntry(ieee, pTS, RX_DIR);
614 list_del_init(&pTS->List);
615 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
619 void TsStartAddBaProcess(struct rtllib_device* ieee, PTX_TS_RECORD pTxTS)
621 if (pTxTS->bAddBaReqInProgress == false)
623 pTxTS->bAddBaReqInProgress = true;
625 if (pTxTS->bAddBaReqDelayed)
627 RTLLIB_DEBUG(RTLLIB_DL_BA, "TsStartAddBaProcess(): Delayed Start ADDBA after 60 sec!!\n");
628 mod_timer(&pTxTS->TsAddBaTimer, jiffies + MSECS(TS_ADDBA_DELAY));
632 RTLLIB_DEBUG(RTLLIB_DL_BA,"TsStartAddBaProcess(): Immediately Start ADDBA now!!\n");
633 mod_timer(&pTxTS->TsAddBaTimer, jiffies+10);
637 RTLLIB_DEBUG(RTLLIB_DL_BA, "%s()==>BA timer is already added\n", __func__);