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"
23 static void TsSetupTimeOut(unsigned long data)
27 static void TsInactTimeout(unsigned long data)
31 static void RxPktPendingTimeout(unsigned long data)
33 struct rx_ts_record *pRxTs = (struct rx_ts_record *)data;
34 struct rtllib_device *ieee = container_of(pRxTs, struct rtllib_device,
35 RxTsRecord[pRxTs->num]);
37 struct rx_reorder_entry *pReorderEntry = NULL;
39 unsigned long flags = 0;
41 bool bPktInBuf = false;
43 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
44 if (pRxTs->RxTimeoutIndicateSeq != 0xffff) {
45 while (!list_empty(&pRxTs->RxPendingPktList)) {
46 pReorderEntry = (struct rx_reorder_entry *)
47 list_entry(pRxTs->RxPendingPktList.prev,
48 struct rx_reorder_entry, List);
50 pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
52 if (SN_LESS(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) ||
53 SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq)) {
54 list_del_init(&pReorderEntry->List);
56 if (SN_EQUAL(pReorderEntry->SeqNum,
57 pRxTs->RxIndicateSeq))
58 pRxTs->RxIndicateSeq =
59 (pRxTs->RxIndicateSeq + 1) % 4096;
61 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Indicate"
62 " SeqNum: %d\n", __func__,
63 pReorderEntry->SeqNum);
64 ieee->stats_IndicateArray[index] =
68 list_add_tail(&pReorderEntry->List,
69 &ieee->RxReorder_Unused_List);
78 pRxTs->RxTimeoutIndicateSeq = 0xffff;
80 if (index > REORDER_WIN_SIZE) {
81 RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket():"
82 " Rx Reorder struct buffer full!!\n");
83 spin_unlock_irqrestore(&(ieee->reorder_spinlock),
87 rtllib_indicate_packets(ieee, ieee->stats_IndicateArray, index);
91 if (bPktInBuf && (pRxTs->RxTimeoutIndicateSeq == 0xffff)) {
92 pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
93 mod_timer(&pRxTs->RxPktPendingTimer, jiffies +
94 MSECS(ieee->pHTInfo->RxReorderPendingTime));
96 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
99 static void TsAddBaProcess(unsigned long data)
101 struct tx_ts_record *pTxTs = (struct tx_ts_record *)data;
103 struct rtllib_device *ieee = container_of(pTxTs, struct rtllib_device,
106 TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
107 RTLLIB_DEBUG(RTLLIB_DL_BA, "TsAddBaProcess(): ADDBA Req is "
111 static void ResetTsCommonInfo(struct ts_common_info *pTsCommonInfo)
113 memset(pTsCommonInfo->Addr, 0, 6);
114 memset(&pTsCommonInfo->TSpec, 0, sizeof(union tspec_body));
115 memset(&pTsCommonInfo->TClass, 0, sizeof(union qos_tclas)*TCLAS_NUM);
116 pTsCommonInfo->TClasProc = 0;
117 pTsCommonInfo->TClasNum = 0;
120 static void ResetTxTsEntry(struct tx_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 static void ResetRxTsEntry(struct rx_ts_record *pTS)
134 ResetTsCommonInfo(&pTS->TsCommonInfo);
135 pTS->RxIndicateSeq = 0xffff;
136 pTS->RxTimeoutIndicateSeq = 0xffff;
137 ResetBaEntry(&pTS->RxAdmittedBARecord);
140 void TSInitialize(struct rtllib_device *ieee)
142 struct tx_ts_record *pTxTS = ieee->TxTsRecord;
143 struct rx_ts_record *pRxTS = ieee->RxTsRecord;
144 struct rx_reorder_entry *pRxReorderEntry = ieee->RxReorderEntry;
147 RTLLIB_DEBUG(RTLLIB_DL_TS, "==========>%s()\n", __func__);
148 INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
149 INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
150 INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
152 for (count = 0; count < TOTAL_TS_NUM; count++) {
154 _setup_timer(&pTxTS->TsCommonInfo.SetupTimer,
156 (unsigned long) pTxTS);
158 _setup_timer(&pTxTS->TsCommonInfo.InactTimer,
160 (unsigned long) pTxTS);
162 _setup_timer(&pTxTS->TsAddBaTimer,
164 (unsigned long) pTxTS);
166 _setup_timer(&pTxTS->TxPendingBARecord.Timer,
168 (unsigned long) pTxTS);
169 _setup_timer(&pTxTS->TxAdmittedBARecord.Timer,
171 (unsigned long) pTxTS);
173 ResetTxTsEntry(pTxTS);
174 list_add_tail(&pTxTS->TsCommonInfo.List,
175 &ieee->Tx_TS_Unused_List);
179 INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
180 INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
181 INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
182 for (count = 0; count < TOTAL_TS_NUM; count++) {
184 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
186 _setup_timer(&pRxTS->TsCommonInfo.SetupTimer,
188 (unsigned long) pRxTS);
190 _setup_timer(&pRxTS->TsCommonInfo.InactTimer,
192 (unsigned long) pRxTS);
194 _setup_timer(&pRxTS->RxAdmittedBARecord.Timer,
196 (unsigned long) pRxTS);
198 _setup_timer(&pRxTS->RxPktPendingTimer,
200 (unsigned long) pRxTS);
202 ResetRxTsEntry(pRxTS);
203 list_add_tail(&pRxTS->TsCommonInfo.List,
204 &ieee->Rx_TS_Unused_List);
207 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
208 for (count = 0; count < REORDER_ENTRY_NUM; count++) {
209 list_add_tail(&pRxReorderEntry->List,
210 &ieee->RxReorder_Unused_List);
211 if (count == (REORDER_ENTRY_NUM-1))
213 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
218 static void AdmitTS(struct rtllib_device *ieee,
219 struct ts_common_info *pTsCommonInfo, u32 InactTime)
221 del_timer_sync(&pTsCommonInfo->SetupTimer);
222 del_timer_sync(&pTsCommonInfo->InactTimer);
225 mod_timer(&pTsCommonInfo->InactTimer, jiffies +
229 static struct ts_common_info *SearchAdmitTRStream(struct rtllib_device *ieee,
231 enum tr_select TxRxSelect)
234 bool search_dir[4] = {0};
235 struct list_head *psearch_list;
236 struct ts_common_info *pRet = NULL;
238 if (ieee->iw_mode == IW_MODE_MASTER) {
239 if (TxRxSelect == TX_DIR) {
240 search_dir[DIR_DOWN] = true;
241 search_dir[DIR_BI_DIR] = true;
243 search_dir[DIR_UP] = true;
244 search_dir[DIR_BI_DIR] = true;
246 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
247 if (TxRxSelect == TX_DIR)
248 search_dir[DIR_UP] = true;
250 search_dir[DIR_DOWN] = true;
252 if (TxRxSelect == TX_DIR) {
253 search_dir[DIR_UP] = true;
254 search_dir[DIR_BI_DIR] = true;
255 search_dir[DIR_DIRECT] = true;
257 search_dir[DIR_DOWN] = true;
258 search_dir[DIR_BI_DIR] = true;
259 search_dir[DIR_DIRECT] = true;
263 if (TxRxSelect == TX_DIR)
264 psearch_list = &ieee->Tx_TS_Admit_List;
266 psearch_list = &ieee->Rx_TS_Admit_List;
268 for (dir = 0; dir <= DIR_BI_DIR; dir++) {
269 if (!search_dir[dir])
271 list_for_each_entry(pRet, psearch_list, List) {
272 if (memcmp(pRet->Addr, Addr, 6) == 0)
273 if (pRet->TSpec.f.TSInfo.field.ucTSID == TID)
274 if (pRet->TSpec.f.TSInfo.field.ucDirection == dir)
278 if (&pRet->List != psearch_list)
282 if (pRet && &pRet->List != psearch_list)
287 static void MakeTSEntry(struct ts_common_info *pTsCommonInfo, u8 *Addr,
288 union tspec_body *pTSPEC, union qos_tclas *pTCLAS,
289 u8 TCLAS_Num, u8 TCLAS_Proc)
293 if (pTsCommonInfo == NULL)
296 memcpy(pTsCommonInfo->Addr, Addr, 6);
299 memcpy((u8 *)(&(pTsCommonInfo->TSpec)), (u8 *)pTSPEC,
300 sizeof(union tspec_body));
302 for (count = 0; count < TCLAS_Num; count++)
303 memcpy((u8 *)(&(pTsCommonInfo->TClass[count])),
304 (u8 *)pTCLAS, sizeof(union qos_tclas));
306 pTsCommonInfo->TClasProc = TCLAS_Proc;
307 pTsCommonInfo->TClasNum = TCLAS_Num;
310 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS,
311 u8 *Addr, u8 TID, enum tr_select TxRxSelect, bool bAddNewTs)
315 if (is_multicast_ether_addr(Addr)) {
316 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! get TS for Broadcast or "
320 if (ieee->current_network.qos_data.supported == 0) {
323 if (!IsACValid(TID)) {
324 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR! in %s(), TID(%d) is "
325 "not valid\n", __func__, TID);
349 *ppTS = SearchAdmitTRStream(ieee, Addr, UP, TxRxSelect);
354 RTLLIB_DEBUG(RTLLIB_DL_TS, "add new TS failed"
358 union tspec_body TSpec;
359 union qos_tsinfo *pTSInfo = &TSpec.f.TSInfo;
360 struct list_head *pUnusedList =
361 (TxRxSelect == TX_DIR) ?
362 (&ieee->Tx_TS_Unused_List) :
363 (&ieee->Rx_TS_Unused_List);
365 struct list_head *pAddmitList =
366 (TxRxSelect == TX_DIR) ?
367 (&ieee->Tx_TS_Admit_List) :
368 (&ieee->Rx_TS_Admit_List);
370 enum direction_value Dir =
371 (ieee->iw_mode == IW_MODE_MASTER) ?
372 ((TxRxSelect == TX_DIR) ? DIR_DOWN : DIR_UP) :
373 ((TxRxSelect == TX_DIR) ? DIR_UP : DIR_DOWN);
374 RTLLIB_DEBUG(RTLLIB_DL_TS, "to add Ts\n");
375 if (!list_empty(pUnusedList)) {
376 (*ppTS) = list_entry(pUnusedList->next,
377 struct ts_common_info, List);
378 list_del_init(&(*ppTS)->List);
379 if (TxRxSelect == TX_DIR) {
380 struct tx_ts_record *tmp =
386 struct rx_ts_record *tmp =
393 RTLLIB_DEBUG(RTLLIB_DL_TS, "to init current TS"
394 ", UP:%d, Dir:%d, addr: %pM"
395 " ppTs=%p\n", UP, Dir,
397 pTSInfo->field.ucTrafficType = 0;
398 pTSInfo->field.ucTSID = UP;
399 pTSInfo->field.ucDirection = Dir;
400 pTSInfo->field.ucAccessPolicy = 1;
401 pTSInfo->field.ucAggregation = 0;
402 pTSInfo->field.ucPSB = 0;
403 pTSInfo->field.ucUP = UP;
404 pTSInfo->field.ucTSInfoAckPolicy = 0;
405 pTSInfo->field.ucSchedule = 0;
407 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
408 AdmitTS(ieee, *ppTS, 0);
409 list_add_tail(&((*ppTS)->List), pAddmitList);
413 RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!in function "
414 "%s() There is not enough dir=%d"
415 "(0=up down=1) TS record to be "
416 "used!!", __func__, Dir);
423 static void RemoveTsEntry(struct rtllib_device *ieee, struct ts_common_info *pTs,
424 enum tr_select TxRxSelect)
426 del_timer_sync(&pTs->SetupTimer);
427 del_timer_sync(&pTs->InactTimer);
428 TsInitDelBA(ieee, pTs, TxRxSelect);
430 if (TxRxSelect == RX_DIR) {
431 struct rx_reorder_entry *pRxReorderEntry;
432 struct rx_ts_record *pRxTS = (struct rx_ts_record *)pTs;
434 if (timer_pending(&pRxTS->RxPktPendingTimer))
435 del_timer_sync(&pRxTS->RxPktPendingTimer);
437 while (!list_empty(&pRxTS->RxPendingPktList)) {
438 pRxReorderEntry = (struct rx_reorder_entry *)
439 list_entry(pRxTS->RxPendingPktList.prev,
440 struct rx_reorder_entry, List);
441 RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Delete SeqNum "
443 pRxReorderEntry->SeqNum);
444 list_del_init(&pRxReorderEntry->List);
447 struct rtllib_rxb *prxb = pRxReorderEntry->prxb;
451 for (i = 0; i < prxb->nr_subframes; i++)
452 dev_kfree_skb(prxb->subframes[i]);
456 list_add_tail(&pRxReorderEntry->List,
457 &ieee->RxReorder_Unused_List);
460 struct tx_ts_record *pTxTS = (struct tx_ts_record *)pTs;
462 del_timer_sync(&pTxTS->TsAddBaTimer);
466 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr)
468 struct ts_common_info *pTS, *pTmpTS;
470 printk(KERN_INFO "===========>RemovePeerTS, %pM\n", Addr);
472 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
473 if (memcmp(pTS->Addr, Addr, 6) == 0) {
474 RemoveTsEntry(ieee, pTS, TX_DIR);
475 list_del_init(&pTS->List);
476 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
480 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
481 if (memcmp(pTS->Addr, Addr, 6) == 0) {
482 printk(KERN_INFO "====>remove Tx_TS_admin_list\n");
483 RemoveTsEntry(ieee, pTS, TX_DIR);
484 list_del_init(&pTS->List);
485 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
489 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
490 if (memcmp(pTS->Addr, Addr, 6) == 0) {
491 RemoveTsEntry(ieee, pTS, RX_DIR);
492 list_del_init(&pTS->List);
493 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
497 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
498 if (memcmp(pTS->Addr, Addr, 6) == 0) {
499 RemoveTsEntry(ieee, pTS, RX_DIR);
500 list_del_init(&pTS->List);
501 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
505 EXPORT_SYMBOL(RemovePeerTS);
507 void RemoveAllTS(struct rtllib_device *ieee)
509 struct ts_common_info *pTS, *pTmpTS;
511 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) {
512 RemoveTsEntry(ieee, pTS, TX_DIR);
513 list_del_init(&pTS->List);
514 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
517 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List) {
518 RemoveTsEntry(ieee, pTS, TX_DIR);
519 list_del_init(&pTS->List);
520 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
523 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List) {
524 RemoveTsEntry(ieee, pTS, RX_DIR);
525 list_del_init(&pTS->List);
526 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
529 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List) {
530 RemoveTsEntry(ieee, pTS, RX_DIR);
531 list_del_init(&pTS->List);
532 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
536 void TsStartAddBaProcess(struct rtllib_device *ieee, struct tx_ts_record *pTxTS)
538 if (pTxTS->bAddBaReqInProgress == false) {
539 pTxTS->bAddBaReqInProgress = true;
541 if (pTxTS->bAddBaReqDelayed) {
542 RTLLIB_DEBUG(RTLLIB_DL_BA, "TsStartAddBaProcess(): "
543 "Delayed Start ADDBA after 60 sec!!\n");
544 mod_timer(&pTxTS->TsAddBaTimer, jiffies +
545 MSECS(TS_ADDBA_DELAY));
547 RTLLIB_DEBUG(RTLLIB_DL_BA, "TsStartAddBaProcess(): "
548 "Immediately Start ADDBA now!!\n");
549 mod_timer(&pTxTS->TsAddBaTimer, jiffies+10);
552 RTLLIB_DEBUG(RTLLIB_DL_BA, "%s()==>BA timer is already added\n",